blob: fc4bfa7f839c8648e021f643387027d1f67cf1d2 [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276 /* Setup to process RIO completion. */
277 handle_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 switch (mb[0]) {
279 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700280 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 handle_cnt = 1;
282 break;
283 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700284 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 handle_cnt = 1;
286 mb[0] = MBA_SCSI_COMPLETION;
287 break;
288 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700289 handles[0] = mb[1];
290 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 handle_cnt = 2;
292 mb[0] = MBA_SCSI_COMPLETION;
293 break;
294 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700295 handles[0] = mb[1];
296 handles[1] = mb[2];
297 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 handle_cnt = 3;
299 mb[0] = MBA_SCSI_COMPLETION;
300 break;
301 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700302 handles[0] = mb[1];
303 handles[1] = mb[2];
304 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
306 handle_cnt = 4;
307 mb[0] = MBA_SCSI_COMPLETION;
308 break;
309 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700310 handles[0] = mb[1];
311 handles[1] = mb[2];
312 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
314 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
315 handle_cnt = 5;
316 mb[0] = MBA_SCSI_COMPLETION;
317 break;
318 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700319 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 handles[1] = le32_to_cpu(
321 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
322 RD_MAILBOX_REG(ha, reg, 6));
323 handle_cnt = 2;
324 mb[0] = MBA_SCSI_COMPLETION;
325 break;
326 default:
327 break;
328 }
329
330 switch (mb[0]) {
331 case MBA_SCSI_COMPLETION: /* Fast Post */
332 if (!ha->flags.online)
333 break;
334
335 for (cnt = 0; cnt < handle_cnt; cnt++)
336 qla2x00_process_completed_request(ha, handles[cnt]);
337 break;
338
339 case MBA_RESET: /* Reset */
340 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
341
342 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
343 break;
344
345 case MBA_SYSTEM_ERR: /* System Error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 qla_printk(KERN_INFO, ha,
347 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
348 mb[1], mb[2], mb[3]);
349
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700350 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700351 ha->isp_ops->fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Andrew Vasqueze4289242007-07-19 15:05:56 -0700353 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700354 if (mb[1] == 0 && mb[2] == 0) {
355 qla_printk(KERN_ERR, ha,
356 "Unrecoverable Hardware Error: adapter "
357 "marked OFFLINE!\n");
358 ha->flags.online = 0;
359 } else
360 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
361 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 qla_printk(KERN_INFO, ha,
363 "Unrecoverable Hardware Error: adapter marked "
364 "OFFLINE!\n");
365 ha->flags.online = 0;
366 } else
367 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
368 break;
369
370 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
371 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
372 ha->host_no));
373 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
374
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700375 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
377 break;
378
379 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
380 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
381 ha->host_no));
382 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
383
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700384 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
386 break;
387
388 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
389 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
390 ha->host_no));
391 break;
392
393 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700394 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", ha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 mb[1]));
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700396 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
399 atomic_set(&ha->loop_state, LOOP_DOWN);
400 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800401 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700404 if (ha->parent) {
405 atomic_set(&ha->vp_state, VP_FAILED);
406 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
407 }
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700410 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700413 qla2x00_post_aen_work(ha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 break;
415
416 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
418 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700419 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700421 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 if (mb[1] < 5)
423 link_speed = link_speeds[mb[1]];
424 ha->link_data_rate = mb[1];
425 }
426
427 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
428 ha->host_no, link_speed));
429 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
430 link_speed);
431
432 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700433 qla2x00_post_aen_work(ha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 break;
435
436 case MBA_LOOP_DOWN: /* Loop Down Event */
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700437 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
438 "(%x %x %x).\n", ha->host_no, mb[1], mb[2], mb[3]));
439 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
440 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
443 atomic_set(&ha->loop_state, LOOP_DOWN);
444 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
445 ha->device_flags |= DFLG_NO_CABLE;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800446 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 }
448
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700449 if (ha->parent) {
450 atomic_set(&ha->vp_state, VP_FAILED);
451 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
452 }
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 ha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700455 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700456 qla2x00_post_aen_work(ha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 break;
458
459 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
461 ha->host_no, mb[1]));
462 qla_printk(KERN_INFO, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700463 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
466 atomic_set(&ha->loop_state, LOOP_DOWN);
467 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800468 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
470
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700471 if (ha->parent) {
472 atomic_set(&ha->vp_state, VP_FAILED);
473 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
474 }
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
477
478 ha->operating_mode = LOOP;
479 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700480 qla2x00_post_aen_work(ha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 break;
482
483 case MBA_POINT_TO_POINT: /* Point-to-Point */
484 if (IS_QLA2100(ha))
485 break;
486
487 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
488 ha->host_no));
489
490 /*
491 * Until there's a transition from loop down to loop up, treat
492 * this as loop down only.
493 */
494 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
495 atomic_set(&ha->loop_state, LOOP_DOWN);
496 if (!atomic_read(&ha->loop_down_timer))
497 atomic_set(&ha->loop_down_timer,
498 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800499 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 }
501
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700502 if (ha->parent) {
503 atomic_set(&ha->vp_state, VP_FAILED);
504 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
505 }
506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
508 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
509 }
510 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700511 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800512
513 ha->flags.gpsc_supported = 1;
Andrew Vasquez02d638b2007-08-12 18:22:54 -0700514 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 break;
516
517 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
518 if (IS_QLA2100(ha))
519 break;
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
522 "received.\n",
523 ha->host_no));
524 qla_printk(KERN_INFO, ha,
525 "Configuration change detected: value=%x.\n", mb[1]);
526
527 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700528 atomic_set(&ha->loop_state, LOOP_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 if (!atomic_read(&ha->loop_down_timer))
530 atomic_set(&ha->loop_down_timer,
531 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800532 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 }
534
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700535 if (ha->parent) {
536 atomic_set(&ha->vp_state, VP_FAILED);
537 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
538 }
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
541 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
542 break;
543
544 case MBA_PORT_UPDATE: /* Port database update */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700546 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 * event etc. earlier indicating loop is down) then process
548 * it. Otherwise ignore it and Wait for RSCN to come in.
549 */
550 atomic_set(&ha->loop_down_timer, 0);
551 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
552 atomic_read(&ha->loop_state) != LOOP_DEAD) {
553 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700554 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
555 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 break;
557 }
558
559 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
560 ha->host_no));
561 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700562 "scsi(%ld): Port database changed %04x %04x %04x.\n",
563 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 /*
566 * Mark all devices as missing so we will login again.
567 */
568 atomic_set(&ha->loop_state, LOOP_UP);
569
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800570 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572 ha->flags.rscn_queue_overflow = 1;
573
574 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
575 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 break;
577
578 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700579 /* Check if the Vport has issued a SCR */
580 if (ha->parent && test_bit(VP_SCR_NEEDED, &ha->vp_flags))
581 break;
582 /* Only handle SCNs for our Vport index. */
583 if (ha->parent && ha->vp_idx != (mb[3] & 0xff))
584 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
587 ha->host_no));
588 DEBUG(printk(KERN_INFO
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800589 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
590 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Ravi Anand59d72d82008-09-11 21:22:53 -0700592 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
594 ha->d_id.b.al_pa;
595 if (rscn_entry == host_pid) {
596 DEBUG(printk(KERN_INFO
597 "scsi(%ld): Ignoring RSCN update to local host "
598 "port ID (%06x)\n",
599 ha->host_no, host_pid));
600 break;
601 }
602
Ravi Anand59d72d82008-09-11 21:22:53 -0700603 /* Ignore reserved bits from RSCN-payload. */
604 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 rscn_queue_index = ha->rscn_in_ptr + 1;
606 if (rscn_queue_index == MAX_RSCN_COUNT)
607 rscn_queue_index = 0;
608 if (rscn_queue_index != ha->rscn_out_ptr) {
609 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
610 ha->rscn_in_ptr = rscn_queue_index;
611 } else {
612 ha->flags.rscn_queue_overflow = 1;
613 }
614
615 atomic_set(&ha->loop_state, LOOP_UPDATE);
616 atomic_set(&ha->loop_down_timer, 0);
617 ha->flags.management_server_logged_in = 0;
618
619 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
620 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -0700621 qla2x00_post_aen_work(ha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 break;
623
624 /* case MBA_RIO_RESPONSE: */
625 case MBA_ZIO_RESPONSE:
626 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
627 ha->host_no));
628 DEBUG(printk(KERN_INFO
629 "scsi(%ld): [R|Z]IO update completion.\n",
630 ha->host_no));
631
Andrew Vasqueze4289242007-07-19 15:05:56 -0700632 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700633 qla24xx_process_response_queue(ha);
634 else
635 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700637
638 case MBA_DISCARD_RND_FRAME:
639 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
640 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
641 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700642
643 case MBA_TRACE_NOTIFICATION:
644 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
645 ha->host_no, mb[1], mb[2]));
646 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700647
648 case MBA_ISP84XX_ALERT:
649 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
650 "%04x %04x %04x\n", ha->host_no, mb[1], mb[2], mb[3]));
651
652 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
653 switch (mb[1]) {
654 case A84_PANIC_RECOVERY:
655 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
656 "%04x %04x\n", mb[2], mb[3]);
657 break;
658 case A84_OP_LOGIN_COMPLETE:
659 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
660 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
661 "firmware version %x\n", ha->cs84xx->op_fw_version));
662 break;
663 case A84_DIAG_LOGIN_COMPLETE:
664 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
665 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
666 "diagnostic firmware version %x\n",
667 ha->cs84xx->diag_fw_version));
668 break;
669 case A84_GOLD_LOGIN_COMPLETE:
670 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
671 ha->cs84xx->fw_update = 1;
672 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
673 "firmware version %x\n",
674 ha->cs84xx->gold_fw_version));
675 break;
676 default:
677 qla_printk(KERN_ERR, ha,
678 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
679 mb[1], mb[2], mb[3]);
680 }
681 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
682 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700684
685 if (!ha->parent && ha->num_vhosts)
686 qla2x00_alert_all_vps(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700689static void
690qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
691{
692 fc_port_t *fcport = data;
693
694 if (fcport->ha->max_q_depth <= sdev->queue_depth)
695 return;
696
697 if (sdev->ordered_tags)
698 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
699 sdev->queue_depth + 1);
700 else
701 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
702 sdev->queue_depth + 1);
703
704 fcport->last_ramp_up = jiffies;
705
706 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
707 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
708 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
709 sdev->queue_depth));
710}
711
712static void
713qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
714{
715 fc_port_t *fcport = data;
716
717 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
718 return;
719
720 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
721 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
722 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
723 sdev->queue_depth));
724}
725
726static inline void
727qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
728{
729 fc_port_t *fcport;
730 struct scsi_device *sdev;
731
732 sdev = sp->cmd->device;
733 if (sdev->queue_depth >= ha->max_q_depth)
734 return;
735
736 fcport = sp->fcport;
737 if (time_before(jiffies,
738 fcport->last_ramp_up + ql2xqfullrampup * HZ))
739 return;
740 if (time_before(jiffies,
741 fcport->last_queue_full + ql2xqfullrampup * HZ))
742 return;
743
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700744 starget_for_each_device(sdev->sdev_target, fcport,
745 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700746}
747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748/**
749 * qla2x00_process_completed_request() - Process a Fast Post response.
750 * @ha: SCSI driver HA context
751 * @index: SRB index
752 */
753static void
754qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
755{
756 srb_t *sp;
757
758 /* Validate handle. */
759 if (index >= MAX_OUTSTANDING_COMMANDS) {
760 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
761 ha->host_no, index));
762 qla_printk(KERN_WARNING, ha,
763 "Invalid SCSI completion handle %d.\n", index);
764
765 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
766 return;
767 }
768
769 sp = ha->outstanding_cmds[index];
770 if (sp) {
771 /* Free outstanding command slot. */
772 ha->outstanding_cmds[index] = NULL;
773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 CMD_COMPL_STATUS(sp->cmd) = 0L;
775 CMD_SCSI_STATUS(sp->cmd) = 0L;
776
777 /* Save ISP completion status */
778 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700779
780 qla2x00_ramp_up_queue_depth(ha, sp);
f4f051e2005-04-17 15:02:26 -0500781 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 } else {
783 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
784 ha->host_no));
785 qla_printk(KERN_WARNING, ha,
786 "Invalid ISP SCSI completion handle\n");
787
788 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
789 }
790}
791
792/**
793 * qla2x00_process_response_queue() - Process response queue entries.
794 * @ha: SCSI driver HA context
795 */
796void
797qla2x00_process_response_queue(struct scsi_qla_host *ha)
798{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700799 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 sts_entry_t *pkt;
801 uint16_t handle_cnt;
802 uint16_t cnt;
803
804 if (!ha->flags.online)
805 return;
806
807 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
808 pkt = (sts_entry_t *)ha->response_ring_ptr;
809
810 ha->rsp_ring_index++;
811 if (ha->rsp_ring_index == ha->response_q_length) {
812 ha->rsp_ring_index = 0;
813 ha->response_ring_ptr = ha->response_ring;
814 } else {
815 ha->response_ring_ptr++;
816 }
817
818 if (pkt->entry_status != 0) {
819 DEBUG3(printk(KERN_INFO
820 "scsi(%ld): Process error entry.\n", ha->host_no));
821
822 qla2x00_error_entry(ha, pkt);
823 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
824 wmb();
825 continue;
826 }
827
828 switch (pkt->entry_type) {
829 case STATUS_TYPE:
830 qla2x00_status_entry(ha, pkt);
831 break;
832 case STATUS_TYPE_21:
833 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
834 for (cnt = 0; cnt < handle_cnt; cnt++) {
835 qla2x00_process_completed_request(ha,
836 ((sts21_entry_t *)pkt)->handle[cnt]);
837 }
838 break;
839 case STATUS_TYPE_22:
840 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
841 for (cnt = 0; cnt < handle_cnt; cnt++) {
842 qla2x00_process_completed_request(ha,
843 ((sts22_entry_t *)pkt)->handle[cnt]);
844 }
845 break;
846 case STATUS_CONT_TYPE:
847 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
848 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 default:
850 /* Type Not Supported. */
851 DEBUG4(printk(KERN_WARNING
852 "scsi(%ld): Received unknown response pkt type %x "
853 "entry status=%x.\n",
854 ha->host_no, pkt->entry_type, pkt->entry_status));
855 break;
856 }
857 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
858 wmb();
859 }
860
861 /* Adjust ring index */
862 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
863}
864
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800865static inline void
866qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
867{
868 struct scsi_cmnd *cp = sp->cmd;
869
870 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
871 sense_len = SCSI_SENSE_BUFFERSIZE;
872
873 CMD_ACTUAL_SNSLEN(cp) = sense_len;
874 sp->request_sense_length = sense_len;
875 sp->request_sense_ptr = cp->sense_buffer;
876 if (sp->request_sense_length > 32)
877 sense_len = 32;
878
879 memcpy(cp->sense_buffer, sense_data, sense_len);
880
881 sp->request_sense_ptr += sense_len;
882 sp->request_sense_length -= sense_len;
883 if (sp->request_sense_length != 0)
Andrew Vasquez19851f12008-08-13 21:37:00 -0700884 sp->fcport->ha->status_srb = sp;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800885
886 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
Andrew Vasquez19851f12008-08-13 21:37:00 -0700887 "cmd=%p pid=%ld\n", __func__, sp->fcport->ha->host_no,
888 cp->device->channel, cp->device->id, cp->device->lun, cp,
889 cp->serial_number));
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800890 if (sense_len)
891 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
892 CMD_ACTUAL_SNSLEN(cp)));
893}
894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895/**
896 * qla2x00_status_entry() - Process a Status IOCB entry.
897 * @ha: SCSI driver HA context
898 * @pkt: Entry pointer
899 */
900static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700901qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 fc_port_t *fcport;
905 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700906 sts_entry_t *sts;
907 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 uint16_t comp_status;
909 uint16_t scsi_status;
910 uint8_t lscsi_status;
911 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700912 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700913 uint8_t *rsp_info, *sense_data;
914
915 sts = (sts_entry_t *) pkt;
916 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700917 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700918 comp_status = le16_to_cpu(sts24->comp_status);
919 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
920 } else {
921 comp_status = le16_to_cpu(sts->comp_status);
922 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700926 if (comp_status == CS_COMPLETE && scsi_status == 0) {
927 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 return;
930 }
931
932 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700933 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
934 sp = ha->outstanding_cmds[sts->handle];
935 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 } else
937 sp = NULL;
938
939 if (sp == NULL) {
940 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
941 ha->host_no));
942 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
943
944 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100945 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 return;
947 }
948 cp = sp->cmd;
949 if (cp == NULL) {
950 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700951 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 qla_printk(KERN_WARNING, ha,
953 "Command is NULL: already returned to OS (sp=%p)\n", sp);
954
955 return;
956 }
957
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700958 lscsi_status = scsi_status & STATUS_MASK;
959 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 CMD_COMPL_STATUS(cp) = comp_status;
961 CMD_SCSI_STATUS(cp) = scsi_status;
962
bdf79622005-04-17 15:06:53 -0500963 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
Ravi Ananded17c71b52006-05-17 15:08:55 -0700965 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700966 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700967 sense_len = le32_to_cpu(sts24->sense_len);
968 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
969 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -0700970 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700971 rsp_info = sts24->data;
972 sense_data = sts24->data;
973 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
974 } else {
975 sense_len = le16_to_cpu(sts->req_sense_length);
976 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
977 resid_len = le32_to_cpu(sts->residual_length);
978 rsp_info = sts->rsp_info;
979 sense_data = sts->req_sense_data;
980 }
981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 /* Check for any FCP transport errors. */
983 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700984 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700985 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700986 sense_data += rsp_info_len;
987 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
989 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700990 "retrying command\n", ha->host_no,
991 cp->device->channel, cp->device->id,
992 cp->device->lun, rsp_info_len, rsp_info[0],
993 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
994 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
996 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500997 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 return;
999 }
1000 }
1001
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08001002 /* Check for overrun. */
1003 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1004 scsi_status & SS_RESIDUAL_OVER)
1005 comp_status = CS_DATA_OVERRUN;
1006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 /*
1008 * Based on Host and scsi status generate status code for Linux
1009 */
1010 switch (comp_status) {
1011 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001012 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 if (scsi_status == 0) {
1014 cp->result = DID_OK << 16;
1015 break;
1016 }
1017 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001018 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001019 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001021
1022 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001023 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001024 cp->underflow)) {
1025 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001026 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1027 "detected (%x of %x bytes)...returning "
1028 "error status.\n", ha->host_no,
1029 cp->device->channel, cp->device->id,
1030 cp->device->lun, resid,
1031 scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001032
1033 cp->result = DID_ERROR << 16;
1034 break;
1035 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 cp->result = DID_OK << 16 | lscsi_status;
1038
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001039 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1040 DEBUG2(printk(KERN_INFO
1041 "scsi(%ld): QUEUE FULL status detected "
1042 "0x%x-0x%x.\n", ha->host_no, comp_status,
1043 scsi_status));
1044
1045 /* Adjust queue depth for all luns on the port. */
1046 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001047 starget_for_each_device(cp->device->sdev_target,
1048 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001049 break;
1050 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (lscsi_status != SS_CHECK_CONDITION)
1052 break;
1053
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001054 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 if (!(scsi_status & SS_SENSE_LEN_VALID))
1056 break;
1057
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001058 qla2x00_handle_sense(sp, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 break;
1060
1061 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001062 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001063 /* Use F/W calculated residual length. */
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001064 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez2d136932008-09-11 21:22:52 -07001065 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1066 lscsi_status = 0;
1067 } else if (resid != fw_resid_len) {
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001068 scsi_status &= ~SS_RESIDUAL_UNDER;
1069 lscsi_status = 0;
1070 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001071 resid = fw_resid_len;
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001072 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001073
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 if (scsi_status & SS_RESIDUAL_UNDER) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001075 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001077 } else {
1078 DEBUG2(printk(KERN_INFO
1079 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -07001080 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1081 "os_underflow=0x%x\n", ha->host_no,
1082 cp->device->id, cp->device->lun, comp_status,
1083 scsi_status, resid_len, resid, cp->cmnd[0],
1084 cp->underflow));
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001085
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 }
1087
1088 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001089 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 * Status.
1091 */
1092 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 cp->result = DID_OK << 16 | lscsi_status;
1094
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001095 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1096 DEBUG2(printk(KERN_INFO
1097 "scsi(%ld): QUEUE FULL status detected "
1098 "0x%x-0x%x.\n", ha->host_no, comp_status,
1099 scsi_status));
1100
1101 /*
1102 * Adjust queue depth for all luns on the
1103 * port.
1104 */
1105 fcport->last_queue_full = jiffies;
1106 starget_for_each_device(
1107 cp->device->sdev_target, fcport,
1108 qla2x00_adjust_sdev_qdepth_down);
1109 break;
1110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 if (lscsi_status != SS_CHECK_CONDITION)
1112 break;
1113
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001114 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if (!(scsi_status & SS_SENSE_LEN_VALID))
1116 break;
1117
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001118 qla2x00_handle_sense(sp, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 } else {
1120 /*
1121 * If RISC reports underrun and target does not report
1122 * it then we must have a lost frame, so tell upper
1123 * layer to retry it by reporting a bus busy.
1124 */
1125 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1126 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001127 "frame(s) detected (%x of %x bytes)..."
1128 "retrying command.\n", ha->host_no,
1129 cp->device->channel, cp->device->id,
1130 cp->device->lun, resid,
1131 scsi_bufflen(cp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
1133 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 break;
1135 }
1136
1137 /* Handle mid-layer underflow */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001138 if ((unsigned)(scsi_bufflen(cp) - resid) <
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 cp->underflow) {
1140 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001141 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1142 "detected (%x of %x bytes)...returning "
1143 "error status.\n", ha->host_no,
1144 cp->device->channel, cp->device->id,
1145 cp->device->lun, resid,
1146 scsi_bufflen(cp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 cp->result = DID_ERROR << 16;
1149 break;
1150 }
1151
1152 /* Everybody online, looking good... */
1153 cp->result = DID_OK << 16;
1154 }
1155 break;
1156
1157 case CS_DATA_OVERRUN:
1158 DEBUG2(printk(KERN_INFO
1159 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001160 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1161 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 DEBUG2(printk(KERN_INFO
1163 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1164 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1165 cp->cmnd[4], cp->cmnd[5]));
1166 DEBUG2(printk(KERN_INFO
1167 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1168 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001169 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
1171 cp->result = DID_ERROR << 16;
1172 break;
1173
1174 case CS_PORT_LOGGED_OUT:
1175 case CS_PORT_CONFIG_CHG:
1176 case CS_PORT_BUSY:
1177 case CS_INCOMPLETE:
1178 case CS_PORT_UNAVAILABLE:
1179 /*
1180 * If the port is in Target Down state, return all IOs for this
1181 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1182 * retry_queue.
1183 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1185 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001186 ha->host_no, cp->device->id, cp->device->lun,
1187 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 atomic_read(&fcport->state)));
1189
f4f051e2005-04-17 15:02:26 -05001190 cp->result = DID_BUS_BUSY << 16;
Andrew Vasqueza7a28502008-08-13 21:36:57 -07001191 if (atomic_read(&fcport->state) == FCS_ONLINE)
1192 qla2x00_mark_device_lost(fcport->ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 break;
1194
1195 case CS_RESET:
1196 DEBUG2(printk(KERN_INFO
1197 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1198 ha->host_no, comp_status, scsi_status));
1199
f4f051e2005-04-17 15:02:26 -05001200 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 break;
1202
1203 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001204 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 * hv2.19.12 - DID_ABORT does not retry the request if we
1206 * aborted this request then abort otherwise it must be a
1207 * reset.
1208 */
1209 DEBUG2(printk(KERN_INFO
1210 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1211 ha->host_no, comp_status, scsi_status));
1212
1213 cp->result = DID_RESET << 16;
1214 break;
1215
1216 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 cp->result = DID_BUS_BUSY << 16;
1218
Andrew Vasqueze4289242007-07-19 15:05:56 -07001219 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001220 DEBUG2(printk(KERN_INFO
1221 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1222 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1223 cp->device->id, cp->device->lun, comp_status,
1224 scsi_status));
1225 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001227 DEBUG2(printk(KERN_INFO
1228 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1229 "sflags=%x.\n", ha->host_no, cp->device->channel,
1230 cp->device->id, cp->device->lun, comp_status, scsi_status,
1231 le16_to_cpu(sts->status_flags)));
1232
1233 /* Check to see if logout occurred. */
1234 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
Andrew Vasqueza7a28502008-08-13 21:36:57 -07001235 qla2x00_mark_device_lost(fcport->ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 break;
1237
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 default:
1239 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001240 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 qla_printk(KERN_INFO, ha,
1242 "Unknown status detected 0x%x-0x%x.\n",
1243 comp_status, scsi_status);
1244
1245 cp->result = DID_ERROR << 16;
1246 break;
1247 }
1248
1249 /* Place command on done queue. */
1250 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001251 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
1254/**
1255 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1256 * @ha: SCSI driver HA context
1257 * @pkt: Entry pointer
1258 *
1259 * Extended sense data.
1260 */
1261static void
1262qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1263{
1264 uint8_t sense_sz = 0;
1265 srb_t *sp = ha->status_srb;
1266 struct scsi_cmnd *cp;
1267
1268 if (sp != NULL && sp->request_sense_length != 0) {
1269 cp = sp->cmd;
1270 if (cp == NULL) {
1271 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001272 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 qla_printk(KERN_INFO, ha,
1274 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001275 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
1277 ha->status_srb = NULL;
1278 return;
1279 }
1280
1281 if (sp->request_sense_length > sizeof(pkt->data)) {
1282 sense_sz = sizeof(pkt->data);
1283 } else {
1284 sense_sz = sp->request_sense_length;
1285 }
1286
1287 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001288 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001289 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1291 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1292
1293 sp->request_sense_ptr += sense_sz;
1294 sp->request_sense_length -= sense_sz;
1295
1296 /* Place command on done queue. */
1297 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001299 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 }
1301 }
1302}
1303
1304/**
1305 * qla2x00_error_entry() - Process an error entry.
1306 * @ha: SCSI driver HA context
1307 * @pkt: Entry pointer
1308 */
1309static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001310qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311{
1312 srb_t *sp;
1313
1314#if defined(QL_DEBUG_LEVEL_2)
1315 if (pkt->entry_status & RF_INV_E_ORDER)
1316 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1317 else if (pkt->entry_status & RF_INV_E_COUNT)
1318 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1319 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001320 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 "%s: Invalid Entry Parameter\n", __func__);
1322 else if (pkt->entry_status & RF_INV_E_TYPE)
1323 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1324 else if (pkt->entry_status & RF_BUSY)
1325 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1326 else
1327 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1328#endif
1329
1330 /* Validate handle. */
1331 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1332 sp = ha->outstanding_cmds[pkt->handle];
1333 else
1334 sp = NULL;
1335
1336 if (sp) {
1337 /* Free outstanding command slot. */
1338 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001339
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 /* Bad payload or header */
1341 if (pkt->entry_status &
1342 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1343 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1344 sp->cmd->result = DID_ERROR << 16;
1345 } else if (pkt->entry_status & RF_BUSY) {
1346 sp->cmd->result = DID_BUS_BUSY << 16;
1347 } else {
1348 sp->cmd->result = DID_ERROR << 16;
1349 }
f4f051e2005-04-17 15:02:26 -05001350 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001352 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1353 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1355 ha->host_no));
1356 qla_printk(KERN_WARNING, ha,
1357 "Error entry - invalid handle\n");
1358
1359 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001360 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 }
1362}
1363
1364/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001365 * qla24xx_mbx_completion() - Process mailbox command completions.
1366 * @ha: SCSI driver HA context
1367 * @mb0: Mailbox0 register
1368 */
1369static void
1370qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1371{
1372 uint16_t cnt;
1373 uint16_t __iomem *wptr;
1374 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1375
1376 /* Load return mailbox registers. */
1377 ha->flags.mbox_int = 1;
1378 ha->mailbox_out[0] = mb0;
1379 wptr = (uint16_t __iomem *)&reg->mailbox1;
1380
1381 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1382 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1383 wptr++;
1384 }
1385
1386 if (ha->mcp) {
1387 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1388 __func__, ha->host_no, ha->mcp->mb[0]));
1389 } else {
1390 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1391 __func__, ha->host_no));
1392 }
1393}
1394
1395/**
1396 * qla24xx_process_response_queue() - Process response queue entries.
1397 * @ha: SCSI driver HA context
1398 */
1399void
1400qla24xx_process_response_queue(struct scsi_qla_host *ha)
1401{
1402 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1403 struct sts_entry_24xx *pkt;
1404
1405 if (!ha->flags.online)
1406 return;
1407
1408 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1409 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1410
1411 ha->rsp_ring_index++;
1412 if (ha->rsp_ring_index == ha->response_q_length) {
1413 ha->rsp_ring_index = 0;
1414 ha->response_ring_ptr = ha->response_ring;
1415 } else {
1416 ha->response_ring_ptr++;
1417 }
1418
1419 if (pkt->entry_status != 0) {
1420 DEBUG3(printk(KERN_INFO
1421 "scsi(%ld): Process error entry.\n", ha->host_no));
1422
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001423 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1424 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1425 wmb();
1426 continue;
1427 }
1428
1429 switch (pkt->entry_type) {
1430 case STATUS_TYPE:
1431 qla2x00_status_entry(ha, pkt);
1432 break;
1433 case STATUS_CONT_TYPE:
1434 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1435 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001436 case VP_RPT_ID_IOCB_TYPE:
1437 qla24xx_report_id_acquisition(ha,
1438 (struct vp_rpt_id_entry_24xx *)pkt);
1439 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001440 default:
1441 /* Type Not Supported. */
1442 DEBUG4(printk(KERN_WARNING
1443 "scsi(%ld): Received unknown response pkt type %x "
1444 "entry status=%x.\n",
1445 ha->host_no, pkt->entry_type, pkt->entry_status));
1446 break;
1447 }
1448 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1449 wmb();
1450 }
1451
1452 /* Adjust ring index */
1453 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1454}
1455
Andrew Vasquez05236a02007-09-20 14:07:37 -07001456static void
1457qla2xxx_check_risc_status(scsi_qla_host_t *ha)
1458{
1459 int rval;
1460 uint32_t cnt;
1461 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1462
1463 if (!IS_QLA25XX(ha))
1464 return;
1465
1466 rval = QLA_SUCCESS;
1467 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1468 RD_REG_DWORD(&reg->iobase_addr);
1469 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1470 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1471 rval == QLA_SUCCESS; cnt--) {
1472 if (cnt) {
1473 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1474 udelay(10);
1475 } else
1476 rval = QLA_FUNCTION_TIMEOUT;
1477 }
1478 if (rval == QLA_SUCCESS)
1479 goto next_test;
1480
1481 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1482 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1483 rval == QLA_SUCCESS; cnt--) {
1484 if (cnt) {
1485 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1486 udelay(10);
1487 } else
1488 rval = QLA_FUNCTION_TIMEOUT;
1489 }
1490 if (rval != QLA_SUCCESS)
1491 goto done;
1492
1493next_test:
1494 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1495 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1496
1497done:
1498 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1499 RD_REG_DWORD(&reg->iobase_window);
1500}
1501
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001502/**
1503 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1504 * @irq:
1505 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001506 *
1507 * Called by system whenever the host adapter generates an interrupt.
1508 *
1509 * Returns handled flag.
1510 */
1511irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001512qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001513{
1514 scsi_qla_host_t *ha;
1515 struct device_reg_24xx __iomem *reg;
1516 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001517 unsigned long iter;
1518 uint32_t stat;
1519 uint32_t hccr;
1520 uint16_t mb[4];
1521
1522 ha = (scsi_qla_host_t *) dev_id;
1523 if (!ha) {
1524 printk(KERN_INFO
1525 "%s(): NULL host pointer\n", __func__);
1526 return IRQ_NONE;
1527 }
1528
1529 reg = &ha->iobase->isp24;
1530 status = 0;
1531
Andrew Vasquezc6952482008-04-03 13:13:17 -07001532 spin_lock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001533 for (iter = 50; iter--; ) {
1534 stat = RD_REG_DWORD(&reg->host_status);
1535 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001536 if (pci_channel_offline(ha->pdev))
1537 break;
1538
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001539 if (ha->hw_event_pause_errors == 0)
1540 qla2x00_post_hwe_work(ha, HW_EVENT_PARITY_ERR,
1541 0, MSW(stat), LSW(stat));
1542 else if (ha->hw_event_pause_errors < 0xffffffff)
1543 ha->hw_event_pause_errors++;
1544
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001545 hccr = RD_REG_DWORD(&reg->hccr);
1546
1547 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1548 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001549
1550 qla2xxx_check_risc_status(ha);
1551
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001552 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001553 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1554 break;
1555 } else if ((stat & HSRX_RISC_INT) == 0)
1556 break;
1557
1558 switch (stat & 0xff) {
1559 case 0x1:
1560 case 0x2:
1561 case 0x10:
1562 case 0x11:
1563 qla24xx_mbx_completion(ha, MSW(stat));
1564 status |= MBX_INTERRUPT;
1565
1566 break;
1567 case 0x12:
1568 mb[0] = MSW(stat);
1569 mb[1] = RD_REG_WORD(&reg->mailbox1);
1570 mb[2] = RD_REG_WORD(&reg->mailbox2);
1571 mb[3] = RD_REG_WORD(&reg->mailbox3);
1572 qla2x00_async_event(ha, mb);
1573 break;
1574 case 0x13:
1575 qla24xx_process_response_queue(ha);
1576 break;
1577 default:
1578 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1579 "(%d).\n",
1580 ha->host_no, stat & 0xff));
1581 break;
1582 }
1583 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1584 RD_REG_DWORD_RELAXED(&reg->hccr);
1585 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001586 spin_unlock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001587
1588 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1589 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001590 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001591 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001592 }
1593
1594 return IRQ_HANDLED;
1595}
1596
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001597static irqreturn_t
1598qla24xx_msix_rsp_q(int irq, void *dev_id)
1599{
1600 scsi_qla_host_t *ha;
1601 struct device_reg_24xx __iomem *reg;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001602
1603 ha = dev_id;
1604 reg = &ha->iobase->isp24;
1605
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001606 spin_lock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001607
1608 qla24xx_process_response_queue(ha);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001609 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001610
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001611 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001612
1613 return IRQ_HANDLED;
1614}
1615
1616static irqreturn_t
1617qla24xx_msix_default(int irq, void *dev_id)
1618{
1619 scsi_qla_host_t *ha;
1620 struct device_reg_24xx __iomem *reg;
1621 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001622 uint32_t stat;
1623 uint32_t hccr;
1624 uint16_t mb[4];
1625
1626 ha = dev_id;
1627 reg = &ha->iobase->isp24;
1628 status = 0;
1629
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001630 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001631 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001632 stat = RD_REG_DWORD(&reg->host_status);
1633 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001634 if (pci_channel_offline(ha->pdev))
1635 break;
1636
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001637 if (ha->hw_event_pause_errors == 0)
1638 qla2x00_post_hwe_work(ha, HW_EVENT_PARITY_ERR,
1639 0, MSW(stat), LSW(stat));
1640 else if (ha->hw_event_pause_errors < 0xffffffff)
1641 ha->hw_event_pause_errors++;
1642
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001643 hccr = RD_REG_DWORD(&reg->hccr);
1644
1645 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1646 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001647
1648 qla2xxx_check_risc_status(ha);
1649
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001650 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001651 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1652 break;
1653 } else if ((stat & HSRX_RISC_INT) == 0)
1654 break;
1655
1656 switch (stat & 0xff) {
1657 case 0x1:
1658 case 0x2:
1659 case 0x10:
1660 case 0x11:
1661 qla24xx_mbx_completion(ha, MSW(stat));
1662 status |= MBX_INTERRUPT;
1663
1664 break;
1665 case 0x12:
1666 mb[0] = MSW(stat);
1667 mb[1] = RD_REG_WORD(&reg->mailbox1);
1668 mb[2] = RD_REG_WORD(&reg->mailbox2);
1669 mb[3] = RD_REG_WORD(&reg->mailbox3);
1670 qla2x00_async_event(ha, mb);
1671 break;
1672 case 0x13:
1673 qla24xx_process_response_queue(ha);
1674 break;
1675 default:
1676 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1677 "(%d).\n",
1678 ha->host_no, stat & 0xff));
1679 break;
1680 }
1681 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001682 } while (0);
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001683 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001684
1685 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1686 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001687 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001688 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001689 }
1690
1691 return IRQ_HANDLED;
1692}
1693
1694/* Interrupt handling helpers. */
1695
1696struct qla_init_msix_entry {
1697 uint16_t entry;
1698 uint16_t index;
1699 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001700 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001701};
1702
1703static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1704 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1705 "qla2xxx (default)", qla24xx_msix_default },
1706
1707 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1708 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1709};
1710
1711static void
1712qla24xx_disable_msix(scsi_qla_host_t *ha)
1713{
1714 int i;
1715 struct qla_msix_entry *qentry;
1716
1717 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1718 qentry = &ha->msix_entries[imsix_entries[i].index];
1719 if (qentry->have_irq)
1720 free_irq(qentry->msix_vector, ha);
1721 }
1722 pci_disable_msix(ha->pdev);
1723}
1724
1725static int
1726qla24xx_enable_msix(scsi_qla_host_t *ha)
1727{
1728 int i, ret;
1729 struct msix_entry entries[QLA_MSIX_ENTRIES];
1730 struct qla_msix_entry *qentry;
1731
1732 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1733 entries[i].entry = imsix_entries[i].entry;
1734
1735 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1736 if (ret) {
1737 qla_printk(KERN_WARNING, ha,
1738 "MSI-X: Failed to enable support -- %d/%d\n",
1739 QLA_MSIX_ENTRIES, ret);
1740 goto msix_out;
1741 }
1742 ha->flags.msix_enabled = 1;
1743
1744 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1745 qentry = &ha->msix_entries[imsix_entries[i].index];
1746 qentry->msix_vector = entries[i].vector;
1747 qentry->msix_entry = entries[i].entry;
1748 qentry->have_irq = 0;
1749 ret = request_irq(qentry->msix_vector,
1750 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1751 if (ret) {
1752 qla_printk(KERN_WARNING, ha,
1753 "MSI-X: Unable to register handler -- %x/%d.\n",
1754 imsix_entries[i].index, ret);
1755 qla24xx_disable_msix(ha);
1756 goto msix_out;
1757 }
1758 qentry->have_irq = 1;
1759 }
1760
1761msix_out:
1762 return ret;
1763}
1764
1765int
1766qla2x00_request_irqs(scsi_qla_host_t *ha)
1767{
1768 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001769 device_reg_t __iomem *reg = ha->iobase;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001770
1771 /* If possible, enable MSI-X. */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001772 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001773 goto skip_msix;
1774
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001775 if (IS_QLA2432(ha) && (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1776 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001777 DEBUG2(qla_printk(KERN_WARNING, ha,
1778 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1779 ha->chip_revision, ha->fw_attributes));
1780
1781 goto skip_msix;
1782 }
1783
Andrew Vasquezda7429f2008-01-17 09:02:11 -08001784 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1785 (ha->pdev->subsystem_device == 0x7040 ||
1786 ha->pdev->subsystem_device == 0x7041 ||
1787 ha->pdev->subsystem_device == 0x1705)) {
1788 DEBUG2(qla_printk(KERN_WARNING, ha,
1789 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1790 ha->pdev->subsystem_vendor,
1791 ha->pdev->subsystem_device));
1792
1793 goto skip_msi;
1794 }
1795
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001796 ret = qla24xx_enable_msix(ha);
1797 if (!ret) {
1798 DEBUG2(qla_printk(KERN_INFO, ha,
1799 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1800 ha->fw_attributes));
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001801 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001802 }
1803 qla_printk(KERN_WARNING, ha,
1804 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1805skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001806
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001807 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001808 goto skip_msi;
1809
1810 ret = pci_enable_msi(ha->pdev);
1811 if (!ret) {
1812 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1813 ha->flags.msi_enabled = 1;
1814 }
1815skip_msi:
1816
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001817 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001818 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001819 if (ret) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001820 qla_printk(KERN_WARNING, ha,
1821 "Failed to reserve interrupt %d already in use.\n",
1822 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001823 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001824 }
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001825 ha->flags.inta_enabled = 1;
1826 ha->host->irq = ha->pdev->irq;
1827clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001828
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001829 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezc6952482008-04-03 13:13:17 -07001830 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001831 if (IS_FWI2_CAPABLE(ha)) {
1832 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1833 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1834 } else {
1835 WRT_REG_WORD(&reg->isp.semaphore, 0);
1836 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1837 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
1838 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001839 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001840
1841fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001842 return ret;
1843}
1844
1845void
1846qla2x00_free_irqs(scsi_qla_host_t *ha)
1847{
1848
1849 if (ha->flags.msix_enabled)
1850 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001851 else if (ha->flags.inta_enabled) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001852 free_irq(ha->host->irq, ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001853 pci_disable_msi(ha->pdev);
1854 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001855}