blob: 360af4e09d127d48306454b2c95d82b2a5740535 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
Andrew Vasquez05236a02007-09-20 14:07:37 -07009#include <linux/delay.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070010#include <scsi/scsi_tcq.h>
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -070013static void qla2x00_process_completed_request(struct scsi_qla_host *, uint32_t);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070014static void qla2x00_status_entry(scsi_qla_host_t *, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070015static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *);
16static void qla2x00_error_entry(scsi_qla_host_t *, sts_entry_t *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070017
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/**
19 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
20 * @irq:
21 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
23 * Called by system whenever the host adapter generates an interrupt.
24 *
25 * Returns handled flag.
26 */
27irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010028qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
30 scsi_qla_host_t *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070031 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070034 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070035 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 ha = (scsi_qla_host_t *) dev_id;
38 if (!ha) {
39 printk(KERN_INFO
40 "%s(): NULL host pointer\n", __func__);
41 return (IRQ_NONE);
42 }
43
Andrew Vasquez3d716442005-07-06 10:30:26 -070044 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 status = 0;
46
Andrew Vasquezc6952482008-04-03 13:13:17 -070047 spin_lock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070049 hccr = RD_REG_WORD(&reg->hccr);
50 if (hccr & HCCR_RISC_PAUSE) {
51 if (pci_channel_offline(ha->pdev))
52 break;
53
54 /*
55 * Issue a "HARD" reset in order for the RISC interrupt
56 * bit to be cleared. Schedule a big hammmer to get
57 * out of the RISC PAUSED state.
58 */
59 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
60 RD_REG_WORD(&reg->hccr);
61
62 ha->isp_ops->fw_dump(ha, 1);
63 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
64 break;
65 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 break;
67
68 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
69 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
70 RD_REG_WORD(&reg->hccr);
71
72 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070073 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
74 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
75 qla2x00_mbx_completion(ha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070077 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
78 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
79 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
80 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
81 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 } else {
83 /*EMPTY*/
84 DEBUG2(printk("scsi(%ld): Unrecognized "
Andrew Vasquez9a853f72005-07-06 10:31:27 -070085 "interrupt type (%d).\n",
86 ha->host_no, mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88 /* Release mailbox registers. */
89 WRT_REG_WORD(&reg->semaphore, 0);
90 RD_REG_WORD(&reg->semaphore);
91 } else {
92 qla2x00_process_response_queue(ha);
93
94 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
95 RD_REG_WORD(&reg->hccr);
96 }
97 }
Andrew Vasquezc6952482008-04-03 13:13:17 -070098 spin_unlock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
101 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800103 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return (IRQ_HANDLED);
107}
108
109/**
110 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
111 * @irq:
112 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 *
114 * Called by system whenever the host adapter generates an interrupt.
115 *
116 * Returns handled flag.
117 */
118irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100119qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
121 scsi_qla_host_t *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700122 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 unsigned long iter;
125 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700127 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 ha = (scsi_qla_host_t *) dev_id;
130 if (!ha) {
131 printk(KERN_INFO
132 "%s(): NULL host pointer\n", __func__);
133 return (IRQ_NONE);
134 }
135
Andrew Vasquez3d716442005-07-06 10:30:26 -0700136 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 status = 0;
138
Andrew Vasquezc6952482008-04-03 13:13:17 -0700139 spin_lock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 for (iter = 50; iter--; ) {
141 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
142 if (stat & HSR_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700143 if (pci_channel_offline(ha->pdev))
144 break;
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 hccr = RD_REG_WORD(&reg->hccr);
147 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Andrew Vasquez07f31802006-12-13 19:20:31 -0800148 qla_printk(KERN_INFO, ha, "Parity error -- "
149 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 else
Andrew Vasquez07f31802006-12-13 19:20:31 -0800151 qla_printk(KERN_INFO, ha, "RISC paused -- "
152 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 /*
155 * Issue a "HARD" reset in order for the RISC
156 * interrupt bit to be cleared. Schedule a big
157 * hammmer to get out of the RISC PAUSED state.
158 */
159 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
160 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800161
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700162 ha->isp_ops->fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
164 break;
165 } else if ((stat & HSR_RISC_INT) == 0)
166 break;
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 case 0x1:
170 case 0x2:
171 case 0x10:
172 case 0x11:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700173 qla2x00_mbx_completion(ha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 status |= MBX_INTERRUPT;
175
176 /* Release mailbox registers. */
177 WRT_REG_WORD(&reg->semaphore, 0);
178 break;
179 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700180 mb[0] = MSW(stat);
181 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
182 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
183 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
184 qla2x00_async_event(ha, mb);
185 break;
186 case 0x13:
187 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 break;
189 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700190 mb[0] = MBA_CMPLT_1_16BIT;
191 mb[1] = MSW(stat);
192 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 break;
194 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700195 mb[0] = MBA_SCSI_COMPLETION;
196 mb[1] = MSW(stat);
197 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
198 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
200 default:
201 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700202 "(%d).\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 ha->host_no, stat & 0xff));
204 break;
205 }
206 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
207 RD_REG_WORD_RELAXED(&reg->hccr);
208 }
Andrew Vasquezc6952482008-04-03 13:13:17 -0700209 spin_unlock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
212 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800214 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 return (IRQ_HANDLED);
218}
219
220/**
221 * qla2x00_mbx_completion() - Process mailbox command completions.
222 * @ha: SCSI driver HA context
223 * @mb0: Mailbox0 register
224 */
225static void
226qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
227{
228 uint16_t cnt;
229 uint16_t __iomem *wptr;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700230 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 /* Load return mailbox registers. */
233 ha->flags.mbox_int = 1;
234 ha->mailbox_out[0] = mb0;
235 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
236
237 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700238 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
240 if (cnt == 4 || cnt == 5)
241 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
242 else
243 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 wptr++;
246 }
247
248 if (ha->mcp) {
249 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
250 __func__, ha->host_no, ha->mcp->mb[0]));
251 } else {
252 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
253 __func__, ha->host_no));
254 }
255}
256
257/**
258 * qla2x00_async_event() - Process aynchronous events.
259 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700260 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700262void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700263qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700265#define LS_UNKNOWN 2
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700266 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 uint16_t handle_cnt;
269 uint16_t cnt;
270 uint32_t handles[5];
Andrew Vasquez3d716442005-07-06 10:30:26 -0700271 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 uint32_t rscn_entry, host_pid;
273 uint8_t rscn_queue_index;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700274 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276 /* Setup to process RIO completion. */
277 handle_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 switch (mb[0]) {
279 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700280 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 handle_cnt = 1;
282 break;
283 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700284 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 handle_cnt = 1;
286 mb[0] = MBA_SCSI_COMPLETION;
287 break;
288 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700289 handles[0] = mb[1];
290 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 handle_cnt = 2;
292 mb[0] = MBA_SCSI_COMPLETION;
293 break;
294 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700295 handles[0] = mb[1];
296 handles[1] = mb[2];
297 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 handle_cnt = 3;
299 mb[0] = MBA_SCSI_COMPLETION;
300 break;
301 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700302 handles[0] = mb[1];
303 handles[1] = mb[2];
304 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
306 handle_cnt = 4;
307 mb[0] = MBA_SCSI_COMPLETION;
308 break;
309 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700310 handles[0] = mb[1];
311 handles[1] = mb[2];
312 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
314 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
315 handle_cnt = 5;
316 mb[0] = MBA_SCSI_COMPLETION;
317 break;
318 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700319 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 handles[1] = le32_to_cpu(
321 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
322 RD_MAILBOX_REG(ha, reg, 6));
323 handle_cnt = 2;
324 mb[0] = MBA_SCSI_COMPLETION;
325 break;
326 default:
327 break;
328 }
329
330 switch (mb[0]) {
331 case MBA_SCSI_COMPLETION: /* Fast Post */
332 if (!ha->flags.online)
333 break;
334
335 for (cnt = 0; cnt < handle_cnt; cnt++)
336 qla2x00_process_completed_request(ha, handles[cnt]);
337 break;
338
339 case MBA_RESET: /* Reset */
340 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
341
342 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
343 break;
344
345 case MBA_SYSTEM_ERR: /* System Error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 qla_printk(KERN_INFO, ha,
347 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
348 mb[1], mb[2], mb[3]);
349
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700350 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700351 ha->isp_ops->fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Andrew Vasqueze4289242007-07-19 15:05:56 -0700353 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700354 if (mb[1] == 0 && mb[2] == 0) {
355 qla_printk(KERN_ERR, ha,
356 "Unrecoverable Hardware Error: adapter "
357 "marked OFFLINE!\n");
358 ha->flags.online = 0;
359 } else
360 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
361 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 qla_printk(KERN_INFO, ha,
363 "Unrecoverable Hardware Error: adapter marked "
364 "OFFLINE!\n");
365 ha->flags.online = 0;
366 } else
367 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
368 break;
369
370 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
371 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
372 ha->host_no));
373 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
374
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700375 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
377 break;
378
379 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
380 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
381 ha->host_no));
382 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
383
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700384 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
386 break;
387
388 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
389 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
390 ha->host_no));
391 break;
392
393 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
395 mb[1]));
396 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
397
398 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
399 atomic_set(&ha->loop_state, LOOP_DOWN);
400 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800401 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700404 if (ha->parent) {
405 atomic_set(&ha->vp_state, VP_FAILED);
406 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
407 }
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
410
411 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700412 qla2x00_post_aen_work(ha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 break;
414
415 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
417 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700418 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700420 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 if (mb[1] < 5)
422 link_speed = link_speeds[mb[1]];
423 ha->link_data_rate = mb[1];
424 }
425
426 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
427 ha->host_no, link_speed));
428 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
429 link_speed);
430
431 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700432 qla2x00_post_aen_work(ha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 break;
434
435 case MBA_LOOP_DOWN: /* Loop Down Event */
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700436 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
437 "(%x %x %x).\n", ha->host_no, mb[1], mb[2], mb[3]));
438 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
439 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
442 atomic_set(&ha->loop_state, LOOP_DOWN);
443 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
444 ha->device_flags |= DFLG_NO_CABLE;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800445 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 }
447
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700448 if (ha->parent) {
449 atomic_set(&ha->vp_state, VP_FAILED);
450 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
451 }
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 ha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700454 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Andrew Vasquezcca53352005-08-26 19:08:30 -0700455 if (ql2xfdmienable)
456 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -0700457 qla2x00_post_aen_work(ha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 break;
459
460 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
462 ha->host_no, mb[1]));
463 qla_printk(KERN_INFO, ha,
464 "LIP reset occured (%x).\n", mb[1]);
465
466 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
467 atomic_set(&ha->loop_state, LOOP_DOWN);
468 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800469 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 }
471
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700472 if (ha->parent) {
473 atomic_set(&ha->vp_state, VP_FAILED);
474 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
475 }
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
478
479 ha->operating_mode = LOOP;
480 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700481 qla2x00_post_aen_work(ha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 break;
483
484 case MBA_POINT_TO_POINT: /* Point-to-Point */
485 if (IS_QLA2100(ha))
486 break;
487
488 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
489 ha->host_no));
490
491 /*
492 * Until there's a transition from loop down to loop up, treat
493 * this as loop down only.
494 */
495 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
496 atomic_set(&ha->loop_state, LOOP_DOWN);
497 if (!atomic_read(&ha->loop_down_timer))
498 atomic_set(&ha->loop_down_timer,
499 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800500 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700503 if (ha->parent) {
504 atomic_set(&ha->vp_state, VP_FAILED);
505 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
506 }
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
509 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
510 }
511 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800512
513 ha->flags.gpsc_supported = 1;
Andrew Vasquez02d638b2007-08-12 18:22:54 -0700514 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 break;
516
517 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
518 if (IS_QLA2100(ha))
519 break;
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
522 "received.\n",
523 ha->host_no));
524 qla_printk(KERN_INFO, ha,
525 "Configuration change detected: value=%x.\n", mb[1]);
526
527 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700528 atomic_set(&ha->loop_state, LOOP_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 if (!atomic_read(&ha->loop_down_timer))
530 atomic_set(&ha->loop_down_timer,
531 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800532 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 }
534
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700535 if (ha->parent) {
536 atomic_set(&ha->vp_state, VP_FAILED);
537 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
538 }
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
541 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
542 break;
543
544 case MBA_PORT_UPDATE: /* Port database update */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
547 * event etc. earlier indicating loop is down) then process
548 * it. Otherwise ignore it and Wait for RSCN to come in.
549 */
550 atomic_set(&ha->loop_down_timer, 0);
551 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
552 atomic_read(&ha->loop_state) != LOOP_DEAD) {
553 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700554 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
555 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 break;
557 }
558
559 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
560 ha->host_no));
561 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700562 "scsi(%ld): Port database changed %04x %04x %04x.\n",
563 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 /*
566 * Mark all devices as missing so we will login again.
567 */
568 atomic_set(&ha->loop_state, LOOP_UP);
569
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800570 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572 ha->flags.rscn_queue_overflow = 1;
573
574 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
575 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 break;
577
578 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700579 /* Check if the Vport has issued a SCR */
580 if (ha->parent && test_bit(VP_SCR_NEEDED, &ha->vp_flags))
581 break;
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800582 /* Only handle SCNs for our Vport index. */
583 if (ha->flags.npiv_supported && ha->vp_idx != mb[3])
584 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
587 ha->host_no));
588 DEBUG(printk(KERN_INFO
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800589 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
590 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 rscn_entry = (mb[1] << 16) | mb[2];
593 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
594 ha->d_id.b.al_pa;
595 if (rscn_entry == host_pid) {
596 DEBUG(printk(KERN_INFO
597 "scsi(%ld): Ignoring RSCN update to local host "
598 "port ID (%06x)\n",
599 ha->host_no, host_pid));
600 break;
601 }
602
603 rscn_queue_index = ha->rscn_in_ptr + 1;
604 if (rscn_queue_index == MAX_RSCN_COUNT)
605 rscn_queue_index = 0;
606 if (rscn_queue_index != ha->rscn_out_ptr) {
607 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
608 ha->rscn_in_ptr = rscn_queue_index;
609 } else {
610 ha->flags.rscn_queue_overflow = 1;
611 }
612
613 atomic_set(&ha->loop_state, LOOP_UPDATE);
614 atomic_set(&ha->loop_down_timer, 0);
615 ha->flags.management_server_logged_in = 0;
616
617 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
618 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -0700619 qla2x00_post_aen_work(ha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 break;
621
622 /* case MBA_RIO_RESPONSE: */
623 case MBA_ZIO_RESPONSE:
624 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
625 ha->host_no));
626 DEBUG(printk(KERN_INFO
627 "scsi(%ld): [R|Z]IO update completion.\n",
628 ha->host_no));
629
Andrew Vasqueze4289242007-07-19 15:05:56 -0700630 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700631 qla24xx_process_response_queue(ha);
632 else
633 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700635
636 case MBA_DISCARD_RND_FRAME:
637 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
638 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
639 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700640
641 case MBA_TRACE_NOTIFICATION:
642 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
643 ha->host_no, mb[1], mb[2]));
644 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700645
646 case MBA_ISP84XX_ALERT:
647 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
648 "%04x %04x %04x\n", ha->host_no, mb[1], mb[2], mb[3]));
649
650 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
651 switch (mb[1]) {
652 case A84_PANIC_RECOVERY:
653 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
654 "%04x %04x\n", mb[2], mb[3]);
655 break;
656 case A84_OP_LOGIN_COMPLETE:
657 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
658 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
659 "firmware version %x\n", ha->cs84xx->op_fw_version));
660 break;
661 case A84_DIAG_LOGIN_COMPLETE:
662 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
663 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
664 "diagnostic firmware version %x\n",
665 ha->cs84xx->diag_fw_version));
666 break;
667 case A84_GOLD_LOGIN_COMPLETE:
668 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
669 ha->cs84xx->fw_update = 1;
670 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
671 "firmware version %x\n",
672 ha->cs84xx->gold_fw_version));
673 break;
674 default:
675 qla_printk(KERN_ERR, ha,
676 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
677 mb[1], mb[2], mb[3]);
678 }
679 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
680 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700682
683 if (!ha->parent && ha->num_vhosts)
684 qla2x00_alert_all_vps(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685}
686
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700687static void
688qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
689{
690 fc_port_t *fcport = data;
691
692 if (fcport->ha->max_q_depth <= sdev->queue_depth)
693 return;
694
695 if (sdev->ordered_tags)
696 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
697 sdev->queue_depth + 1);
698 else
699 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
700 sdev->queue_depth + 1);
701
702 fcport->last_ramp_up = jiffies;
703
704 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
705 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
706 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
707 sdev->queue_depth));
708}
709
710static void
711qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
712{
713 fc_port_t *fcport = data;
714
715 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
716 return;
717
718 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
719 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
720 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
721 sdev->queue_depth));
722}
723
724static inline void
725qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
726{
727 fc_port_t *fcport;
728 struct scsi_device *sdev;
729
730 sdev = sp->cmd->device;
731 if (sdev->queue_depth >= ha->max_q_depth)
732 return;
733
734 fcport = sp->fcport;
735 if (time_before(jiffies,
736 fcport->last_ramp_up + ql2xqfullrampup * HZ))
737 return;
738 if (time_before(jiffies,
739 fcport->last_queue_full + ql2xqfullrampup * HZ))
740 return;
741
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700742 starget_for_each_device(sdev->sdev_target, fcport,
743 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700744}
745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746/**
747 * qla2x00_process_completed_request() - Process a Fast Post response.
748 * @ha: SCSI driver HA context
749 * @index: SRB index
750 */
751static void
752qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
753{
754 srb_t *sp;
755
756 /* Validate handle. */
757 if (index >= MAX_OUTSTANDING_COMMANDS) {
758 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
759 ha->host_no, index));
760 qla_printk(KERN_WARNING, ha,
761 "Invalid SCSI completion handle %d.\n", index);
762
763 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
764 return;
765 }
766
767 sp = ha->outstanding_cmds[index];
768 if (sp) {
769 /* Free outstanding command slot. */
770 ha->outstanding_cmds[index] = NULL;
771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 CMD_COMPL_STATUS(sp->cmd) = 0L;
773 CMD_SCSI_STATUS(sp->cmd) = 0L;
774
775 /* Save ISP completion status */
776 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700777
778 qla2x00_ramp_up_queue_depth(ha, sp);
f4f051e2005-04-17 15:02:26 -0500779 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 } else {
781 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
782 ha->host_no));
783 qla_printk(KERN_WARNING, ha,
784 "Invalid ISP SCSI completion handle\n");
785
786 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
787 }
788}
789
790/**
791 * qla2x00_process_response_queue() - Process response queue entries.
792 * @ha: SCSI driver HA context
793 */
794void
795qla2x00_process_response_queue(struct scsi_qla_host *ha)
796{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700797 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 sts_entry_t *pkt;
799 uint16_t handle_cnt;
800 uint16_t cnt;
801
802 if (!ha->flags.online)
803 return;
804
805 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
806 pkt = (sts_entry_t *)ha->response_ring_ptr;
807
808 ha->rsp_ring_index++;
809 if (ha->rsp_ring_index == ha->response_q_length) {
810 ha->rsp_ring_index = 0;
811 ha->response_ring_ptr = ha->response_ring;
812 } else {
813 ha->response_ring_ptr++;
814 }
815
816 if (pkt->entry_status != 0) {
817 DEBUG3(printk(KERN_INFO
818 "scsi(%ld): Process error entry.\n", ha->host_no));
819
820 qla2x00_error_entry(ha, pkt);
821 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
822 wmb();
823 continue;
824 }
825
826 switch (pkt->entry_type) {
827 case STATUS_TYPE:
828 qla2x00_status_entry(ha, pkt);
829 break;
830 case STATUS_TYPE_21:
831 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
832 for (cnt = 0; cnt < handle_cnt; cnt++) {
833 qla2x00_process_completed_request(ha,
834 ((sts21_entry_t *)pkt)->handle[cnt]);
835 }
836 break;
837 case STATUS_TYPE_22:
838 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
839 for (cnt = 0; cnt < handle_cnt; cnt++) {
840 qla2x00_process_completed_request(ha,
841 ((sts22_entry_t *)pkt)->handle[cnt]);
842 }
843 break;
844 case STATUS_CONT_TYPE:
845 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
846 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 default:
848 /* Type Not Supported. */
849 DEBUG4(printk(KERN_WARNING
850 "scsi(%ld): Received unknown response pkt type %x "
851 "entry status=%x.\n",
852 ha->host_no, pkt->entry_type, pkt->entry_status));
853 break;
854 }
855 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
856 wmb();
857 }
858
859 /* Adjust ring index */
860 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
861}
862
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800863static inline void
864qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
865{
866 struct scsi_cmnd *cp = sp->cmd;
867
868 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
869 sense_len = SCSI_SENSE_BUFFERSIZE;
870
871 CMD_ACTUAL_SNSLEN(cp) = sense_len;
872 sp->request_sense_length = sense_len;
873 sp->request_sense_ptr = cp->sense_buffer;
874 if (sp->request_sense_length > 32)
875 sense_len = 32;
876
877 memcpy(cp->sense_buffer, sense_data, sense_len);
878
879 sp->request_sense_ptr += sense_len;
880 sp->request_sense_length -= sense_len;
881 if (sp->request_sense_length != 0)
882 sp->ha->status_srb = sp;
883
884 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
885 "cmd=%p pid=%ld\n", __func__, sp->ha->host_no, cp->device->channel,
886 cp->device->id, cp->device->lun, cp, cp->serial_number));
887 if (sense_len)
888 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
889 CMD_ACTUAL_SNSLEN(cp)));
890}
891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892/**
893 * qla2x00_status_entry() - Process a Status IOCB entry.
894 * @ha: SCSI driver HA context
895 * @pkt: Entry pointer
896 */
897static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700898qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 fc_port_t *fcport;
902 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700903 sts_entry_t *sts;
904 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 uint16_t comp_status;
906 uint16_t scsi_status;
907 uint8_t lscsi_status;
908 int32_t resid;
Ravi Ananded17c712006-05-17 15:08:55 -0700909 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700910 uint8_t *rsp_info, *sense_data;
911
912 sts = (sts_entry_t *) pkt;
913 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700914 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700915 comp_status = le16_to_cpu(sts24->comp_status);
916 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
917 } else {
918 comp_status = le16_to_cpu(sts->comp_status);
919 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700923 if (comp_status == CS_COMPLETE && scsi_status == 0) {
924 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 return;
927 }
928
929 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700930 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
931 sp = ha->outstanding_cmds[sts->handle];
932 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 } else
934 sp = NULL;
935
936 if (sp == NULL) {
937 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
938 ha->host_no));
939 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
940
941 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100942 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 return;
944 }
945 cp = sp->cmd;
946 if (cp == NULL) {
947 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700948 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 qla_printk(KERN_WARNING, ha,
950 "Command is NULL: already returned to OS (sp=%p)\n", sp);
951
952 return;
953 }
954
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700955 lscsi_status = scsi_status & STATUS_MASK;
956 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 CMD_COMPL_STATUS(cp) = comp_status;
958 CMD_SCSI_STATUS(cp) = scsi_status;
959
bdf79622005-04-17 15:06:53 -0500960 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Ravi Ananded17c712006-05-17 15:08:55 -0700962 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700963 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700964 sense_len = le32_to_cpu(sts24->sense_len);
965 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
966 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c712006-05-17 15:08:55 -0700967 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700968 rsp_info = sts24->data;
969 sense_data = sts24->data;
970 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
971 } else {
972 sense_len = le16_to_cpu(sts->req_sense_length);
973 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
974 resid_len = le32_to_cpu(sts->residual_length);
975 rsp_info = sts->rsp_info;
976 sense_data = sts->req_sense_data;
977 }
978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 /* Check for any FCP transport errors. */
980 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700981 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700982 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700983 sense_data += rsp_info_len;
984 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
986 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700987 "retrying command\n", ha->host_no,
988 cp->device->channel, cp->device->id,
989 cp->device->lun, rsp_info_len, rsp_info[0],
990 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
991 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
993 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500994 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 return;
996 }
997 }
998
Andrew Vasquez3e8ce322008-02-28 14:06:10 -0800999 /* Check for overrun. */
1000 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1001 scsi_status & SS_RESIDUAL_OVER)
1002 comp_status = CS_DATA_OVERRUN;
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 /*
1005 * Based on Host and scsi status generate status code for Linux
1006 */
1007 switch (comp_status) {
1008 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001009 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 if (scsi_status == 0) {
1011 cp->result = DID_OK << 16;
1012 break;
1013 }
1014 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001015 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001016 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001018
1019 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001020 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001021 cp->underflow)) {
1022 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001023 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1024 "detected (%x of %x bytes)...returning "
1025 "error status.\n", ha->host_no,
1026 cp->device->channel, cp->device->id,
1027 cp->device->lun, resid,
1028 scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001029
1030 cp->result = DID_ERROR << 16;
1031 break;
1032 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 cp->result = DID_OK << 16 | lscsi_status;
1035
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001036 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1037 DEBUG2(printk(KERN_INFO
1038 "scsi(%ld): QUEUE FULL status detected "
1039 "0x%x-0x%x.\n", ha->host_no, comp_status,
1040 scsi_status));
1041
1042 /* Adjust queue depth for all luns on the port. */
1043 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001044 starget_for_each_device(cp->device->sdev_target,
1045 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001046 break;
1047 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 if (lscsi_status != SS_CHECK_CONDITION)
1049 break;
1050
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001051 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 if (!(scsi_status & SS_SENSE_LEN_VALID))
1053 break;
1054
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001055 qla2x00_handle_sense(sp, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 break;
1057
1058 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001059 resid = resid_len;
Ravi Ananded17c712006-05-17 15:08:55 -07001060 /* Use F/W calculated residual length. */
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001061 if (IS_FWI2_CAPABLE(ha)) {
1062 if (scsi_status & SS_RESIDUAL_UNDER &&
1063 resid != fw_resid_len) {
1064 scsi_status &= ~SS_RESIDUAL_UNDER;
1065 lscsi_status = 0;
1066 }
Ravi Ananded17c712006-05-17 15:08:55 -07001067 resid = fw_resid_len;
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001068 }
Ravi Ananded17c712006-05-17 15:08:55 -07001069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 if (scsi_status & SS_RESIDUAL_UNDER) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001071 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001073 } else {
1074 DEBUG2(printk(KERN_INFO
1075 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c712006-05-17 15:08:55 -07001076 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1077 "os_underflow=0x%x\n", ha->host_no,
1078 cp->device->id, cp->device->lun, comp_status,
1079 scsi_status, resid_len, resid, cp->cmnd[0],
1080 cp->underflow));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 }
1083
1084 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001085 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 * Status.
1087 */
1088 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 cp->result = DID_OK << 16 | lscsi_status;
1090
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001091 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1092 DEBUG2(printk(KERN_INFO
1093 "scsi(%ld): QUEUE FULL status detected "
1094 "0x%x-0x%x.\n", ha->host_no, comp_status,
1095 scsi_status));
1096
1097 /*
1098 * Adjust queue depth for all luns on the
1099 * port.
1100 */
1101 fcport->last_queue_full = jiffies;
1102 starget_for_each_device(
1103 cp->device->sdev_target, fcport,
1104 qla2x00_adjust_sdev_qdepth_down);
1105 break;
1106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 if (lscsi_status != SS_CHECK_CONDITION)
1108 break;
1109
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001110 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 if (!(scsi_status & SS_SENSE_LEN_VALID))
1112 break;
1113
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001114 qla2x00_handle_sense(sp, sense_data, sense_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001115
Shyam Sundar8084fe12007-07-19 15:05:59 -07001116 /*
1117 * In case of a Underrun condition, set both the lscsi
1118 * status and the completion status to appropriate
1119 * values.
1120 */
1121 if (resid &&
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001122 ((unsigned)(scsi_bufflen(cp) - resid) <
Shyam Sundar8084fe12007-07-19 15:05:59 -07001123 cp->underflow)) {
1124 DEBUG2(qla_printk(KERN_INFO, ha,
1125 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1126 "detected (%x of %x bytes)...returning "
1127 "error status.\n", ha->host_no,
1128 cp->device->channel, cp->device->id,
1129 cp->device->lun, resid,
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001130 scsi_bufflen(cp)));
Shyam Sundar8084fe12007-07-19 15:05:59 -07001131
1132 cp->result = DID_ERROR << 16 | lscsi_status;
1133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 } else {
1135 /*
1136 * If RISC reports underrun and target does not report
1137 * it then we must have a lost frame, so tell upper
1138 * layer to retry it by reporting a bus busy.
1139 */
1140 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1141 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001142 "frame(s) detected (%x of %x bytes)..."
1143 "retrying command.\n", ha->host_no,
1144 cp->device->channel, cp->device->id,
1145 cp->device->lun, resid,
1146 scsi_bufflen(cp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 break;
1150 }
1151
1152 /* Handle mid-layer underflow */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001153 if ((unsigned)(scsi_bufflen(cp) - resid) <
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 cp->underflow) {
1155 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001156 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1157 "detected (%x of %x bytes)...returning "
1158 "error status.\n", ha->host_no,
1159 cp->device->channel, cp->device->id,
1160 cp->device->lun, resid,
1161 scsi_bufflen(cp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
1163 cp->result = DID_ERROR << 16;
1164 break;
1165 }
1166
1167 /* Everybody online, looking good... */
1168 cp->result = DID_OK << 16;
1169 }
1170 break;
1171
1172 case CS_DATA_OVERRUN:
1173 DEBUG2(printk(KERN_INFO
1174 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001175 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1176 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 DEBUG2(printk(KERN_INFO
1178 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1179 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1180 cp->cmnd[4], cp->cmnd[5]));
1181 DEBUG2(printk(KERN_INFO
1182 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1183 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001184 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
1186 cp->result = DID_ERROR << 16;
1187 break;
1188
1189 case CS_PORT_LOGGED_OUT:
1190 case CS_PORT_CONFIG_CHG:
1191 case CS_PORT_BUSY:
1192 case CS_INCOMPLETE:
1193 case CS_PORT_UNAVAILABLE:
1194 /*
1195 * If the port is in Target Down state, return all IOs for this
1196 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1197 * retry_queue.
1198 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1200 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001201 ha->host_no, cp->device->id, cp->device->lun,
1202 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 atomic_read(&fcport->state)));
1204
f4f051e2005-04-17 15:02:26 -05001205 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001207 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 break;
1210
1211 case CS_RESET:
1212 DEBUG2(printk(KERN_INFO
1213 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1214 ha->host_no, comp_status, scsi_status));
1215
f4f051e2005-04-17 15:02:26 -05001216 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 break;
1218
1219 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001220 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 * hv2.19.12 - DID_ABORT does not retry the request if we
1222 * aborted this request then abort otherwise it must be a
1223 * reset.
1224 */
1225 DEBUG2(printk(KERN_INFO
1226 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1227 ha->host_no, comp_status, scsi_status));
1228
1229 cp->result = DID_RESET << 16;
1230 break;
1231
1232 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 cp->result = DID_BUS_BUSY << 16;
1234
Andrew Vasqueze4289242007-07-19 15:05:56 -07001235 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001236 DEBUG2(printk(KERN_INFO
1237 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1238 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1239 cp->device->id, cp->device->lun, comp_status,
1240 scsi_status));
1241 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001243 DEBUG2(printk(KERN_INFO
1244 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1245 "sflags=%x.\n", ha->host_no, cp->device->channel,
1246 cp->device->id, cp->device->lun, comp_status, scsi_status,
1247 le16_to_cpu(sts->status_flags)));
1248
1249 /* Check to see if logout occurred. */
1250 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001251 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 break;
1253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 default:
1255 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001256 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 qla_printk(KERN_INFO, ha,
1258 "Unknown status detected 0x%x-0x%x.\n",
1259 comp_status, scsi_status);
1260
1261 cp->result = DID_ERROR << 16;
1262 break;
1263 }
1264
1265 /* Place command on done queue. */
1266 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001267 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268}
1269
1270/**
1271 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1272 * @ha: SCSI driver HA context
1273 * @pkt: Entry pointer
1274 *
1275 * Extended sense data.
1276 */
1277static void
1278qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1279{
1280 uint8_t sense_sz = 0;
1281 srb_t *sp = ha->status_srb;
1282 struct scsi_cmnd *cp;
1283
1284 if (sp != NULL && sp->request_sense_length != 0) {
1285 cp = sp->cmd;
1286 if (cp == NULL) {
1287 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001288 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 qla_printk(KERN_INFO, ha,
1290 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001291 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
1293 ha->status_srb = NULL;
1294 return;
1295 }
1296
1297 if (sp->request_sense_length > sizeof(pkt->data)) {
1298 sense_sz = sizeof(pkt->data);
1299 } else {
1300 sense_sz = sp->request_sense_length;
1301 }
1302
1303 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001304 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001305 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1307 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1308
1309 sp->request_sense_ptr += sense_sz;
1310 sp->request_sense_length -= sense_sz;
1311
1312 /* Place command on done queue. */
1313 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001315 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 }
1317 }
1318}
1319
1320/**
1321 * qla2x00_error_entry() - Process an error entry.
1322 * @ha: SCSI driver HA context
1323 * @pkt: Entry pointer
1324 */
1325static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001326qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
1328 srb_t *sp;
1329
1330#if defined(QL_DEBUG_LEVEL_2)
1331 if (pkt->entry_status & RF_INV_E_ORDER)
1332 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1333 else if (pkt->entry_status & RF_INV_E_COUNT)
1334 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1335 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001336 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 "%s: Invalid Entry Parameter\n", __func__);
1338 else if (pkt->entry_status & RF_INV_E_TYPE)
1339 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1340 else if (pkt->entry_status & RF_BUSY)
1341 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1342 else
1343 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1344#endif
1345
1346 /* Validate handle. */
1347 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1348 sp = ha->outstanding_cmds[pkt->handle];
1349 else
1350 sp = NULL;
1351
1352 if (sp) {
1353 /* Free outstanding command slot. */
1354 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001355
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 /* Bad payload or header */
1357 if (pkt->entry_status &
1358 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1359 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1360 sp->cmd->result = DID_ERROR << 16;
1361 } else if (pkt->entry_status & RF_BUSY) {
1362 sp->cmd->result = DID_BUS_BUSY << 16;
1363 } else {
1364 sp->cmd->result = DID_ERROR << 16;
1365 }
f4f051e2005-04-17 15:02:26 -05001366 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001368 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1369 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1371 ha->host_no));
1372 qla_printk(KERN_WARNING, ha,
1373 "Error entry - invalid handle\n");
1374
1375 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001376 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 }
1378}
1379
1380/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001381 * qla24xx_mbx_completion() - Process mailbox command completions.
1382 * @ha: SCSI driver HA context
1383 * @mb0: Mailbox0 register
1384 */
1385static void
1386qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1387{
1388 uint16_t cnt;
1389 uint16_t __iomem *wptr;
1390 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1391
1392 /* Load return mailbox registers. */
1393 ha->flags.mbox_int = 1;
1394 ha->mailbox_out[0] = mb0;
1395 wptr = (uint16_t __iomem *)&reg->mailbox1;
1396
1397 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1398 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1399 wptr++;
1400 }
1401
1402 if (ha->mcp) {
1403 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1404 __func__, ha->host_no, ha->mcp->mb[0]));
1405 } else {
1406 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1407 __func__, ha->host_no));
1408 }
1409}
1410
1411/**
1412 * qla24xx_process_response_queue() - Process response queue entries.
1413 * @ha: SCSI driver HA context
1414 */
1415void
1416qla24xx_process_response_queue(struct scsi_qla_host *ha)
1417{
1418 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1419 struct sts_entry_24xx *pkt;
1420
1421 if (!ha->flags.online)
1422 return;
1423
1424 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1425 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1426
1427 ha->rsp_ring_index++;
1428 if (ha->rsp_ring_index == ha->response_q_length) {
1429 ha->rsp_ring_index = 0;
1430 ha->response_ring_ptr = ha->response_ring;
1431 } else {
1432 ha->response_ring_ptr++;
1433 }
1434
1435 if (pkt->entry_status != 0) {
1436 DEBUG3(printk(KERN_INFO
1437 "scsi(%ld): Process error entry.\n", ha->host_no));
1438
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001439 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1440 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1441 wmb();
1442 continue;
1443 }
1444
1445 switch (pkt->entry_type) {
1446 case STATUS_TYPE:
1447 qla2x00_status_entry(ha, pkt);
1448 break;
1449 case STATUS_CONT_TYPE:
1450 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1451 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001452 case VP_RPT_ID_IOCB_TYPE:
1453 qla24xx_report_id_acquisition(ha,
1454 (struct vp_rpt_id_entry_24xx *)pkt);
1455 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001456 default:
1457 /* Type Not Supported. */
1458 DEBUG4(printk(KERN_WARNING
1459 "scsi(%ld): Received unknown response pkt type %x "
1460 "entry status=%x.\n",
1461 ha->host_no, pkt->entry_type, pkt->entry_status));
1462 break;
1463 }
1464 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1465 wmb();
1466 }
1467
1468 /* Adjust ring index */
1469 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1470}
1471
Andrew Vasquez05236a02007-09-20 14:07:37 -07001472static void
1473qla2xxx_check_risc_status(scsi_qla_host_t *ha)
1474{
1475 int rval;
1476 uint32_t cnt;
1477 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1478
1479 if (!IS_QLA25XX(ha))
1480 return;
1481
1482 rval = QLA_SUCCESS;
1483 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1484 RD_REG_DWORD(&reg->iobase_addr);
1485 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1486 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1487 rval == QLA_SUCCESS; cnt--) {
1488 if (cnt) {
1489 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1490 udelay(10);
1491 } else
1492 rval = QLA_FUNCTION_TIMEOUT;
1493 }
1494 if (rval == QLA_SUCCESS)
1495 goto next_test;
1496
1497 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1498 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1499 rval == QLA_SUCCESS; cnt--) {
1500 if (cnt) {
1501 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1502 udelay(10);
1503 } else
1504 rval = QLA_FUNCTION_TIMEOUT;
1505 }
1506 if (rval != QLA_SUCCESS)
1507 goto done;
1508
1509next_test:
1510 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1511 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1512
1513done:
1514 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1515 RD_REG_DWORD(&reg->iobase_window);
1516}
1517
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001518/**
1519 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1520 * @irq:
1521 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001522 *
1523 * Called by system whenever the host adapter generates an interrupt.
1524 *
1525 * Returns handled flag.
1526 */
1527irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001528qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001529{
1530 scsi_qla_host_t *ha;
1531 struct device_reg_24xx __iomem *reg;
1532 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001533 unsigned long iter;
1534 uint32_t stat;
1535 uint32_t hccr;
1536 uint16_t mb[4];
1537
1538 ha = (scsi_qla_host_t *) dev_id;
1539 if (!ha) {
1540 printk(KERN_INFO
1541 "%s(): NULL host pointer\n", __func__);
1542 return IRQ_NONE;
1543 }
1544
1545 reg = &ha->iobase->isp24;
1546 status = 0;
1547
Andrew Vasquezc6952482008-04-03 13:13:17 -07001548 spin_lock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001549 for (iter = 50; iter--; ) {
1550 stat = RD_REG_DWORD(&reg->host_status);
1551 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001552 if (pci_channel_offline(ha->pdev))
1553 break;
1554
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001555 if (ha->hw_event_pause_errors == 0)
1556 qla2x00_post_hwe_work(ha, HW_EVENT_PARITY_ERR,
1557 0, MSW(stat), LSW(stat));
1558 else if (ha->hw_event_pause_errors < 0xffffffff)
1559 ha->hw_event_pause_errors++;
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
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001613static irqreturn_t
1614qla24xx_msix_rsp_q(int irq, void *dev_id)
1615{
1616 scsi_qla_host_t *ha;
1617 struct device_reg_24xx __iomem *reg;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001618
1619 ha = dev_id;
1620 reg = &ha->iobase->isp24;
1621
Andrew Vasquezc6952482008-04-03 13:13:17 -07001622 spin_lock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001623
1624 qla24xx_process_response_queue(ha);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001625 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001626
Andrew Vasquezc6952482008-04-03 13:13:17 -07001627 spin_unlock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001628
1629 return IRQ_HANDLED;
1630}
1631
1632static irqreturn_t
1633qla24xx_msix_default(int irq, void *dev_id)
1634{
1635 scsi_qla_host_t *ha;
1636 struct device_reg_24xx __iomem *reg;
1637 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001638 uint32_t stat;
1639 uint32_t hccr;
1640 uint16_t mb[4];
1641
1642 ha = dev_id;
1643 reg = &ha->iobase->isp24;
1644 status = 0;
1645
Andrew Vasquezc6952482008-04-03 13:13:17 -07001646 spin_lock(&ha->hardware_lock);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001647 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001648 stat = RD_REG_DWORD(&reg->host_status);
1649 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001650 if (pci_channel_offline(ha->pdev))
1651 break;
1652
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001653 if (ha->hw_event_pause_errors == 0)
1654 qla2x00_post_hwe_work(ha, HW_EVENT_PARITY_ERR,
1655 0, MSW(stat), LSW(stat));
1656 else if (ha->hw_event_pause_errors < 0xffffffff)
1657 ha->hw_event_pause_errors++;
1658
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001659 hccr = RD_REG_DWORD(&reg->hccr);
1660
1661 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1662 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001663
1664 qla2xxx_check_risc_status(ha);
1665
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001666 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001667 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1668 break;
1669 } else if ((stat & HSRX_RISC_INT) == 0)
1670 break;
1671
1672 switch (stat & 0xff) {
1673 case 0x1:
1674 case 0x2:
1675 case 0x10:
1676 case 0x11:
1677 qla24xx_mbx_completion(ha, MSW(stat));
1678 status |= MBX_INTERRUPT;
1679
1680 break;
1681 case 0x12:
1682 mb[0] = MSW(stat);
1683 mb[1] = RD_REG_WORD(&reg->mailbox1);
1684 mb[2] = RD_REG_WORD(&reg->mailbox2);
1685 mb[3] = RD_REG_WORD(&reg->mailbox3);
1686 qla2x00_async_event(ha, mb);
1687 break;
1688 case 0x13:
1689 qla24xx_process_response_queue(ha);
1690 break;
1691 default:
1692 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1693 "(%d).\n",
1694 ha->host_no, stat & 0xff));
1695 break;
1696 }
1697 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001698 } while (0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07001699 spin_unlock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001700
1701 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1702 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001703 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001704 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001705 }
1706
1707 return IRQ_HANDLED;
1708}
1709
1710/* Interrupt handling helpers. */
1711
1712struct qla_init_msix_entry {
1713 uint16_t entry;
1714 uint16_t index;
1715 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001716 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001717};
1718
1719static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1720 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1721 "qla2xxx (default)", qla24xx_msix_default },
1722
1723 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1724 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1725};
1726
1727static void
1728qla24xx_disable_msix(scsi_qla_host_t *ha)
1729{
1730 int i;
1731 struct qla_msix_entry *qentry;
1732
1733 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1734 qentry = &ha->msix_entries[imsix_entries[i].index];
1735 if (qentry->have_irq)
1736 free_irq(qentry->msix_vector, ha);
1737 }
1738 pci_disable_msix(ha->pdev);
1739}
1740
1741static int
1742qla24xx_enable_msix(scsi_qla_host_t *ha)
1743{
1744 int i, ret;
1745 struct msix_entry entries[QLA_MSIX_ENTRIES];
1746 struct qla_msix_entry *qentry;
1747
1748 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1749 entries[i].entry = imsix_entries[i].entry;
1750
1751 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1752 if (ret) {
1753 qla_printk(KERN_WARNING, ha,
1754 "MSI-X: Failed to enable support -- %d/%d\n",
1755 QLA_MSIX_ENTRIES, ret);
1756 goto msix_out;
1757 }
1758 ha->flags.msix_enabled = 1;
1759
1760 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1761 qentry = &ha->msix_entries[imsix_entries[i].index];
1762 qentry->msix_vector = entries[i].vector;
1763 qentry->msix_entry = entries[i].entry;
1764 qentry->have_irq = 0;
1765 ret = request_irq(qentry->msix_vector,
1766 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1767 if (ret) {
1768 qla_printk(KERN_WARNING, ha,
1769 "MSI-X: Unable to register handler -- %x/%d.\n",
1770 imsix_entries[i].index, ret);
1771 qla24xx_disable_msix(ha);
1772 goto msix_out;
1773 }
1774 qentry->have_irq = 1;
1775 }
1776
1777msix_out:
1778 return ret;
1779}
1780
1781int
1782qla2x00_request_irqs(scsi_qla_host_t *ha)
1783{
1784 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001785 device_reg_t __iomem *reg = ha->iobase;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001786
1787 /* If possible, enable MSI-X. */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001788 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001789 goto skip_msix;
1790
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001791 if (IS_QLA2432(ha) && (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1792 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001793 DEBUG2(qla_printk(KERN_WARNING, ha,
1794 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1795 ha->chip_revision, ha->fw_attributes));
1796
1797 goto skip_msix;
1798 }
1799
Andrew Vasquezda7429f2008-01-17 09:02:11 -08001800 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1801 (ha->pdev->subsystem_device == 0x7040 ||
1802 ha->pdev->subsystem_device == 0x7041 ||
1803 ha->pdev->subsystem_device == 0x1705)) {
1804 DEBUG2(qla_printk(KERN_WARNING, ha,
1805 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1806 ha->pdev->subsystem_vendor,
1807 ha->pdev->subsystem_device));
1808
1809 goto skip_msi;
1810 }
1811
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001812 ret = qla24xx_enable_msix(ha);
1813 if (!ret) {
1814 DEBUG2(qla_printk(KERN_INFO, ha,
1815 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1816 ha->fw_attributes));
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001817 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001818 }
1819 qla_printk(KERN_WARNING, ha,
1820 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1821skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001822
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001823 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001824 goto skip_msi;
1825
1826 ret = pci_enable_msi(ha->pdev);
1827 if (!ret) {
1828 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1829 ha->flags.msi_enabled = 1;
1830 }
1831skip_msi:
1832
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001833 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001834 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001835 if (ret) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001836 qla_printk(KERN_WARNING, ha,
1837 "Failed to reserve interrupt %d already in use.\n",
1838 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001839 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001840 }
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001841 ha->flags.inta_enabled = 1;
1842 ha->host->irq = ha->pdev->irq;
1843clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001844
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001845 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezc6952482008-04-03 13:13:17 -07001846 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001847 if (IS_FWI2_CAPABLE(ha)) {
1848 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1849 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1850 } else {
1851 WRT_REG_WORD(&reg->isp.semaphore, 0);
1852 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1853 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
1854 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001855 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001856 ha->isp_ops->enable_intrs(ha);
1857
1858fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001859 return ret;
1860}
1861
1862void
1863qla2x00_free_irqs(scsi_qla_host_t *ha)
1864{
1865
1866 if (ha->flags.msix_enabled)
1867 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001868 else if (ha->flags.inta_enabled) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001869 free_irq(ha->host->irq, ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001870 pci_disable_msi(ha->pdev);
1871 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001872}