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;
768 if (!ql2xqfulltracking)
774 if (req->max_q_depth <= sdev->queue_depth)
777 if (sdev->ordered_tags)
778 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
779 sdev->queue_depth + 1);
781 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
782 sdev->queue_depth + 1);
784 fcport->last_ramp_up = jiffies;
786 DEBUG2(qla_printk(KERN_INFO, ha,
787 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
788 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
793 qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
795 fc_port_t *fcport = data;
797 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
800 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
801 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
802 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
807 qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, struct req_que *req,
811 struct scsi_device *sdev;
813 if (!ql2xqfulltracking)
816 sdev = sp->cmd->device;
817 if (sdev->queue_depth >= req->max_q_depth)
821 if (time_before(jiffies,
822 fcport->last_ramp_up + ql2xqfullrampup * HZ))
824 if (time_before(jiffies,
825 fcport->last_queue_full + ql2xqfullrampup * HZ))
828 starget_for_each_device(sdev->sdev_target, fcport,
829 qla2x00_adjust_sdev_qdepth_up);
833 * qla2x00_process_completed_request() - Process a Fast Post response.
834 * @ha: SCSI driver HA context
838 qla2x00_process_completed_request(struct scsi_qla_host *vha,
839 struct req_que *req, uint32_t index)
842 struct qla_hw_data *ha = vha->hw;
844 /* Validate handle. */
845 if (index >= MAX_OUTSTANDING_COMMANDS) {
846 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
847 vha->host_no, index));
848 qla_printk(KERN_WARNING, ha,
849 "Invalid SCSI completion handle %d.\n", index);
851 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
855 sp = req->outstanding_cmds[index];
857 /* Free outstanding command slot. */
858 req->outstanding_cmds[index] = NULL;
860 /* Save ISP completion status */
861 sp->cmd->result = DID_OK << 16;
863 qla2x00_ramp_up_queue_depth(vha, req, sp);
864 qla2x00_sp_compl(ha, sp);
866 DEBUG2(printk("scsi(%ld) Req:%d: Invalid ISP SCSI completion"
867 " handle(%d)\n", vha->host_no, req->id, index));
868 qla_printk(KERN_WARNING, ha,
869 "Invalid ISP SCSI completion handle\n");
871 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
876 * qla2x00_process_response_queue() - Process response queue entries.
877 * @ha: SCSI driver HA context
880 qla2x00_process_response_queue(struct rsp_que *rsp)
882 struct scsi_qla_host *vha;
883 struct qla_hw_data *ha = rsp->hw;
884 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
889 vha = pci_get_drvdata(ha->pdev);
891 if (!vha->flags.online)
894 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
895 pkt = (sts_entry_t *)rsp->ring_ptr;
898 if (rsp->ring_index == rsp->length) {
900 rsp->ring_ptr = rsp->ring;
905 if (pkt->entry_status != 0) {
906 DEBUG3(printk(KERN_INFO
907 "scsi(%ld): Process error entry.\n", vha->host_no));
909 qla2x00_error_entry(vha, rsp, pkt);
910 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
915 switch (pkt->entry_type) {
917 qla2x00_status_entry(vha, rsp, pkt);
920 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
921 for (cnt = 0; cnt < handle_cnt; cnt++) {
922 qla2x00_process_completed_request(vha, rsp->req,
923 ((sts21_entry_t *)pkt)->handle[cnt]);
927 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
928 for (cnt = 0; cnt < handle_cnt; cnt++) {
929 qla2x00_process_completed_request(vha, rsp->req,
930 ((sts22_entry_t *)pkt)->handle[cnt]);
933 case STATUS_CONT_TYPE:
934 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
937 /* Type Not Supported. */
938 DEBUG4(printk(KERN_WARNING
939 "scsi(%ld): Received unknown response pkt type %x "
940 "entry status=%x.\n",
941 vha->host_no, pkt->entry_type, pkt->entry_status));
944 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
948 /* Adjust ring index */
949 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
953 qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len,
956 struct scsi_cmnd *cp = sp->cmd;
958 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
959 sense_len = SCSI_SENSE_BUFFERSIZE;
961 sp->request_sense_length = sense_len;
962 sp->request_sense_ptr = cp->sense_buffer;
963 if (sp->request_sense_length > 32)
966 memcpy(cp->sense_buffer, sense_data, sense_len);
968 sp->request_sense_ptr += sense_len;
969 sp->request_sense_length -= sense_len;
970 if (sp->request_sense_length != 0)
971 rsp->status_srb = sp;
973 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
974 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
975 cp->device->channel, cp->device->id, cp->device->lun, cp,
978 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len));
982 * qla2x00_status_entry() - Process a Status IOCB entry.
983 * @ha: SCSI driver HA context
984 * @pkt: Entry pointer
987 qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
991 struct scsi_cmnd *cp;
993 struct sts_entry_24xx *sts24;
994 uint16_t comp_status;
995 uint16_t scsi_status;
996 uint8_t lscsi_status;
998 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
999 uint8_t *rsp_info, *sense_data;
1000 struct qla_hw_data *ha = vha->hw;
1003 struct req_que *req;
1005 sts = (sts_entry_t *) pkt;
1006 sts24 = (struct sts_entry_24xx *) pkt;
1007 if (IS_FWI2_CAPABLE(ha)) {
1008 comp_status = le16_to_cpu(sts24->comp_status);
1009 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1011 comp_status = le16_to_cpu(sts->comp_status);
1012 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1014 handle = (uint32_t) LSW(sts->handle);
1015 que = MSW(sts->handle);
1016 req = ha->req_q_map[que];
1017 /* Fast path completion. */
1018 if (comp_status == CS_COMPLETE && scsi_status == 0) {
1019 qla2x00_process_completed_request(vha, req, handle);
1024 /* Validate handle. */
1025 if (handle < MAX_OUTSTANDING_COMMANDS) {
1026 sp = req->outstanding_cmds[handle];
1027 req->outstanding_cmds[handle] = NULL;
1032 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
1034 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
1036 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1037 qla2xxx_wake_dpc(vha);
1042 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
1043 "pkt->handle=%d sp=%p.\n", vha->host_no, handle, sp));
1044 qla_printk(KERN_WARNING, ha,
1045 "Command is NULL: already returned to OS (sp=%p)\n", sp);
1050 lscsi_status = scsi_status & STATUS_MASK;
1052 fcport = sp->fcport;
1054 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
1055 if (IS_FWI2_CAPABLE(ha)) {
1056 sense_len = le32_to_cpu(sts24->sense_len);
1057 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1058 resid_len = le32_to_cpu(sts24->rsp_residual_count);
1059 fw_resid_len = le32_to_cpu(sts24->residual_len);
1060 rsp_info = sts24->data;
1061 sense_data = sts24->data;
1062 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
1064 sense_len = le16_to_cpu(sts->req_sense_length);
1065 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
1066 resid_len = le32_to_cpu(sts->residual_length);
1067 rsp_info = sts->rsp_info;
1068 sense_data = sts->req_sense_data;
1071 /* Check for any FCP transport errors. */
1072 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
1073 /* Sense data lies beyond any FCP RESPONSE data. */
1074 if (IS_FWI2_CAPABLE(ha))
1075 sense_data += rsp_info_len;
1076 if (rsp_info_len > 3 && rsp_info[3]) {
1077 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1078 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
1079 "retrying command\n", vha->host_no,
1080 cp->device->channel, cp->device->id,
1081 cp->device->lun, rsp_info_len, rsp_info[0],
1082 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1083 rsp_info[5], rsp_info[6], rsp_info[7]));
1085 cp->result = DID_BUS_BUSY << 16;
1086 qla2x00_sp_compl(ha, sp);
1091 /* Check for overrun. */
1092 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1093 scsi_status & SS_RESIDUAL_OVER)
1094 comp_status = CS_DATA_OVERRUN;
1097 * Based on Host and scsi status generate status code for Linux
1099 switch (comp_status) {
1102 if (scsi_status == 0) {
1103 cp->result = DID_OK << 16;
1106 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
1108 scsi_set_resid(cp, resid);
1110 if (!lscsi_status &&
1111 ((unsigned)(scsi_bufflen(cp) - resid) <
1113 qla_printk(KERN_INFO, ha,
1114 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1115 "detected (%x of %x bytes)...returning "
1116 "error status.\n", vha->host_no,
1117 cp->device->channel, cp->device->id,
1118 cp->device->lun, resid,
1121 cp->result = DID_ERROR << 16;
1125 cp->result = DID_OK << 16 | lscsi_status;
1127 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1128 DEBUG2(printk(KERN_INFO
1129 "scsi(%ld): QUEUE FULL status detected "
1130 "0x%x-0x%x.\n", vha->host_no, comp_status,
1133 /* Adjust queue depth for all luns on the port. */
1134 if (!ql2xqfulltracking)
1136 fcport->last_queue_full = jiffies;
1137 starget_for_each_device(cp->device->sdev_target,
1138 fcport, qla2x00_adjust_sdev_qdepth_down);
1141 if (lscsi_status != SS_CHECK_CONDITION)
1144 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1145 if (!(scsi_status & SS_SENSE_LEN_VALID))
1148 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
1151 case CS_DATA_UNDERRUN:
1153 /* Use F/W calculated residual length. */
1154 if (IS_FWI2_CAPABLE(ha)) {
1155 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1157 } else if (resid != fw_resid_len) {
1158 scsi_status &= ~SS_RESIDUAL_UNDER;
1161 resid = fw_resid_len;
1164 if (scsi_status & SS_RESIDUAL_UNDER) {
1165 scsi_set_resid(cp, resid);
1167 DEBUG2(printk(KERN_INFO
1168 "scsi(%ld:%d:%d) UNDERRUN status detected "
1169 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1170 "os_underflow=0x%x\n", vha->host_no,
1171 cp->device->id, cp->device->lun, comp_status,
1172 scsi_status, resid_len, resid, cp->cmnd[0],
1178 * Check to see if SCSI Status is non zero. If so report SCSI
1181 if (lscsi_status != 0) {
1182 cp->result = DID_OK << 16 | lscsi_status;
1184 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1185 DEBUG2(printk(KERN_INFO
1186 "scsi(%ld): QUEUE FULL status detected "
1187 "0x%x-0x%x.\n", vha->host_no, comp_status,
1191 * Adjust queue depth for all luns on the
1194 if (!ql2xqfulltracking)
1196 fcport->last_queue_full = jiffies;
1197 starget_for_each_device(
1198 cp->device->sdev_target, fcport,
1199 qla2x00_adjust_sdev_qdepth_down);
1202 if (lscsi_status != SS_CHECK_CONDITION)
1205 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1206 if (!(scsi_status & SS_SENSE_LEN_VALID))
1209 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
1212 * If RISC reports underrun and target does not report
1213 * it then we must have a lost frame, so tell upper
1214 * layer to retry it by reporting a bus busy.
1216 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1217 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1218 "frame(s) detected (%x of %x bytes)..."
1219 "retrying command.\n",
1220 vha->host_no, cp->device->channel,
1221 cp->device->id, cp->device->lun, resid,
1224 cp->result = DID_BUS_BUSY << 16;
1228 /* Handle mid-layer underflow */
1229 if ((unsigned)(scsi_bufflen(cp) - resid) <
1231 qla_printk(KERN_INFO, ha,
1232 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1233 "detected (%x of %x bytes)...returning "
1234 "error status.\n", vha->host_no,
1235 cp->device->channel, cp->device->id,
1236 cp->device->lun, resid,
1239 cp->result = DID_ERROR << 16;
1243 /* Everybody online, looking good... */
1244 cp->result = DID_OK << 16;
1248 case CS_DATA_OVERRUN:
1249 DEBUG2(printk(KERN_INFO
1250 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1251 vha->host_no, cp->device->id, cp->device->lun, comp_status,
1253 DEBUG2(printk(KERN_INFO
1254 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1255 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1256 cp->cmnd[4], cp->cmnd[5]));
1257 DEBUG2(printk(KERN_INFO
1258 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1260 cp->serial_number, scsi_bufflen(cp), resid_len));
1262 cp->result = DID_ERROR << 16;
1265 case CS_PORT_LOGGED_OUT:
1266 case CS_PORT_CONFIG_CHG:
1269 case CS_PORT_UNAVAILABLE:
1271 * If the port is in Target Down state, return all IOs for this
1272 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1275 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1276 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1277 vha->host_no, cp->device->id, cp->device->lun,
1278 cp->serial_number, comp_status,
1279 atomic_read(&fcport->state)));
1282 * We are going to have the fc class block the rport
1283 * while we try to recover so instruct the mid layer
1284 * to requeue until the class decides how to handle this.
1286 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1287 if (atomic_read(&fcport->state) == FCS_ONLINE)
1288 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1292 DEBUG2(printk(KERN_INFO
1293 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1294 vha->host_no, comp_status, scsi_status));
1296 cp->result = DID_RESET << 16;
1301 * hv2.19.12 - DID_ABORT does not retry the request if we
1302 * aborted this request then abort otherwise it must be a
1305 DEBUG2(printk(KERN_INFO
1306 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1307 vha->host_no, comp_status, scsi_status));
1309 cp->result = DID_RESET << 16;
1314 * We are going to have the fc class block the rport
1315 * while we try to recover so instruct the mid layer
1316 * to requeue until the class decides how to handle this.
1318 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1320 if (IS_FWI2_CAPABLE(ha)) {
1321 DEBUG2(printk(KERN_INFO
1322 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1323 "0x%x-0x%x\n", vha->host_no, cp->device->channel,
1324 cp->device->id, cp->device->lun, comp_status,
1328 DEBUG2(printk(KERN_INFO
1329 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1330 "sflags=%x.\n", vha->host_no, cp->device->channel,
1331 cp->device->id, cp->device->lun, comp_status, scsi_status,
1332 le16_to_cpu(sts->status_flags)));
1334 /* Check to see if logout occurred. */
1335 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
1336 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1340 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1341 "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
1342 qla_printk(KERN_INFO, ha,
1343 "Unknown status detected 0x%x-0x%x.\n",
1344 comp_status, scsi_status);
1346 cp->result = DID_ERROR << 16;
1350 /* Place command on done queue. */
1351 if (rsp->status_srb == NULL)
1352 qla2x00_sp_compl(ha, sp);
1356 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1357 * @ha: SCSI driver HA context
1358 * @pkt: Entry pointer
1360 * Extended sense data.
1363 qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
1365 uint8_t sense_sz = 0;
1366 struct qla_hw_data *ha = rsp->hw;
1367 srb_t *sp = rsp->status_srb;
1368 struct scsi_cmnd *cp;
1370 if (sp != NULL && sp->request_sense_length != 0) {
1373 DEBUG2(printk("%s(): Cmd already returned back to OS "
1374 "sp=%p.\n", __func__, sp));
1375 qla_printk(KERN_INFO, ha,
1376 "cmd is NULL: already returned to OS (sp=%p)\n",
1379 rsp->status_srb = NULL;
1383 if (sp->request_sense_length > sizeof(pkt->data)) {
1384 sense_sz = sizeof(pkt->data);
1386 sense_sz = sp->request_sense_length;
1389 /* Move sense data. */
1390 if (IS_FWI2_CAPABLE(ha))
1391 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
1392 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1393 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1395 sp->request_sense_ptr += sense_sz;
1396 sp->request_sense_length -= sense_sz;
1398 /* Place command on done queue. */
1399 if (sp->request_sense_length == 0) {
1400 rsp->status_srb = NULL;
1401 qla2x00_sp_compl(ha, sp);
1407 * qla2x00_error_entry() - Process an error entry.
1408 * @ha: SCSI driver HA context
1409 * @pkt: Entry pointer
1412 qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
1415 struct qla_hw_data *ha = vha->hw;
1416 uint32_t handle = LSW(pkt->handle);
1417 uint16_t que = MSW(pkt->handle);
1418 struct req_que *req = ha->req_q_map[que];
1419 #if defined(QL_DEBUG_LEVEL_2)
1420 if (pkt->entry_status & RF_INV_E_ORDER)
1421 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1422 else if (pkt->entry_status & RF_INV_E_COUNT)
1423 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1424 else if (pkt->entry_status & RF_INV_E_PARAM)
1425 qla_printk(KERN_ERR, ha,
1426 "%s: Invalid Entry Parameter\n", __func__);
1427 else if (pkt->entry_status & RF_INV_E_TYPE)
1428 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1429 else if (pkt->entry_status & RF_BUSY)
1430 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1432 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1435 /* Validate handle. */
1436 if (handle < MAX_OUTSTANDING_COMMANDS)
1437 sp = req->outstanding_cmds[handle];
1442 /* Free outstanding command slot. */
1443 req->outstanding_cmds[handle] = NULL;
1445 /* Bad payload or header */
1446 if (pkt->entry_status &
1447 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1448 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1449 sp->cmd->result = DID_ERROR << 16;
1450 } else if (pkt->entry_status & RF_BUSY) {
1451 sp->cmd->result = DID_BUS_BUSY << 16;
1453 sp->cmd->result = DID_ERROR << 16;
1455 qla2x00_sp_compl(ha, sp);
1457 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1458 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
1459 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1461 qla_printk(KERN_WARNING, ha,
1462 "Error entry - invalid handle\n");
1464 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1465 qla2xxx_wake_dpc(vha);
1470 * qla24xx_mbx_completion() - Process mailbox command completions.
1471 * @ha: SCSI driver HA context
1472 * @mb0: Mailbox0 register
1475 qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
1478 uint16_t __iomem *wptr;
1479 struct qla_hw_data *ha = vha->hw;
1480 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1482 /* Load return mailbox registers. */
1483 ha->flags.mbox_int = 1;
1484 ha->mailbox_out[0] = mb0;
1485 wptr = (uint16_t __iomem *)®->mailbox1;
1487 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1488 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1493 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1494 __func__, vha->host_no, ha->mcp->mb[0]));
1496 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1497 __func__, vha->host_no));
1502 * qla24xx_process_response_queue() - Process response queue entries.
1503 * @ha: SCSI driver HA context
1505 void qla24xx_process_response_queue(struct scsi_qla_host *vha,
1506 struct rsp_que *rsp)
1508 struct sts_entry_24xx *pkt;
1510 if (!vha->flags.online)
1513 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1514 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
1517 if (rsp->ring_index == rsp->length) {
1518 rsp->ring_index = 0;
1519 rsp->ring_ptr = rsp->ring;
1524 if (pkt->entry_status != 0) {
1525 DEBUG3(printk(KERN_INFO
1526 "scsi(%ld): Process error entry.\n", vha->host_no));
1528 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
1529 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1534 switch (pkt->entry_type) {
1536 qla2x00_status_entry(vha, rsp, pkt);
1538 case STATUS_CONT_TYPE:
1539 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
1541 case VP_RPT_ID_IOCB_TYPE:
1542 qla24xx_report_id_acquisition(vha,
1543 (struct vp_rpt_id_entry_24xx *)pkt);
1546 /* Type Not Supported. */
1547 DEBUG4(printk(KERN_WARNING
1548 "scsi(%ld): Received unknown response pkt type %x "
1549 "entry status=%x.\n",
1550 vha->host_no, pkt->entry_type, pkt->entry_status));
1553 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1557 /* Adjust ring index */
1558 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
1562 qla2xxx_check_risc_status(scsi_qla_host_t *vha)
1566 struct qla_hw_data *ha = vha->hw;
1567 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1569 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
1573 WRT_REG_DWORD(®->iobase_addr, 0x7C00);
1574 RD_REG_DWORD(®->iobase_addr);
1575 WRT_REG_DWORD(®->iobase_window, 0x0001);
1576 for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1577 rval == QLA_SUCCESS; cnt--) {
1579 WRT_REG_DWORD(®->iobase_window, 0x0001);
1582 rval = QLA_FUNCTION_TIMEOUT;
1584 if (rval == QLA_SUCCESS)
1587 WRT_REG_DWORD(®->iobase_window, 0x0003);
1588 for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1589 rval == QLA_SUCCESS; cnt--) {
1591 WRT_REG_DWORD(®->iobase_window, 0x0003);
1594 rval = QLA_FUNCTION_TIMEOUT;
1596 if (rval != QLA_SUCCESS)
1600 if (RD_REG_DWORD(®->iobase_c8) & BIT_3)
1601 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1604 WRT_REG_DWORD(®->iobase_window, 0x0000);
1605 RD_REG_DWORD(®->iobase_window);
1609 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1611 * @dev_id: SCSI driver HA context
1613 * Called by system whenever the host adapter generates an interrupt.
1615 * Returns handled flag.
1618 qla24xx_intr_handler(int irq, void *dev_id)
1620 scsi_qla_host_t *vha;
1621 struct qla_hw_data *ha;
1622 struct device_reg_24xx __iomem *reg;
1628 struct rsp_que *rsp;
1630 rsp = (struct rsp_que *) dev_id;
1633 "%s(): NULL response queue pointer\n", __func__);
1638 reg = &ha->iobase->isp24;
1641 spin_lock(&ha->hardware_lock);
1642 vha = pci_get_drvdata(ha->pdev);
1643 for (iter = 50; iter--; ) {
1644 stat = RD_REG_DWORD(®->host_status);
1645 if (stat & HSRX_RISC_PAUSED) {
1646 if (pci_channel_offline(ha->pdev))
1649 hccr = RD_REG_DWORD(®->hccr);
1651 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1652 "Dumping firmware!\n", hccr);
1654 qla2xxx_check_risc_status(vha);
1656 ha->isp_ops->fw_dump(vha, 1);
1657 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1659 } else if ((stat & HSRX_RISC_INT) == 0)
1662 switch (stat & 0xff) {
1667 qla24xx_mbx_completion(vha, MSW(stat));
1668 status |= MBX_INTERRUPT;
1673 mb[1] = RD_REG_WORD(®->mailbox1);
1674 mb[2] = RD_REG_WORD(®->mailbox2);
1675 mb[3] = RD_REG_WORD(®->mailbox3);
1676 qla2x00_async_event(vha, rsp, mb);
1680 qla24xx_process_response_queue(vha, rsp);
1683 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1685 vha->host_no, stat & 0xff));
1688 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1689 RD_REG_DWORD_RELAXED(®->hccr);
1691 spin_unlock(&ha->hardware_lock);
1693 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1694 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1695 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1696 complete(&ha->mbx_intr_comp);
1703 qla24xx_msix_rsp_q(int irq, void *dev_id)
1705 struct qla_hw_data *ha;
1706 struct rsp_que *rsp;
1707 struct device_reg_24xx __iomem *reg;
1708 struct scsi_qla_host *vha;
1710 rsp = (struct rsp_que *) dev_id;
1713 "%s(): NULL response queue pointer\n", __func__);
1717 reg = &ha->iobase->isp24;
1719 spin_lock_irq(&ha->hardware_lock);
1721 vha = qla25xx_get_host(rsp);
1722 qla24xx_process_response_queue(vha, rsp);
1723 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1725 spin_unlock_irq(&ha->hardware_lock);
1731 qla25xx_msix_rsp_q(int irq, void *dev_id)
1733 struct qla_hw_data *ha;
1734 struct rsp_que *rsp;
1736 rsp = (struct rsp_que *) dev_id;
1739 "%s(): NULL response queue pointer\n", __func__);
1744 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
1750 qla24xx_msix_default(int irq, void *dev_id)
1752 scsi_qla_host_t *vha;
1753 struct qla_hw_data *ha;
1754 struct rsp_que *rsp;
1755 struct device_reg_24xx __iomem *reg;
1761 rsp = (struct rsp_que *) dev_id;
1764 "%s(): NULL response queue pointer\n", __func__));
1768 reg = &ha->iobase->isp24;
1771 spin_lock_irq(&ha->hardware_lock);
1772 vha = pci_get_drvdata(ha->pdev);
1774 stat = RD_REG_DWORD(®->host_status);
1775 if (stat & HSRX_RISC_PAUSED) {
1776 if (pci_channel_offline(ha->pdev))
1779 hccr = RD_REG_DWORD(®->hccr);
1781 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1782 "Dumping firmware!\n", hccr);
1784 qla2xxx_check_risc_status(vha);
1786 ha->isp_ops->fw_dump(vha, 1);
1787 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1789 } else if ((stat & HSRX_RISC_INT) == 0)
1792 switch (stat & 0xff) {
1797 qla24xx_mbx_completion(vha, MSW(stat));
1798 status |= MBX_INTERRUPT;
1803 mb[1] = RD_REG_WORD(®->mailbox1);
1804 mb[2] = RD_REG_WORD(®->mailbox2);
1805 mb[3] = RD_REG_WORD(®->mailbox3);
1806 qla2x00_async_event(vha, rsp, mb);
1810 qla24xx_process_response_queue(vha, rsp);
1813 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1815 vha->host_no, stat & 0xff));
1818 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1820 spin_unlock_irq(&ha->hardware_lock);
1822 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1823 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1824 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1825 complete(&ha->mbx_intr_comp);
1831 /* Interrupt handling helpers. */
1833 struct qla_init_msix_entry {
1835 irq_handler_t handler;
1838 static struct qla_init_msix_entry msix_entries[3] = {
1839 { "qla2xxx (default)", qla24xx_msix_default },
1840 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1841 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
1845 qla24xx_disable_msix(struct qla_hw_data *ha)
1848 struct qla_msix_entry *qentry;
1850 for (i = 0; i < ha->msix_count; i++) {
1851 qentry = &ha->msix_entries[i];
1852 if (qentry->have_irq)
1853 free_irq(qentry->vector, qentry->rsp);
1855 pci_disable_msix(ha->pdev);
1856 kfree(ha->msix_entries);
1857 ha->msix_entries = NULL;
1858 ha->flags.msix_enabled = 0;
1862 qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
1864 #define MIN_MSIX_COUNT 2
1866 struct msix_entry *entries;
1867 struct qla_msix_entry *qentry;
1869 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
1874 for (i = 0; i < ha->msix_count; i++)
1875 entries[i].entry = i;
1877 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1879 if (ret < MIN_MSIX_COUNT)
1882 qla_printk(KERN_WARNING, ha,
1883 "MSI-X: Failed to enable support -- %d/%d\n"
1884 " Retry with %d vectors\n", ha->msix_count, ret, ret);
1885 ha->msix_count = ret;
1886 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1889 qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
1890 " support, giving up -- %d/%d\n",
1891 ha->msix_count, ret);
1894 ha->max_rsp_queues = ha->msix_count - 1;
1896 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
1897 ha->msix_count, GFP_KERNEL);
1898 if (!ha->msix_entries) {
1902 ha->flags.msix_enabled = 1;
1904 for (i = 0; i < ha->msix_count; i++) {
1905 qentry = &ha->msix_entries[i];
1906 qentry->vector = entries[i].vector;
1907 qentry->entry = entries[i].entry;
1908 qentry->have_irq = 0;
1912 /* Enable MSI-X vectors for the base queue */
1913 for (i = 0; i < 2; i++) {
1914 qentry = &ha->msix_entries[i];
1915 ret = request_irq(qentry->vector, msix_entries[i].handler,
1916 0, msix_entries[i].name, rsp);
1918 qla_printk(KERN_WARNING, ha,
1919 "MSI-X: Unable to register handler -- %x/%d.\n",
1920 qentry->vector, ret);
1921 qla24xx_disable_msix(ha);
1925 qentry->have_irq = 1;
1930 /* Enable MSI-X vector for response queue update for queue 0 */
1931 if (ha->mqiobase && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
1940 qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
1943 device_reg_t __iomem *reg = ha->iobase;
1945 /* If possible, enable MSI-X. */
1946 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
1947 !IS_QLA8432(ha) && !IS_QLA8001(ha))
1950 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
1951 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
1952 DEBUG2(qla_printk(KERN_WARNING, ha,
1953 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1954 ha->pdev->revision, ha->fw_attributes));
1959 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1960 (ha->pdev->subsystem_device == 0x7040 ||
1961 ha->pdev->subsystem_device == 0x7041 ||
1962 ha->pdev->subsystem_device == 0x1705)) {
1963 DEBUG2(qla_printk(KERN_WARNING, ha,
1964 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1965 ha->pdev->subsystem_vendor,
1966 ha->pdev->subsystem_device));
1971 ret = qla24xx_enable_msix(ha, rsp);
1973 DEBUG2(qla_printk(KERN_INFO, ha,
1974 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1975 ha->fw_attributes));
1976 goto clear_risc_ints;
1978 qla_printk(KERN_WARNING, ha,
1979 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1982 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
1986 ret = pci_enable_msi(ha->pdev);
1988 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1989 ha->flags.msi_enabled = 1;
1993 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
1994 IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
1996 qla_printk(KERN_WARNING, ha,
1997 "Failed to reserve interrupt %d already in use.\n",
2001 ha->flags.inta_enabled = 1;
2005 * FIXME: Noted that 8014s were being dropped during NK testing.
2006 * Timing deltas during MSI-X/INTa transitions?
2010 spin_lock_irq(&ha->hardware_lock);
2011 if (IS_FWI2_CAPABLE(ha)) {
2012 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT);
2013 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT);
2015 WRT_REG_WORD(®->isp.semaphore, 0);
2016 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT);
2017 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT);
2019 spin_unlock_irq(&ha->hardware_lock);
2026 qla2x00_free_irqs(scsi_qla_host_t *vha)
2028 struct qla_hw_data *ha = vha->hw;
2029 struct rsp_que *rsp = ha->rsp_q_map[0];
2031 if (ha->flags.msix_enabled)
2032 qla24xx_disable_msix(ha);
2033 else if (ha->flags.inta_enabled) {
2034 free_irq(ha->pdev->irq, rsp);
2035 pci_disable_msi(ha->pdev);
2040 int qla25xx_request_irq(struct rsp_que *rsp)
2042 struct qla_hw_data *ha = rsp->hw;
2043 struct qla_init_msix_entry *intr = &msix_entries[2];
2044 struct qla_msix_entry *msix = rsp->msix;
2047 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2049 qla_printk(KERN_WARNING, ha,
2050 "MSI-X: Unable to register handler -- %x/%d.\n",
2059 struct scsi_qla_host *
2060 qla25xx_get_host(struct rsp_que *rsp)
2063 struct qla_hw_data *ha = rsp->hw;
2064 struct scsi_qla_host *vha = NULL;
2065 struct sts_entry_24xx *pkt;
2066 struct req_que *req;
2070 pkt = (struct sts_entry_24xx *) rsp->ring_ptr;
2071 que = MSW(pkt->handle);
2072 handle = (uint32_t) LSW(pkt->handle);
2073 req = ha->req_q_map[que];
2074 if (handle < MAX_OUTSTANDING_COMMANDS) {
2075 sp = req->outstanding_cmds[handle];
2077 return sp->fcport->vha;
2082 vha = pci_get_drvdata(ha->pdev);