blob: ee1104a3686cb37b1c8fc256955a1de827408442 [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
Vikas Chaudhary7d01d062010-12-02 22:12:51 -08003 * Copyright (c) 2003-2010 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) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700126 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Status Entry invalid "
127 "handle 0x%x, sp=%p. This cmd may have already "
128 "been completed.\n", ha->host_no, __func__,
129 le32_to_cpu(sts_entry->handle), srb));
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530130 ql4_printk(KERN_WARNING, ha, "%s invalid status entry:"
131 " handle=0x%0x\n", __func__, sts_entry->handle);
David C Somayajulu9d562912008-03-19 11:23:03 -0700132 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
246 /*
247 * If there is scsi_status, it takes precedense over
248 * underflow condition.
249 */
250 if (scsi_status != 0) {
251 cmd->result = DID_OK << 16 | scsi_status;
252
253 if (scsi_status != SCSI_CHECK_CONDITION)
254 break;
255
256 /* Copy Sense Data into sense buffer. */
Karen Higgins94bced32009-07-15 15:02:58 -0500257 qla4xxx_copy_sense(ha, sts_entry, srb);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700258 } else {
259 /*
260 * If RISC reports underrun and target does not
261 * report it then we must have a lost frame, so
262 * tell upper layer to retry it by reporting a
263 * bus busy.
264 */
265 if ((sts_entry->iscsiFlags &
266 ISCSI_FLAG_RESIDUAL_UNDER) == 0) {
267 cmd->result = DID_BUS_BUSY << 16;
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900268 } else if ((scsi_bufflen(cmd) - residual) <
David Somayajuluafaf5a22006-09-19 10:28:00 -0700269 cmd->underflow) {
270 /*
271 * Handle mid-layer underflow???
272 *
273 * For kernels less than 2.4, the driver must
274 * return an error if an underflow is detected.
275 * For kernels equal-to and above 2.4, the
276 * mid-layer will appearantly handle the
277 * underflow by detecting the residual count --
278 * unfortunately, we do not see where this is
279 * actually being done. In the interim, we
280 * will return DID_ERROR.
281 */
282 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700283 "Mid-layer Data underrun1, "
284 "xferlen = 0x%x, "
285 "residual = 0x%x\n", ha->host_no,
286 cmd->device->channel,
287 cmd->device->id,
288 cmd->device->lun, __func__,
289 scsi_bufflen(cmd), residual));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700290
291 cmd->result = DID_ERROR << 16;
292 } else {
293 cmd->result = DID_OK << 16;
294 }
295 }
296 break;
297
298 case SCS_DEVICE_LOGGED_OUT:
299 case SCS_DEVICE_UNAVAILABLE:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530300 DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: SCS_DEVICE "
301 "state: 0x%x\n", ha->host_no,
302 cmd->device->channel, cmd->device->id,
303 cmd->device->lun, sts_entry->completionStatus));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700304 /*
305 * Mark device missing so that we won't continue to
306 * send I/O to this device. We should get a ddb
307 * state change AEN soon.
308 */
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500309 if (iscsi_is_session_online(ddb_entry->sess))
310 qla4xxx_mark_device_missing(ddb_entry->sess);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700311
Mike Christie56d7fcf2008-08-19 18:45:26 -0500312 cmd->result = DID_TRANSPORT_DISRUPTED << 16;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700313 break;
314
315 case SCS_QUEUE_FULL:
316 /*
317 * SCSI Mid-Layer handles device queue full
318 */
319 cmd->result = DID_OK << 16 | sts_entry->scsiStatus;
320 DEBUG2(printk("scsi%ld:%d:%d: %s: QUEUE FULL detected "
321 "compl=%02x, scsi=%02x, state=%02x, iFlags=%02x,"
322 " iResp=%02x\n", ha->host_no, cmd->device->id,
323 cmd->device->lun, __func__,
324 sts_entry->completionStatus,
325 sts_entry->scsiStatus, sts_entry->state_flags,
326 sts_entry->iscsiFlags,
327 sts_entry->iscsiResponse));
328 break;
329
330 default:
331 cmd->result = DID_ERROR << 16;
332 break;
333 }
334
335status_entry_exit:
336
Karen Higgins94bced32009-07-15 15:02:58 -0500337 /* complete the request, if not waiting for status_continuation pkt */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700338 srb->cc_stat = sts_entry->completionStatus;
Karen Higgins94bced32009-07-15 15:02:58 -0500339 if (ha->status_srb == NULL)
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530340 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700341}
342
343/**
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500344 * qla4xxx_passthru_status_entry - processes passthru status IOCBs (0x3C)
345 * @ha: Pointer to host adapter structure.
346 * @sts_entry: Pointer to status entry structure.
347 **/
348static void qla4xxx_passthru_status_entry(struct scsi_qla_host *ha,
349 struct passthru_status *sts_entry)
350{
351 struct iscsi_task *task;
352 struct ddb_entry *ddb_entry;
353 struct ql4_task_data *task_data;
354 struct iscsi_cls_conn *cls_conn;
355 struct iscsi_conn *conn;
356 itt_t itt;
357 uint32_t fw_ddb_index;
358
359 itt = sts_entry->handle;
360 fw_ddb_index = le32_to_cpu(sts_entry->target);
361
362 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index);
363
364 if (ddb_entry == NULL) {
365 ql4_printk(KERN_ERR, ha, "%s: Invalid target index = 0x%x\n",
366 __func__, sts_entry->target);
367 return;
368 }
369
370 cls_conn = ddb_entry->conn;
371 conn = cls_conn->dd_data;
372 spin_lock(&conn->session->lock);
373 task = iscsi_itt_to_task(conn, itt);
374 spin_unlock(&conn->session->lock);
375
376 if (task == NULL) {
377 ql4_printk(KERN_ERR, ha, "%s: Task is NULL\n", __func__);
378 return;
379 }
380
381 task_data = task->dd_data;
382 memcpy(&task_data->sts, sts_entry, sizeof(struct passthru_status));
383 ha->req_q_count += task_data->iocb_req_cnt;
384 ha->iocb_cnt -= task_data->iocb_req_cnt;
385 queue_work(ha->task_wq, &task_data->task_work);
386}
387
388/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700389 * qla4xxx_process_response_queue - process response queue completions
390 * @ha: Pointer to host adapter structure.
391 *
392 * This routine process response queue completions in interrupt context.
393 * Hardware_lock locked upon entry
394 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530395void qla4xxx_process_response_queue(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700396{
397 uint32_t count = 0;
398 struct srb *srb = NULL;
399 struct status_entry *sts_entry;
400
401 /* Process all responses from response queue */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530402 while ((ha->response_ptr->signature != RESPONSE_PROCESSED)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700403 sts_entry = (struct status_entry *) ha->response_ptr;
404 count++;
405
406 /* Advance pointers for next entry */
407 if (ha->response_out == (RESPONSE_QUEUE_DEPTH - 1)) {
408 ha->response_out = 0;
409 ha->response_ptr = ha->response_ring;
410 } else {
411 ha->response_out++;
412 ha->response_ptr++;
413 }
414
415 /* process entry */
416 switch (sts_entry->hdr.entryType) {
417 case ET_STATUS:
Karen Higgins94bced32009-07-15 15:02:58 -0500418 /* Common status */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700419 qla4xxx_status_entry(ha, sts_entry);
420 break;
421
422 case ET_PASSTHRU_STATUS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500423 if (sts_entry->hdr.systemDefined == SD_ISCSI_PDU)
424 qla4xxx_passthru_status_entry(ha,
425 (struct passthru_status *)sts_entry);
426 else
427 ql4_printk(KERN_ERR, ha,
428 "%s: Invalid status received\n",
429 __func__);
430
David Somayajuluafaf5a22006-09-19 10:28:00 -0700431 break;
432
433 case ET_STATUS_CONTINUATION:
Karen Higgins94bced32009-07-15 15:02:58 -0500434 qla4xxx_status_cont_entry(ha,
435 (struct status_cont_entry *) sts_entry);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700436 break;
437
438 case ET_COMMAND:
439 /* ISP device queue is full. Command not
440 * accepted by ISP. Queue command for
441 * later */
442
443 srb = qla4xxx_del_from_active_array(ha,
444 le32_to_cpu(sts_entry->
445 handle));
446 if (srb == NULL)
447 goto exit_prq_invalid_handle;
448
449 DEBUG2(printk("scsi%ld: %s: FW device queue full, "
450 "srb %p\n", ha->host_no, __func__, srb));
451
452 /* ETRY normally by sending it back with
453 * DID_BUS_BUSY */
454 srb->cmd->result = DID_BUS_BUSY << 16;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530455 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700456 break;
457
458 case ET_CONTINUE:
459 /* Just throw away the continuation entries */
460 DEBUG2(printk("scsi%ld: %s: Continuation entry - "
461 "ignoring\n", ha->host_no, __func__));
462 break;
463
464 default:
465 /*
466 * Invalid entry in response queue, reset RISC
467 * firmware.
468 */
469 DEBUG2(printk("scsi%ld: %s: Invalid entry %x in "
470 "response queue \n", ha->host_no,
471 __func__,
472 sts_entry->hdr.entryType));
473 goto exit_prq_error;
474 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530475 ((struct response *)sts_entry)->signature = RESPONSE_PROCESSED;
476 wmb();
David Somayajuluafaf5a22006-09-19 10:28:00 -0700477 }
478
479 /*
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530480 * Tell ISP we're done with response(s). This also clears the interrupt.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700481 */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530482 ha->isp_ops->complete_iocb(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700483
484 return;
485
486exit_prq_invalid_handle:
487 DEBUG2(printk("scsi%ld: %s: Invalid handle(srb)=%p type=%x IOCS=%x\n",
488 ha->host_no, __func__, srb, sts_entry->hdr.entryType,
489 sts_entry->completionStatus));
490
491exit_prq_error:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530492 ha->isp_ops->complete_iocb(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700493 set_bit(DPC_RESET_HA, &ha->dpc_flags);
494}
495
496/**
497 * qla4xxx_isr_decode_mailbox - decodes mailbox status
498 * @ha: Pointer to host adapter structure.
499 * @mailbox_status: Mailbox status.
500 *
501 * This routine decodes the mailbox status during the ISR.
502 * Hardware_lock locked upon entry. runs in interrupt context.
503 **/
504static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
505 uint32_t mbox_status)
506{
507 int i;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530508 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
David Somayajuluafaf5a22006-09-19 10:28:00 -0700509
510 if ((mbox_status == MBOX_STS_BUSY) ||
511 (mbox_status == MBOX_STS_INTERMEDIATE_COMPLETION) ||
512 (mbox_status >> 12 == MBOX_COMPLETION_STATUS)) {
513 ha->mbox_status[0] = mbox_status;
514
515 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
516 /*
517 * Copy all mailbox registers to a temporary
518 * location and set mailbox command done flag
519 */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530520 for (i = 0; i < ha->mbox_status_count; i++)
521 ha->mbox_status[i] = is_qla8022(ha)
522 ? readl(&ha->qla4_8xxx_reg->mailbox_out[i])
523 : readl(&ha->reg->mailbox[i]);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700524
525 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530526
527 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags))
528 complete(&ha->mbx_intr_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700529 }
530 } else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530531 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
532 mbox_sts[i] = is_qla8022(ha)
533 ? readl(&ha->qla4_8xxx_reg->mailbox_out[i])
534 : readl(&ha->reg->mailbox[i]);
535
David Somayajuluafaf5a22006-09-19 10:28:00 -0700536 /* Immediately process the AENs that don't require much work.
537 * Only queue the database_changed AENs */
David C Somayajulu401425b2007-05-23 18:03:20 -0700538 if (ha->aen_log.count < MAX_AEN_ENTRIES) {
539 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
540 ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530541 mbox_sts[i];
David C Somayajulu401425b2007-05-23 18:03:20 -0700542 ha->aen_log.count++;
543 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700544 switch (mbox_status) {
545 case MBOX_ASTS_SYSTEM_ERROR:
546 /* Log Mailbox registers */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530547 ql4_printk(KERN_INFO, ha, "%s: System Err\n", __func__);
Karen Higgins91a772a2010-10-06 22:50:21 -0700548 qla4xxx_dump_registers(ha);
549
David Somayajuluafaf5a22006-09-19 10:28:00 -0700550 if (ql4xdontresethba) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530551 DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n",
552 ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700553 } else {
554 set_bit(AF_GET_CRASH_RECORD, &ha->flags);
555 set_bit(DPC_RESET_HA, &ha->dpc_flags);
556 }
557 break;
558
559 case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
560 case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
561 case MBOX_ASTS_NVRAM_INVALID:
562 case MBOX_ASTS_IP_ADDRESS_CHANGED:
563 case MBOX_ASTS_DHCP_LEASE_EXPIRED:
564 DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
565 "Reset HA\n", ha->host_no, mbox_status));
566 set_bit(DPC_RESET_HA, &ha->dpc_flags);
567 break;
568
569 case MBOX_ASTS_LINK_UP:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700570 set_bit(AF_LINK_UP, &ha->flags);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +0530571 if (test_bit(AF_INIT_DONE, &ha->flags))
572 set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
573
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530574 ql4_printk(KERN_INFO, ha, "%s: LINK UP\n", __func__);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700575 break;
576
577 case MBOX_ASTS_LINK_DOWN:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700578 clear_bit(AF_LINK_UP, &ha->flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530579 if (test_bit(AF_INIT_DONE, &ha->flags))
580 set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +0530581
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530582 ql4_printk(KERN_INFO, ha, "%s: LINK DOWN\n", __func__);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700583 break;
584
585 case MBOX_ASTS_HEARTBEAT:
586 ha->seconds_since_last_heartbeat = 0;
587 break;
588
589 case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
590 DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
591 "ACQUIRED\n", ha->host_no, mbox_status));
592 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
593 break;
594
595 case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
596 case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
597 * mode
598 * only */
599 case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
600 case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
601 case MBOX_ASTS_SUBNET_STATE_CHANGE:
Prasanna Mumbai185f1072011-05-17 23:17:03 -0700602 case MBOX_ASTS_DUPLICATE_IP:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700603 /* No action */
604 DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
605 mbox_status));
606 break;
607
David C Somayajulu401425b2007-05-23 18:03:20 -0700608 case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530609 printk("scsi%ld: AEN %04x, mbox_sts[2]=%04x, "
610 "mbox_sts[3]=%04x\n", ha->host_no, mbox_sts[0],
611 mbox_sts[2], mbox_sts[3]);
David C Somayajulu401425b2007-05-23 18:03:20 -0700612
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530613 /* mbox_sts[2] = Old ACB state
614 * mbox_sts[3] = new ACB state */
615 if ((mbox_sts[3] == ACB_STATE_VALID) &&
Prasanna Mumbaie1282712010-12-02 22:12:43 -0800616 ((mbox_sts[2] == ACB_STATE_TENTATIVE) ||
617 (mbox_sts[2] == ACB_STATE_ACQUIRING)))
David C Somayajulu401425b2007-05-23 18:03:20 -0700618 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530619 else if ((mbox_sts[3] == ACB_STATE_ACQUIRING) &&
620 (mbox_sts[2] == ACB_STATE_VALID))
David C Somayajulu401425b2007-05-23 18:03:20 -0700621 set_bit(DPC_RESET_HA, &ha->dpc_flags);
622 break;
623
David Somayajuluafaf5a22006-09-19 10:28:00 -0700624 case MBOX_ASTS_MAC_ADDRESS_CHANGED:
625 case MBOX_ASTS_DNS:
626 /* No action */
627 DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
628 "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530629 ha->host_no, mbox_sts[0],
630 mbox_sts[1], mbox_sts[2]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700631 break;
632
633 case MBOX_ASTS_SELF_TEST_FAILED:
634 case MBOX_ASTS_LOGIN_FAILED:
635 /* No action */
636 DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
637 "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530638 ha->host_no, mbox_sts[0], mbox_sts[1],
639 mbox_sts[2], mbox_sts[3]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700640 break;
641
642 case MBOX_ASTS_DATABASE_CHANGED:
643 /* Queue AEN information and process it in the DPC
644 * routine */
645 if (ha->aen_q_count > 0) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700646
647 /* decrement available counter */
648 ha->aen_q_count--;
649
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530650 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700651 ha->aen_q[ha->aen_in].mbox_sts[i] =
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530652 mbox_sts[i];
David Somayajuluafaf5a22006-09-19 10:28:00 -0700653
654 /* print debug message */
Prasanna Mumbai185f1072011-05-17 23:17:03 -0700655 DEBUG2(printk("scsi%ld: AEN[%d] %04x queued "
656 "mb1:0x%x mb2:0x%x mb3:0x%x "
657 "mb4:0x%x mb5:0x%x\n",
658 ha->host_no, ha->aen_in,
659 mbox_sts[0], mbox_sts[1],
660 mbox_sts[2], mbox_sts[3],
661 mbox_sts[4], mbox_sts[5]));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530662
David C Somayajulu401425b2007-05-23 18:03:20 -0700663 /* advance pointer */
664 ha->aen_in++;
665 if (ha->aen_in == MAX_AEN_ENTRIES)
666 ha->aen_in = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700667
668 /* The DPC routine will process the aen */
669 set_bit(DPC_AEN, &ha->dpc_flags);
670 } else {
671 DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
672 "overflowed! AEN LOST!!\n",
673 ha->host_no, __func__,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530674 mbox_sts[0]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700675
676 DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
677 ha->host_no));
678
679 for (i = 0; i < MAX_AEN_ENTRIES; i++) {
680 DEBUG2(printk("AEN[%d] %04x %04x %04x "
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530681 "%04x\n", i, mbox_sts[0],
682 mbox_sts[1], mbox_sts[2],
683 mbox_sts[3]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700684 }
685 }
686 break;
687
Shyam Sundar64340802010-10-06 22:49:40 -0700688 case MBOX_ASTS_TXSCVR_INSERTED:
689 DEBUG2(printk(KERN_WARNING
690 "scsi%ld: AEN %04x Transceiver"
691 " inserted\n", ha->host_no, mbox_sts[0]));
692 break;
693
694 case MBOX_ASTS_TXSCVR_REMOVED:
695 DEBUG2(printk(KERN_WARNING
696 "scsi%ld: AEN %04x Transceiver"
697 " removed\n", ha->host_no, mbox_sts[0]));
698 break;
699
David Somayajuluafaf5a22006-09-19 10:28:00 -0700700 default:
701 DEBUG2(printk(KERN_WARNING
702 "scsi%ld: AEN %04x UNKNOWN\n",
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530703 ha->host_no, mbox_sts[0]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700704 break;
705 }
706 } else {
707 DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
708 ha->host_no, mbox_status));
709
710 ha->mbox_status[0] = mbox_status;
711 }
712}
713
714/**
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530715 * qla4_8xxx_interrupt_service_routine - isr
716 * @ha: pointer to host adapter structure.
717 *
718 * This is the main interrupt service routine.
719 * hardware_lock locked upon entry. runs in interrupt context.
720 **/
721void qla4_8xxx_interrupt_service_routine(struct scsi_qla_host *ha,
722 uint32_t intr_status)
723{
724 /* Process response queue interrupt. */
725 if (intr_status & HSRX_RISC_IOCB_INT)
726 qla4xxx_process_response_queue(ha);
727
728 /* Process mailbox/asynch event interrupt.*/
729 if (intr_status & HSRX_RISC_MB_INT)
730 qla4xxx_isr_decode_mailbox(ha,
731 readl(&ha->qla4_8xxx_reg->mailbox_out[0]));
732
733 /* clear the interrupt */
734 writel(0, &ha->qla4_8xxx_reg->host_int);
735 readl(&ha->qla4_8xxx_reg->host_int);
736}
737
738/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700739 * qla4xxx_interrupt_service_routine - isr
740 * @ha: pointer to host adapter structure.
741 *
742 * This is the main interrupt service routine.
743 * hardware_lock locked upon entry. runs in interrupt context.
744 **/
745void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
746 uint32_t intr_status)
747{
748 /* Process response queue interrupt. */
749 if (intr_status & CSR_SCSI_COMPLETION_INTR)
750 qla4xxx_process_response_queue(ha);
751
752 /* Process mailbox/asynch event interrupt.*/
753 if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
754 qla4xxx_isr_decode_mailbox(ha,
755 readl(&ha->reg->mailbox[0]));
756
757 /* Clear Mailbox Interrupt */
758 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
759 &ha->reg->ctrl_status);
760 readl(&ha->reg->ctrl_status);
761 }
762}
763
764/**
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530765 * qla4_8xxx_spurious_interrupt - processes spurious interrupt
766 * @ha: pointer to host adapter structure.
767 * @reqs_count: .
768 *
769 **/
770static void qla4_8xxx_spurious_interrupt(struct scsi_qla_host *ha,
771 uint8_t reqs_count)
772{
773 if (reqs_count)
774 return;
775
776 DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
777 if (is_qla8022(ha)) {
778 writel(0, &ha->qla4_8xxx_reg->host_int);
779 if (test_bit(AF_INTx_ENABLED, &ha->flags))
780 qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
781 0xfbff);
782 }
783 ha->spurious_int_count++;
784}
785
786/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700787 * qla4xxx_intr_handler - hardware interrupt handler.
788 * @irq: Unused
789 * @dev_id: Pointer to host adapter structure
David Somayajuluafaf5a22006-09-19 10:28:00 -0700790 **/
David Howells7d12e782006-10-05 14:55:46 +0100791irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700792{
793 struct scsi_qla_host *ha;
794 uint32_t intr_status;
795 unsigned long flags = 0;
796 uint8_t reqs_count = 0;
797
798 ha = (struct scsi_qla_host *) dev_id;
799 if (!ha) {
800 DEBUG2(printk(KERN_INFO
801 "qla4xxx: Interrupt with NULL host ptr\n"));
802 return IRQ_NONE;
803 }
804
805 spin_lock_irqsave(&ha->hardware_lock, flags);
806
David C Somayajulud9150582006-11-15 17:38:40 -0800807 ha->isr_count++;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700808 /*
809 * Repeatedly service interrupts up to a maximum of
810 * MAX_REQS_SERVICED_PER_INTR
811 */
812 while (1) {
813 /*
814 * Read interrupt status
815 */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530816 if (ha->isp_ops->rd_shdw_rsp_q_in(ha) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700817 ha->response_out)
818 intr_status = CSR_SCSI_COMPLETION_INTR;
819 else
820 intr_status = readl(&ha->reg->ctrl_status);
821
822 if ((intr_status &
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530823 (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700824 if (reqs_count == 0)
825 ha->spurious_int_count++;
826 break;
827 }
828
829 if (intr_status & CSR_FATAL_ERROR) {
830 DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
831 "Status 0x%04x\n", ha->host_no,
832 readl(isp_port_error_status (ha))));
833
834 /* Issue Soft Reset to clear this error condition.
835 * This will prevent the RISC from repeatedly
836 * interrupting the driver; thus, allowing the DPC to
837 * get scheduled to continue error recovery.
838 * NOTE: Disabling RISC interrupts does not work in
839 * this case, as CSR_FATAL_ERROR overrides
840 * CSR_SCSI_INTR_ENABLE */
841 if ((readl(&ha->reg->ctrl_status) &
842 CSR_SCSI_RESET_INTR) == 0) {
843 writel(set_rmask(CSR_SOFT_RESET),
844 &ha->reg->ctrl_status);
845 readl(&ha->reg->ctrl_status);
846 }
847
848 writel(set_rmask(CSR_FATAL_ERROR),
849 &ha->reg->ctrl_status);
850 readl(&ha->reg->ctrl_status);
851
852 __qla4xxx_disable_intrs(ha);
853
854 set_bit(DPC_RESET_HA, &ha->dpc_flags);
855
856 break;
857 } else if (intr_status & CSR_SCSI_RESET_INTR) {
858 clear_bit(AF_ONLINE, &ha->flags);
859 __qla4xxx_disable_intrs(ha);
860
861 writel(set_rmask(CSR_SCSI_RESET_INTR),
862 &ha->reg->ctrl_status);
863 readl(&ha->reg->ctrl_status);
864
Karen Higgins7eece5a2011-03-21 03:34:29 -0700865 if (!test_bit(AF_HA_REMOVAL, &ha->flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -0800866 set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700867
868 break;
869 } else if (intr_status & INTR_PENDING) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530870 ha->isp_ops->interrupt_service_routine(ha, intr_status);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700871 ha->total_io_count++;
872 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
873 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700874 }
875 }
876
877 spin_unlock_irqrestore(&ha->hardware_lock, flags);
878
879 return IRQ_HANDLED;
880}
881
882/**
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530883 * qla4_8xxx_intr_handler - hardware interrupt handler.
884 * @irq: Unused
885 * @dev_id: Pointer to host adapter structure
886 **/
887irqreturn_t qla4_8xxx_intr_handler(int irq, void *dev_id)
888{
889 struct scsi_qla_host *ha = dev_id;
890 uint32_t intr_status;
891 uint32_t status;
892 unsigned long flags = 0;
893 uint8_t reqs_count = 0;
894
Lalit Chandivade2232be02010-07-30 14:38:47 +0530895 if (unlikely(pci_channel_offline(ha->pdev)))
896 return IRQ_HANDLED;
897
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530898 ha->isr_count++;
899 status = qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
900 if (!(status & ha->nx_legacy_intr.int_vec_bit))
901 return IRQ_NONE;
902
903 status = qla4_8xxx_rd_32(ha, ISR_INT_STATE_REG);
904 if (!ISR_IS_LEGACY_INTR_TRIGGERED(status)) {
905 DEBUG2(ql4_printk(KERN_INFO, ha,
906 "%s legacy Int not triggered\n", __func__));
907 return IRQ_NONE;
908 }
909
910 /* clear the interrupt */
911 qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
912
913 /* read twice to ensure write is flushed */
914 qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
915 qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
916
917 spin_lock_irqsave(&ha->hardware_lock, flags);
918 while (1) {
919 if (!(readl(&ha->qla4_8xxx_reg->host_int) &
920 ISRX_82XX_RISC_INT)) {
921 qla4_8xxx_spurious_interrupt(ha, reqs_count);
922 break;
923 }
924 intr_status = readl(&ha->qla4_8xxx_reg->host_status);
925 if ((intr_status &
926 (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
927 qla4_8xxx_spurious_interrupt(ha, reqs_count);
928 break;
929 }
930
931 ha->isp_ops->interrupt_service_routine(ha, intr_status);
932
933 /* Enable Interrupt */
934 qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
935
936 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
937 break;
938 }
939
940 spin_unlock_irqrestore(&ha->hardware_lock, flags);
941 return IRQ_HANDLED;
942}
943
944irqreturn_t
945qla4_8xxx_msi_handler(int irq, void *dev_id)
946{
947 struct scsi_qla_host *ha;
948
949 ha = (struct scsi_qla_host *) dev_id;
950 if (!ha) {
951 DEBUG2(printk(KERN_INFO
952 "qla4xxx: MSIX: Interrupt with NULL host ptr\n"));
953 return IRQ_NONE;
954 }
955
956 ha->isr_count++;
957 /* clear the interrupt */
958 qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
959
960 /* read twice to ensure write is flushed */
961 qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
962 qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
963
964 return qla4_8xxx_default_intr_handler(irq, dev_id);
965}
966
967/**
968 * qla4_8xxx_default_intr_handler - hardware interrupt handler.
969 * @irq: Unused
970 * @dev_id: Pointer to host adapter structure
971 *
972 * This interrupt handler is called directly for MSI-X, and
973 * called indirectly for MSI.
974 **/
975irqreturn_t
976qla4_8xxx_default_intr_handler(int irq, void *dev_id)
977{
978 struct scsi_qla_host *ha = dev_id;
979 unsigned long flags;
980 uint32_t intr_status;
981 uint8_t reqs_count = 0;
982
983 spin_lock_irqsave(&ha->hardware_lock, flags);
984 while (1) {
985 if (!(readl(&ha->qla4_8xxx_reg->host_int) &
986 ISRX_82XX_RISC_INT)) {
987 qla4_8xxx_spurious_interrupt(ha, reqs_count);
988 break;
989 }
990
991 intr_status = readl(&ha->qla4_8xxx_reg->host_status);
992 if ((intr_status &
993 (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
994 qla4_8xxx_spurious_interrupt(ha, reqs_count);
995 break;
996 }
997
998 ha->isp_ops->interrupt_service_routine(ha, intr_status);
999
1000 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
1001 break;
1002 }
1003
1004 ha->isr_count++;
1005 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1006 return IRQ_HANDLED;
1007}
1008
1009irqreturn_t
1010qla4_8xxx_msix_rsp_q(int irq, void *dev_id)
1011{
1012 struct scsi_qla_host *ha = dev_id;
1013 unsigned long flags;
1014
1015 spin_lock_irqsave(&ha->hardware_lock, flags);
1016 qla4xxx_process_response_queue(ha);
1017 writel(0, &ha->qla4_8xxx_reg->host_int);
1018 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1019
1020 ha->isr_count++;
1021 return IRQ_HANDLED;
1022}
1023
1024/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001025 * qla4xxx_process_aen - processes AENs generated by firmware
1026 * @ha: pointer to host adapter structure.
1027 * @process_aen: type of AENs to process
1028 *
1029 * Processes specific types of Asynchronous Events generated by firmware.
1030 * The type of AENs to process is specified by process_aen and can be
1031 * PROCESS_ALL_AENS 0
1032 * FLUSH_DDB_CHANGED_AENS 1
1033 * RELOGIN_DDB_CHANGED_AENS 2
1034 **/
1035void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
1036{
1037 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
1038 struct aen *aen;
1039 int i;
1040 unsigned long flags;
1041
1042 spin_lock_irqsave(&ha->hardware_lock, flags);
1043 while (ha->aen_out != ha->aen_in) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001044 aen = &ha->aen_q[ha->aen_out];
David Somayajuluafaf5a22006-09-19 10:28:00 -07001045 /* copy aen information to local structure */
1046 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
1047 mbox_sts[i] = aen->mbox_sts[i];
1048
David C Somayajulu401425b2007-05-23 18:03:20 -07001049 ha->aen_q_count++;
1050 ha->aen_out++;
1051
1052 if (ha->aen_out == MAX_AEN_ENTRIES)
1053 ha->aen_out = 0;
1054
David Somayajuluafaf5a22006-09-19 10:28:00 -07001055 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1056
David C Somayajulu401425b2007-05-23 18:03:20 -07001057 DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
1058 " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
1059 (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
1060 mbox_sts[0], mbox_sts[1], mbox_sts[2],
1061 mbox_sts[3], mbox_sts[4]));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001062
1063 switch (mbox_sts[0]) {
1064 case MBOX_ASTS_DATABASE_CHANGED:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001065 switch (process_aen) {
1066 case FLUSH_DDB_CHANGED_AENS:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001067 DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
1068 "[%d] state=%04x FLUSHED!\n",
1069 ha->host_no, ha->aen_out,
1070 mbox_sts[0], mbox_sts[2],
1071 mbox_sts[3]));
1072 break;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001073 case PROCESS_ALL_AENS:
1074 default:
1075 /* Specific device. */
1076 if (mbox_sts[1] == 1)
1077 qla4xxx_process_ddb_changed(ha,
1078 mbox_sts[2], mbox_sts[3],
1079 mbox_sts[4]);
1080 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001081 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001082 }
1083 spin_lock_irqsave(&ha->hardware_lock, flags);
1084 }
1085 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001086}
1087
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301088int qla4xxx_request_irqs(struct scsi_qla_host *ha)
1089{
1090 int ret;
1091
1092 if (!is_qla8022(ha))
1093 goto try_intx;
1094
1095 if (ql4xenablemsix == 2)
1096 goto try_msi;
1097
1098 if (ql4xenablemsix == 0 || ql4xenablemsix != 1)
1099 goto try_intx;
1100
1101 /* Trying MSI-X */
1102 ret = qla4_8xxx_enable_msix(ha);
1103 if (!ret) {
1104 DEBUG2(ql4_printk(KERN_INFO, ha,
1105 "MSI-X: Enabled (0x%X).\n", ha->revision_id));
1106 goto irq_attached;
1107 }
1108
1109 ql4_printk(KERN_WARNING, ha,
1110 "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
1111
1112try_msi:
1113 /* Trying MSI */
1114 ret = pci_enable_msi(ha->pdev);
1115 if (!ret) {
1116 ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
Shyam Sundar61391d32010-12-02 22:12:08 -08001117 0, DRIVER_NAME, ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301118 if (!ret) {
1119 DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1120 set_bit(AF_MSI_ENABLED, &ha->flags);
1121 goto irq_attached;
1122 } else {
1123 ql4_printk(KERN_WARNING, ha,
1124 "MSI: Failed to reserve interrupt %d "
1125 "already in use.\n", ha->pdev->irq);
1126 pci_disable_msi(ha->pdev);
1127 }
1128 }
1129 ql4_printk(KERN_WARNING, ha,
1130 "MSI: Falling back-to INTx mode -- %d.\n", ret);
1131
1132try_intx:
1133 /* Trying INTx */
1134 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Vikas Chaudhary3e1350c2010-12-02 22:12:03 -08001135 IRQF_SHARED, DRIVER_NAME, ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301136 if (!ret) {
1137 DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
1138 set_bit(AF_INTx_ENABLED, &ha->flags);
1139 goto irq_attached;
1140
1141 } else {
1142 ql4_printk(KERN_WARNING, ha,
1143 "INTx: Failed to reserve interrupt %d already in"
1144 " use.\n", ha->pdev->irq);
1145 return ret;
1146 }
1147
1148irq_attached:
1149 set_bit(AF_IRQ_ATTACHED, &ha->flags);
1150 ha->host->irq = ha->pdev->irq;
1151 ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
1152 __func__, ha->pdev->irq);
1153 return ret;
1154}
1155
1156void qla4xxx_free_irqs(struct scsi_qla_host *ha)
1157{
1158 if (test_bit(AF_MSIX_ENABLED, &ha->flags))
1159 qla4_8xxx_disable_msix(ha);
1160 else if (test_and_clear_bit(AF_MSI_ENABLED, &ha->flags)) {
1161 free_irq(ha->pdev->irq, ha);
1162 pci_disable_msi(ha->pdev);
1163 } else if (test_and_clear_bit(AF_INTx_ENABLED, &ha->flags))
1164 free_irq(ha->pdev->irq, ha);
1165}