2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2005 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
*, uint16_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
*, void *);
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
*);
30 void qla24xx_process_response_queue(scsi_qla_host_t
*);
31 static void qla24xx_ms_entry(scsi_qla_host_t
*, struct ct_entry_24xx
*);
34 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
36 * @dev_id: SCSI driver HA context
39 * Called by system whenever the host adapter generates an interrupt.
41 * Returns handled flag.
44 qla2100_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
47 struct device_reg_2xxx __iomem
*reg
;
53 ha
= (scsi_qla_host_t
*) dev_id
;
56 "%s(): NULL host pointer\n", __func__
);
60 reg
= &ha
->iobase
->isp
;
63 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
64 for (iter
= 50; iter
--; ) {
65 if ((RD_REG_WORD(®
->istatus
) & ISR_RISC_INT
) == 0)
68 if (RD_REG_WORD(®
->semaphore
) & BIT_0
) {
69 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
70 RD_REG_WORD(®
->hccr
);
72 /* Get mailbox data. */
73 mb
[0] = RD_MAILBOX_REG(ha
, reg
, 0);
74 if (mb
[0] > 0x3fff && mb
[0] < 0x8000) {
75 qla2x00_mbx_completion(ha
, mb
[0]);
76 status
|= MBX_INTERRUPT
;
77 } else if (mb
[0] > 0x7fff && mb
[0] < 0xc000) {
78 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
79 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
80 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
81 qla2x00_async_event(ha
, mb
);
84 DEBUG2(printk("scsi(%ld): Unrecognized "
85 "interrupt type (%d).\n",
88 /* Release mailbox registers. */
89 WRT_REG_WORD(®
->semaphore
, 0);
90 RD_REG_WORD(®
->semaphore
);
92 qla2x00_process_response_queue(ha
);
94 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
95 RD_REG_WORD(®
->hccr
);
98 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
100 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
101 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
102 spin_lock_irqsave(&ha
->mbx_reg_lock
, flags
);
104 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
105 up(&ha
->mbx_intr_sem
);
107 spin_unlock_irqrestore(&ha
->mbx_reg_lock
, flags
);
110 return (IRQ_HANDLED
);
114 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
116 * @dev_id: SCSI driver HA context
119 * Called by system whenever the host adapter generates an interrupt.
121 * Returns handled flag.
124 qla2300_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
127 struct device_reg_2xxx __iomem
*reg
;
135 ha
= (scsi_qla_host_t
*) dev_id
;
138 "%s(): NULL host pointer\n", __func__
);
142 reg
= &ha
->iobase
->isp
;
145 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
146 for (iter
= 50; iter
--; ) {
147 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
148 if (stat
& HSR_RISC_PAUSED
) {
149 hccr
= RD_REG_WORD(®
->hccr
);
150 if (hccr
& (BIT_15
| BIT_13
| BIT_11
| BIT_8
))
151 qla_printk(KERN_INFO
, ha
,
152 "Parity error -- HCCR=%x.\n", hccr
);
154 qla_printk(KERN_INFO
, ha
,
155 "RISC paused -- HCCR=%x.\n", hccr
);
158 * Issue a "HARD" reset in order for the RISC
159 * interrupt bit to be cleared. Schedule a big
160 * hammmer to get out of the RISC PAUSED state.
162 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
163 RD_REG_WORD(®
->hccr
);
164 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
166 } else if ((stat
& HSR_RISC_INT
) == 0)
169 switch (stat
& 0xff) {
174 qla2x00_mbx_completion(ha
, MSW(stat
));
175 status
|= MBX_INTERRUPT
;
177 /* Release mailbox registers. */
178 WRT_REG_WORD(®
->semaphore
, 0);
182 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
183 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
184 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
185 qla2x00_async_event(ha
, mb
);
188 qla2x00_process_response_queue(ha
);
191 mb
[0] = MBA_CMPLT_1_16BIT
;
193 qla2x00_async_event(ha
, mb
);
196 mb
[0] = MBA_SCSI_COMPLETION
;
198 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
199 qla2x00_async_event(ha
, mb
);
202 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
204 ha
->host_no
, stat
& 0xff));
207 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
208 RD_REG_WORD_RELAXED(®
->hccr
);
210 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
212 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
213 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
214 spin_lock_irqsave(&ha
->mbx_reg_lock
, flags
);
216 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
217 up(&ha
->mbx_intr_sem
);
219 spin_unlock_irqrestore(&ha
->mbx_reg_lock
, flags
);
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", "10" };
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_QLA24XX(ha
) || IS_QLA25XX(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
);
409 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
411 ha
->flags
.management_server_logged_in
= 0;
413 /* Update AEN queue. */
414 qla2x00_enqueue_aen(ha
, MBA_LIP_OCCURRED
, NULL
);
418 case MBA_LOOP_UP
: /* Loop Up Event */
419 ha
->link_data_rate
= 0;
420 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
421 link_speed
= link_speeds
[0];
423 link_speed
= link_speeds
[LS_UNKNOWN
];
425 link_speed
= link_speeds
[mb
[1]];
426 ha
->link_data_rate
= mb
[1];
429 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
430 ha
->host_no
, link_speed
));
431 qla_printk(KERN_INFO
, ha
, "LOOP UP detected (%s Gbps).\n",
434 ha
->flags
.management_server_logged_in
= 0;
436 /* Update AEN queue. */
437 qla2x00_enqueue_aen(ha
, MBA_LOOP_UP
, NULL
);
440 case MBA_LOOP_DOWN
: /* Loop Down Event */
441 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
442 ha
->host_no
, mb
[1]));
443 qla_printk(KERN_INFO
, ha
, "LOOP DOWN detected (%x).\n", mb
[1]);
445 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
446 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
447 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
448 ha
->device_flags
|= DFLG_NO_CABLE
;
449 qla2x00_mark_all_devices_lost(ha
);
452 ha
->flags
.management_server_logged_in
= 0;
453 ha
->link_data_rate
= 0;
455 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
457 /* Update AEN queue. */
458 qla2x00_enqueue_aen(ha
, MBA_LOOP_DOWN
, NULL
);
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
);
473 set_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
475 ha
->operating_mode
= LOOP
;
476 ha
->flags
.management_server_logged_in
= 0;
478 /* Update AEN queue. */
479 qla2x00_enqueue_aen(ha
, MBA_LIP_RESET
, NULL
);
483 case MBA_POINT_TO_POINT
: /* Point-to-Point */
487 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
491 * Until there's a transition from loop down to loop up, treat
492 * this as loop down only.
494 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
495 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
496 if (!atomic_read(&ha
->loop_down_timer
))
497 atomic_set(&ha
->loop_down_timer
,
499 qla2x00_mark_all_devices_lost(ha
);
502 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
))) {
503 set_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
505 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
508 case MBA_CHG_IN_CONNECTION
: /* Change in connection mode */
512 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
515 qla_printk(KERN_INFO
, ha
,
516 "Configuration change detected: value=%x.\n", mb
[1]);
518 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
519 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
520 if (!atomic_read(&ha
->loop_down_timer
))
521 atomic_set(&ha
->loop_down_timer
,
523 qla2x00_mark_all_devices_lost(ha
);
526 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
527 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
530 case MBA_PORT_UPDATE
: /* Port database update */
532 * If a single remote port just logged into (or logged out of)
533 * us, create a new entry in our rscn fcports list and handle
534 * the event like an RSCN.
536 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA6312(ha
) &&
537 !IS_QLA6322(ha
) && !IS_QLA24XX(ha
) && !IS_QLA25XX(ha
) &&
538 ha
->flags
.init_done
&& mb
[1] != 0xffff &&
539 ((ha
->operating_mode
== P2P
&& mb
[1] != 0) ||
540 (ha
->operating_mode
!= P2P
&& mb
[1] !=
541 SNS_FIRST_LOOP_ID
)) && (mb
[2] == 6 || mb
[2] == 7)) {
543 fc_port_t
*rscn_fcport
;
545 /* Create new fcport for login. */
546 rscn_fcport
= qla2x00_alloc_rscn_fcport(ha
, GFP_ATOMIC
);
548 DEBUG14(printk("scsi(%ld): Port Update -- "
549 "creating RSCN fcport %p for %x/%x/%x.\n",
550 ha
->host_no
, rscn_fcport
, mb
[1], mb
[2],
553 rscn_fcport
->loop_id
= mb
[1];
554 rscn_fcport
->d_id
.b24
= INVALID_PORT_ID
;
555 atomic_set(&rscn_fcport
->state
,
557 list_add_tail(&rscn_fcport
->list
,
560 rval
= qla2x00_handle_port_rscn(ha
, 0,
562 if (rval
== QLA_SUCCESS
)
565 DEBUG14(printk("scsi(%ld): Port Update -- "
566 "-- unable to allocate RSCN fcport "
567 "login.\n", ha
->host_no
));
572 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
573 * event etc. earlier indicating loop is down) then process
574 * it. Otherwise ignore it and Wait for RSCN to come in.
576 atomic_set(&ha
->loop_down_timer
, 0);
577 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
&&
578 atomic_read(&ha
->loop_state
) != LOOP_DEAD
) {
579 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
580 "ignored %04x/%04x/%04x.\n", ha
->host_no
, mb
[1],
585 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
587 DEBUG(printk(KERN_INFO
588 "scsi(%ld): Port database changed %04x %04x %04x.\n",
589 ha
->host_no
, mb
[1], mb
[2], mb
[3]));
592 * Mark all devices as missing so we will login again.
594 atomic_set(&ha
->loop_state
, LOOP_UP
);
596 qla2x00_mark_all_devices_lost(ha
);
598 ha
->flags
.rscn_queue_overflow
= 1;
600 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
601 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
603 /* Update AEN queue. */
604 qla2x00_enqueue_aen(ha
, MBA_PORT_UPDATE
, NULL
);
607 case MBA_RSCN_UPDATE
: /* State Change Registration */
608 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
610 DEBUG(printk(KERN_INFO
611 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
612 ha
->host_no
, mb
[1], mb
[2]));
614 rscn_entry
= (mb
[1] << 16) | mb
[2];
615 host_pid
= (ha
->d_id
.b
.domain
<< 16) | (ha
->d_id
.b
.area
<< 8) |
617 if (rscn_entry
== host_pid
) {
618 DEBUG(printk(KERN_INFO
619 "scsi(%ld): Ignoring RSCN update to local host "
621 ha
->host_no
, host_pid
));
625 rscn_queue_index
= ha
->rscn_in_ptr
+ 1;
626 if (rscn_queue_index
== MAX_RSCN_COUNT
)
627 rscn_queue_index
= 0;
628 if (rscn_queue_index
!= ha
->rscn_out_ptr
) {
629 ha
->rscn_queue
[ha
->rscn_in_ptr
] = rscn_entry
;
630 ha
->rscn_in_ptr
= rscn_queue_index
;
632 ha
->flags
.rscn_queue_overflow
= 1;
635 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
636 atomic_set(&ha
->loop_down_timer
, 0);
637 ha
->flags
.management_server_logged_in
= 0;
639 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
640 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
642 /* Update AEN queue. */
643 qla2x00_enqueue_aen(ha
, MBA_RSCN_UPDATE
, &mb
[0]);
646 /* case MBA_RIO_RESPONSE: */
647 case MBA_ZIO_RESPONSE
:
648 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
650 DEBUG(printk(KERN_INFO
651 "scsi(%ld): [R|Z]IO update completion.\n",
654 qla2x00_process_response_queue(ha
);
657 case MBA_DISCARD_RND_FRAME
:
658 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
659 "%04x.\n", ha
->host_no
, mb
[1], mb
[2], mb
[3]));
665 * qla2x00_process_completed_request() - Process a Fast Post response.
666 * @ha: SCSI driver HA context
670 qla2x00_process_completed_request(struct scsi_qla_host
*ha
, uint32_t index
)
674 /* Validate handle. */
675 if (index
>= MAX_OUTSTANDING_COMMANDS
) {
676 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
677 ha
->host_no
, index
));
678 qla_printk(KERN_WARNING
, ha
,
679 "Invalid SCSI completion handle %d.\n", index
);
681 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
685 sp
= ha
->outstanding_cmds
[index
];
687 /* Free outstanding command slot. */
688 ha
->outstanding_cmds
[index
] = NULL
;
690 CMD_COMPL_STATUS(sp
->cmd
) = 0L;
691 CMD_SCSI_STATUS(sp
->cmd
) = 0L;
693 /* Save ISP completion status */
694 sp
->cmd
->result
= DID_OK
<< 16;
695 qla2x00_sp_compl(ha
, sp
);
697 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
699 qla_printk(KERN_WARNING
, ha
,
700 "Invalid ISP SCSI completion handle\n");
702 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
707 * qla2x00_process_response_queue() - Process response queue entries.
708 * @ha: SCSI driver HA context
711 qla2x00_process_response_queue(struct scsi_qla_host
*ha
)
713 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
718 if (!ha
->flags
.online
)
721 while (ha
->response_ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
722 pkt
= (sts_entry_t
*)ha
->response_ring_ptr
;
724 ha
->rsp_ring_index
++;
725 if (ha
->rsp_ring_index
== ha
->response_q_length
) {
726 ha
->rsp_ring_index
= 0;
727 ha
->response_ring_ptr
= ha
->response_ring
;
729 ha
->response_ring_ptr
++;
732 if (pkt
->entry_status
!= 0) {
733 DEBUG3(printk(KERN_INFO
734 "scsi(%ld): Process error entry.\n", ha
->host_no
));
736 qla2x00_error_entry(ha
, pkt
);
737 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
742 switch (pkt
->entry_type
) {
744 qla2x00_status_entry(ha
, pkt
);
747 handle_cnt
= ((sts21_entry_t
*)pkt
)->handle_count
;
748 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
749 qla2x00_process_completed_request(ha
,
750 ((sts21_entry_t
*)pkt
)->handle
[cnt
]);
754 handle_cnt
= ((sts22_entry_t
*)pkt
)->handle_count
;
755 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
756 qla2x00_process_completed_request(ha
,
757 ((sts22_entry_t
*)pkt
)->handle
[cnt
]);
760 case STATUS_CONT_TYPE
:
761 qla2x00_status_cont_entry(ha
, (sts_cont_entry_t
*)pkt
);
764 qla2x00_ms_entry(ha
, (ms_iocb_entry_t
*)pkt
);
767 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) &&
768 !IS_QLA6312(ha
) && !IS_QLA6322(ha
)) {
769 if (pkt
->sys_define
== SOURCE_ASYNC_IOCB
) {
770 qla2x00_process_iodesc(ha
,
771 (struct mbx_entry
*)pkt
);
773 /* MBX IOCB Type Not Supported. */
774 DEBUG4(printk(KERN_WARNING
775 "scsi(%ld): Received unknown MBX "
776 "IOCB response pkt type=%x "
777 "source=%x entry status=%x.\n",
778 ha
->host_no
, pkt
->entry_type
,
786 /* Type Not Supported. */
787 DEBUG4(printk(KERN_WARNING
788 "scsi(%ld): Received unknown response pkt type %x "
789 "entry status=%x.\n",
790 ha
->host_no
, pkt
->entry_type
, pkt
->entry_status
));
793 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
797 /* Adjust ring index */
798 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), ha
->rsp_ring_index
);
802 * qla2x00_status_entry() - Process a Status IOCB entry.
803 * @ha: SCSI driver HA context
804 * @pkt: Entry pointer
807 qla2x00_status_entry(scsi_qla_host_t
*ha
, void *pkt
)
811 struct scsi_cmnd
*cp
;
813 struct sts_entry_24xx
*sts24
;
814 uint16_t comp_status
;
815 uint16_t scsi_status
;
816 uint8_t lscsi_status
;
818 uint32_t sense_len
, rsp_info_len
, resid_len
;
819 uint8_t *rsp_info
, *sense_data
;
821 sts
= (sts_entry_t
*) pkt
;
822 sts24
= (struct sts_entry_24xx
*) pkt
;
823 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
824 comp_status
= le16_to_cpu(sts24
->comp_status
);
825 scsi_status
= le16_to_cpu(sts24
->scsi_status
) & SS_MASK
;
827 comp_status
= le16_to_cpu(sts
->comp_status
);
828 scsi_status
= le16_to_cpu(sts
->scsi_status
) & SS_MASK
;
831 /* Fast path completion. */
832 if (comp_status
== CS_COMPLETE
&& scsi_status
== 0) {
833 qla2x00_process_completed_request(ha
, sts
->handle
);
838 /* Validate handle. */
839 if (sts
->handle
< MAX_OUTSTANDING_COMMANDS
) {
840 sp
= ha
->outstanding_cmds
[sts
->handle
];
841 ha
->outstanding_cmds
[sts
->handle
] = NULL
;
846 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
848 qla_printk(KERN_WARNING
, ha
, "Status Entry invalid handle.\n");
850 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
851 if (ha
->dpc_wait
&& !ha
->dpc_active
)
858 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
859 "pkt->handle=%d sp=%p sp->state:%d\n",
860 ha
->host_no
, sts
->handle
, sp
, sp
->state
));
861 qla_printk(KERN_WARNING
, ha
,
862 "Command is NULL: already returned to OS (sp=%p)\n", sp
);
867 lscsi_status
= scsi_status
& STATUS_MASK
;
868 CMD_ENTRY_STATUS(cp
) = sts
->entry_status
;
869 CMD_COMPL_STATUS(cp
) = comp_status
;
870 CMD_SCSI_STATUS(cp
) = scsi_status
;
874 sense_len
= rsp_info_len
= resid_len
= 0;
875 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
876 sense_len
= le32_to_cpu(sts24
->sense_len
);
877 rsp_info_len
= le32_to_cpu(sts24
->rsp_data_len
);
878 resid_len
= le32_to_cpu(sts24
->rsp_residual_count
);
879 rsp_info
= sts24
->data
;
880 sense_data
= sts24
->data
;
881 host_to_fcp_swap(sts24
->data
, sizeof(sts24
->data
));
883 sense_len
= le16_to_cpu(sts
->req_sense_length
);
884 rsp_info_len
= le16_to_cpu(sts
->rsp_info_len
);
885 resid_len
= le32_to_cpu(sts
->residual_length
);
886 rsp_info
= sts
->rsp_info
;
887 sense_data
= sts
->req_sense_data
;
890 /* Check for any FCP transport errors. */
891 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
) {
892 /* Sense data lies beyond any FCP RESPONSE data. */
893 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
894 sense_data
+= rsp_info_len
;
895 if (rsp_info_len
> 3 && rsp_info
[3]) {
896 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
897 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
898 "retrying command\n", ha
->host_no
,
899 cp
->device
->channel
, cp
->device
->id
,
900 cp
->device
->lun
, rsp_info_len
, rsp_info
[0],
901 rsp_info
[1], rsp_info
[2], rsp_info
[3], rsp_info
[4],
902 rsp_info
[5], rsp_info
[6], rsp_info
[7]));
904 cp
->result
= DID_BUS_BUSY
<< 16;
905 qla2x00_sp_compl(ha
, sp
);
911 * Based on Host and scsi status generate status code for Linux
913 switch (comp_status
) {
915 if (scsi_status
== 0) {
916 cp
->result
= DID_OK
<< 16;
919 if (scsi_status
& (SS_RESIDUAL_UNDER
| SS_RESIDUAL_OVER
)) {
922 CMD_RESID_LEN(cp
) = resid
;
924 cp
->result
= DID_OK
<< 16 | lscsi_status
;
926 if (lscsi_status
!= SS_CHECK_CONDITION
)
929 /* Copy Sense Data into sense buffer. */
930 memset(cp
->sense_buffer
, 0, sizeof(cp
->sense_buffer
));
932 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
935 if (sense_len
>= sizeof(cp
->sense_buffer
))
936 sense_len
= sizeof(cp
->sense_buffer
);
938 CMD_ACTUAL_SNSLEN(cp
) = sense_len
;
939 sp
->request_sense_length
= sense_len
;
940 sp
->request_sense_ptr
= cp
->sense_buffer
;
942 if (sp
->request_sense_length
> 32)
945 memcpy(cp
->sense_buffer
, sense_data
, sense_len
);
947 sp
->request_sense_ptr
+= sense_len
;
948 sp
->request_sense_length
-= sense_len
;
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", __func__
,
954 ha
->host_no
, cp
->device
->channel
, cp
->device
->id
,
955 cp
->device
->lun
, cp
, cp
->serial_number
));
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
, cp
->device
->id
, cp
->device
->lun
, comp_status
,
968 if (scsi_status
& SS_RESIDUAL_UNDER
) {
970 CMD_RESID_LEN(cp
) = resid
;
974 * Check to see if SCSI Status is non zero. If so report SCSI
977 if (lscsi_status
!= 0) {
978 cp
->result
= DID_OK
<< 16 | lscsi_status
;
980 if (lscsi_status
!= SS_CHECK_CONDITION
)
983 /* Copy Sense Data into sense buffer */
984 memset(cp
->sense_buffer
, 0, sizeof(cp
->sense_buffer
));
986 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
989 if (sense_len
>= sizeof(cp
->sense_buffer
))
990 sense_len
= sizeof(cp
->sense_buffer
);
992 CMD_ACTUAL_SNSLEN(cp
) = sense_len
;
993 sp
->request_sense_length
= sense_len
;
994 sp
->request_sense_ptr
= cp
->sense_buffer
;
996 if (sp
->request_sense_length
> 32)
999 memcpy(cp
->sense_buffer
, sense_data
, sense_len
);
1001 sp
->request_sense_ptr
+= sense_len
;
1002 sp
->request_sense_length
-= sense_len
;
1003 if (sp
->request_sense_length
!= 0)
1004 ha
->status_srb
= sp
;
1006 DEBUG5(printk("%s(): Check condition Sense data, "
1007 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
1008 __func__
, ha
->host_no
, cp
->device
->channel
,
1009 cp
->device
->id
, cp
->device
->lun
, cp
,
1010 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", ha
->host_no
,
1025 cp
->device
->channel
, cp
->device
->id
,
1026 cp
->device
->lun
, resid
,
1027 cp
->request_bufflen
));
1029 cp
->result
= DID_BUS_BUSY
<< 16;
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 "
1039 "error status.\n", ha
->host_no
,
1040 cp
->device
->channel
, cp
->device
->id
,
1041 cp
->device
->lun
, resid
,
1042 cp
->request_bufflen
);
1044 cp
->result
= DID_ERROR
<< 16;
1048 /* Everybody online, looking good... */
1049 cp
->result
= DID_OK
<< 16;
1053 case CS_DATA_OVERRUN
:
1054 DEBUG2(printk(KERN_INFO
1055 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1056 ha
->host_no
, cp
->device
->id
, cp
->device
->lun
, comp_status
,
1058 DEBUG2(printk(KERN_INFO
1059 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1060 cp
->cmnd
[0], cp
->cmnd
[1], cp
->cmnd
[2], cp
->cmnd
[3],
1061 cp
->cmnd
[4], cp
->cmnd
[5]));
1062 DEBUG2(printk(KERN_INFO
1063 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1065 cp
->serial_number
, cp
->request_bufflen
, resid_len
));
1067 cp
->result
= DID_ERROR
<< 16;
1070 case CS_PORT_LOGGED_OUT
:
1071 case CS_PORT_CONFIG_CHG
:
1074 case CS_PORT_UNAVAILABLE
:
1076 * If the port is in Target Down state, return all IOs for this
1077 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1080 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1081 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1082 ha
->host_no
, cp
->device
->id
, cp
->device
->lun
,
1083 cp
->serial_number
, comp_status
,
1084 atomic_read(&fcport
->state
)));
1086 cp
->result
= DID_BUS_BUSY
<< 16;
1087 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
1088 qla2x00_mark_device_lost(ha
, fcport
, 1);
1093 DEBUG2(printk(KERN_INFO
1094 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1095 ha
->host_no
, comp_status
, scsi_status
));
1097 cp
->result
= DID_RESET
<< 16;
1102 * hv2.19.12 - DID_ABORT does not retry the request if we
1103 * aborted this request then abort otherwise it must be a
1106 DEBUG2(printk(KERN_INFO
1107 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1108 ha
->host_no
, comp_status
, scsi_status
));
1110 cp
->result
= DID_RESET
<< 16;
1114 cp
->result
= DID_BUS_BUSY
<< 16;
1116 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
1117 DEBUG2(printk(KERN_INFO
1118 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1119 "0x%x-0x%x\n", ha
->host_no
, cp
->device
->channel
,
1120 cp
->device
->id
, cp
->device
->lun
, comp_status
,
1124 DEBUG2(printk(KERN_INFO
1125 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1126 "sflags=%x.\n", ha
->host_no
, cp
->device
->channel
,
1127 cp
->device
->id
, cp
->device
->lun
, comp_status
, scsi_status
,
1128 le16_to_cpu(sts
->status_flags
)));
1130 /* Check to see if logout occurred. */
1131 if ((le16_to_cpu(sts
->status_flags
) & SF_LOGOUT_SENT
))
1132 qla2x00_mark_device_lost(ha
, fcport
, 1);
1136 DEBUG2(printk(KERN_INFO
1137 "scsi(%ld): QUEUE FULL status detected 0x%x-0x%x.\n",
1138 ha
->host_no
, comp_status
, scsi_status
));
1140 /* SCSI Mid-Layer handles device queue full */
1142 cp
->result
= DID_OK
<< 16 | lscsi_status
;
1147 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1148 "0x%x-0x%x.\n", ha
->host_no
, comp_status
, scsi_status
));
1149 qla_printk(KERN_INFO
, ha
,
1150 "Unknown status detected 0x%x-0x%x.\n",
1151 comp_status
, scsi_status
);
1153 cp
->result
= DID_ERROR
<< 16;
1157 /* Place command on done queue. */
1158 if (ha
->status_srb
== NULL
)
1159 qla2x00_sp_compl(ha
, sp
);
1163 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1164 * @ha: SCSI driver HA context
1165 * @pkt: Entry pointer
1167 * Extended sense data.
1170 qla2x00_status_cont_entry(scsi_qla_host_t
*ha
, sts_cont_entry_t
*pkt
)
1172 uint8_t sense_sz
= 0;
1173 srb_t
*sp
= ha
->status_srb
;
1174 struct scsi_cmnd
*cp
;
1176 if (sp
!= NULL
&& sp
->request_sense_length
!= 0) {
1179 DEBUG2(printk("%s(): Cmd already returned back to OS "
1180 "sp=%p sp->state:%d\n", __func__
, sp
, sp
->state
));
1181 qla_printk(KERN_INFO
, ha
,
1182 "cmd is NULL: already returned to OS (sp=%p)\n",
1185 ha
->status_srb
= NULL
;
1189 if (sp
->request_sense_length
> sizeof(pkt
->data
)) {
1190 sense_sz
= sizeof(pkt
->data
);
1192 sense_sz
= sp
->request_sense_length
;
1195 /* Move sense data. */
1196 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
1197 host_to_fcp_swap(pkt
->data
, sizeof(pkt
->data
));
1198 memcpy(sp
->request_sense_ptr
, pkt
->data
, sense_sz
);
1199 DEBUG5(qla2x00_dump_buffer(sp
->request_sense_ptr
, sense_sz
));
1201 sp
->request_sense_ptr
+= sense_sz
;
1202 sp
->request_sense_length
-= sense_sz
;
1204 /* Place command on done queue. */
1205 if (sp
->request_sense_length
== 0) {
1206 ha
->status_srb
= NULL
;
1207 qla2x00_sp_compl(ha
, sp
);
1213 * qla2x00_error_entry() - Process an error entry.
1214 * @ha: SCSI driver HA context
1215 * @pkt: Entry pointer
1218 qla2x00_error_entry(scsi_qla_host_t
*ha
, sts_entry_t
*pkt
)
1222 #if defined(QL_DEBUG_LEVEL_2)
1223 if (pkt
->entry_status
& RF_INV_E_ORDER
)
1224 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Order\n", __func__
);
1225 else if (pkt
->entry_status
& RF_INV_E_COUNT
)
1226 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Count\n", __func__
);
1227 else if (pkt
->entry_status
& RF_INV_E_PARAM
)
1228 qla_printk(KERN_ERR
, ha
,
1229 "%s: Invalid Entry Parameter\n", __func__
);
1230 else if (pkt
->entry_status
& RF_INV_E_TYPE
)
1231 qla_printk(KERN_ERR
, ha
, "%s: Invalid Entry Type\n", __func__
);
1232 else if (pkt
->entry_status
& RF_BUSY
)
1233 qla_printk(KERN_ERR
, ha
, "%s: Busy\n", __func__
);
1235 qla_printk(KERN_ERR
, ha
, "%s: UNKNOWN flag error\n", __func__
);
1238 /* Validate handle. */
1239 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
1240 sp
= ha
->outstanding_cmds
[pkt
->handle
];
1245 /* Free outstanding command slot. */
1246 ha
->outstanding_cmds
[pkt
->handle
] = NULL
;
1248 /* Bad payload or header */
1249 if (pkt
->entry_status
&
1250 (RF_INV_E_ORDER
| RF_INV_E_COUNT
|
1251 RF_INV_E_PARAM
| RF_INV_E_TYPE
)) {
1252 sp
->cmd
->result
= DID_ERROR
<< 16;
1253 } else if (pkt
->entry_status
& RF_BUSY
) {
1254 sp
->cmd
->result
= DID_BUS_BUSY
<< 16;
1256 sp
->cmd
->result
= DID_ERROR
<< 16;
1258 qla2x00_sp_compl(ha
, sp
);
1260 } else if (pkt
->entry_type
== COMMAND_A64_TYPE
|| pkt
->entry_type
==
1261 COMMAND_TYPE
|| pkt
->entry_type
== COMMAND_TYPE_7
) {
1262 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1264 qla_printk(KERN_WARNING
, ha
,
1265 "Error entry - invalid handle\n");
1267 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1268 if (ha
->dpc_wait
&& !ha
->dpc_active
)
1274 * qla2x00_ms_entry() - Process a Management Server entry.
1275 * @ha: SCSI driver HA context
1276 * @index: Response queue out pointer
1279 qla2x00_ms_entry(scsi_qla_host_t
*ha
, ms_iocb_entry_t
*pkt
)
1283 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1284 __func__
, ha
->host_no
, pkt
, pkt
->handle1
));
1286 /* Validate handle. */
1287 if (pkt
->handle1
< MAX_OUTSTANDING_COMMANDS
)
1288 sp
= ha
->outstanding_cmds
[pkt
->handle1
];
1293 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1295 qla_printk(KERN_WARNING
, ha
, "MS entry - invalid handle\n");
1297 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1301 CMD_COMPL_STATUS(sp
->cmd
) = le16_to_cpu(pkt
->status
);
1302 CMD_ENTRY_STATUS(sp
->cmd
) = pkt
->entry_status
;
1304 /* Free outstanding command slot. */
1305 ha
->outstanding_cmds
[pkt
->handle1
] = NULL
;
1307 qla2x00_sp_compl(ha
, sp
);
1312 * qla24xx_mbx_completion() - Process mailbox command completions.
1313 * @ha: SCSI driver HA context
1314 * @mb0: Mailbox0 register
1317 qla24xx_mbx_completion(scsi_qla_host_t
*ha
, uint16_t mb0
)
1320 uint16_t __iomem
*wptr
;
1321 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1323 /* Load return mailbox registers. */
1324 ha
->flags
.mbox_int
= 1;
1325 ha
->mailbox_out
[0] = mb0
;
1326 wptr
= (uint16_t __iomem
*)®
->mailbox1
;
1328 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
1329 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
1334 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1335 __func__
, ha
->host_no
, ha
->mcp
->mb
[0]));
1337 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1338 __func__
, ha
->host_no
));
1343 * qla24xx_process_response_queue() - Process response queue entries.
1344 * @ha: SCSI driver HA context
1347 qla24xx_process_response_queue(struct scsi_qla_host
*ha
)
1349 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1350 struct sts_entry_24xx
*pkt
;
1352 if (!ha
->flags
.online
)
1355 while (ha
->response_ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
1356 pkt
= (struct sts_entry_24xx
*)ha
->response_ring_ptr
;
1358 ha
->rsp_ring_index
++;
1359 if (ha
->rsp_ring_index
== ha
->response_q_length
) {
1360 ha
->rsp_ring_index
= 0;
1361 ha
->response_ring_ptr
= ha
->response_ring
;
1363 ha
->response_ring_ptr
++;
1366 if (pkt
->entry_status
!= 0) {
1367 DEBUG3(printk(KERN_INFO
1368 "scsi(%ld): Process error entry.\n", ha
->host_no
));
1370 qla2x00_error_entry(ha
, (sts_entry_t
*) pkt
);
1371 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1376 switch (pkt
->entry_type
) {
1378 qla2x00_status_entry(ha
, pkt
);
1380 case STATUS_CONT_TYPE
:
1381 qla2x00_status_cont_entry(ha
, (sts_cont_entry_t
*)pkt
);
1384 qla24xx_ms_entry(ha
, (struct ct_entry_24xx
*)pkt
);
1387 /* Type Not Supported. */
1388 DEBUG4(printk(KERN_WARNING
1389 "scsi(%ld): Received unknown response pkt type %x "
1390 "entry status=%x.\n",
1391 ha
->host_no
, pkt
->entry_type
, pkt
->entry_status
));
1394 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1398 /* Adjust ring index */
1399 WRT_REG_DWORD(®
->rsp_q_out
, ha
->rsp_ring_index
);
1403 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1405 * @dev_id: SCSI driver HA context
1408 * Called by system whenever the host adapter generates an interrupt.
1410 * Returns handled flag.
1413 qla24xx_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1415 scsi_qla_host_t
*ha
;
1416 struct device_reg_24xx __iomem
*reg
;
1418 unsigned long flags
;
1424 ha
= (scsi_qla_host_t
*) dev_id
;
1427 "%s(): NULL host pointer\n", __func__
);
1431 reg
= &ha
->iobase
->isp24
;
1434 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1435 for (iter
= 50; iter
--; ) {
1436 stat
= RD_REG_DWORD(®
->host_status
);
1437 if (stat
& HSRX_RISC_PAUSED
) {
1438 hccr
= RD_REG_DWORD(®
->hccr
);
1440 qla_printk(KERN_INFO
, ha
, "RISC paused -- HCCR=%x, "
1441 "Dumping firmware!\n", hccr
);
1442 qla24xx_fw_dump(ha
, 1);
1444 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1446 } else if ((stat
& HSRX_RISC_INT
) == 0)
1449 switch (stat
& 0xff) {
1454 qla24xx_mbx_completion(ha
, MSW(stat
));
1455 status
|= MBX_INTERRUPT
;
1460 mb
[1] = RD_REG_WORD(®
->mailbox1
);
1461 mb
[2] = RD_REG_WORD(®
->mailbox2
);
1462 mb
[3] = RD_REG_WORD(®
->mailbox3
);
1463 qla2x00_async_event(ha
, mb
);
1466 qla24xx_process_response_queue(ha
);
1469 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1471 ha
->host_no
, stat
& 0xff));
1474 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
1475 RD_REG_DWORD_RELAXED(®
->hccr
);
1477 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1479 if (test_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
) &&
1480 (status
& MBX_INTERRUPT
) && ha
->flags
.mbox_int
) {
1481 spin_lock_irqsave(&ha
->mbx_reg_lock
, flags
);
1483 set_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
1484 up(&ha
->mbx_intr_sem
);
1486 spin_unlock_irqrestore(&ha
->mbx_reg_lock
, flags
);
1493 * qla24xx_ms_entry() - Process a Management Server entry.
1494 * @ha: SCSI driver HA context
1495 * @index: Response queue out pointer
1498 qla24xx_ms_entry(scsi_qla_host_t
*ha
, struct ct_entry_24xx
*pkt
)
1502 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1503 __func__
, ha
->host_no
, pkt
, pkt
->handle
));
1505 DEBUG9(printk("%s: ct pkt dump:\n", __func__
);)
1506 DEBUG9(qla2x00_dump_buffer((void *)pkt
, sizeof(struct ct_entry_24xx
));)
1508 /* Validate handle. */
1509 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
1510 sp
= ha
->outstanding_cmds
[pkt
->handle
];
1515 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1517 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1519 qla_printk(KERN_WARNING
, ha
, "MS entry - invalid handle %d\n",
1522 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1526 CMD_COMPL_STATUS(sp
->cmd
) = le16_to_cpu(pkt
->comp_status
);
1527 CMD_ENTRY_STATUS(sp
->cmd
) = pkt
->entry_status
;
1529 /* Free outstanding command slot. */
1530 ha
->outstanding_cmds
[pkt
->handle
] = NULL
;
1532 qla2x00_sp_compl(ha
, sp
);