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[5] = { "1", "2", "?", "4", "8" };
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. */
292 case MBA_SCSI_COMPLETION:
293 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
296 case MBA_CMPLT_1_16BIT:
299 mb[0] = MBA_SCSI_COMPLETION;
301 case MBA_CMPLT_2_16BIT:
305 mb[0] = MBA_SCSI_COMPLETION;
307 case MBA_CMPLT_3_16BIT:
312 mb[0] = MBA_SCSI_COMPLETION;
314 case MBA_CMPLT_4_16BIT:
318 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
320 mb[0] = MBA_SCSI_COMPLETION;
322 case MBA_CMPLT_5_16BIT:
326 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
327 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
329 mb[0] = MBA_SCSI_COMPLETION;
331 case MBA_CMPLT_2_32BIT:
332 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
333 handles[1] = le32_to_cpu(
334 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
335 RD_MAILBOX_REG(ha, reg, 6));
337 mb[0] = MBA_SCSI_COMPLETION;
344 case MBA_SCSI_COMPLETION: /* Fast Post */
345 if (!vha->flags.online)
348 for (cnt = 0; cnt < handle_cnt; cnt++)
349 qla2x00_process_completed_request(vha, rsp->req,
353 case MBA_RESET: /* Reset */
354 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
357 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
360 case MBA_SYSTEM_ERR: /* System Error */
361 qla_printk(KERN_INFO, ha,
362 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
363 mb[1], mb[2], mb[3]);
365 qla2x00_post_hwe_work(vha, mb[0], mb[1], mb[2], mb[3]);
366 ha->isp_ops->fw_dump(vha, 1);
368 if (IS_FWI2_CAPABLE(ha)) {
369 if (mb[1] == 0 && mb[2] == 0) {
370 qla_printk(KERN_ERR, ha,
371 "Unrecoverable Hardware Error: adapter "
372 "marked OFFLINE!\n");
373 vha->flags.online = 0;
375 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
376 } else if (mb[1] == 0) {
377 qla_printk(KERN_INFO, ha,
378 "Unrecoverable Hardware Error: adapter marked "
380 vha->flags.online = 0;
382 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
385 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
386 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
388 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
390 qla2x00_post_hwe_work(vha, mb[0], mb[1], mb[2], mb[3]);
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 qla2x00_post_hwe_work(vha, mb[0], mb[1], mb[2], mb[3]);
400 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
403 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
404 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
408 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
409 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
411 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
413 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
414 atomic_set(&vha->loop_state, LOOP_DOWN);
415 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
416 qla2x00_mark_all_devices_lost(vha, 1);
420 atomic_set(&vha->vp_state, VP_FAILED);
421 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
424 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
425 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
427 vha->flags.management_server_logged_in = 0;
428 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
431 case MBA_LOOP_UP: /* Loop Up Event */
432 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
433 link_speed = link_speeds[0];
434 ha->link_data_rate = PORT_SPEED_1GB;
436 link_speed = link_speeds[LS_UNKNOWN];
438 link_speed = link_speeds[mb[1]];
439 ha->link_data_rate = mb[1];
442 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
443 vha->host_no, link_speed));
444 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
447 vha->flags.management_server_logged_in = 0;
448 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
451 case MBA_LOOP_DOWN: /* Loop Down Event */
452 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
453 "(%x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3]));
454 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
455 mb[1], mb[2], mb[3]);
457 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
458 atomic_set(&vha->loop_state, LOOP_DOWN);
459 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
460 vha->device_flags |= DFLG_NO_CABLE;
461 qla2x00_mark_all_devices_lost(vha, 1);
465 atomic_set(&vha->vp_state, VP_FAILED);
466 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
469 vha->flags.management_server_logged_in = 0;
470 ha->link_data_rate = PORT_SPEED_UNKNOWN;
471 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
474 case MBA_LIP_RESET: /* LIP reset occurred */
475 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
476 vha->host_no, mb[1]));
477 qla_printk(KERN_INFO, ha,
478 "LIP reset occurred (%x).\n", mb[1]);
480 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
481 atomic_set(&vha->loop_state, LOOP_DOWN);
482 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
483 qla2x00_mark_all_devices_lost(vha, 1);
487 atomic_set(&vha->vp_state, VP_FAILED);
488 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
491 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
493 ha->operating_mode = LOOP;
494 vha->flags.management_server_logged_in = 0;
495 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
498 case MBA_POINT_TO_POINT: /* Point-to-Point */
502 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
506 * Until there's a transition from loop down to loop up, treat
507 * this as loop down only.
509 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
510 atomic_set(&vha->loop_state, LOOP_DOWN);
511 if (!atomic_read(&vha->loop_down_timer))
512 atomic_set(&vha->loop_down_timer,
514 qla2x00_mark_all_devices_lost(vha, 1);
518 atomic_set(&vha->vp_state, VP_FAILED);
519 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
522 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
523 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
525 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
526 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
528 ha->flags.gpsc_supported = 1;
529 vha->flags.management_server_logged_in = 0;
532 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
536 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
539 qla_printk(KERN_INFO, ha,
540 "Configuration change detected: value=%x.\n", mb[1]);
542 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
543 atomic_set(&vha->loop_state, LOOP_DOWN);
544 if (!atomic_read(&vha->loop_down_timer))
545 atomic_set(&vha->loop_down_timer,
547 qla2x00_mark_all_devices_lost(vha, 1);
551 atomic_set(&vha->vp_state, VP_FAILED);
552 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
555 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
556 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
559 case MBA_PORT_UPDATE: /* Port database update */
560 /* Only handle SCNs for our Vport index. */
561 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
565 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
566 * event etc. earlier indicating loop is down) then process
567 * it. Otherwise ignore it and Wait for RSCN to come in.
569 atomic_set(&vha->loop_down_timer, 0);
570 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
571 atomic_read(&vha->loop_state) != LOOP_DEAD) {
572 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
573 "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
578 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
580 DEBUG(printk(KERN_INFO
581 "scsi(%ld): Port database changed %04x %04x %04x.\n",
582 vha->host_no, mb[1], mb[2], mb[3]));
585 * Mark all devices as missing so we will login again.
587 atomic_set(&vha->loop_state, LOOP_UP);
589 qla2x00_mark_all_devices_lost(vha, 1);
591 vha->flags.rscn_queue_overflow = 1;
593 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
594 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
597 case MBA_RSCN_UPDATE: /* State Change Registration */
598 /* Check if the Vport has issued a SCR */
599 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
601 /* Only handle SCNs for our Vport index. */
602 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
604 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
606 DEBUG(printk(KERN_INFO
607 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
608 vha->host_no, mb[1], mb[2], mb[3]));
610 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
611 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
613 if (rscn_entry == host_pid) {
614 DEBUG(printk(KERN_INFO
615 "scsi(%ld): Ignoring RSCN update to local host "
617 vha->host_no, host_pid));
621 /* Ignore reserved bits from RSCN-payload. */
622 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
623 rscn_queue_index = vha->rscn_in_ptr + 1;
624 if (rscn_queue_index == MAX_RSCN_COUNT)
625 rscn_queue_index = 0;
626 if (rscn_queue_index != vha->rscn_out_ptr) {
627 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
628 vha->rscn_in_ptr = rscn_queue_index;
630 vha->flags.rscn_queue_overflow = 1;
633 atomic_set(&vha->loop_state, LOOP_UPDATE);
634 atomic_set(&vha->loop_down_timer, 0);
635 vha->flags.management_server_logged_in = 0;
637 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
638 set_bit(RSCN_UPDATE, &vha->dpc_flags);
639 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
642 /* case MBA_RIO_RESPONSE: */
643 case MBA_ZIO_RESPONSE:
644 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
646 DEBUG(printk(KERN_INFO
647 "scsi(%ld): [R|Z]IO update completion.\n",
650 if (IS_FWI2_CAPABLE(ha))
651 qla24xx_process_response_queue(rsp);
653 qla2x00_process_response_queue(rsp);
656 case MBA_DISCARD_RND_FRAME:
657 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
658 "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
661 case MBA_TRACE_NOTIFICATION:
662 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
663 vha->host_no, mb[1], mb[2]));
666 case MBA_ISP84XX_ALERT:
667 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
668 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
670 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
672 case A84_PANIC_RECOVERY:
673 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
674 "%04x %04x\n", mb[2], mb[3]);
676 case A84_OP_LOGIN_COMPLETE:
677 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
678 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
679 "firmware version %x\n", ha->cs84xx->op_fw_version));
681 case A84_DIAG_LOGIN_COMPLETE:
682 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
683 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
684 "diagnostic firmware version %x\n",
685 ha->cs84xx->diag_fw_version));
687 case A84_GOLD_LOGIN_COMPLETE:
688 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
689 ha->cs84xx->fw_update = 1;
690 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
691 "firmware version %x\n",
692 ha->cs84xx->gold_fw_version));
695 qla_printk(KERN_ERR, ha,
696 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
697 mb[1], mb[2], mb[3]);
699 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
703 if (!vha->vp_idx && ha->num_vhosts)
704 qla2x00_alert_all_vps(rsp, mb);
708 qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
710 fc_port_t *fcport = data;
711 struct scsi_qla_host *vha = fcport->vha;
712 struct qla_hw_data *ha = vha->hw;
713 struct req_que *req = NULL;
715 req = ha->req_q_map[vha->req_ques[0]];
718 if (req->max_q_depth <= sdev->queue_depth)
721 if (sdev->ordered_tags)
722 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
723 sdev->queue_depth + 1);
725 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
726 sdev->queue_depth + 1);
728 fcport->last_ramp_up = jiffies;
730 DEBUG2(qla_printk(KERN_INFO, ha,
731 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
732 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
737 qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
739 fc_port_t *fcport = data;
741 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
744 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
745 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
746 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
751 qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, struct req_que *req,
755 struct scsi_device *sdev;
757 sdev = sp->cmd->device;
758 if (sdev->queue_depth >= req->max_q_depth)
762 if (time_before(jiffies,
763 fcport->last_ramp_up + ql2xqfullrampup * HZ))
765 if (time_before(jiffies,
766 fcport->last_queue_full + ql2xqfullrampup * HZ))
769 starget_for_each_device(sdev->sdev_target, fcport,
770 qla2x00_adjust_sdev_qdepth_up);
774 * qla2x00_process_completed_request() - Process a Fast Post response.
775 * @ha: SCSI driver HA context
779 qla2x00_process_completed_request(struct scsi_qla_host *vha,
780 struct req_que *req, uint32_t index)
783 struct qla_hw_data *ha = vha->hw;
785 /* Validate handle. */
786 if (index >= MAX_OUTSTANDING_COMMANDS) {
787 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
788 vha->host_no, index));
789 qla_printk(KERN_WARNING, ha,
790 "Invalid SCSI completion handle %d.\n", index);
792 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
796 sp = req->outstanding_cmds[index];
798 /* Free outstanding command slot. */
799 req->outstanding_cmds[index] = NULL;
801 CMD_COMPL_STATUS(sp->cmd) = 0L;
802 CMD_SCSI_STATUS(sp->cmd) = 0L;
804 /* Save ISP completion status */
805 sp->cmd->result = DID_OK << 16;
807 qla2x00_ramp_up_queue_depth(vha, req, sp);
808 qla2x00_sp_compl(ha, sp);
810 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
812 qla_printk(KERN_WARNING, ha,
813 "Invalid ISP SCSI completion handle\n");
815 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
820 * qla2x00_process_response_queue() - Process response queue entries.
821 * @ha: SCSI driver HA context
824 qla2x00_process_response_queue(struct rsp_que *rsp)
826 struct scsi_qla_host *vha;
827 struct qla_hw_data *ha = rsp->hw;
828 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
833 vha = qla2x00_get_rsp_host(rsp);
835 if (!vha->flags.online)
838 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
839 pkt = (sts_entry_t *)rsp->ring_ptr;
842 if (rsp->ring_index == rsp->length) {
844 rsp->ring_ptr = rsp->ring;
849 if (pkt->entry_status != 0) {
850 DEBUG3(printk(KERN_INFO
851 "scsi(%ld): Process error entry.\n", vha->host_no));
853 qla2x00_error_entry(vha, rsp, pkt);
854 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
859 switch (pkt->entry_type) {
861 qla2x00_status_entry(vha, rsp, pkt);
864 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
865 for (cnt = 0; cnt < handle_cnt; cnt++) {
866 qla2x00_process_completed_request(vha, rsp->req,
867 ((sts21_entry_t *)pkt)->handle[cnt]);
871 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
872 for (cnt = 0; cnt < handle_cnt; cnt++) {
873 qla2x00_process_completed_request(vha, rsp->req,
874 ((sts22_entry_t *)pkt)->handle[cnt]);
877 case STATUS_CONT_TYPE:
878 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
881 /* Type Not Supported. */
882 DEBUG4(printk(KERN_WARNING
883 "scsi(%ld): Received unknown response pkt type %x "
884 "entry status=%x.\n",
885 vha->host_no, pkt->entry_type, pkt->entry_status));
888 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
892 /* Adjust ring index */
893 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
897 qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
899 struct scsi_cmnd *cp = sp->cmd;
901 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
902 sense_len = SCSI_SENSE_BUFFERSIZE;
904 CMD_ACTUAL_SNSLEN(cp) = sense_len;
905 sp->request_sense_length = sense_len;
906 sp->request_sense_ptr = cp->sense_buffer;
907 if (sp->request_sense_length > 32)
910 memcpy(cp->sense_buffer, sense_data, sense_len);
912 sp->request_sense_ptr += sense_len;
913 sp->request_sense_length -= sense_len;
914 if (sp->request_sense_length != 0)
915 sp->fcport->vha->status_srb = sp;
917 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
918 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
919 cp->device->channel, cp->device->id, cp->device->lun, cp,
922 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
923 CMD_ACTUAL_SNSLEN(cp)));
927 * qla2x00_status_entry() - Process a Status IOCB entry.
928 * @ha: SCSI driver HA context
929 * @pkt: Entry pointer
932 qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
936 struct scsi_cmnd *cp;
938 struct sts_entry_24xx *sts24;
939 uint16_t comp_status;
940 uint16_t scsi_status;
941 uint8_t lscsi_status;
943 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
944 uint8_t *rsp_info, *sense_data;
945 struct qla_hw_data *ha = vha->hw;
946 struct req_que *req = rsp->req;
948 sts = (sts_entry_t *) pkt;
949 sts24 = (struct sts_entry_24xx *) pkt;
950 if (IS_FWI2_CAPABLE(ha)) {
951 comp_status = le16_to_cpu(sts24->comp_status);
952 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
954 comp_status = le16_to_cpu(sts->comp_status);
955 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
958 /* Fast path completion. */
959 if (comp_status == CS_COMPLETE && scsi_status == 0) {
960 qla2x00_process_completed_request(vha, req, sts->handle);
965 /* Validate handle. */
966 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
967 sp = req->outstanding_cmds[sts->handle];
968 req->outstanding_cmds[sts->handle] = NULL;
973 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
975 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
977 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
978 qla2xxx_wake_dpc(vha);
983 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
984 "pkt->handle=%d sp=%p.\n", vha->host_no, sts->handle, sp));
985 qla_printk(KERN_WARNING, ha,
986 "Command is NULL: already returned to OS (sp=%p)\n", sp);
991 lscsi_status = scsi_status & STATUS_MASK;
992 CMD_ENTRY_STATUS(cp) = sts->entry_status;
993 CMD_COMPL_STATUS(cp) = comp_status;
994 CMD_SCSI_STATUS(cp) = scsi_status;
998 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
999 if (IS_FWI2_CAPABLE(ha)) {
1000 sense_len = le32_to_cpu(sts24->sense_len);
1001 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1002 resid_len = le32_to_cpu(sts24->rsp_residual_count);
1003 fw_resid_len = le32_to_cpu(sts24->residual_len);
1004 rsp_info = sts24->data;
1005 sense_data = sts24->data;
1006 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
1008 sense_len = le16_to_cpu(sts->req_sense_length);
1009 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
1010 resid_len = le32_to_cpu(sts->residual_length);
1011 rsp_info = sts->rsp_info;
1012 sense_data = sts->req_sense_data;
1015 /* Check for any FCP transport errors. */
1016 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
1017 /* Sense data lies beyond any FCP RESPONSE data. */
1018 if (IS_FWI2_CAPABLE(ha))
1019 sense_data += rsp_info_len;
1020 if (rsp_info_len > 3 && rsp_info[3]) {
1021 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1022 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
1023 "retrying command\n", vha->host_no,
1024 cp->device->channel, cp->device->id,
1025 cp->device->lun, rsp_info_len, rsp_info[0],
1026 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1027 rsp_info[5], rsp_info[6], rsp_info[7]));
1029 cp->result = DID_BUS_BUSY << 16;
1030 qla2x00_sp_compl(ha, sp);
1035 /* Check for overrun. */
1036 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1037 scsi_status & SS_RESIDUAL_OVER)
1038 comp_status = CS_DATA_OVERRUN;
1041 * Based on Host and scsi status generate status code for Linux
1043 switch (comp_status) {
1046 if (scsi_status == 0) {
1047 cp->result = DID_OK << 16;
1050 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
1052 scsi_set_resid(cp, resid);
1053 CMD_RESID_LEN(cp) = resid;
1055 if (!lscsi_status &&
1056 ((unsigned)(scsi_bufflen(cp) - resid) <
1058 qla_printk(KERN_INFO, ha,
1059 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1060 "detected (%x of %x bytes)...returning "
1061 "error status.\n", vha->host_no,
1062 cp->device->channel, cp->device->id,
1063 cp->device->lun, resid,
1066 cp->result = DID_ERROR << 16;
1070 cp->result = DID_OK << 16 | lscsi_status;
1072 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1073 DEBUG2(printk(KERN_INFO
1074 "scsi(%ld): QUEUE FULL status detected "
1075 "0x%x-0x%x.\n", vha->host_no, comp_status,
1078 /* Adjust queue depth for all luns on the port. */
1079 fcport->last_queue_full = jiffies;
1080 starget_for_each_device(cp->device->sdev_target,
1081 fcport, qla2x00_adjust_sdev_qdepth_down);
1084 if (lscsi_status != SS_CHECK_CONDITION)
1087 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1088 if (!(scsi_status & SS_SENSE_LEN_VALID))
1091 qla2x00_handle_sense(sp, sense_data, sense_len);
1094 case CS_DATA_UNDERRUN:
1096 /* Use F/W calculated residual length. */
1097 if (IS_FWI2_CAPABLE(ha)) {
1098 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1100 } else if (resid != fw_resid_len) {
1101 scsi_status &= ~SS_RESIDUAL_UNDER;
1104 resid = fw_resid_len;
1107 if (scsi_status & SS_RESIDUAL_UNDER) {
1108 scsi_set_resid(cp, resid);
1109 CMD_RESID_LEN(cp) = resid;
1111 DEBUG2(printk(KERN_INFO
1112 "scsi(%ld:%d:%d) UNDERRUN status detected "
1113 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1114 "os_underflow=0x%x\n", vha->host_no,
1115 cp->device->id, cp->device->lun, comp_status,
1116 scsi_status, resid_len, resid, cp->cmnd[0],
1122 * Check to see if SCSI Status is non zero. If so report SCSI
1125 if (lscsi_status != 0) {
1126 cp->result = DID_OK << 16 | lscsi_status;
1128 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1129 DEBUG2(printk(KERN_INFO
1130 "scsi(%ld): QUEUE FULL status detected "
1131 "0x%x-0x%x.\n", vha->host_no, comp_status,
1135 * Adjust queue depth for all luns on the
1138 fcport->last_queue_full = jiffies;
1139 starget_for_each_device(
1140 cp->device->sdev_target, fcport,
1141 qla2x00_adjust_sdev_qdepth_down);
1144 if (lscsi_status != SS_CHECK_CONDITION)
1147 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1148 if (!(scsi_status & SS_SENSE_LEN_VALID))
1151 qla2x00_handle_sense(sp, sense_data, sense_len);
1154 * If RISC reports underrun and target does not report
1155 * it then we must have a lost frame, so tell upper
1156 * layer to retry it by reporting a bus busy.
1158 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1159 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1160 "frame(s) detected (%x of %x bytes)..."
1161 "retrying command.\n",
1162 vha->host_no, cp->device->channel,
1163 cp->device->id, cp->device->lun, resid,
1166 cp->result = DID_BUS_BUSY << 16;
1170 /* Handle mid-layer underflow */
1171 if ((unsigned)(scsi_bufflen(cp) - resid) <
1173 qla_printk(KERN_INFO, ha,
1174 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1175 "detected (%x of %x bytes)...returning "
1176 "error status.\n", vha->host_no,
1177 cp->device->channel, cp->device->id,
1178 cp->device->lun, resid,
1181 cp->result = DID_ERROR << 16;
1185 /* Everybody online, looking good... */
1186 cp->result = DID_OK << 16;
1190 case CS_DATA_OVERRUN:
1191 DEBUG2(printk(KERN_INFO
1192 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1193 vha->host_no, cp->device->id, cp->device->lun, comp_status,
1195 DEBUG2(printk(KERN_INFO
1196 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1197 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1198 cp->cmnd[4], cp->cmnd[5]));
1199 DEBUG2(printk(KERN_INFO
1200 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1202 cp->serial_number, scsi_bufflen(cp), resid_len));
1204 cp->result = DID_ERROR << 16;
1207 case CS_PORT_LOGGED_OUT:
1208 case CS_PORT_CONFIG_CHG:
1211 case CS_PORT_UNAVAILABLE:
1213 * If the port is in Target Down state, return all IOs for this
1214 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1217 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1218 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1219 vha->host_no, cp->device->id, cp->device->lun,
1220 cp->serial_number, comp_status,
1221 atomic_read(&fcport->state)));
1224 * We are going to have the fc class block the rport
1225 * while we try to recover so instruct the mid layer
1226 * to requeue until the class decides how to handle this.
1228 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1229 if (atomic_read(&fcport->state) == FCS_ONLINE)
1230 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1234 DEBUG2(printk(KERN_INFO
1235 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1236 vha->host_no, comp_status, scsi_status));
1238 cp->result = DID_RESET << 16;
1243 * hv2.19.12 - DID_ABORT does not retry the request if we
1244 * aborted this request then abort otherwise it must be a
1247 DEBUG2(printk(KERN_INFO
1248 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1249 vha->host_no, comp_status, scsi_status));
1251 cp->result = DID_RESET << 16;
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;
1262 if (IS_FWI2_CAPABLE(ha)) {
1263 DEBUG2(printk(KERN_INFO
1264 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1265 "0x%x-0x%x\n", vha->host_no, cp->device->channel,
1266 cp->device->id, cp->device->lun, comp_status,
1270 DEBUG2(printk(KERN_INFO
1271 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1272 "sflags=%x.\n", vha->host_no, cp->device->channel,
1273 cp->device->id, cp->device->lun, comp_status, scsi_status,
1274 le16_to_cpu(sts->status_flags)));
1276 /* Check to see if logout occurred. */
1277 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
1278 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1282 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1283 "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
1284 qla_printk(KERN_INFO, ha,
1285 "Unknown status detected 0x%x-0x%x.\n",
1286 comp_status, scsi_status);
1288 cp->result = DID_ERROR << 16;
1292 /* Place command on done queue. */
1293 if (vha->status_srb == NULL)
1294 qla2x00_sp_compl(ha, sp);
1298 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1299 * @ha: SCSI driver HA context
1300 * @pkt: Entry pointer
1302 * Extended sense data.
1305 qla2x00_status_cont_entry(scsi_qla_host_t *vha, sts_cont_entry_t *pkt)
1307 uint8_t sense_sz = 0;
1308 struct qla_hw_data *ha = vha->hw;
1309 srb_t *sp = vha->status_srb;
1310 struct scsi_cmnd *cp;
1312 if (sp != NULL && sp->request_sense_length != 0) {
1315 DEBUG2(printk("%s(): Cmd already returned back to OS "
1316 "sp=%p.\n", __func__, sp));
1317 qla_printk(KERN_INFO, ha,
1318 "cmd is NULL: already returned to OS (sp=%p)\n",
1321 vha->status_srb = NULL;
1325 if (sp->request_sense_length > sizeof(pkt->data)) {
1326 sense_sz = sizeof(pkt->data);
1328 sense_sz = sp->request_sense_length;
1331 /* Move sense data. */
1332 if (IS_FWI2_CAPABLE(ha))
1333 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
1334 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1335 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1337 sp->request_sense_ptr += sense_sz;
1338 sp->request_sense_length -= sense_sz;
1340 /* Place command on done queue. */
1341 if (sp->request_sense_length == 0) {
1342 vha->status_srb = NULL;
1343 qla2x00_sp_compl(ha, sp);
1349 * qla2x00_error_entry() - Process an error entry.
1350 * @ha: SCSI driver HA context
1351 * @pkt: Entry pointer
1354 qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
1357 struct qla_hw_data *ha = vha->hw;
1358 struct req_que *req = rsp->req;
1359 #if defined(QL_DEBUG_LEVEL_2)
1360 if (pkt->entry_status & RF_INV_E_ORDER)
1361 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1362 else if (pkt->entry_status & RF_INV_E_COUNT)
1363 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1364 else if (pkt->entry_status & RF_INV_E_PARAM)
1365 qla_printk(KERN_ERR, ha,
1366 "%s: Invalid Entry Parameter\n", __func__);
1367 else if (pkt->entry_status & RF_INV_E_TYPE)
1368 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1369 else if (pkt->entry_status & RF_BUSY)
1370 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1372 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1375 /* Validate handle. */
1376 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1377 sp = req->outstanding_cmds[pkt->handle];
1382 /* Free outstanding command slot. */
1383 req->outstanding_cmds[pkt->handle] = NULL;
1385 /* Bad payload or header */
1386 if (pkt->entry_status &
1387 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1388 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1389 sp->cmd->result = DID_ERROR << 16;
1390 } else if (pkt->entry_status & RF_BUSY) {
1391 sp->cmd->result = DID_BUS_BUSY << 16;
1393 sp->cmd->result = DID_ERROR << 16;
1395 qla2x00_sp_compl(ha, sp);
1397 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1398 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
1399 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1401 qla_printk(KERN_WARNING, ha,
1402 "Error entry - invalid handle\n");
1404 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1405 qla2xxx_wake_dpc(vha);
1410 * qla24xx_mbx_completion() - Process mailbox command completions.
1411 * @ha: SCSI driver HA context
1412 * @mb0: Mailbox0 register
1415 qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
1418 uint16_t __iomem *wptr;
1419 struct qla_hw_data *ha = vha->hw;
1420 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1422 /* Load return mailbox registers. */
1423 ha->flags.mbox_int = 1;
1424 ha->mailbox_out[0] = mb0;
1425 wptr = (uint16_t __iomem *)®->mailbox1;
1427 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1428 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1433 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1434 __func__, vha->host_no, ha->mcp->mb[0]));
1436 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1437 __func__, vha->host_no));
1442 * qla24xx_process_response_queue() - Process response queue entries.
1443 * @ha: SCSI driver HA context
1446 qla24xx_process_response_queue(struct rsp_que *rsp)
1448 struct qla_hw_data *ha = rsp->hw;
1449 struct sts_entry_24xx *pkt;
1450 struct scsi_qla_host *vha;
1452 vha = qla2x00_get_rsp_host(rsp);
1454 if (!vha->flags.online)
1457 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1458 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
1461 if (rsp->ring_index == rsp->length) {
1462 rsp->ring_index = 0;
1463 rsp->ring_ptr = rsp->ring;
1468 if (pkt->entry_status != 0) {
1469 DEBUG3(printk(KERN_INFO
1470 "scsi(%ld): Process error entry.\n", vha->host_no));
1472 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
1473 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1478 switch (pkt->entry_type) {
1480 qla2x00_status_entry(vha, rsp, pkt);
1482 case STATUS_CONT_TYPE:
1483 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
1485 case VP_RPT_ID_IOCB_TYPE:
1486 qla24xx_report_id_acquisition(vha,
1487 (struct vp_rpt_id_entry_24xx *)pkt);
1490 /* Type Not Supported. */
1491 DEBUG4(printk(KERN_WARNING
1492 "scsi(%ld): Received unknown response pkt type %x "
1493 "entry status=%x.\n",
1494 vha->host_no, pkt->entry_type, pkt->entry_status));
1497 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1501 /* Adjust ring index */
1502 ha->isp_ops->wrt_rsp_reg(ha, rsp->id, rsp->ring_index);
1506 qla2xxx_check_risc_status(scsi_qla_host_t *vha)
1510 struct qla_hw_data *ha = vha->hw;
1511 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1513 if (!IS_QLA25XX(ha))
1517 WRT_REG_DWORD(®->iobase_addr, 0x7C00);
1518 RD_REG_DWORD(®->iobase_addr);
1519 WRT_REG_DWORD(®->iobase_window, 0x0001);
1520 for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1521 rval == QLA_SUCCESS; cnt--) {
1523 WRT_REG_DWORD(®->iobase_window, 0x0001);
1526 rval = QLA_FUNCTION_TIMEOUT;
1528 if (rval == QLA_SUCCESS)
1531 WRT_REG_DWORD(®->iobase_window, 0x0003);
1532 for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1533 rval == QLA_SUCCESS; cnt--) {
1535 WRT_REG_DWORD(®->iobase_window, 0x0003);
1538 rval = QLA_FUNCTION_TIMEOUT;
1540 if (rval != QLA_SUCCESS)
1544 if (RD_REG_DWORD(®->iobase_c8) & BIT_3)
1545 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1548 WRT_REG_DWORD(®->iobase_window, 0x0000);
1549 RD_REG_DWORD(®->iobase_window);
1553 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1555 * @dev_id: SCSI driver HA context
1557 * Called by system whenever the host adapter generates an interrupt.
1559 * Returns handled flag.
1562 qla24xx_intr_handler(int irq, void *dev_id)
1564 scsi_qla_host_t *vha;
1565 struct qla_hw_data *ha;
1566 struct device_reg_24xx __iomem *reg;
1572 struct rsp_que *rsp;
1574 rsp = (struct rsp_que *) dev_id;
1577 "%s(): NULL response queue pointer\n", __func__);
1582 reg = &ha->iobase->isp24;
1585 spin_lock(&ha->hardware_lock);
1586 vha = qla2x00_get_rsp_host(rsp);
1587 for (iter = 50; iter--; ) {
1588 stat = RD_REG_DWORD(®->host_status);
1589 if (stat & HSRX_RISC_PAUSED) {
1590 if (pci_channel_offline(ha->pdev))
1593 if (ha->hw_event_pause_errors == 0)
1594 qla2x00_post_hwe_work(vha, HW_EVENT_PARITY_ERR,
1595 0, MSW(stat), LSW(stat));
1596 else if (ha->hw_event_pause_errors < 0xffffffff)
1597 ha->hw_event_pause_errors++;
1599 hccr = RD_REG_DWORD(®->hccr);
1601 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1602 "Dumping firmware!\n", hccr);
1604 qla2xxx_check_risc_status(vha);
1606 ha->isp_ops->fw_dump(vha, 1);
1607 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1609 } else if ((stat & HSRX_RISC_INT) == 0)
1612 switch (stat & 0xff) {
1617 qla24xx_mbx_completion(vha, MSW(stat));
1618 status |= MBX_INTERRUPT;
1623 mb[1] = RD_REG_WORD(®->mailbox1);
1624 mb[2] = RD_REG_WORD(®->mailbox2);
1625 mb[3] = RD_REG_WORD(®->mailbox3);
1626 qla2x00_async_event(vha, rsp, mb);
1630 qla24xx_process_response_queue(rsp);
1633 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1635 vha->host_no, stat & 0xff));
1638 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1639 RD_REG_DWORD_RELAXED(®->hccr);
1641 spin_unlock(&ha->hardware_lock);
1643 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1644 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1645 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1646 complete(&ha->mbx_intr_comp);
1653 qla24xx_msix_rsp_q(int irq, void *dev_id)
1655 struct qla_hw_data *ha;
1656 struct rsp_que *rsp;
1657 struct device_reg_24xx __iomem *reg;
1659 rsp = (struct rsp_que *) dev_id;
1662 "%s(): NULL response queue pointer\n", __func__);
1666 reg = &ha->iobase->isp24;
1668 spin_lock_irq(&ha->hardware_lock);
1670 qla24xx_process_response_queue(rsp);
1671 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1673 spin_unlock_irq(&ha->hardware_lock);
1679 qla25xx_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;
1684 uint16_t msix_disabled_hccr = 0;
1686 rsp = (struct rsp_que *) dev_id;
1689 "%s(): NULL response queue pointer\n", __func__);
1693 reg = &ha->iobase->isp24;
1695 spin_lock_irq(&ha->hardware_lock);
1697 msix_disabled_hccr = rsp->options;
1699 msix_disabled_hccr &= __constant_cpu_to_le32(BIT_22);
1701 msix_disabled_hccr &= __constant_cpu_to_le32(BIT_6);
1703 qla24xx_process_response_queue(rsp);
1705 if (!msix_disabled_hccr)
1706 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1708 spin_unlock_irq(&ha->hardware_lock);
1714 qla24xx_msix_default(int irq, void *dev_id)
1716 scsi_qla_host_t *vha;
1717 struct qla_hw_data *ha;
1718 struct rsp_que *rsp;
1719 struct device_reg_24xx __iomem *reg;
1725 rsp = (struct rsp_que *) dev_id;
1728 "%s(): NULL response queue pointer\n", __func__));
1732 reg = &ha->iobase->isp24;
1735 spin_lock_irq(&ha->hardware_lock);
1736 vha = qla2x00_get_rsp_host(rsp);
1738 stat = RD_REG_DWORD(®->host_status);
1739 if (stat & HSRX_RISC_PAUSED) {
1740 if (pci_channel_offline(ha->pdev))
1743 if (ha->hw_event_pause_errors == 0)
1744 qla2x00_post_hwe_work(vha, HW_EVENT_PARITY_ERR,
1745 0, MSW(stat), LSW(stat));
1746 else if (ha->hw_event_pause_errors < 0xffffffff)
1747 ha->hw_event_pause_errors++;
1749 hccr = RD_REG_DWORD(®->hccr);
1751 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1752 "Dumping firmware!\n", hccr);
1754 qla2xxx_check_risc_status(vha);
1756 ha->isp_ops->fw_dump(vha, 1);
1757 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1759 } else if ((stat & HSRX_RISC_INT) == 0)
1762 switch (stat & 0xff) {
1767 qla24xx_mbx_completion(vha, MSW(stat));
1768 status |= MBX_INTERRUPT;
1773 mb[1] = RD_REG_WORD(®->mailbox1);
1774 mb[2] = RD_REG_WORD(®->mailbox2);
1775 mb[3] = RD_REG_WORD(®->mailbox3);
1776 qla2x00_async_event(vha, rsp, mb);
1780 qla24xx_process_response_queue(rsp);
1783 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1785 vha->host_no, stat & 0xff));
1788 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1790 spin_unlock_irq(&ha->hardware_lock);
1792 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1793 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1794 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1795 complete(&ha->mbx_intr_comp);
1801 /* Interrupt handling helpers. */
1803 struct qla_init_msix_entry {
1807 irq_handler_t handler;
1810 static struct qla_init_msix_entry base_queue = {
1813 .name = "qla2xxx (default)",
1814 .handler = qla24xx_msix_default,
1817 static struct qla_init_msix_entry base_rsp_queue = {
1820 .name = "qla2xxx (rsp_q)",
1821 .handler = qla24xx_msix_rsp_q,
1824 static struct qla_init_msix_entry multi_rsp_queue = {
1827 .name = "qla2xxx (multi_q)",
1828 .handler = qla25xx_msix_rsp_q,
1832 qla24xx_disable_msix(struct qla_hw_data *ha)
1835 struct qla_msix_entry *qentry;
1837 for (i = 0; i < ha->msix_count; i++) {
1838 qentry = &ha->msix_entries[i];
1839 if (qentry->have_irq)
1840 free_irq(qentry->vector, qentry->rsp);
1842 pci_disable_msix(ha->pdev);
1843 kfree(ha->msix_entries);
1844 ha->msix_entries = NULL;
1845 ha->flags.msix_enabled = 0;
1849 qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
1852 struct msix_entry *entries;
1853 struct qla_msix_entry *qentry;
1854 struct qla_init_msix_entry *msix_queue;
1856 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
1861 for (i = 0; i < ha->msix_count; i++)
1862 entries[i].entry = i;
1864 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1866 qla_printk(KERN_WARNING, ha,
1867 "MSI-X: Failed to enable support -- %d/%d\n"
1868 " Retry with %d vectors\n", ha->msix_count, ret, ret);
1869 ha->msix_count = ret;
1870 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1872 qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
1873 " support, giving up -- %d/%d\n",
1874 ha->msix_count, ret);
1877 ha->max_queues = ha->msix_count - 1;
1879 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
1880 ha->msix_count, GFP_KERNEL);
1881 if (!ha->msix_entries) {
1885 ha->flags.msix_enabled = 1;
1887 for (i = 0; i < ha->msix_count; i++) {
1888 qentry = &ha->msix_entries[i];
1889 qentry->vector = entries[i].vector;
1890 qentry->entry = entries[i].entry;
1891 qentry->have_irq = 0;
1895 /* Enable MSI-X for AENs for queue 0 */
1896 qentry = &ha->msix_entries[0];
1897 ret = request_irq(qentry->vector, base_queue.handler, 0,
1898 base_queue.name, rsp);
1900 qla_printk(KERN_WARNING, ha,
1901 "MSI-X: Unable to register handler -- %x/%d.\n",
1902 qentry->vector, ret);
1903 qla24xx_disable_msix(ha);
1906 qentry->have_irq = 1;
1909 /* Enable MSI-X vector for response queue update for queue 0 */
1910 if (ha->max_queues > 1 && ha->mqiobase) {
1912 msix_queue = &multi_rsp_queue;
1913 qla_printk(KERN_INFO, ha,
1914 "MQ enabled, Number of Queue Resources: %d \n",
1918 msix_queue = &base_rsp_queue;
1921 qentry = &ha->msix_entries[1];
1922 ret = request_irq(qentry->vector, msix_queue->handler, 0,
1923 msix_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);
1932 qentry->have_irq = 1;
1941 qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
1944 device_reg_t __iomem *reg = ha->iobase;
1946 /* If possible, enable MSI-X. */
1947 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(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))
1985 ret = pci_enable_msi(ha->pdev);
1987 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1988 ha->flags.msi_enabled = 1;
1992 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
1993 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
1995 qla_printk(KERN_WARNING, ha,
1996 "Failed to reserve interrupt %d already in use.\n",
2000 ha->flags.inta_enabled = 1;
2003 spin_lock_irq(&ha->hardware_lock);
2004 if (IS_FWI2_CAPABLE(ha)) {
2005 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT);
2006 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT);
2008 WRT_REG_WORD(®->isp.semaphore, 0);
2009 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT);
2010 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT);
2012 spin_unlock_irq(&ha->hardware_lock);
2019 qla2x00_free_irqs(scsi_qla_host_t *vha)
2021 struct qla_hw_data *ha = vha->hw;
2022 struct rsp_que *rsp = ha->rsp_q_map[0];
2024 if (ha->flags.msix_enabled)
2025 qla24xx_disable_msix(ha);
2026 else if (ha->flags.inta_enabled) {
2027 free_irq(ha->pdev->irq, rsp);
2028 pci_disable_msi(ha->pdev);
2032 static struct scsi_qla_host *
2033 qla2x00_get_rsp_host(struct rsp_que *rsp)
2036 struct qla_hw_data *ha = rsp->hw;
2037 struct scsi_qla_host *vha = NULL;
2038 struct sts_entry_24xx *pkt;
2039 struct req_que *req;
2042 pkt = (struct sts_entry_24xx *) rsp->ring_ptr;
2044 if (pkt && pkt->handle < MAX_OUTSTANDING_COMMANDS) {
2045 sp = req->outstanding_cmds[pkt->handle];
2051 /* handle it in base queue */
2052 vha = pci_get_drvdata(ha->pdev);
2057 int qla25xx_request_irq(struct rsp_que *rsp)
2059 struct qla_hw_data *ha = rsp->hw;
2060 struct qla_init_msix_entry *intr = &multi_rsp_queue;
2061 struct qla_msix_entry *msix = rsp->msix;
2064 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2066 qla_printk(KERN_WARNING, ha,
2067 "MSI-X: Unable to register handler -- %x/%d.\n",
2077 qla25xx_wrt_rsp_reg(struct qla_hw_data *ha, uint16_t id, uint16_t index)
2079 device_reg_t __iomem *reg = (void *) ha->mqiobase + QLA_QUE_PAGE * id;
2080 WRT_REG_DWORD(®->isp25mq.rsp_q_out, index);
2084 qla24xx_wrt_rsp_reg(struct qla_hw_data *ha, uint16_t id, uint16_t index)
2086 device_reg_t __iomem *reg = (void *) ha->iobase;
2087 WRT_REG_DWORD(®->isp24.rsp_q_out, index);