2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 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 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
;
41 ha
= (scsi_qla_host_t
*) dev_id
;
44 "%s(): NULL host pointer\n", __func__
);
48 reg
= &ha
->iobase
->isp
;
51 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
52 for (iter
= 50; iter
--; ) {
53 hccr
= RD_REG_WORD(®
->hccr
);
54 if (hccr
& HCCR_RISC_PAUSE
) {
55 if (pci_channel_offline(ha
->pdev
))
59 * Issue a "HARD" reset in order for the RISC interrupt
60 * bit to be cleared. Schedule a big hammmer to get
61 * out of the RISC PAUSED state.
63 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
64 RD_REG_WORD(®
->hccr
);
66 ha
->isp_ops
->fw_dump(ha
, 1);
67 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
69 } else if ((RD_REG_WORD(®
->istatus
) & ISR_RISC_INT
) == 0)
72 if (RD_REG_WORD(®
->semaphore
) & BIT_0
) {
73 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
74 RD_REG_WORD(®
->hccr
);
76 /* Get mailbox data. */
77 mb
[0] = RD_MAILBOX_REG(ha
, reg
, 0);
78 if (mb
[0] > 0x3fff && mb
[0] < 0x8000) {
79 qla2x00_mbx_completion(ha
, mb
[0]);
80 status
|= MBX_INTERRUPT
;
81 } else if (mb
[0] > 0x7fff && mb
[0] < 0xc000) {
82 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
83 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
84 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
85 qla2x00_async_event(ha
, mb
);
88 DEBUG2(printk("scsi(%ld): Unrecognized "
89 "interrupt type (%d).\n",
92 /* Release mailbox registers. */
93 WRT_REG_WORD(®
->semaphore
, 0);
94 RD_REG_WORD(®
->semaphore
);
96 qla2x00_process_response_queue(ha
);
98 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
99 RD_REG_WORD(®
->hccr
);
102 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
104 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
105 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
106 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
107 up(&ha
->mbx_intr_sem
);
110 return (IRQ_HANDLED
);
114 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
116 * @dev_id: SCSI driver HA context
118 * Called by system whenever the host adapter generates an interrupt.
120 * Returns handled flag.
123 qla2300_intr_handler(int irq
, void *dev_id
)
126 struct device_reg_2xxx __iomem
*reg
;
134 ha
= (scsi_qla_host_t
*) dev_id
;
137 "%s(): NULL host pointer\n", __func__
);
141 reg
= &ha
->iobase
->isp
;
144 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
145 for (iter
= 50; iter
--; ) {
146 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
147 if (stat
& HSR_RISC_PAUSED
) {
148 if (pci_channel_offline(ha
->pdev
))
151 hccr
= RD_REG_WORD(®
->hccr
);
152 if (hccr
& (BIT_15
| BIT_13
| BIT_11
| BIT_8
))
153 qla_printk(KERN_INFO
, ha
, "Parity error -- "
154 "HCCR=%x, Dumping firmware!\n", hccr
);
156 qla_printk(KERN_INFO
, ha
, "RISC paused -- "
157 "HCCR=%x, Dumping firmware!\n", hccr
);
160 * Issue a "HARD" reset in order for the RISC
161 * interrupt bit to be cleared. Schedule a big
162 * hammmer to get out of the RISC PAUSED state.
164 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
165 RD_REG_WORD(®
->hccr
);
167 ha
->isp_ops
->fw_dump(ha
, 1);
168 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
170 } else if ((stat
& HSR_RISC_INT
) == 0)
173 switch (stat
& 0xff) {
178 qla2x00_mbx_completion(ha
, MSW(stat
));
179 status
|= MBX_INTERRUPT
;
181 /* Release mailbox registers. */
182 WRT_REG_WORD(®
->semaphore
, 0);
186 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
187 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
188 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
189 qla2x00_async_event(ha
, mb
);
192 qla2x00_process_response_queue(ha
);
195 mb
[0] = MBA_CMPLT_1_16BIT
;
197 qla2x00_async_event(ha
, mb
);
200 mb
[0] = MBA_SCSI_COMPLETION
;
202 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
203 qla2x00_async_event(ha
, mb
);
206 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
208 ha
->host_no
, stat
& 0xff));
211 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
212 RD_REG_WORD_RELAXED(®
->hccr
);
214 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
216 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
217 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
218 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
219 up(&ha
->mbx_intr_sem
);
222 return (IRQ_HANDLED
);
226 * qla2x00_mbx_completion() - Process mailbox command completions.
227 * @ha: SCSI driver HA context
228 * @mb0: Mailbox0 register
231 qla2x00_mbx_completion(scsi_qla_host_t
*ha
, uint16_t mb0
)
234 uint16_t __iomem
*wptr
;
235 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
237 /* Load return mailbox registers. */
238 ha
->flags
.mbox_int
= 1;
239 ha
->mailbox_out
[0] = mb0
;
240 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 1);
242 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
243 if (IS_QLA2200(ha
) && cnt
== 8)
244 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 8);
245 if (cnt
== 4 || cnt
== 5)
246 ha
->mailbox_out
[cnt
] = qla2x00_debounce_register(wptr
);
248 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
254 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
255 __func__
, ha
->host_no
, ha
->mcp
->mb
[0]));
257 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
258 __func__
, ha
->host_no
));
263 * qla2x00_async_event() - Process aynchronous events.
264 * @ha: SCSI driver HA context
265 * @mb: Mailbox registers (0 - 3)
268 qla2x00_async_event(scsi_qla_host_t
*ha
, uint16_t *mb
)
271 static char *link_speeds
[5] = { "1", "2", "?", "4", "8" };
276 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
277 uint32_t rscn_entry
, host_pid
;
278 uint8_t rscn_queue_index
;
280 /* Setup to process RIO completion. */
283 case MBA_SCSI_COMPLETION
:
284 handles
[0] = le32_to_cpu((uint32_t)((mb
[2] << 16) | mb
[1]));
287 case MBA_CMPLT_1_16BIT
:
290 mb
[0] = MBA_SCSI_COMPLETION
;
292 case MBA_CMPLT_2_16BIT
:
296 mb
[0] = MBA_SCSI_COMPLETION
;
298 case MBA_CMPLT_3_16BIT
:
303 mb
[0] = MBA_SCSI_COMPLETION
;
305 case MBA_CMPLT_4_16BIT
:
309 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
311 mb
[0] = MBA_SCSI_COMPLETION
;
313 case MBA_CMPLT_5_16BIT
:
317 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
318 handles
[4] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 7);
320 mb
[0] = MBA_SCSI_COMPLETION
;
322 case MBA_CMPLT_2_32BIT
:
323 handles
[0] = le32_to_cpu((uint32_t)((mb
[2] << 16) | mb
[1]));
324 handles
[1] = le32_to_cpu(
325 ((uint32_t)(RD_MAILBOX_REG(ha
, reg
, 7) << 16)) |
326 RD_MAILBOX_REG(ha
, reg
, 6));
328 mb
[0] = MBA_SCSI_COMPLETION
;
335 case MBA_SCSI_COMPLETION
: /* Fast Post */
336 if (!ha
->flags
.online
)
339 for (cnt
= 0; cnt
< handle_cnt
; cnt
++)
340 qla2x00_process_completed_request(ha
, handles
[cnt
]);
343 case MBA_RESET
: /* Reset */
344 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha
->host_no
));
346 set_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
349 case MBA_SYSTEM_ERR
: /* System Error */
350 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
351 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
352 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
354 qla_printk(KERN_INFO
, ha
,
355 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
356 mb
[1], mb
[2], mb
[3]);
358 ha
->isp_ops
->fw_dump(ha
, 1);
360 if (IS_FWI2_CAPABLE(ha
)) {
361 if (mb
[1] == 0 && mb
[2] == 0) {
362 qla_printk(KERN_ERR
, ha
,
363 "Unrecoverable Hardware Error: adapter "
364 "marked OFFLINE!\n");
365 ha
->flags
.online
= 0;
367 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
368 } else if (mb
[1] == 0) {
369 qla_printk(KERN_INFO
, ha
,
370 "Unrecoverable Hardware Error: adapter marked "
372 ha
->flags
.online
= 0;
374 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
377 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
378 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
380 qla_printk(KERN_WARNING
, ha
, "ISP Request Transfer Error.\n");
382 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
385 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
386 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
388 qla_printk(KERN_WARNING
, ha
, "ISP Response Transfer Error.\n");
390 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
393 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
394 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
398 case MBA_LIP_OCCURRED
: /* Loop Initialization Procedure */
399 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha
->host_no
,
401 qla_printk(KERN_INFO
, ha
, "LIP occured (%x).\n", mb
[1]);
403 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
404 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
405 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
406 qla2x00_mark_all_devices_lost(ha
, 1);
410 atomic_set(&ha
->vp_state
, VP_FAILED
);
411 fc_vport_set_state(ha
->fc_vport
, FC_VPORT_FAILED
);
414 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
416 ha
->flags
.management_server_logged_in
= 0;
419 case MBA_LOOP_UP
: /* Loop Up Event */
420 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
421 link_speed
= link_speeds
[0];
422 ha
->link_data_rate
= PORT_SPEED_1GB
;
424 link_speed
= link_speeds
[LS_UNKNOWN
];
426 link_speed
= link_speeds
[mb
[1]];
427 ha
->link_data_rate
= mb
[1];
430 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
431 ha
->host_no
, link_speed
));
432 qla_printk(KERN_INFO
, ha
, "LOOP UP detected (%s Gbps).\n",
435 ha
->flags
.management_server_logged_in
= 0;
438 case MBA_LOOP_DOWN
: /* Loop Down Event */
439 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
440 ha
->host_no
, mb
[1]));
441 qla_printk(KERN_INFO
, ha
, "LOOP DOWN detected (%x).\n", mb
[1]);
443 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
444 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
445 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
446 ha
->device_flags
|= DFLG_NO_CABLE
;
447 qla2x00_mark_all_devices_lost(ha
, 1);
451 atomic_set(&ha
->vp_state
, VP_FAILED
);
452 fc_vport_set_state(ha
->fc_vport
, FC_VPORT_FAILED
);
455 ha
->flags
.management_server_logged_in
= 0;
456 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
458 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
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;
484 case MBA_POINT_TO_POINT
: /* Point-to-Point */
488 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
492 * Until there's a transition from loop down to loop up, treat
493 * this as loop down only.
495 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
496 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
497 if (!atomic_read(&ha
->loop_down_timer
))
498 atomic_set(&ha
->loop_down_timer
,
500 qla2x00_mark_all_devices_lost(ha
, 1);
504 atomic_set(&ha
->vp_state
, VP_FAILED
);
505 fc_vport_set_state(ha
->fc_vport
, FC_VPORT_FAILED
);
508 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
))) {
509 set_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
511 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
513 ha
->flags
.gpsc_supported
= 1;
514 ha
->flags
.management_server_logged_in
= 0;
517 case MBA_CHG_IN_CONNECTION
: /* Change in connection mode */
521 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
524 qla_printk(KERN_INFO
, ha
,
525 "Configuration change detected: value=%x.\n", mb
[1]);
527 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
528 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
529 if (!atomic_read(&ha
->loop_down_timer
))
530 atomic_set(&ha
->loop_down_timer
,
532 qla2x00_mark_all_devices_lost(ha
, 1);
536 atomic_set(&ha
->vp_state
, VP_FAILED
);
537 fc_vport_set_state(ha
->fc_vport
, FC_VPORT_FAILED
);
540 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
541 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
544 case MBA_PORT_UPDATE
: /* Port database update */
546 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
547 * event etc. earlier indicating loop is down) then process
548 * it. Otherwise ignore it and Wait for RSCN to come in.
550 atomic_set(&ha
->loop_down_timer
, 0);
551 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
&&
552 atomic_read(&ha
->loop_state
) != LOOP_DEAD
) {
553 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
554 "ignored %04x/%04x/%04x.\n", ha
->host_no
, mb
[1],
559 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
561 DEBUG(printk(KERN_INFO
562 "scsi(%ld): Port database changed %04x %04x %04x.\n",
563 ha
->host_no
, mb
[1], mb
[2], mb
[3]));
566 * Mark all devices as missing so we will login again.
568 atomic_set(&ha
->loop_state
, LOOP_UP
);
570 qla2x00_mark_all_devices_lost(ha
, 1);
572 ha
->flags
.rscn_queue_overflow
= 1;
574 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
575 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
578 case MBA_RSCN_UPDATE
: /* State Change Registration */
579 /* Check if the Vport has issued a SCR */
580 if (ha
->parent
&& test_bit(VP_SCR_NEEDED
, &ha
->vp_flags
))
583 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
585 DEBUG(printk(KERN_INFO
586 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
587 ha
->host_no
, mb
[1], mb
[2]));
589 rscn_entry
= (mb
[1] << 16) | mb
[2];
590 host_pid
= (ha
->d_id
.b
.domain
<< 16) | (ha
->d_id
.b
.area
<< 8) |
592 if (rscn_entry
== host_pid
) {
593 DEBUG(printk(KERN_INFO
594 "scsi(%ld): Ignoring RSCN update to local host "
596 ha
->host_no
, host_pid
));
600 rscn_queue_index
= ha
->rscn_in_ptr
+ 1;
601 if (rscn_queue_index
== MAX_RSCN_COUNT
)
602 rscn_queue_index
= 0;
603 if (rscn_queue_index
!= ha
->rscn_out_ptr
) {
604 ha
->rscn_queue
[ha
->rscn_in_ptr
] = rscn_entry
;
605 ha
->rscn_in_ptr
= rscn_queue_index
;
607 ha
->flags
.rscn_queue_overflow
= 1;
610 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
611 atomic_set(&ha
->loop_down_timer
, 0);
612 ha
->flags
.management_server_logged_in
= 0;
614 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
615 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
618 /* case MBA_RIO_RESPONSE: */
619 case MBA_ZIO_RESPONSE
:
620 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
622 DEBUG(printk(KERN_INFO
623 "scsi(%ld): [R|Z]IO update completion.\n",
626 if (IS_FWI2_CAPABLE(ha
))
627 qla24xx_process_response_queue(ha
);
629 qla2x00_process_response_queue(ha
);
632 case MBA_DISCARD_RND_FRAME
:
633 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
634 "%04x.\n", ha
->host_no
, mb
[1], mb
[2], mb
[3]));
637 case MBA_TRACE_NOTIFICATION
:
638 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
639 ha
->host_no
, mb
[1], mb
[2]));
643 if (!ha
->parent
&& ha
->num_vhosts
)
644 qla2x00_alert_all_vps(ha
, mb
);
648 qla2x00_adjust_sdev_qdepth_up(struct scsi_device
*sdev
, void *data
)
650 fc_port_t
*fcport
= data
;
652 if (fcport
->ha
->max_q_depth
<= sdev
->queue_depth
)
655 if (sdev
->ordered_tags
)
656 scsi_adjust_queue_depth(sdev
, MSG_ORDERED_TAG
,
657 sdev
->queue_depth
+ 1);
659 scsi_adjust_queue_depth(sdev
, MSG_SIMPLE_TAG
,
660 sdev
->queue_depth
+ 1);
662 fcport
->last_ramp_up
= jiffies
;
664 DEBUG2(qla_printk(KERN_INFO
, fcport
->ha
,
665 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
666 fcport
->ha
->host_no
, sdev
->channel
, sdev
->id
, sdev
->lun
,
671 qla2x00_adjust_sdev_qdepth_down(struct scsi_device
*sdev
, void *data
)
673 fc_port_t
*fcport
= data
;
675 if (!scsi_track_queue_full(sdev
, sdev
->queue_depth
- 1))
678 DEBUG2(qla_printk(KERN_INFO
, fcport
->ha
,
679 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
680 fcport
->ha
->host_no
, sdev
->channel
, sdev
->id
, sdev
->lun
,
685 qla2x00_ramp_up_queue_depth(scsi_qla_host_t
*ha
, srb_t
*sp
)
688 struct scsi_device
*sdev
;
690 sdev
= sp
->cmd
->device
;
691 if (sdev
->queue_depth
>= ha
->max_q_depth
)
695 if (time_before(jiffies
,
696 fcport
->last_ramp_up
+ ql2xqfullrampup
* HZ
))
698 if (time_before(jiffies
,
699 fcport
->last_queue_full
+ ql2xqfullrampup
* HZ
))
702 starget_for_each_device(sdev
->sdev_target
, fcport
,
703 qla2x00_adjust_sdev_qdepth_up
);
707 * qla2x00_process_completed_request() - Process a Fast Post response.
708 * @ha: SCSI driver HA context
712 qla2x00_process_completed_request(struct scsi_qla_host
*ha
, uint32_t index
)
716 /* Validate handle. */
717 if (index
>= MAX_OUTSTANDING_COMMANDS
) {
718 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
719 ha
->host_no
, index
));
720 qla_printk(KERN_WARNING
, ha
,
721 "Invalid SCSI completion handle %d.\n", index
);
723 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
727 sp
= ha
->outstanding_cmds
[index
];
729 /* Free outstanding command slot. */
730 ha
->outstanding_cmds
[index
] = NULL
;
732 CMD_COMPL_STATUS(sp
->cmd
) = 0L;
733 CMD_SCSI_STATUS(sp
->cmd
) = 0L;
735 /* Save ISP completion status */
736 sp
->cmd
->result
= DID_OK
<< 16;
738 qla2x00_ramp_up_queue_depth(ha
, sp
);
739 qla2x00_sp_compl(ha
, sp
);
741 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
743 qla_printk(KERN_WARNING
, ha
,
744 "Invalid ISP SCSI completion handle\n");
746 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
751 * qla2x00_process_response_queue() - Process response queue entries.
752 * @ha: SCSI driver HA context
755 qla2x00_process_response_queue(struct scsi_qla_host
*ha
)
757 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
762 if (!ha
->flags
.online
)
765 while (ha
->response_ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
766 pkt
= (sts_entry_t
*)ha
->response_ring_ptr
;
768 ha
->rsp_ring_index
++;
769 if (ha
->rsp_ring_index
== ha
->response_q_length
) {
770 ha
->rsp_ring_index
= 0;
771 ha
->response_ring_ptr
= ha
->response_ring
;
773 ha
->response_ring_ptr
++;
776 if (pkt
->entry_status
!= 0) {
777 DEBUG3(printk(KERN_INFO
778 "scsi(%ld): Process error entry.\n", ha
->host_no
));
780 qla2x00_error_entry(ha
, pkt
);
781 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
786 switch (pkt
->entry_type
) {
788 qla2x00_status_entry(ha
, pkt
);
791 handle_cnt
= ((sts21_entry_t
*)pkt
)->handle_count
;
792 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
793 qla2x00_process_completed_request(ha
,
794 ((sts21_entry_t
*)pkt
)->handle
[cnt
]);
798 handle_cnt
= ((sts22_entry_t
*)pkt
)->handle_count
;
799 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
800 qla2x00_process_completed_request(ha
,
801 ((sts22_entry_t
*)pkt
)->handle
[cnt
]);
804 case STATUS_CONT_TYPE
:
805 qla2x00_status_cont_entry(ha
, (sts_cont_entry_t
*)pkt
);
808 qla2x00_ms_entry(ha
, (ms_iocb_entry_t
*)pkt
);
811 /* Type Not Supported. */
812 DEBUG4(printk(KERN_WARNING
813 "scsi(%ld): Received unknown response pkt type %x "
814 "entry status=%x.\n",
815 ha
->host_no
, pkt
->entry_type
, pkt
->entry_status
));
818 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
822 /* Adjust ring index */
823 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), ha
->rsp_ring_index
);
827 * qla2x00_status_entry() - Process a Status IOCB entry.
828 * @ha: SCSI driver HA context
829 * @pkt: Entry pointer
832 qla2x00_status_entry(scsi_qla_host_t
*ha
, void *pkt
)
836 struct scsi_cmnd
*cp
;
838 struct sts_entry_24xx
*sts24
;
839 uint16_t comp_status
;
840 uint16_t scsi_status
;
841 uint8_t lscsi_status
;
843 uint32_t sense_len
, rsp_info_len
, resid_len
, fw_resid_len
;
844 uint8_t *rsp_info
, *sense_data
;
846 sts
= (sts_entry_t
*) pkt
;
847 sts24
= (struct sts_entry_24xx
*) pkt
;
848 if (IS_FWI2_CAPABLE(ha
)) {
849 comp_status
= le16_to_cpu(sts24
->comp_status
);
850 scsi_status
= le16_to_cpu(sts24
->scsi_status
) & SS_MASK
;
852 comp_status
= le16_to_cpu(sts
->comp_status
);
853 scsi_status
= le16_to_cpu(sts
->scsi_status
) & SS_MASK
;
856 /* Fast path completion. */
857 if (comp_status
== CS_COMPLETE
&& scsi_status
== 0) {
858 qla2x00_process_completed_request(ha
, sts
->handle
);
863 /* Validate handle. */
864 if (sts
->handle
< MAX_OUTSTANDING_COMMANDS
) {
865 sp
= ha
->outstanding_cmds
[sts
->handle
];
866 ha
->outstanding_cmds
[sts
->handle
] = NULL
;
871 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
873 qla_printk(KERN_WARNING
, ha
, "Status Entry invalid handle.\n");
875 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
876 qla2xxx_wake_dpc(ha
);
881 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
882 "pkt->handle=%d sp=%p.\n", ha
->host_no
, sts
->handle
, sp
));
883 qla_printk(KERN_WARNING
, ha
,
884 "Command is NULL: already returned to OS (sp=%p)\n", sp
);
889 lscsi_status
= scsi_status
& STATUS_MASK
;
890 CMD_ENTRY_STATUS(cp
) = sts
->entry_status
;
891 CMD_COMPL_STATUS(cp
) = comp_status
;
892 CMD_SCSI_STATUS(cp
) = scsi_status
;
896 sense_len
= rsp_info_len
= resid_len
= fw_resid_len
= 0;
897 if (IS_FWI2_CAPABLE(ha
)) {
898 sense_len
= le32_to_cpu(sts24
->sense_len
);
899 rsp_info_len
= le32_to_cpu(sts24
->rsp_data_len
);
900 resid_len
= le32_to_cpu(sts24
->rsp_residual_count
);
901 fw_resid_len
= le32_to_cpu(sts24
->residual_len
);
902 rsp_info
= sts24
->data
;
903 sense_data
= sts24
->data
;
904 host_to_fcp_swap(sts24
->data
, sizeof(sts24
->data
));
906 sense_len
= le16_to_cpu(sts
->req_sense_length
);
907 rsp_info_len
= le16_to_cpu(sts
->rsp_info_len
);
908 resid_len
= le32_to_cpu(sts
->residual_length
);
909 rsp_info
= sts
->rsp_info
;
910 sense_data
= sts
->req_sense_data
;
913 /* Check for any FCP transport errors. */
914 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
) {
915 /* Sense data lies beyond any FCP RESPONSE data. */
916 if (IS_FWI2_CAPABLE(ha
))
917 sense_data
+= rsp_info_len
;
918 if (rsp_info_len
> 3 && rsp_info
[3]) {
919 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
920 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
921 "retrying command\n", ha
->host_no
,
922 cp
->device
->channel
, cp
->device
->id
,
923 cp
->device
->lun
, rsp_info_len
, rsp_info
[0],
924 rsp_info
[1], rsp_info
[2], rsp_info
[3], rsp_info
[4],
925 rsp_info
[5], rsp_info
[6], rsp_info
[7]));
927 cp
->result
= DID_BUS_BUSY
<< 16;
928 qla2x00_sp_compl(ha
, sp
);
934 * Based on Host and scsi status generate status code for Linux
936 switch (comp_status
) {
939 if (scsi_status
== 0) {
940 cp
->result
= DID_OK
<< 16;
943 if (scsi_status
& (SS_RESIDUAL_UNDER
| SS_RESIDUAL_OVER
)) {
945 scsi_set_resid(cp
, resid
);
946 CMD_RESID_LEN(cp
) = resid
;
949 ((unsigned)(scsi_bufflen(cp
) - resid
) <
951 qla_printk(KERN_INFO
, ha
,
952 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
953 "detected (%x of %x bytes)...returning "
954 "error status.\n", ha
->host_no
,
955 cp
->device
->channel
, cp
->device
->id
,
956 cp
->device
->lun
, resid
,
959 cp
->result
= DID_ERROR
<< 16;
963 cp
->result
= DID_OK
<< 16 | lscsi_status
;
965 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
) {
966 DEBUG2(printk(KERN_INFO
967 "scsi(%ld): QUEUE FULL status detected "
968 "0x%x-0x%x.\n", ha
->host_no
, comp_status
,
971 /* Adjust queue depth for all luns on the port. */
972 fcport
->last_queue_full
= jiffies
;
973 starget_for_each_device(cp
->device
->sdev_target
,
974 fcport
, qla2x00_adjust_sdev_qdepth_down
);
977 if (lscsi_status
!= SS_CHECK_CONDITION
)
980 /* Copy Sense Data into sense buffer. */
981 memset(cp
->sense_buffer
, 0, sizeof(cp
->sense_buffer
));
983 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
986 if (sense_len
>= sizeof(cp
->sense_buffer
))
987 sense_len
= sizeof(cp
->sense_buffer
);
989 CMD_ACTUAL_SNSLEN(cp
) = sense_len
;
990 sp
->request_sense_length
= sense_len
;
991 sp
->request_sense_ptr
= cp
->sense_buffer
;
993 if (sp
->request_sense_length
> 32)
996 memcpy(cp
->sense_buffer
, sense_data
, sense_len
);
998 sp
->request_sense_ptr
+= sense_len
;
999 sp
->request_sense_length
-= sense_len
;
1000 if (sp
->request_sense_length
!= 0)
1001 ha
->status_srb
= sp
;
1003 DEBUG5(printk("%s(): Check condition Sense data, "
1004 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__
,
1005 ha
->host_no
, cp
->device
->channel
, cp
->device
->id
,
1006 cp
->device
->lun
, cp
, cp
->serial_number
));
1008 DEBUG5(qla2x00_dump_buffer(cp
->sense_buffer
,
1009 CMD_ACTUAL_SNSLEN(cp
)));
1012 case CS_DATA_UNDERRUN
:
1014 /* Use F/W calculated residual length. */
1015 if (IS_FWI2_CAPABLE(ha
))
1016 resid
= fw_resid_len
;
1018 if (scsi_status
& SS_RESIDUAL_UNDER
) {
1019 scsi_set_resid(cp
, resid
);
1020 CMD_RESID_LEN(cp
) = resid
;
1022 DEBUG2(printk(KERN_INFO
1023 "scsi(%ld:%d:%d) UNDERRUN status detected "
1024 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1025 "os_underflow=0x%x\n", ha
->host_no
,
1026 cp
->device
->id
, cp
->device
->lun
, comp_status
,
1027 scsi_status
, resid_len
, resid
, cp
->cmnd
[0],
1033 * Check to see if SCSI Status is non zero. If so report SCSI
1036 if (lscsi_status
!= 0) {
1037 cp
->result
= DID_OK
<< 16 | lscsi_status
;
1039 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
) {
1040 DEBUG2(printk(KERN_INFO
1041 "scsi(%ld): QUEUE FULL status detected "
1042 "0x%x-0x%x.\n", ha
->host_no
, comp_status
,
1046 * Adjust queue depth for all luns on the
1049 fcport
->last_queue_full
= jiffies
;
1050 starget_for_each_device(
1051 cp
->device
->sdev_target
, fcport
,
1052 qla2x00_adjust_sdev_qdepth_down
);
1055 if (lscsi_status
!= SS_CHECK_CONDITION
)
1058 /* Copy Sense Data into sense buffer */
1059 memset(cp
->sense_buffer
, 0, sizeof(cp
->sense_buffer
));
1061 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
1064 if (sense_len
>= sizeof(cp
->sense_buffer
))
1065 sense_len
= sizeof(cp
->sense_buffer
);
1067 CMD_ACTUAL_SNSLEN(cp
) = sense_len
;
1068 sp
->request_sense_length
= sense_len
;
1069 sp
->request_sense_ptr
= cp
->sense_buffer
;
1071 if (sp
->request_sense_length
> 32)
1074 memcpy(cp
->sense_buffer
, sense_data
, sense_len
);
1076 sp
->request_sense_ptr
+= sense_len
;
1077 sp
->request_sense_length
-= sense_len
;
1078 if (sp
->request_sense_length
!= 0)
1079 ha
->status_srb
= sp
;
1081 DEBUG5(printk("%s(): Check condition Sense data, "
1082 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
1083 __func__
, ha
->host_no
, cp
->device
->channel
,
1084 cp
->device
->id
, cp
->device
->lun
, cp
,
1085 cp
->serial_number
));
1088 * In case of a Underrun condition, set both the lscsi
1089 * status and the completion status to appropriate
1093 ((unsigned)(scsi_bufflen(cp
) - resid
) <
1095 DEBUG2(qla_printk(KERN_INFO
, ha
,
1096 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1097 "detected (%x of %x bytes)...returning "
1098 "error status.\n", ha
->host_no
,
1099 cp
->device
->channel
, cp
->device
->id
,
1100 cp
->device
->lun
, resid
,
1103 cp
->result
= DID_ERROR
<< 16 | lscsi_status
;
1107 DEBUG5(qla2x00_dump_buffer(cp
->sense_buffer
,
1108 CMD_ACTUAL_SNSLEN(cp
)));
1111 * If RISC reports underrun and target does not report
1112 * it then we must have a lost frame, so tell upper
1113 * layer to retry it by reporting a bus busy.
1115 if (!(scsi_status
& SS_RESIDUAL_UNDER
)) {
1116 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1117 "frame(s) detected (%x of %x bytes)..."
1118 "retrying command.\n", ha
->host_no
,
1119 cp
->device
->channel
, cp
->device
->id
,
1120 cp
->device
->lun
, resid
,
1123 cp
->result
= DID_BUS_BUSY
<< 16;
1127 /* Handle mid-layer underflow */
1128 if ((unsigned)(scsi_bufflen(cp
) - resid
) <
1130 qla_printk(KERN_INFO
, ha
,
1131 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1132 "detected (%x of %x bytes)...returning "
1133 "error status.\n", ha
->host_no
,
1134 cp
->device
->channel
, cp
->device
->id
,
1135 cp
->device
->lun
, resid
,
1138 cp
->result
= DID_ERROR
<< 16;
1142 /* Everybody online, looking good... */
1143 cp
->result
= DID_OK
<< 16;
1147 case CS_DATA_OVERRUN
:
1148 DEBUG2(printk(KERN_INFO
1149 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1150 ha
->host_no
, cp
->device
->id
, cp
->device
->lun
, comp_status
,
1152 DEBUG2(printk(KERN_INFO
1153 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1154 cp
->cmnd
[0], cp
->cmnd
[1], cp
->cmnd
[2], cp
->cmnd
[3],
1155 cp
->cmnd
[4], cp
->cmnd
[5]));
1156 DEBUG2(printk(KERN_INFO
1157 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1159 cp
->serial_number
, scsi_bufflen(cp
), resid_len
));
1161 cp
->result
= DID_ERROR
<< 16;
1164 case CS_PORT_LOGGED_OUT
:
1165 case CS_PORT_CONFIG_CHG
:
1168 case CS_PORT_UNAVAILABLE
:
1170 * If the port is in Target Down state, return all IOs for this
1171 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1174 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1175 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1176 ha
->host_no
, cp
->device
->id
, cp
->device
->lun
,
1177 cp
->serial_number
, comp_status
,
1178 atomic_read(&fcport
->state
)));
1180 cp
->result
= DID_BUS_BUSY
<< 16;
1181 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
1182 qla2x00_mark_device_lost(ha
, fcport
, 1, 1);
1187 DEBUG2(printk(KERN_INFO
1188 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1189 ha
->host_no
, comp_status
, scsi_status
));
1191 cp
->result
= DID_RESET
<< 16;
1196 * hv2.19.12 - DID_ABORT does not retry the request if we
1197 * aborted this request then abort otherwise it must be a
1200 DEBUG2(printk(KERN_INFO
1201 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1202 ha
->host_no
, comp_status
, scsi_status
));
1204 cp
->result
= DID_RESET
<< 16;
1208 cp
->result
= DID_BUS_BUSY
<< 16;
1210 if (IS_FWI2_CAPABLE(ha
)) {
1211 DEBUG2(printk(KERN_INFO
1212 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1213 "0x%x-0x%x\n", ha
->host_no
, cp
->device
->channel
,
1214 cp
->device
->id
, cp
->device
->lun
, comp_status
,
1218 DEBUG2(printk(KERN_INFO
1219 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1220 "sflags=%x.\n", ha
->host_no
, cp
->device
->channel
,
1221 cp
->device
->id
, cp
->device
->lun
, comp_status
, scsi_status
,
1222 le16_to_cpu(sts
->status_flags
)));
1224 /* Check to see if logout occurred. */
1225 if ((le16_to_cpu(sts
->status_flags
) & SF_LOGOUT_SENT
))
1226 qla2x00_mark_device_lost(ha
, fcport
, 1, 1);
1230 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1231 "0x%x-0x%x.\n", ha
->host_no
, comp_status
, scsi_status
));
1232 qla_printk(KERN_INFO
, ha
,
1233 "Unknown status detected 0x%x-0x%x.\n",
1234 comp_status
, scsi_status
);
1236 cp
->result
= DID_ERROR
<< 16;
1240 /* Place command on done queue. */
1241 if (ha
->status_srb
== NULL
)
1242 qla2x00_sp_compl(ha
, sp
);
1246 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1247 * @ha: SCSI driver HA context
1248 * @pkt: Entry pointer
1250 * Extended sense data.
1253 qla2x00_status_cont_entry(scsi_qla_host_t
*ha
, sts_cont_entry_t
*pkt
)
1255 uint8_t sense_sz
= 0;
1256 srb_t
*sp
= ha
->status_srb
;
1257 struct scsi_cmnd
*cp
;
1259 if (sp
!= NULL
&& sp
->request_sense_length
!= 0) {
1262 DEBUG2(printk("%s(): Cmd already returned back to OS "
1263 "sp=%p.\n", __func__
, sp
));
1264 qla_printk(KERN_INFO
, ha
,
1265 "cmd is NULL: already returned to OS (sp=%p)\n",
1268 ha
->status_srb
= NULL
;
1272 if (sp
->request_sense_length
> sizeof(pkt
->data
)) {
1273 sense_sz
= sizeof(pkt
->data
);
1275 sense_sz
= sp
->request_sense_length
;
1278 /* Move sense data. */
1279 if (IS_FWI2_CAPABLE(ha
))
1280 host_to_fcp_swap(pkt
->data
, sizeof(pkt
->data
));
1281 memcpy(sp
->request_sense_ptr
, pkt
->data
, sense_sz
);
1282 DEBUG5(qla2x00_dump_buffer(sp
->request_sense_ptr
, sense_sz
));
1284 sp
->request_sense_ptr
+= sense_sz
;
1285 sp
->request_sense_length
-= sense_sz
;
1287 /* Place command on done queue. */
1288 if (sp
->request_sense_length
== 0) {
1289 ha
->status_srb
= NULL
;
1290 qla2x00_sp_compl(ha
, sp
);
1296 * qla2x00_error_entry() - Process an error entry.
1297 * @ha: SCSI driver HA context
1298 * @pkt: Entry pointer
1301 qla2x00_error_entry(scsi_qla_host_t
*ha
, sts_entry_t
*pkt
)
1305 #if defined(QL_DEBUG_LEVEL_2)
1306 if (pkt
->entry_status
& RF_INV_E_ORDER
)
1307 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Order\n", __func__
);
1308 else if (pkt
->entry_status
& RF_INV_E_COUNT
)
1309 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Count\n", __func__
);
1310 else if (pkt
->entry_status
& RF_INV_E_PARAM
)
1311 qla_printk(KERN_ERR
, ha
,
1312 "%s: Invalid Entry Parameter\n", __func__
);
1313 else if (pkt
->entry_status
& RF_INV_E_TYPE
)
1314 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Type\n", __func__
);
1315 else if (pkt
->entry_status
& RF_BUSY
)
1316 qla_printk(KERN_ERR
, ha
, "%s: Busy\n", __func__
);
1318 qla_printk(KERN_ERR
, ha
, "%s: UNKNOWN flag error\n", __func__
);
1321 /* Validate handle. */
1322 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
1323 sp
= ha
->outstanding_cmds
[pkt
->handle
];
1328 /* Free outstanding command slot. */
1329 ha
->outstanding_cmds
[pkt
->handle
] = NULL
;
1331 /* Bad payload or header */
1332 if (pkt
->entry_status
&
1333 (RF_INV_E_ORDER
| RF_INV_E_COUNT
|
1334 RF_INV_E_PARAM
| RF_INV_E_TYPE
)) {
1335 sp
->cmd
->result
= DID_ERROR
<< 16;
1336 } else if (pkt
->entry_status
& RF_BUSY
) {
1337 sp
->cmd
->result
= DID_BUS_BUSY
<< 16;
1339 sp
->cmd
->result
= DID_ERROR
<< 16;
1341 qla2x00_sp_compl(ha
, sp
);
1343 } else if (pkt
->entry_type
== COMMAND_A64_TYPE
|| pkt
->entry_type
==
1344 COMMAND_TYPE
|| pkt
->entry_type
== COMMAND_TYPE_7
) {
1345 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1347 qla_printk(KERN_WARNING
, ha
,
1348 "Error entry - invalid handle\n");
1350 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1351 qla2xxx_wake_dpc(ha
);
1356 * qla2x00_ms_entry() - Process a Management Server entry.
1357 * @ha: SCSI driver HA context
1358 * @index: Response queue out pointer
1361 qla2x00_ms_entry(scsi_qla_host_t
*ha
, ms_iocb_entry_t
*pkt
)
1365 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1366 __func__
, ha
->host_no
, pkt
, pkt
->handle1
));
1368 /* Validate handle. */
1369 if (pkt
->handle1
< MAX_OUTSTANDING_COMMANDS
)
1370 sp
= ha
->outstanding_cmds
[pkt
->handle1
];
1375 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1377 qla_printk(KERN_WARNING
, ha
, "MS entry - invalid handle\n");
1379 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1383 CMD_COMPL_STATUS(sp
->cmd
) = le16_to_cpu(pkt
->status
);
1384 CMD_ENTRY_STATUS(sp
->cmd
) = pkt
->entry_status
;
1386 /* Free outstanding command slot. */
1387 ha
->outstanding_cmds
[pkt
->handle1
] = NULL
;
1389 qla2x00_sp_compl(ha
, sp
);
1394 * qla24xx_mbx_completion() - Process mailbox command completions.
1395 * @ha: SCSI driver HA context
1396 * @mb0: Mailbox0 register
1399 qla24xx_mbx_completion(scsi_qla_host_t
*ha
, uint16_t mb0
)
1402 uint16_t __iomem
*wptr
;
1403 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1405 /* Load return mailbox registers. */
1406 ha
->flags
.mbox_int
= 1;
1407 ha
->mailbox_out
[0] = mb0
;
1408 wptr
= (uint16_t __iomem
*)®
->mailbox1
;
1410 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
1411 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
1416 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1417 __func__
, ha
->host_no
, ha
->mcp
->mb
[0]));
1419 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1420 __func__
, ha
->host_no
));
1425 * qla24xx_process_response_queue() - Process response queue entries.
1426 * @ha: SCSI driver HA context
1429 qla24xx_process_response_queue(struct scsi_qla_host
*ha
)
1431 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1432 struct sts_entry_24xx
*pkt
;
1434 if (!ha
->flags
.online
)
1437 while (ha
->response_ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
1438 pkt
= (struct sts_entry_24xx
*)ha
->response_ring_ptr
;
1440 ha
->rsp_ring_index
++;
1441 if (ha
->rsp_ring_index
== ha
->response_q_length
) {
1442 ha
->rsp_ring_index
= 0;
1443 ha
->response_ring_ptr
= ha
->response_ring
;
1445 ha
->response_ring_ptr
++;
1448 if (pkt
->entry_status
!= 0) {
1449 DEBUG3(printk(KERN_INFO
1450 "scsi(%ld): Process error entry.\n", ha
->host_no
));
1452 qla2x00_error_entry(ha
, (sts_entry_t
*) pkt
);
1453 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1458 switch (pkt
->entry_type
) {
1460 qla2x00_status_entry(ha
, pkt
);
1462 case STATUS_CONT_TYPE
:
1463 qla2x00_status_cont_entry(ha
, (sts_cont_entry_t
*)pkt
);
1466 qla24xx_ms_entry(ha
, (struct ct_entry_24xx
*)pkt
);
1468 case VP_RPT_ID_IOCB_TYPE
:
1469 qla24xx_report_id_acquisition(ha
,
1470 (struct vp_rpt_id_entry_24xx
*)pkt
);
1473 /* Type Not Supported. */
1474 DEBUG4(printk(KERN_WARNING
1475 "scsi(%ld): Received unknown response pkt type %x "
1476 "entry status=%x.\n",
1477 ha
->host_no
, pkt
->entry_type
, pkt
->entry_status
));
1480 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1484 /* Adjust ring index */
1485 WRT_REG_DWORD(®
->rsp_q_out
, ha
->rsp_ring_index
);
1489 qla2xxx_check_risc_status(scsi_qla_host_t
*ha
)
1493 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1495 if (!IS_QLA25XX(ha
))
1499 WRT_REG_DWORD(®
->iobase_addr
, 0x7C00);
1500 RD_REG_DWORD(®
->iobase_addr
);
1501 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
1502 for (cnt
= 10000; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
1503 rval
== QLA_SUCCESS
; cnt
--) {
1505 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
1508 rval
= QLA_FUNCTION_TIMEOUT
;
1510 if (rval
== QLA_SUCCESS
)
1513 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
1514 for (cnt
= 100; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
1515 rval
== QLA_SUCCESS
; cnt
--) {
1517 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
1520 rval
= QLA_FUNCTION_TIMEOUT
;
1522 if (rval
!= QLA_SUCCESS
)
1526 if (RD_REG_DWORD(®
->iobase_c8
) & BIT_3
)
1527 qla_printk(KERN_INFO
, ha
, "Additional code -- 0x55AA.\n");
1530 WRT_REG_DWORD(®
->iobase_window
, 0x0000);
1531 RD_REG_DWORD(®
->iobase_window
);
1535 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1537 * @dev_id: SCSI driver HA context
1539 * Called by system whenever the host adapter generates an interrupt.
1541 * Returns handled flag.
1544 qla24xx_intr_handler(int irq
, void *dev_id
)
1546 scsi_qla_host_t
*ha
;
1547 struct device_reg_24xx __iomem
*reg
;
1549 unsigned long flags
;
1555 ha
= (scsi_qla_host_t
*) dev_id
;
1558 "%s(): NULL host pointer\n", __func__
);
1562 reg
= &ha
->iobase
->isp24
;
1565 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1566 for (iter
= 50; iter
--; ) {
1567 stat
= RD_REG_DWORD(®
->host_status
);
1568 if (stat
& HSRX_RISC_PAUSED
) {
1569 if (pci_channel_offline(ha
->pdev
))
1572 hccr
= RD_REG_DWORD(®
->hccr
);
1574 qla_printk(KERN_INFO
, ha
, "RISC paused -- HCCR=%x, "
1575 "Dumping firmware!\n", hccr
);
1577 qla2xxx_check_risc_status(ha
);
1579 ha
->isp_ops
->fw_dump(ha
, 1);
1580 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1582 } else if ((stat
& HSRX_RISC_INT
) == 0)
1585 switch (stat
& 0xff) {
1590 qla24xx_mbx_completion(ha
, MSW(stat
));
1591 status
|= MBX_INTERRUPT
;
1596 mb
[1] = RD_REG_WORD(®
->mailbox1
);
1597 mb
[2] = RD_REG_WORD(®
->mailbox2
);
1598 mb
[3] = RD_REG_WORD(®
->mailbox3
);
1599 qla2x00_async_event(ha
, mb
);
1602 qla24xx_process_response_queue(ha
);
1605 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1607 ha
->host_no
, stat
& 0xff));
1610 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
1611 RD_REG_DWORD_RELAXED(®
->hccr
);
1613 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1615 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
1616 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
1617 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
1618 up(&ha
->mbx_intr_sem
);
1625 * qla24xx_ms_entry() - Process a Management Server entry.
1626 * @ha: SCSI driver HA context
1627 * @index: Response queue out pointer
1630 qla24xx_ms_entry(scsi_qla_host_t
*ha
, struct ct_entry_24xx
*pkt
)
1634 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1635 __func__
, ha
->host_no
, pkt
, pkt
->handle
));
1637 DEBUG9(printk("%s: ct pkt dump:\n", __func__
));
1638 DEBUG9(qla2x00_dump_buffer((void *)pkt
, sizeof(struct ct_entry_24xx
)));
1640 /* Validate handle. */
1641 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
1642 sp
= ha
->outstanding_cmds
[pkt
->handle
];
1647 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1649 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1651 qla_printk(KERN_WARNING
, ha
, "MS entry - invalid handle %d\n",
1654 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1658 CMD_COMPL_STATUS(sp
->cmd
) = le16_to_cpu(pkt
->comp_status
);
1659 CMD_ENTRY_STATUS(sp
->cmd
) = pkt
->entry_status
;
1661 /* Free outstanding command slot. */
1662 ha
->outstanding_cmds
[pkt
->handle
] = NULL
;
1664 qla2x00_sp_compl(ha
, sp
);
1668 qla24xx_msix_rsp_q(int irq
, void *dev_id
)
1670 scsi_qla_host_t
*ha
;
1671 struct device_reg_24xx __iomem
*reg
;
1672 unsigned long flags
;
1675 reg
= &ha
->iobase
->isp24
;
1677 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1679 qla24xx_process_response_queue(ha
);
1681 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
1683 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1689 qla24xx_msix_default(int irq
, void *dev_id
)
1691 scsi_qla_host_t
*ha
;
1692 struct device_reg_24xx __iomem
*reg
;
1694 unsigned long flags
;
1700 reg
= &ha
->iobase
->isp24
;
1703 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1705 stat
= RD_REG_DWORD(®
->host_status
);
1706 if (stat
& HSRX_RISC_PAUSED
) {
1707 if (pci_channel_offline(ha
->pdev
))
1710 hccr
= RD_REG_DWORD(®
->hccr
);
1712 qla_printk(KERN_INFO
, ha
, "RISC paused -- HCCR=%x, "
1713 "Dumping firmware!\n", hccr
);
1715 qla2xxx_check_risc_status(ha
);
1717 ha
->isp_ops
->fw_dump(ha
, 1);
1718 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1720 } else if ((stat
& HSRX_RISC_INT
) == 0)
1723 switch (stat
& 0xff) {
1728 qla24xx_mbx_completion(ha
, MSW(stat
));
1729 status
|= MBX_INTERRUPT
;
1734 mb
[1] = RD_REG_WORD(®
->mailbox1
);
1735 mb
[2] = RD_REG_WORD(®
->mailbox2
);
1736 mb
[3] = RD_REG_WORD(®
->mailbox3
);
1737 qla2x00_async_event(ha
, mb
);
1740 qla24xx_process_response_queue(ha
);
1743 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1745 ha
->host_no
, stat
& 0xff));
1748 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
1750 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1752 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
1753 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
1754 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
1755 up(&ha
->mbx_intr_sem
);
1761 /* Interrupt handling helpers. */
1763 struct qla_init_msix_entry
{
1767 irq_handler_t handler
;
1770 static struct qla_init_msix_entry imsix_entries
[QLA_MSIX_ENTRIES
] = {
1771 { QLA_MSIX_DEFAULT
, QLA_MIDX_DEFAULT
,
1772 "qla2xxx (default)", qla24xx_msix_default
},
1774 { QLA_MSIX_RSP_Q
, QLA_MIDX_RSP_Q
,
1775 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q
},
1779 qla24xx_disable_msix(scsi_qla_host_t
*ha
)
1782 struct qla_msix_entry
*qentry
;
1784 for (i
= 0; i
< QLA_MSIX_ENTRIES
; i
++) {
1785 qentry
= &ha
->msix_entries
[imsix_entries
[i
].index
];
1786 if (qentry
->have_irq
)
1787 free_irq(qentry
->msix_vector
, ha
);
1789 pci_disable_msix(ha
->pdev
);
1793 qla24xx_enable_msix(scsi_qla_host_t
*ha
)
1796 struct msix_entry entries
[QLA_MSIX_ENTRIES
];
1797 struct qla_msix_entry
*qentry
;
1799 for (i
= 0; i
< QLA_MSIX_ENTRIES
; i
++)
1800 entries
[i
].entry
= imsix_entries
[i
].entry
;
1802 ret
= pci_enable_msix(ha
->pdev
, entries
, ARRAY_SIZE(entries
));
1804 qla_printk(KERN_WARNING
, ha
,
1805 "MSI-X: Failed to enable support -- %d/%d\n",
1806 QLA_MSIX_ENTRIES
, ret
);
1809 ha
->flags
.msix_enabled
= 1;
1811 for (i
= 0; i
< QLA_MSIX_ENTRIES
; i
++) {
1812 qentry
= &ha
->msix_entries
[imsix_entries
[i
].index
];
1813 qentry
->msix_vector
= entries
[i
].vector
;
1814 qentry
->msix_entry
= entries
[i
].entry
;
1815 qentry
->have_irq
= 0;
1816 ret
= request_irq(qentry
->msix_vector
,
1817 imsix_entries
[i
].handler
, 0, imsix_entries
[i
].name
, ha
);
1819 qla_printk(KERN_WARNING
, ha
,
1820 "MSI-X: Unable to register handler -- %x/%d.\n",
1821 imsix_entries
[i
].index
, ret
);
1822 qla24xx_disable_msix(ha
);
1825 qentry
->have_irq
= 1;
1833 qla2x00_request_irqs(scsi_qla_host_t
*ha
)
1837 /* If possible, enable MSI-X. */
1838 if (!IS_QLA2432(ha
) && !IS_QLA2532(ha
))
1841 if (IS_QLA2432(ha
) && (ha
->chip_revision
< QLA_MSIX_CHIP_REV_24XX
||
1842 !QLA_MSIX_FW_MODE_1(ha
->fw_attributes
))) {
1843 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1844 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1845 ha
->chip_revision
, ha
->fw_attributes
));
1850 ret
= qla24xx_enable_msix(ha
);
1852 DEBUG2(qla_printk(KERN_INFO
, ha
,
1853 "MSI-X: Enabled (0x%X, 0x%X).\n", ha
->chip_revision
,
1854 ha
->fw_attributes
));
1857 qla_printk(KERN_WARNING
, ha
,
1858 "MSI-X: Falling back-to INTa mode -- %d.\n", ret
);
1861 if (!IS_QLA24XX(ha
) && !IS_QLA2532(ha
))
1864 ret
= pci_enable_msi(ha
->pdev
);
1866 DEBUG2(qla_printk(KERN_INFO
, ha
, "MSI: Enabled.\n"));
1867 ha
->flags
.msi_enabled
= 1;
1871 ret
= request_irq(ha
->pdev
->irq
, ha
->isp_ops
->intr_handler
,
1872 IRQF_DISABLED
|IRQF_SHARED
, QLA2XXX_DRIVER_NAME
, ha
);
1874 ha
->flags
.inta_enabled
= 1;
1875 ha
->host
->irq
= ha
->pdev
->irq
;
1877 qla_printk(KERN_WARNING
, ha
,
1878 "Failed to reserve interrupt %d already in use.\n",
1886 qla2x00_free_irqs(scsi_qla_host_t
*ha
)
1889 if (ha
->flags
.msix_enabled
)
1890 qla24xx_disable_msix(ha
);
1891 else if (ha
->flags
.inta_enabled
) {
1892 free_irq(ha
->host
->irq
, ha
);
1893 pci_disable_msi(ha
->pdev
);