blob: fc84db4069f42d267d870b4deb56a763319312c0 [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/**
14 * qla2x00_process_completed_request() - Process a Fast Post response.
15 * @ha: SCSI driver HA context
16 * @index: SRB index
17 **/
18static void qla4xxx_process_completed_request(struct scsi_qla_host *ha,
19 uint32_t index)
20{
21 struct srb *srb;
22
23 srb = qla4xxx_del_from_active_array(ha, index);
24 if (srb) {
25 /* Save ISP completion status */
26 srb->cmd->result = DID_OK << 16;
27 qla4xxx_srb_compl(ha, srb);
28 } else {
29 DEBUG2(printk("scsi%ld: Invalid ISP SCSI completion handle = "
30 "%d\n", ha->host_no, index));
31 set_bit(DPC_RESET_HA, &ha->dpc_flags);
32 }
33}
34
35/**
36 * qla4xxx_status_entry - processes status IOCBs
37 * @ha: Pointer to host adapter structure.
38 * @sts_entry: Pointer to status entry structure.
39 **/
40static void qla4xxx_status_entry(struct scsi_qla_host *ha,
41 struct status_entry *sts_entry)
42{
43 uint8_t scsi_status;
44 struct scsi_cmnd *cmd;
45 struct srb *srb;
46 struct ddb_entry *ddb_entry;
47 uint32_t residual;
48 uint16_t sensebytecnt;
49
50 if (sts_entry->completionStatus == SCS_COMPLETE &&
51 sts_entry->scsiStatus == 0) {
52 qla4xxx_process_completed_request(ha,
53 le32_to_cpu(sts_entry->
54 handle));
55 return;
56 }
57
58 srb = qla4xxx_del_from_active_array(ha, le32_to_cpu(sts_entry->handle));
59 if (!srb) {
60 /* FIXMEdg: Don't we need to reset ISP in this case??? */
61 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Status Entry invalid "
62 "handle 0x%x, sp=%p. This cmd may have already "
63 "been completed.\n", ha->host_no, __func__,
64 le32_to_cpu(sts_entry->handle), srb));
65 return;
66 }
67
68 cmd = srb->cmd;
69 if (cmd == NULL) {
70 DEBUG2(printk("scsi%ld: %s: Command already returned back to "
71 "OS pkt->handle=%d srb=%p srb->state:%d\n",
72 ha->host_no, __func__, sts_entry->handle,
73 srb, srb->state));
74 dev_warn(&ha->pdev->dev, "Command is NULL:"
75 " already returned to OS (srb=%p)\n", srb);
76 return;
77 }
78
79 ddb_entry = srb->ddb;
80 if (ddb_entry == NULL) {
81 cmd->result = DID_NO_CONNECT << 16;
82 goto status_entry_exit;
83 }
84
85 residual = le32_to_cpu(sts_entry->residualByteCnt);
86
87 /* Translate ISP error to a Linux SCSI error. */
88 scsi_status = sts_entry->scsiStatus;
89 switch (sts_entry->completionStatus) {
90 case SCS_COMPLETE:
91 if (scsi_status == 0) {
92 cmd->result = DID_OK << 16;
93 break;
94 }
95
David C Somayajulu6ea7e332007-07-09 12:44:36 -070096 if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) {
97 cmd->result = DID_ERROR << 16;
98 break;
99 }
100
101 if (sts_entry->iscsiFlags &ISCSI_FLAG_RESIDUAL_UNDER) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900102 scsi_set_resid(cmd, residual);
David Somayajulu65fecc72008-02-21 03:43:00 -0800103 if ((scsi_bufflen(cmd) - residual) < cmd->underflow) {
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700104
105 cmd->result = DID_ERROR << 16;
106
107 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
108 "Mid-layer Data underrun0, "
109 "xferlen = 0x%x, "
110 "residual = 0x%x\n", ha->host_no,
111 cmd->device->channel,
112 cmd->device->id,
113 cmd->device->lun, __func__,
114 scsi_bufflen(cmd), residual));
115 break;
116 }
117 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700118
119 cmd->result = DID_OK << 16 | scsi_status;
120
121 if (scsi_status != SCSI_CHECK_CONDITION)
122 break;
123
124 /* Copy Sense Data into sense buffer. */
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +0900125 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700126
127 sensebytecnt = le16_to_cpu(sts_entry->senseDataByteCnt);
128 if (sensebytecnt == 0)
129 break;
130
131 memcpy(cmd->sense_buffer, sts_entry->senseData,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +0900132 min_t(uint16_t, sensebytecnt, SCSI_SENSE_BUFFERSIZE));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700133
134 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: sense key = %x, "
135 "ASC/ASCQ = %02x/%02x\n", ha->host_no,
136 cmd->device->channel, cmd->device->id,
137 cmd->device->lun, __func__,
138 sts_entry->senseData[2] & 0x0f,
139 sts_entry->senseData[12],
140 sts_entry->senseData[13]));
141
142 srb->flags |= SRB_GOT_SENSE;
143 break;
144
145 case SCS_INCOMPLETE:
146 /* Always set the status to DID_ERROR, since
147 * all conditions result in that status anyway */
148 cmd->result = DID_ERROR << 16;
149 break;
150
151 case SCS_RESET_OCCURRED:
152 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Device RESET occurred\n",
153 ha->host_no, cmd->device->channel,
154 cmd->device->id, cmd->device->lun, __func__));
155
156 cmd->result = DID_RESET << 16;
157 break;
158
159 case SCS_ABORTED:
160 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Abort occurred\n",
161 ha->host_no, cmd->device->channel,
162 cmd->device->id, cmd->device->lun, __func__));
163
164 cmd->result = DID_RESET << 16;
165 break;
166
167 case SCS_TIMEOUT:
168 DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: Timeout\n",
169 ha->host_no, cmd->device->channel,
170 cmd->device->id, cmd->device->lun));
171
172 cmd->result = DID_BUS_BUSY << 16;
173
174 /*
175 * Mark device missing so that we won't continue to send
176 * I/O to this device. We should get a ddb state change
177 * AEN soon.
178 */
179 if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
180 qla4xxx_mark_device_missing(ha, ddb_entry);
181 break;
182
183 case SCS_DATA_UNDERRUN:
184 case SCS_DATA_OVERRUN:
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700185 if ((sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) ||
186 (sts_entry->completionStatus == SCS_DATA_OVERRUN)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700187 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: " "Data overrun, "
188 "residual = 0x%x\n", ha->host_no,
189 cmd->device->channel, cmd->device->id,
190 cmd->device->lun, __func__, residual));
191
192 cmd->result = DID_ERROR << 16;
193 break;
194 }
195
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700196 scsi_set_resid(cmd, residual);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700197
198 /*
199 * If there is scsi_status, it takes precedense over
200 * underflow condition.
201 */
202 if (scsi_status != 0) {
203 cmd->result = DID_OK << 16 | scsi_status;
204
205 if (scsi_status != SCSI_CHECK_CONDITION)
206 break;
207
208 /* Copy Sense Data into sense buffer. */
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +0900209 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700210
211 sensebytecnt =
212 le16_to_cpu(sts_entry->senseDataByteCnt);
213 if (sensebytecnt == 0)
214 break;
215
216 memcpy(cmd->sense_buffer, sts_entry->senseData,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +0900217 min_t(uint16_t, sensebytecnt, SCSI_SENSE_BUFFERSIZE));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700218
219 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: sense key = %x, "
220 "ASC/ASCQ = %02x/%02x\n", ha->host_no,
221 cmd->device->channel, cmd->device->id,
222 cmd->device->lun, __func__,
223 sts_entry->senseData[2] & 0x0f,
224 sts_entry->senseData[12],
225 sts_entry->senseData[13]));
226 } else {
227 /*
228 * If RISC reports underrun and target does not
229 * report it then we must have a lost frame, so
230 * tell upper layer to retry it by reporting a
231 * bus busy.
232 */
233 if ((sts_entry->iscsiFlags &
234 ISCSI_FLAG_RESIDUAL_UNDER) == 0) {
235 cmd->result = DID_BUS_BUSY << 16;
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900236 } else if ((scsi_bufflen(cmd) - residual) <
David Somayajuluafaf5a22006-09-19 10:28:00 -0700237 cmd->underflow) {
238 /*
239 * Handle mid-layer underflow???
240 *
241 * For kernels less than 2.4, the driver must
242 * return an error if an underflow is detected.
243 * For kernels equal-to and above 2.4, the
244 * mid-layer will appearantly handle the
245 * underflow by detecting the residual count --
246 * unfortunately, we do not see where this is
247 * actually being done. In the interim, we
248 * will return DID_ERROR.
249 */
250 DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
David C Somayajulu6ea7e332007-07-09 12:44:36 -0700251 "Mid-layer Data underrun1, "
252 "xferlen = 0x%x, "
253 "residual = 0x%x\n", ha->host_no,
254 cmd->device->channel,
255 cmd->device->id,
256 cmd->device->lun, __func__,
257 scsi_bufflen(cmd), residual));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700258
259 cmd->result = DID_ERROR << 16;
260 } else {
261 cmd->result = DID_OK << 16;
262 }
263 }
264 break;
265
266 case SCS_DEVICE_LOGGED_OUT:
267 case SCS_DEVICE_UNAVAILABLE:
268 /*
269 * Mark device missing so that we won't continue to
270 * send I/O to this device. We should get a ddb
271 * state change AEN soon.
272 */
273 if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
274 qla4xxx_mark_device_missing(ha, ddb_entry);
275
276 cmd->result = DID_BUS_BUSY << 16;
277 break;
278
279 case SCS_QUEUE_FULL:
280 /*
281 * SCSI Mid-Layer handles device queue full
282 */
283 cmd->result = DID_OK << 16 | sts_entry->scsiStatus;
284 DEBUG2(printk("scsi%ld:%d:%d: %s: QUEUE FULL detected "
285 "compl=%02x, scsi=%02x, state=%02x, iFlags=%02x,"
286 " iResp=%02x\n", ha->host_no, cmd->device->id,
287 cmd->device->lun, __func__,
288 sts_entry->completionStatus,
289 sts_entry->scsiStatus, sts_entry->state_flags,
290 sts_entry->iscsiFlags,
291 sts_entry->iscsiResponse));
292 break;
293
294 default:
295 cmd->result = DID_ERROR << 16;
296 break;
297 }
298
299status_entry_exit:
300
301 /* complete the request */
302 srb->cc_stat = sts_entry->completionStatus;
303 qla4xxx_srb_compl(ha, srb);
304}
305
306/**
307 * qla4xxx_process_response_queue - process response queue completions
308 * @ha: Pointer to host adapter structure.
309 *
310 * This routine process response queue completions in interrupt context.
311 * Hardware_lock locked upon entry
312 **/
313static void qla4xxx_process_response_queue(struct scsi_qla_host * ha)
314{
315 uint32_t count = 0;
316 struct srb *srb = NULL;
317 struct status_entry *sts_entry;
318
319 /* Process all responses from response queue */
320 while ((ha->response_in =
321 (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in)) !=
322 ha->response_out) {
323 sts_entry = (struct status_entry *) ha->response_ptr;
324 count++;
325
326 /* Advance pointers for next entry */
327 if (ha->response_out == (RESPONSE_QUEUE_DEPTH - 1)) {
328 ha->response_out = 0;
329 ha->response_ptr = ha->response_ring;
330 } else {
331 ha->response_out++;
332 ha->response_ptr++;
333 }
334
335 /* process entry */
336 switch (sts_entry->hdr.entryType) {
337 case ET_STATUS:
338 /*
339 * Common status - Single completion posted in single
340 * IOSB.
341 */
342 qla4xxx_status_entry(ha, sts_entry);
343 break;
344
345 case ET_PASSTHRU_STATUS:
346 break;
347
348 case ET_STATUS_CONTINUATION:
349 /* Just throw away the status continuation entries */
350 DEBUG2(printk("scsi%ld: %s: Status Continuation entry "
351 "- ignoring\n", ha->host_no, __func__));
352 break;
353
354 case ET_COMMAND:
355 /* ISP device queue is full. Command not
356 * accepted by ISP. Queue command for
357 * later */
358
359 srb = qla4xxx_del_from_active_array(ha,
360 le32_to_cpu(sts_entry->
361 handle));
362 if (srb == NULL)
363 goto exit_prq_invalid_handle;
364
365 DEBUG2(printk("scsi%ld: %s: FW device queue full, "
366 "srb %p\n", ha->host_no, __func__, srb));
367
368 /* ETRY normally by sending it back with
369 * DID_BUS_BUSY */
370 srb->cmd->result = DID_BUS_BUSY << 16;
371 qla4xxx_srb_compl(ha, srb);
372 break;
373
374 case ET_CONTINUE:
375 /* Just throw away the continuation entries */
376 DEBUG2(printk("scsi%ld: %s: Continuation entry - "
377 "ignoring\n", ha->host_no, __func__));
378 break;
379
380 default:
381 /*
382 * Invalid entry in response queue, reset RISC
383 * firmware.
384 */
385 DEBUG2(printk("scsi%ld: %s: Invalid entry %x in "
386 "response queue \n", ha->host_no,
387 __func__,
388 sts_entry->hdr.entryType));
389 goto exit_prq_error;
390 }
391 }
392
393 /*
394 * Done with responses, update the ISP For QLA4010, this also clears
395 * the interrupt.
396 */
397 writel(ha->response_out, &ha->reg->rsp_q_out);
398 readl(&ha->reg->rsp_q_out);
399
400 return;
401
402exit_prq_invalid_handle:
403 DEBUG2(printk("scsi%ld: %s: Invalid handle(srb)=%p type=%x IOCS=%x\n",
404 ha->host_no, __func__, srb, sts_entry->hdr.entryType,
405 sts_entry->completionStatus));
406
407exit_prq_error:
408 writel(ha->response_out, &ha->reg->rsp_q_out);
409 readl(&ha->reg->rsp_q_out);
410
411 set_bit(DPC_RESET_HA, &ha->dpc_flags);
412}
413
414/**
415 * qla4xxx_isr_decode_mailbox - decodes mailbox status
416 * @ha: Pointer to host adapter structure.
417 * @mailbox_status: Mailbox status.
418 *
419 * This routine decodes the mailbox status during the ISR.
420 * Hardware_lock locked upon entry. runs in interrupt context.
421 **/
422static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
423 uint32_t mbox_status)
424{
425 int i;
David C Somayajulu401425b2007-05-23 18:03:20 -0700426 uint32_t mbox_stat2, mbox_stat3;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700427
428 if ((mbox_status == MBOX_STS_BUSY) ||
429 (mbox_status == MBOX_STS_INTERMEDIATE_COMPLETION) ||
430 (mbox_status >> 12 == MBOX_COMPLETION_STATUS)) {
431 ha->mbox_status[0] = mbox_status;
432
433 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
434 /*
435 * Copy all mailbox registers to a temporary
436 * location and set mailbox command done flag
437 */
438 for (i = 1; i < ha->mbox_status_count; i++)
439 ha->mbox_status[i] =
440 readl(&ha->reg->mailbox[i]);
441
442 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700443 }
444 } else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
445 /* Immediately process the AENs that don't require much work.
446 * Only queue the database_changed AENs */
David C Somayajulu401425b2007-05-23 18:03:20 -0700447 if (ha->aen_log.count < MAX_AEN_ENTRIES) {
448 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
449 ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
450 readl(&ha->reg->mailbox[i]);
451 ha->aen_log.count++;
452 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700453 switch (mbox_status) {
454 case MBOX_ASTS_SYSTEM_ERROR:
455 /* Log Mailbox registers */
456 if (ql4xdontresethba) {
457 DEBUG2(printk("%s:Dont Reset HBA\n",
458 __func__));
459 } else {
460 set_bit(AF_GET_CRASH_RECORD, &ha->flags);
461 set_bit(DPC_RESET_HA, &ha->dpc_flags);
462 }
463 break;
464
465 case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
466 case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
467 case MBOX_ASTS_NVRAM_INVALID:
468 case MBOX_ASTS_IP_ADDRESS_CHANGED:
469 case MBOX_ASTS_DHCP_LEASE_EXPIRED:
470 DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
471 "Reset HA\n", ha->host_no, mbox_status));
472 set_bit(DPC_RESET_HA, &ha->dpc_flags);
473 break;
474
475 case MBOX_ASTS_LINK_UP:
476 DEBUG2(printk("scsi%ld: AEN %04x Adapter LINK UP\n",
477 ha->host_no, mbox_status));
478 set_bit(AF_LINK_UP, &ha->flags);
479 break;
480
481 case MBOX_ASTS_LINK_DOWN:
482 DEBUG2(printk("scsi%ld: AEN %04x Adapter LINK DOWN\n",
483 ha->host_no, mbox_status));
484 clear_bit(AF_LINK_UP, &ha->flags);
485 break;
486
487 case MBOX_ASTS_HEARTBEAT:
488 ha->seconds_since_last_heartbeat = 0;
489 break;
490
491 case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
492 DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
493 "ACQUIRED\n", ha->host_no, mbox_status));
494 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
495 break;
496
497 case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
498 case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
499 * mode
500 * only */
501 case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
502 case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
503 case MBOX_ASTS_SUBNET_STATE_CHANGE:
504 /* No action */
505 DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
506 mbox_status));
507 break;
508
David C Somayajulu401425b2007-05-23 18:03:20 -0700509 case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
510 mbox_stat2 = readl(&ha->reg->mailbox[2]);
511 mbox_stat3 = readl(&ha->reg->mailbox[3]);
512
513 if ((mbox_stat3 == 5) && (mbox_stat2 == 3))
514 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
515 else if ((mbox_stat3 == 2) && (mbox_stat2 == 5))
516 set_bit(DPC_RESET_HA, &ha->dpc_flags);
517 break;
518
David Somayajuluafaf5a22006-09-19 10:28:00 -0700519 case MBOX_ASTS_MAC_ADDRESS_CHANGED:
520 case MBOX_ASTS_DNS:
521 /* No action */
522 DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
523 "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
524 ha->host_no, mbox_status,
525 readl(&ha->reg->mailbox[1]),
526 readl(&ha->reg->mailbox[2])));
527 break;
528
529 case MBOX_ASTS_SELF_TEST_FAILED:
530 case MBOX_ASTS_LOGIN_FAILED:
531 /* No action */
532 DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
533 "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
534 ha->host_no, mbox_status,
535 readl(&ha->reg->mailbox[1]),
536 readl(&ha->reg->mailbox[2]),
537 readl(&ha->reg->mailbox[3])));
538 break;
539
540 case MBOX_ASTS_DATABASE_CHANGED:
541 /* Queue AEN information and process it in the DPC
542 * routine */
543 if (ha->aen_q_count > 0) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700544
545 /* decrement available counter */
546 ha->aen_q_count--;
547
548 for (i = 1; i < MBOX_AEN_REG_COUNT; i++)
549 ha->aen_q[ha->aen_in].mbox_sts[i] =
550 readl(&ha->reg->mailbox[i]);
551
552 ha->aen_q[ha->aen_in].mbox_sts[0] = mbox_status;
553
554 /* print debug message */
555 DEBUG2(printk("scsi%ld: AEN[%d] %04x queued"
556 " mb1:0x%x mb2:0x%x mb3:0x%x mb4:0x%x\n",
557 ha->host_no, ha->aen_in,
558 mbox_status,
559 ha->aen_q[ha->aen_in].mbox_sts[1],
560 ha->aen_q[ha->aen_in].mbox_sts[2],
561 ha->aen_q[ha->aen_in].mbox_sts[3],
562 ha->aen_q[ha->aen_in]. mbox_sts[4]));
David C Somayajulu401425b2007-05-23 18:03:20 -0700563 /* advance pointer */
564 ha->aen_in++;
565 if (ha->aen_in == MAX_AEN_ENTRIES)
566 ha->aen_in = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700567
568 /* The DPC routine will process the aen */
569 set_bit(DPC_AEN, &ha->dpc_flags);
570 } else {
571 DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
572 "overflowed! AEN LOST!!\n",
573 ha->host_no, __func__,
574 mbox_status));
575
576 DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
577 ha->host_no));
578
579 for (i = 0; i < MAX_AEN_ENTRIES; i++) {
580 DEBUG2(printk("AEN[%d] %04x %04x %04x "
581 "%04x\n", i,
582 ha->aen_q[i].mbox_sts[0],
583 ha->aen_q[i].mbox_sts[1],
584 ha->aen_q[i].mbox_sts[2],
585 ha->aen_q[i].mbox_sts[3]));
586 }
587 }
588 break;
589
590 default:
591 DEBUG2(printk(KERN_WARNING
592 "scsi%ld: AEN %04x UNKNOWN\n",
593 ha->host_no, mbox_status));
594 break;
595 }
596 } else {
597 DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
598 ha->host_no, mbox_status));
599
600 ha->mbox_status[0] = mbox_status;
601 }
602}
603
604/**
605 * qla4xxx_interrupt_service_routine - isr
606 * @ha: pointer to host adapter structure.
607 *
608 * This is the main interrupt service routine.
609 * hardware_lock locked upon entry. runs in interrupt context.
610 **/
611void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
612 uint32_t intr_status)
613{
614 /* Process response queue interrupt. */
615 if (intr_status & CSR_SCSI_COMPLETION_INTR)
616 qla4xxx_process_response_queue(ha);
617
618 /* Process mailbox/asynch event interrupt.*/
619 if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
620 qla4xxx_isr_decode_mailbox(ha,
621 readl(&ha->reg->mailbox[0]));
622
623 /* Clear Mailbox Interrupt */
624 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
625 &ha->reg->ctrl_status);
626 readl(&ha->reg->ctrl_status);
627 }
628}
629
630/**
631 * qla4xxx_intr_handler - hardware interrupt handler.
632 * @irq: Unused
633 * @dev_id: Pointer to host adapter structure
David Somayajuluafaf5a22006-09-19 10:28:00 -0700634 **/
David Howells7d12e782006-10-05 14:55:46 +0100635irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700636{
637 struct scsi_qla_host *ha;
638 uint32_t intr_status;
639 unsigned long flags = 0;
640 uint8_t reqs_count = 0;
641
642 ha = (struct scsi_qla_host *) dev_id;
643 if (!ha) {
644 DEBUG2(printk(KERN_INFO
645 "qla4xxx: Interrupt with NULL host ptr\n"));
646 return IRQ_NONE;
647 }
648
649 spin_lock_irqsave(&ha->hardware_lock, flags);
650
David C Somayajulud9150582006-11-15 17:38:40 -0800651 ha->isr_count++;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700652 /*
653 * Repeatedly service interrupts up to a maximum of
654 * MAX_REQS_SERVICED_PER_INTR
655 */
656 while (1) {
657 /*
658 * Read interrupt status
659 */
660 if (le32_to_cpu(ha->shadow_regs->rsp_q_in) !=
661 ha->response_out)
662 intr_status = CSR_SCSI_COMPLETION_INTR;
663 else
664 intr_status = readl(&ha->reg->ctrl_status);
665
666 if ((intr_status &
667 (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) ==
668 0) {
669 if (reqs_count == 0)
670 ha->spurious_int_count++;
671 break;
672 }
673
674 if (intr_status & CSR_FATAL_ERROR) {
675 DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
676 "Status 0x%04x\n", ha->host_no,
677 readl(isp_port_error_status (ha))));
678
679 /* Issue Soft Reset to clear this error condition.
680 * This will prevent the RISC from repeatedly
681 * interrupting the driver; thus, allowing the DPC to
682 * get scheduled to continue error recovery.
683 * NOTE: Disabling RISC interrupts does not work in
684 * this case, as CSR_FATAL_ERROR overrides
685 * CSR_SCSI_INTR_ENABLE */
686 if ((readl(&ha->reg->ctrl_status) &
687 CSR_SCSI_RESET_INTR) == 0) {
688 writel(set_rmask(CSR_SOFT_RESET),
689 &ha->reg->ctrl_status);
690 readl(&ha->reg->ctrl_status);
691 }
692
693 writel(set_rmask(CSR_FATAL_ERROR),
694 &ha->reg->ctrl_status);
695 readl(&ha->reg->ctrl_status);
696
697 __qla4xxx_disable_intrs(ha);
698
699 set_bit(DPC_RESET_HA, &ha->dpc_flags);
700
701 break;
702 } else if (intr_status & CSR_SCSI_RESET_INTR) {
703 clear_bit(AF_ONLINE, &ha->flags);
704 __qla4xxx_disable_intrs(ha);
705
706 writel(set_rmask(CSR_SCSI_RESET_INTR),
707 &ha->reg->ctrl_status);
708 readl(&ha->reg->ctrl_status);
709
David C Somayajulu477ffb92007-01-22 12:26:11 -0800710 if (!ql4_mod_unload)
711 set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700712
713 break;
714 } else if (intr_status & INTR_PENDING) {
715 qla4xxx_interrupt_service_routine(ha, intr_status);
716 ha->total_io_count++;
717 if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
718 break;
719
720 intr_status = 0;
721 }
722 }
723
724 spin_unlock_irqrestore(&ha->hardware_lock, flags);
725
726 return IRQ_HANDLED;
727}
728
729/**
730 * qla4xxx_process_aen - processes AENs generated by firmware
731 * @ha: pointer to host adapter structure.
732 * @process_aen: type of AENs to process
733 *
734 * Processes specific types of Asynchronous Events generated by firmware.
735 * The type of AENs to process is specified by process_aen and can be
736 * PROCESS_ALL_AENS 0
737 * FLUSH_DDB_CHANGED_AENS 1
738 * RELOGIN_DDB_CHANGED_AENS 2
739 **/
740void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
741{
742 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
743 struct aen *aen;
744 int i;
745 unsigned long flags;
746
747 spin_lock_irqsave(&ha->hardware_lock, flags);
748 while (ha->aen_out != ha->aen_in) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700749 aen = &ha->aen_q[ha->aen_out];
David Somayajuluafaf5a22006-09-19 10:28:00 -0700750 /* copy aen information to local structure */
751 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
752 mbox_sts[i] = aen->mbox_sts[i];
753
David C Somayajulu401425b2007-05-23 18:03:20 -0700754 ha->aen_q_count++;
755 ha->aen_out++;
756
757 if (ha->aen_out == MAX_AEN_ENTRIES)
758 ha->aen_out = 0;
759
David Somayajuluafaf5a22006-09-19 10:28:00 -0700760 spin_unlock_irqrestore(&ha->hardware_lock, flags);
761
David C Somayajulu401425b2007-05-23 18:03:20 -0700762 DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
763 " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
764 (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
765 mbox_sts[0], mbox_sts[1], mbox_sts[2],
766 mbox_sts[3], mbox_sts[4]));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700767
768 switch (mbox_sts[0]) {
769 case MBOX_ASTS_DATABASE_CHANGED:
770 if (process_aen == FLUSH_DDB_CHANGED_AENS) {
771 DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
772 "[%d] state=%04x FLUSHED!\n",
773 ha->host_no, ha->aen_out,
774 mbox_sts[0], mbox_sts[2],
775 mbox_sts[3]));
776 break;
777 } else if (process_aen == RELOGIN_DDB_CHANGED_AENS) {
778 /* for use during init time, we only want to
779 * relogin non-active ddbs */
780 struct ddb_entry *ddb_entry;
781
782 ddb_entry =
783 /* FIXME: name length? */
784 qla4xxx_lookup_ddb_by_fw_index(ha,
785 mbox_sts[2]);
786 if (!ddb_entry)
787 break;
788
789 ddb_entry->dev_scan_wait_to_complete_relogin =
790 0;
791 ddb_entry->dev_scan_wait_to_start_relogin =
792 jiffies +
793 ((ddb_entry->default_time2wait +
794 4) * HZ);
795
796 DEBUG2(printk("scsi%ld: ddb index [%d] initate"
797 " RELOGIN after %d seconds\n",
798 ha->host_no,
799 ddb_entry->fw_ddb_index,
800 ddb_entry->default_time2wait +
801 4));
802 break;
803 }
804
805 if (mbox_sts[1] == 0) { /* Global DB change. */
806 qla4xxx_reinitialize_ddb_list(ha);
807 } else if (mbox_sts[1] == 1) { /* Specific device. */
808 qla4xxx_process_ddb_changed(ha, mbox_sts[2],
809 mbox_sts[3]);
810 }
811 break;
812 }
813 spin_lock_irqsave(&ha->hardware_lock, flags);
814 }
815 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700816}
817