2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/slab.h>
11 #include <scsi/scsi_tcq.h>
12 #include <scsi/scsi_bsg_fc.h>
14 static void qla2x00_mbx_completion(scsi_qla_host_t
*, uint16_t);
15 static void qla2x00_process_completed_request(struct scsi_qla_host
*,
16 struct req_que
*, uint32_t);
17 static void qla2x00_status_entry(scsi_qla_host_t
*, struct rsp_que
*, void *);
18 static void qla2x00_status_cont_entry(struct rsp_que
*, sts_cont_entry_t
*);
19 static void qla2x00_error_entry(scsi_qla_host_t
*, struct rsp_que
*,
23 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
25 * @dev_id: SCSI driver HA context
27 * Called by system whenever the host adapter generates an interrupt.
29 * Returns handled flag.
32 qla2100_intr_handler(int irq
, void *dev_id
)
35 struct qla_hw_data
*ha
;
36 struct device_reg_2xxx __iomem
*reg
;
44 rsp
= (struct rsp_que
*) dev_id
;
47 "%s(): NULL response queue pointer\n", __func__
);
52 reg
= &ha
->iobase
->isp
;
55 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
56 vha
= pci_get_drvdata(ha
->pdev
);
57 for (iter
= 50; iter
--; ) {
58 hccr
= RD_REG_WORD(®
->hccr
);
59 if (hccr
& HCCR_RISC_PAUSE
) {
60 if (pci_channel_offline(ha
->pdev
))
64 * Issue a "HARD" reset in order for the RISC interrupt
65 * bit to be cleared. Schedule a big hammmer to get
66 * out of the RISC PAUSED state.
68 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
69 RD_REG_WORD(®
->hccr
);
71 ha
->isp_ops
->fw_dump(vha
, 1);
72 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
74 } else if ((RD_REG_WORD(®
->istatus
) & ISR_RISC_INT
) == 0)
77 if (RD_REG_WORD(®
->semaphore
) & BIT_0
) {
78 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
79 RD_REG_WORD(®
->hccr
);
81 /* Get mailbox data. */
82 mb
[0] = RD_MAILBOX_REG(ha
, reg
, 0);
83 if (mb
[0] > 0x3fff && mb
[0] < 0x8000) {
84 qla2x00_mbx_completion(vha
, mb
[0]);
85 status
|= MBX_INTERRUPT
;
86 } else if (mb
[0] > 0x7fff && mb
[0] < 0xc000) {
87 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
88 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
89 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
90 qla2x00_async_event(vha
, rsp
, mb
);
93 DEBUG2(printk("scsi(%ld): Unrecognized "
94 "interrupt type (%d).\n",
95 vha
->host_no
, mb
[0]));
97 /* Release mailbox registers. */
98 WRT_REG_WORD(®
->semaphore
, 0);
99 RD_REG_WORD(®
->semaphore
);
101 qla2x00_process_response_queue(rsp
);
103 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
104 RD_REG_WORD(®
->hccr
);
107 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
109 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
110 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
111 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
112 complete(&ha
->mbx_intr_comp
);
115 return (IRQ_HANDLED
);
119 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
121 * @dev_id: SCSI driver HA context
123 * Called by system whenever the host adapter generates an interrupt.
125 * Returns handled flag.
128 qla2300_intr_handler(int irq
, void *dev_id
)
130 scsi_qla_host_t
*vha
;
131 struct device_reg_2xxx __iomem
*reg
;
138 struct qla_hw_data
*ha
;
141 rsp
= (struct rsp_que
*) dev_id
;
144 "%s(): NULL response queue pointer\n", __func__
);
149 reg
= &ha
->iobase
->isp
;
152 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
153 vha
= pci_get_drvdata(ha
->pdev
);
154 for (iter
= 50; iter
--; ) {
155 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
156 if (stat
& HSR_RISC_PAUSED
) {
157 if (unlikely(pci_channel_offline(ha
->pdev
)))
160 hccr
= RD_REG_WORD(®
->hccr
);
161 if (hccr
& (BIT_15
| BIT_13
| BIT_11
| BIT_8
))
162 qla_printk(KERN_INFO
, ha
, "Parity error -- "
163 "HCCR=%x, Dumping firmware!\n", hccr
);
165 qla_printk(KERN_INFO
, ha
, "RISC paused -- "
166 "HCCR=%x, Dumping firmware!\n", hccr
);
169 * Issue a "HARD" reset in order for the RISC
170 * interrupt bit to be cleared. Schedule a big
171 * hammmer to get out of the RISC PAUSED state.
173 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
174 RD_REG_WORD(®
->hccr
);
176 ha
->isp_ops
->fw_dump(vha
, 1);
177 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
179 } else if ((stat
& HSR_RISC_INT
) == 0)
182 switch (stat
& 0xff) {
187 qla2x00_mbx_completion(vha
, MSW(stat
));
188 status
|= MBX_INTERRUPT
;
190 /* Release mailbox registers. */
191 WRT_REG_WORD(®
->semaphore
, 0);
195 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
196 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
197 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
198 qla2x00_async_event(vha
, rsp
, mb
);
201 qla2x00_process_response_queue(rsp
);
204 mb
[0] = MBA_CMPLT_1_16BIT
;
206 qla2x00_async_event(vha
, rsp
, mb
);
209 mb
[0] = MBA_SCSI_COMPLETION
;
211 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
212 qla2x00_async_event(vha
, rsp
, mb
);
215 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
217 vha
->host_no
, stat
& 0xff));
220 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
221 RD_REG_WORD_RELAXED(®
->hccr
);
223 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
225 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
226 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
227 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
228 complete(&ha
->mbx_intr_comp
);
231 return (IRQ_HANDLED
);
235 * qla2x00_mbx_completion() - Process mailbox command completions.
236 * @ha: SCSI driver HA context
237 * @mb0: Mailbox0 register
240 qla2x00_mbx_completion(scsi_qla_host_t
*vha
, uint16_t mb0
)
243 uint16_t __iomem
*wptr
;
244 struct qla_hw_data
*ha
= vha
->hw
;
245 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
247 /* Load return mailbox registers. */
248 ha
->flags
.mbox_int
= 1;
249 ha
->mailbox_out
[0] = mb0
;
250 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 1);
252 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
253 if (IS_QLA2200(ha
) && cnt
== 8)
254 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 8);
255 if (cnt
== 4 || cnt
== 5)
256 ha
->mailbox_out
[cnt
] = qla2x00_debounce_register(wptr
);
258 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
264 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
265 __func__
, vha
->host_no
, ha
->mcp
->mb
[0]));
267 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
268 __func__
, vha
->host_no
));
273 qla81xx_idc_event(scsi_qla_host_t
*vha
, uint16_t aen
, uint16_t descr
)
275 static char *event
[] =
276 { "Complete", "Request Notification", "Time Extension" };
278 struct device_reg_24xx __iomem
*reg24
= &vha
->hw
->iobase
->isp24
;
279 uint16_t __iomem
*wptr
;
280 uint16_t cnt
, timeout
, mb
[QLA_IDC_ACK_REGS
];
282 /* Seed data -- mailbox1 -> mailbox7. */
283 wptr
= (uint16_t __iomem
*)®24
->mailbox1
;
284 for (cnt
= 0; cnt
< QLA_IDC_ACK_REGS
; cnt
++, wptr
++)
285 mb
[cnt
] = RD_REG_WORD(wptr
);
287 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
288 "%04x %04x %04x %04x %04x %04x %04x.\n", vha
->host_no
,
290 mb
[0], mb
[1], mb
[2], mb
[3], mb
[4], mb
[5], mb
[6]));
292 /* Acknowledgement needed? [Notify && non-zero timeout]. */
293 timeout
= (descr
>> 8) & 0xf;
294 if (aen
!= MBA_IDC_NOTIFY
|| !timeout
)
297 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
298 "ACK timeout=%d.\n", vha
->host_no
, event
[aen
& 0xff], timeout
));
300 rval
= qla2x00_post_idc_ack_work(vha
, mb
);
301 if (rval
!= QLA_SUCCESS
)
302 qla_printk(KERN_WARNING
, vha
->hw
,
303 "IDC failed to post ACK.\n");
307 * qla2x00_async_event() - Process aynchronous events.
308 * @ha: SCSI driver HA context
309 * @mb: Mailbox registers (0 - 3)
312 qla2x00_async_event(scsi_qla_host_t
*vha
, struct rsp_que
*rsp
, uint16_t *mb
)
315 static char *link_speeds
[] = { "1", "2", "?", "4", "8", "10" };
320 struct qla_hw_data
*ha
= vha
->hw
;
321 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
322 struct device_reg_24xx __iomem
*reg24
= &ha
->iobase
->isp24
;
323 uint32_t rscn_entry
, host_pid
;
324 uint8_t rscn_queue_index
;
327 /* Setup to process RIO completion. */
332 case MBA_SCSI_COMPLETION
:
333 handles
[0] = le32_to_cpu((uint32_t)((mb
[2] << 16) | mb
[1]));
336 case MBA_CMPLT_1_16BIT
:
339 mb
[0] = MBA_SCSI_COMPLETION
;
341 case MBA_CMPLT_2_16BIT
:
345 mb
[0] = MBA_SCSI_COMPLETION
;
347 case MBA_CMPLT_3_16BIT
:
352 mb
[0] = MBA_SCSI_COMPLETION
;
354 case MBA_CMPLT_4_16BIT
:
358 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
360 mb
[0] = MBA_SCSI_COMPLETION
;
362 case MBA_CMPLT_5_16BIT
:
366 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
367 handles
[4] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 7);
369 mb
[0] = MBA_SCSI_COMPLETION
;
371 case MBA_CMPLT_2_32BIT
:
372 handles
[0] = le32_to_cpu((uint32_t)((mb
[2] << 16) | mb
[1]));
373 handles
[1] = le32_to_cpu(
374 ((uint32_t)(RD_MAILBOX_REG(ha
, reg
, 7) << 16)) |
375 RD_MAILBOX_REG(ha
, reg
, 6));
377 mb
[0] = MBA_SCSI_COMPLETION
;
384 case MBA_SCSI_COMPLETION
: /* Fast Post */
385 if (!vha
->flags
.online
)
388 for (cnt
= 0; cnt
< handle_cnt
; cnt
++)
389 qla2x00_process_completed_request(vha
, rsp
->req
,
393 case MBA_RESET
: /* Reset */
394 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
397 set_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
400 case MBA_SYSTEM_ERR
: /* System Error */
401 mbx
= IS_QLA81XX(ha
) ? RD_REG_WORD(®24
->mailbox7
) : 0;
402 qla_printk(KERN_INFO
, ha
,
403 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
404 "mbx7=%xh.\n", mb
[1], mb
[2], mb
[3], mbx
);
406 ha
->isp_ops
->fw_dump(vha
, 1);
408 if (IS_FWI2_CAPABLE(ha
)) {
409 if (mb
[1] == 0 && mb
[2] == 0) {
410 qla_printk(KERN_ERR
, ha
,
411 "Unrecoverable Hardware Error: adapter "
412 "marked OFFLINE!\n");
413 vha
->flags
.online
= 0;
415 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
416 } else if (mb
[1] == 0) {
417 qla_printk(KERN_INFO
, ha
,
418 "Unrecoverable Hardware Error: adapter marked "
420 vha
->flags
.online
= 0;
422 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
425 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
426 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error (%x).\n",
427 vha
->host_no
, mb
[1]));
428 qla_printk(KERN_WARNING
, ha
,
429 "ISP Request Transfer Error (%x).\n", mb
[1]);
431 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
434 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
435 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
437 qla_printk(KERN_WARNING
, ha
, "ISP Response Transfer Error.\n");
439 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
442 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
443 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
447 case MBA_LIP_OCCURRED
: /* Loop Initialization Procedure */
448 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha
->host_no
,
450 qla_printk(KERN_INFO
, ha
, "LIP occurred (%x).\n", mb
[1]);
452 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
453 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
454 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
455 qla2x00_mark_all_devices_lost(vha
, 1);
459 atomic_set(&vha
->vp_state
, VP_FAILED
);
460 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
463 set_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
);
464 set_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
);
466 vha
->flags
.management_server_logged_in
= 0;
467 qla2x00_post_aen_work(vha
, FCH_EVT_LIP
, mb
[1]);
470 case MBA_LOOP_UP
: /* Loop Up Event */
471 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
472 link_speed
= link_speeds
[0];
473 ha
->link_data_rate
= PORT_SPEED_1GB
;
475 link_speed
= link_speeds
[LS_UNKNOWN
];
477 link_speed
= link_speeds
[mb
[1]];
478 else if (mb
[1] == 0x13)
479 link_speed
= link_speeds
[5];
480 ha
->link_data_rate
= mb
[1];
483 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
484 vha
->host_no
, link_speed
));
485 qla_printk(KERN_INFO
, ha
, "LOOP UP detected (%s Gbps).\n",
488 vha
->flags
.management_server_logged_in
= 0;
489 qla2x00_post_aen_work(vha
, FCH_EVT_LINKUP
, ha
->link_data_rate
);
492 case MBA_LOOP_DOWN
: /* Loop Down Event */
493 mbx
= IS_QLA81XX(ha
) ? RD_REG_WORD(®24
->mailbox4
) : 0;
494 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
495 "(%x %x %x %x).\n", vha
->host_no
, mb
[1], mb
[2], mb
[3],
497 qla_printk(KERN_INFO
, ha
,
498 "LOOP DOWN detected (%x %x %x %x).\n", mb
[1], mb
[2], mb
[3],
501 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
502 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
503 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
504 vha
->device_flags
|= DFLG_NO_CABLE
;
505 qla2x00_mark_all_devices_lost(vha
, 1);
509 atomic_set(&vha
->vp_state
, VP_FAILED
);
510 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
513 vha
->flags
.management_server_logged_in
= 0;
514 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
515 qla2x00_post_aen_work(vha
, FCH_EVT_LINKDOWN
, 0);
518 case MBA_LIP_RESET
: /* LIP reset occurred */
519 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
520 vha
->host_no
, mb
[1]));
521 qla_printk(KERN_INFO
, ha
,
522 "LIP reset occurred (%x).\n", mb
[1]);
524 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
525 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
526 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
527 qla2x00_mark_all_devices_lost(vha
, 1);
531 atomic_set(&vha
->vp_state
, VP_FAILED
);
532 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
535 set_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
537 ha
->operating_mode
= LOOP
;
538 vha
->flags
.management_server_logged_in
= 0;
539 qla2x00_post_aen_work(vha
, FCH_EVT_LIPRESET
, mb
[1]);
542 /* case MBA_DCBX_COMPLETE: */
543 case MBA_POINT_TO_POINT
: /* Point-to-Point */
548 DEBUG2(printk("scsi(%ld): DCBX Completed -- %04x %04x "
549 "%04x\n", vha
->host_no
, mb
[1], mb
[2], mb
[3]));
551 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE "
552 "received.\n", vha
->host_no
));
555 * Until there's a transition from loop down to loop up, treat
556 * this as loop down only.
558 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
559 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
560 if (!atomic_read(&vha
->loop_down_timer
))
561 atomic_set(&vha
->loop_down_timer
,
563 qla2x00_mark_all_devices_lost(vha
, 1);
567 atomic_set(&vha
->vp_state
, VP_FAILED
);
568 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
571 if (!(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)))
572 set_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
574 set_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
);
575 set_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
);
577 ha
->flags
.gpsc_supported
= 1;
578 vha
->flags
.management_server_logged_in
= 0;
581 case MBA_CHG_IN_CONNECTION
: /* Change in connection mode */
585 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
588 qla_printk(KERN_INFO
, ha
,
589 "Configuration change detected: value=%x.\n", mb
[1]);
591 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
592 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
593 if (!atomic_read(&vha
->loop_down_timer
))
594 atomic_set(&vha
->loop_down_timer
,
596 qla2x00_mark_all_devices_lost(vha
, 1);
600 atomic_set(&vha
->vp_state
, VP_FAILED
);
601 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
604 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
605 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
608 case MBA_PORT_UPDATE
: /* Port database update */
610 * Handle only global and vn-port update events
613 * mb[1] = N_Port handle of changed port
614 * OR 0xffff for global event
615 * mb[2] = New login state
616 * 7 = Port logged out
617 * mb[3] = LSB is vp_idx, 0xff = all vps
619 * Skip processing if:
620 * Event is global, vp_idx is NOT all vps,
621 * vp_idx does not match
622 * Event is not global, vp_idx does not match
624 if (IS_QLA2XXX_MIDTYPE(ha
) &&
625 ((mb
[1] == 0xffff && (mb
[3] & 0xff) != 0xff) ||
626 (mb
[1] != 0xffff)) && vha
->vp_idx
!= (mb
[3] & 0xff))
629 /* Global event -- port logout or port unavailable. */
630 if (mb
[1] == 0xffff && mb
[2] == 0x7) {
631 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
633 DEBUG(printk(KERN_INFO
634 "scsi(%ld): Port unavailable %04x %04x %04x.\n",
635 vha
->host_no
, mb
[1], mb
[2], mb
[3]));
637 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
638 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
639 atomic_set(&vha
->loop_down_timer
,
641 vha
->device_flags
|= DFLG_NO_CABLE
;
642 qla2x00_mark_all_devices_lost(vha
, 1);
646 atomic_set(&vha
->vp_state
, VP_FAILED
);
647 fc_vport_set_state(vha
->fc_vport
,
649 qla2x00_mark_all_devices_lost(vha
, 1);
652 vha
->flags
.management_server_logged_in
= 0;
653 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
658 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
659 * event etc. earlier indicating loop is down) then process
660 * it. Otherwise ignore it and Wait for RSCN to come in.
662 atomic_set(&vha
->loop_down_timer
, 0);
663 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
&&
664 atomic_read(&vha
->loop_state
) != LOOP_DEAD
) {
665 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
666 "ignored %04x/%04x/%04x.\n", vha
->host_no
, mb
[1],
671 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
673 DEBUG(printk(KERN_INFO
674 "scsi(%ld): Port database changed %04x %04x %04x.\n",
675 vha
->host_no
, mb
[1], mb
[2], mb
[3]));
678 * Mark all devices as missing so we will login again.
680 atomic_set(&vha
->loop_state
, LOOP_UP
);
682 qla2x00_mark_all_devices_lost(vha
, 1);
684 vha
->flags
.rscn_queue_overflow
= 1;
686 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
687 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
690 case MBA_RSCN_UPDATE
: /* State Change Registration */
691 /* Check if the Vport has issued a SCR */
692 if (vha
->vp_idx
&& test_bit(VP_SCR_NEEDED
, &vha
->vp_flags
))
694 /* Only handle SCNs for our Vport index. */
695 if (ha
->flags
.npiv_supported
&& vha
->vp_idx
!= (mb
[3] & 0xff))
698 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
700 DEBUG(printk(KERN_INFO
701 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
702 vha
->host_no
, mb
[1], mb
[2], mb
[3]));
704 rscn_entry
= ((mb
[1] & 0xff) << 16) | mb
[2];
705 host_pid
= (vha
->d_id
.b
.domain
<< 16) | (vha
->d_id
.b
.area
<< 8)
707 if (rscn_entry
== host_pid
) {
708 DEBUG(printk(KERN_INFO
709 "scsi(%ld): Ignoring RSCN update to local host "
711 vha
->host_no
, host_pid
));
715 /* Ignore reserved bits from RSCN-payload. */
716 rscn_entry
= ((mb
[1] & 0x3ff) << 16) | mb
[2];
717 rscn_queue_index
= vha
->rscn_in_ptr
+ 1;
718 if (rscn_queue_index
== MAX_RSCN_COUNT
)
719 rscn_queue_index
= 0;
720 if (rscn_queue_index
!= vha
->rscn_out_ptr
) {
721 vha
->rscn_queue
[vha
->rscn_in_ptr
] = rscn_entry
;
722 vha
->rscn_in_ptr
= rscn_queue_index
;
724 vha
->flags
.rscn_queue_overflow
= 1;
727 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
728 atomic_set(&vha
->loop_down_timer
, 0);
729 vha
->flags
.management_server_logged_in
= 0;
731 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
732 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
733 qla2x00_post_aen_work(vha
, FCH_EVT_RSCN
, rscn_entry
);
736 /* case MBA_RIO_RESPONSE: */
737 case MBA_ZIO_RESPONSE
:
738 DEBUG3(printk("scsi(%ld): [R|Z]IO update completion.\n",
741 if (IS_FWI2_CAPABLE(ha
))
742 qla24xx_process_response_queue(vha
, rsp
);
744 qla2x00_process_response_queue(rsp
);
747 case MBA_DISCARD_RND_FRAME
:
748 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
749 "%04x.\n", vha
->host_no
, mb
[1], mb
[2], mb
[3]));
752 case MBA_TRACE_NOTIFICATION
:
753 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
754 vha
->host_no
, mb
[1], mb
[2]));
757 case MBA_ISP84XX_ALERT
:
758 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
759 "%04x %04x %04x\n", vha
->host_no
, mb
[1], mb
[2], mb
[3]));
761 spin_lock_irqsave(&ha
->cs84xx
->access_lock
, flags
);
763 case A84_PANIC_RECOVERY
:
764 qla_printk(KERN_INFO
, ha
, "Alert 84XX: panic recovery "
765 "%04x %04x\n", mb
[2], mb
[3]);
767 case A84_OP_LOGIN_COMPLETE
:
768 ha
->cs84xx
->op_fw_version
= mb
[3] << 16 | mb
[2];
769 DEBUG2(qla_printk(KERN_INFO
, ha
, "Alert 84XX:"
770 "firmware version %x\n", ha
->cs84xx
->op_fw_version
));
772 case A84_DIAG_LOGIN_COMPLETE
:
773 ha
->cs84xx
->diag_fw_version
= mb
[3] << 16 | mb
[2];
774 DEBUG2(qla_printk(KERN_INFO
, ha
, "Alert 84XX:"
775 "diagnostic firmware version %x\n",
776 ha
->cs84xx
->diag_fw_version
));
778 case A84_GOLD_LOGIN_COMPLETE
:
779 ha
->cs84xx
->diag_fw_version
= mb
[3] << 16 | mb
[2];
780 ha
->cs84xx
->fw_update
= 1;
781 DEBUG2(qla_printk(KERN_INFO
, ha
, "Alert 84XX: gold "
782 "firmware version %x\n",
783 ha
->cs84xx
->gold_fw_version
));
786 qla_printk(KERN_ERR
, ha
,
787 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
788 mb
[1], mb
[2], mb
[3]);
790 spin_unlock_irqrestore(&ha
->cs84xx
->access_lock
, flags
);
793 DEBUG2(printk("scsi(%ld): DCBX Started -- %04x %04x %04x\n",
794 vha
->host_no
, mb
[1], mb
[2], mb
[3]));
796 case MBA_DCBX_PARAM_UPDATE
:
797 DEBUG2(printk("scsi(%ld): DCBX Parameters Updated -- "
798 "%04x %04x %04x\n", vha
->host_no
, mb
[1], mb
[2], mb
[3]));
800 case MBA_FCF_CONF_ERR
:
801 DEBUG2(printk("scsi(%ld): FCF Configuration Error -- "
802 "%04x %04x %04x\n", vha
->host_no
, mb
[1], mb
[2], mb
[3]));
804 case MBA_IDC_COMPLETE
:
806 case MBA_IDC_TIME_EXT
:
807 qla81xx_idc_event(vha
, mb
[0], mb
[1]);
811 if (!vha
->vp_idx
&& ha
->num_vhosts
)
812 qla2x00_alert_all_vps(rsp
, mb
);
816 * qla2x00_process_completed_request() - Process a Fast Post response.
817 * @ha: SCSI driver HA context
821 qla2x00_process_completed_request(struct scsi_qla_host
*vha
,
822 struct req_que
*req
, uint32_t index
)
825 struct qla_hw_data
*ha
= vha
->hw
;
827 /* Validate handle. */
828 if (index
>= MAX_OUTSTANDING_COMMANDS
) {
829 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
830 vha
->host_no
, index
));
831 qla_printk(KERN_WARNING
, ha
,
832 "Invalid SCSI completion handle %d.\n", index
);
834 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
838 sp
= req
->outstanding_cmds
[index
];
840 /* Free outstanding command slot. */
841 req
->outstanding_cmds
[index
] = NULL
;
843 /* Save ISP completion status */
844 sp
->cmd
->result
= DID_OK
<< 16;
845 qla2x00_sp_compl(ha
, sp
);
847 DEBUG2(printk("scsi(%ld) Req:%d: Invalid ISP SCSI completion"
848 " handle(%d)\n", vha
->host_no
, req
->id
, index
));
849 qla_printk(KERN_WARNING
, ha
,
850 "Invalid ISP SCSI completion handle\n");
852 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
857 qla2x00_get_sp_from_handle(scsi_qla_host_t
*vha
, const char *func
,
858 struct req_que
*req
, void *iocb
)
860 struct qla_hw_data
*ha
= vha
->hw
;
861 sts_entry_t
*pkt
= iocb
;
865 index
= LSW(pkt
->handle
);
866 if (index
>= MAX_OUTSTANDING_COMMANDS
) {
867 qla_printk(KERN_WARNING
, ha
,
868 "%s: Invalid completion handle (%x).\n", func
, index
);
869 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
872 sp
= req
->outstanding_cmds
[index
];
874 qla_printk(KERN_WARNING
, ha
,
875 "%s: Invalid completion handle (%x) -- timed-out.\n", func
,
879 if (sp
->handle
!= index
) {
880 qla_printk(KERN_WARNING
, ha
,
881 "%s: SRB handle (%x) mismatch %x.\n", func
, sp
->handle
,
886 req
->outstanding_cmds
[index
] = NULL
;
893 qla2x00_mbx_iocb_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
894 struct mbx_entry
*mbx
)
896 const char func
[] = "MBX-IOCB";
898 struct qla_hw_data
*ha
= vha
->hw
;
901 struct srb_logio
*lio
;
904 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, mbx
);
910 switch (lio
->ctx
.type
) {
918 qla_printk(KERN_WARNING
, ha
,
919 "%s: Unrecognized SRB: (%p) type=%d.\n", func
, sp
,
924 del_timer(&lio
->ctx
.timer
);
927 data
[0] = data
[1] = 0;
928 if (mbx
->entry_status
) {
929 DEBUG2(printk(KERN_WARNING
930 "scsi(%ld:%x): Async-%s error entry - entry-status=%x "
931 "status=%x state-flag=%x status-flags=%x.\n",
932 fcport
->vha
->host_no
, sp
->handle
, type
,
933 mbx
->entry_status
, le16_to_cpu(mbx
->status
),
934 le16_to_cpu(mbx
->state_flags
),
935 le16_to_cpu(mbx
->status_flags
)));
936 DEBUG2(qla2x00_dump_buffer((uint8_t *)mbx
, sizeof(*mbx
)));
938 data
[0] = MBS_COMMAND_ERROR
;
939 data
[1] = lio
->flags
& SRB_LOGIN_RETRIED
?
940 QLA_LOGIO_LOGIN_RETRIED
: 0;
941 goto done_post_logio_done_work
;
944 if (!mbx
->status
&& le16_to_cpu(mbx
->mb0
) == MBS_COMMAND_COMPLETE
) {
945 DEBUG2(printk(KERN_DEBUG
946 "scsi(%ld:%x): Async-%s complete - mbx1=%x.\n",
947 fcport
->vha
->host_no
, sp
->handle
, type
,
948 le16_to_cpu(mbx
->mb1
)));
950 data
[0] = MBS_COMMAND_COMPLETE
;
951 if (lio
->ctx
.type
== SRB_LOGIN_CMD
&& le16_to_cpu(mbx
->mb1
) & BIT_1
)
952 fcport
->flags
|= FCF_FCP2_DEVICE
;
954 goto done_post_logio_done_work
;
957 data
[0] = le16_to_cpu(mbx
->mb0
);
959 case MBS_PORT_ID_USED
:
960 data
[1] = le16_to_cpu(mbx
->mb1
);
962 case MBS_LOOP_ID_USED
:
965 data
[0] = MBS_COMMAND_ERROR
;
966 data
[1] = lio
->flags
& SRB_LOGIN_RETRIED
?
967 QLA_LOGIO_LOGIN_RETRIED
: 0;
971 DEBUG2(printk(KERN_WARNING
972 "scsi(%ld:%x): Async-%s failed - status=%x mb0=%x mb1=%x mb2=%x "
974 fcport
->vha
->host_no
, sp
->handle
, type
, le16_to_cpu(mbx
->status
),
975 le16_to_cpu(mbx
->mb0
), le16_to_cpu(mbx
->mb1
),
976 le16_to_cpu(mbx
->mb2
), le16_to_cpu(mbx
->mb6
),
977 le16_to_cpu(mbx
->mb7
)));
979 done_post_logio_done_work
:
980 lio
->ctx
.type
== SRB_LOGIN_CMD
?
981 qla2x00_post_async_login_done_work(fcport
->vha
, fcport
, data
):
982 qla2x00_post_async_logout_done_work(fcport
->vha
, fcport
, data
);
988 qla24xx_els_ct_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
989 struct sts_entry_24xx
*pkt
, int iocb_type
)
991 const char func
[] = "ELS_CT_IOCB";
993 struct qla_hw_data
*ha
= vha
->hw
;
995 struct srb_bsg
*sp_bsg
;
996 struct fc_bsg_job
*bsg_job
;
997 uint16_t comp_status
;
998 uint32_t fw_status
[3];
1001 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, pkt
);
1004 sp_bsg
= (struct srb_bsg
*)sp
->ctx
;
1005 bsg_job
= sp_bsg
->bsg_job
;
1008 switch (sp_bsg
->ctx
.type
) {
1009 case SRB_ELS_CMD_RPT
:
1010 case SRB_ELS_CMD_HST
:
1014 type
= "ct pass-through";
1017 qla_printk(KERN_WARNING
, ha
,
1018 "%s: Unrecognized SRB: (%p) type=%d.\n", func
, sp
,
1023 comp_status
= fw_status
[0] = le16_to_cpu(pkt
->comp_status
);
1024 fw_status
[1] = le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->error_subcode_1
);
1025 fw_status
[2] = le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->error_subcode_2
);
1027 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1028 * fc payload to the caller
1030 bsg_job
->reply
->reply_data
.ctels_reply
.status
= FC_CTELS_STATUS_OK
;
1031 bsg_job
->reply_len
= sizeof(struct fc_bsg_reply
) + sizeof(fw_status
);
1033 if (comp_status
!= CS_COMPLETE
) {
1034 if (comp_status
== CS_DATA_UNDERRUN
) {
1035 bsg_job
->reply
->result
= DID_OK
<< 16;
1036 bsg_job
->reply
->reply_payload_rcv_len
=
1037 le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->total_byte_count
);
1039 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1040 "scsi(%ld:0x%x): ELS-CT pass-through-%s error comp_status-status=0x%x "
1041 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
1042 vha
->host_no
, sp
->handle
, type
, comp_status
, fw_status
[1], fw_status
[2],
1043 le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->total_byte_count
)));
1044 fw_sts_ptr
= ((uint8_t*)bsg_job
->req
->sense
) + sizeof(struct fc_bsg_reply
);
1045 memcpy( fw_sts_ptr
, fw_status
, sizeof(fw_status
));
1048 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1049 "scsi(%ld:0x%x): ELS-CT pass-through-%s error comp_status-status=0x%x "
1050 "error subcode 1=0x%x error subcode 2=0x%x.\n",
1051 vha
->host_no
, sp
->handle
, type
, comp_status
,
1052 le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->error_subcode_1
),
1053 le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->error_subcode_2
)));
1054 bsg_job
->reply
->result
= DID_ERROR
<< 16;
1055 bsg_job
->reply
->reply_payload_rcv_len
= 0;
1056 fw_sts_ptr
= ((uint8_t*)bsg_job
->req
->sense
) + sizeof(struct fc_bsg_reply
);
1057 memcpy( fw_sts_ptr
, fw_status
, sizeof(fw_status
));
1059 DEBUG2(qla2x00_dump_buffer((uint8_t *)pkt
, sizeof(*pkt
)));
1062 bsg_job
->reply
->result
= DID_OK
<< 16;;
1063 bsg_job
->reply
->reply_payload_rcv_len
= bsg_job
->reply_payload
.payload_len
;
1064 bsg_job
->reply_len
= 0;
1067 dma_unmap_sg(&ha
->pdev
->dev
,
1068 bsg_job
->request_payload
.sg_list
,
1069 bsg_job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1070 dma_unmap_sg(&ha
->pdev
->dev
,
1071 bsg_job
->reply_payload
.sg_list
,
1072 bsg_job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
1073 if ((sp_bsg
->ctx
.type
== SRB_ELS_CMD_HST
) ||
1074 (sp_bsg
->ctx
.type
== SRB_CT_CMD
))
1077 mempool_free(sp
, ha
->srb_mempool
);
1078 bsg_job
->job_done(bsg_job
);
1082 qla24xx_logio_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
1083 struct logio_entry_24xx
*logio
)
1085 const char func
[] = "LOGIO-IOCB";
1087 struct qla_hw_data
*ha
= vha
->hw
;
1090 struct srb_logio
*lio
;
1094 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, logio
);
1100 switch (lio
->ctx
.type
) {
1104 case SRB_LOGOUT_CMD
:
1108 qla_printk(KERN_WARNING
, ha
,
1109 "%s: Unrecognized SRB: (%p) type=%d.\n", func
, sp
,
1114 del_timer(&lio
->ctx
.timer
);
1115 fcport
= sp
->fcport
;
1117 data
[0] = data
[1] = 0;
1118 if (logio
->entry_status
) {
1119 DEBUG2(printk(KERN_WARNING
1120 "scsi(%ld:%x): Async-%s error entry - entry-status=%x.\n",
1121 fcport
->vha
->host_no
, sp
->handle
, type
,
1122 logio
->entry_status
));
1123 DEBUG2(qla2x00_dump_buffer((uint8_t *)logio
, sizeof(*logio
)));
1125 data
[0] = MBS_COMMAND_ERROR
;
1126 data
[1] = lio
->flags
& SRB_LOGIN_RETRIED
?
1127 QLA_LOGIO_LOGIN_RETRIED
: 0;
1128 goto done_post_logio_done_work
;
1131 if (le16_to_cpu(logio
->comp_status
) == CS_COMPLETE
) {
1132 DEBUG2(printk(KERN_DEBUG
1133 "scsi(%ld:%x): Async-%s complete - iop0=%x.\n",
1134 fcport
->vha
->host_no
, sp
->handle
, type
,
1135 le32_to_cpu(logio
->io_parameter
[0])));
1137 data
[0] = MBS_COMMAND_COMPLETE
;
1138 if (lio
->ctx
.type
== SRB_LOGOUT_CMD
)
1139 goto done_post_logio_done_work
;
1141 iop
[0] = le32_to_cpu(logio
->io_parameter
[0]);
1142 if (iop
[0] & BIT_4
) {
1143 fcport
->port_type
= FCT_TARGET
;
1145 fcport
->flags
|= FCF_FCP2_DEVICE
;
1148 fcport
->port_type
= FCT_INITIATOR
;
1149 if (logio
->io_parameter
[7] || logio
->io_parameter
[8])
1150 fcport
->supported_classes
|= FC_COS_CLASS2
;
1151 if (logio
->io_parameter
[9] || logio
->io_parameter
[10])
1152 fcport
->supported_classes
|= FC_COS_CLASS3
;
1154 goto done_post_logio_done_work
;
1157 iop
[0] = le32_to_cpu(logio
->io_parameter
[0]);
1158 iop
[1] = le32_to_cpu(logio
->io_parameter
[1]);
1160 case LSC_SCODE_PORTID_USED
:
1161 data
[0] = MBS_PORT_ID_USED
;
1162 data
[1] = LSW(iop
[1]);
1164 case LSC_SCODE_NPORT_USED
:
1165 data
[0] = MBS_LOOP_ID_USED
;
1167 case LSC_SCODE_CMD_FAILED
:
1168 if ((iop
[1] & 0xff) == 0x05) {
1169 data
[0] = MBS_NOT_LOGGED_IN
;
1174 data
[0] = MBS_COMMAND_ERROR
;
1175 data
[1] = lio
->flags
& SRB_LOGIN_RETRIED
?
1176 QLA_LOGIO_LOGIN_RETRIED
: 0;
1180 DEBUG2(printk(KERN_WARNING
1181 "scsi(%ld:%x): Async-%s failed - comp=%x iop0=%x iop1=%x.\n",
1182 fcport
->vha
->host_no
, sp
->handle
, type
,
1183 le16_to_cpu(logio
->comp_status
),
1184 le32_to_cpu(logio
->io_parameter
[0]),
1185 le32_to_cpu(logio
->io_parameter
[1])));
1187 done_post_logio_done_work
:
1188 lio
->ctx
.type
== SRB_LOGIN_CMD
?
1189 qla2x00_post_async_login_done_work(fcport
->vha
, fcport
, data
):
1190 qla2x00_post_async_logout_done_work(fcport
->vha
, fcport
, data
);
1196 * qla2x00_process_response_queue() - Process response queue entries.
1197 * @ha: SCSI driver HA context
1200 qla2x00_process_response_queue(struct rsp_que
*rsp
)
1202 struct scsi_qla_host
*vha
;
1203 struct qla_hw_data
*ha
= rsp
->hw
;
1204 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1206 uint16_t handle_cnt
;
1209 vha
= pci_get_drvdata(ha
->pdev
);
1211 if (!vha
->flags
.online
)
1214 while (rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
1215 pkt
= (sts_entry_t
*)rsp
->ring_ptr
;
1218 if (rsp
->ring_index
== rsp
->length
) {
1219 rsp
->ring_index
= 0;
1220 rsp
->ring_ptr
= rsp
->ring
;
1225 if (pkt
->entry_status
!= 0) {
1226 DEBUG3(printk(KERN_INFO
1227 "scsi(%ld): Process error entry.\n", vha
->host_no
));
1229 qla2x00_error_entry(vha
, rsp
, pkt
);
1230 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1235 switch (pkt
->entry_type
) {
1237 qla2x00_status_entry(vha
, rsp
, pkt
);
1239 case STATUS_TYPE_21
:
1240 handle_cnt
= ((sts21_entry_t
*)pkt
)->handle_count
;
1241 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
1242 qla2x00_process_completed_request(vha
, rsp
->req
,
1243 ((sts21_entry_t
*)pkt
)->handle
[cnt
]);
1246 case STATUS_TYPE_22
:
1247 handle_cnt
= ((sts22_entry_t
*)pkt
)->handle_count
;
1248 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
1249 qla2x00_process_completed_request(vha
, rsp
->req
,
1250 ((sts22_entry_t
*)pkt
)->handle
[cnt
]);
1253 case STATUS_CONT_TYPE
:
1254 qla2x00_status_cont_entry(rsp
, (sts_cont_entry_t
*)pkt
);
1257 qla2x00_mbx_iocb_entry(vha
, rsp
->req
,
1258 (struct mbx_entry
*)pkt
);
1260 /* Type Not Supported. */
1261 DEBUG4(printk(KERN_WARNING
1262 "scsi(%ld): Received unknown response pkt type %x "
1263 "entry status=%x.\n",
1264 vha
->host_no
, pkt
->entry_type
, pkt
->entry_status
));
1267 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1271 /* Adjust ring index */
1272 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), rsp
->ring_index
);
1276 qla2x00_handle_sense(srb_t
*sp
, uint8_t *sense_data
, uint32_t sense_len
,
1277 struct rsp_que
*rsp
)
1279 struct scsi_cmnd
*cp
= sp
->cmd
;
1281 if (sense_len
>= SCSI_SENSE_BUFFERSIZE
)
1282 sense_len
= SCSI_SENSE_BUFFERSIZE
;
1284 sp
->request_sense_length
= sense_len
;
1285 sp
->request_sense_ptr
= cp
->sense_buffer
;
1286 if (sp
->request_sense_length
> 32)
1289 memcpy(cp
->sense_buffer
, sense_data
, sense_len
);
1291 sp
->request_sense_ptr
+= sense_len
;
1292 sp
->request_sense_length
-= sense_len
;
1293 if (sp
->request_sense_length
!= 0)
1294 rsp
->status_srb
= sp
;
1296 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
1297 "cmd=%p pid=%ld\n", __func__
, sp
->fcport
->vha
->host_no
,
1298 cp
->device
->channel
, cp
->device
->id
, cp
->device
->lun
, cp
,
1299 cp
->serial_number
));
1301 DEBUG5(qla2x00_dump_buffer(cp
->sense_buffer
, sense_len
));
1305 * qla2x00_status_entry() - Process a Status IOCB entry.
1306 * @ha: SCSI driver HA context
1307 * @pkt: Entry pointer
1310 qla2x00_status_entry(scsi_qla_host_t
*vha
, struct rsp_que
*rsp
, void *pkt
)
1314 struct scsi_cmnd
*cp
;
1316 struct sts_entry_24xx
*sts24
;
1317 uint16_t comp_status
;
1318 uint16_t scsi_status
;
1319 uint8_t lscsi_status
;
1321 uint32_t sense_len
, rsp_info_len
, resid_len
, fw_resid_len
;
1322 uint8_t *rsp_info
, *sense_data
;
1323 struct qla_hw_data
*ha
= vha
->hw
;
1326 struct req_que
*req
;
1328 sts
= (sts_entry_t
*) pkt
;
1329 sts24
= (struct sts_entry_24xx
*) pkt
;
1330 if (IS_FWI2_CAPABLE(ha
)) {
1331 comp_status
= le16_to_cpu(sts24
->comp_status
);
1332 scsi_status
= le16_to_cpu(sts24
->scsi_status
) & SS_MASK
;
1334 comp_status
= le16_to_cpu(sts
->comp_status
);
1335 scsi_status
= le16_to_cpu(sts
->scsi_status
) & SS_MASK
;
1337 handle
= (uint32_t) LSW(sts
->handle
);
1338 que
= MSW(sts
->handle
);
1339 req
= ha
->req_q_map
[que
];
1340 /* Fast path completion. */
1341 if (comp_status
== CS_COMPLETE
&& scsi_status
== 0) {
1342 qla2x00_process_completed_request(vha
, req
, handle
);
1347 /* Validate handle. */
1348 if (handle
< MAX_OUTSTANDING_COMMANDS
) {
1349 sp
= req
->outstanding_cmds
[handle
];
1350 req
->outstanding_cmds
[handle
] = NULL
;
1355 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
1357 qla_printk(KERN_WARNING
, ha
, "Status Entry invalid handle.\n");
1359 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1360 qla2xxx_wake_dpc(vha
);
1365 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
1366 "pkt->handle=%d sp=%p.\n", vha
->host_no
, handle
, sp
));
1367 qla_printk(KERN_WARNING
, ha
,
1368 "Command is NULL: already returned to OS (sp=%p)\n", sp
);
1373 lscsi_status
= scsi_status
& STATUS_MASK
;
1375 fcport
= sp
->fcport
;
1377 sense_len
= rsp_info_len
= resid_len
= fw_resid_len
= 0;
1378 if (IS_FWI2_CAPABLE(ha
)) {
1379 if (scsi_status
& SS_SENSE_LEN_VALID
)
1380 sense_len
= le32_to_cpu(sts24
->sense_len
);
1381 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
)
1382 rsp_info_len
= le32_to_cpu(sts24
->rsp_data_len
);
1383 if (scsi_status
& (SS_RESIDUAL_UNDER
| SS_RESIDUAL_OVER
))
1384 resid_len
= le32_to_cpu(sts24
->rsp_residual_count
);
1385 if (comp_status
== CS_DATA_UNDERRUN
)
1386 fw_resid_len
= le32_to_cpu(sts24
->residual_len
);
1387 rsp_info
= sts24
->data
;
1388 sense_data
= sts24
->data
;
1389 host_to_fcp_swap(sts24
->data
, sizeof(sts24
->data
));
1391 if (scsi_status
& SS_SENSE_LEN_VALID
)
1392 sense_len
= le16_to_cpu(sts
->req_sense_length
);
1393 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
)
1394 rsp_info_len
= le16_to_cpu(sts
->rsp_info_len
);
1395 resid_len
= le32_to_cpu(sts
->residual_length
);
1396 rsp_info
= sts
->rsp_info
;
1397 sense_data
= sts
->req_sense_data
;
1400 /* Check for any FCP transport errors. */
1401 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
) {
1402 /* Sense data lies beyond any FCP RESPONSE data. */
1403 if (IS_FWI2_CAPABLE(ha
))
1404 sense_data
+= rsp_info_len
;
1405 if (rsp_info_len
> 3 && rsp_info
[3]) {
1406 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1407 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
1408 "retrying command\n", vha
->host_no
,
1409 cp
->device
->channel
, cp
->device
->id
,
1410 cp
->device
->lun
, rsp_info_len
, rsp_info
[0],
1411 rsp_info
[1], rsp_info
[2], rsp_info
[3], rsp_info
[4],
1412 rsp_info
[5], rsp_info
[6], rsp_info
[7]));
1414 cp
->result
= DID_BUS_BUSY
<< 16;
1415 qla2x00_sp_compl(ha
, sp
);
1420 /* Check for overrun. */
1421 if (IS_FWI2_CAPABLE(ha
) && comp_status
== CS_COMPLETE
&&
1422 scsi_status
& SS_RESIDUAL_OVER
)
1423 comp_status
= CS_DATA_OVERRUN
;
1426 * Based on Host and scsi status generate status code for Linux
1428 switch (comp_status
) {
1431 if (scsi_status
== 0) {
1432 cp
->result
= DID_OK
<< 16;
1435 if (scsi_status
& (SS_RESIDUAL_UNDER
| SS_RESIDUAL_OVER
)) {
1437 scsi_set_resid(cp
, resid
);
1439 if (!lscsi_status
&&
1440 ((unsigned)(scsi_bufflen(cp
) - resid
) <
1442 qla_printk(KERN_INFO
, ha
,
1443 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1444 "detected (%x of %x bytes)...returning "
1445 "error status.\n", vha
->host_no
,
1446 cp
->device
->channel
, cp
->device
->id
,
1447 cp
->device
->lun
, resid
,
1450 cp
->result
= DID_ERROR
<< 16;
1454 cp
->result
= DID_OK
<< 16 | lscsi_status
;
1456 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
) {
1457 DEBUG2(printk(KERN_INFO
1458 "scsi(%ld): QUEUE FULL status detected "
1459 "0x%x-0x%x.\n", vha
->host_no
, comp_status
,
1463 if (lscsi_status
!= SS_CHECK_CONDITION
)
1466 memset(cp
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
1467 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
1470 qla2x00_handle_sense(sp
, sense_data
, sense_len
, rsp
);
1473 case CS_DATA_UNDERRUN
:
1474 DEBUG2(printk(KERN_INFO
1475 "scsi(%ld:%d:%d) UNDERRUN status detected 0x%x-0x%x. "
1476 "resid=0x%x fw_resid=0x%x cdb=0x%x os_underflow=0x%x\n",
1477 vha
->host_no
, cp
->device
->id
, cp
->device
->lun
, comp_status
,
1478 scsi_status
, resid_len
, fw_resid_len
, cp
->cmnd
[0],
1481 /* Use F/W calculated residual length. */
1482 resid
= IS_FWI2_CAPABLE(ha
) ? fw_resid_len
: resid_len
;
1483 scsi_set_resid(cp
, resid
);
1484 if (scsi_status
& SS_RESIDUAL_UNDER
) {
1485 if (IS_FWI2_CAPABLE(ha
) && fw_resid_len
!= resid_len
) {
1487 "scsi(%ld:%d:%d:%d) Dropped frame(s) "
1488 "detected (%x of %x bytes)...residual "
1489 "length mismatch...retrying command.\n",
1490 vha
->host_no
, cp
->device
->channel
,
1491 cp
->device
->id
, cp
->device
->lun
, resid
,
1494 cp
->result
= DID_ERROR
<< 16 | lscsi_status
;
1498 if (!lscsi_status
&&
1499 ((unsigned)(scsi_bufflen(cp
) - resid
) <
1501 qla_printk(KERN_INFO
, ha
,
1502 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1503 "detected (%x of %x bytes)...returning "
1504 "error status.\n", vha
->host_no
,
1505 cp
->device
->channel
, cp
->device
->id
,
1506 cp
->device
->lun
, resid
, scsi_bufflen(cp
));
1508 cp
->result
= DID_ERROR
<< 16;
1511 } else if (!lscsi_status
) {
1513 "scsi(%ld:%d:%d:%d) Dropped frame(s) detected "
1514 "(%x of %x bytes)...firmware reported underrun..."
1515 "retrying command.\n", vha
->host_no
,
1516 cp
->device
->channel
, cp
->device
->id
,
1517 cp
->device
->lun
, resid
, scsi_bufflen(cp
)));
1519 cp
->result
= DID_ERROR
<< 16;
1523 cp
->result
= DID_OK
<< 16 | lscsi_status
;
1526 * Check to see if SCSI Status is non zero. If so report SCSI
1529 if (lscsi_status
!= 0) {
1530 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
) {
1531 DEBUG2(printk(KERN_INFO
1532 "scsi(%ld): QUEUE FULL status detected "
1533 "0x%x-0x%x.\n", vha
->host_no
, comp_status
,
1537 if (lscsi_status
!= SS_CHECK_CONDITION
)
1540 memset(cp
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
1541 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
1544 qla2x00_handle_sense(sp
, sense_data
, sense_len
, rsp
);
1548 case CS_DATA_OVERRUN
:
1549 DEBUG2(printk(KERN_INFO
1550 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1551 vha
->host_no
, cp
->device
->id
, cp
->device
->lun
, comp_status
,
1553 DEBUG2(printk(KERN_INFO
1554 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1555 cp
->cmnd
[0], cp
->cmnd
[1], cp
->cmnd
[2], cp
->cmnd
[3],
1556 cp
->cmnd
[4], cp
->cmnd
[5]));
1557 DEBUG2(printk(KERN_INFO
1558 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1560 cp
->serial_number
, scsi_bufflen(cp
), resid_len
));
1562 cp
->result
= DID_ERROR
<< 16;
1565 case CS_PORT_LOGGED_OUT
:
1566 case CS_PORT_CONFIG_CHG
:
1569 case CS_PORT_UNAVAILABLE
:
1571 * If the port is in Target Down state, return all IOs for this
1572 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1575 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1576 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1577 vha
->host_no
, cp
->device
->id
, cp
->device
->lun
,
1578 cp
->serial_number
, comp_status
,
1579 atomic_read(&fcport
->state
)));
1582 * We are going to have the fc class block the rport
1583 * while we try to recover so instruct the mid layer
1584 * to requeue until the class decides how to handle this.
1586 cp
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
1587 if (atomic_read(&fcport
->state
) == FCS_ONLINE
)
1588 qla2x00_mark_device_lost(fcport
->vha
, fcport
, 1, 1);
1592 DEBUG2(printk(KERN_INFO
1593 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1594 vha
->host_no
, comp_status
, scsi_status
));
1596 cp
->result
= DID_RESET
<< 16;
1601 * hv2.19.12 - DID_ABORT does not retry the request if we
1602 * aborted this request then abort otherwise it must be a
1605 DEBUG2(printk(KERN_INFO
1606 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1607 vha
->host_no
, comp_status
, scsi_status
));
1609 cp
->result
= DID_RESET
<< 16;
1614 * We are going to have the fc class block the rport
1615 * while we try to recover so instruct the mid layer
1616 * to requeue until the class decides how to handle this.
1618 cp
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
1620 if (IS_FWI2_CAPABLE(ha
)) {
1621 DEBUG2(printk(KERN_INFO
1622 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1623 "0x%x-0x%x\n", vha
->host_no
, cp
->device
->channel
,
1624 cp
->device
->id
, cp
->device
->lun
, comp_status
,
1628 DEBUG2(printk(KERN_INFO
1629 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1630 "sflags=%x.\n", vha
->host_no
, cp
->device
->channel
,
1631 cp
->device
->id
, cp
->device
->lun
, comp_status
, scsi_status
,
1632 le16_to_cpu(sts
->status_flags
)));
1634 /* Check to see if logout occurred. */
1635 if ((le16_to_cpu(sts
->status_flags
) & SF_LOGOUT_SENT
))
1636 qla2x00_mark_device_lost(fcport
->vha
, fcport
, 1, 1);
1640 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1641 "0x%x-0x%x.\n", vha
->host_no
, comp_status
, scsi_status
));
1642 qla_printk(KERN_INFO
, ha
,
1643 "Unknown status detected 0x%x-0x%x.\n",
1644 comp_status
, scsi_status
);
1646 cp
->result
= DID_ERROR
<< 16;
1650 /* Place command on done queue. */
1651 if (rsp
->status_srb
== NULL
)
1652 qla2x00_sp_compl(ha
, sp
);
1656 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1657 * @ha: SCSI driver HA context
1658 * @pkt: Entry pointer
1660 * Extended sense data.
1663 qla2x00_status_cont_entry(struct rsp_que
*rsp
, sts_cont_entry_t
*pkt
)
1665 uint8_t sense_sz
= 0;
1666 struct qla_hw_data
*ha
= rsp
->hw
;
1667 srb_t
*sp
= rsp
->status_srb
;
1668 struct scsi_cmnd
*cp
;
1670 if (sp
!= NULL
&& sp
->request_sense_length
!= 0) {
1673 DEBUG2(printk("%s(): Cmd already returned back to OS "
1674 "sp=%p.\n", __func__
, sp
));
1675 qla_printk(KERN_INFO
, ha
,
1676 "cmd is NULL: already returned to OS (sp=%p)\n",
1679 rsp
->status_srb
= NULL
;
1683 if (sp
->request_sense_length
> sizeof(pkt
->data
)) {
1684 sense_sz
= sizeof(pkt
->data
);
1686 sense_sz
= sp
->request_sense_length
;
1689 /* Move sense data. */
1690 if (IS_FWI2_CAPABLE(ha
))
1691 host_to_fcp_swap(pkt
->data
, sizeof(pkt
->data
));
1692 memcpy(sp
->request_sense_ptr
, pkt
->data
, sense_sz
);
1693 DEBUG5(qla2x00_dump_buffer(sp
->request_sense_ptr
, sense_sz
));
1695 sp
->request_sense_ptr
+= sense_sz
;
1696 sp
->request_sense_length
-= sense_sz
;
1698 /* Place command on done queue. */
1699 if (sp
->request_sense_length
== 0) {
1700 rsp
->status_srb
= NULL
;
1701 qla2x00_sp_compl(ha
, sp
);
1707 * qla2x00_error_entry() - Process an error entry.
1708 * @ha: SCSI driver HA context
1709 * @pkt: Entry pointer
1712 qla2x00_error_entry(scsi_qla_host_t
*vha
, struct rsp_que
*rsp
, sts_entry_t
*pkt
)
1715 struct qla_hw_data
*ha
= vha
->hw
;
1716 uint32_t handle
= LSW(pkt
->handle
);
1717 uint16_t que
= MSW(pkt
->handle
);
1718 struct req_que
*req
= ha
->req_q_map
[que
];
1719 #if defined(QL_DEBUG_LEVEL_2)
1720 if (pkt
->entry_status
& RF_INV_E_ORDER
)
1721 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Order\n", __func__
);
1722 else if (pkt
->entry_status
& RF_INV_E_COUNT
)
1723 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Count\n", __func__
);
1724 else if (pkt
->entry_status
& RF_INV_E_PARAM
)
1725 qla_printk(KERN_ERR
, ha
,
1726 "%s: Invalid Entry Parameter\n", __func__
);
1727 else if (pkt
->entry_status
& RF_INV_E_TYPE
)
1728 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Type\n", __func__
);
1729 else if (pkt
->entry_status
& RF_BUSY
)
1730 qla_printk(KERN_ERR
, ha
, "%s: Busy\n", __func__
);
1732 qla_printk(KERN_ERR
, ha
, "%s: UNKNOWN flag error\n", __func__
);
1735 /* Validate handle. */
1736 if (handle
< MAX_OUTSTANDING_COMMANDS
)
1737 sp
= req
->outstanding_cmds
[handle
];
1742 /* Free outstanding command slot. */
1743 req
->outstanding_cmds
[handle
] = NULL
;
1745 /* Bad payload or header */
1746 if (pkt
->entry_status
&
1747 (RF_INV_E_ORDER
| RF_INV_E_COUNT
|
1748 RF_INV_E_PARAM
| RF_INV_E_TYPE
)) {
1749 sp
->cmd
->result
= DID_ERROR
<< 16;
1750 } else if (pkt
->entry_status
& RF_BUSY
) {
1751 sp
->cmd
->result
= DID_BUS_BUSY
<< 16;
1753 sp
->cmd
->result
= DID_ERROR
<< 16;
1755 qla2x00_sp_compl(ha
, sp
);
1757 } else if (pkt
->entry_type
== COMMAND_A64_TYPE
|| pkt
->entry_type
==
1758 COMMAND_TYPE
|| pkt
->entry_type
== COMMAND_TYPE_7
) {
1759 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1761 qla_printk(KERN_WARNING
, ha
,
1762 "Error entry - invalid handle\n");
1764 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1765 qla2xxx_wake_dpc(vha
);
1770 * qla24xx_mbx_completion() - Process mailbox command completions.
1771 * @ha: SCSI driver HA context
1772 * @mb0: Mailbox0 register
1775 qla24xx_mbx_completion(scsi_qla_host_t
*vha
, uint16_t mb0
)
1778 uint16_t __iomem
*wptr
;
1779 struct qla_hw_data
*ha
= vha
->hw
;
1780 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1782 /* Load return mailbox registers. */
1783 ha
->flags
.mbox_int
= 1;
1784 ha
->mailbox_out
[0] = mb0
;
1785 wptr
= (uint16_t __iomem
*)®
->mailbox1
;
1787 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
1788 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
1793 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1794 __func__
, vha
->host_no
, ha
->mcp
->mb
[0]));
1796 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1797 __func__
, vha
->host_no
));
1802 * qla24xx_process_response_queue() - Process response queue entries.
1803 * @ha: SCSI driver HA context
1805 void qla24xx_process_response_queue(struct scsi_qla_host
*vha
,
1806 struct rsp_que
*rsp
)
1808 struct sts_entry_24xx
*pkt
;
1810 if (!vha
->flags
.online
)
1813 while (rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
1814 pkt
= (struct sts_entry_24xx
*)rsp
->ring_ptr
;
1817 if (rsp
->ring_index
== rsp
->length
) {
1818 rsp
->ring_index
= 0;
1819 rsp
->ring_ptr
= rsp
->ring
;
1824 if (pkt
->entry_status
!= 0) {
1825 DEBUG3(printk(KERN_INFO
1826 "scsi(%ld): Process error entry.\n", vha
->host_no
));
1828 qla2x00_error_entry(vha
, rsp
, (sts_entry_t
*) pkt
);
1829 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1834 switch (pkt
->entry_type
) {
1836 qla2x00_status_entry(vha
, rsp
, pkt
);
1838 case STATUS_CONT_TYPE
:
1839 qla2x00_status_cont_entry(rsp
, (sts_cont_entry_t
*)pkt
);
1841 case VP_RPT_ID_IOCB_TYPE
:
1842 qla24xx_report_id_acquisition(vha
,
1843 (struct vp_rpt_id_entry_24xx
*)pkt
);
1845 case LOGINOUT_PORT_IOCB_TYPE
:
1846 qla24xx_logio_entry(vha
, rsp
->req
,
1847 (struct logio_entry_24xx
*)pkt
);
1850 qla24xx_els_ct_entry(vha
, rsp
->req
, pkt
, CT_IOCB_TYPE
);
1851 clear_bit(MBX_INTERRUPT
, &vha
->hw
->mbx_cmd_flags
);
1854 qla24xx_els_ct_entry(vha
, rsp
->req
, pkt
, ELS_IOCB_TYPE
);
1857 /* Type Not Supported. */
1858 DEBUG4(printk(KERN_WARNING
1859 "scsi(%ld): Received unknown response pkt type %x "
1860 "entry status=%x.\n",
1861 vha
->host_no
, pkt
->entry_type
, pkt
->entry_status
));
1864 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1868 /* Adjust ring index */
1869 WRT_REG_DWORD(rsp
->rsp_q_out
, rsp
->ring_index
);
1873 qla2xxx_check_risc_status(scsi_qla_host_t
*vha
)
1877 struct qla_hw_data
*ha
= vha
->hw
;
1878 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1880 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
))
1884 WRT_REG_DWORD(®
->iobase_addr
, 0x7C00);
1885 RD_REG_DWORD(®
->iobase_addr
);
1886 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
1887 for (cnt
= 10000; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
1888 rval
== QLA_SUCCESS
; cnt
--) {
1890 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
1893 rval
= QLA_FUNCTION_TIMEOUT
;
1895 if (rval
== QLA_SUCCESS
)
1898 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
1899 for (cnt
= 100; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
1900 rval
== QLA_SUCCESS
; cnt
--) {
1902 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
1905 rval
= QLA_FUNCTION_TIMEOUT
;
1907 if (rval
!= QLA_SUCCESS
)
1911 if (RD_REG_DWORD(®
->iobase_c8
) & BIT_3
)
1912 qla_printk(KERN_INFO
, ha
, "Additional code -- 0x55AA.\n");
1915 WRT_REG_DWORD(®
->iobase_window
, 0x0000);
1916 RD_REG_DWORD(®
->iobase_window
);
1920 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1922 * @dev_id: SCSI driver HA context
1924 * Called by system whenever the host adapter generates an interrupt.
1926 * Returns handled flag.
1929 qla24xx_intr_handler(int irq
, void *dev_id
)
1931 scsi_qla_host_t
*vha
;
1932 struct qla_hw_data
*ha
;
1933 struct device_reg_24xx __iomem
*reg
;
1939 struct rsp_que
*rsp
;
1940 unsigned long flags
;
1942 rsp
= (struct rsp_que
*) dev_id
;
1945 "%s(): NULL response queue pointer\n", __func__
);
1950 reg
= &ha
->iobase
->isp24
;
1953 if (unlikely(pci_channel_offline(ha
->pdev
)))
1956 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1957 vha
= pci_get_drvdata(ha
->pdev
);
1958 for (iter
= 50; iter
--; ) {
1959 stat
= RD_REG_DWORD(®
->host_status
);
1960 if (stat
& HSRX_RISC_PAUSED
) {
1961 if (unlikely(pci_channel_offline(ha
->pdev
)))
1964 hccr
= RD_REG_DWORD(®
->hccr
);
1966 qla_printk(KERN_INFO
, ha
, "RISC paused -- HCCR=%x, "
1967 "Dumping firmware!\n", hccr
);
1969 qla2xxx_check_risc_status(vha
);
1971 ha
->isp_ops
->fw_dump(vha
, 1);
1972 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1974 } else if ((stat
& HSRX_RISC_INT
) == 0)
1977 switch (stat
& 0xff) {
1982 qla24xx_mbx_completion(vha
, MSW(stat
));
1983 status
|= MBX_INTERRUPT
;
1988 mb
[1] = RD_REG_WORD(®
->mailbox1
);
1989 mb
[2] = RD_REG_WORD(®
->mailbox2
);
1990 mb
[3] = RD_REG_WORD(®
->mailbox3
);
1991 qla2x00_async_event(vha
, rsp
, mb
);
1995 qla24xx_process_response_queue(vha
, rsp
);
1998 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
2000 vha
->host_no
, stat
& 0xff));
2003 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2004 RD_REG_DWORD_RELAXED(®
->hccr
);
2006 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2008 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
2009 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
2010 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
2011 complete(&ha
->mbx_intr_comp
);
2018 qla24xx_msix_rsp_q(int irq
, void *dev_id
)
2020 struct qla_hw_data
*ha
;
2021 struct rsp_que
*rsp
;
2022 struct device_reg_24xx __iomem
*reg
;
2023 struct scsi_qla_host
*vha
;
2024 unsigned long flags
;
2026 rsp
= (struct rsp_que
*) dev_id
;
2029 "%s(): NULL response queue pointer\n", __func__
);
2033 reg
= &ha
->iobase
->isp24
;
2035 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2037 vha
= pci_get_drvdata(ha
->pdev
);
2038 qla24xx_process_response_queue(vha
, rsp
);
2039 if (!ha
->flags
.disable_msix_handshake
) {
2040 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2041 RD_REG_DWORD_RELAXED(®
->hccr
);
2043 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2049 qla25xx_msix_rsp_q(int irq
, void *dev_id
)
2051 struct qla_hw_data
*ha
;
2052 struct rsp_que
*rsp
;
2053 struct device_reg_24xx __iomem
*reg
;
2054 unsigned long flags
;
2056 rsp
= (struct rsp_que
*) dev_id
;
2059 "%s(): NULL response queue pointer\n", __func__
);
2064 /* Clear the interrupt, if enabled, for this response queue */
2065 if (rsp
->options
& ~BIT_6
) {
2066 reg
= &ha
->iobase
->isp24
;
2067 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2068 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2069 RD_REG_DWORD_RELAXED(®
->hccr
);
2070 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2072 queue_work_on((int) (rsp
->id
- 1), ha
->wq
, &rsp
->q_work
);
2078 qla24xx_msix_default(int irq
, void *dev_id
)
2080 scsi_qla_host_t
*vha
;
2081 struct qla_hw_data
*ha
;
2082 struct rsp_que
*rsp
;
2083 struct device_reg_24xx __iomem
*reg
;
2088 unsigned long flags
;
2090 rsp
= (struct rsp_que
*) dev_id
;
2093 "%s(): NULL response queue pointer\n", __func__
));
2097 reg
= &ha
->iobase
->isp24
;
2100 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2101 vha
= pci_get_drvdata(ha
->pdev
);
2103 stat
= RD_REG_DWORD(®
->host_status
);
2104 if (stat
& HSRX_RISC_PAUSED
) {
2105 if (unlikely(pci_channel_offline(ha
->pdev
)))
2108 hccr
= RD_REG_DWORD(®
->hccr
);
2110 qla_printk(KERN_INFO
, ha
, "RISC paused -- HCCR=%x, "
2111 "Dumping firmware!\n", hccr
);
2113 qla2xxx_check_risc_status(vha
);
2115 ha
->isp_ops
->fw_dump(vha
, 1);
2116 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2118 } else if ((stat
& HSRX_RISC_INT
) == 0)
2121 switch (stat
& 0xff) {
2126 qla24xx_mbx_completion(vha
, MSW(stat
));
2127 status
|= MBX_INTERRUPT
;
2132 mb
[1] = RD_REG_WORD(®
->mailbox1
);
2133 mb
[2] = RD_REG_WORD(®
->mailbox2
);
2134 mb
[3] = RD_REG_WORD(®
->mailbox3
);
2135 qla2x00_async_event(vha
, rsp
, mb
);
2139 qla24xx_process_response_queue(vha
, rsp
);
2142 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
2144 vha
->host_no
, stat
& 0xff));
2147 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2149 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2151 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
2152 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
2153 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
2154 complete(&ha
->mbx_intr_comp
);
2159 /* Interrupt handling helpers. */
2161 struct qla_init_msix_entry
{
2163 irq_handler_t handler
;
2166 static struct qla_init_msix_entry msix_entries
[3] = {
2167 { "qla2xxx (default)", qla24xx_msix_default
},
2168 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q
},
2169 { "qla2xxx (multiq)", qla25xx_msix_rsp_q
},
2173 qla24xx_disable_msix(struct qla_hw_data
*ha
)
2176 struct qla_msix_entry
*qentry
;
2178 for (i
= 0; i
< ha
->msix_count
; i
++) {
2179 qentry
= &ha
->msix_entries
[i
];
2180 if (qentry
->have_irq
)
2181 free_irq(qentry
->vector
, qentry
->rsp
);
2183 pci_disable_msix(ha
->pdev
);
2184 kfree(ha
->msix_entries
);
2185 ha
->msix_entries
= NULL
;
2186 ha
->flags
.msix_enabled
= 0;
2190 qla24xx_enable_msix(struct qla_hw_data
*ha
, struct rsp_que
*rsp
)
2192 #define MIN_MSIX_COUNT 2
2194 struct msix_entry
*entries
;
2195 struct qla_msix_entry
*qentry
;
2197 entries
= kzalloc(sizeof(struct msix_entry
) * ha
->msix_count
,
2202 for (i
= 0; i
< ha
->msix_count
; i
++)
2203 entries
[i
].entry
= i
;
2205 ret
= pci_enable_msix(ha
->pdev
, entries
, ha
->msix_count
);
2207 if (ret
< MIN_MSIX_COUNT
)
2210 qla_printk(KERN_WARNING
, ha
,
2211 "MSI-X: Failed to enable support -- %d/%d\n"
2212 " Retry with %d vectors\n", ha
->msix_count
, ret
, ret
);
2213 ha
->msix_count
= ret
;
2214 ret
= pci_enable_msix(ha
->pdev
, entries
, ha
->msix_count
);
2217 qla_printk(KERN_WARNING
, ha
, "MSI-X: Failed to enable"
2218 " support, giving up -- %d/%d\n",
2219 ha
->msix_count
, ret
);
2222 ha
->max_rsp_queues
= ha
->msix_count
- 1;
2224 ha
->msix_entries
= kzalloc(sizeof(struct qla_msix_entry
) *
2225 ha
->msix_count
, GFP_KERNEL
);
2226 if (!ha
->msix_entries
) {
2230 ha
->flags
.msix_enabled
= 1;
2232 for (i
= 0; i
< ha
->msix_count
; i
++) {
2233 qentry
= &ha
->msix_entries
[i
];
2234 qentry
->vector
= entries
[i
].vector
;
2235 qentry
->entry
= entries
[i
].entry
;
2236 qentry
->have_irq
= 0;
2240 /* Enable MSI-X vectors for the base queue */
2241 for (i
= 0; i
< 2; i
++) {
2242 qentry
= &ha
->msix_entries
[i
];
2243 ret
= request_irq(qentry
->vector
, msix_entries
[i
].handler
,
2244 0, msix_entries
[i
].name
, rsp
);
2246 qla_printk(KERN_WARNING
, ha
,
2247 "MSI-X: Unable to register handler -- %x/%d.\n",
2248 qentry
->vector
, ret
);
2249 qla24xx_disable_msix(ha
);
2253 qentry
->have_irq
= 1;
2258 /* Enable MSI-X vector for response queue update for queue 0 */
2259 if (ha
->mqiobase
&& (ha
->max_rsp_queues
> 1 || ha
->max_req_queues
> 1))
2268 qla2x00_request_irqs(struct qla_hw_data
*ha
, struct rsp_que
*rsp
)
2271 device_reg_t __iomem
*reg
= ha
->iobase
;
2273 /* If possible, enable MSI-X. */
2274 if (!IS_QLA2432(ha
) && !IS_QLA2532(ha
) &&
2275 !IS_QLA8432(ha
) && !IS_QLA8001(ha
))
2278 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_HP
&&
2279 (ha
->pdev
->subsystem_device
== 0x7040 ||
2280 ha
->pdev
->subsystem_device
== 0x7041 ||
2281 ha
->pdev
->subsystem_device
== 0x1705)) {
2282 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2283 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X,0x%X).\n",
2284 ha
->pdev
->subsystem_vendor
,
2285 ha
->pdev
->subsystem_device
));
2289 if (IS_QLA2432(ha
) && (ha
->pdev
->revision
< QLA_MSIX_CHIP_REV_24XX
||
2290 !QLA_MSIX_FW_MODE_1(ha
->fw_attributes
))) {
2291 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2292 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
2293 ha
->pdev
->revision
, ha
->fw_attributes
));
2297 ret
= qla24xx_enable_msix(ha
, rsp
);
2299 DEBUG2(qla_printk(KERN_INFO
, ha
,
2300 "MSI-X: Enabled (0x%X, 0x%X).\n", ha
->chip_revision
,
2301 ha
->fw_attributes
));
2302 goto clear_risc_ints
;
2304 qla_printk(KERN_WARNING
, ha
,
2305 "MSI-X: Falling back-to INTa mode -- %d.\n", ret
);
2308 if (!IS_QLA24XX(ha
) && !IS_QLA2532(ha
) && !IS_QLA8432(ha
) &&
2312 ret
= pci_enable_msi(ha
->pdev
);
2314 DEBUG2(qla_printk(KERN_INFO
, ha
, "MSI: Enabled.\n"));
2315 ha
->flags
.msi_enabled
= 1;
2319 ret
= request_irq(ha
->pdev
->irq
, ha
->isp_ops
->intr_handler
,
2320 IRQF_SHARED
, QLA2XXX_DRIVER_NAME
, rsp
);
2322 qla_printk(KERN_WARNING
, ha
,
2323 "Failed to reserve interrupt %d already in use.\n",
2327 ha
->flags
.inta_enabled
= 1;
2331 * FIXME: Noted that 8014s were being dropped during NK testing.
2332 * Timing deltas during MSI-X/INTa transitions?
2336 spin_lock_irq(&ha
->hardware_lock
);
2337 if (IS_FWI2_CAPABLE(ha
)) {
2338 WRT_REG_DWORD(®
->isp24
.hccr
, HCCRX_CLR_HOST_INT
);
2339 WRT_REG_DWORD(®
->isp24
.hccr
, HCCRX_CLR_RISC_INT
);
2341 WRT_REG_WORD(®
->isp
.semaphore
, 0);
2342 WRT_REG_WORD(®
->isp
.hccr
, HCCR_CLR_RISC_INT
);
2343 WRT_REG_WORD(®
->isp
.hccr
, HCCR_CLR_HOST_INT
);
2345 spin_unlock_irq(&ha
->hardware_lock
);
2352 qla2x00_free_irqs(scsi_qla_host_t
*vha
)
2354 struct qla_hw_data
*ha
= vha
->hw
;
2355 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
2357 if (ha
->flags
.msix_enabled
)
2358 qla24xx_disable_msix(ha
);
2359 else if (ha
->flags
.msi_enabled
) {
2360 free_irq(ha
->pdev
->irq
, rsp
);
2361 pci_disable_msi(ha
->pdev
);
2363 free_irq(ha
->pdev
->irq
, rsp
);
2367 int qla25xx_request_irq(struct rsp_que
*rsp
)
2369 struct qla_hw_data
*ha
= rsp
->hw
;
2370 struct qla_init_msix_entry
*intr
= &msix_entries
[2];
2371 struct qla_msix_entry
*msix
= rsp
->msix
;
2374 ret
= request_irq(msix
->vector
, intr
->handler
, 0, intr
->name
, rsp
);
2376 qla_printk(KERN_WARNING
, ha
,
2377 "MSI-X: Unable to register handler -- %x/%d.\n",