blob: e9d8a79dd6a41163a98ff82504620f86ba030795 [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;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700411 qla2x00_post_aen_work(ha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 break;
413
414 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
416 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700417 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700419 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 if (mb[1] < 5)
421 link_speed = link_speeds[mb[1]];
422 ha->link_data_rate = mb[1];
423 }
424
425 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
426 ha->host_no, link_speed));
427 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
428 link_speed);
429
430 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700431 qla2x00_post_aen_work(ha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 break;
433
434 case MBA_LOOP_DOWN: /* Loop Down Event */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700435 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
436 ha->host_no, mb[1]));
437 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
440 atomic_set(&ha->loop_state, LOOP_DOWN);
441 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
442 ha->device_flags |= DFLG_NO_CABLE;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800443 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 }
445
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700446 if (ha->parent) {
447 atomic_set(&ha->vp_state, VP_FAILED);
448 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
449 }
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 ha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700452 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Andrew Vasquezcca53352005-08-26 19:08:30 -0700453 if (ql2xfdmienable)
454 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -0700455 qla2x00_post_aen_work(ha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 break;
457
458 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
460 ha->host_no, mb[1]));
461 qla_printk(KERN_INFO, ha,
462 "LIP reset occured (%x).\n", mb[1]);
463
464 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
465 atomic_set(&ha->loop_state, LOOP_DOWN);
466 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800467 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 }
469
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700470 if (ha->parent) {
471 atomic_set(&ha->vp_state, VP_FAILED);
472 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
473 }
474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
476
477 ha->operating_mode = LOOP;
478 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700479 qla2x00_post_aen_work(ha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 break;
481
482 case MBA_POINT_TO_POINT: /* Point-to-Point */
483 if (IS_QLA2100(ha))
484 break;
485
486 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
487 ha->host_no));
488
489 /*
490 * Until there's a transition from loop down to loop up, treat
491 * this as loop down only.
492 */
493 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
494 atomic_set(&ha->loop_state, LOOP_DOWN);
495 if (!atomic_read(&ha->loop_down_timer))
496 atomic_set(&ha->loop_down_timer,
497 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800498 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
500
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700501 if (ha->parent) {
502 atomic_set(&ha->vp_state, VP_FAILED);
503 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
504 }
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
507 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
508 }
509 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800510
511 ha->flags.gpsc_supported = 1;
Andrew Vasquez02d638b2007-08-12 18:22:54 -0700512 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 break;
514
515 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
516 if (IS_QLA2100(ha))
517 break;
518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
520 "received.\n",
521 ha->host_no));
522 qla_printk(KERN_INFO, ha,
523 "Configuration change detected: value=%x.\n", mb[1]);
524
525 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700526 atomic_set(&ha->loop_state, LOOP_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 if (!atomic_read(&ha->loop_down_timer))
528 atomic_set(&ha->loop_down_timer,
529 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800530 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 }
532
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700533 if (ha->parent) {
534 atomic_set(&ha->vp_state, VP_FAILED);
535 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
536 }
537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
539 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
540 break;
541
542 case MBA_PORT_UPDATE: /* Port database update */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
545 * event etc. earlier indicating loop is down) then process
546 * it. Otherwise ignore it and Wait for RSCN to come in.
547 */
548 atomic_set(&ha->loop_down_timer, 0);
549 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
550 atomic_read(&ha->loop_state) != LOOP_DEAD) {
551 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700552 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
553 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 break;
555 }
556
557 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
558 ha->host_no));
559 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700560 "scsi(%ld): Port database changed %04x %04x %04x.\n",
561 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 /*
564 * Mark all devices as missing so we will login again.
565 */
566 atomic_set(&ha->loop_state, LOOP_UP);
567
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800568 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 ha->flags.rscn_queue_overflow = 1;
571
572 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
573 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 break;
575
576 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700577 /* Check if the Vport has issued a SCR */
578 if (ha->parent && test_bit(VP_SCR_NEEDED, &ha->vp_flags))
579 break;
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800580 /* Only handle SCNs for our Vport index. */
581 if (ha->flags.npiv_supported && ha->vp_idx != mb[3])
582 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
585 ha->host_no));
586 DEBUG(printk(KERN_INFO
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800587 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
588 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 rscn_entry = (mb[1] << 16) | mb[2];
591 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
592 ha->d_id.b.al_pa;
593 if (rscn_entry == host_pid) {
594 DEBUG(printk(KERN_INFO
595 "scsi(%ld): Ignoring RSCN update to local host "
596 "port ID (%06x)\n",
597 ha->host_no, host_pid));
598 break;
599 }
600
601 rscn_queue_index = ha->rscn_in_ptr + 1;
602 if (rscn_queue_index == MAX_RSCN_COUNT)
603 rscn_queue_index = 0;
604 if (rscn_queue_index != ha->rscn_out_ptr) {
605 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
606 ha->rscn_in_ptr = rscn_queue_index;
607 } else {
608 ha->flags.rscn_queue_overflow = 1;
609 }
610
611 atomic_set(&ha->loop_state, LOOP_UPDATE);
612 atomic_set(&ha->loop_down_timer, 0);
613 ha->flags.management_server_logged_in = 0;
614
615 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
616 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -0700617 qla2x00_post_aen_work(ha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 break;
619
620 /* case MBA_RIO_RESPONSE: */
621 case MBA_ZIO_RESPONSE:
622 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
623 ha->host_no));
624 DEBUG(printk(KERN_INFO
625 "scsi(%ld): [R|Z]IO update completion.\n",
626 ha->host_no));
627
Andrew Vasqueze4289242007-07-19 15:05:56 -0700628 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700629 qla24xx_process_response_queue(ha);
630 else
631 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700633
634 case MBA_DISCARD_RND_FRAME:
635 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
636 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
637 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700638
639 case MBA_TRACE_NOTIFICATION:
640 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
641 ha->host_no, mb[1], mb[2]));
642 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700644
645 if (!ha->parent && ha->num_vhosts)
646 qla2x00_alert_all_vps(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
648
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700649static void
650qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
651{
652 fc_port_t *fcport = data;
653
654 if (fcport->ha->max_q_depth <= sdev->queue_depth)
655 return;
656
657 if (sdev->ordered_tags)
658 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
659 sdev->queue_depth + 1);
660 else
661 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
662 sdev->queue_depth + 1);
663
664 fcport->last_ramp_up = jiffies;
665
666 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
667 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
668 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
669 sdev->queue_depth));
670}
671
672static void
673qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
674{
675 fc_port_t *fcport = data;
676
677 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
678 return;
679
680 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
681 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
682 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
683 sdev->queue_depth));
684}
685
686static inline void
687qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
688{
689 fc_port_t *fcport;
690 struct scsi_device *sdev;
691
692 sdev = sp->cmd->device;
693 if (sdev->queue_depth >= ha->max_q_depth)
694 return;
695
696 fcport = sp->fcport;
697 if (time_before(jiffies,
698 fcport->last_ramp_up + ql2xqfullrampup * HZ))
699 return;
700 if (time_before(jiffies,
701 fcport->last_queue_full + ql2xqfullrampup * HZ))
702 return;
703
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700704 starget_for_each_device(sdev->sdev_target, fcport,
705 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700706}
707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708/**
709 * qla2x00_process_completed_request() - Process a Fast Post response.
710 * @ha: SCSI driver HA context
711 * @index: SRB index
712 */
713static void
714qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
715{
716 srb_t *sp;
717
718 /* Validate handle. */
719 if (index >= MAX_OUTSTANDING_COMMANDS) {
720 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
721 ha->host_no, index));
722 qla_printk(KERN_WARNING, ha,
723 "Invalid SCSI completion handle %d.\n", index);
724
725 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
726 return;
727 }
728
729 sp = ha->outstanding_cmds[index];
730 if (sp) {
731 /* Free outstanding command slot. */
732 ha->outstanding_cmds[index] = NULL;
733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 CMD_COMPL_STATUS(sp->cmd) = 0L;
735 CMD_SCSI_STATUS(sp->cmd) = 0L;
736
737 /* Save ISP completion status */
738 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700739
740 qla2x00_ramp_up_queue_depth(ha, sp);
f4f051e2005-04-17 15:02:26 -0500741 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 } else {
743 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
744 ha->host_no));
745 qla_printk(KERN_WARNING, ha,
746 "Invalid ISP SCSI completion handle\n");
747
748 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
749 }
750}
751
752/**
753 * qla2x00_process_response_queue() - Process response queue entries.
754 * @ha: SCSI driver HA context
755 */
756void
757qla2x00_process_response_queue(struct scsi_qla_host *ha)
758{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700759 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 sts_entry_t *pkt;
761 uint16_t handle_cnt;
762 uint16_t cnt;
763
764 if (!ha->flags.online)
765 return;
766
767 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
768 pkt = (sts_entry_t *)ha->response_ring_ptr;
769
770 ha->rsp_ring_index++;
771 if (ha->rsp_ring_index == ha->response_q_length) {
772 ha->rsp_ring_index = 0;
773 ha->response_ring_ptr = ha->response_ring;
774 } else {
775 ha->response_ring_ptr++;
776 }
777
778 if (pkt->entry_status != 0) {
779 DEBUG3(printk(KERN_INFO
780 "scsi(%ld): Process error entry.\n", ha->host_no));
781
782 qla2x00_error_entry(ha, pkt);
783 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
784 wmb();
785 continue;
786 }
787
788 switch (pkt->entry_type) {
789 case STATUS_TYPE:
790 qla2x00_status_entry(ha, pkt);
791 break;
792 case STATUS_TYPE_21:
793 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
794 for (cnt = 0; cnt < handle_cnt; cnt++) {
795 qla2x00_process_completed_request(ha,
796 ((sts21_entry_t *)pkt)->handle[cnt]);
797 }
798 break;
799 case STATUS_TYPE_22:
800 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
801 for (cnt = 0; cnt < handle_cnt; cnt++) {
802 qla2x00_process_completed_request(ha,
803 ((sts22_entry_t *)pkt)->handle[cnt]);
804 }
805 break;
806 case STATUS_CONT_TYPE:
807 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
808 break;
809 case MS_IOCB_TYPE:
810 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
811 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 default:
813 /* Type Not Supported. */
814 DEBUG4(printk(KERN_WARNING
815 "scsi(%ld): Received unknown response pkt type %x "
816 "entry status=%x.\n",
817 ha->host_no, pkt->entry_type, pkt->entry_status));
818 break;
819 }
820 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
821 wmb();
822 }
823
824 /* Adjust ring index */
825 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
826}
827
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800828static inline void
829qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
830{
831 struct scsi_cmnd *cp = sp->cmd;
832
833 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
834 sense_len = SCSI_SENSE_BUFFERSIZE;
835
836 CMD_ACTUAL_SNSLEN(cp) = sense_len;
837 sp->request_sense_length = sense_len;
838 sp->request_sense_ptr = cp->sense_buffer;
839 if (sp->request_sense_length > 32)
840 sense_len = 32;
841
842 memcpy(cp->sense_buffer, sense_data, sense_len);
843
844 sp->request_sense_ptr += sense_len;
845 sp->request_sense_length -= sense_len;
846 if (sp->request_sense_length != 0)
847 sp->ha->status_srb = sp;
848
849 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
850 "cmd=%p pid=%ld\n", __func__, sp->ha->host_no, cp->device->channel,
851 cp->device->id, cp->device->lun, cp, cp->serial_number));
852 if (sense_len)
853 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
854 CMD_ACTUAL_SNSLEN(cp)));
855}
856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857/**
858 * qla2x00_status_entry() - Process a Status IOCB entry.
859 * @ha: SCSI driver HA context
860 * @pkt: Entry pointer
861 */
862static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700863qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 fc_port_t *fcport;
867 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700868 sts_entry_t *sts;
869 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 uint16_t comp_status;
871 uint16_t scsi_status;
872 uint8_t lscsi_status;
873 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700874 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700875 uint8_t *rsp_info, *sense_data;
876
877 sts = (sts_entry_t *) pkt;
878 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700879 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700880 comp_status = le16_to_cpu(sts24->comp_status);
881 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
882 } else {
883 comp_status = le16_to_cpu(sts->comp_status);
884 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
885 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700888 if (comp_status == CS_COMPLETE && scsi_status == 0) {
889 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 return;
892 }
893
894 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700895 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
896 sp = ha->outstanding_cmds[sts->handle];
897 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 } else
899 sp = NULL;
900
901 if (sp == NULL) {
902 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
903 ha->host_no));
904 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
905
906 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100907 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 return;
909 }
910 cp = sp->cmd;
911 if (cp == NULL) {
912 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700913 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 qla_printk(KERN_WARNING, ha,
915 "Command is NULL: already returned to OS (sp=%p)\n", sp);
916
917 return;
918 }
919
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700920 lscsi_status = scsi_status & STATUS_MASK;
921 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 CMD_COMPL_STATUS(cp) = comp_status;
923 CMD_SCSI_STATUS(cp) = scsi_status;
924
bdf79622005-04-17 15:06:53 -0500925 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
Ravi Ananded17c71b52006-05-17 15:08:55 -0700927 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700928 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700929 sense_len = le32_to_cpu(sts24->sense_len);
930 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
931 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -0700932 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700933 rsp_info = sts24->data;
934 sense_data = sts24->data;
935 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
936 } else {
937 sense_len = le16_to_cpu(sts->req_sense_length);
938 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
939 resid_len = le32_to_cpu(sts->residual_length);
940 rsp_info = sts->rsp_info;
941 sense_data = sts->req_sense_data;
942 }
943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 /* Check for any FCP transport errors. */
945 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700946 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700947 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700948 sense_data += rsp_info_len;
949 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
951 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700952 "retrying command\n", ha->host_no,
953 cp->device->channel, cp->device->id,
954 cp->device->lun, rsp_info_len, rsp_info[0],
955 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
956 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
958 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500959 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 return;
961 }
962 }
963
Andrew Vasquez3e8ce322008-02-28 14:06:10 -0800964 /* Check for overrun. */
965 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
966 scsi_status & SS_RESIDUAL_OVER)
967 comp_status = CS_DATA_OVERRUN;
968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 /*
970 * Based on Host and scsi status generate status code for Linux
971 */
972 switch (comp_status) {
973 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700974 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 if (scsi_status == 0) {
976 cp->result = DID_OK << 16;
977 break;
978 }
979 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700980 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900981 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800983
984 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900985 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800986 cp->underflow)) {
987 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900988 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
989 "detected (%x of %x bytes)...returning "
990 "error status.\n", ha->host_no,
991 cp->device->channel, cp->device->id,
992 cp->device->lun, resid,
993 scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800994
995 cp->result = DID_ERROR << 16;
996 break;
997 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 cp->result = DID_OK << 16 | lscsi_status;
1000
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001001 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1002 DEBUG2(printk(KERN_INFO
1003 "scsi(%ld): QUEUE FULL status detected "
1004 "0x%x-0x%x.\n", ha->host_no, comp_status,
1005 scsi_status));
1006
1007 /* Adjust queue depth for all luns on the port. */
1008 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001009 starget_for_each_device(cp->device->sdev_target,
1010 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001011 break;
1012 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 if (lscsi_status != SS_CHECK_CONDITION)
1014 break;
1015
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001016 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 if (!(scsi_status & SS_SENSE_LEN_VALID))
1018 break;
1019
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001020 qla2x00_handle_sense(sp, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 break;
1022
1023 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001024 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001025 /* Use F/W calculated residual length. */
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001026 if (IS_FWI2_CAPABLE(ha)) {
1027 if (scsi_status & SS_RESIDUAL_UNDER &&
1028 resid != fw_resid_len) {
1029 scsi_status &= ~SS_RESIDUAL_UNDER;
1030 lscsi_status = 0;
1031 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001032 resid = fw_resid_len;
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001033 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001034
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 if (scsi_status & SS_RESIDUAL_UNDER) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001036 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001038 } else {
1039 DEBUG2(printk(KERN_INFO
1040 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -07001041 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1042 "os_underflow=0x%x\n", ha->host_no,
1043 cp->device->id, cp->device->lun, comp_status,
1044 scsi_status, resid_len, resid, cp->cmnd[0],
1045 cp->underflow));
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 }
1048
1049 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001050 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 * Status.
1052 */
1053 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 cp->result = DID_OK << 16 | lscsi_status;
1055
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001056 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1057 DEBUG2(printk(KERN_INFO
1058 "scsi(%ld): QUEUE FULL status detected "
1059 "0x%x-0x%x.\n", ha->host_no, comp_status,
1060 scsi_status));
1061
1062 /*
1063 * Adjust queue depth for all luns on the
1064 * port.
1065 */
1066 fcport->last_queue_full = jiffies;
1067 starget_for_each_device(
1068 cp->device->sdev_target, fcport,
1069 qla2x00_adjust_sdev_qdepth_down);
1070 break;
1071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 if (lscsi_status != SS_CHECK_CONDITION)
1073 break;
1074
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001075 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 if (!(scsi_status & SS_SENSE_LEN_VALID))
1077 break;
1078
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001079 qla2x00_handle_sense(sp, sense_data, sense_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001080
Shyam Sundar8084fe12007-07-19 15:05:59 -07001081 /*
1082 * In case of a Underrun condition, set both the lscsi
1083 * status and the completion status to appropriate
1084 * values.
1085 */
1086 if (resid &&
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001087 ((unsigned)(scsi_bufflen(cp) - resid) <
Shyam Sundar8084fe12007-07-19 15:05:59 -07001088 cp->underflow)) {
1089 DEBUG2(qla_printk(KERN_INFO, ha,
1090 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1091 "detected (%x of %x bytes)...returning "
1092 "error status.\n", ha->host_no,
1093 cp->device->channel, cp->device->id,
1094 cp->device->lun, resid,
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001095 scsi_bufflen(cp)));
Shyam Sundar8084fe12007-07-19 15:05:59 -07001096
1097 cp->result = DID_ERROR << 16 | lscsi_status;
1098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 } else {
1100 /*
1101 * If RISC reports underrun and target does not report
1102 * it then we must have a lost frame, so tell upper
1103 * layer to retry it by reporting a bus busy.
1104 */
1105 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1106 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001107 "frame(s) detected (%x of %x bytes)..."
1108 "retrying command.\n", ha->host_no,
1109 cp->device->channel, cp->device->id,
1110 cp->device->lun, resid,
1111 scsi_bufflen(cp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
1113 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 break;
1115 }
1116
1117 /* Handle mid-layer underflow */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001118 if ((unsigned)(scsi_bufflen(cp) - resid) <
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 cp->underflow) {
1120 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001121 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1122 "detected (%x of %x bytes)...returning "
1123 "error status.\n", ha->host_no,
1124 cp->device->channel, cp->device->id,
1125 cp->device->lun, resid,
1126 scsi_bufflen(cp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
1128 cp->result = DID_ERROR << 16;
1129 break;
1130 }
1131
1132 /* Everybody online, looking good... */
1133 cp->result = DID_OK << 16;
1134 }
1135 break;
1136
1137 case CS_DATA_OVERRUN:
1138 DEBUG2(printk(KERN_INFO
1139 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001140 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1141 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 DEBUG2(printk(KERN_INFO
1143 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1144 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1145 cp->cmnd[4], cp->cmnd[5]));
1146 DEBUG2(printk(KERN_INFO
1147 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1148 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001149 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 cp->result = DID_ERROR << 16;
1152 break;
1153
1154 case CS_PORT_LOGGED_OUT:
1155 case CS_PORT_CONFIG_CHG:
1156 case CS_PORT_BUSY:
1157 case CS_INCOMPLETE:
1158 case CS_PORT_UNAVAILABLE:
1159 /*
1160 * If the port is in Target Down state, return all IOs for this
1161 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1162 * retry_queue.
1163 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1165 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001166 ha->host_no, cp->device->id, cp->device->lun,
1167 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 atomic_read(&fcport->state)));
1169
f4f051e2005-04-17 15:02:26 -05001170 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001172 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 break;
1175
1176 case CS_RESET:
1177 DEBUG2(printk(KERN_INFO
1178 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1179 ha->host_no, comp_status, scsi_status));
1180
f4f051e2005-04-17 15:02:26 -05001181 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 break;
1183
1184 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001185 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 * hv2.19.12 - DID_ABORT does not retry the request if we
1187 * aborted this request then abort otherwise it must be a
1188 * reset.
1189 */
1190 DEBUG2(printk(KERN_INFO
1191 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1192 ha->host_no, comp_status, scsi_status));
1193
1194 cp->result = DID_RESET << 16;
1195 break;
1196
1197 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 cp->result = DID_BUS_BUSY << 16;
1199
Andrew Vasqueze4289242007-07-19 15:05:56 -07001200 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001201 DEBUG2(printk(KERN_INFO
1202 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1203 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1204 cp->device->id, cp->device->lun, comp_status,
1205 scsi_status));
1206 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001208 DEBUG2(printk(KERN_INFO
1209 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1210 "sflags=%x.\n", ha->host_no, cp->device->channel,
1211 cp->device->id, cp->device->lun, comp_status, scsi_status,
1212 le16_to_cpu(sts->status_flags)));
1213
1214 /* Check to see if logout occurred. */
1215 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001216 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 break;
1218
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 default:
1220 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001221 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 qla_printk(KERN_INFO, ha,
1223 "Unknown status detected 0x%x-0x%x.\n",
1224 comp_status, scsi_status);
1225
1226 cp->result = DID_ERROR << 16;
1227 break;
1228 }
1229
1230 /* Place command on done queue. */
1231 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001232 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233}
1234
1235/**
1236 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1237 * @ha: SCSI driver HA context
1238 * @pkt: Entry pointer
1239 *
1240 * Extended sense data.
1241 */
1242static void
1243qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1244{
1245 uint8_t sense_sz = 0;
1246 srb_t *sp = ha->status_srb;
1247 struct scsi_cmnd *cp;
1248
1249 if (sp != NULL && sp->request_sense_length != 0) {
1250 cp = sp->cmd;
1251 if (cp == NULL) {
1252 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001253 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 qla_printk(KERN_INFO, ha,
1255 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001256 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
1258 ha->status_srb = NULL;
1259 return;
1260 }
1261
1262 if (sp->request_sense_length > sizeof(pkt->data)) {
1263 sense_sz = sizeof(pkt->data);
1264 } else {
1265 sense_sz = sp->request_sense_length;
1266 }
1267
1268 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001269 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001270 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1272 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1273
1274 sp->request_sense_ptr += sense_sz;
1275 sp->request_sense_length -= sense_sz;
1276
1277 /* Place command on done queue. */
1278 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001280 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 }
1282 }
1283}
1284
1285/**
1286 * qla2x00_error_entry() - Process an error entry.
1287 * @ha: SCSI driver HA context
1288 * @pkt: Entry pointer
1289 */
1290static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001291qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
1293 srb_t *sp;
1294
1295#if defined(QL_DEBUG_LEVEL_2)
1296 if (pkt->entry_status & RF_INV_E_ORDER)
1297 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1298 else if (pkt->entry_status & RF_INV_E_COUNT)
1299 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1300 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001301 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 "%s: Invalid Entry Parameter\n", __func__);
1303 else if (pkt->entry_status & RF_INV_E_TYPE)
1304 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1305 else if (pkt->entry_status & RF_BUSY)
1306 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1307 else
1308 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1309#endif
1310
1311 /* Validate handle. */
1312 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1313 sp = ha->outstanding_cmds[pkt->handle];
1314 else
1315 sp = NULL;
1316
1317 if (sp) {
1318 /* Free outstanding command slot. */
1319 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001320
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 /* Bad payload or header */
1322 if (pkt->entry_status &
1323 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1324 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1325 sp->cmd->result = DID_ERROR << 16;
1326 } else if (pkt->entry_status & RF_BUSY) {
1327 sp->cmd->result = DID_BUS_BUSY << 16;
1328 } else {
1329 sp->cmd->result = DID_ERROR << 16;
1330 }
f4f051e2005-04-17 15:02:26 -05001331 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001333 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1334 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1336 ha->host_no));
1337 qla_printk(KERN_WARNING, ha,
1338 "Error entry - invalid handle\n");
1339
1340 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001341 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 }
1343}
1344
1345/**
1346 * qla2x00_ms_entry() - Process a Management Server entry.
1347 * @ha: SCSI driver HA context
1348 * @index: Response queue out pointer
1349 */
1350static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001351qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
1353 srb_t *sp;
1354
1355 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1356 __func__, ha->host_no, pkt, pkt->handle1));
1357
1358 /* Validate handle. */
1359 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1360 sp = ha->outstanding_cmds[pkt->handle1];
1361 else
1362 sp = NULL;
1363
1364 if (sp == NULL) {
1365 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1366 ha->host_no));
1367 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1368
1369 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1370 return;
1371 }
1372
1373 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1374 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1375
1376 /* Free outstanding command slot. */
1377 ha->outstanding_cmds[pkt->handle1] = NULL;
1378
f4f051e2005-04-17 15:02:26 -05001379 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380}
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001381
1382
1383/**
1384 * qla24xx_mbx_completion() - Process mailbox command completions.
1385 * @ha: SCSI driver HA context
1386 * @mb0: Mailbox0 register
1387 */
1388static void
1389qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1390{
1391 uint16_t cnt;
1392 uint16_t __iomem *wptr;
1393 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1394
1395 /* Load return mailbox registers. */
1396 ha->flags.mbox_int = 1;
1397 ha->mailbox_out[0] = mb0;
1398 wptr = (uint16_t __iomem *)&reg->mailbox1;
1399
1400 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1401 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1402 wptr++;
1403 }
1404
1405 if (ha->mcp) {
1406 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1407 __func__, ha->host_no, ha->mcp->mb[0]));
1408 } else {
1409 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1410 __func__, ha->host_no));
1411 }
1412}
1413
1414/**
1415 * qla24xx_process_response_queue() - Process response queue entries.
1416 * @ha: SCSI driver HA context
1417 */
1418void
1419qla24xx_process_response_queue(struct scsi_qla_host *ha)
1420{
1421 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1422 struct sts_entry_24xx *pkt;
1423
1424 if (!ha->flags.online)
1425 return;
1426
1427 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1428 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1429
1430 ha->rsp_ring_index++;
1431 if (ha->rsp_ring_index == ha->response_q_length) {
1432 ha->rsp_ring_index = 0;
1433 ha->response_ring_ptr = ha->response_ring;
1434 } else {
1435 ha->response_ring_ptr++;
1436 }
1437
1438 if (pkt->entry_status != 0) {
1439 DEBUG3(printk(KERN_INFO
1440 "scsi(%ld): Process error entry.\n", ha->host_no));
1441
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001442 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1443 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1444 wmb();
1445 continue;
1446 }
1447
1448 switch (pkt->entry_type) {
1449 case STATUS_TYPE:
1450 qla2x00_status_entry(ha, pkt);
1451 break;
1452 case STATUS_CONT_TYPE:
1453 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1454 break;
1455 case MS_IOCB_TYPE:
1456 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1457 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001458 case VP_RPT_ID_IOCB_TYPE:
1459 qla24xx_report_id_acquisition(ha,
1460 (struct vp_rpt_id_entry_24xx *)pkt);
1461 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001462 default:
1463 /* Type Not Supported. */
1464 DEBUG4(printk(KERN_WARNING
1465 "scsi(%ld): Received unknown response pkt type %x "
1466 "entry status=%x.\n",
1467 ha->host_no, pkt->entry_type, pkt->entry_status));
1468 break;
1469 }
1470 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1471 wmb();
1472 }
1473
1474 /* Adjust ring index */
1475 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1476}
1477
Andrew Vasquez05236a02007-09-20 14:07:37 -07001478static void
1479qla2xxx_check_risc_status(scsi_qla_host_t *ha)
1480{
1481 int rval;
1482 uint32_t cnt;
1483 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1484
1485 if (!IS_QLA25XX(ha))
1486 return;
1487
1488 rval = QLA_SUCCESS;
1489 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1490 RD_REG_DWORD(&reg->iobase_addr);
1491 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1492 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1493 rval == QLA_SUCCESS; cnt--) {
1494 if (cnt) {
1495 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1496 udelay(10);
1497 } else
1498 rval = QLA_FUNCTION_TIMEOUT;
1499 }
1500 if (rval == QLA_SUCCESS)
1501 goto next_test;
1502
1503 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1504 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1505 rval == QLA_SUCCESS; cnt--) {
1506 if (cnt) {
1507 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1508 udelay(10);
1509 } else
1510 rval = QLA_FUNCTION_TIMEOUT;
1511 }
1512 if (rval != QLA_SUCCESS)
1513 goto done;
1514
1515next_test:
1516 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1517 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1518
1519done:
1520 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1521 RD_REG_DWORD(&reg->iobase_window);
1522}
1523
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001524/**
1525 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1526 * @irq:
1527 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001528 *
1529 * Called by system whenever the host adapter generates an interrupt.
1530 *
1531 * Returns handled flag.
1532 */
1533irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001534qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001535{
1536 scsi_qla_host_t *ha;
1537 struct device_reg_24xx __iomem *reg;
1538 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001539 unsigned long iter;
1540 uint32_t stat;
1541 uint32_t hccr;
1542 uint16_t mb[4];
1543
1544 ha = (scsi_qla_host_t *) dev_id;
1545 if (!ha) {
1546 printk(KERN_INFO
1547 "%s(): NULL host pointer\n", __func__);
1548 return IRQ_NONE;
1549 }
1550
1551 reg = &ha->iobase->isp24;
1552 status = 0;
1553
Andrew Vasquezc6952482008-04-03 13:13:17 -07001554 spin_lock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001555 for (iter = 50; iter--; ) {
1556 stat = RD_REG_DWORD(&reg->host_status);
1557 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001558 if (pci_channel_offline(ha->pdev))
1559 break;
1560
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001561 hccr = RD_REG_DWORD(&reg->hccr);
1562
1563 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1564 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001565
1566 qla2xxx_check_risc_status(ha);
1567
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001568 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001569 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1570 break;
1571 } else if ((stat & HSRX_RISC_INT) == 0)
1572 break;
1573
1574 switch (stat & 0xff) {
1575 case 0x1:
1576 case 0x2:
1577 case 0x10:
1578 case 0x11:
1579 qla24xx_mbx_completion(ha, MSW(stat));
1580 status |= MBX_INTERRUPT;
1581
1582 break;
1583 case 0x12:
1584 mb[0] = MSW(stat);
1585 mb[1] = RD_REG_WORD(&reg->mailbox1);
1586 mb[2] = RD_REG_WORD(&reg->mailbox2);
1587 mb[3] = RD_REG_WORD(&reg->mailbox3);
1588 qla2x00_async_event(ha, mb);
1589 break;
1590 case 0x13:
1591 qla24xx_process_response_queue(ha);
1592 break;
1593 default:
1594 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1595 "(%d).\n",
1596 ha->host_no, stat & 0xff));
1597 break;
1598 }
1599 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1600 RD_REG_DWORD_RELAXED(&reg->hccr);
1601 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001602 spin_unlock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001603
1604 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1605 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001606 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001607 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001608 }
1609
1610 return IRQ_HANDLED;
1611}
1612
1613/**
1614 * qla24xx_ms_entry() - Process a Management Server entry.
1615 * @ha: SCSI driver HA context
1616 * @index: Response queue out pointer
1617 */
1618static void
1619qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1620{
1621 srb_t *sp;
1622
1623 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1624 __func__, ha->host_no, pkt, pkt->handle));
1625
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001626 DEBUG9(printk("%s: ct pkt dump:\n", __func__));
1627 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx)));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001628
1629 /* Validate handle. */
1630 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1631 sp = ha->outstanding_cmds[pkt->handle];
1632 else
1633 sp = NULL;
1634
1635 if (sp == NULL) {
1636 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1637 ha->host_no));
1638 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1639 ha->host_no));
1640 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1641 pkt->handle);
1642
1643 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1644 return;
1645 }
1646
1647 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1648 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1649
1650 /* Free outstanding command slot. */
1651 ha->outstanding_cmds[pkt->handle] = NULL;
1652
1653 qla2x00_sp_compl(ha, sp);
1654}
1655
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001656static irqreturn_t
1657qla24xx_msix_rsp_q(int irq, void *dev_id)
1658{
1659 scsi_qla_host_t *ha;
1660 struct device_reg_24xx __iomem *reg;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001661
1662 ha = dev_id;
1663 reg = &ha->iobase->isp24;
1664
Andrew Vasquezc6952482008-04-03 13:13:17 -07001665 spin_lock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001666
1667 qla24xx_process_response_queue(ha);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001668 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001669
Andrew Vasquezc6952482008-04-03 13:13:17 -07001670 spin_unlock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001671
1672 return IRQ_HANDLED;
1673}
1674
1675static irqreturn_t
1676qla24xx_msix_default(int irq, void *dev_id)
1677{
1678 scsi_qla_host_t *ha;
1679 struct device_reg_24xx __iomem *reg;
1680 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001681 uint32_t stat;
1682 uint32_t hccr;
1683 uint16_t mb[4];
1684
1685 ha = dev_id;
1686 reg = &ha->iobase->isp24;
1687 status = 0;
1688
Andrew Vasquezc6952482008-04-03 13:13:17 -07001689 spin_lock(&ha->hardware_lock);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001690 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001691 stat = RD_REG_DWORD(&reg->host_status);
1692 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001693 if (pci_channel_offline(ha->pdev))
1694 break;
1695
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001696 hccr = RD_REG_DWORD(&reg->hccr);
1697
1698 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1699 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001700
1701 qla2xxx_check_risc_status(ha);
1702
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001703 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001704 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1705 break;
1706 } else if ((stat & HSRX_RISC_INT) == 0)
1707 break;
1708
1709 switch (stat & 0xff) {
1710 case 0x1:
1711 case 0x2:
1712 case 0x10:
1713 case 0x11:
1714 qla24xx_mbx_completion(ha, MSW(stat));
1715 status |= MBX_INTERRUPT;
1716
1717 break;
1718 case 0x12:
1719 mb[0] = MSW(stat);
1720 mb[1] = RD_REG_WORD(&reg->mailbox1);
1721 mb[2] = RD_REG_WORD(&reg->mailbox2);
1722 mb[3] = RD_REG_WORD(&reg->mailbox3);
1723 qla2x00_async_event(ha, mb);
1724 break;
1725 case 0x13:
1726 qla24xx_process_response_queue(ha);
1727 break;
1728 default:
1729 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1730 "(%d).\n",
1731 ha->host_no, stat & 0xff));
1732 break;
1733 }
1734 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001735 } while (0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07001736 spin_unlock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001737
1738 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1739 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001740 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001741 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001742 }
1743
1744 return IRQ_HANDLED;
1745}
1746
1747/* Interrupt handling helpers. */
1748
1749struct qla_init_msix_entry {
1750 uint16_t entry;
1751 uint16_t index;
1752 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001753 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001754};
1755
1756static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1757 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1758 "qla2xxx (default)", qla24xx_msix_default },
1759
1760 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1761 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1762};
1763
1764static void
1765qla24xx_disable_msix(scsi_qla_host_t *ha)
1766{
1767 int i;
1768 struct qla_msix_entry *qentry;
1769
1770 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1771 qentry = &ha->msix_entries[imsix_entries[i].index];
1772 if (qentry->have_irq)
1773 free_irq(qentry->msix_vector, ha);
1774 }
1775 pci_disable_msix(ha->pdev);
1776}
1777
1778static int
1779qla24xx_enable_msix(scsi_qla_host_t *ha)
1780{
1781 int i, ret;
1782 struct msix_entry entries[QLA_MSIX_ENTRIES];
1783 struct qla_msix_entry *qentry;
1784
1785 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1786 entries[i].entry = imsix_entries[i].entry;
1787
1788 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1789 if (ret) {
1790 qla_printk(KERN_WARNING, ha,
1791 "MSI-X: Failed to enable support -- %d/%d\n",
1792 QLA_MSIX_ENTRIES, ret);
1793 goto msix_out;
1794 }
1795 ha->flags.msix_enabled = 1;
1796
1797 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1798 qentry = &ha->msix_entries[imsix_entries[i].index];
1799 qentry->msix_vector = entries[i].vector;
1800 qentry->msix_entry = entries[i].entry;
1801 qentry->have_irq = 0;
1802 ret = request_irq(qentry->msix_vector,
1803 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1804 if (ret) {
1805 qla_printk(KERN_WARNING, ha,
1806 "MSI-X: Unable to register handler -- %x/%d.\n",
1807 imsix_entries[i].index, ret);
1808 qla24xx_disable_msix(ha);
1809 goto msix_out;
1810 }
1811 qentry->have_irq = 1;
1812 }
1813
1814msix_out:
1815 return ret;
1816}
1817
1818int
1819qla2x00_request_irqs(scsi_qla_host_t *ha)
1820{
1821 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001822 device_reg_t __iomem *reg = ha->iobase;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001823
1824 /* If possible, enable MSI-X. */
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001825 if (!IS_QLA2432(ha) && !IS_QLA2532(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001826 goto skip_msix;
1827
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001828 if (IS_QLA2432(ha) && (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1829 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001830 DEBUG2(qla_printk(KERN_WARNING, ha,
1831 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1832 ha->chip_revision, ha->fw_attributes));
1833
1834 goto skip_msix;
1835 }
1836
Andrew Vasquezda7429f2008-01-17 09:02:11 -08001837 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1838 (ha->pdev->subsystem_device == 0x7040 ||
1839 ha->pdev->subsystem_device == 0x7041 ||
1840 ha->pdev->subsystem_device == 0x1705)) {
1841 DEBUG2(qla_printk(KERN_WARNING, ha,
1842 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1843 ha->pdev->subsystem_vendor,
1844 ha->pdev->subsystem_device));
1845
1846 goto skip_msi;
1847 }
1848
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001849 ret = qla24xx_enable_msix(ha);
1850 if (!ret) {
1851 DEBUG2(qla_printk(KERN_INFO, ha,
1852 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1853 ha->fw_attributes));
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001854 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001855 }
1856 qla_printk(KERN_WARNING, ha,
1857 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1858skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001859
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001860 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001861 goto skip_msi;
1862
1863 ret = pci_enable_msi(ha->pdev);
1864 if (!ret) {
1865 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1866 ha->flags.msi_enabled = 1;
1867 }
1868skip_msi:
1869
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001870 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001871 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001872 if (ret) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001873 qla_printk(KERN_WARNING, ha,
1874 "Failed to reserve interrupt %d already in use.\n",
1875 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001876 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001877 }
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001878 ha->flags.inta_enabled = 1;
1879 ha->host->irq = ha->pdev->irq;
1880clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001881
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001882 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezc6952482008-04-03 13:13:17 -07001883 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001884 if (IS_FWI2_CAPABLE(ha)) {
1885 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1886 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1887 } else {
1888 WRT_REG_WORD(&reg->isp.semaphore, 0);
1889 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1890 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
1891 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001892 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001893 ha->isp_ops->enable_intrs(ha);
1894
1895fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001896 return ret;
1897}
1898
1899void
1900qla2x00_free_irqs(scsi_qla_host_t *ha)
1901{
1902
1903 if (ha->flags.msix_enabled)
1904 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001905 else if (ha->flags.inta_enabled) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001906 free_irq(ha->host->irq, ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001907 pci_disable_msi(ha->pdev);
1908 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001909}