blob: 5d9a64a7879bce722b4bb6b94ffce8d3facb7750 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
Andrew Vasquez05236a02007-09-20 14:07:37 -07009#include <linux/delay.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070010#include <scsi/scsi_tcq.h>
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -070013static void qla2x00_process_completed_request(struct scsi_qla_host *, uint32_t);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070014static void qla2x00_status_entry(scsi_qla_host_t *, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070015static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *);
16static void qla2x00_error_entry(scsi_qla_host_t *, sts_entry_t *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070017
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/**
19 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
20 * @irq:
21 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
23 * Called by system whenever the host adapter generates an interrupt.
24 *
25 * Returns handled flag.
26 */
27irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010028qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
30 scsi_qla_host_t *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070031 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070034 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070035 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 ha = (scsi_qla_host_t *) dev_id;
38 if (!ha) {
39 printk(KERN_INFO
40 "%s(): NULL host pointer\n", __func__);
41 return (IRQ_NONE);
42 }
43
Andrew Vasquez3d716442005-07-06 10:30:26 -070044 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 status = 0;
46
Andrew Vasquezc6952482008-04-03 13:13:17 -070047 spin_lock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070049 hccr = RD_REG_WORD(&reg->hccr);
50 if (hccr & HCCR_RISC_PAUSE) {
51 if (pci_channel_offline(ha->pdev))
52 break;
53
54 /*
55 * Issue a "HARD" reset in order for the RISC interrupt
56 * bit to be cleared. Schedule a big hammmer to get
57 * out of the RISC PAUSED state.
58 */
59 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
60 RD_REG_WORD(&reg->hccr);
61
62 ha->isp_ops->fw_dump(ha, 1);
63 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
64 break;
65 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 break;
67
68 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
69 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
70 RD_REG_WORD(&reg->hccr);
71
72 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070073 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
74 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
75 qla2x00_mbx_completion(ha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070077 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
78 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
79 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
80 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
81 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 } else {
83 /*EMPTY*/
84 DEBUG2(printk("scsi(%ld): Unrecognized "
Andrew Vasquez9a853f72005-07-06 10:31:27 -070085 "interrupt type (%d).\n",
86 ha->host_no, mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88 /* Release mailbox registers. */
89 WRT_REG_WORD(&reg->semaphore, 0);
90 RD_REG_WORD(&reg->semaphore);
91 } else {
92 qla2x00_process_response_queue(ha);
93
94 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
95 RD_REG_WORD(&reg->hccr);
96 }
97 }
Andrew Vasquezc6952482008-04-03 13:13:17 -070098 spin_unlock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
101 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800103 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return (IRQ_HANDLED);
107}
108
109/**
110 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
111 * @irq:
112 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 *
114 * Called by system whenever the host adapter generates an interrupt.
115 *
116 * Returns handled flag.
117 */
118irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100119qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
121 scsi_qla_host_t *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700122 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 unsigned long iter;
125 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700127 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 ha = (scsi_qla_host_t *) dev_id;
130 if (!ha) {
131 printk(KERN_INFO
132 "%s(): NULL host pointer\n", __func__);
133 return (IRQ_NONE);
134 }
135
Andrew Vasquez3d716442005-07-06 10:30:26 -0700136 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 status = 0;
138
Andrew Vasquezc6952482008-04-03 13:13:17 -0700139 spin_lock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 for (iter = 50; iter--; ) {
141 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
142 if (stat & HSR_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700143 if (pci_channel_offline(ha->pdev))
144 break;
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 hccr = RD_REG_WORD(&reg->hccr);
147 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Andrew Vasquez07f31802006-12-13 19:20:31 -0800148 qla_printk(KERN_INFO, ha, "Parity error -- "
149 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 else
Andrew Vasquez07f31802006-12-13 19:20:31 -0800151 qla_printk(KERN_INFO, ha, "RISC paused -- "
152 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 /*
155 * Issue a "HARD" reset in order for the RISC
156 * interrupt bit to be cleared. Schedule a big
157 * hammmer to get out of the RISC PAUSED state.
158 */
159 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
160 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800161
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700162 ha->isp_ops->fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
164 break;
165 } else if ((stat & HSR_RISC_INT) == 0)
166 break;
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 case 0x1:
170 case 0x2:
171 case 0x10:
172 case 0x11:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700173 qla2x00_mbx_completion(ha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 status |= MBX_INTERRUPT;
175
176 /* Release mailbox registers. */
177 WRT_REG_WORD(&reg->semaphore, 0);
178 break;
179 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700180 mb[0] = MSW(stat);
181 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
182 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
183 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
184 qla2x00_async_event(ha, mb);
185 break;
186 case 0x13:
187 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 break;
189 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700190 mb[0] = MBA_CMPLT_1_16BIT;
191 mb[1] = MSW(stat);
192 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 break;
194 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700195 mb[0] = MBA_SCSI_COMPLETION;
196 mb[1] = MSW(stat);
197 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
198 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
200 default:
201 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700202 "(%d).\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 ha->host_no, stat & 0xff));
204 break;
205 }
206 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
207 RD_REG_WORD_RELAXED(&reg->hccr);
208 }
Andrew Vasquezc6952482008-04-03 13:13:17 -0700209 spin_unlock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
212 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800214 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 return (IRQ_HANDLED);
218}
219
220/**
221 * qla2x00_mbx_completion() - Process mailbox command completions.
222 * @ha: SCSI driver HA context
223 * @mb0: Mailbox0 register
224 */
225static void
226qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
227{
228 uint16_t cnt;
229 uint16_t __iomem *wptr;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700230 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 /* Load return mailbox registers. */
233 ha->flags.mbox_int = 1;
234 ha->mailbox_out[0] = mb0;
235 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
236
237 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700238 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
240 if (cnt == 4 || cnt == 5)
241 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
242 else
243 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 wptr++;
246 }
247
248 if (ha->mcp) {
249 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
250 __func__, ha->host_no, ha->mcp->mb[0]));
251 } else {
252 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
253 __func__, ha->host_no));
254 }
255}
256
257/**
258 * qla2x00_async_event() - Process aynchronous events.
259 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700260 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700262void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700263qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700265#define LS_UNKNOWN 2
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700266 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 uint16_t handle_cnt;
269 uint16_t cnt;
270 uint32_t handles[5];
Andrew Vasquez3d716442005-07-06 10:30:26 -0700271 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 uint32_t rscn_entry, host_pid;
273 uint8_t rscn_queue_index;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700274 unsigned long flags;
Seokmann Jubd2a1842008-04-03 13:13:30 -0700275 scsi_qla_host_t *vha;
276 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 /* Setup to process RIO completion. */
279 handle_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 switch (mb[0]) {
281 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700282 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 handle_cnt = 1;
284 break;
285 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700286 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 handle_cnt = 1;
288 mb[0] = MBA_SCSI_COMPLETION;
289 break;
290 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700291 handles[0] = mb[1];
292 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 handle_cnt = 2;
294 mb[0] = MBA_SCSI_COMPLETION;
295 break;
296 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700297 handles[0] = mb[1];
298 handles[1] = mb[2];
299 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 handle_cnt = 3;
301 mb[0] = MBA_SCSI_COMPLETION;
302 break;
303 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700304 handles[0] = mb[1];
305 handles[1] = mb[2];
306 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
308 handle_cnt = 4;
309 mb[0] = MBA_SCSI_COMPLETION;
310 break;
311 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700312 handles[0] = mb[1];
313 handles[1] = mb[2];
314 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
316 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
317 handle_cnt = 5;
318 mb[0] = MBA_SCSI_COMPLETION;
319 break;
320 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700321 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 handles[1] = le32_to_cpu(
323 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
324 RD_MAILBOX_REG(ha, reg, 6));
325 handle_cnt = 2;
326 mb[0] = MBA_SCSI_COMPLETION;
327 break;
328 default:
329 break;
330 }
331
332 switch (mb[0]) {
333 case MBA_SCSI_COMPLETION: /* Fast Post */
334 if (!ha->flags.online)
335 break;
336
337 for (cnt = 0; cnt < handle_cnt; cnt++)
338 qla2x00_process_completed_request(ha, handles[cnt]);
339 break;
340
341 case MBA_RESET: /* Reset */
342 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
343
344 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
345 break;
346
347 case MBA_SYSTEM_ERR: /* System Error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 qla_printk(KERN_INFO, ha,
349 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
350 mb[1], mb[2], mb[3]);
351
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700352 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700353 ha->isp_ops->fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Andrew Vasqueze4289242007-07-19 15:05:56 -0700355 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700356 if (mb[1] == 0 && mb[2] == 0) {
357 qla_printk(KERN_ERR, ha,
358 "Unrecoverable Hardware Error: adapter "
359 "marked OFFLINE!\n");
360 ha->flags.online = 0;
361 } else
362 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
363 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 qla_printk(KERN_INFO, ha,
365 "Unrecoverable Hardware Error: adapter marked "
366 "OFFLINE!\n");
367 ha->flags.online = 0;
368 } else
369 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
370 break;
371
372 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
373 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
374 ha->host_no));
375 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
376
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700377 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
379 break;
380
381 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
382 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
383 ha->host_no));
384 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
385
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700386 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
388 break;
389
390 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
391 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
392 ha->host_no));
393 break;
394
395 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
397 mb[1]));
398 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
399
400 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
401 atomic_set(&ha->loop_state, LOOP_DOWN);
402 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800403 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700406 if (ha->parent) {
407 atomic_set(&ha->vp_state, VP_FAILED);
408 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
409 }
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700412 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700415 qla2x00_post_aen_work(ha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 break;
417
418 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
420 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700421 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700423 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 if (mb[1] < 5)
425 link_speed = link_speeds[mb[1]];
426 ha->link_data_rate = mb[1];
427 }
428
429 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
430 ha->host_no, link_speed));
431 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
432 link_speed);
433
434 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700435 qla2x00_post_aen_work(ha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 break;
437
438 case MBA_LOOP_DOWN: /* Loop Down Event */
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700439 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
440 "(%x %x %x).\n", ha->host_no, mb[1], mb[2], mb[3]));
441 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
442 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
445 atomic_set(&ha->loop_state, LOOP_DOWN);
446 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
447 ha->device_flags |= DFLG_NO_CABLE;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800448 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
450
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700451 if (ha->parent) {
452 atomic_set(&ha->vp_state, VP_FAILED);
453 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
454 }
455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 ha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700457 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700458 qla2x00_post_aen_work(ha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 break;
460
461 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
463 ha->host_no, mb[1]));
464 qla_printk(KERN_INFO, ha,
465 "LIP reset occured (%x).\n", mb[1]);
466
467 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
468 atomic_set(&ha->loop_state, LOOP_DOWN);
469 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800470 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
472
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700473 if (ha->parent) {
474 atomic_set(&ha->vp_state, VP_FAILED);
475 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
476 }
477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
479
480 ha->operating_mode = LOOP;
481 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700482 qla2x00_post_aen_work(ha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 break;
484
485 case MBA_POINT_TO_POINT: /* Point-to-Point */
486 if (IS_QLA2100(ha))
487 break;
488
489 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
490 ha->host_no));
491
492 /*
493 * Until there's a transition from loop down to loop up, treat
494 * this as loop down only.
495 */
496 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
497 atomic_set(&ha->loop_state, LOOP_DOWN);
498 if (!atomic_read(&ha->loop_down_timer))
499 atomic_set(&ha->loop_down_timer,
500 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800501 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700504 if (ha->parent) {
505 atomic_set(&ha->vp_state, VP_FAILED);
506 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
507 }
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
510 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
511 }
512 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700513 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800514
515 ha->flags.gpsc_supported = 1;
Andrew Vasquez02d638b2007-08-12 18:22:54 -0700516 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 break;
518
519 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
520 if (IS_QLA2100(ha))
521 break;
522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
524 "received.\n",
525 ha->host_no));
526 qla_printk(KERN_INFO, ha,
527 "Configuration change detected: value=%x.\n", mb[1]);
528
529 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700530 atomic_set(&ha->loop_state, LOOP_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 if (!atomic_read(&ha->loop_down_timer))
532 atomic_set(&ha->loop_down_timer,
533 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800534 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 }
536
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700537 if (ha->parent) {
538 atomic_set(&ha->vp_state, VP_FAILED);
539 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
540 }
541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
543 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
544 break;
545
546 case MBA_PORT_UPDATE: /* Port database update */
Seokmann Jubd2a1842008-04-03 13:13:30 -0700547 if ((ha->flags.npiv_supported) && (ha->num_vhosts)) {
548 for_each_mapped_vp_idx(ha, i) {
549 list_for_each_entry(vha, &ha->vp_list,
550 vp_list) {
551 if ((mb[3] & 0xff)
552 == vha->vp_idx) {
553 ha = vha;
554 break;
555 }
556 }
557 }
558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
561 * event etc. earlier indicating loop is down) then process
562 * it. Otherwise ignore it and Wait for RSCN to come in.
563 */
564 atomic_set(&ha->loop_down_timer, 0);
565 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
566 atomic_read(&ha->loop_state) != LOOP_DEAD) {
567 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700568 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
569 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 break;
571 }
572
573 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
574 ha->host_no));
575 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700576 "scsi(%ld): Port database changed %04x %04x %04x.\n",
577 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579 /*
580 * Mark all devices as missing so we will login again.
581 */
582 atomic_set(&ha->loop_state, LOOP_UP);
583
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800584 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 ha->flags.rscn_queue_overflow = 1;
587
588 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
589 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 break;
591
592 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Jubd2a1842008-04-03 13:13:30 -0700593 if ((ha->flags.npiv_supported) && (ha->num_vhosts)) {
594 for_each_mapped_vp_idx(ha, i) {
595 list_for_each_entry(vha, &ha->vp_list,
596 vp_list) {
597 if ((mb[3] & 0xff)
598 == vha->vp_idx) {
599 ha = vha;
600 break;
601 }
602 }
603 }
604 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
607 ha->host_no));
608 DEBUG(printk(KERN_INFO
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800609 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
610 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 rscn_entry = (mb[1] << 16) | mb[2];
613 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
614 ha->d_id.b.al_pa;
615 if (rscn_entry == host_pid) {
616 DEBUG(printk(KERN_INFO
617 "scsi(%ld): Ignoring RSCN update to local host "
618 "port ID (%06x)\n",
619 ha->host_no, host_pid));
620 break;
621 }
622
623 rscn_queue_index = ha->rscn_in_ptr + 1;
624 if (rscn_queue_index == MAX_RSCN_COUNT)
625 rscn_queue_index = 0;
626 if (rscn_queue_index != ha->rscn_out_ptr) {
627 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
628 ha->rscn_in_ptr = rscn_queue_index;
629 } else {
630 ha->flags.rscn_queue_overflow = 1;
631 }
632
633 atomic_set(&ha->loop_state, LOOP_UPDATE);
634 atomic_set(&ha->loop_down_timer, 0);
635 ha->flags.management_server_logged_in = 0;
636
637 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
638 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -0700639 qla2x00_post_aen_work(ha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 break;
641
642 /* case MBA_RIO_RESPONSE: */
643 case MBA_ZIO_RESPONSE:
644 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
645 ha->host_no));
646 DEBUG(printk(KERN_INFO
647 "scsi(%ld): [R|Z]IO update completion.\n",
648 ha->host_no));
649
Andrew Vasqueze4289242007-07-19 15:05:56 -0700650 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700651 qla24xx_process_response_queue(ha);
652 else
653 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700655
656 case MBA_DISCARD_RND_FRAME:
657 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
658 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
659 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700660
661 case MBA_TRACE_NOTIFICATION:
662 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
663 ha->host_no, mb[1], mb[2]));
664 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700665
666 case MBA_ISP84XX_ALERT:
667 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
668 "%04x %04x %04x\n", ha->host_no, mb[1], mb[2], mb[3]));
669
670 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
671 switch (mb[1]) {
672 case A84_PANIC_RECOVERY:
673 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
674 "%04x %04x\n", mb[2], mb[3]);
675 break;
676 case A84_OP_LOGIN_COMPLETE:
677 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
678 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
679 "firmware version %x\n", ha->cs84xx->op_fw_version));
680 break;
681 case A84_DIAG_LOGIN_COMPLETE:
682 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
683 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
684 "diagnostic firmware version %x\n",
685 ha->cs84xx->diag_fw_version));
686 break;
687 case A84_GOLD_LOGIN_COMPLETE:
688 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
689 ha->cs84xx->fw_update = 1;
690 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
691 "firmware version %x\n",
692 ha->cs84xx->gold_fw_version));
693 break;
694 default:
695 qla_printk(KERN_ERR, ha,
696 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
697 mb[1], mb[2], mb[3]);
698 }
699 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
700 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700702
703 if (!ha->parent && ha->num_vhosts)
704 qla2x00_alert_all_vps(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
706
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700707static void
708qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
709{
710 fc_port_t *fcport = data;
711
712 if (fcport->ha->max_q_depth <= sdev->queue_depth)
713 return;
714
715 if (sdev->ordered_tags)
716 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
717 sdev->queue_depth + 1);
718 else
719 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
720 sdev->queue_depth + 1);
721
722 fcport->last_ramp_up = jiffies;
723
724 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
725 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
726 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
727 sdev->queue_depth));
728}
729
730static void
731qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
732{
733 fc_port_t *fcport = data;
734
735 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
736 return;
737
738 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
739 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
740 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
741 sdev->queue_depth));
742}
743
744static inline void
745qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
746{
747 fc_port_t *fcport;
748 struct scsi_device *sdev;
749
750 sdev = sp->cmd->device;
751 if (sdev->queue_depth >= ha->max_q_depth)
752 return;
753
754 fcport = sp->fcport;
755 if (time_before(jiffies,
756 fcport->last_ramp_up + ql2xqfullrampup * HZ))
757 return;
758 if (time_before(jiffies,
759 fcport->last_queue_full + ql2xqfullrampup * HZ))
760 return;
761
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700762 starget_for_each_device(sdev->sdev_target, fcport,
763 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700764}
765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766/**
767 * qla2x00_process_completed_request() - Process a Fast Post response.
768 * @ha: SCSI driver HA context
769 * @index: SRB index
770 */
771static void
772qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
773{
774 srb_t *sp;
775
776 /* Validate handle. */
777 if (index >= MAX_OUTSTANDING_COMMANDS) {
778 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
779 ha->host_no, index));
780 qla_printk(KERN_WARNING, ha,
781 "Invalid SCSI completion handle %d.\n", index);
782
783 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
784 return;
785 }
786
787 sp = ha->outstanding_cmds[index];
788 if (sp) {
789 /* Free outstanding command slot. */
790 ha->outstanding_cmds[index] = NULL;
791
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 CMD_COMPL_STATUS(sp->cmd) = 0L;
793 CMD_SCSI_STATUS(sp->cmd) = 0L;
794
795 /* Save ISP completion status */
796 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700797
798 qla2x00_ramp_up_queue_depth(ha, sp);
f4f051e2005-04-17 15:02:26 -0500799 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 } else {
801 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
802 ha->host_no));
803 qla_printk(KERN_WARNING, ha,
804 "Invalid ISP SCSI completion handle\n");
805
806 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
807 }
808}
809
810/**
811 * qla2x00_process_response_queue() - Process response queue entries.
812 * @ha: SCSI driver HA context
813 */
814void
815qla2x00_process_response_queue(struct scsi_qla_host *ha)
816{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700817 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 sts_entry_t *pkt;
819 uint16_t handle_cnt;
820 uint16_t cnt;
821
822 if (!ha->flags.online)
823 return;
824
825 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
826 pkt = (sts_entry_t *)ha->response_ring_ptr;
827
828 ha->rsp_ring_index++;
829 if (ha->rsp_ring_index == ha->response_q_length) {
830 ha->rsp_ring_index = 0;
831 ha->response_ring_ptr = ha->response_ring;
832 } else {
833 ha->response_ring_ptr++;
834 }
835
836 if (pkt->entry_status != 0) {
837 DEBUG3(printk(KERN_INFO
838 "scsi(%ld): Process error entry.\n", ha->host_no));
839
840 qla2x00_error_entry(ha, pkt);
841 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
842 wmb();
843 continue;
844 }
845
846 switch (pkt->entry_type) {
847 case STATUS_TYPE:
848 qla2x00_status_entry(ha, pkt);
849 break;
850 case STATUS_TYPE_21:
851 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
852 for (cnt = 0; cnt < handle_cnt; cnt++) {
853 qla2x00_process_completed_request(ha,
854 ((sts21_entry_t *)pkt)->handle[cnt]);
855 }
856 break;
857 case STATUS_TYPE_22:
858 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
859 for (cnt = 0; cnt < handle_cnt; cnt++) {
860 qla2x00_process_completed_request(ha,
861 ((sts22_entry_t *)pkt)->handle[cnt]);
862 }
863 break;
864 case STATUS_CONT_TYPE:
865 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
866 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 default:
868 /* Type Not Supported. */
869 DEBUG4(printk(KERN_WARNING
870 "scsi(%ld): Received unknown response pkt type %x "
871 "entry status=%x.\n",
872 ha->host_no, pkt->entry_type, pkt->entry_status));
873 break;
874 }
875 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
876 wmb();
877 }
878
879 /* Adjust ring index */
880 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
881}
882
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800883static inline void
884qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
885{
886 struct scsi_cmnd *cp = sp->cmd;
887
888 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
889 sense_len = SCSI_SENSE_BUFFERSIZE;
890
891 CMD_ACTUAL_SNSLEN(cp) = sense_len;
892 sp->request_sense_length = sense_len;
893 sp->request_sense_ptr = cp->sense_buffer;
894 if (sp->request_sense_length > 32)
895 sense_len = 32;
896
897 memcpy(cp->sense_buffer, sense_data, sense_len);
898
899 sp->request_sense_ptr += sense_len;
900 sp->request_sense_length -= sense_len;
901 if (sp->request_sense_length != 0)
902 sp->ha->status_srb = sp;
903
904 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
905 "cmd=%p pid=%ld\n", __func__, sp->ha->host_no, cp->device->channel,
906 cp->device->id, cp->device->lun, cp, cp->serial_number));
907 if (sense_len)
908 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
909 CMD_ACTUAL_SNSLEN(cp)));
910}
911
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912/**
913 * qla2x00_status_entry() - Process a Status IOCB entry.
914 * @ha: SCSI driver HA context
915 * @pkt: Entry pointer
916 */
917static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700918qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 fc_port_t *fcport;
922 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700923 sts_entry_t *sts;
924 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 uint16_t comp_status;
926 uint16_t scsi_status;
927 uint8_t lscsi_status;
928 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700929 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700930 uint8_t *rsp_info, *sense_data;
931
932 sts = (sts_entry_t *) pkt;
933 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700934 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700935 comp_status = le16_to_cpu(sts24->comp_status);
936 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
937 } else {
938 comp_status = le16_to_cpu(sts->comp_status);
939 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700943 if (comp_status == CS_COMPLETE && scsi_status == 0) {
944 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 return;
947 }
948
949 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700950 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
951 sp = ha->outstanding_cmds[sts->handle];
952 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 } else
954 sp = NULL;
955
956 if (sp == NULL) {
957 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
958 ha->host_no));
959 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
960
961 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100962 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 return;
964 }
965 cp = sp->cmd;
966 if (cp == NULL) {
967 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700968 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 qla_printk(KERN_WARNING, ha,
970 "Command is NULL: already returned to OS (sp=%p)\n", sp);
971
972 return;
973 }
974
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700975 lscsi_status = scsi_status & STATUS_MASK;
976 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 CMD_COMPL_STATUS(cp) = comp_status;
978 CMD_SCSI_STATUS(cp) = scsi_status;
979
bdf79622005-04-17 15:06:53 -0500980 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Ravi Ananded17c71b52006-05-17 15:08:55 -0700982 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700983 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700984 sense_len = le32_to_cpu(sts24->sense_len);
985 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
986 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -0700987 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700988 rsp_info = sts24->data;
989 sense_data = sts24->data;
990 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
991 } else {
992 sense_len = le16_to_cpu(sts->req_sense_length);
993 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
994 resid_len = le32_to_cpu(sts->residual_length);
995 rsp_info = sts->rsp_info;
996 sense_data = sts->req_sense_data;
997 }
998
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 /* Check for any FCP transport errors. */
1000 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001001 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001002 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001003 sense_data += rsp_info_len;
1004 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1006 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001007 "retrying command\n", ha->host_no,
1008 cp->device->channel, cp->device->id,
1009 cp->device->lun, rsp_info_len, rsp_info[0],
1010 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1011 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
1013 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -05001014 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 return;
1016 }
1017 }
1018
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08001019 /* Check for overrun. */
1020 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1021 scsi_status & SS_RESIDUAL_OVER)
1022 comp_status = CS_DATA_OVERRUN;
1023
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 /*
1025 * Based on Host and scsi status generate status code for Linux
1026 */
1027 switch (comp_status) {
1028 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001029 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 if (scsi_status == 0) {
1031 cp->result = DID_OK << 16;
1032 break;
1033 }
1034 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001035 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001036 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001038
1039 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001040 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001041 cp->underflow)) {
1042 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001043 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1044 "detected (%x of %x bytes)...returning "
1045 "error status.\n", ha->host_no,
1046 cp->device->channel, cp->device->id,
1047 cp->device->lun, resid,
1048 scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001049
1050 cp->result = DID_ERROR << 16;
1051 break;
1052 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 cp->result = DID_OK << 16 | lscsi_status;
1055
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001056 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1057 DEBUG2(printk(KERN_INFO
1058 "scsi(%ld): QUEUE FULL status detected "
1059 "0x%x-0x%x.\n", ha->host_no, comp_status,
1060 scsi_status));
1061
1062 /* Adjust queue depth for all luns on the port. */
1063 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001064 starget_for_each_device(cp->device->sdev_target,
1065 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001066 break;
1067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 if (lscsi_status != SS_CHECK_CONDITION)
1069 break;
1070
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001071 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 if (!(scsi_status & SS_SENSE_LEN_VALID))
1073 break;
1074
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001075 qla2x00_handle_sense(sp, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 break;
1077
1078 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001079 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001080 /* Use F/W calculated residual length. */
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001081 if (IS_FWI2_CAPABLE(ha)) {
1082 if (scsi_status & SS_RESIDUAL_UNDER &&
1083 resid != fw_resid_len) {
1084 scsi_status &= ~SS_RESIDUAL_UNDER;
1085 lscsi_status = 0;
1086 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001087 resid = fw_resid_len;
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001088 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 if (scsi_status & SS_RESIDUAL_UNDER) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001091 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001093 } else {
1094 DEBUG2(printk(KERN_INFO
1095 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -07001096 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1097 "os_underflow=0x%x\n", ha->host_no,
1098 cp->device->id, cp->device->lun, comp_status,
1099 scsi_status, resid_len, resid, cp->cmnd[0],
1100 cp->underflow));
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001101
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 }
1103
1104 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001105 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 * Status.
1107 */
1108 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 cp->result = DID_OK << 16 | lscsi_status;
1110
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001111 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1112 DEBUG2(printk(KERN_INFO
1113 "scsi(%ld): QUEUE FULL status detected "
1114 "0x%x-0x%x.\n", ha->host_no, comp_status,
1115 scsi_status));
1116
1117 /*
1118 * Adjust queue depth for all luns on the
1119 * port.
1120 */
1121 fcport->last_queue_full = jiffies;
1122 starget_for_each_device(
1123 cp->device->sdev_target, fcport,
1124 qla2x00_adjust_sdev_qdepth_down);
1125 break;
1126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 if (lscsi_status != SS_CHECK_CONDITION)
1128 break;
1129
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001130 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 if (!(scsi_status & SS_SENSE_LEN_VALID))
1132 break;
1133
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001134 qla2x00_handle_sense(sp, sense_data, sense_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001135
Shyam Sundar8084fe12007-07-19 15:05:59 -07001136 /*
1137 * In case of a Underrun condition, set both the lscsi
1138 * status and the completion status to appropriate
1139 * values.
1140 */
1141 if (resid &&
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001142 ((unsigned)(scsi_bufflen(cp) - resid) <
Shyam Sundar8084fe12007-07-19 15:05:59 -07001143 cp->underflow)) {
1144 DEBUG2(qla_printk(KERN_INFO, ha,
1145 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1146 "detected (%x of %x bytes)...returning "
1147 "error status.\n", ha->host_no,
1148 cp->device->channel, cp->device->id,
1149 cp->device->lun, resid,
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001150 scsi_bufflen(cp)));
Shyam Sundar8084fe12007-07-19 15:05:59 -07001151
1152 cp->result = DID_ERROR << 16 | lscsi_status;
1153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 } else {
1155 /*
1156 * If RISC reports underrun and target does not report
1157 * it then we must have a lost frame, so tell upper
1158 * layer to retry it by reporting a bus busy.
1159 */
1160 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1161 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001162 "frame(s) detected (%x of %x bytes)..."
1163 "retrying command.\n", ha->host_no,
1164 cp->device->channel, cp->device->id,
1165 cp->device->lun, resid,
1166 scsi_bufflen(cp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 break;
1170 }
1171
1172 /* Handle mid-layer underflow */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001173 if ((unsigned)(scsi_bufflen(cp) - resid) <
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 cp->underflow) {
1175 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001176 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1177 "detected (%x of %x bytes)...returning "
1178 "error status.\n", ha->host_no,
1179 cp->device->channel, cp->device->id,
1180 cp->device->lun, resid,
1181 scsi_bufflen(cp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
1183 cp->result = DID_ERROR << 16;
1184 break;
1185 }
1186
1187 /* Everybody online, looking good... */
1188 cp->result = DID_OK << 16;
1189 }
1190 break;
1191
1192 case CS_DATA_OVERRUN:
1193 DEBUG2(printk(KERN_INFO
1194 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001195 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1196 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 DEBUG2(printk(KERN_INFO
1198 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1199 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1200 cp->cmnd[4], cp->cmnd[5]));
1201 DEBUG2(printk(KERN_INFO
1202 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1203 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001204 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
1206 cp->result = DID_ERROR << 16;
1207 break;
1208
1209 case CS_PORT_LOGGED_OUT:
1210 case CS_PORT_CONFIG_CHG:
1211 case CS_PORT_BUSY:
1212 case CS_INCOMPLETE:
1213 case CS_PORT_UNAVAILABLE:
1214 /*
1215 * If the port is in Target Down state, return all IOs for this
1216 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1217 * retry_queue.
1218 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1220 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001221 ha->host_no, cp->device->id, cp->device->lun,
1222 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 atomic_read(&fcport->state)));
1224
f4f051e2005-04-17 15:02:26 -05001225 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001227 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 break;
1230
1231 case CS_RESET:
1232 DEBUG2(printk(KERN_INFO
1233 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1234 ha->host_no, comp_status, scsi_status));
1235
f4f051e2005-04-17 15:02:26 -05001236 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 break;
1238
1239 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001240 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 * hv2.19.12 - DID_ABORT does not retry the request if we
1242 * aborted this request then abort otherwise it must be a
1243 * reset.
1244 */
1245 DEBUG2(printk(KERN_INFO
1246 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1247 ha->host_no, comp_status, scsi_status));
1248
1249 cp->result = DID_RESET << 16;
1250 break;
1251
1252 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 cp->result = DID_BUS_BUSY << 16;
1254
Andrew Vasqueze4289242007-07-19 15:05:56 -07001255 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001256 DEBUG2(printk(KERN_INFO
1257 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1258 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1259 cp->device->id, cp->device->lun, comp_status,
1260 scsi_status));
1261 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001263 DEBUG2(printk(KERN_INFO
1264 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1265 "sflags=%x.\n", ha->host_no, cp->device->channel,
1266 cp->device->id, cp->device->lun, comp_status, scsi_status,
1267 le16_to_cpu(sts->status_flags)));
1268
1269 /* Check to see if logout occurred. */
1270 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001271 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 break;
1273
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 default:
1275 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001276 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 qla_printk(KERN_INFO, ha,
1278 "Unknown status detected 0x%x-0x%x.\n",
1279 comp_status, scsi_status);
1280
1281 cp->result = DID_ERROR << 16;
1282 break;
1283 }
1284
1285 /* Place command on done queue. */
1286 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001287 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288}
1289
1290/**
1291 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1292 * @ha: SCSI driver HA context
1293 * @pkt: Entry pointer
1294 *
1295 * Extended sense data.
1296 */
1297static void
1298qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1299{
1300 uint8_t sense_sz = 0;
1301 srb_t *sp = ha->status_srb;
1302 struct scsi_cmnd *cp;
1303
1304 if (sp != NULL && sp->request_sense_length != 0) {
1305 cp = sp->cmd;
1306 if (cp == NULL) {
1307 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001308 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 qla_printk(KERN_INFO, ha,
1310 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001311 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
1313 ha->status_srb = NULL;
1314 return;
1315 }
1316
1317 if (sp->request_sense_length > sizeof(pkt->data)) {
1318 sense_sz = sizeof(pkt->data);
1319 } else {
1320 sense_sz = sp->request_sense_length;
1321 }
1322
1323 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001324 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001325 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1327 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1328
1329 sp->request_sense_ptr += sense_sz;
1330 sp->request_sense_length -= sense_sz;
1331
1332 /* Place command on done queue. */
1333 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001335 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 }
1337 }
1338}
1339
1340/**
1341 * qla2x00_error_entry() - Process an error entry.
1342 * @ha: SCSI driver HA context
1343 * @pkt: Entry pointer
1344 */
1345static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001346qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347{
1348 srb_t *sp;
1349
1350#if defined(QL_DEBUG_LEVEL_2)
1351 if (pkt->entry_status & RF_INV_E_ORDER)
1352 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1353 else if (pkt->entry_status & RF_INV_E_COUNT)
1354 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1355 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001356 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 "%s: Invalid Entry Parameter\n", __func__);
1358 else if (pkt->entry_status & RF_INV_E_TYPE)
1359 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1360 else if (pkt->entry_status & RF_BUSY)
1361 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1362 else
1363 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1364#endif
1365
1366 /* Validate handle. */
1367 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1368 sp = ha->outstanding_cmds[pkt->handle];
1369 else
1370 sp = NULL;
1371
1372 if (sp) {
1373 /* Free outstanding command slot. */
1374 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001375
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 /* Bad payload or header */
1377 if (pkt->entry_status &
1378 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1379 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1380 sp->cmd->result = DID_ERROR << 16;
1381 } else if (pkt->entry_status & RF_BUSY) {
1382 sp->cmd->result = DID_BUS_BUSY << 16;
1383 } else {
1384 sp->cmd->result = DID_ERROR << 16;
1385 }
f4f051e2005-04-17 15:02:26 -05001386 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001388 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1389 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1391 ha->host_no));
1392 qla_printk(KERN_WARNING, ha,
1393 "Error entry - invalid handle\n");
1394
1395 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001396 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 }
1398}
1399
1400/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001401 * qla24xx_mbx_completion() - Process mailbox command completions.
1402 * @ha: SCSI driver HA context
1403 * @mb0: Mailbox0 register
1404 */
1405static void
1406qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1407{
1408 uint16_t cnt;
1409 uint16_t __iomem *wptr;
1410 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1411
1412 /* Load return mailbox registers. */
1413 ha->flags.mbox_int = 1;
1414 ha->mailbox_out[0] = mb0;
1415 wptr = (uint16_t __iomem *)&reg->mailbox1;
1416
1417 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1418 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1419 wptr++;
1420 }
1421
1422 if (ha->mcp) {
1423 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1424 __func__, ha->host_no, ha->mcp->mb[0]));
1425 } else {
1426 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1427 __func__, ha->host_no));
1428 }
1429}
1430
1431/**
1432 * qla24xx_process_response_queue() - Process response queue entries.
1433 * @ha: SCSI driver HA context
1434 */
1435void
1436qla24xx_process_response_queue(struct scsi_qla_host *ha)
1437{
1438 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1439 struct sts_entry_24xx *pkt;
1440
1441 if (!ha->flags.online)
1442 return;
1443
1444 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1445 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1446
1447 ha->rsp_ring_index++;
1448 if (ha->rsp_ring_index == ha->response_q_length) {
1449 ha->rsp_ring_index = 0;
1450 ha->response_ring_ptr = ha->response_ring;
1451 } else {
1452 ha->response_ring_ptr++;
1453 }
1454
1455 if (pkt->entry_status != 0) {
1456 DEBUG3(printk(KERN_INFO
1457 "scsi(%ld): Process error entry.\n", ha->host_no));
1458
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001459 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1460 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1461 wmb();
1462 continue;
1463 }
1464
1465 switch (pkt->entry_type) {
1466 case STATUS_TYPE:
1467 qla2x00_status_entry(ha, pkt);
1468 break;
1469 case STATUS_CONT_TYPE:
1470 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1471 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001472 case VP_RPT_ID_IOCB_TYPE:
1473 qla24xx_report_id_acquisition(ha,
1474 (struct vp_rpt_id_entry_24xx *)pkt);
1475 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001476 default:
1477 /* Type Not Supported. */
1478 DEBUG4(printk(KERN_WARNING
1479 "scsi(%ld): Received unknown response pkt type %x "
1480 "entry status=%x.\n",
1481 ha->host_no, pkt->entry_type, pkt->entry_status));
1482 break;
1483 }
1484 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1485 wmb();
1486 }
1487
1488 /* Adjust ring index */
1489 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1490}
1491
Andrew Vasquez05236a02007-09-20 14:07:37 -07001492static void
1493qla2xxx_check_risc_status(scsi_qla_host_t *ha)
1494{
1495 int rval;
1496 uint32_t cnt;
1497 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1498
1499 if (!IS_QLA25XX(ha))
1500 return;
1501
1502 rval = QLA_SUCCESS;
1503 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1504 RD_REG_DWORD(&reg->iobase_addr);
1505 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1506 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1507 rval == QLA_SUCCESS; cnt--) {
1508 if (cnt) {
1509 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1510 udelay(10);
1511 } else
1512 rval = QLA_FUNCTION_TIMEOUT;
1513 }
1514 if (rval == QLA_SUCCESS)
1515 goto next_test;
1516
1517 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1518 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1519 rval == QLA_SUCCESS; cnt--) {
1520 if (cnt) {
1521 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1522 udelay(10);
1523 } else
1524 rval = QLA_FUNCTION_TIMEOUT;
1525 }
1526 if (rval != QLA_SUCCESS)
1527 goto done;
1528
1529next_test:
1530 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1531 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1532
1533done:
1534 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1535 RD_REG_DWORD(&reg->iobase_window);
1536}
1537
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001538/**
1539 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1540 * @irq:
1541 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001542 *
1543 * Called by system whenever the host adapter generates an interrupt.
1544 *
1545 * Returns handled flag.
1546 */
1547irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001548qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001549{
1550 scsi_qla_host_t *ha;
1551 struct device_reg_24xx __iomem *reg;
1552 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001553 unsigned long iter;
1554 uint32_t stat;
1555 uint32_t hccr;
1556 uint16_t mb[4];
1557
1558 ha = (scsi_qla_host_t *) dev_id;
1559 if (!ha) {
1560 printk(KERN_INFO
1561 "%s(): NULL host pointer\n", __func__);
1562 return IRQ_NONE;
1563 }
1564
1565 reg = &ha->iobase->isp24;
1566 status = 0;
1567
Andrew Vasquezc6952482008-04-03 13:13:17 -07001568 spin_lock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001569 for (iter = 50; iter--; ) {
1570 stat = RD_REG_DWORD(&reg->host_status);
1571 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001572 if (pci_channel_offline(ha->pdev))
1573 break;
1574
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001575 if (ha->hw_event_pause_errors == 0)
1576 qla2x00_post_hwe_work(ha, HW_EVENT_PARITY_ERR,
1577 0, MSW(stat), LSW(stat));
1578 else if (ha->hw_event_pause_errors < 0xffffffff)
1579 ha->hw_event_pause_errors++;
1580
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001581 hccr = RD_REG_DWORD(&reg->hccr);
1582
1583 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1584 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001585
1586 qla2xxx_check_risc_status(ha);
1587
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001588 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001589 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1590 break;
1591 } else if ((stat & HSRX_RISC_INT) == 0)
1592 break;
1593
1594 switch (stat & 0xff) {
1595 case 0x1:
1596 case 0x2:
1597 case 0x10:
1598 case 0x11:
1599 qla24xx_mbx_completion(ha, MSW(stat));
1600 status |= MBX_INTERRUPT;
1601
1602 break;
1603 case 0x12:
1604 mb[0] = MSW(stat);
1605 mb[1] = RD_REG_WORD(&reg->mailbox1);
1606 mb[2] = RD_REG_WORD(&reg->mailbox2);
1607 mb[3] = RD_REG_WORD(&reg->mailbox3);
1608 qla2x00_async_event(ha, mb);
1609 break;
1610 case 0x13:
1611 qla24xx_process_response_queue(ha);
1612 break;
1613 default:
1614 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1615 "(%d).\n",
1616 ha->host_no, stat & 0xff));
1617 break;
1618 }
1619 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1620 RD_REG_DWORD_RELAXED(&reg->hccr);
1621 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001622 spin_unlock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001623
1624 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1625 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001626 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001627 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001628 }
1629
1630 return IRQ_HANDLED;
1631}
1632
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001633static irqreturn_t
1634qla24xx_msix_rsp_q(int irq, void *dev_id)
1635{
1636 scsi_qla_host_t *ha;
1637 struct device_reg_24xx __iomem *reg;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001638
1639 ha = dev_id;
1640 reg = &ha->iobase->isp24;
1641
Andrew Vasquezc6952482008-04-03 13:13:17 -07001642 spin_lock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001643
1644 qla24xx_process_response_queue(ha);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001645 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001646
Andrew Vasquezc6952482008-04-03 13:13:17 -07001647 spin_unlock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001648
1649 return IRQ_HANDLED;
1650}
1651
1652static irqreturn_t
1653qla24xx_msix_default(int irq, void *dev_id)
1654{
1655 scsi_qla_host_t *ha;
1656 struct device_reg_24xx __iomem *reg;
1657 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001658 uint32_t stat;
1659 uint32_t hccr;
1660 uint16_t mb[4];
1661
1662 ha = dev_id;
1663 reg = &ha->iobase->isp24;
1664 status = 0;
1665
Andrew Vasquezc6952482008-04-03 13:13:17 -07001666 spin_lock(&ha->hardware_lock);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001667 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001668 stat = RD_REG_DWORD(&reg->host_status);
1669 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001670 if (pci_channel_offline(ha->pdev))
1671 break;
1672
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001673 if (ha->hw_event_pause_errors == 0)
1674 qla2x00_post_hwe_work(ha, HW_EVENT_PARITY_ERR,
1675 0, MSW(stat), LSW(stat));
1676 else if (ha->hw_event_pause_errors < 0xffffffff)
1677 ha->hw_event_pause_errors++;
1678
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001679 hccr = RD_REG_DWORD(&reg->hccr);
1680
1681 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1682 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001683
1684 qla2xxx_check_risc_status(ha);
1685
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001686 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001687 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1688 break;
1689 } else if ((stat & HSRX_RISC_INT) == 0)
1690 break;
1691
1692 switch (stat & 0xff) {
1693 case 0x1:
1694 case 0x2:
1695 case 0x10:
1696 case 0x11:
1697 qla24xx_mbx_completion(ha, MSW(stat));
1698 status |= MBX_INTERRUPT;
1699
1700 break;
1701 case 0x12:
1702 mb[0] = MSW(stat);
1703 mb[1] = RD_REG_WORD(&reg->mailbox1);
1704 mb[2] = RD_REG_WORD(&reg->mailbox2);
1705 mb[3] = RD_REG_WORD(&reg->mailbox3);
1706 qla2x00_async_event(ha, mb);
1707 break;
1708 case 0x13:
1709 qla24xx_process_response_queue(ha);
1710 break;
1711 default:
1712 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1713 "(%d).\n",
1714 ha->host_no, stat & 0xff));
1715 break;
1716 }
1717 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001718 } while (0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07001719 spin_unlock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001720
1721 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1722 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001723 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001724 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001725 }
1726
1727 return IRQ_HANDLED;
1728}
1729
1730/* Interrupt handling helpers. */
1731
1732struct qla_init_msix_entry {
1733 uint16_t entry;
1734 uint16_t index;
1735 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001736 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001737};
1738
1739static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1740 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1741 "qla2xxx (default)", qla24xx_msix_default },
1742
1743 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1744 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1745};
1746
1747static void
1748qla24xx_disable_msix(scsi_qla_host_t *ha)
1749{
1750 int i;
1751 struct qla_msix_entry *qentry;
1752
1753 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1754 qentry = &ha->msix_entries[imsix_entries[i].index];
1755 if (qentry->have_irq)
1756 free_irq(qentry->msix_vector, ha);
1757 }
1758 pci_disable_msix(ha->pdev);
1759}
1760
1761static int
1762qla24xx_enable_msix(scsi_qla_host_t *ha)
1763{
1764 int i, ret;
1765 struct msix_entry entries[QLA_MSIX_ENTRIES];
1766 struct qla_msix_entry *qentry;
1767
1768 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1769 entries[i].entry = imsix_entries[i].entry;
1770
1771 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1772 if (ret) {
1773 qla_printk(KERN_WARNING, ha,
1774 "MSI-X: Failed to enable support -- %d/%d\n",
1775 QLA_MSIX_ENTRIES, ret);
1776 goto msix_out;
1777 }
1778 ha->flags.msix_enabled = 1;
1779
1780 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1781 qentry = &ha->msix_entries[imsix_entries[i].index];
1782 qentry->msix_vector = entries[i].vector;
1783 qentry->msix_entry = entries[i].entry;
1784 qentry->have_irq = 0;
1785 ret = request_irq(qentry->msix_vector,
1786 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1787 if (ret) {
1788 qla_printk(KERN_WARNING, ha,
1789 "MSI-X: Unable to register handler -- %x/%d.\n",
1790 imsix_entries[i].index, ret);
1791 qla24xx_disable_msix(ha);
1792 goto msix_out;
1793 }
1794 qentry->have_irq = 1;
1795 }
1796
1797msix_out:
1798 return ret;
1799}
1800
1801int
1802qla2x00_request_irqs(scsi_qla_host_t *ha)
1803{
1804 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001805 device_reg_t __iomem *reg = ha->iobase;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001806
1807 /* If possible, enable MSI-X. */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001808 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001809 goto skip_msix;
1810
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001811 if (IS_QLA2432(ha) && (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1812 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001813 DEBUG2(qla_printk(KERN_WARNING, ha,
1814 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1815 ha->chip_revision, ha->fw_attributes));
1816
1817 goto skip_msix;
1818 }
1819
Andrew Vasquezda7429f2008-01-17 09:02:11 -08001820 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1821 (ha->pdev->subsystem_device == 0x7040 ||
1822 ha->pdev->subsystem_device == 0x7041 ||
1823 ha->pdev->subsystem_device == 0x1705)) {
1824 DEBUG2(qla_printk(KERN_WARNING, ha,
1825 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1826 ha->pdev->subsystem_vendor,
1827 ha->pdev->subsystem_device));
1828
1829 goto skip_msi;
1830 }
1831
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001832 ret = qla24xx_enable_msix(ha);
1833 if (!ret) {
1834 DEBUG2(qla_printk(KERN_INFO, ha,
1835 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1836 ha->fw_attributes));
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001837 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001838 }
1839 qla_printk(KERN_WARNING, ha,
1840 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1841skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001842
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001843 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001844 goto skip_msi;
1845
1846 ret = pci_enable_msi(ha->pdev);
1847 if (!ret) {
1848 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1849 ha->flags.msi_enabled = 1;
1850 }
1851skip_msi:
1852
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001853 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001854 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001855 if (ret) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001856 qla_printk(KERN_WARNING, ha,
1857 "Failed to reserve interrupt %d already in use.\n",
1858 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001859 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001860 }
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001861 ha->flags.inta_enabled = 1;
1862 ha->host->irq = ha->pdev->irq;
1863clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001864
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001865 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezc6952482008-04-03 13:13:17 -07001866 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001867 if (IS_FWI2_CAPABLE(ha)) {
1868 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1869 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1870 } else {
1871 WRT_REG_WORD(&reg->isp.semaphore, 0);
1872 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1873 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
1874 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001875 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001876 ha->isp_ops->enable_intrs(ha);
1877
1878fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001879 return ret;
1880}
1881
1882void
1883qla2x00_free_irqs(scsi_qla_host_t *ha)
1884{
1885
1886 if (ha->flags.msix_enabled)
1887 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001888 else if (ha->flags.inta_enabled) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001889 free_irq(ha->host->irq, ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001890 pci_disable_msi(ha->pdev);
1891 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001892}