blob: 15ea81465ce4eaf7facddd6ecce4d682b36b6b5b [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
Vikas Chaudharyc68cdbf2012-08-22 07:55:09 -04003 * Copyright (c) 2003-2012 QLogic Corporation
David Somayajuluafaf5a22006-09-19 10:28:00 -07004 *
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7
8#include "ql4_def.h"
David C Somayajulu401425b2007-05-23 18:03:20 -07009#include "ql4_glbl.h"
10#include "ql4_dbg.h"
11#include "ql4_inline.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070012
13/**
Karen Higgins94bced32009-07-15 15:02:58 -050014 * 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 **/
19static void qla4xxx_copy_sense(struct scsi_qla_host *ha,
20 struct status_entry *sts_entry,
21 struct srb *srb)
22{
23 struct scsi_cmnd *cmd = srb->cmd;
24 uint16_t sense_len;
25
26 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
27 sense_len = le16_to_cpu(sts_entry->senseDataByteCnt);
Prasanna Mumbai6d78bd52011-05-17 23:17:06 -070028 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;
Karen Higgins94bced32009-07-15 15:02:58 -050034 return;
Prasanna Mumbai6d78bd52011-05-17 23:17:06 -070035 }
Karen Higgins94bced32009-07-15 15:02:58 -050036 /* 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;
41
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);
45
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]));
54
55 DEBUG5(qla4xxx_dump_buffer(cmd->sense_buffer, sense_len));
56 srb->flags |= SRB_GOT_SENSE;
57
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;
65}
66
67/**
68 * qla4xxx_status_cont_entry - Process a Status Continuations entry.
69 * @ha: SCSI driver HA context
70 * @sts_cont: Entry pointer
71 *
72 * Extended sense data.
73 */
74static void
75qla4xxx_status_cont_entry(struct scsi_qla_host *ha,
76 struct status_cont_entry *sts_cont)
77{
78 struct srb *srb = ha->status_srb;
79 struct scsi_cmnd *cmd;
Vikas Chaudhary735e4152010-10-06 22:48:53 -070080 uint16_t sense_len;
Karen Higgins94bced32009-07-15 15:02:58 -050081
82 if (srb == NULL)
83 return;
84
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;
92 }
93
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));
99
100 srb->req_sense_ptr += sense_len;
101 srb->req_sense_len -= sense_len;
102
103 /* Place command on done queue. */
104 if (srb->req_sense_len == 0) {
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530105 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
Karen Higgins94bced32009-07-15 15:02:58 -0500106 ha->status_srb = NULL;
107 }
108}
109
110/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700111 * qla4xxx_status_entry - processes status IOCBs
112 * @ha: Pointer to host adapter structure.
113 * @sts_entry: Pointer to status entry structure.
114 **/
115static void qla4xxx_status_entry(struct scsi_qla_host *ha,
116 struct status_entry *sts_entry)
117{
118 uint8_t scsi_status;
119 struct scsi_cmnd *cmd;
120 struct srb *srb;
121 struct ddb_entry *ddb_entry;
122 uint32_t residual;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700123
David Somayajuluafaf5a22006-09-19 10:28:00 -0700124 srb = qla4xxx_del_from_active_array(ha, le32_to_cpu(sts_entry->handle));
125 if (!srb) {
Vikas Chaudhary4c6a7942011-12-01 22:42:06 -0800126 ql4_printk(KERN_WARNING, ha, "%s invalid status entry: "
127 "handle=0x%0x, srb=%p\n", __func__,
128 sts_entry->handle, srb);
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400129 if (is_qla80XX(ha))
Vikas Chaudhary4c6a7942011-12-01 22:42:06 -0800130 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
131 else
132 set_bit(DPC_RESET_HA, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700133 return;
134 }
135
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));
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530142 ql4_printk(KERN_WARNING, ha, "Command is NULL:"
143 " already returned to OS (srb=%p)\n", srb);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700144 return;
145 }
146
147 ddb_entry = srb->ddb;
148 if (ddb_entry == NULL) {
149 cmd->result = DID_NO_CONNECT << 16;
150 goto status_entry_exit;
151 }
152
153 residual = le32_to_cpu(sts_entry->residualByteCnt);
154
155 /* Translate ISP error to a Linux SCSI error. */
156 scsi_status = sts_entry->scsiStatus;
157 switch (sts_entry->completionStatus) {
158 case SCS_COMPLETE:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700159
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700160 if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) {
161 cmd->result = DID_ERROR << 16;
162 break;
163 }
164
165 if (sts_entry->iscsiFlags &ISCSI_FLAG_RESIDUAL_UNDER) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900166 scsi_set_resid(cmd, residual);
David C Somayajulu9d562912008-03-19 11:23:03 -0700167 if (!scsi_status && ((scsi_bufflen(cmd) - residual) <
168 cmd->underflow)) {
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700169
170 cmd->result = DID_ERROR << 16;
171
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;
181 }
182 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700183
184 cmd->result = DID_OK << 16 | scsi_status;
185
186 if (scsi_status != SCSI_CHECK_CONDITION)
187 break;
188
189 /* Copy Sense Data into sense buffer. */
Karen Higgins94bced32009-07-15 15:02:58 -0500190 qla4xxx_copy_sense(ha, sts_entry, srb);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700191 break;
192
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;
198
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__));
203
204 cmd->result = DID_RESET << 16;
205 break;
206
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__));
211
212 cmd->result = DID_RESET << 16;
213 break;
214
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));
219
Mike Christie56d7fcf2008-08-19 18:45:26 -0500220 cmd->result = DID_TRANSPORT_DISRUPTED << 16;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700221
222 /*
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.
226 */
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500227 if (iscsi_is_session_online(ddb_entry->sess))
228 qla4xxx_mark_device_missing(ddb_entry->sess);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700229 break;
230
231 case SCS_DATA_UNDERRUN:
232 case SCS_DATA_OVERRUN:
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700233 if ((sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) ||
Mike Christieb06fc732009-08-20 15:11:00 -0500234 (sts_entry->completionStatus == SCS_DATA_OVERRUN)) {
235 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: " "Data overrun\n",
236 ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700237 cmd->device->channel, cmd->device->id,
Mike Christieb06fc732009-08-20 15:11:00 -0500238 cmd->device->lun, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700239
240 cmd->result = DID_ERROR << 16;
241 break;
242 }
243
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700244 scsi_set_resid(cmd, residual);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700245
Lalit Chandivade24c14202012-08-07 07:57:16 -0400246 if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_UNDER) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700247
Lalit Chandivade24c14202012-08-07 07:57:16 -0400248 /* Both the firmware and target reported UNDERRUN:
249 *
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.
255 *
256 * ALL OTHER cases:
257 * Fall thru to check scsi_status
David Somayajuluafaf5a22006-09-19 10:28:00 -0700258 */
Lalit Chandivade24c14202012-08-07 07:57:16 -0400259 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));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700269
270 cmd->result = DID_ERROR << 16;
Lalit Chandivade24c14202012-08-07 07:57:16 -0400271 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700272 }
Lalit Chandivade24c14202012-08-07 07:57:16 -0400273
274 } else if (scsi_status != SAM_STAT_TASK_SET_FULL &&
275 scsi_status != SAM_STAT_BUSY) {
276
277 /*
278 * The firmware reports UNDERRUN, but the target does
279 * not report it:
280 *
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
287 *
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.
291 */
292
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)));
301
302 cmd->result = DID_ERROR << 16 | scsi_status;
303 goto check_scsi_status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700304 }
Lalit Chandivade24c14202012-08-07 07:57:16 -0400305
306 cmd->result = DID_OK << 16 | scsi_status;
307
308check_scsi_status:
309 if (scsi_status == SAM_STAT_CHECK_CONDITION)
310 qla4xxx_copy_sense(ha, sts_entry, srb);
311
David Somayajuluafaf5a22006-09-19 10:28:00 -0700312 break;
313
314 case SCS_DEVICE_LOGGED_OUT:
315 case SCS_DEVICE_UNAVAILABLE:
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530316 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));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700320 /*
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.
324 */
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500325 if (iscsi_is_session_online(ddb_entry->sess))
326 qla4xxx_mark_device_missing(ddb_entry->sess);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700327
Mike Christie56d7fcf2008-08-19 18:45:26 -0500328 cmd->result = DID_TRANSPORT_DISRUPTED << 16;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700329 break;
330
331 case SCS_QUEUE_FULL:
332 /*
333 * SCSI Mid-Layer handles device queue full
334 */
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;
345
346 default:
347 cmd->result = DID_ERROR << 16;
348 break;
349 }
350
351status_entry_exit:
352
Karen Higgins94bced32009-07-15 15:02:58 -0500353 /* complete the request, if not waiting for status_continuation pkt */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700354 srb->cc_stat = sts_entry->completionStatus;
Karen Higgins94bced32009-07-15 15:02:58 -0500355 if (ha->status_srb == NULL)
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530356 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700357}
358
359/**
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500360 * qla4xxx_passthru_status_entry - processes passthru status IOCBs (0x3C)
361 * @ha: Pointer to host adapter structure.
362 * @sts_entry: Pointer to status entry structure.
363 **/
364static void qla4xxx_passthru_status_entry(struct scsi_qla_host *ha,
365 struct passthru_status *sts_entry)
366{
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;
374
375 itt = sts_entry->handle;
376 fw_ddb_index = le32_to_cpu(sts_entry->target);
377
378 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index);
379
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;
384 }
385
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);
391
392 if (task == NULL) {
393 ql4_printk(KERN_ERR, ha, "%s: Task is NULL\n", __func__);
394 return;
395 }
396
397 task_data = task->dd_data;
398 memcpy(&task_data->sts, sts_entry, sizeof(struct passthru_status));
399 ha->req_q_count += task_data->iocb_req_cnt;
400 ha->iocb_cnt -= task_data->iocb_req_cnt;
401 queue_work(ha->task_wq, &task_data->task_work);
402}
403
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530404static struct mrb *qla4xxx_del_mrb_from_active_array(struct scsi_qla_host *ha,
405 uint32_t index)
406{
407 struct mrb *mrb = NULL;
408
409 /* validate handle and remove from active array */
410 if (index >= MAX_MRB)
411 return mrb;
412
413 mrb = ha->active_mrb_array[index];
414 ha->active_mrb_array[index] = NULL;
415 if (!mrb)
416 return mrb;
417
418 /* update counters */
419 ha->req_q_count += mrb->iocb_cnt;
420 ha->iocb_cnt -= mrb->iocb_cnt;
421
422 return mrb;
423}
424
425static void qla4xxx_mbox_status_entry(struct scsi_qla_host *ha,
426 struct mbox_status_iocb *mbox_sts_entry)
427{
428 struct mrb *mrb;
429 uint32_t status;
430 uint32_t data_size;
431
432 mrb = qla4xxx_del_mrb_from_active_array(ha,
433 le32_to_cpu(mbox_sts_entry->handle));
434
435 if (mrb == NULL) {
436 ql4_printk(KERN_WARNING, ha, "%s: mrb[%d] is null\n", __func__,
437 mbox_sts_entry->handle);
438 return;
439 }
440
441 switch (mrb->mbox_cmd) {
442 case MBOX_CMD_PING:
443 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: mbox_cmd = 0x%x, "
444 "mbox_sts[0] = 0x%x, mbox_sts[6] = 0x%x\n",
445 __func__, mrb->mbox_cmd,
446 mbox_sts_entry->out_mbox[0],
447 mbox_sts_entry->out_mbox[6]));
448
449 if (mbox_sts_entry->out_mbox[0] == MBOX_STS_COMMAND_COMPLETE)
Vikas Chaudhary1a590ca2012-03-06 04:16:04 -0800450 status = ISCSI_PING_SUCCESS;
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530451 else
Vikas Chaudhary1a590ca2012-03-06 04:16:04 -0800452 status = mbox_sts_entry->out_mbox[6];
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530453
454 data_size = sizeof(mbox_sts_entry->out_mbox);
455
456 qla4xxx_post_ping_evt_work(ha, status, mrb->pid, data_size,
457 (uint8_t *) mbox_sts_entry->out_mbox);
458 break;
459
460 default:
461 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: invalid mbox_cmd = "
462 "0x%x\n", __func__, mrb->mbox_cmd));
463 }
464
465 kfree(mrb);
466 return;
467}
468
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500469/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700470 * qla4xxx_process_response_queue - process response queue completions
471 * @ha: Pointer to host adapter structure.
472 *
473 * This routine process response queue completions in interrupt context.
474 * Hardware_lock locked upon entry
475 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530476void qla4xxx_process_response_queue(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700477{
478 uint32_t count = 0;
479 struct srb *srb = NULL;
480 struct status_entry *sts_entry;
481
482 /* Process all responses from response queue */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530483 while ((ha->response_ptr->signature != RESPONSE_PROCESSED)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700484 sts_entry = (struct status_entry *) ha->response_ptr;
485 count++;
486
487 /* Advance pointers for next entry */
488 if (ha->response_out == (RESPONSE_QUEUE_DEPTH - 1)) {
489 ha->response_out = 0;
490 ha->response_ptr = ha->response_ring;
491 } else {
492 ha->response_out++;
493 ha->response_ptr++;
494 }
495
496 /* process entry */
497 switch (sts_entry->hdr.entryType) {
498 case ET_STATUS:
Karen Higgins94bced32009-07-15 15:02:58 -0500499 /* Common status */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700500 qla4xxx_status_entry(ha, sts_entry);
501 break;
502
503 case ET_PASSTHRU_STATUS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500504 if (sts_entry->hdr.systemDefined == SD_ISCSI_PDU)
505 qla4xxx_passthru_status_entry(ha,
506 (struct passthru_status *)sts_entry);
507 else
508 ql4_printk(KERN_ERR, ha,
509 "%s: Invalid status received\n",
510 __func__);
511
David Somayajuluafaf5a22006-09-19 10:28:00 -0700512 break;
513
514 case ET_STATUS_CONTINUATION:
Karen Higgins94bced32009-07-15 15:02:58 -0500515 qla4xxx_status_cont_entry(ha,
516 (struct status_cont_entry *) sts_entry);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700517 break;
518
519 case ET_COMMAND:
520 /* ISP device queue is full. Command not
521 * accepted by ISP. Queue command for
522 * later */
523
524 srb = qla4xxx_del_from_active_array(ha,
525 le32_to_cpu(sts_entry->
526 handle));
527 if (srb == NULL)
528 goto exit_prq_invalid_handle;
529
530 DEBUG2(printk("scsi%ld: %s: FW device queue full, "
531 "srb %p\n", ha->host_no, __func__, srb));
532
533 /* ETRY normally by sending it back with
534 * DID_BUS_BUSY */
535 srb->cmd->result = DID_BUS_BUSY << 16;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530536 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700537 break;
538
539 case ET_CONTINUE:
540 /* Just throw away the continuation entries */
541 DEBUG2(printk("scsi%ld: %s: Continuation entry - "
542 "ignoring\n", ha->host_no, __func__));
543 break;
544
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530545 case ET_MBOX_STATUS:
546 DEBUG2(ql4_printk(KERN_INFO, ha,
547 "%s: mbox status IOCB\n", __func__));
548 qla4xxx_mbox_status_entry(ha,
549 (struct mbox_status_iocb *)sts_entry);
550 break;
551
David Somayajuluafaf5a22006-09-19 10:28:00 -0700552 default:
553 /*
554 * Invalid entry in response queue, reset RISC
555 * firmware.
556 */
557 DEBUG2(printk("scsi%ld: %s: Invalid entry %x in "
558 "response queue \n", ha->host_no,
559 __func__,
560 sts_entry->hdr.entryType));
561 goto exit_prq_error;
562 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530563 ((struct response *)sts_entry)->signature = RESPONSE_PROCESSED;
564 wmb();
David Somayajuluafaf5a22006-09-19 10:28:00 -0700565 }
566
567 /*
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530568 * Tell ISP we're done with response(s). This also clears the interrupt.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700569 */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530570 ha->isp_ops->complete_iocb(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700571
572 return;
573
574exit_prq_invalid_handle:
575 DEBUG2(printk("scsi%ld: %s: Invalid handle(srb)=%p type=%x IOCS=%x\n",
576 ha->host_no, __func__, srb, sts_entry->hdr.entryType,
577 sts_entry->completionStatus));
578
579exit_prq_error:
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530580 ha->isp_ops->complete_iocb(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700581 set_bit(DPC_RESET_HA, &ha->dpc_flags);
582}
583
584/**
585 * qla4xxx_isr_decode_mailbox - decodes mailbox status
586 * @ha: Pointer to host adapter structure.
587 * @mailbox_status: Mailbox status.
588 *
589 * This routine decodes the mailbox status during the ISR.
590 * Hardware_lock locked upon entry. runs in interrupt context.
591 **/
592static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
593 uint32_t mbox_status)
594{
595 int i;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530596 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400597 __le32 __iomem *mailbox_out;
598
599 if (is_qla8032(ha))
600 mailbox_out = &ha->qla4_83xx_reg->mailbox_out[0];
601 else if (is_qla8022(ha))
602 mailbox_out = &ha->qla4_82xx_reg->mailbox_out[0];
603 else
604 mailbox_out = &ha->reg->mailbox[0];
David Somayajuluafaf5a22006-09-19 10:28:00 -0700605
606 if ((mbox_status == MBOX_STS_BUSY) ||
607 (mbox_status == MBOX_STS_INTERMEDIATE_COMPLETION) ||
608 (mbox_status >> 12 == MBOX_COMPLETION_STATUS)) {
609 ha->mbox_status[0] = mbox_status;
610
611 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
612 /*
613 * Copy all mailbox registers to a temporary
614 * location and set mailbox command done flag
615 */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530616 for (i = 0; i < ha->mbox_status_count; i++)
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400617 ha->mbox_status[i] = readl(&mailbox_out[i]);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700618
619 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530620
621 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags))
622 complete(&ha->mbx_intr_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700623 }
624 } else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530625 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400626 mbox_sts[i] = readl(&mailbox_out[i]);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530627
David Somayajuluafaf5a22006-09-19 10:28:00 -0700628 /* Immediately process the AENs that don't require much work.
629 * Only queue the database_changed AENs */
David C Somayajulu401425b2007-05-23 18:03:20 -0700630 if (ha->aen_log.count < MAX_AEN_ENTRIES) {
631 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
632 ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530633 mbox_sts[i];
David C Somayajulu401425b2007-05-23 18:03:20 -0700634 ha->aen_log.count++;
635 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700636 switch (mbox_status) {
637 case MBOX_ASTS_SYSTEM_ERROR:
638 /* Log Mailbox registers */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530639 ql4_printk(KERN_INFO, ha, "%s: System Err\n", __func__);
Karen Higgins91a772a2010-10-06 22:50:21 -0700640 qla4xxx_dump_registers(ha);
641
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400642 if ((is_qla8022(ha) && ql4xdontresethba) ||
643 (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530644 DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n",
645 ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700646 } else {
647 set_bit(AF_GET_CRASH_RECORD, &ha->flags);
648 set_bit(DPC_RESET_HA, &ha->dpc_flags);
649 }
650 break;
651
652 case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
653 case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
654 case MBOX_ASTS_NVRAM_INVALID:
655 case MBOX_ASTS_IP_ADDRESS_CHANGED:
656 case MBOX_ASTS_DHCP_LEASE_EXPIRED:
657 DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
658 "Reset HA\n", ha->host_no, mbox_status));
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400659 if (is_qla80XX(ha))
Vikas Chaudhary4c6a7942011-12-01 22:42:06 -0800660 set_bit(DPC_RESET_HA_FW_CONTEXT,
661 &ha->dpc_flags);
662 else
663 set_bit(DPC_RESET_HA, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700664 break;
665
666 case MBOX_ASTS_LINK_UP:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700667 set_bit(AF_LINK_UP, &ha->flags);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +0530668 if (test_bit(AF_INIT_DONE, &ha->flags))
669 set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
670
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530671 ql4_printk(KERN_INFO, ha, "%s: LINK UP\n", __func__);
Vikas Chaudharyff884432011-08-29 23:43:02 +0530672 qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKUP,
673 sizeof(mbox_sts),
674 (uint8_t *) mbox_sts);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700675 break;
676
677 case MBOX_ASTS_LINK_DOWN:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700678 clear_bit(AF_LINK_UP, &ha->flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530679 if (test_bit(AF_INIT_DONE, &ha->flags))
680 set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +0530681
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530682 ql4_printk(KERN_INFO, ha, "%s: LINK DOWN\n", __func__);
Vikas Chaudharyff884432011-08-29 23:43:02 +0530683 qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKDOWN,
684 sizeof(mbox_sts),
685 (uint8_t *) mbox_sts);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700686 break;
687
688 case MBOX_ASTS_HEARTBEAT:
689 ha->seconds_since_last_heartbeat = 0;
690 break;
691
692 case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
693 DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
694 "ACQUIRED\n", ha->host_no, mbox_status));
695 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
696 break;
697
698 case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
699 case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
700 * mode
701 * only */
702 case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
703 case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
704 case MBOX_ASTS_SUBNET_STATE_CHANGE:
Prasanna Mumbai185f1072011-05-17 23:17:03 -0700705 case MBOX_ASTS_DUPLICATE_IP:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700706 /* No action */
707 DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
708 mbox_status));
709 break;
710
David C Somayajulu401425b2007-05-23 18:03:20 -0700711 case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530712 printk("scsi%ld: AEN %04x, mbox_sts[2]=%04x, "
713 "mbox_sts[3]=%04x\n", ha->host_no, mbox_sts[0],
714 mbox_sts[2], mbox_sts[3]);
David C Somayajulu401425b2007-05-23 18:03:20 -0700715
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530716 /* mbox_sts[2] = Old ACB state
717 * mbox_sts[3] = new ACB state */
718 if ((mbox_sts[3] == ACB_STATE_VALID) &&
Prasanna Mumbaie1282712010-12-02 22:12:43 -0800719 ((mbox_sts[2] == ACB_STATE_TENTATIVE) ||
720 (mbox_sts[2] == ACB_STATE_ACQUIRING)))
David C Somayajulu401425b2007-05-23 18:03:20 -0700721 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530722 else if ((mbox_sts[3] == ACB_STATE_ACQUIRING) &&
Vikas Chaudhary4c6a7942011-12-01 22:42:06 -0800723 (mbox_sts[2] == ACB_STATE_VALID)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400724 if (is_qla80XX(ha))
Vikas Chaudhary4c6a7942011-12-01 22:42:06 -0800725 set_bit(DPC_RESET_HA_FW_CONTEXT,
726 &ha->dpc_flags);
727 else
728 set_bit(DPC_RESET_HA, &ha->dpc_flags);
729 } else if ((mbox_sts[3] == ACB_STATE_UNCONFIGURED))
Vikas Chaudhary95d31262011-08-12 02:51:29 -0700730 complete(&ha->disable_acb_comp);
David C Somayajulu401425b2007-05-23 18:03:20 -0700731 break;
732
David Somayajuluafaf5a22006-09-19 10:28:00 -0700733 case MBOX_ASTS_MAC_ADDRESS_CHANGED:
734 case MBOX_ASTS_DNS:
735 /* No action */
736 DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
737 "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530738 ha->host_no, mbox_sts[0],
739 mbox_sts[1], mbox_sts[2]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700740 break;
741
742 case MBOX_ASTS_SELF_TEST_FAILED:
743 case MBOX_ASTS_LOGIN_FAILED:
744 /* No action */
745 DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
746 "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530747 ha->host_no, mbox_sts[0], mbox_sts[1],
748 mbox_sts[2], mbox_sts[3]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700749 break;
750
751 case MBOX_ASTS_DATABASE_CHANGED:
752 /* Queue AEN information and process it in the DPC
753 * routine */
754 if (ha->aen_q_count > 0) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700755
756 /* decrement available counter */
757 ha->aen_q_count--;
758
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530759 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700760 ha->aen_q[ha->aen_in].mbox_sts[i] =
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530761 mbox_sts[i];
David Somayajuluafaf5a22006-09-19 10:28:00 -0700762
763 /* print debug message */
Prasanna Mumbai185f1072011-05-17 23:17:03 -0700764 DEBUG2(printk("scsi%ld: AEN[%d] %04x queued "
765 "mb1:0x%x mb2:0x%x mb3:0x%x "
766 "mb4:0x%x mb5:0x%x\n",
767 ha->host_no, ha->aen_in,
768 mbox_sts[0], mbox_sts[1],
769 mbox_sts[2], mbox_sts[3],
770 mbox_sts[4], mbox_sts[5]));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530771
David C Somayajulu401425b2007-05-23 18:03:20 -0700772 /* advance pointer */
773 ha->aen_in++;
774 if (ha->aen_in == MAX_AEN_ENTRIES)
775 ha->aen_in = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700776
777 /* The DPC routine will process the aen */
778 set_bit(DPC_AEN, &ha->dpc_flags);
779 } else {
780 DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
781 "overflowed! AEN LOST!!\n",
782 ha->host_no, __func__,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530783 mbox_sts[0]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700784
785 DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
786 ha->host_no));
787
788 for (i = 0; i < MAX_AEN_ENTRIES; i++) {
789 DEBUG2(printk("AEN[%d] %04x %04x %04x "
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530790 "%04x\n", i, mbox_sts[0],
791 mbox_sts[1], mbox_sts[2],
792 mbox_sts[3]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700793 }
794 }
795 break;
796
Shyam Sundar64340802010-10-06 22:49:40 -0700797 case MBOX_ASTS_TXSCVR_INSERTED:
798 DEBUG2(printk(KERN_WARNING
799 "scsi%ld: AEN %04x Transceiver"
800 " inserted\n", ha->host_no, mbox_sts[0]));
801 break;
802
803 case MBOX_ASTS_TXSCVR_REMOVED:
804 DEBUG2(printk(KERN_WARNING
805 "scsi%ld: AEN %04x Transceiver"
806 " removed\n", ha->host_no, mbox_sts[0]));
807 break;
808
Nilesh Javali320a61d2012-09-20 07:35:10 -0400809 case MBOX_ASTS_IDC_NOTIFY:
810 {
811 uint32_t opcode;
812 if (is_qla8032(ha)) {
813 DEBUG2(ql4_printk(KERN_INFO, ha,
814 "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x\n",
815 ha->host_no, mbox_sts[0],
816 mbox_sts[1], mbox_sts[2],
817 mbox_sts[3], mbox_sts[4]));
818 opcode = mbox_sts[1] >> 16;
819 if ((opcode == MBOX_CMD_SET_PORT_CONFIG) ||
820 (opcode == MBOX_CMD_PORT_RESET)) {
821 set_bit(DPC_POST_IDC_ACK,
822 &ha->dpc_flags);
823 ha->idc_info.request_desc = mbox_sts[1];
824 ha->idc_info.info1 = mbox_sts[2];
825 ha->idc_info.info2 = mbox_sts[3];
826 ha->idc_info.info3 = mbox_sts[4];
827 qla4xxx_wake_dpc(ha);
828 }
829 }
830 break;
831 }
832
833 case MBOX_ASTS_IDC_COMPLETE:
834 if (is_qla8032(ha)) {
835 DEBUG2(ql4_printk(KERN_INFO, ha,
836 "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x\n",
837 ha->host_no, mbox_sts[0],
838 mbox_sts[1], mbox_sts[2],
839 mbox_sts[3], mbox_sts[4]));
840 DEBUG2(ql4_printk(KERN_INFO, ha,
841 "scsi:%ld: AEN %04x IDC Complete notification\n",
842 ha->host_no, mbox_sts[0]));
843 }
844 break;
845
David Somayajuluafaf5a22006-09-19 10:28:00 -0700846 default:
847 DEBUG2(printk(KERN_WARNING
848 "scsi%ld: AEN %04x UNKNOWN\n",
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530849 ha->host_no, mbox_sts[0]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700850 break;
851 }
852 } else {
853 DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
854 ha->host_no, mbox_status));
855
856 ha->mbox_status[0] = mbox_status;
857 }
858}
859
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400860void qla4_83xx_interrupt_service_routine(struct scsi_qla_host *ha,
861 uint32_t intr_status)
862{
863 /* Process mailbox/asynch event interrupt.*/
864 if (intr_status) {
865 qla4xxx_isr_decode_mailbox(ha,
866 readl(&ha->qla4_83xx_reg->mailbox_out[0]));
867 /* clear the interrupt */
868 writel(0, &ha->qla4_83xx_reg->risc_intr);
869 } else {
870 qla4xxx_process_response_queue(ha);
871 }
872
873 /* clear the interrupt */
874 writel(0, &ha->qla4_83xx_reg->mb_int_mask);
875}
876
David Somayajuluafaf5a22006-09-19 10:28:00 -0700877/**
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400878 * qla4_82xx_interrupt_service_routine - isr
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530879 * @ha: pointer to host adapter structure.
880 *
881 * This is the main interrupt service routine.
882 * hardware_lock locked upon entry. runs in interrupt context.
883 **/
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400884void qla4_82xx_interrupt_service_routine(struct scsi_qla_host *ha,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530885 uint32_t intr_status)
886{
887 /* Process response queue interrupt. */
888 if (intr_status & HSRX_RISC_IOCB_INT)
889 qla4xxx_process_response_queue(ha);
890
891 /* Process mailbox/asynch event interrupt.*/
892 if (intr_status & HSRX_RISC_MB_INT)
893 qla4xxx_isr_decode_mailbox(ha,
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -0400894 readl(&ha->qla4_82xx_reg->mailbox_out[0]));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530895
896 /* clear the interrupt */
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -0400897 writel(0, &ha->qla4_82xx_reg->host_int);
898 readl(&ha->qla4_82xx_reg->host_int);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530899}
900
901/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700902 * qla4xxx_interrupt_service_routine - isr
903 * @ha: pointer to host adapter structure.
904 *
905 * This is the main interrupt service routine.
906 * hardware_lock locked upon entry. runs in interrupt context.
907 **/
908void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
909 uint32_t intr_status)
910{
911 /* Process response queue interrupt. */
912 if (intr_status & CSR_SCSI_COMPLETION_INTR)
913 qla4xxx_process_response_queue(ha);
914
915 /* Process mailbox/asynch event interrupt.*/
916 if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
917 qla4xxx_isr_decode_mailbox(ha,
918 readl(&ha->reg->mailbox[0]));
919
920 /* Clear Mailbox Interrupt */
921 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
922 &ha->reg->ctrl_status);
923 readl(&ha->reg->ctrl_status);
924 }
925}
926
927/**
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400928 * qla4_82xx_spurious_interrupt - processes spurious interrupt
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530929 * @ha: pointer to host adapter structure.
930 * @reqs_count: .
931 *
932 **/
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400933static void qla4_82xx_spurious_interrupt(struct scsi_qla_host *ha,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530934 uint8_t reqs_count)
935{
936 if (reqs_count)
937 return;
938
939 DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
940 if (is_qla8022(ha)) {
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -0400941 writel(0, &ha->qla4_82xx_reg->host_int);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530942 if (test_bit(AF_INTx_ENABLED, &ha->flags))
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400943 qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530944 0xfbff);
945 }
946 ha->spurious_int_count++;
947}
948
949/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700950 * qla4xxx_intr_handler - hardware interrupt handler.
951 * @irq: Unused
952 * @dev_id: Pointer to host adapter structure
David Somayajuluafaf5a22006-09-19 10:28:00 -0700953 **/
David Howells7d12e782006-10-05 14:55:46 +0100954irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700955{
956 struct scsi_qla_host *ha;
957 uint32_t intr_status;
958 unsigned long flags = 0;
959 uint8_t reqs_count = 0;
960
961 ha = (struct scsi_qla_host *) dev_id;
962 if (!ha) {
963 DEBUG2(printk(KERN_INFO
964 "qla4xxx: Interrupt with NULL host ptr\n"));
965 return IRQ_NONE;
966 }
967
968 spin_lock_irqsave(&ha->hardware_lock, flags);
969
David C Somayajulud9150582006-11-15 17:38:40 -0800970 ha->isr_count++;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700971 /*
972 * Repeatedly service interrupts up to a maximum of
973 * MAX_REQS_SERVICED_PER_INTR
974 */
975 while (1) {
976 /*
977 * Read interrupt status
978 */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530979 if (ha->isp_ops->rd_shdw_rsp_q_in(ha) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700980 ha->response_out)
981 intr_status = CSR_SCSI_COMPLETION_INTR;
982 else
983 intr_status = readl(&ha->reg->ctrl_status);
984
985 if ((intr_status &
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530986 (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700987 if (reqs_count == 0)
988 ha->spurious_int_count++;
989 break;
990 }
991
992 if (intr_status & CSR_FATAL_ERROR) {
993 DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
994 "Status 0x%04x\n", ha->host_no,
995 readl(isp_port_error_status (ha))));
996
997 /* Issue Soft Reset to clear this error condition.
998 * This will prevent the RISC from repeatedly
999 * interrupting the driver; thus, allowing the DPC to
1000 * get scheduled to continue error recovery.
1001 * NOTE: Disabling RISC interrupts does not work in
1002 * this case, as CSR_FATAL_ERROR overrides
1003 * CSR_SCSI_INTR_ENABLE */
1004 if ((readl(&ha->reg->ctrl_status) &
1005 CSR_SCSI_RESET_INTR) == 0) {
1006 writel(set_rmask(CSR_SOFT_RESET),
1007 &ha->reg->ctrl_status);
1008 readl(&ha->reg->ctrl_status);
1009 }
1010
1011 writel(set_rmask(CSR_FATAL_ERROR),
1012 &ha->reg->ctrl_status);
1013 readl(&ha->reg->ctrl_status);
1014
1015 __qla4xxx_disable_intrs(ha);
1016
1017 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1018
1019 break;
1020 } else if (intr_status & CSR_SCSI_RESET_INTR) {
1021 clear_bit(AF_ONLINE, &ha->flags);
1022 __qla4xxx_disable_intrs(ha);
1023
1024 writel(set_rmask(CSR_SCSI_RESET_INTR),
1025 &ha->reg->ctrl_status);
1026 readl(&ha->reg->ctrl_status);
1027
Karen Higgins7eece5a2011-03-21 03:34:29 -07001028 if (!test_bit(AF_HA_REMOVAL, &ha->flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -08001029 set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001030
1031 break;
1032 } else if (intr_status & INTR_PENDING) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301033 ha->isp_ops->interrupt_service_routine(ha, intr_status);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001034 ha->total_io_count++;
1035 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
1036 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001037 }
1038 }
1039
1040 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1041
1042 return IRQ_HANDLED;
1043}
1044
1045/**
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001046 * qla4_82xx_intr_handler - hardware interrupt handler.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301047 * @irq: Unused
1048 * @dev_id: Pointer to host adapter structure
1049 **/
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001050irqreturn_t qla4_82xx_intr_handler(int irq, void *dev_id)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301051{
1052 struct scsi_qla_host *ha = dev_id;
1053 uint32_t intr_status;
1054 uint32_t status;
1055 unsigned long flags = 0;
1056 uint8_t reqs_count = 0;
1057
Lalit Chandivade2232be02010-07-30 14:38:47 +05301058 if (unlikely(pci_channel_offline(ha->pdev)))
1059 return IRQ_HANDLED;
1060
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301061 ha->isr_count++;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001062 status = qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301063 if (!(status & ha->nx_legacy_intr.int_vec_bit))
1064 return IRQ_NONE;
1065
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001066 status = qla4_82xx_rd_32(ha, ISR_INT_STATE_REG);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301067 if (!ISR_IS_LEGACY_INTR_TRIGGERED(status)) {
1068 DEBUG2(ql4_printk(KERN_INFO, ha,
1069 "%s legacy Int not triggered\n", __func__));
1070 return IRQ_NONE;
1071 }
1072
1073 /* clear the interrupt */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001074 qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301075
1076 /* read twice to ensure write is flushed */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001077 qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1078 qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301079
1080 spin_lock_irqsave(&ha->hardware_lock, flags);
1081 while (1) {
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001082 if (!(readl(&ha->qla4_82xx_reg->host_int) &
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301083 ISRX_82XX_RISC_INT)) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001084 qla4_82xx_spurious_interrupt(ha, reqs_count);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301085 break;
1086 }
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001087 intr_status = readl(&ha->qla4_82xx_reg->host_status);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301088 if ((intr_status &
1089 (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001090 qla4_82xx_spurious_interrupt(ha, reqs_count);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301091 break;
1092 }
1093
1094 ha->isp_ops->interrupt_service_routine(ha, intr_status);
1095
1096 /* Enable Interrupt */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001097 qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301098
1099 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
1100 break;
1101 }
1102
1103 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1104 return IRQ_HANDLED;
1105}
1106
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04001107#define LEG_INT_PTR_B31 (1 << 31)
1108#define LEG_INT_PTR_B30 (1 << 30)
1109#define PF_BITS_MASK (0xF << 16)
1110
1111/**
1112 * qla4_83xx_intr_handler - hardware interrupt handler.
1113 * @irq: Unused
1114 * @dev_id: Pointer to host adapter structure
1115 **/
1116irqreturn_t qla4_83xx_intr_handler(int irq, void *dev_id)
1117{
1118 struct scsi_qla_host *ha = dev_id;
1119 uint32_t leg_int_ptr = 0;
1120 unsigned long flags = 0;
1121
1122 ha->isr_count++;
1123 leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
1124
1125 /* Legacy interrupt is valid if bit31 of leg_int_ptr is set */
1126 if (!(leg_int_ptr & LEG_INT_PTR_B31)) {
1127 ql4_printk(KERN_ERR, ha,
1128 "%s: Legacy Interrupt Bit 31 not set, spurious interrupt!\n",
1129 __func__);
1130 return IRQ_NONE;
1131 }
1132
1133 /* Validate the PCIE function ID set in leg_int_ptr bits [19..16] */
1134 if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit) {
1135 ql4_printk(KERN_ERR, ha,
1136 "%s: Incorrect function ID 0x%x in legacy interrupt register, ha->pf_bit = 0x%x\n",
1137 __func__, (leg_int_ptr & PF_BITS_MASK), ha->pf_bit);
1138 return IRQ_NONE;
1139 }
1140
1141 /* To de-assert legacy interrupt, write 0 to Legacy Interrupt Trigger
1142 * Control register and poll till Legacy Interrupt Pointer register
1143 * bit30 is 0.
1144 */
1145 writel(0, &ha->qla4_83xx_reg->leg_int_trig);
1146 do {
1147 leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
1148 if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit)
1149 break;
1150 } while (leg_int_ptr & LEG_INT_PTR_B30);
1151
1152 spin_lock_irqsave(&ha->hardware_lock, flags);
1153 leg_int_ptr = readl(&ha->qla4_83xx_reg->risc_intr);
1154 ha->isp_ops->interrupt_service_routine(ha, leg_int_ptr);
1155 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1156
1157 return IRQ_HANDLED;
1158}
1159
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301160irqreturn_t
1161qla4_8xxx_msi_handler(int irq, void *dev_id)
1162{
1163 struct scsi_qla_host *ha;
1164
1165 ha = (struct scsi_qla_host *) dev_id;
1166 if (!ha) {
1167 DEBUG2(printk(KERN_INFO
1168 "qla4xxx: MSIX: Interrupt with NULL host ptr\n"));
1169 return IRQ_NONE;
1170 }
1171
1172 ha->isr_count++;
1173 /* clear the interrupt */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001174 qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301175
1176 /* read twice to ensure write is flushed */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001177 qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1178 qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301179
1180 return qla4_8xxx_default_intr_handler(irq, dev_id);
1181}
1182
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04001183static irqreturn_t qla4_83xx_mailbox_intr_handler(int irq, void *dev_id)
1184{
1185 struct scsi_qla_host *ha = dev_id;
1186 unsigned long flags;
1187 uint32_t ival = 0;
1188
1189 spin_lock_irqsave(&ha->hardware_lock, flags);
1190
1191 ival = readl(&ha->qla4_83xx_reg->risc_intr);
1192 if (ival == 0) {
1193 ql4_printk(KERN_INFO, ha,
1194 "%s: It is a spurious mailbox interrupt!\n",
1195 __func__);
1196 ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
1197 ival &= ~INT_MASK_FW_MB;
1198 writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
1199 goto exit;
1200 }
1201
1202 qla4xxx_isr_decode_mailbox(ha,
1203 readl(&ha->qla4_83xx_reg->mailbox_out[0]));
1204 writel(0, &ha->qla4_83xx_reg->risc_intr);
1205 ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
1206 ival &= ~INT_MASK_FW_MB;
1207 writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
1208 ha->isr_count++;
1209exit:
1210 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1211 return IRQ_HANDLED;
1212}
1213
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301214/**
1215 * qla4_8xxx_default_intr_handler - hardware interrupt handler.
1216 * @irq: Unused
1217 * @dev_id: Pointer to host adapter structure
1218 *
1219 * This interrupt handler is called directly for MSI-X, and
1220 * called indirectly for MSI.
1221 **/
1222irqreturn_t
1223qla4_8xxx_default_intr_handler(int irq, void *dev_id)
1224{
1225 struct scsi_qla_host *ha = dev_id;
1226 unsigned long flags;
1227 uint32_t intr_status;
1228 uint8_t reqs_count = 0;
1229
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04001230 if (is_qla8032(ha)) {
1231 qla4_83xx_mailbox_intr_handler(irq, dev_id);
1232 } else {
1233 spin_lock_irqsave(&ha->hardware_lock, flags);
1234 while (1) {
1235 if (!(readl(&ha->qla4_82xx_reg->host_int) &
1236 ISRX_82XX_RISC_INT)) {
1237 qla4_82xx_spurious_interrupt(ha, reqs_count);
1238 break;
1239 }
1240
1241 intr_status = readl(&ha->qla4_82xx_reg->host_status);
1242 if ((intr_status &
1243 (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
1244 qla4_82xx_spurious_interrupt(ha, reqs_count);
1245 break;
1246 }
1247
1248 ha->isp_ops->interrupt_service_routine(ha, intr_status);
1249
1250 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
1251 break;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301252 }
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04001253 ha->isr_count++;
1254 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301255 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301256 return IRQ_HANDLED;
1257}
1258
1259irqreturn_t
1260qla4_8xxx_msix_rsp_q(int irq, void *dev_id)
1261{
1262 struct scsi_qla_host *ha = dev_id;
1263 unsigned long flags;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04001264 uint32_t ival = 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301265
1266 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04001267 if (is_qla8032(ha)) {
1268 ival = readl(&ha->qla4_83xx_reg->iocb_int_mask);
1269 if (ival == 0) {
1270 ql4_printk(KERN_INFO, ha, "%s: It is a spurious iocb interrupt!\n",
1271 __func__);
1272 goto exit_msix_rsp_q;
1273 }
1274 qla4xxx_process_response_queue(ha);
1275 writel(0, &ha->qla4_83xx_reg->iocb_int_mask);
1276 } else {
1277 qla4xxx_process_response_queue(ha);
1278 writel(0, &ha->qla4_82xx_reg->host_int);
1279 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301280 ha->isr_count++;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04001281exit_msix_rsp_q:
1282 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301283 return IRQ_HANDLED;
1284}
1285
1286/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001287 * qla4xxx_process_aen - processes AENs generated by firmware
1288 * @ha: pointer to host adapter structure.
1289 * @process_aen: type of AENs to process
1290 *
1291 * Processes specific types of Asynchronous Events generated by firmware.
1292 * The type of AENs to process is specified by process_aen and can be
1293 * PROCESS_ALL_AENS 0
1294 * FLUSH_DDB_CHANGED_AENS 1
1295 * RELOGIN_DDB_CHANGED_AENS 2
1296 **/
1297void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
1298{
1299 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
1300 struct aen *aen;
1301 int i;
1302 unsigned long flags;
1303
1304 spin_lock_irqsave(&ha->hardware_lock, flags);
1305 while (ha->aen_out != ha->aen_in) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001306 aen = &ha->aen_q[ha->aen_out];
David Somayajuluafaf5a22006-09-19 10:28:00 -07001307 /* copy aen information to local structure */
1308 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
1309 mbox_sts[i] = aen->mbox_sts[i];
1310
David C Somayajulu401425b2007-05-23 18:03:20 -07001311 ha->aen_q_count++;
1312 ha->aen_out++;
1313
1314 if (ha->aen_out == MAX_AEN_ENTRIES)
1315 ha->aen_out = 0;
1316
David Somayajuluafaf5a22006-09-19 10:28:00 -07001317 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1318
David C Somayajulu401425b2007-05-23 18:03:20 -07001319 DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
1320 " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
1321 (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
1322 mbox_sts[0], mbox_sts[1], mbox_sts[2],
1323 mbox_sts[3], mbox_sts[4]));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001324
1325 switch (mbox_sts[0]) {
1326 case MBOX_ASTS_DATABASE_CHANGED:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001327 switch (process_aen) {
1328 case FLUSH_DDB_CHANGED_AENS:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001329 DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
1330 "[%d] state=%04x FLUSHED!\n",
1331 ha->host_no, ha->aen_out,
1332 mbox_sts[0], mbox_sts[2],
1333 mbox_sts[3]));
1334 break;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001335 case PROCESS_ALL_AENS:
1336 default:
1337 /* Specific device. */
1338 if (mbox_sts[1] == 1)
1339 qla4xxx_process_ddb_changed(ha,
1340 mbox_sts[2], mbox_sts[3],
1341 mbox_sts[4]);
1342 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001343 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001344 }
1345 spin_lock_irqsave(&ha->hardware_lock, flags);
1346 }
1347 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001348}
1349
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301350int qla4xxx_request_irqs(struct scsi_qla_host *ha)
1351{
1352 int ret;
1353
Vikas Chaudharyee996a62012-08-22 07:55:05 -04001354 if (is_qla40XX(ha))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301355 goto try_intx;
1356
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04001357 if (ql4xenablemsix == 2) {
1358 /* Note: MSI Interrupts not supported for ISP8324 */
1359 if (is_qla8032(ha)) {
1360 ql4_printk(KERN_INFO, ha, "%s: MSI Interrupts not supported for ISP8324, Falling back-to INTx mode\n",
1361 __func__);
1362 goto try_intx;
1363 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301364 goto try_msi;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04001365 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301366
1367 if (ql4xenablemsix == 0 || ql4xenablemsix != 1)
1368 goto try_intx;
1369
1370 /* Trying MSI-X */
1371 ret = qla4_8xxx_enable_msix(ha);
1372 if (!ret) {
1373 DEBUG2(ql4_printk(KERN_INFO, ha,
1374 "MSI-X: Enabled (0x%X).\n", ha->revision_id));
1375 goto irq_attached;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04001376 } else {
1377 if (is_qla8032(ha)) {
1378 ql4_printk(KERN_INFO, ha, "%s: ISP8324: MSI-X: Falling back-to INTx mode. ret = %d\n",
1379 __func__, ret);
1380 goto try_intx;
1381 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301382 }
1383
1384 ql4_printk(KERN_WARNING, ha,
1385 "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
1386
1387try_msi:
1388 /* Trying MSI */
1389 ret = pci_enable_msi(ha->pdev);
1390 if (!ret) {
1391 ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
Shyam Sundar61391d32010-12-02 22:12:08 -08001392 0, DRIVER_NAME, ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301393 if (!ret) {
1394 DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1395 set_bit(AF_MSI_ENABLED, &ha->flags);
1396 goto irq_attached;
1397 } else {
1398 ql4_printk(KERN_WARNING, ha,
1399 "MSI: Failed to reserve interrupt %d "
1400 "already in use.\n", ha->pdev->irq);
1401 pci_disable_msi(ha->pdev);
1402 }
1403 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301404
Vikas Chaudhary109a0082012-09-20 07:35:06 -04001405 /*
1406 * Prevent interrupts from falling back to INTx mode in cases where
1407 * interrupts cannot get acquired through MSI-X or MSI mode.
1408 */
1409 if (is_qla8022(ha)) {
1410 ql4_printk(KERN_WARNING, ha, "IRQ not attached -- %d.\n", ret);
1411 goto irq_not_attached;
1412 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301413try_intx:
1414 /* Trying INTx */
1415 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Vikas Chaudhary3e1350c2010-12-02 22:12:03 -08001416 IRQF_SHARED, DRIVER_NAME, ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301417 if (!ret) {
1418 DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
1419 set_bit(AF_INTx_ENABLED, &ha->flags);
1420 goto irq_attached;
1421
1422 } else {
1423 ql4_printk(KERN_WARNING, ha,
1424 "INTx: Failed to reserve interrupt %d already in"
1425 " use.\n", ha->pdev->irq);
Vikas Chaudhary109a0082012-09-20 07:35:06 -04001426 goto irq_not_attached;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301427 }
1428
1429irq_attached:
1430 set_bit(AF_IRQ_ATTACHED, &ha->flags);
1431 ha->host->irq = ha->pdev->irq;
1432 ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
1433 __func__, ha->pdev->irq);
Vikas Chaudhary109a0082012-09-20 07:35:06 -04001434irq_not_attached:
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301435 return ret;
1436}
1437
1438void qla4xxx_free_irqs(struct scsi_qla_host *ha)
1439{
1440 if (test_bit(AF_MSIX_ENABLED, &ha->flags))
1441 qla4_8xxx_disable_msix(ha);
1442 else if (test_and_clear_bit(AF_MSI_ENABLED, &ha->flags)) {
1443 free_irq(ha->pdev->irq, ha);
1444 pci_disable_msi(ha->pdev);
1445 } else if (test_and_clear_bit(AF_INTx_ENABLED, &ha->flags))
1446 free_irq(ha->pdev->irq, ha);
1447}