Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / drivers / scsi / qla4xxx / ql4_isr.c
blobfc84db4069f42d267d870b4deb56a763319312c0
1 /*
2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
8 #include "ql4_def.h"
9 #include "ql4_glbl.h"
10 #include "ql4_dbg.h"
11 #include "ql4_inline.h"
13 /**
14 * qla2x00_process_completed_request() - Process a Fast Post response.
15 * @ha: SCSI driver HA context
16 * @index: SRB index
17 **/
18 static void qla4xxx_process_completed_request(struct scsi_qla_host *ha,
19 uint32_t index)
21 struct srb *srb;
23 srb = qla4xxx_del_from_active_array(ha, index);
24 if (srb) {
25 /* Save ISP completion status */
26 srb->cmd->result = DID_OK << 16;
27 qla4xxx_srb_compl(ha, srb);
28 } else {
29 DEBUG2(printk("scsi%ld: Invalid ISP SCSI completion handle = "
30 "%d\n", ha->host_no, index));
31 set_bit(DPC_RESET_HA, &ha->dpc_flags);
35 /**
36 * qla4xxx_status_entry - processes status IOCBs
37 * @ha: Pointer to host adapter structure.
38 * @sts_entry: Pointer to status entry structure.
39 **/
40 static void qla4xxx_status_entry(struct scsi_qla_host *ha,
41 struct status_entry *sts_entry)
43 uint8_t scsi_status;
44 struct scsi_cmnd *cmd;
45 struct srb *srb;
46 struct ddb_entry *ddb_entry;
47 uint32_t residual;
48 uint16_t sensebytecnt;
50 if (sts_entry->completionStatus == SCS_COMPLETE &&
51 sts_entry->scsiStatus == 0) {
52 qla4xxx_process_completed_request(ha,
53 le32_to_cpu(sts_entry->
54 handle));
55 return;
58 srb = qla4xxx_del_from_active_array(ha, le32_to_cpu(sts_entry->handle));
59 if (!srb) {
60 /* FIXMEdg: Don't we need to reset ISP in this case??? */
61 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Status Entry invalid "
62 "handle 0x%x, sp=%p. This cmd may have already "
63 "been completed.\n", ha->host_no, __func__,
64 le32_to_cpu(sts_entry->handle), srb));
65 return;
68 cmd = srb->cmd;
69 if (cmd == NULL) {
70 DEBUG2(printk("scsi%ld: %s: Command already returned back to "
71 "OS pkt->handle=%d srb=%p srb->state:%d\n",
72 ha->host_no, __func__, sts_entry->handle,
73 srb, srb->state));
74 dev_warn(&ha->pdev->dev, "Command is NULL:"
75 " already returned to OS (srb=%p)\n", srb);
76 return;
79 ddb_entry = srb->ddb;
80 if (ddb_entry == NULL) {
81 cmd->result = DID_NO_CONNECT << 16;
82 goto status_entry_exit;
85 residual = le32_to_cpu(sts_entry->residualByteCnt);
87 /* Translate ISP error to a Linux SCSI error. */
88 scsi_status = sts_entry->scsiStatus;
89 switch (sts_entry->completionStatus) {
90 case SCS_COMPLETE:
91 if (scsi_status == 0) {
92 cmd->result = DID_OK << 16;
93 break;
96 if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) {
97 cmd->result = DID_ERROR << 16;
98 break;
101 if (sts_entry->iscsiFlags &ISCSI_FLAG_RESIDUAL_UNDER) {
102 scsi_set_resid(cmd, residual);
103 if ((scsi_bufflen(cmd) - residual) < cmd->underflow) {
105 cmd->result = DID_ERROR << 16;
107 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
108 "Mid-layer Data underrun0, "
109 "xferlen = 0x%x, "
110 "residual = 0x%x\n", ha->host_no,
111 cmd->device->channel,
112 cmd->device->id,
113 cmd->device->lun, __func__,
114 scsi_bufflen(cmd), residual));
115 break;
119 cmd->result = DID_OK << 16 | scsi_status;
121 if (scsi_status != SCSI_CHECK_CONDITION)
122 break;
124 /* Copy Sense Data into sense buffer. */
125 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
127 sensebytecnt = le16_to_cpu(sts_entry->senseDataByteCnt);
128 if (sensebytecnt == 0)
129 break;
131 memcpy(cmd->sense_buffer, sts_entry->senseData,
132 min_t(uint16_t, sensebytecnt, SCSI_SENSE_BUFFERSIZE));
134 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: sense key = %x, "
135 "ASC/ASCQ = %02x/%02x\n", ha->host_no,
136 cmd->device->channel, cmd->device->id,
137 cmd->device->lun, __func__,
138 sts_entry->senseData[2] & 0x0f,
139 sts_entry->senseData[12],
140 sts_entry->senseData[13]));
142 srb->flags |= SRB_GOT_SENSE;
143 break;
145 case SCS_INCOMPLETE:
146 /* Always set the status to DID_ERROR, since
147 * all conditions result in that status anyway */
148 cmd->result = DID_ERROR << 16;
149 break;
151 case SCS_RESET_OCCURRED:
152 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Device RESET occurred\n",
153 ha->host_no, cmd->device->channel,
154 cmd->device->id, cmd->device->lun, __func__));
156 cmd->result = DID_RESET << 16;
157 break;
159 case SCS_ABORTED:
160 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Abort occurred\n",
161 ha->host_no, cmd->device->channel,
162 cmd->device->id, cmd->device->lun, __func__));
164 cmd->result = DID_RESET << 16;
165 break;
167 case SCS_TIMEOUT:
168 DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: Timeout\n",
169 ha->host_no, cmd->device->channel,
170 cmd->device->id, cmd->device->lun));
172 cmd->result = DID_BUS_BUSY << 16;
175 * Mark device missing so that we won't continue to send
176 * I/O to this device. We should get a ddb state change
177 * AEN soon.
179 if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
180 qla4xxx_mark_device_missing(ha, ddb_entry);
181 break;
183 case SCS_DATA_UNDERRUN:
184 case SCS_DATA_OVERRUN:
185 if ((sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) ||
186 (sts_entry->completionStatus == SCS_DATA_OVERRUN)) {
187 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: " "Data overrun, "
188 "residual = 0x%x\n", ha->host_no,
189 cmd->device->channel, cmd->device->id,
190 cmd->device->lun, __func__, residual));
192 cmd->result = DID_ERROR << 16;
193 break;
196 scsi_set_resid(cmd, residual);
199 * If there is scsi_status, it takes precedense over
200 * underflow condition.
202 if (scsi_status != 0) {
203 cmd->result = DID_OK << 16 | scsi_status;
205 if (scsi_status != SCSI_CHECK_CONDITION)
206 break;
208 /* Copy Sense Data into sense buffer. */
209 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
211 sensebytecnt =
212 le16_to_cpu(sts_entry->senseDataByteCnt);
213 if (sensebytecnt == 0)
214 break;
216 memcpy(cmd->sense_buffer, sts_entry->senseData,
217 min_t(uint16_t, sensebytecnt, SCSI_SENSE_BUFFERSIZE));
219 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: sense key = %x, "
220 "ASC/ASCQ = %02x/%02x\n", ha->host_no,
221 cmd->device->channel, cmd->device->id,
222 cmd->device->lun, __func__,
223 sts_entry->senseData[2] & 0x0f,
224 sts_entry->senseData[12],
225 sts_entry->senseData[13]));
226 } else {
228 * If RISC reports underrun and target does not
229 * report it then we must have a lost frame, so
230 * tell upper layer to retry it by reporting a
231 * bus busy.
233 if ((sts_entry->iscsiFlags &
234 ISCSI_FLAG_RESIDUAL_UNDER) == 0) {
235 cmd->result = DID_BUS_BUSY << 16;
236 } else if ((scsi_bufflen(cmd) - residual) <
237 cmd->underflow) {
239 * Handle mid-layer underflow???
241 * For kernels less than 2.4, the driver must
242 * return an error if an underflow is detected.
243 * For kernels equal-to and above 2.4, the
244 * mid-layer will appearantly handle the
245 * underflow by detecting the residual count --
246 * unfortunately, we do not see where this is
247 * actually being done. In the interim, we
248 * will return DID_ERROR.
250 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
251 "Mid-layer Data underrun1, "
252 "xferlen = 0x%x, "
253 "residual = 0x%x\n", ha->host_no,
254 cmd->device->channel,
255 cmd->device->id,
256 cmd->device->lun, __func__,
257 scsi_bufflen(cmd), residual));
259 cmd->result = DID_ERROR << 16;
260 } else {
261 cmd->result = DID_OK << 16;
264 break;
266 case SCS_DEVICE_LOGGED_OUT:
267 case SCS_DEVICE_UNAVAILABLE:
269 * Mark device missing so that we won't continue to
270 * send I/O to this device. We should get a ddb
271 * state change AEN soon.
273 if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
274 qla4xxx_mark_device_missing(ha, ddb_entry);
276 cmd->result = DID_BUS_BUSY << 16;
277 break;
279 case SCS_QUEUE_FULL:
281 * SCSI Mid-Layer handles device queue full
283 cmd->result = DID_OK << 16 | sts_entry->scsiStatus;
284 DEBUG2(printk("scsi%ld:%d:%d: %s: QUEUE FULL detected "
285 "compl=%02x, scsi=%02x, state=%02x, iFlags=%02x,"
286 " iResp=%02x\n", ha->host_no, cmd->device->id,
287 cmd->device->lun, __func__,
288 sts_entry->completionStatus,
289 sts_entry->scsiStatus, sts_entry->state_flags,
290 sts_entry->iscsiFlags,
291 sts_entry->iscsiResponse));
292 break;
294 default:
295 cmd->result = DID_ERROR << 16;
296 break;
299 status_entry_exit:
301 /* complete the request */
302 srb->cc_stat = sts_entry->completionStatus;
303 qla4xxx_srb_compl(ha, srb);
307 * qla4xxx_process_response_queue - process response queue completions
308 * @ha: Pointer to host adapter structure.
310 * This routine process response queue completions in interrupt context.
311 * Hardware_lock locked upon entry
313 static void qla4xxx_process_response_queue(struct scsi_qla_host * ha)
315 uint32_t count = 0;
316 struct srb *srb = NULL;
317 struct status_entry *sts_entry;
319 /* Process all responses from response queue */
320 while ((ha->response_in =
321 (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in)) !=
322 ha->response_out) {
323 sts_entry = (struct status_entry *) ha->response_ptr;
324 count++;
326 /* Advance pointers for next entry */
327 if (ha->response_out == (RESPONSE_QUEUE_DEPTH - 1)) {
328 ha->response_out = 0;
329 ha->response_ptr = ha->response_ring;
330 } else {
331 ha->response_out++;
332 ha->response_ptr++;
335 /* process entry */
336 switch (sts_entry->hdr.entryType) {
337 case ET_STATUS:
339 * Common status - Single completion posted in single
340 * IOSB.
342 qla4xxx_status_entry(ha, sts_entry);
343 break;
345 case ET_PASSTHRU_STATUS:
346 break;
348 case ET_STATUS_CONTINUATION:
349 /* Just throw away the status continuation entries */
350 DEBUG2(printk("scsi%ld: %s: Status Continuation entry "
351 "- ignoring\n", ha->host_no, __func__));
352 break;
354 case ET_COMMAND:
355 /* ISP device queue is full. Command not
356 * accepted by ISP. Queue command for
357 * later */
359 srb = qla4xxx_del_from_active_array(ha,
360 le32_to_cpu(sts_entry->
361 handle));
362 if (srb == NULL)
363 goto exit_prq_invalid_handle;
365 DEBUG2(printk("scsi%ld: %s: FW device queue full, "
366 "srb %p\n", ha->host_no, __func__, srb));
368 /* ETRY normally by sending it back with
369 * DID_BUS_BUSY */
370 srb->cmd->result = DID_BUS_BUSY << 16;
371 qla4xxx_srb_compl(ha, srb);
372 break;
374 case ET_CONTINUE:
375 /* Just throw away the continuation entries */
376 DEBUG2(printk("scsi%ld: %s: Continuation entry - "
377 "ignoring\n", ha->host_no, __func__));
378 break;
380 default:
382 * Invalid entry in response queue, reset RISC
383 * firmware.
385 DEBUG2(printk("scsi%ld: %s: Invalid entry %x in "
386 "response queue \n", ha->host_no,
387 __func__,
388 sts_entry->hdr.entryType));
389 goto exit_prq_error;
394 * Done with responses, update the ISP For QLA4010, this also clears
395 * the interrupt.
397 writel(ha->response_out, &ha->reg->rsp_q_out);
398 readl(&ha->reg->rsp_q_out);
400 return;
402 exit_prq_invalid_handle:
403 DEBUG2(printk("scsi%ld: %s: Invalid handle(srb)=%p type=%x IOCS=%x\n",
404 ha->host_no, __func__, srb, sts_entry->hdr.entryType,
405 sts_entry->completionStatus));
407 exit_prq_error:
408 writel(ha->response_out, &ha->reg->rsp_q_out);
409 readl(&ha->reg->rsp_q_out);
411 set_bit(DPC_RESET_HA, &ha->dpc_flags);
415 * qla4xxx_isr_decode_mailbox - decodes mailbox status
416 * @ha: Pointer to host adapter structure.
417 * @mailbox_status: Mailbox status.
419 * This routine decodes the mailbox status during the ISR.
420 * Hardware_lock locked upon entry. runs in interrupt context.
422 static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
423 uint32_t mbox_status)
425 int i;
426 uint32_t mbox_stat2, mbox_stat3;
428 if ((mbox_status == MBOX_STS_BUSY) ||
429 (mbox_status == MBOX_STS_INTERMEDIATE_COMPLETION) ||
430 (mbox_status >> 12 == MBOX_COMPLETION_STATUS)) {
431 ha->mbox_status[0] = mbox_status;
433 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
435 * Copy all mailbox registers to a temporary
436 * location and set mailbox command done flag
438 for (i = 1; i < ha->mbox_status_count; i++)
439 ha->mbox_status[i] =
440 readl(&ha->reg->mailbox[i]);
442 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
444 } else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
445 /* Immediately process the AENs that don't require much work.
446 * Only queue the database_changed AENs */
447 if (ha->aen_log.count < MAX_AEN_ENTRIES) {
448 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
449 ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
450 readl(&ha->reg->mailbox[i]);
451 ha->aen_log.count++;
453 switch (mbox_status) {
454 case MBOX_ASTS_SYSTEM_ERROR:
455 /* Log Mailbox registers */
456 if (ql4xdontresethba) {
457 DEBUG2(printk("%s:Dont Reset HBA\n",
458 __func__));
459 } else {
460 set_bit(AF_GET_CRASH_RECORD, &ha->flags);
461 set_bit(DPC_RESET_HA, &ha->dpc_flags);
463 break;
465 case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
466 case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
467 case MBOX_ASTS_NVRAM_INVALID:
468 case MBOX_ASTS_IP_ADDRESS_CHANGED:
469 case MBOX_ASTS_DHCP_LEASE_EXPIRED:
470 DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
471 "Reset HA\n", ha->host_no, mbox_status));
472 set_bit(DPC_RESET_HA, &ha->dpc_flags);
473 break;
475 case MBOX_ASTS_LINK_UP:
476 DEBUG2(printk("scsi%ld: AEN %04x Adapter LINK UP\n",
477 ha->host_no, mbox_status));
478 set_bit(AF_LINK_UP, &ha->flags);
479 break;
481 case MBOX_ASTS_LINK_DOWN:
482 DEBUG2(printk("scsi%ld: AEN %04x Adapter LINK DOWN\n",
483 ha->host_no, mbox_status));
484 clear_bit(AF_LINK_UP, &ha->flags);
485 break;
487 case MBOX_ASTS_HEARTBEAT:
488 ha->seconds_since_last_heartbeat = 0;
489 break;
491 case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
492 DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
493 "ACQUIRED\n", ha->host_no, mbox_status));
494 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
495 break;
497 case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
498 case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
499 * mode
500 * only */
501 case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
502 case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
503 case MBOX_ASTS_SUBNET_STATE_CHANGE:
504 /* No action */
505 DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
506 mbox_status));
507 break;
509 case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
510 mbox_stat2 = readl(&ha->reg->mailbox[2]);
511 mbox_stat3 = readl(&ha->reg->mailbox[3]);
513 if ((mbox_stat3 == 5) && (mbox_stat2 == 3))
514 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
515 else if ((mbox_stat3 == 2) && (mbox_stat2 == 5))
516 set_bit(DPC_RESET_HA, &ha->dpc_flags);
517 break;
519 case MBOX_ASTS_MAC_ADDRESS_CHANGED:
520 case MBOX_ASTS_DNS:
521 /* No action */
522 DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
523 "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
524 ha->host_no, mbox_status,
525 readl(&ha->reg->mailbox[1]),
526 readl(&ha->reg->mailbox[2])));
527 break;
529 case MBOX_ASTS_SELF_TEST_FAILED:
530 case MBOX_ASTS_LOGIN_FAILED:
531 /* No action */
532 DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
533 "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
534 ha->host_no, mbox_status,
535 readl(&ha->reg->mailbox[1]),
536 readl(&ha->reg->mailbox[2]),
537 readl(&ha->reg->mailbox[3])));
538 break;
540 case MBOX_ASTS_DATABASE_CHANGED:
541 /* Queue AEN information and process it in the DPC
542 * routine */
543 if (ha->aen_q_count > 0) {
545 /* decrement available counter */
546 ha->aen_q_count--;
548 for (i = 1; i < MBOX_AEN_REG_COUNT; i++)
549 ha->aen_q[ha->aen_in].mbox_sts[i] =
550 readl(&ha->reg->mailbox[i]);
552 ha->aen_q[ha->aen_in].mbox_sts[0] = mbox_status;
554 /* print debug message */
555 DEBUG2(printk("scsi%ld: AEN[%d] %04x queued"
556 " mb1:0x%x mb2:0x%x mb3:0x%x mb4:0x%x\n",
557 ha->host_no, ha->aen_in,
558 mbox_status,
559 ha->aen_q[ha->aen_in].mbox_sts[1],
560 ha->aen_q[ha->aen_in].mbox_sts[2],
561 ha->aen_q[ha->aen_in].mbox_sts[3],
562 ha->aen_q[ha->aen_in]. mbox_sts[4]));
563 /* advance pointer */
564 ha->aen_in++;
565 if (ha->aen_in == MAX_AEN_ENTRIES)
566 ha->aen_in = 0;
568 /* The DPC routine will process the aen */
569 set_bit(DPC_AEN, &ha->dpc_flags);
570 } else {
571 DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
572 "overflowed! AEN LOST!!\n",
573 ha->host_no, __func__,
574 mbox_status));
576 DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
577 ha->host_no));
579 for (i = 0; i < MAX_AEN_ENTRIES; i++) {
580 DEBUG2(printk("AEN[%d] %04x %04x %04x "
581 "%04x\n", i,
582 ha->aen_q[i].mbox_sts[0],
583 ha->aen_q[i].mbox_sts[1],
584 ha->aen_q[i].mbox_sts[2],
585 ha->aen_q[i].mbox_sts[3]));
588 break;
590 default:
591 DEBUG2(printk(KERN_WARNING
592 "scsi%ld: AEN %04x UNKNOWN\n",
593 ha->host_no, mbox_status));
594 break;
596 } else {
597 DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
598 ha->host_no, mbox_status));
600 ha->mbox_status[0] = mbox_status;
605 * qla4xxx_interrupt_service_routine - isr
606 * @ha: pointer to host adapter structure.
608 * This is the main interrupt service routine.
609 * hardware_lock locked upon entry. runs in interrupt context.
611 void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
612 uint32_t intr_status)
614 /* Process response queue interrupt. */
615 if (intr_status & CSR_SCSI_COMPLETION_INTR)
616 qla4xxx_process_response_queue(ha);
618 /* Process mailbox/asynch event interrupt.*/
619 if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
620 qla4xxx_isr_decode_mailbox(ha,
621 readl(&ha->reg->mailbox[0]));
623 /* Clear Mailbox Interrupt */
624 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
625 &ha->reg->ctrl_status);
626 readl(&ha->reg->ctrl_status);
631 * qla4xxx_intr_handler - hardware interrupt handler.
632 * @irq: Unused
633 * @dev_id: Pointer to host adapter structure
635 irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
637 struct scsi_qla_host *ha;
638 uint32_t intr_status;
639 unsigned long flags = 0;
640 uint8_t reqs_count = 0;
642 ha = (struct scsi_qla_host *) dev_id;
643 if (!ha) {
644 DEBUG2(printk(KERN_INFO
645 "qla4xxx: Interrupt with NULL host ptr\n"));
646 return IRQ_NONE;
649 spin_lock_irqsave(&ha->hardware_lock, flags);
651 ha->isr_count++;
653 * Repeatedly service interrupts up to a maximum of
654 * MAX_REQS_SERVICED_PER_INTR
656 while (1) {
658 * Read interrupt status
660 if (le32_to_cpu(ha->shadow_regs->rsp_q_in) !=
661 ha->response_out)
662 intr_status = CSR_SCSI_COMPLETION_INTR;
663 else
664 intr_status = readl(&ha->reg->ctrl_status);
666 if ((intr_status &
667 (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) ==
668 0) {
669 if (reqs_count == 0)
670 ha->spurious_int_count++;
671 break;
674 if (intr_status & CSR_FATAL_ERROR) {
675 DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
676 "Status 0x%04x\n", ha->host_no,
677 readl(isp_port_error_status (ha))));
679 /* Issue Soft Reset to clear this error condition.
680 * This will prevent the RISC from repeatedly
681 * interrupting the driver; thus, allowing the DPC to
682 * get scheduled to continue error recovery.
683 * NOTE: Disabling RISC interrupts does not work in
684 * this case, as CSR_FATAL_ERROR overrides
685 * CSR_SCSI_INTR_ENABLE */
686 if ((readl(&ha->reg->ctrl_status) &
687 CSR_SCSI_RESET_INTR) == 0) {
688 writel(set_rmask(CSR_SOFT_RESET),
689 &ha->reg->ctrl_status);
690 readl(&ha->reg->ctrl_status);
693 writel(set_rmask(CSR_FATAL_ERROR),
694 &ha->reg->ctrl_status);
695 readl(&ha->reg->ctrl_status);
697 __qla4xxx_disable_intrs(ha);
699 set_bit(DPC_RESET_HA, &ha->dpc_flags);
701 break;
702 } else if (intr_status & CSR_SCSI_RESET_INTR) {
703 clear_bit(AF_ONLINE, &ha->flags);
704 __qla4xxx_disable_intrs(ha);
706 writel(set_rmask(CSR_SCSI_RESET_INTR),
707 &ha->reg->ctrl_status);
708 readl(&ha->reg->ctrl_status);
710 if (!ql4_mod_unload)
711 set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
713 break;
714 } else if (intr_status & INTR_PENDING) {
715 qla4xxx_interrupt_service_routine(ha, intr_status);
716 ha->total_io_count++;
717 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
718 break;
720 intr_status = 0;
724 spin_unlock_irqrestore(&ha->hardware_lock, flags);
726 return IRQ_HANDLED;
730 * qla4xxx_process_aen - processes AENs generated by firmware
731 * @ha: pointer to host adapter structure.
732 * @process_aen: type of AENs to process
734 * Processes specific types of Asynchronous Events generated by firmware.
735 * The type of AENs to process is specified by process_aen and can be
736 * PROCESS_ALL_AENS 0
737 * FLUSH_DDB_CHANGED_AENS 1
738 * RELOGIN_DDB_CHANGED_AENS 2
740 void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
742 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
743 struct aen *aen;
744 int i;
745 unsigned long flags;
747 spin_lock_irqsave(&ha->hardware_lock, flags);
748 while (ha->aen_out != ha->aen_in) {
749 aen = &ha->aen_q[ha->aen_out];
750 /* copy aen information to local structure */
751 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
752 mbox_sts[i] = aen->mbox_sts[i];
754 ha->aen_q_count++;
755 ha->aen_out++;
757 if (ha->aen_out == MAX_AEN_ENTRIES)
758 ha->aen_out = 0;
760 spin_unlock_irqrestore(&ha->hardware_lock, flags);
762 DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
763 " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
764 (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
765 mbox_sts[0], mbox_sts[1], mbox_sts[2],
766 mbox_sts[3], mbox_sts[4]));
768 switch (mbox_sts[0]) {
769 case MBOX_ASTS_DATABASE_CHANGED:
770 if (process_aen == FLUSH_DDB_CHANGED_AENS) {
771 DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
772 "[%d] state=%04x FLUSHED!\n",
773 ha->host_no, ha->aen_out,
774 mbox_sts[0], mbox_sts[2],
775 mbox_sts[3]));
776 break;
777 } else if (process_aen == RELOGIN_DDB_CHANGED_AENS) {
778 /* for use during init time, we only want to
779 * relogin non-active ddbs */
780 struct ddb_entry *ddb_entry;
782 ddb_entry =
783 /* FIXME: name length? */
784 qla4xxx_lookup_ddb_by_fw_index(ha,
785 mbox_sts[2]);
786 if (!ddb_entry)
787 break;
789 ddb_entry->dev_scan_wait_to_complete_relogin =
791 ddb_entry->dev_scan_wait_to_start_relogin =
792 jiffies +
793 ((ddb_entry->default_time2wait +
794 4) * HZ);
796 DEBUG2(printk("scsi%ld: ddb index [%d] initate"
797 " RELOGIN after %d seconds\n",
798 ha->host_no,
799 ddb_entry->fw_ddb_index,
800 ddb_entry->default_time2wait +
801 4));
802 break;
805 if (mbox_sts[1] == 0) { /* Global DB change. */
806 qla4xxx_reinitialize_ddb_list(ha);
807 } else if (mbox_sts[1] == 1) { /* Specific device. */
808 qla4xxx_process_ddb_changed(ha, mbox_sts[2],
809 mbox_sts[3]);
811 break;
813 spin_lock_irqsave(&ha->hardware_lock, flags);
815 spin_unlock_irqrestore(&ha->hardware_lock, flags);