blob: c4768c4f39904f0fe80f53e0aeb5d17b01adde01 [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 Vasqueze4289242007-07-19 15:05:56 -07001015 if (IS_FWI2_CAPABLE(ha))
Ravi Ananded17c712006-05-17 15:08:55 -07001016 resid = fw_resid_len;
1017
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 if (scsi_status & SS_RESIDUAL_UNDER) {
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.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001021 } else {
1022 DEBUG2(printk(KERN_INFO
1023 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c712006-05-17 15:08:55 -07001024 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1025 "os_underflow=0x%x\n", ha->host_no,
1026 cp->device->id, cp->device->lun, comp_status,
1027 scsi_status, resid_len, resid, cp->cmnd[0],
1028 cp->underflow));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001029
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031
1032 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001033 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 * Status.
1035 */
1036 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 cp->result = DID_OK << 16 | lscsi_status;
1038
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001039 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 /*
1046 * Adjust queue depth for all luns on the
1047 * port.
1048 */
1049 fcport->last_queue_full = jiffies;
1050 starget_for_each_device(
1051 cp->device->sdev_target, fcport,
1052 qla2x00_adjust_sdev_qdepth_down);
1053 break;
1054 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 if (lscsi_status != SS_CHECK_CONDITION)
1056 break;
1057
1058 /* Copy Sense Data into sense buffer */
1059 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
1060
1061 if (!(scsi_status & SS_SENSE_LEN_VALID))
1062 break;
1063
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001064 if (sense_len >= sizeof(cp->sense_buffer))
1065 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001067 CMD_ACTUAL_SNSLEN(cp) = sense_len;
1068 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 sp->request_sense_ptr = cp->sense_buffer;
1070
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001071 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001072 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001074 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001076 sp->request_sense_ptr += sense_len;
1077 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 if (sp->request_sense_length != 0)
1079 ha->status_srb = sp;
1080
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 DEBUG5(printk("%s(): Check condition Sense data, "
1082 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001083 __func__, ha->host_no, cp->device->channel,
1084 cp->device->id, cp->device->lun, cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 cp->serial_number));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001086
Shyam Sundar8084fe12007-07-19 15:05:59 -07001087 /*
1088 * In case of a Underrun condition, set both the lscsi
1089 * status and the completion status to appropriate
1090 * values.
1091 */
1092 if (resid &&
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001093 ((unsigned)(scsi_bufflen(cp) - resid) <
Shyam Sundar8084fe12007-07-19 15:05:59 -07001094 cp->underflow)) {
1095 DEBUG2(qla_printk(KERN_INFO, ha,
1096 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1097 "detected (%x of %x bytes)...returning "
1098 "error status.\n", ha->host_no,
1099 cp->device->channel, cp->device->id,
1100 cp->device->lun, resid,
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001101 scsi_bufflen(cp)));
Shyam Sundar8084fe12007-07-19 15:05:59 -07001102
1103 cp->result = DID_ERROR << 16 | lscsi_status;
1104 }
1105
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001106 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1108 CMD_ACTUAL_SNSLEN(cp)));
1109 } else {
1110 /*
1111 * If RISC reports underrun and target does not report
1112 * it then we must have a lost frame, so tell upper
1113 * layer to retry it by reporting a bus busy.
1114 */
1115 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1116 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001117 "frame(s) detected (%x of %x bytes)..."
1118 "retrying command.\n", ha->host_no,
1119 cp->device->channel, cp->device->id,
1120 cp->device->lun, resid,
1121 scsi_bufflen(cp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 break;
1125 }
1126
1127 /* Handle mid-layer underflow */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001128 if ((unsigned)(scsi_bufflen(cp) - resid) <
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 cp->underflow) {
1130 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001131 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1132 "detected (%x of %x bytes)...returning "
1133 "error status.\n", ha->host_no,
1134 cp->device->channel, cp->device->id,
1135 cp->device->lun, resid,
1136 scsi_bufflen(cp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 cp->result = DID_ERROR << 16;
1139 break;
1140 }
1141
1142 /* Everybody online, looking good... */
1143 cp->result = DID_OK << 16;
1144 }
1145 break;
1146
1147 case CS_DATA_OVERRUN:
1148 DEBUG2(printk(KERN_INFO
1149 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001150 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1151 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 DEBUG2(printk(KERN_INFO
1153 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1154 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1155 cp->cmnd[4], cp->cmnd[5]));
1156 DEBUG2(printk(KERN_INFO
1157 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1158 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001159 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
1161 cp->result = DID_ERROR << 16;
1162 break;
1163
1164 case CS_PORT_LOGGED_OUT:
1165 case CS_PORT_CONFIG_CHG:
1166 case CS_PORT_BUSY:
1167 case CS_INCOMPLETE:
1168 case CS_PORT_UNAVAILABLE:
1169 /*
1170 * If the port is in Target Down state, return all IOs for this
1171 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1172 * retry_queue.
1173 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1175 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001176 ha->host_no, cp->device->id, cp->device->lun,
1177 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 atomic_read(&fcport->state)));
1179
f4f051e2005-04-17 15:02:26 -05001180 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001182 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 break;
1185
1186 case CS_RESET:
1187 DEBUG2(printk(KERN_INFO
1188 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1189 ha->host_no, comp_status, scsi_status));
1190
f4f051e2005-04-17 15:02:26 -05001191 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 break;
1193
1194 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001195 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 * hv2.19.12 - DID_ABORT does not retry the request if we
1197 * aborted this request then abort otherwise it must be a
1198 * reset.
1199 */
1200 DEBUG2(printk(KERN_INFO
1201 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1202 ha->host_no, comp_status, scsi_status));
1203
1204 cp->result = DID_RESET << 16;
1205 break;
1206
1207 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 cp->result = DID_BUS_BUSY << 16;
1209
Andrew Vasqueze4289242007-07-19 15:05:56 -07001210 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001211 DEBUG2(printk(KERN_INFO
1212 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1213 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1214 cp->device->id, cp->device->lun, comp_status,
1215 scsi_status));
1216 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001218 DEBUG2(printk(KERN_INFO
1219 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1220 "sflags=%x.\n", ha->host_no, cp->device->channel,
1221 cp->device->id, cp->device->lun, comp_status, scsi_status,
1222 le16_to_cpu(sts->status_flags)));
1223
1224 /* Check to see if logout occurred. */
1225 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001226 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 break;
1228
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 default:
1230 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001231 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 qla_printk(KERN_INFO, ha,
1233 "Unknown status detected 0x%x-0x%x.\n",
1234 comp_status, scsi_status);
1235
1236 cp->result = DID_ERROR << 16;
1237 break;
1238 }
1239
1240 /* Place command on done queue. */
1241 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001242 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243}
1244
1245/**
1246 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1247 * @ha: SCSI driver HA context
1248 * @pkt: Entry pointer
1249 *
1250 * Extended sense data.
1251 */
1252static void
1253qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1254{
1255 uint8_t sense_sz = 0;
1256 srb_t *sp = ha->status_srb;
1257 struct scsi_cmnd *cp;
1258
1259 if (sp != NULL && sp->request_sense_length != 0) {
1260 cp = sp->cmd;
1261 if (cp == NULL) {
1262 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001263 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 qla_printk(KERN_INFO, ha,
1265 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001266 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 ha->status_srb = NULL;
1269 return;
1270 }
1271
1272 if (sp->request_sense_length > sizeof(pkt->data)) {
1273 sense_sz = sizeof(pkt->data);
1274 } else {
1275 sense_sz = sp->request_sense_length;
1276 }
1277
1278 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001279 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001280 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1282 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1283
1284 sp->request_sense_ptr += sense_sz;
1285 sp->request_sense_length -= sense_sz;
1286
1287 /* Place command on done queue. */
1288 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001290 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 }
1292 }
1293}
1294
1295/**
1296 * qla2x00_error_entry() - Process an error entry.
1297 * @ha: SCSI driver HA context
1298 * @pkt: Entry pointer
1299 */
1300static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001301qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
1303 srb_t *sp;
1304
1305#if defined(QL_DEBUG_LEVEL_2)
1306 if (pkt->entry_status & RF_INV_E_ORDER)
1307 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1308 else if (pkt->entry_status & RF_INV_E_COUNT)
1309 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1310 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001311 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 "%s: Invalid Entry Parameter\n", __func__);
1313 else if (pkt->entry_status & RF_INV_E_TYPE)
1314 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1315 else if (pkt->entry_status & RF_BUSY)
1316 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1317 else
1318 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1319#endif
1320
1321 /* Validate handle. */
1322 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1323 sp = ha->outstanding_cmds[pkt->handle];
1324 else
1325 sp = NULL;
1326
1327 if (sp) {
1328 /* Free outstanding command slot. */
1329 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001330
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 /* Bad payload or header */
1332 if (pkt->entry_status &
1333 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1334 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1335 sp->cmd->result = DID_ERROR << 16;
1336 } else if (pkt->entry_status & RF_BUSY) {
1337 sp->cmd->result = DID_BUS_BUSY << 16;
1338 } else {
1339 sp->cmd->result = DID_ERROR << 16;
1340 }
f4f051e2005-04-17 15:02:26 -05001341 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001343 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1344 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1346 ha->host_no));
1347 qla_printk(KERN_WARNING, ha,
1348 "Error entry - invalid handle\n");
1349
1350 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001351 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 }
1353}
1354
1355/**
1356 * qla2x00_ms_entry() - Process a Management Server entry.
1357 * @ha: SCSI driver HA context
1358 * @index: Response queue out pointer
1359 */
1360static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001361qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362{
1363 srb_t *sp;
1364
1365 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1366 __func__, ha->host_no, pkt, pkt->handle1));
1367
1368 /* Validate handle. */
1369 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1370 sp = ha->outstanding_cmds[pkt->handle1];
1371 else
1372 sp = NULL;
1373
1374 if (sp == NULL) {
1375 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1376 ha->host_no));
1377 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1378
1379 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1380 return;
1381 }
1382
1383 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1384 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1385
1386 /* Free outstanding command slot. */
1387 ha->outstanding_cmds[pkt->handle1] = NULL;
1388
f4f051e2005-04-17 15:02:26 -05001389 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390}
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001391
1392
1393/**
1394 * qla24xx_mbx_completion() - Process mailbox command completions.
1395 * @ha: SCSI driver HA context
1396 * @mb0: Mailbox0 register
1397 */
1398static void
1399qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1400{
1401 uint16_t cnt;
1402 uint16_t __iomem *wptr;
1403 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1404
1405 /* Load return mailbox registers. */
1406 ha->flags.mbox_int = 1;
1407 ha->mailbox_out[0] = mb0;
1408 wptr = (uint16_t __iomem *)&reg->mailbox1;
1409
1410 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1411 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1412 wptr++;
1413 }
1414
1415 if (ha->mcp) {
1416 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1417 __func__, ha->host_no, ha->mcp->mb[0]));
1418 } else {
1419 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1420 __func__, ha->host_no));
1421 }
1422}
1423
1424/**
1425 * qla24xx_process_response_queue() - Process response queue entries.
1426 * @ha: SCSI driver HA context
1427 */
1428void
1429qla24xx_process_response_queue(struct scsi_qla_host *ha)
1430{
1431 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1432 struct sts_entry_24xx *pkt;
1433
1434 if (!ha->flags.online)
1435 return;
1436
1437 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1438 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1439
1440 ha->rsp_ring_index++;
1441 if (ha->rsp_ring_index == ha->response_q_length) {
1442 ha->rsp_ring_index = 0;
1443 ha->response_ring_ptr = ha->response_ring;
1444 } else {
1445 ha->response_ring_ptr++;
1446 }
1447
1448 if (pkt->entry_status != 0) {
1449 DEBUG3(printk(KERN_INFO
1450 "scsi(%ld): Process error entry.\n", ha->host_no));
1451
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001452 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1453 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1454 wmb();
1455 continue;
1456 }
1457
1458 switch (pkt->entry_type) {
1459 case STATUS_TYPE:
1460 qla2x00_status_entry(ha, pkt);
1461 break;
1462 case STATUS_CONT_TYPE:
1463 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1464 break;
1465 case MS_IOCB_TYPE:
1466 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1467 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001468 case VP_RPT_ID_IOCB_TYPE:
1469 qla24xx_report_id_acquisition(ha,
1470 (struct vp_rpt_id_entry_24xx *)pkt);
1471 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001472 default:
1473 /* Type Not Supported. */
1474 DEBUG4(printk(KERN_WARNING
1475 "scsi(%ld): Received unknown response pkt type %x "
1476 "entry status=%x.\n",
1477 ha->host_no, pkt->entry_type, pkt->entry_status));
1478 break;
1479 }
1480 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1481 wmb();
1482 }
1483
1484 /* Adjust ring index */
1485 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1486}
1487
Andrew Vasquez05236a02007-09-20 14:07:37 -07001488static void
1489qla2xxx_check_risc_status(scsi_qla_host_t *ha)
1490{
1491 int rval;
1492 uint32_t cnt;
1493 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1494
1495 if (!IS_QLA25XX(ha))
1496 return;
1497
1498 rval = QLA_SUCCESS;
1499 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1500 RD_REG_DWORD(&reg->iobase_addr);
1501 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1502 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1503 rval == QLA_SUCCESS; cnt--) {
1504 if (cnt) {
1505 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1506 udelay(10);
1507 } else
1508 rval = QLA_FUNCTION_TIMEOUT;
1509 }
1510 if (rval == QLA_SUCCESS)
1511 goto next_test;
1512
1513 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1514 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1515 rval == QLA_SUCCESS; cnt--) {
1516 if (cnt) {
1517 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1518 udelay(10);
1519 } else
1520 rval = QLA_FUNCTION_TIMEOUT;
1521 }
1522 if (rval != QLA_SUCCESS)
1523 goto done;
1524
1525next_test:
1526 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1527 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1528
1529done:
1530 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1531 RD_REG_DWORD(&reg->iobase_window);
1532}
1533
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001534/**
1535 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1536 * @irq:
1537 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001538 *
1539 * Called by system whenever the host adapter generates an interrupt.
1540 *
1541 * Returns handled flag.
1542 */
1543irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001544qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001545{
1546 scsi_qla_host_t *ha;
1547 struct device_reg_24xx __iomem *reg;
1548 int status;
1549 unsigned long flags;
1550 unsigned long iter;
1551 uint32_t stat;
1552 uint32_t hccr;
1553 uint16_t mb[4];
1554
1555 ha = (scsi_qla_host_t *) dev_id;
1556 if (!ha) {
1557 printk(KERN_INFO
1558 "%s(): NULL host pointer\n", __func__);
1559 return IRQ_NONE;
1560 }
1561
1562 reg = &ha->iobase->isp24;
1563 status = 0;
1564
1565 spin_lock_irqsave(&ha->hardware_lock, flags);
1566 for (iter = 50; iter--; ) {
1567 stat = RD_REG_DWORD(&reg->host_status);
1568 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001569 if (pci_channel_offline(ha->pdev))
1570 break;
1571
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001572 hccr = RD_REG_DWORD(&reg->hccr);
1573
1574 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1575 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001576
1577 qla2xxx_check_risc_status(ha);
1578
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001579 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001580 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1581 break;
1582 } else if ((stat & HSRX_RISC_INT) == 0)
1583 break;
1584
1585 switch (stat & 0xff) {
1586 case 0x1:
1587 case 0x2:
1588 case 0x10:
1589 case 0x11:
1590 qla24xx_mbx_completion(ha, MSW(stat));
1591 status |= MBX_INTERRUPT;
1592
1593 break;
1594 case 0x12:
1595 mb[0] = MSW(stat);
1596 mb[1] = RD_REG_WORD(&reg->mailbox1);
1597 mb[2] = RD_REG_WORD(&reg->mailbox2);
1598 mb[3] = RD_REG_WORD(&reg->mailbox3);
1599 qla2x00_async_event(ha, mb);
1600 break;
1601 case 0x13:
1602 qla24xx_process_response_queue(ha);
1603 break;
1604 default:
1605 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1606 "(%d).\n",
1607 ha->host_no, stat & 0xff));
1608 break;
1609 }
1610 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1611 RD_REG_DWORD_RELAXED(&reg->hccr);
1612 }
1613 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1614
1615 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1616 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001617 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1618 up(&ha->mbx_intr_sem);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001619 }
1620
1621 return IRQ_HANDLED;
1622}
1623
1624/**
1625 * qla24xx_ms_entry() - Process a Management Server entry.
1626 * @ha: SCSI driver HA context
1627 * @index: Response queue out pointer
1628 */
1629static void
1630qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1631{
1632 srb_t *sp;
1633
1634 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1635 __func__, ha->host_no, pkt, pkt->handle));
1636
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001637 DEBUG9(printk("%s: ct pkt dump:\n", __func__));
1638 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx)));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001639
1640 /* Validate handle. */
1641 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1642 sp = ha->outstanding_cmds[pkt->handle];
1643 else
1644 sp = NULL;
1645
1646 if (sp == NULL) {
1647 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1648 ha->host_no));
1649 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1650 ha->host_no));
1651 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1652 pkt->handle);
1653
1654 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1655 return;
1656 }
1657
1658 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1659 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1660
1661 /* Free outstanding command slot. */
1662 ha->outstanding_cmds[pkt->handle] = NULL;
1663
1664 qla2x00_sp_compl(ha, sp);
1665}
1666
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001667static irqreturn_t
1668qla24xx_msix_rsp_q(int irq, void *dev_id)
1669{
1670 scsi_qla_host_t *ha;
1671 struct device_reg_24xx __iomem *reg;
1672 unsigned long flags;
1673
1674 ha = dev_id;
1675 reg = &ha->iobase->isp24;
1676
1677 spin_lock_irqsave(&ha->hardware_lock, flags);
1678
1679 qla24xx_process_response_queue(ha);
1680
1681 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001682
1683 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1684
1685 return IRQ_HANDLED;
1686}
1687
1688static irqreturn_t
1689qla24xx_msix_default(int irq, void *dev_id)
1690{
1691 scsi_qla_host_t *ha;
1692 struct device_reg_24xx __iomem *reg;
1693 int status;
1694 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001695 uint32_t stat;
1696 uint32_t hccr;
1697 uint16_t mb[4];
1698
1699 ha = dev_id;
1700 reg = &ha->iobase->isp24;
1701 status = 0;
1702
1703 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001704 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001705 stat = RD_REG_DWORD(&reg->host_status);
1706 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001707 if (pci_channel_offline(ha->pdev))
1708 break;
1709
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001710 hccr = RD_REG_DWORD(&reg->hccr);
1711
1712 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1713 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001714
1715 qla2xxx_check_risc_status(ha);
1716
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001717 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001718 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1719 break;
1720 } else if ((stat & HSRX_RISC_INT) == 0)
1721 break;
1722
1723 switch (stat & 0xff) {
1724 case 0x1:
1725 case 0x2:
1726 case 0x10:
1727 case 0x11:
1728 qla24xx_mbx_completion(ha, MSW(stat));
1729 status |= MBX_INTERRUPT;
1730
1731 break;
1732 case 0x12:
1733 mb[0] = MSW(stat);
1734 mb[1] = RD_REG_WORD(&reg->mailbox1);
1735 mb[2] = RD_REG_WORD(&reg->mailbox2);
1736 mb[3] = RD_REG_WORD(&reg->mailbox3);
1737 qla2x00_async_event(ha, mb);
1738 break;
1739 case 0x13:
1740 qla24xx_process_response_queue(ha);
1741 break;
1742 default:
1743 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1744 "(%d).\n",
1745 ha->host_no, stat & 0xff));
1746 break;
1747 }
1748 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001749 } while (0);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001750 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1751
1752 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1753 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001754 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1755 up(&ha->mbx_intr_sem);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001756 }
1757
1758 return IRQ_HANDLED;
1759}
1760
1761/* Interrupt handling helpers. */
1762
1763struct qla_init_msix_entry {
1764 uint16_t entry;
1765 uint16_t index;
1766 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001767 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001768};
1769
1770static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1771 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1772 "qla2xxx (default)", qla24xx_msix_default },
1773
1774 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1775 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1776};
1777
1778static void
1779qla24xx_disable_msix(scsi_qla_host_t *ha)
1780{
1781 int i;
1782 struct qla_msix_entry *qentry;
1783
1784 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1785 qentry = &ha->msix_entries[imsix_entries[i].index];
1786 if (qentry->have_irq)
1787 free_irq(qentry->msix_vector, ha);
1788 }
1789 pci_disable_msix(ha->pdev);
1790}
1791
1792static int
1793qla24xx_enable_msix(scsi_qla_host_t *ha)
1794{
1795 int i, ret;
1796 struct msix_entry entries[QLA_MSIX_ENTRIES];
1797 struct qla_msix_entry *qentry;
1798
1799 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1800 entries[i].entry = imsix_entries[i].entry;
1801
1802 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1803 if (ret) {
1804 qla_printk(KERN_WARNING, ha,
1805 "MSI-X: Failed to enable support -- %d/%d\n",
1806 QLA_MSIX_ENTRIES, ret);
1807 goto msix_out;
1808 }
1809 ha->flags.msix_enabled = 1;
1810
1811 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1812 qentry = &ha->msix_entries[imsix_entries[i].index];
1813 qentry->msix_vector = entries[i].vector;
1814 qentry->msix_entry = entries[i].entry;
1815 qentry->have_irq = 0;
1816 ret = request_irq(qentry->msix_vector,
1817 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1818 if (ret) {
1819 qla_printk(KERN_WARNING, ha,
1820 "MSI-X: Unable to register handler -- %x/%d.\n",
1821 imsix_entries[i].index, ret);
1822 qla24xx_disable_msix(ha);
1823 goto msix_out;
1824 }
1825 qentry->have_irq = 1;
1826 }
1827
1828msix_out:
1829 return ret;
1830}
1831
1832int
1833qla2x00_request_irqs(scsi_qla_host_t *ha)
1834{
1835 int ret;
1836
1837 /* If possible, enable MSI-X. */
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001838 if (!IS_QLA2432(ha) && !IS_QLA2532(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001839 goto skip_msix;
1840
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001841 if (IS_QLA2432(ha) && (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1842 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001843 DEBUG2(qla_printk(KERN_WARNING, ha,
1844 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1845 ha->chip_revision, ha->fw_attributes));
1846
1847 goto skip_msix;
1848 }
1849
1850 ret = qla24xx_enable_msix(ha);
1851 if (!ret) {
1852 DEBUG2(qla_printk(KERN_INFO, ha,
1853 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1854 ha->fw_attributes));
1855 return ret;
1856 }
1857 qla_printk(KERN_WARNING, ha,
1858 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1859skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001860
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001861 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001862 goto skip_msi;
1863
1864 ret = pci_enable_msi(ha->pdev);
1865 if (!ret) {
1866 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1867 ha->flags.msi_enabled = 1;
1868 }
1869skip_msi:
1870
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001871 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001872 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
Andrew Vasquezd88021a2007-01-29 10:22:20 -08001873 if (!ret) {
1874 ha->flags.inta_enabled = 1;
1875 ha->host->irq = ha->pdev->irq;
1876 } else {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001877 qla_printk(KERN_WARNING, ha,
1878 "Failed to reserve interrupt %d already in use.\n",
1879 ha->pdev->irq);
1880 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001881
1882 return ret;
1883}
1884
1885void
1886qla2x00_free_irqs(scsi_qla_host_t *ha)
1887{
1888
1889 if (ha->flags.msix_enabled)
1890 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001891 else if (ha->flags.inta_enabled) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001892 free_irq(ha->host->irq, ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001893 pci_disable_msi(ha->pdev);
1894 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001895}