2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
8 #include "qla_target.h"
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <scsi/scsi_tcq.h>
13 #include <scsi/scsi_bsg_fc.h>
14 #include <scsi/scsi_eh.h>
16 static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_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 *,
23 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
25 * @dev_id: SCSI driver HA context
27 * Called by system whenever the host adapter generates an interrupt.
29 * Returns handled flag.
32 qla2100_intr_handler(int irq, void *dev_id)
35 struct qla_hw_data *ha;
36 struct device_reg_2xxx __iomem *reg;
44 rsp = (struct rsp_que *) dev_id;
46 ql_log(ql_log_info, NULL, 0x505d,
47 "%s: NULL response queue pointer.\n", __func__);
52 reg = &ha->iobase->isp;
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(®->hccr);
59 if (qla2x00_check_reg16_for_disconnect(vha, hccr))
61 if (hccr & HCCR_RISC_PAUSE) {
62 if (pci_channel_offline(ha->pdev))
66 * Issue a "HARD" reset in order for the RISC interrupt
67 * bit to be cleared. Schedule a big hammer to get
68 * out of the RISC PAUSED state.
70 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
71 RD_REG_WORD(®->hccr);
73 ha->isp_ops->fw_dump(vha, 1);
74 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
76 } else if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0)
79 if (RD_REG_WORD(®->semaphore) & BIT_0) {
80 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
81 RD_REG_WORD(®->hccr);
83 /* Get mailbox data. */
84 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
85 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
86 qla2x00_mbx_completion(vha, mb[0]);
87 status |= MBX_INTERRUPT;
88 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
89 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
90 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
91 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
92 qla2x00_async_event(vha, rsp, mb);
95 ql_dbg(ql_dbg_async, vha, 0x5025,
96 "Unrecognized interrupt type (%d).\n",
99 /* Release mailbox registers. */
100 WRT_REG_WORD(®->semaphore, 0);
101 RD_REG_WORD(®->semaphore);
103 qla2x00_process_response_queue(rsp);
105 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
106 RD_REG_WORD(®->hccr);
109 qla2x00_handle_mbx_completion(ha, status);
110 spin_unlock_irqrestore(&ha->hardware_lock, flags);
112 return (IRQ_HANDLED);
116 qla2x00_check_reg32_for_disconnect(scsi_qla_host_t *vha, uint32_t reg)
118 /* Check for PCI disconnection */
119 if (reg == 0xffffffff) {
120 if (!test_and_set_bit(PFLG_DISCONNECTED, &vha->pci_flags) &&
121 !test_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags) &&
122 !test_bit(PFLG_DRIVER_PROBING, &vha->pci_flags)) {
124 * Schedule this (only once) on the default system
125 * workqueue so that all the adapter workqueues and the
126 * DPC thread can be shutdown cleanly.
128 schedule_work(&vha->hw->board_disable);
136 qla2x00_check_reg16_for_disconnect(scsi_qla_host_t *vha, uint16_t reg)
138 return qla2x00_check_reg32_for_disconnect(vha, 0xffff0000 | reg);
142 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
144 * @dev_id: SCSI driver HA context
146 * Called by system whenever the host adapter generates an interrupt.
148 * Returns handled flag.
151 qla2300_intr_handler(int irq, void *dev_id)
153 scsi_qla_host_t *vha;
154 struct device_reg_2xxx __iomem *reg;
161 struct qla_hw_data *ha;
164 rsp = (struct rsp_que *) dev_id;
166 ql_log(ql_log_info, NULL, 0x5058,
167 "%s: NULL response queue pointer.\n", __func__);
172 reg = &ha->iobase->isp;
175 spin_lock_irqsave(&ha->hardware_lock, flags);
176 vha = pci_get_drvdata(ha->pdev);
177 for (iter = 50; iter--; ) {
178 stat = RD_REG_DWORD(®->u.isp2300.host_status);
179 if (qla2x00_check_reg32_for_disconnect(vha, stat))
181 if (stat & HSR_RISC_PAUSED) {
182 if (unlikely(pci_channel_offline(ha->pdev)))
185 hccr = RD_REG_WORD(®->hccr);
187 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
188 ql_log(ql_log_warn, vha, 0x5026,
189 "Parity error -- HCCR=%x, Dumping "
190 "firmware.\n", hccr);
192 ql_log(ql_log_warn, vha, 0x5027,
193 "RISC paused -- HCCR=%x, Dumping "
194 "firmware.\n", hccr);
197 * Issue a "HARD" reset in order for the RISC
198 * interrupt bit to be cleared. Schedule a big
199 * hammer to get out of the RISC PAUSED state.
201 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
202 RD_REG_WORD(®->hccr);
204 ha->isp_ops->fw_dump(vha, 1);
205 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
207 } else if ((stat & HSR_RISC_INT) == 0)
210 switch (stat & 0xff) {
215 qla2x00_mbx_completion(vha, MSW(stat));
216 status |= MBX_INTERRUPT;
218 /* Release mailbox registers. */
219 WRT_REG_WORD(®->semaphore, 0);
223 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
224 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
225 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
226 qla2x00_async_event(vha, rsp, mb);
229 qla2x00_process_response_queue(rsp);
232 mb[0] = MBA_CMPLT_1_16BIT;
234 qla2x00_async_event(vha, rsp, mb);
237 mb[0] = MBA_SCSI_COMPLETION;
239 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
240 qla2x00_async_event(vha, rsp, mb);
243 ql_dbg(ql_dbg_async, vha, 0x5028,
244 "Unrecognized interrupt type (%d).\n", stat & 0xff);
247 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
248 RD_REG_WORD_RELAXED(®->hccr);
250 qla2x00_handle_mbx_completion(ha, status);
251 spin_unlock_irqrestore(&ha->hardware_lock, flags);
253 return (IRQ_HANDLED);
257 * qla2x00_mbx_completion() - Process mailbox command completions.
258 * @ha: SCSI driver HA context
259 * @mb0: Mailbox0 register
262 qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
266 uint16_t __iomem *wptr;
267 struct qla_hw_data *ha = vha->hw;
268 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
270 /* Read all mbox registers? */
271 mboxes = (1 << ha->mbx_count) - 1;
273 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n");
275 mboxes = ha->mcp->in_mb;
277 /* Load return mailbox registers. */
278 ha->flags.mbox_int = 1;
279 ha->mailbox_out[0] = mb0;
281 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
283 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
284 if (IS_QLA2200(ha) && cnt == 8)
285 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
286 if ((cnt == 4 || cnt == 5) && (mboxes & BIT_0))
287 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
288 else if (mboxes & BIT_0)
289 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
297 qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
299 static char *event[] =
300 { "Complete", "Request Notification", "Time Extension" };
302 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
303 struct device_reg_82xx __iomem *reg82 = &vha->hw->iobase->isp82;
304 uint16_t __iomem *wptr;
305 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
307 /* Seed data -- mailbox1 -> mailbox7. */
308 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw))
309 wptr = (uint16_t __iomem *)®24->mailbox1;
310 else if (IS_QLA8044(vha->hw))
311 wptr = (uint16_t __iomem *)®82->mailbox_out[1];
315 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
316 mb[cnt] = RD_REG_WORD(wptr);
318 ql_dbg(ql_dbg_async, vha, 0x5021,
319 "Inter-Driver Communication %s -- "
320 "%04x %04x %04x %04x %04x %04x %04x.\n",
321 event[aen & 0xff], mb[0], mb[1], mb[2], mb[3],
322 mb[4], mb[5], mb[6]);
324 /* Handle IDC Error completion case. */
325 case MBA_IDC_COMPLETE:
327 vha->hw->flags.idc_compl_status = 1;
328 if (vha->hw->notify_dcbx_comp && !vha->vp_idx)
329 complete(&vha->hw->dcbx_comp);
334 /* Acknowledgement needed? [Notify && non-zero timeout]. */
335 timeout = (descr >> 8) & 0xf;
336 ql_dbg(ql_dbg_async, vha, 0x5022,
337 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
338 vha->host_no, event[aen & 0xff], timeout);
342 rval = qla2x00_post_idc_ack_work(vha, mb);
343 if (rval != QLA_SUCCESS)
344 ql_log(ql_log_warn, vha, 0x5023,
345 "IDC failed to post ACK.\n");
347 case MBA_IDC_TIME_EXT:
348 vha->hw->idc_extend_tmo = descr;
349 ql_dbg(ql_dbg_async, vha, 0x5087,
350 "%lu Inter-Driver Communication %s -- "
351 "Extend timeout by=%d.\n",
352 vha->host_no, event[aen & 0xff], vha->hw->idc_extend_tmo);
359 qla2x00_get_link_speed_str(struct qla_hw_data *ha, uint16_t speed)
361 static const char *const link_speeds[] = {
362 "1", "2", "?", "4", "8", "16", "32", "10"
364 #define QLA_LAST_SPEED 7
366 if (IS_QLA2100(ha) || IS_QLA2200(ha))
367 return link_speeds[0];
368 else if (speed == 0x13)
369 return link_speeds[QLA_LAST_SPEED];
370 else if (speed < QLA_LAST_SPEED)
371 return link_speeds[speed];
373 return link_speeds[LS_UNKNOWN];
377 qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t *mb)
379 struct qla_hw_data *ha = vha->hw;
382 * 8200 AEN Interpretation:
384 * mb[1] = AEN Reason code
385 * mb[2] = LSW of Peg-Halt Status-1 Register
386 * mb[6] = MSW of Peg-Halt Status-1 Register
387 * mb[3] = LSW of Peg-Halt Status-2 register
388 * mb[7] = MSW of Peg-Halt Status-2 register
389 * mb[4] = IDC Device-State Register value
390 * mb[5] = IDC Driver-Presence Register value
392 ql_dbg(ql_dbg_async, vha, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: "
393 "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n",
394 mb[0], mb[1], mb[2], mb[6]);
395 ql_dbg(ql_dbg_async, vha, 0x506c, "PH-status2: mb[3] = 0x%x "
396 "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x "
397 "Drv-Presence: mb[5] = 0x%x.\n", mb[3], mb[7], mb[4], mb[5]);
399 if (mb[1] & (IDC_PEG_HALT_STATUS_CHANGE | IDC_NIC_FW_REPORTED_FAILURE |
400 IDC_HEARTBEAT_FAILURE)) {
401 ha->flags.nic_core_hung = 1;
402 ql_log(ql_log_warn, vha, 0x5060,
403 "83XX: F/W Error Reported: Check if reset required.\n");
405 if (mb[1] & IDC_PEG_HALT_STATUS_CHANGE) {
406 uint32_t protocol_engine_id, fw_err_code, err_level;
409 * IDC_PEG_HALT_STATUS_CHANGE interpretation:
410 * - PEG-Halt Status-1 Register:
411 * (LSW = mb[2], MSW = mb[6])
412 * Bits 0-7 = protocol-engine ID
413 * Bits 8-28 = f/w error code
414 * Bits 29-31 = Error-level
415 * Error-level 0x1 = Non-Fatal error
416 * Error-level 0x2 = Recoverable Fatal error
417 * Error-level 0x4 = UnRecoverable Fatal error
418 * - PEG-Halt Status-2 Register:
419 * (LSW = mb[3], MSW = mb[7])
421 protocol_engine_id = (mb[2] & 0xff);
422 fw_err_code = (((mb[2] & 0xff00) >> 8) |
423 ((mb[6] & 0x1fff) << 8));
424 err_level = ((mb[6] & 0xe000) >> 13);
425 ql_log(ql_log_warn, vha, 0x5061, "PegHalt Status-1 "
426 "Register: protocol_engine_id=0x%x "
427 "fw_err_code=0x%x err_level=0x%x.\n",
428 protocol_engine_id, fw_err_code, err_level);
429 ql_log(ql_log_warn, vha, 0x5062, "PegHalt Status-2 "
430 "Register: 0x%x%x.\n", mb[7], mb[3]);
431 if (err_level == ERR_LEVEL_NON_FATAL) {
432 ql_log(ql_log_warn, vha, 0x5063,
433 "Not a fatal error, f/w has recovered "
435 } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
436 ql_log(ql_log_fatal, vha, 0x5064,
437 "Recoverable Fatal error: Chip reset "
439 qla83xx_schedule_work(vha,
440 QLA83XX_NIC_CORE_RESET);
441 } else if (err_level == ERR_LEVEL_UNRECOVERABLE_FATAL) {
442 ql_log(ql_log_fatal, vha, 0x5065,
443 "Unrecoverable Fatal error: Set FAILED "
444 "state, reboot required.\n");
445 qla83xx_schedule_work(vha,
446 QLA83XX_NIC_CORE_UNRECOVERABLE);
450 if (mb[1] & IDC_NIC_FW_REPORTED_FAILURE) {
451 uint16_t peg_fw_state, nw_interface_link_up;
452 uint16_t nw_interface_signal_detect, sfp_status;
453 uint16_t htbt_counter, htbt_monitor_enable;
454 uint16_t sfp_additonal_info, sfp_multirate;
455 uint16_t sfp_tx_fault, link_speed, dcbx_status;
458 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
459 * - PEG-to-FC Status Register:
460 * (LSW = mb[2], MSW = mb[6])
461 * Bits 0-7 = Peg-Firmware state
462 * Bit 8 = N/W Interface Link-up
463 * Bit 9 = N/W Interface signal detected
464 * Bits 10-11 = SFP Status
465 * SFP Status 0x0 = SFP+ transceiver not expected
466 * SFP Status 0x1 = SFP+ transceiver not present
467 * SFP Status 0x2 = SFP+ transceiver invalid
468 * SFP Status 0x3 = SFP+ transceiver present and
470 * Bits 12-14 = Heartbeat Counter
471 * Bit 15 = Heartbeat Monitor Enable
472 * Bits 16-17 = SFP Additional Info
473 * SFP info 0x0 = Unregocnized transceiver for
475 * SFP info 0x1 = SFP+ brand validation failed
476 * SFP info 0x2 = SFP+ speed validation failed
477 * SFP info 0x3 = SFP+ access error
478 * Bit 18 = SFP Multirate
479 * Bit 19 = SFP Tx Fault
480 * Bits 20-22 = Link Speed
481 * Bits 23-27 = Reserved
482 * Bits 28-30 = DCBX Status
483 * DCBX Status 0x0 = DCBX Disabled
484 * DCBX Status 0x1 = DCBX Enabled
485 * DCBX Status 0x2 = DCBX Exchange error
488 peg_fw_state = (mb[2] & 0x00ff);
489 nw_interface_link_up = ((mb[2] & 0x0100) >> 8);
490 nw_interface_signal_detect = ((mb[2] & 0x0200) >> 9);
491 sfp_status = ((mb[2] & 0x0c00) >> 10);
492 htbt_counter = ((mb[2] & 0x7000) >> 12);
493 htbt_monitor_enable = ((mb[2] & 0x8000) >> 15);
494 sfp_additonal_info = (mb[6] & 0x0003);
495 sfp_multirate = ((mb[6] & 0x0004) >> 2);
496 sfp_tx_fault = ((mb[6] & 0x0008) >> 3);
497 link_speed = ((mb[6] & 0x0070) >> 4);
498 dcbx_status = ((mb[6] & 0x7000) >> 12);
500 ql_log(ql_log_warn, vha, 0x5066,
501 "Peg-to-Fc Status Register:\n"
502 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
503 "nw_interface_signal_detect=0x%x"
504 "\nsfp_statis=0x%x.\n ", peg_fw_state,
505 nw_interface_link_up, nw_interface_signal_detect,
507 ql_log(ql_log_warn, vha, 0x5067,
508 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
509 "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ",
510 htbt_counter, htbt_monitor_enable,
511 sfp_additonal_info, sfp_multirate);
512 ql_log(ql_log_warn, vha, 0x5068,
513 "sfp_tx_fault=0x%x, link_state=0x%x, "
514 "dcbx_status=0x%x.\n", sfp_tx_fault, link_speed,
517 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
520 if (mb[1] & IDC_HEARTBEAT_FAILURE) {
521 ql_log(ql_log_warn, vha, 0x5069,
522 "Heartbeat Failure encountered, chip reset "
525 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
529 if (mb[1] & IDC_DEVICE_STATE_CHANGE) {
530 ql_log(ql_log_info, vha, 0x506a,
531 "IDC Device-State changed = 0x%x.\n", mb[4]);
532 if (ha->flags.nic_core_reset_owner)
534 qla83xx_schedule_work(vha, MBA_IDC_AEN);
539 qla2x00_is_a_vp_did(scsi_qla_host_t *vha, uint32_t rscn_entry)
541 struct qla_hw_data *ha = vha->hw;
550 spin_lock_irqsave(&ha->vport_slock, flags);
551 list_for_each_entry(vp, &ha->vp_list, list) {
552 vp_did = vp->d_id.b24;
553 if (vp_did == rscn_entry) {
558 spin_unlock_irqrestore(&ha->vport_slock, flags);
564 * qla2x00_async_event() - Process aynchronous events.
565 * @ha: SCSI driver HA context
566 * @mb: Mailbox registers (0 - 3)
569 qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
574 struct qla_hw_data *ha = vha->hw;
575 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
576 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
577 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
578 uint32_t rscn_entry, host_pid, tmp_pid;
580 fc_port_t *fcport = NULL;
582 /* Setup to process RIO completion. */
584 if (IS_CNA_CAPABLE(ha))
587 case MBA_SCSI_COMPLETION:
588 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
591 case MBA_CMPLT_1_16BIT:
594 mb[0] = MBA_SCSI_COMPLETION;
596 case MBA_CMPLT_2_16BIT:
600 mb[0] = MBA_SCSI_COMPLETION;
602 case MBA_CMPLT_3_16BIT:
607 mb[0] = MBA_SCSI_COMPLETION;
609 case MBA_CMPLT_4_16BIT:
613 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
615 mb[0] = MBA_SCSI_COMPLETION;
617 case MBA_CMPLT_5_16BIT:
621 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
622 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
624 mb[0] = MBA_SCSI_COMPLETION;
626 case MBA_CMPLT_2_32BIT:
627 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
628 handles[1] = le32_to_cpu(
629 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
630 RD_MAILBOX_REG(ha, reg, 6));
632 mb[0] = MBA_SCSI_COMPLETION;
639 case MBA_SCSI_COMPLETION: /* Fast Post */
640 if (!vha->flags.online)
643 for (cnt = 0; cnt < handle_cnt; cnt++)
644 qla2x00_process_completed_request(vha, rsp->req,
648 case MBA_RESET: /* Reset */
649 ql_dbg(ql_dbg_async, vha, 0x5002,
650 "Asynchronous RESET.\n");
652 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
655 case MBA_SYSTEM_ERR: /* System Error */
656 mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) ?
657 RD_REG_WORD(®24->mailbox7) : 0;
658 ql_log(ql_log_warn, vha, 0x5003,
659 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
660 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
662 ha->isp_ops->fw_dump(vha, 1);
664 if (IS_FWI2_CAPABLE(ha)) {
665 if (mb[1] == 0 && mb[2] == 0) {
666 ql_log(ql_log_fatal, vha, 0x5004,
667 "Unrecoverable Hardware Error: adapter "
668 "marked OFFLINE!\n");
669 vha->flags.online = 0;
670 vha->device_flags |= DFLG_DEV_FAILED;
672 /* Check to see if MPI timeout occurred */
673 if ((mbx & MBX_3) && (ha->port_no == 0))
674 set_bit(MPI_RESET_NEEDED,
677 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
679 } else if (mb[1] == 0) {
680 ql_log(ql_log_fatal, vha, 0x5005,
681 "Unrecoverable Hardware Error: adapter marked "
683 vha->flags.online = 0;
684 vha->device_flags |= DFLG_DEV_FAILED;
686 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
689 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
690 ql_log(ql_log_warn, vha, 0x5006,
691 "ISP Request Transfer Error (%x).\n", mb[1]);
693 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
696 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
697 ql_log(ql_log_warn, vha, 0x5007,
698 "ISP Response Transfer Error.\n");
700 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
703 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
704 ql_dbg(ql_dbg_async, vha, 0x5008,
705 "Asynchronous WAKEUP_THRES.\n");
708 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
709 ql_dbg(ql_dbg_async, vha, 0x5009,
710 "LIP occurred (%x).\n", mb[1]);
712 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
713 atomic_set(&vha->loop_state, LOOP_DOWN);
714 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
715 qla2x00_mark_all_devices_lost(vha, 1);
719 atomic_set(&vha->vp_state, VP_FAILED);
720 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
723 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
724 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
726 vha->flags.management_server_logged_in = 0;
727 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
730 case MBA_LOOP_UP: /* Loop Up Event */
731 if (IS_QLA2100(ha) || IS_QLA2200(ha))
732 ha->link_data_rate = PORT_SPEED_1GB;
734 ha->link_data_rate = mb[1];
736 ql_log(ql_log_info, vha, 0x500a,
737 "LOOP UP detected (%s Gbps).\n",
738 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
740 vha->flags.management_server_logged_in = 0;
741 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
744 case MBA_LOOP_DOWN: /* Loop Down Event */
745 mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha))
746 ? RD_REG_WORD(®24->mailbox4) : 0;
747 mbx = (IS_P3P_TYPE(ha)) ? RD_REG_WORD(®82->mailbox_out[4])
749 ql_log(ql_log_info, vha, 0x500b,
750 "LOOP DOWN detected (%x %x %x %x).\n",
751 mb[1], mb[2], mb[3], mbx);
753 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
754 atomic_set(&vha->loop_state, LOOP_DOWN);
755 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
757 * In case of loop down, restore WWPN from
758 * NVRAM in case of FA-WWPN capable ISP
759 * Restore for Physical Port only
762 if (ha->flags.fawwpn_enabled) {
763 void *wwpn = ha->init_cb->port_name;
764 memcpy(vha->port_name, wwpn, WWN_SIZE);
765 fc_host_port_name(vha->host) =
766 wwn_to_u64(vha->port_name);
767 ql_dbg(ql_dbg_init + ql_dbg_verbose,
768 vha, 0x0144, "LOOP DOWN detected,"
769 "restore WWPN %016llx\n",
770 wwn_to_u64(vha->port_name));
773 clear_bit(VP_CONFIG_OK, &vha->vp_flags);
776 vha->device_flags |= DFLG_NO_CABLE;
777 qla2x00_mark_all_devices_lost(vha, 1);
781 atomic_set(&vha->vp_state, VP_FAILED);
782 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
785 vha->flags.management_server_logged_in = 0;
786 ha->link_data_rate = PORT_SPEED_UNKNOWN;
787 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
790 case MBA_LIP_RESET: /* LIP reset occurred */
791 ql_dbg(ql_dbg_async, vha, 0x500c,
792 "LIP reset occurred (%x).\n", mb[1]);
794 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
795 atomic_set(&vha->loop_state, LOOP_DOWN);
796 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
797 qla2x00_mark_all_devices_lost(vha, 1);
801 atomic_set(&vha->vp_state, VP_FAILED);
802 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
805 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
807 ha->operating_mode = LOOP;
808 vha->flags.management_server_logged_in = 0;
809 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
812 /* case MBA_DCBX_COMPLETE: */
813 case MBA_POINT_TO_POINT: /* Point-to-Point */
817 if (IS_CNA_CAPABLE(ha)) {
818 ql_dbg(ql_dbg_async, vha, 0x500d,
819 "DCBX Completed -- %04x %04x %04x.\n",
820 mb[1], mb[2], mb[3]);
821 if (ha->notify_dcbx_comp && !vha->vp_idx)
822 complete(&ha->dcbx_comp);
825 ql_dbg(ql_dbg_async, vha, 0x500e,
826 "Asynchronous P2P MODE received.\n");
829 * Until there's a transition from loop down to loop up, treat
830 * this as loop down only.
832 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
833 atomic_set(&vha->loop_state, LOOP_DOWN);
834 if (!atomic_read(&vha->loop_down_timer))
835 atomic_set(&vha->loop_down_timer,
837 qla2x00_mark_all_devices_lost(vha, 1);
841 atomic_set(&vha->vp_state, VP_FAILED);
842 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
845 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
846 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
848 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
849 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
851 ha->flags.gpsc_supported = 1;
852 vha->flags.management_server_logged_in = 0;
855 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
859 ql_dbg(ql_dbg_async, vha, 0x500f,
860 "Configuration change detected: value=%x.\n", mb[1]);
862 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
863 atomic_set(&vha->loop_state, LOOP_DOWN);
864 if (!atomic_read(&vha->loop_down_timer))
865 atomic_set(&vha->loop_down_timer,
867 qla2x00_mark_all_devices_lost(vha, 1);
871 atomic_set(&vha->vp_state, VP_FAILED);
872 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
875 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
876 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
879 case MBA_PORT_UPDATE: /* Port database update */
881 * Handle only global and vn-port update events
884 * mb[1] = N_Port handle of changed port
885 * OR 0xffff for global event
886 * mb[2] = New login state
887 * 7 = Port logged out
888 * mb[3] = LSB is vp_idx, 0xff = all vps
890 * Skip processing if:
891 * Event is global, vp_idx is NOT all vps,
892 * vp_idx does not match
893 * Event is not global, vp_idx does not match
895 if (IS_QLA2XXX_MIDTYPE(ha) &&
896 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
897 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
900 /* Global event -- port logout or port unavailable. */
901 if (mb[1] == 0xffff && mb[2] == 0x7) {
902 ql_dbg(ql_dbg_async, vha, 0x5010,
903 "Port unavailable %04x %04x %04x.\n",
904 mb[1], mb[2], mb[3]);
905 ql_log(ql_log_warn, vha, 0x505e,
906 "Link is offline.\n");
908 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
909 atomic_set(&vha->loop_state, LOOP_DOWN);
910 atomic_set(&vha->loop_down_timer,
912 vha->device_flags |= DFLG_NO_CABLE;
913 qla2x00_mark_all_devices_lost(vha, 1);
917 atomic_set(&vha->vp_state, VP_FAILED);
918 fc_vport_set_state(vha->fc_vport,
920 qla2x00_mark_all_devices_lost(vha, 1);
923 vha->flags.management_server_logged_in = 0;
924 ha->link_data_rate = PORT_SPEED_UNKNOWN;
929 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
930 * event etc. earlier indicating loop is down) then process
931 * it. Otherwise ignore it and Wait for RSCN to come in.
933 atomic_set(&vha->loop_down_timer, 0);
934 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
935 atomic_read(&vha->loop_state) != LOOP_DEAD) {
936 ql_dbg(ql_dbg_async, vha, 0x5011,
937 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
938 mb[1], mb[2], mb[3]);
940 qlt_async_event(mb[0], vha, mb);
944 ql_dbg(ql_dbg_async, vha, 0x5012,
945 "Port database changed %04x %04x %04x.\n",
946 mb[1], mb[2], mb[3]);
949 * Mark all devices as missing so we will login again.
951 atomic_set(&vha->loop_state, LOOP_UP);
953 qla2x00_mark_all_devices_lost(vha, 1);
955 if (vha->vp_idx == 0 && !qla_ini_mode_enabled(vha))
956 set_bit(SCR_PENDING, &vha->dpc_flags);
958 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
959 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
960 set_bit(VP_CONFIG_OK, &vha->vp_flags);
962 qlt_async_event(mb[0], vha, mb);
965 case MBA_RSCN_UPDATE: /* State Change Registration */
966 /* Check if the Vport has issued a SCR */
967 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
969 /* Only handle SCNs for our Vport index. */
970 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
973 ql_dbg(ql_dbg_async, vha, 0x5013,
974 "RSCN database changed -- %04x %04x %04x.\n",
975 mb[1], mb[2], mb[3]);
977 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
978 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
980 if (rscn_entry == host_pid) {
981 ql_dbg(ql_dbg_async, vha, 0x5014,
982 "Ignoring RSCN update to local host "
983 "port ID (%06x).\n", host_pid);
987 /* Ignore reserved bits from RSCN-payload. */
988 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
990 /* Skip RSCNs for virtual ports on the same physical port */
991 if (qla2x00_is_a_vp_did(vha, rscn_entry))
995 * Search for the rport related to this RSCN entry and mark it
998 list_for_each_entry(fcport, &vha->vp_fcports, list) {
999 if (atomic_read(&fcport->state) != FCS_ONLINE)
1001 tmp_pid = fcport->d_id.b24;
1002 if (fcport->d_id.b24 == rscn_entry) {
1003 qla2x00_mark_device_lost(vha, fcport, 0, 0);
1008 atomic_set(&vha->loop_down_timer, 0);
1009 vha->flags.management_server_logged_in = 0;
1011 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1012 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1013 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
1016 /* case MBA_RIO_RESPONSE: */
1017 case MBA_ZIO_RESPONSE:
1018 ql_dbg(ql_dbg_async, vha, 0x5015,
1019 "[R|Z]IO update completion.\n");
1021 if (IS_FWI2_CAPABLE(ha))
1022 qla24xx_process_response_queue(vha, rsp);
1024 qla2x00_process_response_queue(rsp);
1027 case MBA_DISCARD_RND_FRAME:
1028 ql_dbg(ql_dbg_async, vha, 0x5016,
1029 "Discard RND Frame -- %04x %04x %04x.\n",
1030 mb[1], mb[2], mb[3]);
1033 case MBA_TRACE_NOTIFICATION:
1034 ql_dbg(ql_dbg_async, vha, 0x5017,
1035 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
1038 case MBA_ISP84XX_ALERT:
1039 ql_dbg(ql_dbg_async, vha, 0x5018,
1040 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
1041 mb[1], mb[2], mb[3]);
1043 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
1045 case A84_PANIC_RECOVERY:
1046 ql_log(ql_log_info, vha, 0x5019,
1047 "Alert 84XX: panic recovery %04x %04x.\n",
1050 case A84_OP_LOGIN_COMPLETE:
1051 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
1052 ql_log(ql_log_info, vha, 0x501a,
1053 "Alert 84XX: firmware version %x.\n",
1054 ha->cs84xx->op_fw_version);
1056 case A84_DIAG_LOGIN_COMPLETE:
1057 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
1058 ql_log(ql_log_info, vha, 0x501b,
1059 "Alert 84XX: diagnostic firmware version %x.\n",
1060 ha->cs84xx->diag_fw_version);
1062 case A84_GOLD_LOGIN_COMPLETE:
1063 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
1064 ha->cs84xx->fw_update = 1;
1065 ql_log(ql_log_info, vha, 0x501c,
1066 "Alert 84XX: gold firmware version %x.\n",
1067 ha->cs84xx->gold_fw_version);
1070 ql_log(ql_log_warn, vha, 0x501d,
1071 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
1072 mb[1], mb[2], mb[3]);
1074 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
1076 case MBA_DCBX_START:
1077 ql_dbg(ql_dbg_async, vha, 0x501e,
1078 "DCBX Started -- %04x %04x %04x.\n",
1079 mb[1], mb[2], mb[3]);
1081 case MBA_DCBX_PARAM_UPDATE:
1082 ql_dbg(ql_dbg_async, vha, 0x501f,
1083 "DCBX Parameters Updated -- %04x %04x %04x.\n",
1084 mb[1], mb[2], mb[3]);
1086 case MBA_FCF_CONF_ERR:
1087 ql_dbg(ql_dbg_async, vha, 0x5020,
1088 "FCF Configuration Error -- %04x %04x %04x.\n",
1089 mb[1], mb[2], mb[3]);
1091 case MBA_IDC_NOTIFY:
1092 if (IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
1093 mb[4] = RD_REG_WORD(®24->mailbox4);
1094 if (((mb[2] & 0x7fff) == MBC_PORT_RESET ||
1095 (mb[2] & 0x7fff) == MBC_SET_PORT_CONFIG) &&
1096 (mb[4] & INTERNAL_LOOPBACK_MASK) != 0) {
1097 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
1099 * Extend loop down timer since port is active.
1101 if (atomic_read(&vha->loop_state) == LOOP_DOWN)
1102 atomic_set(&vha->loop_down_timer,
1104 qla2xxx_wake_dpc(vha);
1107 case MBA_IDC_COMPLETE:
1108 if (ha->notify_lb_portup_comp && !vha->vp_idx)
1109 complete(&ha->lb_portup_comp);
1111 case MBA_IDC_TIME_EXT:
1112 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) ||
1114 qla81xx_idc_event(vha, mb[0], mb[1]);
1118 mb[4] = RD_REG_WORD(®24->mailbox4);
1119 mb[5] = RD_REG_WORD(®24->mailbox5);
1120 mb[6] = RD_REG_WORD(®24->mailbox6);
1121 mb[7] = RD_REG_WORD(®24->mailbox7);
1122 qla83xx_handle_8200_aen(vha, mb);
1125 case MBA_DPORT_DIAGNOSTICS:
1126 ql_dbg(ql_dbg_async, vha, 0x5052,
1127 "D-Port Diagnostics: %04x %04x=%s\n", mb[0], mb[1],
1128 mb[1] == 0 ? "start" :
1129 mb[1] == 1 ? "done (ok)" :
1130 mb[1] == 2 ? "done (error)" : "other");
1134 ql_dbg(ql_dbg_async, vha, 0x5057,
1135 "Unknown AEN:%04x %04x %04x %04x\n",
1136 mb[0], mb[1], mb[2], mb[3]);
1139 qlt_async_event(mb[0], vha, mb);
1141 if (!vha->vp_idx && ha->num_vhosts)
1142 qla2x00_alert_all_vps(rsp, mb);
1146 * qla2x00_process_completed_request() - Process a Fast Post response.
1147 * @ha: SCSI driver HA context
1151 qla2x00_process_completed_request(struct scsi_qla_host *vha,
1152 struct req_que *req, uint32_t index)
1155 struct qla_hw_data *ha = vha->hw;
1157 /* Validate handle. */
1158 if (index >= req->num_outstanding_cmds) {
1159 ql_log(ql_log_warn, vha, 0x3014,
1160 "Invalid SCSI command index (%x).\n", index);
1162 if (IS_P3P_TYPE(ha))
1163 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1165 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1169 sp = req->outstanding_cmds[index];
1171 /* Free outstanding command slot. */
1172 req->outstanding_cmds[index] = NULL;
1174 /* Save ISP completion status */
1175 sp->done(ha, sp, DID_OK << 16);
1177 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
1179 if (IS_P3P_TYPE(ha))
1180 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1182 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1187 qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
1188 struct req_que *req, void *iocb)
1190 struct qla_hw_data *ha = vha->hw;
1191 sts_entry_t *pkt = iocb;
1195 index = LSW(pkt->handle);
1196 if (index >= req->num_outstanding_cmds) {
1197 ql_log(ql_log_warn, vha, 0x5031,
1198 "Invalid command index (%x).\n", index);
1199 if (IS_P3P_TYPE(ha))
1200 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1202 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1205 sp = req->outstanding_cmds[index];
1207 ql_log(ql_log_warn, vha, 0x5032,
1208 "Invalid completion handle (%x) -- timed-out.\n", index);
1211 if (sp->handle != index) {
1212 ql_log(ql_log_warn, vha, 0x5033,
1213 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
1217 req->outstanding_cmds[index] = NULL;
1224 qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1225 struct mbx_entry *mbx)
1227 const char func[] = "MBX-IOCB";
1231 struct srb_iocb *lio;
1235 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
1239 lio = &sp->u.iocb_cmd;
1241 fcport = sp->fcport;
1242 data = lio->u.logio.data;
1244 data[0] = MBS_COMMAND_ERROR;
1245 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
1246 QLA_LOGIO_LOGIN_RETRIED : 0;
1247 if (mbx->entry_status) {
1248 ql_dbg(ql_dbg_async, vha, 0x5043,
1249 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
1250 "entry-status=%x status=%x state-flag=%x "
1251 "status-flags=%x.\n", type, sp->handle,
1252 fcport->d_id.b.domain, fcport->d_id.b.area,
1253 fcport->d_id.b.al_pa, mbx->entry_status,
1254 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
1255 le16_to_cpu(mbx->status_flags));
1257 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
1258 (uint8_t *)mbx, sizeof(*mbx));
1263 status = le16_to_cpu(mbx->status);
1264 if (status == 0x30 && sp->type == SRB_LOGIN_CMD &&
1265 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
1267 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
1268 ql_dbg(ql_dbg_async, vha, 0x5045,
1269 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1270 type, sp->handle, fcport->d_id.b.domain,
1271 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1272 le16_to_cpu(mbx->mb1));
1274 data[0] = MBS_COMMAND_COMPLETE;
1275 if (sp->type == SRB_LOGIN_CMD) {
1276 fcport->port_type = FCT_TARGET;
1277 if (le16_to_cpu(mbx->mb1) & BIT_0)
1278 fcport->port_type = FCT_INITIATOR;
1279 else if (le16_to_cpu(mbx->mb1) & BIT_1)
1280 fcport->flags |= FCF_FCP2_DEVICE;
1285 data[0] = le16_to_cpu(mbx->mb0);
1287 case MBS_PORT_ID_USED:
1288 data[1] = le16_to_cpu(mbx->mb1);
1290 case MBS_LOOP_ID_USED:
1293 data[0] = MBS_COMMAND_ERROR;
1297 ql_log(ql_log_warn, vha, 0x5046,
1298 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1299 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
1300 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
1301 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
1302 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
1303 le16_to_cpu(mbx->mb7));
1306 sp->done(vha, sp, 0);
1310 qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1311 sts_entry_t *pkt, int iocb_type)
1313 const char func[] = "CT_IOCB";
1316 struct fc_bsg_job *bsg_job;
1317 uint16_t comp_status;
1320 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1324 bsg_job = sp->u.bsg_job;
1326 type = "ct pass-through";
1328 comp_status = le16_to_cpu(pkt->comp_status);
1330 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1331 * fc payload to the caller
1333 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1334 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1336 if (comp_status != CS_COMPLETE) {
1337 if (comp_status == CS_DATA_UNDERRUN) {
1339 bsg_job->reply->reply_payload_rcv_len =
1340 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
1342 ql_log(ql_log_warn, vha, 0x5048,
1343 "CT pass-through-%s error "
1344 "comp_status-status=0x%x total_byte = 0x%x.\n",
1346 bsg_job->reply->reply_payload_rcv_len);
1348 ql_log(ql_log_warn, vha, 0x5049,
1349 "CT pass-through-%s error "
1350 "comp_status-status=0x%x.\n", type, comp_status);
1351 res = DID_ERROR << 16;
1352 bsg_job->reply->reply_payload_rcv_len = 0;
1354 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
1355 (uint8_t *)pkt, sizeof(*pkt));
1358 bsg_job->reply->reply_payload_rcv_len =
1359 bsg_job->reply_payload.payload_len;
1360 bsg_job->reply_len = 0;
1363 sp->done(vha, sp, res);
1367 qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1368 struct sts_entry_24xx *pkt, int iocb_type)
1370 const char func[] = "ELS_CT_IOCB";
1373 struct fc_bsg_job *bsg_job;
1374 uint16_t comp_status;
1375 uint32_t fw_status[3];
1376 uint8_t* fw_sts_ptr;
1379 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1382 bsg_job = sp->u.bsg_job;
1386 case SRB_ELS_CMD_RPT:
1387 case SRB_ELS_CMD_HST:
1391 type = "ct pass-through";
1394 ql_dbg(ql_dbg_user, vha, 0x503e,
1395 "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type);
1399 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1400 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1401 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1403 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1404 * fc payload to the caller
1406 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1407 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1409 if (comp_status != CS_COMPLETE) {
1410 if (comp_status == CS_DATA_UNDERRUN) {
1412 bsg_job->reply->reply_payload_rcv_len =
1413 le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count);
1415 ql_dbg(ql_dbg_user, vha, 0x503f,
1416 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
1417 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
1418 type, sp->handle, comp_status, fw_status[1], fw_status[2],
1419 le16_to_cpu(((struct els_sts_entry_24xx *)
1420 pkt)->total_byte_count));
1421 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1422 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1425 ql_dbg(ql_dbg_user, vha, 0x5040,
1426 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
1427 "error subcode 1=0x%x error subcode 2=0x%x.\n",
1428 type, sp->handle, comp_status,
1429 le16_to_cpu(((struct els_sts_entry_24xx *)
1430 pkt)->error_subcode_1),
1431 le16_to_cpu(((struct els_sts_entry_24xx *)
1432 pkt)->error_subcode_2));
1433 res = DID_ERROR << 16;
1434 bsg_job->reply->reply_payload_rcv_len = 0;
1435 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1436 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1438 ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056,
1439 (uint8_t *)pkt, sizeof(*pkt));
1443 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1444 bsg_job->reply_len = 0;
1447 sp->done(vha, sp, res);
1451 qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1452 struct logio_entry_24xx *logio)
1454 const char func[] = "LOGIO-IOCB";
1458 struct srb_iocb *lio;
1462 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1466 lio = &sp->u.iocb_cmd;
1468 fcport = sp->fcport;
1469 data = lio->u.logio.data;
1471 data[0] = MBS_COMMAND_ERROR;
1472 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
1473 QLA_LOGIO_LOGIN_RETRIED : 0;
1474 if (logio->entry_status) {
1475 ql_log(ql_log_warn, fcport->vha, 0x5034,
1476 "Async-%s error entry - hdl=%x"
1477 "portid=%02x%02x%02x entry-status=%x.\n",
1478 type, sp->handle, fcport->d_id.b.domain,
1479 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1480 logio->entry_status);
1481 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
1482 (uint8_t *)logio, sizeof(*logio));
1487 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
1488 ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
1489 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1490 "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1491 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1492 le32_to_cpu(logio->io_parameter[0]));
1494 data[0] = MBS_COMMAND_COMPLETE;
1495 if (sp->type != SRB_LOGIN_CMD)
1498 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1499 if (iop[0] & BIT_4) {
1500 fcport->port_type = FCT_TARGET;
1502 fcport->flags |= FCF_FCP2_DEVICE;
1503 } else if (iop[0] & BIT_5)
1504 fcport->port_type = FCT_INITIATOR;
1507 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1509 if (logio->io_parameter[7] || logio->io_parameter[8])
1510 fcport->supported_classes |= FC_COS_CLASS2;
1511 if (logio->io_parameter[9] || logio->io_parameter[10])
1512 fcport->supported_classes |= FC_COS_CLASS3;
1517 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1518 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1520 case LSC_SCODE_PORTID_USED:
1521 data[0] = MBS_PORT_ID_USED;
1522 data[1] = LSW(iop[1]);
1524 case LSC_SCODE_NPORT_USED:
1525 data[0] = MBS_LOOP_ID_USED;
1528 data[0] = MBS_COMMAND_ERROR;
1532 ql_dbg(ql_dbg_async, fcport->vha, 0x5037,
1533 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1534 "iop0=%x iop1=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1535 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1536 le16_to_cpu(logio->comp_status),
1537 le32_to_cpu(logio->io_parameter[0]),
1538 le32_to_cpu(logio->io_parameter[1]));
1541 sp->done(vha, sp, 0);
1545 qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, void *tsk)
1547 const char func[] = "TMF-IOCB";
1551 struct srb_iocb *iocb;
1552 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1554 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1558 iocb = &sp->u.iocb_cmd;
1560 fcport = sp->fcport;
1561 iocb->u.tmf.data = QLA_SUCCESS;
1563 if (sts->entry_status) {
1564 ql_log(ql_log_warn, fcport->vha, 0x5038,
1565 "Async-%s error - hdl=%x entry-status(%x).\n",
1566 type, sp->handle, sts->entry_status);
1567 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1568 } else if (sts->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1569 ql_log(ql_log_warn, fcport->vha, 0x5039,
1570 "Async-%s error - hdl=%x completion status(%x).\n",
1571 type, sp->handle, sts->comp_status);
1572 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1573 } else if ((le16_to_cpu(sts->scsi_status) &
1574 SS_RESPONSE_INFO_LEN_VALID)) {
1575 if (le32_to_cpu(sts->rsp_data_len) < 4) {
1576 ql_log(ql_log_warn, fcport->vha, 0x503b,
1577 "Async-%s error - hdl=%x not enough response(%d).\n",
1578 type, sp->handle, sts->rsp_data_len);
1579 } else if (sts->data[3]) {
1580 ql_log(ql_log_warn, fcport->vha, 0x503c,
1581 "Async-%s error - hdl=%x response(%x).\n",
1582 type, sp->handle, sts->data[3]);
1583 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1587 if (iocb->u.tmf.data != QLA_SUCCESS)
1588 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1589 (uint8_t *)sts, sizeof(*sts));
1591 sp->done(vha, sp, 0);
1595 * qla2x00_process_response_queue() - Process response queue entries.
1596 * @ha: SCSI driver HA context
1599 qla2x00_process_response_queue(struct rsp_que *rsp)
1601 struct scsi_qla_host *vha;
1602 struct qla_hw_data *ha = rsp->hw;
1603 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1605 uint16_t handle_cnt;
1608 vha = pci_get_drvdata(ha->pdev);
1610 if (!vha->flags.online)
1613 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1614 pkt = (sts_entry_t *)rsp->ring_ptr;
1617 if (rsp->ring_index == rsp->length) {
1618 rsp->ring_index = 0;
1619 rsp->ring_ptr = rsp->ring;
1624 if (pkt->entry_status != 0) {
1625 qla2x00_error_entry(vha, rsp, pkt);
1626 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1631 switch (pkt->entry_type) {
1633 qla2x00_status_entry(vha, rsp, pkt);
1635 case STATUS_TYPE_21:
1636 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1637 for (cnt = 0; cnt < handle_cnt; cnt++) {
1638 qla2x00_process_completed_request(vha, rsp->req,
1639 ((sts21_entry_t *)pkt)->handle[cnt]);
1642 case STATUS_TYPE_22:
1643 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1644 for (cnt = 0; cnt < handle_cnt; cnt++) {
1645 qla2x00_process_completed_request(vha, rsp->req,
1646 ((sts22_entry_t *)pkt)->handle[cnt]);
1649 case STATUS_CONT_TYPE:
1650 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
1653 qla2x00_mbx_iocb_entry(vha, rsp->req,
1654 (struct mbx_entry *)pkt);
1657 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1660 /* Type Not Supported. */
1661 ql_log(ql_log_warn, vha, 0x504a,
1662 "Received unknown response pkt type %x "
1663 "entry status=%x.\n",
1664 pkt->entry_type, pkt->entry_status);
1667 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1671 /* Adjust ring index */
1672 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
1676 qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
1677 uint32_t sense_len, struct rsp_que *rsp, int res)
1679 struct scsi_qla_host *vha = sp->fcport->vha;
1680 struct scsi_cmnd *cp = GET_CMD_SP(sp);
1681 uint32_t track_sense_len;
1683 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1684 sense_len = SCSI_SENSE_BUFFERSIZE;
1686 SET_CMD_SENSE_LEN(sp, sense_len);
1687 SET_CMD_SENSE_PTR(sp, cp->sense_buffer);
1688 track_sense_len = sense_len;
1690 if (sense_len > par_sense_len)
1691 sense_len = par_sense_len;
1693 memcpy(cp->sense_buffer, sense_data, sense_len);
1695 SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len);
1696 track_sense_len -= sense_len;
1697 SET_CMD_SENSE_LEN(sp, track_sense_len);
1699 if (track_sense_len != 0) {
1700 rsp->status_srb = sp;
1705 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
1706 "Check condition Sense data, nexus%ld:%d:%llu cmd=%p.\n",
1707 sp->fcport->vha->host_no, cp->device->id, cp->device->lun,
1709 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
1710 cp->sense_buffer, sense_len);
1714 struct scsi_dif_tuple {
1715 __be16 guard; /* Checksum */
1716 __be16 app_tag; /* APPL identifier */
1717 __be32 ref_tag; /* Target LBA or indirect LBA */
1721 * Checks the guard or meta-data for the type of error
1722 * detected by the HBA. In case of errors, we set the
1723 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1724 * to indicate to the kernel that the HBA detected error.
1727 qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
1729 struct scsi_qla_host *vha = sp->fcport->vha;
1730 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
1731 uint8_t *ap = &sts24->data[12];
1732 uint8_t *ep = &sts24->data[20];
1733 uint32_t e_ref_tag, a_ref_tag;
1734 uint16_t e_app_tag, a_app_tag;
1735 uint16_t e_guard, a_guard;
1738 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1739 * would make guard field appear at offset 2
1741 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
1742 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
1743 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
1744 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
1745 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
1746 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
1748 ql_dbg(ql_dbg_io, vha, 0x3023,
1749 "iocb(s) %p Returned STATUS.\n", sts24);
1751 ql_dbg(ql_dbg_io, vha, 0x3024,
1752 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
1753 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
1754 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
1755 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
1756 a_app_tag, e_app_tag, a_guard, e_guard);
1760 * For type 3: ref & app tag is all 'f's
1761 * For type 0,1,2: app tag is all 'f's
1763 if ((a_app_tag == 0xffff) &&
1764 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
1765 (a_ref_tag == 0xffffffff))) {
1766 uint32_t blocks_done, resid;
1767 sector_t lba_s = scsi_get_lba(cmd);
1769 /* 2TB boundary case covered automatically with this */
1770 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
1772 resid = scsi_bufflen(cmd) - (blocks_done *
1773 cmd->device->sector_size);
1775 scsi_set_resid(cmd, resid);
1776 cmd->result = DID_OK << 16;
1778 /* Update protection tag */
1779 if (scsi_prot_sg_count(cmd)) {
1780 uint32_t i, j = 0, k = 0, num_ent;
1781 struct scatterlist *sg;
1782 struct sd_dif_tuple *spt;
1784 /* Patch the corresponding protection tags */
1785 scsi_for_each_prot_sg(cmd, sg,
1786 scsi_prot_sg_count(cmd), i) {
1787 num_ent = sg_dma_len(sg) / 8;
1788 if (k + num_ent < blocks_done) {
1792 j = blocks_done - k - 1;
1797 if (k != blocks_done) {
1798 ql_log(ql_log_warn, vha, 0x302f,
1799 "unexpected tag values tag:lba=%x:%llx)\n",
1800 e_ref_tag, (unsigned long long)lba_s);
1804 spt = page_address(sg_page(sg)) + sg->offset;
1807 spt->app_tag = 0xffff;
1808 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
1809 spt->ref_tag = 0xffffffff;
1816 if (e_guard != a_guard) {
1817 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1819 set_driver_byte(cmd, DRIVER_SENSE);
1820 set_host_byte(cmd, DID_ABORT);
1821 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1826 if (e_ref_tag != a_ref_tag) {
1827 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1829 set_driver_byte(cmd, DRIVER_SENSE);
1830 set_host_byte(cmd, DID_ABORT);
1831 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1835 /* check appl tag */
1836 if (e_app_tag != a_app_tag) {
1837 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1839 set_driver_byte(cmd, DRIVER_SENSE);
1840 set_host_byte(cmd, DID_ABORT);
1841 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1849 qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, void *pkt,
1850 struct req_que *req, uint32_t index)
1852 struct qla_hw_data *ha = vha->hw;
1854 uint16_t comp_status;
1855 uint16_t scsi_status;
1857 uint32_t rval = EXT_STATUS_OK;
1858 struct fc_bsg_job *bsg_job = NULL;
1860 struct sts_entry_24xx *sts24;
1861 sts = (sts_entry_t *) pkt;
1862 sts24 = (struct sts_entry_24xx *) pkt;
1864 /* Validate handle. */
1865 if (index >= req->num_outstanding_cmds) {
1866 ql_log(ql_log_warn, vha, 0x70af,
1867 "Invalid SCSI completion handle 0x%x.\n", index);
1868 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1872 sp = req->outstanding_cmds[index];
1874 /* Free outstanding command slot. */
1875 req->outstanding_cmds[index] = NULL;
1876 bsg_job = sp->u.bsg_job;
1878 ql_log(ql_log_warn, vha, 0x70b0,
1879 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
1882 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1886 if (IS_FWI2_CAPABLE(ha)) {
1887 comp_status = le16_to_cpu(sts24->comp_status);
1888 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1890 comp_status = le16_to_cpu(sts->comp_status);
1891 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1894 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1895 switch (comp_status) {
1897 if (scsi_status == 0) {
1898 bsg_job->reply->reply_payload_rcv_len =
1899 bsg_job->reply_payload.payload_len;
1900 vha->qla_stats.input_bytes +=
1901 bsg_job->reply->reply_payload_rcv_len;
1902 vha->qla_stats.input_requests++;
1903 rval = EXT_STATUS_OK;
1907 case CS_DATA_OVERRUN:
1908 ql_dbg(ql_dbg_user, vha, 0x70b1,
1909 "Command completed with date overrun thread_id=%d\n",
1911 rval = EXT_STATUS_DATA_OVERRUN;
1914 case CS_DATA_UNDERRUN:
1915 ql_dbg(ql_dbg_user, vha, 0x70b2,
1916 "Command completed with date underrun thread_id=%d\n",
1918 rval = EXT_STATUS_DATA_UNDERRUN;
1920 case CS_BIDIR_RD_OVERRUN:
1921 ql_dbg(ql_dbg_user, vha, 0x70b3,
1922 "Command completed with read data overrun thread_id=%d\n",
1924 rval = EXT_STATUS_DATA_OVERRUN;
1927 case CS_BIDIR_RD_WR_OVERRUN:
1928 ql_dbg(ql_dbg_user, vha, 0x70b4,
1929 "Command completed with read and write data overrun "
1930 "thread_id=%d\n", thread_id);
1931 rval = EXT_STATUS_DATA_OVERRUN;
1934 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN:
1935 ql_dbg(ql_dbg_user, vha, 0x70b5,
1936 "Command completed with read data over and write data "
1937 "underrun thread_id=%d\n", thread_id);
1938 rval = EXT_STATUS_DATA_OVERRUN;
1941 case CS_BIDIR_RD_UNDERRUN:
1942 ql_dbg(ql_dbg_user, vha, 0x70b6,
1943 "Command completed with read data data underrun "
1944 "thread_id=%d\n", thread_id);
1945 rval = EXT_STATUS_DATA_UNDERRUN;
1948 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN:
1949 ql_dbg(ql_dbg_user, vha, 0x70b7,
1950 "Command completed with read data under and write data "
1951 "overrun thread_id=%d\n", thread_id);
1952 rval = EXT_STATUS_DATA_UNDERRUN;
1955 case CS_BIDIR_RD_WR_UNDERRUN:
1956 ql_dbg(ql_dbg_user, vha, 0x70b8,
1957 "Command completed with read and write data underrun "
1958 "thread_id=%d\n", thread_id);
1959 rval = EXT_STATUS_DATA_UNDERRUN;
1963 ql_dbg(ql_dbg_user, vha, 0x70b9,
1964 "Command completed with data DMA error thread_id=%d\n",
1966 rval = EXT_STATUS_DMA_ERR;
1970 ql_dbg(ql_dbg_user, vha, 0x70ba,
1971 "Command completed with timeout thread_id=%d\n",
1973 rval = EXT_STATUS_TIMEOUT;
1976 ql_dbg(ql_dbg_user, vha, 0x70bb,
1977 "Command completed with completion status=0x%x "
1978 "thread_id=%d\n", comp_status, thread_id);
1979 rval = EXT_STATUS_ERR;
1982 bsg_job->reply->reply_payload_rcv_len = 0;
1985 /* Return the vendor specific reply to API */
1986 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1987 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1988 /* Always return DID_OK, bsg will send the vendor specific response
1989 * in this case only */
1990 sp->done(vha, sp, (DID_OK << 6));
1995 * qla2x00_status_entry() - Process a Status IOCB entry.
1996 * @ha: SCSI driver HA context
1997 * @pkt: Entry pointer
2000 qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
2004 struct scsi_cmnd *cp;
2006 struct sts_entry_24xx *sts24;
2007 uint16_t comp_status;
2008 uint16_t scsi_status;
2010 uint8_t lscsi_status;
2012 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
2014 uint8_t *rsp_info, *sense_data;
2015 struct qla_hw_data *ha = vha->hw;
2018 struct req_que *req;
2021 uint16_t state_flags = 0;
2022 uint16_t retry_delay = 0;
2024 sts = (sts_entry_t *) pkt;
2025 sts24 = (struct sts_entry_24xx *) pkt;
2026 if (IS_FWI2_CAPABLE(ha)) {
2027 comp_status = le16_to_cpu(sts24->comp_status);
2028 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
2029 state_flags = le16_to_cpu(sts24->state_flags);
2031 comp_status = le16_to_cpu(sts->comp_status);
2032 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
2034 handle = (uint32_t) LSW(sts->handle);
2035 que = MSW(sts->handle);
2036 req = ha->req_q_map[que];
2038 /* Check for invalid queue pointer */
2040 que >= find_first_zero_bit(ha->req_qid_map, ha->max_req_queues)) {
2041 ql_dbg(ql_dbg_io, vha, 0x3059,
2042 "Invalid status handle (0x%x): Bad req pointer. req=%p, "
2043 "que=%u.\n", sts->handle, req, que);
2047 /* Validate handle. */
2048 if (handle < req->num_outstanding_cmds)
2049 sp = req->outstanding_cmds[handle];
2054 ql_dbg(ql_dbg_io, vha, 0x3017,
2055 "Invalid status handle (0x%x).\n", sts->handle);
2057 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
2058 if (IS_P3P_TYPE(ha))
2059 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2061 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2062 qla2xxx_wake_dpc(vha);
2067 if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) {
2068 qla25xx_process_bidir_status_iocb(vha, pkt, req, handle);
2072 /* Task Management completion. */
2073 if (sp->type == SRB_TM_CMD) {
2074 qla24xx_tm_iocb_entry(vha, req, pkt);
2078 /* Fast path completion. */
2079 if (comp_status == CS_COMPLETE && scsi_status == 0) {
2080 qla2x00_process_completed_request(vha, req, handle);
2085 req->outstanding_cmds[handle] = NULL;
2086 cp = GET_CMD_SP(sp);
2088 ql_dbg(ql_dbg_io, vha, 0x3018,
2089 "Command already returned (0x%x/%p).\n",
2095 lscsi_status = scsi_status & STATUS_MASK;
2097 fcport = sp->fcport;
2100 sense_len = par_sense_len = rsp_info_len = resid_len =
2102 if (IS_FWI2_CAPABLE(ha)) {
2103 if (scsi_status & SS_SENSE_LEN_VALID)
2104 sense_len = le32_to_cpu(sts24->sense_len);
2105 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2106 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
2107 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
2108 resid_len = le32_to_cpu(sts24->rsp_residual_count);
2109 if (comp_status == CS_DATA_UNDERRUN)
2110 fw_resid_len = le32_to_cpu(sts24->residual_len);
2111 rsp_info = sts24->data;
2112 sense_data = sts24->data;
2113 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
2114 ox_id = le16_to_cpu(sts24->ox_id);
2115 par_sense_len = sizeof(sts24->data);
2116 /* Valid values of the retry delay timer are 0x1-0xffef */
2117 if (sts24->retry_delay > 0 && sts24->retry_delay < 0xfff1)
2118 retry_delay = sts24->retry_delay;
2120 if (scsi_status & SS_SENSE_LEN_VALID)
2121 sense_len = le16_to_cpu(sts->req_sense_length);
2122 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2123 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
2124 resid_len = le32_to_cpu(sts->residual_length);
2125 rsp_info = sts->rsp_info;
2126 sense_data = sts->req_sense_data;
2127 par_sense_len = sizeof(sts->req_sense_data);
2130 /* Check for any FCP transport errors. */
2131 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
2132 /* Sense data lies beyond any FCP RESPONSE data. */
2133 if (IS_FWI2_CAPABLE(ha)) {
2134 sense_data += rsp_info_len;
2135 par_sense_len -= rsp_info_len;
2137 if (rsp_info_len > 3 && rsp_info[3]) {
2138 ql_dbg(ql_dbg_io, fcport->vha, 0x3019,
2139 "FCP I/O protocol failure (0x%x/0x%x).\n",
2140 rsp_info_len, rsp_info[3]);
2142 res = DID_BUS_BUSY << 16;
2147 /* Check for overrun. */
2148 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
2149 scsi_status & SS_RESIDUAL_OVER)
2150 comp_status = CS_DATA_OVERRUN;
2153 * Check retry_delay_timer value if we receive a busy or
2156 if (lscsi_status == SAM_STAT_TASK_SET_FULL ||
2157 lscsi_status == SAM_STAT_BUSY)
2158 qla2x00_set_retry_delay_timestamp(fcport, retry_delay);
2161 * Based on Host and scsi status generate status code for Linux
2163 switch (comp_status) {
2166 if (scsi_status == 0) {
2170 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
2172 scsi_set_resid(cp, resid);
2174 if (!lscsi_status &&
2175 ((unsigned)(scsi_bufflen(cp) - resid) <
2177 ql_dbg(ql_dbg_io, fcport->vha, 0x301a,
2178 "Mid-layer underflow "
2179 "detected (0x%x of 0x%x bytes).\n",
2180 resid, scsi_bufflen(cp));
2182 res = DID_ERROR << 16;
2186 res = DID_OK << 16 | lscsi_status;
2188 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
2189 ql_dbg(ql_dbg_io, fcport->vha, 0x301b,
2190 "QUEUE FULL detected.\n");
2194 if (lscsi_status != SS_CHECK_CONDITION)
2197 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
2198 if (!(scsi_status & SS_SENSE_LEN_VALID))
2201 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
2205 case CS_DATA_UNDERRUN:
2206 /* Use F/W calculated residual length. */
2207 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
2208 scsi_set_resid(cp, resid);
2209 if (scsi_status & SS_RESIDUAL_UNDER) {
2210 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
2211 ql_dbg(ql_dbg_io, fcport->vha, 0x301d,
2212 "Dropped frame(s) detected "
2213 "(0x%x of 0x%x bytes).\n",
2214 resid, scsi_bufflen(cp));
2216 res = DID_ERROR << 16 | lscsi_status;
2217 goto check_scsi_status;
2220 if (!lscsi_status &&
2221 ((unsigned)(scsi_bufflen(cp) - resid) <
2223 ql_dbg(ql_dbg_io, fcport->vha, 0x301e,
2224 "Mid-layer underflow "
2225 "detected (0x%x of 0x%x bytes).\n",
2226 resid, scsi_bufflen(cp));
2228 res = DID_ERROR << 16;
2231 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
2232 lscsi_status != SAM_STAT_BUSY) {
2234 * scsi status of task set and busy are considered to be
2235 * task not completed.
2238 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
2239 "Dropped frame(s) detected (0x%x "
2240 "of 0x%x bytes).\n", resid,
2243 res = DID_ERROR << 16 | lscsi_status;
2244 goto check_scsi_status;
2246 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
2247 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2248 scsi_status, lscsi_status);
2251 res = DID_OK << 16 | lscsi_status;
2256 * Check to see if SCSI Status is non zero. If so report SCSI
2259 if (lscsi_status != 0) {
2260 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
2261 ql_dbg(ql_dbg_io, fcport->vha, 0x3020,
2262 "QUEUE FULL detected.\n");
2266 if (lscsi_status != SS_CHECK_CONDITION)
2269 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
2270 if (!(scsi_status & SS_SENSE_LEN_VALID))
2273 qla2x00_handle_sense(sp, sense_data, par_sense_len,
2274 sense_len, rsp, res);
2278 case CS_PORT_LOGGED_OUT:
2279 case CS_PORT_CONFIG_CHG:
2282 case CS_PORT_UNAVAILABLE:
2287 * We are going to have the fc class block the rport
2288 * while we try to recover so instruct the mid layer
2289 * to requeue until the class decides how to handle this.
2291 res = DID_TRANSPORT_DISRUPTED << 16;
2293 if (comp_status == CS_TIMEOUT) {
2294 if (IS_FWI2_CAPABLE(ha))
2296 else if ((le16_to_cpu(sts->status_flags) &
2297 SF_LOGOUT_SENT) == 0)
2301 ql_dbg(ql_dbg_io, fcport->vha, 0x3021,
2302 "Port to be marked lost on fcport=%02x%02x%02x, current "
2303 "port state= %s.\n", fcport->d_id.b.domain,
2304 fcport->d_id.b.area, fcport->d_id.b.al_pa,
2305 port_state_str[atomic_read(&fcport->state)]);
2307 if (atomic_read(&fcport->state) == FCS_ONLINE)
2308 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
2312 res = DID_RESET << 16;
2316 logit = qla2x00_handle_dif_error(sp, sts24);
2321 res = DID_ERROR << 16;
2323 if (!IS_PI_SPLIT_DET_CAPABLE(ha))
2326 if (state_flags & BIT_4)
2327 scmd_printk(KERN_WARNING, cp,
2328 "Unsupported device '%s' found.\n",
2329 cp->device->vendor);
2333 res = DID_ERROR << 16;
2339 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
2340 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%llu "
2341 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
2342 "rsp_info=0x%x resid=0x%x fw_resid=0x%x.\n",
2343 comp_status, scsi_status, res, vha->host_no,
2344 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
2345 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
2346 cp->cmnd, scsi_bufflen(cp), rsp_info_len,
2347 resid_len, fw_resid_len);
2349 if (rsp->status_srb == NULL)
2350 sp->done(ha, sp, res);
2354 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2355 * @ha: SCSI driver HA context
2356 * @pkt: Entry pointer
2358 * Extended sense data.
2361 qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
2363 uint8_t sense_sz = 0;
2364 struct qla_hw_data *ha = rsp->hw;
2365 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
2366 srb_t *sp = rsp->status_srb;
2367 struct scsi_cmnd *cp;
2371 if (!sp || !GET_CMD_SENSE_LEN(sp))
2374 sense_len = GET_CMD_SENSE_LEN(sp);
2375 sense_ptr = GET_CMD_SENSE_PTR(sp);
2377 cp = GET_CMD_SP(sp);
2379 ql_log(ql_log_warn, vha, 0x3025,
2380 "cmd is NULL: already returned to OS (sp=%p).\n", sp);
2382 rsp->status_srb = NULL;
2386 if (sense_len > sizeof(pkt->data))
2387 sense_sz = sizeof(pkt->data);
2389 sense_sz = sense_len;
2391 /* Move sense data. */
2392 if (IS_FWI2_CAPABLE(ha))
2393 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
2394 memcpy(sense_ptr, pkt->data, sense_sz);
2395 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
2396 sense_ptr, sense_sz);
2398 sense_len -= sense_sz;
2399 sense_ptr += sense_sz;
2401 SET_CMD_SENSE_PTR(sp, sense_ptr);
2402 SET_CMD_SENSE_LEN(sp, sense_len);
2404 /* Place command on done queue. */
2405 if (sense_len == 0) {
2406 rsp->status_srb = NULL;
2407 sp->done(ha, sp, cp->result);
2412 * qla2x00_error_entry() - Process an error entry.
2413 * @ha: SCSI driver HA context
2414 * @pkt: Entry pointer
2417 qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
2420 struct qla_hw_data *ha = vha->hw;
2421 const char func[] = "ERROR-IOCB";
2422 uint16_t que = MSW(pkt->handle);
2423 struct req_que *req = NULL;
2424 int res = DID_ERROR << 16;
2426 ql_dbg(ql_dbg_async, vha, 0x502a,
2427 "type of error status in response: 0x%x\n", pkt->entry_status);
2429 if (que >= ha->max_req_queues || !ha->req_q_map[que])
2432 req = ha->req_q_map[que];
2434 if (pkt->entry_status & RF_BUSY)
2435 res = DID_BUS_BUSY << 16;
2437 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2439 sp->done(ha, sp, res);
2443 ql_log(ql_log_warn, vha, 0x5030,
2444 "Error entry - invalid handle/queue.\n");
2446 if (IS_P3P_TYPE(ha))
2447 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2449 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2450 qla2xxx_wake_dpc(vha);
2454 * qla24xx_mbx_completion() - Process mailbox command completions.
2455 * @ha: SCSI driver HA context
2456 * @mb0: Mailbox0 register
2459 qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
2463 uint16_t __iomem *wptr;
2464 struct qla_hw_data *ha = vha->hw;
2465 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2467 /* Read all mbox registers? */
2468 mboxes = (1 << ha->mbx_count) - 1;
2470 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n");
2472 mboxes = ha->mcp->in_mb;
2474 /* Load return mailbox registers. */
2475 ha->flags.mbox_int = 1;
2476 ha->mailbox_out[0] = mb0;
2478 wptr = (uint16_t __iomem *)®->mailbox1;
2480 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
2482 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2490 qla24xx_abort_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
2491 struct abort_entry_24xx *pkt)
2493 const char func[] = "ABT_IOCB";
2495 struct srb_iocb *abt;
2497 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2501 abt = &sp->u.iocb_cmd;
2502 abt->u.abt.comp_status = le32_to_cpu(pkt->nport_handle);
2503 sp->done(vha, sp, 0);
2507 * qla24xx_process_response_queue() - Process response queue entries.
2508 * @ha: SCSI driver HA context
2510 void qla24xx_process_response_queue(struct scsi_qla_host *vha,
2511 struct rsp_que *rsp)
2513 struct sts_entry_24xx *pkt;
2514 struct qla_hw_data *ha = vha->hw;
2516 if (!vha->flags.online)
2519 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2520 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
2523 if (rsp->ring_index == rsp->length) {
2524 rsp->ring_index = 0;
2525 rsp->ring_ptr = rsp->ring;
2530 if (pkt->entry_status != 0) {
2531 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
2533 if (qlt_24xx_process_response_error(vha, pkt))
2536 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2542 switch (pkt->entry_type) {
2544 qla2x00_status_entry(vha, rsp, pkt);
2546 case STATUS_CONT_TYPE:
2547 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
2549 case VP_RPT_ID_IOCB_TYPE:
2550 qla24xx_report_id_acquisition(vha,
2551 (struct vp_rpt_id_entry_24xx *)pkt);
2553 case LOGINOUT_PORT_IOCB_TYPE:
2554 qla24xx_logio_entry(vha, rsp->req,
2555 (struct logio_entry_24xx *)pkt);
2558 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
2561 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2563 case ABTS_RECV_24XX:
2564 /* ensure that the ATIO queue is empty */
2565 qlt_24xx_process_atio_queue(vha);
2566 case ABTS_RESP_24XX:
2568 case NOTIFY_ACK_TYPE:
2570 qlt_response_pkt_all_vps(vha, (response_t *)pkt);
2573 /* Do nothing in this case, this check is to prevent it
2574 * from falling into default case
2577 case ABORT_IOCB_TYPE:
2578 qla24xx_abort_iocb_entry(vha, rsp->req,
2579 (struct abort_entry_24xx *)pkt);
2582 /* Type Not Supported. */
2583 ql_dbg(ql_dbg_async, vha, 0x5042,
2584 "Received unknown response pkt type %x "
2585 "entry status=%x.\n",
2586 pkt->entry_type, pkt->entry_status);
2589 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2593 /* Adjust ring index */
2594 if (IS_P3P_TYPE(ha)) {
2595 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2596 WRT_REG_DWORD(®->rsp_q_out[0], rsp->ring_index);
2598 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
2602 qla2xxx_check_risc_status(scsi_qla_host_t *vha)
2606 struct qla_hw_data *ha = vha->hw;
2607 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2609 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2614 WRT_REG_DWORD(®->iobase_addr, 0x7C00);
2615 RD_REG_DWORD(®->iobase_addr);
2616 WRT_REG_DWORD(®->iobase_window, 0x0001);
2617 for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
2618 rval == QLA_SUCCESS; cnt--) {
2620 WRT_REG_DWORD(®->iobase_window, 0x0001);
2623 rval = QLA_FUNCTION_TIMEOUT;
2625 if (rval == QLA_SUCCESS)
2629 WRT_REG_DWORD(®->iobase_window, 0x0003);
2630 for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
2631 rval == QLA_SUCCESS; cnt--) {
2633 WRT_REG_DWORD(®->iobase_window, 0x0003);
2636 rval = QLA_FUNCTION_TIMEOUT;
2638 if (rval != QLA_SUCCESS)
2642 if (RD_REG_DWORD(®->iobase_c8) & BIT_3)
2643 ql_log(ql_log_info, vha, 0x504c,
2644 "Additional code -- 0x55AA.\n");
2647 WRT_REG_DWORD(®->iobase_window, 0x0000);
2648 RD_REG_DWORD(®->iobase_window);
2652 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
2654 * @dev_id: SCSI driver HA context
2656 * Called by system whenever the host adapter generates an interrupt.
2658 * Returns handled flag.
2661 qla24xx_intr_handler(int irq, void *dev_id)
2663 scsi_qla_host_t *vha;
2664 struct qla_hw_data *ha;
2665 struct device_reg_24xx __iomem *reg;
2671 struct rsp_que *rsp;
2672 unsigned long flags;
2674 rsp = (struct rsp_que *) dev_id;
2676 ql_log(ql_log_info, NULL, 0x5059,
2677 "%s: NULL response queue pointer.\n", __func__);
2682 reg = &ha->iobase->isp24;
2685 if (unlikely(pci_channel_offline(ha->pdev)))
2688 spin_lock_irqsave(&ha->hardware_lock, flags);
2689 vha = pci_get_drvdata(ha->pdev);
2690 for (iter = 50; iter--; ) {
2691 stat = RD_REG_DWORD(®->host_status);
2692 if (qla2x00_check_reg32_for_disconnect(vha, stat))
2694 if (stat & HSRX_RISC_PAUSED) {
2695 if (unlikely(pci_channel_offline(ha->pdev)))
2698 hccr = RD_REG_DWORD(®->hccr);
2700 ql_log(ql_log_warn, vha, 0x504b,
2701 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2704 qla2xxx_check_risc_status(vha);
2706 ha->isp_ops->fw_dump(vha, 1);
2707 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2709 } else if ((stat & HSRX_RISC_INT) == 0)
2712 switch (stat & 0xff) {
2713 case INTR_ROM_MB_SUCCESS:
2714 case INTR_ROM_MB_FAILED:
2715 case INTR_MB_SUCCESS:
2716 case INTR_MB_FAILED:
2717 qla24xx_mbx_completion(vha, MSW(stat));
2718 status |= MBX_INTERRUPT;
2721 case INTR_ASYNC_EVENT:
2723 mb[1] = RD_REG_WORD(®->mailbox1);
2724 mb[2] = RD_REG_WORD(®->mailbox2);
2725 mb[3] = RD_REG_WORD(®->mailbox3);
2726 qla2x00_async_event(vha, rsp, mb);
2728 case INTR_RSP_QUE_UPDATE:
2729 case INTR_RSP_QUE_UPDATE_83XX:
2730 qla24xx_process_response_queue(vha, rsp);
2732 case INTR_ATIO_QUE_UPDATE:
2733 qlt_24xx_process_atio_queue(vha);
2735 case INTR_ATIO_RSP_QUE_UPDATE:
2736 qlt_24xx_process_atio_queue(vha);
2737 qla24xx_process_response_queue(vha, rsp);
2740 ql_dbg(ql_dbg_async, vha, 0x504f,
2741 "Unrecognized interrupt type (%d).\n", stat * 0xff);
2744 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2745 RD_REG_DWORD_RELAXED(®->hccr);
2746 if (unlikely(IS_QLA83XX(ha) && (ha->pdev->revision == 1)))
2749 qla2x00_handle_mbx_completion(ha, status);
2750 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2756 qla24xx_msix_rsp_q(int irq, void *dev_id)
2758 struct qla_hw_data *ha;
2759 struct rsp_que *rsp;
2760 struct device_reg_24xx __iomem *reg;
2761 struct scsi_qla_host *vha;
2762 unsigned long flags;
2765 rsp = (struct rsp_que *) dev_id;
2767 ql_log(ql_log_info, NULL, 0x505a,
2768 "%s: NULL response queue pointer.\n", __func__);
2772 reg = &ha->iobase->isp24;
2774 spin_lock_irqsave(&ha->hardware_lock, flags);
2776 vha = pci_get_drvdata(ha->pdev);
2778 * Use host_status register to check to PCI disconnection before we
2779 * we process the response queue.
2781 stat = RD_REG_DWORD(®->host_status);
2782 if (qla2x00_check_reg32_for_disconnect(vha, stat))
2784 qla24xx_process_response_queue(vha, rsp);
2785 if (!ha->flags.disable_msix_handshake) {
2786 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2787 RD_REG_DWORD_RELAXED(®->hccr);
2790 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2796 qla25xx_msix_rsp_q(int irq, void *dev_id)
2798 struct qla_hw_data *ha;
2799 scsi_qla_host_t *vha;
2800 struct rsp_que *rsp;
2801 struct device_reg_24xx __iomem *reg;
2802 unsigned long flags;
2805 rsp = (struct rsp_que *) dev_id;
2807 ql_log(ql_log_info, NULL, 0x505b,
2808 "%s: NULL response queue pointer.\n", __func__);
2812 vha = pci_get_drvdata(ha->pdev);
2814 /* Clear the interrupt, if enabled, for this response queue */
2815 if (!ha->flags.disable_msix_handshake) {
2816 reg = &ha->iobase->isp24;
2817 spin_lock_irqsave(&ha->hardware_lock, flags);
2818 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2819 hccr = RD_REG_DWORD_RELAXED(®->hccr);
2820 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2822 if (qla2x00_check_reg32_for_disconnect(vha, hccr))
2824 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2831 qla24xx_msix_default(int irq, void *dev_id)
2833 scsi_qla_host_t *vha;
2834 struct qla_hw_data *ha;
2835 struct rsp_que *rsp;
2836 struct device_reg_24xx __iomem *reg;
2841 unsigned long flags;
2843 rsp = (struct rsp_que *) dev_id;
2845 ql_log(ql_log_info, NULL, 0x505c,
2846 "%s: NULL response queue pointer.\n", __func__);
2850 reg = &ha->iobase->isp24;
2853 spin_lock_irqsave(&ha->hardware_lock, flags);
2854 vha = pci_get_drvdata(ha->pdev);
2856 stat = RD_REG_DWORD(®->host_status);
2857 if (qla2x00_check_reg32_for_disconnect(vha, stat))
2859 if (stat & HSRX_RISC_PAUSED) {
2860 if (unlikely(pci_channel_offline(ha->pdev)))
2863 hccr = RD_REG_DWORD(®->hccr);
2865 ql_log(ql_log_info, vha, 0x5050,
2866 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2869 qla2xxx_check_risc_status(vha);
2871 ha->isp_ops->fw_dump(vha, 1);
2872 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2874 } else if ((stat & HSRX_RISC_INT) == 0)
2877 switch (stat & 0xff) {
2878 case INTR_ROM_MB_SUCCESS:
2879 case INTR_ROM_MB_FAILED:
2880 case INTR_MB_SUCCESS:
2881 case INTR_MB_FAILED:
2882 qla24xx_mbx_completion(vha, MSW(stat));
2883 status |= MBX_INTERRUPT;
2886 case INTR_ASYNC_EVENT:
2888 mb[1] = RD_REG_WORD(®->mailbox1);
2889 mb[2] = RD_REG_WORD(®->mailbox2);
2890 mb[3] = RD_REG_WORD(®->mailbox3);
2891 qla2x00_async_event(vha, rsp, mb);
2893 case INTR_RSP_QUE_UPDATE:
2894 case INTR_RSP_QUE_UPDATE_83XX:
2895 qla24xx_process_response_queue(vha, rsp);
2897 case INTR_ATIO_QUE_UPDATE:
2898 qlt_24xx_process_atio_queue(vha);
2900 case INTR_ATIO_RSP_QUE_UPDATE:
2901 qlt_24xx_process_atio_queue(vha);
2902 qla24xx_process_response_queue(vha, rsp);
2905 ql_dbg(ql_dbg_async, vha, 0x5051,
2906 "Unrecognized interrupt type (%d).\n", stat & 0xff);
2909 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2911 qla2x00_handle_mbx_completion(ha, status);
2912 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2917 /* Interrupt handling helpers. */
2919 struct qla_init_msix_entry {
2921 irq_handler_t handler;
2924 static struct qla_init_msix_entry msix_entries[3] = {
2925 { "qla2xxx (default)", qla24xx_msix_default },
2926 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
2927 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
2930 static struct qla_init_msix_entry qla82xx_msix_entries[2] = {
2931 { "qla2xxx (default)", qla82xx_msix_default },
2932 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
2935 static struct qla_init_msix_entry qla83xx_msix_entries[3] = {
2936 { "qla2xxx (default)", qla24xx_msix_default },
2937 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
2938 { "qla2xxx (atio_q)", qla83xx_msix_atio_q },
2942 qla24xx_disable_msix(struct qla_hw_data *ha)
2945 struct qla_msix_entry *qentry;
2946 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
2948 for (i = 0; i < ha->msix_count; i++) {
2949 qentry = &ha->msix_entries[i];
2950 if (qentry->have_irq)
2951 free_irq(qentry->vector, qentry->rsp);
2953 pci_disable_msix(ha->pdev);
2954 kfree(ha->msix_entries);
2955 ha->msix_entries = NULL;
2956 ha->flags.msix_enabled = 0;
2957 ql_dbg(ql_dbg_init, vha, 0x0042,
2958 "Disabled the MSI.\n");
2962 qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
2964 #define MIN_MSIX_COUNT 2
2965 #define ATIO_VECTOR 2
2967 struct msix_entry *entries;
2968 struct qla_msix_entry *qentry;
2969 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
2971 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
2974 ql_log(ql_log_warn, vha, 0x00bc,
2975 "Failed to allocate memory for msix_entry.\n");
2979 for (i = 0; i < ha->msix_count; i++)
2980 entries[i].entry = i;
2982 ret = pci_enable_msix_range(ha->pdev,
2983 entries, MIN_MSIX_COUNT, ha->msix_count);
2985 ql_log(ql_log_fatal, vha, 0x00c7,
2986 "MSI-X: Failed to enable support, "
2987 "giving up -- %d/%d.\n",
2988 ha->msix_count, ret);
2990 } else if (ret < ha->msix_count) {
2991 ql_log(ql_log_warn, vha, 0x00c6,
2992 "MSI-X: Failed to enable support "
2993 "-- %d/%d\n Retry with %d vectors.\n",
2994 ha->msix_count, ret, ret);
2996 ha->msix_count = ret;
2997 ha->max_rsp_queues = ha->msix_count - 1;
2998 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
2999 ha->msix_count, GFP_KERNEL);
3000 if (!ha->msix_entries) {
3001 ql_log(ql_log_fatal, vha, 0x00c8,
3002 "Failed to allocate memory for ha->msix_entries.\n");
3006 ha->flags.msix_enabled = 1;
3008 for (i = 0; i < ha->msix_count; i++) {
3009 qentry = &ha->msix_entries[i];
3010 qentry->vector = entries[i].vector;
3011 qentry->entry = entries[i].entry;
3012 qentry->have_irq = 0;
3016 /* Enable MSI-X vectors for the base queue */
3017 for (i = 0; i < 2; i++) {
3018 qentry = &ha->msix_entries[i];
3019 if (IS_P3P_TYPE(ha))
3020 ret = request_irq(qentry->vector,
3021 qla82xx_msix_entries[i].handler,
3022 0, qla82xx_msix_entries[i].name, rsp);
3024 ret = request_irq(qentry->vector,
3025 msix_entries[i].handler,
3026 0, msix_entries[i].name, rsp);
3028 goto msix_register_fail;
3029 qentry->have_irq = 1;
3035 * If target mode is enable, also request the vector for the ATIO
3038 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
3039 qentry = &ha->msix_entries[ATIO_VECTOR];
3040 ret = request_irq(qentry->vector,
3041 qla83xx_msix_entries[ATIO_VECTOR].handler,
3042 0, qla83xx_msix_entries[ATIO_VECTOR].name, rsp);
3043 qentry->have_irq = 1;
3050 ql_log(ql_log_fatal, vha, 0x00cb,
3051 "MSI-X: unable to register handler -- %x/%d.\n",
3052 qentry->vector, ret);
3053 qla24xx_disable_msix(ha);
3058 /* Enable MSI-X vector for response queue update for queue 0 */
3059 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3060 if (ha->msixbase && ha->mqiobase &&
3061 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
3065 && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
3067 ql_dbg(ql_dbg_multiq, vha, 0xc005,
3068 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3069 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
3070 ql_dbg(ql_dbg_init, vha, 0x0055,
3071 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3072 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
3080 qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
3082 int ret = QLA_FUNCTION_FAILED;
3083 device_reg_t *reg = ha->iobase;
3084 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
3086 /* If possible, enable MSI-X. */
3087 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
3088 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLAFX00(ha) &&
3092 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
3093 (ha->pdev->subsystem_device == 0x7040 ||
3094 ha->pdev->subsystem_device == 0x7041 ||
3095 ha->pdev->subsystem_device == 0x1705)) {
3096 ql_log(ql_log_warn, vha, 0x0034,
3097 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
3098 ha->pdev->subsystem_vendor,
3099 ha->pdev->subsystem_device);
3103 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
3104 ql_log(ql_log_warn, vha, 0x0035,
3105 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
3106 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
3110 ret = qla24xx_enable_msix(ha, rsp);
3112 ql_dbg(ql_dbg_init, vha, 0x0036,
3113 "MSI-X: Enabled (0x%X, 0x%X).\n",
3114 ha->chip_revision, ha->fw_attributes);
3115 goto clear_risc_ints;
3120 ql_log(ql_log_info, vha, 0x0037,
3121 "Falling back-to MSI mode -%d.\n", ret);
3123 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
3124 !IS_QLA8001(ha) && !IS_P3P_TYPE(ha) && !IS_QLAFX00(ha) &&
3128 ret = pci_enable_msi(ha->pdev);
3130 ql_dbg(ql_dbg_init, vha, 0x0038,
3132 ha->flags.msi_enabled = 1;
3134 ql_log(ql_log_warn, vha, 0x0039,
3135 "Falling back-to INTa mode -- %d.\n", ret);
3138 /* Skip INTx on ISP82xx. */
3139 if (!ha->flags.msi_enabled && IS_QLA82XX(ha))
3140 return QLA_FUNCTION_FAILED;
3142 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
3143 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
3144 QLA2XXX_DRIVER_NAME, rsp);
3146 ql_log(ql_log_warn, vha, 0x003a,
3147 "Failed to reserve interrupt %d already in use.\n",
3150 } else if (!ha->flags.msi_enabled) {
3151 ql_dbg(ql_dbg_init, vha, 0x0125,
3152 "INTa mode: Enabled.\n");
3153 ha->flags.mr_intr_valid = 1;
3157 if (IS_FWI2_CAPABLE(ha) || IS_QLAFX00(ha))
3160 spin_lock_irq(&ha->hardware_lock);
3161 WRT_REG_WORD(®->isp.semaphore, 0);
3162 spin_unlock_irq(&ha->hardware_lock);
3169 qla2x00_free_irqs(scsi_qla_host_t *vha)
3171 struct qla_hw_data *ha = vha->hw;
3172 struct rsp_que *rsp;
3175 * We need to check that ha->rsp_q_map is valid in case we are called
3176 * from a probe failure context.
3178 if (!ha->rsp_q_map || !ha->rsp_q_map[0])
3180 rsp = ha->rsp_q_map[0];
3182 if (ha->flags.msix_enabled)
3183 qla24xx_disable_msix(ha);
3184 else if (ha->flags.msi_enabled) {
3185 free_irq(ha->pdev->irq, rsp);
3186 pci_disable_msi(ha->pdev);
3188 free_irq(ha->pdev->irq, rsp);
3192 int qla25xx_request_irq(struct rsp_que *rsp)
3194 struct qla_hw_data *ha = rsp->hw;
3195 struct qla_init_msix_entry *intr = &msix_entries[2];
3196 struct qla_msix_entry *msix = rsp->msix;
3197 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
3200 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
3202 ql_log(ql_log_fatal, vha, 0x00e6,
3203 "MSI-X: Unable to register handler -- %x/%d.\n",