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 *);
19 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
21 * @dev_id: SCSI driver HA context
23 * Called by system whenever the host adapter generates an interrupt.
25 * Returns handled flag.
28 qla2100_intr_handler(int irq, void *dev_id)
31 struct device_reg_2xxx __iomem *reg;
37 ha = (scsi_qla_host_t *) dev_id;
40 "%s(): NULL host pointer\n", __func__);
44 reg = &ha->iobase->isp;
47 spin_lock(&ha->hardware_lock);
48 for (iter = 50; iter--; ) {
49 hccr = RD_REG_WORD(®->hccr);
50 if (hccr & HCCR_RISC_PAUSE) {
51 if (pci_channel_offline(ha->pdev))
55 * Issue a "HARD" reset in order for the RISC interrupt
56 * bit to be cleared. Schedule a big hammmer to get
57 * out of the RISC PAUSED state.
59 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
60 RD_REG_WORD(®->hccr);
62 ha->isp_ops->fw_dump(ha, 1);
63 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
65 } else if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0)
68 if (RD_REG_WORD(®->semaphore) & BIT_0) {
69 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
70 RD_REG_WORD(®->hccr);
72 /* Get mailbox data. */
73 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
74 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
75 qla2x00_mbx_completion(ha, mb[0]);
76 status |= MBX_INTERRUPT;
77 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
78 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
79 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
80 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
81 qla2x00_async_event(ha, mb);
84 DEBUG2(printk("scsi(%ld): Unrecognized "
85 "interrupt type (%d).\n",
88 /* Release mailbox registers. */
89 WRT_REG_WORD(®->semaphore, 0);
90 RD_REG_WORD(®->semaphore);
92 qla2x00_process_response_queue(ha);
94 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
95 RD_REG_WORD(®->hccr);
98 spin_unlock(&ha->hardware_lock);
100 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
101 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
102 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
103 complete(&ha->mbx_intr_comp);
106 return (IRQ_HANDLED);
110 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
112 * @dev_id: SCSI driver HA context
114 * Called by system whenever the host adapter generates an interrupt.
116 * Returns handled flag.
119 qla2300_intr_handler(int irq, void *dev_id)
122 struct device_reg_2xxx __iomem *reg;
129 ha = (scsi_qla_host_t *) dev_id;
132 "%s(): NULL host pointer\n", __func__);
136 reg = &ha->iobase->isp;
139 spin_lock(&ha->hardware_lock);
140 for (iter = 50; iter--; ) {
141 stat = RD_REG_DWORD(®->u.isp2300.host_status);
142 if (stat & HSR_RISC_PAUSED) {
143 if (pci_channel_offline(ha->pdev))
146 hccr = RD_REG_WORD(®->hccr);
147 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
148 qla_printk(KERN_INFO, ha, "Parity error -- "
149 "HCCR=%x, Dumping firmware!\n", hccr);
151 qla_printk(KERN_INFO, ha, "RISC paused -- "
152 "HCCR=%x, Dumping firmware!\n", hccr);
155 * Issue a "HARD" reset in order for the RISC
156 * interrupt bit to be cleared. Schedule a big
157 * hammmer to get out of the RISC PAUSED state.
159 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
160 RD_REG_WORD(®->hccr);
162 ha->isp_ops->fw_dump(ha, 1);
163 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
165 } else if ((stat & HSR_RISC_INT) == 0)
168 switch (stat & 0xff) {
173 qla2x00_mbx_completion(ha, MSW(stat));
174 status |= MBX_INTERRUPT;
176 /* Release mailbox registers. */
177 WRT_REG_WORD(®->semaphore, 0);
181 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
182 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
183 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
184 qla2x00_async_event(ha, mb);
187 qla2x00_process_response_queue(ha);
190 mb[0] = MBA_CMPLT_1_16BIT;
192 qla2x00_async_event(ha, mb);
195 mb[0] = MBA_SCSI_COMPLETION;
197 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
198 qla2x00_async_event(ha, mb);
201 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
203 ha->host_no, stat & 0xff));
206 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
207 RD_REG_WORD_RELAXED(®->hccr);
209 spin_unlock(&ha->hardware_lock);
211 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
212 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
213 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
214 complete(&ha->mbx_intr_comp);
217 return (IRQ_HANDLED);
221 * qla2x00_mbx_completion() - Process mailbox command completions.
222 * @ha: SCSI driver HA context
223 * @mb0: Mailbox0 register
226 qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
229 uint16_t __iomem *wptr;
230 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
232 /* Load return mailbox registers. */
233 ha->flags.mbox_int = 1;
234 ha->mailbox_out[0] = mb0;
235 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
237 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
238 if (IS_QLA2200(ha) && cnt == 8)
239 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
240 if (cnt == 4 || cnt == 5)
241 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
243 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
249 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
250 __func__, ha->host_no, ha->mcp->mb[0]));
252 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
253 __func__, ha->host_no));
258 * qla2x00_async_event() - Process aynchronous events.
259 * @ha: SCSI driver HA context
260 * @mb: Mailbox registers (0 - 3)
263 qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
266 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
271 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
272 uint32_t rscn_entry, host_pid;
273 uint8_t rscn_queue_index;
275 scsi_qla_host_t *vha;
278 /* Setup to process RIO completion. */
281 case MBA_SCSI_COMPLETION:
282 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
285 case MBA_CMPLT_1_16BIT:
288 mb[0] = MBA_SCSI_COMPLETION;
290 case MBA_CMPLT_2_16BIT:
294 mb[0] = MBA_SCSI_COMPLETION;
296 case MBA_CMPLT_3_16BIT:
301 mb[0] = MBA_SCSI_COMPLETION;
303 case MBA_CMPLT_4_16BIT:
307 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
309 mb[0] = MBA_SCSI_COMPLETION;
311 case MBA_CMPLT_5_16BIT:
315 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
316 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
318 mb[0] = MBA_SCSI_COMPLETION;
320 case MBA_CMPLT_2_32BIT:
321 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
322 handles[1] = le32_to_cpu(
323 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
324 RD_MAILBOX_REG(ha, reg, 6));
326 mb[0] = MBA_SCSI_COMPLETION;
333 case MBA_SCSI_COMPLETION: /* Fast Post */
334 if (!ha->flags.online)
337 for (cnt = 0; cnt < handle_cnt; cnt++)
338 qla2x00_process_completed_request(ha, handles[cnt]);
341 case MBA_RESET: /* Reset */
342 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
344 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
347 case MBA_SYSTEM_ERR: /* System Error */
348 qla_printk(KERN_INFO, ha,
349 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
350 mb[1], mb[2], mb[3]);
352 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
353 ha->isp_ops->fw_dump(ha, 1);
355 if (IS_FWI2_CAPABLE(ha)) {
356 if (mb[1] == 0 && mb[2] == 0) {
357 qla_printk(KERN_ERR, ha,
358 "Unrecoverable Hardware Error: adapter "
359 "marked OFFLINE!\n");
360 ha->flags.online = 0;
362 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
363 } else if (mb[1] == 0) {
364 qla_printk(KERN_INFO, ha,
365 "Unrecoverable Hardware Error: adapter marked "
367 ha->flags.online = 0;
369 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
372 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
373 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
375 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
377 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
378 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
381 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
382 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
384 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
386 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
387 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
390 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
391 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
395 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
396 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
398 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
400 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
401 atomic_set(&ha->loop_state, LOOP_DOWN);
402 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
403 qla2x00_mark_all_devices_lost(ha, 1);
407 atomic_set(&ha->vp_state, VP_FAILED);
408 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
411 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
412 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
414 ha->flags.management_server_logged_in = 0;
415 qla2x00_post_aen_work(ha, FCH_EVT_LIP, mb[1]);
418 case MBA_LOOP_UP: /* Loop Up Event */
419 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
420 link_speed = link_speeds[0];
421 ha->link_data_rate = PORT_SPEED_1GB;
423 link_speed = link_speeds[LS_UNKNOWN];
425 link_speed = link_speeds[mb[1]];
426 ha->link_data_rate = mb[1];
429 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
430 ha->host_no, link_speed));
431 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
434 ha->flags.management_server_logged_in = 0;
435 qla2x00_post_aen_work(ha, FCH_EVT_LINKUP, ha->link_data_rate);
438 case MBA_LOOP_DOWN: /* Loop Down Event */
439 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
440 "(%x %x %x).\n", ha->host_no, mb[1], mb[2], mb[3]));
441 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
442 mb[1], mb[2], mb[3]);
444 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
445 atomic_set(&ha->loop_state, LOOP_DOWN);
446 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
447 ha->device_flags |= DFLG_NO_CABLE;
448 qla2x00_mark_all_devices_lost(ha, 1);
452 atomic_set(&ha->vp_state, VP_FAILED);
453 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
456 ha->flags.management_server_logged_in = 0;
457 ha->link_data_rate = PORT_SPEED_UNKNOWN;
458 qla2x00_post_aen_work(ha, FCH_EVT_LINKDOWN, 0);
461 case MBA_LIP_RESET: /* LIP reset occurred */
462 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
463 ha->host_no, mb[1]));
464 qla_printk(KERN_INFO, ha,
465 "LIP reset occured (%x).\n", mb[1]);
467 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
468 atomic_set(&ha->loop_state, LOOP_DOWN);
469 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
470 qla2x00_mark_all_devices_lost(ha, 1);
474 atomic_set(&ha->vp_state, VP_FAILED);
475 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
478 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
480 ha->operating_mode = LOOP;
481 ha->flags.management_server_logged_in = 0;
482 qla2x00_post_aen_work(ha, FCH_EVT_LIPRESET, mb[1]);
485 case MBA_POINT_TO_POINT: /* Point-to-Point */
489 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
493 * Until there's a transition from loop down to loop up, treat
494 * this as loop down only.
496 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
497 atomic_set(&ha->loop_state, LOOP_DOWN);
498 if (!atomic_read(&ha->loop_down_timer))
499 atomic_set(&ha->loop_down_timer,
501 qla2x00_mark_all_devices_lost(ha, 1);
505 atomic_set(&ha->vp_state, VP_FAILED);
506 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
509 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
510 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
512 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
513 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
515 ha->flags.gpsc_supported = 1;
516 ha->flags.management_server_logged_in = 0;
519 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
523 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
526 qla_printk(KERN_INFO, ha,
527 "Configuration change detected: value=%x.\n", mb[1]);
529 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
530 atomic_set(&ha->loop_state, LOOP_DOWN);
531 if (!atomic_read(&ha->loop_down_timer))
532 atomic_set(&ha->loop_down_timer,
534 qla2x00_mark_all_devices_lost(ha, 1);
538 atomic_set(&ha->vp_state, VP_FAILED);
539 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
542 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
543 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
546 case MBA_PORT_UPDATE: /* Port database update */
547 if ((ha->flags.npiv_supported) && (ha->num_vhosts)) {
548 for_each_mapped_vp_idx(ha, i) {
549 list_for_each_entry(vha, &ha->vp_list,
560 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
561 * event etc. earlier indicating loop is down) then process
562 * it. Otherwise ignore it and Wait for RSCN to come in.
564 atomic_set(&ha->loop_down_timer, 0);
565 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
566 atomic_read(&ha->loop_state) != LOOP_DEAD) {
567 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
568 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
573 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
575 DEBUG(printk(KERN_INFO
576 "scsi(%ld): Port database changed %04x %04x %04x.\n",
577 ha->host_no, mb[1], mb[2], mb[3]));
580 * Mark all devices as missing so we will login again.
582 atomic_set(&ha->loop_state, LOOP_UP);
584 qla2x00_mark_all_devices_lost(ha, 1);
586 ha->flags.rscn_queue_overflow = 1;
588 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
589 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
592 case MBA_RSCN_UPDATE: /* State Change Registration */
593 if ((ha->flags.npiv_supported) && (ha->num_vhosts)) {
594 for_each_mapped_vp_idx(ha, i) {
595 list_for_each_entry(vha, &ha->vp_list,
606 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
608 DEBUG(printk(KERN_INFO
609 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
610 ha->host_no, mb[1], mb[2], mb[3]));
612 rscn_entry = (mb[1] << 16) | mb[2];
613 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
615 if (rscn_entry == host_pid) {
616 DEBUG(printk(KERN_INFO
617 "scsi(%ld): Ignoring RSCN update to local host "
619 ha->host_no, host_pid));
623 rscn_queue_index = ha->rscn_in_ptr + 1;
624 if (rscn_queue_index == MAX_RSCN_COUNT)
625 rscn_queue_index = 0;
626 if (rscn_queue_index != ha->rscn_out_ptr) {
627 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
628 ha->rscn_in_ptr = rscn_queue_index;
630 ha->flags.rscn_queue_overflow = 1;
633 atomic_set(&ha->loop_state, LOOP_UPDATE);
634 atomic_set(&ha->loop_down_timer, 0);
635 ha->flags.management_server_logged_in = 0;
637 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
638 set_bit(RSCN_UPDATE, &ha->dpc_flags);
639 qla2x00_post_aen_work(ha, 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(ha);
653 qla2x00_process_response_queue(ha);
656 case MBA_DISCARD_RND_FRAME:
657 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
658 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
661 case MBA_TRACE_NOTIFICATION:
662 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
663 ha->host_no, mb[1], mb[2]));
666 case MBA_ISP84XX_ALERT:
667 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
668 "%04x %04x %04x\n", ha->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 (!ha->parent && ha->num_vhosts)
704 qla2x00_alert_all_vps(ha, mb);
708 qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
710 fc_port_t *fcport = data;
712 if (fcport->ha->max_q_depth <= sdev->queue_depth)
715 if (sdev->ordered_tags)
716 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
717 sdev->queue_depth + 1);
719 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
720 sdev->queue_depth + 1);
722 fcport->last_ramp_up = jiffies;
724 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
725 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
726 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
731 qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
733 fc_port_t *fcport = data;
735 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
738 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
739 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
740 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
745 qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
748 struct scsi_device *sdev;
750 sdev = sp->cmd->device;
751 if (sdev->queue_depth >= ha->max_q_depth)
755 if (time_before(jiffies,
756 fcport->last_ramp_up + ql2xqfullrampup * HZ))
758 if (time_before(jiffies,
759 fcport->last_queue_full + ql2xqfullrampup * HZ))
762 starget_for_each_device(sdev->sdev_target, fcport,
763 qla2x00_adjust_sdev_qdepth_up);
767 * qla2x00_process_completed_request() - Process a Fast Post response.
768 * @ha: SCSI driver HA context
772 qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
776 /* Validate handle. */
777 if (index >= MAX_OUTSTANDING_COMMANDS) {
778 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
779 ha->host_no, index));
780 qla_printk(KERN_WARNING, ha,
781 "Invalid SCSI completion handle %d.\n", index);
783 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
787 sp = ha->outstanding_cmds[index];
789 /* Free outstanding command slot. */
790 ha->outstanding_cmds[index] = NULL;
792 CMD_COMPL_STATUS(sp->cmd) = 0L;
793 CMD_SCSI_STATUS(sp->cmd) = 0L;
795 /* Save ISP completion status */
796 sp->cmd->result = DID_OK << 16;
798 qla2x00_ramp_up_queue_depth(ha, sp);
799 qla2x00_sp_compl(ha, sp);
801 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
803 qla_printk(KERN_WARNING, ha,
804 "Invalid ISP SCSI completion handle\n");
806 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
811 * qla2x00_process_response_queue() - Process response queue entries.
812 * @ha: SCSI driver HA context
815 qla2x00_process_response_queue(struct scsi_qla_host *ha)
817 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
822 if (!ha->flags.online)
825 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
826 pkt = (sts_entry_t *)ha->response_ring_ptr;
828 ha->rsp_ring_index++;
829 if (ha->rsp_ring_index == ha->response_q_length) {
830 ha->rsp_ring_index = 0;
831 ha->response_ring_ptr = ha->response_ring;
833 ha->response_ring_ptr++;
836 if (pkt->entry_status != 0) {
837 DEBUG3(printk(KERN_INFO
838 "scsi(%ld): Process error entry.\n", ha->host_no));
840 qla2x00_error_entry(ha, pkt);
841 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
846 switch (pkt->entry_type) {
848 qla2x00_status_entry(ha, pkt);
851 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
852 for (cnt = 0; cnt < handle_cnt; cnt++) {
853 qla2x00_process_completed_request(ha,
854 ((sts21_entry_t *)pkt)->handle[cnt]);
858 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
859 for (cnt = 0; cnt < handle_cnt; cnt++) {
860 qla2x00_process_completed_request(ha,
861 ((sts22_entry_t *)pkt)->handle[cnt]);
864 case STATUS_CONT_TYPE:
865 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
868 /* Type Not Supported. */
869 DEBUG4(printk(KERN_WARNING
870 "scsi(%ld): Received unknown response pkt type %x "
871 "entry status=%x.\n",
872 ha->host_no, pkt->entry_type, pkt->entry_status));
875 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
879 /* Adjust ring index */
880 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
884 qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
886 struct scsi_cmnd *cp = sp->cmd;
888 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
889 sense_len = SCSI_SENSE_BUFFERSIZE;
891 CMD_ACTUAL_SNSLEN(cp) = sense_len;
892 sp->request_sense_length = sense_len;
893 sp->request_sense_ptr = cp->sense_buffer;
894 if (sp->request_sense_length > 32)
897 memcpy(cp->sense_buffer, sense_data, sense_len);
899 sp->request_sense_ptr += sense_len;
900 sp->request_sense_length -= sense_len;
901 if (sp->request_sense_length != 0)
902 sp->ha->status_srb = sp;
904 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
905 "cmd=%p pid=%ld\n", __func__, sp->ha->host_no, cp->device->channel,
906 cp->device->id, cp->device->lun, cp, cp->serial_number));
908 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
909 CMD_ACTUAL_SNSLEN(cp)));
913 * qla2x00_status_entry() - Process a Status IOCB entry.
914 * @ha: SCSI driver HA context
915 * @pkt: Entry pointer
918 qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
922 struct scsi_cmnd *cp;
924 struct sts_entry_24xx *sts24;
925 uint16_t comp_status;
926 uint16_t scsi_status;
927 uint8_t lscsi_status;
929 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
930 uint8_t *rsp_info, *sense_data;
932 sts = (sts_entry_t *) pkt;
933 sts24 = (struct sts_entry_24xx *) pkt;
934 if (IS_FWI2_CAPABLE(ha)) {
935 comp_status = le16_to_cpu(sts24->comp_status);
936 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
938 comp_status = le16_to_cpu(sts->comp_status);
939 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
942 /* Fast path completion. */
943 if (comp_status == CS_COMPLETE && scsi_status == 0) {
944 qla2x00_process_completed_request(ha, sts->handle);
949 /* Validate handle. */
950 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
951 sp = ha->outstanding_cmds[sts->handle];
952 ha->outstanding_cmds[sts->handle] = NULL;
957 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
959 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
961 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
962 qla2xxx_wake_dpc(ha);
967 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
968 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
969 qla_printk(KERN_WARNING, ha,
970 "Command is NULL: already returned to OS (sp=%p)\n", sp);
975 lscsi_status = scsi_status & STATUS_MASK;
976 CMD_ENTRY_STATUS(cp) = sts->entry_status;
977 CMD_COMPL_STATUS(cp) = comp_status;
978 CMD_SCSI_STATUS(cp) = scsi_status;
982 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
983 if (IS_FWI2_CAPABLE(ha)) {
984 sense_len = le32_to_cpu(sts24->sense_len);
985 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
986 resid_len = le32_to_cpu(sts24->rsp_residual_count);
987 fw_resid_len = le32_to_cpu(sts24->residual_len);
988 rsp_info = sts24->data;
989 sense_data = sts24->data;
990 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
992 sense_len = le16_to_cpu(sts->req_sense_length);
993 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
994 resid_len = le32_to_cpu(sts->residual_length);
995 rsp_info = sts->rsp_info;
996 sense_data = sts->req_sense_data;
999 /* Check for any FCP transport errors. */
1000 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
1001 /* Sense data lies beyond any FCP RESPONSE data. */
1002 if (IS_FWI2_CAPABLE(ha))
1003 sense_data += rsp_info_len;
1004 if (rsp_info_len > 3 && rsp_info[3]) {
1005 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1006 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
1007 "retrying command\n", ha->host_no,
1008 cp->device->channel, cp->device->id,
1009 cp->device->lun, rsp_info_len, rsp_info[0],
1010 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1011 rsp_info[5], rsp_info[6], rsp_info[7]));
1013 cp->result = DID_BUS_BUSY << 16;
1014 qla2x00_sp_compl(ha, sp);
1019 /* Check for overrun. */
1020 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1021 scsi_status & SS_RESIDUAL_OVER)
1022 comp_status = CS_DATA_OVERRUN;
1025 * Based on Host and scsi status generate status code for Linux
1027 switch (comp_status) {
1030 if (scsi_status == 0) {
1031 cp->result = DID_OK << 16;
1034 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
1036 scsi_set_resid(cp, resid);
1037 CMD_RESID_LEN(cp) = resid;
1039 if (!lscsi_status &&
1040 ((unsigned)(scsi_bufflen(cp) - resid) <
1042 qla_printk(KERN_INFO, ha,
1043 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1044 "detected (%x of %x bytes)...returning "
1045 "error status.\n", ha->host_no,
1046 cp->device->channel, cp->device->id,
1047 cp->device->lun, resid,
1050 cp->result = DID_ERROR << 16;
1054 cp->result = DID_OK << 16 | lscsi_status;
1056 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1057 DEBUG2(printk(KERN_INFO
1058 "scsi(%ld): QUEUE FULL status detected "
1059 "0x%x-0x%x.\n", ha->host_no, comp_status,
1062 /* Adjust queue depth for all luns on the port. */
1063 fcport->last_queue_full = jiffies;
1064 starget_for_each_device(cp->device->sdev_target,
1065 fcport, qla2x00_adjust_sdev_qdepth_down);
1068 if (lscsi_status != SS_CHECK_CONDITION)
1071 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1072 if (!(scsi_status & SS_SENSE_LEN_VALID))
1075 qla2x00_handle_sense(sp, sense_data, sense_len);
1078 case CS_DATA_UNDERRUN:
1080 /* Use F/W calculated residual length. */
1081 if (IS_FWI2_CAPABLE(ha)) {
1082 if (scsi_status & SS_RESIDUAL_UNDER &&
1083 resid != fw_resid_len) {
1084 scsi_status &= ~SS_RESIDUAL_UNDER;
1087 resid = fw_resid_len;
1090 if (scsi_status & SS_RESIDUAL_UNDER) {
1091 scsi_set_resid(cp, resid);
1092 CMD_RESID_LEN(cp) = resid;
1094 DEBUG2(printk(KERN_INFO
1095 "scsi(%ld:%d:%d) UNDERRUN status detected "
1096 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1097 "os_underflow=0x%x\n", ha->host_no,
1098 cp->device->id, cp->device->lun, comp_status,
1099 scsi_status, resid_len, resid, cp->cmnd[0],
1105 * Check to see if SCSI Status is non zero. If so report SCSI
1108 if (lscsi_status != 0) {
1109 cp->result = DID_OK << 16 | lscsi_status;
1111 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1112 DEBUG2(printk(KERN_INFO
1113 "scsi(%ld): QUEUE FULL status detected "
1114 "0x%x-0x%x.\n", ha->host_no, comp_status,
1118 * Adjust queue depth for all luns on the
1121 fcport->last_queue_full = jiffies;
1122 starget_for_each_device(
1123 cp->device->sdev_target, fcport,
1124 qla2x00_adjust_sdev_qdepth_down);
1127 if (lscsi_status != SS_CHECK_CONDITION)
1130 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1131 if (!(scsi_status & SS_SENSE_LEN_VALID))
1134 qla2x00_handle_sense(sp, sense_data, sense_len);
1137 * In case of a Underrun condition, set both the lscsi
1138 * status and the completion status to appropriate
1142 ((unsigned)(scsi_bufflen(cp) - resid) <
1144 DEBUG2(qla_printk(KERN_INFO, ha,
1145 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1146 "detected (%x of %x bytes)...returning "
1147 "error status.\n", ha->host_no,
1148 cp->device->channel, cp->device->id,
1149 cp->device->lun, resid,
1152 cp->result = DID_ERROR << 16 | lscsi_status;
1156 * If RISC reports underrun and target does not report
1157 * it then we must have a lost frame, so tell upper
1158 * layer to retry it by reporting a bus busy.
1160 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1161 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1162 "frame(s) detected (%x of %x bytes)..."
1163 "retrying command.\n", ha->host_no,
1164 cp->device->channel, cp->device->id,
1165 cp->device->lun, resid,
1168 cp->result = DID_BUS_BUSY << 16;
1172 /* Handle mid-layer underflow */
1173 if ((unsigned)(scsi_bufflen(cp) - resid) <
1175 qla_printk(KERN_INFO, ha,
1176 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1177 "detected (%x of %x bytes)...returning "
1178 "error status.\n", ha->host_no,
1179 cp->device->channel, cp->device->id,
1180 cp->device->lun, resid,
1183 cp->result = DID_ERROR << 16;
1187 /* Everybody online, looking good... */
1188 cp->result = DID_OK << 16;
1192 case CS_DATA_OVERRUN:
1193 DEBUG2(printk(KERN_INFO
1194 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1195 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1197 DEBUG2(printk(KERN_INFO
1198 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1199 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1200 cp->cmnd[4], cp->cmnd[5]));
1201 DEBUG2(printk(KERN_INFO
1202 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1204 cp->serial_number, scsi_bufflen(cp), resid_len));
1206 cp->result = DID_ERROR << 16;
1209 case CS_PORT_LOGGED_OUT:
1210 case CS_PORT_CONFIG_CHG:
1213 case CS_PORT_UNAVAILABLE:
1215 * If the port is in Target Down state, return all IOs for this
1216 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1219 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1220 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1221 ha->host_no, cp->device->id, cp->device->lun,
1222 cp->serial_number, comp_status,
1223 atomic_read(&fcport->state)));
1225 cp->result = DID_BUS_BUSY << 16;
1226 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1227 qla2x00_mark_device_lost(ha, fcport, 1, 1);
1232 DEBUG2(printk(KERN_INFO
1233 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1234 ha->host_no, comp_status, scsi_status));
1236 cp->result = DID_RESET << 16;
1241 * hv2.19.12 - DID_ABORT does not retry the request if we
1242 * aborted this request then abort otherwise it must be a
1245 DEBUG2(printk(KERN_INFO
1246 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1247 ha->host_no, comp_status, scsi_status));
1249 cp->result = DID_RESET << 16;
1253 cp->result = DID_BUS_BUSY << 16;
1255 if (IS_FWI2_CAPABLE(ha)) {
1256 DEBUG2(printk(KERN_INFO
1257 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1258 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1259 cp->device->id, cp->device->lun, comp_status,
1263 DEBUG2(printk(KERN_INFO
1264 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1265 "sflags=%x.\n", ha->host_no, cp->device->channel,
1266 cp->device->id, cp->device->lun, comp_status, scsi_status,
1267 le16_to_cpu(sts->status_flags)));
1269 /* Check to see if logout occurred. */
1270 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
1271 qla2x00_mark_device_lost(ha, fcport, 1, 1);
1275 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1276 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
1277 qla_printk(KERN_INFO, ha,
1278 "Unknown status detected 0x%x-0x%x.\n",
1279 comp_status, scsi_status);
1281 cp->result = DID_ERROR << 16;
1285 /* Place command on done queue. */
1286 if (ha->status_srb == NULL)
1287 qla2x00_sp_compl(ha, sp);
1291 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1292 * @ha: SCSI driver HA context
1293 * @pkt: Entry pointer
1295 * Extended sense data.
1298 qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1300 uint8_t sense_sz = 0;
1301 srb_t *sp = ha->status_srb;
1302 struct scsi_cmnd *cp;
1304 if (sp != NULL && sp->request_sense_length != 0) {
1307 DEBUG2(printk("%s(): Cmd already returned back to OS "
1308 "sp=%p.\n", __func__, sp));
1309 qla_printk(KERN_INFO, ha,
1310 "cmd is NULL: already returned to OS (sp=%p)\n",
1313 ha->status_srb = NULL;
1317 if (sp->request_sense_length > sizeof(pkt->data)) {
1318 sense_sz = sizeof(pkt->data);
1320 sense_sz = sp->request_sense_length;
1323 /* Move sense data. */
1324 if (IS_FWI2_CAPABLE(ha))
1325 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
1326 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1327 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1329 sp->request_sense_ptr += sense_sz;
1330 sp->request_sense_length -= sense_sz;
1332 /* Place command on done queue. */
1333 if (sp->request_sense_length == 0) {
1334 ha->status_srb = NULL;
1335 qla2x00_sp_compl(ha, sp);
1341 * qla2x00_error_entry() - Process an error entry.
1342 * @ha: SCSI driver HA context
1343 * @pkt: Entry pointer
1346 qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
1350 #if defined(QL_DEBUG_LEVEL_2)
1351 if (pkt->entry_status & RF_INV_E_ORDER)
1352 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1353 else if (pkt->entry_status & RF_INV_E_COUNT)
1354 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1355 else if (pkt->entry_status & RF_INV_E_PARAM)
1356 qla_printk(KERN_ERR, ha,
1357 "%s: Invalid Entry Parameter\n", __func__);
1358 else if (pkt->entry_status & RF_INV_E_TYPE)
1359 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1360 else if (pkt->entry_status & RF_BUSY)
1361 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1363 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1366 /* Validate handle. */
1367 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1368 sp = ha->outstanding_cmds[pkt->handle];
1373 /* Free outstanding command slot. */
1374 ha->outstanding_cmds[pkt->handle] = NULL;
1376 /* Bad payload or header */
1377 if (pkt->entry_status &
1378 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1379 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1380 sp->cmd->result = DID_ERROR << 16;
1381 } else if (pkt->entry_status & RF_BUSY) {
1382 sp->cmd->result = DID_BUS_BUSY << 16;
1384 sp->cmd->result = DID_ERROR << 16;
1386 qla2x00_sp_compl(ha, sp);
1388 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1389 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
1390 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1392 qla_printk(KERN_WARNING, ha,
1393 "Error entry - invalid handle\n");
1395 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1396 qla2xxx_wake_dpc(ha);
1401 * qla24xx_mbx_completion() - Process mailbox command completions.
1402 * @ha: SCSI driver HA context
1403 * @mb0: Mailbox0 register
1406 qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1409 uint16_t __iomem *wptr;
1410 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1412 /* Load return mailbox registers. */
1413 ha->flags.mbox_int = 1;
1414 ha->mailbox_out[0] = mb0;
1415 wptr = (uint16_t __iomem *)®->mailbox1;
1417 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1418 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1423 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1424 __func__, ha->host_no, ha->mcp->mb[0]));
1426 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1427 __func__, ha->host_no));
1432 * qla24xx_process_response_queue() - Process response queue entries.
1433 * @ha: SCSI driver HA context
1436 qla24xx_process_response_queue(struct scsi_qla_host *ha)
1438 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1439 struct sts_entry_24xx *pkt;
1441 if (!ha->flags.online)
1444 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1445 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1447 ha->rsp_ring_index++;
1448 if (ha->rsp_ring_index == ha->response_q_length) {
1449 ha->rsp_ring_index = 0;
1450 ha->response_ring_ptr = ha->response_ring;
1452 ha->response_ring_ptr++;
1455 if (pkt->entry_status != 0) {
1456 DEBUG3(printk(KERN_INFO
1457 "scsi(%ld): Process error entry.\n", ha->host_no));
1459 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1460 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1465 switch (pkt->entry_type) {
1467 qla2x00_status_entry(ha, pkt);
1469 case STATUS_CONT_TYPE:
1470 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1472 case VP_RPT_ID_IOCB_TYPE:
1473 qla24xx_report_id_acquisition(ha,
1474 (struct vp_rpt_id_entry_24xx *)pkt);
1477 /* Type Not Supported. */
1478 DEBUG4(printk(KERN_WARNING
1479 "scsi(%ld): Received unknown response pkt type %x "
1480 "entry status=%x.\n",
1481 ha->host_no, pkt->entry_type, pkt->entry_status));
1484 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1488 /* Adjust ring index */
1489 WRT_REG_DWORD(®->rsp_q_out, ha->rsp_ring_index);
1493 qla2xxx_check_risc_status(scsi_qla_host_t *ha)
1497 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1499 if (!IS_QLA25XX(ha))
1503 WRT_REG_DWORD(®->iobase_addr, 0x7C00);
1504 RD_REG_DWORD(®->iobase_addr);
1505 WRT_REG_DWORD(®->iobase_window, 0x0001);
1506 for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1507 rval == QLA_SUCCESS; cnt--) {
1509 WRT_REG_DWORD(®->iobase_window, 0x0001);
1512 rval = QLA_FUNCTION_TIMEOUT;
1514 if (rval == QLA_SUCCESS)
1517 WRT_REG_DWORD(®->iobase_window, 0x0003);
1518 for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
1519 rval == QLA_SUCCESS; cnt--) {
1521 WRT_REG_DWORD(®->iobase_window, 0x0003);
1524 rval = QLA_FUNCTION_TIMEOUT;
1526 if (rval != QLA_SUCCESS)
1530 if (RD_REG_DWORD(®->iobase_c8) & BIT_3)
1531 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1534 WRT_REG_DWORD(®->iobase_window, 0x0000);
1535 RD_REG_DWORD(®->iobase_window);
1539 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1541 * @dev_id: SCSI driver HA context
1543 * Called by system whenever the host adapter generates an interrupt.
1545 * Returns handled flag.
1548 qla24xx_intr_handler(int irq, void *dev_id)
1550 scsi_qla_host_t *ha;
1551 struct device_reg_24xx __iomem *reg;
1558 ha = (scsi_qla_host_t *) dev_id;
1561 "%s(): NULL host pointer\n", __func__);
1565 reg = &ha->iobase->isp24;
1568 spin_lock(&ha->hardware_lock);
1569 for (iter = 50; iter--; ) {
1570 stat = RD_REG_DWORD(®->host_status);
1571 if (stat & HSRX_RISC_PAUSED) {
1572 if (pci_channel_offline(ha->pdev))
1575 if (ha->hw_event_pause_errors == 0)
1576 qla2x00_post_hwe_work(ha, HW_EVENT_PARITY_ERR,
1577 0, MSW(stat), LSW(stat));
1578 else if (ha->hw_event_pause_errors < 0xffffffff)
1579 ha->hw_event_pause_errors++;
1581 hccr = RD_REG_DWORD(®->hccr);
1583 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1584 "Dumping firmware!\n", hccr);
1586 qla2xxx_check_risc_status(ha);
1588 ha->isp_ops->fw_dump(ha, 1);
1589 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1591 } else if ((stat & HSRX_RISC_INT) == 0)
1594 switch (stat & 0xff) {
1599 qla24xx_mbx_completion(ha, MSW(stat));
1600 status |= MBX_INTERRUPT;
1605 mb[1] = RD_REG_WORD(®->mailbox1);
1606 mb[2] = RD_REG_WORD(®->mailbox2);
1607 mb[3] = RD_REG_WORD(®->mailbox3);
1608 qla2x00_async_event(ha, mb);
1611 qla24xx_process_response_queue(ha);
1614 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1616 ha->host_no, stat & 0xff));
1619 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1620 RD_REG_DWORD_RELAXED(®->hccr);
1622 spin_unlock(&ha->hardware_lock);
1624 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1625 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1626 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1627 complete(&ha->mbx_intr_comp);
1634 qla24xx_msix_rsp_q(int irq, void *dev_id)
1636 scsi_qla_host_t *ha;
1637 struct device_reg_24xx __iomem *reg;
1640 reg = &ha->iobase->isp24;
1642 spin_lock(&ha->hardware_lock);
1644 qla24xx_process_response_queue(ha);
1645 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1647 spin_unlock(&ha->hardware_lock);
1653 qla24xx_msix_default(int irq, void *dev_id)
1655 scsi_qla_host_t *ha;
1656 struct device_reg_24xx __iomem *reg;
1663 reg = &ha->iobase->isp24;
1666 spin_lock(&ha->hardware_lock);
1668 stat = RD_REG_DWORD(®->host_status);
1669 if (stat & HSRX_RISC_PAUSED) {
1670 if (pci_channel_offline(ha->pdev))
1673 if (ha->hw_event_pause_errors == 0)
1674 qla2x00_post_hwe_work(ha, HW_EVENT_PARITY_ERR,
1675 0, MSW(stat), LSW(stat));
1676 else if (ha->hw_event_pause_errors < 0xffffffff)
1677 ha->hw_event_pause_errors++;
1679 hccr = RD_REG_DWORD(®->hccr);
1681 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1682 "Dumping firmware!\n", hccr);
1684 qla2xxx_check_risc_status(ha);
1686 ha->isp_ops->fw_dump(ha, 1);
1687 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1689 } else if ((stat & HSRX_RISC_INT) == 0)
1692 switch (stat & 0xff) {
1697 qla24xx_mbx_completion(ha, MSW(stat));
1698 status |= MBX_INTERRUPT;
1703 mb[1] = RD_REG_WORD(®->mailbox1);
1704 mb[2] = RD_REG_WORD(®->mailbox2);
1705 mb[3] = RD_REG_WORD(®->mailbox3);
1706 qla2x00_async_event(ha, mb);
1709 qla24xx_process_response_queue(ha);
1712 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1714 ha->host_no, stat & 0xff));
1717 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1719 spin_unlock(&ha->hardware_lock);
1721 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1722 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1723 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1724 complete(&ha->mbx_intr_comp);
1730 /* Interrupt handling helpers. */
1732 struct qla_init_msix_entry {
1736 irq_handler_t handler;
1739 static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1740 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1741 "qla2xxx (default)", qla24xx_msix_default },
1743 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1744 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1748 qla24xx_disable_msix(scsi_qla_host_t *ha)
1751 struct qla_msix_entry *qentry;
1753 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1754 qentry = &ha->msix_entries[imsix_entries[i].index];
1755 if (qentry->have_irq)
1756 free_irq(qentry->msix_vector, ha);
1758 pci_disable_msix(ha->pdev);
1762 qla24xx_enable_msix(scsi_qla_host_t *ha)
1765 struct msix_entry entries[QLA_MSIX_ENTRIES];
1766 struct qla_msix_entry *qentry;
1768 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1769 entries[i].entry = imsix_entries[i].entry;
1771 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1773 qla_printk(KERN_WARNING, ha,
1774 "MSI-X: Failed to enable support -- %d/%d\n",
1775 QLA_MSIX_ENTRIES, ret);
1778 ha->flags.msix_enabled = 1;
1780 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1781 qentry = &ha->msix_entries[imsix_entries[i].index];
1782 qentry->msix_vector = entries[i].vector;
1783 qentry->msix_entry = entries[i].entry;
1784 qentry->have_irq = 0;
1785 ret = request_irq(qentry->msix_vector,
1786 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1788 qla_printk(KERN_WARNING, ha,
1789 "MSI-X: Unable to register handler -- %x/%d.\n",
1790 imsix_entries[i].index, ret);
1791 qla24xx_disable_msix(ha);
1794 qentry->have_irq = 1;
1802 qla2x00_request_irqs(scsi_qla_host_t *ha)
1805 device_reg_t __iomem *reg = ha->iobase;
1807 /* If possible, enable MSI-X. */
1808 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
1811 if (IS_QLA2432(ha) && (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1812 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
1813 DEBUG2(qla_printk(KERN_WARNING, ha,
1814 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1815 ha->chip_revision, ha->fw_attributes));
1820 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1821 (ha->pdev->subsystem_device == 0x7040 ||
1822 ha->pdev->subsystem_device == 0x7041 ||
1823 ha->pdev->subsystem_device == 0x1705)) {
1824 DEBUG2(qla_printk(KERN_WARNING, ha,
1825 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1826 ha->pdev->subsystem_vendor,
1827 ha->pdev->subsystem_device));
1832 ret = qla24xx_enable_msix(ha);
1834 DEBUG2(qla_printk(KERN_INFO, ha,
1835 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1836 ha->fw_attributes));
1837 goto clear_risc_ints;
1839 qla_printk(KERN_WARNING, ha,
1840 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1843 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
1846 ret = pci_enable_msi(ha->pdev);
1848 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1849 ha->flags.msi_enabled = 1;
1853 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
1854 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
1856 qla_printk(KERN_WARNING, ha,
1857 "Failed to reserve interrupt %d already in use.\n",
1861 ha->flags.inta_enabled = 1;
1862 ha->host->irq = ha->pdev->irq;
1865 ha->isp_ops->disable_intrs(ha);
1866 spin_lock_irq(&ha->hardware_lock);
1867 if (IS_FWI2_CAPABLE(ha)) {
1868 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT);
1869 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT);
1871 WRT_REG_WORD(®->isp.semaphore, 0);
1872 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT);
1873 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT);
1875 spin_unlock_irq(&ha->hardware_lock);
1876 ha->isp_ops->enable_intrs(ha);
1883 qla2x00_free_irqs(scsi_qla_host_t *ha)
1886 if (ha->flags.msix_enabled)
1887 qla24xx_disable_msix(ha);
1888 else if (ha->flags.inta_enabled) {
1889 free_irq(ha->host->irq, ha);
1890 pci_disable_msi(ha->pdev);