]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/scsi/qla2xxx/qla_isr.c
[SCSI] qla2xxx: Remove implicit ISP-abort after a flash update.
[net-next-2.6.git] / drivers / scsi / qla2xxx / qla_isr.c
CommitLineData
1da177e4 1/*
fa90c54f 2 * QLogic Fibre Channel HBA Driver
01e58d8e 3 * Copyright (c) 2003-2008 QLogic Corporation
1da177e4 4 *
fa90c54f 5 * See LICENSE.qla2xxx for copyright and licensing details.
1da177e4
LT
6 */
7#include "qla_def.h"
8
05236a05 9#include <linux/delay.h>
df7baa50
AV
10#include <scsi/scsi_tcq.h>
11
1da177e4 12static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
73208dfd
AC
13static void qla2x00_process_completed_request(struct scsi_qla_host *,
14 struct req_que *, uint32_t);
15static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
1da177e4 16static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *);
73208dfd
AC
17static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
18 sts_entry_t *);
e315cd28 19static struct scsi_qla_host *qla2x00_get_rsp_host(struct rsp_que *);
9a853f71 20
1da177e4
LT
21/**
22 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
23 * @irq:
24 * @dev_id: SCSI driver HA context
1da177e4
LT
25 *
26 * Called by system whenever the host adapter generates an interrupt.
27 *
28 * Returns handled flag.
29 */
30irqreturn_t
7d12e780 31qla2100_intr_handler(int irq, void *dev_id)
1da177e4 32{
e315cd28
AC
33 scsi_qla_host_t *vha;
34 struct qla_hw_data *ha;
3d71644c 35 struct device_reg_2xxx __iomem *reg;
1da177e4 36 int status;
1da177e4 37 unsigned long iter;
14e660e6 38 uint16_t hccr;
9a853f71 39 uint16_t mb[4];
e315cd28 40 struct rsp_que *rsp;
1da177e4 41
e315cd28
AC
42 rsp = (struct rsp_que *) dev_id;
43 if (!rsp) {
1da177e4 44 printk(KERN_INFO
e315cd28 45 "%s(): NULL response queue pointer\n", __func__);
1da177e4
LT
46 return (IRQ_NONE);
47 }
48
e315cd28 49 ha = rsp->hw;
3d71644c 50 reg = &ha->iobase->isp;
1da177e4
LT
51 status = 0;
52
c6952483 53 spin_lock(&ha->hardware_lock);
e315cd28 54 vha = qla2x00_get_rsp_host(rsp);
1da177e4 55 for (iter = 50; iter--; ) {
14e660e6
SJ
56 hccr = RD_REG_WORD(&reg->hccr);
57 if (hccr & HCCR_RISC_PAUSE) {
58 if (pci_channel_offline(ha->pdev))
59 break;
60
61 /*
62 * Issue a "HARD" reset in order for the RISC interrupt
63 * bit to be cleared. Schedule a big hammmer to get
64 * out of the RISC PAUSED state.
65 */
66 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
67 RD_REG_WORD(&reg->hccr);
68
e315cd28
AC
69 ha->isp_ops->fw_dump(vha, 1);
70 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
14e660e6
SJ
71 break;
72 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
1da177e4
LT
73 break;
74
75 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
76 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
77 RD_REG_WORD(&reg->hccr);
78
79 /* Get mailbox data. */
9a853f71
AV
80 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
81 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
e315cd28 82 qla2x00_mbx_completion(vha, mb[0]);
1da177e4 83 status |= MBX_INTERRUPT;
9a853f71
AV
84 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
85 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
86 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
87 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
73208dfd 88 qla2x00_async_event(vha, rsp, mb);
1da177e4
LT
89 } else {
90 /*EMPTY*/
91 DEBUG2(printk("scsi(%ld): Unrecognized "
9a853f71 92 "interrupt type (%d).\n",
e315cd28 93 vha->host_no, mb[0]));
1da177e4
LT
94 }
95 /* Release mailbox registers. */
96 WRT_REG_WORD(&reg->semaphore, 0);
97 RD_REG_WORD(&reg->semaphore);
98 } else {
73208dfd 99 qla2x00_process_response_queue(rsp);
1da177e4
LT
100
101 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
102 RD_REG_WORD(&reg->hccr);
103 }
104 }
c6952483 105 spin_unlock(&ha->hardware_lock);
1da177e4 106
1da177e4
LT
107 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
108 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1da177e4 109 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
0b05a1f0 110 complete(&ha->mbx_intr_comp);
1da177e4
LT
111 }
112
1da177e4
LT
113 return (IRQ_HANDLED);
114}
115
116/**
117 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
118 * @irq:
119 * @dev_id: SCSI driver HA context
1da177e4
LT
120 *
121 * Called by system whenever the host adapter generates an interrupt.
122 *
123 * Returns handled flag.
124 */
125irqreturn_t
7d12e780 126qla2300_intr_handler(int irq, void *dev_id)
1da177e4 127{
e315cd28 128 scsi_qla_host_t *vha;
3d71644c 129 struct device_reg_2xxx __iomem *reg;
1da177e4 130 int status;
1da177e4
LT
131 unsigned long iter;
132 uint32_t stat;
1da177e4 133 uint16_t hccr;
9a853f71 134 uint16_t mb[4];
e315cd28
AC
135 struct rsp_que *rsp;
136 struct qla_hw_data *ha;
1da177e4 137
e315cd28
AC
138 rsp = (struct rsp_que *) dev_id;
139 if (!rsp) {
1da177e4 140 printk(KERN_INFO
e315cd28 141 "%s(): NULL response queue pointer\n", __func__);
1da177e4
LT
142 return (IRQ_NONE);
143 }
144
e315cd28 145 ha = rsp->hw;
3d71644c 146 reg = &ha->iobase->isp;
1da177e4
LT
147 status = 0;
148
c6952483 149 spin_lock(&ha->hardware_lock);
e315cd28 150 vha = qla2x00_get_rsp_host(rsp);
1da177e4
LT
151 for (iter = 50; iter--; ) {
152 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
153 if (stat & HSR_RISC_PAUSED) {
14e660e6
SJ
154 if (pci_channel_offline(ha->pdev))
155 break;
156
1da177e4
LT
157 hccr = RD_REG_WORD(&reg->hccr);
158 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
07f31805
AV
159 qla_printk(KERN_INFO, ha, "Parity error -- "
160 "HCCR=%x, Dumping firmware!\n", hccr);
1da177e4 161 else
07f31805
AV
162 qla_printk(KERN_INFO, ha, "RISC paused -- "
163 "HCCR=%x, Dumping firmware!\n", hccr);
1da177e4
LT
164
165 /*
166 * Issue a "HARD" reset in order for the RISC
167 * interrupt bit to be cleared. Schedule a big
168 * hammmer to get out of the RISC PAUSED state.
169 */
170 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
171 RD_REG_WORD(&reg->hccr);
07f31805 172
e315cd28
AC
173 ha->isp_ops->fw_dump(vha, 1);
174 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1da177e4
LT
175 break;
176 } else if ((stat & HSR_RISC_INT) == 0)
177 break;
178
1da177e4 179 switch (stat & 0xff) {
1da177e4
LT
180 case 0x1:
181 case 0x2:
182 case 0x10:
183 case 0x11:
e315cd28 184 qla2x00_mbx_completion(vha, MSW(stat));
1da177e4
LT
185 status |= MBX_INTERRUPT;
186
187 /* Release mailbox registers. */
188 WRT_REG_WORD(&reg->semaphore, 0);
189 break;
190 case 0x12:
9a853f71
AV
191 mb[0] = MSW(stat);
192 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
193 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
194 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
73208dfd 195 qla2x00_async_event(vha, rsp, mb);
9a853f71
AV
196 break;
197 case 0x13:
73208dfd 198 qla2x00_process_response_queue(rsp);
1da177e4
LT
199 break;
200 case 0x15:
9a853f71
AV
201 mb[0] = MBA_CMPLT_1_16BIT;
202 mb[1] = MSW(stat);
73208dfd 203 qla2x00_async_event(vha, rsp, mb);
1da177e4
LT
204 break;
205 case 0x16:
9a853f71
AV
206 mb[0] = MBA_SCSI_COMPLETION;
207 mb[1] = MSW(stat);
208 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
73208dfd 209 qla2x00_async_event(vha, rsp, mb);
1da177e4
LT
210 break;
211 default:
212 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
9a853f71 213 "(%d).\n",
e315cd28 214 vha->host_no, stat & 0xff));
1da177e4
LT
215 break;
216 }
217 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
218 RD_REG_WORD_RELAXED(&reg->hccr);
219 }
c6952483 220 spin_unlock(&ha->hardware_lock);
1da177e4 221
1da177e4
LT
222 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
223 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1da177e4 224 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
0b05a1f0 225 complete(&ha->mbx_intr_comp);
1da177e4
LT
226 }
227
1da177e4
LT
228 return (IRQ_HANDLED);
229}
230
231/**
232 * qla2x00_mbx_completion() - Process mailbox command completions.
233 * @ha: SCSI driver HA context
234 * @mb0: Mailbox0 register
235 */
236static void
e315cd28 237qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
1da177e4
LT
238{
239 uint16_t cnt;
240 uint16_t __iomem *wptr;
e315cd28 241 struct qla_hw_data *ha = vha->hw;
3d71644c 242 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1da177e4
LT
243
244 /* Load return mailbox registers. */
245 ha->flags.mbox_int = 1;
246 ha->mailbox_out[0] = mb0;
247 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
248
249 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
fa2a1ce5 250 if (IS_QLA2200(ha) && cnt == 8)
1da177e4
LT
251 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
252 if (cnt == 4 || cnt == 5)
253 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
254 else
255 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
fa2a1ce5 256
1da177e4
LT
257 wptr++;
258 }
259
260 if (ha->mcp) {
261 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
e315cd28 262 __func__, vha->host_no, ha->mcp->mb[0]));
1da177e4
LT
263 } else {
264 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
e315cd28 265 __func__, vha->host_no));
1da177e4
LT
266 }
267}
268
8a659571
AV
269static void
270qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
271{
272 static char *event[] =
273 { "Complete", "Request Notification", "Time Extension" };
274 int rval;
275 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
276 uint16_t __iomem *wptr;
277 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
278
279 /* Seed data -- mailbox1 -> mailbox7. */
280 wptr = (uint16_t __iomem *)&reg24->mailbox1;
281 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
282 mb[cnt] = RD_REG_WORD(wptr);
283
284 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
285 "%04x %04x %04x %04x %04x %04x %04x.\n", vha->host_no,
286 event[aen & 0xff],
287 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6]));
288
289 /* Acknowledgement needed? [Notify && non-zero timeout]. */
290 timeout = (descr >> 8) & 0xf;
291 if (aen != MBA_IDC_NOTIFY || !timeout)
292 return;
293
294 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
295 "ACK timeout=%d.\n", vha->host_no, event[aen & 0xff], timeout));
296
297 rval = qla2x00_post_idc_ack_work(vha, mb);
298 if (rval != QLA_SUCCESS)
299 qla_printk(KERN_WARNING, vha->hw,
300 "IDC failed to post ACK.\n");
301}
302
1da177e4
LT
303/**
304 * qla2x00_async_event() - Process aynchronous events.
305 * @ha: SCSI driver HA context
9a853f71 306 * @mb: Mailbox registers (0 - 3)
1da177e4 307 */
2c3dfe3f 308void
73208dfd 309qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
1da177e4 310{
9a853f71 311#define LS_UNKNOWN 2
3a03eb79 312 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
1da177e4 313 char *link_speed;
1da177e4
LT
314 uint16_t handle_cnt;
315 uint16_t cnt;
316 uint32_t handles[5];
e315cd28 317 struct qla_hw_data *ha = vha->hw;
3d71644c 318 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1da177e4
LT
319 uint32_t rscn_entry, host_pid;
320 uint8_t rscn_queue_index;
4d4df193 321 unsigned long flags;
1da177e4
LT
322
323 /* Setup to process RIO completion. */
324 handle_cnt = 0;
3a03eb79
AV
325 if (IS_QLA81XX(ha))
326 goto skip_rio;
1da177e4
LT
327 switch (mb[0]) {
328 case MBA_SCSI_COMPLETION:
9a853f71 329 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
1da177e4
LT
330 handle_cnt = 1;
331 break;
332 case MBA_CMPLT_1_16BIT:
9a853f71 333 handles[0] = mb[1];
1da177e4
LT
334 handle_cnt = 1;
335 mb[0] = MBA_SCSI_COMPLETION;
336 break;
337 case MBA_CMPLT_2_16BIT:
9a853f71
AV
338 handles[0] = mb[1];
339 handles[1] = mb[2];
1da177e4
LT
340 handle_cnt = 2;
341 mb[0] = MBA_SCSI_COMPLETION;
342 break;
343 case MBA_CMPLT_3_16BIT:
9a853f71
AV
344 handles[0] = mb[1];
345 handles[1] = mb[2];
346 handles[2] = mb[3];
1da177e4
LT
347 handle_cnt = 3;
348 mb[0] = MBA_SCSI_COMPLETION;
349 break;
350 case MBA_CMPLT_4_16BIT:
9a853f71
AV
351 handles[0] = mb[1];
352 handles[1] = mb[2];
353 handles[2] = mb[3];
1da177e4
LT
354 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
355 handle_cnt = 4;
356 mb[0] = MBA_SCSI_COMPLETION;
357 break;
358 case MBA_CMPLT_5_16BIT:
9a853f71
AV
359 handles[0] = mb[1];
360 handles[1] = mb[2];
361 handles[2] = mb[3];
1da177e4
LT
362 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
363 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
364 handle_cnt = 5;
365 mb[0] = MBA_SCSI_COMPLETION;
366 break;
367 case MBA_CMPLT_2_32BIT:
9a853f71 368 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
1da177e4
LT
369 handles[1] = le32_to_cpu(
370 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
371 RD_MAILBOX_REG(ha, reg, 6));
372 handle_cnt = 2;
373 mb[0] = MBA_SCSI_COMPLETION;
374 break;
375 default:
376 break;
377 }
3a03eb79 378skip_rio:
1da177e4
LT
379 switch (mb[0]) {
380 case MBA_SCSI_COMPLETION: /* Fast Post */
e315cd28 381 if (!vha->flags.online)
1da177e4
LT
382 break;
383
384 for (cnt = 0; cnt < handle_cnt; cnt++)
73208dfd
AC
385 qla2x00_process_completed_request(vha, rsp->req,
386 handles[cnt]);
1da177e4
LT
387 break;
388
389 case MBA_RESET: /* Reset */
e315cd28
AC
390 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
391 vha->host_no));
1da177e4 392
e315cd28 393 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
1da177e4
LT
394 break;
395
396 case MBA_SYSTEM_ERR: /* System Error */
1da177e4
LT
397 qla_printk(KERN_INFO, ha,
398 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
399 mb[1], mb[2], mb[3]);
400
e315cd28 401 ha->isp_ops->fw_dump(vha, 1);
1da177e4 402
e428924c 403 if (IS_FWI2_CAPABLE(ha)) {
9a853f71
AV
404 if (mb[1] == 0 && mb[2] == 0) {
405 qla_printk(KERN_ERR, ha,
406 "Unrecoverable Hardware Error: adapter "
407 "marked OFFLINE!\n");
e315cd28 408 vha->flags.online = 0;
9a853f71 409 } else
e315cd28 410 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
9a853f71 411 } else if (mb[1] == 0) {
1da177e4
LT
412 qla_printk(KERN_INFO, ha,
413 "Unrecoverable Hardware Error: adapter marked "
414 "OFFLINE!\n");
e315cd28 415 vha->flags.online = 0;
1da177e4 416 } else
e315cd28 417 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1da177e4
LT
418 break;
419
420 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
421 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
e315cd28 422 vha->host_no));
1da177e4
LT
423 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
424
e315cd28 425 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1da177e4
LT
426 break;
427
428 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
429 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
e315cd28 430 vha->host_no));
1da177e4
LT
431 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
432
e315cd28 433 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1da177e4
LT
434 break;
435
436 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
437 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
e315cd28 438 vha->host_no));
1da177e4
LT
439 break;
440
441 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
e315cd28 442 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
1da177e4 443 mb[1]));
cc3ef7bc 444 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
1da177e4 445
e315cd28
AC
446 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
447 atomic_set(&vha->loop_state, LOOP_DOWN);
448 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
449 qla2x00_mark_all_devices_lost(vha, 1);
1da177e4
LT
450 }
451
e315cd28
AC
452 if (vha->vp_idx) {
453 atomic_set(&vha->vp_state, VP_FAILED);
454 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
2c3dfe3f
SJ
455 }
456
e315cd28
AC
457 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
458 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
1da177e4 459
e315cd28
AC
460 vha->flags.management_server_logged_in = 0;
461 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
1da177e4
LT
462 break;
463
464 case MBA_LOOP_UP: /* Loop Up Event */
1da177e4
LT
465 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
466 link_speed = link_speeds[0];
d8b45213 467 ha->link_data_rate = PORT_SPEED_1GB;
1da177e4 468 } else {
9a853f71 469 link_speed = link_speeds[LS_UNKNOWN];
1da177e4
LT
470 if (mb[1] < 5)
471 link_speed = link_speeds[mb[1]];
3a03eb79
AV
472 else if (mb[1] == 0x13)
473 link_speed = link_speeds[5];
1da177e4
LT
474 ha->link_data_rate = mb[1];
475 }
476
477 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
e315cd28 478 vha->host_no, link_speed));
1da177e4
LT
479 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
480 link_speed);
481
e315cd28
AC
482 vha->flags.management_server_logged_in = 0;
483 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
1da177e4
LT
484 break;
485
486 case MBA_LOOP_DOWN: /* Loop Down Event */
4d4df193 487 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
e315cd28 488 "(%x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3]));
4d4df193
HK
489 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
490 mb[1], mb[2], mb[3]);
1da177e4 491
e315cd28
AC
492 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
493 atomic_set(&vha->loop_state, LOOP_DOWN);
494 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
495 vha->device_flags |= DFLG_NO_CABLE;
496 qla2x00_mark_all_devices_lost(vha, 1);
1da177e4
LT
497 }
498
e315cd28
AC
499 if (vha->vp_idx) {
500 atomic_set(&vha->vp_state, VP_FAILED);
501 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
2c3dfe3f
SJ
502 }
503
e315cd28 504 vha->flags.management_server_logged_in = 0;
d8b45213 505 ha->link_data_rate = PORT_SPEED_UNKNOWN;
e315cd28 506 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
1da177e4
LT
507 break;
508
509 case MBA_LIP_RESET: /* LIP reset occurred */
1da177e4 510 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
e315cd28 511 vha->host_no, mb[1]));
1da177e4 512 qla_printk(KERN_INFO, ha,
cc3ef7bc 513 "LIP reset occurred (%x).\n", mb[1]);
1da177e4 514
e315cd28
AC
515 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
516 atomic_set(&vha->loop_state, LOOP_DOWN);
517 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
518 qla2x00_mark_all_devices_lost(vha, 1);
1da177e4
LT
519 }
520
e315cd28
AC
521 if (vha->vp_idx) {
522 atomic_set(&vha->vp_state, VP_FAILED);
523 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
2c3dfe3f
SJ
524 }
525
e315cd28 526 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
1da177e4
LT
527
528 ha->operating_mode = LOOP;
e315cd28
AC
529 vha->flags.management_server_logged_in = 0;
530 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
1da177e4
LT
531 break;
532
3a03eb79 533 /* case MBA_DCBX_COMPLETE: */
1da177e4
LT
534 case MBA_POINT_TO_POINT: /* Point-to-Point */
535 if (IS_QLA2100(ha))
536 break;
537
3a03eb79
AV
538 if (IS_QLA81XX(ha))
539 DEBUG2(printk("scsi(%ld): DCBX Completed -- %04x %04x "
540 "%04x\n", vha->host_no, mb[1], mb[2], mb[3]));
541 else
542 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE "
543 "received.\n", vha->host_no));
1da177e4
LT
544
545 /*
546 * Until there's a transition from loop down to loop up, treat
547 * this as loop down only.
548 */
e315cd28
AC
549 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
550 atomic_set(&vha->loop_state, LOOP_DOWN);
551 if (!atomic_read(&vha->loop_down_timer))
552 atomic_set(&vha->loop_down_timer,
1da177e4 553 LOOP_DOWN_TIME);
e315cd28 554 qla2x00_mark_all_devices_lost(vha, 1);
1da177e4
LT
555 }
556
e315cd28
AC
557 if (vha->vp_idx) {
558 atomic_set(&vha->vp_state, VP_FAILED);
559 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
2c3dfe3f
SJ
560 }
561
e315cd28
AC
562 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
563 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
564
565 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
566 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
4346b149
AV
567
568 ha->flags.gpsc_supported = 1;
e315cd28 569 vha->flags.management_server_logged_in = 0;
1da177e4
LT
570 break;
571
572 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
573 if (IS_QLA2100(ha))
574 break;
575
1da177e4
LT
576 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
577 "received.\n",
e315cd28 578 vha->host_no));
1da177e4
LT
579 qla_printk(KERN_INFO, ha,
580 "Configuration change detected: value=%x.\n", mb[1]);
581
e315cd28
AC
582 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
583 atomic_set(&vha->loop_state, LOOP_DOWN);
584 if (!atomic_read(&vha->loop_down_timer))
585 atomic_set(&vha->loop_down_timer,
1da177e4 586 LOOP_DOWN_TIME);
e315cd28 587 qla2x00_mark_all_devices_lost(vha, 1);
1da177e4
LT
588 }
589
e315cd28
AC
590 if (vha->vp_idx) {
591 atomic_set(&vha->vp_state, VP_FAILED);
592 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
2c3dfe3f
SJ
593 }
594
e315cd28
AC
595 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
596 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1da177e4
LT
597 break;
598
599 case MBA_PORT_UPDATE: /* Port database update */
73208dfd
AC
600 /* Only handle SCNs for our Vport index. */
601 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
602 break;
603
1da177e4 604 /*
cc3ef7bc 605 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
1da177e4
LT
606 * event etc. earlier indicating loop is down) then process
607 * it. Otherwise ignore it and Wait for RSCN to come in.
608 */
e315cd28
AC
609 atomic_set(&vha->loop_down_timer, 0);
610 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
611 atomic_read(&vha->loop_state) != LOOP_DEAD) {
1da177e4 612 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
e315cd28 613 "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
9a853f71 614 mb[2], mb[3]));
1da177e4
LT
615 break;
616 }
617
618 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
e315cd28 619 vha->host_no));
1da177e4 620 DEBUG(printk(KERN_INFO
9a853f71 621 "scsi(%ld): Port database changed %04x %04x %04x.\n",
e315cd28 622 vha->host_no, mb[1], mb[2], mb[3]));
1da177e4
LT
623
624 /*
625 * Mark all devices as missing so we will login again.
626 */
e315cd28 627 atomic_set(&vha->loop_state, LOOP_UP);
1da177e4 628
e315cd28 629 qla2x00_mark_all_devices_lost(vha, 1);
1da177e4 630
e315cd28 631 vha->flags.rscn_queue_overflow = 1;
1da177e4 632
e315cd28
AC
633 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
634 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1da177e4
LT
635 break;
636
637 case MBA_RSCN_UPDATE: /* State Change Registration */
3c397400 638 /* Check if the Vport has issued a SCR */
e315cd28 639 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
3c397400
SJ
640 break;
641 /* Only handle SCNs for our Vport index. */
e315cd28 642 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
3c397400 643 break;
1da177e4 644 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
e315cd28 645 vha->host_no));
1da177e4 646 DEBUG(printk(KERN_INFO
f4a8dbc7 647 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
e315cd28 648 vha->host_no, mb[1], mb[2], mb[3]));
1da177e4 649
59d72d87 650 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
e315cd28
AC
651 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
652 | vha->d_id.b.al_pa;
1da177e4
LT
653 if (rscn_entry == host_pid) {
654 DEBUG(printk(KERN_INFO
655 "scsi(%ld): Ignoring RSCN update to local host "
656 "port ID (%06x)\n",
e315cd28 657 vha->host_no, host_pid));
1da177e4
LT
658 break;
659 }
660
59d72d87
RA
661 /* Ignore reserved bits from RSCN-payload. */
662 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
e315cd28 663 rscn_queue_index = vha->rscn_in_ptr + 1;
1da177e4
LT
664 if (rscn_queue_index == MAX_RSCN_COUNT)
665 rscn_queue_index = 0;
e315cd28
AC
666 if (rscn_queue_index != vha->rscn_out_ptr) {
667 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
668 vha->rscn_in_ptr = rscn_queue_index;
1da177e4 669 } else {
e315cd28 670 vha->flags.rscn_queue_overflow = 1;
1da177e4
LT
671 }
672
e315cd28
AC
673 atomic_set(&vha->loop_state, LOOP_UPDATE);
674 atomic_set(&vha->loop_down_timer, 0);
675 vha->flags.management_server_logged_in = 0;
1da177e4 676
e315cd28
AC
677 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
678 set_bit(RSCN_UPDATE, &vha->dpc_flags);
679 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
1da177e4
LT
680 break;
681
682 /* case MBA_RIO_RESPONSE: */
683 case MBA_ZIO_RESPONSE:
3fd67cdf 684 DEBUG3(printk("scsi(%ld): [R|Z]IO update completion.\n",
e315cd28 685 vha->host_no));
1da177e4 686
e428924c 687 if (IS_FWI2_CAPABLE(ha))
73208dfd 688 qla24xx_process_response_queue(rsp);
4fdfefe5 689 else
73208dfd 690 qla2x00_process_response_queue(rsp);
1da177e4 691 break;
9a853f71
AV
692
693 case MBA_DISCARD_RND_FRAME:
694 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
e315cd28 695 "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
9a853f71 696 break;
45ebeb56
AV
697
698 case MBA_TRACE_NOTIFICATION:
699 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
e315cd28 700 vha->host_no, mb[1], mb[2]));
45ebeb56 701 break;
4d4df193
HK
702
703 case MBA_ISP84XX_ALERT:
704 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
e315cd28 705 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
4d4df193
HK
706
707 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
708 switch (mb[1]) {
709 case A84_PANIC_RECOVERY:
710 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
711 "%04x %04x\n", mb[2], mb[3]);
712 break;
713 case A84_OP_LOGIN_COMPLETE:
714 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
715 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
716 "firmware version %x\n", ha->cs84xx->op_fw_version));
717 break;
718 case A84_DIAG_LOGIN_COMPLETE:
719 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
720 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
721 "diagnostic firmware version %x\n",
722 ha->cs84xx->diag_fw_version));
723 break;
724 case A84_GOLD_LOGIN_COMPLETE:
725 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
726 ha->cs84xx->fw_update = 1;
727 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
728 "firmware version %x\n",
729 ha->cs84xx->gold_fw_version));
730 break;
731 default:
732 qla_printk(KERN_ERR, ha,
733 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
734 mb[1], mb[2], mb[3]);
735 }
736 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
737 break;
3a03eb79
AV
738 case MBA_DCBX_START:
739 DEBUG2(printk("scsi(%ld): DCBX Started -- %04x %04x %04x\n",
740 vha->host_no, mb[1], mb[2], mb[3]));
741 break;
742 case MBA_DCBX_PARAM_UPDATE:
743 DEBUG2(printk("scsi(%ld): DCBX Parameters Updated -- "
744 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
745 break;
746 case MBA_FCF_CONF_ERR:
747 DEBUG2(printk("scsi(%ld): FCF Configuration Error -- "
748 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
749 break;
750 case MBA_IDC_COMPLETE:
3a03eb79 751 case MBA_IDC_NOTIFY:
3a03eb79 752 case MBA_IDC_TIME_EXT:
8a659571 753 qla81xx_idc_event(vha, mb[0], mb[1]);
3a03eb79 754 break;
1da177e4 755 }
2c3dfe3f 756
e315cd28 757 if (!vha->vp_idx && ha->num_vhosts)
73208dfd 758 qla2x00_alert_all_vps(rsp, mb);
1da177e4
LT
759}
760
df7baa50
AV
761static void
762qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
763{
764 fc_port_t *fcport = data;
73208dfd
AC
765 struct scsi_qla_host *vha = fcport->vha;
766 struct qla_hw_data *ha = vha->hw;
767 struct req_que *req = NULL;
768
769 req = ha->req_q_map[vha->req_ques[0]];
770 if (!req)
771 return;
772 if (req->max_q_depth <= sdev->queue_depth)
df7baa50
AV
773 return;
774
775 if (sdev->ordered_tags)
776 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
777 sdev->queue_depth + 1);
778 else
779 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
780 sdev->queue_depth + 1);
781
782 fcport->last_ramp_up = jiffies;
783
e315cd28 784 DEBUG2(qla_printk(KERN_INFO, ha,
df7baa50 785 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
e315cd28 786 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
df7baa50
AV
787 sdev->queue_depth));
788}
789
790static void
791qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
792{
793 fc_port_t *fcport = data;
794
795 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
796 return;
797
e315cd28 798 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
df7baa50 799 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
e315cd28 800 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
df7baa50
AV
801 sdev->queue_depth));
802}
803
804static inline void
73208dfd
AC
805qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, struct req_que *req,
806 srb_t *sp)
df7baa50
AV
807{
808 fc_port_t *fcport;
809 struct scsi_device *sdev;
810
811 sdev = sp->cmd->device;
73208dfd 812 if (sdev->queue_depth >= req->max_q_depth)
df7baa50
AV
813 return;
814
815 fcport = sp->fcport;
816 if (time_before(jiffies,
817 fcport->last_ramp_up + ql2xqfullrampup * HZ))
818 return;
819 if (time_before(jiffies,
820 fcport->last_queue_full + ql2xqfullrampup * HZ))
821 return;
822
df7baa50
AV
823 starget_for_each_device(sdev->sdev_target, fcport,
824 qla2x00_adjust_sdev_qdepth_up);
df7baa50
AV
825}
826
1da177e4
LT
827/**
828 * qla2x00_process_completed_request() - Process a Fast Post response.
829 * @ha: SCSI driver HA context
830 * @index: SRB index
831 */
832static void
73208dfd
AC
833qla2x00_process_completed_request(struct scsi_qla_host *vha,
834 struct req_que *req, uint32_t index)
1da177e4
LT
835{
836 srb_t *sp;
e315cd28 837 struct qla_hw_data *ha = vha->hw;
1da177e4
LT
838
839 /* Validate handle. */
840 if (index >= MAX_OUTSTANDING_COMMANDS) {
841 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
e315cd28 842 vha->host_no, index));
1da177e4
LT
843 qla_printk(KERN_WARNING, ha,
844 "Invalid SCSI completion handle %d.\n", index);
845
e315cd28 846 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1da177e4
LT
847 return;
848 }
849
e315cd28 850 sp = req->outstanding_cmds[index];
1da177e4
LT
851 if (sp) {
852 /* Free outstanding command slot. */
e315cd28 853 req->outstanding_cmds[index] = NULL;
1da177e4 854
1da177e4
LT
855 CMD_COMPL_STATUS(sp->cmd) = 0L;
856 CMD_SCSI_STATUS(sp->cmd) = 0L;
857
858 /* Save ISP completion status */
859 sp->cmd->result = DID_OK << 16;
df7baa50 860
73208dfd
AC
861 qla2x00_ramp_up_queue_depth(vha, req, sp);
862 qla2x00_sp_compl(ha, sp);
1da177e4
LT
863 } else {
864 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
e315cd28 865 vha->host_no));
1da177e4
LT
866 qla_printk(KERN_WARNING, ha,
867 "Invalid ISP SCSI completion handle\n");
868
e315cd28 869 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1da177e4
LT
870 }
871}
872
873/**
874 * qla2x00_process_response_queue() - Process response queue entries.
875 * @ha: SCSI driver HA context
876 */
877void
73208dfd 878qla2x00_process_response_queue(struct rsp_que *rsp)
1da177e4 879{
73208dfd
AC
880 struct scsi_qla_host *vha;
881 struct qla_hw_data *ha = rsp->hw;
3d71644c 882 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1da177e4
LT
883 sts_entry_t *pkt;
884 uint16_t handle_cnt;
885 uint16_t cnt;
73208dfd
AC
886
887 vha = qla2x00_get_rsp_host(rsp);
1da177e4 888
e315cd28 889 if (!vha->flags.online)
1da177e4
LT
890 return;
891
e315cd28
AC
892 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
893 pkt = (sts_entry_t *)rsp->ring_ptr;
1da177e4 894
e315cd28
AC
895 rsp->ring_index++;
896 if (rsp->ring_index == rsp->length) {
897 rsp->ring_index = 0;
898 rsp->ring_ptr = rsp->ring;
1da177e4 899 } else {
e315cd28 900 rsp->ring_ptr++;
1da177e4
LT
901 }
902
903 if (pkt->entry_status != 0) {
904 DEBUG3(printk(KERN_INFO
e315cd28 905 "scsi(%ld): Process error entry.\n", vha->host_no));
1da177e4 906
73208dfd 907 qla2x00_error_entry(vha, rsp, pkt);
1da177e4
LT
908 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
909 wmb();
910 continue;
911 }
912
913 switch (pkt->entry_type) {
914 case STATUS_TYPE:
73208dfd 915 qla2x00_status_entry(vha, rsp, pkt);
1da177e4
LT
916 break;
917 case STATUS_TYPE_21:
918 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
919 for (cnt = 0; cnt < handle_cnt; cnt++) {
73208dfd 920 qla2x00_process_completed_request(vha, rsp->req,
1da177e4
LT
921 ((sts21_entry_t *)pkt)->handle[cnt]);
922 }
923 break;
924 case STATUS_TYPE_22:
925 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
926 for (cnt = 0; cnt < handle_cnt; cnt++) {
73208dfd 927 qla2x00_process_completed_request(vha, rsp->req,
1da177e4
LT
928 ((sts22_entry_t *)pkt)->handle[cnt]);
929 }
930 break;
931 case STATUS_CONT_TYPE:
e315cd28 932 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
1da177e4 933 break;
1da177e4
LT
934 default:
935 /* Type Not Supported. */
936 DEBUG4(printk(KERN_WARNING
937 "scsi(%ld): Received unknown response pkt type %x "
938 "entry status=%x.\n",
e315cd28 939 vha->host_no, pkt->entry_type, pkt->entry_status));
1da177e4
LT
940 break;
941 }
942 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
943 wmb();
944 }
945
946 /* Adjust ring index */
e315cd28 947 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
1da177e4
LT
948}
949
4733fcb1
AV
950static inline void
951qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
952{
953 struct scsi_cmnd *cp = sp->cmd;
954
955 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
956 sense_len = SCSI_SENSE_BUFFERSIZE;
957
958 CMD_ACTUAL_SNSLEN(cp) = sense_len;
959 sp->request_sense_length = sense_len;
960 sp->request_sense_ptr = cp->sense_buffer;
961 if (sp->request_sense_length > 32)
962 sense_len = 32;
963
964 memcpy(cp->sense_buffer, sense_data, sense_len);
965
966 sp->request_sense_ptr += sense_len;
967 sp->request_sense_length -= sense_len;
968 if (sp->request_sense_length != 0)
e315cd28 969 sp->fcport->vha->status_srb = sp;
4733fcb1
AV
970
971 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
e315cd28 972 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
19851f13
AV
973 cp->device->channel, cp->device->id, cp->device->lun, cp,
974 cp->serial_number));
4733fcb1
AV
975 if (sense_len)
976 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
977 CMD_ACTUAL_SNSLEN(cp)));
978}
979
1da177e4
LT
980/**
981 * qla2x00_status_entry() - Process a Status IOCB entry.
982 * @ha: SCSI driver HA context
983 * @pkt: Entry pointer
984 */
985static void
73208dfd 986qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
1da177e4 987{
1da177e4 988 srb_t *sp;
1da177e4
LT
989 fc_port_t *fcport;
990 struct scsi_cmnd *cp;
9a853f71
AV
991 sts_entry_t *sts;
992 struct sts_entry_24xx *sts24;
1da177e4
LT
993 uint16_t comp_status;
994 uint16_t scsi_status;
995 uint8_t lscsi_status;
996 int32_t resid;
ed17c71b 997 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
9a853f71 998 uint8_t *rsp_info, *sense_data;
e315cd28 999 struct qla_hw_data *ha = vha->hw;
73208dfd 1000 struct req_que *req = rsp->req;
9a853f71
AV
1001
1002 sts = (sts_entry_t *) pkt;
1003 sts24 = (struct sts_entry_24xx *) pkt;
e428924c 1004 if (IS_FWI2_CAPABLE(ha)) {
9a853f71
AV
1005 comp_status = le16_to_cpu(sts24->comp_status);
1006 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1007 } else {
1008 comp_status = le16_to_cpu(sts->comp_status);
1009 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1010 }
1da177e4
LT
1011
1012 /* Fast path completion. */
9a853f71 1013 if (comp_status == CS_COMPLETE && scsi_status == 0) {
73208dfd 1014 qla2x00_process_completed_request(vha, req, sts->handle);
1da177e4
LT
1015
1016 return;
1017 }
1018
1019 /* Validate handle. */
9a853f71 1020 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
e315cd28
AC
1021 sp = req->outstanding_cmds[sts->handle];
1022 req->outstanding_cmds[sts->handle] = NULL;
1da177e4
LT
1023 } else
1024 sp = NULL;
1025
1026 if (sp == NULL) {
1027 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
e315cd28 1028 vha->host_no));
1da177e4
LT
1029 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
1030
e315cd28
AC
1031 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1032 qla2xxx_wake_dpc(vha);
1da177e4
LT
1033 return;
1034 }
1035 cp = sp->cmd;
1036 if (cp == NULL) {
1037 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
e315cd28 1038 "pkt->handle=%d sp=%p.\n", vha->host_no, sts->handle, sp));
1da177e4
LT
1039 qla_printk(KERN_WARNING, ha,
1040 "Command is NULL: already returned to OS (sp=%p)\n", sp);
1041
1042 return;
1043 }
1044
9a853f71
AV
1045 lscsi_status = scsi_status & STATUS_MASK;
1046 CMD_ENTRY_STATUS(cp) = sts->entry_status;
1da177e4
LT
1047 CMD_COMPL_STATUS(cp) = comp_status;
1048 CMD_SCSI_STATUS(cp) = scsi_status;
1049
bdf79621 1050 fcport = sp->fcport;
1da177e4 1051
ed17c71b 1052 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
e428924c 1053 if (IS_FWI2_CAPABLE(ha)) {
9a853f71
AV
1054 sense_len = le32_to_cpu(sts24->sense_len);
1055 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1056 resid_len = le32_to_cpu(sts24->rsp_residual_count);
ed17c71b 1057 fw_resid_len = le32_to_cpu(sts24->residual_len);
9a853f71
AV
1058 rsp_info = sts24->data;
1059 sense_data = sts24->data;
1060 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
1061 } else {
1062 sense_len = le16_to_cpu(sts->req_sense_length);
1063 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
1064 resid_len = le32_to_cpu(sts->residual_length);
1065 rsp_info = sts->rsp_info;
1066 sense_data = sts->req_sense_data;
1067 }
1068
1da177e4
LT
1069 /* Check for any FCP transport errors. */
1070 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
9a853f71 1071 /* Sense data lies beyond any FCP RESPONSE data. */
e428924c 1072 if (IS_FWI2_CAPABLE(ha))
9a853f71
AV
1073 sense_data += rsp_info_len;
1074 if (rsp_info_len > 3 && rsp_info[3]) {
1da177e4
LT
1075 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1076 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
e315cd28 1077 "retrying command\n", vha->host_no,
9a853f71
AV
1078 cp->device->channel, cp->device->id,
1079 cp->device->lun, rsp_info_len, rsp_info[0],
1080 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1081 rsp_info[5], rsp_info[6], rsp_info[7]));
1da177e4
LT
1082
1083 cp->result = DID_BUS_BUSY << 16;
73208dfd 1084 qla2x00_sp_compl(ha, sp);
1da177e4
LT
1085 return;
1086 }
1087 }
1088
3e8ce320
AV
1089 /* Check for overrun. */
1090 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1091 scsi_status & SS_RESIDUAL_OVER)
1092 comp_status = CS_DATA_OVERRUN;
1093
1da177e4
LT
1094 /*
1095 * Based on Host and scsi status generate status code for Linux
1096 */
1097 switch (comp_status) {
1098 case CS_COMPLETE:
df7baa50 1099 case CS_QUEUE_FULL:
1da177e4
LT
1100 if (scsi_status == 0) {
1101 cp->result = DID_OK << 16;
1102 break;
1103 }
1104 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
9a853f71 1105 resid = resid_len;
385d70b4 1106 scsi_set_resid(cp, resid);
1da177e4 1107 CMD_RESID_LEN(cp) = resid;
0da69df1
AV
1108
1109 if (!lscsi_status &&
385d70b4 1110 ((unsigned)(scsi_bufflen(cp) - resid) <
0da69df1
AV
1111 cp->underflow)) {
1112 qla_printk(KERN_INFO, ha,
385d70b4
FT
1113 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1114 "detected (%x of %x bytes)...returning "
e315cd28 1115 "error status.\n", vha->host_no,
385d70b4
FT
1116 cp->device->channel, cp->device->id,
1117 cp->device->lun, resid,
1118 scsi_bufflen(cp));
0da69df1
AV
1119
1120 cp->result = DID_ERROR << 16;
1121 break;
1122 }
1da177e4 1123 }
1da177e4
LT
1124 cp->result = DID_OK << 16 | lscsi_status;
1125
df7baa50
AV
1126 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1127 DEBUG2(printk(KERN_INFO
1128 "scsi(%ld): QUEUE FULL status detected "
e315cd28 1129 "0x%x-0x%x.\n", vha->host_no, comp_status,
df7baa50
AV
1130 scsi_status));
1131
1132 /* Adjust queue depth for all luns on the port. */
1133 fcport->last_queue_full = jiffies;
df7baa50
AV
1134 starget_for_each_device(cp->device->sdev_target,
1135 fcport, qla2x00_adjust_sdev_qdepth_down);
df7baa50
AV
1136 break;
1137 }
1da177e4
LT
1138 if (lscsi_status != SS_CHECK_CONDITION)
1139 break;
1140
b80ca4f7 1141 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1da177e4
LT
1142 if (!(scsi_status & SS_SENSE_LEN_VALID))
1143 break;
1144
4733fcb1 1145 qla2x00_handle_sense(sp, sense_data, sense_len);
1da177e4
LT
1146 break;
1147
1148 case CS_DATA_UNDERRUN:
9a853f71 1149 resid = resid_len;
ed17c71b 1150 /* Use F/W calculated residual length. */
6acf8190 1151 if (IS_FWI2_CAPABLE(ha)) {
2d136938
AV
1152 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1153 lscsi_status = 0;
1154 } else if (resid != fw_resid_len) {
6acf8190
AV
1155 scsi_status &= ~SS_RESIDUAL_UNDER;
1156 lscsi_status = 0;
1157 }
ed17c71b 1158 resid = fw_resid_len;
6acf8190 1159 }
ed17c71b 1160
1da177e4 1161 if (scsi_status & SS_RESIDUAL_UNDER) {
385d70b4 1162 scsi_set_resid(cp, resid);
1da177e4 1163 CMD_RESID_LEN(cp) = resid;
e038a1be
AV
1164 } else {
1165 DEBUG2(printk(KERN_INFO
1166 "scsi(%ld:%d:%d) UNDERRUN status detected "
ed17c71b 1167 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
e315cd28 1168 "os_underflow=0x%x\n", vha->host_no,
ed17c71b
RA
1169 cp->device->id, cp->device->lun, comp_status,
1170 scsi_status, resid_len, resid, cp->cmnd[0],
1171 cp->underflow));
e038a1be 1172
1da177e4
LT
1173 }
1174
1175 /*
fa2a1ce5 1176 * Check to see if SCSI Status is non zero. If so report SCSI
1da177e4
LT
1177 * Status.
1178 */
1179 if (lscsi_status != 0) {
1da177e4
LT
1180 cp->result = DID_OK << 16 | lscsi_status;
1181
ffec28a3
AV
1182 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1183 DEBUG2(printk(KERN_INFO
1184 "scsi(%ld): QUEUE FULL status detected "
e315cd28 1185 "0x%x-0x%x.\n", vha->host_no, comp_status,
ffec28a3
AV
1186 scsi_status));
1187
1188 /*
1189 * Adjust queue depth for all luns on the
1190 * port.
1191 */
1192 fcport->last_queue_full = jiffies;
1193 starget_for_each_device(
1194 cp->device->sdev_target, fcport,
1195 qla2x00_adjust_sdev_qdepth_down);
1196 break;
1197 }
1da177e4
LT
1198 if (lscsi_status != SS_CHECK_CONDITION)
1199 break;
1200
b80ca4f7 1201 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1da177e4
LT
1202 if (!(scsi_status & SS_SENSE_LEN_VALID))
1203 break;
1204
4733fcb1 1205 qla2x00_handle_sense(sp, sense_data, sense_len);
1da177e4
LT
1206 } else {
1207 /*
1208 * If RISC reports underrun and target does not report
1209 * it then we must have a lost frame, so tell upper
1210 * layer to retry it by reporting a bus busy.
1211 */
1212 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1213 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
385d70b4 1214 "frame(s) detected (%x of %x bytes)..."
e315cd28
AC
1215 "retrying command.\n",
1216 vha->host_no, cp->device->channel,
1217 cp->device->id, cp->device->lun, resid,
1218 scsi_bufflen(cp)));
1da177e4
LT
1219
1220 cp->result = DID_BUS_BUSY << 16;
1da177e4
LT
1221 break;
1222 }
1223
1224 /* Handle mid-layer underflow */
385d70b4 1225 if ((unsigned)(scsi_bufflen(cp) - resid) <
1da177e4
LT
1226 cp->underflow) {
1227 qla_printk(KERN_INFO, ha,
385d70b4
FT
1228 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1229 "detected (%x of %x bytes)...returning "
e315cd28 1230 "error status.\n", vha->host_no,
385d70b4
FT
1231 cp->device->channel, cp->device->id,
1232 cp->device->lun, resid,
1233 scsi_bufflen(cp));
1da177e4
LT
1234
1235 cp->result = DID_ERROR << 16;
1236 break;
1237 }
1238
1239 /* Everybody online, looking good... */
1240 cp->result = DID_OK << 16;
1241 }
1242 break;
1243
1244 case CS_DATA_OVERRUN:
1245 DEBUG2(printk(KERN_INFO
1246 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
e315cd28 1247 vha->host_no, cp->device->id, cp->device->lun, comp_status,
9a853f71 1248 scsi_status));
1da177e4
LT
1249 DEBUG2(printk(KERN_INFO
1250 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1251 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1252 cp->cmnd[4], cp->cmnd[5]));
1253 DEBUG2(printk(KERN_INFO
1254 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1255 "status!\n",
385d70b4 1256 cp->serial_number, scsi_bufflen(cp), resid_len));
1da177e4
LT
1257
1258 cp->result = DID_ERROR << 16;
1259 break;
1260
1261 case CS_PORT_LOGGED_OUT:
1262 case CS_PORT_CONFIG_CHG:
1263 case CS_PORT_BUSY:
1264 case CS_INCOMPLETE:
1265 case CS_PORT_UNAVAILABLE:
1266 /*
1267 * If the port is in Target Down state, return all IOs for this
1268 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1269 * retry_queue.
1270 */
1da177e4
LT
1271 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1272 "pid=%ld, compl status=0x%x, port state=0x%x\n",
e315cd28 1273 vha->host_no, cp->device->id, cp->device->lun,
9a853f71 1274 cp->serial_number, comp_status,
1da177e4
LT
1275 atomic_read(&fcport->state)));
1276
056a4483
MC
1277 /*
1278 * We are going to have the fc class block the rport
1279 * while we try to recover so instruct the mid layer
1280 * to requeue until the class decides how to handle this.
1281 */
1282 cp->result = DID_TRANSPORT_DISRUPTED << 16;
a7a28504 1283 if (atomic_read(&fcport->state) == FCS_ONLINE)
e315cd28 1284 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1da177e4
LT
1285 break;
1286
1287 case CS_RESET:
1288 DEBUG2(printk(KERN_INFO
1289 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
e315cd28 1290 vha->host_no, comp_status, scsi_status));
1da177e4 1291
f4f051eb 1292 cp->result = DID_RESET << 16;
1da177e4
LT
1293 break;
1294
1295 case CS_ABORTED:
fa2a1ce5 1296 /*
1da177e4
LT
1297 * hv2.19.12 - DID_ABORT does not retry the request if we
1298 * aborted this request then abort otherwise it must be a
1299 * reset.
1300 */
1301 DEBUG2(printk(KERN_INFO
1302 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
e315cd28 1303 vha->host_no, comp_status, scsi_status));
1da177e4
LT
1304
1305 cp->result = DID_RESET << 16;
1306 break;
1307
1308 case CS_TIMEOUT:
056a4483
MC
1309 /*
1310 * We are going to have the fc class block the rport
1311 * while we try to recover so instruct the mid layer
1312 * to requeue until the class decides how to handle this.
1313 */
1314 cp->result = DID_TRANSPORT_DISRUPTED << 16;
9a853f71 1315
e428924c 1316 if (IS_FWI2_CAPABLE(ha)) {
9a853f71
AV
1317 DEBUG2(printk(KERN_INFO
1318 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
e315cd28 1319 "0x%x-0x%x\n", vha->host_no, cp->device->channel,
9a853f71
AV
1320 cp->device->id, cp->device->lun, comp_status,
1321 scsi_status));
1322 break;
1323 }
1da177e4
LT
1324 DEBUG2(printk(KERN_INFO
1325 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
e315cd28 1326 "sflags=%x.\n", vha->host_no, cp->device->channel,
9a853f71
AV
1327 cp->device->id, cp->device->lun, comp_status, scsi_status,
1328 le16_to_cpu(sts->status_flags)));
1da177e4 1329
9a853f71
AV
1330 /* Check to see if logout occurred. */
1331 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
e315cd28 1332 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1da177e4
LT
1333 break;
1334
1da177e4
LT
1335 default:
1336 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
e315cd28 1337 "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
1da177e4
LT
1338 qla_printk(KERN_INFO, ha,
1339 "Unknown status detected 0x%x-0x%x.\n",
1340 comp_status, scsi_status);
1341
1342 cp->result = DID_ERROR << 16;
1343 break;
1344 }
1345
1346 /* Place command on done queue. */
e315cd28 1347 if (vha->status_srb == NULL)
73208dfd 1348 qla2x00_sp_compl(ha, sp);
1da177e4
LT
1349}
1350
1351/**
1352 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1353 * @ha: SCSI driver HA context
1354 * @pkt: Entry pointer
1355 *
1356 * Extended sense data.
1357 */
1358static void
e315cd28 1359qla2x00_status_cont_entry(scsi_qla_host_t *vha, sts_cont_entry_t *pkt)
1da177e4
LT
1360{
1361 uint8_t sense_sz = 0;
e315cd28
AC
1362 struct qla_hw_data *ha = vha->hw;
1363 srb_t *sp = vha->status_srb;
1da177e4
LT
1364 struct scsi_cmnd *cp;
1365
1366 if (sp != NULL && sp->request_sense_length != 0) {
1367 cp = sp->cmd;
1368 if (cp == NULL) {
1369 DEBUG2(printk("%s(): Cmd already returned back to OS "
75bc4190 1370 "sp=%p.\n", __func__, sp));
1da177e4
LT
1371 qla_printk(KERN_INFO, ha,
1372 "cmd is NULL: already returned to OS (sp=%p)\n",
fa2a1ce5 1373 sp);
1da177e4 1374
e315cd28 1375 vha->status_srb = NULL;
1da177e4
LT
1376 return;
1377 }
1378
1379 if (sp->request_sense_length > sizeof(pkt->data)) {
1380 sense_sz = sizeof(pkt->data);
1381 } else {
1382 sense_sz = sp->request_sense_length;
1383 }
1384
1385 /* Move sense data. */
e428924c 1386 if (IS_FWI2_CAPABLE(ha))
9a853f71 1387 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
1da177e4
LT
1388 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1389 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1390
1391 sp->request_sense_ptr += sense_sz;
1392 sp->request_sense_length -= sense_sz;
1393
1394 /* Place command on done queue. */
1395 if (sp->request_sense_length == 0) {
e315cd28 1396 vha->status_srb = NULL;
73208dfd 1397 qla2x00_sp_compl(ha, sp);
1da177e4
LT
1398 }
1399 }
1400}
1401
1402/**
1403 * qla2x00_error_entry() - Process an error entry.
1404 * @ha: SCSI driver HA context
1405 * @pkt: Entry pointer
1406 */
1407static void
73208dfd 1408qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
1da177e4
LT
1409{
1410 srb_t *sp;
e315cd28 1411 struct qla_hw_data *ha = vha->hw;
73208dfd 1412 struct req_que *req = rsp->req;
1da177e4
LT
1413#if defined(QL_DEBUG_LEVEL_2)
1414 if (pkt->entry_status & RF_INV_E_ORDER)
1415 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1416 else if (pkt->entry_status & RF_INV_E_COUNT)
1417 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1418 else if (pkt->entry_status & RF_INV_E_PARAM)
fa2a1ce5 1419 qla_printk(KERN_ERR, ha,
1da177e4
LT
1420 "%s: Invalid Entry Parameter\n", __func__);
1421 else if (pkt->entry_status & RF_INV_E_TYPE)
1422 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1423 else if (pkt->entry_status & RF_BUSY)
1424 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1425 else
1426 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1427#endif
1428
1429 /* Validate handle. */
1430 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
e315cd28 1431 sp = req->outstanding_cmds[pkt->handle];
1da177e4
LT
1432 else
1433 sp = NULL;
1434
1435 if (sp) {
1436 /* Free outstanding command slot. */
e315cd28 1437 req->outstanding_cmds[pkt->handle] = NULL;
354d6b21 1438
1da177e4
LT
1439 /* Bad payload or header */
1440 if (pkt->entry_status &
1441 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1442 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1443 sp->cmd->result = DID_ERROR << 16;
1444 } else if (pkt->entry_status & RF_BUSY) {
1445 sp->cmd->result = DID_BUS_BUSY << 16;
1446 } else {
1447 sp->cmd->result = DID_ERROR << 16;
1448 }
73208dfd 1449 qla2x00_sp_compl(ha, sp);
1da177e4 1450
9a853f71
AV
1451 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1452 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
1da177e4 1453 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
e315cd28 1454 vha->host_no));
1da177e4
LT
1455 qla_printk(KERN_WARNING, ha,
1456 "Error entry - invalid handle\n");
1457
e315cd28
AC
1458 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1459 qla2xxx_wake_dpc(vha);
1da177e4
LT
1460 }
1461}
1462
9a853f71
AV
1463/**
1464 * qla24xx_mbx_completion() - Process mailbox command completions.
1465 * @ha: SCSI driver HA context
1466 * @mb0: Mailbox0 register
1467 */
1468static void
e315cd28 1469qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
9a853f71
AV
1470{
1471 uint16_t cnt;
1472 uint16_t __iomem *wptr;
e315cd28 1473 struct qla_hw_data *ha = vha->hw;
9a853f71
AV
1474 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1475
1476 /* Load return mailbox registers. */
1477 ha->flags.mbox_int = 1;
1478 ha->mailbox_out[0] = mb0;
1479 wptr = (uint16_t __iomem *)&reg->mailbox1;
1480
1481 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1482 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1483 wptr++;
1484 }
1485
1486 if (ha->mcp) {
1487 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
e315cd28 1488 __func__, vha->host_no, ha->mcp->mb[0]));
9a853f71
AV
1489 } else {
1490 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
e315cd28 1491 __func__, vha->host_no));
9a853f71
AV
1492 }
1493}
1494
1495/**
1496 * qla24xx_process_response_queue() - Process response queue entries.
1497 * @ha: SCSI driver HA context
1498 */
1499void
73208dfd 1500qla24xx_process_response_queue(struct rsp_que *rsp)
9a853f71 1501{
9a853f71 1502 struct sts_entry_24xx *pkt;
73208dfd
AC
1503 struct scsi_qla_host *vha;
1504
1505 vha = qla2x00_get_rsp_host(rsp);
9a853f71 1506
e315cd28 1507 if (!vha->flags.online)
9a853f71
AV
1508 return;
1509
e315cd28
AC
1510 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1511 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
9a853f71 1512
e315cd28
AC
1513 rsp->ring_index++;
1514 if (rsp->ring_index == rsp->length) {
1515 rsp->ring_index = 0;
1516 rsp->ring_ptr = rsp->ring;
9a853f71 1517 } else {
e315cd28 1518 rsp->ring_ptr++;
9a853f71
AV
1519 }
1520
1521 if (pkt->entry_status != 0) {
1522 DEBUG3(printk(KERN_INFO
e315cd28 1523 "scsi(%ld): Process error entry.\n", vha->host_no));
9a853f71 1524
73208dfd 1525 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
9a853f71
AV
1526 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1527 wmb();
1528 continue;
1529 }
1530
1531 switch (pkt->entry_type) {
1532 case STATUS_TYPE:
73208dfd 1533 qla2x00_status_entry(vha, rsp, pkt);
9a853f71
AV
1534 break;
1535 case STATUS_CONT_TYPE:
e315cd28 1536 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
9a853f71 1537 break;
2c3dfe3f 1538 case VP_RPT_ID_IOCB_TYPE:
e315cd28 1539 qla24xx_report_id_acquisition(vha,
2c3dfe3f
SJ
1540 (struct vp_rpt_id_entry_24xx *)pkt);
1541 break;
9a853f71
AV
1542 default:
1543 /* Type Not Supported. */
1544 DEBUG4(printk(KERN_WARNING
1545 "scsi(%ld): Received unknown response pkt type %x "
1546 "entry status=%x.\n",
e315cd28 1547 vha->host_no, pkt->entry_type, pkt->entry_status));
9a853f71
AV
1548 break;
1549 }
1550 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1551 wmb();
1552 }
1553
1554 /* Adjust ring index */
08029990 1555 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
9a853f71
AV
1556}
1557
05236a05 1558static void
e315cd28 1559qla2xxx_check_risc_status(scsi_qla_host_t *vha)
05236a05
AV
1560{
1561 int rval;
1562 uint32_t cnt;
e315cd28 1563 struct qla_hw_data *ha = vha->hw;
05236a05
AV
1564 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1565
3a03eb79 1566 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
05236a05
AV
1567 return;
1568
1569 rval = QLA_SUCCESS;
1570 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1571 RD_REG_DWORD(&reg->iobase_addr);
1572 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1573 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1574 rval == QLA_SUCCESS; cnt--) {
1575 if (cnt) {
1576 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1577 udelay(10);
1578 } else
1579 rval = QLA_FUNCTION_TIMEOUT;
1580 }
1581 if (rval == QLA_SUCCESS)
1582 goto next_test;
1583
1584 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1585 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1586 rval == QLA_SUCCESS; cnt--) {
1587 if (cnt) {
1588 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1589 udelay(10);
1590 } else
1591 rval = QLA_FUNCTION_TIMEOUT;
1592 }
1593 if (rval != QLA_SUCCESS)
1594 goto done;
1595
1596next_test:
1597 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1598 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1599
1600done:
1601 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1602 RD_REG_DWORD(&reg->iobase_window);
1603}
1604
9a853f71
AV
1605/**
1606 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1607 * @irq:
1608 * @dev_id: SCSI driver HA context
9a853f71
AV
1609 *
1610 * Called by system whenever the host adapter generates an interrupt.
1611 *
1612 * Returns handled flag.
1613 */
1614irqreturn_t
7d12e780 1615qla24xx_intr_handler(int irq, void *dev_id)
9a853f71 1616{
e315cd28
AC
1617 scsi_qla_host_t *vha;
1618 struct qla_hw_data *ha;
9a853f71
AV
1619 struct device_reg_24xx __iomem *reg;
1620 int status;
9a853f71
AV
1621 unsigned long iter;
1622 uint32_t stat;
1623 uint32_t hccr;
1624 uint16_t mb[4];
e315cd28 1625 struct rsp_que *rsp;
9a853f71 1626
e315cd28
AC
1627 rsp = (struct rsp_que *) dev_id;
1628 if (!rsp) {
9a853f71 1629 printk(KERN_INFO
e315cd28 1630 "%s(): NULL response queue pointer\n", __func__);
9a853f71
AV
1631 return IRQ_NONE;
1632 }
1633
e315cd28 1634 ha = rsp->hw;
9a853f71
AV
1635 reg = &ha->iobase->isp24;
1636 status = 0;
1637
c6952483 1638 spin_lock(&ha->hardware_lock);
e315cd28 1639 vha = qla2x00_get_rsp_host(rsp);
9a853f71
AV
1640 for (iter = 50; iter--; ) {
1641 stat = RD_REG_DWORD(&reg->host_status);
1642 if (stat & HSRX_RISC_PAUSED) {
14e660e6
SJ
1643 if (pci_channel_offline(ha->pdev))
1644 break;
1645
9a853f71
AV
1646 hccr = RD_REG_DWORD(&reg->hccr);
1647
1648 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1649 "Dumping firmware!\n", hccr);
05236a05 1650
e315cd28 1651 qla2xxx_check_risc_status(vha);
05236a05 1652
e315cd28
AC
1653 ha->isp_ops->fw_dump(vha, 1);
1654 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
9a853f71
AV
1655 break;
1656 } else if ((stat & HSRX_RISC_INT) == 0)
1657 break;
1658
1659 switch (stat & 0xff) {
1660 case 0x1:
1661 case 0x2:
1662 case 0x10:
1663 case 0x11:
e315cd28 1664 qla24xx_mbx_completion(vha, MSW(stat));
9a853f71
AV
1665 status |= MBX_INTERRUPT;
1666
1667 break;
1668 case 0x12:
1669 mb[0] = MSW(stat);
1670 mb[1] = RD_REG_WORD(&reg->mailbox1);
1671 mb[2] = RD_REG_WORD(&reg->mailbox2);
1672 mb[3] = RD_REG_WORD(&reg->mailbox3);
73208dfd 1673 qla2x00_async_event(vha, rsp, mb);
9a853f71
AV
1674 break;
1675 case 0x13:
73208dfd
AC
1676 case 0x14:
1677 qla24xx_process_response_queue(rsp);
9a853f71
AV
1678 break;
1679 default:
1680 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1681 "(%d).\n",
e315cd28 1682 vha->host_no, stat & 0xff));
9a853f71
AV
1683 break;
1684 }
1685 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1686 RD_REG_DWORD_RELAXED(&reg->hccr);
1687 }
c6952483 1688 spin_unlock(&ha->hardware_lock);
9a853f71
AV
1689
1690 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1691 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
9a853f71 1692 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
0b05a1f0 1693 complete(&ha->mbx_intr_comp);
9a853f71
AV
1694 }
1695
1696 return IRQ_HANDLED;
1697}
1698
a8488abe
AV
1699static irqreturn_t
1700qla24xx_msix_rsp_q(int irq, void *dev_id)
1701{
e315cd28
AC
1702 struct qla_hw_data *ha;
1703 struct rsp_que *rsp;
a8488abe 1704 struct device_reg_24xx __iomem *reg;
a8488abe 1705
e315cd28
AC
1706 rsp = (struct rsp_que *) dev_id;
1707 if (!rsp) {
1708 printk(KERN_INFO
1709 "%s(): NULL response queue pointer\n", __func__);
1710 return IRQ_NONE;
1711 }
1712 ha = rsp->hw;
a8488abe
AV
1713 reg = &ha->iobase->isp24;
1714
0e973a24 1715 spin_lock_irq(&ha->hardware_lock);
a8488abe 1716
73208dfd 1717 qla24xx_process_response_queue(rsp);
a8488abe 1718 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
a8488abe 1719
0e973a24 1720 spin_unlock_irq(&ha->hardware_lock);
a8488abe
AV
1721
1722 return IRQ_HANDLED;
1723}
1724
73208dfd
AC
1725static irqreturn_t
1726qla25xx_msix_rsp_q(int irq, void *dev_id)
1727{
1728 struct qla_hw_data *ha;
1729 struct rsp_que *rsp;
1730 struct device_reg_24xx __iomem *reg;
73208dfd
AC
1731
1732 rsp = (struct rsp_que *) dev_id;
1733 if (!rsp) {
1734 printk(KERN_INFO
1735 "%s(): NULL response queue pointer\n", __func__);
1736 return IRQ_NONE;
1737 }
1738 ha = rsp->hw;
1739 reg = &ha->iobase->isp24;
1740
1741 spin_lock_irq(&ha->hardware_lock);
1742
73208dfd
AC
1743 qla24xx_process_response_queue(rsp);
1744
73208dfd
AC
1745 spin_unlock_irq(&ha->hardware_lock);
1746
1747 return IRQ_HANDLED;
1748}
1749
a8488abe
AV
1750static irqreturn_t
1751qla24xx_msix_default(int irq, void *dev_id)
1752{
e315cd28
AC
1753 scsi_qla_host_t *vha;
1754 struct qla_hw_data *ha;
1755 struct rsp_que *rsp;
a8488abe
AV
1756 struct device_reg_24xx __iomem *reg;
1757 int status;
a8488abe
AV
1758 uint32_t stat;
1759 uint32_t hccr;
1760 uint16_t mb[4];
1761
e315cd28
AC
1762 rsp = (struct rsp_que *) dev_id;
1763 if (!rsp) {
1764 DEBUG(printk(
1765 "%s(): NULL response queue pointer\n", __func__));
1766 return IRQ_NONE;
1767 }
1768 ha = rsp->hw;
a8488abe
AV
1769 reg = &ha->iobase->isp24;
1770 status = 0;
1771
0e973a24 1772 spin_lock_irq(&ha->hardware_lock);
e315cd28 1773 vha = qla2x00_get_rsp_host(rsp);
87f27015 1774 do {
a8488abe
AV
1775 stat = RD_REG_DWORD(&reg->host_status);
1776 if (stat & HSRX_RISC_PAUSED) {
14e660e6
SJ
1777 if (pci_channel_offline(ha->pdev))
1778 break;
1779
a8488abe
AV
1780 hccr = RD_REG_DWORD(&reg->hccr);
1781
1782 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1783 "Dumping firmware!\n", hccr);
05236a05 1784
e315cd28 1785 qla2xxx_check_risc_status(vha);
05236a05 1786
e315cd28
AC
1787 ha->isp_ops->fw_dump(vha, 1);
1788 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
a8488abe
AV
1789 break;
1790 } else if ((stat & HSRX_RISC_INT) == 0)
1791 break;
1792
1793 switch (stat & 0xff) {
1794 case 0x1:
1795 case 0x2:
1796 case 0x10:
1797 case 0x11:
e315cd28 1798 qla24xx_mbx_completion(vha, MSW(stat));
a8488abe
AV
1799 status |= MBX_INTERRUPT;
1800
1801 break;
1802 case 0x12:
1803 mb[0] = MSW(stat);
1804 mb[1] = RD_REG_WORD(&reg->mailbox1);
1805 mb[2] = RD_REG_WORD(&reg->mailbox2);
1806 mb[3] = RD_REG_WORD(&reg->mailbox3);
73208dfd 1807 qla2x00_async_event(vha, rsp, mb);
a8488abe
AV
1808 break;
1809 case 0x13:
73208dfd
AC
1810 case 0x14:
1811 qla24xx_process_response_queue(rsp);
a8488abe
AV
1812 break;
1813 default:
1814 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1815 "(%d).\n",
e315cd28 1816 vha->host_no, stat & 0xff));
a8488abe
AV
1817 break;
1818 }
1819 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
87f27015 1820 } while (0);
0e973a24 1821 spin_unlock_irq(&ha->hardware_lock);
a8488abe
AV
1822
1823 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1824 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
a8488abe 1825 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
0b05a1f0 1826 complete(&ha->mbx_intr_comp);
a8488abe
AV
1827 }
1828
1829 return IRQ_HANDLED;
1830}
1831
1832/* Interrupt handling helpers. */
1833
1834struct qla_init_msix_entry {
1835 uint16_t entry;
1836 uint16_t index;
1837 const char *name;
476834c2 1838 irq_handler_t handler;
a8488abe
AV
1839};
1840
73208dfd
AC
1841static struct qla_init_msix_entry base_queue = {
1842 .entry = 0,
1843 .index = 0,
1844 .name = "qla2xxx (default)",
1845 .handler = qla24xx_msix_default,
1846};
1847
1848static struct qla_init_msix_entry base_rsp_queue = {
1849 .entry = 1,
1850 .index = 1,
1851 .name = "qla2xxx (rsp_q)",
1852 .handler = qla24xx_msix_rsp_q,
1853};
a8488abe 1854
73208dfd
AC
1855static struct qla_init_msix_entry multi_rsp_queue = {
1856 .entry = 1,
1857 .index = 1,
1858 .name = "qla2xxx (multi_q)",
1859 .handler = qla25xx_msix_rsp_q,
a8488abe
AV
1860};
1861
1862static void
e315cd28 1863qla24xx_disable_msix(struct qla_hw_data *ha)
a8488abe
AV
1864{
1865 int i;
1866 struct qla_msix_entry *qentry;
1867
73208dfd
AC
1868 for (i = 0; i < ha->msix_count; i++) {
1869 qentry = &ha->msix_entries[i];
a8488abe 1870 if (qentry->have_irq)
73208dfd 1871 free_irq(qentry->vector, qentry->rsp);
a8488abe
AV
1872 }
1873 pci_disable_msix(ha->pdev);
73208dfd
AC
1874 kfree(ha->msix_entries);
1875 ha->msix_entries = NULL;
1876 ha->flags.msix_enabled = 0;
a8488abe
AV
1877}
1878
1879static int
73208dfd 1880qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
a8488abe 1881{
ad038fa8 1882#define MIN_MSIX_COUNT 2
a8488abe 1883 int i, ret;
73208dfd 1884 struct msix_entry *entries;
a8488abe 1885 struct qla_msix_entry *qentry;
73208dfd
AC
1886 struct qla_init_msix_entry *msix_queue;
1887
1888 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
1889 GFP_KERNEL);
1890 if (!entries)
1891 return -ENOMEM;
a8488abe 1892
73208dfd
AC
1893 for (i = 0; i < ha->msix_count; i++)
1894 entries[i].entry = i;
a8488abe 1895
73208dfd 1896 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
a8488abe 1897 if (ret) {
ad038fa8
LC
1898 if (ret < MIN_MSIX_COUNT)
1899 goto msix_failed;
1900
a8488abe 1901 qla_printk(KERN_WARNING, ha,
73208dfd
AC
1902 "MSI-X: Failed to enable support -- %d/%d\n"
1903 " Retry with %d vectors\n", ha->msix_count, ret, ret);
1904 ha->msix_count = ret;
1905 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1906 if (ret) {
ad038fa8 1907msix_failed:
73208dfd
AC
1908 qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
1909 " support, giving up -- %d/%d\n",
1910 ha->msix_count, ret);
1911 goto msix_out;
1912 }
1913 ha->max_queues = ha->msix_count - 1;
1914 }
1915 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
1916 ha->msix_count, GFP_KERNEL);
1917 if (!ha->msix_entries) {
1918 ret = -ENOMEM;
a8488abe
AV
1919 goto msix_out;
1920 }
1921 ha->flags.msix_enabled = 1;
1922
73208dfd
AC
1923 for (i = 0; i < ha->msix_count; i++) {
1924 qentry = &ha->msix_entries[i];
1925 qentry->vector = entries[i].vector;
1926 qentry->entry = entries[i].entry;
a8488abe 1927 qentry->have_irq = 0;
73208dfd 1928 qentry->rsp = NULL;
a8488abe
AV
1929 }
1930
73208dfd
AC
1931 /* Enable MSI-X for AENs for queue 0 */
1932 qentry = &ha->msix_entries[0];
1933 ret = request_irq(qentry->vector, base_queue.handler, 0,
1934 base_queue.name, rsp);
1935 if (ret) {
1936 qla_printk(KERN_WARNING, ha,
1937 "MSI-X: Unable to register handler -- %x/%d.\n",
1938 qentry->vector, ret);
1939 qla24xx_disable_msix(ha);
1940 goto msix_out;
1941 }
1942 qentry->have_irq = 1;
1943 qentry->rsp = rsp;
1944
1945 /* Enable MSI-X vector for response queue update for queue 0 */
1946 if (ha->max_queues > 1 && ha->mqiobase) {
1947 ha->mqenable = 1;
1948 msix_queue = &multi_rsp_queue;
1949 qla_printk(KERN_INFO, ha,
1950 "MQ enabled, Number of Queue Resources: %d \n",
1951 ha->max_queues);
1952 } else {
1953 ha->mqenable = 0;
1954 msix_queue = &base_rsp_queue;
1955 }
1956
1957 qentry = &ha->msix_entries[1];
1958 ret = request_irq(qentry->vector, msix_queue->handler, 0,
1959 msix_queue->name, rsp);
1960 if (ret) {
1961 qla_printk(KERN_WARNING, ha,
1962 "MSI-X: Unable to register handler -- %x/%d.\n",
1963 qentry->vector, ret);
1964 qla24xx_disable_msix(ha);
1965 ha->mqenable = 0;
1966 goto msix_out;
1967 }
1968 qentry->have_irq = 1;
1969 qentry->rsp = rsp;
1970
a8488abe 1971msix_out:
73208dfd 1972 kfree(entries);
a8488abe
AV
1973 return ret;
1974}
1975
1976int
73208dfd 1977qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
a8488abe
AV
1978{
1979 int ret;
963b0fdd 1980 device_reg_t __iomem *reg = ha->iobase;
a8488abe
AV
1981
1982 /* If possible, enable MSI-X. */
3a03eb79
AV
1983 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
1984 !IS_QLA8432(ha) && !IS_QLA8001(ha))
a8488abe
AV
1985 goto skip_msix;
1986
e315cd28
AC
1987 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
1988 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
a8488abe 1989 DEBUG2(qla_printk(KERN_WARNING, ha,
e315cd28
AC
1990 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1991 ha->pdev->revision, ha->fw_attributes));
a8488abe
AV
1992
1993 goto skip_msix;
1994 }
1995
da7429f9
AV
1996 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1997 (ha->pdev->subsystem_device == 0x7040 ||
1998 ha->pdev->subsystem_device == 0x7041 ||
1999 ha->pdev->subsystem_device == 0x1705)) {
2000 DEBUG2(qla_printk(KERN_WARNING, ha,
2001 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
2002 ha->pdev->subsystem_vendor,
2003 ha->pdev->subsystem_device));
2004
2005 goto skip_msi;
2006 }
2007
73208dfd 2008 ret = qla24xx_enable_msix(ha, rsp);
a8488abe
AV
2009 if (!ret) {
2010 DEBUG2(qla_printk(KERN_INFO, ha,
2011 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
2012 ha->fw_attributes));
963b0fdd 2013 goto clear_risc_ints;
a8488abe
AV
2014 }
2015 qla_printk(KERN_WARNING, ha,
2016 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
2017skip_msix:
cbedb601 2018
3a03eb79
AV
2019 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
2020 !IS_QLA8001(ha))
cbedb601
AV
2021 goto skip_msi;
2022
2023 ret = pci_enable_msi(ha->pdev);
2024 if (!ret) {
2025 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
2026 ha->flags.msi_enabled = 1;
2027 }
2028skip_msi:
2029
fd34f556 2030 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
e315cd28 2031 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
963b0fdd 2032 if (ret) {
a8488abe
AV
2033 qla_printk(KERN_WARNING, ha,
2034 "Failed to reserve interrupt %d already in use.\n",
2035 ha->pdev->irq);
963b0fdd
AV
2036 goto fail;
2037 }
2038 ha->flags.inta_enabled = 1;
963b0fdd
AV
2039clear_risc_ints:
2040
3a03eb79
AV
2041 /*
2042 * FIXME: Noted that 8014s were being dropped during NK testing.
2043 * Timing deltas during MSI-X/INTa transitions?
2044 */
2045 if (IS_QLA81XX(ha))
2046 goto fail;
c6952483 2047 spin_lock_irq(&ha->hardware_lock);
963b0fdd
AV
2048 if (IS_FWI2_CAPABLE(ha)) {
2049 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
2050 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
2051 } else {
2052 WRT_REG_WORD(&reg->isp.semaphore, 0);
2053 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
2054 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
a8488abe 2055 }
c6952483 2056 spin_unlock_irq(&ha->hardware_lock);
a8488abe 2057
963b0fdd 2058fail:
a8488abe
AV
2059 return ret;
2060}
2061
2062void
e315cd28 2063qla2x00_free_irqs(scsi_qla_host_t *vha)
a8488abe 2064{
e315cd28 2065 struct qla_hw_data *ha = vha->hw;
73208dfd 2066 struct rsp_que *rsp = ha->rsp_q_map[0];
a8488abe
AV
2067
2068 if (ha->flags.msix_enabled)
2069 qla24xx_disable_msix(ha);
cbedb601 2070 else if (ha->flags.inta_enabled) {
e315cd28 2071 free_irq(ha->pdev->irq, rsp);
cbedb601
AV
2072 pci_disable_msi(ha->pdev);
2073 }
a8488abe 2074}
e315cd28
AC
2075
2076static struct scsi_qla_host *
2077qla2x00_get_rsp_host(struct rsp_que *rsp)
2078{
2079 srb_t *sp;
2080 struct qla_hw_data *ha = rsp->hw;
2081 struct scsi_qla_host *vha = NULL;
73208dfd
AC
2082 struct sts_entry_24xx *pkt;
2083 struct req_que *req;
2084
2085 if (rsp->id) {
2086 pkt = (struct sts_entry_24xx *) rsp->ring_ptr;
2087 req = rsp->req;
2088 if (pkt && pkt->handle < MAX_OUTSTANDING_COMMANDS) {
2089 sp = req->outstanding_cmds[pkt->handle];
2090 if (sp)
444786d7 2091 vha = sp->fcport->vha;
73208dfd 2092 }
e315cd28
AC
2093 }
2094 if (!vha)
73208dfd 2095 /* handle it in base queue */
e315cd28
AC
2096 vha = pci_get_drvdata(ha->pdev);
2097
2098 return vha;
2099}
73208dfd
AC
2100
2101int qla25xx_request_irq(struct rsp_que *rsp)
2102{
2103 struct qla_hw_data *ha = rsp->hw;
2104 struct qla_init_msix_entry *intr = &multi_rsp_queue;
2105 struct qla_msix_entry *msix = rsp->msix;
2106 int ret;
2107
2108 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2109 if (ret) {
2110 qla_printk(KERN_WARNING, ha,
2111 "MSI-X: Unable to register handler -- %x/%d.\n",
2112 msix->vector, ret);
2113 return ret;
2114 }
2115 msix->have_irq = 1;
2116 msix->rsp = rsp;
2117 return ret;
2118}