blob: 4e9f410344669a4b5ff022de39320b1a940432ef [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
Andrew Vasquez05236a02007-09-20 14:07:37 -07009#include <linux/delay.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070010#include <scsi/scsi_tcq.h>
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -070013static void qla2x00_process_completed_request(struct scsi_qla_host *, uint32_t);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070014static void qla2x00_status_entry(scsi_qla_host_t *, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070015static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *);
16static void qla2x00_error_entry(scsi_qla_host_t *, sts_entry_t *);
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070037 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070038 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40 ha = (scsi_qla_host_t *) dev_id;
41 if (!ha) {
42 printk(KERN_INFO
43 "%s(): NULL host pointer\n", __func__);
44 return (IRQ_NONE);
45 }
46
Andrew Vasquez3d716442005-07-06 10:30:26 -070047 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 status = 0;
49
Andrew Vasquezc6952482008-04-03 13:13:17 -070050 spin_lock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070052 hccr = RD_REG_WORD(&reg->hccr);
53 if (hccr & HCCR_RISC_PAUSE) {
54 if (pci_channel_offline(ha->pdev))
55 break;
56
57 /*
58 * Issue a "HARD" reset in order for the RISC interrupt
59 * bit to be cleared. Schedule a big hammmer to get
60 * out of the RISC PAUSED state.
61 */
62 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
63 RD_REG_WORD(&reg->hccr);
64
65 ha->isp_ops->fw_dump(ha, 1);
66 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
67 break;
68 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 break;
70
71 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
72 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
73 RD_REG_WORD(&reg->hccr);
74
75 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070076 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
77 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
78 qla2x00_mbx_completion(ha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070080 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
81 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
82 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
83 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
84 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 } else {
86 /*EMPTY*/
87 DEBUG2(printk("scsi(%ld): Unrecognized "
Andrew Vasquez9a853f72005-07-06 10:31:27 -070088 "interrupt type (%d).\n",
89 ha->host_no, mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 }
91 /* Release mailbox registers. */
92 WRT_REG_WORD(&reg->semaphore, 0);
93 RD_REG_WORD(&reg->semaphore);
94 } else {
95 qla2x00_process_response_queue(ha);
96
97 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
98 RD_REG_WORD(&reg->hccr);
99 }
100 }
Andrew Vasquezc6952482008-04-03 13:13:17 -0700101 spin_unlock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
104 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800106 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 return (IRQ_HANDLED);
110}
111
112/**
113 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
114 * @irq:
115 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 *
117 * Called by system whenever the host adapter generates an interrupt.
118 *
119 * Returns handled flag.
120 */
121irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100122qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 scsi_qla_host_t *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700125 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 unsigned long iter;
128 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700130 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 ha = (scsi_qla_host_t *) dev_id;
133 if (!ha) {
134 printk(KERN_INFO
135 "%s(): NULL host pointer\n", __func__);
136 return (IRQ_NONE);
137 }
138
Andrew Vasquez3d716442005-07-06 10:30:26 -0700139 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 status = 0;
141
Andrew Vasquezc6952482008-04-03 13:13:17 -0700142 spin_lock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 for (iter = 50; iter--; ) {
144 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
145 if (stat & HSR_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700146 if (pci_channel_offline(ha->pdev))
147 break;
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 hccr = RD_REG_WORD(&reg->hccr);
150 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Andrew Vasquez07f31802006-12-13 19:20:31 -0800151 qla_printk(KERN_INFO, ha, "Parity error -- "
152 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 else
Andrew Vasquez07f31802006-12-13 19:20:31 -0800154 qla_printk(KERN_INFO, ha, "RISC paused -- "
155 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 /*
158 * Issue a "HARD" reset in order for the RISC
159 * interrupt bit to be cleared. Schedule a big
160 * hammmer to get out of the RISC PAUSED state.
161 */
162 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
163 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800164
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700165 ha->isp_ops->fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
167 break;
168 } else if ((stat & HSR_RISC_INT) == 0)
169 break;
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 case 0x1:
173 case 0x2:
174 case 0x10:
175 case 0x11:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700176 qla2x00_mbx_completion(ha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 status |= MBX_INTERRUPT;
178
179 /* Release mailbox registers. */
180 WRT_REG_WORD(&reg->semaphore, 0);
181 break;
182 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700183 mb[0] = MSW(stat);
184 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
185 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
186 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
187 qla2x00_async_event(ha, mb);
188 break;
189 case 0x13:
190 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 break;
192 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700193 mb[0] = MBA_CMPLT_1_16BIT;
194 mb[1] = MSW(stat);
195 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 break;
197 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700198 mb[0] = MBA_SCSI_COMPLETION;
199 mb[1] = MSW(stat);
200 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
201 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 break;
203 default:
204 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700205 "(%d).\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 ha->host_no, stat & 0xff));
207 break;
208 }
209 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
210 RD_REG_WORD_RELAXED(&reg->hccr);
211 }
Andrew Vasquezc6952482008-04-03 13:13:17 -0700212 spin_unlock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
215 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800217 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 }
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return (IRQ_HANDLED);
221}
222
223/**
224 * qla2x00_mbx_completion() - Process mailbox command completions.
225 * @ha: SCSI driver HA context
226 * @mb0: Mailbox0 register
227 */
228static void
229qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
230{
231 uint16_t cnt;
232 uint16_t __iomem *wptr;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700233 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 /* Load return mailbox registers. */
236 ha->flags.mbox_int = 1;
237 ha->mailbox_out[0] = mb0;
238 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
239
240 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700241 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
243 if (cnt == 4 || cnt == 5)
244 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
245 else
246 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 wptr++;
249 }
250
251 if (ha->mcp) {
252 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
253 __func__, ha->host_no, ha->mcp->mb[0]));
254 } else {
255 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
256 __func__, ha->host_no));
257 }
258}
259
260/**
261 * qla2x00_async_event() - Process aynchronous events.
262 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700263 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700265void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700266qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700268#define LS_UNKNOWN 2
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700269 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 uint16_t handle_cnt;
272 uint16_t cnt;
273 uint32_t handles[5];
Andrew Vasquez3d716442005-07-06 10:30:26 -0700274 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 uint32_t rscn_entry, host_pid;
276 uint8_t rscn_queue_index;
277
278 /* Setup to process RIO completion. */
279 handle_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 switch (mb[0]) {
281 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700282 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 handle_cnt = 1;
284 break;
285 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700286 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 handle_cnt = 1;
288 mb[0] = MBA_SCSI_COMPLETION;
289 break;
290 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700291 handles[0] = mb[1];
292 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 handle_cnt = 2;
294 mb[0] = MBA_SCSI_COMPLETION;
295 break;
296 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700297 handles[0] = mb[1];
298 handles[1] = mb[2];
299 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 handle_cnt = 3;
301 mb[0] = MBA_SCSI_COMPLETION;
302 break;
303 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700304 handles[0] = mb[1];
305 handles[1] = mb[2];
306 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
308 handle_cnt = 4;
309 mb[0] = MBA_SCSI_COMPLETION;
310 break;
311 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700312 handles[0] = mb[1];
313 handles[1] = mb[2];
314 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
316 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
317 handle_cnt = 5;
318 mb[0] = MBA_SCSI_COMPLETION;
319 break;
320 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700321 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 handles[1] = le32_to_cpu(
323 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
324 RD_MAILBOX_REG(ha, reg, 6));
325 handle_cnt = 2;
326 mb[0] = MBA_SCSI_COMPLETION;
327 break;
328 default:
329 break;
330 }
331
332 switch (mb[0]) {
333 case MBA_SCSI_COMPLETION: /* Fast Post */
334 if (!ha->flags.online)
335 break;
336
337 for (cnt = 0; cnt < handle_cnt; cnt++)
338 qla2x00_process_completed_request(ha, handles[cnt]);
339 break;
340
341 case MBA_RESET: /* Reset */
342 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
343
344 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
345 break;
346
347 case MBA_SYSTEM_ERR: /* System Error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 qla_printk(KERN_INFO, ha,
349 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
350 mb[1], mb[2], mb[3]);
351
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700352 ha->isp_ops->fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Andrew Vasqueze4289242007-07-19 15:05:56 -0700354 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700355 if (mb[1] == 0 && mb[2] == 0) {
356 qla_printk(KERN_ERR, ha,
357 "Unrecoverable Hardware Error: adapter "
358 "marked OFFLINE!\n");
359 ha->flags.online = 0;
360 } else
361 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
362 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 qla_printk(KERN_INFO, ha,
364 "Unrecoverable Hardware Error: adapter marked "
365 "OFFLINE!\n");
366 ha->flags.online = 0;
367 } else
368 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
369 break;
370
371 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
372 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
373 ha->host_no));
374 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
375
376 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
377 break;
378
379 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
380 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
381 ha->host_no));
382 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
383
384 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
385 break;
386
387 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
388 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
389 ha->host_no));
390 break;
391
392 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
394 mb[1]));
395 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
396
397 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
398 atomic_set(&ha->loop_state, LOOP_DOWN);
399 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800400 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
402
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700403 if (ha->parent) {
404 atomic_set(&ha->vp_state, VP_FAILED);
405 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
406 }
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
409
410 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 break;
412
413 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
415 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700416 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700418 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 if (mb[1] < 5)
420 link_speed = link_speeds[mb[1]];
421 ha->link_data_rate = mb[1];
422 }
423
424 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
425 ha->host_no, link_speed));
426 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
427 link_speed);
428
429 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 break;
431
432 case MBA_LOOP_DOWN: /* Loop Down Event */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700433 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
434 ha->host_no, mb[1]));
435 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
438 atomic_set(&ha->loop_state, LOOP_DOWN);
439 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
440 ha->device_flags |= DFLG_NO_CABLE;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800441 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 }
443
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700444 if (ha->parent) {
445 atomic_set(&ha->vp_state, VP_FAILED);
446 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
447 }
448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 ha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700450 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Andrew Vasquezcca53352005-08-26 19:08:30 -0700451 if (ql2xfdmienable)
452 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 break;
454
455 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
457 ha->host_no, mb[1]));
458 qla_printk(KERN_INFO, ha,
459 "LIP reset occured (%x).\n", mb[1]);
460
461 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
462 atomic_set(&ha->loop_state, LOOP_DOWN);
463 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800464 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 }
466
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700467 if (ha->parent) {
468 atomic_set(&ha->vp_state, VP_FAILED);
469 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
470 }
471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
473
474 ha->operating_mode = LOOP;
475 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 break;
477
478 case MBA_POINT_TO_POINT: /* Point-to-Point */
479 if (IS_QLA2100(ha))
480 break;
481
482 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
483 ha->host_no));
484
485 /*
486 * Until there's a transition from loop down to loop up, treat
487 * this as loop down only.
488 */
489 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
490 atomic_set(&ha->loop_state, LOOP_DOWN);
491 if (!atomic_read(&ha->loop_down_timer))
492 atomic_set(&ha->loop_down_timer,
493 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800494 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
496
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700497 if (ha->parent) {
498 atomic_set(&ha->vp_state, VP_FAILED);
499 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
500 }
501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
503 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
504 }
505 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800506
507 ha->flags.gpsc_supported = 1;
Andrew Vasquez02d638b2007-08-12 18:22:54 -0700508 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 break;
510
511 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
512 if (IS_QLA2100(ha))
513 break;
514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
516 "received.\n",
517 ha->host_no));
518 qla_printk(KERN_INFO, ha,
519 "Configuration change detected: value=%x.\n", mb[1]);
520
521 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700522 atomic_set(&ha->loop_state, LOOP_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 if (!atomic_read(&ha->loop_down_timer))
524 atomic_set(&ha->loop_down_timer,
525 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800526 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 }
528
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700529 if (ha->parent) {
530 atomic_set(&ha->vp_state, VP_FAILED);
531 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
532 }
533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
535 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
536 break;
537
538 case MBA_PORT_UPDATE: /* Port database update */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
541 * event etc. earlier indicating loop is down) then process
542 * it. Otherwise ignore it and Wait for RSCN to come in.
543 */
544 atomic_set(&ha->loop_down_timer, 0);
545 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
546 atomic_read(&ha->loop_state) != LOOP_DEAD) {
547 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700548 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
549 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 break;
551 }
552
553 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
554 ha->host_no));
555 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700556 "scsi(%ld): Port database changed %04x %04x %04x.\n",
557 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559 /*
560 * Mark all devices as missing so we will login again.
561 */
562 atomic_set(&ha->loop_state, LOOP_UP);
563
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800564 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 ha->flags.rscn_queue_overflow = 1;
567
568 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
569 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 break;
571
572 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700573 /* Check if the Vport has issued a SCR */
574 if (ha->parent && test_bit(VP_SCR_NEEDED, &ha->vp_flags))
575 break;
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800576 /* Only handle SCNs for our Vport index. */
577 if (ha->flags.npiv_supported && ha->vp_idx != mb[3])
578 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
581 ha->host_no));
582 DEBUG(printk(KERN_INFO
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800583 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
584 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 rscn_entry = (mb[1] << 16) | mb[2];
587 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
588 ha->d_id.b.al_pa;
589 if (rscn_entry == host_pid) {
590 DEBUG(printk(KERN_INFO
591 "scsi(%ld): Ignoring RSCN update to local host "
592 "port ID (%06x)\n",
593 ha->host_no, host_pid));
594 break;
595 }
596
597 rscn_queue_index = ha->rscn_in_ptr + 1;
598 if (rscn_queue_index == MAX_RSCN_COUNT)
599 rscn_queue_index = 0;
600 if (rscn_queue_index != ha->rscn_out_ptr) {
601 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
602 ha->rscn_in_ptr = rscn_queue_index;
603 } else {
604 ha->flags.rscn_queue_overflow = 1;
605 }
606
607 atomic_set(&ha->loop_state, LOOP_UPDATE);
608 atomic_set(&ha->loop_down_timer, 0);
609 ha->flags.management_server_logged_in = 0;
610
611 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
612 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 break;
614
615 /* case MBA_RIO_RESPONSE: */
616 case MBA_ZIO_RESPONSE:
617 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
618 ha->host_no));
619 DEBUG(printk(KERN_INFO
620 "scsi(%ld): [R|Z]IO update completion.\n",
621 ha->host_no));
622
Andrew Vasqueze4289242007-07-19 15:05:56 -0700623 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700624 qla24xx_process_response_queue(ha);
625 else
626 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700628
629 case MBA_DISCARD_RND_FRAME:
630 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
631 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
632 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700633
634 case MBA_TRACE_NOTIFICATION:
635 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
636 ha->host_no, mb[1], mb[2]));
637 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700639
640 if (!ha->parent && ha->num_vhosts)
641 qla2x00_alert_all_vps(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642}
643
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700644static void
645qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
646{
647 fc_port_t *fcport = data;
648
649 if (fcport->ha->max_q_depth <= sdev->queue_depth)
650 return;
651
652 if (sdev->ordered_tags)
653 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
654 sdev->queue_depth + 1);
655 else
656 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
657 sdev->queue_depth + 1);
658
659 fcport->last_ramp_up = jiffies;
660
661 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
662 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
663 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
664 sdev->queue_depth));
665}
666
667static void
668qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
669{
670 fc_port_t *fcport = data;
671
672 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
673 return;
674
675 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
676 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
677 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
678 sdev->queue_depth));
679}
680
681static inline void
682qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
683{
684 fc_port_t *fcport;
685 struct scsi_device *sdev;
686
687 sdev = sp->cmd->device;
688 if (sdev->queue_depth >= ha->max_q_depth)
689 return;
690
691 fcport = sp->fcport;
692 if (time_before(jiffies,
693 fcport->last_ramp_up + ql2xqfullrampup * HZ))
694 return;
695 if (time_before(jiffies,
696 fcport->last_queue_full + ql2xqfullrampup * HZ))
697 return;
698
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700699 starget_for_each_device(sdev->sdev_target, fcport,
700 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700701}
702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703/**
704 * qla2x00_process_completed_request() - Process a Fast Post response.
705 * @ha: SCSI driver HA context
706 * @index: SRB index
707 */
708static void
709qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
710{
711 srb_t *sp;
712
713 /* Validate handle. */
714 if (index >= MAX_OUTSTANDING_COMMANDS) {
715 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
716 ha->host_no, index));
717 qla_printk(KERN_WARNING, ha,
718 "Invalid SCSI completion handle %d.\n", index);
719
720 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
721 return;
722 }
723
724 sp = ha->outstanding_cmds[index];
725 if (sp) {
726 /* Free outstanding command slot. */
727 ha->outstanding_cmds[index] = NULL;
728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 CMD_COMPL_STATUS(sp->cmd) = 0L;
730 CMD_SCSI_STATUS(sp->cmd) = 0L;
731
732 /* Save ISP completion status */
733 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700734
735 qla2x00_ramp_up_queue_depth(ha, sp);
f4f051e2005-04-17 15:02:26 -0500736 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 } else {
738 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
739 ha->host_no));
740 qla_printk(KERN_WARNING, ha,
741 "Invalid ISP SCSI completion handle\n");
742
743 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
744 }
745}
746
747/**
748 * qla2x00_process_response_queue() - Process response queue entries.
749 * @ha: SCSI driver HA context
750 */
751void
752qla2x00_process_response_queue(struct scsi_qla_host *ha)
753{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700754 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 sts_entry_t *pkt;
756 uint16_t handle_cnt;
757 uint16_t cnt;
758
759 if (!ha->flags.online)
760 return;
761
762 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
763 pkt = (sts_entry_t *)ha->response_ring_ptr;
764
765 ha->rsp_ring_index++;
766 if (ha->rsp_ring_index == ha->response_q_length) {
767 ha->rsp_ring_index = 0;
768 ha->response_ring_ptr = ha->response_ring;
769 } else {
770 ha->response_ring_ptr++;
771 }
772
773 if (pkt->entry_status != 0) {
774 DEBUG3(printk(KERN_INFO
775 "scsi(%ld): Process error entry.\n", ha->host_no));
776
777 qla2x00_error_entry(ha, pkt);
778 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
779 wmb();
780 continue;
781 }
782
783 switch (pkt->entry_type) {
784 case STATUS_TYPE:
785 qla2x00_status_entry(ha, pkt);
786 break;
787 case STATUS_TYPE_21:
788 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
789 for (cnt = 0; cnt < handle_cnt; cnt++) {
790 qla2x00_process_completed_request(ha,
791 ((sts21_entry_t *)pkt)->handle[cnt]);
792 }
793 break;
794 case STATUS_TYPE_22:
795 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
796 for (cnt = 0; cnt < handle_cnt; cnt++) {
797 qla2x00_process_completed_request(ha,
798 ((sts22_entry_t *)pkt)->handle[cnt]);
799 }
800 break;
801 case STATUS_CONT_TYPE:
802 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
803 break;
804 case MS_IOCB_TYPE:
805 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
806 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 default:
808 /* Type Not Supported. */
809 DEBUG4(printk(KERN_WARNING
810 "scsi(%ld): Received unknown response pkt type %x "
811 "entry status=%x.\n",
812 ha->host_no, pkt->entry_type, pkt->entry_status));
813 break;
814 }
815 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
816 wmb();
817 }
818
819 /* Adjust ring index */
820 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
821}
822
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800823static inline void
824qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
825{
826 struct scsi_cmnd *cp = sp->cmd;
827
828 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
829 sense_len = SCSI_SENSE_BUFFERSIZE;
830
831 CMD_ACTUAL_SNSLEN(cp) = sense_len;
832 sp->request_sense_length = sense_len;
833 sp->request_sense_ptr = cp->sense_buffer;
834 if (sp->request_sense_length > 32)
835 sense_len = 32;
836
837 memcpy(cp->sense_buffer, sense_data, sense_len);
838
839 sp->request_sense_ptr += sense_len;
840 sp->request_sense_length -= sense_len;
841 if (sp->request_sense_length != 0)
842 sp->ha->status_srb = sp;
843
844 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
845 "cmd=%p pid=%ld\n", __func__, sp->ha->host_no, cp->device->channel,
846 cp->device->id, cp->device->lun, cp, cp->serial_number));
847 if (sense_len)
848 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
849 CMD_ACTUAL_SNSLEN(cp)));
850}
851
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852/**
853 * qla2x00_status_entry() - Process a Status IOCB entry.
854 * @ha: SCSI driver HA context
855 * @pkt: Entry pointer
856 */
857static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700858qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 fc_port_t *fcport;
862 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700863 sts_entry_t *sts;
864 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 uint16_t comp_status;
866 uint16_t scsi_status;
867 uint8_t lscsi_status;
868 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700869 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700870 uint8_t *rsp_info, *sense_data;
871
872 sts = (sts_entry_t *) pkt;
873 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700874 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700875 comp_status = le16_to_cpu(sts24->comp_status);
876 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
877 } else {
878 comp_status = le16_to_cpu(sts->comp_status);
879 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
880 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700883 if (comp_status == CS_COMPLETE && scsi_status == 0) {
884 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886 return;
887 }
888
889 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700890 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
891 sp = ha->outstanding_cmds[sts->handle];
892 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 } else
894 sp = NULL;
895
896 if (sp == NULL) {
897 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
898 ha->host_no));
899 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
900
901 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100902 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 return;
904 }
905 cp = sp->cmd;
906 if (cp == NULL) {
907 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700908 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 qla_printk(KERN_WARNING, ha,
910 "Command is NULL: already returned to OS (sp=%p)\n", sp);
911
912 return;
913 }
914
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700915 lscsi_status = scsi_status & STATUS_MASK;
916 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 CMD_COMPL_STATUS(cp) = comp_status;
918 CMD_SCSI_STATUS(cp) = scsi_status;
919
bdf79622005-04-17 15:06:53 -0500920 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Ravi Ananded17c71b52006-05-17 15:08:55 -0700922 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700923 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700924 sense_len = le32_to_cpu(sts24->sense_len);
925 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
926 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -0700927 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700928 rsp_info = sts24->data;
929 sense_data = sts24->data;
930 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
931 } else {
932 sense_len = le16_to_cpu(sts->req_sense_length);
933 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
934 resid_len = le32_to_cpu(sts->residual_length);
935 rsp_info = sts->rsp_info;
936 sense_data = sts->req_sense_data;
937 }
938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 /* Check for any FCP transport errors. */
940 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700941 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700942 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700943 sense_data += rsp_info_len;
944 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
946 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700947 "retrying command\n", ha->host_no,
948 cp->device->channel, cp->device->id,
949 cp->device->lun, rsp_info_len, rsp_info[0],
950 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
951 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
953 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500954 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 return;
956 }
957 }
958
Andrew Vasquez3e8ce322008-02-28 14:06:10 -0800959 /* Check for overrun. */
960 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
961 scsi_status & SS_RESIDUAL_OVER)
962 comp_status = CS_DATA_OVERRUN;
963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 /*
965 * Based on Host and scsi status generate status code for Linux
966 */
967 switch (comp_status) {
968 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700969 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 if (scsi_status == 0) {
971 cp->result = DID_OK << 16;
972 break;
973 }
974 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700975 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900976 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800978
979 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900980 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800981 cp->underflow)) {
982 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900983 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
984 "detected (%x of %x bytes)...returning "
985 "error status.\n", ha->host_no,
986 cp->device->channel, cp->device->id,
987 cp->device->lun, resid,
988 scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800989
990 cp->result = DID_ERROR << 16;
991 break;
992 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 cp->result = DID_OK << 16 | lscsi_status;
995
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700996 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
997 DEBUG2(printk(KERN_INFO
998 "scsi(%ld): QUEUE FULL status detected "
999 "0x%x-0x%x.\n", ha->host_no, comp_status,
1000 scsi_status));
1001
1002 /* Adjust queue depth for all luns on the port. */
1003 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001004 starget_for_each_device(cp->device->sdev_target,
1005 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001006 break;
1007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if (lscsi_status != SS_CHECK_CONDITION)
1009 break;
1010
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001011 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 if (!(scsi_status & SS_SENSE_LEN_VALID))
1013 break;
1014
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001015 qla2x00_handle_sense(sp, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 break;
1017
1018 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001019 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001020 /* Use F/W calculated residual length. */
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001021 if (IS_FWI2_CAPABLE(ha)) {
1022 if (scsi_status & SS_RESIDUAL_UNDER &&
1023 resid != fw_resid_len) {
1024 scsi_status &= ~SS_RESIDUAL_UNDER;
1025 lscsi_status = 0;
1026 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001027 resid = fw_resid_len;
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001028 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001029
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 if (scsi_status & SS_RESIDUAL_UNDER) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001031 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001033 } else {
1034 DEBUG2(printk(KERN_INFO
1035 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -07001036 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1037 "os_underflow=0x%x\n", ha->host_no,
1038 cp->device->id, cp->device->lun, comp_status,
1039 scsi_status, resid_len, resid, cp->cmnd[0],
1040 cp->underflow));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 }
1043
1044 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001045 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 * Status.
1047 */
1048 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 cp->result = DID_OK << 16 | lscsi_status;
1050
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001051 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1052 DEBUG2(printk(KERN_INFO
1053 "scsi(%ld): QUEUE FULL status detected "
1054 "0x%x-0x%x.\n", ha->host_no, comp_status,
1055 scsi_status));
1056
1057 /*
1058 * Adjust queue depth for all luns on the
1059 * port.
1060 */
1061 fcport->last_queue_full = jiffies;
1062 starget_for_each_device(
1063 cp->device->sdev_target, fcport,
1064 qla2x00_adjust_sdev_qdepth_down);
1065 break;
1066 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 if (lscsi_status != SS_CHECK_CONDITION)
1068 break;
1069
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001070 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 if (!(scsi_status & SS_SENSE_LEN_VALID))
1072 break;
1073
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001074 qla2x00_handle_sense(sp, sense_data, sense_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001075
Shyam Sundar8084fe12007-07-19 15:05:59 -07001076 /*
1077 * In case of a Underrun condition, set both the lscsi
1078 * status and the completion status to appropriate
1079 * values.
1080 */
1081 if (resid &&
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001082 ((unsigned)(scsi_bufflen(cp) - resid) <
Shyam Sundar8084fe12007-07-19 15:05:59 -07001083 cp->underflow)) {
1084 DEBUG2(qla_printk(KERN_INFO, ha,
1085 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1086 "detected (%x of %x bytes)...returning "
1087 "error status.\n", ha->host_no,
1088 cp->device->channel, cp->device->id,
1089 cp->device->lun, resid,
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001090 scsi_bufflen(cp)));
Shyam Sundar8084fe12007-07-19 15:05:59 -07001091
1092 cp->result = DID_ERROR << 16 | lscsi_status;
1093 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 } else {
1095 /*
1096 * If RISC reports underrun and target does not report
1097 * it then we must have a lost frame, so tell upper
1098 * layer to retry it by reporting a bus busy.
1099 */
1100 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1101 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001102 "frame(s) detected (%x of %x bytes)..."
1103 "retrying command.\n", ha->host_no,
1104 cp->device->channel, cp->device->id,
1105 cp->device->lun, resid,
1106 scsi_bufflen(cp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
1108 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 break;
1110 }
1111
1112 /* Handle mid-layer underflow */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001113 if ((unsigned)(scsi_bufflen(cp) - resid) <
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 cp->underflow) {
1115 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001116 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1117 "detected (%x of %x bytes)...returning "
1118 "error status.\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_ERROR << 16;
1124 break;
1125 }
1126
1127 /* Everybody online, looking good... */
1128 cp->result = DID_OK << 16;
1129 }
1130 break;
1131
1132 case CS_DATA_OVERRUN:
1133 DEBUG2(printk(KERN_INFO
1134 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001135 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1136 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 DEBUG2(printk(KERN_INFO
1138 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1139 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1140 cp->cmnd[4], cp->cmnd[5]));
1141 DEBUG2(printk(KERN_INFO
1142 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1143 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001144 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 cp->result = DID_ERROR << 16;
1147 break;
1148
1149 case CS_PORT_LOGGED_OUT:
1150 case CS_PORT_CONFIG_CHG:
1151 case CS_PORT_BUSY:
1152 case CS_INCOMPLETE:
1153 case CS_PORT_UNAVAILABLE:
1154 /*
1155 * If the port is in Target Down state, return all IOs for this
1156 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1157 * retry_queue.
1158 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1160 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001161 ha->host_no, cp->device->id, cp->device->lun,
1162 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 atomic_read(&fcport->state)));
1164
f4f051e2005-04-17 15:02:26 -05001165 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001167 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 break;
1170
1171 case CS_RESET:
1172 DEBUG2(printk(KERN_INFO
1173 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1174 ha->host_no, comp_status, scsi_status));
1175
f4f051e2005-04-17 15:02:26 -05001176 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 break;
1178
1179 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001180 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 * hv2.19.12 - DID_ABORT does not retry the request if we
1182 * aborted this request then abort otherwise it must be a
1183 * reset.
1184 */
1185 DEBUG2(printk(KERN_INFO
1186 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1187 ha->host_no, comp_status, scsi_status));
1188
1189 cp->result = DID_RESET << 16;
1190 break;
1191
1192 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 cp->result = DID_BUS_BUSY << 16;
1194
Andrew Vasqueze4289242007-07-19 15:05:56 -07001195 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001196 DEBUG2(printk(KERN_INFO
1197 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1198 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1199 cp->device->id, cp->device->lun, comp_status,
1200 scsi_status));
1201 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001203 DEBUG2(printk(KERN_INFO
1204 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1205 "sflags=%x.\n", ha->host_no, cp->device->channel,
1206 cp->device->id, cp->device->lun, comp_status, scsi_status,
1207 le16_to_cpu(sts->status_flags)));
1208
1209 /* Check to see if logout occurred. */
1210 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001211 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 break;
1213
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 default:
1215 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001216 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 qla_printk(KERN_INFO, ha,
1218 "Unknown status detected 0x%x-0x%x.\n",
1219 comp_status, scsi_status);
1220
1221 cp->result = DID_ERROR << 16;
1222 break;
1223 }
1224
1225 /* Place command on done queue. */
1226 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001227 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
1230/**
1231 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1232 * @ha: SCSI driver HA context
1233 * @pkt: Entry pointer
1234 *
1235 * Extended sense data.
1236 */
1237static void
1238qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1239{
1240 uint8_t sense_sz = 0;
1241 srb_t *sp = ha->status_srb;
1242 struct scsi_cmnd *cp;
1243
1244 if (sp != NULL && sp->request_sense_length != 0) {
1245 cp = sp->cmd;
1246 if (cp == NULL) {
1247 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001248 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 qla_printk(KERN_INFO, ha,
1250 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001251 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
1253 ha->status_srb = NULL;
1254 return;
1255 }
1256
1257 if (sp->request_sense_length > sizeof(pkt->data)) {
1258 sense_sz = sizeof(pkt->data);
1259 } else {
1260 sense_sz = sp->request_sense_length;
1261 }
1262
1263 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001264 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001265 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1267 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1268
1269 sp->request_sense_ptr += sense_sz;
1270 sp->request_sense_length -= sense_sz;
1271
1272 /* Place command on done queue. */
1273 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001275 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 }
1277 }
1278}
1279
1280/**
1281 * qla2x00_error_entry() - Process an error entry.
1282 * @ha: SCSI driver HA context
1283 * @pkt: Entry pointer
1284 */
1285static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001286qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287{
1288 srb_t *sp;
1289
1290#if defined(QL_DEBUG_LEVEL_2)
1291 if (pkt->entry_status & RF_INV_E_ORDER)
1292 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1293 else if (pkt->entry_status & RF_INV_E_COUNT)
1294 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1295 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001296 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 "%s: Invalid Entry Parameter\n", __func__);
1298 else if (pkt->entry_status & RF_INV_E_TYPE)
1299 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1300 else if (pkt->entry_status & RF_BUSY)
1301 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1302 else
1303 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1304#endif
1305
1306 /* Validate handle. */
1307 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1308 sp = ha->outstanding_cmds[pkt->handle];
1309 else
1310 sp = NULL;
1311
1312 if (sp) {
1313 /* Free outstanding command slot. */
1314 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001315
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 /* Bad payload or header */
1317 if (pkt->entry_status &
1318 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1319 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1320 sp->cmd->result = DID_ERROR << 16;
1321 } else if (pkt->entry_status & RF_BUSY) {
1322 sp->cmd->result = DID_BUS_BUSY << 16;
1323 } else {
1324 sp->cmd->result = DID_ERROR << 16;
1325 }
f4f051e2005-04-17 15:02:26 -05001326 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001328 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1329 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1331 ha->host_no));
1332 qla_printk(KERN_WARNING, ha,
1333 "Error entry - invalid handle\n");
1334
1335 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001336 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 }
1338}
1339
1340/**
1341 * qla2x00_ms_entry() - Process a Management Server entry.
1342 * @ha: SCSI driver HA context
1343 * @index: Response queue out pointer
1344 */
1345static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001346qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347{
1348 srb_t *sp;
1349
1350 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1351 __func__, ha->host_no, pkt, pkt->handle1));
1352
1353 /* Validate handle. */
1354 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1355 sp = ha->outstanding_cmds[pkt->handle1];
1356 else
1357 sp = NULL;
1358
1359 if (sp == NULL) {
1360 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1361 ha->host_no));
1362 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1363
1364 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1365 return;
1366 }
1367
1368 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1369 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1370
1371 /* Free outstanding command slot. */
1372 ha->outstanding_cmds[pkt->handle1] = NULL;
1373
f4f051e2005-04-17 15:02:26 -05001374 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375}
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001376
1377
1378/**
1379 * qla24xx_mbx_completion() - Process mailbox command completions.
1380 * @ha: SCSI driver HA context
1381 * @mb0: Mailbox0 register
1382 */
1383static void
1384qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1385{
1386 uint16_t cnt;
1387 uint16_t __iomem *wptr;
1388 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1389
1390 /* Load return mailbox registers. */
1391 ha->flags.mbox_int = 1;
1392 ha->mailbox_out[0] = mb0;
1393 wptr = (uint16_t __iomem *)&reg->mailbox1;
1394
1395 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1396 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1397 wptr++;
1398 }
1399
1400 if (ha->mcp) {
1401 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1402 __func__, ha->host_no, ha->mcp->mb[0]));
1403 } else {
1404 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1405 __func__, ha->host_no));
1406 }
1407}
1408
1409/**
1410 * qla24xx_process_response_queue() - Process response queue entries.
1411 * @ha: SCSI driver HA context
1412 */
1413void
1414qla24xx_process_response_queue(struct scsi_qla_host *ha)
1415{
1416 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1417 struct sts_entry_24xx *pkt;
1418
1419 if (!ha->flags.online)
1420 return;
1421
1422 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1423 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1424
1425 ha->rsp_ring_index++;
1426 if (ha->rsp_ring_index == ha->response_q_length) {
1427 ha->rsp_ring_index = 0;
1428 ha->response_ring_ptr = ha->response_ring;
1429 } else {
1430 ha->response_ring_ptr++;
1431 }
1432
1433 if (pkt->entry_status != 0) {
1434 DEBUG3(printk(KERN_INFO
1435 "scsi(%ld): Process error entry.\n", ha->host_no));
1436
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001437 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1438 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1439 wmb();
1440 continue;
1441 }
1442
1443 switch (pkt->entry_type) {
1444 case STATUS_TYPE:
1445 qla2x00_status_entry(ha, pkt);
1446 break;
1447 case STATUS_CONT_TYPE:
1448 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1449 break;
1450 case MS_IOCB_TYPE:
1451 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1452 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001453 case VP_RPT_ID_IOCB_TYPE:
1454 qla24xx_report_id_acquisition(ha,
1455 (struct vp_rpt_id_entry_24xx *)pkt);
1456 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001457 default:
1458 /* Type Not Supported. */
1459 DEBUG4(printk(KERN_WARNING
1460 "scsi(%ld): Received unknown response pkt type %x "
1461 "entry status=%x.\n",
1462 ha->host_no, pkt->entry_type, pkt->entry_status));
1463 break;
1464 }
1465 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1466 wmb();
1467 }
1468
1469 /* Adjust ring index */
1470 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1471}
1472
Andrew Vasquez05236a02007-09-20 14:07:37 -07001473static void
1474qla2xxx_check_risc_status(scsi_qla_host_t *ha)
1475{
1476 int rval;
1477 uint32_t cnt;
1478 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1479
1480 if (!IS_QLA25XX(ha))
1481 return;
1482
1483 rval = QLA_SUCCESS;
1484 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1485 RD_REG_DWORD(&reg->iobase_addr);
1486 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1487 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1488 rval == QLA_SUCCESS; cnt--) {
1489 if (cnt) {
1490 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1491 udelay(10);
1492 } else
1493 rval = QLA_FUNCTION_TIMEOUT;
1494 }
1495 if (rval == QLA_SUCCESS)
1496 goto next_test;
1497
1498 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1499 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1500 rval == QLA_SUCCESS; cnt--) {
1501 if (cnt) {
1502 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1503 udelay(10);
1504 } else
1505 rval = QLA_FUNCTION_TIMEOUT;
1506 }
1507 if (rval != QLA_SUCCESS)
1508 goto done;
1509
1510next_test:
1511 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1512 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1513
1514done:
1515 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1516 RD_REG_DWORD(&reg->iobase_window);
1517}
1518
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001519/**
1520 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1521 * @irq:
1522 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001523 *
1524 * Called by system whenever the host adapter generates an interrupt.
1525 *
1526 * Returns handled flag.
1527 */
1528irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001529qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001530{
1531 scsi_qla_host_t *ha;
1532 struct device_reg_24xx __iomem *reg;
1533 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001534 unsigned long iter;
1535 uint32_t stat;
1536 uint32_t hccr;
1537 uint16_t mb[4];
1538
1539 ha = (scsi_qla_host_t *) dev_id;
1540 if (!ha) {
1541 printk(KERN_INFO
1542 "%s(): NULL host pointer\n", __func__);
1543 return IRQ_NONE;
1544 }
1545
1546 reg = &ha->iobase->isp24;
1547 status = 0;
1548
Andrew Vasquezc6952482008-04-03 13:13:17 -07001549 spin_lock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001550 for (iter = 50; iter--; ) {
1551 stat = RD_REG_DWORD(&reg->host_status);
1552 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001553 if (pci_channel_offline(ha->pdev))
1554 break;
1555
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001556 hccr = RD_REG_DWORD(&reg->hccr);
1557
1558 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1559 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001560
1561 qla2xxx_check_risc_status(ha);
1562
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001563 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001564 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1565 break;
1566 } else if ((stat & HSRX_RISC_INT) == 0)
1567 break;
1568
1569 switch (stat & 0xff) {
1570 case 0x1:
1571 case 0x2:
1572 case 0x10:
1573 case 0x11:
1574 qla24xx_mbx_completion(ha, MSW(stat));
1575 status |= MBX_INTERRUPT;
1576
1577 break;
1578 case 0x12:
1579 mb[0] = MSW(stat);
1580 mb[1] = RD_REG_WORD(&reg->mailbox1);
1581 mb[2] = RD_REG_WORD(&reg->mailbox2);
1582 mb[3] = RD_REG_WORD(&reg->mailbox3);
1583 qla2x00_async_event(ha, mb);
1584 break;
1585 case 0x13:
1586 qla24xx_process_response_queue(ha);
1587 break;
1588 default:
1589 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1590 "(%d).\n",
1591 ha->host_no, stat & 0xff));
1592 break;
1593 }
1594 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1595 RD_REG_DWORD_RELAXED(&reg->hccr);
1596 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001597 spin_unlock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001598
1599 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1600 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001601 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001602 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001603 }
1604
1605 return IRQ_HANDLED;
1606}
1607
1608/**
1609 * qla24xx_ms_entry() - Process a Management Server entry.
1610 * @ha: SCSI driver HA context
1611 * @index: Response queue out pointer
1612 */
1613static void
1614qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1615{
1616 srb_t *sp;
1617
1618 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1619 __func__, ha->host_no, pkt, pkt->handle));
1620
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001621 DEBUG9(printk("%s: ct pkt dump:\n", __func__));
1622 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx)));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001623
1624 /* Validate handle. */
1625 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1626 sp = ha->outstanding_cmds[pkt->handle];
1627 else
1628 sp = NULL;
1629
1630 if (sp == NULL) {
1631 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1632 ha->host_no));
1633 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1634 ha->host_no));
1635 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1636 pkt->handle);
1637
1638 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1639 return;
1640 }
1641
1642 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1643 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1644
1645 /* Free outstanding command slot. */
1646 ha->outstanding_cmds[pkt->handle] = NULL;
1647
1648 qla2x00_sp_compl(ha, sp);
1649}
1650
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001651static irqreturn_t
1652qla24xx_msix_rsp_q(int irq, void *dev_id)
1653{
1654 scsi_qla_host_t *ha;
1655 struct device_reg_24xx __iomem *reg;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001656
1657 ha = dev_id;
1658 reg = &ha->iobase->isp24;
1659
Andrew Vasquezc6952482008-04-03 13:13:17 -07001660 spin_lock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001661
1662 qla24xx_process_response_queue(ha);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001663 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001664
Andrew Vasquezc6952482008-04-03 13:13:17 -07001665 spin_unlock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001666
1667 return IRQ_HANDLED;
1668}
1669
1670static irqreturn_t
1671qla24xx_msix_default(int irq, void *dev_id)
1672{
1673 scsi_qla_host_t *ha;
1674 struct device_reg_24xx __iomem *reg;
1675 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001676 uint32_t stat;
1677 uint32_t hccr;
1678 uint16_t mb[4];
1679
1680 ha = dev_id;
1681 reg = &ha->iobase->isp24;
1682 status = 0;
1683
Andrew Vasquezc6952482008-04-03 13:13:17 -07001684 spin_lock(&ha->hardware_lock);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001685 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001686 stat = RD_REG_DWORD(&reg->host_status);
1687 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001688 if (pci_channel_offline(ha->pdev))
1689 break;
1690
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001691 hccr = RD_REG_DWORD(&reg->hccr);
1692
1693 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1694 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001695
1696 qla2xxx_check_risc_status(ha);
1697
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001698 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001699 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1700 break;
1701 } else if ((stat & HSRX_RISC_INT) == 0)
1702 break;
1703
1704 switch (stat & 0xff) {
1705 case 0x1:
1706 case 0x2:
1707 case 0x10:
1708 case 0x11:
1709 qla24xx_mbx_completion(ha, MSW(stat));
1710 status |= MBX_INTERRUPT;
1711
1712 break;
1713 case 0x12:
1714 mb[0] = MSW(stat);
1715 mb[1] = RD_REG_WORD(&reg->mailbox1);
1716 mb[2] = RD_REG_WORD(&reg->mailbox2);
1717 mb[3] = RD_REG_WORD(&reg->mailbox3);
1718 qla2x00_async_event(ha, mb);
1719 break;
1720 case 0x13:
1721 qla24xx_process_response_queue(ha);
1722 break;
1723 default:
1724 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1725 "(%d).\n",
1726 ha->host_no, stat & 0xff));
1727 break;
1728 }
1729 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001730 } while (0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07001731 spin_unlock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001732
1733 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1734 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001735 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001736 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001737 }
1738
1739 return IRQ_HANDLED;
1740}
1741
1742/* Interrupt handling helpers. */
1743
1744struct qla_init_msix_entry {
1745 uint16_t entry;
1746 uint16_t index;
1747 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001748 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001749};
1750
1751static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1752 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1753 "qla2xxx (default)", qla24xx_msix_default },
1754
1755 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1756 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1757};
1758
1759static void
1760qla24xx_disable_msix(scsi_qla_host_t *ha)
1761{
1762 int i;
1763 struct qla_msix_entry *qentry;
1764
1765 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1766 qentry = &ha->msix_entries[imsix_entries[i].index];
1767 if (qentry->have_irq)
1768 free_irq(qentry->msix_vector, ha);
1769 }
1770 pci_disable_msix(ha->pdev);
1771}
1772
1773static int
1774qla24xx_enable_msix(scsi_qla_host_t *ha)
1775{
1776 int i, ret;
1777 struct msix_entry entries[QLA_MSIX_ENTRIES];
1778 struct qla_msix_entry *qentry;
1779
1780 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1781 entries[i].entry = imsix_entries[i].entry;
1782
1783 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1784 if (ret) {
1785 qla_printk(KERN_WARNING, ha,
1786 "MSI-X: Failed to enable support -- %d/%d\n",
1787 QLA_MSIX_ENTRIES, ret);
1788 goto msix_out;
1789 }
1790 ha->flags.msix_enabled = 1;
1791
1792 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1793 qentry = &ha->msix_entries[imsix_entries[i].index];
1794 qentry->msix_vector = entries[i].vector;
1795 qentry->msix_entry = entries[i].entry;
1796 qentry->have_irq = 0;
1797 ret = request_irq(qentry->msix_vector,
1798 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1799 if (ret) {
1800 qla_printk(KERN_WARNING, ha,
1801 "MSI-X: Unable to register handler -- %x/%d.\n",
1802 imsix_entries[i].index, ret);
1803 qla24xx_disable_msix(ha);
1804 goto msix_out;
1805 }
1806 qentry->have_irq = 1;
1807 }
1808
1809msix_out:
1810 return ret;
1811}
1812
1813int
1814qla2x00_request_irqs(scsi_qla_host_t *ha)
1815{
1816 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001817 device_reg_t __iomem *reg = ha->iobase;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001818
1819 /* If possible, enable MSI-X. */
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001820 if (!IS_QLA2432(ha) && !IS_QLA2532(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001821 goto skip_msix;
1822
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001823 if (IS_QLA2432(ha) && (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1824 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001825 DEBUG2(qla_printk(KERN_WARNING, ha,
1826 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1827 ha->chip_revision, ha->fw_attributes));
1828
1829 goto skip_msix;
1830 }
1831
Andrew Vasquezda7429f2008-01-17 09:02:11 -08001832 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1833 (ha->pdev->subsystem_device == 0x7040 ||
1834 ha->pdev->subsystem_device == 0x7041 ||
1835 ha->pdev->subsystem_device == 0x1705)) {
1836 DEBUG2(qla_printk(KERN_WARNING, ha,
1837 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1838 ha->pdev->subsystem_vendor,
1839 ha->pdev->subsystem_device));
1840
1841 goto skip_msi;
1842 }
1843
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001844 ret = qla24xx_enable_msix(ha);
1845 if (!ret) {
1846 DEBUG2(qla_printk(KERN_INFO, ha,
1847 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1848 ha->fw_attributes));
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001849 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001850 }
1851 qla_printk(KERN_WARNING, ha,
1852 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1853skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001854
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001855 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001856 goto skip_msi;
1857
1858 ret = pci_enable_msi(ha->pdev);
1859 if (!ret) {
1860 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1861 ha->flags.msi_enabled = 1;
1862 }
1863skip_msi:
1864
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001865 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001866 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001867 if (ret) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001868 qla_printk(KERN_WARNING, ha,
1869 "Failed to reserve interrupt %d already in use.\n",
1870 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001871 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001872 }
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001873 ha->flags.inta_enabled = 1;
1874 ha->host->irq = ha->pdev->irq;
1875clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001876
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001877 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezc6952482008-04-03 13:13:17 -07001878 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001879 if (IS_FWI2_CAPABLE(ha)) {
1880 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1881 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1882 } else {
1883 WRT_REG_WORD(&reg->isp.semaphore, 0);
1884 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1885 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
1886 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001887 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001888 ha->isp_ops->enable_intrs(ha);
1889
1890fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001891 return ret;
1892}
1893
1894void
1895qla2x00_free_irqs(scsi_qla_host_t *ha)
1896{
1897
1898 if (ha->flags.msix_enabled)
1899 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001900 else if (ha->flags.inta_enabled) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001901 free_irq(ha->host->irq, ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001902 pci_disable_msi(ha->pdev);
1903 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001904}