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.
24 static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
25 static void qla2x00_async_event(scsi_qla_host_t *, uint32_t);
26 static void qla2x00_process_completed_request(struct scsi_qla_host *, uint32_t);
27 void qla2x00_process_response_queue(struct scsi_qla_host *);
28 static void qla2x00_status_entry(scsi_qla_host_t *, sts_entry_t *);
29 static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *);
30 static void qla2x00_error_entry(scsi_qla_host_t *, sts_entry_t *);
31 static void qla2x00_ms_entry(scsi_qla_host_t *, ms_iocb_entry_t *);
33 static int qla2x00_check_sense(struct scsi_cmnd *cp, os_lun_t *);
36 * qla2x00_intr_handler() - Process interrupts for the ISP.
38 * @dev_id: SCSI driver HA context
41 * Called by system whenever the host adapter generates an interrupt.
43 * Returns handled flag.
46 qla2x00_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
52 unsigned long flags = 0;
53 unsigned long mbx_flags = 0;
54 unsigned long intr_iter;
58 /* Don't loop forever, interrupt are OFF */
61 ha = (scsi_qla_host_t *) dev_id;
64 "%s(): NULL host pointer\n", __func__);
70 spin_lock_irqsave(&ha->hardware_lock, flags);
77 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
78 if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0)
81 if (RD_REG_WORD(®->semaphore) & BIT_0) {
82 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
83 RD_REG_WORD(®->hccr);
85 /* Get mailbox data. */
86 mbx = RD_MAILBOX_REG(ha, reg, 0);
87 if (mbx > 0x3fff && mbx < 0x8000) {
88 qla2x00_mbx_completion(ha,
90 status |= MBX_INTERRUPT;
91 } else if (mbx > 0x7fff && mbx < 0xc000) {
92 qla2x00_async_event(ha, mbx);
95 DEBUG2(printk("scsi(%ld): Unrecognized "
96 "interrupt type (%d)\n",
99 /* Release mailbox registers. */
100 WRT_REG_WORD(®->semaphore, 0);
101 /* Workaround for ISP2100 chip. */
103 RD_REG_WORD(®->semaphore);
105 qla2x00_process_response_queue(ha);
107 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
108 RD_REG_WORD(®->hccr);
110 } else /* IS_QLA23XX(ha) */ {
111 stat = RD_REG_DWORD(®->u.isp2300.host_status);
112 if ((stat & HSR_RISC_INT) == 0)
116 switch (stat & 0xff) {
118 qla2x00_process_response_queue(ha);
124 qla2x00_mbx_completion(ha, (uint16_t)mbx);
125 status |= MBX_INTERRUPT;
127 /* Release mailbox registers. */
128 WRT_REG_WORD(®->semaphore, 0);
131 qla2x00_async_event(ha, mbx);
134 mbx = mbx << 16 | MBA_CMPLT_1_16BIT;
135 qla2x00_async_event(ha, mbx);
138 mbx = mbx << 16 | MBA_SCSI_COMPLETION;
139 qla2x00_async_event(ha, mbx);
142 hccr = RD_REG_WORD(®->hccr);
143 if (hccr & HCCR_RISC_PAUSE) {
144 qla_printk(KERN_INFO, ha,
145 "RISC paused, dumping HCCR=%x\n",
149 * Issue a "HARD" reset in order for
150 * the RISC interrupt bit to be
151 * cleared. Schedule a big hammmer to
152 * get out of the RISC PAUSED state.
154 WRT_REG_WORD(®->hccr,
156 RD_REG_WORD(®->hccr);
157 set_bit(ISP_ABORT_NEEDED,
161 DEBUG2(printk("scsi(%ld): Unrecognized "
162 "interrupt type (%d)\n",
163 ha->host_no, stat & 0xff));
167 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
168 RD_REG_WORD(®->hccr);
172 spin_unlock_irqrestore(&ha->hardware_lock, flags);
175 ha->last_irq_cpu = smp_processor_id();
178 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
179 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
181 /* There was a mailbox completion */
182 DEBUG3(printk("%s(%ld): Going to get mbx reg lock.\n",
183 __func__, ha->host_no));
185 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
187 if (ha->mcp == NULL) {
188 DEBUG3(printk("%s(%ld): Error mbx pointer.\n",
189 __func__, ha->host_no));
191 DEBUG3(printk("%s(%ld): Going to set mbx intr flags. "
193 __func__, ha->host_no, ha->mcp->mb[0]));
195 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
197 DEBUG3(printk("%s(%ld): Going to wake up mbx function for "
199 __func__, ha->host_no));
201 up(&ha->mbx_intr_sem);
203 DEBUG3(printk("%s(%ld): Going to release mbx reg lock.\n",
204 __func__, ha->host_no));
206 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
209 if (!list_empty(&ha->done_queue))
212 /* Wakeup the DPC routine */
213 if ((!ha->flags.mbox_busy &&
214 (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
215 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
216 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))) &&
217 ha->dpc_wait && !ha->dpc_active) {
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)
235 device_reg_t *reg = ha->iobase;
237 /* Load return mailbox registers. */
238 ha->flags.mbox_int = TRUE;
239 ha->mailbox_out[0] = mb0;
240 wptr = (uint16_t *)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 *)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 * @mb0: Mailbox0 register
268 qla2x00_async_event(scsi_qla_host_t *ha, uint32_t mbx)
270 static char *link_speeds[5] = { "1", "2", "4", "?", "10" };
276 device_reg_t *reg = ha->iobase;
277 uint32_t rscn_entry, host_pid;
278 uint8_t rscn_queue_index;
280 /* Setup to process RIO completion. */
284 case MBA_SCSI_COMPLETION:
285 if (IS_QLA2100(ha) || IS_QLA2200(ha))
286 handles[0] = le32_to_cpu(
287 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 2) << 16)) |
288 RD_MAILBOX_REG(ha, reg, 1));
290 handles[0] = le32_to_cpu(
291 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 2) << 16)) |
295 case MBA_CMPLT_1_16BIT:
296 if (IS_QLA2100(ha) || IS_QLA2200(ha))
297 handles[0] = (uint32_t)RD_MAILBOX_REG(ha, reg, 1);
299 handles[0] = MSW(mbx);
301 mb[0] = MBA_SCSI_COMPLETION;
303 case MBA_CMPLT_2_16BIT:
304 handles[0] = (uint32_t)RD_MAILBOX_REG(ha, reg, 1);
305 handles[1] = (uint32_t)RD_MAILBOX_REG(ha, reg, 2);
307 mb[0] = MBA_SCSI_COMPLETION;
309 case MBA_CMPLT_3_16BIT:
310 handles[0] = (uint32_t)RD_MAILBOX_REG(ha, reg, 1);
311 handles[1] = (uint32_t)RD_MAILBOX_REG(ha, reg, 2);
312 handles[2] = (uint32_t)RD_MAILBOX_REG(ha, reg, 3);
314 mb[0] = MBA_SCSI_COMPLETION;
316 case MBA_CMPLT_4_16BIT:
317 handles[0] = (uint32_t)RD_MAILBOX_REG(ha, reg, 1);
318 handles[1] = (uint32_t)RD_MAILBOX_REG(ha, reg, 2);
319 handles[2] = (uint32_t)RD_MAILBOX_REG(ha, reg, 3);
320 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
322 mb[0] = MBA_SCSI_COMPLETION;
324 case MBA_CMPLT_5_16BIT:
325 handles[0] = (uint32_t)RD_MAILBOX_REG(ha, reg, 1);
326 handles[1] = (uint32_t)RD_MAILBOX_REG(ha, reg, 2);
327 handles[2] = (uint32_t)RD_MAILBOX_REG(ha, reg, 3);
328 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
329 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
331 mb[0] = MBA_SCSI_COMPLETION;
333 case MBA_CMPLT_2_32BIT:
334 handles[0] = le32_to_cpu(
335 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 2) << 16)) |
336 RD_MAILBOX_REG(ha, reg, 1));
337 handles[1] = le32_to_cpu(
338 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
339 RD_MAILBOX_REG(ha, reg, 6));
341 mb[0] = MBA_SCSI_COMPLETION;
349 case MBA_SCSI_COMPLETION: /* Fast Post */
350 if (!ha->flags.online)
353 for (cnt = 0; cnt < handle_cnt; cnt++)
354 qla2x00_process_completed_request(ha, handles[cnt]);
357 case MBA_RESET: /* Reset */
358 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
360 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
363 case MBA_SYSTEM_ERR: /* System Error */
364 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
365 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
366 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
368 qla_printk(KERN_INFO, ha,
369 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
370 mb[1], mb[2], mb[3]);
372 if (IS_QLA2100(ha) || IS_QLA2200(ha))
373 qla2100_fw_dump(ha, 1);
375 qla2300_fw_dump(ha, 1);
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 login.\n",
562 ha->host_no, rscn_fcport));
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 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
588 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
589 "ignored.\n", ha->host_no));
593 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
595 DEBUG(printk(KERN_INFO
596 "scsi(%ld): Port database changed %04x %04x.\n",
597 ha->host_no, mb[1], mb[2]));
600 * Mark all devices as missing so we will login again.
602 atomic_set(&ha->loop_state, LOOP_UP);
604 atomic_set(&ha->loop_down_timer, 0);
605 qla2x00_mark_all_devices_lost(ha);
607 ha->flags.rscn_queue_overflow = 1;
609 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
610 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
612 /* Update AEN queue. */
613 qla2x00_enqueue_aen(ha, MBA_PORT_UPDATE, NULL);
616 case MBA_RSCN_UPDATE: /* State Change Registration */
617 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
618 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
620 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
622 DEBUG(printk(KERN_INFO
623 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
624 ha->host_no, mb[1], mb[2]));
626 rscn_entry = (mb[1] << 16) | mb[2];
627 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
629 if (rscn_entry == host_pid) {
630 DEBUG(printk(KERN_INFO
631 "scsi(%ld): Ignoring RSCN update to local host "
633 ha->host_no, host_pid));
637 rscn_queue_index = ha->rscn_in_ptr + 1;
638 if (rscn_queue_index == MAX_RSCN_COUNT)
639 rscn_queue_index = 0;
640 if (rscn_queue_index != ha->rscn_out_ptr) {
641 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
642 ha->rscn_in_ptr = rscn_queue_index;
644 ha->flags.rscn_queue_overflow = 1;
647 atomic_set(&ha->loop_state, LOOP_UPDATE);
648 atomic_set(&ha->loop_down_timer, 0);
649 ha->flags.management_server_logged_in = 0;
651 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
652 set_bit(RSCN_UPDATE, &ha->dpc_flags);
654 /* Update AEN queue. */
655 qla2x00_enqueue_aen(ha, MBA_RSCN_UPDATE, &mb[0]);
658 /* case MBA_RIO_RESPONSE: */
659 case MBA_ZIO_RESPONSE:
660 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
662 DEBUG(printk(KERN_INFO
663 "scsi(%ld): [R|Z]IO update completion.\n",
666 qla2x00_process_response_queue(ha);
672 * qla2x00_process_completed_request() - Process a Fast Post response.
673 * @ha: SCSI driver HA context
677 qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
681 /* Validate handle. */
682 if (index >= MAX_OUTSTANDING_COMMANDS) {
683 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
684 ha->host_no, index));
685 qla_printk(KERN_WARNING, ha,
686 "Invalid SCSI completion handle %d.\n", index);
688 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
692 sp = ha->outstanding_cmds[index];
694 /* Free outstanding command slot. */
695 ha->outstanding_cmds[index] = 0;
699 sp->lun_queue->out_cnt--;
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 add_to_done_queue(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 *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)
826 struct scsi_cmnd *cp;
827 uint16_t comp_status;
828 uint16_t scsi_status;
829 uint8_t lscsi_status;
831 uint8_t sense_sz = 0;
832 uint16_t rsp_info_len;
834 /* Fast path completion. */
835 if (le16_to_cpu(pkt->comp_status) == CS_COMPLETE &&
836 (le16_to_cpu(pkt->scsi_status) & SS_MASK) == 0) {
837 qla2x00_process_completed_request(ha, pkt->handle);
842 /* Validate handle. */
843 if (pkt->handle < MAX_OUTSTANDING_COMMANDS) {
844 sp = ha->outstanding_cmds[pkt->handle];
845 ha->outstanding_cmds[pkt->handle] = 0;
850 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
852 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
854 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
855 if (ha->dpc_wait && !ha->dpc_active)
862 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
863 "pkt->handle=%d sp=%p sp->state:%d\n",
864 ha->host_no, pkt->handle, sp, sp->state));
865 qla_printk(KERN_WARNING, ha,
866 "Command is NULL: already returned to OS (sp=%p)\n", sp);
874 if (sp->lun_queue == NULL) {
875 DEBUG2(printk("scsi(%ld): Status Entry invalid lun pointer.\n",
877 qla_printk(KERN_WARNING, ha,
878 "Status Entry invalid lun pointer.\n");
880 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
881 if (ha->dpc_wait && !ha->dpc_active)
887 sp->lun_queue->out_cnt--;
889 comp_status = le16_to_cpu(pkt->comp_status);
890 /* Mask of reserved bits 12-15, before we examine the scsi status */
891 scsi_status = le16_to_cpu(pkt->scsi_status) & SS_MASK;
892 lscsi_status = scsi_status & STATUS_MASK;
894 CMD_ENTRY_STATUS(cp) = pkt->entry_status;
895 CMD_COMPL_STATUS(cp) = comp_status;
896 CMD_SCSI_STATUS(cp) = scsi_status;
898 /* Generate LU queue on cntrl, target, LUN */
899 b = cp->device->channel;
907 * If loop is in transient state Report DID_BUS_BUSY
909 if ((comp_status != CS_COMPLETE || scsi_status != 0)) {
910 if (!(sp->flags & SRB_IOCTL) &&
911 (atomic_read(&ha->loop_down_timer) ||
912 atomic_read(&ha->loop_state) != LOOP_READY)) {
914 DEBUG2(printk("scsi(%ld:%d:%d:%d): Loop Not Ready - "
916 ha->host_no, b, t, l, cp->serial_number));
918 qla2x00_extend_timeout(cp, EXTEND_CMD_TIMEOUT);
919 add_to_retry_queue(ha, sp);
924 /* Check for any FCP transport errors. */
925 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
926 rsp_info_len = le16_to_cpu(pkt->rsp_info_len);
927 if (rsp_info_len > 3 && pkt->rsp_info[3]) {
928 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
929 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
930 "retrying command\n", ha->host_no, b, t, l,
931 rsp_info_len, pkt->rsp_info[0], pkt->rsp_info[1],
932 pkt->rsp_info[2], pkt->rsp_info[3],
933 pkt->rsp_info[4], pkt->rsp_info[5],
934 pkt->rsp_info[6], pkt->rsp_info[7]));
936 cp->result = DID_BUS_BUSY << 16;
937 add_to_done_queue(ha, sp);
943 * Based on Host and scsi status generate status code for Linux
945 switch (comp_status) {
947 if (scsi_status == 0) {
948 cp->result = DID_OK << 16;
951 if (lscsi_status == SS_BUSY_CONDITION) {
952 cp->result = DID_BUS_BUSY << 16 | lscsi_status;
956 cp->result = DID_OK << 16 | lscsi_status;
958 if (lscsi_status != SS_CHECK_CONDITION)
962 * Copy Sense Data into sense buffer
964 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
966 if (!(scsi_status & SS_SENSE_LEN_VALID))
969 if (le16_to_cpu(pkt->req_sense_length) <
970 sizeof(cp->sense_buffer))
971 sense_sz = le16_to_cpu(pkt->req_sense_length);
973 sense_sz = sizeof(cp->sense_buffer) - 1;
975 CMD_ACTUAL_SNSLEN(cp) = sense_sz;
976 sp->request_sense_length = sense_sz;
977 sp->request_sense_ptr = cp->sense_buffer;
979 if (sp->request_sense_length > 32)
982 memcpy(cp->sense_buffer, pkt->req_sense_data, sense_sz);
984 sp->request_sense_ptr += sense_sz;
985 sp->request_sense_length -= sense_sz;
986 if (sp->request_sense_length != 0)
989 if (!(sp->flags & SRB_IOCTL) &&
990 qla2x00_check_sense(cp, lq) == QLA_SUCCESS) {
991 /* Throw away status_cont if any */
992 ha->status_srb = NULL;
993 add_to_scsi_retry_queue(ha, sp);
997 DEBUG5(printk("%s(): Check condition Sense data, "
998 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
999 __func__, ha->host_no, b, t, l, cp,
1000 cp->serial_number));
1002 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1003 CMD_ACTUAL_SNSLEN(cp)));
1006 case CS_DATA_UNDERRUN:
1007 DEBUG2(printk(KERN_INFO
1008 "scsi(%ld:%d:%d) UNDERRUN status detected 0x%x-0x%x.\n",
1009 ha->host_no, t, l, comp_status, scsi_status));
1011 resid = le32_to_cpu(pkt->residual_length);
1012 CMD_RESID_LEN(cp) = resid;
1015 * Check to see if SCSI Status is non zero. If so report SCSI
1018 if (lscsi_status != 0) {
1019 if (lscsi_status == SS_BUSY_CONDITION) {
1020 cp->result = DID_BUS_BUSY << 16 |
1025 cp->result = DID_OK << 16 | lscsi_status;
1027 if (lscsi_status != SS_CHECK_CONDITION)
1030 /* Copy Sense Data into sense buffer */
1031 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
1033 if (!(scsi_status & SS_SENSE_LEN_VALID))
1036 if (le16_to_cpu(pkt->req_sense_length) <
1037 sizeof(cp->sense_buffer))
1038 sense_sz = le16_to_cpu(pkt->req_sense_length);
1040 sense_sz = sizeof(cp->sense_buffer) - 1;
1042 CMD_ACTUAL_SNSLEN(cp) = sense_sz;
1043 sp->request_sense_length = sense_sz;
1044 sp->request_sense_ptr = cp->sense_buffer;
1046 if (sp->request_sense_length > 32)
1049 memcpy(cp->sense_buffer, pkt->req_sense_data, sense_sz);
1051 sp->request_sense_ptr += sense_sz;
1052 sp->request_sense_length -= sense_sz;
1053 if (sp->request_sense_length != 0)
1054 ha->status_srb = sp;
1056 if (!(sp->flags & SRB_IOCTL) &&
1057 (qla2x00_check_sense(cp, lq) == QLA_SUCCESS)) {
1058 ha->status_srb = NULL;
1059 add_to_scsi_retry_queue(ha, sp);
1062 DEBUG5(printk("%s(): Check condition Sense data, "
1063 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
1064 __func__, ha->host_no, b, t, l, cp,
1065 cp->serial_number));
1067 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1068 CMD_ACTUAL_SNSLEN(cp)));
1071 * If RISC reports underrun and target does not report
1072 * it then we must have a lost frame, so tell upper
1073 * layer to retry it by reporting a bus busy.
1075 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1076 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1077 "frame(s) detected (%x of %x bytes)..."
1078 "retrying command.\n",
1079 ha->host_no, b, t, l, resid,
1080 cp->request_bufflen));
1082 cp->result = DID_BUS_BUSY << 16;
1083 ha->dropped_frame_error_cnt++;
1087 /* Handle mid-layer underflow */
1089 if ((unsigned)(cp->request_bufflen - resid) <
1091 qla_printk(KERN_INFO, ha,
1092 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1093 "detected (%x of %x bytes)...returning "
1095 ha->host_no, b, t, l, resid,
1096 cp->request_bufflen);
1098 cp->result = DID_ERROR << 16;
1102 /* Everybody online, looking good... */
1103 cp->result = DID_OK << 16;
1107 case CS_DATA_OVERRUN:
1108 DEBUG2(printk(KERN_INFO
1109 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1110 ha->host_no, t, l, comp_status, scsi_status));
1111 DEBUG2(printk(KERN_INFO
1112 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1113 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1114 cp->cmnd[4], cp->cmnd[5]));
1115 DEBUG2(printk(KERN_INFO
1116 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1118 cp->serial_number, cp->request_bufflen,
1119 le32_to_cpu(pkt->residual_length)));
1121 cp->result = DID_ERROR << 16;
1124 case CS_PORT_LOGGED_OUT:
1125 case CS_PORT_CONFIG_CHG:
1128 case CS_PORT_UNAVAILABLE:
1130 * If the port is in Target Down state, return all IOs for this
1131 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1134 fcport = sp->fclun->fcport;
1135 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1136 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1137 ha->host_no, t, l, cp->serial_number, comp_status,
1138 atomic_read(&fcport->state)));
1140 if ((sp->flags & SRB_IOCTL) ||
1141 atomic_read(&fcport->state) == FCS_DEVICE_DEAD) {
1142 cp->result = DID_NO_CONNECT << 16;
1143 if (atomic_read(&ha->loop_state) == LOOP_DOWN)
1144 sp->err_id = SRB_ERR_LOOP;
1146 sp->err_id = SRB_ERR_PORT;
1147 add_to_done_queue(ha, sp);
1149 qla2x00_extend_timeout(cp, EXTEND_CMD_TIMEOUT);
1150 add_to_retry_queue(ha, sp);
1153 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1154 qla2x00_mark_device_lost(ha, fcport, 1);
1161 DEBUG2(printk(KERN_INFO
1162 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1163 ha->host_no, comp_status, scsi_status));
1165 if (sp->flags & SRB_IOCTL) {
1166 cp->result = DID_RESET << 16;
1168 qla2x00_extend_timeout(cp, EXTEND_CMD_TIMEOUT);
1169 add_to_retry_queue(ha, sp);
1176 * hv2.19.12 - DID_ABORT does not retry the request if we
1177 * aborted this request then abort otherwise it must be a
1180 DEBUG2(printk(KERN_INFO
1181 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1182 ha->host_no, comp_status, scsi_status));
1184 cp->result = DID_RESET << 16;
1188 DEBUG2(printk(KERN_INFO
1189 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x.\n",
1190 ha->host_no, b, t, l, comp_status, scsi_status));
1192 cp->result = DID_BUS_BUSY << 16;
1194 fcport = lq->fclun->fcport;
1196 /* Check to see if logout occurred */
1197 if ((le16_to_cpu(pkt->status_flags) & SF_LOGOUT_SENT)) {
1198 qla2x00_mark_device_lost(ha, fcport, 1);
1203 DEBUG2(printk(KERN_INFO
1204 "scsi(%ld): QUEUE FULL status detected 0x%x-0x%x.\n",
1205 ha->host_no, comp_status, scsi_status));
1207 /* SCSI Mid-Layer handles device queue full */
1209 cp->result = DID_OK << 16 | lscsi_status;
1212 /* Adjust queue depth */
1213 ret = scsi_track_queue_full(cp->device,
1214 sp->lun_queue->out_cnt - 1);
1216 qla_printk(KERN_INFO, ha,
1217 "scsi(%ld:%d:%d:%d): Queue depth adjusted to %d.\n",
1218 ha->host_no, cp->device->channel, cp->device->id,
1219 cp->device->lun, ret);
1224 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1226 ha->host_no, comp_status, scsi_status));
1227 qla_printk(KERN_INFO, ha,
1228 "Unknown status detected 0x%x-0x%x.\n",
1229 comp_status, scsi_status);
1231 cp->result = DID_ERROR << 16;
1235 /* Place command on done queue. */
1236 if (ha->status_srb == NULL)
1237 add_to_done_queue(ha, sp);
1241 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1242 * @ha: SCSI driver HA context
1243 * @pkt: Entry pointer
1245 * Extended sense data.
1248 qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1250 uint8_t sense_sz = 0;
1251 srb_t *sp = ha->status_srb;
1252 struct scsi_cmnd *cp;
1254 if (sp != NULL && sp->request_sense_length != 0) {
1257 DEBUG2(printk("%s(): Cmd already returned back to OS "
1258 "sp=%p sp->state:%d\n", __func__, sp, sp->state));
1259 qla_printk(KERN_INFO, ha,
1260 "cmd is NULL: already returned to OS (sp=%p)\n",
1263 ha->status_srb = NULL;
1267 if (sp->request_sense_length > sizeof(pkt->data)) {
1268 sense_sz = sizeof(pkt->data);
1270 sense_sz = sp->request_sense_length;
1273 /* Move sense data. */
1274 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1275 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1277 sp->request_sense_ptr += sense_sz;
1278 sp->request_sense_length -= sense_sz;
1280 /* Place command on done queue. */
1281 if (sp->request_sense_length == 0) {
1282 add_to_done_queue(ha, sp);
1283 ha->status_srb = NULL;
1289 * qla2x00_error_entry() - Process an error entry.
1290 * @ha: SCSI driver HA context
1291 * @pkt: Entry pointer
1294 qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
1298 #if defined(QL_DEBUG_LEVEL_2)
1299 if (pkt->entry_status & RF_INV_E_ORDER)
1300 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1301 else if (pkt->entry_status & RF_INV_E_COUNT)
1302 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1303 else if (pkt->entry_status & RF_INV_E_PARAM)
1304 qla_printk(KERN_ERR, ha,
1305 "%s: Invalid Entry Parameter\n", __func__);
1306 else if (pkt->entry_status & RF_INV_E_TYPE)
1307 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1308 else if (pkt->entry_status & RF_BUSY)
1309 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1311 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1314 /* Validate handle. */
1315 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1316 sp = ha->outstanding_cmds[pkt->handle];
1321 /* Free outstanding command slot. */
1322 ha->outstanding_cmds[pkt->handle] = 0;
1325 sp->lun_queue->out_cnt--;
1327 /* Bad payload or header */
1328 if (pkt->entry_status &
1329 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1330 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1331 sp->cmd->result = DID_ERROR << 16;
1332 } else if (pkt->entry_status & RF_BUSY) {
1333 sp->cmd->result = DID_BUS_BUSY << 16;
1335 sp->cmd->result = DID_ERROR << 16;
1337 /* Place command on done queue. */
1338 add_to_done_queue(ha, sp);
1340 } else if (pkt->entry_type == COMMAND_A64_TYPE ||
1341 pkt->entry_type == COMMAND_TYPE) {
1342 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1344 qla_printk(KERN_WARNING, ha,
1345 "Error entry - invalid handle\n");
1347 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1348 if (ha->dpc_wait && !ha->dpc_active)
1354 * qla2x00_ms_entry() - Process a Management Server entry.
1355 * @ha: SCSI driver HA context
1356 * @index: Response queue out pointer
1359 qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
1363 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1364 __func__, ha->host_no, pkt, pkt->handle1));
1366 /* Validate handle. */
1367 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1368 sp = ha->outstanding_cmds[pkt->handle1];
1373 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1375 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1377 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1381 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1382 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1384 /* Free outstanding command slot. */
1385 ha->outstanding_cmds[pkt->handle1] = 0;
1387 add_to_done_queue(ha, sp);
1391 * qla2x00_check_sense() - Perform any sense data interrogation.
1395 * Returns QLA_SUCCESS if the lun queue is suspended, else
1396 * QLA_FUNCTION_FAILED (lun queue not suspended).
1399 qla2x00_check_sense(struct scsi_cmnd *cp, os_lun_t *lq)
1401 scsi_qla_host_t *ha;
1405 ha = (scsi_qla_host_t *) cp->device->host->hostdata;
1406 if ((cp->sense_buffer[0] & 0x70) != 0x70) {
1407 return (QLA_FUNCTION_FAILED);
1410 sp = (srb_t * )CMD_SP(cp);
1411 sp->flags |= SRB_GOT_SENSE;
1413 switch (cp->sense_buffer[2] & 0xf) {
1414 case RECOVERED_ERROR:
1415 cp->result = DID_OK << 16;
1416 cp->sense_buffer[0] = 0;
1420 fcport = lq->fclun->fcport;
1423 * Suspend the lun only for hard disk device type.
1425 if ((fcport->flags & FCF_TAPE_PRESENT) == 0 &&
1426 lq->q_state != LUN_STATE_TIMEOUT) {
1428 * If target is in process of being ready then suspend
1429 * lun for 6 secs and retry all the commands.
1431 if (cp->sense_buffer[12] == 0x4 &&
1432 cp->sense_buffer[13] == 0x1) {
1434 /* Suspend the lun for 6 secs */
1435 qla2x00_suspend_lun(ha, lq, 6,
1438 return (QLA_SUCCESS);
1444 return (QLA_FUNCTION_FAILED);