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(scsi_qla_host_t *, sts_cont_entry_t *);
17 static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
19 static struct scsi_qla_host *qla2x00_get_rsp_host(struct rsp_que *);
22 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
24 * @dev_id: SCSI driver HA context
26 * Called by system whenever the host adapter generates an interrupt.
28 * Returns handled flag.
31 qla2100_intr_handler(int irq, void *dev_id)
34 struct qla_hw_data *ha;
35 struct device_reg_2xxx __iomem *reg;
42 rsp = (struct rsp_que *) dev_id;
45 "%s(): NULL response queue pointer\n", __func__);
50 reg = &ha->iobase->isp;
53 spin_lock(&ha->hardware_lock);
54 vha = qla2x00_get_rsp_host(rsp);
55 for (iter = 50; iter--; ) {
56 hccr = RD_REG_WORD(®->hccr);
57 if (hccr & HCCR_RISC_PAUSE) {
58 if (pci_channel_offline(ha->pdev))
62 * Issue a "HARD" reset in order for the RISC interrupt
63 * bit to be cleared. Schedule a big hammmer to get
64 * out of the RISC PAUSED state.
66 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
67 RD_REG_WORD(®->hccr);
69 ha->isp_ops->fw_dump(vha, 1);
70 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
72 } else if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0)
75 if (RD_REG_WORD(®->semaphore) & BIT_0) {
76 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
77 RD_REG_WORD(®->hccr);
79 /* Get mailbox data. */
80 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
81 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
82 qla2x00_mbx_completion(vha, mb[0]);
83 status |= MBX_INTERRUPT;
84 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
85 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
86 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
87 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
88 qla2x00_async_event(vha, rsp, mb);
91 DEBUG2(printk("scsi(%ld): Unrecognized "
92 "interrupt type (%d).\n",
93 vha->host_no, mb[0]));
95 /* Release mailbox registers. */
96 WRT_REG_WORD(®->semaphore, 0);
97 RD_REG_WORD(®->semaphore);
99 qla2x00_process_response_queue(rsp);
101 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
102 RD_REG_WORD(®->hccr);
105 spin_unlock(&ha->hardware_lock);
107 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
108 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
109 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
110 complete(&ha->mbx_intr_comp);
113 return (IRQ_HANDLED);
117 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
119 * @dev_id: SCSI driver HA context
121 * Called by system whenever the host adapter generates an interrupt.
123 * Returns handled flag.
126 qla2300_intr_handler(int irq, void *dev_id)
128 scsi_qla_host_t *vha;
129 struct device_reg_2xxx __iomem *reg;
136 struct qla_hw_data *ha;
138 rsp = (struct rsp_que *) dev_id;
141 "%s(): NULL response queue pointer\n", __func__);
146 reg = &ha->iobase->isp;
149 spin_lock(&ha->hardware_lock);
150 vha = qla2x00_get_rsp_host(rsp);
151 for (iter = 50; iter--; ) {
152 stat = RD_REG_DWORD(®->u.isp2300.host_status);
153 if (stat & HSR_RISC_PAUSED) {
154 if (pci_channel_offline(ha->pdev))
157 hccr = RD_REG_WORD(®->hccr);
158 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
159 qla_printk(KERN_INFO, ha, "Parity error -- "
160 "HCCR=%x, Dumping firmware!\n", hccr);
162 qla_printk(KERN_INFO, ha, "RISC paused -- "
163 "HCCR=%x, Dumping firmware!\n", hccr);
166 * Issue a "HARD" reset in order for the RISC
167 * interrupt bit to be cleared. Schedule a big
168 * hammmer to get out of the RISC PAUSED state.
170 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
171 RD_REG_WORD(®->hccr);
173 ha->isp_ops->fw_dump(vha, 1);
174 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
176 } else if ((stat & HSR_RISC_INT) == 0)
179 switch (stat & 0xff) {
184 qla2x00_mbx_completion(vha, MSW(stat));
185 status |= MBX_INTERRUPT;
187 /* Release mailbox registers. */
188 WRT_REG_WORD(®->semaphore, 0);
192 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
193 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
194 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
195 qla2x00_async_event(vha, rsp, mb);
198 qla2x00_process_response_queue(rsp);
201 mb[0] = MBA_CMPLT_1_16BIT;
203 qla2x00_async_event(vha, rsp, mb);
206 mb[0] = MBA_SCSI_COMPLETION;
208 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
209 qla2x00_async_event(vha, rsp, mb);
212 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
214 vha->host_no, stat & 0xff));
217 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
218 RD_REG_WORD_RELAXED(®->hccr);
220 spin_unlock(&ha->hardware_lock);
222 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
223 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
224 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
225 complete(&ha->mbx_intr_comp);
228 return (IRQ_HANDLED);
232 * qla2x00_mbx_completion() - Process mailbox command completions.
233 * @ha: SCSI driver HA context
234 * @mb0: Mailbox0 register
237 qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
240 uint16_t __iomem *wptr;
241 struct qla_hw_data *ha = vha->hw;
242 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
244 /* Load return mailbox registers. */
245 ha->flags.mbox_int = 1;
246 ha->mailbox_out[0] = mb0;
247 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
249 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
250 if (IS_QLA2200(ha) && cnt == 8)
251 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
252 if (cnt == 4 || cnt == 5)
253 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
255 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
261 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
262 __func__, vha->host_no, ha->mcp->mb[0]));
264 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
265 __func__, vha->host_no));
270 * qla2x00_async_event() - Process aynchronous events.
271 * @ha: SCSI driver HA context
272 * @mb: Mailbox registers (0 - 3)
275 qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
278 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
283 struct qla_hw_data *ha = vha->hw;
284 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
285 uint32_t rscn_entry, host_pid;
286 uint8_t rscn_queue_index;
289 /* Setup to process RIO completion. */
294 case MBA_SCSI_COMPLETION:
295 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
298 case MBA_CMPLT_1_16BIT:
301 mb[0] = MBA_SCSI_COMPLETION;
303 case MBA_CMPLT_2_16BIT:
307 mb[0] = MBA_SCSI_COMPLETION;
309 case MBA_CMPLT_3_16BIT:
314 mb[0] = MBA_SCSI_COMPLETION;
316 case MBA_CMPLT_4_16BIT:
320 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
322 mb[0] = MBA_SCSI_COMPLETION;
324 case MBA_CMPLT_5_16BIT:
328 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
329 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
331 mb[0] = MBA_SCSI_COMPLETION;
333 case MBA_CMPLT_2_32BIT:
334 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
335 handles[1] = le32_to_cpu(
336 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
337 RD_MAILBOX_REG(ha, reg, 6));
339 mb[0] = MBA_SCSI_COMPLETION;
346 case MBA_SCSI_COMPLETION: /* Fast Post */
347 if (!vha->flags.online)
350 for (cnt = 0; cnt < handle_cnt; cnt++)
351 qla2x00_process_completed_request(vha, rsp->req,
355 case MBA_RESET: /* Reset */
356 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
359 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
362 case MBA_SYSTEM_ERR: /* System Error */
363 qla_printk(KERN_INFO, ha,
364 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
365 mb[1], mb[2], mb[3]);
367 ha->isp_ops->fw_dump(vha, 1);
369 if (IS_FWI2_CAPABLE(ha)) {
370 if (mb[1] == 0 && mb[2] == 0) {
371 qla_printk(KERN_ERR, ha,
372 "Unrecoverable Hardware Error: adapter "
373 "marked OFFLINE!\n");
374 vha->flags.online = 0;
376 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
377 } else if (mb[1] == 0) {
378 qla_printk(KERN_INFO, ha,
379 "Unrecoverable Hardware Error: adapter marked "
381 vha->flags.online = 0;
383 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
386 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
387 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
389 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
391 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
394 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
395 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
397 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
399 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
402 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
403 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
407 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
408 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
410 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
412 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
413 atomic_set(&vha->loop_state, LOOP_DOWN);
414 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
415 qla2x00_mark_all_devices_lost(vha, 1);
419 atomic_set(&vha->vp_state, VP_FAILED);
420 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
423 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
424 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
426 vha->flags.management_server_logged_in = 0;
427 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
430 case MBA_LOOP_UP: /* Loop Up Event */
431 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
432 link_speed = link_speeds[0];
433 ha->link_data_rate = PORT_SPEED_1GB;
435 link_speed = link_speeds[LS_UNKNOWN];
437 link_speed = link_speeds[mb[1]];
438 else if (mb[1] == 0x13)
439 link_speed = link_speeds[5];
440 ha->link_data_rate = mb[1];
443 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
444 vha->host_no, link_speed));
445 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
448 vha->flags.management_server_logged_in = 0;
449 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
452 case MBA_LOOP_DOWN: /* Loop Down Event */
453 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
454 "(%x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3]));
455 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
456 mb[1], mb[2], mb[3]);
458 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
459 atomic_set(&vha->loop_state, LOOP_DOWN);
460 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
461 vha->device_flags |= DFLG_NO_CABLE;
462 qla2x00_mark_all_devices_lost(vha, 1);
466 atomic_set(&vha->vp_state, VP_FAILED);
467 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
470 vha->flags.management_server_logged_in = 0;
471 ha->link_data_rate = PORT_SPEED_UNKNOWN;
472 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
475 case MBA_LIP_RESET: /* LIP reset occurred */
476 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
477 vha->host_no, mb[1]));
478 qla_printk(KERN_INFO, ha,
479 "LIP reset occurred (%x).\n", mb[1]);
481 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
482 atomic_set(&vha->loop_state, LOOP_DOWN);
483 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
484 qla2x00_mark_all_devices_lost(vha, 1);
488 atomic_set(&vha->vp_state, VP_FAILED);
489 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
492 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
494 ha->operating_mode = LOOP;
495 vha->flags.management_server_logged_in = 0;
496 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
499 /* case MBA_DCBX_COMPLETE: */
500 case MBA_POINT_TO_POINT: /* Point-to-Point */
505 DEBUG2(printk("scsi(%ld): DCBX Completed -- %04x %04x "
506 "%04x\n", vha->host_no, mb[1], mb[2], mb[3]));
508 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE "
509 "received.\n", vha->host_no));
512 * Until there's a transition from loop down to loop up, treat
513 * this as loop down only.
515 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
516 atomic_set(&vha->loop_state, LOOP_DOWN);
517 if (!atomic_read(&vha->loop_down_timer))
518 atomic_set(&vha->loop_down_timer,
520 qla2x00_mark_all_devices_lost(vha, 1);
524 atomic_set(&vha->vp_state, VP_FAILED);
525 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
528 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
529 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
531 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
532 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
534 ha->flags.gpsc_supported = 1;
535 vha->flags.management_server_logged_in = 0;
538 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
542 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
545 qla_printk(KERN_INFO, ha,
546 "Configuration change detected: value=%x.\n", mb[1]);
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 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
562 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
565 case MBA_PORT_UPDATE: /* Port database update */
566 /* Only handle SCNs for our Vport index. */
567 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
571 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
572 * event etc. earlier indicating loop is down) then process
573 * it. Otherwise ignore it and Wait for RSCN to come in.
575 atomic_set(&vha->loop_down_timer, 0);
576 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
577 atomic_read(&vha->loop_state) != LOOP_DEAD) {
578 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
579 "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
584 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
586 DEBUG(printk(KERN_INFO
587 "scsi(%ld): Port database changed %04x %04x %04x.\n",
588 vha->host_no, mb[1], mb[2], mb[3]));
591 * Mark all devices as missing so we will login again.
593 atomic_set(&vha->loop_state, LOOP_UP);
595 qla2x00_mark_all_devices_lost(vha, 1);
597 vha->flags.rscn_queue_overflow = 1;
599 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
600 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
603 case MBA_RSCN_UPDATE: /* State Change Registration */
604 /* Check if the Vport has issued a SCR */
605 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
607 /* Only handle SCNs for our Vport index. */
608 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
610 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
612 DEBUG(printk(KERN_INFO
613 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
614 vha->host_no, mb[1], mb[2], mb[3]));
616 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
617 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
619 if (rscn_entry == host_pid) {
620 DEBUG(printk(KERN_INFO
621 "scsi(%ld): Ignoring RSCN update to local host "
623 vha->host_no, host_pid));
627 /* Ignore reserved bits from RSCN-payload. */
628 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
629 rscn_queue_index = vha->rscn_in_ptr + 1;
630 if (rscn_queue_index == MAX_RSCN_COUNT)
631 rscn_queue_index = 0;
632 if (rscn_queue_index != vha->rscn_out_ptr) {
633 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
634 vha->rscn_in_ptr = rscn_queue_index;
636 vha->flags.rscn_queue_overflow = 1;
639 atomic_set(&vha->loop_state, LOOP_UPDATE);
640 atomic_set(&vha->loop_down_timer, 0);
641 vha->flags.management_server_logged_in = 0;
643 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
644 set_bit(RSCN_UPDATE, &vha->dpc_flags);
645 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
648 /* case MBA_RIO_RESPONSE: */
649 case MBA_ZIO_RESPONSE:
650 DEBUG3(printk("scsi(%ld): [R|Z]IO update completion.\n",
653 if (IS_FWI2_CAPABLE(ha))
654 qla24xx_process_response_queue(rsp);
656 qla2x00_process_response_queue(rsp);
659 case MBA_DISCARD_RND_FRAME:
660 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
661 "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
664 case MBA_TRACE_NOTIFICATION:
665 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
666 vha->host_no, mb[1], mb[2]));
669 case MBA_ISP84XX_ALERT:
670 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
671 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
673 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
675 case A84_PANIC_RECOVERY:
676 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
677 "%04x %04x\n", mb[2], mb[3]);
679 case A84_OP_LOGIN_COMPLETE:
680 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
681 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
682 "firmware version %x\n", ha->cs84xx->op_fw_version));
684 case A84_DIAG_LOGIN_COMPLETE:
685 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
686 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
687 "diagnostic firmware version %x\n",
688 ha->cs84xx->diag_fw_version));
690 case A84_GOLD_LOGIN_COMPLETE:
691 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
692 ha->cs84xx->fw_update = 1;
693 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
694 "firmware version %x\n",
695 ha->cs84xx->gold_fw_version));
698 qla_printk(KERN_ERR, ha,
699 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
700 mb[1], mb[2], mb[3]);
702 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
705 DEBUG2(printk("scsi(%ld): DCBX Started -- %04x %04x %04x\n",
706 vha->host_no, mb[1], mb[2], mb[3]));
708 case MBA_DCBX_PARAM_UPDATE:
709 DEBUG2(printk("scsi(%ld): DCBX Parameters Updated -- "
710 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
712 case MBA_FCF_CONF_ERR:
713 DEBUG2(printk("scsi(%ld): FCF Configuration Error -- "
714 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
716 case MBA_IDC_COMPLETE:
717 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation "
718 "Complete -- %04x %04x %04x\n", vha->host_no, mb[1], mb[2],
722 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation "
723 "Request Notification -- %04x %04x %04x\n", vha->host_no,
724 mb[1], mb[2], mb[3]));
725 /**** Mailbox registers 4 - 7 valid!!! */
727 case MBA_IDC_TIME_EXT:
728 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation "
729 "Time Extension -- %04x %04x %04x\n", vha->host_no, mb[1],
731 /**** Mailbox registers 4 - 7 valid!!! */
735 if (!vha->vp_idx && ha->num_vhosts)
736 qla2x00_alert_all_vps(rsp, mb);
740 qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
742 fc_port_t *fcport = data;
743 struct scsi_qla_host *vha = fcport->vha;
744 struct qla_hw_data *ha = vha->hw;
745 struct req_que *req = NULL;
747 req = ha->req_q_map[vha->req_ques[0]];
750 if (req->max_q_depth <= sdev->queue_depth)
753 if (sdev->ordered_tags)
754 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
755 sdev->queue_depth + 1);
757 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
758 sdev->queue_depth + 1);
760 fcport->last_ramp_up = jiffies;
762 DEBUG2(qla_printk(KERN_INFO, ha,
763 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
764 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
769 qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
771 fc_port_t *fcport = data;
773 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
776 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
777 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
778 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
783 qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, struct req_que *req,
787 struct scsi_device *sdev;
789 sdev = sp->cmd->device;
790 if (sdev->queue_depth >= req->max_q_depth)
794 if (time_before(jiffies,
795 fcport->last_ramp_up + ql2xqfullrampup * HZ))
797 if (time_before(jiffies,
798 fcport->last_queue_full + ql2xqfullrampup * HZ))
801 starget_for_each_device(sdev->sdev_target, fcport,
802 qla2x00_adjust_sdev_qdepth_up);
806 * qla2x00_process_completed_request() - Process a Fast Post response.
807 * @ha: SCSI driver HA context
811 qla2x00_process_completed_request(struct scsi_qla_host *vha,
812 struct req_que *req, uint32_t index)
815 struct qla_hw_data *ha = vha->hw;
817 /* Validate handle. */
818 if (index >= MAX_OUTSTANDING_COMMANDS) {
819 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
820 vha->host_no, index));
821 qla_printk(KERN_WARNING, ha,
822 "Invalid SCSI completion handle %d.\n", index);
824 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
828 sp = req->outstanding_cmds[index];
830 /* Free outstanding command slot. */
831 req->outstanding_cmds[index] = NULL;
833 CMD_COMPL_STATUS(sp->cmd) = 0L;
834 CMD_SCSI_STATUS(sp->cmd) = 0L;
836 /* Save ISP completion status */
837 sp->cmd->result = DID_OK << 16;
839 qla2x00_ramp_up_queue_depth(vha, req, sp);
840 qla2x00_sp_compl(ha, sp);
842 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
844 qla_printk(KERN_WARNING, ha,
845 "Invalid ISP SCSI completion handle\n");
847 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
852 * qla2x00_process_response_queue() - Process response queue entries.
853 * @ha: SCSI driver HA context
856 qla2x00_process_response_queue(struct rsp_que *rsp)
858 struct scsi_qla_host *vha;
859 struct qla_hw_data *ha = rsp->hw;
860 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
865 vha = qla2x00_get_rsp_host(rsp);
867 if (!vha->flags.online)
870 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
871 pkt = (sts_entry_t *)rsp->ring_ptr;
874 if (rsp->ring_index == rsp->length) {
876 rsp->ring_ptr = rsp->ring;
881 if (pkt->entry_status != 0) {
882 DEBUG3(printk(KERN_INFO
883 "scsi(%ld): Process error entry.\n", vha->host_no));
885 qla2x00_error_entry(vha, rsp, pkt);
886 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
891 switch (pkt->entry_type) {
893 qla2x00_status_entry(vha, rsp, pkt);
896 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
897 for (cnt = 0; cnt < handle_cnt; cnt++) {
898 qla2x00_process_completed_request(vha, rsp->req,
899 ((sts21_entry_t *)pkt)->handle[cnt]);
903 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
904 for (cnt = 0; cnt < handle_cnt; cnt++) {
905 qla2x00_process_completed_request(vha, rsp->req,
906 ((sts22_entry_t *)pkt)->handle[cnt]);
909 case STATUS_CONT_TYPE:
910 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
913 /* Type Not Supported. */
914 DEBUG4(printk(KERN_WARNING
915 "scsi(%ld): Received unknown response pkt type %x "
916 "entry status=%x.\n",
917 vha->host_no, pkt->entry_type, pkt->entry_status));
920 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
924 /* Adjust ring index */
925 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
929 qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
931 struct scsi_cmnd *cp = sp->cmd;
933 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
934 sense_len = SCSI_SENSE_BUFFERSIZE;
936 CMD_ACTUAL_SNSLEN(cp) = sense_len;
937 sp->request_sense_length = sense_len;
938 sp->request_sense_ptr = cp->sense_buffer;
939 if (sp->request_sense_length > 32)
942 memcpy(cp->sense_buffer, sense_data, sense_len);
944 sp->request_sense_ptr += sense_len;
945 sp->request_sense_length -= sense_len;
946 if (sp->request_sense_length != 0)
947 sp->fcport->vha->status_srb = sp;
949 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
950 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
951 cp->device->channel, cp->device->id, cp->device->lun, cp,
954 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
955 CMD_ACTUAL_SNSLEN(cp)));
959 * qla2x00_status_entry() - Process a Status IOCB entry.
960 * @ha: SCSI driver HA context
961 * @pkt: Entry pointer
964 qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
968 struct scsi_cmnd *cp;
970 struct sts_entry_24xx *sts24;
971 uint16_t comp_status;
972 uint16_t scsi_status;
973 uint8_t lscsi_status;
975 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
976 uint8_t *rsp_info, *sense_data;
977 struct qla_hw_data *ha = vha->hw;
978 struct req_que *req = rsp->req;
980 sts = (sts_entry_t *) pkt;
981 sts24 = (struct sts_entry_24xx *) pkt;
982 if (IS_FWI2_CAPABLE(ha)) {
983 comp_status = le16_to_cpu(sts24->comp_status);
984 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
986 comp_status = le16_to_cpu(sts->comp_status);
987 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
990 /* Fast path completion. */
991 if (comp_status == CS_COMPLETE && scsi_status == 0) {
992 qla2x00_process_completed_request(vha, req, sts->handle);
997 /* Validate handle. */
998 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
999 sp = req->outstanding_cmds[sts->handle];
1000 req->outstanding_cmds[sts->handle] = NULL;
1005 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
1007 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
1009 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1010 qla2xxx_wake_dpc(vha);
1015 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
1016 "pkt->handle=%d sp=%p.\n", vha->host_no, sts->handle, sp));
1017 qla_printk(KERN_WARNING, ha,
1018 "Command is NULL: already returned to OS (sp=%p)\n", sp);
1023 lscsi_status = scsi_status & STATUS_MASK;
1024 CMD_ENTRY_STATUS(cp) = sts->entry_status;
1025 CMD_COMPL_STATUS(cp) = comp_status;
1026 CMD_SCSI_STATUS(cp) = scsi_status;
1028 fcport = sp->fcport;
1030 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
1031 if (IS_FWI2_CAPABLE(ha)) {
1032 sense_len = le32_to_cpu(sts24->sense_len);
1033 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1034 resid_len = le32_to_cpu(sts24->rsp_residual_count);
1035 fw_resid_len = le32_to_cpu(sts24->residual_len);
1036 rsp_info = sts24->data;
1037 sense_data = sts24->data;
1038 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
1040 sense_len = le16_to_cpu(sts->req_sense_length);
1041 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
1042 resid_len = le32_to_cpu(sts->residual_length);
1043 rsp_info = sts->rsp_info;
1044 sense_data = sts->req_sense_data;
1047 /* Check for any FCP transport errors. */
1048 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
1049 /* Sense data lies beyond any FCP RESPONSE data. */
1050 if (IS_FWI2_CAPABLE(ha))
1051 sense_data += rsp_info_len;
1052 if (rsp_info_len > 3 && rsp_info[3]) {
1053 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1054 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
1055 "retrying command\n", vha->host_no,
1056 cp->device->channel, cp->device->id,
1057 cp->device->lun, rsp_info_len, rsp_info[0],
1058 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1059 rsp_info[5], rsp_info[6], rsp_info[7]));
1061 cp->result = DID_BUS_BUSY << 16;
1062 qla2x00_sp_compl(ha, sp);
1067 /* Check for overrun. */
1068 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1069 scsi_status & SS_RESIDUAL_OVER)
1070 comp_status = CS_DATA_OVERRUN;
1073 * Based on Host and scsi status generate status code for Linux
1075 switch (comp_status) {
1078 if (scsi_status == 0) {
1079 cp->result = DID_OK << 16;
1082 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
1084 scsi_set_resid(cp, resid);
1085 CMD_RESID_LEN(cp) = resid;
1087 if (!lscsi_status &&
1088 ((unsigned)(scsi_bufflen(cp) - resid) <
1090 qla_printk(KERN_INFO, ha,
1091 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1092 "detected (%x of %x bytes)...returning "
1093 "error status.\n", vha->host_no,
1094 cp->device->channel, cp->device->id,
1095 cp->device->lun, resid,
1098 cp->result = DID_ERROR << 16;
1102 cp->result = DID_OK << 16 | lscsi_status;
1104 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1105 DEBUG2(printk(KERN_INFO
1106 "scsi(%ld): QUEUE FULL status detected "
1107 "0x%x-0x%x.\n", vha->host_no, comp_status,
1110 /* Adjust queue depth for all luns on the port. */
1111 fcport->last_queue_full = jiffies;
1112 starget_for_each_device(cp->device->sdev_target,
1113 fcport, qla2x00_adjust_sdev_qdepth_down);
1116 if (lscsi_status != SS_CHECK_CONDITION)
1119 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1120 if (!(scsi_status & SS_SENSE_LEN_VALID))
1123 qla2x00_handle_sense(sp, sense_data, sense_len);
1126 case CS_DATA_UNDERRUN:
1128 /* Use F/W calculated residual length. */
1129 if (IS_FWI2_CAPABLE(ha)) {
1130 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1132 } else if (resid != fw_resid_len) {
1133 scsi_status &= ~SS_RESIDUAL_UNDER;
1136 resid = fw_resid_len;
1139 if (scsi_status & SS_RESIDUAL_UNDER) {
1140 scsi_set_resid(cp, resid);
1141 CMD_RESID_LEN(cp) = resid;
1143 DEBUG2(printk(KERN_INFO
1144 "scsi(%ld:%d:%d) UNDERRUN status detected "
1145 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1146 "os_underflow=0x%x\n", vha->host_no,
1147 cp->device->id, cp->device->lun, comp_status,
1148 scsi_status, resid_len, resid, cp->cmnd[0],
1154 * Check to see if SCSI Status is non zero. If so report SCSI
1157 if (lscsi_status != 0) {
1158 cp->result = DID_OK << 16 | lscsi_status;
1160 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1161 DEBUG2(printk(KERN_INFO
1162 "scsi(%ld): QUEUE FULL status detected "
1163 "0x%x-0x%x.\n", vha->host_no, comp_status,
1167 * Adjust queue depth for all luns on the
1170 fcport->last_queue_full = jiffies;
1171 starget_for_each_device(
1172 cp->device->sdev_target, fcport,
1173 qla2x00_adjust_sdev_qdepth_down);
1176 if (lscsi_status != SS_CHECK_CONDITION)
1179 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1180 if (!(scsi_status & SS_SENSE_LEN_VALID))
1183 qla2x00_handle_sense(sp, sense_data, sense_len);
1186 * If RISC reports underrun and target does not report
1187 * it then we must have a lost frame, so tell upper
1188 * layer to retry it by reporting a bus busy.
1190 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1191 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1192 "frame(s) detected (%x of %x bytes)..."
1193 "retrying command.\n",
1194 vha->host_no, cp->device->channel,
1195 cp->device->id, cp->device->lun, resid,
1198 cp->result = DID_BUS_BUSY << 16;
1202 /* Handle mid-layer underflow */
1203 if ((unsigned)(scsi_bufflen(cp) - resid) <
1205 qla_printk(KERN_INFO, ha,
1206 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1207 "detected (%x of %x bytes)...returning "
1208 "error status.\n", vha->host_no,
1209 cp->device->channel, cp->device->id,
1210 cp->device->lun, resid,
1213 cp->result = DID_ERROR << 16;
1217 /* Everybody online, looking good... */
1218 cp->result = DID_OK << 16;
1222 case CS_DATA_OVERRUN:
1223 DEBUG2(printk(KERN_INFO
1224 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1225 vha->host_no, cp->device->id, cp->device->lun, comp_status,
1227 DEBUG2(printk(KERN_INFO
1228 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1229 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1230 cp->cmnd[4], cp->cmnd[5]));
1231 DEBUG2(printk(KERN_INFO
1232 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1234 cp->serial_number, scsi_bufflen(cp), resid_len));
1236 cp->result = DID_ERROR << 16;
1239 case CS_PORT_LOGGED_OUT:
1240 case CS_PORT_CONFIG_CHG:
1243 case CS_PORT_UNAVAILABLE:
1245 * If the port is in Target Down state, return all IOs for this
1246 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1249 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1250 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1251 vha->host_no, cp->device->id, cp->device->lun,
1252 cp->serial_number, comp_status,
1253 atomic_read(&fcport->state)));
1256 * We are going to have the fc class block the rport
1257 * while we try to recover so instruct the mid layer
1258 * to requeue until the class decides how to handle this.
1260 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1261 if (atomic_read(&fcport->state) == FCS_ONLINE)
1262 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1266 DEBUG2(printk(KERN_INFO
1267 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1268 vha->host_no, comp_status, scsi_status));
1270 cp->result = DID_RESET << 16;
1275 * hv2.19.12 - DID_ABORT does not retry the request if we
1276 * aborted this request then abort otherwise it must be a
1279 DEBUG2(printk(KERN_INFO
1280 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1281 vha->host_no, comp_status, scsi_status));
1283 cp->result = DID_RESET << 16;
1288 * We are going to have the fc class block the rport
1289 * while we try to recover so instruct the mid layer
1290 * to requeue until the class decides how to handle this.
1292 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1294 if (IS_FWI2_CAPABLE(ha)) {
1295 DEBUG2(printk(KERN_INFO
1296 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1297 "0x%x-0x%x\n", vha->host_no, cp->device->channel,
1298 cp->device->id, cp->device->lun, comp_status,
1302 DEBUG2(printk(KERN_INFO
1303 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1304 "sflags=%x.\n", vha->host_no, cp->device->channel,
1305 cp->device->id, cp->device->lun, comp_status, scsi_status,
1306 le16_to_cpu(sts->status_flags)));
1308 /* Check to see if logout occurred. */
1309 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
1310 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1314 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1315 "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
1316 qla_printk(KERN_INFO, ha,
1317 "Unknown status detected 0x%x-0x%x.\n",
1318 comp_status, scsi_status);
1320 cp->result = DID_ERROR << 16;
1324 /* Place command on done queue. */
1325 if (vha->status_srb == NULL)
1326 qla2x00_sp_compl(ha, sp);
1330 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1331 * @ha: SCSI driver HA context
1332 * @pkt: Entry pointer
1334 * Extended sense data.
1337 qla2x00_status_cont_entry(scsi_qla_host_t *vha, sts_cont_entry_t *pkt)
1339 uint8_t sense_sz = 0;
1340 struct qla_hw_data *ha = vha->hw;
1341 srb_t *sp = vha->status_srb;
1342 struct scsi_cmnd *cp;
1344 if (sp != NULL && sp->request_sense_length != 0) {
1347 DEBUG2(printk("%s(): Cmd already returned back to OS "
1348 "sp=%p.\n", __func__, sp));
1349 qla_printk(KERN_INFO, ha,
1350 "cmd is NULL: already returned to OS (sp=%p)\n",
1353 vha->status_srb = NULL;
1357 if (sp->request_sense_length > sizeof(pkt->data)) {
1358 sense_sz = sizeof(pkt->data);
1360 sense_sz = sp->request_sense_length;
1363 /* Move sense data. */
1364 if (IS_FWI2_CAPABLE(ha))
1365 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
1366 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1367 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1369 sp->request_sense_ptr += sense_sz;
1370 sp->request_sense_length -= sense_sz;
1372 /* Place command on done queue. */
1373 if (sp->request_sense_length == 0) {
1374 vha->status_srb = NULL;
1375 qla2x00_sp_compl(ha, sp);
1381 * qla2x00_error_entry() - Process an error entry.
1382 * @ha: SCSI driver HA context
1383 * @pkt: Entry pointer
1386 qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
1389 struct qla_hw_data *ha = vha->hw;
1390 struct req_que *req = rsp->req;
1391 #if defined(QL_DEBUG_LEVEL_2)
1392 if (pkt->entry_status & RF_INV_E_ORDER)
1393 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1394 else if (pkt->entry_status & RF_INV_E_COUNT)
1395 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1396 else if (pkt->entry_status & RF_INV_E_PARAM)
1397 qla_printk(KERN_ERR, ha,
1398 "%s: Invalid Entry Parameter\n", __func__);
1399 else if (pkt->entry_status & RF_INV_E_TYPE)
1400 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1401 else if (pkt->entry_status & RF_BUSY)
1402 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1404 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1407 /* Validate handle. */
1408 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1409 sp = req->outstanding_cmds[pkt->handle];
1414 /* Free outstanding command slot. */
1415 req->outstanding_cmds[pkt->handle] = NULL;
1417 /* Bad payload or header */
1418 if (pkt->entry_status &
1419 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1420 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1421 sp->cmd->result = DID_ERROR << 16;
1422 } else if (pkt->entry_status & RF_BUSY) {
1423 sp->cmd->result = DID_BUS_BUSY << 16;
1425 sp->cmd->result = DID_ERROR << 16;
1427 qla2x00_sp_compl(ha, sp);
1429 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1430 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
1431 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1433 qla_printk(KERN_WARNING, ha,
1434 "Error entry - invalid handle\n");
1436 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1437 qla2xxx_wake_dpc(vha);
1442 * qla24xx_mbx_completion() - Process mailbox command completions.
1443 * @ha: SCSI driver HA context
1444 * @mb0: Mailbox0 register
1447 qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
1450 uint16_t __iomem *wptr;
1451 struct qla_hw_data *ha = vha->hw;
1452 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1454 /* Load return mailbox registers. */
1455 ha->flags.mbox_int = 1;
1456 ha->mailbox_out[0] = mb0;
1457 wptr = (uint16_t __iomem *)®->mailbox1;
1459 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1460 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1465 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1466 __func__, vha->host_no, ha->mcp->mb[0]));
1468 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1469 __func__, vha->host_no));
1474 * qla24xx_process_response_queue() - Process response queue entries.
1475 * @ha: SCSI driver HA context
1478 qla24xx_process_response_queue(struct rsp_que *rsp)
1480 struct qla_hw_data *ha = rsp->hw;
1481 struct sts_entry_24xx *pkt;
1482 struct scsi_qla_host *vha;
1484 vha = qla2x00_get_rsp_host(rsp);
1486 if (!vha->flags.online)
1489 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1490 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
1493 if (rsp->ring_index == rsp->length) {
1494 rsp->ring_index = 0;
1495 rsp->ring_ptr = rsp->ring;
1500 if (pkt->entry_status != 0) {
1501 DEBUG3(printk(KERN_INFO
1502 "scsi(%ld): Process error entry.\n", vha->host_no));
1504 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
1505 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1510 switch (pkt->entry_type) {
1512 qla2x00_status_entry(vha, rsp, pkt);
1514 case STATUS_CONT_TYPE:
1515 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
1517 case VP_RPT_ID_IOCB_TYPE:
1518 qla24xx_report_id_acquisition(vha,
1519 (struct vp_rpt_id_entry_24xx *)pkt);
1522 /* Type Not Supported. */
1523 DEBUG4(printk(KERN_WARNING
1524 "scsi(%ld): Received unknown response pkt type %x "
1525 "entry status=%x.\n",
1526 vha->host_no, pkt->entry_type, pkt->entry_status));
1529 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1533 /* Adjust ring index */
1534 ha->isp_ops->wrt_rsp_reg(ha, rsp->id, rsp->ring_index);
1538 qla2xxx_check_risc_status(scsi_qla_host_t *vha)
1542 struct qla_hw_data *ha = vha->hw;
1543 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1545 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
1549 WRT_REG_DWORD(®->iobase_addr, 0x7C00);
1550 RD_REG_DWORD(®->iobase_addr);
1551 WRT_REG_DWORD(®->iobase_window, 0x0001);
1552 for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1553 rval == QLA_SUCCESS; cnt--) {
1555 WRT_REG_DWORD(®->iobase_window, 0x0001);
1558 rval = QLA_FUNCTION_TIMEOUT;
1560 if (rval == QLA_SUCCESS)
1563 WRT_REG_DWORD(®->iobase_window, 0x0003);
1564 for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1565 rval == QLA_SUCCESS; cnt--) {
1567 WRT_REG_DWORD(®->iobase_window, 0x0003);
1570 rval = QLA_FUNCTION_TIMEOUT;
1572 if (rval != QLA_SUCCESS)
1576 if (RD_REG_DWORD(®->iobase_c8) & BIT_3)
1577 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1580 WRT_REG_DWORD(®->iobase_window, 0x0000);
1581 RD_REG_DWORD(®->iobase_window);
1585 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1587 * @dev_id: SCSI driver HA context
1589 * Called by system whenever the host adapter generates an interrupt.
1591 * Returns handled flag.
1594 qla24xx_intr_handler(int irq, void *dev_id)
1596 scsi_qla_host_t *vha;
1597 struct qla_hw_data *ha;
1598 struct device_reg_24xx __iomem *reg;
1604 struct rsp_que *rsp;
1606 rsp = (struct rsp_que *) dev_id;
1609 "%s(): NULL response queue pointer\n", __func__);
1614 reg = &ha->iobase->isp24;
1617 spin_lock(&ha->hardware_lock);
1618 vha = qla2x00_get_rsp_host(rsp);
1619 for (iter = 50; iter--; ) {
1620 stat = RD_REG_DWORD(®->host_status);
1621 if (stat & HSRX_RISC_PAUSED) {
1622 if (pci_channel_offline(ha->pdev))
1625 hccr = RD_REG_DWORD(®->hccr);
1627 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1628 "Dumping firmware!\n", hccr);
1630 qla2xxx_check_risc_status(vha);
1632 ha->isp_ops->fw_dump(vha, 1);
1633 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1635 } else if ((stat & HSRX_RISC_INT) == 0)
1638 switch (stat & 0xff) {
1643 qla24xx_mbx_completion(vha, MSW(stat));
1644 status |= MBX_INTERRUPT;
1649 mb[1] = RD_REG_WORD(®->mailbox1);
1650 mb[2] = RD_REG_WORD(®->mailbox2);
1651 mb[3] = RD_REG_WORD(®->mailbox3);
1652 qla2x00_async_event(vha, rsp, mb);
1656 qla24xx_process_response_queue(rsp);
1659 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1661 vha->host_no, stat & 0xff));
1664 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1665 RD_REG_DWORD_RELAXED(®->hccr);
1667 spin_unlock(&ha->hardware_lock);
1669 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1670 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1671 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1672 complete(&ha->mbx_intr_comp);
1679 qla24xx_msix_rsp_q(int irq, void *dev_id)
1681 struct qla_hw_data *ha;
1682 struct rsp_que *rsp;
1683 struct device_reg_24xx __iomem *reg;
1685 rsp = (struct rsp_que *) dev_id;
1688 "%s(): NULL response queue pointer\n", __func__);
1692 reg = &ha->iobase->isp24;
1694 spin_lock_irq(&ha->hardware_lock);
1696 qla24xx_process_response_queue(rsp);
1697 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1699 spin_unlock_irq(&ha->hardware_lock);
1705 qla25xx_msix_rsp_q(int irq, void *dev_id)
1707 struct qla_hw_data *ha;
1708 struct rsp_que *rsp;
1709 struct device_reg_24xx __iomem *reg;
1710 uint16_t msix_disabled_hccr = 0;
1712 rsp = (struct rsp_que *) dev_id;
1715 "%s(): NULL response queue pointer\n", __func__);
1719 reg = &ha->iobase->isp24;
1721 spin_lock_irq(&ha->hardware_lock);
1723 msix_disabled_hccr = rsp->options;
1725 msix_disabled_hccr &= __constant_cpu_to_le32(BIT_22);
1727 msix_disabled_hccr &= __constant_cpu_to_le32(BIT_6);
1729 qla24xx_process_response_queue(rsp);
1731 if (!msix_disabled_hccr)
1732 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1734 spin_unlock_irq(&ha->hardware_lock);
1740 qla24xx_msix_default(int irq, void *dev_id)
1742 scsi_qla_host_t *vha;
1743 struct qla_hw_data *ha;
1744 struct rsp_que *rsp;
1745 struct device_reg_24xx __iomem *reg;
1751 rsp = (struct rsp_que *) dev_id;
1754 "%s(): NULL response queue pointer\n", __func__));
1758 reg = &ha->iobase->isp24;
1761 spin_lock_irq(&ha->hardware_lock);
1762 vha = qla2x00_get_rsp_host(rsp);
1764 stat = RD_REG_DWORD(®->host_status);
1765 if (stat & HSRX_RISC_PAUSED) {
1766 if (pci_channel_offline(ha->pdev))
1769 hccr = RD_REG_DWORD(®->hccr);
1771 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1772 "Dumping firmware!\n", hccr);
1774 qla2xxx_check_risc_status(vha);
1776 ha->isp_ops->fw_dump(vha, 1);
1777 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1779 } else if ((stat & HSRX_RISC_INT) == 0)
1782 switch (stat & 0xff) {
1787 qla24xx_mbx_completion(vha, MSW(stat));
1788 status |= MBX_INTERRUPT;
1793 mb[1] = RD_REG_WORD(®->mailbox1);
1794 mb[2] = RD_REG_WORD(®->mailbox2);
1795 mb[3] = RD_REG_WORD(®->mailbox3);
1796 qla2x00_async_event(vha, rsp, mb);
1800 qla24xx_process_response_queue(rsp);
1803 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1805 vha->host_no, stat & 0xff));
1808 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1810 spin_unlock_irq(&ha->hardware_lock);
1812 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1813 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1814 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1815 complete(&ha->mbx_intr_comp);
1821 /* Interrupt handling helpers. */
1823 struct qla_init_msix_entry {
1827 irq_handler_t handler;
1830 static struct qla_init_msix_entry base_queue = {
1833 .name = "qla2xxx (default)",
1834 .handler = qla24xx_msix_default,
1837 static struct qla_init_msix_entry base_rsp_queue = {
1840 .name = "qla2xxx (rsp_q)",
1841 .handler = qla24xx_msix_rsp_q,
1844 static struct qla_init_msix_entry multi_rsp_queue = {
1847 .name = "qla2xxx (multi_q)",
1848 .handler = qla25xx_msix_rsp_q,
1852 qla24xx_disable_msix(struct qla_hw_data *ha)
1855 struct qla_msix_entry *qentry;
1857 for (i = 0; i < ha->msix_count; i++) {
1858 qentry = &ha->msix_entries[i];
1859 if (qentry->have_irq)
1860 free_irq(qentry->vector, qentry->rsp);
1862 pci_disable_msix(ha->pdev);
1863 kfree(ha->msix_entries);
1864 ha->msix_entries = NULL;
1865 ha->flags.msix_enabled = 0;
1869 qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
1871 #define MIN_MSIX_COUNT 2
1873 struct msix_entry *entries;
1874 struct qla_msix_entry *qentry;
1875 struct qla_init_msix_entry *msix_queue;
1877 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
1882 for (i = 0; i < ha->msix_count; i++)
1883 entries[i].entry = i;
1885 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1887 if (ret < MIN_MSIX_COUNT)
1890 qla_printk(KERN_WARNING, ha,
1891 "MSI-X: Failed to enable support -- %d/%d\n"
1892 " Retry with %d vectors\n", ha->msix_count, ret, ret);
1893 ha->msix_count = ret;
1894 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1897 qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
1898 " support, giving up -- %d/%d\n",
1899 ha->msix_count, ret);
1902 ha->max_queues = ha->msix_count - 1;
1904 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
1905 ha->msix_count, GFP_KERNEL);
1906 if (!ha->msix_entries) {
1910 ha->flags.msix_enabled = 1;
1912 for (i = 0; i < ha->msix_count; i++) {
1913 qentry = &ha->msix_entries[i];
1914 qentry->vector = entries[i].vector;
1915 qentry->entry = entries[i].entry;
1916 qentry->have_irq = 0;
1920 /* Enable MSI-X for AENs for queue 0 */
1921 qentry = &ha->msix_entries[0];
1922 ret = request_irq(qentry->vector, base_queue.handler, 0,
1923 base_queue.name, rsp);
1925 qla_printk(KERN_WARNING, ha,
1926 "MSI-X: Unable to register handler -- %x/%d.\n",
1927 qentry->vector, ret);
1928 qla24xx_disable_msix(ha);
1931 qentry->have_irq = 1;
1934 /* Enable MSI-X vector for response queue update for queue 0 */
1935 if (ha->max_queues > 1 && ha->mqiobase) {
1937 msix_queue = &multi_rsp_queue;
1938 qla_printk(KERN_INFO, ha,
1939 "MQ enabled, Number of Queue Resources: %d \n",
1943 msix_queue = &base_rsp_queue;
1946 qentry = &ha->msix_entries[1];
1947 ret = request_irq(qentry->vector, msix_queue->handler, 0,
1948 msix_queue->name, rsp);
1950 qla_printk(KERN_WARNING, ha,
1951 "MSI-X: Unable to register handler -- %x/%d.\n",
1952 qentry->vector, ret);
1953 qla24xx_disable_msix(ha);
1957 qentry->have_irq = 1;
1966 qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
1969 device_reg_t __iomem *reg = ha->iobase;
1971 /* If possible, enable MSI-X. */
1972 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
1973 !IS_QLA8432(ha) && !IS_QLA8001(ha))
1976 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
1977 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
1978 DEBUG2(qla_printk(KERN_WARNING, ha,
1979 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1980 ha->pdev->revision, ha->fw_attributes));
1985 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1986 (ha->pdev->subsystem_device == 0x7040 ||
1987 ha->pdev->subsystem_device == 0x7041 ||
1988 ha->pdev->subsystem_device == 0x1705)) {
1989 DEBUG2(qla_printk(KERN_WARNING, ha,
1990 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1991 ha->pdev->subsystem_vendor,
1992 ha->pdev->subsystem_device));
1997 ret = qla24xx_enable_msix(ha, rsp);
1999 DEBUG2(qla_printk(KERN_INFO, ha,
2000 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
2001 ha->fw_attributes));
2002 goto clear_risc_ints;
2004 qla_printk(KERN_WARNING, ha,
2005 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
2008 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
2012 ret = pci_enable_msi(ha->pdev);
2014 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
2015 ha->flags.msi_enabled = 1;
2019 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
2020 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
2022 qla_printk(KERN_WARNING, ha,
2023 "Failed to reserve interrupt %d already in use.\n",
2027 ha->flags.inta_enabled = 1;
2031 * FIXME: Noted that 8014s were being dropped during NK testing.
2032 * Timing deltas during MSI-X/INTa transitions?
2036 spin_lock_irq(&ha->hardware_lock);
2037 if (IS_FWI2_CAPABLE(ha)) {
2038 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT);
2039 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT);
2041 WRT_REG_WORD(®->isp.semaphore, 0);
2042 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT);
2043 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT);
2045 spin_unlock_irq(&ha->hardware_lock);
2052 qla2x00_free_irqs(scsi_qla_host_t *vha)
2054 struct qla_hw_data *ha = vha->hw;
2055 struct rsp_que *rsp = ha->rsp_q_map[0];
2057 if (ha->flags.msix_enabled)
2058 qla24xx_disable_msix(ha);
2059 else if (ha->flags.inta_enabled) {
2060 free_irq(ha->pdev->irq, rsp);
2061 pci_disable_msi(ha->pdev);
2065 static struct scsi_qla_host *
2066 qla2x00_get_rsp_host(struct rsp_que *rsp)
2069 struct qla_hw_data *ha = rsp->hw;
2070 struct scsi_qla_host *vha = NULL;
2071 struct sts_entry_24xx *pkt;
2072 struct req_que *req;
2075 pkt = (struct sts_entry_24xx *) rsp->ring_ptr;
2077 if (pkt && pkt->handle < MAX_OUTSTANDING_COMMANDS) {
2078 sp = req->outstanding_cmds[pkt->handle];
2080 vha = sp->fcport->vha;
2084 /* handle it in base queue */
2085 vha = pci_get_drvdata(ha->pdev);
2090 int qla25xx_request_irq(struct rsp_que *rsp)
2092 struct qla_hw_data *ha = rsp->hw;
2093 struct qla_init_msix_entry *intr = &multi_rsp_queue;
2094 struct qla_msix_entry *msix = rsp->msix;
2097 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2099 qla_printk(KERN_WARNING, ha,
2100 "MSI-X: Unable to register handler -- %x/%d.\n",
2110 qla25xx_wrt_rsp_reg(struct qla_hw_data *ha, uint16_t id, uint16_t index)
2112 device_reg_t __iomem *reg = (void *) ha->mqiobase + QLA_QUE_PAGE * id;
2113 WRT_REG_DWORD(®->isp25mq.rsp_q_out, index);
2117 qla24xx_wrt_rsp_reg(struct qla_hw_data *ha, uint16_t id, uint16_t index)
2119 device_reg_t __iomem *reg = (void *) ha->iobase;
2120 WRT_REG_DWORD(®->isp24.rsp_q_out, index);