PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / scsi / qla4xxx / ql4_isr.c
bloba3c8bc7706c298a03810eb608550fa6e53ff7529
1 /*
2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2013 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 * qla4xxx_copy_sense - copy sense data into cmd sense buffer
15 * @ha: Pointer to host adapter structure.
16 * @sts_entry: Pointer to status entry structure.
17 * @srb: Pointer to srb structure.
18 **/
19 static void qla4xxx_copy_sense(struct scsi_qla_host *ha,
20 struct status_entry *sts_entry,
21 struct srb *srb)
23 struct scsi_cmnd *cmd = srb->cmd;
24 uint16_t sense_len;
26 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
27 sense_len = le16_to_cpu(sts_entry->senseDataByteCnt);
28 if (sense_len == 0) {
29 DEBUG2(ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%d:%d: %s:"
30 " sense len 0\n", ha->host_no,
31 cmd->device->channel, cmd->device->id,
32 cmd->device->lun, __func__));
33 ha->status_srb = NULL;
34 return;
36 /* Save total available sense length,
37 * not to exceed cmd's sense buffer size */
38 sense_len = min_t(uint16_t, sense_len, SCSI_SENSE_BUFFERSIZE);
39 srb->req_sense_ptr = cmd->sense_buffer;
40 srb->req_sense_len = sense_len;
42 /* Copy sense from sts_entry pkt */
43 sense_len = min_t(uint16_t, sense_len, IOCB_MAX_SENSEDATA_LEN);
44 memcpy(cmd->sense_buffer, sts_entry->senseData, sense_len);
46 DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: %s: sense key = %x, "
47 "ASL= %02x, ASC/ASCQ = %02x/%02x\n", ha->host_no,
48 cmd->device->channel, cmd->device->id,
49 cmd->device->lun, __func__,
50 sts_entry->senseData[2] & 0x0f,
51 sts_entry->senseData[7],
52 sts_entry->senseData[12],
53 sts_entry->senseData[13]));
55 DEBUG5(qla4xxx_dump_buffer(cmd->sense_buffer, sense_len));
56 srb->flags |= SRB_GOT_SENSE;
58 /* Update srb, in case a sts_cont pkt follows */
59 srb->req_sense_ptr += sense_len;
60 srb->req_sense_len -= sense_len;
61 if (srb->req_sense_len != 0)
62 ha->status_srb = srb;
63 else
64 ha->status_srb = NULL;
67 /**
68 * qla4xxx_status_cont_entry - Process a Status Continuations entry.
69 * @ha: SCSI driver HA context
70 * @sts_cont: Entry pointer
72 * Extended sense data.
74 static void
75 qla4xxx_status_cont_entry(struct scsi_qla_host *ha,
76 struct status_cont_entry *sts_cont)
78 struct srb *srb = ha->status_srb;
79 struct scsi_cmnd *cmd;
80 uint16_t sense_len;
82 if (srb == NULL)
83 return;
85 cmd = srb->cmd;
86 if (cmd == NULL) {
87 DEBUG2(printk(KERN_INFO "scsi%ld: %s: Cmd already returned "
88 "back to OS srb=%p srb->state:%d\n", ha->host_no,
89 __func__, srb, srb->state));
90 ha->status_srb = NULL;
91 return;
94 /* Copy sense data. */
95 sense_len = min_t(uint16_t, srb->req_sense_len,
96 IOCB_MAX_EXT_SENSEDATA_LEN);
97 memcpy(srb->req_sense_ptr, sts_cont->ext_sense_data, sense_len);
98 DEBUG5(qla4xxx_dump_buffer(srb->req_sense_ptr, sense_len));
100 srb->req_sense_ptr += sense_len;
101 srb->req_sense_len -= sense_len;
103 /* Place command on done queue. */
104 if (srb->req_sense_len == 0) {
105 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
106 ha->status_srb = NULL;
111 * qla4xxx_status_entry - processes status IOCBs
112 * @ha: Pointer to host adapter structure.
113 * @sts_entry: Pointer to status entry structure.
115 static void qla4xxx_status_entry(struct scsi_qla_host *ha,
116 struct status_entry *sts_entry)
118 uint8_t scsi_status;
119 struct scsi_cmnd *cmd;
120 struct srb *srb;
121 struct ddb_entry *ddb_entry;
122 uint32_t residual;
124 srb = qla4xxx_del_from_active_array(ha, le32_to_cpu(sts_entry->handle));
125 if (!srb) {
126 ql4_printk(KERN_WARNING, ha, "%s invalid status entry: "
127 "handle=0x%0x, srb=%p\n", __func__,
128 sts_entry->handle, srb);
129 if (is_qla80XX(ha))
130 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
131 else
132 set_bit(DPC_RESET_HA, &ha->dpc_flags);
133 return;
136 cmd = srb->cmd;
137 if (cmd == NULL) {
138 DEBUG2(printk("scsi%ld: %s: Command already returned back to "
139 "OS pkt->handle=%d srb=%p srb->state:%d\n",
140 ha->host_no, __func__, sts_entry->handle,
141 srb, srb->state));
142 ql4_printk(KERN_WARNING, ha, "Command is NULL:"
143 " already returned to OS (srb=%p)\n", srb);
144 return;
147 ddb_entry = srb->ddb;
148 if (ddb_entry == NULL) {
149 cmd->result = DID_NO_CONNECT << 16;
150 goto status_entry_exit;
153 residual = le32_to_cpu(sts_entry->residualByteCnt);
155 /* Translate ISP error to a Linux SCSI error. */
156 scsi_status = sts_entry->scsiStatus;
157 switch (sts_entry->completionStatus) {
158 case SCS_COMPLETE:
160 if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) {
161 cmd->result = DID_ERROR << 16;
162 break;
165 if (sts_entry->iscsiFlags &ISCSI_FLAG_RESIDUAL_UNDER) {
166 scsi_set_resid(cmd, residual);
167 if (!scsi_status && ((scsi_bufflen(cmd) - residual) <
168 cmd->underflow)) {
170 cmd->result = DID_ERROR << 16;
172 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
173 "Mid-layer Data underrun0, "
174 "xferlen = 0x%x, "
175 "residual = 0x%x\n", ha->host_no,
176 cmd->device->channel,
177 cmd->device->id,
178 cmd->device->lun, __func__,
179 scsi_bufflen(cmd), residual));
180 break;
184 cmd->result = DID_OK << 16 | scsi_status;
186 if (scsi_status != SCSI_CHECK_CONDITION)
187 break;
189 /* Copy Sense Data into sense buffer. */
190 qla4xxx_copy_sense(ha, sts_entry, srb);
191 break;
193 case SCS_INCOMPLETE:
194 /* Always set the status to DID_ERROR, since
195 * all conditions result in that status anyway */
196 cmd->result = DID_ERROR << 16;
197 break;
199 case SCS_RESET_OCCURRED:
200 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Device RESET occurred\n",
201 ha->host_no, cmd->device->channel,
202 cmd->device->id, cmd->device->lun, __func__));
204 cmd->result = DID_RESET << 16;
205 break;
207 case SCS_ABORTED:
208 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Abort occurred\n",
209 ha->host_no, cmd->device->channel,
210 cmd->device->id, cmd->device->lun, __func__));
212 cmd->result = DID_RESET << 16;
213 break;
215 case SCS_TIMEOUT:
216 DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: Timeout\n",
217 ha->host_no, cmd->device->channel,
218 cmd->device->id, cmd->device->lun));
220 cmd->result = DID_TRANSPORT_DISRUPTED << 16;
223 * Mark device missing so that we won't continue to send
224 * I/O to this device. We should get a ddb state change
225 * AEN soon.
227 if (iscsi_is_session_online(ddb_entry->sess))
228 qla4xxx_mark_device_missing(ddb_entry->sess);
229 break;
231 case SCS_DATA_UNDERRUN:
232 case SCS_DATA_OVERRUN:
233 if ((sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) ||
234 (sts_entry->completionStatus == SCS_DATA_OVERRUN)) {
235 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: " "Data overrun\n",
236 ha->host_no,
237 cmd->device->channel, cmd->device->id,
238 cmd->device->lun, __func__));
240 cmd->result = DID_ERROR << 16;
241 break;
244 scsi_set_resid(cmd, residual);
246 if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_UNDER) {
248 /* Both the firmware and target reported UNDERRUN:
250 * MID-LAYER UNDERFLOW case:
251 * Some kernels do not properly detect midlayer
252 * underflow, so we manually check it and return
253 * ERROR if the minimum required data was not
254 * received.
256 * ALL OTHER cases:
257 * Fall thru to check scsi_status
259 if (!scsi_status && (scsi_bufflen(cmd) - residual) <
260 cmd->underflow) {
261 DEBUG2(ql4_printk(KERN_INFO, ha,
262 "scsi%ld:%d:%d:%d: %s: Mid-layer Data underrun, xferlen = 0x%x,residual = 0x%x\n",
263 ha->host_no,
264 cmd->device->channel,
265 cmd->device->id,
266 cmd->device->lun, __func__,
267 scsi_bufflen(cmd),
268 residual));
270 cmd->result = DID_ERROR << 16;
271 break;
274 } else if (scsi_status != SAM_STAT_TASK_SET_FULL &&
275 scsi_status != SAM_STAT_BUSY) {
278 * The firmware reports UNDERRUN, but the target does
279 * not report it:
281 * scsi_status | host_byte device_byte
282 * | (19:16) (7:0)
283 * ============= | ========= ===========
284 * TASK_SET_FULL | DID_OK scsi_status
285 * BUSY | DID_OK scsi_status
286 * ALL OTHERS | DID_ERROR scsi_status
288 * Note: If scsi_status is task set full or busy,
289 * then this else if would fall thru to check the
290 * scsi_status and return DID_OK.
293 DEBUG2(ql4_printk(KERN_INFO, ha,
294 "scsi%ld:%d:%d:%d: %s: Dropped frame(s) detected (0x%x of 0x%x bytes).\n",
295 ha->host_no,
296 cmd->device->channel,
297 cmd->device->id,
298 cmd->device->lun, __func__,
299 residual,
300 scsi_bufflen(cmd)));
302 cmd->result = DID_ERROR << 16 | scsi_status;
303 goto check_scsi_status;
306 cmd->result = DID_OK << 16 | scsi_status;
308 check_scsi_status:
309 if (scsi_status == SAM_STAT_CHECK_CONDITION)
310 qla4xxx_copy_sense(ha, sts_entry, srb);
312 break;
314 case SCS_DEVICE_LOGGED_OUT:
315 case SCS_DEVICE_UNAVAILABLE:
316 DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: SCS_DEVICE "
317 "state: 0x%x\n", ha->host_no,
318 cmd->device->channel, cmd->device->id,
319 cmd->device->lun, sts_entry->completionStatus));
321 * Mark device missing so that we won't continue to
322 * send I/O to this device. We should get a ddb
323 * state change AEN soon.
325 if (iscsi_is_session_online(ddb_entry->sess))
326 qla4xxx_mark_device_missing(ddb_entry->sess);
328 cmd->result = DID_TRANSPORT_DISRUPTED << 16;
329 break;
331 case SCS_QUEUE_FULL:
333 * SCSI Mid-Layer handles device queue full
335 cmd->result = DID_OK << 16 | sts_entry->scsiStatus;
336 DEBUG2(printk("scsi%ld:%d:%d: %s: QUEUE FULL detected "
337 "compl=%02x, scsi=%02x, state=%02x, iFlags=%02x,"
338 " iResp=%02x\n", ha->host_no, cmd->device->id,
339 cmd->device->lun, __func__,
340 sts_entry->completionStatus,
341 sts_entry->scsiStatus, sts_entry->state_flags,
342 sts_entry->iscsiFlags,
343 sts_entry->iscsiResponse));
344 break;
346 default:
347 cmd->result = DID_ERROR << 16;
348 break;
351 status_entry_exit:
353 /* complete the request, if not waiting for status_continuation pkt */
354 srb->cc_stat = sts_entry->completionStatus;
355 if (ha->status_srb == NULL)
356 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
360 * qla4xxx_passthru_status_entry - processes passthru status IOCBs (0x3C)
361 * @ha: Pointer to host adapter structure.
362 * @sts_entry: Pointer to status entry structure.
364 static void qla4xxx_passthru_status_entry(struct scsi_qla_host *ha,
365 struct passthru_status *sts_entry)
367 struct iscsi_task *task;
368 struct ddb_entry *ddb_entry;
369 struct ql4_task_data *task_data;
370 struct iscsi_cls_conn *cls_conn;
371 struct iscsi_conn *conn;
372 itt_t itt;
373 uint32_t fw_ddb_index;
375 itt = sts_entry->handle;
376 fw_ddb_index = le32_to_cpu(sts_entry->target);
378 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index);
380 if (ddb_entry == NULL) {
381 ql4_printk(KERN_ERR, ha, "%s: Invalid target index = 0x%x\n",
382 __func__, sts_entry->target);
383 return;
386 cls_conn = ddb_entry->conn;
387 conn = cls_conn->dd_data;
388 spin_lock(&conn->session->lock);
389 task = iscsi_itt_to_task(conn, itt);
390 spin_unlock(&conn->session->lock);
392 if (task == NULL) {
393 ql4_printk(KERN_ERR, ha, "%s: Task is NULL\n", __func__);
394 return;
397 task_data = task->dd_data;
398 memcpy(&task_data->sts, sts_entry, sizeof(struct passthru_status));
399 ha->iocb_cnt -= task_data->iocb_req_cnt;
400 queue_work(ha->task_wq, &task_data->task_work);
403 static struct mrb *qla4xxx_del_mrb_from_active_array(struct scsi_qla_host *ha,
404 uint32_t index)
406 struct mrb *mrb = NULL;
408 /* validate handle and remove from active array */
409 if (index >= MAX_MRB)
410 return mrb;
412 mrb = ha->active_mrb_array[index];
413 ha->active_mrb_array[index] = NULL;
414 if (!mrb)
415 return mrb;
417 /* update counters */
418 ha->iocb_cnt -= mrb->iocb_cnt;
420 return mrb;
423 static void qla4xxx_mbox_status_entry(struct scsi_qla_host *ha,
424 struct mbox_status_iocb *mbox_sts_entry)
426 struct mrb *mrb;
427 uint32_t status;
428 uint32_t data_size;
430 mrb = qla4xxx_del_mrb_from_active_array(ha,
431 le32_to_cpu(mbox_sts_entry->handle));
433 if (mrb == NULL) {
434 ql4_printk(KERN_WARNING, ha, "%s: mrb[%d] is null\n", __func__,
435 mbox_sts_entry->handle);
436 return;
439 switch (mrb->mbox_cmd) {
440 case MBOX_CMD_PING:
441 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: mbox_cmd = 0x%x, "
442 "mbox_sts[0] = 0x%x, mbox_sts[6] = 0x%x\n",
443 __func__, mrb->mbox_cmd,
444 mbox_sts_entry->out_mbox[0],
445 mbox_sts_entry->out_mbox[6]));
447 if (mbox_sts_entry->out_mbox[0] == MBOX_STS_COMMAND_COMPLETE)
448 status = ISCSI_PING_SUCCESS;
449 else
450 status = mbox_sts_entry->out_mbox[6];
452 data_size = sizeof(mbox_sts_entry->out_mbox);
454 qla4xxx_post_ping_evt_work(ha, status, mrb->pid, data_size,
455 (uint8_t *) mbox_sts_entry->out_mbox);
456 break;
458 default:
459 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: invalid mbox_cmd = "
460 "0x%x\n", __func__, mrb->mbox_cmd));
463 kfree(mrb);
464 return;
468 * qla4xxx_process_response_queue - process response queue completions
469 * @ha: Pointer to host adapter structure.
471 * This routine process response queue completions in interrupt context.
472 * Hardware_lock locked upon entry
474 void qla4xxx_process_response_queue(struct scsi_qla_host *ha)
476 uint32_t count = 0;
477 struct srb *srb = NULL;
478 struct status_entry *sts_entry;
480 /* Process all responses from response queue */
481 while ((ha->response_ptr->signature != RESPONSE_PROCESSED)) {
482 sts_entry = (struct status_entry *) ha->response_ptr;
483 count++;
485 /* Advance pointers for next entry */
486 if (ha->response_out == (RESPONSE_QUEUE_DEPTH - 1)) {
487 ha->response_out = 0;
488 ha->response_ptr = ha->response_ring;
489 } else {
490 ha->response_out++;
491 ha->response_ptr++;
494 /* process entry */
495 switch (sts_entry->hdr.entryType) {
496 case ET_STATUS:
497 /* Common status */
498 qla4xxx_status_entry(ha, sts_entry);
499 break;
501 case ET_PASSTHRU_STATUS:
502 if (sts_entry->hdr.systemDefined == SD_ISCSI_PDU)
503 qla4xxx_passthru_status_entry(ha,
504 (struct passthru_status *)sts_entry);
505 else
506 ql4_printk(KERN_ERR, ha,
507 "%s: Invalid status received\n",
508 __func__);
510 break;
512 case ET_STATUS_CONTINUATION:
513 qla4xxx_status_cont_entry(ha,
514 (struct status_cont_entry *) sts_entry);
515 break;
517 case ET_COMMAND:
518 /* ISP device queue is full. Command not
519 * accepted by ISP. Queue command for
520 * later */
522 srb = qla4xxx_del_from_active_array(ha,
523 le32_to_cpu(sts_entry->
524 handle));
525 if (srb == NULL)
526 goto exit_prq_invalid_handle;
528 DEBUG2(printk("scsi%ld: %s: FW device queue full, "
529 "srb %p\n", ha->host_no, __func__, srb));
531 /* ETRY normally by sending it back with
532 * DID_BUS_BUSY */
533 srb->cmd->result = DID_BUS_BUSY << 16;
534 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
535 break;
537 case ET_CONTINUE:
538 /* Just throw away the continuation entries */
539 DEBUG2(printk("scsi%ld: %s: Continuation entry - "
540 "ignoring\n", ha->host_no, __func__));
541 break;
543 case ET_MBOX_STATUS:
544 DEBUG2(ql4_printk(KERN_INFO, ha,
545 "%s: mbox status IOCB\n", __func__));
546 qla4xxx_mbox_status_entry(ha,
547 (struct mbox_status_iocb *)sts_entry);
548 break;
550 default:
552 * Invalid entry in response queue, reset RISC
553 * firmware.
555 DEBUG2(printk("scsi%ld: %s: Invalid entry %x in "
556 "response queue \n", ha->host_no,
557 __func__,
558 sts_entry->hdr.entryType));
559 goto exit_prq_error;
561 ((struct response *)sts_entry)->signature = RESPONSE_PROCESSED;
562 wmb();
566 * Tell ISP we're done with response(s). This also clears the interrupt.
568 ha->isp_ops->complete_iocb(ha);
570 return;
572 exit_prq_invalid_handle:
573 DEBUG2(printk("scsi%ld: %s: Invalid handle(srb)=%p type=%x IOCS=%x\n",
574 ha->host_no, __func__, srb, sts_entry->hdr.entryType,
575 sts_entry->completionStatus));
577 exit_prq_error:
578 ha->isp_ops->complete_iocb(ha);
579 set_bit(DPC_RESET_HA, &ha->dpc_flags);
583 * qla4_83xx_loopback_in_progress: Is loopback in progress?
584 * @ha: Pointer to host adapter structure.
585 * @ret: 1 = loopback in progress, 0 = loopback not in progress
587 static int qla4_83xx_loopback_in_progress(struct scsi_qla_host *ha)
589 int rval = 1;
591 if (is_qla8032(ha) || is_qla8042(ha)) {
592 if ((ha->idc_info.info2 & ENABLE_INTERNAL_LOOPBACK) ||
593 (ha->idc_info.info2 & ENABLE_EXTERNAL_LOOPBACK)) {
594 DEBUG2(ql4_printk(KERN_INFO, ha,
595 "%s: Loopback diagnostics in progress\n",
596 __func__));
597 rval = 1;
598 } else {
599 DEBUG2(ql4_printk(KERN_INFO, ha,
600 "%s: Loopback diagnostics not in progress\n",
601 __func__));
602 rval = 0;
606 return rval;
609 static void qla4xxx_update_ipaddr_state(struct scsi_qla_host *ha,
610 uint32_t ipaddr_idx,
611 uint32_t ipaddr_fw_state)
613 uint8_t ipaddr_state;
614 uint8_t ip_idx;
616 ip_idx = ipaddr_idx & 0xF;
617 ipaddr_state = qla4xxx_set_ipaddr_state((uint8_t)ipaddr_fw_state);
619 switch (ip_idx) {
620 case 0:
621 ha->ip_config.ipv4_addr_state = ipaddr_state;
622 break;
623 case 1:
624 ha->ip_config.ipv6_link_local_state = ipaddr_state;
625 break;
626 case 2:
627 ha->ip_config.ipv6_addr0_state = ipaddr_state;
628 break;
629 case 3:
630 ha->ip_config.ipv6_addr1_state = ipaddr_state;
631 break;
632 default:
633 ql4_printk(KERN_INFO, ha, "%s: Invalid IPADDR index %d\n",
634 __func__, ip_idx);
640 * qla4xxx_isr_decode_mailbox - decodes mailbox status
641 * @ha: Pointer to host adapter structure.
642 * @mailbox_status: Mailbox status.
644 * This routine decodes the mailbox status during the ISR.
645 * Hardware_lock locked upon entry. runs in interrupt context.
647 static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
648 uint32_t mbox_status)
650 int i;
651 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
652 __le32 __iomem *mailbox_out;
653 uint32_t opcode = 0;
655 if (is_qla8032(ha) || is_qla8042(ha))
656 mailbox_out = &ha->qla4_83xx_reg->mailbox_out[0];
657 else if (is_qla8022(ha))
658 mailbox_out = &ha->qla4_82xx_reg->mailbox_out[0];
659 else
660 mailbox_out = &ha->reg->mailbox[0];
662 if ((mbox_status == MBOX_STS_BUSY) ||
663 (mbox_status == MBOX_STS_INTERMEDIATE_COMPLETION) ||
664 (mbox_status >> 12 == MBOX_COMPLETION_STATUS)) {
665 ha->mbox_status[0] = mbox_status;
667 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
669 * Copy all mailbox registers to a temporary
670 * location and set mailbox command done flag
672 for (i = 0; i < ha->mbox_status_count; i++)
673 ha->mbox_status[i] = readl(&mailbox_out[i]);
675 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
677 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags))
678 complete(&ha->mbx_intr_comp);
680 } else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
681 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
682 mbox_sts[i] = readl(&mailbox_out[i]);
684 /* Immediately process the AENs that don't require much work.
685 * Only queue the database_changed AENs */
686 if (ha->aen_log.count < MAX_AEN_ENTRIES) {
687 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
688 ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
689 mbox_sts[i];
690 ha->aen_log.count++;
692 switch (mbox_status) {
693 case MBOX_ASTS_SYSTEM_ERROR:
694 /* Log Mailbox registers */
695 ql4_printk(KERN_INFO, ha, "%s: System Err\n", __func__);
696 qla4xxx_dump_registers(ha);
698 if ((is_qla8022(ha) && ql4xdontresethba) ||
699 ((is_qla8032(ha) || is_qla8042(ha)) &&
700 qla4_83xx_idc_dontreset(ha))) {
701 DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n",
702 ha->host_no, __func__));
703 } else {
704 set_bit(AF_GET_CRASH_RECORD, &ha->flags);
705 set_bit(DPC_RESET_HA, &ha->dpc_flags);
707 break;
709 case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
710 case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
711 case MBOX_ASTS_NVRAM_INVALID:
712 case MBOX_ASTS_IP_ADDRESS_CHANGED:
713 case MBOX_ASTS_DHCP_LEASE_EXPIRED:
714 DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
715 "Reset HA\n", ha->host_no, mbox_status));
716 if (is_qla80XX(ha))
717 set_bit(DPC_RESET_HA_FW_CONTEXT,
718 &ha->dpc_flags);
719 else
720 set_bit(DPC_RESET_HA, &ha->dpc_flags);
721 break;
723 case MBOX_ASTS_LINK_UP:
724 set_bit(AF_LINK_UP, &ha->flags);
725 if (test_bit(AF_INIT_DONE, &ha->flags))
726 set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
728 ql4_printk(KERN_INFO, ha, "%s: LINK UP\n", __func__);
729 qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKUP,
730 sizeof(mbox_sts),
731 (uint8_t *) mbox_sts);
733 if ((is_qla8032(ha) || is_qla8042(ha)) &&
734 ha->notify_link_up_comp)
735 complete(&ha->link_up_comp);
737 break;
739 case MBOX_ASTS_LINK_DOWN:
740 clear_bit(AF_LINK_UP, &ha->flags);
741 if (test_bit(AF_INIT_DONE, &ha->flags)) {
742 set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
743 qla4xxx_wake_dpc(ha);
746 ql4_printk(KERN_INFO, ha, "%s: LINK DOWN\n", __func__);
747 qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKDOWN,
748 sizeof(mbox_sts),
749 (uint8_t *) mbox_sts);
750 break;
752 case MBOX_ASTS_HEARTBEAT:
753 ha->seconds_since_last_heartbeat = 0;
754 break;
756 case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
757 DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
758 "ACQUIRED\n", ha->host_no, mbox_status));
759 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
760 break;
762 case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
763 case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
764 * mode
765 * only */
766 case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
767 case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
768 case MBOX_ASTS_SUBNET_STATE_CHANGE:
769 case MBOX_ASTS_DUPLICATE_IP:
770 /* No action */
771 DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
772 mbox_status));
773 break;
775 case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
776 printk("scsi%ld: AEN %04x, mbox_sts[2]=%04x, "
777 "mbox_sts[3]=%04x\n", ha->host_no, mbox_sts[0],
778 mbox_sts[2], mbox_sts[3]);
780 qla4xxx_update_ipaddr_state(ha, mbox_sts[5],
781 mbox_sts[3]);
782 /* mbox_sts[2] = Old ACB state
783 * mbox_sts[3] = new ACB state */
784 if ((mbox_sts[3] == ACB_STATE_VALID) &&
785 ((mbox_sts[2] == ACB_STATE_TENTATIVE) ||
786 (mbox_sts[2] == ACB_STATE_ACQUIRING))) {
787 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
788 } else if ((mbox_sts[3] == ACB_STATE_ACQUIRING) &&
789 (mbox_sts[2] == ACB_STATE_VALID)) {
790 if (is_qla80XX(ha))
791 set_bit(DPC_RESET_HA_FW_CONTEXT,
792 &ha->dpc_flags);
793 else
794 set_bit(DPC_RESET_HA, &ha->dpc_flags);
795 } else if (mbox_sts[3] == ACB_STATE_DISABLING) {
796 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ACB in disabling state\n",
797 ha->host_no, __func__);
798 } else if ((mbox_sts[3] == ACB_STATE_UNCONFIGURED)) {
799 complete(&ha->disable_acb_comp);
800 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ACB state unconfigured\n",
801 ha->host_no, __func__);
803 break;
805 case MBOX_ASTS_MAC_ADDRESS_CHANGED:
806 case MBOX_ASTS_DNS:
807 /* No action */
808 DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
809 "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
810 ha->host_no, mbox_sts[0],
811 mbox_sts[1], mbox_sts[2]));
812 break;
814 case MBOX_ASTS_SELF_TEST_FAILED:
815 case MBOX_ASTS_LOGIN_FAILED:
816 /* No action */
817 DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
818 "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
819 ha->host_no, mbox_sts[0], mbox_sts[1],
820 mbox_sts[2], mbox_sts[3]));
821 break;
823 case MBOX_ASTS_DATABASE_CHANGED:
824 /* Queue AEN information and process it in the DPC
825 * routine */
826 if (ha->aen_q_count > 0) {
828 /* decrement available counter */
829 ha->aen_q_count--;
831 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
832 ha->aen_q[ha->aen_in].mbox_sts[i] =
833 mbox_sts[i];
835 /* print debug message */
836 DEBUG2(printk("scsi%ld: AEN[%d] %04x queued "
837 "mb1:0x%x mb2:0x%x mb3:0x%x "
838 "mb4:0x%x mb5:0x%x\n",
839 ha->host_no, ha->aen_in,
840 mbox_sts[0], mbox_sts[1],
841 mbox_sts[2], mbox_sts[3],
842 mbox_sts[4], mbox_sts[5]));
844 /* advance pointer */
845 ha->aen_in++;
846 if (ha->aen_in == MAX_AEN_ENTRIES)
847 ha->aen_in = 0;
849 /* The DPC routine will process the aen */
850 set_bit(DPC_AEN, &ha->dpc_flags);
851 } else {
852 DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
853 "overflowed! AEN LOST!!\n",
854 ha->host_no, __func__,
855 mbox_sts[0]));
857 DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
858 ha->host_no));
860 for (i = 0; i < MAX_AEN_ENTRIES; i++) {
861 DEBUG2(printk("AEN[%d] %04x %04x %04x "
862 "%04x\n", i, mbox_sts[0],
863 mbox_sts[1], mbox_sts[2],
864 mbox_sts[3]));
867 break;
869 case MBOX_ASTS_TXSCVR_INSERTED:
870 DEBUG2(printk(KERN_WARNING
871 "scsi%ld: AEN %04x Transceiver"
872 " inserted\n", ha->host_no, mbox_sts[0]));
873 break;
875 case MBOX_ASTS_TXSCVR_REMOVED:
876 DEBUG2(printk(KERN_WARNING
877 "scsi%ld: AEN %04x Transceiver"
878 " removed\n", ha->host_no, mbox_sts[0]));
879 break;
881 case MBOX_ASTS_IDC_REQUEST_NOTIFICATION:
882 if (is_qla8032(ha) || is_qla8042(ha)) {
883 DEBUG2(ql4_printk(KERN_INFO, ha,
884 "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x\n",
885 ha->host_no, mbox_sts[0],
886 mbox_sts[1], mbox_sts[2],
887 mbox_sts[3], mbox_sts[4]));
888 opcode = mbox_sts[1] >> 16;
889 if ((opcode == MBOX_CMD_SET_PORT_CONFIG) ||
890 (opcode == MBOX_CMD_PORT_RESET)) {
891 set_bit(DPC_POST_IDC_ACK,
892 &ha->dpc_flags);
893 ha->idc_info.request_desc = mbox_sts[1];
894 ha->idc_info.info1 = mbox_sts[2];
895 ha->idc_info.info2 = mbox_sts[3];
896 ha->idc_info.info3 = mbox_sts[4];
897 qla4xxx_wake_dpc(ha);
900 break;
902 case MBOX_ASTS_IDC_COMPLETE:
903 if (is_qla8032(ha) || is_qla8042(ha)) {
904 DEBUG2(ql4_printk(KERN_INFO, ha,
905 "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x\n",
906 ha->host_no, mbox_sts[0],
907 mbox_sts[1], mbox_sts[2],
908 mbox_sts[3], mbox_sts[4]));
909 DEBUG2(ql4_printk(KERN_INFO, ha,
910 "scsi:%ld: AEN %04x IDC Complete notification\n",
911 ha->host_no, mbox_sts[0]));
913 opcode = mbox_sts[1] >> 16;
914 if (ha->notify_idc_comp)
915 complete(&ha->idc_comp);
917 if ((opcode == MBOX_CMD_SET_PORT_CONFIG) ||
918 (opcode == MBOX_CMD_PORT_RESET))
919 ha->idc_info.info2 = mbox_sts[3];
921 if (qla4_83xx_loopback_in_progress(ha)) {
922 set_bit(AF_LOOPBACK, &ha->flags);
923 } else {
924 clear_bit(AF_LOOPBACK, &ha->flags);
925 if (ha->saved_acb)
926 set_bit(DPC_RESTORE_ACB,
927 &ha->dpc_flags);
929 qla4xxx_wake_dpc(ha);
931 break;
933 case MBOX_ASTS_IPV6_DEFAULT_ROUTER_CHANGED:
934 DEBUG2(ql4_printk(KERN_INFO, ha,
935 "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
936 ha->host_no, mbox_sts[0], mbox_sts[1],
937 mbox_sts[2], mbox_sts[3], mbox_sts[4],
938 mbox_sts[5]));
939 DEBUG2(ql4_printk(KERN_INFO, ha,
940 "scsi%ld: AEN %04x Received IPv6 default router changed notification\n",
941 ha->host_no, mbox_sts[0]));
942 break;
944 case MBOX_ASTS_IDC_TIME_EXTEND_NOTIFICATION:
945 DEBUG2(ql4_printk(KERN_INFO, ha,
946 "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
947 ha->host_no, mbox_sts[0], mbox_sts[1],
948 mbox_sts[2], mbox_sts[3], mbox_sts[4],
949 mbox_sts[5]));
950 DEBUG2(ql4_printk(KERN_INFO, ha,
951 "scsi%ld: AEN %04x Received IDC Extend Timeout notification\n",
952 ha->host_no, mbox_sts[0]));
953 /* new IDC timeout */
954 ha->idc_extend_tmo = mbox_sts[1];
955 break;
957 case MBOX_ASTS_INITIALIZATION_FAILED:
958 DEBUG2(ql4_printk(KERN_INFO, ha,
959 "scsi%ld: AEN %04x, mbox_sts[3]=%08x\n",
960 ha->host_no, mbox_sts[0],
961 mbox_sts[3]));
962 break;
964 case MBOX_ASTS_SYSTEM_WARNING_EVENT:
965 DEBUG2(ql4_printk(KERN_WARNING, ha,
966 "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
967 ha->host_no, mbox_sts[0], mbox_sts[1],
968 mbox_sts[2], mbox_sts[3], mbox_sts[4],
969 mbox_sts[5]));
970 break;
972 case MBOX_ASTS_DCBX_CONF_CHANGE:
973 DEBUG2(ql4_printk(KERN_INFO, ha,
974 "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
975 ha->host_no, mbox_sts[0], mbox_sts[1],
976 mbox_sts[2], mbox_sts[3], mbox_sts[4],
977 mbox_sts[5]));
978 DEBUG2(ql4_printk(KERN_INFO, ha,
979 "scsi%ld: AEN %04x Received DCBX configuration changed notification\n",
980 ha->host_no, mbox_sts[0]));
981 break;
983 default:
984 DEBUG2(printk(KERN_WARNING
985 "scsi%ld: AEN %04x UNKNOWN\n",
986 ha->host_no, mbox_sts[0]));
987 break;
989 } else {
990 DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
991 ha->host_no, mbox_status));
993 ha->mbox_status[0] = mbox_status;
997 void qla4_83xx_interrupt_service_routine(struct scsi_qla_host *ha,
998 uint32_t intr_status)
1000 /* Process mailbox/asynch event interrupt.*/
1001 if (intr_status) {
1002 qla4xxx_isr_decode_mailbox(ha,
1003 readl(&ha->qla4_83xx_reg->mailbox_out[0]));
1004 /* clear the interrupt */
1005 writel(0, &ha->qla4_83xx_reg->risc_intr);
1006 } else {
1007 qla4xxx_process_response_queue(ha);
1010 /* clear the interrupt */
1011 writel(0, &ha->qla4_83xx_reg->mb_int_mask);
1015 * qla4_82xx_interrupt_service_routine - isr
1016 * @ha: pointer to host adapter structure.
1018 * This is the main interrupt service routine.
1019 * hardware_lock locked upon entry. runs in interrupt context.
1021 void qla4_82xx_interrupt_service_routine(struct scsi_qla_host *ha,
1022 uint32_t intr_status)
1024 /* Process response queue interrupt. */
1025 if (intr_status & HSRX_RISC_IOCB_INT)
1026 qla4xxx_process_response_queue(ha);
1028 /* Process mailbox/asynch event interrupt.*/
1029 if (intr_status & HSRX_RISC_MB_INT)
1030 qla4xxx_isr_decode_mailbox(ha,
1031 readl(&ha->qla4_82xx_reg->mailbox_out[0]));
1033 /* clear the interrupt */
1034 writel(0, &ha->qla4_82xx_reg->host_int);
1035 readl(&ha->qla4_82xx_reg->host_int);
1039 * qla4xxx_interrupt_service_routine - isr
1040 * @ha: pointer to host adapter structure.
1042 * This is the main interrupt service routine.
1043 * hardware_lock locked upon entry. runs in interrupt context.
1045 void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
1046 uint32_t intr_status)
1048 /* Process response queue interrupt. */
1049 if (intr_status & CSR_SCSI_COMPLETION_INTR)
1050 qla4xxx_process_response_queue(ha);
1052 /* Process mailbox/asynch event interrupt.*/
1053 if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
1054 qla4xxx_isr_decode_mailbox(ha,
1055 readl(&ha->reg->mailbox[0]));
1057 /* Clear Mailbox Interrupt */
1058 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
1059 &ha->reg->ctrl_status);
1060 readl(&ha->reg->ctrl_status);
1065 * qla4_82xx_spurious_interrupt - processes spurious interrupt
1066 * @ha: pointer to host adapter structure.
1067 * @reqs_count: .
1070 static void qla4_82xx_spurious_interrupt(struct scsi_qla_host *ha,
1071 uint8_t reqs_count)
1073 if (reqs_count)
1074 return;
1076 DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
1077 if (is_qla8022(ha)) {
1078 writel(0, &ha->qla4_82xx_reg->host_int);
1079 if (test_bit(AF_INTx_ENABLED, &ha->flags))
1080 qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
1081 0xfbff);
1083 ha->spurious_int_count++;
1087 * qla4xxx_intr_handler - hardware interrupt handler.
1088 * @irq: Unused
1089 * @dev_id: Pointer to host adapter structure
1091 irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
1093 struct scsi_qla_host *ha;
1094 uint32_t intr_status;
1095 unsigned long flags = 0;
1096 uint8_t reqs_count = 0;
1098 ha = (struct scsi_qla_host *) dev_id;
1099 if (!ha) {
1100 DEBUG2(printk(KERN_INFO
1101 "qla4xxx: Interrupt with NULL host ptr\n"));
1102 return IRQ_NONE;
1105 spin_lock_irqsave(&ha->hardware_lock, flags);
1107 ha->isr_count++;
1109 * Repeatedly service interrupts up to a maximum of
1110 * MAX_REQS_SERVICED_PER_INTR
1112 while (1) {
1114 * Read interrupt status
1116 if (ha->isp_ops->rd_shdw_rsp_q_in(ha) !=
1117 ha->response_out)
1118 intr_status = CSR_SCSI_COMPLETION_INTR;
1119 else
1120 intr_status = readl(&ha->reg->ctrl_status);
1122 if ((intr_status &
1123 (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
1124 if (reqs_count == 0)
1125 ha->spurious_int_count++;
1126 break;
1129 if (intr_status & CSR_FATAL_ERROR) {
1130 DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
1131 "Status 0x%04x\n", ha->host_no,
1132 readl(isp_port_error_status (ha))));
1134 /* Issue Soft Reset to clear this error condition.
1135 * This will prevent the RISC from repeatedly
1136 * interrupting the driver; thus, allowing the DPC to
1137 * get scheduled to continue error recovery.
1138 * NOTE: Disabling RISC interrupts does not work in
1139 * this case, as CSR_FATAL_ERROR overrides
1140 * CSR_SCSI_INTR_ENABLE */
1141 if ((readl(&ha->reg->ctrl_status) &
1142 CSR_SCSI_RESET_INTR) == 0) {
1143 writel(set_rmask(CSR_SOFT_RESET),
1144 &ha->reg->ctrl_status);
1145 readl(&ha->reg->ctrl_status);
1148 writel(set_rmask(CSR_FATAL_ERROR),
1149 &ha->reg->ctrl_status);
1150 readl(&ha->reg->ctrl_status);
1152 __qla4xxx_disable_intrs(ha);
1154 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1156 break;
1157 } else if (intr_status & CSR_SCSI_RESET_INTR) {
1158 clear_bit(AF_ONLINE, &ha->flags);
1159 __qla4xxx_disable_intrs(ha);
1161 writel(set_rmask(CSR_SCSI_RESET_INTR),
1162 &ha->reg->ctrl_status);
1163 readl(&ha->reg->ctrl_status);
1165 if (!test_bit(AF_HA_REMOVAL, &ha->flags))
1166 set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1168 break;
1169 } else if (intr_status & INTR_PENDING) {
1170 ha->isp_ops->interrupt_service_routine(ha, intr_status);
1171 ha->total_io_count++;
1172 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
1173 break;
1177 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1179 return IRQ_HANDLED;
1183 * qla4_82xx_intr_handler - hardware interrupt handler.
1184 * @irq: Unused
1185 * @dev_id: Pointer to host adapter structure
1187 irqreturn_t qla4_82xx_intr_handler(int irq, void *dev_id)
1189 struct scsi_qla_host *ha = dev_id;
1190 uint32_t intr_status;
1191 uint32_t status;
1192 unsigned long flags = 0;
1193 uint8_t reqs_count = 0;
1195 if (unlikely(pci_channel_offline(ha->pdev)))
1196 return IRQ_HANDLED;
1198 ha->isr_count++;
1199 status = qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1200 if (!(status & ha->nx_legacy_intr.int_vec_bit))
1201 return IRQ_NONE;
1203 status = qla4_82xx_rd_32(ha, ISR_INT_STATE_REG);
1204 if (!ISR_IS_LEGACY_INTR_TRIGGERED(status)) {
1205 DEBUG7(ql4_printk(KERN_INFO, ha,
1206 "%s legacy Int not triggered\n", __func__));
1207 return IRQ_NONE;
1210 /* clear the interrupt */
1211 qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
1213 /* read twice to ensure write is flushed */
1214 qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1215 qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1217 spin_lock_irqsave(&ha->hardware_lock, flags);
1218 while (1) {
1219 if (!(readl(&ha->qla4_82xx_reg->host_int) &
1220 ISRX_82XX_RISC_INT)) {
1221 qla4_82xx_spurious_interrupt(ha, reqs_count);
1222 break;
1224 intr_status = readl(&ha->qla4_82xx_reg->host_status);
1225 if ((intr_status &
1226 (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
1227 qla4_82xx_spurious_interrupt(ha, reqs_count);
1228 break;
1231 ha->isp_ops->interrupt_service_routine(ha, intr_status);
1233 /* Enable Interrupt */
1234 qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
1236 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
1237 break;
1240 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1241 return IRQ_HANDLED;
1244 #define LEG_INT_PTR_B31 (1 << 31)
1245 #define LEG_INT_PTR_B30 (1 << 30)
1246 #define PF_BITS_MASK (0xF << 16)
1249 * qla4_83xx_intr_handler - hardware interrupt handler.
1250 * @irq: Unused
1251 * @dev_id: Pointer to host adapter structure
1253 irqreturn_t qla4_83xx_intr_handler(int irq, void *dev_id)
1255 struct scsi_qla_host *ha = dev_id;
1256 uint32_t leg_int_ptr = 0;
1257 unsigned long flags = 0;
1259 ha->isr_count++;
1260 leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
1262 /* Legacy interrupt is valid if bit31 of leg_int_ptr is set */
1263 if (!(leg_int_ptr & LEG_INT_PTR_B31)) {
1264 DEBUG7(ql4_printk(KERN_ERR, ha,
1265 "%s: Legacy Interrupt Bit 31 not set, spurious interrupt!\n",
1266 __func__));
1267 return IRQ_NONE;
1270 /* Validate the PCIE function ID set in leg_int_ptr bits [19..16] */
1271 if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit) {
1272 DEBUG7(ql4_printk(KERN_ERR, ha,
1273 "%s: Incorrect function ID 0x%x in legacy interrupt register, ha->pf_bit = 0x%x\n",
1274 __func__, (leg_int_ptr & PF_BITS_MASK),
1275 ha->pf_bit));
1276 return IRQ_NONE;
1279 /* To de-assert legacy interrupt, write 0 to Legacy Interrupt Trigger
1280 * Control register and poll till Legacy Interrupt Pointer register
1281 * bit30 is 0.
1283 writel(0, &ha->qla4_83xx_reg->leg_int_trig);
1284 do {
1285 leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
1286 if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit)
1287 break;
1288 } while (leg_int_ptr & LEG_INT_PTR_B30);
1290 spin_lock_irqsave(&ha->hardware_lock, flags);
1291 leg_int_ptr = readl(&ha->qla4_83xx_reg->risc_intr);
1292 ha->isp_ops->interrupt_service_routine(ha, leg_int_ptr);
1293 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1295 return IRQ_HANDLED;
1298 irqreturn_t
1299 qla4_8xxx_msi_handler(int irq, void *dev_id)
1301 struct scsi_qla_host *ha;
1303 ha = (struct scsi_qla_host *) dev_id;
1304 if (!ha) {
1305 DEBUG2(printk(KERN_INFO
1306 "qla4xxx: MSIX: Interrupt with NULL host ptr\n"));
1307 return IRQ_NONE;
1310 ha->isr_count++;
1311 /* clear the interrupt */
1312 qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
1314 /* read twice to ensure write is flushed */
1315 qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1316 qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1318 return qla4_8xxx_default_intr_handler(irq, dev_id);
1321 static irqreturn_t qla4_83xx_mailbox_intr_handler(int irq, void *dev_id)
1323 struct scsi_qla_host *ha = dev_id;
1324 unsigned long flags;
1325 uint32_t ival = 0;
1327 spin_lock_irqsave(&ha->hardware_lock, flags);
1329 ival = readl(&ha->qla4_83xx_reg->risc_intr);
1330 if (ival == 0) {
1331 ql4_printk(KERN_INFO, ha,
1332 "%s: It is a spurious mailbox interrupt!\n",
1333 __func__);
1334 ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
1335 ival &= ~INT_MASK_FW_MB;
1336 writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
1337 goto exit;
1340 qla4xxx_isr_decode_mailbox(ha,
1341 readl(&ha->qla4_83xx_reg->mailbox_out[0]));
1342 writel(0, &ha->qla4_83xx_reg->risc_intr);
1343 ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
1344 ival &= ~INT_MASK_FW_MB;
1345 writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
1346 ha->isr_count++;
1347 exit:
1348 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1349 return IRQ_HANDLED;
1353 * qla4_8xxx_default_intr_handler - hardware interrupt handler.
1354 * @irq: Unused
1355 * @dev_id: Pointer to host adapter structure
1357 * This interrupt handler is called directly for MSI-X, and
1358 * called indirectly for MSI.
1360 irqreturn_t
1361 qla4_8xxx_default_intr_handler(int irq, void *dev_id)
1363 struct scsi_qla_host *ha = dev_id;
1364 unsigned long flags;
1365 uint32_t intr_status;
1366 uint8_t reqs_count = 0;
1368 if (is_qla8032(ha) || is_qla8042(ha)) {
1369 qla4_83xx_mailbox_intr_handler(irq, dev_id);
1370 } else {
1371 spin_lock_irqsave(&ha->hardware_lock, flags);
1372 while (1) {
1373 if (!(readl(&ha->qla4_82xx_reg->host_int) &
1374 ISRX_82XX_RISC_INT)) {
1375 qla4_82xx_spurious_interrupt(ha, reqs_count);
1376 break;
1379 intr_status = readl(&ha->qla4_82xx_reg->host_status);
1380 if ((intr_status &
1381 (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
1382 qla4_82xx_spurious_interrupt(ha, reqs_count);
1383 break;
1386 ha->isp_ops->interrupt_service_routine(ha, intr_status);
1388 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
1389 break;
1391 ha->isr_count++;
1392 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1394 return IRQ_HANDLED;
1397 irqreturn_t
1398 qla4_8xxx_msix_rsp_q(int irq, void *dev_id)
1400 struct scsi_qla_host *ha = dev_id;
1401 unsigned long flags;
1402 uint32_t ival = 0;
1404 spin_lock_irqsave(&ha->hardware_lock, flags);
1405 if (is_qla8032(ha) || is_qla8042(ha)) {
1406 ival = readl(&ha->qla4_83xx_reg->iocb_int_mask);
1407 if (ival == 0) {
1408 ql4_printk(KERN_INFO, ha, "%s: It is a spurious iocb interrupt!\n",
1409 __func__);
1410 goto exit_msix_rsp_q;
1412 qla4xxx_process_response_queue(ha);
1413 writel(0, &ha->qla4_83xx_reg->iocb_int_mask);
1414 } else {
1415 qla4xxx_process_response_queue(ha);
1416 writel(0, &ha->qla4_82xx_reg->host_int);
1418 ha->isr_count++;
1419 exit_msix_rsp_q:
1420 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1421 return IRQ_HANDLED;
1425 * qla4xxx_process_aen - processes AENs generated by firmware
1426 * @ha: pointer to host adapter structure.
1427 * @process_aen: type of AENs to process
1429 * Processes specific types of Asynchronous Events generated by firmware.
1430 * The type of AENs to process is specified by process_aen and can be
1431 * PROCESS_ALL_AENS 0
1432 * FLUSH_DDB_CHANGED_AENS 1
1433 * RELOGIN_DDB_CHANGED_AENS 2
1435 void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
1437 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
1438 struct aen *aen;
1439 int i;
1440 unsigned long flags;
1442 spin_lock_irqsave(&ha->hardware_lock, flags);
1443 while (ha->aen_out != ha->aen_in) {
1444 aen = &ha->aen_q[ha->aen_out];
1445 /* copy aen information to local structure */
1446 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
1447 mbox_sts[i] = aen->mbox_sts[i];
1449 ha->aen_q_count++;
1450 ha->aen_out++;
1452 if (ha->aen_out == MAX_AEN_ENTRIES)
1453 ha->aen_out = 0;
1455 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1457 DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
1458 " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
1459 (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
1460 mbox_sts[0], mbox_sts[1], mbox_sts[2],
1461 mbox_sts[3], mbox_sts[4]));
1463 switch (mbox_sts[0]) {
1464 case MBOX_ASTS_DATABASE_CHANGED:
1465 switch (process_aen) {
1466 case FLUSH_DDB_CHANGED_AENS:
1467 DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
1468 "[%d] state=%04x FLUSHED!\n",
1469 ha->host_no, ha->aen_out,
1470 mbox_sts[0], mbox_sts[2],
1471 mbox_sts[3]));
1472 break;
1473 case PROCESS_ALL_AENS:
1474 default:
1475 /* Specific device. */
1476 if (mbox_sts[1] == 1)
1477 qla4xxx_process_ddb_changed(ha,
1478 mbox_sts[2], mbox_sts[3],
1479 mbox_sts[4]);
1480 break;
1483 spin_lock_irqsave(&ha->hardware_lock, flags);
1485 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1488 int qla4xxx_request_irqs(struct scsi_qla_host *ha)
1490 int ret;
1492 if (is_qla40XX(ha))
1493 goto try_intx;
1495 if (ql4xenablemsix == 2) {
1496 /* Note: MSI Interrupts not supported for ISP8324 and ISP8042 */
1497 if (is_qla8032(ha) || is_qla8042(ha)) {
1498 ql4_printk(KERN_INFO, ha, "%s: MSI Interrupts not supported for ISP%04x, Falling back-to INTx mode\n",
1499 __func__, ha->pdev->device);
1500 goto try_intx;
1502 goto try_msi;
1505 if (ql4xenablemsix == 0 || ql4xenablemsix != 1)
1506 goto try_intx;
1508 /* Trying MSI-X */
1509 ret = qla4_8xxx_enable_msix(ha);
1510 if (!ret) {
1511 DEBUG2(ql4_printk(KERN_INFO, ha,
1512 "MSI-X: Enabled (0x%X).\n", ha->revision_id));
1513 goto irq_attached;
1514 } else {
1515 if (is_qla8032(ha) || is_qla8042(ha)) {
1516 ql4_printk(KERN_INFO, ha, "%s: ISP%04x: MSI-X: Falling back-to INTx mode. ret = %d\n",
1517 __func__, ha->pdev->device, ret);
1518 goto try_intx;
1522 ql4_printk(KERN_WARNING, ha,
1523 "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
1525 try_msi:
1526 /* Trying MSI */
1527 ret = pci_enable_msi(ha->pdev);
1528 if (!ret) {
1529 ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
1530 0, DRIVER_NAME, ha);
1531 if (!ret) {
1532 DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1533 set_bit(AF_MSI_ENABLED, &ha->flags);
1534 goto irq_attached;
1535 } else {
1536 ql4_printk(KERN_WARNING, ha,
1537 "MSI: Failed to reserve interrupt %d "
1538 "already in use.\n", ha->pdev->irq);
1539 pci_disable_msi(ha->pdev);
1544 * Prevent interrupts from falling back to INTx mode in cases where
1545 * interrupts cannot get acquired through MSI-X or MSI mode.
1547 if (is_qla8022(ha)) {
1548 ql4_printk(KERN_WARNING, ha, "IRQ not attached -- %d.\n", ret);
1549 goto irq_not_attached;
1551 try_intx:
1552 /* Trying INTx */
1553 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
1554 IRQF_SHARED, DRIVER_NAME, ha);
1555 if (!ret) {
1556 DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
1557 set_bit(AF_INTx_ENABLED, &ha->flags);
1558 goto irq_attached;
1560 } else {
1561 ql4_printk(KERN_WARNING, ha,
1562 "INTx: Failed to reserve interrupt %d already in"
1563 " use.\n", ha->pdev->irq);
1564 goto irq_not_attached;
1567 irq_attached:
1568 set_bit(AF_IRQ_ATTACHED, &ha->flags);
1569 ha->host->irq = ha->pdev->irq;
1570 ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
1571 __func__, ha->pdev->irq);
1572 irq_not_attached:
1573 return ret;
1576 void qla4xxx_free_irqs(struct scsi_qla_host *ha)
1578 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags)) {
1579 if (test_bit(AF_MSIX_ENABLED, &ha->flags)) {
1580 qla4_8xxx_disable_msix(ha);
1581 } else if (test_and_clear_bit(AF_MSI_ENABLED, &ha->flags)) {
1582 free_irq(ha->pdev->irq, ha);
1583 pci_disable_msi(ha->pdev);
1584 } else if (test_and_clear_bit(AF_INTx_ENABLED, &ha->flags)) {
1585 free_irq(ha->pdev->irq, ha);