2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <scsi/scsi_tcq.h>
12 static void qla2x00_mbx_completion(scsi_qla_host_t
*, uint16_t);
13 static void qla2x00_process_completed_request(struct scsi_qla_host
*, uint32_t);
14 static void qla2x00_status_entry(scsi_qla_host_t
*, void *);
15 static void qla2x00_status_cont_entry(scsi_qla_host_t
*, sts_cont_entry_t
*);
16 static void qla2x00_error_entry(scsi_qla_host_t
*, sts_entry_t
*);
17 static void qla2x00_ms_entry(scsi_qla_host_t
*, ms_iocb_entry_t
*);
19 static void qla24xx_ms_entry(scsi_qla_host_t
*, struct ct_entry_24xx
*);
22 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
24 * @dev_id: SCSI driver HA context
26 * Called by system whenever the host adapter generates an interrupt.
28 * Returns handled flag.
31 qla2100_intr_handler(int irq
, void *dev_id
)
34 struct device_reg_2xxx __iomem
*reg
;
41 ha
= (scsi_qla_host_t
*) dev_id
;
44 "%s(): NULL host pointer\n", __func__
);
48 reg
= &ha
->iobase
->isp
;
51 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
52 for (iter
= 50; iter
--; ) {
53 hccr
= RD_REG_WORD(®
->hccr
);
54 if (hccr
& HCCR_RISC_PAUSE
) {
55 if (pci_channel_offline(ha
->pdev
))
59 * Issue a "HARD" reset in order for the RISC interrupt
60 * bit to be cleared. Schedule a big hammmer to get
61 * out of the RISC PAUSED state.
63 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
64 RD_REG_WORD(®
->hccr
);
66 ha
->isp_ops
->fw_dump(ha
, 1);
67 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
69 } else if ((RD_REG_WORD(®
->istatus
) & ISR_RISC_INT
) == 0)
72 if (RD_REG_WORD(®
->semaphore
) & BIT_0
) {
73 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
74 RD_REG_WORD(®
->hccr
);
76 /* Get mailbox data. */
77 mb
[0] = RD_MAILBOX_REG(ha
, reg
, 0);
78 if (mb
[0] > 0x3fff && mb
[0] < 0x8000) {
79 qla2x00_mbx_completion(ha
, mb
[0]);
80 status
|= MBX_INTERRUPT
;
81 } else if (mb
[0] > 0x7fff && mb
[0] < 0xc000) {
82 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
83 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
84 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
85 qla2x00_async_event(ha
, mb
);
88 DEBUG2(printk("scsi(%ld): Unrecognized "
89 "interrupt type (%d).\n",
92 /* Release mailbox registers. */
93 WRT_REG_WORD(®
->semaphore
, 0);
94 RD_REG_WORD(®
->semaphore
);
96 qla2x00_process_response_queue(ha
);
98 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
99 RD_REG_WORD(®
->hccr
);
102 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
104 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
105 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
106 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
107 complete(&ha
->mbx_intr_comp
);
110 return (IRQ_HANDLED
);
114 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
116 * @dev_id: SCSI driver HA context
118 * Called by system whenever the host adapter generates an interrupt.
120 * Returns handled flag.
123 qla2300_intr_handler(int irq
, void *dev_id
)
126 struct device_reg_2xxx __iomem
*reg
;
134 ha
= (scsi_qla_host_t
*) dev_id
;
137 "%s(): NULL host pointer\n", __func__
);
141 reg
= &ha
->iobase
->isp
;
144 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
145 for (iter
= 50; iter
--; ) {
146 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
147 if (stat
& HSR_RISC_PAUSED
) {
148 if (pci_channel_offline(ha
->pdev
))
151 hccr
= RD_REG_WORD(®
->hccr
);
152 if (hccr
& (BIT_15
| BIT_13
| BIT_11
| BIT_8
))
153 qla_printk(KERN_INFO
, ha
, "Parity error -- "
154 "HCCR=%x, Dumping firmware!\n", hccr
);
156 qla_printk(KERN_INFO
, ha
, "RISC paused -- "
157 "HCCR=%x, Dumping firmware!\n", hccr
);
160 * Issue a "HARD" reset in order for the RISC
161 * interrupt bit to be cleared. Schedule a big
162 * hammmer to get out of the RISC PAUSED state.
164 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
165 RD_REG_WORD(®
->hccr
);
167 ha
->isp_ops
->fw_dump(ha
, 1);
168 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
170 } else if ((stat
& HSR_RISC_INT
) == 0)
173 switch (stat
& 0xff) {
178 qla2x00_mbx_completion(ha
, MSW(stat
));
179 status
|= MBX_INTERRUPT
;
181 /* Release mailbox registers. */
182 WRT_REG_WORD(®
->semaphore
, 0);
186 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
187 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
188 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
189 qla2x00_async_event(ha
, mb
);
192 qla2x00_process_response_queue(ha
);
195 mb
[0] = MBA_CMPLT_1_16BIT
;
197 qla2x00_async_event(ha
, mb
);
200 mb
[0] = MBA_SCSI_COMPLETION
;
202 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
203 qla2x00_async_event(ha
, mb
);
206 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
208 ha
->host_no
, stat
& 0xff));
211 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
212 RD_REG_WORD_RELAXED(®
->hccr
);
214 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
216 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
217 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
218 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
219 complete(&ha
->mbx_intr_comp
);
222 return (IRQ_HANDLED
);
226 * qla2x00_mbx_completion() - Process mailbox command completions.
227 * @ha: SCSI driver HA context
228 * @mb0: Mailbox0 register
231 qla2x00_mbx_completion(scsi_qla_host_t
*ha
, uint16_t mb0
)
234 uint16_t __iomem
*wptr
;
235 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
237 /* Load return mailbox registers. */
238 ha
->flags
.mbox_int
= 1;
239 ha
->mailbox_out
[0] = mb0
;
240 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 1);
242 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
243 if (IS_QLA2200(ha
) && cnt
== 8)
244 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 8);
245 if (cnt
== 4 || cnt
== 5)
246 ha
->mailbox_out
[cnt
] = qla2x00_debounce_register(wptr
);
248 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
254 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
255 __func__
, ha
->host_no
, ha
->mcp
->mb
[0]));
257 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
258 __func__
, ha
->host_no
));
263 * qla2x00_async_event() - Process aynchronous events.
264 * @ha: SCSI driver HA context
265 * @mb: Mailbox registers (0 - 3)
268 qla2x00_async_event(scsi_qla_host_t
*ha
, uint16_t *mb
)
271 static char *link_speeds
[5] = { "1", "2", "?", "4", "8" };
276 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
277 uint32_t rscn_entry
, host_pid
;
278 uint8_t rscn_queue_index
;
280 /* Setup to process RIO completion. */
283 case MBA_SCSI_COMPLETION
:
284 handles
[0] = le32_to_cpu((uint32_t)((mb
[2] << 16) | mb
[1]));
287 case MBA_CMPLT_1_16BIT
:
290 mb
[0] = MBA_SCSI_COMPLETION
;
292 case MBA_CMPLT_2_16BIT
:
296 mb
[0] = MBA_SCSI_COMPLETION
;
298 case MBA_CMPLT_3_16BIT
:
303 mb
[0] = MBA_SCSI_COMPLETION
;
305 case MBA_CMPLT_4_16BIT
:
309 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
311 mb
[0] = MBA_SCSI_COMPLETION
;
313 case MBA_CMPLT_5_16BIT
:
317 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
318 handles
[4] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 7);
320 mb
[0] = MBA_SCSI_COMPLETION
;
322 case MBA_CMPLT_2_32BIT
:
323 handles
[0] = le32_to_cpu((uint32_t)((mb
[2] << 16) | mb
[1]));
324 handles
[1] = le32_to_cpu(
325 ((uint32_t)(RD_MAILBOX_REG(ha
, reg
, 7) << 16)) |
326 RD_MAILBOX_REG(ha
, reg
, 6));
328 mb
[0] = MBA_SCSI_COMPLETION
;
335 case MBA_SCSI_COMPLETION
: /* Fast Post */
336 if (!ha
->flags
.online
)
339 for (cnt
= 0; cnt
< handle_cnt
; cnt
++)
340 qla2x00_process_completed_request(ha
, handles
[cnt
]);
343 case MBA_RESET
: /* Reset */
344 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha
->host_no
));
346 set_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
349 case MBA_SYSTEM_ERR
: /* System Error */
350 qla_printk(KERN_INFO
, ha
,
351 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
352 mb
[1], mb
[2], mb
[3]);
354 ha
->isp_ops
->fw_dump(ha
, 1);
356 if (IS_FWI2_CAPABLE(ha
)) {
357 if (mb
[1] == 0 && mb
[2] == 0) {
358 qla_printk(KERN_ERR
, ha
,
359 "Unrecoverable Hardware Error: adapter "
360 "marked OFFLINE!\n");
361 ha
->flags
.online
= 0;
363 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
364 } else if (mb
[1] == 0) {
365 qla_printk(KERN_INFO
, ha
,
366 "Unrecoverable Hardware Error: adapter marked "
368 ha
->flags
.online
= 0;
370 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
373 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
374 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
376 qla_printk(KERN_WARNING
, ha
, "ISP Request Transfer Error.\n");
378 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
381 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
382 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
384 qla_printk(KERN_WARNING
, ha
, "ISP Response Transfer Error.\n");
386 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
389 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
390 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
394 case MBA_LIP_OCCURRED
: /* Loop Initialization Procedure */
395 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha
->host_no
,
397 qla_printk(KERN_INFO
, ha
, "LIP occured (%x).\n", mb
[1]);
399 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
400 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
401 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
402 qla2x00_mark_all_devices_lost(ha
, 1);
406 atomic_set(&ha
->vp_state
, VP_FAILED
);
407 fc_vport_set_state(ha
->fc_vport
, FC_VPORT_FAILED
);
410 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
412 ha
->flags
.management_server_logged_in
= 0;
415 case MBA_LOOP_UP
: /* Loop Up Event */
416 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
417 link_speed
= link_speeds
[0];
418 ha
->link_data_rate
= PORT_SPEED_1GB
;
420 link_speed
= link_speeds
[LS_UNKNOWN
];
422 link_speed
= link_speeds
[mb
[1]];
423 ha
->link_data_rate
= mb
[1];
426 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
427 ha
->host_no
, link_speed
));
428 qla_printk(KERN_INFO
, ha
, "LOOP UP detected (%s Gbps).\n",
431 ha
->flags
.management_server_logged_in
= 0;
434 case MBA_LOOP_DOWN
: /* Loop Down Event */
435 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
436 ha
->host_no
, mb
[1]));
437 qla_printk(KERN_INFO
, ha
, "LOOP DOWN detected (%x).\n", mb
[1]);
439 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
440 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
441 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
442 ha
->device_flags
|= DFLG_NO_CABLE
;
443 qla2x00_mark_all_devices_lost(ha
, 1);
447 atomic_set(&ha
->vp_state
, VP_FAILED
);
448 fc_vport_set_state(ha
->fc_vport
, FC_VPORT_FAILED
);
451 ha
->flags
.management_server_logged_in
= 0;
452 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
454 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
457 case MBA_LIP_RESET
: /* LIP reset occurred */
458 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
459 ha
->host_no
, mb
[1]));
460 qla_printk(KERN_INFO
, ha
,
461 "LIP reset occured (%x).\n", mb
[1]);
463 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
464 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
465 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
466 qla2x00_mark_all_devices_lost(ha
, 1);
470 atomic_set(&ha
->vp_state
, VP_FAILED
);
471 fc_vport_set_state(ha
->fc_vport
, FC_VPORT_FAILED
);
474 set_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
476 ha
->operating_mode
= LOOP
;
477 ha
->flags
.management_server_logged_in
= 0;
480 case MBA_POINT_TO_POINT
: /* Point-to-Point */
484 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
488 * Until there's a transition from loop down to loop up, treat
489 * this as loop down only.
491 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
492 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
493 if (!atomic_read(&ha
->loop_down_timer
))
494 atomic_set(&ha
->loop_down_timer
,
496 qla2x00_mark_all_devices_lost(ha
, 1);
500 atomic_set(&ha
->vp_state
, VP_FAILED
);
501 fc_vport_set_state(ha
->fc_vport
, FC_VPORT_FAILED
);
504 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
))) {
505 set_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
507 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
509 ha
->flags
.gpsc_supported
= 1;
510 ha
->flags
.management_server_logged_in
= 0;
513 case MBA_CHG_IN_CONNECTION
: /* Change in connection mode */
517 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
520 qla_printk(KERN_INFO
, ha
,
521 "Configuration change detected: value=%x.\n", mb
[1]);
523 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
524 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
525 if (!atomic_read(&ha
->loop_down_timer
))
526 atomic_set(&ha
->loop_down_timer
,
528 qla2x00_mark_all_devices_lost(ha
, 1);
532 atomic_set(&ha
->vp_state
, VP_FAILED
);
533 fc_vport_set_state(ha
->fc_vport
, FC_VPORT_FAILED
);
536 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
537 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
540 case MBA_PORT_UPDATE
: /* Port database update */
542 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
543 * event etc. earlier indicating loop is down) then process
544 * it. Otherwise ignore it and Wait for RSCN to come in.
546 atomic_set(&ha
->loop_down_timer
, 0);
547 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
&&
548 atomic_read(&ha
->loop_state
) != LOOP_DEAD
) {
549 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
550 "ignored %04x/%04x/%04x.\n", ha
->host_no
, mb
[1],
555 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
557 DEBUG(printk(KERN_INFO
558 "scsi(%ld): Port database changed %04x %04x %04x.\n",
559 ha
->host_no
, mb
[1], mb
[2], mb
[3]));
562 * Mark all devices as missing so we will login again.
564 atomic_set(&ha
->loop_state
, LOOP_UP
);
566 qla2x00_mark_all_devices_lost(ha
, 1);
568 ha
->flags
.rscn_queue_overflow
= 1;
570 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
571 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
574 case MBA_RSCN_UPDATE
: /* State Change Registration */
575 /* Check if the Vport has issued a SCR */
576 if (ha
->parent
&& test_bit(VP_SCR_NEEDED
, &ha
->vp_flags
))
578 /* Only handle SCNs for our Vport index. */
579 if (ha
->flags
.npiv_supported
&& ha
->vp_idx
!= mb
[3])
582 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
584 DEBUG(printk(KERN_INFO
585 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
586 ha
->host_no
, mb
[1], mb
[2], mb
[3]));
588 rscn_entry
= (mb
[1] << 16) | mb
[2];
589 host_pid
= (ha
->d_id
.b
.domain
<< 16) | (ha
->d_id
.b
.area
<< 8) |
591 if (rscn_entry
== host_pid
) {
592 DEBUG(printk(KERN_INFO
593 "scsi(%ld): Ignoring RSCN update to local host "
595 ha
->host_no
, host_pid
));
599 rscn_queue_index
= ha
->rscn_in_ptr
+ 1;
600 if (rscn_queue_index
== MAX_RSCN_COUNT
)
601 rscn_queue_index
= 0;
602 if (rscn_queue_index
!= ha
->rscn_out_ptr
) {
603 ha
->rscn_queue
[ha
->rscn_in_ptr
] = rscn_entry
;
604 ha
->rscn_in_ptr
= rscn_queue_index
;
606 ha
->flags
.rscn_queue_overflow
= 1;
609 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
610 atomic_set(&ha
->loop_down_timer
, 0);
611 ha
->flags
.management_server_logged_in
= 0;
613 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
614 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
617 /* case MBA_RIO_RESPONSE: */
618 case MBA_ZIO_RESPONSE
:
619 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
621 DEBUG(printk(KERN_INFO
622 "scsi(%ld): [R|Z]IO update completion.\n",
625 if (IS_FWI2_CAPABLE(ha
))
626 qla24xx_process_response_queue(ha
);
628 qla2x00_process_response_queue(ha
);
631 case MBA_DISCARD_RND_FRAME
:
632 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
633 "%04x.\n", ha
->host_no
, mb
[1], mb
[2], mb
[3]));
636 case MBA_TRACE_NOTIFICATION
:
637 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
638 ha
->host_no
, mb
[1], mb
[2]));
642 if (!ha
->parent
&& ha
->num_vhosts
)
643 qla2x00_alert_all_vps(ha
, mb
);
647 qla2x00_adjust_sdev_qdepth_up(struct scsi_device
*sdev
, void *data
)
649 fc_port_t
*fcport
= data
;
651 if (fcport
->ha
->max_q_depth
<= sdev
->queue_depth
)
654 if (sdev
->ordered_tags
)
655 scsi_adjust_queue_depth(sdev
, MSG_ORDERED_TAG
,
656 sdev
->queue_depth
+ 1);
658 scsi_adjust_queue_depth(sdev
, MSG_SIMPLE_TAG
,
659 sdev
->queue_depth
+ 1);
661 fcport
->last_ramp_up
= jiffies
;
663 DEBUG2(qla_printk(KERN_INFO
, fcport
->ha
,
664 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
665 fcport
->ha
->host_no
, sdev
->channel
, sdev
->id
, sdev
->lun
,
670 qla2x00_adjust_sdev_qdepth_down(struct scsi_device
*sdev
, void *data
)
672 fc_port_t
*fcport
= data
;
674 if (!scsi_track_queue_full(sdev
, sdev
->queue_depth
- 1))
677 DEBUG2(qla_printk(KERN_INFO
, fcport
->ha
,
678 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
679 fcport
->ha
->host_no
, sdev
->channel
, sdev
->id
, sdev
->lun
,
684 qla2x00_ramp_up_queue_depth(scsi_qla_host_t
*ha
, srb_t
*sp
)
687 struct scsi_device
*sdev
;
689 sdev
= sp
->cmd
->device
;
690 if (sdev
->queue_depth
>= ha
->max_q_depth
)
694 if (time_before(jiffies
,
695 fcport
->last_ramp_up
+ ql2xqfullrampup
* HZ
))
697 if (time_before(jiffies
,
698 fcport
->last_queue_full
+ ql2xqfullrampup
* HZ
))
701 starget_for_each_device(sdev
->sdev_target
, fcport
,
702 qla2x00_adjust_sdev_qdepth_up
);
706 * qla2x00_process_completed_request() - Process a Fast Post response.
707 * @ha: SCSI driver HA context
711 qla2x00_process_completed_request(struct scsi_qla_host
*ha
, uint32_t index
)
715 /* Validate handle. */
716 if (index
>= MAX_OUTSTANDING_COMMANDS
) {
717 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
718 ha
->host_no
, index
));
719 qla_printk(KERN_WARNING
, ha
,
720 "Invalid SCSI completion handle %d.\n", index
);
722 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
726 sp
= ha
->outstanding_cmds
[index
];
728 /* Free outstanding command slot. */
729 ha
->outstanding_cmds
[index
] = NULL
;
731 CMD_COMPL_STATUS(sp
->cmd
) = 0L;
732 CMD_SCSI_STATUS(sp
->cmd
) = 0L;
734 /* Save ISP completion status */
735 sp
->cmd
->result
= DID_OK
<< 16;
737 qla2x00_ramp_up_queue_depth(ha
, sp
);
738 qla2x00_sp_compl(ha
, sp
);
740 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
742 qla_printk(KERN_WARNING
, ha
,
743 "Invalid ISP SCSI completion handle\n");
745 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
750 * qla2x00_process_response_queue() - Process response queue entries.
751 * @ha: SCSI driver HA context
754 qla2x00_process_response_queue(struct scsi_qla_host
*ha
)
756 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
761 if (!ha
->flags
.online
)
764 while (ha
->response_ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
765 pkt
= (sts_entry_t
*)ha
->response_ring_ptr
;
767 ha
->rsp_ring_index
++;
768 if (ha
->rsp_ring_index
== ha
->response_q_length
) {
769 ha
->rsp_ring_index
= 0;
770 ha
->response_ring_ptr
= ha
->response_ring
;
772 ha
->response_ring_ptr
++;
775 if (pkt
->entry_status
!= 0) {
776 DEBUG3(printk(KERN_INFO
777 "scsi(%ld): Process error entry.\n", ha
->host_no
));
779 qla2x00_error_entry(ha
, pkt
);
780 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
785 switch (pkt
->entry_type
) {
787 qla2x00_status_entry(ha
, pkt
);
790 handle_cnt
= ((sts21_entry_t
*)pkt
)->handle_count
;
791 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
792 qla2x00_process_completed_request(ha
,
793 ((sts21_entry_t
*)pkt
)->handle
[cnt
]);
797 handle_cnt
= ((sts22_entry_t
*)pkt
)->handle_count
;
798 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
799 qla2x00_process_completed_request(ha
,
800 ((sts22_entry_t
*)pkt
)->handle
[cnt
]);
803 case STATUS_CONT_TYPE
:
804 qla2x00_status_cont_entry(ha
, (sts_cont_entry_t
*)pkt
);
807 qla2x00_ms_entry(ha
, (ms_iocb_entry_t
*)pkt
);
810 /* Type Not Supported. */
811 DEBUG4(printk(KERN_WARNING
812 "scsi(%ld): Received unknown response pkt type %x "
813 "entry status=%x.\n",
814 ha
->host_no
, pkt
->entry_type
, pkt
->entry_status
));
817 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
821 /* Adjust ring index */
822 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), ha
->rsp_ring_index
);
826 qla2x00_handle_sense(srb_t
*sp
, uint8_t *sense_data
, uint32_t sense_len
)
828 struct scsi_cmnd
*cp
= sp
->cmd
;
830 if (sense_len
>= SCSI_SENSE_BUFFERSIZE
)
831 sense_len
= SCSI_SENSE_BUFFERSIZE
;
833 CMD_ACTUAL_SNSLEN(cp
) = sense_len
;
834 sp
->request_sense_length
= sense_len
;
835 sp
->request_sense_ptr
= cp
->sense_buffer
;
836 if (sp
->request_sense_length
> 32)
839 memcpy(cp
->sense_buffer
, sense_data
, sense_len
);
841 sp
->request_sense_ptr
+= sense_len
;
842 sp
->request_sense_length
-= sense_len
;
843 if (sp
->request_sense_length
!= 0)
844 sp
->ha
->status_srb
= sp
;
846 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
847 "cmd=%p pid=%ld\n", __func__
, sp
->ha
->host_no
, cp
->device
->channel
,
848 cp
->device
->id
, cp
->device
->lun
, cp
, cp
->serial_number
));
850 DEBUG5(qla2x00_dump_buffer(cp
->sense_buffer
,
851 CMD_ACTUAL_SNSLEN(cp
)));
855 * qla2x00_status_entry() - Process a Status IOCB entry.
856 * @ha: SCSI driver HA context
857 * @pkt: Entry pointer
860 qla2x00_status_entry(scsi_qla_host_t
*ha
, void *pkt
)
864 struct scsi_cmnd
*cp
;
866 struct sts_entry_24xx
*sts24
;
867 uint16_t comp_status
;
868 uint16_t scsi_status
;
869 uint8_t lscsi_status
;
871 uint32_t sense_len
, rsp_info_len
, resid_len
, fw_resid_len
;
872 uint8_t *rsp_info
, *sense_data
;
874 sts
= (sts_entry_t
*) pkt
;
875 sts24
= (struct sts_entry_24xx
*) pkt
;
876 if (IS_FWI2_CAPABLE(ha
)) {
877 comp_status
= le16_to_cpu(sts24
->comp_status
);
878 scsi_status
= le16_to_cpu(sts24
->scsi_status
) & SS_MASK
;
880 comp_status
= le16_to_cpu(sts
->comp_status
);
881 scsi_status
= le16_to_cpu(sts
->scsi_status
) & SS_MASK
;
884 /* Fast path completion. */
885 if (comp_status
== CS_COMPLETE
&& scsi_status
== 0) {
886 qla2x00_process_completed_request(ha
, sts
->handle
);
891 /* Validate handle. */
892 if (sts
->handle
< MAX_OUTSTANDING_COMMANDS
) {
893 sp
= ha
->outstanding_cmds
[sts
->handle
];
894 ha
->outstanding_cmds
[sts
->handle
] = NULL
;
899 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
901 qla_printk(KERN_WARNING
, ha
, "Status Entry invalid handle.\n");
903 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
904 qla2xxx_wake_dpc(ha
);
909 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
910 "pkt->handle=%d sp=%p.\n", ha
->host_no
, sts
->handle
, sp
));
911 qla_printk(KERN_WARNING
, ha
,
912 "Command is NULL: already returned to OS (sp=%p)\n", sp
);
917 lscsi_status
= scsi_status
& STATUS_MASK
;
918 CMD_ENTRY_STATUS(cp
) = sts
->entry_status
;
919 CMD_COMPL_STATUS(cp
) = comp_status
;
920 CMD_SCSI_STATUS(cp
) = scsi_status
;
924 sense_len
= rsp_info_len
= resid_len
= fw_resid_len
= 0;
925 if (IS_FWI2_CAPABLE(ha
)) {
926 sense_len
= le32_to_cpu(sts24
->sense_len
);
927 rsp_info_len
= le32_to_cpu(sts24
->rsp_data_len
);
928 resid_len
= le32_to_cpu(sts24
->rsp_residual_count
);
929 fw_resid_len
= le32_to_cpu(sts24
->residual_len
);
930 rsp_info
= sts24
->data
;
931 sense_data
= sts24
->data
;
932 host_to_fcp_swap(sts24
->data
, sizeof(sts24
->data
));
934 sense_len
= le16_to_cpu(sts
->req_sense_length
);
935 rsp_info_len
= le16_to_cpu(sts
->rsp_info_len
);
936 resid_len
= le32_to_cpu(sts
->residual_length
);
937 rsp_info
= sts
->rsp_info
;
938 sense_data
= sts
->req_sense_data
;
941 /* Check for any FCP transport errors. */
942 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
) {
943 /* Sense data lies beyond any FCP RESPONSE data. */
944 if (IS_FWI2_CAPABLE(ha
))
945 sense_data
+= rsp_info_len
;
946 if (rsp_info_len
> 3 && rsp_info
[3]) {
947 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
948 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
949 "retrying command\n", ha
->host_no
,
950 cp
->device
->channel
, cp
->device
->id
,
951 cp
->device
->lun
, rsp_info_len
, rsp_info
[0],
952 rsp_info
[1], rsp_info
[2], rsp_info
[3], rsp_info
[4],
953 rsp_info
[5], rsp_info
[6], rsp_info
[7]));
955 cp
->result
= DID_BUS_BUSY
<< 16;
956 qla2x00_sp_compl(ha
, sp
);
961 /* Check for overrun. */
962 if (IS_FWI2_CAPABLE(ha
) && comp_status
== CS_COMPLETE
&&
963 scsi_status
& SS_RESIDUAL_OVER
)
964 comp_status
= CS_DATA_OVERRUN
;
967 * Based on Host and scsi status generate status code for Linux
969 switch (comp_status
) {
972 if (scsi_status
== 0) {
973 cp
->result
= DID_OK
<< 16;
976 if (scsi_status
& (SS_RESIDUAL_UNDER
| SS_RESIDUAL_OVER
)) {
978 scsi_set_resid(cp
, resid
);
979 CMD_RESID_LEN(cp
) = resid
;
982 ((unsigned)(scsi_bufflen(cp
) - resid
) <
984 qla_printk(KERN_INFO
, ha
,
985 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
986 "detected (%x of %x bytes)...returning "
987 "error status.\n", ha
->host_no
,
988 cp
->device
->channel
, cp
->device
->id
,
989 cp
->device
->lun
, resid
,
992 cp
->result
= DID_ERROR
<< 16;
996 cp
->result
= DID_OK
<< 16 | lscsi_status
;
998 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
) {
999 DEBUG2(printk(KERN_INFO
1000 "scsi(%ld): QUEUE FULL status detected "
1001 "0x%x-0x%x.\n", ha
->host_no
, comp_status
,
1004 /* Adjust queue depth for all luns on the port. */
1005 fcport
->last_queue_full
= jiffies
;
1006 starget_for_each_device(cp
->device
->sdev_target
,
1007 fcport
, qla2x00_adjust_sdev_qdepth_down
);
1010 if (lscsi_status
!= SS_CHECK_CONDITION
)
1013 memset(cp
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
1014 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
1017 qla2x00_handle_sense(sp
, sense_data
, sense_len
);
1020 case CS_DATA_UNDERRUN
:
1022 /* Use F/W calculated residual length. */
1023 if (IS_FWI2_CAPABLE(ha
)) {
1024 if (scsi_status
& SS_RESIDUAL_UNDER
&&
1025 resid
!= fw_resid_len
) {
1026 scsi_status
&= ~SS_RESIDUAL_UNDER
;
1029 resid
= fw_resid_len
;
1032 if (scsi_status
& SS_RESIDUAL_UNDER
) {
1033 scsi_set_resid(cp
, resid
);
1034 CMD_RESID_LEN(cp
) = resid
;
1036 DEBUG2(printk(KERN_INFO
1037 "scsi(%ld:%d:%d) UNDERRUN status detected "
1038 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1039 "os_underflow=0x%x\n", ha
->host_no
,
1040 cp
->device
->id
, cp
->device
->lun
, comp_status
,
1041 scsi_status
, resid_len
, resid
, cp
->cmnd
[0],
1047 * Check to see if SCSI Status is non zero. If so report SCSI
1050 if (lscsi_status
!= 0) {
1051 cp
->result
= DID_OK
<< 16 | lscsi_status
;
1053 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
) {
1054 DEBUG2(printk(KERN_INFO
1055 "scsi(%ld): QUEUE FULL status detected "
1056 "0x%x-0x%x.\n", ha
->host_no
, comp_status
,
1060 * Adjust queue depth for all luns on the
1063 fcport
->last_queue_full
= jiffies
;
1064 starget_for_each_device(
1065 cp
->device
->sdev_target
, fcport
,
1066 qla2x00_adjust_sdev_qdepth_down
);
1069 if (lscsi_status
!= SS_CHECK_CONDITION
)
1072 memset(cp
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
1073 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
1076 qla2x00_handle_sense(sp
, sense_data
, sense_len
);
1079 * In case of a Underrun condition, set both the lscsi
1080 * status and the completion status to appropriate
1084 ((unsigned)(scsi_bufflen(cp
) - resid
) <
1086 DEBUG2(qla_printk(KERN_INFO
, ha
,
1087 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1088 "detected (%x of %x bytes)...returning "
1089 "error status.\n", ha
->host_no
,
1090 cp
->device
->channel
, cp
->device
->id
,
1091 cp
->device
->lun
, resid
,
1094 cp
->result
= DID_ERROR
<< 16 | lscsi_status
;
1098 * If RISC reports underrun and target does not report
1099 * it then we must have a lost frame, so tell upper
1100 * layer to retry it by reporting a bus busy.
1102 if (!(scsi_status
& SS_RESIDUAL_UNDER
)) {
1103 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1104 "frame(s) detected (%x of %x bytes)..."
1105 "retrying command.\n", ha
->host_no
,
1106 cp
->device
->channel
, cp
->device
->id
,
1107 cp
->device
->lun
, resid
,
1110 cp
->result
= DID_BUS_BUSY
<< 16;
1114 /* Handle mid-layer underflow */
1115 if ((unsigned)(scsi_bufflen(cp
) - resid
) <
1117 qla_printk(KERN_INFO
, ha
,
1118 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1119 "detected (%x of %x bytes)...returning "
1120 "error status.\n", ha
->host_no
,
1121 cp
->device
->channel
, cp
->device
->id
,
1122 cp
->device
->lun
, resid
,
1125 cp
->result
= DID_ERROR
<< 16;
1129 /* Everybody online, looking good... */
1130 cp
->result
= DID_OK
<< 16;
1134 case CS_DATA_OVERRUN
:
1135 DEBUG2(printk(KERN_INFO
1136 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1137 ha
->host_no
, cp
->device
->id
, cp
->device
->lun
, comp_status
,
1139 DEBUG2(printk(KERN_INFO
1140 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1141 cp
->cmnd
[0], cp
->cmnd
[1], cp
->cmnd
[2], cp
->cmnd
[3],
1142 cp
->cmnd
[4], cp
->cmnd
[5]));
1143 DEBUG2(printk(KERN_INFO
1144 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1146 cp
->serial_number
, scsi_bufflen(cp
), resid_len
));
1148 cp
->result
= DID_ERROR
<< 16;
1151 case CS_PORT_LOGGED_OUT
:
1152 case CS_PORT_CONFIG_CHG
:
1155 case CS_PORT_UNAVAILABLE
:
1157 * If the port is in Target Down state, return all IOs for this
1158 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1161 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1162 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1163 ha
->host_no
, cp
->device
->id
, cp
->device
->lun
,
1164 cp
->serial_number
, comp_status
,
1165 atomic_read(&fcport
->state
)));
1167 cp
->result
= DID_BUS_BUSY
<< 16;
1168 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
1169 qla2x00_mark_device_lost(ha
, fcport
, 1, 1);
1174 DEBUG2(printk(KERN_INFO
1175 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1176 ha
->host_no
, comp_status
, scsi_status
));
1178 cp
->result
= DID_RESET
<< 16;
1183 * hv2.19.12 - DID_ABORT does not retry the request if we
1184 * aborted this request then abort otherwise it must be a
1187 DEBUG2(printk(KERN_INFO
1188 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1189 ha
->host_no
, comp_status
, scsi_status
));
1191 cp
->result
= DID_RESET
<< 16;
1195 cp
->result
= DID_BUS_BUSY
<< 16;
1197 if (IS_FWI2_CAPABLE(ha
)) {
1198 DEBUG2(printk(KERN_INFO
1199 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1200 "0x%x-0x%x\n", ha
->host_no
, cp
->device
->channel
,
1201 cp
->device
->id
, cp
->device
->lun
, comp_status
,
1205 DEBUG2(printk(KERN_INFO
1206 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1207 "sflags=%x.\n", ha
->host_no
, cp
->device
->channel
,
1208 cp
->device
->id
, cp
->device
->lun
, comp_status
, scsi_status
,
1209 le16_to_cpu(sts
->status_flags
)));
1211 /* Check to see if logout occurred. */
1212 if ((le16_to_cpu(sts
->status_flags
) & SF_LOGOUT_SENT
))
1213 qla2x00_mark_device_lost(ha
, fcport
, 1, 1);
1217 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1218 "0x%x-0x%x.\n", ha
->host_no
, comp_status
, scsi_status
));
1219 qla_printk(KERN_INFO
, ha
,
1220 "Unknown status detected 0x%x-0x%x.\n",
1221 comp_status
, scsi_status
);
1223 cp
->result
= DID_ERROR
<< 16;
1227 /* Place command on done queue. */
1228 if (ha
->status_srb
== NULL
)
1229 qla2x00_sp_compl(ha
, sp
);
1233 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1234 * @ha: SCSI driver HA context
1235 * @pkt: Entry pointer
1237 * Extended sense data.
1240 qla2x00_status_cont_entry(scsi_qla_host_t
*ha
, sts_cont_entry_t
*pkt
)
1242 uint8_t sense_sz
= 0;
1243 srb_t
*sp
= ha
->status_srb
;
1244 struct scsi_cmnd
*cp
;
1246 if (sp
!= NULL
&& sp
->request_sense_length
!= 0) {
1249 DEBUG2(printk("%s(): Cmd already returned back to OS "
1250 "sp=%p.\n", __func__
, sp
));
1251 qla_printk(KERN_INFO
, ha
,
1252 "cmd is NULL: already returned to OS (sp=%p)\n",
1255 ha
->status_srb
= NULL
;
1259 if (sp
->request_sense_length
> sizeof(pkt
->data
)) {
1260 sense_sz
= sizeof(pkt
->data
);
1262 sense_sz
= sp
->request_sense_length
;
1265 /* Move sense data. */
1266 if (IS_FWI2_CAPABLE(ha
))
1267 host_to_fcp_swap(pkt
->data
, sizeof(pkt
->data
));
1268 memcpy(sp
->request_sense_ptr
, pkt
->data
, sense_sz
);
1269 DEBUG5(qla2x00_dump_buffer(sp
->request_sense_ptr
, sense_sz
));
1271 sp
->request_sense_ptr
+= sense_sz
;
1272 sp
->request_sense_length
-= sense_sz
;
1274 /* Place command on done queue. */
1275 if (sp
->request_sense_length
== 0) {
1276 ha
->status_srb
= NULL
;
1277 qla2x00_sp_compl(ha
, sp
);
1283 * qla2x00_error_entry() - Process an error entry.
1284 * @ha: SCSI driver HA context
1285 * @pkt: Entry pointer
1288 qla2x00_error_entry(scsi_qla_host_t
*ha
, sts_entry_t
*pkt
)
1292 #if defined(QL_DEBUG_LEVEL_2)
1293 if (pkt
->entry_status
& RF_INV_E_ORDER
)
1294 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Order\n", __func__
);
1295 else if (pkt
->entry_status
& RF_INV_E_COUNT
)
1296 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Count\n", __func__
);
1297 else if (pkt
->entry_status
& RF_INV_E_PARAM
)
1298 qla_printk(KERN_ERR
, ha
,
1299 "%s: Invalid Entry Parameter\n", __func__
);
1300 else if (pkt
->entry_status
& RF_INV_E_TYPE
)
1301 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Type\n", __func__
);
1302 else if (pkt
->entry_status
& RF_BUSY
)
1303 qla_printk(KERN_ERR
, ha
, "%s: Busy\n", __func__
);
1305 qla_printk(KERN_ERR
, ha
, "%s: UNKNOWN flag error\n", __func__
);
1308 /* Validate handle. */
1309 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
1310 sp
= ha
->outstanding_cmds
[pkt
->handle
];
1315 /* Free outstanding command slot. */
1316 ha
->outstanding_cmds
[pkt
->handle
] = NULL
;
1318 /* Bad payload or header */
1319 if (pkt
->entry_status
&
1320 (RF_INV_E_ORDER
| RF_INV_E_COUNT
|
1321 RF_INV_E_PARAM
| RF_INV_E_TYPE
)) {
1322 sp
->cmd
->result
= DID_ERROR
<< 16;
1323 } else if (pkt
->entry_status
& RF_BUSY
) {
1324 sp
->cmd
->result
= DID_BUS_BUSY
<< 16;
1326 sp
->cmd
->result
= DID_ERROR
<< 16;
1328 qla2x00_sp_compl(ha
, sp
);
1330 } else if (pkt
->entry_type
== COMMAND_A64_TYPE
|| pkt
->entry_type
==
1331 COMMAND_TYPE
|| pkt
->entry_type
== COMMAND_TYPE_7
) {
1332 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1334 qla_printk(KERN_WARNING
, ha
,
1335 "Error entry - invalid handle\n");
1337 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1338 qla2xxx_wake_dpc(ha
);
1343 * qla2x00_ms_entry() - Process a Management Server entry.
1344 * @ha: SCSI driver HA context
1345 * @index: Response queue out pointer
1348 qla2x00_ms_entry(scsi_qla_host_t
*ha
, ms_iocb_entry_t
*pkt
)
1352 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1353 __func__
, ha
->host_no
, pkt
, pkt
->handle1
));
1355 /* Validate handle. */
1356 if (pkt
->handle1
< MAX_OUTSTANDING_COMMANDS
)
1357 sp
= ha
->outstanding_cmds
[pkt
->handle1
];
1362 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1364 qla_printk(KERN_WARNING
, ha
, "MS entry - invalid handle\n");
1366 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1370 CMD_COMPL_STATUS(sp
->cmd
) = le16_to_cpu(pkt
->status
);
1371 CMD_ENTRY_STATUS(sp
->cmd
) = pkt
->entry_status
;
1373 /* Free outstanding command slot. */
1374 ha
->outstanding_cmds
[pkt
->handle1
] = NULL
;
1376 qla2x00_sp_compl(ha
, sp
);
1381 * qla24xx_mbx_completion() - Process mailbox command completions.
1382 * @ha: SCSI driver HA context
1383 * @mb0: Mailbox0 register
1386 qla24xx_mbx_completion(scsi_qla_host_t
*ha
, uint16_t mb0
)
1389 uint16_t __iomem
*wptr
;
1390 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1392 /* Load return mailbox registers. */
1393 ha
->flags
.mbox_int
= 1;
1394 ha
->mailbox_out
[0] = mb0
;
1395 wptr
= (uint16_t __iomem
*)®
->mailbox1
;
1397 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
1398 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
1403 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1404 __func__
, ha
->host_no
, ha
->mcp
->mb
[0]));
1406 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1407 __func__
, ha
->host_no
));
1412 * qla24xx_process_response_queue() - Process response queue entries.
1413 * @ha: SCSI driver HA context
1416 qla24xx_process_response_queue(struct scsi_qla_host
*ha
)
1418 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1419 struct sts_entry_24xx
*pkt
;
1421 if (!ha
->flags
.online
)
1424 while (ha
->response_ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
1425 pkt
= (struct sts_entry_24xx
*)ha
->response_ring_ptr
;
1427 ha
->rsp_ring_index
++;
1428 if (ha
->rsp_ring_index
== ha
->response_q_length
) {
1429 ha
->rsp_ring_index
= 0;
1430 ha
->response_ring_ptr
= ha
->response_ring
;
1432 ha
->response_ring_ptr
++;
1435 if (pkt
->entry_status
!= 0) {
1436 DEBUG3(printk(KERN_INFO
1437 "scsi(%ld): Process error entry.\n", ha
->host_no
));
1439 qla2x00_error_entry(ha
, (sts_entry_t
*) pkt
);
1440 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1445 switch (pkt
->entry_type
) {
1447 qla2x00_status_entry(ha
, pkt
);
1449 case STATUS_CONT_TYPE
:
1450 qla2x00_status_cont_entry(ha
, (sts_cont_entry_t
*)pkt
);
1453 qla24xx_ms_entry(ha
, (struct ct_entry_24xx
*)pkt
);
1455 case VP_RPT_ID_IOCB_TYPE
:
1456 qla24xx_report_id_acquisition(ha
,
1457 (struct vp_rpt_id_entry_24xx
*)pkt
);
1460 /* Type Not Supported. */
1461 DEBUG4(printk(KERN_WARNING
1462 "scsi(%ld): Received unknown response pkt type %x "
1463 "entry status=%x.\n",
1464 ha
->host_no
, pkt
->entry_type
, pkt
->entry_status
));
1467 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1471 /* Adjust ring index */
1472 WRT_REG_DWORD(®
->rsp_q_out
, ha
->rsp_ring_index
);
1476 qla2xxx_check_risc_status(scsi_qla_host_t
*ha
)
1480 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1482 if (!IS_QLA25XX(ha
))
1486 WRT_REG_DWORD(®
->iobase_addr
, 0x7C00);
1487 RD_REG_DWORD(®
->iobase_addr
);
1488 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
1489 for (cnt
= 10000; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
1490 rval
== QLA_SUCCESS
; cnt
--) {
1492 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
1495 rval
= QLA_FUNCTION_TIMEOUT
;
1497 if (rval
== QLA_SUCCESS
)
1500 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
1501 for (cnt
= 100; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
1502 rval
== QLA_SUCCESS
; cnt
--) {
1504 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
1507 rval
= QLA_FUNCTION_TIMEOUT
;
1509 if (rval
!= QLA_SUCCESS
)
1513 if (RD_REG_DWORD(®
->iobase_c8
) & BIT_3
)
1514 qla_printk(KERN_INFO
, ha
, "Additional code -- 0x55AA.\n");
1517 WRT_REG_DWORD(®
->iobase_window
, 0x0000);
1518 RD_REG_DWORD(®
->iobase_window
);
1522 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1524 * @dev_id: SCSI driver HA context
1526 * Called by system whenever the host adapter generates an interrupt.
1528 * Returns handled flag.
1531 qla24xx_intr_handler(int irq
, void *dev_id
)
1533 scsi_qla_host_t
*ha
;
1534 struct device_reg_24xx __iomem
*reg
;
1536 unsigned long flags
;
1542 ha
= (scsi_qla_host_t
*) dev_id
;
1545 "%s(): NULL host pointer\n", __func__
);
1549 reg
= &ha
->iobase
->isp24
;
1552 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1553 for (iter
= 50; iter
--; ) {
1554 stat
= RD_REG_DWORD(®
->host_status
);
1555 if (stat
& HSRX_RISC_PAUSED
) {
1556 if (pci_channel_offline(ha
->pdev
))
1559 hccr
= RD_REG_DWORD(®
->hccr
);
1561 qla_printk(KERN_INFO
, ha
, "RISC paused -- HCCR=%x, "
1562 "Dumping firmware!\n", hccr
);
1564 qla2xxx_check_risc_status(ha
);
1566 ha
->isp_ops
->fw_dump(ha
, 1);
1567 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1569 } else if ((stat
& HSRX_RISC_INT
) == 0)
1572 switch (stat
& 0xff) {
1577 qla24xx_mbx_completion(ha
, MSW(stat
));
1578 status
|= MBX_INTERRUPT
;
1583 mb
[1] = RD_REG_WORD(®
->mailbox1
);
1584 mb
[2] = RD_REG_WORD(®
->mailbox2
);
1585 mb
[3] = RD_REG_WORD(®
->mailbox3
);
1586 qla2x00_async_event(ha
, mb
);
1589 qla24xx_process_response_queue(ha
);
1592 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1594 ha
->host_no
, stat
& 0xff));
1597 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
1598 RD_REG_DWORD_RELAXED(®
->hccr
);
1600 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1602 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
1603 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
1604 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
1605 complete(&ha
->mbx_intr_comp
);
1612 * qla24xx_ms_entry() - Process a Management Server entry.
1613 * @ha: SCSI driver HA context
1614 * @index: Response queue out pointer
1617 qla24xx_ms_entry(scsi_qla_host_t
*ha
, struct ct_entry_24xx
*pkt
)
1621 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1622 __func__
, ha
->host_no
, pkt
, pkt
->handle
));
1624 DEBUG9(printk("%s: ct pkt dump:\n", __func__
));
1625 DEBUG9(qla2x00_dump_buffer((void *)pkt
, sizeof(struct ct_entry_24xx
)));
1627 /* Validate handle. */
1628 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
1629 sp
= ha
->outstanding_cmds
[pkt
->handle
];
1634 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1636 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1638 qla_printk(KERN_WARNING
, ha
, "MS entry - invalid handle %d\n",
1641 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1645 CMD_COMPL_STATUS(sp
->cmd
) = le16_to_cpu(pkt
->comp_status
);
1646 CMD_ENTRY_STATUS(sp
->cmd
) = pkt
->entry_status
;
1648 /* Free outstanding command slot. */
1649 ha
->outstanding_cmds
[pkt
->handle
] = NULL
;
1651 qla2x00_sp_compl(ha
, sp
);
1655 qla24xx_msix_rsp_q(int irq
, void *dev_id
)
1657 scsi_qla_host_t
*ha
;
1658 struct device_reg_24xx __iomem
*reg
;
1659 unsigned long flags
;
1662 reg
= &ha
->iobase
->isp24
;
1664 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1666 qla24xx_process_response_queue(ha
);
1668 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
1670 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1676 qla24xx_msix_default(int irq
, void *dev_id
)
1678 scsi_qla_host_t
*ha
;
1679 struct device_reg_24xx __iomem
*reg
;
1681 unsigned long flags
;
1687 reg
= &ha
->iobase
->isp24
;
1690 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1692 stat
= RD_REG_DWORD(®
->host_status
);
1693 if (stat
& HSRX_RISC_PAUSED
) {
1694 if (pci_channel_offline(ha
->pdev
))
1697 hccr
= RD_REG_DWORD(®
->hccr
);
1699 qla_printk(KERN_INFO
, ha
, "RISC paused -- HCCR=%x, "
1700 "Dumping firmware!\n", hccr
);
1702 qla2xxx_check_risc_status(ha
);
1704 ha
->isp_ops
->fw_dump(ha
, 1);
1705 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1707 } else if ((stat
& HSRX_RISC_INT
) == 0)
1710 switch (stat
& 0xff) {
1715 qla24xx_mbx_completion(ha
, MSW(stat
));
1716 status
|= MBX_INTERRUPT
;
1721 mb
[1] = RD_REG_WORD(®
->mailbox1
);
1722 mb
[2] = RD_REG_WORD(®
->mailbox2
);
1723 mb
[3] = RD_REG_WORD(®
->mailbox3
);
1724 qla2x00_async_event(ha
, mb
);
1727 qla24xx_process_response_queue(ha
);
1730 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1732 ha
->host_no
, stat
& 0xff));
1735 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
1737 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1739 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
1740 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
1741 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
1742 complete(&ha
->mbx_intr_comp
);
1748 /* Interrupt handling helpers. */
1750 struct qla_init_msix_entry
{
1754 irq_handler_t handler
;
1757 static struct qla_init_msix_entry imsix_entries
[QLA_MSIX_ENTRIES
] = {
1758 { QLA_MSIX_DEFAULT
, QLA_MIDX_DEFAULT
,
1759 "qla2xxx (default)", qla24xx_msix_default
},
1761 { QLA_MSIX_RSP_Q
, QLA_MIDX_RSP_Q
,
1762 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q
},
1766 qla24xx_disable_msix(scsi_qla_host_t
*ha
)
1769 struct qla_msix_entry
*qentry
;
1771 for (i
= 0; i
< QLA_MSIX_ENTRIES
; i
++) {
1772 qentry
= &ha
->msix_entries
[imsix_entries
[i
].index
];
1773 if (qentry
->have_irq
)
1774 free_irq(qentry
->msix_vector
, ha
);
1776 pci_disable_msix(ha
->pdev
);
1780 qla24xx_enable_msix(scsi_qla_host_t
*ha
)
1783 struct msix_entry entries
[QLA_MSIX_ENTRIES
];
1784 struct qla_msix_entry
*qentry
;
1786 for (i
= 0; i
< QLA_MSIX_ENTRIES
; i
++)
1787 entries
[i
].entry
= imsix_entries
[i
].entry
;
1789 ret
= pci_enable_msix(ha
->pdev
, entries
, ARRAY_SIZE(entries
));
1791 qla_printk(KERN_WARNING
, ha
,
1792 "MSI-X: Failed to enable support -- %d/%d\n",
1793 QLA_MSIX_ENTRIES
, ret
);
1796 ha
->flags
.msix_enabled
= 1;
1798 for (i
= 0; i
< QLA_MSIX_ENTRIES
; i
++) {
1799 qentry
= &ha
->msix_entries
[imsix_entries
[i
].index
];
1800 qentry
->msix_vector
= entries
[i
].vector
;
1801 qentry
->msix_entry
= entries
[i
].entry
;
1802 qentry
->have_irq
= 0;
1803 ret
= request_irq(qentry
->msix_vector
,
1804 imsix_entries
[i
].handler
, 0, imsix_entries
[i
].name
, ha
);
1806 qla_printk(KERN_WARNING
, ha
,
1807 "MSI-X: Unable to register handler -- %x/%d.\n",
1808 imsix_entries
[i
].index
, ret
);
1809 qla24xx_disable_msix(ha
);
1812 qentry
->have_irq
= 1;
1820 qla2x00_request_irqs(scsi_qla_host_t
*ha
)
1823 device_reg_t __iomem
*reg
= ha
->iobase
;
1824 unsigned long flags
;
1826 /* If possible, enable MSI-X. */
1827 if (!IS_QLA2432(ha
) && !IS_QLA2532(ha
))
1830 if (IS_QLA2432(ha
) && (ha
->chip_revision
< QLA_MSIX_CHIP_REV_24XX
||
1831 !QLA_MSIX_FW_MODE_1(ha
->fw_attributes
))) {
1832 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1833 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1834 ha
->chip_revision
, ha
->fw_attributes
));
1839 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_HP
&&
1840 (ha
->pdev
->subsystem_device
== 0x7040 ||
1841 ha
->pdev
->subsystem_device
== 0x7041 ||
1842 ha
->pdev
->subsystem_device
== 0x1705)) {
1843 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1844 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1845 ha
->pdev
->subsystem_vendor
,
1846 ha
->pdev
->subsystem_device
));
1851 ret
= qla24xx_enable_msix(ha
);
1853 DEBUG2(qla_printk(KERN_INFO
, ha
,
1854 "MSI-X: Enabled (0x%X, 0x%X).\n", ha
->chip_revision
,
1855 ha
->fw_attributes
));
1856 goto clear_risc_ints
;
1858 qla_printk(KERN_WARNING
, ha
,
1859 "MSI-X: Falling back-to INTa mode -- %d.\n", ret
);
1862 if (!IS_QLA24XX(ha
) && !IS_QLA2532(ha
))
1865 ret
= pci_enable_msi(ha
->pdev
);
1867 DEBUG2(qla_printk(KERN_INFO
, ha
, "MSI: Enabled.\n"));
1868 ha
->flags
.msi_enabled
= 1;
1872 ret
= request_irq(ha
->pdev
->irq
, ha
->isp_ops
->intr_handler
,
1873 IRQF_DISABLED
|IRQF_SHARED
, QLA2XXX_DRIVER_NAME
, ha
);
1875 qla_printk(KERN_WARNING
, ha
,
1876 "Failed to reserve interrupt %d already in use.\n",
1880 ha
->flags
.inta_enabled
= 1;
1881 ha
->host
->irq
= ha
->pdev
->irq
;
1884 ha
->isp_ops
->disable_intrs(ha
);
1885 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1886 if (IS_FWI2_CAPABLE(ha
)) {
1887 WRT_REG_DWORD(®
->isp24
.hccr
, HCCRX_CLR_HOST_INT
);
1888 WRT_REG_DWORD(®
->isp24
.hccr
, HCCRX_CLR_RISC_INT
);
1890 WRT_REG_WORD(®
->isp
.semaphore
, 0);
1891 WRT_REG_WORD(®
->isp
.hccr
, HCCR_CLR_RISC_INT
);
1892 WRT_REG_WORD(®
->isp
.hccr
, HCCR_CLR_HOST_INT
);
1894 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1895 ha
->isp_ops
->enable_intrs(ha
);
1902 qla2x00_free_irqs(scsi_qla_host_t
*ha
)
1905 if (ha
->flags
.msix_enabled
)
1906 qla24xx_disable_msix(ha
);
1907 else if (ha
->flags
.inta_enabled
) {
1908 free_irq(ha
->host
->irq
, ha
);
1909 pci_disable_msi(ha
->pdev
);