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 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
95 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
96 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
98 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
99 up(&ha->mbx_intr_sem);
101 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
104 return (IRQ_HANDLED);
108 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
110 * @dev_id: SCSI driver HA context
113 * Called by system whenever the host adapter generates an interrupt.
115 * Returns handled flag.
118 qla2300_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
121 device_reg_t __iomem *reg;
129 ha = (scsi_qla_host_t *) dev_id;
132 "%s(): NULL host pointer\n", __func__);
139 spin_lock_irqsave(&ha->hardware_lock, flags);
140 for (iter = 50; iter--; ) {
141 stat = RD_REG_DWORD(®->u.isp2300.host_status);
142 if (stat & HSR_RISC_PAUSED) {
143 hccr = RD_REG_WORD(®->hccr);
144 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
145 qla_printk(KERN_INFO, ha,
146 "Parity error -- HCCR=%x.\n", hccr);
148 qla_printk(KERN_INFO, ha,
149 "RISC paused -- HCCR=%x\n", hccr);
152 * Issue a "HARD" reset in order for the RISC
153 * interrupt bit to be cleared. Schedule a big
154 * hammmer to get out of the RISC PAUSED state.
156 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
157 RD_REG_WORD(®->hccr);
158 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
160 } else if ((stat & HSR_RISC_INT) == 0)
164 switch (stat & 0xff) {
166 qla2x00_process_response_queue(ha);
172 qla2x00_mbx_completion(ha, (uint16_t)mbx);
173 status |= MBX_INTERRUPT;
175 /* Release mailbox registers. */
176 WRT_REG_WORD(®->semaphore, 0);
179 qla2x00_async_event(ha, mbx);
182 mbx = mbx << 16 | MBA_CMPLT_1_16BIT;
183 qla2x00_async_event(ha, mbx);
186 mbx = mbx << 16 | MBA_SCSI_COMPLETION;
187 qla2x00_async_event(ha, mbx);
190 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
192 ha->host_no, stat & 0xff));
195 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
196 RD_REG_WORD_RELAXED(®->hccr);
198 spin_unlock_irqrestore(&ha->hardware_lock, flags);
200 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
201 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
202 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
204 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
205 up(&ha->mbx_intr_sem);
207 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
210 return (IRQ_HANDLED);
214 * qla2x00_mbx_completion() - Process mailbox command completions.
215 * @ha: SCSI driver HA context
216 * @mb0: Mailbox0 register
219 qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
222 uint16_t __iomem *wptr;
223 device_reg_t __iomem *reg = ha->iobase;
225 /* Load return mailbox registers. */
226 ha->flags.mbox_int = 1;
227 ha->mailbox_out[0] = mb0;
228 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
230 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
231 if (IS_QLA2200(ha) && cnt == 8)
232 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
233 if (cnt == 4 || cnt == 5)
234 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
236 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
242 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
243 __func__, ha->host_no, ha->mcp->mb[0]));
245 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
246 __func__, ha->host_no));
251 * qla2x00_async_event() - Process aynchronous events.
252 * @ha: SCSI driver HA context
253 * @mb0: Mailbox0 register
256 qla2x00_async_event(scsi_qla_host_t *ha, uint32_t mbx)
258 static char *link_speeds[5] = { "1", "2", "4", "?", "10" };
264 device_reg_t __iomem *reg = ha->iobase;
265 uint32_t rscn_entry, host_pid;
266 uint8_t rscn_queue_index;
268 /* Setup to process RIO completion. */
272 case MBA_SCSI_COMPLETION:
273 if (IS_QLA2100(ha) || IS_QLA2200(ha))
274 handles[0] = le32_to_cpu(
275 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 2) << 16)) |
276 RD_MAILBOX_REG(ha, reg, 1));
278 handles[0] = le32_to_cpu(
279 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 2) << 16)) |
283 case MBA_CMPLT_1_16BIT:
284 if (IS_QLA2100(ha) || IS_QLA2200(ha))
285 handles[0] = (uint32_t)RD_MAILBOX_REG(ha, reg, 1);
287 handles[0] = MSW(mbx);
289 mb[0] = MBA_SCSI_COMPLETION;
291 case MBA_CMPLT_2_16BIT:
292 handles[0] = (uint32_t)RD_MAILBOX_REG(ha, reg, 1);
293 handles[1] = (uint32_t)RD_MAILBOX_REG(ha, reg, 2);
295 mb[0] = MBA_SCSI_COMPLETION;
297 case MBA_CMPLT_3_16BIT:
298 handles[0] = (uint32_t)RD_MAILBOX_REG(ha, reg, 1);
299 handles[1] = (uint32_t)RD_MAILBOX_REG(ha, reg, 2);
300 handles[2] = (uint32_t)RD_MAILBOX_REG(ha, reg, 3);
302 mb[0] = MBA_SCSI_COMPLETION;
304 case MBA_CMPLT_4_16BIT:
305 handles[0] = (uint32_t)RD_MAILBOX_REG(ha, reg, 1);
306 handles[1] = (uint32_t)RD_MAILBOX_REG(ha, reg, 2);
307 handles[2] = (uint32_t)RD_MAILBOX_REG(ha, reg, 3);
308 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
310 mb[0] = MBA_SCSI_COMPLETION;
312 case MBA_CMPLT_5_16BIT:
313 handles[0] = (uint32_t)RD_MAILBOX_REG(ha, reg, 1);
314 handles[1] = (uint32_t)RD_MAILBOX_REG(ha, reg, 2);
315 handles[2] = (uint32_t)RD_MAILBOX_REG(ha, reg, 3);
316 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
317 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
319 mb[0] = MBA_SCSI_COMPLETION;
321 case MBA_CMPLT_2_32BIT:
322 handles[0] = le32_to_cpu(
323 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 2) << 16)) |
324 RD_MAILBOX_REG(ha, reg, 1));
325 handles[1] = le32_to_cpu(
326 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
327 RD_MAILBOX_REG(ha, reg, 6));
329 mb[0] = MBA_SCSI_COMPLETION;
336 case MBA_SCSI_COMPLETION: /* Fast Post */
337 if (!ha->flags.online)
340 for (cnt = 0; cnt < handle_cnt; cnt++)
341 qla2x00_process_completed_request(ha, handles[cnt]);
344 case MBA_RESET: /* Reset */
345 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
347 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
350 case MBA_SYSTEM_ERR: /* System Error */
351 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
352 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
353 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
355 qla_printk(KERN_INFO, ha,
356 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
357 mb[1], mb[2], mb[3]);
359 ha->isp_ops.fw_dump(ha, 1);
362 qla_printk(KERN_INFO, ha,
363 "Unrecoverable Hardware Error: adapter marked "
365 ha->flags.online = 0;
367 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
370 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
371 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
373 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
375 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
378 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
379 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
381 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
383 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
386 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
387 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
391 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
392 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
394 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
396 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
398 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
399 atomic_set(&ha->loop_state, LOOP_DOWN);
400 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
401 qla2x00_mark_all_devices_lost(ha);
404 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
406 ha->flags.management_server_logged_in = 0;
408 /* Update AEN queue. */
409 qla2x00_enqueue_aen(ha, MBA_LIP_OCCURRED, NULL);
413 case MBA_LOOP_UP: /* Loop Up Event */
414 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
416 ha->link_data_rate = 0;
417 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
418 link_speed = link_speeds[0];
420 link_speed = link_speeds[3];
422 link_speed = link_speeds[mb[1]];
423 ha->link_data_rate = mb[1];
426 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
427 ha->host_no, link_speed));
428 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
431 ha->flags.management_server_logged_in = 0;
433 /* Update AEN queue. */
434 qla2x00_enqueue_aen(ha, MBA_LOOP_UP, NULL);
437 case MBA_LOOP_DOWN: /* Loop Down Event */
438 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN.\n",
440 qla_printk(KERN_INFO, ha, "LOOP DOWN detected.\n");
442 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
443 atomic_set(&ha->loop_state, LOOP_DOWN);
444 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
445 ha->device_flags |= DFLG_NO_CABLE;
446 qla2x00_mark_all_devices_lost(ha);
449 ha->flags.management_server_logged_in = 0;
450 ha->link_data_rate = 0;
452 /* Update AEN queue. */
453 qla2x00_enqueue_aen(ha, MBA_LOOP_DOWN, NULL);
456 case MBA_LIP_RESET: /* LIP reset occurred */
457 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
459 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
460 ha->host_no, mb[1]));
461 qla_printk(KERN_INFO, ha,
462 "LIP reset occured (%x).\n", mb[1]);
464 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
465 atomic_set(&ha->loop_state, LOOP_DOWN);
466 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
467 qla2x00_mark_all_devices_lost(ha);
470 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
472 ha->operating_mode = LOOP;
473 ha->flags.management_server_logged_in = 0;
475 /* Update AEN queue. */
476 qla2x00_enqueue_aen(ha, MBA_LIP_RESET, NULL);
480 case MBA_POINT_TO_POINT: /* Point-to-Point */
484 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
488 * Until there's a transition from loop down to loop up, treat
489 * this as loop down only.
491 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
492 atomic_set(&ha->loop_state, LOOP_DOWN);
493 if (!atomic_read(&ha->loop_down_timer))
494 atomic_set(&ha->loop_down_timer,
496 qla2x00_mark_all_devices_lost(ha);
499 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
500 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
502 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
505 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
509 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
511 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
514 qla_printk(KERN_INFO, ha,
515 "Configuration change detected: value=%x.\n", mb[1]);
517 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
518 atomic_set(&ha->loop_state, LOOP_DOWN);
519 if (!atomic_read(&ha->loop_down_timer))
520 atomic_set(&ha->loop_down_timer,
522 qla2x00_mark_all_devices_lost(ha);
525 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
526 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
529 case MBA_PORT_UPDATE: /* Port database update */
530 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
531 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
534 * If a single remote port just logged into (or logged out of)
535 * us, create a new entry in our rscn fcports list and handle
536 * the event like an RSCN.
538 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA6312(ha) &&
539 !IS_QLA6322(ha) && ha->flags.init_done && mb[1] != 0xffff &&
540 ((ha->operating_mode == P2P && mb[1] != 0) ||
541 (ha->operating_mode != P2P && mb[1] !=
542 SNS_FIRST_LOOP_ID)) && (mb[2] == 6 || mb[2] == 7)) {
544 fc_port_t *rscn_fcport;
546 /* Create new fcport for login. */
547 rscn_fcport = qla2x00_alloc_rscn_fcport(ha, GFP_ATOMIC);
549 DEBUG14(printk("scsi(%ld): Port Update -- "
550 "creating RSCN fcport %p for %x/%x.\n",
551 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.\n", ha->host_no));
584 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
586 DEBUG(printk(KERN_INFO
587 "scsi(%ld): Port database changed %04x %04x.\n",
588 ha->host_no, mb[1], mb[2]));
591 * Mark all devices as missing so we will login again.
593 atomic_set(&ha->loop_state, LOOP_UP);
595 qla2x00_mark_all_devices_lost(ha);
597 ha->flags.rscn_queue_overflow = 1;
599 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
600 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
602 /* Update AEN queue. */
603 qla2x00_enqueue_aen(ha, MBA_PORT_UPDATE, NULL);
606 case MBA_RSCN_UPDATE: /* State Change Registration */
607 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
608 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
610 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
612 DEBUG(printk(KERN_INFO
613 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
614 ha->host_no, mb[1], mb[2]));
616 rscn_entry = (mb[1] << 16) | mb[2];
617 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
619 if (rscn_entry == host_pid) {
620 DEBUG(printk(KERN_INFO
621 "scsi(%ld): Ignoring RSCN update to local host "
623 ha->host_no, host_pid));
627 rscn_queue_index = ha->rscn_in_ptr + 1;
628 if (rscn_queue_index == MAX_RSCN_COUNT)
629 rscn_queue_index = 0;
630 if (rscn_queue_index != ha->rscn_out_ptr) {
631 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
632 ha->rscn_in_ptr = rscn_queue_index;
634 ha->flags.rscn_queue_overflow = 1;
637 atomic_set(&ha->loop_state, LOOP_UPDATE);
638 atomic_set(&ha->loop_down_timer, 0);
639 ha->flags.management_server_logged_in = 0;
641 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
642 set_bit(RSCN_UPDATE, &ha->dpc_flags);
644 /* Update AEN queue. */
645 qla2x00_enqueue_aen(ha, MBA_RSCN_UPDATE, &mb[0]);
648 /* case MBA_RIO_RESPONSE: */
649 case MBA_ZIO_RESPONSE:
650 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
652 DEBUG(printk(KERN_INFO
653 "scsi(%ld): [R|Z]IO update completion.\n",
656 qla2x00_process_response_queue(ha);
662 * qla2x00_process_completed_request() - Process a Fast Post response.
663 * @ha: SCSI driver HA context
667 qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
671 /* Validate handle. */
672 if (index >= MAX_OUTSTANDING_COMMANDS) {
673 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
674 ha->host_no, index));
675 qla_printk(KERN_WARNING, ha,
676 "Invalid SCSI completion handle %d.\n", index);
678 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
682 sp = ha->outstanding_cmds[index];
684 /* Free outstanding command slot. */
685 ha->outstanding_cmds[index] = NULL;
687 CMD_COMPL_STATUS(sp->cmd) = 0L;
688 CMD_SCSI_STATUS(sp->cmd) = 0L;
690 /* Save ISP completion status */
691 sp->cmd->result = DID_OK << 16;
692 qla2x00_sp_compl(ha, sp);
694 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
696 qla_printk(KERN_WARNING, ha,
697 "Invalid ISP SCSI completion handle\n");
699 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
704 * qla2x00_process_response_queue() - Process response queue entries.
705 * @ha: SCSI driver HA context
708 qla2x00_process_response_queue(struct scsi_qla_host *ha)
710 device_reg_t __iomem *reg = ha->iobase;
715 if (!ha->flags.online)
718 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
719 pkt = (sts_entry_t *)ha->response_ring_ptr;
721 ha->rsp_ring_index++;
722 if (ha->rsp_ring_index == ha->response_q_length) {
723 ha->rsp_ring_index = 0;
724 ha->response_ring_ptr = ha->response_ring;
726 ha->response_ring_ptr++;
729 if (pkt->entry_status != 0) {
730 DEBUG3(printk(KERN_INFO
731 "scsi(%ld): Process error entry.\n", ha->host_no));
733 qla2x00_error_entry(ha, pkt);
734 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
739 switch (pkt->entry_type) {
741 qla2x00_status_entry(ha, pkt);
744 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
745 for (cnt = 0; cnt < handle_cnt; cnt++) {
746 qla2x00_process_completed_request(ha,
747 ((sts21_entry_t *)pkt)->handle[cnt]);
751 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
752 for (cnt = 0; cnt < handle_cnt; cnt++) {
753 qla2x00_process_completed_request(ha,
754 ((sts22_entry_t *)pkt)->handle[cnt]);
757 case STATUS_CONT_TYPE:
758 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
761 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
764 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
765 !IS_QLA6312(ha) && !IS_QLA6322(ha)) {
766 if (pkt->sys_define == SOURCE_ASYNC_IOCB) {
767 qla2x00_process_iodesc(ha,
768 (struct mbx_entry *)pkt);
770 /* MBX IOCB Type Not Supported. */
771 DEBUG4(printk(KERN_WARNING
772 "scsi(%ld): Received unknown MBX "
773 "IOCB response pkt type=%x "
774 "source=%x entry status=%x.\n",
775 ha->host_no, pkt->entry_type,
783 /* Type Not Supported. */
784 DEBUG4(printk(KERN_WARNING
785 "scsi(%ld): Received unknown response pkt type %x "
786 "entry status=%x.\n",
787 ha->host_no, pkt->entry_type, pkt->entry_status));
790 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
794 /* Adjust ring index */
795 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
799 * qla2x00_status_entry() - Process a Status IOCB entry.
800 * @ha: SCSI driver HA context
801 * @pkt: Entry pointer
804 qla2x00_status_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
809 struct scsi_cmnd *cp;
810 uint16_t comp_status;
811 uint16_t scsi_status;
812 uint8_t lscsi_status;
814 uint8_t sense_sz = 0;
815 uint16_t rsp_info_len;
817 /* Fast path completion. */
818 if (le16_to_cpu(pkt->comp_status) == CS_COMPLETE &&
819 (le16_to_cpu(pkt->scsi_status) & SS_MASK) == 0) {
820 qla2x00_process_completed_request(ha, pkt->handle);
825 /* Validate handle. */
826 if (pkt->handle < MAX_OUTSTANDING_COMMANDS) {
827 sp = ha->outstanding_cmds[pkt->handle];
828 ha->outstanding_cmds[pkt->handle] = NULL;
833 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
835 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
837 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
838 if (ha->dpc_wait && !ha->dpc_active)
845 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
846 "pkt->handle=%d sp=%p sp->state:%d\n",
847 ha->host_no, pkt->handle, sp, sp->state));
848 qla_printk(KERN_WARNING, ha,
849 "Command is NULL: already returned to OS (sp=%p)\n", sp);
854 comp_status = le16_to_cpu(pkt->comp_status);
855 /* Mask of reserved bits 12-15, before we examine the scsi status */
856 scsi_status = le16_to_cpu(pkt->scsi_status) & SS_MASK;
857 lscsi_status = scsi_status & STATUS_MASK;
859 CMD_ENTRY_STATUS(cp) = pkt->entry_status;
860 CMD_COMPL_STATUS(cp) = comp_status;
861 CMD_SCSI_STATUS(cp) = scsi_status;
863 /* Generate LU queue on cntrl, target, LUN */
864 b = cp->device->channel;
870 /* Check for any FCP transport errors. */
871 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
872 rsp_info_len = le16_to_cpu(pkt->rsp_info_len);
873 if (rsp_info_len > 3 && pkt->rsp_info[3]) {
874 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
875 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
876 "retrying command\n", ha->host_no, b, t, l,
877 rsp_info_len, pkt->rsp_info[0], pkt->rsp_info[1],
878 pkt->rsp_info[2], pkt->rsp_info[3],
879 pkt->rsp_info[4], pkt->rsp_info[5],
880 pkt->rsp_info[6], pkt->rsp_info[7]));
882 cp->result = DID_BUS_BUSY << 16;
883 qla2x00_sp_compl(ha, sp);
889 * Based on Host and scsi status generate status code for Linux
891 switch (comp_status) {
893 if (scsi_status == 0) {
894 cp->result = DID_OK << 16;
897 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
898 resid = le32_to_cpu(pkt->residual_length);
900 CMD_RESID_LEN(cp) = resid;
902 cp->result = DID_OK << 16 | lscsi_status;
904 if (lscsi_status != SS_CHECK_CONDITION)
908 * Copy Sense Data into sense buffer
910 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
912 if (!(scsi_status & SS_SENSE_LEN_VALID))
915 if (le16_to_cpu(pkt->req_sense_length) <
916 sizeof(cp->sense_buffer))
917 sense_sz = le16_to_cpu(pkt->req_sense_length);
919 sense_sz = sizeof(cp->sense_buffer);
921 CMD_ACTUAL_SNSLEN(cp) = sense_sz;
922 sp->request_sense_length = sense_sz;
923 sp->request_sense_ptr = cp->sense_buffer;
925 if (sp->request_sense_length > 32)
928 memcpy(cp->sense_buffer, pkt->req_sense_data, sense_sz);
930 sp->request_sense_ptr += sense_sz;
931 sp->request_sense_length -= sense_sz;
932 if (sp->request_sense_length != 0)
935 DEBUG5(printk("%s(): Check condition Sense data, "
936 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
937 __func__, ha->host_no, b, t, l, cp,
940 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
941 CMD_ACTUAL_SNSLEN(cp)));
944 case CS_DATA_UNDERRUN:
945 DEBUG2(printk(KERN_INFO
946 "scsi(%ld:%d:%d) UNDERRUN status detected 0x%x-0x%x.\n",
947 ha->host_no, t, l, comp_status, scsi_status));
949 resid = le32_to_cpu(pkt->residual_length);
950 if (scsi_status & SS_RESIDUAL_UNDER) {
952 CMD_RESID_LEN(cp) = resid;
956 * Check to see if SCSI Status is non zero. If so report SCSI
959 if (lscsi_status != 0) {
960 cp->result = DID_OK << 16 | lscsi_status;
962 if (lscsi_status != SS_CHECK_CONDITION)
965 /* Copy Sense Data into sense buffer */
966 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
968 if (!(scsi_status & SS_SENSE_LEN_VALID))
971 if (le16_to_cpu(pkt->req_sense_length) <
972 sizeof(cp->sense_buffer))
973 sense_sz = le16_to_cpu(pkt->req_sense_length);
975 sense_sz = sizeof(cp->sense_buffer);
977 CMD_ACTUAL_SNSLEN(cp) = sense_sz;
978 sp->request_sense_length = sense_sz;
979 sp->request_sense_ptr = cp->sense_buffer;
981 if (sp->request_sense_length > 32)
984 memcpy(cp->sense_buffer, pkt->req_sense_data, sense_sz);
986 sp->request_sense_ptr += sense_sz;
987 sp->request_sense_length -= sense_sz;
988 if (sp->request_sense_length != 0)
991 DEBUG5(printk("%s(): Check condition Sense data, "
992 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
993 __func__, ha->host_no, b, t, l, cp,
996 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
997 CMD_ACTUAL_SNSLEN(cp)));
1000 * If RISC reports underrun and target does not report
1001 * it then we must have a lost frame, so tell upper
1002 * layer to retry it by reporting a bus busy.
1004 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1005 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1006 "frame(s) detected (%x of %x bytes)..."
1007 "retrying command.\n",
1008 ha->host_no, b, t, l, resid,
1009 cp->request_bufflen));
1011 cp->result = DID_BUS_BUSY << 16;
1015 /* Handle mid-layer underflow */
1016 if ((unsigned)(cp->request_bufflen - resid) <
1018 qla_printk(KERN_INFO, ha,
1019 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1020 "detected (%x of %x bytes)...returning "
1022 ha->host_no, b, t, l, resid,
1023 cp->request_bufflen);
1025 cp->result = DID_ERROR << 16;
1029 /* Everybody online, looking good... */
1030 cp->result = DID_OK << 16;
1034 case CS_DATA_OVERRUN:
1035 DEBUG2(printk(KERN_INFO
1036 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1037 ha->host_no, t, l, comp_status, scsi_status));
1038 DEBUG2(printk(KERN_INFO
1039 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1040 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1041 cp->cmnd[4], cp->cmnd[5]));
1042 DEBUG2(printk(KERN_INFO
1043 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1045 cp->serial_number, cp->request_bufflen,
1046 le32_to_cpu(pkt->residual_length)));
1048 cp->result = DID_ERROR << 16;
1051 case CS_PORT_LOGGED_OUT:
1052 case CS_PORT_CONFIG_CHG:
1055 case CS_PORT_UNAVAILABLE:
1057 * If the port is in Target Down state, return all IOs for this
1058 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1061 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1062 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1063 ha->host_no, t, l, cp->serial_number, comp_status,
1064 atomic_read(&fcport->state)));
1066 cp->result = DID_BUS_BUSY << 16;
1067 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1068 qla2x00_mark_device_lost(ha, fcport, 1);
1073 DEBUG2(printk(KERN_INFO
1074 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1075 ha->host_no, comp_status, scsi_status));
1077 cp->result = DID_RESET << 16;
1082 * hv2.19.12 - DID_ABORT does not retry the request if we
1083 * aborted this request then abort otherwise it must be a
1086 DEBUG2(printk(KERN_INFO
1087 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1088 ha->host_no, comp_status, scsi_status));
1090 cp->result = DID_RESET << 16;
1094 DEBUG2(printk(KERN_INFO
1095 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1096 "sflags=%x.\n", ha->host_no, b, t, l, comp_status,
1097 scsi_status, le16_to_cpu(pkt->status_flags)));
1099 cp->result = DID_BUS_BUSY << 16;
1101 /* Check to see if logout occurred */
1102 if ((le16_to_cpu(pkt->status_flags) & SF_LOGOUT_SENT)) {
1103 qla2x00_mark_device_lost(ha, fcport, 1);
1108 DEBUG2(printk(KERN_INFO
1109 "scsi(%ld): QUEUE FULL status detected 0x%x-0x%x.\n",
1110 ha->host_no, comp_status, scsi_status));
1112 /* SCSI Mid-Layer handles device queue full */
1114 cp->result = DID_OK << 16 | lscsi_status;
1119 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1121 ha->host_no, comp_status, scsi_status));
1122 qla_printk(KERN_INFO, ha,
1123 "Unknown status detected 0x%x-0x%x.\n",
1124 comp_status, scsi_status);
1126 cp->result = DID_ERROR << 16;
1130 /* Place command on done queue. */
1131 if (ha->status_srb == NULL)
1132 qla2x00_sp_compl(ha, sp);
1136 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1137 * @ha: SCSI driver HA context
1138 * @pkt: Entry pointer
1140 * Extended sense data.
1143 qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1145 uint8_t sense_sz = 0;
1146 srb_t *sp = ha->status_srb;
1147 struct scsi_cmnd *cp;
1149 if (sp != NULL && sp->request_sense_length != 0) {
1152 DEBUG2(printk("%s(): Cmd already returned back to OS "
1153 "sp=%p sp->state:%d\n", __func__, sp, sp->state));
1154 qla_printk(KERN_INFO, ha,
1155 "cmd is NULL: already returned to OS (sp=%p)\n",
1158 ha->status_srb = NULL;
1162 if (sp->request_sense_length > sizeof(pkt->data)) {
1163 sense_sz = sizeof(pkt->data);
1165 sense_sz = sp->request_sense_length;
1168 /* Move sense data. */
1169 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1170 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1172 sp->request_sense_ptr += sense_sz;
1173 sp->request_sense_length -= sense_sz;
1175 /* Place command on done queue. */
1176 if (sp->request_sense_length == 0) {
1177 ha->status_srb = NULL;
1178 qla2x00_sp_compl(ha, sp);
1184 * qla2x00_error_entry() - Process an error entry.
1185 * @ha: SCSI driver HA context
1186 * @pkt: Entry pointer
1189 qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
1193 #if defined(QL_DEBUG_LEVEL_2)
1194 if (pkt->entry_status & RF_INV_E_ORDER)
1195 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1196 else if (pkt->entry_status & RF_INV_E_COUNT)
1197 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1198 else if (pkt->entry_status & RF_INV_E_PARAM)
1199 qla_printk(KERN_ERR, ha,
1200 "%s: Invalid Entry Parameter\n", __func__);
1201 else if (pkt->entry_status & RF_INV_E_TYPE)
1202 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1203 else if (pkt->entry_status & RF_BUSY)
1204 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1206 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1209 /* Validate handle. */
1210 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1211 sp = ha->outstanding_cmds[pkt->handle];
1216 /* Free outstanding command slot. */
1217 ha->outstanding_cmds[pkt->handle] = NULL;
1219 /* Bad payload or header */
1220 if (pkt->entry_status &
1221 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1222 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1223 sp->cmd->result = DID_ERROR << 16;
1224 } else if (pkt->entry_status & RF_BUSY) {
1225 sp->cmd->result = DID_BUS_BUSY << 16;
1227 sp->cmd->result = DID_ERROR << 16;
1229 qla2x00_sp_compl(ha, sp);
1231 } else if (pkt->entry_type == COMMAND_A64_TYPE ||
1232 pkt->entry_type == COMMAND_TYPE) {
1233 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1235 qla_printk(KERN_WARNING, ha,
1236 "Error entry - invalid handle\n");
1238 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1239 if (ha->dpc_wait && !ha->dpc_active)
1245 * qla2x00_ms_entry() - Process a Management Server entry.
1246 * @ha: SCSI driver HA context
1247 * @index: Response queue out pointer
1250 qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
1254 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1255 __func__, ha->host_no, pkt, pkt->handle1));
1257 /* Validate handle. */
1258 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1259 sp = ha->outstanding_cmds[pkt->handle1];
1264 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1266 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1268 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1272 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1273 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1275 /* Free outstanding command slot. */
1276 ha->outstanding_cmds[pkt->handle1] = NULL;
1278 qla2x00_sp_compl(ha, sp);