2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <scsi/scsi_tcq.h>
11 static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
12 static void qla2x00_async_event(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 void qla2x00_ms_entry(scsi_qla_host_t *, ms_iocb_entry_t *);
19 static void qla24xx_ms_entry(scsi_qla_host_t *, struct ct_entry_24xx *);
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 device_reg_2xxx __iomem *reg;
40 ha = (scsi_qla_host_t *) dev_id;
43 "%s(): NULL host pointer\n", __func__);
47 reg = &ha->iobase->isp;
50 spin_lock_irqsave(&ha->hardware_lock, flags);
51 for (iter = 50; iter--; ) {
52 if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0)
55 if (RD_REG_WORD(®->semaphore) & BIT_0) {
56 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
57 RD_REG_WORD(®->hccr);
59 /* Get mailbox data. */
60 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
61 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
62 qla2x00_mbx_completion(ha, mb[0]);
63 status |= MBX_INTERRUPT;
64 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
65 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
66 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
67 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
68 qla2x00_async_event(ha, mb);
71 DEBUG2(printk("scsi(%ld): Unrecognized "
72 "interrupt type (%d).\n",
75 /* Release mailbox registers. */
76 WRT_REG_WORD(®->semaphore, 0);
77 RD_REG_WORD(®->semaphore);
79 qla2x00_process_response_queue(ha);
81 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
82 RD_REG_WORD(®->hccr);
85 spin_unlock_irqrestore(&ha->hardware_lock, flags);
87 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
88 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
89 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
90 up(&ha->mbx_intr_sem);
97 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
99 * @dev_id: SCSI driver HA context
101 * Called by system whenever the host adapter generates an interrupt.
103 * Returns handled flag.
106 qla2300_intr_handler(int irq, void *dev_id)
109 struct device_reg_2xxx __iomem *reg;
117 ha = (scsi_qla_host_t *) dev_id;
120 "%s(): NULL host pointer\n", __func__);
124 reg = &ha->iobase->isp;
127 spin_lock_irqsave(&ha->hardware_lock, flags);
128 for (iter = 50; iter--; ) {
129 stat = RD_REG_DWORD(®->u.isp2300.host_status);
130 if (stat & HSR_RISC_PAUSED) {
131 hccr = RD_REG_WORD(®->hccr);
132 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
133 qla_printk(KERN_INFO, ha, "Parity error -- "
134 "HCCR=%x, Dumping firmware!\n", hccr);
136 qla_printk(KERN_INFO, ha, "RISC paused -- "
137 "HCCR=%x, Dumping firmware!\n", hccr);
140 * Issue a "HARD" reset in order for the RISC
141 * interrupt bit to be cleared. Schedule a big
142 * hammmer to get out of the RISC PAUSED state.
144 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
145 RD_REG_WORD(®->hccr);
147 ha->isp_ops.fw_dump(ha, 1);
148 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
150 } else if ((stat & HSR_RISC_INT) == 0)
153 switch (stat & 0xff) {
158 qla2x00_mbx_completion(ha, MSW(stat));
159 status |= MBX_INTERRUPT;
161 /* Release mailbox registers. */
162 WRT_REG_WORD(®->semaphore, 0);
166 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
167 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
168 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
169 qla2x00_async_event(ha, mb);
172 qla2x00_process_response_queue(ha);
175 mb[0] = MBA_CMPLT_1_16BIT;
177 qla2x00_async_event(ha, mb);
180 mb[0] = MBA_SCSI_COMPLETION;
182 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
183 qla2x00_async_event(ha, mb);
186 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
188 ha->host_no, stat & 0xff));
191 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
192 RD_REG_WORD_RELAXED(®->hccr);
194 spin_unlock_irqrestore(&ha->hardware_lock, flags);
196 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
197 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
198 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
199 up(&ha->mbx_intr_sem);
202 return (IRQ_HANDLED);
206 * qla2x00_mbx_completion() - Process mailbox command completions.
207 * @ha: SCSI driver HA context
208 * @mb0: Mailbox0 register
211 qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
214 uint16_t __iomem *wptr;
215 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
217 /* Load return mailbox registers. */
218 ha->flags.mbox_int = 1;
219 ha->mailbox_out[0] = mb0;
220 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
222 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
223 if (IS_QLA2200(ha) && cnt == 8)
224 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
225 if (cnt == 4 || cnt == 5)
226 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
228 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
234 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
235 __func__, ha->host_no, ha->mcp->mb[0]));
237 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
238 __func__, ha->host_no));
243 * qla2x00_async_event() - Process aynchronous events.
244 * @ha: SCSI driver HA context
245 * @mb: Mailbox registers (0 - 3)
248 qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
251 static char *link_speeds[5] = { "1", "2", "?", "4", "10" };
256 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
257 uint32_t rscn_entry, host_pid;
258 uint8_t rscn_queue_index;
260 /* Setup to process RIO completion. */
263 case MBA_SCSI_COMPLETION:
264 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
267 case MBA_CMPLT_1_16BIT:
270 mb[0] = MBA_SCSI_COMPLETION;
272 case MBA_CMPLT_2_16BIT:
276 mb[0] = MBA_SCSI_COMPLETION;
278 case MBA_CMPLT_3_16BIT:
283 mb[0] = MBA_SCSI_COMPLETION;
285 case MBA_CMPLT_4_16BIT:
289 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
291 mb[0] = MBA_SCSI_COMPLETION;
293 case MBA_CMPLT_5_16BIT:
297 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
298 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
300 mb[0] = MBA_SCSI_COMPLETION;
302 case MBA_CMPLT_2_32BIT:
303 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
304 handles[1] = le32_to_cpu(
305 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
306 RD_MAILBOX_REG(ha, reg, 6));
308 mb[0] = MBA_SCSI_COMPLETION;
315 case MBA_SCSI_COMPLETION: /* Fast Post */
316 if (!ha->flags.online)
319 for (cnt = 0; cnt < handle_cnt; cnt++)
320 qla2x00_process_completed_request(ha, handles[cnt]);
323 case MBA_RESET: /* Reset */
324 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
326 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
329 case MBA_SYSTEM_ERR: /* System Error */
330 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
331 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
332 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
334 qla_printk(KERN_INFO, ha,
335 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
336 mb[1], mb[2], mb[3]);
338 ha->isp_ops.fw_dump(ha, 1);
340 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
341 if (mb[1] == 0 && mb[2] == 0) {
342 qla_printk(KERN_ERR, ha,
343 "Unrecoverable Hardware Error: adapter "
344 "marked OFFLINE!\n");
345 ha->flags.online = 0;
347 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
348 } else if (mb[1] == 0) {
349 qla_printk(KERN_INFO, ha,
350 "Unrecoverable Hardware Error: adapter marked "
352 ha->flags.online = 0;
354 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
357 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
358 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
360 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
362 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
365 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
366 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
368 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
370 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
373 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
374 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
378 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
379 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
381 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
383 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
384 atomic_set(&ha->loop_state, LOOP_DOWN);
385 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
386 qla2x00_mark_all_devices_lost(ha, 1);
389 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
391 ha->flags.management_server_logged_in = 0;
394 case MBA_LOOP_UP: /* Loop Up Event */
395 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
396 link_speed = link_speeds[0];
397 ha->link_data_rate = PORT_SPEED_1GB;
399 link_speed = link_speeds[LS_UNKNOWN];
401 link_speed = link_speeds[mb[1]];
402 ha->link_data_rate = mb[1];
405 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
406 ha->host_no, link_speed));
407 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
410 ha->flags.management_server_logged_in = 0;
413 case MBA_LOOP_DOWN: /* Loop Down Event */
414 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
415 ha->host_no, mb[1]));
416 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]);
418 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
419 atomic_set(&ha->loop_state, LOOP_DOWN);
420 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
421 ha->device_flags |= DFLG_NO_CABLE;
422 qla2x00_mark_all_devices_lost(ha, 1);
425 ha->flags.management_server_logged_in = 0;
426 ha->link_data_rate = PORT_SPEED_UNKNOWN;
428 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
431 case MBA_LIP_RESET: /* LIP reset occurred */
432 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
433 ha->host_no, mb[1]));
434 qla_printk(KERN_INFO, ha,
435 "LIP reset occured (%x).\n", mb[1]);
437 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
438 atomic_set(&ha->loop_state, LOOP_DOWN);
439 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
440 qla2x00_mark_all_devices_lost(ha, 1);
443 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
445 ha->operating_mode = LOOP;
446 ha->flags.management_server_logged_in = 0;
449 case MBA_POINT_TO_POINT: /* Point-to-Point */
453 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
457 * Until there's a transition from loop down to loop up, treat
458 * this as loop down only.
460 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
461 atomic_set(&ha->loop_state, LOOP_DOWN);
462 if (!atomic_read(&ha->loop_down_timer))
463 atomic_set(&ha->loop_down_timer,
465 qla2x00_mark_all_devices_lost(ha, 1);
468 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
469 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
471 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
473 ha->flags.gpsc_supported = 1;
476 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
480 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
483 qla_printk(KERN_INFO, ha,
484 "Configuration change detected: value=%x.\n", mb[1]);
486 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
487 atomic_set(&ha->loop_state, LOOP_DOWN);
488 if (!atomic_read(&ha->loop_down_timer))
489 atomic_set(&ha->loop_down_timer,
491 qla2x00_mark_all_devices_lost(ha, 1);
494 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
495 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
498 case MBA_PORT_UPDATE: /* Port database update */
500 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
501 * event etc. earlier indicating loop is down) then process
502 * it. Otherwise ignore it and Wait for RSCN to come in.
504 atomic_set(&ha->loop_down_timer, 0);
505 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
506 atomic_read(&ha->loop_state) != LOOP_DEAD) {
507 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
508 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
513 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
515 DEBUG(printk(KERN_INFO
516 "scsi(%ld): Port database changed %04x %04x %04x.\n",
517 ha->host_no, mb[1], mb[2], mb[3]));
520 * Mark all devices as missing so we will login again.
522 atomic_set(&ha->loop_state, LOOP_UP);
524 qla2x00_mark_all_devices_lost(ha, 1);
526 ha->flags.rscn_queue_overflow = 1;
528 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
529 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
532 case MBA_RSCN_UPDATE: /* State Change Registration */
533 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
535 DEBUG(printk(KERN_INFO
536 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
537 ha->host_no, mb[1], mb[2]));
539 rscn_entry = (mb[1] << 16) | mb[2];
540 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
542 if (rscn_entry == host_pid) {
543 DEBUG(printk(KERN_INFO
544 "scsi(%ld): Ignoring RSCN update to local host "
546 ha->host_no, host_pid));
550 rscn_queue_index = ha->rscn_in_ptr + 1;
551 if (rscn_queue_index == MAX_RSCN_COUNT)
552 rscn_queue_index = 0;
553 if (rscn_queue_index != ha->rscn_out_ptr) {
554 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
555 ha->rscn_in_ptr = rscn_queue_index;
557 ha->flags.rscn_queue_overflow = 1;
560 atomic_set(&ha->loop_state, LOOP_UPDATE);
561 atomic_set(&ha->loop_down_timer, 0);
562 ha->flags.management_server_logged_in = 0;
564 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
565 set_bit(RSCN_UPDATE, &ha->dpc_flags);
568 /* case MBA_RIO_RESPONSE: */
569 case MBA_ZIO_RESPONSE:
570 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
572 DEBUG(printk(KERN_INFO
573 "scsi(%ld): [R|Z]IO update completion.\n",
576 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
577 qla24xx_process_response_queue(ha);
579 qla2x00_process_response_queue(ha);
582 case MBA_DISCARD_RND_FRAME:
583 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
584 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
587 case MBA_TRACE_NOTIFICATION:
588 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
589 ha->host_no, mb[1], mb[2]));
595 qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
597 fc_port_t *fcport = data;
599 if (fcport->ha->max_q_depth <= sdev->queue_depth)
602 if (sdev->ordered_tags)
603 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
604 sdev->queue_depth + 1);
606 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
607 sdev->queue_depth + 1);
609 fcport->last_ramp_up = jiffies;
611 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
612 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
613 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
618 qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
620 fc_port_t *fcport = data;
622 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
625 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
626 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
627 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
632 qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
635 struct scsi_device *sdev;
637 sdev = sp->cmd->device;
638 if (sdev->queue_depth >= ha->max_q_depth)
642 if (time_before(jiffies,
643 fcport->last_ramp_up + ql2xqfullrampup * HZ))
645 if (time_before(jiffies,
646 fcport->last_queue_full + ql2xqfullrampup * HZ))
649 starget_for_each_device(sdev->sdev_target, fcport,
650 qla2x00_adjust_sdev_qdepth_up);
654 * qla2x00_process_completed_request() - Process a Fast Post response.
655 * @ha: SCSI driver HA context
659 qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
663 /* Validate handle. */
664 if (index >= MAX_OUTSTANDING_COMMANDS) {
665 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
666 ha->host_no, index));
667 qla_printk(KERN_WARNING, ha,
668 "Invalid SCSI completion handle %d.\n", index);
670 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
674 sp = ha->outstanding_cmds[index];
676 /* Free outstanding command slot. */
677 ha->outstanding_cmds[index] = NULL;
679 CMD_COMPL_STATUS(sp->cmd) = 0L;
680 CMD_SCSI_STATUS(sp->cmd) = 0L;
682 /* Save ISP completion status */
683 sp->cmd->result = DID_OK << 16;
685 qla2x00_ramp_up_queue_depth(ha, sp);
686 qla2x00_sp_compl(ha, sp);
688 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
690 qla_printk(KERN_WARNING, ha,
691 "Invalid ISP SCSI completion handle\n");
693 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
698 * qla2x00_process_response_queue() - Process response queue entries.
699 * @ha: SCSI driver HA context
702 qla2x00_process_response_queue(struct scsi_qla_host *ha)
704 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
709 if (!ha->flags.online)
712 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
713 pkt = (sts_entry_t *)ha->response_ring_ptr;
715 ha->rsp_ring_index++;
716 if (ha->rsp_ring_index == ha->response_q_length) {
717 ha->rsp_ring_index = 0;
718 ha->response_ring_ptr = ha->response_ring;
720 ha->response_ring_ptr++;
723 if (pkt->entry_status != 0) {
724 DEBUG3(printk(KERN_INFO
725 "scsi(%ld): Process error entry.\n", ha->host_no));
727 qla2x00_error_entry(ha, pkt);
728 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
733 switch (pkt->entry_type) {
735 qla2x00_status_entry(ha, pkt);
738 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
739 for (cnt = 0; cnt < handle_cnt; cnt++) {
740 qla2x00_process_completed_request(ha,
741 ((sts21_entry_t *)pkt)->handle[cnt]);
745 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
746 for (cnt = 0; cnt < handle_cnt; cnt++) {
747 qla2x00_process_completed_request(ha,
748 ((sts22_entry_t *)pkt)->handle[cnt]);
751 case STATUS_CONT_TYPE:
752 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
755 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
758 /* Type Not Supported. */
759 DEBUG4(printk(KERN_WARNING
760 "scsi(%ld): Received unknown response pkt type %x "
761 "entry status=%x.\n",
762 ha->host_no, pkt->entry_type, pkt->entry_status));
765 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
769 /* Adjust ring index */
770 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
774 * qla2x00_status_entry() - Process a Status IOCB entry.
775 * @ha: SCSI driver HA context
776 * @pkt: Entry pointer
779 qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
783 struct scsi_cmnd *cp;
785 struct sts_entry_24xx *sts24;
786 uint16_t comp_status;
787 uint16_t scsi_status;
788 uint8_t lscsi_status;
790 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
791 uint8_t *rsp_info, *sense_data;
793 sts = (sts_entry_t *) pkt;
794 sts24 = (struct sts_entry_24xx *) pkt;
795 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
796 comp_status = le16_to_cpu(sts24->comp_status);
797 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
799 comp_status = le16_to_cpu(sts->comp_status);
800 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
803 /* Fast path completion. */
804 if (comp_status == CS_COMPLETE && scsi_status == 0) {
805 qla2x00_process_completed_request(ha, sts->handle);
810 /* Validate handle. */
811 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
812 sp = ha->outstanding_cmds[sts->handle];
813 ha->outstanding_cmds[sts->handle] = NULL;
818 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
820 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
822 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
823 qla2xxx_wake_dpc(ha);
828 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
829 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
830 qla_printk(KERN_WARNING, ha,
831 "Command is NULL: already returned to OS (sp=%p)\n", sp);
836 lscsi_status = scsi_status & STATUS_MASK;
837 CMD_ENTRY_STATUS(cp) = sts->entry_status;
838 CMD_COMPL_STATUS(cp) = comp_status;
839 CMD_SCSI_STATUS(cp) = scsi_status;
843 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
844 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
845 sense_len = le32_to_cpu(sts24->sense_len);
846 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
847 resid_len = le32_to_cpu(sts24->rsp_residual_count);
848 fw_resid_len = le32_to_cpu(sts24->residual_len);
849 rsp_info = sts24->data;
850 sense_data = sts24->data;
851 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
853 sense_len = le16_to_cpu(sts->req_sense_length);
854 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
855 resid_len = le32_to_cpu(sts->residual_length);
856 rsp_info = sts->rsp_info;
857 sense_data = sts->req_sense_data;
860 /* Check for any FCP transport errors. */
861 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
862 /* Sense data lies beyond any FCP RESPONSE data. */
863 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
864 sense_data += rsp_info_len;
865 if (rsp_info_len > 3 && rsp_info[3]) {
866 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
867 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
868 "retrying command\n", ha->host_no,
869 cp->device->channel, cp->device->id,
870 cp->device->lun, rsp_info_len, rsp_info[0],
871 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
872 rsp_info[5], rsp_info[6], rsp_info[7]));
874 cp->result = DID_BUS_BUSY << 16;
875 qla2x00_sp_compl(ha, sp);
881 * Based on Host and scsi status generate status code for Linux
883 switch (comp_status) {
886 if (scsi_status == 0) {
887 cp->result = DID_OK << 16;
890 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
893 CMD_RESID_LEN(cp) = resid;
896 ((unsigned)(cp->request_bufflen - resid) <
898 qla_printk(KERN_INFO, ha,
899 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
900 "detected (%x of %x bytes)...returning "
901 "error status.\n", ha->host_no,
902 cp->device->channel, cp->device->id,
903 cp->device->lun, resid,
904 cp->request_bufflen);
906 cp->result = DID_ERROR << 16;
910 cp->result = DID_OK << 16 | lscsi_status;
912 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
913 DEBUG2(printk(KERN_INFO
914 "scsi(%ld): QUEUE FULL status detected "
915 "0x%x-0x%x.\n", ha->host_no, comp_status,
918 /* Adjust queue depth for all luns on the port. */
919 fcport->last_queue_full = jiffies;
920 starget_for_each_device(cp->device->sdev_target,
921 fcport, qla2x00_adjust_sdev_qdepth_down);
924 if (lscsi_status != SS_CHECK_CONDITION)
927 /* Copy Sense Data into sense buffer. */
928 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
930 if (!(scsi_status & SS_SENSE_LEN_VALID))
933 if (sense_len >= sizeof(cp->sense_buffer))
934 sense_len = sizeof(cp->sense_buffer);
936 CMD_ACTUAL_SNSLEN(cp) = sense_len;
937 sp->request_sense_length = sense_len;
938 sp->request_sense_ptr = cp->sense_buffer;
940 if (sp->request_sense_length > 32)
943 memcpy(cp->sense_buffer, sense_data, sense_len);
945 sp->request_sense_ptr += sense_len;
946 sp->request_sense_length -= sense_len;
947 if (sp->request_sense_length != 0)
950 DEBUG5(printk("%s(): Check condition Sense data, "
951 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__,
952 ha->host_no, cp->device->channel, cp->device->id,
953 cp->device->lun, cp, cp->serial_number));
955 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
956 CMD_ACTUAL_SNSLEN(cp)));
959 case CS_DATA_UNDERRUN:
961 /* Use F/W calculated residual length. */
962 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
963 resid = fw_resid_len;
965 if (scsi_status & SS_RESIDUAL_UNDER) {
967 CMD_RESID_LEN(cp) = resid;
969 DEBUG2(printk(KERN_INFO
970 "scsi(%ld:%d:%d) UNDERRUN status detected "
971 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
972 "os_underflow=0x%x\n", ha->host_no,
973 cp->device->id, cp->device->lun, comp_status,
974 scsi_status, resid_len, resid, cp->cmnd[0],
980 * Check to see if SCSI Status is non zero. If so report SCSI
983 if (lscsi_status != 0) {
984 cp->result = DID_OK << 16 | lscsi_status;
986 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
987 DEBUG2(printk(KERN_INFO
988 "scsi(%ld): QUEUE FULL status detected "
989 "0x%x-0x%x.\n", ha->host_no, comp_status,
993 * Adjust queue depth for all luns on the
996 fcport->last_queue_full = jiffies;
997 starget_for_each_device(
998 cp->device->sdev_target, fcport,
999 qla2x00_adjust_sdev_qdepth_down);
1002 if (lscsi_status != SS_CHECK_CONDITION)
1005 /* Copy Sense Data into sense buffer */
1006 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
1008 if (!(scsi_status & SS_SENSE_LEN_VALID))
1011 if (sense_len >= sizeof(cp->sense_buffer))
1012 sense_len = sizeof(cp->sense_buffer);
1014 CMD_ACTUAL_SNSLEN(cp) = sense_len;
1015 sp->request_sense_length = sense_len;
1016 sp->request_sense_ptr = cp->sense_buffer;
1018 if (sp->request_sense_length > 32)
1021 memcpy(cp->sense_buffer, sense_data, sense_len);
1023 sp->request_sense_ptr += sense_len;
1024 sp->request_sense_length -= sense_len;
1025 if (sp->request_sense_length != 0)
1026 ha->status_srb = sp;
1028 DEBUG5(printk("%s(): Check condition Sense data, "
1029 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
1030 __func__, ha->host_no, cp->device->channel,
1031 cp->device->id, cp->device->lun, cp,
1032 cp->serial_number));
1035 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1036 CMD_ACTUAL_SNSLEN(cp)));
1039 * If RISC reports underrun and target does not report
1040 * it then we must have a lost frame, so tell upper
1041 * layer to retry it by reporting a bus busy.
1043 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1044 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1045 "frame(s) detected (%x of %x bytes)..."
1046 "retrying command.\n", ha->host_no,
1047 cp->device->channel, cp->device->id,
1048 cp->device->lun, resid,
1049 cp->request_bufflen));
1051 cp->result = DID_BUS_BUSY << 16;
1055 /* Handle mid-layer underflow */
1056 if ((unsigned)(cp->request_bufflen - 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", ha->host_no,
1062 cp->device->channel, cp->device->id,
1063 cp->device->lun, resid,
1064 cp->request_bufflen);
1066 cp->result = DID_ERROR << 16;
1070 /* Everybody online, looking good... */
1071 cp->result = DID_OK << 16;
1075 case CS_DATA_OVERRUN:
1076 DEBUG2(printk(KERN_INFO
1077 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1078 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1080 DEBUG2(printk(KERN_INFO
1081 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1082 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1083 cp->cmnd[4], cp->cmnd[5]));
1084 DEBUG2(printk(KERN_INFO
1085 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1087 cp->serial_number, cp->request_bufflen, resid_len));
1089 cp->result = DID_ERROR << 16;
1092 case CS_PORT_LOGGED_OUT:
1093 case CS_PORT_CONFIG_CHG:
1096 case CS_PORT_UNAVAILABLE:
1098 * If the port is in Target Down state, return all IOs for this
1099 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1102 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1103 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1104 ha->host_no, cp->device->id, cp->device->lun,
1105 cp->serial_number, comp_status,
1106 atomic_read(&fcport->state)));
1108 cp->result = DID_BUS_BUSY << 16;
1109 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1110 qla2x00_mark_device_lost(ha, fcport, 1, 1);
1115 DEBUG2(printk(KERN_INFO
1116 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1117 ha->host_no, comp_status, scsi_status));
1119 cp->result = DID_RESET << 16;
1124 * hv2.19.12 - DID_ABORT does not retry the request if we
1125 * aborted this request then abort otherwise it must be a
1128 DEBUG2(printk(KERN_INFO
1129 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1130 ha->host_no, comp_status, scsi_status));
1132 cp->result = DID_RESET << 16;
1136 cp->result = DID_BUS_BUSY << 16;
1138 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1139 DEBUG2(printk(KERN_INFO
1140 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1141 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1142 cp->device->id, cp->device->lun, comp_status,
1146 DEBUG2(printk(KERN_INFO
1147 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1148 "sflags=%x.\n", ha->host_no, cp->device->channel,
1149 cp->device->id, cp->device->lun, comp_status, scsi_status,
1150 le16_to_cpu(sts->status_flags)));
1152 /* Check to see if logout occurred. */
1153 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
1154 qla2x00_mark_device_lost(ha, fcport, 1, 1);
1158 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1159 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
1160 qla_printk(KERN_INFO, ha,
1161 "Unknown status detected 0x%x-0x%x.\n",
1162 comp_status, scsi_status);
1164 cp->result = DID_ERROR << 16;
1168 /* Place command on done queue. */
1169 if (ha->status_srb == NULL)
1170 qla2x00_sp_compl(ha, sp);
1174 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1175 * @ha: SCSI driver HA context
1176 * @pkt: Entry pointer
1178 * Extended sense data.
1181 qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1183 uint8_t sense_sz = 0;
1184 srb_t *sp = ha->status_srb;
1185 struct scsi_cmnd *cp;
1187 if (sp != NULL && sp->request_sense_length != 0) {
1190 DEBUG2(printk("%s(): Cmd already returned back to OS "
1191 "sp=%p.\n", __func__, sp));
1192 qla_printk(KERN_INFO, ha,
1193 "cmd is NULL: already returned to OS (sp=%p)\n",
1196 ha->status_srb = NULL;
1200 if (sp->request_sense_length > sizeof(pkt->data)) {
1201 sense_sz = sizeof(pkt->data);
1203 sense_sz = sp->request_sense_length;
1206 /* Move sense data. */
1207 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
1208 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
1209 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1210 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1212 sp->request_sense_ptr += sense_sz;
1213 sp->request_sense_length -= sense_sz;
1215 /* Place command on done queue. */
1216 if (sp->request_sense_length == 0) {
1217 ha->status_srb = NULL;
1218 qla2x00_sp_compl(ha, sp);
1224 * qla2x00_error_entry() - Process an error entry.
1225 * @ha: SCSI driver HA context
1226 * @pkt: Entry pointer
1229 qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
1233 #if defined(QL_DEBUG_LEVEL_2)
1234 if (pkt->entry_status & RF_INV_E_ORDER)
1235 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1236 else if (pkt->entry_status & RF_INV_E_COUNT)
1237 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1238 else if (pkt->entry_status & RF_INV_E_PARAM)
1239 qla_printk(KERN_ERR, ha,
1240 "%s: Invalid Entry Parameter\n", __func__);
1241 else if (pkt->entry_status & RF_INV_E_TYPE)
1242 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1243 else if (pkt->entry_status & RF_BUSY)
1244 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1246 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1249 /* Validate handle. */
1250 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1251 sp = ha->outstanding_cmds[pkt->handle];
1256 /* Free outstanding command slot. */
1257 ha->outstanding_cmds[pkt->handle] = NULL;
1259 /* Bad payload or header */
1260 if (pkt->entry_status &
1261 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1262 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1263 sp->cmd->result = DID_ERROR << 16;
1264 } else if (pkt->entry_status & RF_BUSY) {
1265 sp->cmd->result = DID_BUS_BUSY << 16;
1267 sp->cmd->result = DID_ERROR << 16;
1269 qla2x00_sp_compl(ha, sp);
1271 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1272 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
1273 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1275 qla_printk(KERN_WARNING, ha,
1276 "Error entry - invalid handle\n");
1278 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1279 qla2xxx_wake_dpc(ha);
1284 * qla2x00_ms_entry() - Process a Management Server entry.
1285 * @ha: SCSI driver HA context
1286 * @index: Response queue out pointer
1289 qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
1293 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1294 __func__, ha->host_no, pkt, pkt->handle1));
1296 /* Validate handle. */
1297 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1298 sp = ha->outstanding_cmds[pkt->handle1];
1303 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1305 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1307 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1311 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1312 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1314 /* Free outstanding command slot. */
1315 ha->outstanding_cmds[pkt->handle1] = NULL;
1317 qla2x00_sp_compl(ha, sp);
1322 * qla24xx_mbx_completion() - Process mailbox command completions.
1323 * @ha: SCSI driver HA context
1324 * @mb0: Mailbox0 register
1327 qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1330 uint16_t __iomem *wptr;
1331 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1333 /* Load return mailbox registers. */
1334 ha->flags.mbox_int = 1;
1335 ha->mailbox_out[0] = mb0;
1336 wptr = (uint16_t __iomem *)®->mailbox1;
1338 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1339 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1344 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1345 __func__, ha->host_no, ha->mcp->mb[0]));
1347 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1348 __func__, ha->host_no));
1353 * qla24xx_process_response_queue() - Process response queue entries.
1354 * @ha: SCSI driver HA context
1357 qla24xx_process_response_queue(struct scsi_qla_host *ha)
1359 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1360 struct sts_entry_24xx *pkt;
1362 if (!ha->flags.online)
1365 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1366 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1368 ha->rsp_ring_index++;
1369 if (ha->rsp_ring_index == ha->response_q_length) {
1370 ha->rsp_ring_index = 0;
1371 ha->response_ring_ptr = ha->response_ring;
1373 ha->response_ring_ptr++;
1376 if (pkt->entry_status != 0) {
1377 DEBUG3(printk(KERN_INFO
1378 "scsi(%ld): Process error entry.\n", ha->host_no));
1380 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1381 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1386 switch (pkt->entry_type) {
1388 qla2x00_status_entry(ha, pkt);
1390 case STATUS_CONT_TYPE:
1391 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1394 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1397 /* Type Not Supported. */
1398 DEBUG4(printk(KERN_WARNING
1399 "scsi(%ld): Received unknown response pkt type %x "
1400 "entry status=%x.\n",
1401 ha->host_no, pkt->entry_type, pkt->entry_status));
1404 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1408 /* Adjust ring index */
1409 WRT_REG_DWORD(®->rsp_q_out, ha->rsp_ring_index);
1413 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1415 * @dev_id: SCSI driver HA context
1417 * Called by system whenever the host adapter generates an interrupt.
1419 * Returns handled flag.
1422 qla24xx_intr_handler(int irq, void *dev_id)
1424 scsi_qla_host_t *ha;
1425 struct device_reg_24xx __iomem *reg;
1427 unsigned long flags;
1433 ha = (scsi_qla_host_t *) dev_id;
1436 "%s(): NULL host pointer\n", __func__);
1440 reg = &ha->iobase->isp24;
1443 spin_lock_irqsave(&ha->hardware_lock, flags);
1444 for (iter = 50; iter--; ) {
1445 stat = RD_REG_DWORD(®->host_status);
1446 if (stat & HSRX_RISC_PAUSED) {
1447 hccr = RD_REG_DWORD(®->hccr);
1449 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1450 "Dumping firmware!\n", hccr);
1451 ha->isp_ops.fw_dump(ha, 1);
1452 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1454 } else if ((stat & HSRX_RISC_INT) == 0)
1457 switch (stat & 0xff) {
1462 qla24xx_mbx_completion(ha, MSW(stat));
1463 status |= MBX_INTERRUPT;
1468 mb[1] = RD_REG_WORD(®->mailbox1);
1469 mb[2] = RD_REG_WORD(®->mailbox2);
1470 mb[3] = RD_REG_WORD(®->mailbox3);
1471 qla2x00_async_event(ha, mb);
1474 qla24xx_process_response_queue(ha);
1477 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1479 ha->host_no, stat & 0xff));
1482 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1483 RD_REG_DWORD_RELAXED(®->hccr);
1485 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1487 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1488 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1489 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1490 up(&ha->mbx_intr_sem);
1497 * qla24xx_ms_entry() - Process a Management Server entry.
1498 * @ha: SCSI driver HA context
1499 * @index: Response queue out pointer
1502 qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1506 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1507 __func__, ha->host_no, pkt, pkt->handle));
1509 DEBUG9(printk("%s: ct pkt dump:\n", __func__));
1510 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx)));
1512 /* Validate handle. */
1513 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1514 sp = ha->outstanding_cmds[pkt->handle];
1519 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1521 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1523 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1526 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1530 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1531 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1533 /* Free outstanding command slot. */
1534 ha->outstanding_cmds[pkt->handle] = NULL;
1536 qla2x00_sp_compl(ha, sp);
1540 qla24xx_msix_rsp_q(int irq, void *dev_id)
1542 scsi_qla_host_t *ha;
1543 struct device_reg_24xx __iomem *reg;
1544 unsigned long flags;
1547 reg = &ha->iobase->isp24;
1549 spin_lock_irqsave(&ha->hardware_lock, flags);
1551 qla24xx_process_response_queue(ha);
1553 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1554 RD_REG_DWORD_RELAXED(®->hccr);
1556 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1562 qla24xx_msix_default(int irq, void *dev_id)
1564 scsi_qla_host_t *ha;
1565 struct device_reg_24xx __iomem *reg;
1567 unsigned long flags;
1574 reg = &ha->iobase->isp24;
1577 spin_lock_irqsave(&ha->hardware_lock, flags);
1578 for (iter = 50; iter--; ) {
1579 stat = RD_REG_DWORD(®->host_status);
1580 if (stat & HSRX_RISC_PAUSED) {
1581 hccr = RD_REG_DWORD(®->hccr);
1583 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1584 "Dumping firmware!\n", hccr);
1585 ha->isp_ops.fw_dump(ha, 1);
1586 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1588 } else if ((stat & HSRX_RISC_INT) == 0)
1591 switch (stat & 0xff) {
1596 qla24xx_mbx_completion(ha, MSW(stat));
1597 status |= MBX_INTERRUPT;
1602 mb[1] = RD_REG_WORD(®->mailbox1);
1603 mb[2] = RD_REG_WORD(®->mailbox2);
1604 mb[3] = RD_REG_WORD(®->mailbox3);
1605 qla2x00_async_event(ha, mb);
1608 qla24xx_process_response_queue(ha);
1611 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1613 ha->host_no, stat & 0xff));
1616 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
1617 RD_REG_DWORD_RELAXED(®->hccr);
1619 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1621 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1622 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1623 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1624 up(&ha->mbx_intr_sem);
1630 /* Interrupt handling helpers. */
1632 struct qla_init_msix_entry {
1636 irqreturn_t (*handler)(int, void *);
1639 static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1640 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1641 "qla2xxx (default)", qla24xx_msix_default },
1643 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1644 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1648 qla24xx_disable_msix(scsi_qla_host_t *ha)
1651 struct qla_msix_entry *qentry;
1653 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1654 qentry = &ha->msix_entries[imsix_entries[i].index];
1655 if (qentry->have_irq)
1656 free_irq(qentry->msix_vector, ha);
1658 pci_disable_msix(ha->pdev);
1662 qla24xx_enable_msix(scsi_qla_host_t *ha)
1665 struct msix_entry entries[QLA_MSIX_ENTRIES];
1666 struct qla_msix_entry *qentry;
1668 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1669 entries[i].entry = imsix_entries[i].entry;
1671 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1673 qla_printk(KERN_WARNING, ha,
1674 "MSI-X: Failed to enable support -- %d/%d\n",
1675 QLA_MSIX_ENTRIES, ret);
1678 ha->flags.msix_enabled = 1;
1680 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1681 qentry = &ha->msix_entries[imsix_entries[i].index];
1682 qentry->msix_vector = entries[i].vector;
1683 qentry->msix_entry = entries[i].entry;
1684 qentry->have_irq = 0;
1685 ret = request_irq(qentry->msix_vector,
1686 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1688 qla_printk(KERN_WARNING, ha,
1689 "MSI-X: Unable to register handler -- %x/%d.\n",
1690 imsix_entries[i].index, ret);
1691 qla24xx_disable_msix(ha);
1694 qentry->have_irq = 1;
1702 qla2x00_request_irqs(scsi_qla_host_t *ha)
1706 /* If possible, enable MSI-X. */
1707 if (!IS_QLA2432(ha))
1710 if (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1711 !QLA_MSIX_FW_MODE_1(ha->fw_attributes)) {
1712 DEBUG2(qla_printk(KERN_WARNING, ha,
1713 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1714 ha->chip_revision, ha->fw_attributes));
1719 ret = qla24xx_enable_msix(ha);
1721 DEBUG2(qla_printk(KERN_INFO, ha,
1722 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1723 ha->fw_attributes));
1726 qla_printk(KERN_WARNING, ha,
1727 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1730 if (!IS_QLA24XX(ha))
1733 ret = pci_enable_msi(ha->pdev);
1735 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1736 ha->flags.msi_enabled = 1;
1740 ret = request_irq(ha->pdev->irq, ha->isp_ops.intr_handler,
1741 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
1743 ha->flags.inta_enabled = 1;
1744 ha->host->irq = ha->pdev->irq;
1746 qla_printk(KERN_WARNING, ha,
1747 "Failed to reserve interrupt %d already in use.\n",
1755 qla2x00_free_irqs(scsi_qla_host_t *ha)
1758 if (ha->flags.msix_enabled)
1759 qla24xx_disable_msix(ha);
1760 else if (ha->flags.inta_enabled) {
1761 free_irq(ha->host->irq, ha);
1762 pci_disable_msi(ha->pdev);