blob: 1104bd2eed405a0ce3432c702d8bdc804ad7edcc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 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 *);
17static void qla2x00_ms_entry(scsi_qla_host_t *, ms_iocb_entry_t *);
18
Andrew Vasquez9a853f72005-07-06 10:31:27 -070019static void qla24xx_ms_entry(scsi_qla_host_t *, struct ct_entry_24xx *);
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021/**
22 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
23 * @irq:
24 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 *
26 * Called by system whenever the host adapter generates an interrupt.
27 *
28 * Returns handled flag.
29 */
30irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010031qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
33 scsi_qla_host_t *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070034 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 int status;
36 unsigned long flags;
37 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070038 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070039 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41 ha = (scsi_qla_host_t *) dev_id;
42 if (!ha) {
43 printk(KERN_INFO
44 "%s(): NULL host pointer\n", __func__);
45 return (IRQ_NONE);
46 }
47
Andrew Vasquez3d716442005-07-06 10:30:26 -070048 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 status = 0;
50
51 spin_lock_irqsave(&ha->hardware_lock, flags);
52 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070053 hccr = RD_REG_WORD(&reg->hccr);
54 if (hccr & HCCR_RISC_PAUSE) {
55 if (pci_channel_offline(ha->pdev))
56 break;
57
58 /*
59 * Issue a "HARD" reset in order for the RISC interrupt
60 * bit to be cleared. Schedule a big hammmer to get
61 * out of the RISC PAUSED state.
62 */
63 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
64 RD_REG_WORD(&reg->hccr);
65
66 ha->isp_ops->fw_dump(ha, 1);
67 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
68 break;
69 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 break;
71
72 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
73 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
74 RD_REG_WORD(&reg->hccr);
75
76 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070077 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
78 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
79 qla2x00_mbx_completion(ha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070081 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
82 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
83 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
84 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
85 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 } else {
87 /*EMPTY*/
88 DEBUG2(printk("scsi(%ld): Unrecognized "
Andrew Vasquez9a853f72005-07-06 10:31:27 -070089 "interrupt type (%d).\n",
90 ha->host_no, mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 }
92 /* Release mailbox registers. */
93 WRT_REG_WORD(&reg->semaphore, 0);
94 RD_REG_WORD(&reg->semaphore);
95 } else {
96 qla2x00_process_response_queue(ha);
97
98 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
99 RD_REG_WORD(&reg->hccr);
100 }
101 }
102 spin_unlock_irqrestore(&ha->hardware_lock, flags);
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
105 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
107 up(&ha->mbx_intr_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 }
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return (IRQ_HANDLED);
111}
112
113/**
114 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
115 * @irq:
116 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 *
118 * Called by system whenever the host adapter generates an interrupt.
119 *
120 * Returns handled flag.
121 */
122irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100123qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 scsi_qla_host_t *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700126 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 int status;
128 unsigned long flags;
129 unsigned long iter;
130 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700132 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 ha = (scsi_qla_host_t *) dev_id;
135 if (!ha) {
136 printk(KERN_INFO
137 "%s(): NULL host pointer\n", __func__);
138 return (IRQ_NONE);
139 }
140
Andrew Vasquez3d716442005-07-06 10:30:26 -0700141 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 status = 0;
143
144 spin_lock_irqsave(&ha->hardware_lock, flags);
145 for (iter = 50; iter--; ) {
146 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
147 if (stat & HSR_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700148 if (pci_channel_offline(ha->pdev))
149 break;
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 hccr = RD_REG_WORD(&reg->hccr);
152 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Andrew Vasquez07f31802006-12-13 19:20:31 -0800153 qla_printk(KERN_INFO, ha, "Parity error -- "
154 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 else
Andrew Vasquez07f31802006-12-13 19:20:31 -0800156 qla_printk(KERN_INFO, ha, "RISC paused -- "
157 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 /*
160 * Issue a "HARD" reset in order for the RISC
161 * interrupt bit to be cleared. Schedule a big
162 * hammmer to get out of the RISC PAUSED state.
163 */
164 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
165 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800166
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700167 ha->isp_ops->fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
169 break;
170 } else if ((stat & HSR_RISC_INT) == 0)
171 break;
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 case 0x1:
175 case 0x2:
176 case 0x10:
177 case 0x11:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700178 qla2x00_mbx_completion(ha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 status |= MBX_INTERRUPT;
180
181 /* Release mailbox registers. */
182 WRT_REG_WORD(&reg->semaphore, 0);
183 break;
184 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700185 mb[0] = MSW(stat);
186 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
187 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
188 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
189 qla2x00_async_event(ha, mb);
190 break;
191 case 0x13:
192 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 break;
194 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700195 mb[0] = MBA_CMPLT_1_16BIT;
196 mb[1] = MSW(stat);
197 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 break;
199 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700200 mb[0] = MBA_SCSI_COMPLETION;
201 mb[1] = MSW(stat);
202 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
203 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 break;
205 default:
206 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700207 "(%d).\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 ha->host_no, stat & 0xff));
209 break;
210 }
211 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
212 RD_REG_WORD_RELAXED(&reg->hccr);
213 }
214 spin_unlock_irqrestore(&ha->hardware_lock, flags);
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
217 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
219 up(&ha->mbx_intr_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 }
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 return (IRQ_HANDLED);
223}
224
225/**
226 * qla2x00_mbx_completion() - Process mailbox command completions.
227 * @ha: SCSI driver HA context
228 * @mb0: Mailbox0 register
229 */
230static void
231qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
232{
233 uint16_t cnt;
234 uint16_t __iomem *wptr;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700235 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 /* Load return mailbox registers. */
238 ha->flags.mbox_int = 1;
239 ha->mailbox_out[0] = mb0;
240 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
241
242 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700243 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
245 if (cnt == 4 || cnt == 5)
246 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
247 else
248 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 wptr++;
251 }
252
253 if (ha->mcp) {
254 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
255 __func__, ha->host_no, ha->mcp->mb[0]));
256 } else {
257 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
258 __func__, ha->host_no));
259 }
260}
261
262/**
263 * qla2x00_async_event() - Process aynchronous events.
264 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700265 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700267void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700268qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700270#define LS_UNKNOWN 2
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700271 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 uint16_t handle_cnt;
274 uint16_t cnt;
275 uint32_t handles[5];
Andrew Vasquez3d716442005-07-06 10:30:26 -0700276 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 uint32_t rscn_entry, host_pid;
278 uint8_t rscn_queue_index;
279
280 /* Setup to process RIO completion. */
281 handle_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 switch (mb[0]) {
283 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700284 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 handle_cnt = 1;
286 break;
287 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700288 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 handle_cnt = 1;
290 mb[0] = MBA_SCSI_COMPLETION;
291 break;
292 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700293 handles[0] = mb[1];
294 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 handle_cnt = 2;
296 mb[0] = MBA_SCSI_COMPLETION;
297 break;
298 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700299 handles[0] = mb[1];
300 handles[1] = mb[2];
301 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 handle_cnt = 3;
303 mb[0] = MBA_SCSI_COMPLETION;
304 break;
305 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700306 handles[0] = mb[1];
307 handles[1] = mb[2];
308 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
310 handle_cnt = 4;
311 mb[0] = MBA_SCSI_COMPLETION;
312 break;
313 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700314 handles[0] = mb[1];
315 handles[1] = mb[2];
316 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
318 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
319 handle_cnt = 5;
320 mb[0] = MBA_SCSI_COMPLETION;
321 break;
322 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700323 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 handles[1] = le32_to_cpu(
325 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
326 RD_MAILBOX_REG(ha, reg, 6));
327 handle_cnt = 2;
328 mb[0] = MBA_SCSI_COMPLETION;
329 break;
330 default:
331 break;
332 }
333
334 switch (mb[0]) {
335 case MBA_SCSI_COMPLETION: /* Fast Post */
336 if (!ha->flags.online)
337 break;
338
339 for (cnt = 0; cnt < handle_cnt; cnt++)
340 qla2x00_process_completed_request(ha, handles[cnt]);
341 break;
342
343 case MBA_RESET: /* Reset */
344 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
345
346 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
347 break;
348
349 case MBA_SYSTEM_ERR: /* System Error */
350 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
351 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
352 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
353
354 qla_printk(KERN_INFO, ha,
355 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
356 mb[1], mb[2], mb[3]);
357
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700358 ha->isp_ops->fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Andrew Vasqueze4289242007-07-19 15:05:56 -0700360 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700361 if (mb[1] == 0 && mb[2] == 0) {
362 qla_printk(KERN_ERR, ha,
363 "Unrecoverable Hardware Error: adapter "
364 "marked OFFLINE!\n");
365 ha->flags.online = 0;
366 } else
367 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
368 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 qla_printk(KERN_INFO, ha,
370 "Unrecoverable Hardware Error: adapter marked "
371 "OFFLINE!\n");
372 ha->flags.online = 0;
373 } else
374 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
375 break;
376
377 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
378 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
379 ha->host_no));
380 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
381
382 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
383 break;
384
385 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
386 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
387 ha->host_no));
388 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
389
390 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
391 break;
392
393 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
394 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
395 ha->host_no));
396 break;
397
398 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
400 mb[1]));
401 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
402
403 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
404 atomic_set(&ha->loop_state, LOOP_DOWN);
405 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800406 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 }
408
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700409 if (ha->parent) {
410 atomic_set(&ha->vp_state, VP_FAILED);
411 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
412 }
413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
415
416 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 break;
418
419 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
421 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700422 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700424 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 if (mb[1] < 5)
426 link_speed = link_speeds[mb[1]];
427 ha->link_data_rate = mb[1];
428 }
429
430 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
431 ha->host_no, link_speed));
432 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
433 link_speed);
434
435 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 break;
437
438 case MBA_LOOP_DOWN: /* Loop Down Event */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700439 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
440 ha->host_no, mb[1]));
441 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
444 atomic_set(&ha->loop_state, LOOP_DOWN);
445 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
446 ha->device_flags |= DFLG_NO_CABLE;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800447 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 }
449
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700450 if (ha->parent) {
451 atomic_set(&ha->vp_state, VP_FAILED);
452 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
453 }
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 ha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700456 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Andrew Vasquezcca53352005-08-26 19:08:30 -0700457 if (ql2xfdmienable)
458 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 break;
483
484 case MBA_POINT_TO_POINT: /* Point-to-Point */
485 if (IS_QLA2100(ha))
486 break;
487
488 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
489 ha->host_no));
490
491 /*
492 * Until there's a transition from loop down to loop up, treat
493 * this as loop down only.
494 */
495 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
496 atomic_set(&ha->loop_state, LOOP_DOWN);
497 if (!atomic_read(&ha->loop_down_timer))
498 atomic_set(&ha->loop_down_timer,
499 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800500 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700503 if (ha->parent) {
504 atomic_set(&ha->vp_state, VP_FAILED);
505 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
506 }
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
509 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
510 }
511 set_bit(REGISTER_FC4_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 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
547 * 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 Ju2c3dfe32007-07-05 13:16:51 -0700579 /* Check if the Vport has issued a SCR */
580 if (ha->parent && test_bit(VP_SCR_NEEDED, &ha->vp_flags))
581 break;
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
584 ha->host_no));
585 DEBUG(printk(KERN_INFO
586 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
587 ha->host_no, mb[1], mb[2]));
588
589 rscn_entry = (mb[1] << 16) | mb[2];
590 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
591 ha->d_id.b.al_pa;
592 if (rscn_entry == host_pid) {
593 DEBUG(printk(KERN_INFO
594 "scsi(%ld): Ignoring RSCN update to local host "
595 "port ID (%06x)\n",
596 ha->host_no, host_pid));
597 break;
598 }
599
600 rscn_queue_index = ha->rscn_in_ptr + 1;
601 if (rscn_queue_index == MAX_RSCN_COUNT)
602 rscn_queue_index = 0;
603 if (rscn_queue_index != ha->rscn_out_ptr) {
604 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
605 ha->rscn_in_ptr = rscn_queue_index;
606 } else {
607 ha->flags.rscn_queue_overflow = 1;
608 }
609
610 atomic_set(&ha->loop_state, LOOP_UPDATE);
611 atomic_set(&ha->loop_down_timer, 0);
612 ha->flags.management_server_logged_in = 0;
613
614 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
615 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 break;
617
618 /* case MBA_RIO_RESPONSE: */
619 case MBA_ZIO_RESPONSE:
620 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
621 ha->host_no));
622 DEBUG(printk(KERN_INFO
623 "scsi(%ld): [R|Z]IO update completion.\n",
624 ha->host_no));
625
Andrew Vasqueze4289242007-07-19 15:05:56 -0700626 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700627 qla24xx_process_response_queue(ha);
628 else
629 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700631
632 case MBA_DISCARD_RND_FRAME:
633 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
634 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
635 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700636
637 case MBA_TRACE_NOTIFICATION:
638 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
639 ha->host_no, mb[1], mb[2]));
640 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700642
643 if (!ha->parent && ha->num_vhosts)
644 qla2x00_alert_all_vps(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645}
646
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700647static void
648qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
649{
650 fc_port_t *fcport = data;
651
652 if (fcport->ha->max_q_depth <= sdev->queue_depth)
653 return;
654
655 if (sdev->ordered_tags)
656 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
657 sdev->queue_depth + 1);
658 else
659 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
660 sdev->queue_depth + 1);
661
662 fcport->last_ramp_up = jiffies;
663
664 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
665 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
666 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
667 sdev->queue_depth));
668}
669
670static void
671qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
672{
673 fc_port_t *fcport = data;
674
675 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
676 return;
677
678 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
679 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
680 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
681 sdev->queue_depth));
682}
683
684static inline void
685qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
686{
687 fc_port_t *fcport;
688 struct scsi_device *sdev;
689
690 sdev = sp->cmd->device;
691 if (sdev->queue_depth >= ha->max_q_depth)
692 return;
693
694 fcport = sp->fcport;
695 if (time_before(jiffies,
696 fcport->last_ramp_up + ql2xqfullrampup * HZ))
697 return;
698 if (time_before(jiffies,
699 fcport->last_queue_full + ql2xqfullrampup * HZ))
700 return;
701
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700702 starget_for_each_device(sdev->sdev_target, fcport,
703 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700704}
705
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706/**
707 * qla2x00_process_completed_request() - Process a Fast Post response.
708 * @ha: SCSI driver HA context
709 * @index: SRB index
710 */
711static void
712qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
713{
714 srb_t *sp;
715
716 /* Validate handle. */
717 if (index >= MAX_OUTSTANDING_COMMANDS) {
718 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
719 ha->host_no, index));
720 qla_printk(KERN_WARNING, ha,
721 "Invalid SCSI completion handle %d.\n", index);
722
723 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
724 return;
725 }
726
727 sp = ha->outstanding_cmds[index];
728 if (sp) {
729 /* Free outstanding command slot. */
730 ha->outstanding_cmds[index] = NULL;
731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 CMD_COMPL_STATUS(sp->cmd) = 0L;
733 CMD_SCSI_STATUS(sp->cmd) = 0L;
734
735 /* Save ISP completion status */
736 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700737
738 qla2x00_ramp_up_queue_depth(ha, sp);
f4f051e2005-04-17 15:02:26 -0500739 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 } else {
741 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
742 ha->host_no));
743 qla_printk(KERN_WARNING, ha,
744 "Invalid ISP SCSI completion handle\n");
745
746 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
747 }
748}
749
750/**
751 * qla2x00_process_response_queue() - Process response queue entries.
752 * @ha: SCSI driver HA context
753 */
754void
755qla2x00_process_response_queue(struct scsi_qla_host *ha)
756{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700757 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 sts_entry_t *pkt;
759 uint16_t handle_cnt;
760 uint16_t cnt;
761
762 if (!ha->flags.online)
763 return;
764
765 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
766 pkt = (sts_entry_t *)ha->response_ring_ptr;
767
768 ha->rsp_ring_index++;
769 if (ha->rsp_ring_index == ha->response_q_length) {
770 ha->rsp_ring_index = 0;
771 ha->response_ring_ptr = ha->response_ring;
772 } else {
773 ha->response_ring_ptr++;
774 }
775
776 if (pkt->entry_status != 0) {
777 DEBUG3(printk(KERN_INFO
778 "scsi(%ld): Process error entry.\n", ha->host_no));
779
780 qla2x00_error_entry(ha, pkt);
781 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
782 wmb();
783 continue;
784 }
785
786 switch (pkt->entry_type) {
787 case STATUS_TYPE:
788 qla2x00_status_entry(ha, pkt);
789 break;
790 case STATUS_TYPE_21:
791 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
792 for (cnt = 0; cnt < handle_cnt; cnt++) {
793 qla2x00_process_completed_request(ha,
794 ((sts21_entry_t *)pkt)->handle[cnt]);
795 }
796 break;
797 case STATUS_TYPE_22:
798 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
799 for (cnt = 0; cnt < handle_cnt; cnt++) {
800 qla2x00_process_completed_request(ha,
801 ((sts22_entry_t *)pkt)->handle[cnt]);
802 }
803 break;
804 case STATUS_CONT_TYPE:
805 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
806 break;
807 case MS_IOCB_TYPE:
808 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
809 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 default:
811 /* Type Not Supported. */
812 DEBUG4(printk(KERN_WARNING
813 "scsi(%ld): Received unknown response pkt type %x "
814 "entry status=%x.\n",
815 ha->host_no, pkt->entry_type, pkt->entry_status));
816 break;
817 }
818 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
819 wmb();
820 }
821
822 /* Adjust ring index */
823 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
824}
825
826/**
827 * qla2x00_status_entry() - Process a Status IOCB entry.
828 * @ha: SCSI driver HA context
829 * @pkt: Entry pointer
830 */
831static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700832qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 fc_port_t *fcport;
836 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700837 sts_entry_t *sts;
838 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 uint16_t comp_status;
840 uint16_t scsi_status;
841 uint8_t lscsi_status;
842 int32_t resid;
Ravi Ananded17c712006-05-17 15:08:55 -0700843 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700844 uint8_t *rsp_info, *sense_data;
845
846 sts = (sts_entry_t *) pkt;
847 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700848 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700849 comp_status = le16_to_cpu(sts24->comp_status);
850 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
851 } else {
852 comp_status = le16_to_cpu(sts->comp_status);
853 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
856 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700857 if (comp_status == CS_COMPLETE && scsi_status == 0) {
858 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 return;
861 }
862
863 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700864 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
865 sp = ha->outstanding_cmds[sts->handle];
866 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 } else
868 sp = NULL;
869
870 if (sp == NULL) {
871 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
872 ha->host_no));
873 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
874
875 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100876 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 return;
878 }
879 cp = sp->cmd;
880 if (cp == NULL) {
881 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700882 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 qla_printk(KERN_WARNING, ha,
884 "Command is NULL: already returned to OS (sp=%p)\n", sp);
885
886 return;
887 }
888
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700889 lscsi_status = scsi_status & STATUS_MASK;
890 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 CMD_COMPL_STATUS(cp) = comp_status;
892 CMD_SCSI_STATUS(cp) = scsi_status;
893
bdf79622005-04-17 15:06:53 -0500894 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Ravi Ananded17c712006-05-17 15:08:55 -0700896 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700897 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700898 sense_len = le32_to_cpu(sts24->sense_len);
899 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
900 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c712006-05-17 15:08:55 -0700901 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700902 rsp_info = sts24->data;
903 sense_data = sts24->data;
904 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
905 } else {
906 sense_len = le16_to_cpu(sts->req_sense_length);
907 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
908 resid_len = le32_to_cpu(sts->residual_length);
909 rsp_info = sts->rsp_info;
910 sense_data = sts->req_sense_data;
911 }
912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 /* Check for any FCP transport errors. */
914 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700915 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700916 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700917 sense_data += rsp_info_len;
918 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
920 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700921 "retrying command\n", ha->host_no,
922 cp->device->channel, cp->device->id,
923 cp->device->lun, rsp_info_len, rsp_info[0],
924 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
925 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500928 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 return;
930 }
931 }
932
933 /*
934 * Based on Host and scsi status generate status code for Linux
935 */
936 switch (comp_status) {
937 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700938 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 if (scsi_status == 0) {
940 cp->result = DID_OK << 16;
941 break;
942 }
943 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700944 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900945 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800947
948 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900949 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800950 cp->underflow)) {
951 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900952 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
953 "detected (%x of %x bytes)...returning "
954 "error status.\n", ha->host_no,
955 cp->device->channel, cp->device->id,
956 cp->device->lun, resid,
957 scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800958
959 cp->result = DID_ERROR << 16;
960 break;
961 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 cp->result = DID_OK << 16 | lscsi_status;
964
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700965 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
966 DEBUG2(printk(KERN_INFO
967 "scsi(%ld): QUEUE FULL status detected "
968 "0x%x-0x%x.\n", ha->host_no, comp_status,
969 scsi_status));
970
971 /* Adjust queue depth for all luns on the port. */
972 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700973 starget_for_each_device(cp->device->sdev_target,
974 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700975 break;
976 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 if (lscsi_status != SS_CHECK_CONDITION)
978 break;
979
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700980 /* Copy Sense Data into sense buffer. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
982
983 if (!(scsi_status & SS_SENSE_LEN_VALID))
984 break;
985
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700986 if (sense_len >= sizeof(cp->sense_buffer))
987 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700989 CMD_ACTUAL_SNSLEN(cp) = sense_len;
990 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 sp->request_sense_ptr = cp->sense_buffer;
992
993 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700994 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700996 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700998 sp->request_sense_ptr += sense_len;
999 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (sp->request_sense_length != 0)
1001 ha->status_srb = sp;
1002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 DEBUG5(printk("%s(): Check condition Sense data, "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001004 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__,
1005 ha->host_no, cp->device->channel, cp->device->id,
1006 cp->device->lun, cp, cp->serial_number));
1007 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1009 CMD_ACTUAL_SNSLEN(cp)));
1010 break;
1011
1012 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001013 resid = resid_len;
Ravi Ananded17c712006-05-17 15:08:55 -07001014 /* Use F/W calculated residual length. */
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001015 if (IS_FWI2_CAPABLE(ha)) {
1016 if (scsi_status & SS_RESIDUAL_UNDER &&
1017 resid != fw_resid_len) {
1018 scsi_status &= ~SS_RESIDUAL_UNDER;
1019 lscsi_status = 0;
1020 }
Ravi Ananded17c712006-05-17 15:08:55 -07001021 resid = fw_resid_len;
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001022 }
Ravi Ananded17c712006-05-17 15:08:55 -07001023
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (scsi_status & SS_RESIDUAL_UNDER) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001025 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001027 } else {
1028 DEBUG2(printk(KERN_INFO
1029 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c712006-05-17 15:08:55 -07001030 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1031 "os_underflow=0x%x\n", ha->host_no,
1032 cp->device->id, cp->device->lun, comp_status,
1033 scsi_status, resid_len, resid, cp->cmnd[0],
1034 cp->underflow));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001035
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
1037
1038 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001039 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 * Status.
1041 */
1042 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 cp->result = DID_OK << 16 | lscsi_status;
1044
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001045 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1046 DEBUG2(printk(KERN_INFO
1047 "scsi(%ld): QUEUE FULL status detected "
1048 "0x%x-0x%x.\n", ha->host_no, comp_status,
1049 scsi_status));
1050
1051 /*
1052 * Adjust queue depth for all luns on the
1053 * port.
1054 */
1055 fcport->last_queue_full = jiffies;
1056 starget_for_each_device(
1057 cp->device->sdev_target, fcport,
1058 qla2x00_adjust_sdev_qdepth_down);
1059 break;
1060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 if (lscsi_status != SS_CHECK_CONDITION)
1062 break;
1063
1064 /* Copy Sense Data into sense buffer */
1065 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
1066
1067 if (!(scsi_status & SS_SENSE_LEN_VALID))
1068 break;
1069
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001070 if (sense_len >= sizeof(cp->sense_buffer))
1071 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001073 CMD_ACTUAL_SNSLEN(cp) = sense_len;
1074 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 sp->request_sense_ptr = cp->sense_buffer;
1076
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001077 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001078 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001080 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001082 sp->request_sense_ptr += sense_len;
1083 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 if (sp->request_sense_length != 0)
1085 ha->status_srb = sp;
1086
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 DEBUG5(printk("%s(): Check condition Sense data, "
1088 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001089 __func__, ha->host_no, cp->device->channel,
1090 cp->device->id, cp->device->lun, cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 cp->serial_number));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001092
Shyam Sundar8084fe12007-07-19 15:05:59 -07001093 /*
1094 * In case of a Underrun condition, set both the lscsi
1095 * status and the completion status to appropriate
1096 * values.
1097 */
1098 if (resid &&
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001099 ((unsigned)(scsi_bufflen(cp) - resid) <
Shyam Sundar8084fe12007-07-19 15:05:59 -07001100 cp->underflow)) {
1101 DEBUG2(qla_printk(KERN_INFO, ha,
1102 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1103 "detected (%x of %x bytes)...returning "
1104 "error status.\n", ha->host_no,
1105 cp->device->channel, cp->device->id,
1106 cp->device->lun, resid,
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001107 scsi_bufflen(cp)));
Shyam Sundar8084fe12007-07-19 15:05:59 -07001108
1109 cp->result = DID_ERROR << 16 | lscsi_status;
1110 }
1111
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001112 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1114 CMD_ACTUAL_SNSLEN(cp)));
1115 } else {
1116 /*
1117 * If RISC reports underrun and target does not report
1118 * it then we must have a lost frame, so tell upper
1119 * layer to retry it by reporting a bus busy.
1120 */
1121 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1122 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001123 "frame(s) detected (%x of %x bytes)..."
1124 "retrying command.\n", ha->host_no,
1125 cp->device->channel, cp->device->id,
1126 cp->device->lun, resid,
1127 scsi_bufflen(cp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
1129 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 break;
1131 }
1132
1133 /* Handle mid-layer underflow */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001134 if ((unsigned)(scsi_bufflen(cp) - resid) <
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 cp->underflow) {
1136 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001137 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1138 "detected (%x of %x bytes)...returning "
1139 "error status.\n", ha->host_no,
1140 cp->device->channel, cp->device->id,
1141 cp->device->lun, resid,
1142 scsi_bufflen(cp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 cp->result = DID_ERROR << 16;
1145 break;
1146 }
1147
1148 /* Everybody online, looking good... */
1149 cp->result = DID_OK << 16;
1150 }
1151 break;
1152
1153 case CS_DATA_OVERRUN:
1154 DEBUG2(printk(KERN_INFO
1155 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001156 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1157 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 DEBUG2(printk(KERN_INFO
1159 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1160 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1161 cp->cmnd[4], cp->cmnd[5]));
1162 DEBUG2(printk(KERN_INFO
1163 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1164 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001165 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
1167 cp->result = DID_ERROR << 16;
1168 break;
1169
1170 case CS_PORT_LOGGED_OUT:
1171 case CS_PORT_CONFIG_CHG:
1172 case CS_PORT_BUSY:
1173 case CS_INCOMPLETE:
1174 case CS_PORT_UNAVAILABLE:
1175 /*
1176 * If the port is in Target Down state, return all IOs for this
1177 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1178 * retry_queue.
1179 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1181 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001182 ha->host_no, cp->device->id, cp->device->lun,
1183 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 atomic_read(&fcport->state)));
1185
f4f051e2005-04-17 15:02:26 -05001186 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001188 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 break;
1191
1192 case CS_RESET:
1193 DEBUG2(printk(KERN_INFO
1194 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1195 ha->host_no, comp_status, scsi_status));
1196
f4f051e2005-04-17 15:02:26 -05001197 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 break;
1199
1200 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001201 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 * hv2.19.12 - DID_ABORT does not retry the request if we
1203 * aborted this request then abort otherwise it must be a
1204 * reset.
1205 */
1206 DEBUG2(printk(KERN_INFO
1207 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1208 ha->host_no, comp_status, scsi_status));
1209
1210 cp->result = DID_RESET << 16;
1211 break;
1212
1213 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 cp->result = DID_BUS_BUSY << 16;
1215
Andrew Vasqueze4289242007-07-19 15:05:56 -07001216 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001217 DEBUG2(printk(KERN_INFO
1218 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1219 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1220 cp->device->id, cp->device->lun, comp_status,
1221 scsi_status));
1222 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001224 DEBUG2(printk(KERN_INFO
1225 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1226 "sflags=%x.\n", ha->host_no, cp->device->channel,
1227 cp->device->id, cp->device->lun, comp_status, scsi_status,
1228 le16_to_cpu(sts->status_flags)));
1229
1230 /* Check to see if logout occurred. */
1231 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001232 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 break;
1234
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 default:
1236 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001237 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 qla_printk(KERN_INFO, ha,
1239 "Unknown status detected 0x%x-0x%x.\n",
1240 comp_status, scsi_status);
1241
1242 cp->result = DID_ERROR << 16;
1243 break;
1244 }
1245
1246 /* Place command on done queue. */
1247 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001248 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249}
1250
1251/**
1252 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1253 * @ha: SCSI driver HA context
1254 * @pkt: Entry pointer
1255 *
1256 * Extended sense data.
1257 */
1258static void
1259qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1260{
1261 uint8_t sense_sz = 0;
1262 srb_t *sp = ha->status_srb;
1263 struct scsi_cmnd *cp;
1264
1265 if (sp != NULL && sp->request_sense_length != 0) {
1266 cp = sp->cmd;
1267 if (cp == NULL) {
1268 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001269 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 qla_printk(KERN_INFO, ha,
1271 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001272 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
1274 ha->status_srb = NULL;
1275 return;
1276 }
1277
1278 if (sp->request_sense_length > sizeof(pkt->data)) {
1279 sense_sz = sizeof(pkt->data);
1280 } else {
1281 sense_sz = sp->request_sense_length;
1282 }
1283
1284 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001285 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001286 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1288 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1289
1290 sp->request_sense_ptr += sense_sz;
1291 sp->request_sense_length -= sense_sz;
1292
1293 /* Place command on done queue. */
1294 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001296 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 }
1298 }
1299}
1300
1301/**
1302 * qla2x00_error_entry() - Process an error entry.
1303 * @ha: SCSI driver HA context
1304 * @pkt: Entry pointer
1305 */
1306static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001307qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308{
1309 srb_t *sp;
1310
1311#if defined(QL_DEBUG_LEVEL_2)
1312 if (pkt->entry_status & RF_INV_E_ORDER)
1313 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1314 else if (pkt->entry_status & RF_INV_E_COUNT)
1315 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1316 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001317 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 "%s: Invalid Entry Parameter\n", __func__);
1319 else if (pkt->entry_status & RF_INV_E_TYPE)
1320 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1321 else if (pkt->entry_status & RF_BUSY)
1322 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1323 else
1324 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1325#endif
1326
1327 /* Validate handle. */
1328 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1329 sp = ha->outstanding_cmds[pkt->handle];
1330 else
1331 sp = NULL;
1332
1333 if (sp) {
1334 /* Free outstanding command slot. */
1335 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001336
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 /* Bad payload or header */
1338 if (pkt->entry_status &
1339 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1340 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1341 sp->cmd->result = DID_ERROR << 16;
1342 } else if (pkt->entry_status & RF_BUSY) {
1343 sp->cmd->result = DID_BUS_BUSY << 16;
1344 } else {
1345 sp->cmd->result = DID_ERROR << 16;
1346 }
f4f051e2005-04-17 15:02:26 -05001347 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001349 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1350 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1352 ha->host_no));
1353 qla_printk(KERN_WARNING, ha,
1354 "Error entry - invalid handle\n");
1355
1356 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001357 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 }
1359}
1360
1361/**
1362 * qla2x00_ms_entry() - Process a Management Server entry.
1363 * @ha: SCSI driver HA context
1364 * @index: Response queue out pointer
1365 */
1366static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001367qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368{
1369 srb_t *sp;
1370
1371 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1372 __func__, ha->host_no, pkt, pkt->handle1));
1373
1374 /* Validate handle. */
1375 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1376 sp = ha->outstanding_cmds[pkt->handle1];
1377 else
1378 sp = NULL;
1379
1380 if (sp == NULL) {
1381 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1382 ha->host_no));
1383 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1384
1385 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1386 return;
1387 }
1388
1389 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1390 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1391
1392 /* Free outstanding command slot. */
1393 ha->outstanding_cmds[pkt->handle1] = NULL;
1394
f4f051e2005-04-17 15:02:26 -05001395 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001397
1398
1399/**
1400 * qla24xx_mbx_completion() - Process mailbox command completions.
1401 * @ha: SCSI driver HA context
1402 * @mb0: Mailbox0 register
1403 */
1404static void
1405qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1406{
1407 uint16_t cnt;
1408 uint16_t __iomem *wptr;
1409 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1410
1411 /* Load return mailbox registers. */
1412 ha->flags.mbox_int = 1;
1413 ha->mailbox_out[0] = mb0;
1414 wptr = (uint16_t __iomem *)&reg->mailbox1;
1415
1416 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1417 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1418 wptr++;
1419 }
1420
1421 if (ha->mcp) {
1422 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1423 __func__, ha->host_no, ha->mcp->mb[0]));
1424 } else {
1425 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1426 __func__, ha->host_no));
1427 }
1428}
1429
1430/**
1431 * qla24xx_process_response_queue() - Process response queue entries.
1432 * @ha: SCSI driver HA context
1433 */
1434void
1435qla24xx_process_response_queue(struct scsi_qla_host *ha)
1436{
1437 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1438 struct sts_entry_24xx *pkt;
1439
1440 if (!ha->flags.online)
1441 return;
1442
1443 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1444 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1445
1446 ha->rsp_ring_index++;
1447 if (ha->rsp_ring_index == ha->response_q_length) {
1448 ha->rsp_ring_index = 0;
1449 ha->response_ring_ptr = ha->response_ring;
1450 } else {
1451 ha->response_ring_ptr++;
1452 }
1453
1454 if (pkt->entry_status != 0) {
1455 DEBUG3(printk(KERN_INFO
1456 "scsi(%ld): Process error entry.\n", ha->host_no));
1457
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001458 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1459 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1460 wmb();
1461 continue;
1462 }
1463
1464 switch (pkt->entry_type) {
1465 case STATUS_TYPE:
1466 qla2x00_status_entry(ha, pkt);
1467 break;
1468 case STATUS_CONT_TYPE:
1469 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1470 break;
1471 case MS_IOCB_TYPE:
1472 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1473 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001474 case VP_RPT_ID_IOCB_TYPE:
1475 qla24xx_report_id_acquisition(ha,
1476 (struct vp_rpt_id_entry_24xx *)pkt);
1477 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001478 default:
1479 /* Type Not Supported. */
1480 DEBUG4(printk(KERN_WARNING
1481 "scsi(%ld): Received unknown response pkt type %x "
1482 "entry status=%x.\n",
1483 ha->host_no, pkt->entry_type, pkt->entry_status));
1484 break;
1485 }
1486 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1487 wmb();
1488 }
1489
1490 /* Adjust ring index */
1491 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1492}
1493
Andrew Vasquez05236a02007-09-20 14:07:37 -07001494static void
1495qla2xxx_check_risc_status(scsi_qla_host_t *ha)
1496{
1497 int rval;
1498 uint32_t cnt;
1499 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1500
1501 if (!IS_QLA25XX(ha))
1502 return;
1503
1504 rval = QLA_SUCCESS;
1505 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1506 RD_REG_DWORD(&reg->iobase_addr);
1507 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1508 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1509 rval == QLA_SUCCESS; cnt--) {
1510 if (cnt) {
1511 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1512 udelay(10);
1513 } else
1514 rval = QLA_FUNCTION_TIMEOUT;
1515 }
1516 if (rval == QLA_SUCCESS)
1517 goto next_test;
1518
1519 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1520 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1521 rval == QLA_SUCCESS; cnt--) {
1522 if (cnt) {
1523 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1524 udelay(10);
1525 } else
1526 rval = QLA_FUNCTION_TIMEOUT;
1527 }
1528 if (rval != QLA_SUCCESS)
1529 goto done;
1530
1531next_test:
1532 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1533 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1534
1535done:
1536 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1537 RD_REG_DWORD(&reg->iobase_window);
1538}
1539
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001540/**
1541 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1542 * @irq:
1543 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001544 *
1545 * Called by system whenever the host adapter generates an interrupt.
1546 *
1547 * Returns handled flag.
1548 */
1549irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001550qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001551{
1552 scsi_qla_host_t *ha;
1553 struct device_reg_24xx __iomem *reg;
1554 int status;
1555 unsigned long flags;
1556 unsigned long iter;
1557 uint32_t stat;
1558 uint32_t hccr;
1559 uint16_t mb[4];
1560
1561 ha = (scsi_qla_host_t *) dev_id;
1562 if (!ha) {
1563 printk(KERN_INFO
1564 "%s(): NULL host pointer\n", __func__);
1565 return IRQ_NONE;
1566 }
1567
1568 reg = &ha->iobase->isp24;
1569 status = 0;
1570
1571 spin_lock_irqsave(&ha->hardware_lock, flags);
1572 for (iter = 50; iter--; ) {
1573 stat = RD_REG_DWORD(&reg->host_status);
1574 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001575 if (pci_channel_offline(ha->pdev))
1576 break;
1577
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001578 hccr = RD_REG_DWORD(&reg->hccr);
1579
1580 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1581 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001582
1583 qla2xxx_check_risc_status(ha);
1584
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001585 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001586 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1587 break;
1588 } else if ((stat & HSRX_RISC_INT) == 0)
1589 break;
1590
1591 switch (stat & 0xff) {
1592 case 0x1:
1593 case 0x2:
1594 case 0x10:
1595 case 0x11:
1596 qla24xx_mbx_completion(ha, MSW(stat));
1597 status |= MBX_INTERRUPT;
1598
1599 break;
1600 case 0x12:
1601 mb[0] = MSW(stat);
1602 mb[1] = RD_REG_WORD(&reg->mailbox1);
1603 mb[2] = RD_REG_WORD(&reg->mailbox2);
1604 mb[3] = RD_REG_WORD(&reg->mailbox3);
1605 qla2x00_async_event(ha, mb);
1606 break;
1607 case 0x13:
1608 qla24xx_process_response_queue(ha);
1609 break;
1610 default:
1611 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1612 "(%d).\n",
1613 ha->host_no, stat & 0xff));
1614 break;
1615 }
1616 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1617 RD_REG_DWORD_RELAXED(&reg->hccr);
1618 }
1619 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1620
1621 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1622 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001623 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1624 up(&ha->mbx_intr_sem);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001625 }
1626
1627 return IRQ_HANDLED;
1628}
1629
1630/**
1631 * qla24xx_ms_entry() - Process a Management Server entry.
1632 * @ha: SCSI driver HA context
1633 * @index: Response queue out pointer
1634 */
1635static void
1636qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1637{
1638 srb_t *sp;
1639
1640 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1641 __func__, ha->host_no, pkt, pkt->handle));
1642
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001643 DEBUG9(printk("%s: ct pkt dump:\n", __func__));
1644 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx)));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001645
1646 /* Validate handle. */
1647 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1648 sp = ha->outstanding_cmds[pkt->handle];
1649 else
1650 sp = NULL;
1651
1652 if (sp == NULL) {
1653 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1654 ha->host_no));
1655 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1656 ha->host_no));
1657 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1658 pkt->handle);
1659
1660 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1661 return;
1662 }
1663
1664 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1665 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1666
1667 /* Free outstanding command slot. */
1668 ha->outstanding_cmds[pkt->handle] = NULL;
1669
1670 qla2x00_sp_compl(ha, sp);
1671}
1672
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001673static irqreturn_t
1674qla24xx_msix_rsp_q(int irq, void *dev_id)
1675{
1676 scsi_qla_host_t *ha;
1677 struct device_reg_24xx __iomem *reg;
1678 unsigned long flags;
1679
1680 ha = dev_id;
1681 reg = &ha->iobase->isp24;
1682
1683 spin_lock_irqsave(&ha->hardware_lock, flags);
1684
1685 qla24xx_process_response_queue(ha);
1686
1687 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001688
1689 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1690
1691 return IRQ_HANDLED;
1692}
1693
1694static irqreturn_t
1695qla24xx_msix_default(int irq, void *dev_id)
1696{
1697 scsi_qla_host_t *ha;
1698 struct device_reg_24xx __iomem *reg;
1699 int status;
1700 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001701 uint32_t stat;
1702 uint32_t hccr;
1703 uint16_t mb[4];
1704
1705 ha = dev_id;
1706 reg = &ha->iobase->isp24;
1707 status = 0;
1708
1709 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001710 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001711 stat = RD_REG_DWORD(&reg->host_status);
1712 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001713 if (pci_channel_offline(ha->pdev))
1714 break;
1715
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001716 hccr = RD_REG_DWORD(&reg->hccr);
1717
1718 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1719 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001720
1721 qla2xxx_check_risc_status(ha);
1722
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001723 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001724 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1725 break;
1726 } else if ((stat & HSRX_RISC_INT) == 0)
1727 break;
1728
1729 switch (stat & 0xff) {
1730 case 0x1:
1731 case 0x2:
1732 case 0x10:
1733 case 0x11:
1734 qla24xx_mbx_completion(ha, MSW(stat));
1735 status |= MBX_INTERRUPT;
1736
1737 break;
1738 case 0x12:
1739 mb[0] = MSW(stat);
1740 mb[1] = RD_REG_WORD(&reg->mailbox1);
1741 mb[2] = RD_REG_WORD(&reg->mailbox2);
1742 mb[3] = RD_REG_WORD(&reg->mailbox3);
1743 qla2x00_async_event(ha, mb);
1744 break;
1745 case 0x13:
1746 qla24xx_process_response_queue(ha);
1747 break;
1748 default:
1749 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1750 "(%d).\n",
1751 ha->host_no, stat & 0xff));
1752 break;
1753 }
1754 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001755 } while (0);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001756 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1757
1758 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1759 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001760 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1761 up(&ha->mbx_intr_sem);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001762 }
1763
1764 return IRQ_HANDLED;
1765}
1766
1767/* Interrupt handling helpers. */
1768
1769struct qla_init_msix_entry {
1770 uint16_t entry;
1771 uint16_t index;
1772 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001773 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001774};
1775
1776static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1777 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1778 "qla2xxx (default)", qla24xx_msix_default },
1779
1780 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1781 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1782};
1783
1784static void
1785qla24xx_disable_msix(scsi_qla_host_t *ha)
1786{
1787 int i;
1788 struct qla_msix_entry *qentry;
1789
1790 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1791 qentry = &ha->msix_entries[imsix_entries[i].index];
1792 if (qentry->have_irq)
1793 free_irq(qentry->msix_vector, ha);
1794 }
1795 pci_disable_msix(ha->pdev);
1796}
1797
1798static int
1799qla24xx_enable_msix(scsi_qla_host_t *ha)
1800{
1801 int i, ret;
1802 struct msix_entry entries[QLA_MSIX_ENTRIES];
1803 struct qla_msix_entry *qentry;
1804
1805 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1806 entries[i].entry = imsix_entries[i].entry;
1807
1808 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1809 if (ret) {
1810 qla_printk(KERN_WARNING, ha,
1811 "MSI-X: Failed to enable support -- %d/%d\n",
1812 QLA_MSIX_ENTRIES, ret);
1813 goto msix_out;
1814 }
1815 ha->flags.msix_enabled = 1;
1816
1817 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1818 qentry = &ha->msix_entries[imsix_entries[i].index];
1819 qentry->msix_vector = entries[i].vector;
1820 qentry->msix_entry = entries[i].entry;
1821 qentry->have_irq = 0;
1822 ret = request_irq(qentry->msix_vector,
1823 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1824 if (ret) {
1825 qla_printk(KERN_WARNING, ha,
1826 "MSI-X: Unable to register handler -- %x/%d.\n",
1827 imsix_entries[i].index, ret);
1828 qla24xx_disable_msix(ha);
1829 goto msix_out;
1830 }
1831 qentry->have_irq = 1;
1832 }
1833
1834msix_out:
1835 return ret;
1836}
1837
1838int
1839qla2x00_request_irqs(scsi_qla_host_t *ha)
1840{
1841 int ret;
1842
1843 /* If possible, enable MSI-X. */
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001844 if (!IS_QLA2432(ha) && !IS_QLA2532(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001845 goto skip_msix;
1846
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001847 if (IS_QLA2432(ha) && (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1848 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001849 DEBUG2(qla_printk(KERN_WARNING, ha,
1850 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1851 ha->chip_revision, ha->fw_attributes));
1852
1853 goto skip_msix;
1854 }
1855
1856 ret = qla24xx_enable_msix(ha);
1857 if (!ret) {
1858 DEBUG2(qla_printk(KERN_INFO, ha,
1859 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1860 ha->fw_attributes));
1861 return ret;
1862 }
1863 qla_printk(KERN_WARNING, ha,
1864 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1865skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001866
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001867 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001868 goto skip_msi;
1869
1870 ret = pci_enable_msi(ha->pdev);
1871 if (!ret) {
1872 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1873 ha->flags.msi_enabled = 1;
1874 }
1875skip_msi:
1876
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001877 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001878 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
Andrew Vasquezd88021a2007-01-29 10:22:20 -08001879 if (!ret) {
1880 ha->flags.inta_enabled = 1;
1881 ha->host->irq = ha->pdev->irq;
1882 } else {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001883 qla_printk(KERN_WARNING, ha,
1884 "Failed to reserve interrupt %d already in use.\n",
1885 ha->pdev->irq);
1886 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001887
1888 return ret;
1889}
1890
1891void
1892qla2x00_free_irqs(scsi_qla_host_t *ha)
1893{
1894
1895 if (ha->flags.msix_enabled)
1896 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001897 else if (ha->flags.inta_enabled) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001898 free_irq(ha->host->irq, ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001899 pci_disable_msi(ha->pdev);
1900 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001901}