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