Staging: strip: delete the driver
[linux/fpc-iii.git] / drivers / scsi / qla2xxx / qla_isr.c
blobdb539b0c3dae71cbe8b86609b44409c6c7f3f56b
1 /*
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
7 #include "qla_def.h"
9 #include <linux/delay.h>
10 #include <linux/slab.h>
11 #include <scsi/scsi_tcq.h>
12 #include <scsi/scsi_bsg_fc.h>
14 static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
15 static void qla2x00_process_completed_request(struct scsi_qla_host *,
16 struct req_que *, uint32_t);
17 static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
18 static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
19 static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
20 sts_entry_t *);
22 /**
23 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
24 * @irq:
25 * @dev_id: SCSI driver HA context
27 * Called by system whenever the host adapter generates an interrupt.
29 * Returns handled flag.
31 irqreturn_t
32 qla2100_intr_handler(int irq, void *dev_id)
34 scsi_qla_host_t *vha;
35 struct qla_hw_data *ha;
36 struct device_reg_2xxx __iomem *reg;
37 int status;
38 unsigned long iter;
39 uint16_t hccr;
40 uint16_t mb[4];
41 struct rsp_que *rsp;
42 unsigned long flags;
44 rsp = (struct rsp_que *) dev_id;
45 if (!rsp) {
46 printk(KERN_INFO
47 "%s(): NULL response queue pointer\n", __func__);
48 return (IRQ_NONE);
51 ha = rsp->hw;
52 reg = &ha->iobase->isp;
53 status = 0;
55 spin_lock_irqsave(&ha->hardware_lock, flags);
56 vha = pci_get_drvdata(ha->pdev);
57 for (iter = 50; iter--; ) {
58 hccr = RD_REG_WORD(&reg->hccr);
59 if (hccr & HCCR_RISC_PAUSE) {
60 if (pci_channel_offline(ha->pdev))
61 break;
64 * Issue a "HARD" reset in order for the RISC interrupt
65 * bit to be cleared. Schedule a big hammmer to get
66 * out of the RISC PAUSED state.
68 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
69 RD_REG_WORD(&reg->hccr);
71 ha->isp_ops->fw_dump(vha, 1);
72 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
73 break;
74 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
75 break;
77 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
78 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
79 RD_REG_WORD(&reg->hccr);
81 /* Get mailbox data. */
82 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
83 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
84 qla2x00_mbx_completion(vha, mb[0]);
85 status |= MBX_INTERRUPT;
86 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
87 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
88 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
89 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
90 qla2x00_async_event(vha, rsp, mb);
91 } else {
92 /*EMPTY*/
93 DEBUG2(printk("scsi(%ld): Unrecognized "
94 "interrupt type (%d).\n",
95 vha->host_no, mb[0]));
97 /* Release mailbox registers. */
98 WRT_REG_WORD(&reg->semaphore, 0);
99 RD_REG_WORD(&reg->semaphore);
100 } else {
101 qla2x00_process_response_queue(rsp);
103 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
104 RD_REG_WORD(&reg->hccr);
107 spin_unlock_irqrestore(&ha->hardware_lock, flags);
109 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
110 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
111 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
112 complete(&ha->mbx_intr_comp);
115 return (IRQ_HANDLED);
119 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
120 * @irq:
121 * @dev_id: SCSI driver HA context
123 * Called by system whenever the host adapter generates an interrupt.
125 * Returns handled flag.
127 irqreturn_t
128 qla2300_intr_handler(int irq, void *dev_id)
130 scsi_qla_host_t *vha;
131 struct device_reg_2xxx __iomem *reg;
132 int status;
133 unsigned long iter;
134 uint32_t stat;
135 uint16_t hccr;
136 uint16_t mb[4];
137 struct rsp_que *rsp;
138 struct qla_hw_data *ha;
139 unsigned long flags;
141 rsp = (struct rsp_que *) dev_id;
142 if (!rsp) {
143 printk(KERN_INFO
144 "%s(): NULL response queue pointer\n", __func__);
145 return (IRQ_NONE);
148 ha = rsp->hw;
149 reg = &ha->iobase->isp;
150 status = 0;
152 spin_lock_irqsave(&ha->hardware_lock, flags);
153 vha = pci_get_drvdata(ha->pdev);
154 for (iter = 50; iter--; ) {
155 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
156 if (stat & HSR_RISC_PAUSED) {
157 if (unlikely(pci_channel_offline(ha->pdev)))
158 break;
160 hccr = RD_REG_WORD(&reg->hccr);
161 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
162 qla_printk(KERN_INFO, ha, "Parity error -- "
163 "HCCR=%x, Dumping firmware!\n", hccr);
164 else
165 qla_printk(KERN_INFO, ha, "RISC paused -- "
166 "HCCR=%x, Dumping firmware!\n", hccr);
169 * Issue a "HARD" reset in order for the RISC
170 * interrupt bit to be cleared. Schedule a big
171 * hammmer to get out of the RISC PAUSED state.
173 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
174 RD_REG_WORD(&reg->hccr);
176 ha->isp_ops->fw_dump(vha, 1);
177 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
178 break;
179 } else if ((stat & HSR_RISC_INT) == 0)
180 break;
182 switch (stat & 0xff) {
183 case 0x1:
184 case 0x2:
185 case 0x10:
186 case 0x11:
187 qla2x00_mbx_completion(vha, MSW(stat));
188 status |= MBX_INTERRUPT;
190 /* Release mailbox registers. */
191 WRT_REG_WORD(&reg->semaphore, 0);
192 break;
193 case 0x12:
194 mb[0] = MSW(stat);
195 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
196 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
197 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
198 qla2x00_async_event(vha, rsp, mb);
199 break;
200 case 0x13:
201 qla2x00_process_response_queue(rsp);
202 break;
203 case 0x15:
204 mb[0] = MBA_CMPLT_1_16BIT;
205 mb[1] = MSW(stat);
206 qla2x00_async_event(vha, rsp, mb);
207 break;
208 case 0x16:
209 mb[0] = MBA_SCSI_COMPLETION;
210 mb[1] = MSW(stat);
211 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
212 qla2x00_async_event(vha, rsp, mb);
213 break;
214 default:
215 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
216 "(%d).\n",
217 vha->host_no, stat & 0xff));
218 break;
220 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
221 RD_REG_WORD_RELAXED(&reg->hccr);
223 spin_unlock_irqrestore(&ha->hardware_lock, flags);
225 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
226 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
227 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
228 complete(&ha->mbx_intr_comp);
231 return (IRQ_HANDLED);
235 * qla2x00_mbx_completion() - Process mailbox command completions.
236 * @ha: SCSI driver HA context
237 * @mb0: Mailbox0 register
239 static void
240 qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
242 uint16_t cnt;
243 uint16_t __iomem *wptr;
244 struct qla_hw_data *ha = vha->hw;
245 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
247 /* Load return mailbox registers. */
248 ha->flags.mbox_int = 1;
249 ha->mailbox_out[0] = mb0;
250 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
252 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
253 if (IS_QLA2200(ha) && cnt == 8)
254 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
255 if (cnt == 4 || cnt == 5)
256 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
257 else
258 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
260 wptr++;
263 if (ha->mcp) {
264 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
265 __func__, vha->host_no, ha->mcp->mb[0]));
266 } else {
267 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
268 __func__, vha->host_no));
272 static void
273 qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
275 static char *event[] =
276 { "Complete", "Request Notification", "Time Extension" };
277 int rval;
278 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
279 uint16_t __iomem *wptr;
280 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
282 /* Seed data -- mailbox1 -> mailbox7. */
283 wptr = (uint16_t __iomem *)&reg24->mailbox1;
284 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
285 mb[cnt] = RD_REG_WORD(wptr);
287 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
288 "%04x %04x %04x %04x %04x %04x %04x.\n", vha->host_no,
289 event[aen & 0xff],
290 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6]));
292 /* Acknowledgement needed? [Notify && non-zero timeout]. */
293 timeout = (descr >> 8) & 0xf;
294 if (aen != MBA_IDC_NOTIFY || !timeout)
295 return;
297 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
298 "ACK timeout=%d.\n", vha->host_no, event[aen & 0xff], timeout));
300 rval = qla2x00_post_idc_ack_work(vha, mb);
301 if (rval != QLA_SUCCESS)
302 qla_printk(KERN_WARNING, vha->hw,
303 "IDC failed to post ACK.\n");
307 * qla2x00_async_event() - Process aynchronous events.
308 * @ha: SCSI driver HA context
309 * @mb: Mailbox registers (0 - 3)
311 void
312 qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
314 #define LS_UNKNOWN 2
315 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
316 char *link_speed;
317 uint16_t handle_cnt;
318 uint16_t cnt, mbx;
319 uint32_t handles[5];
320 struct qla_hw_data *ha = vha->hw;
321 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
322 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
323 uint32_t rscn_entry, host_pid;
324 uint8_t rscn_queue_index;
325 unsigned long flags;
327 /* Setup to process RIO completion. */
328 handle_cnt = 0;
329 if (IS_QLA81XX(ha))
330 goto skip_rio;
331 switch (mb[0]) {
332 case MBA_SCSI_COMPLETION:
333 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
334 handle_cnt = 1;
335 break;
336 case MBA_CMPLT_1_16BIT:
337 handles[0] = mb[1];
338 handle_cnt = 1;
339 mb[0] = MBA_SCSI_COMPLETION;
340 break;
341 case MBA_CMPLT_2_16BIT:
342 handles[0] = mb[1];
343 handles[1] = mb[2];
344 handle_cnt = 2;
345 mb[0] = MBA_SCSI_COMPLETION;
346 break;
347 case MBA_CMPLT_3_16BIT:
348 handles[0] = mb[1];
349 handles[1] = mb[2];
350 handles[2] = mb[3];
351 handle_cnt = 3;
352 mb[0] = MBA_SCSI_COMPLETION;
353 break;
354 case MBA_CMPLT_4_16BIT:
355 handles[0] = mb[1];
356 handles[1] = mb[2];
357 handles[2] = mb[3];
358 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
359 handle_cnt = 4;
360 mb[0] = MBA_SCSI_COMPLETION;
361 break;
362 case MBA_CMPLT_5_16BIT:
363 handles[0] = mb[1];
364 handles[1] = mb[2];
365 handles[2] = mb[3];
366 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
367 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
368 handle_cnt = 5;
369 mb[0] = MBA_SCSI_COMPLETION;
370 break;
371 case MBA_CMPLT_2_32BIT:
372 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
373 handles[1] = le32_to_cpu(
374 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
375 RD_MAILBOX_REG(ha, reg, 6));
376 handle_cnt = 2;
377 mb[0] = MBA_SCSI_COMPLETION;
378 break;
379 default:
380 break;
382 skip_rio:
383 switch (mb[0]) {
384 case MBA_SCSI_COMPLETION: /* Fast Post */
385 if (!vha->flags.online)
386 break;
388 for (cnt = 0; cnt < handle_cnt; cnt++)
389 qla2x00_process_completed_request(vha, rsp->req,
390 handles[cnt]);
391 break;
393 case MBA_RESET: /* Reset */
394 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
395 vha->host_no));
397 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
398 break;
400 case MBA_SYSTEM_ERR: /* System Error */
401 mbx = IS_QLA81XX(ha) ? RD_REG_WORD(&reg24->mailbox7) : 0;
402 qla_printk(KERN_INFO, ha,
403 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
404 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
406 ha->isp_ops->fw_dump(vha, 1);
408 if (IS_FWI2_CAPABLE(ha)) {
409 if (mb[1] == 0 && mb[2] == 0) {
410 qla_printk(KERN_ERR, ha,
411 "Unrecoverable Hardware Error: adapter "
412 "marked OFFLINE!\n");
413 vha->flags.online = 0;
414 } else
415 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
416 } else if (mb[1] == 0) {
417 qla_printk(KERN_INFO, ha,
418 "Unrecoverable Hardware Error: adapter marked "
419 "OFFLINE!\n");
420 vha->flags.online = 0;
421 } else
422 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
423 break;
425 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
426 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error (%x).\n",
427 vha->host_no, mb[1]));
428 qla_printk(KERN_WARNING, ha,
429 "ISP Request Transfer Error (%x).\n", mb[1]);
431 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
432 break;
434 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
435 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
436 vha->host_no));
437 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
439 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
440 break;
442 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
443 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
444 vha->host_no));
445 break;
447 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
448 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
449 mb[1]));
450 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
452 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
453 atomic_set(&vha->loop_state, LOOP_DOWN);
454 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
455 qla2x00_mark_all_devices_lost(vha, 1);
458 if (vha->vp_idx) {
459 atomic_set(&vha->vp_state, VP_FAILED);
460 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
463 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
464 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
466 vha->flags.management_server_logged_in = 0;
467 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
468 break;
470 case MBA_LOOP_UP: /* Loop Up Event */
471 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
472 link_speed = link_speeds[0];
473 ha->link_data_rate = PORT_SPEED_1GB;
474 } else {
475 link_speed = link_speeds[LS_UNKNOWN];
476 if (mb[1] < 5)
477 link_speed = link_speeds[mb[1]];
478 else if (mb[1] == 0x13)
479 link_speed = link_speeds[5];
480 ha->link_data_rate = mb[1];
483 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
484 vha->host_no, link_speed));
485 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
486 link_speed);
488 vha->flags.management_server_logged_in = 0;
489 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
490 break;
492 case MBA_LOOP_DOWN: /* Loop Down Event */
493 mbx = IS_QLA81XX(ha) ? RD_REG_WORD(&reg24->mailbox4) : 0;
494 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
495 "(%x %x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3],
496 mbx));
497 qla_printk(KERN_INFO, ha,
498 "LOOP DOWN detected (%x %x %x %x).\n", mb[1], mb[2], mb[3],
499 mbx);
501 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
502 atomic_set(&vha->loop_state, LOOP_DOWN);
503 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
504 vha->device_flags |= DFLG_NO_CABLE;
505 qla2x00_mark_all_devices_lost(vha, 1);
508 if (vha->vp_idx) {
509 atomic_set(&vha->vp_state, VP_FAILED);
510 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
513 vha->flags.management_server_logged_in = 0;
514 ha->link_data_rate = PORT_SPEED_UNKNOWN;
515 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
516 break;
518 case MBA_LIP_RESET: /* LIP reset occurred */
519 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
520 vha->host_no, mb[1]));
521 qla_printk(KERN_INFO, ha,
522 "LIP reset occurred (%x).\n", mb[1]);
524 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
525 atomic_set(&vha->loop_state, LOOP_DOWN);
526 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
527 qla2x00_mark_all_devices_lost(vha, 1);
530 if (vha->vp_idx) {
531 atomic_set(&vha->vp_state, VP_FAILED);
532 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
535 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
537 ha->operating_mode = LOOP;
538 vha->flags.management_server_logged_in = 0;
539 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
540 break;
542 /* case MBA_DCBX_COMPLETE: */
543 case MBA_POINT_TO_POINT: /* Point-to-Point */
544 if (IS_QLA2100(ha))
545 break;
547 if (IS_QLA81XX(ha))
548 DEBUG2(printk("scsi(%ld): DCBX Completed -- %04x %04x "
549 "%04x\n", vha->host_no, mb[1], mb[2], mb[3]));
550 else
551 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE "
552 "received.\n", vha->host_no));
555 * Until there's a transition from loop down to loop up, treat
556 * this as loop down only.
558 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
559 atomic_set(&vha->loop_state, LOOP_DOWN);
560 if (!atomic_read(&vha->loop_down_timer))
561 atomic_set(&vha->loop_down_timer,
562 LOOP_DOWN_TIME);
563 qla2x00_mark_all_devices_lost(vha, 1);
566 if (vha->vp_idx) {
567 atomic_set(&vha->vp_state, VP_FAILED);
568 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
571 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
572 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
574 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
575 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
577 ha->flags.gpsc_supported = 1;
578 vha->flags.management_server_logged_in = 0;
579 break;
581 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
582 if (IS_QLA2100(ha))
583 break;
585 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
586 "received.\n",
587 vha->host_no));
588 qla_printk(KERN_INFO, ha,
589 "Configuration change detected: value=%x.\n", mb[1]);
591 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
592 atomic_set(&vha->loop_state, LOOP_DOWN);
593 if (!atomic_read(&vha->loop_down_timer))
594 atomic_set(&vha->loop_down_timer,
595 LOOP_DOWN_TIME);
596 qla2x00_mark_all_devices_lost(vha, 1);
599 if (vha->vp_idx) {
600 atomic_set(&vha->vp_state, VP_FAILED);
601 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
604 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
605 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
606 break;
608 case MBA_PORT_UPDATE: /* Port database update */
610 * Handle only global and vn-port update events
612 * Relevant inputs:
613 * mb[1] = N_Port handle of changed port
614 * OR 0xffff for global event
615 * mb[2] = New login state
616 * 7 = Port logged out
617 * mb[3] = LSB is vp_idx, 0xff = all vps
619 * Skip processing if:
620 * Event is global, vp_idx is NOT all vps,
621 * vp_idx does not match
622 * Event is not global, vp_idx does not match
624 if (IS_QLA2XXX_MIDTYPE(ha) &&
625 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
626 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
627 break;
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]));
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);
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);
652 vha->flags.management_server_logged_in = 0;
653 ha->link_data_rate = PORT_SPEED_UNKNOWN;
654 break;
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.
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;
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]));
678 * Mark all devices as missing so we will login again.
680 atomic_set(&vha->loop_state, LOOP_UP);
682 qla2x00_mark_all_devices_lost(vha, 1);
684 vha->flags.rscn_queue_overflow = 1;
686 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
687 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
688 break;
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;
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]));
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;
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;
727 atomic_set(&vha->loop_state, LOOP_UPDATE);
728 atomic_set(&vha->loop_down_timer, 0);
729 vha->flags.management_server_logged_in = 0;
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;
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));
741 if (IS_FWI2_CAPABLE(ha))
742 qla24xx_process_response_queue(vha, rsp);
743 else
744 qla2x00_process_response_queue(rsp);
745 break;
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;
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;
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]));
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]);
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;
811 if (!vha->vp_idx && ha->num_vhosts)
812 qla2x00_alert_all_vps(rsp, mb);
816 * qla2x00_process_completed_request() - Process a Fast Post response.
817 * @ha: SCSI driver HA context
818 * @index: SRB index
820 static void
821 qla2x00_process_completed_request(struct scsi_qla_host *vha,
822 struct req_que *req, uint32_t index)
824 srb_t *sp;
825 struct qla_hw_data *ha = vha->hw;
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);
834 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
835 return;
838 sp = req->outstanding_cmds[index];
839 if (sp) {
840 /* Free outstanding command slot. */
841 req->outstanding_cmds[index] = NULL;
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");
852 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
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)
860 struct qla_hw_data *ha = vha->hw;
861 sts_entry_t *pkt = iocb;
862 srb_t *sp = NULL;
863 uint16_t index;
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;
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;
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;
886 req->outstanding_cmds[index] = NULL;
888 done:
889 return sp;
892 static void
893 qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
894 struct mbx_entry *mbx)
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];
904 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
905 if (!sp)
906 return;
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;
924 del_timer(&lio->ctx.timer);
925 fcport = sp->fcport;
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)));
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;
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)));
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;
954 goto done_post_logio_done_work;
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;
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)));
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);
984 lio->ctx.free(sp);
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)
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;
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;
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;
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);
1027 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1028 * fc payload to the caller
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);
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);
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));
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));
1059 DEBUG2(qla2x00_dump_buffer((uint8_t *)pkt, sizeof(*pkt)));
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;
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);
1081 static void
1082 qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1083 struct logio_entry_24xx *logio)
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];
1094 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1095 if (!sp)
1096 return;
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;
1114 del_timer(&lio->ctx.timer);
1115 fcport = sp->fcport;
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)));
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;
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])));
1137 data[0] = MBS_COMMAND_COMPLETE;
1138 if (lio->ctx.type == SRB_LOGOUT_CMD)
1139 goto done_post_logio_done_work;
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;
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;
1154 goto done_post_logio_done_work;
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;
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;
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])));
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);
1192 lio->ctx.free(sp);
1196 * qla2x00_process_response_queue() - Process response queue entries.
1197 * @ha: SCSI driver HA context
1199 void
1200 qla2x00_process_response_queue(struct rsp_que *rsp)
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;
1209 vha = pci_get_drvdata(ha->pdev);
1211 if (!vha->flags.online)
1212 return;
1214 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1215 pkt = (sts_entry_t *)rsp->ring_ptr;
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++;
1225 if (pkt->entry_status != 0) {
1226 DEBUG3(printk(KERN_INFO
1227 "scsi(%ld): Process error entry.\n", vha->host_no));
1229 qla2x00_error_entry(vha, rsp, pkt);
1230 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1231 wmb();
1232 continue;
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]);
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]);
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;
1267 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1268 wmb();
1271 /* Adjust ring index */
1272 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
1275 static inline void
1276 qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len,
1277 struct rsp_que *rsp)
1279 struct scsi_cmnd *cp = sp->cmd;
1281 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1282 sense_len = SCSI_SENSE_BUFFERSIZE;
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;
1289 memcpy(cp->sense_buffer, sense_data, sense_len);
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;
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));
1305 * qla2x00_status_entry() - Process a Status IOCB entry.
1306 * @ha: SCSI driver HA context
1307 * @pkt: Entry pointer
1309 static void
1310 qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
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;
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;
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);
1344 return;
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;
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");
1359 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1360 qla2xxx_wake_dpc(vha);
1361 return;
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);
1370 return;
1373 lscsi_status = scsi_status & STATUS_MASK;
1375 fcport = sp->fcport;
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;
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]));
1414 cp->result = DID_BUS_BUSY << 16;
1415 qla2x00_sp_compl(ha, sp);
1416 return;
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;
1426 * Based on Host and scsi status generate status code for Linux
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;
1435 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
1436 resid = resid_len;
1437 scsi_set_resid(cp, resid);
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));
1450 cp->result = DID_ERROR << 16;
1451 break;
1454 cp->result = DID_OK << 16 | lscsi_status;
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;
1463 if (lscsi_status != SS_CHECK_CONDITION)
1464 break;
1466 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1467 if (!(scsi_status & SS_SENSE_LEN_VALID))
1468 break;
1470 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
1471 break;
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));
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)));
1494 cp->result = DID_ERROR << 16 | lscsi_status;
1495 break;
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));
1508 cp->result = DID_ERROR << 16;
1509 break;
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)));
1519 cp->result = DID_ERROR << 16;
1520 break;
1523 cp->result = DID_OK << 16 | lscsi_status;
1526 * Check to see if SCSI Status is non zero. If so report SCSI
1527 * Status.
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;
1537 if (lscsi_status != SS_CHECK_CONDITION)
1538 break;
1540 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1541 if (!(scsi_status & SS_SENSE_LEN_VALID))
1542 break;
1544 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
1546 break;
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));
1562 cp->result = DID_ERROR << 16;
1563 break;
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:
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.
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)));
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.
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;
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));
1596 cp->result = DID_RESET << 16;
1597 break;
1599 case CS_ABORTED:
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.
1605 DEBUG2(printk(KERN_INFO
1606 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1607 vha->host_no, comp_status, scsi_status));
1609 cp->result = DID_RESET << 16;
1610 break;
1612 case CS_TIMEOUT:
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.
1618 cp->result = DID_TRANSPORT_DISRUPTED << 16;
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;
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)));
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;
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);
1646 cp->result = DID_ERROR << 16;
1647 break;
1650 /* Place command on done queue. */
1651 if (rsp->status_srb == NULL)
1652 qla2x00_sp_compl(ha, sp);
1656 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1657 * @ha: SCSI driver HA context
1658 * @pkt: Entry pointer
1660 * Extended sense data.
1662 static void
1663 qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
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;
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);
1679 rsp->status_srb = NULL;
1680 return;
1683 if (sp->request_sense_length > sizeof(pkt->data)) {
1684 sense_sz = sizeof(pkt->data);
1685 } else {
1686 sense_sz = sp->request_sense_length;
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));
1695 sp->request_sense_ptr += sense_sz;
1696 sp->request_sense_length -= sense_sz;
1698 /* Place command on done queue. */
1699 if (sp->request_sense_length == 0) {
1700 rsp->status_srb = NULL;
1701 qla2x00_sp_compl(ha, sp);
1707 * qla2x00_error_entry() - Process an error entry.
1708 * @ha: SCSI driver HA context
1709 * @pkt: Entry pointer
1711 static void
1712 qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
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
1735 /* Validate handle. */
1736 if (handle < MAX_OUTSTANDING_COMMANDS)
1737 sp = req->outstanding_cmds[handle];
1738 else
1739 sp = NULL;
1741 if (sp) {
1742 /* Free outstanding command slot. */
1743 req->outstanding_cmds[handle] = NULL;
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;
1755 qla2x00_sp_compl(ha, sp);
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");
1764 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1765 qla2xxx_wake_dpc(vha);
1770 * qla24xx_mbx_completion() - Process mailbox command completions.
1771 * @ha: SCSI driver HA context
1772 * @mb0: Mailbox0 register
1774 static void
1775 qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
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;
1782 /* Load return mailbox registers. */
1783 ha->flags.mbox_int = 1;
1784 ha->mailbox_out[0] = mb0;
1785 wptr = (uint16_t __iomem *)&reg->mailbox1;
1787 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1788 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1789 wptr++;
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));
1802 * qla24xx_process_response_queue() - Process response queue entries.
1803 * @ha: SCSI driver HA context
1805 void qla24xx_process_response_queue(struct scsi_qla_host *vha,
1806 struct rsp_que *rsp)
1808 struct sts_entry_24xx *pkt;
1810 if (!vha->flags.online)
1811 return;
1813 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1814 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
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++;
1824 if (pkt->entry_status != 0) {
1825 DEBUG3(printk(KERN_INFO
1826 "scsi(%ld): Process error entry.\n", vha->host_no));
1828 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
1829 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1830 wmb();
1831 continue;
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;
1864 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1865 wmb();
1868 /* Adjust ring index */
1869 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
1872 static void
1873 qla2xxx_check_risc_status(scsi_qla_host_t *vha)
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;
1880 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
1881 return;
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;
1895 if (rval == QLA_SUCCESS)
1896 goto next_test;
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;
1907 if (rval != QLA_SUCCESS)
1908 goto done;
1910 next_test:
1911 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1912 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1914 done:
1915 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1916 RD_REG_DWORD(&reg->iobase_window);
1920 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1921 * @irq:
1922 * @dev_id: SCSI driver HA context
1924 * Called by system whenever the host adapter generates an interrupt.
1926 * Returns handled flag.
1928 irqreturn_t
1929 qla24xx_intr_handler(int irq, void *dev_id)
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;
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;
1949 ha = rsp->hw;
1950 reg = &ha->iobase->isp24;
1951 status = 0;
1953 if (unlikely(pci_channel_offline(ha->pdev)))
1954 return IRQ_HANDLED;
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;
1964 hccr = RD_REG_DWORD(&reg->hccr);
1966 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1967 "Dumping firmware!\n", hccr);
1969 qla2xxx_check_risc_status(vha);
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;
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;
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;
2003 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2004 RD_REG_DWORD_RELAXED(&reg->hccr);
2006 spin_unlock_irqrestore(&ha->hardware_lock, flags);
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);
2014 return IRQ_HANDLED;
2017 static irqreturn_t
2018 qla24xx_msix_rsp_q(int irq, void *dev_id)
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;
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;
2032 ha = rsp->hw;
2033 reg = &ha->iobase->isp24;
2035 spin_lock_irqsave(&ha->hardware_lock, flags);
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);
2043 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2045 return IRQ_HANDLED;
2048 static irqreturn_t
2049 qla25xx_msix_rsp_q(int irq, void *dev_id)
2051 struct qla_hw_data *ha;
2052 struct rsp_que *rsp;
2053 struct device_reg_24xx __iomem *reg;
2054 unsigned long flags;
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;
2062 ha = rsp->hw;
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);
2072 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2074 return IRQ_HANDLED;
2077 static irqreturn_t
2078 qla24xx_msix_default(int irq, void *dev_id)
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;
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;
2096 ha = rsp->hw;
2097 reg = &ha->iobase->isp24;
2098 status = 0;
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;
2108 hccr = RD_REG_DWORD(&reg->hccr);
2110 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
2111 "Dumping firmware!\n", hccr);
2113 qla2xxx_check_risc_status(vha);
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;
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;
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;
2147 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2148 } while (0);
2149 spin_unlock_irqrestore(&ha->hardware_lock, flags);
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);
2156 return IRQ_HANDLED;
2159 /* Interrupt handling helpers. */
2161 struct qla_init_msix_entry {
2162 const char *name;
2163 irq_handler_t handler;
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 },
2172 static void
2173 qla24xx_disable_msix(struct qla_hw_data *ha)
2175 int i;
2176 struct qla_msix_entry *qentry;
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);
2183 pci_disable_msix(ha->pdev);
2184 kfree(ha->msix_entries);
2185 ha->msix_entries = NULL;
2186 ha->flags.msix_enabled = 0;
2189 static int
2190 qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
2192 #define MIN_MSIX_COUNT 2
2193 int i, ret;
2194 struct msix_entry *entries;
2195 struct qla_msix_entry *qentry;
2197 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
2198 GFP_KERNEL);
2199 if (!entries)
2200 return -ENOMEM;
2202 for (i = 0; i < ha->msix_count; i++)
2203 entries[i].entry = i;
2205 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
2206 if (ret) {
2207 if (ret < MIN_MSIX_COUNT)
2208 goto msix_failed;
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;
2222 ha->max_rsp_queues = ha->msix_count - 1;
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;
2230 ha->flags.msix_enabled = 1;
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;
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;
2253 qentry->have_irq = 1;
2254 qentry->rsp = rsp;
2255 rsp->msix = qentry;
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;
2262 msix_out:
2263 kfree(entries);
2264 return ret;
2268 qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
2270 int ret;
2271 device_reg_t __iomem *reg = ha->iobase;
2273 /* If possible, enable MSI-X. */
2274 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
2275 !IS_QLA8432(ha) && !IS_QLA8001(ha))
2276 goto skip_msi;
2278 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
2279 (ha->pdev->subsystem_device == 0x7040 ||
2280 ha->pdev->subsystem_device == 0x7041 ||
2281 ha->pdev->subsystem_device == 0x1705)) {
2282 DEBUG2(qla_printk(KERN_WARNING, ha,
2283 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X,0x%X).\n",
2284 ha->pdev->subsystem_vendor,
2285 ha->pdev->subsystem_device));
2286 goto skip_msi;
2289 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
2290 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
2291 DEBUG2(qla_printk(KERN_WARNING, ha,
2292 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
2293 ha->pdev->revision, ha->fw_attributes));
2294 goto skip_msix;
2297 ret = qla24xx_enable_msix(ha, rsp);
2298 if (!ret) {
2299 DEBUG2(qla_printk(KERN_INFO, ha,
2300 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
2301 ha->fw_attributes));
2302 goto clear_risc_ints;
2304 qla_printk(KERN_WARNING, ha,
2305 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
2306 skip_msix:
2308 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
2309 !IS_QLA8001(ha))
2310 goto skip_msi;
2312 ret = pci_enable_msi(ha->pdev);
2313 if (!ret) {
2314 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
2315 ha->flags.msi_enabled = 1;
2317 skip_msi:
2319 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
2320 IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
2321 if (ret) {
2322 qla_printk(KERN_WARNING, ha,
2323 "Failed to reserve interrupt %d already in use.\n",
2324 ha->pdev->irq);
2325 goto fail;
2327 ha->flags.inta_enabled = 1;
2328 clear_risc_ints:
2331 * FIXME: Noted that 8014s were being dropped during NK testing.
2332 * Timing deltas during MSI-X/INTa transitions?
2334 if (IS_QLA81XX(ha))
2335 goto fail;
2336 spin_lock_irq(&ha->hardware_lock);
2337 if (IS_FWI2_CAPABLE(ha)) {
2338 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
2339 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
2340 } else {
2341 WRT_REG_WORD(&reg->isp.semaphore, 0);
2342 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
2343 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
2345 spin_unlock_irq(&ha->hardware_lock);
2347 fail:
2348 return ret;
2351 void
2352 qla2x00_free_irqs(scsi_qla_host_t *vha)
2354 struct qla_hw_data *ha = vha->hw;
2355 struct rsp_que *rsp = ha->rsp_q_map[0];
2357 if (ha->flags.msix_enabled)
2358 qla24xx_disable_msix(ha);
2359 else if (ha->flags.msi_enabled) {
2360 free_irq(ha->pdev->irq, rsp);
2361 pci_disable_msi(ha->pdev);
2362 } else
2363 free_irq(ha->pdev->irq, rsp);
2367 int qla25xx_request_irq(struct rsp_que *rsp)
2369 struct qla_hw_data *ha = rsp->hw;
2370 struct qla_init_msix_entry *intr = &msix_entries[2];
2371 struct qla_msix_entry *msix = rsp->msix;
2372 int ret;
2374 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2375 if (ret) {
2376 qla_printk(KERN_WARNING, ha,
2377 "MSI-X: Unable to register handler -- %x/%d.\n",
2378 msix->vector, ret);
2379 return ret;
2381 msix->have_irq = 1;
2382 msix->rsp = rsp;
2383 return ret;