blob: aa65697a86b4718ccf4db3504ba37e396cf58126 [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
4 *
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);
28 if (sense_len == 0)
29 return;
30
31 /* Save total available sense length,
32 * not to exceed cmd's sense buffer size */
33 sense_len = min_t(uint16_t, sense_len, SCSI_SENSE_BUFFERSIZE);
34 srb->req_sense_ptr = cmd->sense_buffer;
35 srb->req_sense_len = sense_len;
36
37 /* Copy sense from sts_entry pkt */
38 sense_len = min_t(uint16_t, sense_len, IOCB_MAX_SENSEDATA_LEN);
39 memcpy(cmd->sense_buffer, sts_entry->senseData, sense_len);
40
41 DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: %s: sense key = %x, "
42 "ASL= %02x, ASC/ASCQ = %02x/%02x\n", ha->host_no,
43 cmd->device->channel, cmd->device->id,
44 cmd->device->lun, __func__,
45 sts_entry->senseData[2] & 0x0f,
46 sts_entry->senseData[7],
47 sts_entry->senseData[12],
48 sts_entry->senseData[13]));
49
50 DEBUG5(qla4xxx_dump_buffer(cmd->sense_buffer, sense_len));
51 srb->flags |= SRB_GOT_SENSE;
52
53 /* Update srb, in case a sts_cont pkt follows */
54 srb->req_sense_ptr += sense_len;
55 srb->req_sense_len -= sense_len;
56 if (srb->req_sense_len != 0)
57 ha->status_srb = srb;
58 else
59 ha->status_srb = NULL;
60}
61
62/**
63 * qla4xxx_status_cont_entry - Process a Status Continuations entry.
64 * @ha: SCSI driver HA context
65 * @sts_cont: Entry pointer
66 *
67 * Extended sense data.
68 */
69static void
70qla4xxx_status_cont_entry(struct scsi_qla_host *ha,
71 struct status_cont_entry *sts_cont)
72{
73 struct srb *srb = ha->status_srb;
74 struct scsi_cmnd *cmd;
75 uint8_t sense_len;
76
77 if (srb == NULL)
78 return;
79
80 cmd = srb->cmd;
81 if (cmd == NULL) {
82 DEBUG2(printk(KERN_INFO "scsi%ld: %s: Cmd already returned "
83 "back to OS srb=%p srb->state:%d\n", ha->host_no,
84 __func__, srb, srb->state));
85 ha->status_srb = NULL;
86 return;
87 }
88
89 /* Copy sense data. */
90 sense_len = min_t(uint16_t, srb->req_sense_len,
91 IOCB_MAX_EXT_SENSEDATA_LEN);
92 memcpy(srb->req_sense_ptr, sts_cont->ext_sense_data, sense_len);
93 DEBUG5(qla4xxx_dump_buffer(srb->req_sense_ptr, sense_len));
94
95 srb->req_sense_ptr += sense_len;
96 srb->req_sense_len -= sense_len;
97
98 /* Place command on done queue. */
99 if (srb->req_sense_len == 0) {
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530100 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
Karen Higgins94bced32009-07-15 15:02:58 -0500101 ha->status_srb = NULL;
102 }
103}
104
105/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700106 * qla4xxx_status_entry - processes status IOCBs
107 * @ha: Pointer to host adapter structure.
108 * @sts_entry: Pointer to status entry structure.
109 **/
110static void qla4xxx_status_entry(struct scsi_qla_host *ha,
111 struct status_entry *sts_entry)
112{
113 uint8_t scsi_status;
114 struct scsi_cmnd *cmd;
115 struct srb *srb;
116 struct ddb_entry *ddb_entry;
117 uint32_t residual;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700118
David Somayajuluafaf5a22006-09-19 10:28:00 -0700119 srb = qla4xxx_del_from_active_array(ha, le32_to_cpu(sts_entry->handle));
120 if (!srb) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700121 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Status Entry invalid "
122 "handle 0x%x, sp=%p. This cmd may have already "
123 "been completed.\n", ha->host_no, __func__,
124 le32_to_cpu(sts_entry->handle), srb));
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530125 ql4_printk(KERN_WARNING, ha, "%s invalid status entry:"
126 " handle=0x%0x\n", __func__, sts_entry->handle);
David C Somayajulu9d562912008-03-19 11:23:03 -0700127 set_bit(DPC_RESET_HA, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700128 return;
129 }
130
131 cmd = srb->cmd;
132 if (cmd == NULL) {
133 DEBUG2(printk("scsi%ld: %s: Command already returned back to "
134 "OS pkt->handle=%d srb=%p srb->state:%d\n",
135 ha->host_no, __func__, sts_entry->handle,
136 srb, srb->state));
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530137 ql4_printk(KERN_WARNING, ha, "Command is NULL:"
138 " already returned to OS (srb=%p)\n", srb);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700139 return;
140 }
141
142 ddb_entry = srb->ddb;
143 if (ddb_entry == NULL) {
144 cmd->result = DID_NO_CONNECT << 16;
145 goto status_entry_exit;
146 }
147
148 residual = le32_to_cpu(sts_entry->residualByteCnt);
149
150 /* Translate ISP error to a Linux SCSI error. */
151 scsi_status = sts_entry->scsiStatus;
152 switch (sts_entry->completionStatus) {
153 case SCS_COMPLETE:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700154
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700155 if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) {
156 cmd->result = DID_ERROR << 16;
157 break;
158 }
159
160 if (sts_entry->iscsiFlags &ISCSI_FLAG_RESIDUAL_UNDER) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900161 scsi_set_resid(cmd, residual);
David C Somayajulu9d562912008-03-19 11:23:03 -0700162 if (!scsi_status && ((scsi_bufflen(cmd) - residual) <
163 cmd->underflow)) {
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700164
165 cmd->result = DID_ERROR << 16;
166
167 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
168 "Mid-layer Data underrun0, "
169 "xferlen = 0x%x, "
170 "residual = 0x%x\n", ha->host_no,
171 cmd->device->channel,
172 cmd->device->id,
173 cmd->device->lun, __func__,
174 scsi_bufflen(cmd), residual));
175 break;
176 }
177 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700178
179 cmd->result = DID_OK << 16 | scsi_status;
180
181 if (scsi_status != SCSI_CHECK_CONDITION)
182 break;
183
184 /* Copy Sense Data into sense buffer. */
Karen Higgins94bced32009-07-15 15:02:58 -0500185 qla4xxx_copy_sense(ha, sts_entry, srb);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700186 break;
187
188 case SCS_INCOMPLETE:
189 /* Always set the status to DID_ERROR, since
190 * all conditions result in that status anyway */
191 cmd->result = DID_ERROR << 16;
192 break;
193
194 case SCS_RESET_OCCURRED:
195 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Device RESET occurred\n",
196 ha->host_no, cmd->device->channel,
197 cmd->device->id, cmd->device->lun, __func__));
198
199 cmd->result = DID_RESET << 16;
200 break;
201
202 case SCS_ABORTED:
203 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Abort occurred\n",
204 ha->host_no, cmd->device->channel,
205 cmd->device->id, cmd->device->lun, __func__));
206
207 cmd->result = DID_RESET << 16;
208 break;
209
210 case SCS_TIMEOUT:
211 DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: Timeout\n",
212 ha->host_no, cmd->device->channel,
213 cmd->device->id, cmd->device->lun));
214
Mike Christie56d7fcf2008-08-19 18:45:26 -0500215 cmd->result = DID_TRANSPORT_DISRUPTED << 16;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700216
217 /*
218 * Mark device missing so that we won't continue to send
219 * I/O to this device. We should get a ddb state change
220 * AEN soon.
221 */
222 if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
223 qla4xxx_mark_device_missing(ha, ddb_entry);
224 break;
225
226 case SCS_DATA_UNDERRUN:
227 case SCS_DATA_OVERRUN:
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700228 if ((sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) ||
Mike Christieb06fc732009-08-20 15:11:00 -0500229 (sts_entry->completionStatus == SCS_DATA_OVERRUN)) {
230 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: " "Data overrun\n",
231 ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700232 cmd->device->channel, cmd->device->id,
Mike Christieb06fc732009-08-20 15:11:00 -0500233 cmd->device->lun, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700234
235 cmd->result = DID_ERROR << 16;
236 break;
237 }
238
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700239 scsi_set_resid(cmd, residual);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700240
241 /*
242 * If there is scsi_status, it takes precedense over
243 * underflow condition.
244 */
245 if (scsi_status != 0) {
246 cmd->result = DID_OK << 16 | scsi_status;
247
248 if (scsi_status != SCSI_CHECK_CONDITION)
249 break;
250
251 /* Copy Sense Data into sense buffer. */
Karen Higgins94bced32009-07-15 15:02:58 -0500252 qla4xxx_copy_sense(ha, sts_entry, srb);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700253 } else {
254 /*
255 * If RISC reports underrun and target does not
256 * report it then we must have a lost frame, so
257 * tell upper layer to retry it by reporting a
258 * bus busy.
259 */
260 if ((sts_entry->iscsiFlags &
261 ISCSI_FLAG_RESIDUAL_UNDER) == 0) {
262 cmd->result = DID_BUS_BUSY << 16;
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900263 } else if ((scsi_bufflen(cmd) - residual) <
David Somayajuluafaf5a22006-09-19 10:28:00 -0700264 cmd->underflow) {
265 /*
266 * Handle mid-layer underflow???
267 *
268 * For kernels less than 2.4, the driver must
269 * return an error if an underflow is detected.
270 * For kernels equal-to and above 2.4, the
271 * mid-layer will appearantly handle the
272 * underflow by detecting the residual count --
273 * unfortunately, we do not see where this is
274 * actually being done. In the interim, we
275 * will return DID_ERROR.
276 */
277 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700278 "Mid-layer Data underrun1, "
279 "xferlen = 0x%x, "
280 "residual = 0x%x\n", ha->host_no,
281 cmd->device->channel,
282 cmd->device->id,
283 cmd->device->lun, __func__,
284 scsi_bufflen(cmd), residual));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700285
286 cmd->result = DID_ERROR << 16;
287 } else {
288 cmd->result = DID_OK << 16;
289 }
290 }
291 break;
292
293 case SCS_DEVICE_LOGGED_OUT:
294 case SCS_DEVICE_UNAVAILABLE:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530295 DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: SCS_DEVICE "
296 "state: 0x%x\n", ha->host_no,
297 cmd->device->channel, cmd->device->id,
298 cmd->device->lun, sts_entry->completionStatus));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700299 /*
300 * Mark device missing so that we won't continue to
301 * send I/O to this device. We should get a ddb
302 * state change AEN soon.
303 */
304 if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
305 qla4xxx_mark_device_missing(ha, ddb_entry);
306
Mike Christie56d7fcf2008-08-19 18:45:26 -0500307 cmd->result = DID_TRANSPORT_DISRUPTED << 16;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700308 break;
309
310 case SCS_QUEUE_FULL:
311 /*
312 * SCSI Mid-Layer handles device queue full
313 */
314 cmd->result = DID_OK << 16 | sts_entry->scsiStatus;
315 DEBUG2(printk("scsi%ld:%d:%d: %s: QUEUE FULL detected "
316 "compl=%02x, scsi=%02x, state=%02x, iFlags=%02x,"
317 " iResp=%02x\n", ha->host_no, cmd->device->id,
318 cmd->device->lun, __func__,
319 sts_entry->completionStatus,
320 sts_entry->scsiStatus, sts_entry->state_flags,
321 sts_entry->iscsiFlags,
322 sts_entry->iscsiResponse));
323 break;
324
325 default:
326 cmd->result = DID_ERROR << 16;
327 break;
328 }
329
330status_entry_exit:
331
Karen Higgins94bced32009-07-15 15:02:58 -0500332 /* complete the request, if not waiting for status_continuation pkt */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700333 srb->cc_stat = sts_entry->completionStatus;
Karen Higgins94bced32009-07-15 15:02:58 -0500334 if (ha->status_srb == NULL)
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530335 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700336}
337
338/**
339 * qla4xxx_process_response_queue - process response queue completions
340 * @ha: Pointer to host adapter structure.
341 *
342 * This routine process response queue completions in interrupt context.
343 * Hardware_lock locked upon entry
344 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530345void qla4xxx_process_response_queue(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700346{
347 uint32_t count = 0;
348 struct srb *srb = NULL;
349 struct status_entry *sts_entry;
350
351 /* Process all responses from response queue */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530352 while ((ha->response_ptr->signature != RESPONSE_PROCESSED)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700353 sts_entry = (struct status_entry *) ha->response_ptr;
354 count++;
355
356 /* Advance pointers for next entry */
357 if (ha->response_out == (RESPONSE_QUEUE_DEPTH - 1)) {
358 ha->response_out = 0;
359 ha->response_ptr = ha->response_ring;
360 } else {
361 ha->response_out++;
362 ha->response_ptr++;
363 }
364
365 /* process entry */
366 switch (sts_entry->hdr.entryType) {
367 case ET_STATUS:
Karen Higgins94bced32009-07-15 15:02:58 -0500368 /* Common status */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700369 qla4xxx_status_entry(ha, sts_entry);
370 break;
371
372 case ET_PASSTHRU_STATUS:
373 break;
374
375 case ET_STATUS_CONTINUATION:
Karen Higgins94bced32009-07-15 15:02:58 -0500376 qla4xxx_status_cont_entry(ha,
377 (struct status_cont_entry *) sts_entry);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700378 break;
379
380 case ET_COMMAND:
381 /* ISP device queue is full. Command not
382 * accepted by ISP. Queue command for
383 * later */
384
385 srb = qla4xxx_del_from_active_array(ha,
386 le32_to_cpu(sts_entry->
387 handle));
388 if (srb == NULL)
389 goto exit_prq_invalid_handle;
390
391 DEBUG2(printk("scsi%ld: %s: FW device queue full, "
392 "srb %p\n", ha->host_no, __func__, srb));
393
394 /* ETRY normally by sending it back with
395 * DID_BUS_BUSY */
396 srb->cmd->result = DID_BUS_BUSY << 16;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530397 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700398 break;
399
400 case ET_CONTINUE:
401 /* Just throw away the continuation entries */
402 DEBUG2(printk("scsi%ld: %s: Continuation entry - "
403 "ignoring\n", ha->host_no, __func__));
404 break;
405
406 default:
407 /*
408 * Invalid entry in response queue, reset RISC
409 * firmware.
410 */
411 DEBUG2(printk("scsi%ld: %s: Invalid entry %x in "
412 "response queue \n", ha->host_no,
413 __func__,
414 sts_entry->hdr.entryType));
415 goto exit_prq_error;
416 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530417 ((struct response *)sts_entry)->signature = RESPONSE_PROCESSED;
418 wmb();
David Somayajuluafaf5a22006-09-19 10:28:00 -0700419 }
420
421 /*
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530422 * Tell ISP we're done with response(s). This also clears the interrupt.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700423 */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530424 ha->isp_ops->complete_iocb(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700425
426 return;
427
428exit_prq_invalid_handle:
429 DEBUG2(printk("scsi%ld: %s: Invalid handle(srb)=%p type=%x IOCS=%x\n",
430 ha->host_no, __func__, srb, sts_entry->hdr.entryType,
431 sts_entry->completionStatus));
432
433exit_prq_error:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530434 ha->isp_ops->complete_iocb(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700435 set_bit(DPC_RESET_HA, &ha->dpc_flags);
436}
437
438/**
439 * qla4xxx_isr_decode_mailbox - decodes mailbox status
440 * @ha: Pointer to host adapter structure.
441 * @mailbox_status: Mailbox status.
442 *
443 * This routine decodes the mailbox status during the ISR.
444 * Hardware_lock locked upon entry. runs in interrupt context.
445 **/
446static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
447 uint32_t mbox_status)
448{
449 int i;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530450 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
David Somayajuluafaf5a22006-09-19 10:28:00 -0700451
452 if ((mbox_status == MBOX_STS_BUSY) ||
453 (mbox_status == MBOX_STS_INTERMEDIATE_COMPLETION) ||
454 (mbox_status >> 12 == MBOX_COMPLETION_STATUS)) {
455 ha->mbox_status[0] = mbox_status;
456
457 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
458 /*
459 * Copy all mailbox registers to a temporary
460 * location and set mailbox command done flag
461 */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530462 for (i = 0; i < ha->mbox_status_count; i++)
463 ha->mbox_status[i] = is_qla8022(ha)
464 ? readl(&ha->qla4_8xxx_reg->mailbox_out[i])
465 : readl(&ha->reg->mailbox[i]);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700466
467 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530468
469 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags))
470 complete(&ha->mbx_intr_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700471 }
472 } else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530473 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
474 mbox_sts[i] = is_qla8022(ha)
475 ? readl(&ha->qla4_8xxx_reg->mailbox_out[i])
476 : readl(&ha->reg->mailbox[i]);
477
David Somayajuluafaf5a22006-09-19 10:28:00 -0700478 /* Immediately process the AENs that don't require much work.
479 * Only queue the database_changed AENs */
David C Somayajulu401425b2007-05-23 18:03:20 -0700480 if (ha->aen_log.count < MAX_AEN_ENTRIES) {
481 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
482 ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530483 mbox_sts[i];
David C Somayajulu401425b2007-05-23 18:03:20 -0700484 ha->aen_log.count++;
485 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700486 switch (mbox_status) {
487 case MBOX_ASTS_SYSTEM_ERROR:
488 /* Log Mailbox registers */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530489 ql4_printk(KERN_INFO, ha, "%s: System Err\n", __func__);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700490 if (ql4xdontresethba) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530491 DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n",
492 ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700493 } else {
494 set_bit(AF_GET_CRASH_RECORD, &ha->flags);
495 set_bit(DPC_RESET_HA, &ha->dpc_flags);
496 }
497 break;
498
499 case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
500 case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
501 case MBOX_ASTS_NVRAM_INVALID:
502 case MBOX_ASTS_IP_ADDRESS_CHANGED:
503 case MBOX_ASTS_DHCP_LEASE_EXPIRED:
504 DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
505 "Reset HA\n", ha->host_no, mbox_status));
506 set_bit(DPC_RESET_HA, &ha->dpc_flags);
507 break;
508
509 case MBOX_ASTS_LINK_UP:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700510 set_bit(AF_LINK_UP, &ha->flags);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +0530511 if (test_bit(AF_INIT_DONE, &ha->flags))
512 set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
513
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530514 ql4_printk(KERN_INFO, ha, "%s: LINK UP\n", __func__);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700515 break;
516
517 case MBOX_ASTS_LINK_DOWN:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700518 clear_bit(AF_LINK_UP, &ha->flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530519 if (test_bit(AF_INIT_DONE, &ha->flags))
520 set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +0530521
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530522 ql4_printk(KERN_INFO, ha, "%s: LINK DOWN\n", __func__);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700523 break;
524
525 case MBOX_ASTS_HEARTBEAT:
526 ha->seconds_since_last_heartbeat = 0;
527 break;
528
529 case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
530 DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
531 "ACQUIRED\n", ha->host_no, mbox_status));
532 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
533 break;
534
535 case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
536 case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
537 * mode
538 * only */
539 case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
540 case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
541 case MBOX_ASTS_SUBNET_STATE_CHANGE:
542 /* No action */
543 DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
544 mbox_status));
545 break;
546
David C Somayajulu401425b2007-05-23 18:03:20 -0700547 case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530548 printk("scsi%ld: AEN %04x, mbox_sts[2]=%04x, "
549 "mbox_sts[3]=%04x\n", ha->host_no, mbox_sts[0],
550 mbox_sts[2], mbox_sts[3]);
David C Somayajulu401425b2007-05-23 18:03:20 -0700551
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530552 /* mbox_sts[2] = Old ACB state
553 * mbox_sts[3] = new ACB state */
554 if ((mbox_sts[3] == ACB_STATE_VALID) &&
555 (mbox_sts[2] == ACB_STATE_TENTATIVE))
David C Somayajulu401425b2007-05-23 18:03:20 -0700556 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530557 else if ((mbox_sts[3] == ACB_STATE_ACQUIRING) &&
558 (mbox_sts[2] == ACB_STATE_VALID))
David C Somayajulu401425b2007-05-23 18:03:20 -0700559 set_bit(DPC_RESET_HA, &ha->dpc_flags);
560 break;
561
David Somayajuluafaf5a22006-09-19 10:28:00 -0700562 case MBOX_ASTS_MAC_ADDRESS_CHANGED:
563 case MBOX_ASTS_DNS:
564 /* No action */
565 DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
566 "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530567 ha->host_no, mbox_sts[0],
568 mbox_sts[1], mbox_sts[2]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700569 break;
570
571 case MBOX_ASTS_SELF_TEST_FAILED:
572 case MBOX_ASTS_LOGIN_FAILED:
573 /* No action */
574 DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
575 "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530576 ha->host_no, mbox_sts[0], mbox_sts[1],
577 mbox_sts[2], mbox_sts[3]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700578 break;
579
580 case MBOX_ASTS_DATABASE_CHANGED:
581 /* Queue AEN information and process it in the DPC
582 * routine */
583 if (ha->aen_q_count > 0) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700584
585 /* decrement available counter */
586 ha->aen_q_count--;
587
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530588 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700589 ha->aen_q[ha->aen_in].mbox_sts[i] =
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530590 mbox_sts[i];
David Somayajuluafaf5a22006-09-19 10:28:00 -0700591
592 /* print debug message */
593 DEBUG2(printk("scsi%ld: AEN[%d] %04x queued"
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530594 " mb1:0x%x mb2:0x%x mb3:0x%x mb4:0x%x\n",
595 ha->host_no, ha->aen_in, mbox_sts[0],
596 mbox_sts[1], mbox_sts[2], mbox_sts[3],
597 mbox_sts[4]));
598
David C Somayajulu401425b2007-05-23 18:03:20 -0700599 /* advance pointer */
600 ha->aen_in++;
601 if (ha->aen_in == MAX_AEN_ENTRIES)
602 ha->aen_in = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700603
604 /* The DPC routine will process the aen */
605 set_bit(DPC_AEN, &ha->dpc_flags);
606 } else {
607 DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
608 "overflowed! AEN LOST!!\n",
609 ha->host_no, __func__,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530610 mbox_sts[0]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700611
612 DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
613 ha->host_no));
614
615 for (i = 0; i < MAX_AEN_ENTRIES; i++) {
616 DEBUG2(printk("AEN[%d] %04x %04x %04x "
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530617 "%04x\n", i, mbox_sts[0],
618 mbox_sts[1], mbox_sts[2],
619 mbox_sts[3]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700620 }
621 }
622 break;
623
624 default:
625 DEBUG2(printk(KERN_WARNING
626 "scsi%ld: AEN %04x UNKNOWN\n",
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530627 ha->host_no, mbox_sts[0]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700628 break;
629 }
630 } else {
631 DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
632 ha->host_no, mbox_status));
633
634 ha->mbox_status[0] = mbox_status;
635 }
636}
637
638/**
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530639 * qla4_8xxx_interrupt_service_routine - isr
640 * @ha: pointer to host adapter structure.
641 *
642 * This is the main interrupt service routine.
643 * hardware_lock locked upon entry. runs in interrupt context.
644 **/
645void qla4_8xxx_interrupt_service_routine(struct scsi_qla_host *ha,
646 uint32_t intr_status)
647{
648 /* Process response queue interrupt. */
649 if (intr_status & HSRX_RISC_IOCB_INT)
650 qla4xxx_process_response_queue(ha);
651
652 /* Process mailbox/asynch event interrupt.*/
653 if (intr_status & HSRX_RISC_MB_INT)
654 qla4xxx_isr_decode_mailbox(ha,
655 readl(&ha->qla4_8xxx_reg->mailbox_out[0]));
656
657 /* clear the interrupt */
658 writel(0, &ha->qla4_8xxx_reg->host_int);
659 readl(&ha->qla4_8xxx_reg->host_int);
660}
661
662/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700663 * qla4xxx_interrupt_service_routine - isr
664 * @ha: pointer to host adapter structure.
665 *
666 * This is the main interrupt service routine.
667 * hardware_lock locked upon entry. runs in interrupt context.
668 **/
669void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
670 uint32_t intr_status)
671{
672 /* Process response queue interrupt. */
673 if (intr_status & CSR_SCSI_COMPLETION_INTR)
674 qla4xxx_process_response_queue(ha);
675
676 /* Process mailbox/asynch event interrupt.*/
677 if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
678 qla4xxx_isr_decode_mailbox(ha,
679 readl(&ha->reg->mailbox[0]));
680
681 /* Clear Mailbox Interrupt */
682 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
683 &ha->reg->ctrl_status);
684 readl(&ha->reg->ctrl_status);
685 }
686}
687
688/**
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530689 * qla4_8xxx_spurious_interrupt - processes spurious interrupt
690 * @ha: pointer to host adapter structure.
691 * @reqs_count: .
692 *
693 **/
694static void qla4_8xxx_spurious_interrupt(struct scsi_qla_host *ha,
695 uint8_t reqs_count)
696{
697 if (reqs_count)
698 return;
699
700 DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
701 if (is_qla8022(ha)) {
702 writel(0, &ha->qla4_8xxx_reg->host_int);
703 if (test_bit(AF_INTx_ENABLED, &ha->flags))
704 qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
705 0xfbff);
706 }
707 ha->spurious_int_count++;
708}
709
710/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700711 * qla4xxx_intr_handler - hardware interrupt handler.
712 * @irq: Unused
713 * @dev_id: Pointer to host adapter structure
David Somayajuluafaf5a22006-09-19 10:28:00 -0700714 **/
David Howells7d12e782006-10-05 14:55:46 +0100715irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700716{
717 struct scsi_qla_host *ha;
718 uint32_t intr_status;
719 unsigned long flags = 0;
720 uint8_t reqs_count = 0;
721
722 ha = (struct scsi_qla_host *) dev_id;
723 if (!ha) {
724 DEBUG2(printk(KERN_INFO
725 "qla4xxx: Interrupt with NULL host ptr\n"));
726 return IRQ_NONE;
727 }
728
729 spin_lock_irqsave(&ha->hardware_lock, flags);
730
David C Somayajulud9150582006-11-15 17:38:40 -0800731 ha->isr_count++;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700732 /*
733 * Repeatedly service interrupts up to a maximum of
734 * MAX_REQS_SERVICED_PER_INTR
735 */
736 while (1) {
737 /*
738 * Read interrupt status
739 */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530740 if (ha->isp_ops->rd_shdw_rsp_q_in(ha) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700741 ha->response_out)
742 intr_status = CSR_SCSI_COMPLETION_INTR;
743 else
744 intr_status = readl(&ha->reg->ctrl_status);
745
746 if ((intr_status &
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530747 (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700748 if (reqs_count == 0)
749 ha->spurious_int_count++;
750 break;
751 }
752
753 if (intr_status & CSR_FATAL_ERROR) {
754 DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
755 "Status 0x%04x\n", ha->host_no,
756 readl(isp_port_error_status (ha))));
757
758 /* Issue Soft Reset to clear this error condition.
759 * This will prevent the RISC from repeatedly
760 * interrupting the driver; thus, allowing the DPC to
761 * get scheduled to continue error recovery.
762 * NOTE: Disabling RISC interrupts does not work in
763 * this case, as CSR_FATAL_ERROR overrides
764 * CSR_SCSI_INTR_ENABLE */
765 if ((readl(&ha->reg->ctrl_status) &
766 CSR_SCSI_RESET_INTR) == 0) {
767 writel(set_rmask(CSR_SOFT_RESET),
768 &ha->reg->ctrl_status);
769 readl(&ha->reg->ctrl_status);
770 }
771
772 writel(set_rmask(CSR_FATAL_ERROR),
773 &ha->reg->ctrl_status);
774 readl(&ha->reg->ctrl_status);
775
776 __qla4xxx_disable_intrs(ha);
777
778 set_bit(DPC_RESET_HA, &ha->dpc_flags);
779
780 break;
781 } else if (intr_status & CSR_SCSI_RESET_INTR) {
782 clear_bit(AF_ONLINE, &ha->flags);
783 __qla4xxx_disable_intrs(ha);
784
785 writel(set_rmask(CSR_SCSI_RESET_INTR),
786 &ha->reg->ctrl_status);
787 readl(&ha->reg->ctrl_status);
788
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530789 if (!test_bit(AF_HBA_GOING_AWAY, &ha->flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -0800790 set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700791
792 break;
793 } else if (intr_status & INTR_PENDING) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530794 ha->isp_ops->interrupt_service_routine(ha, intr_status);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700795 ha->total_io_count++;
796 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
797 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700798 }
799 }
800
801 spin_unlock_irqrestore(&ha->hardware_lock, flags);
802
803 return IRQ_HANDLED;
804}
805
806/**
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530807 * qla4_8xxx_intr_handler - hardware interrupt handler.
808 * @irq: Unused
809 * @dev_id: Pointer to host adapter structure
810 **/
811irqreturn_t qla4_8xxx_intr_handler(int irq, void *dev_id)
812{
813 struct scsi_qla_host *ha = dev_id;
814 uint32_t intr_status;
815 uint32_t status;
816 unsigned long flags = 0;
817 uint8_t reqs_count = 0;
818
819 ha->isr_count++;
820 status = qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
821 if (!(status & ha->nx_legacy_intr.int_vec_bit))
822 return IRQ_NONE;
823
824 status = qla4_8xxx_rd_32(ha, ISR_INT_STATE_REG);
825 if (!ISR_IS_LEGACY_INTR_TRIGGERED(status)) {
826 DEBUG2(ql4_printk(KERN_INFO, ha,
827 "%s legacy Int not triggered\n", __func__));
828 return IRQ_NONE;
829 }
830
831 /* clear the interrupt */
832 qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
833
834 /* read twice to ensure write is flushed */
835 qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
836 qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
837
838 spin_lock_irqsave(&ha->hardware_lock, flags);
839 while (1) {
840 if (!(readl(&ha->qla4_8xxx_reg->host_int) &
841 ISRX_82XX_RISC_INT)) {
842 qla4_8xxx_spurious_interrupt(ha, reqs_count);
843 break;
844 }
845 intr_status = readl(&ha->qla4_8xxx_reg->host_status);
846 if ((intr_status &
847 (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
848 qla4_8xxx_spurious_interrupt(ha, reqs_count);
849 break;
850 }
851
852 ha->isp_ops->interrupt_service_routine(ha, intr_status);
853
854 /* Enable Interrupt */
855 qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
856
857 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
858 break;
859 }
860
861 spin_unlock_irqrestore(&ha->hardware_lock, flags);
862 return IRQ_HANDLED;
863}
864
865irqreturn_t
866qla4_8xxx_msi_handler(int irq, void *dev_id)
867{
868 struct scsi_qla_host *ha;
869
870 ha = (struct scsi_qla_host *) dev_id;
871 if (!ha) {
872 DEBUG2(printk(KERN_INFO
873 "qla4xxx: MSIX: Interrupt with NULL host ptr\n"));
874 return IRQ_NONE;
875 }
876
877 ha->isr_count++;
878 /* clear the interrupt */
879 qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
880
881 /* read twice to ensure write is flushed */
882 qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
883 qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
884
885 return qla4_8xxx_default_intr_handler(irq, dev_id);
886}
887
888/**
889 * qla4_8xxx_default_intr_handler - hardware interrupt handler.
890 * @irq: Unused
891 * @dev_id: Pointer to host adapter structure
892 *
893 * This interrupt handler is called directly for MSI-X, and
894 * called indirectly for MSI.
895 **/
896irqreturn_t
897qla4_8xxx_default_intr_handler(int irq, void *dev_id)
898{
899 struct scsi_qla_host *ha = dev_id;
900 unsigned long flags;
901 uint32_t intr_status;
902 uint8_t reqs_count = 0;
903
904 spin_lock_irqsave(&ha->hardware_lock, flags);
905 while (1) {
906 if (!(readl(&ha->qla4_8xxx_reg->host_int) &
907 ISRX_82XX_RISC_INT)) {
908 qla4_8xxx_spurious_interrupt(ha, reqs_count);
909 break;
910 }
911
912 intr_status = readl(&ha->qla4_8xxx_reg->host_status);
913 if ((intr_status &
914 (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
915 qla4_8xxx_spurious_interrupt(ha, reqs_count);
916 break;
917 }
918
919 ha->isp_ops->interrupt_service_routine(ha, intr_status);
920
921 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
922 break;
923 }
924
925 ha->isr_count++;
926 spin_unlock_irqrestore(&ha->hardware_lock, flags);
927 return IRQ_HANDLED;
928}
929
930irqreturn_t
931qla4_8xxx_msix_rsp_q(int irq, void *dev_id)
932{
933 struct scsi_qla_host *ha = dev_id;
934 unsigned long flags;
935
936 spin_lock_irqsave(&ha->hardware_lock, flags);
937 qla4xxx_process_response_queue(ha);
938 writel(0, &ha->qla4_8xxx_reg->host_int);
939 spin_unlock_irqrestore(&ha->hardware_lock, flags);
940
941 ha->isr_count++;
942 return IRQ_HANDLED;
943}
944
945/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700946 * qla4xxx_process_aen - processes AENs generated by firmware
947 * @ha: pointer to host adapter structure.
948 * @process_aen: type of AENs to process
949 *
950 * Processes specific types of Asynchronous Events generated by firmware.
951 * The type of AENs to process is specified by process_aen and can be
952 * PROCESS_ALL_AENS 0
953 * FLUSH_DDB_CHANGED_AENS 1
954 * RELOGIN_DDB_CHANGED_AENS 2
955 **/
956void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
957{
958 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
959 struct aen *aen;
960 int i;
961 unsigned long flags;
962
963 spin_lock_irqsave(&ha->hardware_lock, flags);
964 while (ha->aen_out != ha->aen_in) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700965 aen = &ha->aen_q[ha->aen_out];
David Somayajuluafaf5a22006-09-19 10:28:00 -0700966 /* copy aen information to local structure */
967 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
968 mbox_sts[i] = aen->mbox_sts[i];
969
David C Somayajulu401425b2007-05-23 18:03:20 -0700970 ha->aen_q_count++;
971 ha->aen_out++;
972
973 if (ha->aen_out == MAX_AEN_ENTRIES)
974 ha->aen_out = 0;
975
David Somayajuluafaf5a22006-09-19 10:28:00 -0700976 spin_unlock_irqrestore(&ha->hardware_lock, flags);
977
David C Somayajulu401425b2007-05-23 18:03:20 -0700978 DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
979 " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
980 (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
981 mbox_sts[0], mbox_sts[1], mbox_sts[2],
982 mbox_sts[3], mbox_sts[4]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700983
984 switch (mbox_sts[0]) {
985 case MBOX_ASTS_DATABASE_CHANGED:
986 if (process_aen == FLUSH_DDB_CHANGED_AENS) {
987 DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
988 "[%d] state=%04x FLUSHED!\n",
989 ha->host_no, ha->aen_out,
990 mbox_sts[0], mbox_sts[2],
991 mbox_sts[3]));
992 break;
993 } else if (process_aen == RELOGIN_DDB_CHANGED_AENS) {
994 /* for use during init time, we only want to
995 * relogin non-active ddbs */
996 struct ddb_entry *ddb_entry;
997
998 ddb_entry =
999 /* FIXME: name length? */
1000 qla4xxx_lookup_ddb_by_fw_index(ha,
1001 mbox_sts[2]);
1002 if (!ddb_entry)
1003 break;
1004
1005 ddb_entry->dev_scan_wait_to_complete_relogin =
1006 0;
1007 ddb_entry->dev_scan_wait_to_start_relogin =
1008 jiffies +
1009 ((ddb_entry->default_time2wait +
1010 4) * HZ);
1011
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301012 DEBUG2(printk("scsi%ld: ddb [%d] initate"
David Somayajuluafaf5a22006-09-19 10:28:00 -07001013 " RELOGIN after %d seconds\n",
1014 ha->host_no,
1015 ddb_entry->fw_ddb_index,
1016 ddb_entry->default_time2wait +
1017 4));
1018 break;
1019 }
1020
1021 if (mbox_sts[1] == 0) { /* Global DB change. */
1022 qla4xxx_reinitialize_ddb_list(ha);
1023 } else if (mbox_sts[1] == 1) { /* Specific device. */
1024 qla4xxx_process_ddb_changed(ha, mbox_sts[2],
Vikas Chaudhary821d6e52010-04-28 11:41:21 +05301025 mbox_sts[3], mbox_sts[4]);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001026 }
1027 break;
1028 }
1029 spin_lock_irqsave(&ha->hardware_lock, flags);
1030 }
1031 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001032}
1033
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301034int qla4xxx_request_irqs(struct scsi_qla_host *ha)
1035{
1036 int ret;
1037
1038 if (!is_qla8022(ha))
1039 goto try_intx;
1040
1041 if (ql4xenablemsix == 2)
1042 goto try_msi;
1043
1044 if (ql4xenablemsix == 0 || ql4xenablemsix != 1)
1045 goto try_intx;
1046
1047 /* Trying MSI-X */
1048 ret = qla4_8xxx_enable_msix(ha);
1049 if (!ret) {
1050 DEBUG2(ql4_printk(KERN_INFO, ha,
1051 "MSI-X: Enabled (0x%X).\n", ha->revision_id));
1052 goto irq_attached;
1053 }
1054
1055 ql4_printk(KERN_WARNING, ha,
1056 "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
1057
1058try_msi:
1059 /* Trying MSI */
1060 ret = pci_enable_msi(ha->pdev);
1061 if (!ret) {
1062 ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
1063 IRQF_DISABLED|IRQF_SHARED, DRIVER_NAME, ha);
1064 if (!ret) {
1065 DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1066 set_bit(AF_MSI_ENABLED, &ha->flags);
1067 goto irq_attached;
1068 } else {
1069 ql4_printk(KERN_WARNING, ha,
1070 "MSI: Failed to reserve interrupt %d "
1071 "already in use.\n", ha->pdev->irq);
1072 pci_disable_msi(ha->pdev);
1073 }
1074 }
1075 ql4_printk(KERN_WARNING, ha,
1076 "MSI: Falling back-to INTx mode -- %d.\n", ret);
1077
1078try_intx:
1079 /* Trying INTx */
1080 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
1081 IRQF_DISABLED|IRQF_SHARED, DRIVER_NAME, ha);
1082 if (!ret) {
1083 DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
1084 set_bit(AF_INTx_ENABLED, &ha->flags);
1085 goto irq_attached;
1086
1087 } else {
1088 ql4_printk(KERN_WARNING, ha,
1089 "INTx: Failed to reserve interrupt %d already in"
1090 " use.\n", ha->pdev->irq);
1091 return ret;
1092 }
1093
1094irq_attached:
1095 set_bit(AF_IRQ_ATTACHED, &ha->flags);
1096 ha->host->irq = ha->pdev->irq;
1097 ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
1098 __func__, ha->pdev->irq);
1099 return ret;
1100}
1101
1102void qla4xxx_free_irqs(struct scsi_qla_host *ha)
1103{
1104 if (test_bit(AF_MSIX_ENABLED, &ha->flags))
1105 qla4_8xxx_disable_msix(ha);
1106 else if (test_and_clear_bit(AF_MSI_ENABLED, &ha->flags)) {
1107 free_irq(ha->pdev->irq, ha);
1108 pci_disable_msi(ha->pdev);
1109 } else if (test_and_clear_bit(AF_INTx_ENABLED, &ha->flags))
1110 free_irq(ha->pdev->irq, ha);
1111}