2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 static void qla2x00_mbx_completion(scsi_qla_host_t
*, uint16_t);
22 static void qla2x00_async_event(scsi_qla_host_t
*, uint32_t);
23 static void qla2x00_process_completed_request(struct scsi_qla_host
*, uint32_t);
24 void qla2x00_process_response_queue(struct scsi_qla_host
*);
25 static void qla2x00_status_entry(scsi_qla_host_t
*, sts_entry_t
*);
26 static void qla2x00_status_cont_entry(scsi_qla_host_t
*, sts_cont_entry_t
*);
27 static void qla2x00_error_entry(scsi_qla_host_t
*, sts_entry_t
*);
28 static void qla2x00_ms_entry(scsi_qla_host_t
*, ms_iocb_entry_t
*);
31 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
33 * @dev_id: SCSI driver HA context
36 * Called by system whenever the host adapter generates an interrupt.
38 * Returns handled flag.
41 qla2100_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
44 device_reg_t __iomem
*reg
;
50 ha
= (scsi_qla_host_t
*) dev_id
;
53 "%s(): NULL host pointer\n", __func__
);
60 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
61 for (iter
= 50; iter
--; ) {
62 if ((RD_REG_WORD(®
->istatus
) & ISR_RISC_INT
) == 0)
65 if (RD_REG_WORD(®
->semaphore
) & BIT_0
) {
66 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
67 RD_REG_WORD(®
->hccr
);
69 /* Get mailbox data. */
70 mbx
= RD_MAILBOX_REG(ha
, reg
, 0);
71 if (mbx
> 0x3fff && mbx
< 0x8000) {
72 qla2x00_mbx_completion(ha
, (uint16_t)mbx
);
73 status
|= MBX_INTERRUPT
;
74 } else if (mbx
> 0x7fff && mbx
< 0xc000) {
75 qla2x00_async_event(ha
, mbx
);
78 DEBUG2(printk("scsi(%ld): Unrecognized "
79 "interrupt type (%d)\n",
82 /* Release mailbox registers. */
83 WRT_REG_WORD(®
->semaphore
, 0);
84 RD_REG_WORD(®
->semaphore
);
86 qla2x00_process_response_queue(ha
);
88 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
89 RD_REG_WORD(®
->hccr
);
92 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
94 ha
->last_irq_cpu
= _smp_processor_id();
97 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
98 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
99 spin_lock_irqsave(&ha
->mbx_reg_lock
, flags
);
101 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
102 up(&ha
->mbx_intr_sem
);
104 spin_unlock_irqrestore(&ha
->mbx_reg_lock
, flags
);
107 return (IRQ_HANDLED
);
111 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
113 * @dev_id: SCSI driver HA context
116 * Called by system whenever the host adapter generates an interrupt.
118 * Returns handled flag.
121 qla2300_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
124 device_reg_t __iomem
*reg
;
132 ha
= (scsi_qla_host_t
*) dev_id
;
135 "%s(): NULL host pointer\n", __func__
);
142 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
143 for (iter
= 50; iter
--; ) {
144 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
145 if (stat
& HSR_RISC_PAUSED
) {
146 hccr
= RD_REG_WORD(®
->hccr
);
147 if (hccr
& (BIT_15
| BIT_13
| BIT_11
| BIT_8
))
148 qla_printk(KERN_INFO
, ha
,
149 "Parity error -- HCCR=%x.\n", hccr
);
151 qla_printk(KERN_INFO
, ha
,
152 "RISC paused -- HCCR=%x\n", hccr
);
155 * Issue a "HARD" reset in order for the RISC
156 * interrupt bit to be cleared. Schedule a big
157 * hammmer to get out of the RISC PAUSED state.
159 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
160 RD_REG_WORD(®
->hccr
);
161 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
163 } else if ((stat
& HSR_RISC_INT
) == 0)
167 switch (stat
& 0xff) {
169 qla2x00_process_response_queue(ha
);
175 qla2x00_mbx_completion(ha
, (uint16_t)mbx
);
176 status
|= MBX_INTERRUPT
;
178 /* Release mailbox registers. */
179 WRT_REG_WORD(®
->semaphore
, 0);
182 qla2x00_async_event(ha
, mbx
);
185 mbx
= mbx
<< 16 | MBA_CMPLT_1_16BIT
;
186 qla2x00_async_event(ha
, mbx
);
189 mbx
= mbx
<< 16 | MBA_SCSI_COMPLETION
;
190 qla2x00_async_event(ha
, mbx
);
193 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
195 ha
->host_no
, stat
& 0xff));
198 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
199 RD_REG_WORD_RELAXED(®
->hccr
);
201 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
203 ha
->last_irq_cpu
= _smp_processor_id();
206 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
207 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
208 spin_lock_irqsave(&ha
->mbx_reg_lock
, flags
);
210 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
211 up(&ha
->mbx_intr_sem
);
213 spin_unlock_irqrestore(&ha
->mbx_reg_lock
, flags
);
216 return (IRQ_HANDLED
);
220 * qla2x00_mbx_completion() - Process mailbox command completions.
221 * @ha: SCSI driver HA context
222 * @mb0: Mailbox0 register
225 qla2x00_mbx_completion(scsi_qla_host_t
*ha
, uint16_t mb0
)
228 uint16_t __iomem
*wptr
;
229 device_reg_t __iomem
*reg
= ha
->iobase
;
231 /* Load return mailbox registers. */
232 ha
->flags
.mbox_int
= 1;
233 ha
->mailbox_out
[0] = mb0
;
234 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 1);
236 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
237 if (IS_QLA2200(ha
) && cnt
== 8)
238 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 8);
239 if (cnt
== 4 || cnt
== 5)
240 ha
->mailbox_out
[cnt
] = qla2x00_debounce_register(wptr
);
242 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
248 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
249 __func__
, ha
->host_no
, ha
->mcp
->mb
[0]));
251 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
252 __func__
, ha
->host_no
));
257 * qla2x00_async_event() - Process aynchronous events.
258 * @ha: SCSI driver HA context
259 * @mb0: Mailbox0 register
262 qla2x00_async_event(scsi_qla_host_t
*ha
, uint32_t mbx
)
264 static char *link_speeds
[5] = { "1", "2", "4", "?", "10" };
270 device_reg_t __iomem
*reg
= ha
->iobase
;
271 uint32_t rscn_entry
, host_pid
;
272 uint8_t rscn_queue_index
;
274 /* Setup to process RIO completion. */
278 case MBA_SCSI_COMPLETION
:
279 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
280 handles
[0] = le32_to_cpu(
281 ((uint32_t)(RD_MAILBOX_REG(ha
, reg
, 2) << 16)) |
282 RD_MAILBOX_REG(ha
, reg
, 1));
284 handles
[0] = le32_to_cpu(
285 ((uint32_t)(RD_MAILBOX_REG(ha
, reg
, 2) << 16)) |
289 case MBA_CMPLT_1_16BIT
:
290 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
291 handles
[0] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 1);
293 handles
[0] = MSW(mbx
);
295 mb
[0] = MBA_SCSI_COMPLETION
;
297 case MBA_CMPLT_2_16BIT
:
298 handles
[0] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 1);
299 handles
[1] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 2);
301 mb
[0] = MBA_SCSI_COMPLETION
;
303 case MBA_CMPLT_3_16BIT
:
304 handles
[0] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 1);
305 handles
[1] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 2);
306 handles
[2] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 3);
308 mb
[0] = MBA_SCSI_COMPLETION
;
310 case MBA_CMPLT_4_16BIT
:
311 handles
[0] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 1);
312 handles
[1] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 2);
313 handles
[2] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 3);
314 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
316 mb
[0] = MBA_SCSI_COMPLETION
;
318 case MBA_CMPLT_5_16BIT
:
319 handles
[0] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 1);
320 handles
[1] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 2);
321 handles
[2] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 3);
322 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
323 handles
[4] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 7);
325 mb
[0] = MBA_SCSI_COMPLETION
;
327 case MBA_CMPLT_2_32BIT
:
328 handles
[0] = le32_to_cpu(
329 ((uint32_t)(RD_MAILBOX_REG(ha
, reg
, 2) << 16)) |
330 RD_MAILBOX_REG(ha
, reg
, 1));
331 handles
[1] = le32_to_cpu(
332 ((uint32_t)(RD_MAILBOX_REG(ha
, reg
, 7) << 16)) |
333 RD_MAILBOX_REG(ha
, reg
, 6));
335 mb
[0] = MBA_SCSI_COMPLETION
;
342 case MBA_SCSI_COMPLETION
: /* Fast Post */
343 if (!ha
->flags
.online
)
346 for (cnt
= 0; cnt
< handle_cnt
; cnt
++)
347 qla2x00_process_completed_request(ha
, handles
[cnt
]);
350 case MBA_RESET
: /* Reset */
351 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha
->host_no
));
353 set_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
356 case MBA_SYSTEM_ERR
: /* System Error */
357 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
358 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
359 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
361 qla_printk(KERN_INFO
, ha
,
362 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
363 mb
[1], mb
[2], mb
[3]);
365 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
366 qla2100_fw_dump(ha
, 1);
368 qla2300_fw_dump(ha
, 1);
371 qla_printk(KERN_INFO
, ha
,
372 "Unrecoverable Hardware Error: adapter marked "
374 ha
->flags
.online
= 0;
376 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
379 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
380 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
382 qla_printk(KERN_WARNING
, ha
, "ISP Request Transfer Error.\n");
384 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
387 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
388 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
390 qla_printk(KERN_WARNING
, ha
, "ISP Response Transfer Error.\n");
392 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
395 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
396 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
400 case MBA_LIP_OCCURRED
: /* Loop Initialization Procedure */
401 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
403 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha
->host_no
,
405 qla_printk(KERN_INFO
, ha
, "LIP occured (%x).\n", mb
[1]);
407 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
408 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
409 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
410 qla2x00_mark_all_devices_lost(ha
);
413 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
415 ha
->flags
.management_server_logged_in
= 0;
417 /* Update AEN queue. */
418 qla2x00_enqueue_aen(ha
, MBA_LIP_OCCURRED
, NULL
);
423 case MBA_LOOP_UP
: /* Loop Up Event */
424 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
426 ha
->link_data_rate
= 0;
427 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
428 link_speed
= link_speeds
[0];
430 link_speed
= link_speeds
[3];
432 link_speed
= link_speeds
[mb
[1]];
433 ha
->link_data_rate
= mb
[1];
436 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
437 ha
->host_no
, link_speed
));
438 qla_printk(KERN_INFO
, ha
, "LOOP UP detected (%s Gbps).\n",
441 ha
->flags
.management_server_logged_in
= 0;
443 /* Update AEN queue. */
444 qla2x00_enqueue_aen(ha
, MBA_LOOP_UP
, NULL
);
447 case MBA_LOOP_DOWN
: /* Loop Down Event */
448 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN.\n",
450 qla_printk(KERN_INFO
, ha
, "LOOP DOWN detected.\n");
452 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
453 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
454 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
455 ha
->device_flags
|= DFLG_NO_CABLE
;
456 qla2x00_mark_all_devices_lost(ha
);
459 ha
->flags
.management_server_logged_in
= 0;
460 ha
->link_data_rate
= 0;
462 /* Update AEN queue. */
463 qla2x00_enqueue_aen(ha
, MBA_LOOP_DOWN
, NULL
);
466 case MBA_LIP_RESET
: /* LIP reset occurred */
467 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
469 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
470 ha
->host_no
, mb
[1]));
471 qla_printk(KERN_INFO
, ha
,
472 "LIP reset occured (%x).\n", mb
[1]);
474 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
475 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
476 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
477 qla2x00_mark_all_devices_lost(ha
);
480 set_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
482 ha
->operating_mode
= LOOP
;
483 ha
->flags
.management_server_logged_in
= 0;
485 /* Update AEN queue. */
486 qla2x00_enqueue_aen(ha
, MBA_LIP_RESET
, NULL
);
491 case MBA_POINT_TO_POINT
: /* Point-to-Point */
495 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
499 * Until there's a transition from loop down to loop up, treat
500 * this as loop down only.
502 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
503 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
504 if (!atomic_read(&ha
->loop_down_timer
))
505 atomic_set(&ha
->loop_down_timer
,
507 qla2x00_mark_all_devices_lost(ha
);
510 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
))) {
511 set_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
513 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
516 case MBA_CHG_IN_CONNECTION
: /* Change in connection mode */
520 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
522 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
525 qla_printk(KERN_INFO
, ha
,
526 "Configuration change detected: value=%x.\n", mb
[1]);
528 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
529 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
530 if (!atomic_read(&ha
->loop_down_timer
))
531 atomic_set(&ha
->loop_down_timer
,
533 qla2x00_mark_all_devices_lost(ha
);
536 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
537 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
540 case MBA_PORT_UPDATE
: /* Port database update */
541 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
542 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
545 * If a single remote port just logged into (or logged out of)
546 * us, create a new entry in our rscn fcports list and handle
547 * the event like an RSCN.
549 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA6312(ha
) &&
550 !IS_QLA6322(ha
) && ha
->flags
.init_done
&& mb
[1] != 0xffff &&
551 ((ha
->operating_mode
== P2P
&& mb
[1] != 0) ||
552 (ha
->operating_mode
!= P2P
&& mb
[1] !=
553 SNS_FIRST_LOOP_ID
)) && (mb
[2] == 6 || mb
[2] == 7)) {
555 fc_port_t
*rscn_fcport
;
557 /* Create new fcport for login. */
558 rscn_fcport
= qla2x00_alloc_rscn_fcport(ha
, GFP_ATOMIC
);
560 DEBUG14(printk("scsi(%ld): Port Update -- "
561 "creating RSCN fcport %p for %x/%x.\n",
562 ha
->host_no
, rscn_fcport
, mb
[1], mb
[2]));
564 rscn_fcport
->loop_id
= mb
[1];
565 rscn_fcport
->d_id
.b24
= INVALID_PORT_ID
;
566 atomic_set(&rscn_fcport
->state
,
568 list_add_tail(&rscn_fcport
->list
,
571 rval
= qla2x00_handle_port_rscn(ha
, 0,
573 if (rval
== QLA_SUCCESS
)
576 DEBUG14(printk("scsi(%ld): Port Update -- "
577 "-- unable to allocate RSCN fcport "
578 "login.\n", ha
->host_no
));
583 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
584 * event etc. earlier indicating loop is down) then process
585 * it. Otherwise ignore it and Wait for RSCN to come in.
587 atomic_set(&ha
->loop_down_timer
, 0);
588 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
&&
589 atomic_read(&ha
->loop_state
) != LOOP_DEAD
) {
590 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
591 "ignored.\n", ha
->host_no
));
595 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
597 DEBUG(printk(KERN_INFO
598 "scsi(%ld): Port database changed %04x %04x.\n",
599 ha
->host_no
, mb
[1], mb
[2]));
602 * Mark all devices as missing so we will login again.
604 atomic_set(&ha
->loop_state
, LOOP_UP
);
606 qla2x00_mark_all_devices_lost(ha
);
608 ha
->flags
.rscn_queue_overflow
= 1;
610 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
611 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
613 /* Update AEN queue. */
614 qla2x00_enqueue_aen(ha
, MBA_PORT_UPDATE
, NULL
);
617 case MBA_RSCN_UPDATE
: /* State Change Registration */
618 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
619 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
621 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
623 DEBUG(printk(KERN_INFO
624 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
625 ha
->host_no
, mb
[1], mb
[2]));
627 rscn_entry
= (mb
[1] << 16) | mb
[2];
628 host_pid
= (ha
->d_id
.b
.domain
<< 16) | (ha
->d_id
.b
.area
<< 8) |
630 if (rscn_entry
== host_pid
) {
631 DEBUG(printk(KERN_INFO
632 "scsi(%ld): Ignoring RSCN update to local host "
634 ha
->host_no
, host_pid
));
638 rscn_queue_index
= ha
->rscn_in_ptr
+ 1;
639 if (rscn_queue_index
== MAX_RSCN_COUNT
)
640 rscn_queue_index
= 0;
641 if (rscn_queue_index
!= ha
->rscn_out_ptr
) {
642 ha
->rscn_queue
[ha
->rscn_in_ptr
] = rscn_entry
;
643 ha
->rscn_in_ptr
= rscn_queue_index
;
645 ha
->flags
.rscn_queue_overflow
= 1;
648 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
649 atomic_set(&ha
->loop_down_timer
, 0);
650 ha
->flags
.management_server_logged_in
= 0;
652 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
653 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
655 /* Update AEN queue. */
656 qla2x00_enqueue_aen(ha
, MBA_RSCN_UPDATE
, &mb
[0]);
659 /* case MBA_RIO_RESPONSE: */
660 case MBA_ZIO_RESPONSE
:
661 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
663 DEBUG(printk(KERN_INFO
664 "scsi(%ld): [R|Z]IO update completion.\n",
667 qla2x00_process_response_queue(ha
);
673 * qla2x00_process_completed_request() - Process a Fast Post response.
674 * @ha: SCSI driver HA context
678 qla2x00_process_completed_request(struct scsi_qla_host
*ha
, uint32_t index
)
682 /* Validate handle. */
683 if (index
>= MAX_OUTSTANDING_COMMANDS
) {
684 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
685 ha
->host_no
, index
));
686 qla_printk(KERN_WARNING
, ha
,
687 "Invalid SCSI completion handle %d.\n", index
);
689 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
693 sp
= ha
->outstanding_cmds
[index
];
695 /* Free outstanding command slot. */
696 ha
->outstanding_cmds
[index
] = NULL
;
700 CMD_COMPL_STATUS(sp
->cmd
) = 0L;
701 CMD_SCSI_STATUS(sp
->cmd
) = 0L;
703 /* Save ISP completion status */
704 sp
->cmd
->result
= DID_OK
<< 16;
705 sp
->fo_retry_cnt
= 0;
706 qla2x00_sp_compl(ha
, sp
);
708 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
710 qla_printk(KERN_WARNING
, ha
,
711 "Invalid ISP SCSI completion handle\n");
713 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
718 * qla2x00_process_response_queue() - Process response queue entries.
719 * @ha: SCSI driver HA context
722 qla2x00_process_response_queue(struct scsi_qla_host
*ha
)
724 device_reg_t __iomem
*reg
= ha
->iobase
;
729 if (!ha
->flags
.online
)
732 while (ha
->response_ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
733 pkt
= (sts_entry_t
*)ha
->response_ring_ptr
;
735 ha
->rsp_ring_index
++;
736 if (ha
->rsp_ring_index
== ha
->response_q_length
) {
737 ha
->rsp_ring_index
= 0;
738 ha
->response_ring_ptr
= ha
->response_ring
;
740 ha
->response_ring_ptr
++;
743 if (pkt
->entry_status
!= 0) {
744 DEBUG3(printk(KERN_INFO
745 "scsi(%ld): Process error entry.\n", ha
->host_no
));
747 qla2x00_error_entry(ha
, pkt
);
748 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
753 switch (pkt
->entry_type
) {
755 qla2x00_status_entry(ha
, pkt
);
758 handle_cnt
= ((sts21_entry_t
*)pkt
)->handle_count
;
759 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
760 qla2x00_process_completed_request(ha
,
761 ((sts21_entry_t
*)pkt
)->handle
[cnt
]);
765 handle_cnt
= ((sts22_entry_t
*)pkt
)->handle_count
;
766 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
767 qla2x00_process_completed_request(ha
,
768 ((sts22_entry_t
*)pkt
)->handle
[cnt
]);
771 case STATUS_CONT_TYPE
:
772 qla2x00_status_cont_entry(ha
, (sts_cont_entry_t
*)pkt
);
775 qla2x00_ms_entry(ha
, (ms_iocb_entry_t
*)pkt
);
778 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) &&
779 !IS_QLA6312(ha
) && !IS_QLA6322(ha
)) {
780 if (pkt
->sys_define
== SOURCE_ASYNC_IOCB
) {
781 qla2x00_process_iodesc(ha
,
782 (struct mbx_entry
*)pkt
);
784 /* MBX IOCB Type Not Supported. */
785 DEBUG4(printk(KERN_WARNING
786 "scsi(%ld): Received unknown MBX "
787 "IOCB response pkt type=%x "
788 "source=%x entry status=%x.\n",
789 ha
->host_no
, pkt
->entry_type
,
797 /* Type Not Supported. */
798 DEBUG4(printk(KERN_WARNING
799 "scsi(%ld): Received unknown response pkt type %x "
800 "entry status=%x.\n",
801 ha
->host_no
, pkt
->entry_type
, pkt
->entry_status
));
804 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
808 /* Adjust ring index */
809 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), ha
->rsp_ring_index
);
813 * qla2x00_status_entry() - Process a Status IOCB entry.
814 * @ha: SCSI driver HA context
815 * @pkt: Entry pointer
818 qla2x00_status_entry(scsi_qla_host_t
*ha
, sts_entry_t
*pkt
)
823 struct scsi_cmnd
*cp
;
824 uint16_t comp_status
;
825 uint16_t scsi_status
;
826 uint8_t lscsi_status
;
828 uint8_t sense_sz
= 0;
829 uint16_t rsp_info_len
;
831 /* Fast path completion. */
832 if (le16_to_cpu(pkt
->comp_status
) == CS_COMPLETE
&&
833 (le16_to_cpu(pkt
->scsi_status
) & SS_MASK
) == 0) {
834 qla2x00_process_completed_request(ha
, pkt
->handle
);
839 /* Validate handle. */
840 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
) {
841 sp
= ha
->outstanding_cmds
[pkt
->handle
];
842 ha
->outstanding_cmds
[pkt
->handle
] = NULL
;
847 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
849 qla_printk(KERN_WARNING
, ha
, "Status Entry invalid handle.\n");
851 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
852 if (ha
->dpc_wait
&& !ha
->dpc_active
)
859 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
860 "pkt->handle=%d sp=%p sp->state:%d\n",
861 ha
->host_no
, pkt
->handle
, sp
, sp
->state
));
862 qla_printk(KERN_WARNING
, ha
,
863 "Command is NULL: already returned to OS (sp=%p)\n", sp
);
871 comp_status
= le16_to_cpu(pkt
->comp_status
);
872 /* Mask of reserved bits 12-15, before we examine the scsi status */
873 scsi_status
= le16_to_cpu(pkt
->scsi_status
) & SS_MASK
;
874 lscsi_status
= scsi_status
& STATUS_MASK
;
876 CMD_ENTRY_STATUS(cp
) = pkt
->entry_status
;
877 CMD_COMPL_STATUS(cp
) = comp_status
;
878 CMD_SCSI_STATUS(cp
) = scsi_status
;
880 /* Generate LU queue on cntrl, target, LUN */
881 b
= cp
->device
->channel
;
887 /* Check for any FCP transport errors. */
888 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
) {
889 rsp_info_len
= le16_to_cpu(pkt
->rsp_info_len
);
890 if (rsp_info_len
> 3 && pkt
->rsp_info
[3]) {
891 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
892 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
893 "retrying command\n", ha
->host_no
, b
, t
, l
,
894 rsp_info_len
, pkt
->rsp_info
[0], pkt
->rsp_info
[1],
895 pkt
->rsp_info
[2], pkt
->rsp_info
[3],
896 pkt
->rsp_info
[4], pkt
->rsp_info
[5],
897 pkt
->rsp_info
[6], pkt
->rsp_info
[7]));
899 cp
->result
= DID_BUS_BUSY
<< 16;
900 qla2x00_sp_compl(ha
, sp
);
906 * Based on Host and scsi status generate status code for Linux
908 switch (comp_status
) {
910 if (scsi_status
== 0) {
911 cp
->result
= DID_OK
<< 16;
914 if (scsi_status
& (SS_RESIDUAL_UNDER
| SS_RESIDUAL_OVER
)) {
915 resid
= le32_to_cpu(pkt
->residual_length
);
917 CMD_RESID_LEN(cp
) = resid
;
919 cp
->result
= DID_OK
<< 16 | lscsi_status
;
921 if (lscsi_status
!= SS_CHECK_CONDITION
)
925 * Copy Sense Data into sense buffer
927 memset(cp
->sense_buffer
, 0, sizeof(cp
->sense_buffer
));
929 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
932 if (le16_to_cpu(pkt
->req_sense_length
) <
933 sizeof(cp
->sense_buffer
))
934 sense_sz
= le16_to_cpu(pkt
->req_sense_length
);
936 sense_sz
= sizeof(cp
->sense_buffer
);
938 CMD_ACTUAL_SNSLEN(cp
) = sense_sz
;
939 sp
->request_sense_length
= sense_sz
;
940 sp
->request_sense_ptr
= cp
->sense_buffer
;
942 if (sp
->request_sense_length
> 32)
945 memcpy(cp
->sense_buffer
, pkt
->req_sense_data
, sense_sz
);
947 sp
->request_sense_ptr
+= sense_sz
;
948 sp
->request_sense_length
-= sense_sz
;
949 if (sp
->request_sense_length
!= 0)
952 DEBUG5(printk("%s(): Check condition Sense data, "
953 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
954 __func__
, ha
->host_no
, b
, t
, l
, cp
,
957 DEBUG5(qla2x00_dump_buffer(cp
->sense_buffer
,
958 CMD_ACTUAL_SNSLEN(cp
)));
961 case CS_DATA_UNDERRUN
:
962 DEBUG2(printk(KERN_INFO
963 "scsi(%ld:%d:%d) UNDERRUN status detected 0x%x-0x%x.\n",
964 ha
->host_no
, t
, l
, comp_status
, scsi_status
));
966 resid
= le32_to_cpu(pkt
->residual_length
);
967 if (scsi_status
& SS_RESIDUAL_UNDER
) {
969 CMD_RESID_LEN(cp
) = resid
;
973 * Check to see if SCSI Status is non zero. If so report SCSI
976 if (lscsi_status
!= 0) {
977 cp
->result
= DID_OK
<< 16 | lscsi_status
;
979 if (lscsi_status
!= SS_CHECK_CONDITION
)
982 /* Copy Sense Data into sense buffer */
983 memset(cp
->sense_buffer
, 0, sizeof(cp
->sense_buffer
));
985 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
988 if (le16_to_cpu(pkt
->req_sense_length
) <
989 sizeof(cp
->sense_buffer
))
990 sense_sz
= le16_to_cpu(pkt
->req_sense_length
);
992 sense_sz
= sizeof(cp
->sense_buffer
);
994 CMD_ACTUAL_SNSLEN(cp
) = sense_sz
;
995 sp
->request_sense_length
= sense_sz
;
996 sp
->request_sense_ptr
= cp
->sense_buffer
;
998 if (sp
->request_sense_length
> 32)
1001 memcpy(cp
->sense_buffer
, pkt
->req_sense_data
, sense_sz
);
1003 sp
->request_sense_ptr
+= sense_sz
;
1004 sp
->request_sense_length
-= sense_sz
;
1005 if (sp
->request_sense_length
!= 0)
1006 ha
->status_srb
= sp
;
1008 DEBUG5(printk("%s(): Check condition Sense data, "
1009 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
1010 __func__
, ha
->host_no
, b
, t
, l
, cp
,
1011 cp
->serial_number
));
1013 DEBUG5(qla2x00_dump_buffer(cp
->sense_buffer
,
1014 CMD_ACTUAL_SNSLEN(cp
)));
1017 * If RISC reports underrun and target does not report
1018 * it then we must have a lost frame, so tell upper
1019 * layer to retry it by reporting a bus busy.
1021 if (!(scsi_status
& SS_RESIDUAL_UNDER
)) {
1022 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1023 "frame(s) detected (%x of %x bytes)..."
1024 "retrying command.\n",
1025 ha
->host_no
, b
, t
, l
, resid
,
1026 cp
->request_bufflen
));
1028 cp
->result
= DID_BUS_BUSY
<< 16;
1029 ha
->dropped_frame_error_cnt
++;
1033 /* Handle mid-layer underflow */
1034 if ((unsigned)(cp
->request_bufflen
- resid
) <
1036 qla_printk(KERN_INFO
, ha
,
1037 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1038 "detected (%x of %x bytes)...returning "
1040 ha
->host_no
, b
, t
, l
, resid
,
1041 cp
->request_bufflen
);
1043 cp
->result
= DID_ERROR
<< 16;
1047 /* Everybody online, looking good... */
1048 cp
->result
= DID_OK
<< 16;
1052 case CS_DATA_OVERRUN
:
1053 DEBUG2(printk(KERN_INFO
1054 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1055 ha
->host_no
, t
, l
, comp_status
, scsi_status
));
1056 DEBUG2(printk(KERN_INFO
1057 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1058 cp
->cmnd
[0], cp
->cmnd
[1], cp
->cmnd
[2], cp
->cmnd
[3],
1059 cp
->cmnd
[4], cp
->cmnd
[5]));
1060 DEBUG2(printk(KERN_INFO
1061 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1063 cp
->serial_number
, cp
->request_bufflen
,
1064 le32_to_cpu(pkt
->residual_length
)));
1066 cp
->result
= DID_ERROR
<< 16;
1069 case CS_PORT_LOGGED_OUT
:
1070 case CS_PORT_CONFIG_CHG
:
1073 case CS_PORT_UNAVAILABLE
:
1075 * If the port is in Target Down state, return all IOs for this
1076 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1079 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1080 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1081 ha
->host_no
, t
, l
, cp
->serial_number
, comp_status
,
1082 atomic_read(&fcport
->state
)));
1084 cp
->result
= DID_BUS_BUSY
<< 16;
1085 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
1086 qla2x00_mark_device_lost(ha
, fcport
, 1);
1091 DEBUG2(printk(KERN_INFO
1092 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1093 ha
->host_no
, comp_status
, scsi_status
));
1095 cp
->result
= DID_RESET
<< 16;
1100 * hv2.19.12 - DID_ABORT does not retry the request if we
1101 * aborted this request then abort otherwise it must be a
1104 DEBUG2(printk(KERN_INFO
1105 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1106 ha
->host_no
, comp_status
, scsi_status
));
1108 cp
->result
= DID_RESET
<< 16;
1112 DEBUG2(printk(KERN_INFO
1113 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1114 "sflags=%x.\n", ha
->host_no
, b
, t
, l
, comp_status
,
1115 scsi_status
, le16_to_cpu(pkt
->status_flags
)));
1117 cp
->result
= DID_BUS_BUSY
<< 16;
1119 /* Check to see if logout occurred */
1120 if ((le16_to_cpu(pkt
->status_flags
) & SF_LOGOUT_SENT
)) {
1121 qla2x00_mark_device_lost(ha
, fcport
, 1);
1126 DEBUG2(printk(KERN_INFO
1127 "scsi(%ld): QUEUE FULL status detected 0x%x-0x%x.\n",
1128 ha
->host_no
, comp_status
, scsi_status
));
1130 /* SCSI Mid-Layer handles device queue full */
1132 cp
->result
= DID_OK
<< 16 | lscsi_status
;
1137 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1139 ha
->host_no
, comp_status
, scsi_status
));
1140 qla_printk(KERN_INFO
, ha
,
1141 "Unknown status detected 0x%x-0x%x.\n",
1142 comp_status
, scsi_status
);
1144 cp
->result
= DID_ERROR
<< 16;
1148 /* Place command on done queue. */
1149 if (ha
->status_srb
== NULL
)
1150 qla2x00_sp_compl(ha
, sp
);
1154 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1155 * @ha: SCSI driver HA context
1156 * @pkt: Entry pointer
1158 * Extended sense data.
1161 qla2x00_status_cont_entry(scsi_qla_host_t
*ha
, sts_cont_entry_t
*pkt
)
1163 uint8_t sense_sz
= 0;
1164 srb_t
*sp
= ha
->status_srb
;
1165 struct scsi_cmnd
*cp
;
1167 if (sp
!= NULL
&& sp
->request_sense_length
!= 0) {
1170 DEBUG2(printk("%s(): Cmd already returned back to OS "
1171 "sp=%p sp->state:%d\n", __func__
, sp
, sp
->state
));
1172 qla_printk(KERN_INFO
, ha
,
1173 "cmd is NULL: already returned to OS (sp=%p)\n",
1176 ha
->status_srb
= NULL
;
1180 if (sp
->request_sense_length
> sizeof(pkt
->data
)) {
1181 sense_sz
= sizeof(pkt
->data
);
1183 sense_sz
= sp
->request_sense_length
;
1186 /* Move sense data. */
1187 memcpy(sp
->request_sense_ptr
, pkt
->data
, sense_sz
);
1188 DEBUG5(qla2x00_dump_buffer(sp
->request_sense_ptr
, sense_sz
));
1190 sp
->request_sense_ptr
+= sense_sz
;
1191 sp
->request_sense_length
-= sense_sz
;
1193 /* Place command on done queue. */
1194 if (sp
->request_sense_length
== 0) {
1195 ha
->status_srb
= NULL
;
1196 qla2x00_sp_compl(ha
, sp
);
1202 * qla2x00_error_entry() - Process an error entry.
1203 * @ha: SCSI driver HA context
1204 * @pkt: Entry pointer
1207 qla2x00_error_entry(scsi_qla_host_t
*ha
, sts_entry_t
*pkt
)
1211 #if defined(QL_DEBUG_LEVEL_2)
1212 if (pkt
->entry_status
& RF_INV_E_ORDER
)
1213 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Order\n", __func__
);
1214 else if (pkt
->entry_status
& RF_INV_E_COUNT
)
1215 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Count\n", __func__
);
1216 else if (pkt
->entry_status
& RF_INV_E_PARAM
)
1217 qla_printk(KERN_ERR
, ha
,
1218 "%s: Invalid Entry Parameter\n", __func__
);
1219 else if (pkt
->entry_status
& RF_INV_E_TYPE
)
1220 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Type\n", __func__
);
1221 else if (pkt
->entry_status
& RF_BUSY
)
1222 qla_printk(KERN_ERR
, ha
, "%s: Busy\n", __func__
);
1224 qla_printk(KERN_ERR
, ha
, "%s: UNKNOWN flag error\n", __func__
);
1227 /* Validate handle. */
1228 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
1229 sp
= ha
->outstanding_cmds
[pkt
->handle
];
1234 /* Free outstanding command slot. */
1235 ha
->outstanding_cmds
[pkt
->handle
] = NULL
;
1238 /* Bad payload or header */
1239 if (pkt
->entry_status
&
1240 (RF_INV_E_ORDER
| RF_INV_E_COUNT
|
1241 RF_INV_E_PARAM
| RF_INV_E_TYPE
)) {
1242 sp
->cmd
->result
= DID_ERROR
<< 16;
1243 } else if (pkt
->entry_status
& RF_BUSY
) {
1244 sp
->cmd
->result
= DID_BUS_BUSY
<< 16;
1246 sp
->cmd
->result
= DID_ERROR
<< 16;
1248 qla2x00_sp_compl(ha
, sp
);
1250 } else if (pkt
->entry_type
== COMMAND_A64_TYPE
||
1251 pkt
->entry_type
== COMMAND_TYPE
) {
1252 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1254 qla_printk(KERN_WARNING
, ha
,
1255 "Error entry - invalid handle\n");
1257 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1258 if (ha
->dpc_wait
&& !ha
->dpc_active
)
1264 * qla2x00_ms_entry() - Process a Management Server entry.
1265 * @ha: SCSI driver HA context
1266 * @index: Response queue out pointer
1269 qla2x00_ms_entry(scsi_qla_host_t
*ha
, ms_iocb_entry_t
*pkt
)
1273 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1274 __func__
, ha
->host_no
, pkt
, pkt
->handle1
));
1276 /* Validate handle. */
1277 if (pkt
->handle1
< MAX_OUTSTANDING_COMMANDS
)
1278 sp
= ha
->outstanding_cmds
[pkt
->handle1
];
1283 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1285 qla_printk(KERN_WARNING
, ha
, "MS entry - invalid handle\n");
1287 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1291 CMD_COMPL_STATUS(sp
->cmd
) = le16_to_cpu(pkt
->status
);
1292 CMD_ENTRY_STATUS(sp
->cmd
) = pkt
->entry_status
;
1294 /* Free outstanding command slot. */
1295 ha
->outstanding_cmds
[pkt
->handle1
] = NULL
;
1297 qla2x00_sp_compl(ha
, sp
);