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 <scsi/scsi_tcq.h>
12 static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
13 static void qla2x00_process_completed_request(struct scsi_qla_host *,
14 struct req_que *, uint32_t);
15 static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
16 static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
17 static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
21 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
23 * @dev_id: SCSI driver HA context
25 * Called by system whenever the host adapter generates an interrupt.
27 * Returns handled flag.
30 qla2100_intr_handler(int irq, void *dev_id)
33 struct qla_hw_data *ha;
34 struct device_reg_2xxx __iomem *reg;
41 rsp = (struct rsp_que *) dev_id;
44 "%s(): NULL response queue pointer\n", __func__);
49 reg = &ha->iobase->isp;
52 spin_lock(&ha->hardware_lock);
53 vha = pci_get_drvdata(ha->pdev);
54 for (iter = 50; iter--; ) {
55 hccr = RD_REG_WORD(®->hccr);
56 if (hccr & HCCR_RISC_PAUSE) {
57 if (pci_channel_offline(ha->pdev))
61 * Issue a "HARD" reset in order for the RISC interrupt
62 * bit to be cleared. Schedule a big hammmer to get
63 * out of the RISC PAUSED state.
65 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
66 RD_REG_WORD(®->hccr);
68 ha->isp_ops->fw_dump(vha, 1);
69 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
71 } else if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0)
74 if (RD_REG_WORD(®->semaphore) & BIT_0) {
75 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
76 RD_REG_WORD(®->hccr);
78 /* Get mailbox data. */
79 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
80 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
81 qla2x00_mbx_completion(vha, mb[0]);
82 status |= MBX_INTERRUPT;
83 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
84 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
85 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
86 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
87 qla2x00_async_event(vha, rsp, mb);
90 DEBUG2(printk("scsi(%ld): Unrecognized "
91 "interrupt type (%d).\n",
92 vha->host_no, mb[0]));
94 /* Release mailbox registers. */
95 WRT_REG_WORD(®->semaphore, 0);
96 RD_REG_WORD(®->semaphore);
98 qla2x00_process_response_queue(rsp);
100 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
101 RD_REG_WORD(®->hccr);
104 spin_unlock(&ha->hardware_lock);
106 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
107 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
108 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
109 complete(&ha->mbx_intr_comp);
112 return (IRQ_HANDLED);
116 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
118 * @dev_id: SCSI driver HA context
120 * Called by system whenever the host adapter generates an interrupt.
122 * Returns handled flag.
125 qla2300_intr_handler(int irq, void *dev_id)
127 scsi_qla_host_t *vha;
128 struct device_reg_2xxx __iomem *reg;
135 struct qla_hw_data *ha;
137 rsp = (struct rsp_que *) dev_id;
140 "%s(): NULL response queue pointer\n", __func__);
145 reg = &ha->iobase->isp;
148 spin_lock(&ha->hardware_lock);
149 vha = pci_get_drvdata(ha->pdev);
150 for (iter = 50; iter--; ) {
151 stat = RD_REG_DWORD(®->u.isp2300.host_status);
152 if (stat & HSR_RISC_PAUSED) {
153 if (pci_channel_offline(ha->pdev))
156 hccr = RD_REG_WORD(®->hccr);
157 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
158 qla_printk(KERN_INFO, ha, "Parity error -- "
159 "HCCR=%x, Dumping firmware!\n", hccr);
161 qla_printk(KERN_INFO, ha, "RISC paused -- "
162 "HCCR=%x, Dumping firmware!\n", hccr);
165 * Issue a "HARD" reset in order for the RISC
166 * interrupt bit to be cleared. Schedule a big
167 * hammmer to get out of the RISC PAUSED state.
169 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
170 RD_REG_WORD(®->hccr);
172 ha->isp_ops->fw_dump(vha, 1);
173 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
175 } else if ((stat & HSR_RISC_INT) == 0)
178 switch (stat & 0xff) {
183 qla2x00_mbx_completion(vha, MSW(stat));
184 status |= MBX_INTERRUPT;
186 /* Release mailbox registers. */
187 WRT_REG_WORD(®->semaphore, 0);
191 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
192 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
193 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
194 qla2x00_async_event(vha, rsp, mb);
197 qla2x00_process_response_queue(rsp);
200 mb[0] = MBA_CMPLT_1_16BIT;
202 qla2x00_async_event(vha, rsp, mb);
205 mb[0] = MBA_SCSI_COMPLETION;
207 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
208 qla2x00_async_event(vha, rsp, mb);
211 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
213 vha->host_no, stat & 0xff));
216 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
217 RD_REG_WORD_RELAXED(®->hccr);
219 spin_unlock(&ha->hardware_lock);
221 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
222 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
223 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
224 complete(&ha->mbx_intr_comp);
227 return (IRQ_HANDLED);
231 * qla2x00_mbx_completion() - Process mailbox command completions.
232 * @ha: SCSI driver HA context
233 * @mb0: Mailbox0 register
236 qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
239 uint16_t __iomem *wptr;
240 struct qla_hw_data *ha = vha->hw;
241 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
243 /* Load return mailbox registers. */
244 ha->flags.mbox_int = 1;
245 ha->mailbox_out[0] = mb0;
246 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
248 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
249 if (IS_QLA2200(ha) && cnt == 8)
250 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
251 if (cnt == 4 || cnt == 5)
252 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
254 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
260 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
261 __func__, vha->host_no, ha->mcp->mb[0]));
263 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
264 __func__, vha->host_no));
269 qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
271 static char *event[] =
272 { "Complete", "Request Notification", "Time Extension" };
274 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
275 uint16_t __iomem *wptr;
276 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
278 /* Seed data -- mailbox1 -> mailbox7. */
279 wptr = (uint16_t __iomem *)®24->mailbox1;
280 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
281 mb[cnt] = RD_REG_WORD(wptr);
283 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
284 "%04x %04x %04x %04x %04x %04x %04x.\n", vha->host_no,
286 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6]));
288 /* Acknowledgement needed? [Notify && non-zero timeout]. */
289 timeout = (descr >> 8) & 0xf;
290 if (aen != MBA_IDC_NOTIFY || !timeout)
293 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
294 "ACK timeout=%d.\n", vha->host_no, event[aen & 0xff], timeout));
296 rval = qla2x00_post_idc_ack_work(vha, mb);
297 if (rval != QLA_SUCCESS)
298 qla_printk(KERN_WARNING, vha->hw,
299 "IDC failed to post ACK.\n");
303 * qla2x00_async_event() - Process aynchronous events.
304 * @ha: SCSI driver HA context
305 * @mb: Mailbox registers (0 - 3)
308 qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
311 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
316 struct qla_hw_data *ha = vha->hw;
317 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
318 uint32_t rscn_entry, host_pid;
319 uint8_t rscn_queue_index;
322 /* Setup to process RIO completion. */
327 case MBA_SCSI_COMPLETION:
328 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
331 case MBA_CMPLT_1_16BIT:
334 mb[0] = MBA_SCSI_COMPLETION;
336 case MBA_CMPLT_2_16BIT:
340 mb[0] = MBA_SCSI_COMPLETION;
342 case MBA_CMPLT_3_16BIT:
347 mb[0] = MBA_SCSI_COMPLETION;
349 case MBA_CMPLT_4_16BIT:
353 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
355 mb[0] = MBA_SCSI_COMPLETION;
357 case MBA_CMPLT_5_16BIT:
361 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
362 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
364 mb[0] = MBA_SCSI_COMPLETION;
366 case MBA_CMPLT_2_32BIT:
367 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
368 handles[1] = le32_to_cpu(
369 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
370 RD_MAILBOX_REG(ha, reg, 6));
372 mb[0] = MBA_SCSI_COMPLETION;
379 case MBA_SCSI_COMPLETION: /* Fast Post */
380 if (!vha->flags.online)
383 for (cnt = 0; cnt < handle_cnt; cnt++)
384 qla2x00_process_completed_request(vha, rsp->req,
388 case MBA_RESET: /* Reset */
389 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
392 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
395 case MBA_SYSTEM_ERR: /* System Error */
396 qla_printk(KERN_INFO, ha,
397 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
398 mb[1], mb[2], mb[3]);
400 ha->isp_ops->fw_dump(vha, 1);
402 if (IS_FWI2_CAPABLE(ha)) {
403 if (mb[1] == 0 && mb[2] == 0) {
404 qla_printk(KERN_ERR, ha,
405 "Unrecoverable Hardware Error: adapter "
406 "marked OFFLINE!\n");
407 vha->flags.online = 0;
409 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
410 } else if (mb[1] == 0) {
411 qla_printk(KERN_INFO, ha,
412 "Unrecoverable Hardware Error: adapter marked "
414 vha->flags.online = 0;
416 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
419 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
420 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
422 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
424 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
427 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
428 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
430 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
432 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
435 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
436 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
440 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
441 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
443 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
445 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
446 atomic_set(&vha->loop_state, LOOP_DOWN);
447 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
448 qla2x00_mark_all_devices_lost(vha, 1);
452 atomic_set(&vha->vp_state, VP_FAILED);
453 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
456 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
457 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
459 vha->flags.management_server_logged_in = 0;
460 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
463 case MBA_LOOP_UP: /* Loop Up Event */
464 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
465 link_speed = link_speeds[0];
466 ha->link_data_rate = PORT_SPEED_1GB;
468 link_speed = link_speeds[LS_UNKNOWN];
470 link_speed = link_speeds[mb[1]];
471 else if (mb[1] == 0x13)
472 link_speed = link_speeds[5];
473 ha->link_data_rate = mb[1];
476 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
477 vha->host_no, link_speed));
478 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
481 vha->flags.management_server_logged_in = 0;
482 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
485 case MBA_LOOP_DOWN: /* Loop Down Event */
486 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
487 "(%x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3]));
488 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
489 mb[1], mb[2], mb[3]);
491 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
492 atomic_set(&vha->loop_state, LOOP_DOWN);
493 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
494 vha->device_flags |= DFLG_NO_CABLE;
495 qla2x00_mark_all_devices_lost(vha, 1);
499 atomic_set(&vha->vp_state, VP_FAILED);
500 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
503 vha->flags.management_server_logged_in = 0;
504 ha->link_data_rate = PORT_SPEED_UNKNOWN;
505 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
508 case MBA_LIP_RESET: /* LIP reset occurred */
509 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
510 vha->host_no, mb[1]));
511 qla_printk(KERN_INFO, ha,
512 "LIP reset occurred (%x).\n", mb[1]);
514 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
515 atomic_set(&vha->loop_state, LOOP_DOWN);
516 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
517 qla2x00_mark_all_devices_lost(vha, 1);
521 atomic_set(&vha->vp_state, VP_FAILED);
522 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
525 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
527 ha->operating_mode = LOOP;
528 vha->flags.management_server_logged_in = 0;
529 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
532 /* case MBA_DCBX_COMPLETE: */
533 case MBA_POINT_TO_POINT: /* Point-to-Point */
538 DEBUG2(printk("scsi(%ld): DCBX Completed -- %04x %04x "
539 "%04x\n", vha->host_no, mb[1], mb[2], mb[3]));
541 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE "
542 "received.\n", vha->host_no));
545 * Until there's a transition from loop down to loop up, treat
546 * this as loop down only.
548 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
549 atomic_set(&vha->loop_state, LOOP_DOWN);
550 if (!atomic_read(&vha->loop_down_timer))
551 atomic_set(&vha->loop_down_timer,
553 qla2x00_mark_all_devices_lost(vha, 1);
557 atomic_set(&vha->vp_state, VP_FAILED);
558 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
561 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
562 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
564 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
565 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
567 ha->flags.gpsc_supported = 1;
568 vha->flags.management_server_logged_in = 0;
571 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
575 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
578 qla_printk(KERN_INFO, ha,
579 "Configuration change detected: value=%x.\n", mb[1]);
581 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
582 atomic_set(&vha->loop_state, LOOP_DOWN);
583 if (!atomic_read(&vha->loop_down_timer))
584 atomic_set(&vha->loop_down_timer,
586 qla2x00_mark_all_devices_lost(vha, 1);
590 atomic_set(&vha->vp_state, VP_FAILED);
591 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
594 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
595 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
598 case MBA_PORT_UPDATE: /* Port database update */
599 /* Only handle SCNs for our Vport index. */
600 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
604 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
605 * event etc. earlier indicating loop is down) then process
606 * it. Otherwise ignore it and Wait for RSCN to come in.
608 atomic_set(&vha->loop_down_timer, 0);
609 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
610 atomic_read(&vha->loop_state) != LOOP_DEAD) {
611 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
612 "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
617 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
619 DEBUG(printk(KERN_INFO
620 "scsi(%ld): Port database changed %04x %04x %04x.\n",
621 vha->host_no, mb[1], mb[2], mb[3]));
624 * Mark all devices as missing so we will login again.
626 atomic_set(&vha->loop_state, LOOP_UP);
628 qla2x00_mark_all_devices_lost(vha, 1);
630 vha->flags.rscn_queue_overflow = 1;
632 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
633 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
636 case MBA_RSCN_UPDATE: /* State Change Registration */
637 /* Check if the Vport has issued a SCR */
638 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
640 /* Only handle SCNs for our Vport index. */
641 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
643 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
645 DEBUG(printk(KERN_INFO
646 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
647 vha->host_no, mb[1], mb[2], mb[3]));
649 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
650 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
652 if (rscn_entry == host_pid) {
653 DEBUG(printk(KERN_INFO
654 "scsi(%ld): Ignoring RSCN update to local host "
656 vha->host_no, host_pid));
660 /* Ignore reserved bits from RSCN-payload. */
661 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
662 rscn_queue_index = vha->rscn_in_ptr + 1;
663 if (rscn_queue_index == MAX_RSCN_COUNT)
664 rscn_queue_index = 0;
665 if (rscn_queue_index != vha->rscn_out_ptr) {
666 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
667 vha->rscn_in_ptr = rscn_queue_index;
669 vha->flags.rscn_queue_overflow = 1;
672 atomic_set(&vha->loop_state, LOOP_UPDATE);
673 atomic_set(&vha->loop_down_timer, 0);
674 vha->flags.management_server_logged_in = 0;
676 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
677 set_bit(RSCN_UPDATE, &vha->dpc_flags);
678 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
681 /* case MBA_RIO_RESPONSE: */
682 case MBA_ZIO_RESPONSE:
683 DEBUG3(printk("scsi(%ld): [R|Z]IO update completion.\n",
686 if (IS_FWI2_CAPABLE(ha))
687 qla24xx_process_response_queue(vha, rsp);
689 qla2x00_process_response_queue(rsp);
692 case MBA_DISCARD_RND_FRAME:
693 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
694 "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
697 case MBA_TRACE_NOTIFICATION:
698 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
699 vha->host_no, mb[1], mb[2]));
702 case MBA_ISP84XX_ALERT:
703 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
704 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
706 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
708 case A84_PANIC_RECOVERY:
709 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
710 "%04x %04x\n", mb[2], mb[3]);
712 case A84_OP_LOGIN_COMPLETE:
713 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
714 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
715 "firmware version %x\n", ha->cs84xx->op_fw_version));
717 case A84_DIAG_LOGIN_COMPLETE:
718 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
719 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
720 "diagnostic firmware version %x\n",
721 ha->cs84xx->diag_fw_version));
723 case A84_GOLD_LOGIN_COMPLETE:
724 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
725 ha->cs84xx->fw_update = 1;
726 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
727 "firmware version %x\n",
728 ha->cs84xx->gold_fw_version));
731 qla_printk(KERN_ERR, ha,
732 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
733 mb[1], mb[2], mb[3]);
735 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
738 DEBUG2(printk("scsi(%ld): DCBX Started -- %04x %04x %04x\n",
739 vha->host_no, mb[1], mb[2], mb[3]));
741 case MBA_DCBX_PARAM_UPDATE:
742 DEBUG2(printk("scsi(%ld): DCBX Parameters Updated -- "
743 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
745 case MBA_FCF_CONF_ERR:
746 DEBUG2(printk("scsi(%ld): FCF Configuration Error -- "
747 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
749 case MBA_IDC_COMPLETE:
751 case MBA_IDC_TIME_EXT:
752 qla81xx_idc_event(vha, mb[0], mb[1]);
756 if (!vha->vp_idx && ha->num_vhosts)
757 qla2x00_alert_all_vps(rsp, mb);
761 qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
763 fc_port_t *fcport = data;
764 struct scsi_qla_host *vha = fcport->vha;
765 struct qla_hw_data *ha = vha->hw;
766 struct req_que *req = NULL;
771 if (req->max_q_depth <= sdev->queue_depth)
774 if (sdev->ordered_tags)
775 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
776 sdev->queue_depth + 1);
778 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
779 sdev->queue_depth + 1);
781 fcport->last_ramp_up = jiffies;
783 DEBUG2(qla_printk(KERN_INFO, ha,
784 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
785 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
790 qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
792 fc_port_t *fcport = data;
794 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
797 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
798 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
799 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
804 qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, struct req_que *req,
808 struct scsi_device *sdev;
810 sdev = sp->cmd->device;
811 if (sdev->queue_depth >= req->max_q_depth)
815 if (time_before(jiffies,
816 fcport->last_ramp_up + ql2xqfullrampup * HZ))
818 if (time_before(jiffies,
819 fcport->last_queue_full + ql2xqfullrampup * HZ))
822 starget_for_each_device(sdev->sdev_target, fcport,
823 qla2x00_adjust_sdev_qdepth_up);
827 * qla2x00_process_completed_request() - Process a Fast Post response.
828 * @ha: SCSI driver HA context
832 qla2x00_process_completed_request(struct scsi_qla_host *vha,
833 struct req_que *req, uint32_t index)
836 struct qla_hw_data *ha = vha->hw;
838 /* Validate handle. */
839 if (index >= MAX_OUTSTANDING_COMMANDS) {
840 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
841 vha->host_no, index));
842 qla_printk(KERN_WARNING, ha,
843 "Invalid SCSI completion handle %d.\n", index);
845 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
849 sp = req->outstanding_cmds[index];
851 /* Free outstanding command slot. */
852 req->outstanding_cmds[index] = NULL;
854 /* Save ISP completion status */
855 sp->cmd->result = DID_OK << 16;
857 qla2x00_ramp_up_queue_depth(vha, req, sp);
858 qla2x00_sp_compl(ha, sp);
860 DEBUG2(printk("scsi(%ld) Req:%d: Invalid ISP SCSI completion"
861 " handle(%d)\n", vha->host_no, req->id, index));
862 qla_printk(KERN_WARNING, ha,
863 "Invalid ISP SCSI completion handle\n");
865 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
870 * qla2x00_process_response_queue() - Process response queue entries.
871 * @ha: SCSI driver HA context
874 qla2x00_process_response_queue(struct rsp_que *rsp)
876 struct scsi_qla_host *vha;
877 struct qla_hw_data *ha = rsp->hw;
878 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
883 vha = pci_get_drvdata(ha->pdev);
885 if (!vha->flags.online)
888 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
889 pkt = (sts_entry_t *)rsp->ring_ptr;
892 if (rsp->ring_index == rsp->length) {
894 rsp->ring_ptr = rsp->ring;
899 if (pkt->entry_status != 0) {
900 DEBUG3(printk(KERN_INFO
901 "scsi(%ld): Process error entry.\n", vha->host_no));
903 qla2x00_error_entry(vha, rsp, pkt);
904 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
909 switch (pkt->entry_type) {
911 qla2x00_status_entry(vha, rsp, pkt);
914 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
915 for (cnt = 0; cnt < handle_cnt; cnt++) {
916 qla2x00_process_completed_request(vha, rsp->req,
917 ((sts21_entry_t *)pkt)->handle[cnt]);
921 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
922 for (cnt = 0; cnt < handle_cnt; cnt++) {
923 qla2x00_process_completed_request(vha, rsp->req,
924 ((sts22_entry_t *)pkt)->handle[cnt]);
927 case STATUS_CONT_TYPE:
928 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
931 /* Type Not Supported. */
932 DEBUG4(printk(KERN_WARNING
933 "scsi(%ld): Received unknown response pkt type %x "
934 "entry status=%x.\n",
935 vha->host_no, pkt->entry_type, pkt->entry_status));
938 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
942 /* Adjust ring index */
943 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
947 qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len,
950 struct scsi_cmnd *cp = sp->cmd;
952 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
953 sense_len = SCSI_SENSE_BUFFERSIZE;
955 sp->request_sense_length = sense_len;
956 sp->request_sense_ptr = cp->sense_buffer;
957 if (sp->request_sense_length > 32)
960 memcpy(cp->sense_buffer, sense_data, sense_len);
962 sp->request_sense_ptr += sense_len;
963 sp->request_sense_length -= sense_len;
964 if (sp->request_sense_length != 0)
965 rsp->status_srb = sp;
967 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
968 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
969 cp->device->channel, cp->device->id, cp->device->lun, cp,
972 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len));
976 * qla2x00_status_entry() - Process a Status IOCB entry.
977 * @ha: SCSI driver HA context
978 * @pkt: Entry pointer
981 qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
985 struct scsi_cmnd *cp;
987 struct sts_entry_24xx *sts24;
988 uint16_t comp_status;
989 uint16_t scsi_status;
990 uint8_t lscsi_status;
992 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
993 uint8_t *rsp_info, *sense_data;
994 struct qla_hw_data *ha = vha->hw;
999 sts = (sts_entry_t *) pkt;
1000 sts24 = (struct sts_entry_24xx *) pkt;
1001 if (IS_FWI2_CAPABLE(ha)) {
1002 comp_status = le16_to_cpu(sts24->comp_status);
1003 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1005 comp_status = le16_to_cpu(sts->comp_status);
1006 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1008 handle = (uint32_t) LSW(sts->handle);
1009 que = MSW(sts->handle);
1010 req = ha->req_q_map[que];
1011 /* Fast path completion. */
1012 if (comp_status == CS_COMPLETE && scsi_status == 0) {
1013 qla2x00_process_completed_request(vha, req, handle);
1018 /* Validate handle. */
1019 if (handle < MAX_OUTSTANDING_COMMANDS) {
1020 sp = req->outstanding_cmds[handle];
1021 req->outstanding_cmds[handle] = NULL;
1026 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
1028 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
1030 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1031 qla2xxx_wake_dpc(vha);
1036 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
1037 "pkt->handle=%d sp=%p.\n", vha->host_no, handle, sp));
1038 qla_printk(KERN_WARNING, ha,
1039 "Command is NULL: already returned to OS (sp=%p)\n", sp);
1044 lscsi_status = scsi_status & STATUS_MASK;
1046 fcport = sp->fcport;
1048 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
1049 if (IS_FWI2_CAPABLE(ha)) {
1050 sense_len = le32_to_cpu(sts24->sense_len);
1051 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1052 resid_len = le32_to_cpu(sts24->rsp_residual_count);
1053 fw_resid_len = le32_to_cpu(sts24->residual_len);
1054 rsp_info = sts24->data;
1055 sense_data = sts24->data;
1056 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
1058 sense_len = le16_to_cpu(sts->req_sense_length);
1059 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
1060 resid_len = le32_to_cpu(sts->residual_length);
1061 rsp_info = sts->rsp_info;
1062 sense_data = sts->req_sense_data;
1065 /* Check for any FCP transport errors. */
1066 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
1067 /* Sense data lies beyond any FCP RESPONSE data. */
1068 if (IS_FWI2_CAPABLE(ha))
1069 sense_data += rsp_info_len;
1070 if (rsp_info_len > 3 && rsp_info[3]) {
1071 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1072 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
1073 "retrying command\n", vha->host_no,
1074 cp->device->channel, cp->device->id,
1075 cp->device->lun, rsp_info_len, rsp_info[0],
1076 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1077 rsp_info[5], rsp_info[6], rsp_info[7]));
1079 cp->result = DID_BUS_BUSY << 16;
1080 qla2x00_sp_compl(ha, sp);
1085 /* Check for overrun. */
1086 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1087 scsi_status & SS_RESIDUAL_OVER)
1088 comp_status = CS_DATA_OVERRUN;
1091 * Based on Host and scsi status generate status code for Linux
1093 switch (comp_status) {
1096 if (scsi_status == 0) {
1097 cp->result = DID_OK << 16;
1100 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
1102 scsi_set_resid(cp, resid);
1104 if (!lscsi_status &&
1105 ((unsigned)(scsi_bufflen(cp) - resid) <
1107 qla_printk(KERN_INFO, ha,
1108 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1109 "detected (%x of %x bytes)...returning "
1110 "error status.\n", vha->host_no,
1111 cp->device->channel, cp->device->id,
1112 cp->device->lun, resid,
1115 cp->result = DID_ERROR << 16;
1119 cp->result = DID_OK << 16 | lscsi_status;
1121 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1122 DEBUG2(printk(KERN_INFO
1123 "scsi(%ld): QUEUE FULL status detected "
1124 "0x%x-0x%x.\n", vha->host_no, comp_status,
1127 /* Adjust queue depth for all luns on the port. */
1128 fcport->last_queue_full = jiffies;
1129 starget_for_each_device(cp->device->sdev_target,
1130 fcport, qla2x00_adjust_sdev_qdepth_down);
1133 if (lscsi_status != SS_CHECK_CONDITION)
1136 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1137 if (!(scsi_status & SS_SENSE_LEN_VALID))
1140 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
1143 case CS_DATA_UNDERRUN:
1145 /* Use F/W calculated residual length. */
1146 if (IS_FWI2_CAPABLE(ha)) {
1147 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1149 } else if (resid != fw_resid_len) {
1150 scsi_status &= ~SS_RESIDUAL_UNDER;
1153 resid = fw_resid_len;
1156 if (scsi_status & SS_RESIDUAL_UNDER) {
1157 scsi_set_resid(cp, resid);
1159 DEBUG2(printk(KERN_INFO
1160 "scsi(%ld:%d:%d) UNDERRUN status detected "
1161 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1162 "os_underflow=0x%x\n", vha->host_no,
1163 cp->device->id, cp->device->lun, comp_status,
1164 scsi_status, resid_len, resid, cp->cmnd[0],
1170 * Check to see if SCSI Status is non zero. If so report SCSI
1173 if (lscsi_status != 0) {
1174 cp->result = DID_OK << 16 | lscsi_status;
1176 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1177 DEBUG2(printk(KERN_INFO
1178 "scsi(%ld): QUEUE FULL status detected "
1179 "0x%x-0x%x.\n", vha->host_no, comp_status,
1183 * Adjust queue depth for all luns on the
1186 fcport->last_queue_full = jiffies;
1187 starget_for_each_device(
1188 cp->device->sdev_target, fcport,
1189 qla2x00_adjust_sdev_qdepth_down);
1192 if (lscsi_status != SS_CHECK_CONDITION)
1195 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1196 if (!(scsi_status & SS_SENSE_LEN_VALID))
1199 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
1202 * If RISC reports underrun and target does not report
1203 * it then we must have a lost frame, so tell upper
1204 * layer to retry it by reporting a bus busy.
1206 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1207 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1208 "frame(s) detected (%x of %x bytes)..."
1209 "retrying command.\n",
1210 vha->host_no, cp->device->channel,
1211 cp->device->id, cp->device->lun, resid,
1214 cp->result = DID_BUS_BUSY << 16;
1218 /* Handle mid-layer underflow */
1219 if ((unsigned)(scsi_bufflen(cp) - resid) <
1221 qla_printk(KERN_INFO, ha,
1222 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1223 "detected (%x of %x bytes)...returning "
1224 "error status.\n", vha->host_no,
1225 cp->device->channel, cp->device->id,
1226 cp->device->lun, resid,
1229 cp->result = DID_ERROR << 16;
1233 /* Everybody online, looking good... */
1234 cp->result = DID_OK << 16;
1238 case CS_DATA_OVERRUN:
1239 DEBUG2(printk(KERN_INFO
1240 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1241 vha->host_no, cp->device->id, cp->device->lun, comp_status,
1243 DEBUG2(printk(KERN_INFO
1244 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1245 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1246 cp->cmnd[4], cp->cmnd[5]));
1247 DEBUG2(printk(KERN_INFO
1248 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1250 cp->serial_number, scsi_bufflen(cp), resid_len));
1252 cp->result = DID_ERROR << 16;
1255 case CS_PORT_LOGGED_OUT:
1256 case CS_PORT_CONFIG_CHG:
1259 case CS_PORT_UNAVAILABLE:
1261 * If the port is in Target Down state, return all IOs for this
1262 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1265 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1266 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1267 vha->host_no, cp->device->id, cp->device->lun,
1268 cp->serial_number, comp_status,
1269 atomic_read(&fcport->state)));
1272 * We are going to have the fc class block the rport
1273 * while we try to recover so instruct the mid layer
1274 * to requeue until the class decides how to handle this.
1276 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1277 if (atomic_read(&fcport->state) == FCS_ONLINE)
1278 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1282 DEBUG2(printk(KERN_INFO
1283 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1284 vha->host_no, comp_status, scsi_status));
1286 cp->result = DID_RESET << 16;
1291 * hv2.19.12 - DID_ABORT does not retry the request if we
1292 * aborted this request then abort otherwise it must be a
1295 DEBUG2(printk(KERN_INFO
1296 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1297 vha->host_no, comp_status, scsi_status));
1299 cp->result = DID_RESET << 16;
1304 * We are going to have the fc class block the rport
1305 * while we try to recover so instruct the mid layer
1306 * to requeue until the class decides how to handle this.
1308 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1310 if (IS_FWI2_CAPABLE(ha)) {
1311 DEBUG2(printk(KERN_INFO
1312 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1313 "0x%x-0x%x\n", vha->host_no, cp->device->channel,
1314 cp->device->id, cp->device->lun, comp_status,
1318 DEBUG2(printk(KERN_INFO
1319 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1320 "sflags=%x.\n", vha->host_no, cp->device->channel,
1321 cp->device->id, cp->device->lun, comp_status, scsi_status,
1322 le16_to_cpu(sts->status_flags)));
1324 /* Check to see if logout occurred. */
1325 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
1326 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1330 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1331 "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
1332 qla_printk(KERN_INFO, ha,
1333 "Unknown status detected 0x%x-0x%x.\n",
1334 comp_status, scsi_status);
1336 cp->result = DID_ERROR << 16;
1340 /* Place command on done queue. */
1341 if (rsp->status_srb == NULL)
1342 qla2x00_sp_compl(ha, sp);
1346 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1347 * @ha: SCSI driver HA context
1348 * @pkt: Entry pointer
1350 * Extended sense data.
1353 qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
1355 uint8_t sense_sz = 0;
1356 struct qla_hw_data *ha = rsp->hw;
1357 srb_t *sp = rsp->status_srb;
1358 struct scsi_cmnd *cp;
1360 if (sp != NULL && sp->request_sense_length != 0) {
1363 DEBUG2(printk("%s(): Cmd already returned back to OS "
1364 "sp=%p.\n", __func__, sp));
1365 qla_printk(KERN_INFO, ha,
1366 "cmd is NULL: already returned to OS (sp=%p)\n",
1369 rsp->status_srb = NULL;
1373 if (sp->request_sense_length > sizeof(pkt->data)) {
1374 sense_sz = sizeof(pkt->data);
1376 sense_sz = sp->request_sense_length;
1379 /* Move sense data. */
1380 if (IS_FWI2_CAPABLE(ha))
1381 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
1382 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1383 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1385 sp->request_sense_ptr += sense_sz;
1386 sp->request_sense_length -= sense_sz;
1388 /* Place command on done queue. */
1389 if (sp->request_sense_length == 0) {
1390 rsp->status_srb = NULL;
1391 qla2x00_sp_compl(ha, sp);
1397 * qla2x00_error_entry() - Process an error entry.
1398 * @ha: SCSI driver HA context
1399 * @pkt: Entry pointer
1402 qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
1405 struct qla_hw_data *ha = vha->hw;
1406 uint32_t handle = LSW(pkt->handle);
1407 uint16_t que = MSW(pkt->handle);
1408 struct req_que *req = ha->req_q_map[que];
1409 #if defined(QL_DEBUG_LEVEL_2)
1410 if (pkt->entry_status & RF_INV_E_ORDER)
1411 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1412 else if (pkt->entry_status & RF_INV_E_COUNT)
1413 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1414 else if (pkt->entry_status & RF_INV_E_PARAM)
1415 qla_printk(KERN_ERR, ha,
1416 "%s: Invalid Entry Parameter\n", __func__);
1417 else if (pkt->entry_status & RF_INV_E_TYPE)
1418 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1419 else if (pkt->entry_status & RF_BUSY)
1420 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1422 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1425 /* Validate handle. */
1426 if (handle < MAX_OUTSTANDING_COMMANDS)
1427 sp = req->outstanding_cmds[handle];
1432 /* Free outstanding command slot. */
1433 req->outstanding_cmds[handle] = NULL;
1435 /* Bad payload or header */
1436 if (pkt->entry_status &
1437 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1438 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1439 sp->cmd->result = DID_ERROR << 16;
1440 } else if (pkt->entry_status & RF_BUSY) {
1441 sp->cmd->result = DID_BUS_BUSY << 16;
1443 sp->cmd->result = DID_ERROR << 16;
1445 qla2x00_sp_compl(ha, sp);
1447 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1448 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
1449 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1451 qla_printk(KERN_WARNING, ha,
1452 "Error entry - invalid handle\n");
1454 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1455 qla2xxx_wake_dpc(vha);
1460 * qla24xx_mbx_completion() - Process mailbox command completions.
1461 * @ha: SCSI driver HA context
1462 * @mb0: Mailbox0 register
1465 qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
1468 uint16_t __iomem *wptr;
1469 struct qla_hw_data *ha = vha->hw;
1470 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1472 /* Load return mailbox registers. */
1473 ha->flags.mbox_int = 1;
1474 ha->mailbox_out[0] = mb0;
1475 wptr = (uint16_t __iomem *)®->mailbox1;
1477 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1478 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1483 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1484 __func__, vha->host_no, ha->mcp->mb[0]));
1486 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1487 __func__, vha->host_no));
1492 * qla24xx_process_response_queue() - Process response queue entries.
1493 * @ha: SCSI driver HA context
1495 void qla24xx_process_response_queue(struct scsi_qla_host *vha,
1496 struct rsp_que *rsp)
1498 struct sts_entry_24xx *pkt;
1500 if (!vha->flags.online)
1503 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1504 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
1507 if (rsp->ring_index == rsp->length) {
1508 rsp->ring_index = 0;
1509 rsp->ring_ptr = rsp->ring;
1514 if (pkt->entry_status != 0) {
1515 DEBUG3(printk(KERN_INFO
1516 "scsi(%ld): Process error entry.\n", vha->host_no));
1518 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
1519 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1524 switch (pkt->entry_type) {
1526 qla2x00_status_entry(vha, rsp, pkt);
1528 case STATUS_CONT_TYPE:
1529 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
1531 case VP_RPT_ID_IOCB_TYPE:
1532 qla24xx_report_id_acquisition(vha,
1533 (struct vp_rpt_id_entry_24xx *)pkt);
1536 /* Type Not Supported. */
1537 DEBUG4(printk(KERN_WARNING
1538 "scsi(%ld): Received unknown response pkt type %x "
1539 "entry status=%x.\n",
1540 vha->host_no, pkt->entry_type, pkt->entry_status));
1543 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1547 /* Adjust ring index */
1548 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
1552 qla2xxx_check_risc_status(scsi_qla_host_t *vha)
1556 struct qla_hw_data *ha = vha->hw;
1557 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1559 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
1563 WRT_REG_DWORD(®->iobase_addr, 0x7C00);
1564 RD_REG_DWORD(®->iobase_addr);
1565 WRT_REG_DWORD(®->iobase_window, 0x0001);
1566 for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1567 rval == QLA_SUCCESS; cnt--) {
1569 WRT_REG_DWORD(®->iobase_window, 0x0001);
1572 rval = QLA_FUNCTION_TIMEOUT;
1574 if (rval == QLA_SUCCESS)
1577 WRT_REG_DWORD(®->iobase_window, 0x0003);
1578 for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1579 rval == QLA_SUCCESS; cnt--) {
1581 WRT_REG_DWORD(®->iobase_window, 0x0003);
1584 rval = QLA_FUNCTION_TIMEOUT;
1586 if (rval != QLA_SUCCESS)
1590 if (RD_REG_DWORD(®->iobase_c8) & BIT_3)
1591 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1594 WRT_REG_DWORD(®->iobase_window, 0x0000);
1595 RD_REG_DWORD(®->iobase_window);
1599 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1601 * @dev_id: SCSI driver HA context
1603 * Called by system whenever the host adapter generates an interrupt.
1605 * Returns handled flag.
1608 qla24xx_intr_handler(int irq, void *dev_id)
1610 scsi_qla_host_t *vha;
1611 struct qla_hw_data *ha;
1612 struct device_reg_24xx __iomem *reg;
1618 struct rsp_que *rsp;
1620 rsp = (struct rsp_que *) dev_id;
1623 "%s(): NULL response queue pointer\n", __func__);
1628 reg = &ha->iobase->isp24;
1631 spin_lock(&ha->hardware_lock);
1632 vha = pci_get_drvdata(ha->pdev);
1633 for (iter = 50; iter--; ) {
1634 stat = RD_REG_DWORD(®->host_status);
1635 if (stat & HSRX_RISC_PAUSED) {
1636 if (pci_channel_offline(ha->pdev))
1639 hccr = RD_REG_DWORD(®->hccr);
1641 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1642 "Dumping firmware!\n", hccr);
1644 qla2xxx_check_risc_status(vha);
1646 ha->isp_ops->fw_dump(vha, 1);
1647 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1649 } else if ((stat & HSRX_RISC_INT) == 0)
1652 switch (stat & 0xff) {
1657 qla24xx_mbx_completion(vha, MSW(stat));
1658 status |= MBX_INTERRUPT;
1663 mb[1] = RD_REG_WORD(®->mailbox1);
1664 mb[2] = RD_REG_WORD(®->mailbox2);
1665 mb[3] = RD_REG_WORD(®->mailbox3);
1666 qla2x00_async_event(vha, rsp, mb);
1670 qla24xx_process_response_queue(vha, rsp);
1673 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1675 vha->host_no, stat & 0xff));
1678 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1679 RD_REG_DWORD_RELAXED(®->hccr);
1681 spin_unlock(&ha->hardware_lock);
1683 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1684 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1685 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1686 complete(&ha->mbx_intr_comp);
1693 qla24xx_msix_rsp_q(int irq, void *dev_id)
1695 struct qla_hw_data *ha;
1696 struct rsp_que *rsp;
1697 struct device_reg_24xx __iomem *reg;
1698 struct scsi_qla_host *vha;
1700 rsp = (struct rsp_que *) dev_id;
1703 "%s(): NULL response queue pointer\n", __func__);
1707 reg = &ha->iobase->isp24;
1709 spin_lock_irq(&ha->hardware_lock);
1711 vha = qla25xx_get_host(rsp);
1712 qla24xx_process_response_queue(vha, rsp);
1713 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1715 spin_unlock_irq(&ha->hardware_lock);
1721 qla24xx_msix_default(int irq, void *dev_id)
1723 scsi_qla_host_t *vha;
1724 struct qla_hw_data *ha;
1725 struct rsp_que *rsp;
1726 struct device_reg_24xx __iomem *reg;
1732 rsp = (struct rsp_que *) dev_id;
1735 "%s(): NULL response queue pointer\n", __func__));
1739 reg = &ha->iobase->isp24;
1742 spin_lock_irq(&ha->hardware_lock);
1743 vha = pci_get_drvdata(ha->pdev);
1745 stat = RD_REG_DWORD(®->host_status);
1746 if (stat & HSRX_RISC_PAUSED) {
1747 if (pci_channel_offline(ha->pdev))
1750 hccr = RD_REG_DWORD(®->hccr);
1752 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1753 "Dumping firmware!\n", hccr);
1755 qla2xxx_check_risc_status(vha);
1757 ha->isp_ops->fw_dump(vha, 1);
1758 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1760 } else if ((stat & HSRX_RISC_INT) == 0)
1763 switch (stat & 0xff) {
1768 qla24xx_mbx_completion(vha, MSW(stat));
1769 status |= MBX_INTERRUPT;
1774 mb[1] = RD_REG_WORD(®->mailbox1);
1775 mb[2] = RD_REG_WORD(®->mailbox2);
1776 mb[3] = RD_REG_WORD(®->mailbox3);
1777 qla2x00_async_event(vha, rsp, mb);
1781 qla24xx_process_response_queue(vha, rsp);
1784 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1786 vha->host_no, stat & 0xff));
1789 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1791 spin_unlock_irq(&ha->hardware_lock);
1793 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1794 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1795 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1796 complete(&ha->mbx_intr_comp);
1802 /* Interrupt handling helpers. */
1804 struct qla_init_msix_entry {
1806 irq_handler_t handler;
1809 static struct qla_init_msix_entry msix_entries[2] = {
1810 { "qla2xxx (default)", qla24xx_msix_default },
1811 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1815 qla24xx_disable_msix(struct qla_hw_data *ha)
1818 struct qla_msix_entry *qentry;
1820 for (i = 0; i < ha->msix_count; i++) {
1821 qentry = &ha->msix_entries[i];
1822 if (qentry->have_irq)
1823 free_irq(qentry->vector, qentry->rsp);
1825 pci_disable_msix(ha->pdev);
1826 kfree(ha->msix_entries);
1827 ha->msix_entries = NULL;
1828 ha->flags.msix_enabled = 0;
1832 qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
1834 #define MIN_MSIX_COUNT 2
1836 struct msix_entry *entries;
1837 struct qla_msix_entry *qentry;
1839 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
1844 for (i = 0; i < ha->msix_count; i++)
1845 entries[i].entry = i;
1847 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1849 if (ret < MIN_MSIX_COUNT)
1852 qla_printk(KERN_WARNING, ha,
1853 "MSI-X: Failed to enable support -- %d/%d\n"
1854 " Retry with %d vectors\n", ha->msix_count, ret, ret);
1855 ha->msix_count = ret;
1856 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1859 qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
1860 " support, giving up -- %d/%d\n",
1861 ha->msix_count, ret);
1864 ha->max_rsp_queues = ha->msix_count - 1;
1866 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
1867 ha->msix_count, GFP_KERNEL);
1868 if (!ha->msix_entries) {
1872 ha->flags.msix_enabled = 1;
1874 for (i = 0; i < ha->msix_count; i++) {
1875 qentry = &ha->msix_entries[i];
1876 qentry->vector = entries[i].vector;
1877 qentry->entry = entries[i].entry;
1878 qentry->have_irq = 0;
1882 /* Enable MSI-X vectors for the base queue */
1883 for (i = 0; i < 2; i++) {
1884 qentry = &ha->msix_entries[i];
1885 ret = request_irq(qentry->vector, msix_entries[i].handler,
1886 0, msix_entries[i].name, rsp);
1888 qla_printk(KERN_WARNING, ha,
1889 "MSI-X: Unable to register handler -- %x/%d.\n",
1890 qentry->vector, ret);
1891 qla24xx_disable_msix(ha);
1895 qentry->have_irq = 1;
1900 /* Enable MSI-X vector for response queue update for queue 0 */
1901 if (ha->mqiobase && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
1910 qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
1913 device_reg_t __iomem *reg = ha->iobase;
1915 /* If possible, enable MSI-X. */
1916 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
1917 !IS_QLA8432(ha) && !IS_QLA8001(ha))
1920 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
1921 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
1922 DEBUG2(qla_printk(KERN_WARNING, ha,
1923 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1924 ha->pdev->revision, ha->fw_attributes));
1929 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1930 (ha->pdev->subsystem_device == 0x7040 ||
1931 ha->pdev->subsystem_device == 0x7041 ||
1932 ha->pdev->subsystem_device == 0x1705)) {
1933 DEBUG2(qla_printk(KERN_WARNING, ha,
1934 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1935 ha->pdev->subsystem_vendor,
1936 ha->pdev->subsystem_device));
1941 ret = qla24xx_enable_msix(ha, rsp);
1943 DEBUG2(qla_printk(KERN_INFO, ha,
1944 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1945 ha->fw_attributes));
1946 goto clear_risc_ints;
1948 qla_printk(KERN_WARNING, ha,
1949 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1952 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
1956 ret = pci_enable_msi(ha->pdev);
1958 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1959 ha->flags.msi_enabled = 1;
1963 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
1964 IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
1966 qla_printk(KERN_WARNING, ha,
1967 "Failed to reserve interrupt %d already in use.\n",
1971 ha->flags.inta_enabled = 1;
1975 * FIXME: Noted that 8014s were being dropped during NK testing.
1976 * Timing deltas during MSI-X/INTa transitions?
1980 spin_lock_irq(&ha->hardware_lock);
1981 if (IS_FWI2_CAPABLE(ha)) {
1982 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT);
1983 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT);
1985 WRT_REG_WORD(®->isp.semaphore, 0);
1986 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT);
1987 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT);
1989 spin_unlock_irq(&ha->hardware_lock);
1996 qla2x00_free_irqs(scsi_qla_host_t *vha)
1998 struct qla_hw_data *ha = vha->hw;
1999 struct rsp_que *rsp = ha->rsp_q_map[0];
2001 if (ha->flags.msix_enabled)
2002 qla24xx_disable_msix(ha);
2003 else if (ha->flags.inta_enabled) {
2004 free_irq(ha->pdev->irq, rsp);
2005 pci_disable_msi(ha->pdev);
2010 int qla25xx_request_irq(struct rsp_que *rsp)
2012 struct qla_hw_data *ha = rsp->hw;
2013 struct qla_init_msix_entry *intr = &msix_entries[2];
2014 struct qla_msix_entry *msix = rsp->msix;
2017 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2019 qla_printk(KERN_WARNING, ha,
2020 "MSI-X: Unable to register handler -- %x/%d.\n",
2029 struct scsi_qla_host *
2030 qla25xx_get_host(struct rsp_que *rsp)
2033 struct qla_hw_data *ha = rsp->hw;
2034 struct scsi_qla_host *vha = NULL;
2035 struct sts_entry_24xx *pkt;
2036 struct req_que *req;
2040 pkt = (struct sts_entry_24xx *) rsp->ring_ptr;
2041 que = MSW(pkt->handle);
2042 handle = (uint32_t) LSW(pkt->handle);
2043 req = ha->req_q_map[que];
2044 if (handle < MAX_OUTSTANDING_COMMANDS) {
2045 sp = req->outstanding_cmds[handle];
2047 return sp->fcport->vha;
2052 vha = pci_get_drvdata(ha->pdev);