blob: 088464251d7e6aa1f92b35f7eadd405099fa0949 [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 Vasquezcb8dacb2008-04-03 13:13:19 -0700352 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700353 ha->isp_ops->fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Andrew Vasqueze4289242007-07-19 15:05:56 -0700355 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700356 if (mb[1] == 0 && mb[2] == 0) {
357 qla_printk(KERN_ERR, ha,
358 "Unrecoverable Hardware Error: adapter "
359 "marked OFFLINE!\n");
360 ha->flags.online = 0;
361 } else
362 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
363 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 qla_printk(KERN_INFO, ha,
365 "Unrecoverable Hardware Error: adapter marked "
366 "OFFLINE!\n");
367 ha->flags.online = 0;
368 } else
369 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
370 break;
371
372 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
373 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
374 ha->host_no));
375 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
376
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700377 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
379 break;
380
381 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
382 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
383 ha->host_no));
384 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
385
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700386 qla2x00_post_hwe_work(ha, mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
388 break;
389
390 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
391 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
392 ha->host_no));
393 break;
394
395 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
397 mb[1]));
398 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
399
400 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
401 atomic_set(&ha->loop_state, LOOP_DOWN);
402 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800403 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700406 if (ha->parent) {
407 atomic_set(&ha->vp_state, VP_FAILED);
408 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
409 }
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
412
413 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700414 qla2x00_post_aen_work(ha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 break;
416
417 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
419 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700420 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700422 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 if (mb[1] < 5)
424 link_speed = link_speeds[mb[1]];
425 ha->link_data_rate = mb[1];
426 }
427
428 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
429 ha->host_no, link_speed));
430 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
431 link_speed);
432
433 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700434 qla2x00_post_aen_work(ha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 break;
436
437 case MBA_LOOP_DOWN: /* Loop Down Event */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700438 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
439 ha->host_no, mb[1]));
440 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
443 atomic_set(&ha->loop_state, LOOP_DOWN);
444 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
445 ha->device_flags |= DFLG_NO_CABLE;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800446 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 }
448
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700449 if (ha->parent) {
450 atomic_set(&ha->vp_state, VP_FAILED);
451 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
452 }
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 ha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700455 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Andrew Vasquezcca53352005-08-26 19:08:30 -0700456 if (ql2xfdmienable)
457 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -0700458 qla2x00_post_aen_work(ha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 break;
460
461 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
463 ha->host_no, mb[1]));
464 qla_printk(KERN_INFO, ha,
465 "LIP reset occured (%x).\n", mb[1]);
466
467 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
468 atomic_set(&ha->loop_state, LOOP_DOWN);
469 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800470 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
472
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700473 if (ha->parent) {
474 atomic_set(&ha->vp_state, VP_FAILED);
475 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
476 }
477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
479
480 ha->operating_mode = LOOP;
481 ha->flags.management_server_logged_in = 0;
Andrew Vasquez0971de72008-04-03 13:13:18 -0700482 qla2x00_post_aen_work(ha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 break;
484
485 case MBA_POINT_TO_POINT: /* Point-to-Point */
486 if (IS_QLA2100(ha))
487 break;
488
489 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
490 ha->host_no));
491
492 /*
493 * Until there's a transition from loop down to loop up, treat
494 * this as loop down only.
495 */
496 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
497 atomic_set(&ha->loop_state, LOOP_DOWN);
498 if (!atomic_read(&ha->loop_down_timer))
499 atomic_set(&ha->loop_down_timer,
500 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800501 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700504 if (ha->parent) {
505 atomic_set(&ha->vp_state, VP_FAILED);
506 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
507 }
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
510 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
511 }
512 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800513
514 ha->flags.gpsc_supported = 1;
Andrew Vasquez02d638b2007-08-12 18:22:54 -0700515 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 break;
517
518 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
519 if (IS_QLA2100(ha))
520 break;
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
523 "received.\n",
524 ha->host_no));
525 qla_printk(KERN_INFO, ha,
526 "Configuration change detected: value=%x.\n", mb[1]);
527
528 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700529 atomic_set(&ha->loop_state, LOOP_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (!atomic_read(&ha->loop_down_timer))
531 atomic_set(&ha->loop_down_timer,
532 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800533 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
535
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700536 if (ha->parent) {
537 atomic_set(&ha->vp_state, VP_FAILED);
538 fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED);
539 }
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
542 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
543 break;
544
545 case MBA_PORT_UPDATE: /* Port database update */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
548 * event etc. earlier indicating loop is down) then process
549 * it. Otherwise ignore it and Wait for RSCN to come in.
550 */
551 atomic_set(&ha->loop_down_timer, 0);
552 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
553 atomic_read(&ha->loop_state) != LOOP_DEAD) {
554 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700555 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
556 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 break;
558 }
559
560 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
561 ha->host_no));
562 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700563 "scsi(%ld): Port database changed %04x %04x %04x.\n",
564 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 /*
567 * Mark all devices as missing so we will login again.
568 */
569 atomic_set(&ha->loop_state, LOOP_UP);
570
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800571 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 ha->flags.rscn_queue_overflow = 1;
574
575 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
576 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 break;
578
579 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700580 /* Check if the Vport has issued a SCR */
581 if (ha->parent && test_bit(VP_SCR_NEEDED, &ha->vp_flags))
582 break;
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800583 /* Only handle SCNs for our Vport index. */
584 if (ha->flags.npiv_supported && ha->vp_idx != mb[3])
585 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
588 ha->host_no));
589 DEBUG(printk(KERN_INFO
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800590 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
591 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
593 rscn_entry = (mb[1] << 16) | mb[2];
594 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
595 ha->d_id.b.al_pa;
596 if (rscn_entry == host_pid) {
597 DEBUG(printk(KERN_INFO
598 "scsi(%ld): Ignoring RSCN update to local host "
599 "port ID (%06x)\n",
600 ha->host_no, host_pid));
601 break;
602 }
603
604 rscn_queue_index = ha->rscn_in_ptr + 1;
605 if (rscn_queue_index == MAX_RSCN_COUNT)
606 rscn_queue_index = 0;
607 if (rscn_queue_index != ha->rscn_out_ptr) {
608 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
609 ha->rscn_in_ptr = rscn_queue_index;
610 } else {
611 ha->flags.rscn_queue_overflow = 1;
612 }
613
614 atomic_set(&ha->loop_state, LOOP_UPDATE);
615 atomic_set(&ha->loop_down_timer, 0);
616 ha->flags.management_server_logged_in = 0;
617
618 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
619 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -0700620 qla2x00_post_aen_work(ha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 break;
622
623 /* case MBA_RIO_RESPONSE: */
624 case MBA_ZIO_RESPONSE:
625 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
626 ha->host_no));
627 DEBUG(printk(KERN_INFO
628 "scsi(%ld): [R|Z]IO update completion.\n",
629 ha->host_no));
630
Andrew Vasqueze4289242007-07-19 15:05:56 -0700631 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700632 qla24xx_process_response_queue(ha);
633 else
634 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700636
637 case MBA_DISCARD_RND_FRAME:
638 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
639 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
640 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700641
642 case MBA_TRACE_NOTIFICATION:
643 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
644 ha->host_no, mb[1], mb[2]));
645 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700647
648 if (!ha->parent && ha->num_vhosts)
649 qla2x00_alert_all_vps(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
651
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700652static void
653qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
654{
655 fc_port_t *fcport = data;
656
657 if (fcport->ha->max_q_depth <= sdev->queue_depth)
658 return;
659
660 if (sdev->ordered_tags)
661 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
662 sdev->queue_depth + 1);
663 else
664 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
665 sdev->queue_depth + 1);
666
667 fcport->last_ramp_up = jiffies;
668
669 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
670 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
671 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
672 sdev->queue_depth));
673}
674
675static void
676qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
677{
678 fc_port_t *fcport = data;
679
680 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
681 return;
682
683 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
684 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
685 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
686 sdev->queue_depth));
687}
688
689static inline void
690qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
691{
692 fc_port_t *fcport;
693 struct scsi_device *sdev;
694
695 sdev = sp->cmd->device;
696 if (sdev->queue_depth >= ha->max_q_depth)
697 return;
698
699 fcport = sp->fcport;
700 if (time_before(jiffies,
701 fcport->last_ramp_up + ql2xqfullrampup * HZ))
702 return;
703 if (time_before(jiffies,
704 fcport->last_queue_full + ql2xqfullrampup * HZ))
705 return;
706
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700707 starget_for_each_device(sdev->sdev_target, fcport,
708 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700709}
710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711/**
712 * qla2x00_process_completed_request() - Process a Fast Post response.
713 * @ha: SCSI driver HA context
714 * @index: SRB index
715 */
716static void
717qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
718{
719 srb_t *sp;
720
721 /* Validate handle. */
722 if (index >= MAX_OUTSTANDING_COMMANDS) {
723 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
724 ha->host_no, index));
725 qla_printk(KERN_WARNING, ha,
726 "Invalid SCSI completion handle %d.\n", index);
727
728 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
729 return;
730 }
731
732 sp = ha->outstanding_cmds[index];
733 if (sp) {
734 /* Free outstanding command slot. */
735 ha->outstanding_cmds[index] = NULL;
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 CMD_COMPL_STATUS(sp->cmd) = 0L;
738 CMD_SCSI_STATUS(sp->cmd) = 0L;
739
740 /* Save ISP completion status */
741 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700742
743 qla2x00_ramp_up_queue_depth(ha, sp);
f4f051e2005-04-17 15:02:26 -0500744 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 } else {
746 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
747 ha->host_no));
748 qla_printk(KERN_WARNING, ha,
749 "Invalid ISP SCSI completion handle\n");
750
751 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
752 }
753}
754
755/**
756 * qla2x00_process_response_queue() - Process response queue entries.
757 * @ha: SCSI driver HA context
758 */
759void
760qla2x00_process_response_queue(struct scsi_qla_host *ha)
761{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700762 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 sts_entry_t *pkt;
764 uint16_t handle_cnt;
765 uint16_t cnt;
766
767 if (!ha->flags.online)
768 return;
769
770 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
771 pkt = (sts_entry_t *)ha->response_ring_ptr;
772
773 ha->rsp_ring_index++;
774 if (ha->rsp_ring_index == ha->response_q_length) {
775 ha->rsp_ring_index = 0;
776 ha->response_ring_ptr = ha->response_ring;
777 } else {
778 ha->response_ring_ptr++;
779 }
780
781 if (pkt->entry_status != 0) {
782 DEBUG3(printk(KERN_INFO
783 "scsi(%ld): Process error entry.\n", ha->host_no));
784
785 qla2x00_error_entry(ha, pkt);
786 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
787 wmb();
788 continue;
789 }
790
791 switch (pkt->entry_type) {
792 case STATUS_TYPE:
793 qla2x00_status_entry(ha, pkt);
794 break;
795 case STATUS_TYPE_21:
796 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
797 for (cnt = 0; cnt < handle_cnt; cnt++) {
798 qla2x00_process_completed_request(ha,
799 ((sts21_entry_t *)pkt)->handle[cnt]);
800 }
801 break;
802 case STATUS_TYPE_22:
803 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
804 for (cnt = 0; cnt < handle_cnt; cnt++) {
805 qla2x00_process_completed_request(ha,
806 ((sts22_entry_t *)pkt)->handle[cnt]);
807 }
808 break;
809 case STATUS_CONT_TYPE:
810 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
811 break;
812 case MS_IOCB_TYPE:
813 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
814 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 default:
816 /* Type Not Supported. */
817 DEBUG4(printk(KERN_WARNING
818 "scsi(%ld): Received unknown response pkt type %x "
819 "entry status=%x.\n",
820 ha->host_no, pkt->entry_type, pkt->entry_status));
821 break;
822 }
823 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
824 wmb();
825 }
826
827 /* Adjust ring index */
828 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
829}
830
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800831static inline void
832qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
833{
834 struct scsi_cmnd *cp = sp->cmd;
835
836 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
837 sense_len = SCSI_SENSE_BUFFERSIZE;
838
839 CMD_ACTUAL_SNSLEN(cp) = sense_len;
840 sp->request_sense_length = sense_len;
841 sp->request_sense_ptr = cp->sense_buffer;
842 if (sp->request_sense_length > 32)
843 sense_len = 32;
844
845 memcpy(cp->sense_buffer, sense_data, sense_len);
846
847 sp->request_sense_ptr += sense_len;
848 sp->request_sense_length -= sense_len;
849 if (sp->request_sense_length != 0)
850 sp->ha->status_srb = sp;
851
852 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
853 "cmd=%p pid=%ld\n", __func__, sp->ha->host_no, cp->device->channel,
854 cp->device->id, cp->device->lun, cp, cp->serial_number));
855 if (sense_len)
856 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
857 CMD_ACTUAL_SNSLEN(cp)));
858}
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860/**
861 * qla2x00_status_entry() - Process a Status IOCB entry.
862 * @ha: SCSI driver HA context
863 * @pkt: Entry pointer
864 */
865static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700866qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 fc_port_t *fcport;
870 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700871 sts_entry_t *sts;
872 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 uint16_t comp_status;
874 uint16_t scsi_status;
875 uint8_t lscsi_status;
876 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700877 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700878 uint8_t *rsp_info, *sense_data;
879
880 sts = (sts_entry_t *) pkt;
881 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700882 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700883 comp_status = le16_to_cpu(sts24->comp_status);
884 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
885 } else {
886 comp_status = le16_to_cpu(sts->comp_status);
887 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
888 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700891 if (comp_status == CS_COMPLETE && scsi_status == 0) {
892 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894 return;
895 }
896
897 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700898 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
899 sp = ha->outstanding_cmds[sts->handle];
900 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 } else
902 sp = NULL;
903
904 if (sp == NULL) {
905 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
906 ha->host_no));
907 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
908
909 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100910 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 return;
912 }
913 cp = sp->cmd;
914 if (cp == NULL) {
915 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700916 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 qla_printk(KERN_WARNING, ha,
918 "Command is NULL: already returned to OS (sp=%p)\n", sp);
919
920 return;
921 }
922
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700923 lscsi_status = scsi_status & STATUS_MASK;
924 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 CMD_COMPL_STATUS(cp) = comp_status;
926 CMD_SCSI_STATUS(cp) = scsi_status;
927
bdf79622005-04-17 15:06:53 -0500928 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Ravi Ananded17c71b52006-05-17 15:08:55 -0700930 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700931 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700932 sense_len = le32_to_cpu(sts24->sense_len);
933 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
934 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -0700935 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700936 rsp_info = sts24->data;
937 sense_data = sts24->data;
938 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
939 } else {
940 sense_len = le16_to_cpu(sts->req_sense_length);
941 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
942 resid_len = le32_to_cpu(sts->residual_length);
943 rsp_info = sts->rsp_info;
944 sense_data = sts->req_sense_data;
945 }
946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 /* Check for any FCP transport errors. */
948 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700949 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700950 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700951 sense_data += rsp_info_len;
952 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
954 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700955 "retrying command\n", ha->host_no,
956 cp->device->channel, cp->device->id,
957 cp->device->lun, rsp_info_len, rsp_info[0],
958 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
959 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500962 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 return;
964 }
965 }
966
Andrew Vasquez3e8ce322008-02-28 14:06:10 -0800967 /* Check for overrun. */
968 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
969 scsi_status & SS_RESIDUAL_OVER)
970 comp_status = CS_DATA_OVERRUN;
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 /*
973 * Based on Host and scsi status generate status code for Linux
974 */
975 switch (comp_status) {
976 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700977 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 if (scsi_status == 0) {
979 cp->result = DID_OK << 16;
980 break;
981 }
982 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700983 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900984 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800986
987 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900988 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800989 cp->underflow)) {
990 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900991 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
992 "detected (%x of %x bytes)...returning "
993 "error status.\n", ha->host_no,
994 cp->device->channel, cp->device->id,
995 cp->device->lun, resid,
996 scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800997
998 cp->result = DID_ERROR << 16;
999 break;
1000 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 cp->result = DID_OK << 16 | lscsi_status;
1003
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001004 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1005 DEBUG2(printk(KERN_INFO
1006 "scsi(%ld): QUEUE FULL status detected "
1007 "0x%x-0x%x.\n", ha->host_no, comp_status,
1008 scsi_status));
1009
1010 /* Adjust queue depth for all luns on the port. */
1011 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001012 starget_for_each_device(cp->device->sdev_target,
1013 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001014 break;
1015 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 if (lscsi_status != SS_CHECK_CONDITION)
1017 break;
1018
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001019 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 if (!(scsi_status & SS_SENSE_LEN_VALID))
1021 break;
1022
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001023 qla2x00_handle_sense(sp, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 break;
1025
1026 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001027 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001028 /* Use F/W calculated residual length. */
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001029 if (IS_FWI2_CAPABLE(ha)) {
1030 if (scsi_status & SS_RESIDUAL_UNDER &&
1031 resid != fw_resid_len) {
1032 scsi_status &= ~SS_RESIDUAL_UNDER;
1033 lscsi_status = 0;
1034 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001035 resid = fw_resid_len;
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001036 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001037
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (scsi_status & SS_RESIDUAL_UNDER) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001039 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001041 } else {
1042 DEBUG2(printk(KERN_INFO
1043 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -07001044 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
1045 "os_underflow=0x%x\n", ha->host_no,
1046 cp->device->id, cp->device->lun, comp_status,
1047 scsi_status, resid_len, resid, cp->cmnd[0],
1048 cp->underflow));
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 }
1051
1052 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001053 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 * Status.
1055 */
1056 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 cp->result = DID_OK << 16 | lscsi_status;
1058
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001059 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1060 DEBUG2(printk(KERN_INFO
1061 "scsi(%ld): QUEUE FULL status detected "
1062 "0x%x-0x%x.\n", ha->host_no, comp_status,
1063 scsi_status));
1064
1065 /*
1066 * Adjust queue depth for all luns on the
1067 * port.
1068 */
1069 fcport->last_queue_full = jiffies;
1070 starget_for_each_device(
1071 cp->device->sdev_target, fcport,
1072 qla2x00_adjust_sdev_qdepth_down);
1073 break;
1074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 if (lscsi_status != SS_CHECK_CONDITION)
1076 break;
1077
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001078 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 if (!(scsi_status & SS_SENSE_LEN_VALID))
1080 break;
1081
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001082 qla2x00_handle_sense(sp, sense_data, sense_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001083
Shyam Sundar8084fe12007-07-19 15:05:59 -07001084 /*
1085 * In case of a Underrun condition, set both the lscsi
1086 * status and the completion status to appropriate
1087 * values.
1088 */
1089 if (resid &&
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001090 ((unsigned)(scsi_bufflen(cp) - resid) <
Shyam Sundar8084fe12007-07-19 15:05:59 -07001091 cp->underflow)) {
1092 DEBUG2(qla_printk(KERN_INFO, ha,
1093 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1094 "detected (%x of %x bytes)...returning "
1095 "error status.\n", ha->host_no,
1096 cp->device->channel, cp->device->id,
1097 cp->device->lun, resid,
Boaz Harrosh4b39c1d2007-07-22 17:28:55 +03001098 scsi_bufflen(cp)));
Shyam Sundar8084fe12007-07-19 15:05:59 -07001099
1100 cp->result = DID_ERROR << 16 | lscsi_status;
1101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 } else {
1103 /*
1104 * If RISC reports underrun and target does not report
1105 * it then we must have a lost frame, so tell upper
1106 * layer to retry it by reporting a bus busy.
1107 */
1108 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1109 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001110 "frame(s) detected (%x of %x bytes)..."
1111 "retrying command.\n", ha->host_no,
1112 cp->device->channel, cp->device->id,
1113 cp->device->lun, resid,
1114 scsi_bufflen(cp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 break;
1118 }
1119
1120 /* Handle mid-layer underflow */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001121 if ((unsigned)(scsi_bufflen(cp) - resid) <
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 cp->underflow) {
1123 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001124 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1125 "detected (%x of %x bytes)...returning "
1126 "error status.\n", ha->host_no,
1127 cp->device->channel, cp->device->id,
1128 cp->device->lun, resid,
1129 scsi_bufflen(cp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
1131 cp->result = DID_ERROR << 16;
1132 break;
1133 }
1134
1135 /* Everybody online, looking good... */
1136 cp->result = DID_OK << 16;
1137 }
1138 break;
1139
1140 case CS_DATA_OVERRUN:
1141 DEBUG2(printk(KERN_INFO
1142 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001143 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1144 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 DEBUG2(printk(KERN_INFO
1146 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1147 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1148 cp->cmnd[4], cp->cmnd[5]));
1149 DEBUG2(printk(KERN_INFO
1150 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1151 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001152 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
1154 cp->result = DID_ERROR << 16;
1155 break;
1156
1157 case CS_PORT_LOGGED_OUT:
1158 case CS_PORT_CONFIG_CHG:
1159 case CS_PORT_BUSY:
1160 case CS_INCOMPLETE:
1161 case CS_PORT_UNAVAILABLE:
1162 /*
1163 * If the port is in Target Down state, return all IOs for this
1164 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1165 * retry_queue.
1166 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1168 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001169 ha->host_no, cp->device->id, cp->device->lun,
1170 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 atomic_read(&fcport->state)));
1172
f4f051e2005-04-17 15:02:26 -05001173 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001175 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 break;
1178
1179 case CS_RESET:
1180 DEBUG2(printk(KERN_INFO
1181 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1182 ha->host_no, comp_status, scsi_status));
1183
f4f051e2005-04-17 15:02:26 -05001184 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 break;
1186
1187 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001188 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 * hv2.19.12 - DID_ABORT does not retry the request if we
1190 * aborted this request then abort otherwise it must be a
1191 * reset.
1192 */
1193 DEBUG2(printk(KERN_INFO
1194 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1195 ha->host_no, comp_status, scsi_status));
1196
1197 cp->result = DID_RESET << 16;
1198 break;
1199
1200 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 cp->result = DID_BUS_BUSY << 16;
1202
Andrew Vasqueze4289242007-07-19 15:05:56 -07001203 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001204 DEBUG2(printk(KERN_INFO
1205 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1206 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1207 cp->device->id, cp->device->lun, comp_status,
1208 scsi_status));
1209 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001211 DEBUG2(printk(KERN_INFO
1212 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1213 "sflags=%x.\n", ha->host_no, cp->device->channel,
1214 cp->device->id, cp->device->lun, comp_status, scsi_status,
1215 le16_to_cpu(sts->status_flags)));
1216
1217 /* Check to see if logout occurred. */
1218 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001219 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 break;
1221
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 default:
1223 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001224 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 qla_printk(KERN_INFO, ha,
1226 "Unknown status detected 0x%x-0x%x.\n",
1227 comp_status, scsi_status);
1228
1229 cp->result = DID_ERROR << 16;
1230 break;
1231 }
1232
1233 /* Place command on done queue. */
1234 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001235 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236}
1237
1238/**
1239 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1240 * @ha: SCSI driver HA context
1241 * @pkt: Entry pointer
1242 *
1243 * Extended sense data.
1244 */
1245static void
1246qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1247{
1248 uint8_t sense_sz = 0;
1249 srb_t *sp = ha->status_srb;
1250 struct scsi_cmnd *cp;
1251
1252 if (sp != NULL && sp->request_sense_length != 0) {
1253 cp = sp->cmd;
1254 if (cp == NULL) {
1255 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001256 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 qla_printk(KERN_INFO, ha,
1258 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001259 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261 ha->status_srb = NULL;
1262 return;
1263 }
1264
1265 if (sp->request_sense_length > sizeof(pkt->data)) {
1266 sense_sz = sizeof(pkt->data);
1267 } else {
1268 sense_sz = sp->request_sense_length;
1269 }
1270
1271 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001272 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001273 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1275 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1276
1277 sp->request_sense_ptr += sense_sz;
1278 sp->request_sense_length -= sense_sz;
1279
1280 /* Place command on done queue. */
1281 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001283 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 }
1285 }
1286}
1287
1288/**
1289 * qla2x00_error_entry() - Process an error entry.
1290 * @ha: SCSI driver HA context
1291 * @pkt: Entry pointer
1292 */
1293static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001294qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295{
1296 srb_t *sp;
1297
1298#if defined(QL_DEBUG_LEVEL_2)
1299 if (pkt->entry_status & RF_INV_E_ORDER)
1300 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1301 else if (pkt->entry_status & RF_INV_E_COUNT)
1302 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1303 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001304 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 "%s: Invalid Entry Parameter\n", __func__);
1306 else if (pkt->entry_status & RF_INV_E_TYPE)
1307 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1308 else if (pkt->entry_status & RF_BUSY)
1309 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1310 else
1311 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1312#endif
1313
1314 /* Validate handle. */
1315 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1316 sp = ha->outstanding_cmds[pkt->handle];
1317 else
1318 sp = NULL;
1319
1320 if (sp) {
1321 /* Free outstanding command slot. */
1322 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001323
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 /* Bad payload or header */
1325 if (pkt->entry_status &
1326 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1327 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1328 sp->cmd->result = DID_ERROR << 16;
1329 } else if (pkt->entry_status & RF_BUSY) {
1330 sp->cmd->result = DID_BUS_BUSY << 16;
1331 } else {
1332 sp->cmd->result = DID_ERROR << 16;
1333 }
f4f051e2005-04-17 15:02:26 -05001334 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001336 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1337 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1339 ha->host_no));
1340 qla_printk(KERN_WARNING, ha,
1341 "Error entry - invalid handle\n");
1342
1343 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001344 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 }
1346}
1347
1348/**
1349 * qla2x00_ms_entry() - Process a Management Server entry.
1350 * @ha: SCSI driver HA context
1351 * @index: Response queue out pointer
1352 */
1353static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001354qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355{
1356 srb_t *sp;
1357
1358 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1359 __func__, ha->host_no, pkt, pkt->handle1));
1360
1361 /* Validate handle. */
1362 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1363 sp = ha->outstanding_cmds[pkt->handle1];
1364 else
1365 sp = NULL;
1366
1367 if (sp == NULL) {
1368 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1369 ha->host_no));
1370 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1371
1372 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1373 return;
1374 }
1375
1376 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1377 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1378
1379 /* Free outstanding command slot. */
1380 ha->outstanding_cmds[pkt->handle1] = NULL;
1381
f4f051e2005-04-17 15:02:26 -05001382 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383}
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001384
1385
1386/**
1387 * qla24xx_mbx_completion() - Process mailbox command completions.
1388 * @ha: SCSI driver HA context
1389 * @mb0: Mailbox0 register
1390 */
1391static void
1392qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1393{
1394 uint16_t cnt;
1395 uint16_t __iomem *wptr;
1396 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1397
1398 /* Load return mailbox registers. */
1399 ha->flags.mbox_int = 1;
1400 ha->mailbox_out[0] = mb0;
1401 wptr = (uint16_t __iomem *)&reg->mailbox1;
1402
1403 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1404 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1405 wptr++;
1406 }
1407
1408 if (ha->mcp) {
1409 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1410 __func__, ha->host_no, ha->mcp->mb[0]));
1411 } else {
1412 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1413 __func__, ha->host_no));
1414 }
1415}
1416
1417/**
1418 * qla24xx_process_response_queue() - Process response queue entries.
1419 * @ha: SCSI driver HA context
1420 */
1421void
1422qla24xx_process_response_queue(struct scsi_qla_host *ha)
1423{
1424 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1425 struct sts_entry_24xx *pkt;
1426
1427 if (!ha->flags.online)
1428 return;
1429
1430 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1431 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1432
1433 ha->rsp_ring_index++;
1434 if (ha->rsp_ring_index == ha->response_q_length) {
1435 ha->rsp_ring_index = 0;
1436 ha->response_ring_ptr = ha->response_ring;
1437 } else {
1438 ha->response_ring_ptr++;
1439 }
1440
1441 if (pkt->entry_status != 0) {
1442 DEBUG3(printk(KERN_INFO
1443 "scsi(%ld): Process error entry.\n", ha->host_no));
1444
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001445 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1446 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1447 wmb();
1448 continue;
1449 }
1450
1451 switch (pkt->entry_type) {
1452 case STATUS_TYPE:
1453 qla2x00_status_entry(ha, pkt);
1454 break;
1455 case STATUS_CONT_TYPE:
1456 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1457 break;
1458 case MS_IOCB_TYPE:
1459 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1460 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001461 case VP_RPT_ID_IOCB_TYPE:
1462 qla24xx_report_id_acquisition(ha,
1463 (struct vp_rpt_id_entry_24xx *)pkt);
1464 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001465 default:
1466 /* Type Not Supported. */
1467 DEBUG4(printk(KERN_WARNING
1468 "scsi(%ld): Received unknown response pkt type %x "
1469 "entry status=%x.\n",
1470 ha->host_no, pkt->entry_type, pkt->entry_status));
1471 break;
1472 }
1473 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1474 wmb();
1475 }
1476
1477 /* Adjust ring index */
1478 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1479}
1480
Andrew Vasquez05236a02007-09-20 14:07:37 -07001481static void
1482qla2xxx_check_risc_status(scsi_qla_host_t *ha)
1483{
1484 int rval;
1485 uint32_t cnt;
1486 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1487
1488 if (!IS_QLA25XX(ha))
1489 return;
1490
1491 rval = QLA_SUCCESS;
1492 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1493 RD_REG_DWORD(&reg->iobase_addr);
1494 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1495 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1496 rval == QLA_SUCCESS; cnt--) {
1497 if (cnt) {
1498 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1499 udelay(10);
1500 } else
1501 rval = QLA_FUNCTION_TIMEOUT;
1502 }
1503 if (rval == QLA_SUCCESS)
1504 goto next_test;
1505
1506 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1507 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1508 rval == QLA_SUCCESS; cnt--) {
1509 if (cnt) {
1510 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1511 udelay(10);
1512 } else
1513 rval = QLA_FUNCTION_TIMEOUT;
1514 }
1515 if (rval != QLA_SUCCESS)
1516 goto done;
1517
1518next_test:
1519 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1520 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1521
1522done:
1523 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1524 RD_REG_DWORD(&reg->iobase_window);
1525}
1526
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001527/**
1528 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1529 * @irq:
1530 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001531 *
1532 * Called by system whenever the host adapter generates an interrupt.
1533 *
1534 * Returns handled flag.
1535 */
1536irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001537qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001538{
1539 scsi_qla_host_t *ha;
1540 struct device_reg_24xx __iomem *reg;
1541 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001542 unsigned long iter;
1543 uint32_t stat;
1544 uint32_t hccr;
1545 uint16_t mb[4];
1546
1547 ha = (scsi_qla_host_t *) dev_id;
1548 if (!ha) {
1549 printk(KERN_INFO
1550 "%s(): NULL host pointer\n", __func__);
1551 return IRQ_NONE;
1552 }
1553
1554 reg = &ha->iobase->isp24;
1555 status = 0;
1556
Andrew Vasquezc6952482008-04-03 13:13:17 -07001557 spin_lock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001558 for (iter = 50; iter--; ) {
1559 stat = RD_REG_DWORD(&reg->host_status);
1560 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001561 if (pci_channel_offline(ha->pdev))
1562 break;
1563
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001564 if (ha->hw_event_pause_errors == 0)
1565 qla2x00_post_hwe_work(ha, HW_EVENT_PARITY_ERR,
1566 0, MSW(stat), LSW(stat));
1567 else if (ha->hw_event_pause_errors < 0xffffffff)
1568 ha->hw_event_pause_errors++;
1569
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001570 hccr = RD_REG_DWORD(&reg->hccr);
1571
1572 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1573 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001574
1575 qla2xxx_check_risc_status(ha);
1576
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001577 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001578 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1579 break;
1580 } else if ((stat & HSRX_RISC_INT) == 0)
1581 break;
1582
1583 switch (stat & 0xff) {
1584 case 0x1:
1585 case 0x2:
1586 case 0x10:
1587 case 0x11:
1588 qla24xx_mbx_completion(ha, MSW(stat));
1589 status |= MBX_INTERRUPT;
1590
1591 break;
1592 case 0x12:
1593 mb[0] = MSW(stat);
1594 mb[1] = RD_REG_WORD(&reg->mailbox1);
1595 mb[2] = RD_REG_WORD(&reg->mailbox2);
1596 mb[3] = RD_REG_WORD(&reg->mailbox3);
1597 qla2x00_async_event(ha, mb);
1598 break;
1599 case 0x13:
1600 qla24xx_process_response_queue(ha);
1601 break;
1602 default:
1603 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1604 "(%d).\n",
1605 ha->host_no, stat & 0xff));
1606 break;
1607 }
1608 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1609 RD_REG_DWORD_RELAXED(&reg->hccr);
1610 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001611 spin_unlock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001612
1613 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1614 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001615 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001616 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001617 }
1618
1619 return IRQ_HANDLED;
1620}
1621
1622/**
1623 * qla24xx_ms_entry() - Process a Management Server entry.
1624 * @ha: SCSI driver HA context
1625 * @index: Response queue out pointer
1626 */
1627static void
1628qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1629{
1630 srb_t *sp;
1631
1632 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1633 __func__, ha->host_no, pkt, pkt->handle));
1634
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001635 DEBUG9(printk("%s: ct pkt dump:\n", __func__));
1636 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx)));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001637
1638 /* Validate handle. */
1639 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1640 sp = ha->outstanding_cmds[pkt->handle];
1641 else
1642 sp = NULL;
1643
1644 if (sp == NULL) {
1645 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1646 ha->host_no));
1647 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1648 ha->host_no));
1649 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1650 pkt->handle);
1651
1652 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1653 return;
1654 }
1655
1656 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1657 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1658
1659 /* Free outstanding command slot. */
1660 ha->outstanding_cmds[pkt->handle] = NULL;
1661
1662 qla2x00_sp_compl(ha, sp);
1663}
1664
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001665static irqreturn_t
1666qla24xx_msix_rsp_q(int irq, void *dev_id)
1667{
1668 scsi_qla_host_t *ha;
1669 struct device_reg_24xx __iomem *reg;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001670
1671 ha = dev_id;
1672 reg = &ha->iobase->isp24;
1673
Andrew Vasquezc6952482008-04-03 13:13:17 -07001674 spin_lock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001675
1676 qla24xx_process_response_queue(ha);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001677 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001678
Andrew Vasquezc6952482008-04-03 13:13:17 -07001679 spin_unlock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001680
1681 return IRQ_HANDLED;
1682}
1683
1684static irqreturn_t
1685qla24xx_msix_default(int irq, void *dev_id)
1686{
1687 scsi_qla_host_t *ha;
1688 struct device_reg_24xx __iomem *reg;
1689 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001690 uint32_t stat;
1691 uint32_t hccr;
1692 uint16_t mb[4];
1693
1694 ha = dev_id;
1695 reg = &ha->iobase->isp24;
1696 status = 0;
1697
Andrew Vasquezc6952482008-04-03 13:13:17 -07001698 spin_lock(&ha->hardware_lock);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001699 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001700 stat = RD_REG_DWORD(&reg->host_status);
1701 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001702 if (pci_channel_offline(ha->pdev))
1703 break;
1704
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001705 if (ha->hw_event_pause_errors == 0)
1706 qla2x00_post_hwe_work(ha, HW_EVENT_PARITY_ERR,
1707 0, MSW(stat), LSW(stat));
1708 else if (ha->hw_event_pause_errors < 0xffffffff)
1709 ha->hw_event_pause_errors++;
1710
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001711 hccr = RD_REG_DWORD(&reg->hccr);
1712
1713 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1714 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001715
1716 qla2xxx_check_risc_status(ha);
1717
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001718 ha->isp_ops->fw_dump(ha, 1);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001719 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1720 break;
1721 } else if ((stat & HSRX_RISC_INT) == 0)
1722 break;
1723
1724 switch (stat & 0xff) {
1725 case 0x1:
1726 case 0x2:
1727 case 0x10:
1728 case 0x11:
1729 qla24xx_mbx_completion(ha, MSW(stat));
1730 status |= MBX_INTERRUPT;
1731
1732 break;
1733 case 0x12:
1734 mb[0] = MSW(stat);
1735 mb[1] = RD_REG_WORD(&reg->mailbox1);
1736 mb[2] = RD_REG_WORD(&reg->mailbox2);
1737 mb[3] = RD_REG_WORD(&reg->mailbox3);
1738 qla2x00_async_event(ha, mb);
1739 break;
1740 case 0x13:
1741 qla24xx_process_response_queue(ha);
1742 break;
1743 default:
1744 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1745 "(%d).\n",
1746 ha->host_no, stat & 0xff));
1747 break;
1748 }
1749 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001750 } while (0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07001751 spin_unlock(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001752
1753 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1754 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001755 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001756 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001757 }
1758
1759 return IRQ_HANDLED;
1760}
1761
1762/* Interrupt handling helpers. */
1763
1764struct qla_init_msix_entry {
1765 uint16_t entry;
1766 uint16_t index;
1767 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001768 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001769};
1770
1771static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1772 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1773 "qla2xxx (default)", qla24xx_msix_default },
1774
1775 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1776 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1777};
1778
1779static void
1780qla24xx_disable_msix(scsi_qla_host_t *ha)
1781{
1782 int i;
1783 struct qla_msix_entry *qentry;
1784
1785 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1786 qentry = &ha->msix_entries[imsix_entries[i].index];
1787 if (qentry->have_irq)
1788 free_irq(qentry->msix_vector, ha);
1789 }
1790 pci_disable_msix(ha->pdev);
1791}
1792
1793static int
1794qla24xx_enable_msix(scsi_qla_host_t *ha)
1795{
1796 int i, ret;
1797 struct msix_entry entries[QLA_MSIX_ENTRIES];
1798 struct qla_msix_entry *qentry;
1799
1800 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1801 entries[i].entry = imsix_entries[i].entry;
1802
1803 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1804 if (ret) {
1805 qla_printk(KERN_WARNING, ha,
1806 "MSI-X: Failed to enable support -- %d/%d\n",
1807 QLA_MSIX_ENTRIES, ret);
1808 goto msix_out;
1809 }
1810 ha->flags.msix_enabled = 1;
1811
1812 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1813 qentry = &ha->msix_entries[imsix_entries[i].index];
1814 qentry->msix_vector = entries[i].vector;
1815 qentry->msix_entry = entries[i].entry;
1816 qentry->have_irq = 0;
1817 ret = request_irq(qentry->msix_vector,
1818 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1819 if (ret) {
1820 qla_printk(KERN_WARNING, ha,
1821 "MSI-X: Unable to register handler -- %x/%d.\n",
1822 imsix_entries[i].index, ret);
1823 qla24xx_disable_msix(ha);
1824 goto msix_out;
1825 }
1826 qentry->have_irq = 1;
1827 }
1828
1829msix_out:
1830 return ret;
1831}
1832
1833int
1834qla2x00_request_irqs(scsi_qla_host_t *ha)
1835{
1836 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001837 device_reg_t __iomem *reg = ha->iobase;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001838
1839 /* If possible, enable MSI-X. */
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001840 if (!IS_QLA2432(ha) && !IS_QLA2532(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001841 goto skip_msix;
1842
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001843 if (IS_QLA2432(ha) && (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1844 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001845 DEBUG2(qla_printk(KERN_WARNING, ha,
1846 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1847 ha->chip_revision, ha->fw_attributes));
1848
1849 goto skip_msix;
1850 }
1851
Andrew Vasquezda7429f2008-01-17 09:02:11 -08001852 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1853 (ha->pdev->subsystem_device == 0x7040 ||
1854 ha->pdev->subsystem_device == 0x7041 ||
1855 ha->pdev->subsystem_device == 0x1705)) {
1856 DEBUG2(qla_printk(KERN_WARNING, ha,
1857 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1858 ha->pdev->subsystem_vendor,
1859 ha->pdev->subsystem_device));
1860
1861 goto skip_msi;
1862 }
1863
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001864 ret = qla24xx_enable_msix(ha);
1865 if (!ret) {
1866 DEBUG2(qla_printk(KERN_INFO, ha,
1867 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1868 ha->fw_attributes));
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001869 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001870 }
1871 qla_printk(KERN_WARNING, ha,
1872 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1873skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001874
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001875 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001876 goto skip_msi;
1877
1878 ret = pci_enable_msi(ha->pdev);
1879 if (!ret) {
1880 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1881 ha->flags.msi_enabled = 1;
1882 }
1883skip_msi:
1884
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001885 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001886 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001887 if (ret) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001888 qla_printk(KERN_WARNING, ha,
1889 "Failed to reserve interrupt %d already in use.\n",
1890 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001891 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001892 }
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001893 ha->flags.inta_enabled = 1;
1894 ha->host->irq = ha->pdev->irq;
1895clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001896
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001897 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezc6952482008-04-03 13:13:17 -07001898 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001899 if (IS_FWI2_CAPABLE(ha)) {
1900 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1901 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1902 } else {
1903 WRT_REG_WORD(&reg->isp.semaphore, 0);
1904 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1905 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
1906 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001907 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001908 ha->isp_ops->enable_intrs(ha);
1909
1910fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001911 return ret;
1912}
1913
1914void
1915qla2x00_free_irqs(scsi_qla_host_t *ha)
1916{
1917
1918 if (ha->flags.msix_enabled)
1919 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001920 else if (ha->flags.inta_enabled) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001921 free_irq(ha->host->irq, ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001922 pci_disable_msi(ha->pdev);
1923 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001924}