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 if (scsi_status
& SS_RESIDUAL_UNDER
&&
1017 resid
!= fw_resid_len
) {
1018 scsi_status
&= ~SS_RESIDUAL_UNDER
;
1021 resid
= fw_resid_len
;
1024 if (scsi_status
& SS_RESIDUAL_UNDER
) {
1025 scsi_set_resid(cp
, resid
);
1026 CMD_RESID_LEN(cp
) = resid
;
1028 DEBUG2(printk(KERN_INFO
1029 "scsi(%ld:%d:%d) UNDERRUN status detected "
1030 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1031 "os_underflow=0x%x\n", ha
->host_no
,
1032 cp
->device
->id
, cp
->device
->lun
, comp_status
,
1033 scsi_status
, resid_len
, resid
, cp
->cmnd
[0],
1039 * Check to see if SCSI Status is non zero. If so report SCSI
1042 if (lscsi_status
!= 0) {
1043 cp
->result
= DID_OK
<< 16 | lscsi_status
;
1045 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
) {
1046 DEBUG2(printk(KERN_INFO
1047 "scsi(%ld): QUEUE FULL status detected "
1048 "0x%x-0x%x.\n", ha
->host_no
, comp_status
,
1052 * Adjust queue depth for all luns on the
1055 fcport
->last_queue_full
= jiffies
;
1056 starget_for_each_device(
1057 cp
->device
->sdev_target
, fcport
,
1058 qla2x00_adjust_sdev_qdepth_down
);
1061 if (lscsi_status
!= SS_CHECK_CONDITION
)
1064 /* Copy Sense Data into sense buffer */
1065 memset(cp
->sense_buffer
, 0, sizeof(cp
->sense_buffer
));
1067 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
1070 if (sense_len
>= sizeof(cp
->sense_buffer
))
1071 sense_len
= sizeof(cp
->sense_buffer
);
1073 CMD_ACTUAL_SNSLEN(cp
) = sense_len
;
1074 sp
->request_sense_length
= sense_len
;
1075 sp
->request_sense_ptr
= cp
->sense_buffer
;
1077 if (sp
->request_sense_length
> 32)
1080 memcpy(cp
->sense_buffer
, sense_data
, sense_len
);
1082 sp
->request_sense_ptr
+= sense_len
;
1083 sp
->request_sense_length
-= sense_len
;
1084 if (sp
->request_sense_length
!= 0)
1085 ha
->status_srb
= sp
;
1087 DEBUG5(printk("%s(): Check condition Sense data, "
1088 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
1089 __func__
, ha
->host_no
, cp
->device
->channel
,
1090 cp
->device
->id
, cp
->device
->lun
, cp
,
1091 cp
->serial_number
));
1094 * In case of a Underrun condition, set both the lscsi
1095 * status and the completion status to appropriate
1099 ((unsigned)(scsi_bufflen(cp
) - resid
) <
1101 DEBUG2(qla_printk(KERN_INFO
, ha
,
1102 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1103 "detected (%x of %x bytes)...returning "
1104 "error status.\n", ha
->host_no
,
1105 cp
->device
->channel
, cp
->device
->id
,
1106 cp
->device
->lun
, resid
,
1109 cp
->result
= DID_ERROR
<< 16 | lscsi_status
;
1113 DEBUG5(qla2x00_dump_buffer(cp
->sense_buffer
,
1114 CMD_ACTUAL_SNSLEN(cp
)));
1117 * If RISC reports underrun and target does not report
1118 * it then we must have a lost frame, so tell upper
1119 * layer to retry it by reporting a bus busy.
1121 if (!(scsi_status
& SS_RESIDUAL_UNDER
)) {
1122 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1123 "frame(s) detected (%x of %x bytes)..."
1124 "retrying command.\n", ha
->host_no
,
1125 cp
->device
->channel
, cp
->device
->id
,
1126 cp
->device
->lun
, resid
,
1129 cp
->result
= DID_BUS_BUSY
<< 16;
1133 /* Handle mid-layer underflow */
1134 if ((unsigned)(scsi_bufflen(cp
) - resid
) <
1136 qla_printk(KERN_INFO
, ha
,
1137 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1138 "detected (%x of %x bytes)...returning "
1139 "error status.\n", ha
->host_no
,
1140 cp
->device
->channel
, cp
->device
->id
,
1141 cp
->device
->lun
, resid
,
1144 cp
->result
= DID_ERROR
<< 16;
1148 /* Everybody online, looking good... */
1149 cp
->result
= DID_OK
<< 16;
1153 case CS_DATA_OVERRUN
:
1154 DEBUG2(printk(KERN_INFO
1155 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1156 ha
->host_no
, cp
->device
->id
, cp
->device
->lun
, comp_status
,
1158 DEBUG2(printk(KERN_INFO
1159 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1160 cp
->cmnd
[0], cp
->cmnd
[1], cp
->cmnd
[2], cp
->cmnd
[3],
1161 cp
->cmnd
[4], cp
->cmnd
[5]));
1162 DEBUG2(printk(KERN_INFO
1163 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1165 cp
->serial_number
, scsi_bufflen(cp
), resid_len
));
1167 cp
->result
= DID_ERROR
<< 16;
1170 case CS_PORT_LOGGED_OUT
:
1171 case CS_PORT_CONFIG_CHG
:
1174 case CS_PORT_UNAVAILABLE
:
1176 * If the port is in Target Down state, return all IOs for this
1177 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1180 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1181 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1182 ha
->host_no
, cp
->device
->id
, cp
->device
->lun
,
1183 cp
->serial_number
, comp_status
,
1184 atomic_read(&fcport
->state
)));
1186 cp
->result
= DID_BUS_BUSY
<< 16;
1187 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
1188 qla2x00_mark_device_lost(ha
, fcport
, 1, 1);
1193 DEBUG2(printk(KERN_INFO
1194 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1195 ha
->host_no
, comp_status
, scsi_status
));
1197 cp
->result
= DID_RESET
<< 16;
1202 * hv2.19.12 - DID_ABORT does not retry the request if we
1203 * aborted this request then abort otherwise it must be a
1206 DEBUG2(printk(KERN_INFO
1207 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1208 ha
->host_no
, comp_status
, scsi_status
));
1210 cp
->result
= DID_RESET
<< 16;
1214 cp
->result
= DID_BUS_BUSY
<< 16;
1216 if (IS_FWI2_CAPABLE(ha
)) {
1217 DEBUG2(printk(KERN_INFO
1218 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1219 "0x%x-0x%x\n", ha
->host_no
, cp
->device
->channel
,
1220 cp
->device
->id
, cp
->device
->lun
, comp_status
,
1224 DEBUG2(printk(KERN_INFO
1225 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1226 "sflags=%x.\n", ha
->host_no
, cp
->device
->channel
,
1227 cp
->device
->id
, cp
->device
->lun
, comp_status
, scsi_status
,
1228 le16_to_cpu(sts
->status_flags
)));
1230 /* Check to see if logout occurred. */
1231 if ((le16_to_cpu(sts
->status_flags
) & SF_LOGOUT_SENT
))
1232 qla2x00_mark_device_lost(ha
, fcport
, 1, 1);
1236 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1237 "0x%x-0x%x.\n", ha
->host_no
, comp_status
, scsi_status
));
1238 qla_printk(KERN_INFO
, ha
,
1239 "Unknown status detected 0x%x-0x%x.\n",
1240 comp_status
, scsi_status
);
1242 cp
->result
= DID_ERROR
<< 16;
1246 /* Place command on done queue. */
1247 if (ha
->status_srb
== NULL
)
1248 qla2x00_sp_compl(ha
, sp
);
1252 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1253 * @ha: SCSI driver HA context
1254 * @pkt: Entry pointer
1256 * Extended sense data.
1259 qla2x00_status_cont_entry(scsi_qla_host_t
*ha
, sts_cont_entry_t
*pkt
)
1261 uint8_t sense_sz
= 0;
1262 srb_t
*sp
= ha
->status_srb
;
1263 struct scsi_cmnd
*cp
;
1265 if (sp
!= NULL
&& sp
->request_sense_length
!= 0) {
1268 DEBUG2(printk("%s(): Cmd already returned back to OS "
1269 "sp=%p.\n", __func__
, sp
));
1270 qla_printk(KERN_INFO
, ha
,
1271 "cmd is NULL: already returned to OS (sp=%p)\n",
1274 ha
->status_srb
= NULL
;
1278 if (sp
->request_sense_length
> sizeof(pkt
->data
)) {
1279 sense_sz
= sizeof(pkt
->data
);
1281 sense_sz
= sp
->request_sense_length
;
1284 /* Move sense data. */
1285 if (IS_FWI2_CAPABLE(ha
))
1286 host_to_fcp_swap(pkt
->data
, sizeof(pkt
->data
));
1287 memcpy(sp
->request_sense_ptr
, pkt
->data
, sense_sz
);
1288 DEBUG5(qla2x00_dump_buffer(sp
->request_sense_ptr
, sense_sz
));
1290 sp
->request_sense_ptr
+= sense_sz
;
1291 sp
->request_sense_length
-= sense_sz
;
1293 /* Place command on done queue. */
1294 if (sp
->request_sense_length
== 0) {
1295 ha
->status_srb
= NULL
;
1296 qla2x00_sp_compl(ha
, sp
);
1302 * qla2x00_error_entry() - Process an error entry.
1303 * @ha: SCSI driver HA context
1304 * @pkt: Entry pointer
1307 qla2x00_error_entry(scsi_qla_host_t
*ha
, sts_entry_t
*pkt
)
1311 #if defined(QL_DEBUG_LEVEL_2)
1312 if (pkt
->entry_status
& RF_INV_E_ORDER
)
1313 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Order\n", __func__
);
1314 else if (pkt
->entry_status
& RF_INV_E_COUNT
)
1315 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Count\n", __func__
);
1316 else if (pkt
->entry_status
& RF_INV_E_PARAM
)
1317 qla_printk(KERN_ERR
, ha
,
1318 "%s: Invalid Entry Parameter\n", __func__
);
1319 else if (pkt
->entry_status
& RF_INV_E_TYPE
)
1320 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Type\n", __func__
);
1321 else if (pkt
->entry_status
& RF_BUSY
)
1322 qla_printk(KERN_ERR
, ha
, "%s: Busy\n", __func__
);
1324 qla_printk(KERN_ERR
, ha
, "%s: UNKNOWN flag error\n", __func__
);
1327 /* Validate handle. */
1328 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
1329 sp
= ha
->outstanding_cmds
[pkt
->handle
];
1334 /* Free outstanding command slot. */
1335 ha
->outstanding_cmds
[pkt
->handle
] = NULL
;
1337 /* Bad payload or header */
1338 if (pkt
->entry_status
&
1339 (RF_INV_E_ORDER
| RF_INV_E_COUNT
|
1340 RF_INV_E_PARAM
| RF_INV_E_TYPE
)) {
1341 sp
->cmd
->result
= DID_ERROR
<< 16;
1342 } else if (pkt
->entry_status
& RF_BUSY
) {
1343 sp
->cmd
->result
= DID_BUS_BUSY
<< 16;
1345 sp
->cmd
->result
= DID_ERROR
<< 16;
1347 qla2x00_sp_compl(ha
, sp
);
1349 } else if (pkt
->entry_type
== COMMAND_A64_TYPE
|| pkt
->entry_type
==
1350 COMMAND_TYPE
|| pkt
->entry_type
== COMMAND_TYPE_7
) {
1351 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1353 qla_printk(KERN_WARNING
, ha
,
1354 "Error entry - invalid handle\n");
1356 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1357 qla2xxx_wake_dpc(ha
);
1362 * qla2x00_ms_entry() - Process a Management Server entry.
1363 * @ha: SCSI driver HA context
1364 * @index: Response queue out pointer
1367 qla2x00_ms_entry(scsi_qla_host_t
*ha
, ms_iocb_entry_t
*pkt
)
1371 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1372 __func__
, ha
->host_no
, pkt
, pkt
->handle1
));
1374 /* Validate handle. */
1375 if (pkt
->handle1
< MAX_OUTSTANDING_COMMANDS
)
1376 sp
= ha
->outstanding_cmds
[pkt
->handle1
];
1381 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1383 qla_printk(KERN_WARNING
, ha
, "MS entry - invalid handle\n");
1385 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1389 CMD_COMPL_STATUS(sp
->cmd
) = le16_to_cpu(pkt
->status
);
1390 CMD_ENTRY_STATUS(sp
->cmd
) = pkt
->entry_status
;
1392 /* Free outstanding command slot. */
1393 ha
->outstanding_cmds
[pkt
->handle1
] = NULL
;
1395 qla2x00_sp_compl(ha
, sp
);
1400 * qla24xx_mbx_completion() - Process mailbox command completions.
1401 * @ha: SCSI driver HA context
1402 * @mb0: Mailbox0 register
1405 qla24xx_mbx_completion(scsi_qla_host_t
*ha
, uint16_t mb0
)
1408 uint16_t __iomem
*wptr
;
1409 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1411 /* Load return mailbox registers. */
1412 ha
->flags
.mbox_int
= 1;
1413 ha
->mailbox_out
[0] = mb0
;
1414 wptr
= (uint16_t __iomem
*)®
->mailbox1
;
1416 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
1417 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
1422 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1423 __func__
, ha
->host_no
, ha
->mcp
->mb
[0]));
1425 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1426 __func__
, ha
->host_no
));
1431 * qla24xx_process_response_queue() - Process response queue entries.
1432 * @ha: SCSI driver HA context
1435 qla24xx_process_response_queue(struct scsi_qla_host
*ha
)
1437 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1438 struct sts_entry_24xx
*pkt
;
1440 if (!ha
->flags
.online
)
1443 while (ha
->response_ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
1444 pkt
= (struct sts_entry_24xx
*)ha
->response_ring_ptr
;
1446 ha
->rsp_ring_index
++;
1447 if (ha
->rsp_ring_index
== ha
->response_q_length
) {
1448 ha
->rsp_ring_index
= 0;
1449 ha
->response_ring_ptr
= ha
->response_ring
;
1451 ha
->response_ring_ptr
++;
1454 if (pkt
->entry_status
!= 0) {
1455 DEBUG3(printk(KERN_INFO
1456 "scsi(%ld): Process error entry.\n", ha
->host_no
));
1458 qla2x00_error_entry(ha
, (sts_entry_t
*) pkt
);
1459 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1464 switch (pkt
->entry_type
) {
1466 qla2x00_status_entry(ha
, pkt
);
1468 case STATUS_CONT_TYPE
:
1469 qla2x00_status_cont_entry(ha
, (sts_cont_entry_t
*)pkt
);
1472 qla24xx_ms_entry(ha
, (struct ct_entry_24xx
*)pkt
);
1474 case VP_RPT_ID_IOCB_TYPE
:
1475 qla24xx_report_id_acquisition(ha
,
1476 (struct vp_rpt_id_entry_24xx
*)pkt
);
1479 /* Type Not Supported. */
1480 DEBUG4(printk(KERN_WARNING
1481 "scsi(%ld): Received unknown response pkt type %x "
1482 "entry status=%x.\n",
1483 ha
->host_no
, pkt
->entry_type
, pkt
->entry_status
));
1486 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1490 /* Adjust ring index */
1491 WRT_REG_DWORD(®
->rsp_q_out
, ha
->rsp_ring_index
);
1495 qla2xxx_check_risc_status(scsi_qla_host_t
*ha
)
1499 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1501 if (!IS_QLA25XX(ha
))
1505 WRT_REG_DWORD(®
->iobase_addr
, 0x7C00);
1506 RD_REG_DWORD(®
->iobase_addr
);
1507 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
1508 for (cnt
= 10000; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
1509 rval
== QLA_SUCCESS
; cnt
--) {
1511 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
1514 rval
= QLA_FUNCTION_TIMEOUT
;
1516 if (rval
== QLA_SUCCESS
)
1519 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
1520 for (cnt
= 100; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
1521 rval
== QLA_SUCCESS
; cnt
--) {
1523 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
1526 rval
= QLA_FUNCTION_TIMEOUT
;
1528 if (rval
!= QLA_SUCCESS
)
1532 if (RD_REG_DWORD(®
->iobase_c8
) & BIT_3
)
1533 qla_printk(KERN_INFO
, ha
, "Additional code -- 0x55AA.\n");
1536 WRT_REG_DWORD(®
->iobase_window
, 0x0000);
1537 RD_REG_DWORD(®
->iobase_window
);
1541 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1543 * @dev_id: SCSI driver HA context
1545 * Called by system whenever the host adapter generates an interrupt.
1547 * Returns handled flag.
1550 qla24xx_intr_handler(int irq
, void *dev_id
)
1552 scsi_qla_host_t
*ha
;
1553 struct device_reg_24xx __iomem
*reg
;
1555 unsigned long flags
;
1561 ha
= (scsi_qla_host_t
*) dev_id
;
1564 "%s(): NULL host pointer\n", __func__
);
1568 reg
= &ha
->iobase
->isp24
;
1571 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1572 for (iter
= 50; iter
--; ) {
1573 stat
= RD_REG_DWORD(®
->host_status
);
1574 if (stat
& HSRX_RISC_PAUSED
) {
1575 if (pci_channel_offline(ha
->pdev
))
1578 hccr
= RD_REG_DWORD(®
->hccr
);
1580 qla_printk(KERN_INFO
, ha
, "RISC paused -- HCCR=%x, "
1581 "Dumping firmware!\n", hccr
);
1583 qla2xxx_check_risc_status(ha
);
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
);
1631 * qla24xx_ms_entry() - Process a Management Server entry.
1632 * @ha: SCSI driver HA context
1633 * @index: Response queue out pointer
1636 qla24xx_ms_entry(scsi_qla_host_t
*ha
, struct ct_entry_24xx
*pkt
)
1640 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1641 __func__
, ha
->host_no
, pkt
, pkt
->handle
));
1643 DEBUG9(printk("%s: ct pkt dump:\n", __func__
));
1644 DEBUG9(qla2x00_dump_buffer((void *)pkt
, sizeof(struct ct_entry_24xx
)));
1646 /* Validate handle. */
1647 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
1648 sp
= ha
->outstanding_cmds
[pkt
->handle
];
1653 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1655 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1657 qla_printk(KERN_WARNING
, ha
, "MS entry - invalid handle %d\n",
1660 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1664 CMD_COMPL_STATUS(sp
->cmd
) = le16_to_cpu(pkt
->comp_status
);
1665 CMD_ENTRY_STATUS(sp
->cmd
) = pkt
->entry_status
;
1667 /* Free outstanding command slot. */
1668 ha
->outstanding_cmds
[pkt
->handle
] = NULL
;
1670 qla2x00_sp_compl(ha
, sp
);
1674 qla24xx_msix_rsp_q(int irq
, void *dev_id
)
1676 scsi_qla_host_t
*ha
;
1677 struct device_reg_24xx __iomem
*reg
;
1678 unsigned long flags
;
1681 reg
= &ha
->iobase
->isp24
;
1683 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1685 qla24xx_process_response_queue(ha
);
1687 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
1689 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1695 qla24xx_msix_default(int irq
, void *dev_id
)
1697 scsi_qla_host_t
*ha
;
1698 struct device_reg_24xx __iomem
*reg
;
1700 unsigned long flags
;
1706 reg
= &ha
->iobase
->isp24
;
1709 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1711 stat
= RD_REG_DWORD(®
->host_status
);
1712 if (stat
& HSRX_RISC_PAUSED
) {
1713 if (pci_channel_offline(ha
->pdev
))
1716 hccr
= RD_REG_DWORD(®
->hccr
);
1718 qla_printk(KERN_INFO
, ha
, "RISC paused -- HCCR=%x, "
1719 "Dumping firmware!\n", hccr
);
1721 qla2xxx_check_risc_status(ha
);
1723 ha
->isp_ops
->fw_dump(ha
, 1);
1724 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1726 } else if ((stat
& HSRX_RISC_INT
) == 0)
1729 switch (stat
& 0xff) {
1734 qla24xx_mbx_completion(ha
, MSW(stat
));
1735 status
|= MBX_INTERRUPT
;
1740 mb
[1] = RD_REG_WORD(®
->mailbox1
);
1741 mb
[2] = RD_REG_WORD(®
->mailbox2
);
1742 mb
[3] = RD_REG_WORD(®
->mailbox3
);
1743 qla2x00_async_event(ha
, mb
);
1746 qla24xx_process_response_queue(ha
);
1749 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1751 ha
->host_no
, stat
& 0xff));
1754 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
1756 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1758 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
1759 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
1760 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
1761 up(&ha
->mbx_intr_sem
);
1767 /* Interrupt handling helpers. */
1769 struct qla_init_msix_entry
{
1773 irq_handler_t handler
;
1776 static struct qla_init_msix_entry imsix_entries
[QLA_MSIX_ENTRIES
] = {
1777 { QLA_MSIX_DEFAULT
, QLA_MIDX_DEFAULT
,
1778 "qla2xxx (default)", qla24xx_msix_default
},
1780 { QLA_MSIX_RSP_Q
, QLA_MIDX_RSP_Q
,
1781 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q
},
1785 qla24xx_disable_msix(scsi_qla_host_t
*ha
)
1788 struct qla_msix_entry
*qentry
;
1790 for (i
= 0; i
< QLA_MSIX_ENTRIES
; i
++) {
1791 qentry
= &ha
->msix_entries
[imsix_entries
[i
].index
];
1792 if (qentry
->have_irq
)
1793 free_irq(qentry
->msix_vector
, ha
);
1795 pci_disable_msix(ha
->pdev
);
1799 qla24xx_enable_msix(scsi_qla_host_t
*ha
)
1802 struct msix_entry entries
[QLA_MSIX_ENTRIES
];
1803 struct qla_msix_entry
*qentry
;
1805 for (i
= 0; i
< QLA_MSIX_ENTRIES
; i
++)
1806 entries
[i
].entry
= imsix_entries
[i
].entry
;
1808 ret
= pci_enable_msix(ha
->pdev
, entries
, ARRAY_SIZE(entries
));
1810 qla_printk(KERN_WARNING
, ha
,
1811 "MSI-X: Failed to enable support -- %d/%d\n",
1812 QLA_MSIX_ENTRIES
, ret
);
1815 ha
->flags
.msix_enabled
= 1;
1817 for (i
= 0; i
< QLA_MSIX_ENTRIES
; i
++) {
1818 qentry
= &ha
->msix_entries
[imsix_entries
[i
].index
];
1819 qentry
->msix_vector
= entries
[i
].vector
;
1820 qentry
->msix_entry
= entries
[i
].entry
;
1821 qentry
->have_irq
= 0;
1822 ret
= request_irq(qentry
->msix_vector
,
1823 imsix_entries
[i
].handler
, 0, imsix_entries
[i
].name
, ha
);
1825 qla_printk(KERN_WARNING
, ha
,
1826 "MSI-X: Unable to register handler -- %x/%d.\n",
1827 imsix_entries
[i
].index
, ret
);
1828 qla24xx_disable_msix(ha
);
1831 qentry
->have_irq
= 1;
1839 qla2x00_request_irqs(scsi_qla_host_t
*ha
)
1843 /* If possible, enable MSI-X. */
1844 if (!IS_QLA2432(ha
) && !IS_QLA2532(ha
))
1847 if (IS_QLA2432(ha
) && (ha
->chip_revision
< QLA_MSIX_CHIP_REV_24XX
||
1848 !QLA_MSIX_FW_MODE_1(ha
->fw_attributes
))) {
1849 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1850 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1851 ha
->chip_revision
, ha
->fw_attributes
));
1856 ret
= qla24xx_enable_msix(ha
);
1858 DEBUG2(qla_printk(KERN_INFO
, ha
,
1859 "MSI-X: Enabled (0x%X, 0x%X).\n", ha
->chip_revision
,
1860 ha
->fw_attributes
));
1863 qla_printk(KERN_WARNING
, ha
,
1864 "MSI-X: Falling back-to INTa mode -- %d.\n", ret
);
1867 if (!IS_QLA24XX(ha
) && !IS_QLA2532(ha
))
1870 ret
= pci_enable_msi(ha
->pdev
);
1872 DEBUG2(qla_printk(KERN_INFO
, ha
, "MSI: Enabled.\n"));
1873 ha
->flags
.msi_enabled
= 1;
1877 ret
= request_irq(ha
->pdev
->irq
, ha
->isp_ops
->intr_handler
,
1878 IRQF_DISABLED
|IRQF_SHARED
, QLA2XXX_DRIVER_NAME
, ha
);
1880 ha
->flags
.inta_enabled
= 1;
1881 ha
->host
->irq
= ha
->pdev
->irq
;
1883 qla_printk(KERN_WARNING
, ha
,
1884 "Failed to reserve interrupt %d already in use.\n",
1892 qla2x00_free_irqs(scsi_qla_host_t
*ha
)
1895 if (ha
->flags
.msix_enabled
)
1896 qla24xx_disable_msix(ha
);
1897 else if (ha
->flags
.inta_enabled
) {
1898 free_irq(ha
->host
->irq
, ha
);
1899 pci_disable_msi(ha
->pdev
);