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 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff)
625 || (mb[1] != 0xffff)) {
626 if (vha->vp_idx != (mb[3] & 0xff))
630 /* Global event -- port logout or port unavailable. */
631 if (mb[1] == 0xffff && mb[2] == 0x7) {
632 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
634 DEBUG(printk(KERN_INFO
635 "scsi(%ld): Port unavailable %04x %04x %04x.\n",
636 vha->host_no, mb[1], mb[2], mb[3]));
638 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
639 atomic_set(&vha->loop_state, LOOP_DOWN);
640 atomic_set(&vha->loop_down_timer,
642 vha->device_flags |= DFLG_NO_CABLE;
643 qla2x00_mark_all_devices_lost(vha, 1);
647 atomic_set(&vha->vp_state, VP_FAILED);
648 fc_vport_set_state(vha->fc_vport,
650 qla2x00_mark_all_devices_lost(vha, 1);
653 vha->flags.management_server_logged_in = 0;
654 ha->link_data_rate = PORT_SPEED_UNKNOWN;
659 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
660 * event etc. earlier indicating loop is down) then process
661 * it. Otherwise ignore it and Wait for RSCN to come in.
663 atomic_set(&vha->loop_down_timer, 0);
664 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
665 atomic_read(&vha->loop_state) != LOOP_DEAD) {
666 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
667 "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
672 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
674 DEBUG(printk(KERN_INFO
675 "scsi(%ld): Port database changed %04x %04x %04x.\n",
676 vha->host_no, mb[1], mb[2], mb[3]));
679 * Mark all devices as missing so we will login again.
681 atomic_set(&vha->loop_state, LOOP_UP);
683 qla2x00_mark_all_devices_lost(vha, 1);
685 vha->flags.rscn_queue_overflow = 1;
687 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
688 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
691 case MBA_RSCN_UPDATE: /* State Change Registration */
692 /* Check if the Vport has issued a SCR */
693 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
695 /* Only handle SCNs for our Vport index. */
696 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
699 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
701 DEBUG(printk(KERN_INFO
702 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
703 vha->host_no, mb[1], mb[2], mb[3]));
705 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
706 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
708 if (rscn_entry == host_pid) {
709 DEBUG(printk(KERN_INFO
710 "scsi(%ld): Ignoring RSCN update to local host "
712 vha->host_no, host_pid));
716 /* Ignore reserved bits from RSCN-payload. */
717 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
718 rscn_queue_index = vha->rscn_in_ptr + 1;
719 if (rscn_queue_index == MAX_RSCN_COUNT)
720 rscn_queue_index = 0;
721 if (rscn_queue_index != vha->rscn_out_ptr) {
722 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
723 vha->rscn_in_ptr = rscn_queue_index;
725 vha->flags.rscn_queue_overflow = 1;
728 atomic_set(&vha->loop_state, LOOP_UPDATE);
729 atomic_set(&vha->loop_down_timer, 0);
730 vha->flags.management_server_logged_in = 0;
732 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
733 set_bit(RSCN_UPDATE, &vha->dpc_flags);
734 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
737 /* case MBA_RIO_RESPONSE: */
738 case MBA_ZIO_RESPONSE:
739 DEBUG3(printk("scsi(%ld): [R|Z]IO update completion.\n",
742 if (IS_FWI2_CAPABLE(ha))
743 qla24xx_process_response_queue(vha, rsp);
745 qla2x00_process_response_queue(rsp);
748 case MBA_DISCARD_RND_FRAME:
749 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
750 "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
753 case MBA_TRACE_NOTIFICATION:
754 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
755 vha->host_no, mb[1], mb[2]));
758 case MBA_ISP84XX_ALERT:
759 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
760 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
762 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
764 case A84_PANIC_RECOVERY:
765 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
766 "%04x %04x\n", mb[2], mb[3]);
768 case A84_OP_LOGIN_COMPLETE:
769 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
770 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
771 "firmware version %x\n", ha->cs84xx->op_fw_version));
773 case A84_DIAG_LOGIN_COMPLETE:
774 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
775 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
776 "diagnostic firmware version %x\n",
777 ha->cs84xx->diag_fw_version));
779 case A84_GOLD_LOGIN_COMPLETE:
780 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
781 ha->cs84xx->fw_update = 1;
782 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
783 "firmware version %x\n",
784 ha->cs84xx->gold_fw_version));
787 qla_printk(KERN_ERR, ha,
788 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
789 mb[1], mb[2], mb[3]);
791 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
794 DEBUG2(printk("scsi(%ld): DCBX Started -- %04x %04x %04x\n",
795 vha->host_no, mb[1], mb[2], mb[3]));
797 case MBA_DCBX_PARAM_UPDATE:
798 DEBUG2(printk("scsi(%ld): DCBX Parameters Updated -- "
799 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
801 case MBA_FCF_CONF_ERR:
802 DEBUG2(printk("scsi(%ld): FCF Configuration Error -- "
803 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
805 case MBA_IDC_COMPLETE:
807 case MBA_IDC_TIME_EXT:
808 qla81xx_idc_event(vha, mb[0], mb[1]);
812 if (!vha->vp_idx && ha->num_vhosts)
813 qla2x00_alert_all_vps(rsp, mb);
817 * qla2x00_process_completed_request() - Process a Fast Post response.
818 * @ha: SCSI driver HA context
822 qla2x00_process_completed_request(struct scsi_qla_host *vha,
823 struct req_que *req, uint32_t index)
826 struct qla_hw_data *ha = vha->hw;
828 /* Validate handle. */
829 if (index >= MAX_OUTSTANDING_COMMANDS) {
830 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
831 vha->host_no, index));
832 qla_printk(KERN_WARNING, ha,
833 "Invalid SCSI completion handle %d.\n", index);
835 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
839 sp = req->outstanding_cmds[index];
841 /* Free outstanding command slot. */
842 req->outstanding_cmds[index] = NULL;
844 /* Save ISP completion status */
845 sp->cmd->result = DID_OK << 16;
846 qla2x00_sp_compl(ha, sp);
848 DEBUG2(printk("scsi(%ld) Req:%d: Invalid ISP SCSI completion"
849 " handle(%d)\n", vha->host_no, req->id, index));
850 qla_printk(KERN_WARNING, ha,
851 "Invalid ISP SCSI completion handle\n");
853 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
858 qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
859 struct req_que *req, void *iocb)
861 struct qla_hw_data *ha = vha->hw;
862 sts_entry_t *pkt = iocb;
866 index = LSW(pkt->handle);
867 if (index >= MAX_OUTSTANDING_COMMANDS) {
868 qla_printk(KERN_WARNING, ha,
869 "%s: Invalid completion handle (%x).\n", func, index);
870 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
873 sp = req->outstanding_cmds[index];
875 qla_printk(KERN_WARNING, ha,
876 "%s: Invalid completion handle (%x) -- timed-out.\n", func,
880 if (sp->handle != index) {
881 qla_printk(KERN_WARNING, ha,
882 "%s: SRB handle (%x) mismatch %x.\n", func, sp->handle,
887 req->outstanding_cmds[index] = NULL;
894 qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
895 struct mbx_entry *mbx)
897 const char func[] = "MBX-IOCB";
899 struct qla_hw_data *ha = vha->hw;
902 struct srb_logio *lio;
905 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
911 switch (lio->ctx.type) {
919 qla_printk(KERN_WARNING, ha,
920 "%s: Unrecognized SRB: (%p) type=%d.\n", func, sp,
925 del_timer(&lio->ctx.timer);
928 data[0] = data[1] = 0;
929 if (mbx->entry_status) {
930 DEBUG2(printk(KERN_WARNING
931 "scsi(%ld:%x): Async-%s error entry - entry-status=%x "
932 "status=%x state-flag=%x status-flags=%x.\n",
933 fcport->vha->host_no, sp->handle, type,
934 mbx->entry_status, le16_to_cpu(mbx->status),
935 le16_to_cpu(mbx->state_flags),
936 le16_to_cpu(mbx->status_flags)));
937 DEBUG2(qla2x00_dump_buffer((uint8_t *)mbx, sizeof(*mbx)));
939 data[0] = MBS_COMMAND_ERROR;
940 data[1] = lio->flags & SRB_LOGIN_RETRIED ?
941 QLA_LOGIO_LOGIN_RETRIED: 0;
942 goto done_post_logio_done_work;
945 if (!mbx->status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
946 DEBUG2(printk(KERN_DEBUG
947 "scsi(%ld:%x): Async-%s complete - mbx1=%x.\n",
948 fcport->vha->host_no, sp->handle, type,
949 le16_to_cpu(mbx->mb1)));
951 data[0] = MBS_COMMAND_COMPLETE;
952 if (lio->ctx.type == SRB_LOGIN_CMD && le16_to_cpu(mbx->mb1) & BIT_1)
953 fcport->flags |= FCF_FCP2_DEVICE;
955 goto done_post_logio_done_work;
958 data[0] = le16_to_cpu(mbx->mb0);
960 case MBS_PORT_ID_USED:
961 data[1] = le16_to_cpu(mbx->mb1);
963 case MBS_LOOP_ID_USED:
966 data[0] = MBS_COMMAND_ERROR;
967 data[1] = lio->flags & SRB_LOGIN_RETRIED ?
968 QLA_LOGIO_LOGIN_RETRIED: 0;
972 DEBUG2(printk(KERN_WARNING
973 "scsi(%ld:%x): Async-%s failed - status=%x mb0=%x mb1=%x mb2=%x "
975 fcport->vha->host_no, sp->handle, type, le16_to_cpu(mbx->status),
976 le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
977 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
978 le16_to_cpu(mbx->mb7)));
980 done_post_logio_done_work:
981 lio->ctx.type == SRB_LOGIN_CMD ?
982 qla2x00_post_async_login_done_work(fcport->vha, fcport, data):
983 qla2x00_post_async_logout_done_work(fcport->vha, fcport, data);
989 qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
990 struct sts_entry_24xx *pkt, int iocb_type)
992 const char func[] = "ELS_CT_IOCB";
994 struct qla_hw_data *ha = vha->hw;
996 struct srb_bsg *sp_bsg;
997 struct fc_bsg_job *bsg_job;
998 uint16_t comp_status;
999 uint32_t fw_status[3];
1000 uint8_t* fw_sts_ptr;
1002 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1005 sp_bsg = (struct srb_bsg*)sp->ctx;
1006 bsg_job = sp_bsg->bsg_job;
1009 switch (sp_bsg->ctx.type) {
1010 case SRB_ELS_CMD_RPT:
1011 case SRB_ELS_CMD_HST:
1015 type = "ct pass-through";
1018 qla_printk(KERN_WARNING, ha,
1019 "%s: Unrecognized SRB: (%p) type=%d.\n", func, sp,
1024 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1025 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1026 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1028 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1029 * fc payload to the caller
1031 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1032 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1034 if (comp_status != CS_COMPLETE) {
1035 if (comp_status == CS_DATA_UNDERRUN) {
1036 bsg_job->reply->result = DID_OK << 16;
1037 bsg_job->reply->reply_payload_rcv_len =
1038 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->total_byte_count);
1040 DEBUG2(qla_printk(KERN_WARNING, ha,
1041 "scsi(%ld:0x%x): ELS-CT pass-through-%s error comp_status-status=0x%x "
1042 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
1043 vha->host_no, sp->handle, type, comp_status, fw_status[1], fw_status[2],
1044 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->total_byte_count)));
1045 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1046 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1049 DEBUG2(qla_printk(KERN_WARNING, ha,
1050 "scsi(%ld:0x%x): ELS-CT pass-through-%s error comp_status-status=0x%x "
1051 "error subcode 1=0x%x error subcode 2=0x%x.\n",
1052 vha->host_no, sp->handle, type, comp_status,
1053 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1),
1054 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2)));
1055 bsg_job->reply->result = DID_ERROR << 16;
1056 bsg_job->reply->reply_payload_rcv_len = 0;
1057 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1058 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1060 DEBUG2(qla2x00_dump_buffer((uint8_t *)pkt, sizeof(*pkt)));
1063 bsg_job->reply->result = DID_OK << 16;;
1064 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1065 bsg_job->reply_len = 0;
1068 dma_unmap_sg(&ha->pdev->dev,
1069 bsg_job->request_payload.sg_list,
1070 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1071 dma_unmap_sg(&ha->pdev->dev,
1072 bsg_job->reply_payload.sg_list,
1073 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1074 if ((sp_bsg->ctx.type == SRB_ELS_CMD_HST) ||
1075 (sp_bsg->ctx.type == SRB_CT_CMD))
1078 mempool_free(sp, ha->srb_mempool);
1079 bsg_job->job_done(bsg_job);
1083 qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1084 struct logio_entry_24xx *logio)
1086 const char func[] = "LOGIO-IOCB";
1088 struct qla_hw_data *ha = vha->hw;
1091 struct srb_logio *lio;
1095 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1101 switch (lio->ctx.type) {
1105 case SRB_LOGOUT_CMD:
1109 qla_printk(KERN_WARNING, ha,
1110 "%s: Unrecognized SRB: (%p) type=%d.\n", func, sp,
1115 del_timer(&lio->ctx.timer);
1116 fcport = sp->fcport;
1118 data[0] = data[1] = 0;
1119 if (logio->entry_status) {
1120 DEBUG2(printk(KERN_WARNING
1121 "scsi(%ld:%x): Async-%s error entry - entry-status=%x.\n",
1122 fcport->vha->host_no, sp->handle, type,
1123 logio->entry_status));
1124 DEBUG2(qla2x00_dump_buffer((uint8_t *)logio, sizeof(*logio)));
1126 data[0] = MBS_COMMAND_ERROR;
1127 data[1] = lio->flags & SRB_LOGIN_RETRIED ?
1128 QLA_LOGIO_LOGIN_RETRIED: 0;
1129 goto done_post_logio_done_work;
1132 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
1133 DEBUG2(printk(KERN_DEBUG
1134 "scsi(%ld:%x): Async-%s complete - iop0=%x.\n",
1135 fcport->vha->host_no, sp->handle, type,
1136 le32_to_cpu(logio->io_parameter[0])));
1138 data[0] = MBS_COMMAND_COMPLETE;
1139 if (lio->ctx.type == SRB_LOGOUT_CMD)
1140 goto done_post_logio_done_work;
1142 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1143 if (iop[0] & BIT_4) {
1144 fcport->port_type = FCT_TARGET;
1146 fcport->flags |= FCF_FCP2_DEVICE;
1149 fcport->port_type = FCT_INITIATOR;
1150 if (logio->io_parameter[7] || logio->io_parameter[8])
1151 fcport->supported_classes |= FC_COS_CLASS2;
1152 if (logio->io_parameter[9] || logio->io_parameter[10])
1153 fcport->supported_classes |= FC_COS_CLASS3;
1155 goto done_post_logio_done_work;
1158 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1159 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1161 case LSC_SCODE_PORTID_USED:
1162 data[0] = MBS_PORT_ID_USED;
1163 data[1] = LSW(iop[1]);
1165 case LSC_SCODE_NPORT_USED:
1166 data[0] = MBS_LOOP_ID_USED;
1168 case LSC_SCODE_CMD_FAILED:
1169 if ((iop[1] & 0xff) == 0x05) {
1170 data[0] = MBS_NOT_LOGGED_IN;
1175 data[0] = MBS_COMMAND_ERROR;
1176 data[1] = lio->flags & SRB_LOGIN_RETRIED ?
1177 QLA_LOGIO_LOGIN_RETRIED: 0;
1181 DEBUG2(printk(KERN_WARNING
1182 "scsi(%ld:%x): Async-%s failed - comp=%x iop0=%x iop1=%x.\n",
1183 fcport->vha->host_no, sp->handle, type,
1184 le16_to_cpu(logio->comp_status),
1185 le32_to_cpu(logio->io_parameter[0]),
1186 le32_to_cpu(logio->io_parameter[1])));
1188 done_post_logio_done_work:
1189 lio->ctx.type == SRB_LOGIN_CMD ?
1190 qla2x00_post_async_login_done_work(fcport->vha, fcport, data):
1191 qla2x00_post_async_logout_done_work(fcport->vha, fcport, data);
1197 * qla2x00_process_response_queue() - Process response queue entries.
1198 * @ha: SCSI driver HA context
1201 qla2x00_process_response_queue(struct rsp_que *rsp)
1203 struct scsi_qla_host *vha;
1204 struct qla_hw_data *ha = rsp->hw;
1205 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1207 uint16_t handle_cnt;
1210 vha = pci_get_drvdata(ha->pdev);
1212 if (!vha->flags.online)
1215 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1216 pkt = (sts_entry_t *)rsp->ring_ptr;
1219 if (rsp->ring_index == rsp->length) {
1220 rsp->ring_index = 0;
1221 rsp->ring_ptr = rsp->ring;
1226 if (pkt->entry_status != 0) {
1227 DEBUG3(printk(KERN_INFO
1228 "scsi(%ld): Process error entry.\n", vha->host_no));
1230 qla2x00_error_entry(vha, rsp, pkt);
1231 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1236 switch (pkt->entry_type) {
1238 qla2x00_status_entry(vha, rsp, pkt);
1240 case STATUS_TYPE_21:
1241 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1242 for (cnt = 0; cnt < handle_cnt; cnt++) {
1243 qla2x00_process_completed_request(vha, rsp->req,
1244 ((sts21_entry_t *)pkt)->handle[cnt]);
1247 case STATUS_TYPE_22:
1248 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1249 for (cnt = 0; cnt < handle_cnt; cnt++) {
1250 qla2x00_process_completed_request(vha, rsp->req,
1251 ((sts22_entry_t *)pkt)->handle[cnt]);
1254 case STATUS_CONT_TYPE:
1255 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
1258 qla2x00_mbx_iocb_entry(vha, rsp->req,
1259 (struct mbx_entry *)pkt);
1261 /* Type Not Supported. */
1262 DEBUG4(printk(KERN_WARNING
1263 "scsi(%ld): Received unknown response pkt type %x "
1264 "entry status=%x.\n",
1265 vha->host_no, pkt->entry_type, pkt->entry_status));
1268 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1272 /* Adjust ring index */
1273 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
1277 qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len,
1278 struct rsp_que *rsp)
1280 struct scsi_cmnd *cp = sp->cmd;
1282 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1283 sense_len = SCSI_SENSE_BUFFERSIZE;
1285 sp->request_sense_length = sense_len;
1286 sp->request_sense_ptr = cp->sense_buffer;
1287 if (sp->request_sense_length > 32)
1290 memcpy(cp->sense_buffer, sense_data, sense_len);
1292 sp->request_sense_ptr += sense_len;
1293 sp->request_sense_length -= sense_len;
1294 if (sp->request_sense_length != 0)
1295 rsp->status_srb = sp;
1297 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
1298 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
1299 cp->device->channel, cp->device->id, cp->device->lun, cp,
1300 cp->serial_number));
1302 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len));
1306 * qla2x00_status_entry() - Process a Status IOCB entry.
1307 * @ha: SCSI driver HA context
1308 * @pkt: Entry pointer
1311 qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
1315 struct scsi_cmnd *cp;
1317 struct sts_entry_24xx *sts24;
1318 uint16_t comp_status;
1319 uint16_t scsi_status;
1320 uint8_t lscsi_status;
1322 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
1323 uint8_t *rsp_info, *sense_data;
1324 struct qla_hw_data *ha = vha->hw;
1327 struct req_que *req;
1329 sts = (sts_entry_t *) pkt;
1330 sts24 = (struct sts_entry_24xx *) pkt;
1331 if (IS_FWI2_CAPABLE(ha)) {
1332 comp_status = le16_to_cpu(sts24->comp_status);
1333 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1335 comp_status = le16_to_cpu(sts->comp_status);
1336 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1338 handle = (uint32_t) LSW(sts->handle);
1339 que = MSW(sts->handle);
1340 req = ha->req_q_map[que];
1341 /* Fast path completion. */
1342 if (comp_status == CS_COMPLETE && scsi_status == 0) {
1343 qla2x00_process_completed_request(vha, req, handle);
1348 /* Validate handle. */
1349 if (handle < MAX_OUTSTANDING_COMMANDS) {
1350 sp = req->outstanding_cmds[handle];
1351 req->outstanding_cmds[handle] = NULL;
1356 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
1358 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
1360 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1361 qla2xxx_wake_dpc(vha);
1366 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
1367 "pkt->handle=%d sp=%p.\n", vha->host_no, handle, sp));
1368 qla_printk(KERN_WARNING, ha,
1369 "Command is NULL: already returned to OS (sp=%p)\n", sp);
1374 lscsi_status = scsi_status & STATUS_MASK;
1376 fcport = sp->fcport;
1378 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
1379 if (IS_FWI2_CAPABLE(ha)) {
1380 if (scsi_status & SS_SENSE_LEN_VALID)
1381 sense_len = le32_to_cpu(sts24->sense_len);
1382 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1383 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1384 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
1385 resid_len = le32_to_cpu(sts24->rsp_residual_count);
1386 if (comp_status == CS_DATA_UNDERRUN)
1387 fw_resid_len = le32_to_cpu(sts24->residual_len);
1388 rsp_info = sts24->data;
1389 sense_data = sts24->data;
1390 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
1392 if (scsi_status & SS_SENSE_LEN_VALID)
1393 sense_len = le16_to_cpu(sts->req_sense_length);
1394 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1395 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
1396 resid_len = le32_to_cpu(sts->residual_length);
1397 rsp_info = sts->rsp_info;
1398 sense_data = sts->req_sense_data;
1401 /* Check for any FCP transport errors. */
1402 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
1403 /* Sense data lies beyond any FCP RESPONSE data. */
1404 if (IS_FWI2_CAPABLE(ha))
1405 sense_data += rsp_info_len;
1406 if (rsp_info_len > 3 && rsp_info[3]) {
1407 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1408 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
1409 "retrying command\n", vha->host_no,
1410 cp->device->channel, cp->device->id,
1411 cp->device->lun, rsp_info_len, rsp_info[0],
1412 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1413 rsp_info[5], rsp_info[6], rsp_info[7]));
1415 cp->result = DID_BUS_BUSY << 16;
1416 qla2x00_sp_compl(ha, sp);
1421 /* Check for overrun. */
1422 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1423 scsi_status & SS_RESIDUAL_OVER)
1424 comp_status = CS_DATA_OVERRUN;
1427 * Based on Host and scsi status generate status code for Linux
1429 switch (comp_status) {
1432 if (scsi_status == 0) {
1433 cp->result = DID_OK << 16;
1436 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
1438 scsi_set_resid(cp, resid);
1440 if (!lscsi_status &&
1441 ((unsigned)(scsi_bufflen(cp) - resid) <
1443 qla_printk(KERN_INFO, ha,
1444 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1445 "detected (%x of %x bytes)...returning "
1446 "error status.\n", vha->host_no,
1447 cp->device->channel, cp->device->id,
1448 cp->device->lun, resid,
1451 cp->result = DID_ERROR << 16;
1455 cp->result = DID_OK << 16 | lscsi_status;
1457 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1458 DEBUG2(printk(KERN_INFO
1459 "scsi(%ld): QUEUE FULL status detected "
1460 "0x%x-0x%x.\n", vha->host_no, comp_status,
1464 if (lscsi_status != SS_CHECK_CONDITION)
1467 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1468 if (!(scsi_status & SS_SENSE_LEN_VALID))
1471 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
1474 case CS_DATA_UNDERRUN:
1475 DEBUG2(printk(KERN_INFO
1476 "scsi(%ld:%d:%d) UNDERRUN status detected 0x%x-0x%x. "
1477 "resid=0x%x fw_resid=0x%x cdb=0x%x os_underflow=0x%x\n",
1478 vha->host_no, cp->device->id, cp->device->lun, comp_status,
1479 scsi_status, resid_len, fw_resid_len, cp->cmnd[0],
1482 /* Use F/W calculated residual length. */
1483 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
1484 scsi_set_resid(cp, resid);
1485 if (scsi_status & SS_RESIDUAL_UNDER) {
1486 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
1488 "scsi(%ld:%d:%d:%d) Dropped frame(s) "
1489 "detected (%x of %x bytes)...residual "
1490 "length mismatch...retrying command.\n",
1491 vha->host_no, cp->device->channel,
1492 cp->device->id, cp->device->lun, resid,
1495 cp->result = DID_ERROR << 16 | lscsi_status;
1499 if (!lscsi_status &&
1500 ((unsigned)(scsi_bufflen(cp) - resid) <
1502 qla_printk(KERN_INFO, ha,
1503 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1504 "detected (%x of %x bytes)...returning "
1505 "error status.\n", vha->host_no,
1506 cp->device->channel, cp->device->id,
1507 cp->device->lun, resid, scsi_bufflen(cp));
1509 cp->result = DID_ERROR << 16;
1512 } else if (!lscsi_status) {
1514 "scsi(%ld:%d:%d:%d) Dropped frame(s) detected "
1515 "(%x of %x bytes)...firmware reported underrun..."
1516 "retrying command.\n", vha->host_no,
1517 cp->device->channel, cp->device->id,
1518 cp->device->lun, resid, scsi_bufflen(cp)));
1520 cp->result = DID_ERROR << 16;
1524 cp->result = DID_OK << 16 | lscsi_status;
1527 * Check to see if SCSI Status is non zero. If so report SCSI
1530 if (lscsi_status != 0) {
1531 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1532 DEBUG2(printk(KERN_INFO
1533 "scsi(%ld): QUEUE FULL status detected "
1534 "0x%x-0x%x.\n", vha->host_no, comp_status,
1538 if (lscsi_status != SS_CHECK_CONDITION)
1541 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1542 if (!(scsi_status & SS_SENSE_LEN_VALID))
1545 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
1549 case CS_DATA_OVERRUN:
1550 DEBUG2(printk(KERN_INFO
1551 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1552 vha->host_no, cp->device->id, cp->device->lun, comp_status,
1554 DEBUG2(printk(KERN_INFO
1555 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1556 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1557 cp->cmnd[4], cp->cmnd[5]));
1558 DEBUG2(printk(KERN_INFO
1559 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1561 cp->serial_number, scsi_bufflen(cp), resid_len));
1563 cp->result = DID_ERROR << 16;
1566 case CS_PORT_LOGGED_OUT:
1567 case CS_PORT_CONFIG_CHG:
1570 case CS_PORT_UNAVAILABLE:
1572 * If the port is in Target Down state, return all IOs for this
1573 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1576 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1577 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1578 vha->host_no, cp->device->id, cp->device->lun,
1579 cp->serial_number, comp_status,
1580 atomic_read(&fcport->state)));
1583 * We are going to have the fc class block the rport
1584 * while we try to recover so instruct the mid layer
1585 * to requeue until the class decides how to handle this.
1587 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1588 if (atomic_read(&fcport->state) == FCS_ONLINE)
1589 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1593 DEBUG2(printk(KERN_INFO
1594 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1595 vha->host_no, comp_status, scsi_status));
1597 cp->result = DID_RESET << 16;
1602 * hv2.19.12 - DID_ABORT does not retry the request if we
1603 * aborted this request then abort otherwise it must be a
1606 DEBUG2(printk(KERN_INFO
1607 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1608 vha->host_no, comp_status, scsi_status));
1610 cp->result = DID_RESET << 16;
1615 * We are going to have the fc class block the rport
1616 * while we try to recover so instruct the mid layer
1617 * to requeue until the class decides how to handle this.
1619 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1621 if (IS_FWI2_CAPABLE(ha)) {
1622 DEBUG2(printk(KERN_INFO
1623 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1624 "0x%x-0x%x\n", vha->host_no, cp->device->channel,
1625 cp->device->id, cp->device->lun, comp_status,
1629 DEBUG2(printk(KERN_INFO
1630 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1631 "sflags=%x.\n", vha->host_no, cp->device->channel,
1632 cp->device->id, cp->device->lun, comp_status, scsi_status,
1633 le16_to_cpu(sts->status_flags)));
1635 /* Check to see if logout occurred. */
1636 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
1637 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1641 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1642 "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
1643 qla_printk(KERN_INFO, ha,
1644 "Unknown status detected 0x%x-0x%x.\n",
1645 comp_status, scsi_status);
1647 cp->result = DID_ERROR << 16;
1651 /* Place command on done queue. */
1652 if (rsp->status_srb == NULL)
1653 qla2x00_sp_compl(ha, sp);
1657 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1658 * @ha: SCSI driver HA context
1659 * @pkt: Entry pointer
1661 * Extended sense data.
1664 qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
1666 uint8_t sense_sz = 0;
1667 struct qla_hw_data *ha = rsp->hw;
1668 srb_t *sp = rsp->status_srb;
1669 struct scsi_cmnd *cp;
1671 if (sp != NULL && sp->request_sense_length != 0) {
1674 DEBUG2(printk("%s(): Cmd already returned back to OS "
1675 "sp=%p.\n", __func__, sp));
1676 qla_printk(KERN_INFO, ha,
1677 "cmd is NULL: already returned to OS (sp=%p)\n",
1680 rsp->status_srb = NULL;
1684 if (sp->request_sense_length > sizeof(pkt->data)) {
1685 sense_sz = sizeof(pkt->data);
1687 sense_sz = sp->request_sense_length;
1690 /* Move sense data. */
1691 if (IS_FWI2_CAPABLE(ha))
1692 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
1693 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1694 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1696 sp->request_sense_ptr += sense_sz;
1697 sp->request_sense_length -= sense_sz;
1699 /* Place command on done queue. */
1700 if (sp->request_sense_length == 0) {
1701 rsp->status_srb = NULL;
1702 qla2x00_sp_compl(ha, sp);
1708 * qla2x00_error_entry() - Process an error entry.
1709 * @ha: SCSI driver HA context
1710 * @pkt: Entry pointer
1713 qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
1716 struct qla_hw_data *ha = vha->hw;
1717 uint32_t handle = LSW(pkt->handle);
1718 uint16_t que = MSW(pkt->handle);
1719 struct req_que *req = ha->req_q_map[que];
1720 #if defined(QL_DEBUG_LEVEL_2)
1721 if (pkt->entry_status & RF_INV_E_ORDER)
1722 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1723 else if (pkt->entry_status & RF_INV_E_COUNT)
1724 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1725 else if (pkt->entry_status & RF_INV_E_PARAM)
1726 qla_printk(KERN_ERR, ha,
1727 "%s: Invalid Entry Parameter\n", __func__);
1728 else if (pkt->entry_status & RF_INV_E_TYPE)
1729 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1730 else if (pkt->entry_status & RF_BUSY)
1731 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1733 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1736 /* Validate handle. */
1737 if (handle < MAX_OUTSTANDING_COMMANDS)
1738 sp = req->outstanding_cmds[handle];
1743 /* Free outstanding command slot. */
1744 req->outstanding_cmds[handle] = NULL;
1746 /* Bad payload or header */
1747 if (pkt->entry_status &
1748 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1749 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1750 sp->cmd->result = DID_ERROR << 16;
1751 } else if (pkt->entry_status & RF_BUSY) {
1752 sp->cmd->result = DID_BUS_BUSY << 16;
1754 sp->cmd->result = DID_ERROR << 16;
1756 qla2x00_sp_compl(ha, sp);
1758 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1759 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
1760 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1762 qla_printk(KERN_WARNING, ha,
1763 "Error entry - invalid handle\n");
1765 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1766 qla2xxx_wake_dpc(vha);
1771 * qla24xx_mbx_completion() - Process mailbox command completions.
1772 * @ha: SCSI driver HA context
1773 * @mb0: Mailbox0 register
1776 qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
1779 uint16_t __iomem *wptr;
1780 struct qla_hw_data *ha = vha->hw;
1781 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1783 /* Load return mailbox registers. */
1784 ha->flags.mbox_int = 1;
1785 ha->mailbox_out[0] = mb0;
1786 wptr = (uint16_t __iomem *)®->mailbox1;
1788 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1789 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1794 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1795 __func__, vha->host_no, ha->mcp->mb[0]));
1797 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1798 __func__, vha->host_no));
1803 * qla24xx_process_response_queue() - Process response queue entries.
1804 * @ha: SCSI driver HA context
1806 void qla24xx_process_response_queue(struct scsi_qla_host *vha,
1807 struct rsp_que *rsp)
1809 struct sts_entry_24xx *pkt;
1811 if (!vha->flags.online)
1814 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1815 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
1818 if (rsp->ring_index == rsp->length) {
1819 rsp->ring_index = 0;
1820 rsp->ring_ptr = rsp->ring;
1825 if (pkt->entry_status != 0) {
1826 DEBUG3(printk(KERN_INFO
1827 "scsi(%ld): Process error entry.\n", vha->host_no));
1829 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
1830 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1835 switch (pkt->entry_type) {
1837 qla2x00_status_entry(vha, rsp, pkt);
1839 case STATUS_CONT_TYPE:
1840 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
1842 case VP_RPT_ID_IOCB_TYPE:
1843 qla24xx_report_id_acquisition(vha,
1844 (struct vp_rpt_id_entry_24xx *)pkt);
1846 case LOGINOUT_PORT_IOCB_TYPE:
1847 qla24xx_logio_entry(vha, rsp->req,
1848 (struct logio_entry_24xx *)pkt);
1851 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1852 clear_bit(MBX_INTERRUPT, &vha->hw->mbx_cmd_flags);
1855 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
1858 /* Type Not Supported. */
1859 DEBUG4(printk(KERN_WARNING
1860 "scsi(%ld): Received unknown response pkt type %x "
1861 "entry status=%x.\n",
1862 vha->host_no, pkt->entry_type, pkt->entry_status));
1865 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1869 /* Adjust ring index */
1870 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
1874 qla2xxx_check_risc_status(scsi_qla_host_t *vha)
1878 struct qla_hw_data *ha = vha->hw;
1879 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1881 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
1885 WRT_REG_DWORD(®->iobase_addr, 0x7C00);
1886 RD_REG_DWORD(®->iobase_addr);
1887 WRT_REG_DWORD(®->iobase_window, 0x0001);
1888 for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1889 rval == QLA_SUCCESS; cnt--) {
1891 WRT_REG_DWORD(®->iobase_window, 0x0001);
1894 rval = QLA_FUNCTION_TIMEOUT;
1896 if (rval == QLA_SUCCESS)
1899 WRT_REG_DWORD(®->iobase_window, 0x0003);
1900 for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1901 rval == QLA_SUCCESS; cnt--) {
1903 WRT_REG_DWORD(®->iobase_window, 0x0003);
1906 rval = QLA_FUNCTION_TIMEOUT;
1908 if (rval != QLA_SUCCESS)
1912 if (RD_REG_DWORD(®->iobase_c8) & BIT_3)
1913 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1916 WRT_REG_DWORD(®->iobase_window, 0x0000);
1917 RD_REG_DWORD(®->iobase_window);
1921 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1923 * @dev_id: SCSI driver HA context
1925 * Called by system whenever the host adapter generates an interrupt.
1927 * Returns handled flag.
1930 qla24xx_intr_handler(int irq, void *dev_id)
1932 scsi_qla_host_t *vha;
1933 struct qla_hw_data *ha;
1934 struct device_reg_24xx __iomem *reg;
1940 struct rsp_que *rsp;
1941 unsigned long flags;
1943 rsp = (struct rsp_que *) dev_id;
1946 "%s(): NULL response queue pointer\n", __func__);
1951 reg = &ha->iobase->isp24;
1954 if (unlikely(pci_channel_offline(ha->pdev)))
1957 spin_lock_irqsave(&ha->hardware_lock, flags);
1958 vha = pci_get_drvdata(ha->pdev);
1959 for (iter = 50; iter--; ) {
1960 stat = RD_REG_DWORD(®->host_status);
1961 if (stat & HSRX_RISC_PAUSED) {
1962 if (unlikely(pci_channel_offline(ha->pdev)))
1965 hccr = RD_REG_DWORD(®->hccr);
1967 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1968 "Dumping firmware!\n", hccr);
1970 qla2xxx_check_risc_status(vha);
1972 ha->isp_ops->fw_dump(vha, 1);
1973 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1975 } else if ((stat & HSRX_RISC_INT) == 0)
1978 switch (stat & 0xff) {
1983 qla24xx_mbx_completion(vha, MSW(stat));
1984 status |= MBX_INTERRUPT;
1989 mb[1] = RD_REG_WORD(®->mailbox1);
1990 mb[2] = RD_REG_WORD(®->mailbox2);
1991 mb[3] = RD_REG_WORD(®->mailbox3);
1992 qla2x00_async_event(vha, rsp, mb);
1996 qla24xx_process_response_queue(vha, rsp);
1999 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
2001 vha->host_no, stat & 0xff));
2004 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2005 RD_REG_DWORD_RELAXED(®->hccr);
2007 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2009 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
2010 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
2011 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
2012 complete(&ha->mbx_intr_comp);
2019 qla24xx_msix_rsp_q(int irq, void *dev_id)
2021 struct qla_hw_data *ha;
2022 struct rsp_que *rsp;
2023 struct device_reg_24xx __iomem *reg;
2024 struct scsi_qla_host *vha;
2025 unsigned long flags;
2027 rsp = (struct rsp_que *) dev_id;
2030 "%s(): NULL response queue pointer\n", __func__);
2034 reg = &ha->iobase->isp24;
2036 spin_lock_irqsave(&ha->hardware_lock, flags);
2038 vha = pci_get_drvdata(ha->pdev);
2039 qla24xx_process_response_queue(vha, rsp);
2040 if (!ha->flags.disable_msix_handshake) {
2041 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2042 RD_REG_DWORD_RELAXED(®->hccr);
2044 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2050 qla25xx_msix_rsp_q(int irq, void *dev_id)
2052 struct qla_hw_data *ha;
2053 struct rsp_que *rsp;
2054 struct device_reg_24xx __iomem *reg;
2055 unsigned long flags;
2057 rsp = (struct rsp_que *) dev_id;
2060 "%s(): NULL response queue pointer\n", __func__);
2065 /* Clear the interrupt, if enabled, for this response queue */
2066 if (rsp->options & ~BIT_6) {
2067 reg = &ha->iobase->isp24;
2068 spin_lock_irqsave(&ha->hardware_lock, flags);
2069 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2070 RD_REG_DWORD_RELAXED(®->hccr);
2071 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2073 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2079 qla24xx_msix_default(int irq, void *dev_id)
2081 scsi_qla_host_t *vha;
2082 struct qla_hw_data *ha;
2083 struct rsp_que *rsp;
2084 struct device_reg_24xx __iomem *reg;
2089 unsigned long flags;
2091 rsp = (struct rsp_que *) dev_id;
2094 "%s(): NULL response queue pointer\n", __func__));
2098 reg = &ha->iobase->isp24;
2101 spin_lock_irqsave(&ha->hardware_lock, flags);
2102 vha = pci_get_drvdata(ha->pdev);
2104 stat = RD_REG_DWORD(®->host_status);
2105 if (stat & HSRX_RISC_PAUSED) {
2106 if (unlikely(pci_channel_offline(ha->pdev)))
2109 hccr = RD_REG_DWORD(®->hccr);
2111 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
2112 "Dumping firmware!\n", hccr);
2114 qla2xxx_check_risc_status(vha);
2116 ha->isp_ops->fw_dump(vha, 1);
2117 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2119 } else if ((stat & HSRX_RISC_INT) == 0)
2122 switch (stat & 0xff) {
2127 qla24xx_mbx_completion(vha, MSW(stat));
2128 status |= MBX_INTERRUPT;
2133 mb[1] = RD_REG_WORD(®->mailbox1);
2134 mb[2] = RD_REG_WORD(®->mailbox2);
2135 mb[3] = RD_REG_WORD(®->mailbox3);
2136 qla2x00_async_event(vha, rsp, mb);
2140 qla24xx_process_response_queue(vha, rsp);
2143 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
2145 vha->host_no, stat & 0xff));
2148 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2150 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2152 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
2153 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
2154 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
2155 complete(&ha->mbx_intr_comp);
2160 /* Interrupt handling helpers. */
2162 struct qla_init_msix_entry {
2164 irq_handler_t handler;
2167 static struct qla_init_msix_entry msix_entries[3] = {
2168 { "qla2xxx (default)", qla24xx_msix_default },
2169 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
2170 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
2174 qla24xx_disable_msix(struct qla_hw_data *ha)
2177 struct qla_msix_entry *qentry;
2179 for (i = 0; i < ha->msix_count; i++) {
2180 qentry = &ha->msix_entries[i];
2181 if (qentry->have_irq)
2182 free_irq(qentry->vector, qentry->rsp);
2184 pci_disable_msix(ha->pdev);
2185 kfree(ha->msix_entries);
2186 ha->msix_entries = NULL;
2187 ha->flags.msix_enabled = 0;
2191 qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
2193 #define MIN_MSIX_COUNT 2
2195 struct msix_entry *entries;
2196 struct qla_msix_entry *qentry;
2198 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
2203 for (i = 0; i < ha->msix_count; i++)
2204 entries[i].entry = i;
2206 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
2208 if (ret < MIN_MSIX_COUNT)
2211 qla_printk(KERN_WARNING, ha,
2212 "MSI-X: Failed to enable support -- %d/%d\n"
2213 " Retry with %d vectors\n", ha->msix_count, ret, ret);
2214 ha->msix_count = ret;
2215 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
2218 qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
2219 " support, giving up -- %d/%d\n",
2220 ha->msix_count, ret);
2223 ha->max_rsp_queues = ha->msix_count - 1;
2225 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
2226 ha->msix_count, GFP_KERNEL);
2227 if (!ha->msix_entries) {
2231 ha->flags.msix_enabled = 1;
2233 for (i = 0; i < ha->msix_count; i++) {
2234 qentry = &ha->msix_entries[i];
2235 qentry->vector = entries[i].vector;
2236 qentry->entry = entries[i].entry;
2237 qentry->have_irq = 0;
2241 /* Enable MSI-X vectors for the base queue */
2242 for (i = 0; i < 2; i++) {
2243 qentry = &ha->msix_entries[i];
2244 ret = request_irq(qentry->vector, msix_entries[i].handler,
2245 0, msix_entries[i].name, rsp);
2247 qla_printk(KERN_WARNING, ha,
2248 "MSI-X: Unable to register handler -- %x/%d.\n",
2249 qentry->vector, ret);
2250 qla24xx_disable_msix(ha);
2254 qentry->have_irq = 1;
2259 /* Enable MSI-X vector for response queue update for queue 0 */
2260 if (ha->mqiobase && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
2269 qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
2272 device_reg_t __iomem *reg = ha->iobase;
2274 /* If possible, enable MSI-X. */
2275 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
2276 !IS_QLA8432(ha) && !IS_QLA8001(ha))
2279 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
2280 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
2281 DEBUG2(qla_printk(KERN_WARNING, ha,
2282 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
2283 ha->pdev->revision, ha->fw_attributes));
2288 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
2289 (ha->pdev->subsystem_device == 0x7040 ||
2290 ha->pdev->subsystem_device == 0x7041 ||
2291 ha->pdev->subsystem_device == 0x1705)) {
2292 DEBUG2(qla_printk(KERN_WARNING, ha,
2293 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
2294 ha->pdev->subsystem_vendor,
2295 ha->pdev->subsystem_device));
2300 ret = qla24xx_enable_msix(ha, rsp);
2302 DEBUG2(qla_printk(KERN_INFO, ha,
2303 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
2304 ha->fw_attributes));
2305 goto clear_risc_ints;
2307 qla_printk(KERN_WARNING, ha,
2308 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
2311 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
2315 ret = pci_enable_msi(ha->pdev);
2317 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
2318 ha->flags.msi_enabled = 1;
2322 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
2323 IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
2325 qla_printk(KERN_WARNING, ha,
2326 "Failed to reserve interrupt %d already in use.\n",
2330 ha->flags.inta_enabled = 1;
2334 * FIXME: Noted that 8014s were being dropped during NK testing.
2335 * Timing deltas during MSI-X/INTa transitions?
2339 spin_lock_irq(&ha->hardware_lock);
2340 if (IS_FWI2_CAPABLE(ha)) {
2341 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT);
2342 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT);
2344 WRT_REG_WORD(®->isp.semaphore, 0);
2345 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT);
2346 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT);
2348 spin_unlock_irq(&ha->hardware_lock);
2355 qla2x00_free_irqs(scsi_qla_host_t *vha)
2357 struct qla_hw_data *ha = vha->hw;
2358 struct rsp_que *rsp = ha->rsp_q_map[0];
2360 if (ha->flags.msix_enabled)
2361 qla24xx_disable_msix(ha);
2362 else if (ha->flags.msi_enabled) {
2363 free_irq(ha->pdev->irq, rsp);
2364 pci_disable_msi(ha->pdev);
2366 free_irq(ha->pdev->irq, rsp);
2370 int qla25xx_request_irq(struct rsp_que *rsp)
2372 struct qla_hw_data *ha = rsp->hw;
2373 struct qla_init_msix_entry *intr = &msix_entries[2];
2374 struct qla_msix_entry *msix = rsp->msix;
2377 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2379 qla_printk(KERN_WARNING, ha,
2380 "MSI-X: Unable to register handler -- %x/%d.\n",