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 *, uint32_t);
14 static void qla2x00_status_entry(scsi_qla_host_t *, void *);
15 static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *);
16 static void qla2x00_error_entry(scsi_qla_host_t *, sts_entry_t *);
17 static struct scsi_qla_host *qla2x00_get_rsp_host(struct rsp_que *);
20 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
22 * @dev_id: SCSI driver HA context
24 * Called by system whenever the host adapter generates an interrupt.
26 * Returns handled flag.
29 qla2100_intr_handler(int irq, void *dev_id)
32 struct qla_hw_data *ha;
33 struct device_reg_2xxx __iomem *reg;
40 rsp = (struct rsp_que *) dev_id;
43 "%s(): NULL response queue pointer\n", __func__);
48 reg = &ha->iobase->isp;
51 spin_lock(&ha->hardware_lock);
52 vha = qla2x00_get_rsp_host(rsp);
53 for (iter = 50; iter--; ) {
54 hccr = RD_REG_WORD(®->hccr);
55 if (hccr & HCCR_RISC_PAUSE) {
56 if (pci_channel_offline(ha->pdev))
60 * Issue a "HARD" reset in order for the RISC interrupt
61 * bit to be cleared. Schedule a big hammmer to get
62 * out of the RISC PAUSED state.
64 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
65 RD_REG_WORD(®->hccr);
67 ha->isp_ops->fw_dump(vha, 1);
68 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
70 } else if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0)
73 if (RD_REG_WORD(®->semaphore) & BIT_0) {
74 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
75 RD_REG_WORD(®->hccr);
77 /* Get mailbox data. */
78 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
79 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
80 qla2x00_mbx_completion(vha, mb[0]);
81 status |= MBX_INTERRUPT;
82 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
83 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
84 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
85 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
86 qla2x00_async_event(vha, mb);
89 DEBUG2(printk("scsi(%ld): Unrecognized "
90 "interrupt type (%d).\n",
91 vha->host_no, mb[0]));
93 /* Release mailbox registers. */
94 WRT_REG_WORD(®->semaphore, 0);
95 RD_REG_WORD(®->semaphore);
97 qla2x00_process_response_queue(vha);
99 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
100 RD_REG_WORD(®->hccr);
103 spin_unlock(&ha->hardware_lock);
105 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
106 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
107 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
108 complete(&ha->mbx_intr_comp);
111 return (IRQ_HANDLED);
115 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
117 * @dev_id: SCSI driver HA context
119 * Called by system whenever the host adapter generates an interrupt.
121 * Returns handled flag.
124 qla2300_intr_handler(int irq, void *dev_id)
126 scsi_qla_host_t *vha;
127 struct device_reg_2xxx __iomem *reg;
134 struct qla_hw_data *ha;
136 rsp = (struct rsp_que *) dev_id;
139 "%s(): NULL response queue pointer\n", __func__);
144 reg = &ha->iobase->isp;
147 spin_lock(&ha->hardware_lock);
148 vha = qla2x00_get_rsp_host(rsp);
149 for (iter = 50; iter--; ) {
150 stat = RD_REG_DWORD(®->u.isp2300.host_status);
151 if (stat & HSR_RISC_PAUSED) {
152 if (pci_channel_offline(ha->pdev))
155 hccr = RD_REG_WORD(®->hccr);
156 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
157 qla_printk(KERN_INFO, ha, "Parity error -- "
158 "HCCR=%x, Dumping firmware!\n", hccr);
160 qla_printk(KERN_INFO, ha, "RISC paused -- "
161 "HCCR=%x, Dumping firmware!\n", hccr);
164 * Issue a "HARD" reset in order for the RISC
165 * interrupt bit to be cleared. Schedule a big
166 * hammmer to get out of the RISC PAUSED state.
168 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
169 RD_REG_WORD(®->hccr);
171 ha->isp_ops->fw_dump(vha, 1);
172 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
174 } else if ((stat & HSR_RISC_INT) == 0)
177 switch (stat & 0xff) {
182 qla2x00_mbx_completion(vha, MSW(stat));
183 status |= MBX_INTERRUPT;
185 /* Release mailbox registers. */
186 WRT_REG_WORD(®->semaphore, 0);
190 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
191 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
192 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
193 qla2x00_async_event(vha, mb);
196 qla2x00_process_response_queue(vha);
199 mb[0] = MBA_CMPLT_1_16BIT;
201 qla2x00_async_event(vha, mb);
204 mb[0] = MBA_SCSI_COMPLETION;
206 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
207 qla2x00_async_event(vha, mb);
210 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
212 vha->host_no, stat & 0xff));
215 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
216 RD_REG_WORD_RELAXED(®->hccr);
218 spin_unlock(&ha->hardware_lock);
220 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
221 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
222 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
223 complete(&ha->mbx_intr_comp);
226 return (IRQ_HANDLED);
230 * qla2x00_mbx_completion() - Process mailbox command completions.
231 * @ha: SCSI driver HA context
232 * @mb0: Mailbox0 register
235 qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
238 uint16_t __iomem *wptr;
239 struct qla_hw_data *ha = vha->hw;
240 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
242 /* Load return mailbox registers. */
243 ha->flags.mbox_int = 1;
244 ha->mailbox_out[0] = mb0;
245 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
247 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
248 if (IS_QLA2200(ha) && cnt == 8)
249 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
250 if (cnt == 4 || cnt == 5)
251 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
253 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
259 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
260 __func__, vha->host_no, ha->mcp->mb[0]));
262 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
263 __func__, vha->host_no));
268 * qla2x00_async_event() - Process aynchronous events.
269 * @ha: SCSI driver HA context
270 * @mb: Mailbox registers (0 - 3)
273 qla2x00_async_event(scsi_qla_host_t *vha, uint16_t *mb)
276 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
281 struct qla_hw_data *ha = vha->hw;
282 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
283 uint32_t rscn_entry, host_pid;
284 uint8_t rscn_queue_index;
287 /* Setup to process RIO completion. */
290 case MBA_SCSI_COMPLETION:
291 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
294 case MBA_CMPLT_1_16BIT:
297 mb[0] = MBA_SCSI_COMPLETION;
299 case MBA_CMPLT_2_16BIT:
303 mb[0] = MBA_SCSI_COMPLETION;
305 case MBA_CMPLT_3_16BIT:
310 mb[0] = MBA_SCSI_COMPLETION;
312 case MBA_CMPLT_4_16BIT:
316 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
318 mb[0] = MBA_SCSI_COMPLETION;
320 case MBA_CMPLT_5_16BIT:
324 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
325 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
327 mb[0] = MBA_SCSI_COMPLETION;
329 case MBA_CMPLT_2_32BIT:
330 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
331 handles[1] = le32_to_cpu(
332 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
333 RD_MAILBOX_REG(ha, reg, 6));
335 mb[0] = MBA_SCSI_COMPLETION;
342 case MBA_SCSI_COMPLETION: /* Fast Post */
343 if (!vha->flags.online)
346 for (cnt = 0; cnt < handle_cnt; cnt++)
347 qla2x00_process_completed_request(vha, handles[cnt]);
350 case MBA_RESET: /* Reset */
351 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
354 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
357 case MBA_SYSTEM_ERR: /* System Error */
358 qla_printk(KERN_INFO, ha,
359 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
360 mb[1], mb[2], mb[3]);
362 qla2x00_post_hwe_work(vha, mb[0], mb[1], mb[2], mb[3]);
363 ha->isp_ops->fw_dump(vha, 1);
365 if (IS_FWI2_CAPABLE(ha)) {
366 if (mb[1] == 0 && mb[2] == 0) {
367 qla_printk(KERN_ERR, ha,
368 "Unrecoverable Hardware Error: adapter "
369 "marked OFFLINE!\n");
370 vha->flags.online = 0;
372 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
373 } else if (mb[1] == 0) {
374 qla_printk(KERN_INFO, ha,
375 "Unrecoverable Hardware Error: adapter marked "
377 vha->flags.online = 0;
379 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
382 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
383 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
385 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
387 qla2x00_post_hwe_work(vha, mb[0], mb[1], mb[2], mb[3]);
388 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
391 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
392 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
394 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
396 qla2x00_post_hwe_work(vha, mb[0], mb[1], mb[2], mb[3]);
397 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
400 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
401 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
405 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
406 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
408 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
410 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
411 atomic_set(&vha->loop_state, LOOP_DOWN);
412 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
413 qla2x00_mark_all_devices_lost(vha, 1);
417 atomic_set(&vha->vp_state, VP_FAILED);
418 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
421 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
422 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
424 vha->flags.management_server_logged_in = 0;
425 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
428 case MBA_LOOP_UP: /* Loop Up Event */
429 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
430 link_speed = link_speeds[0];
431 ha->link_data_rate = PORT_SPEED_1GB;
433 link_speed = link_speeds[LS_UNKNOWN];
435 link_speed = link_speeds[mb[1]];
436 ha->link_data_rate = mb[1];
439 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
440 vha->host_no, link_speed));
441 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
444 vha->flags.management_server_logged_in = 0;
445 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
448 case MBA_LOOP_DOWN: /* Loop Down Event */
449 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
450 "(%x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3]));
451 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
452 mb[1], mb[2], mb[3]);
454 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
455 atomic_set(&vha->loop_state, LOOP_DOWN);
456 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
457 vha->device_flags |= DFLG_NO_CABLE;
458 qla2x00_mark_all_devices_lost(vha, 1);
462 atomic_set(&vha->vp_state, VP_FAILED);
463 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
466 vha->flags.management_server_logged_in = 0;
467 ha->link_data_rate = PORT_SPEED_UNKNOWN;
468 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
471 case MBA_LIP_RESET: /* LIP reset occurred */
472 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
473 vha->host_no, mb[1]));
474 qla_printk(KERN_INFO, ha,
475 "LIP reset occurred (%x).\n", mb[1]);
477 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
478 atomic_set(&vha->loop_state, LOOP_DOWN);
479 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
480 qla2x00_mark_all_devices_lost(vha, 1);
484 atomic_set(&vha->vp_state, VP_FAILED);
485 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
488 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
490 ha->operating_mode = LOOP;
491 vha->flags.management_server_logged_in = 0;
492 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
495 case MBA_POINT_TO_POINT: /* Point-to-Point */
499 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
503 * Until there's a transition from loop down to loop up, treat
504 * this as loop down only.
506 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
507 atomic_set(&vha->loop_state, LOOP_DOWN);
508 if (!atomic_read(&vha->loop_down_timer))
509 atomic_set(&vha->loop_down_timer,
511 qla2x00_mark_all_devices_lost(vha, 1);
515 atomic_set(&vha->vp_state, VP_FAILED);
516 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
519 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
520 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
522 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
523 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
525 ha->flags.gpsc_supported = 1;
526 vha->flags.management_server_logged_in = 0;
529 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
533 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
536 qla_printk(KERN_INFO, ha,
537 "Configuration change detected: value=%x.\n", mb[1]);
539 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
540 atomic_set(&vha->loop_state, LOOP_DOWN);
541 if (!atomic_read(&vha->loop_down_timer))
542 atomic_set(&vha->loop_down_timer,
544 qla2x00_mark_all_devices_lost(vha, 1);
548 atomic_set(&vha->vp_state, VP_FAILED);
549 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
552 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
553 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
556 case MBA_PORT_UPDATE: /* Port database update */
558 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
559 * event etc. earlier indicating loop is down) then process
560 * it. Otherwise ignore it and Wait for RSCN to come in.
562 atomic_set(&vha->loop_down_timer, 0);
563 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
564 atomic_read(&vha->loop_state) != LOOP_DEAD) {
565 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
566 "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
571 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
573 DEBUG(printk(KERN_INFO
574 "scsi(%ld): Port database changed %04x %04x %04x.\n",
575 vha->host_no, mb[1], mb[2], mb[3]));
578 * Mark all devices as missing so we will login again.
580 atomic_set(&vha->loop_state, LOOP_UP);
582 qla2x00_mark_all_devices_lost(vha, 1);
584 vha->flags.rscn_queue_overflow = 1;
586 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
587 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
590 case MBA_RSCN_UPDATE: /* State Change Registration */
591 /* Check if the Vport has issued a SCR */
592 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
594 /* Only handle SCNs for our Vport index. */
595 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
597 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
599 DEBUG(printk(KERN_INFO
600 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
601 vha->host_no, mb[1], mb[2], mb[3]));
603 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
604 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
606 if (rscn_entry == host_pid) {
607 DEBUG(printk(KERN_INFO
608 "scsi(%ld): Ignoring RSCN update to local host "
610 vha->host_no, host_pid));
614 /* Ignore reserved bits from RSCN-payload. */
615 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
616 rscn_queue_index = vha->rscn_in_ptr + 1;
617 if (rscn_queue_index == MAX_RSCN_COUNT)
618 rscn_queue_index = 0;
619 if (rscn_queue_index != vha->rscn_out_ptr) {
620 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
621 vha->rscn_in_ptr = rscn_queue_index;
623 vha->flags.rscn_queue_overflow = 1;
626 atomic_set(&vha->loop_state, LOOP_UPDATE);
627 atomic_set(&vha->loop_down_timer, 0);
628 vha->flags.management_server_logged_in = 0;
630 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
631 set_bit(RSCN_UPDATE, &vha->dpc_flags);
632 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
635 /* case MBA_RIO_RESPONSE: */
636 case MBA_ZIO_RESPONSE:
637 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
639 DEBUG(printk(KERN_INFO
640 "scsi(%ld): [R|Z]IO update completion.\n",
643 if (IS_FWI2_CAPABLE(ha))
644 qla24xx_process_response_queue(vha);
646 qla2x00_process_response_queue(vha);
649 case MBA_DISCARD_RND_FRAME:
650 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
651 "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
654 case MBA_TRACE_NOTIFICATION:
655 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
656 vha->host_no, mb[1], mb[2]));
659 case MBA_ISP84XX_ALERT:
660 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
661 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
663 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
665 case A84_PANIC_RECOVERY:
666 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
667 "%04x %04x\n", mb[2], mb[3]);
669 case A84_OP_LOGIN_COMPLETE:
670 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
671 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
672 "firmware version %x\n", ha->cs84xx->op_fw_version));
674 case A84_DIAG_LOGIN_COMPLETE:
675 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
676 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
677 "diagnostic firmware version %x\n",
678 ha->cs84xx->diag_fw_version));
680 case A84_GOLD_LOGIN_COMPLETE:
681 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
682 ha->cs84xx->fw_update = 1;
683 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
684 "firmware version %x\n",
685 ha->cs84xx->gold_fw_version));
688 qla_printk(KERN_ERR, ha,
689 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
690 mb[1], mb[2], mb[3]);
692 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
696 if (!vha->vp_idx && ha->num_vhosts)
697 qla2x00_alert_all_vps(ha, mb);
701 qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
703 fc_port_t *fcport = data;
704 struct qla_hw_data *ha = fcport->vha->hw;
705 if (ha->req->max_q_depth <= sdev->queue_depth)
708 if (sdev->ordered_tags)
709 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
710 sdev->queue_depth + 1);
712 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
713 sdev->queue_depth + 1);
715 fcport->last_ramp_up = jiffies;
717 DEBUG2(qla_printk(KERN_INFO, ha,
718 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
719 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
724 qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
726 fc_port_t *fcport = data;
728 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
731 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
732 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
733 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
738 qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, srb_t *sp)
741 struct scsi_device *sdev;
742 struct qla_hw_data *ha = vha->hw;
744 sdev = sp->cmd->device;
745 if (sdev->queue_depth >= ha->req->max_q_depth)
749 if (time_before(jiffies,
750 fcport->last_ramp_up + ql2xqfullrampup * HZ))
752 if (time_before(jiffies,
753 fcport->last_queue_full + ql2xqfullrampup * HZ))
756 starget_for_each_device(sdev->sdev_target, fcport,
757 qla2x00_adjust_sdev_qdepth_up);
761 * qla2x00_process_completed_request() - Process a Fast Post response.
762 * @ha: SCSI driver HA context
766 qla2x00_process_completed_request(struct scsi_qla_host *vha, uint32_t index)
769 struct qla_hw_data *ha = vha->hw;
770 struct req_que *req = ha->req;
772 /* Validate handle. */
773 if (index >= MAX_OUTSTANDING_COMMANDS) {
774 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
775 vha->host_no, index));
776 qla_printk(KERN_WARNING, ha,
777 "Invalid SCSI completion handle %d.\n", index);
779 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
783 sp = req->outstanding_cmds[index];
785 /* Free outstanding command slot. */
786 req->outstanding_cmds[index] = NULL;
788 CMD_COMPL_STATUS(sp->cmd) = 0L;
789 CMD_SCSI_STATUS(sp->cmd) = 0L;
791 /* Save ISP completion status */
792 sp->cmd->result = DID_OK << 16;
794 qla2x00_ramp_up_queue_depth(vha, sp);
795 qla2x00_sp_compl(vha, sp);
797 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
799 qla_printk(KERN_WARNING, ha,
800 "Invalid ISP SCSI completion handle\n");
802 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
807 * qla2x00_process_response_queue() - Process response queue entries.
808 * @ha: SCSI driver HA context
811 qla2x00_process_response_queue(struct scsi_qla_host *vha)
813 struct qla_hw_data *ha = vha->hw;
814 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
818 struct rsp_que *rsp = ha->rsp;
820 if (!vha->flags.online)
823 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
824 pkt = (sts_entry_t *)rsp->ring_ptr;
827 if (rsp->ring_index == rsp->length) {
829 rsp->ring_ptr = rsp->ring;
834 if (pkt->entry_status != 0) {
835 DEBUG3(printk(KERN_INFO
836 "scsi(%ld): Process error entry.\n", vha->host_no));
838 qla2x00_error_entry(vha, pkt);
839 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
844 switch (pkt->entry_type) {
846 qla2x00_status_entry(vha, pkt);
849 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
850 for (cnt = 0; cnt < handle_cnt; cnt++) {
851 qla2x00_process_completed_request(vha,
852 ((sts21_entry_t *)pkt)->handle[cnt]);
856 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
857 for (cnt = 0; cnt < handle_cnt; cnt++) {
858 qla2x00_process_completed_request(vha,
859 ((sts22_entry_t *)pkt)->handle[cnt]);
862 case STATUS_CONT_TYPE:
863 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
866 /* Type Not Supported. */
867 DEBUG4(printk(KERN_WARNING
868 "scsi(%ld): Received unknown response pkt type %x "
869 "entry status=%x.\n",
870 vha->host_no, pkt->entry_type, pkt->entry_status));
873 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
877 /* Adjust ring index */
878 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
882 qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
884 struct scsi_cmnd *cp = sp->cmd;
886 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
887 sense_len = SCSI_SENSE_BUFFERSIZE;
889 CMD_ACTUAL_SNSLEN(cp) = sense_len;
890 sp->request_sense_length = sense_len;
891 sp->request_sense_ptr = cp->sense_buffer;
892 if (sp->request_sense_length > 32)
895 memcpy(cp->sense_buffer, sense_data, sense_len);
897 sp->request_sense_ptr += sense_len;
898 sp->request_sense_length -= sense_len;
899 if (sp->request_sense_length != 0)
900 sp->fcport->vha->status_srb = sp;
902 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
903 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
904 cp->device->channel, cp->device->id, cp->device->lun, cp,
907 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
908 CMD_ACTUAL_SNSLEN(cp)));
912 * qla2x00_status_entry() - Process a Status IOCB entry.
913 * @ha: SCSI driver HA context
914 * @pkt: Entry pointer
917 qla2x00_status_entry(scsi_qla_host_t *vha, void *pkt)
921 struct scsi_cmnd *cp;
923 struct sts_entry_24xx *sts24;
924 uint16_t comp_status;
925 uint16_t scsi_status;
926 uint8_t lscsi_status;
928 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
929 uint8_t *rsp_info, *sense_data;
930 struct qla_hw_data *ha = vha->hw;
931 struct req_que *req = ha->req;
933 sts = (sts_entry_t *) pkt;
934 sts24 = (struct sts_entry_24xx *) pkt;
935 if (IS_FWI2_CAPABLE(ha)) {
936 comp_status = le16_to_cpu(sts24->comp_status);
937 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
939 comp_status = le16_to_cpu(sts->comp_status);
940 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
943 /* Fast path completion. */
944 if (comp_status == CS_COMPLETE && scsi_status == 0) {
945 qla2x00_process_completed_request(vha, sts->handle);
950 /* Validate handle. */
951 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
952 sp = req->outstanding_cmds[sts->handle];
953 req->outstanding_cmds[sts->handle] = NULL;
958 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
960 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
962 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
963 qla2xxx_wake_dpc(vha);
968 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
969 "pkt->handle=%d sp=%p.\n", vha->host_no, sts->handle, sp));
970 qla_printk(KERN_WARNING, ha,
971 "Command is NULL: already returned to OS (sp=%p)\n", sp);
976 lscsi_status = scsi_status & STATUS_MASK;
977 CMD_ENTRY_STATUS(cp) = sts->entry_status;
978 CMD_COMPL_STATUS(cp) = comp_status;
979 CMD_SCSI_STATUS(cp) = scsi_status;
983 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
984 if (IS_FWI2_CAPABLE(ha)) {
985 sense_len = le32_to_cpu(sts24->sense_len);
986 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
987 resid_len = le32_to_cpu(sts24->rsp_residual_count);
988 fw_resid_len = le32_to_cpu(sts24->residual_len);
989 rsp_info = sts24->data;
990 sense_data = sts24->data;
991 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
993 sense_len = le16_to_cpu(sts->req_sense_length);
994 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
995 resid_len = le32_to_cpu(sts->residual_length);
996 rsp_info = sts->rsp_info;
997 sense_data = sts->req_sense_data;
1000 /* Check for any FCP transport errors. */
1001 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
1002 /* Sense data lies beyond any FCP RESPONSE data. */
1003 if (IS_FWI2_CAPABLE(ha))
1004 sense_data += rsp_info_len;
1005 if (rsp_info_len > 3 && rsp_info[3]) {
1006 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1007 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
1008 "retrying command\n", vha->host_no,
1009 cp->device->channel, cp->device->id,
1010 cp->device->lun, rsp_info_len, rsp_info[0],
1011 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1012 rsp_info[5], rsp_info[6], rsp_info[7]));
1014 cp->result = DID_BUS_BUSY << 16;
1015 qla2x00_sp_compl(vha, sp);
1020 /* Check for overrun. */
1021 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1022 scsi_status & SS_RESIDUAL_OVER)
1023 comp_status = CS_DATA_OVERRUN;
1026 * Based on Host and scsi status generate status code for Linux
1028 switch (comp_status) {
1031 if (scsi_status == 0) {
1032 cp->result = DID_OK << 16;
1035 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
1037 scsi_set_resid(cp, resid);
1038 CMD_RESID_LEN(cp) = resid;
1040 if (!lscsi_status &&
1041 ((unsigned)(scsi_bufflen(cp) - resid) <
1043 qla_printk(KERN_INFO, ha,
1044 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1045 "detected (%x of %x bytes)...returning "
1046 "error status.\n", vha->host_no,
1047 cp->device->channel, cp->device->id,
1048 cp->device->lun, resid,
1051 cp->result = DID_ERROR << 16;
1055 cp->result = DID_OK << 16 | lscsi_status;
1057 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1058 DEBUG2(printk(KERN_INFO
1059 "scsi(%ld): QUEUE FULL status detected "
1060 "0x%x-0x%x.\n", vha->host_no, comp_status,
1063 /* Adjust queue depth for all luns on the port. */
1064 fcport->last_queue_full = jiffies;
1065 starget_for_each_device(cp->device->sdev_target,
1066 fcport, qla2x00_adjust_sdev_qdepth_down);
1069 if (lscsi_status != SS_CHECK_CONDITION)
1072 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1073 if (!(scsi_status & SS_SENSE_LEN_VALID))
1076 qla2x00_handle_sense(sp, sense_data, sense_len);
1079 case CS_DATA_UNDERRUN:
1081 /* Use F/W calculated residual length. */
1082 if (IS_FWI2_CAPABLE(ha)) {
1083 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1085 } else if (resid != fw_resid_len) {
1086 scsi_status &= ~SS_RESIDUAL_UNDER;
1089 resid = fw_resid_len;
1092 if (scsi_status & SS_RESIDUAL_UNDER) {
1093 scsi_set_resid(cp, resid);
1094 CMD_RESID_LEN(cp) = resid;
1096 DEBUG2(printk(KERN_INFO
1097 "scsi(%ld:%d:%d) UNDERRUN status detected "
1098 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1099 "os_underflow=0x%x\n", vha->host_no,
1100 cp->device->id, cp->device->lun, comp_status,
1101 scsi_status, resid_len, resid, cp->cmnd[0],
1107 * Check to see if SCSI Status is non zero. If so report SCSI
1110 if (lscsi_status != 0) {
1111 cp->result = DID_OK << 16 | lscsi_status;
1113 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1114 DEBUG2(printk(KERN_INFO
1115 "scsi(%ld): QUEUE FULL status detected "
1116 "0x%x-0x%x.\n", vha->host_no, comp_status,
1120 * Adjust queue depth for all luns on the
1123 fcport->last_queue_full = jiffies;
1124 starget_for_each_device(
1125 cp->device->sdev_target, fcport,
1126 qla2x00_adjust_sdev_qdepth_down);
1129 if (lscsi_status != SS_CHECK_CONDITION)
1132 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1133 if (!(scsi_status & SS_SENSE_LEN_VALID))
1136 qla2x00_handle_sense(sp, sense_data, sense_len);
1139 * If RISC reports underrun and target does not report
1140 * it then we must have a lost frame, so tell upper
1141 * layer to retry it by reporting a bus busy.
1143 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1144 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1145 "frame(s) detected (%x of %x bytes)..."
1146 "retrying command.\n",
1147 vha->host_no, cp->device->channel,
1148 cp->device->id, cp->device->lun, resid,
1151 cp->result = DID_BUS_BUSY << 16;
1155 /* Handle mid-layer underflow */
1156 if ((unsigned)(scsi_bufflen(cp) - resid) <
1158 qla_printk(KERN_INFO, ha,
1159 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1160 "detected (%x of %x bytes)...returning "
1161 "error status.\n", vha->host_no,
1162 cp->device->channel, cp->device->id,
1163 cp->device->lun, resid,
1166 cp->result = DID_ERROR << 16;
1170 /* Everybody online, looking good... */
1171 cp->result = DID_OK << 16;
1175 case CS_DATA_OVERRUN:
1176 DEBUG2(printk(KERN_INFO
1177 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1178 vha->host_no, cp->device->id, cp->device->lun, comp_status,
1180 DEBUG2(printk(KERN_INFO
1181 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1182 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1183 cp->cmnd[4], cp->cmnd[5]));
1184 DEBUG2(printk(KERN_INFO
1185 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1187 cp->serial_number, scsi_bufflen(cp), resid_len));
1189 cp->result = DID_ERROR << 16;
1192 case CS_PORT_LOGGED_OUT:
1193 case CS_PORT_CONFIG_CHG:
1196 case CS_PORT_UNAVAILABLE:
1198 * If the port is in Target Down state, return all IOs for this
1199 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1202 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1203 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1204 vha->host_no, cp->device->id, cp->device->lun,
1205 cp->serial_number, comp_status,
1206 atomic_read(&fcport->state)));
1209 * We are going to have the fc class block the rport
1210 * while we try to recover so instruct the mid layer
1211 * to requeue until the class decides how to handle this.
1213 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1214 if (atomic_read(&fcport->state) == FCS_ONLINE)
1215 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1219 DEBUG2(printk(KERN_INFO
1220 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1221 vha->host_no, comp_status, scsi_status));
1223 cp->result = DID_RESET << 16;
1228 * hv2.19.12 - DID_ABORT does not retry the request if we
1229 * aborted this request then abort otherwise it must be a
1232 DEBUG2(printk(KERN_INFO
1233 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1234 vha->host_no, comp_status, scsi_status));
1236 cp->result = DID_RESET << 16;
1241 * We are going to have the fc class block the rport
1242 * while we try to recover so instruct the mid layer
1243 * to requeue until the class decides how to handle this.
1245 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1247 if (IS_FWI2_CAPABLE(ha)) {
1248 DEBUG2(printk(KERN_INFO
1249 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1250 "0x%x-0x%x\n", vha->host_no, cp->device->channel,
1251 cp->device->id, cp->device->lun, comp_status,
1255 DEBUG2(printk(KERN_INFO
1256 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1257 "sflags=%x.\n", vha->host_no, cp->device->channel,
1258 cp->device->id, cp->device->lun, comp_status, scsi_status,
1259 le16_to_cpu(sts->status_flags)));
1261 /* Check to see if logout occurred. */
1262 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
1263 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1267 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1268 "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
1269 qla_printk(KERN_INFO, ha,
1270 "Unknown status detected 0x%x-0x%x.\n",
1271 comp_status, scsi_status);
1273 cp->result = DID_ERROR << 16;
1277 /* Place command on done queue. */
1278 if (vha->status_srb == NULL)
1279 qla2x00_sp_compl(vha, sp);
1283 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1284 * @ha: SCSI driver HA context
1285 * @pkt: Entry pointer
1287 * Extended sense data.
1290 qla2x00_status_cont_entry(scsi_qla_host_t *vha, sts_cont_entry_t *pkt)
1292 uint8_t sense_sz = 0;
1293 struct qla_hw_data *ha = vha->hw;
1294 srb_t *sp = vha->status_srb;
1295 struct scsi_cmnd *cp;
1297 if (sp != NULL && sp->request_sense_length != 0) {
1300 DEBUG2(printk("%s(): Cmd already returned back to OS "
1301 "sp=%p.\n", __func__, sp));
1302 qla_printk(KERN_INFO, ha,
1303 "cmd is NULL: already returned to OS (sp=%p)\n",
1306 vha->status_srb = NULL;
1310 if (sp->request_sense_length > sizeof(pkt->data)) {
1311 sense_sz = sizeof(pkt->data);
1313 sense_sz = sp->request_sense_length;
1316 /* Move sense data. */
1317 if (IS_FWI2_CAPABLE(ha))
1318 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
1319 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1320 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1322 sp->request_sense_ptr += sense_sz;
1323 sp->request_sense_length -= sense_sz;
1325 /* Place command on done queue. */
1326 if (sp->request_sense_length == 0) {
1327 vha->status_srb = NULL;
1328 qla2x00_sp_compl(vha, sp);
1334 * qla2x00_error_entry() - Process an error entry.
1335 * @ha: SCSI driver HA context
1336 * @pkt: Entry pointer
1339 qla2x00_error_entry(scsi_qla_host_t *vha, sts_entry_t *pkt)
1342 struct qla_hw_data *ha = vha->hw;
1343 struct req_que *req = ha->req;
1344 #if defined(QL_DEBUG_LEVEL_2)
1345 if (pkt->entry_status & RF_INV_E_ORDER)
1346 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1347 else if (pkt->entry_status & RF_INV_E_COUNT)
1348 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1349 else if (pkt->entry_status & RF_INV_E_PARAM)
1350 qla_printk(KERN_ERR, ha,
1351 "%s: Invalid Entry Parameter\n", __func__);
1352 else if (pkt->entry_status & RF_INV_E_TYPE)
1353 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1354 else if (pkt->entry_status & RF_BUSY)
1355 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1357 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1360 /* Validate handle. */
1361 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1362 sp = req->outstanding_cmds[pkt->handle];
1367 /* Free outstanding command slot. */
1368 req->outstanding_cmds[pkt->handle] = NULL;
1370 /* Bad payload or header */
1371 if (pkt->entry_status &
1372 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1373 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1374 sp->cmd->result = DID_ERROR << 16;
1375 } else if (pkt->entry_status & RF_BUSY) {
1376 sp->cmd->result = DID_BUS_BUSY << 16;
1378 sp->cmd->result = DID_ERROR << 16;
1380 qla2x00_sp_compl(vha, sp);
1382 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1383 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
1384 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1386 qla_printk(KERN_WARNING, ha,
1387 "Error entry - invalid handle\n");
1389 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1390 qla2xxx_wake_dpc(vha);
1395 * qla24xx_mbx_completion() - Process mailbox command completions.
1396 * @ha: SCSI driver HA context
1397 * @mb0: Mailbox0 register
1400 qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
1403 uint16_t __iomem *wptr;
1404 struct qla_hw_data *ha = vha->hw;
1405 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1407 /* Load return mailbox registers. */
1408 ha->flags.mbox_int = 1;
1409 ha->mailbox_out[0] = mb0;
1410 wptr = (uint16_t __iomem *)®->mailbox1;
1412 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1413 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1418 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1419 __func__, vha->host_no, ha->mcp->mb[0]));
1421 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1422 __func__, vha->host_no));
1427 * qla24xx_process_response_queue() - Process response queue entries.
1428 * @ha: SCSI driver HA context
1431 qla24xx_process_response_queue(struct scsi_qla_host *vha)
1433 struct qla_hw_data *ha = vha->hw;
1434 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1435 struct sts_entry_24xx *pkt;
1436 struct rsp_que *rsp = ha->rsp;
1438 if (!vha->flags.online)
1441 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1442 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
1445 if (rsp->ring_index == rsp->length) {
1446 rsp->ring_index = 0;
1447 rsp->ring_ptr = rsp->ring;
1452 if (pkt->entry_status != 0) {
1453 DEBUG3(printk(KERN_INFO
1454 "scsi(%ld): Process error entry.\n", vha->host_no));
1456 qla2x00_error_entry(vha, (sts_entry_t *) pkt);
1457 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1462 switch (pkt->entry_type) {
1464 qla2x00_status_entry(vha, pkt);
1466 case STATUS_CONT_TYPE:
1467 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
1469 case VP_RPT_ID_IOCB_TYPE:
1470 qla24xx_report_id_acquisition(vha,
1471 (struct vp_rpt_id_entry_24xx *)pkt);
1474 /* Type Not Supported. */
1475 DEBUG4(printk(KERN_WARNING
1476 "scsi(%ld): Received unknown response pkt type %x "
1477 "entry status=%x.\n",
1478 vha->host_no, pkt->entry_type, pkt->entry_status));
1481 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1485 /* Adjust ring index */
1486 WRT_REG_DWORD(®->rsp_q_out, rsp->ring_index);
1490 qla2xxx_check_risc_status(scsi_qla_host_t *vha)
1494 struct qla_hw_data *ha = vha->hw;
1495 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1497 if (!IS_QLA25XX(ha))
1501 WRT_REG_DWORD(®->iobase_addr, 0x7C00);
1502 RD_REG_DWORD(®->iobase_addr);
1503 WRT_REG_DWORD(®->iobase_window, 0x0001);
1504 for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1505 rval == QLA_SUCCESS; cnt--) {
1507 WRT_REG_DWORD(®->iobase_window, 0x0001);
1510 rval = QLA_FUNCTION_TIMEOUT;
1512 if (rval == QLA_SUCCESS)
1515 WRT_REG_DWORD(®->iobase_window, 0x0003);
1516 for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1517 rval == QLA_SUCCESS; cnt--) {
1519 WRT_REG_DWORD(®->iobase_window, 0x0003);
1522 rval = QLA_FUNCTION_TIMEOUT;
1524 if (rval != QLA_SUCCESS)
1528 if (RD_REG_DWORD(®->iobase_c8) & BIT_3)
1529 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1532 WRT_REG_DWORD(®->iobase_window, 0x0000);
1533 RD_REG_DWORD(®->iobase_window);
1537 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1539 * @dev_id: SCSI driver HA context
1541 * Called by system whenever the host adapter generates an interrupt.
1543 * Returns handled flag.
1546 qla24xx_intr_handler(int irq, void *dev_id)
1548 scsi_qla_host_t *vha;
1549 struct qla_hw_data *ha;
1550 struct device_reg_24xx __iomem *reg;
1556 struct rsp_que *rsp;
1558 rsp = (struct rsp_que *) dev_id;
1561 "%s(): NULL response queue pointer\n", __func__);
1566 reg = &ha->iobase->isp24;
1569 spin_lock(&ha->hardware_lock);
1570 vha = qla2x00_get_rsp_host(rsp);
1571 for (iter = 50; iter--; ) {
1572 stat = RD_REG_DWORD(®->host_status);
1573 if (stat & HSRX_RISC_PAUSED) {
1574 if (pci_channel_offline(ha->pdev))
1577 if (ha->hw_event_pause_errors == 0)
1578 qla2x00_post_hwe_work(vha, HW_EVENT_PARITY_ERR,
1579 0, MSW(stat), LSW(stat));
1580 else if (ha->hw_event_pause_errors < 0xffffffff)
1581 ha->hw_event_pause_errors++;
1583 hccr = RD_REG_DWORD(®->hccr);
1585 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1586 "Dumping firmware!\n", hccr);
1588 qla2xxx_check_risc_status(vha);
1590 ha->isp_ops->fw_dump(vha, 1);
1591 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1593 } else if ((stat & HSRX_RISC_INT) == 0)
1596 switch (stat & 0xff) {
1601 qla24xx_mbx_completion(vha, MSW(stat));
1602 status |= MBX_INTERRUPT;
1607 mb[1] = RD_REG_WORD(®->mailbox1);
1608 mb[2] = RD_REG_WORD(®->mailbox2);
1609 mb[3] = RD_REG_WORD(®->mailbox3);
1610 qla2x00_async_event(vha, mb);
1613 qla24xx_process_response_queue(vha);
1616 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1618 vha->host_no, stat & 0xff));
1621 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1622 RD_REG_DWORD_RELAXED(®->hccr);
1624 spin_unlock(&ha->hardware_lock);
1626 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1627 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1628 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1629 complete(&ha->mbx_intr_comp);
1636 qla24xx_msix_rsp_q(int irq, void *dev_id)
1638 scsi_qla_host_t *vha;
1639 struct qla_hw_data *ha;
1640 struct rsp_que *rsp;
1641 struct device_reg_24xx __iomem *reg;
1643 rsp = (struct rsp_que *) dev_id;
1646 "%s(): NULL response queue pointer\n", __func__);
1650 reg = &ha->iobase->isp24;
1652 spin_lock_irq(&ha->hardware_lock);
1654 vha = qla2x00_get_rsp_host(rsp);
1655 qla24xx_process_response_queue(vha);
1656 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1658 spin_unlock_irq(&ha->hardware_lock);
1664 qla24xx_msix_default(int irq, void *dev_id)
1666 scsi_qla_host_t *vha;
1667 struct qla_hw_data *ha;
1668 struct rsp_que *rsp;
1669 struct device_reg_24xx __iomem *reg;
1675 rsp = (struct rsp_que *) dev_id;
1678 "%s(): NULL response queue pointer\n", __func__));
1682 reg = &ha->iobase->isp24;
1685 spin_lock_irq(&ha->hardware_lock);
1686 vha = qla2x00_get_rsp_host(rsp);
1688 stat = RD_REG_DWORD(®->host_status);
1689 if (stat & HSRX_RISC_PAUSED) {
1690 if (pci_channel_offline(ha->pdev))
1693 if (ha->hw_event_pause_errors == 0)
1694 qla2x00_post_hwe_work(vha, HW_EVENT_PARITY_ERR,
1695 0, MSW(stat), LSW(stat));
1696 else if (ha->hw_event_pause_errors < 0xffffffff)
1697 ha->hw_event_pause_errors++;
1699 hccr = RD_REG_DWORD(®->hccr);
1701 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1702 "Dumping firmware!\n", hccr);
1704 qla2xxx_check_risc_status(vha);
1706 ha->isp_ops->fw_dump(vha, 1);
1707 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1709 } else if ((stat & HSRX_RISC_INT) == 0)
1712 switch (stat & 0xff) {
1717 qla24xx_mbx_completion(vha, MSW(stat));
1718 status |= MBX_INTERRUPT;
1723 mb[1] = RD_REG_WORD(®->mailbox1);
1724 mb[2] = RD_REG_WORD(®->mailbox2);
1725 mb[3] = RD_REG_WORD(®->mailbox3);
1726 qla2x00_async_event(vha, mb);
1729 qla24xx_process_response_queue(vha);
1732 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1734 vha->host_no, stat & 0xff));
1737 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1739 spin_unlock_irq(&ha->hardware_lock);
1741 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1742 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1743 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1744 complete(&ha->mbx_intr_comp);
1750 /* Interrupt handling helpers. */
1752 struct qla_init_msix_entry {
1756 irq_handler_t handler;
1759 static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1760 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1761 "qla2xxx (default)", qla24xx_msix_default },
1763 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1764 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1768 qla24xx_disable_msix(struct qla_hw_data *ha)
1771 struct qla_msix_entry *qentry;
1772 struct rsp_que *rsp = ha->rsp;
1774 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1775 qentry = &ha->msix_entries[imsix_entries[i].index];
1776 if (qentry->have_irq)
1777 free_irq(qentry->msix_vector, rsp);
1779 pci_disable_msix(ha->pdev);
1783 qla24xx_enable_msix(struct qla_hw_data *ha)
1786 struct rsp_que *rsp = ha->rsp;
1787 struct msix_entry entries[QLA_MSIX_ENTRIES];
1788 struct qla_msix_entry *qentry;
1790 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1791 entries[i].entry = imsix_entries[i].entry;
1793 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1795 qla_printk(KERN_WARNING, ha,
1796 "MSI-X: Failed to enable support -- %d/%d\n",
1797 QLA_MSIX_ENTRIES, ret);
1800 ha->flags.msix_enabled = 1;
1802 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1803 qentry = &ha->msix_entries[imsix_entries[i].index];
1804 qentry->msix_vector = entries[i].vector;
1805 qentry->msix_entry = entries[i].entry;
1806 qentry->have_irq = 0;
1807 ret = request_irq(qentry->msix_vector,
1808 imsix_entries[i].handler, 0, imsix_entries[i].name, rsp);
1810 qla_printk(KERN_WARNING, ha,
1811 "MSI-X: Unable to register handler -- %x/%d.\n",
1812 imsix_entries[i].index, ret);
1813 qla24xx_disable_msix(ha);
1816 qentry->have_irq = 1;
1824 qla2x00_request_irqs(struct qla_hw_data *ha)
1827 device_reg_t __iomem *reg = ha->iobase;
1828 struct rsp_que *rsp = ha->rsp;
1830 /* If possible, enable MSI-X. */
1831 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
1834 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
1835 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
1836 DEBUG2(qla_printk(KERN_WARNING, ha,
1837 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1838 ha->pdev->revision, ha->fw_attributes));
1843 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1844 (ha->pdev->subsystem_device == 0x7040 ||
1845 ha->pdev->subsystem_device == 0x7041 ||
1846 ha->pdev->subsystem_device == 0x1705)) {
1847 DEBUG2(qla_printk(KERN_WARNING, ha,
1848 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1849 ha->pdev->subsystem_vendor,
1850 ha->pdev->subsystem_device));
1855 ret = qla24xx_enable_msix(ha);
1857 DEBUG2(qla_printk(KERN_INFO, ha,
1858 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1859 ha->fw_attributes));
1860 goto clear_risc_ints;
1862 qla_printk(KERN_WARNING, ha,
1863 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1866 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
1869 ret = pci_enable_msi(ha->pdev);
1871 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1872 ha->flags.msi_enabled = 1;
1876 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
1877 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
1879 qla_printk(KERN_WARNING, ha,
1880 "Failed to reserve interrupt %d already in use.\n",
1884 ha->flags.inta_enabled = 1;
1887 spin_lock_irq(&ha->hardware_lock);
1888 if (IS_FWI2_CAPABLE(ha)) {
1889 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT);
1890 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT);
1892 WRT_REG_WORD(®->isp.semaphore, 0);
1893 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT);
1894 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT);
1896 spin_unlock_irq(&ha->hardware_lock);
1903 qla2x00_free_irqs(scsi_qla_host_t *vha)
1905 struct qla_hw_data *ha = vha->hw;
1906 struct rsp_que *rsp = ha->rsp;
1908 if (ha->flags.msix_enabled)
1909 qla24xx_disable_msix(ha);
1910 else if (ha->flags.inta_enabled) {
1911 free_irq(ha->pdev->irq, rsp);
1912 pci_disable_msi(ha->pdev);
1916 static struct scsi_qla_host *
1917 qla2x00_get_rsp_host(struct rsp_que *rsp)
1920 struct qla_hw_data *ha = rsp->hw;
1921 struct scsi_qla_host *vha = NULL;
1922 struct sts_entry_24xx *pkt = (struct sts_entry_24xx *) rsp->ring_ptr;
1924 if (pkt && pkt->handle < MAX_OUTSTANDING_COMMANDS) {
1925 sp = ha->req->outstanding_cmds[pkt->handle];
1930 /* Invalid entry, handle it in base queue */
1931 vha = pci_get_drvdata(ha->pdev);