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 <linux/cpu.h>
13 #include <linux/t10-pi.h>
14 #include <scsi/scsi_tcq.h>
15 #include <scsi/scsi_bsg_fc.h>
16 #include <scsi/scsi_eh.h>
17 #include <scsi/fc/fc_fs.h>
18 #include <linux/nvme-fc-driver.h>
20 static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
21 static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
22 static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
23 static int qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
27 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
29 * @dev_id: SCSI driver HA context
31 * Called by system whenever the host adapter generates an interrupt.
33 * Returns handled flag.
36 qla2100_intr_handler(int irq, void *dev_id)
39 struct qla_hw_data *ha;
40 struct device_reg_2xxx __iomem *reg;
48 rsp = (struct rsp_que *) dev_id;
50 ql_log(ql_log_info, NULL, 0x505d,
51 "%s: NULL response queue pointer.\n", __func__);
56 reg = &ha->iobase->isp;
59 spin_lock_irqsave(&ha->hardware_lock, flags);
60 vha = pci_get_drvdata(ha->pdev);
61 for (iter = 50; iter--; ) {
62 hccr = RD_REG_WORD(®->hccr);
63 if (qla2x00_check_reg16_for_disconnect(vha, hccr))
65 if (hccr & HCCR_RISC_PAUSE) {
66 if (pci_channel_offline(ha->pdev))
70 * Issue a "HARD" reset in order for the RISC interrupt
71 * bit to be cleared. Schedule a big hammer to get
72 * out of the RISC PAUSED state.
74 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
75 RD_REG_WORD(®->hccr);
77 ha->isp_ops->fw_dump(vha, 1);
78 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
80 } else if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0)
83 if (RD_REG_WORD(®->semaphore) & BIT_0) {
84 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
85 RD_REG_WORD(®->hccr);
87 /* Get mailbox data. */
88 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
89 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
90 qla2x00_mbx_completion(vha, mb[0]);
91 status |= MBX_INTERRUPT;
92 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
93 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
94 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
95 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
96 qla2x00_async_event(vha, rsp, mb);
99 ql_dbg(ql_dbg_async, vha, 0x5025,
100 "Unrecognized interrupt type (%d).\n",
103 /* Release mailbox registers. */
104 WRT_REG_WORD(®->semaphore, 0);
105 RD_REG_WORD(®->semaphore);
107 qla2x00_process_response_queue(rsp);
109 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
110 RD_REG_WORD(®->hccr);
113 qla2x00_handle_mbx_completion(ha, status);
114 spin_unlock_irqrestore(&ha->hardware_lock, flags);
116 return (IRQ_HANDLED);
120 qla2x00_check_reg32_for_disconnect(scsi_qla_host_t *vha, uint32_t reg)
122 /* Check for PCI disconnection */
123 if (reg == 0xffffffff && !pci_channel_offline(vha->hw->pdev)) {
124 if (!test_and_set_bit(PFLG_DISCONNECTED, &vha->pci_flags) &&
125 !test_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags) &&
126 !test_bit(PFLG_DRIVER_PROBING, &vha->pci_flags)) {
128 * Schedule this (only once) on the default system
129 * workqueue so that all the adapter workqueues and the
130 * DPC thread can be shutdown cleanly.
132 schedule_work(&vha->hw->board_disable);
140 qla2x00_check_reg16_for_disconnect(scsi_qla_host_t *vha, uint16_t reg)
142 return qla2x00_check_reg32_for_disconnect(vha, 0xffff0000 | reg);
146 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
148 * @dev_id: SCSI driver HA context
150 * Called by system whenever the host adapter generates an interrupt.
152 * Returns handled flag.
155 qla2300_intr_handler(int irq, void *dev_id)
157 scsi_qla_host_t *vha;
158 struct device_reg_2xxx __iomem *reg;
165 struct qla_hw_data *ha;
168 rsp = (struct rsp_que *) dev_id;
170 ql_log(ql_log_info, NULL, 0x5058,
171 "%s: NULL response queue pointer.\n", __func__);
176 reg = &ha->iobase->isp;
179 spin_lock_irqsave(&ha->hardware_lock, flags);
180 vha = pci_get_drvdata(ha->pdev);
181 for (iter = 50; iter--; ) {
182 stat = RD_REG_DWORD(®->u.isp2300.host_status);
183 if (qla2x00_check_reg32_for_disconnect(vha, stat))
185 if (stat & HSR_RISC_PAUSED) {
186 if (unlikely(pci_channel_offline(ha->pdev)))
189 hccr = RD_REG_WORD(®->hccr);
191 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
192 ql_log(ql_log_warn, vha, 0x5026,
193 "Parity error -- HCCR=%x, Dumping "
194 "firmware.\n", hccr);
196 ql_log(ql_log_warn, vha, 0x5027,
197 "RISC paused -- HCCR=%x, Dumping "
198 "firmware.\n", hccr);
201 * Issue a "HARD" reset in order for the RISC
202 * interrupt bit to be cleared. Schedule a big
203 * hammer to get out of the RISC PAUSED state.
205 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
206 RD_REG_WORD(®->hccr);
208 ha->isp_ops->fw_dump(vha, 1);
209 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
211 } else if ((stat & HSR_RISC_INT) == 0)
214 switch (stat & 0xff) {
219 qla2x00_mbx_completion(vha, MSW(stat));
220 status |= MBX_INTERRUPT;
222 /* Release mailbox registers. */
223 WRT_REG_WORD(®->semaphore, 0);
227 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
228 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
229 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
230 qla2x00_async_event(vha, rsp, mb);
233 qla2x00_process_response_queue(rsp);
236 mb[0] = MBA_CMPLT_1_16BIT;
238 qla2x00_async_event(vha, rsp, mb);
241 mb[0] = MBA_SCSI_COMPLETION;
243 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
244 qla2x00_async_event(vha, rsp, mb);
247 ql_dbg(ql_dbg_async, vha, 0x5028,
248 "Unrecognized interrupt type (%d).\n", stat & 0xff);
251 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
252 RD_REG_WORD_RELAXED(®->hccr);
254 qla2x00_handle_mbx_completion(ha, status);
255 spin_unlock_irqrestore(&ha->hardware_lock, flags);
257 return (IRQ_HANDLED);
261 * qla2x00_mbx_completion() - Process mailbox command completions.
262 * @ha: SCSI driver HA context
263 * @mb0: Mailbox0 register
266 qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
270 uint16_t __iomem *wptr;
271 struct qla_hw_data *ha = vha->hw;
272 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
274 /* Read all mbox registers? */
275 WARN_ON_ONCE(ha->mbx_count > 32);
276 mboxes = (1ULL << ha->mbx_count) - 1;
278 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n");
280 mboxes = ha->mcp->in_mb;
282 /* Load return mailbox registers. */
283 ha->flags.mbox_int = 1;
284 ha->mailbox_out[0] = mb0;
286 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
288 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
289 if (IS_QLA2200(ha) && cnt == 8)
290 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
291 if ((cnt == 4 || cnt == 5) && (mboxes & BIT_0))
292 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
293 else if (mboxes & BIT_0)
294 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
302 qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
304 static char *event[] =
305 { "Complete", "Request Notification", "Time Extension" };
307 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
308 struct device_reg_82xx __iomem *reg82 = &vha->hw->iobase->isp82;
309 uint16_t __iomem *wptr;
310 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
312 /* Seed data -- mailbox1 -> mailbox7. */
313 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw))
314 wptr = (uint16_t __iomem *)®24->mailbox1;
315 else if (IS_QLA8044(vha->hw))
316 wptr = (uint16_t __iomem *)®82->mailbox_out[1];
320 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
321 mb[cnt] = RD_REG_WORD(wptr);
323 ql_dbg(ql_dbg_async, vha, 0x5021,
324 "Inter-Driver Communication %s -- "
325 "%04x %04x %04x %04x %04x %04x %04x.\n",
326 event[aen & 0xff], mb[0], mb[1], mb[2], mb[3],
327 mb[4], mb[5], mb[6]);
329 /* Handle IDC Error completion case. */
330 case MBA_IDC_COMPLETE:
332 vha->hw->flags.idc_compl_status = 1;
333 if (vha->hw->notify_dcbx_comp && !vha->vp_idx)
334 complete(&vha->hw->dcbx_comp);
339 /* Acknowledgement needed? [Notify && non-zero timeout]. */
340 timeout = (descr >> 8) & 0xf;
341 ql_dbg(ql_dbg_async, vha, 0x5022,
342 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
343 vha->host_no, event[aen & 0xff], timeout);
347 rval = qla2x00_post_idc_ack_work(vha, mb);
348 if (rval != QLA_SUCCESS)
349 ql_log(ql_log_warn, vha, 0x5023,
350 "IDC failed to post ACK.\n");
352 case MBA_IDC_TIME_EXT:
353 vha->hw->idc_extend_tmo = descr;
354 ql_dbg(ql_dbg_async, vha, 0x5087,
355 "%lu Inter-Driver Communication %s -- "
356 "Extend timeout by=%d.\n",
357 vha->host_no, event[aen & 0xff], vha->hw->idc_extend_tmo);
364 qla2x00_get_link_speed_str(struct qla_hw_data *ha, uint16_t speed)
366 static const char *const link_speeds[] = {
367 "1", "2", "?", "4", "8", "16", "32", "10"
369 #define QLA_LAST_SPEED 7
371 if (IS_QLA2100(ha) || IS_QLA2200(ha))
372 return link_speeds[0];
373 else if (speed == 0x13)
374 return link_speeds[QLA_LAST_SPEED];
375 else if (speed < QLA_LAST_SPEED)
376 return link_speeds[speed];
378 return link_speeds[LS_UNKNOWN];
382 qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t *mb)
384 struct qla_hw_data *ha = vha->hw;
387 * 8200 AEN Interpretation:
389 * mb[1] = AEN Reason code
390 * mb[2] = LSW of Peg-Halt Status-1 Register
391 * mb[6] = MSW of Peg-Halt Status-1 Register
392 * mb[3] = LSW of Peg-Halt Status-2 register
393 * mb[7] = MSW of Peg-Halt Status-2 register
394 * mb[4] = IDC Device-State Register value
395 * mb[5] = IDC Driver-Presence Register value
397 ql_dbg(ql_dbg_async, vha, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: "
398 "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n",
399 mb[0], mb[1], mb[2], mb[6]);
400 ql_dbg(ql_dbg_async, vha, 0x506c, "PH-status2: mb[3] = 0x%x "
401 "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x "
402 "Drv-Presence: mb[5] = 0x%x.\n", mb[3], mb[7], mb[4], mb[5]);
404 if (mb[1] & (IDC_PEG_HALT_STATUS_CHANGE | IDC_NIC_FW_REPORTED_FAILURE |
405 IDC_HEARTBEAT_FAILURE)) {
406 ha->flags.nic_core_hung = 1;
407 ql_log(ql_log_warn, vha, 0x5060,
408 "83XX: F/W Error Reported: Check if reset required.\n");
410 if (mb[1] & IDC_PEG_HALT_STATUS_CHANGE) {
411 uint32_t protocol_engine_id, fw_err_code, err_level;
414 * IDC_PEG_HALT_STATUS_CHANGE interpretation:
415 * - PEG-Halt Status-1 Register:
416 * (LSW = mb[2], MSW = mb[6])
417 * Bits 0-7 = protocol-engine ID
418 * Bits 8-28 = f/w error code
419 * Bits 29-31 = Error-level
420 * Error-level 0x1 = Non-Fatal error
421 * Error-level 0x2 = Recoverable Fatal error
422 * Error-level 0x4 = UnRecoverable Fatal error
423 * - PEG-Halt Status-2 Register:
424 * (LSW = mb[3], MSW = mb[7])
426 protocol_engine_id = (mb[2] & 0xff);
427 fw_err_code = (((mb[2] & 0xff00) >> 8) |
428 ((mb[6] & 0x1fff) << 8));
429 err_level = ((mb[6] & 0xe000) >> 13);
430 ql_log(ql_log_warn, vha, 0x5061, "PegHalt Status-1 "
431 "Register: protocol_engine_id=0x%x "
432 "fw_err_code=0x%x err_level=0x%x.\n",
433 protocol_engine_id, fw_err_code, err_level);
434 ql_log(ql_log_warn, vha, 0x5062, "PegHalt Status-2 "
435 "Register: 0x%x%x.\n", mb[7], mb[3]);
436 if (err_level == ERR_LEVEL_NON_FATAL) {
437 ql_log(ql_log_warn, vha, 0x5063,
438 "Not a fatal error, f/w has recovered itself.\n");
439 } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
440 ql_log(ql_log_fatal, vha, 0x5064,
441 "Recoverable Fatal error: Chip reset "
443 qla83xx_schedule_work(vha,
444 QLA83XX_NIC_CORE_RESET);
445 } else if (err_level == ERR_LEVEL_UNRECOVERABLE_FATAL) {
446 ql_log(ql_log_fatal, vha, 0x5065,
447 "Unrecoverable Fatal error: Set FAILED "
448 "state, reboot required.\n");
449 qla83xx_schedule_work(vha,
450 QLA83XX_NIC_CORE_UNRECOVERABLE);
454 if (mb[1] & IDC_NIC_FW_REPORTED_FAILURE) {
455 uint16_t peg_fw_state, nw_interface_link_up;
456 uint16_t nw_interface_signal_detect, sfp_status;
457 uint16_t htbt_counter, htbt_monitor_enable;
458 uint16_t sfp_additional_info, sfp_multirate;
459 uint16_t sfp_tx_fault, link_speed, dcbx_status;
462 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
463 * - PEG-to-FC Status Register:
464 * (LSW = mb[2], MSW = mb[6])
465 * Bits 0-7 = Peg-Firmware state
466 * Bit 8 = N/W Interface Link-up
467 * Bit 9 = N/W Interface signal detected
468 * Bits 10-11 = SFP Status
469 * SFP Status 0x0 = SFP+ transceiver not expected
470 * SFP Status 0x1 = SFP+ transceiver not present
471 * SFP Status 0x2 = SFP+ transceiver invalid
472 * SFP Status 0x3 = SFP+ transceiver present and
474 * Bits 12-14 = Heartbeat Counter
475 * Bit 15 = Heartbeat Monitor Enable
476 * Bits 16-17 = SFP Additional Info
477 * SFP info 0x0 = Unregocnized transceiver for
479 * SFP info 0x1 = SFP+ brand validation failed
480 * SFP info 0x2 = SFP+ speed validation failed
481 * SFP info 0x3 = SFP+ access error
482 * Bit 18 = SFP Multirate
483 * Bit 19 = SFP Tx Fault
484 * Bits 20-22 = Link Speed
485 * Bits 23-27 = Reserved
486 * Bits 28-30 = DCBX Status
487 * DCBX Status 0x0 = DCBX Disabled
488 * DCBX Status 0x1 = DCBX Enabled
489 * DCBX Status 0x2 = DCBX Exchange error
492 peg_fw_state = (mb[2] & 0x00ff);
493 nw_interface_link_up = ((mb[2] & 0x0100) >> 8);
494 nw_interface_signal_detect = ((mb[2] & 0x0200) >> 9);
495 sfp_status = ((mb[2] & 0x0c00) >> 10);
496 htbt_counter = ((mb[2] & 0x7000) >> 12);
497 htbt_monitor_enable = ((mb[2] & 0x8000) >> 15);
498 sfp_additional_info = (mb[6] & 0x0003);
499 sfp_multirate = ((mb[6] & 0x0004) >> 2);
500 sfp_tx_fault = ((mb[6] & 0x0008) >> 3);
501 link_speed = ((mb[6] & 0x0070) >> 4);
502 dcbx_status = ((mb[6] & 0x7000) >> 12);
504 ql_log(ql_log_warn, vha, 0x5066,
505 "Peg-to-Fc Status Register:\n"
506 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
507 "nw_interface_signal_detect=0x%x"
508 "\nsfp_statis=0x%x.\n ", peg_fw_state,
509 nw_interface_link_up, nw_interface_signal_detect,
511 ql_log(ql_log_warn, vha, 0x5067,
512 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
513 "sfp_additional_info=0x%x, sfp_multirate=0x%x.\n ",
514 htbt_counter, htbt_monitor_enable,
515 sfp_additional_info, sfp_multirate);
516 ql_log(ql_log_warn, vha, 0x5068,
517 "sfp_tx_fault=0x%x, link_state=0x%x, "
518 "dcbx_status=0x%x.\n", sfp_tx_fault, link_speed,
521 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
524 if (mb[1] & IDC_HEARTBEAT_FAILURE) {
525 ql_log(ql_log_warn, vha, 0x5069,
526 "Heartbeat Failure encountered, chip reset "
529 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
533 if (mb[1] & IDC_DEVICE_STATE_CHANGE) {
534 ql_log(ql_log_info, vha, 0x506a,
535 "IDC Device-State changed = 0x%x.\n", mb[4]);
536 if (ha->flags.nic_core_reset_owner)
538 qla83xx_schedule_work(vha, MBA_IDC_AEN);
543 qla2x00_is_a_vp_did(scsi_qla_host_t *vha, uint32_t rscn_entry)
545 struct qla_hw_data *ha = vha->hw;
554 spin_lock_irqsave(&ha->vport_slock, flags);
555 list_for_each_entry(vp, &ha->vp_list, list) {
556 vp_did = vp->d_id.b24;
557 if (vp_did == rscn_entry) {
562 spin_unlock_irqrestore(&ha->vport_slock, flags);
568 qla2x00_find_fcport_by_loopid(scsi_qla_host_t *vha, uint16_t loop_id)
573 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list)
574 if (f->loop_id == loop_id)
580 qla2x00_find_fcport_by_wwpn(scsi_qla_host_t *vha, u8 *wwpn, u8 incl_deleted)
585 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
586 if (memcmp(f->port_name, wwpn, WWN_SIZE) == 0) {
589 else if (f->deleted == 0)
597 qla2x00_find_fcport_by_nportid(scsi_qla_host_t *vha, port_id_t *id,
603 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
604 if (f->d_id.b24 == id->b24) {
607 else if (f->deleted == 0)
615 * qla2x00_async_event() - Process aynchronous events.
616 * @ha: SCSI driver HA context
617 * @mb: Mailbox registers (0 - 3)
620 qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
625 struct qla_hw_data *ha = vha->hw;
626 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
627 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
628 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
629 uint32_t rscn_entry, host_pid;
631 fc_port_t *fcport = NULL;
633 /* Setup to process RIO completion. */
635 if (IS_CNA_CAPABLE(ha))
638 case MBA_SCSI_COMPLETION:
639 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
642 case MBA_CMPLT_1_16BIT:
645 mb[0] = MBA_SCSI_COMPLETION;
647 case MBA_CMPLT_2_16BIT:
651 mb[0] = MBA_SCSI_COMPLETION;
653 case MBA_CMPLT_3_16BIT:
658 mb[0] = MBA_SCSI_COMPLETION;
660 case MBA_CMPLT_4_16BIT:
664 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
666 mb[0] = MBA_SCSI_COMPLETION;
668 case MBA_CMPLT_5_16BIT:
672 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
673 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
675 mb[0] = MBA_SCSI_COMPLETION;
677 case MBA_CMPLT_2_32BIT:
678 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
679 handles[1] = le32_to_cpu(
680 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
681 RD_MAILBOX_REG(ha, reg, 6));
683 mb[0] = MBA_SCSI_COMPLETION;
690 case MBA_SCSI_COMPLETION: /* Fast Post */
691 if (!vha->flags.online)
694 for (cnt = 0; cnt < handle_cnt; cnt++)
695 qla2x00_process_completed_request(vha, rsp->req,
699 case MBA_RESET: /* Reset */
700 ql_dbg(ql_dbg_async, vha, 0x5002,
701 "Asynchronous RESET.\n");
703 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
706 case MBA_SYSTEM_ERR: /* System Error */
707 mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) ?
708 RD_REG_WORD(®24->mailbox7) : 0;
709 ql_log(ql_log_warn, vha, 0x5003,
710 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
711 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
713 ha->isp_ops->fw_dump(vha, 1);
714 ha->flags.fw_init_done = 0;
717 if (IS_FWI2_CAPABLE(ha)) {
718 if (mb[1] == 0 && mb[2] == 0) {
719 ql_log(ql_log_fatal, vha, 0x5004,
720 "Unrecoverable Hardware Error: adapter "
721 "marked OFFLINE!\n");
722 vha->flags.online = 0;
723 vha->device_flags |= DFLG_DEV_FAILED;
725 /* Check to see if MPI timeout occurred */
726 if ((mbx & MBX_3) && (ha->port_no == 0))
727 set_bit(MPI_RESET_NEEDED,
730 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
732 } else if (mb[1] == 0) {
733 ql_log(ql_log_fatal, vha, 0x5005,
734 "Unrecoverable Hardware Error: adapter marked "
736 vha->flags.online = 0;
737 vha->device_flags |= DFLG_DEV_FAILED;
739 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
742 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
743 ql_log(ql_log_warn, vha, 0x5006,
744 "ISP Request Transfer Error (%x).\n", mb[1]);
746 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
749 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
750 ql_log(ql_log_warn, vha, 0x5007,
751 "ISP Response Transfer Error (%x).\n", mb[1]);
753 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
756 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
757 ql_dbg(ql_dbg_async, vha, 0x5008,
758 "Asynchronous WAKEUP_THRES (%x).\n", mb[1]);
761 case MBA_LOOP_INIT_ERR:
762 ql_log(ql_log_warn, vha, 0x5090,
763 "LOOP INIT ERROR (%x).\n", mb[1]);
764 ha->isp_ops->fw_dump(vha, 1);
765 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
768 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
769 ha->flags.lip_ae = 1;
770 ha->flags.n2n_ae = 0;
772 ql_dbg(ql_dbg_async, vha, 0x5009,
773 "LIP occurred (%x).\n", mb[1]);
775 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
776 atomic_set(&vha->loop_state, LOOP_DOWN);
777 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
778 qla2x00_mark_all_devices_lost(vha, 1);
782 atomic_set(&vha->vp_state, VP_FAILED);
783 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
786 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
787 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
789 vha->flags.management_server_logged_in = 0;
790 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
793 case MBA_LOOP_UP: /* Loop Up Event */
794 if (IS_QLA2100(ha) || IS_QLA2200(ha))
795 ha->link_data_rate = PORT_SPEED_1GB;
797 ha->link_data_rate = mb[1];
799 ql_log(ql_log_info, vha, 0x500a,
800 "LOOP UP detected (%s Gbps).\n",
801 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
803 vha->flags.management_server_logged_in = 0;
804 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
806 if (AUTO_DETECT_SFP_SUPPORT(vha)) {
807 set_bit(DETECT_SFP_CHANGE, &vha->dpc_flags);
808 qla2xxx_wake_dpc(vha);
812 case MBA_LOOP_DOWN: /* Loop Down Event */
813 ha->flags.n2n_ae = 0;
814 ha->flags.lip_ae = 0;
815 ha->current_topology = 0;
817 mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha))
818 ? RD_REG_WORD(®24->mailbox4) : 0;
819 mbx = (IS_P3P_TYPE(ha)) ? RD_REG_WORD(®82->mailbox_out[4])
821 ql_log(ql_log_info, vha, 0x500b,
822 "LOOP DOWN detected (%x %x %x %x).\n",
823 mb[1], mb[2], mb[3], mbx);
825 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
826 atomic_set(&vha->loop_state, LOOP_DOWN);
827 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
829 * In case of loop down, restore WWPN from
830 * NVRAM in case of FA-WWPN capable ISP
831 * Restore for Physical Port only
834 if (ha->flags.fawwpn_enabled) {
835 void *wwpn = ha->init_cb->port_name;
836 memcpy(vha->port_name, wwpn, WWN_SIZE);
837 fc_host_port_name(vha->host) =
838 wwn_to_u64(vha->port_name);
839 ql_dbg(ql_dbg_init + ql_dbg_verbose,
840 vha, 0x00d8, "LOOP DOWN detected,"
841 "restore WWPN %016llx\n",
842 wwn_to_u64(vha->port_name));
845 clear_bit(VP_CONFIG_OK, &vha->vp_flags);
848 vha->device_flags |= DFLG_NO_CABLE;
849 qla2x00_mark_all_devices_lost(vha, 1);
853 atomic_set(&vha->vp_state, VP_FAILED);
854 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
857 vha->flags.management_server_logged_in = 0;
858 ha->link_data_rate = PORT_SPEED_UNKNOWN;
859 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
862 case MBA_LIP_RESET: /* LIP reset occurred */
863 ql_dbg(ql_dbg_async, vha, 0x500c,
864 "LIP reset occurred (%x).\n", mb[1]);
866 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
867 atomic_set(&vha->loop_state, LOOP_DOWN);
868 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
869 qla2x00_mark_all_devices_lost(vha, 1);
873 atomic_set(&vha->vp_state, VP_FAILED);
874 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
877 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
879 ha->operating_mode = LOOP;
880 vha->flags.management_server_logged_in = 0;
881 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
884 /* case MBA_DCBX_COMPLETE: */
885 case MBA_POINT_TO_POINT: /* Point-to-Point */
886 ha->flags.lip_ae = 0;
887 ha->flags.n2n_ae = 1;
892 if (IS_CNA_CAPABLE(ha)) {
893 ql_dbg(ql_dbg_async, vha, 0x500d,
894 "DCBX Completed -- %04x %04x %04x.\n",
895 mb[1], mb[2], mb[3]);
896 if (ha->notify_dcbx_comp && !vha->vp_idx)
897 complete(&ha->dcbx_comp);
900 ql_dbg(ql_dbg_async, vha, 0x500e,
901 "Asynchronous P2P MODE received.\n");
904 * Until there's a transition from loop down to loop up, treat
905 * this as loop down only.
907 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
908 atomic_set(&vha->loop_state, LOOP_DOWN);
909 if (!atomic_read(&vha->loop_down_timer))
910 atomic_set(&vha->loop_down_timer,
912 qla2x00_mark_all_devices_lost(vha, 1);
916 atomic_set(&vha->vp_state, VP_FAILED);
917 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
920 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
921 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
923 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
924 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
926 ha->flags.gpsc_supported = 1;
927 vha->flags.management_server_logged_in = 0;
930 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
934 ql_dbg(ql_dbg_async, vha, 0x500f,
935 "Configuration change detected: value=%x.\n", mb[1]);
937 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
938 atomic_set(&vha->loop_state, LOOP_DOWN);
939 if (!atomic_read(&vha->loop_down_timer))
940 atomic_set(&vha->loop_down_timer,
942 qla2x00_mark_all_devices_lost(vha, 1);
946 atomic_set(&vha->vp_state, VP_FAILED);
947 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
950 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
951 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
954 case MBA_PORT_UPDATE: /* Port database update */
956 * Handle only global and vn-port update events
959 * mb[1] = N_Port handle of changed port
960 * OR 0xffff for global event
961 * mb[2] = New login state
962 * 7 = Port logged out
963 * mb[3] = LSB is vp_idx, 0xff = all vps
965 * Skip processing if:
966 * Event is global, vp_idx is NOT all vps,
967 * vp_idx does not match
968 * Event is not global, vp_idx does not match
970 if (IS_QLA2XXX_MIDTYPE(ha) &&
971 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
972 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
976 ql_dbg(ql_dbg_async, vha, 0x5010,
977 "Port %s %04x %04x %04x.\n",
978 mb[1] == 0xffff ? "unavailable" : "logout",
979 mb[1], mb[2], mb[3]);
982 goto global_port_update;
984 if (mb[1] == NPH_SNS_LID(ha)) {
985 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
986 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
990 /* use handle_cnt for loop id/nport handle */
991 if (IS_FWI2_CAPABLE(ha))
992 handle_cnt = NPH_SNS;
994 handle_cnt = SIMPLE_NAME_SERVER;
995 if (mb[1] == handle_cnt) {
996 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
997 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1002 fcport = qla2x00_find_fcport_by_loopid(vha, mb[1]);
1005 if (atomic_read(&fcport->state) != FCS_ONLINE)
1007 ql_dbg(ql_dbg_async, vha, 0x508a,
1008 "Marking port lost loopid=%04x portid=%06x.\n",
1009 fcport->loop_id, fcport->d_id.b24);
1010 if (qla_ini_mode_enabled(vha)) {
1011 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1012 fcport->logout_on_delete = 0;
1013 qlt_schedule_sess_for_deletion_lock(fcport);
1018 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
1019 atomic_set(&vha->loop_state, LOOP_DOWN);
1020 atomic_set(&vha->loop_down_timer,
1022 vha->device_flags |= DFLG_NO_CABLE;
1023 qla2x00_mark_all_devices_lost(vha, 1);
1027 atomic_set(&vha->vp_state, VP_FAILED);
1028 fc_vport_set_state(vha->fc_vport,
1030 qla2x00_mark_all_devices_lost(vha, 1);
1033 vha->flags.management_server_logged_in = 0;
1034 ha->link_data_rate = PORT_SPEED_UNKNOWN;
1039 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
1040 * event etc. earlier indicating loop is down) then process
1041 * it. Otherwise ignore it and Wait for RSCN to come in.
1043 atomic_set(&vha->loop_down_timer, 0);
1044 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
1045 atomic_read(&vha->loop_state) != LOOP_DEAD) {
1046 ql_dbg(ql_dbg_async, vha, 0x5011,
1047 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
1048 mb[1], mb[2], mb[3]);
1052 ql_dbg(ql_dbg_async, vha, 0x5012,
1053 "Port database changed %04x %04x %04x.\n",
1054 mb[1], mb[2], mb[3]);
1057 * Mark all devices as missing so we will login again.
1059 atomic_set(&vha->loop_state, LOOP_UP);
1061 qla2x00_mark_all_devices_lost(vha, 1);
1063 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1064 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1065 set_bit(VP_CONFIG_OK, &vha->vp_flags);
1068 case MBA_RSCN_UPDATE: /* State Change Registration */
1069 /* Check if the Vport has issued a SCR */
1070 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
1072 /* Only handle SCNs for our Vport index. */
1073 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
1076 ql_dbg(ql_dbg_async, vha, 0x5013,
1077 "RSCN database changed -- %04x %04x %04x.\n",
1078 mb[1], mb[2], mb[3]);
1080 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
1081 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
1082 | vha->d_id.b.al_pa;
1083 if (rscn_entry == host_pid) {
1084 ql_dbg(ql_dbg_async, vha, 0x5014,
1085 "Ignoring RSCN update to local host "
1086 "port ID (%06x).\n", host_pid);
1090 /* Ignore reserved bits from RSCN-payload. */
1091 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
1093 /* Skip RSCNs for virtual ports on the same physical port */
1094 if (qla2x00_is_a_vp_did(vha, rscn_entry))
1097 atomic_set(&vha->loop_down_timer, 0);
1098 vha->flags.management_server_logged_in = 0;
1100 struct event_arg ea;
1102 memset(&ea, 0, sizeof(ea));
1103 ea.event = FCME_RSCN;
1104 ea.id.b24 = rscn_entry;
1105 ea.id.b.rsvd_1 = rscn_entry >> 24;
1106 qla2x00_fcport_event_handler(vha, &ea);
1107 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
1110 /* case MBA_RIO_RESPONSE: */
1111 case MBA_ZIO_RESPONSE:
1112 ql_dbg(ql_dbg_async, vha, 0x5015,
1113 "[R|Z]IO update completion.\n");
1115 if (IS_FWI2_CAPABLE(ha))
1116 qla24xx_process_response_queue(vha, rsp);
1118 qla2x00_process_response_queue(rsp);
1121 case MBA_DISCARD_RND_FRAME:
1122 ql_dbg(ql_dbg_async, vha, 0x5016,
1123 "Discard RND Frame -- %04x %04x %04x.\n",
1124 mb[1], mb[2], mb[3]);
1127 case MBA_TRACE_NOTIFICATION:
1128 ql_dbg(ql_dbg_async, vha, 0x5017,
1129 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
1132 case MBA_ISP84XX_ALERT:
1133 ql_dbg(ql_dbg_async, vha, 0x5018,
1134 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
1135 mb[1], mb[2], mb[3]);
1137 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
1139 case A84_PANIC_RECOVERY:
1140 ql_log(ql_log_info, vha, 0x5019,
1141 "Alert 84XX: panic recovery %04x %04x.\n",
1144 case A84_OP_LOGIN_COMPLETE:
1145 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
1146 ql_log(ql_log_info, vha, 0x501a,
1147 "Alert 84XX: firmware version %x.\n",
1148 ha->cs84xx->op_fw_version);
1150 case A84_DIAG_LOGIN_COMPLETE:
1151 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
1152 ql_log(ql_log_info, vha, 0x501b,
1153 "Alert 84XX: diagnostic firmware version %x.\n",
1154 ha->cs84xx->diag_fw_version);
1156 case A84_GOLD_LOGIN_COMPLETE:
1157 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
1158 ha->cs84xx->fw_update = 1;
1159 ql_log(ql_log_info, vha, 0x501c,
1160 "Alert 84XX: gold firmware version %x.\n",
1161 ha->cs84xx->gold_fw_version);
1164 ql_log(ql_log_warn, vha, 0x501d,
1165 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
1166 mb[1], mb[2], mb[3]);
1168 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
1170 case MBA_DCBX_START:
1171 ql_dbg(ql_dbg_async, vha, 0x501e,
1172 "DCBX Started -- %04x %04x %04x.\n",
1173 mb[1], mb[2], mb[3]);
1175 case MBA_DCBX_PARAM_UPDATE:
1176 ql_dbg(ql_dbg_async, vha, 0x501f,
1177 "DCBX Parameters Updated -- %04x %04x %04x.\n",
1178 mb[1], mb[2], mb[3]);
1180 case MBA_FCF_CONF_ERR:
1181 ql_dbg(ql_dbg_async, vha, 0x5020,
1182 "FCF Configuration Error -- %04x %04x %04x.\n",
1183 mb[1], mb[2], mb[3]);
1185 case MBA_IDC_NOTIFY:
1186 if (IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
1187 mb[4] = RD_REG_WORD(®24->mailbox4);
1188 if (((mb[2] & 0x7fff) == MBC_PORT_RESET ||
1189 (mb[2] & 0x7fff) == MBC_SET_PORT_CONFIG) &&
1190 (mb[4] & INTERNAL_LOOPBACK_MASK) != 0) {
1191 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
1193 * Extend loop down timer since port is active.
1195 if (atomic_read(&vha->loop_state) == LOOP_DOWN)
1196 atomic_set(&vha->loop_down_timer,
1198 qla2xxx_wake_dpc(vha);
1201 case MBA_IDC_COMPLETE:
1202 if (ha->notify_lb_portup_comp && !vha->vp_idx)
1203 complete(&ha->lb_portup_comp);
1205 case MBA_IDC_TIME_EXT:
1206 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) ||
1208 qla81xx_idc_event(vha, mb[0], mb[1]);
1212 mb[4] = RD_REG_WORD(®24->mailbox4);
1213 mb[5] = RD_REG_WORD(®24->mailbox5);
1214 mb[6] = RD_REG_WORD(®24->mailbox6);
1215 mb[7] = RD_REG_WORD(®24->mailbox7);
1216 qla83xx_handle_8200_aen(vha, mb);
1219 case MBA_DPORT_DIAGNOSTICS:
1220 ql_dbg(ql_dbg_async, vha, 0x5052,
1221 "D-Port Diagnostics: %04x result=%s\n",
1223 mb[1] == 0 ? "start" :
1224 mb[1] == 1 ? "done (pass)" :
1225 mb[1] == 2 ? "done (error)" : "other");
1228 case MBA_TEMPERATURE_ALERT:
1229 ql_dbg(ql_dbg_async, vha, 0x505e,
1230 "TEMPERATURE ALERT: %04x %04x %04x\n", mb[1], mb[2], mb[3]);
1232 schedule_work(&ha->board_disable);
1235 case MBA_TRANS_INSERT:
1236 ql_dbg(ql_dbg_async, vha, 0x5091,
1237 "Transceiver Insertion: %04x\n", mb[1]);
1241 ql_dbg(ql_dbg_async, vha, 0x5057,
1242 "Unknown AEN:%04x %04x %04x %04x\n",
1243 mb[0], mb[1], mb[2], mb[3]);
1246 qlt_async_event(mb[0], vha, mb);
1248 if (!vha->vp_idx && ha->num_vhosts)
1249 qla2x00_alert_all_vps(rsp, mb);
1253 * qla2x00_process_completed_request() - Process a Fast Post response.
1254 * @ha: SCSI driver HA context
1258 qla2x00_process_completed_request(struct scsi_qla_host *vha,
1259 struct req_que *req, uint32_t index)
1262 struct qla_hw_data *ha = vha->hw;
1264 /* Validate handle. */
1265 if (index >= req->num_outstanding_cmds) {
1266 ql_log(ql_log_warn, vha, 0x3014,
1267 "Invalid SCSI command index (%x).\n", index);
1269 if (IS_P3P_TYPE(ha))
1270 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1272 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1276 sp = req->outstanding_cmds[index];
1278 /* Free outstanding command slot. */
1279 req->outstanding_cmds[index] = NULL;
1281 /* Save ISP completion status */
1282 sp->done(sp, DID_OK << 16);
1284 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
1286 if (IS_P3P_TYPE(ha))
1287 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1289 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1294 qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
1295 struct req_que *req, void *iocb)
1297 struct qla_hw_data *ha = vha->hw;
1298 sts_entry_t *pkt = iocb;
1302 index = LSW(pkt->handle);
1303 if (index >= req->num_outstanding_cmds) {
1304 ql_log(ql_log_warn, vha, 0x5031,
1305 "Invalid command index (%x) type %8ph.\n",
1307 if (IS_P3P_TYPE(ha))
1308 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1310 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1313 sp = req->outstanding_cmds[index];
1315 ql_log(ql_log_warn, vha, 0x5032,
1316 "Invalid completion handle (%x) -- timed-out.\n", index);
1319 if (sp->handle != index) {
1320 ql_log(ql_log_warn, vha, 0x5033,
1321 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
1325 req->outstanding_cmds[index] = NULL;
1332 qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1333 struct mbx_entry *mbx)
1335 const char func[] = "MBX-IOCB";
1339 struct srb_iocb *lio;
1343 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
1347 lio = &sp->u.iocb_cmd;
1349 fcport = sp->fcport;
1350 data = lio->u.logio.data;
1352 data[0] = MBS_COMMAND_ERROR;
1353 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
1354 QLA_LOGIO_LOGIN_RETRIED : 0;
1355 if (mbx->entry_status) {
1356 ql_dbg(ql_dbg_async, vha, 0x5043,
1357 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
1358 "entry-status=%x status=%x state-flag=%x "
1359 "status-flags=%x.\n", type, sp->handle,
1360 fcport->d_id.b.domain, fcport->d_id.b.area,
1361 fcport->d_id.b.al_pa, mbx->entry_status,
1362 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
1363 le16_to_cpu(mbx->status_flags));
1365 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
1366 (uint8_t *)mbx, sizeof(*mbx));
1371 status = le16_to_cpu(mbx->status);
1372 if (status == 0x30 && sp->type == SRB_LOGIN_CMD &&
1373 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
1375 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
1376 ql_dbg(ql_dbg_async, vha, 0x5045,
1377 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1378 type, sp->handle, fcport->d_id.b.domain,
1379 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1380 le16_to_cpu(mbx->mb1));
1382 data[0] = MBS_COMMAND_COMPLETE;
1383 if (sp->type == SRB_LOGIN_CMD) {
1384 fcport->port_type = FCT_TARGET;
1385 if (le16_to_cpu(mbx->mb1) & BIT_0)
1386 fcport->port_type = FCT_INITIATOR;
1387 else if (le16_to_cpu(mbx->mb1) & BIT_1)
1388 fcport->flags |= FCF_FCP2_DEVICE;
1393 data[0] = le16_to_cpu(mbx->mb0);
1395 case MBS_PORT_ID_USED:
1396 data[1] = le16_to_cpu(mbx->mb1);
1398 case MBS_LOOP_ID_USED:
1401 data[0] = MBS_COMMAND_ERROR;
1405 ql_log(ql_log_warn, vha, 0x5046,
1406 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1407 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
1408 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
1409 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
1410 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
1411 le16_to_cpu(mbx->mb7));
1418 qla24xx_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1419 struct mbx_24xx_entry *pkt)
1421 const char func[] = "MBX-IOCB2";
1423 struct srb_iocb *si;
1427 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1431 si = &sp->u.iocb_cmd;
1432 sz = min(ARRAY_SIZE(pkt->mb), ARRAY_SIZE(sp->u.iocb_cmd.u.mbx.in_mb));
1434 for (i = 0; i < sz; i++)
1435 si->u.mbx.in_mb[i] = le16_to_cpu(pkt->mb[i]);
1437 res = (si->u.mbx.in_mb[0] & MBS_MASK);
1443 qla24xxx_nack_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1444 struct nack_to_isp *pkt)
1446 const char func[] = "nack";
1450 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1454 if (pkt->u.isp2x.status != cpu_to_le16(NOTIFY_ACK_SUCCESS))
1455 res = QLA_FUNCTION_FAILED;
1461 qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1462 sts_entry_t *pkt, int iocb_type)
1464 const char func[] = "CT_IOCB";
1467 struct bsg_job *bsg_job;
1468 struct fc_bsg_reply *bsg_reply;
1469 uint16_t comp_status;
1472 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1478 bsg_job = sp->u.bsg_job;
1479 bsg_reply = bsg_job->reply;
1481 type = "ct pass-through";
1483 comp_status = le16_to_cpu(pkt->comp_status);
1486 * return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1487 * fc payload to the caller
1489 bsg_reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1490 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1492 if (comp_status != CS_COMPLETE) {
1493 if (comp_status == CS_DATA_UNDERRUN) {
1495 bsg_reply->reply_payload_rcv_len =
1496 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
1498 ql_log(ql_log_warn, vha, 0x5048,
1499 "CT pass-through-%s error comp_status=0x%x total_byte=0x%x.\n",
1501 bsg_reply->reply_payload_rcv_len);
1503 ql_log(ql_log_warn, vha, 0x5049,
1504 "CT pass-through-%s error comp_status=0x%x.\n",
1506 res = DID_ERROR << 16;
1507 bsg_reply->reply_payload_rcv_len = 0;
1509 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
1510 (uint8_t *)pkt, sizeof(*pkt));
1513 bsg_reply->reply_payload_rcv_len =
1514 bsg_job->reply_payload.payload_len;
1515 bsg_job->reply_len = 0;
1518 case SRB_CT_PTHRU_CMD:
1520 * borrowing sts_entry_24xx.comp_status.
1521 * same location as ct_entry_24xx.comp_status
1523 res = qla2x00_chk_ms_status(vha, (ms_iocb_entry_t *)pkt,
1524 (struct ct_sns_rsp *)sp->u.iocb_cmd.u.ctarg.rsp,
1533 qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1534 struct sts_entry_24xx *pkt, int iocb_type)
1536 const char func[] = "ELS_CT_IOCB";
1539 struct bsg_job *bsg_job;
1540 struct fc_bsg_reply *bsg_reply;
1541 uint16_t comp_status;
1542 uint32_t fw_status[3];
1545 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1551 case SRB_ELS_CMD_RPT:
1552 case SRB_ELS_CMD_HST:
1556 type = "ct pass-through";
1559 type = "Driver ELS logo";
1560 ql_dbg(ql_dbg_user, vha, 0x5047,
1561 "Completing %s: (%p) type=%d.\n", type, sp, sp->type);
1564 case SRB_CT_PTHRU_CMD:
1565 /* borrowing sts_entry_24xx.comp_status.
1566 same location as ct_entry_24xx.comp_status
1568 res = qla2x00_chk_ms_status(sp->vha, (ms_iocb_entry_t *)pkt,
1569 (struct ct_sns_rsp *)sp->u.iocb_cmd.u.ctarg.rsp,
1574 ql_dbg(ql_dbg_user, vha, 0x503e,
1575 "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type);
1579 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1580 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1581 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1583 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1584 * fc payload to the caller
1586 bsg_job = sp->u.bsg_job;
1587 bsg_reply = bsg_job->reply;
1588 bsg_reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1589 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1591 if (comp_status != CS_COMPLETE) {
1592 if (comp_status == CS_DATA_UNDERRUN) {
1594 bsg_reply->reply_payload_rcv_len =
1595 le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count);
1597 ql_dbg(ql_dbg_user, vha, 0x503f,
1598 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
1599 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
1600 type, sp->handle, comp_status, fw_status[1], fw_status[2],
1601 le16_to_cpu(((struct els_sts_entry_24xx *)
1602 pkt)->total_byte_count));
1604 ql_dbg(ql_dbg_user, vha, 0x5040,
1605 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
1606 "error subcode 1=0x%x error subcode 2=0x%x.\n",
1607 type, sp->handle, comp_status,
1608 le16_to_cpu(((struct els_sts_entry_24xx *)
1609 pkt)->error_subcode_1),
1610 le16_to_cpu(((struct els_sts_entry_24xx *)
1611 pkt)->error_subcode_2));
1612 res = DID_ERROR << 16;
1613 bsg_reply->reply_payload_rcv_len = 0;
1615 memcpy(bsg_job->reply + sizeof(struct fc_bsg_reply),
1616 fw_status, sizeof(fw_status));
1617 ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056,
1618 (uint8_t *)pkt, sizeof(*pkt));
1622 bsg_reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1623 bsg_job->reply_len = 0;
1630 qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1631 struct logio_entry_24xx *logio)
1633 const char func[] = "LOGIO-IOCB";
1637 struct srb_iocb *lio;
1641 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1645 lio = &sp->u.iocb_cmd;
1647 fcport = sp->fcport;
1648 data = lio->u.logio.data;
1650 data[0] = MBS_COMMAND_ERROR;
1651 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
1652 QLA_LOGIO_LOGIN_RETRIED : 0;
1653 if (logio->entry_status) {
1654 ql_log(ql_log_warn, fcport->vha, 0x5034,
1655 "Async-%s error entry - %8phC hdl=%x"
1656 "portid=%02x%02x%02x entry-status=%x.\n",
1657 type, fcport->port_name, sp->handle, fcport->d_id.b.domain,
1658 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1659 logio->entry_status);
1660 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
1661 (uint8_t *)logio, sizeof(*logio));
1666 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
1667 ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
1668 "Async-%s complete - %8phC hdl=%x portid=%02x%02x%02x "
1669 "iop0=%x.\n", type, fcport->port_name, sp->handle,
1670 fcport->d_id.b.domain,
1671 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1672 le32_to_cpu(logio->io_parameter[0]));
1674 vha->hw->exch_starvation = 0;
1675 data[0] = MBS_COMMAND_COMPLETE;
1676 if (sp->type != SRB_LOGIN_CMD)
1679 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1680 if (iop[0] & BIT_4) {
1681 fcport->port_type = FCT_TARGET;
1683 fcport->flags |= FCF_FCP2_DEVICE;
1684 } else if (iop[0] & BIT_5)
1685 fcport->port_type = FCT_INITIATOR;
1688 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1690 if (logio->io_parameter[7] || logio->io_parameter[8])
1691 fcport->supported_classes |= FC_COS_CLASS2;
1692 if (logio->io_parameter[9] || logio->io_parameter[10])
1693 fcport->supported_classes |= FC_COS_CLASS3;
1698 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1699 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1700 lio->u.logio.iop[0] = iop[0];
1701 lio->u.logio.iop[1] = iop[1];
1703 case LSC_SCODE_PORTID_USED:
1704 data[0] = MBS_PORT_ID_USED;
1705 data[1] = LSW(iop[1]);
1707 case LSC_SCODE_NPORT_USED:
1708 data[0] = MBS_LOOP_ID_USED;
1710 case LSC_SCODE_CMD_FAILED:
1711 if (iop[1] == 0x0606) {
1713 * PLOGI/PRLI Completed. We must have Recv PLOGI/PRLI,
1714 * Target side acked.
1716 data[0] = MBS_COMMAND_COMPLETE;
1719 data[0] = MBS_COMMAND_ERROR;
1721 case LSC_SCODE_NOXCB:
1722 vha->hw->exch_starvation++;
1723 if (vha->hw->exch_starvation > 5) {
1724 ql_log(ql_log_warn, vha, 0xd046,
1725 "Exchange starvation. Resetting RISC\n");
1727 vha->hw->exch_starvation = 0;
1729 if (IS_P3P_TYPE(vha->hw))
1730 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1732 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1733 qla2xxx_wake_dpc(vha);
1737 data[0] = MBS_COMMAND_ERROR;
1741 ql_dbg(ql_dbg_async, fcport->vha, 0x5037,
1742 "Async-%s failed - %8phC hdl=%x portid=%02x%02x%02x comp=%x "
1743 "iop0=%x iop1=%x.\n", type, fcport->port_name,
1744 sp->handle, fcport->d_id.b.domain,
1745 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1746 le16_to_cpu(logio->comp_status),
1747 le32_to_cpu(logio->io_parameter[0]),
1748 le32_to_cpu(logio->io_parameter[1]));
1755 qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, void *tsk)
1757 const char func[] = "TMF-IOCB";
1761 struct srb_iocb *iocb;
1762 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1764 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1768 iocb = &sp->u.iocb_cmd;
1770 fcport = sp->fcport;
1771 iocb->u.tmf.data = QLA_SUCCESS;
1773 if (sts->entry_status) {
1774 ql_log(ql_log_warn, fcport->vha, 0x5038,
1775 "Async-%s error - hdl=%x entry-status(%x).\n",
1776 type, sp->handle, sts->entry_status);
1777 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1778 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
1779 ql_log(ql_log_warn, fcport->vha, 0x5039,
1780 "Async-%s error - hdl=%x completion status(%x).\n",
1781 type, sp->handle, sts->comp_status);
1782 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1783 } else if ((le16_to_cpu(sts->scsi_status) &
1784 SS_RESPONSE_INFO_LEN_VALID)) {
1785 if (le32_to_cpu(sts->rsp_data_len) < 4) {
1786 ql_log(ql_log_warn, fcport->vha, 0x503b,
1787 "Async-%s error - hdl=%x not enough response(%d).\n",
1788 type, sp->handle, sts->rsp_data_len);
1789 } else if (sts->data[3]) {
1790 ql_log(ql_log_warn, fcport->vha, 0x503c,
1791 "Async-%s error - hdl=%x response(%x).\n",
1792 type, sp->handle, sts->data[3]);
1793 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1797 if (iocb->u.tmf.data != QLA_SUCCESS)
1798 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1799 (uint8_t *)sts, sizeof(*sts));
1805 qla24xx_nvme_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, void *tsk)
1807 const char func[] = "NVME-IOCB";
1810 struct srb_iocb *iocb;
1811 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1812 uint16_t state_flags;
1813 struct nvmefc_fcp_req *fd;
1815 struct srb_iocb *nvme;
1817 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1821 iocb = &sp->u.iocb_cmd;
1822 fcport = sp->fcport;
1823 iocb->u.nvme.comp_status = le16_to_cpu(sts->comp_status);
1824 state_flags = le16_to_cpu(sts->state_flags);
1825 fd = iocb->u.nvme.desc;
1826 nvme = &sp->u.iocb_cmd;
1828 if (unlikely(nvme->u.nvme.aen_op))
1829 atomic_dec(&sp->vha->hw->nvme_active_aen_cnt);
1832 * State flags: Bit 6 and 0.
1833 * If 0 is set, we don't care about 6.
1834 * both cases resp was dma'd to host buffer
1835 * if both are 0, that is good path case.
1836 * if six is set and 0 is clear, we need to
1837 * copy resp data from status iocb to resp buffer.
1839 if (!(state_flags & (SF_FCP_RSP_DMA | SF_NVME_ERSP))) {
1840 iocb->u.nvme.rsp_pyld_len = 0;
1841 } else if ((state_flags & SF_FCP_RSP_DMA)) {
1842 iocb->u.nvme.rsp_pyld_len = le16_to_cpu(sts->nvme_rsp_pyld_len);
1843 } else if (state_flags & SF_NVME_ERSP) {
1844 uint32_t *inbuf, *outbuf;
1847 inbuf = (uint32_t *)&sts->nvme_ersp_data;
1848 outbuf = (uint32_t *)fd->rspaddr;
1849 iocb->u.nvme.rsp_pyld_len = le16_to_cpu(sts->nvme_rsp_pyld_len);
1850 if (unlikely(iocb->u.nvme.rsp_pyld_len >
1851 sizeof(struct nvme_fc_ersp_iu))) {
1852 if (ql_mask_match(ql_dbg_io)) {
1853 WARN_ONCE(1, "Unexpected response payload length %u.\n",
1854 iocb->u.nvme.rsp_pyld_len);
1855 ql_log(ql_log_warn, fcport->vha, 0x5100,
1856 "Unexpected response payload length %u.\n",
1857 iocb->u.nvme.rsp_pyld_len);
1859 iocb->u.nvme.rsp_pyld_len =
1860 sizeof(struct nvme_fc_ersp_iu);
1862 iter = iocb->u.nvme.rsp_pyld_len >> 2;
1863 for (; iter; iter--)
1864 *outbuf++ = swab32(*inbuf++);
1865 } else { /* unhandled case */
1866 ql_log(ql_log_warn, fcport->vha, 0x503a,
1867 "NVME-%s error. Unhandled state_flags of %x\n",
1868 sp->name, state_flags);
1871 fd->transferred_length = fd->payload_length -
1872 le32_to_cpu(sts->residual_len);
1875 * If transport error then Failure (HBA rejects request)
1876 * otherwise transport will handle.
1878 if (sts->entry_status) {
1879 ql_log(ql_log_warn, fcport->vha, 0x5038,
1880 "NVME-%s error - hdl=%x entry-status(%x).\n",
1881 sp->name, sp->handle, sts->entry_status);
1882 ret = QLA_FUNCTION_FAILED;
1884 switch (le16_to_cpu(sts->comp_status)) {
1891 case CS_PORT_UNAVAILABLE:
1892 case CS_PORT_LOGGED_OUT:
1894 ql_log(ql_log_warn, fcport->vha, 0x5060,
1895 "NVME-%s ERR Handling - hdl=%x completion status(%x) resid=%x ox_id=%x\n",
1896 sp->name, sp->handle, sts->comp_status,
1897 le32_to_cpu(sts->residual_len), sts->ox_id);
1898 fd->transferred_length = fd->payload_length;
1903 ql_log(ql_log_warn, fcport->vha, 0x5060,
1904 "NVME-%s error - hdl=%x completion status(%x) resid=%x ox_id=%x\n",
1905 sp->name, sp->handle, sts->comp_status,
1906 le32_to_cpu(sts->residual_len), sts->ox_id);
1907 ret = QLA_FUNCTION_FAILED;
1915 * qla2x00_process_response_queue() - Process response queue entries.
1916 * @ha: SCSI driver HA context
1919 qla2x00_process_response_queue(struct rsp_que *rsp)
1921 struct scsi_qla_host *vha;
1922 struct qla_hw_data *ha = rsp->hw;
1923 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1925 uint16_t handle_cnt;
1928 vha = pci_get_drvdata(ha->pdev);
1930 if (!vha->flags.online)
1933 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1934 pkt = (sts_entry_t *)rsp->ring_ptr;
1937 if (rsp->ring_index == rsp->length) {
1938 rsp->ring_index = 0;
1939 rsp->ring_ptr = rsp->ring;
1944 if (pkt->entry_status != 0) {
1945 qla2x00_error_entry(vha, rsp, pkt);
1946 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1951 switch (pkt->entry_type) {
1953 qla2x00_status_entry(vha, rsp, pkt);
1955 case STATUS_TYPE_21:
1956 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1957 for (cnt = 0; cnt < handle_cnt; cnt++) {
1958 qla2x00_process_completed_request(vha, rsp->req,
1959 ((sts21_entry_t *)pkt)->handle[cnt]);
1962 case STATUS_TYPE_22:
1963 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1964 for (cnt = 0; cnt < handle_cnt; cnt++) {
1965 qla2x00_process_completed_request(vha, rsp->req,
1966 ((sts22_entry_t *)pkt)->handle[cnt]);
1969 case STATUS_CONT_TYPE:
1970 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
1973 qla2x00_mbx_iocb_entry(vha, rsp->req,
1974 (struct mbx_entry *)pkt);
1977 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1980 /* Type Not Supported. */
1981 ql_log(ql_log_warn, vha, 0x504a,
1982 "Received unknown response pkt type %x "
1983 "entry status=%x.\n",
1984 pkt->entry_type, pkt->entry_status);
1987 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1991 /* Adjust ring index */
1992 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
1996 qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
1997 uint32_t sense_len, struct rsp_que *rsp, int res)
1999 struct scsi_qla_host *vha = sp->vha;
2000 struct scsi_cmnd *cp = GET_CMD_SP(sp);
2001 uint32_t track_sense_len;
2003 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
2004 sense_len = SCSI_SENSE_BUFFERSIZE;
2006 SET_CMD_SENSE_LEN(sp, sense_len);
2007 SET_CMD_SENSE_PTR(sp, cp->sense_buffer);
2008 track_sense_len = sense_len;
2010 if (sense_len > par_sense_len)
2011 sense_len = par_sense_len;
2013 memcpy(cp->sense_buffer, sense_data, sense_len);
2015 SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len);
2016 track_sense_len -= sense_len;
2017 SET_CMD_SENSE_LEN(sp, track_sense_len);
2019 if (track_sense_len != 0) {
2020 rsp->status_srb = sp;
2025 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
2026 "Check condition Sense data, nexus%ld:%d:%llu cmd=%p.\n",
2027 sp->vha->host_no, cp->device->id, cp->device->lun,
2029 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
2030 cp->sense_buffer, sense_len);
2034 struct scsi_dif_tuple {
2035 __be16 guard; /* Checksum */
2036 __be16 app_tag; /* APPL identifier */
2037 __be32 ref_tag; /* Target LBA or indirect LBA */
2041 * Checks the guard or meta-data for the type of error
2042 * detected by the HBA. In case of errors, we set the
2043 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
2044 * to indicate to the kernel that the HBA detected error.
2047 qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
2049 struct scsi_qla_host *vha = sp->vha;
2050 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
2051 uint8_t *ap = &sts24->data[12];
2052 uint8_t *ep = &sts24->data[20];
2053 uint32_t e_ref_tag, a_ref_tag;
2054 uint16_t e_app_tag, a_app_tag;
2055 uint16_t e_guard, a_guard;
2058 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
2059 * would make guard field appear at offset 2
2061 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
2062 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
2063 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
2064 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
2065 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
2066 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
2068 ql_dbg(ql_dbg_io, vha, 0x3023,
2069 "iocb(s) %p Returned STATUS.\n", sts24);
2071 ql_dbg(ql_dbg_io, vha, 0x3024,
2072 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
2073 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
2074 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
2075 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
2076 a_app_tag, e_app_tag, a_guard, e_guard);
2080 * For type 3: ref & app tag is all 'f's
2081 * For type 0,1,2: app tag is all 'f's
2083 if ((a_app_tag == T10_PI_APP_ESCAPE) &&
2084 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
2085 (a_ref_tag == T10_PI_REF_ESCAPE))) {
2086 uint32_t blocks_done, resid;
2087 sector_t lba_s = scsi_get_lba(cmd);
2089 /* 2TB boundary case covered automatically with this */
2090 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
2092 resid = scsi_bufflen(cmd) - (blocks_done *
2093 cmd->device->sector_size);
2095 scsi_set_resid(cmd, resid);
2096 cmd->result = DID_OK << 16;
2098 /* Update protection tag */
2099 if (scsi_prot_sg_count(cmd)) {
2100 uint32_t i, j = 0, k = 0, num_ent;
2101 struct scatterlist *sg;
2102 struct t10_pi_tuple *spt;
2104 /* Patch the corresponding protection tags */
2105 scsi_for_each_prot_sg(cmd, sg,
2106 scsi_prot_sg_count(cmd), i) {
2107 num_ent = sg_dma_len(sg) / 8;
2108 if (k + num_ent < blocks_done) {
2112 j = blocks_done - k - 1;
2117 if (k != blocks_done) {
2118 ql_log(ql_log_warn, vha, 0x302f,
2119 "unexpected tag values tag:lba=%x:%llx)\n",
2120 e_ref_tag, (unsigned long long)lba_s);
2124 spt = page_address(sg_page(sg)) + sg->offset;
2127 spt->app_tag = T10_PI_APP_ESCAPE;
2128 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
2129 spt->ref_tag = T10_PI_REF_ESCAPE;
2136 if (e_guard != a_guard) {
2137 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2139 set_driver_byte(cmd, DRIVER_SENSE);
2140 set_host_byte(cmd, DID_ABORT);
2141 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
2146 if (e_ref_tag != a_ref_tag) {
2147 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2149 set_driver_byte(cmd, DRIVER_SENSE);
2150 set_host_byte(cmd, DID_ABORT);
2151 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
2155 /* check appl tag */
2156 if (e_app_tag != a_app_tag) {
2157 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2159 set_driver_byte(cmd, DRIVER_SENSE);
2160 set_host_byte(cmd, DID_ABORT);
2161 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
2169 qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, void *pkt,
2170 struct req_que *req, uint32_t index)
2172 struct qla_hw_data *ha = vha->hw;
2174 uint16_t comp_status;
2175 uint16_t scsi_status;
2177 uint32_t rval = EXT_STATUS_OK;
2178 struct bsg_job *bsg_job = NULL;
2179 struct fc_bsg_request *bsg_request;
2180 struct fc_bsg_reply *bsg_reply;
2182 struct sts_entry_24xx *sts24;
2183 sts = (sts_entry_t *) pkt;
2184 sts24 = (struct sts_entry_24xx *) pkt;
2186 /* Validate handle. */
2187 if (index >= req->num_outstanding_cmds) {
2188 ql_log(ql_log_warn, vha, 0x70af,
2189 "Invalid SCSI completion handle 0x%x.\n", index);
2190 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2194 sp = req->outstanding_cmds[index];
2196 ql_log(ql_log_warn, vha, 0x70b0,
2197 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
2200 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2204 /* Free outstanding command slot. */
2205 req->outstanding_cmds[index] = NULL;
2206 bsg_job = sp->u.bsg_job;
2207 bsg_request = bsg_job->request;
2208 bsg_reply = bsg_job->reply;
2210 if (IS_FWI2_CAPABLE(ha)) {
2211 comp_status = le16_to_cpu(sts24->comp_status);
2212 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
2214 comp_status = le16_to_cpu(sts->comp_status);
2215 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
2218 thread_id = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
2219 switch (comp_status) {
2221 if (scsi_status == 0) {
2222 bsg_reply->reply_payload_rcv_len =
2223 bsg_job->reply_payload.payload_len;
2224 vha->qla_stats.input_bytes +=
2225 bsg_reply->reply_payload_rcv_len;
2226 vha->qla_stats.input_requests++;
2227 rval = EXT_STATUS_OK;
2231 case CS_DATA_OVERRUN:
2232 ql_dbg(ql_dbg_user, vha, 0x70b1,
2233 "Command completed with data overrun thread_id=%d\n",
2235 rval = EXT_STATUS_DATA_OVERRUN;
2238 case CS_DATA_UNDERRUN:
2239 ql_dbg(ql_dbg_user, vha, 0x70b2,
2240 "Command completed with data underrun thread_id=%d\n",
2242 rval = EXT_STATUS_DATA_UNDERRUN;
2244 case CS_BIDIR_RD_OVERRUN:
2245 ql_dbg(ql_dbg_user, vha, 0x70b3,
2246 "Command completed with read data overrun thread_id=%d\n",
2248 rval = EXT_STATUS_DATA_OVERRUN;
2251 case CS_BIDIR_RD_WR_OVERRUN:
2252 ql_dbg(ql_dbg_user, vha, 0x70b4,
2253 "Command completed with read and write data overrun "
2254 "thread_id=%d\n", thread_id);
2255 rval = EXT_STATUS_DATA_OVERRUN;
2258 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN:
2259 ql_dbg(ql_dbg_user, vha, 0x70b5,
2260 "Command completed with read data over and write data "
2261 "underrun thread_id=%d\n", thread_id);
2262 rval = EXT_STATUS_DATA_OVERRUN;
2265 case CS_BIDIR_RD_UNDERRUN:
2266 ql_dbg(ql_dbg_user, vha, 0x70b6,
2267 "Command completed with read data underrun "
2268 "thread_id=%d\n", thread_id);
2269 rval = EXT_STATUS_DATA_UNDERRUN;
2272 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN:
2273 ql_dbg(ql_dbg_user, vha, 0x70b7,
2274 "Command completed with read data under and write data "
2275 "overrun thread_id=%d\n", thread_id);
2276 rval = EXT_STATUS_DATA_UNDERRUN;
2279 case CS_BIDIR_RD_WR_UNDERRUN:
2280 ql_dbg(ql_dbg_user, vha, 0x70b8,
2281 "Command completed with read and write data underrun "
2282 "thread_id=%d\n", thread_id);
2283 rval = EXT_STATUS_DATA_UNDERRUN;
2287 ql_dbg(ql_dbg_user, vha, 0x70b9,
2288 "Command completed with data DMA error thread_id=%d\n",
2290 rval = EXT_STATUS_DMA_ERR;
2294 ql_dbg(ql_dbg_user, vha, 0x70ba,
2295 "Command completed with timeout thread_id=%d\n",
2297 rval = EXT_STATUS_TIMEOUT;
2300 ql_dbg(ql_dbg_user, vha, 0x70bb,
2301 "Command completed with completion status=0x%x "
2302 "thread_id=%d\n", comp_status, thread_id);
2303 rval = EXT_STATUS_ERR;
2306 bsg_reply->reply_payload_rcv_len = 0;
2309 /* Return the vendor specific reply to API */
2310 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
2311 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2312 /* Always return DID_OK, bsg will send the vendor specific response
2313 * in this case only */
2314 sp->done(sp, DID_OK << 6);
2319 * qla2x00_status_entry() - Process a Status IOCB entry.
2320 * @ha: SCSI driver HA context
2321 * @pkt: Entry pointer
2324 qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
2328 struct scsi_cmnd *cp;
2330 struct sts_entry_24xx *sts24;
2331 uint16_t comp_status;
2332 uint16_t scsi_status;
2334 uint8_t lscsi_status;
2336 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
2338 uint8_t *rsp_info, *sense_data;
2339 struct qla_hw_data *ha = vha->hw;
2342 struct req_que *req;
2345 uint16_t state_flags = 0;
2346 uint16_t retry_delay = 0;
2348 sts = (sts_entry_t *) pkt;
2349 sts24 = (struct sts_entry_24xx *) pkt;
2350 if (IS_FWI2_CAPABLE(ha)) {
2351 comp_status = le16_to_cpu(sts24->comp_status);
2352 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
2353 state_flags = le16_to_cpu(sts24->state_flags);
2355 comp_status = le16_to_cpu(sts->comp_status);
2356 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
2358 handle = (uint32_t) LSW(sts->handle);
2359 que = MSW(sts->handle);
2360 req = ha->req_q_map[que];
2362 /* Check for invalid queue pointer */
2364 que >= find_first_zero_bit(ha->req_qid_map, ha->max_req_queues)) {
2365 ql_dbg(ql_dbg_io, vha, 0x3059,
2366 "Invalid status handle (0x%x): Bad req pointer. req=%p, "
2367 "que=%u.\n", sts->handle, req, que);
2371 /* Validate handle. */
2372 if (handle < req->num_outstanding_cmds) {
2373 sp = req->outstanding_cmds[handle];
2375 ql_dbg(ql_dbg_io, vha, 0x3075,
2376 "%s(%ld): Already returned command for status handle (0x%x).\n",
2377 __func__, vha->host_no, sts->handle);
2381 ql_dbg(ql_dbg_io, vha, 0x3017,
2382 "Invalid status handle, out of range (0x%x).\n",
2385 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
2386 if (IS_P3P_TYPE(ha))
2387 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2389 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2390 qla2xxx_wake_dpc(vha);
2395 if (sp->cmd_type != TYPE_SRB) {
2396 req->outstanding_cmds[handle] = NULL;
2397 ql_dbg(ql_dbg_io, vha, 0x3015,
2398 "Unknown sp->cmd_type %x %p).\n",
2403 /* NVME completion. */
2404 if (sp->type == SRB_NVME_CMD) {
2405 qla24xx_nvme_iocb_entry(vha, req, pkt);
2409 if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) {
2410 qla25xx_process_bidir_status_iocb(vha, pkt, req, handle);
2414 /* Task Management completion. */
2415 if (sp->type == SRB_TM_CMD) {
2416 qla24xx_tm_iocb_entry(vha, req, pkt);
2420 /* Fast path completion. */
2421 if (comp_status == CS_COMPLETE && scsi_status == 0) {
2422 qla2x00_process_completed_request(vha, req, handle);
2427 req->outstanding_cmds[handle] = NULL;
2428 cp = GET_CMD_SP(sp);
2430 ql_dbg(ql_dbg_io, vha, 0x3018,
2431 "Command already returned (0x%x/%p).\n",
2437 lscsi_status = scsi_status & STATUS_MASK;
2439 fcport = sp->fcport;
2442 sense_len = par_sense_len = rsp_info_len = resid_len =
2444 if (IS_FWI2_CAPABLE(ha)) {
2445 if (scsi_status & SS_SENSE_LEN_VALID)
2446 sense_len = le32_to_cpu(sts24->sense_len);
2447 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2448 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
2449 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
2450 resid_len = le32_to_cpu(sts24->rsp_residual_count);
2451 if (comp_status == CS_DATA_UNDERRUN)
2452 fw_resid_len = le32_to_cpu(sts24->residual_len);
2453 rsp_info = sts24->data;
2454 sense_data = sts24->data;
2455 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
2456 ox_id = le16_to_cpu(sts24->ox_id);
2457 par_sense_len = sizeof(sts24->data);
2458 /* Valid values of the retry delay timer are 0x1-0xffef */
2459 if (sts24->retry_delay > 0 && sts24->retry_delay < 0xfff1) {
2460 retry_delay = sts24->retry_delay & 0x3fff;
2461 ql_dbg(ql_dbg_io, sp->vha, 0x3033,
2462 "%s: scope=%#x retry_delay=%#x\n", __func__,
2463 sts24->retry_delay >> 14, retry_delay);
2466 if (scsi_status & SS_SENSE_LEN_VALID)
2467 sense_len = le16_to_cpu(sts->req_sense_length);
2468 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2469 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
2470 resid_len = le32_to_cpu(sts->residual_length);
2471 rsp_info = sts->rsp_info;
2472 sense_data = sts->req_sense_data;
2473 par_sense_len = sizeof(sts->req_sense_data);
2476 /* Check for any FCP transport errors. */
2477 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
2478 /* Sense data lies beyond any FCP RESPONSE data. */
2479 if (IS_FWI2_CAPABLE(ha)) {
2480 sense_data += rsp_info_len;
2481 par_sense_len -= rsp_info_len;
2483 if (rsp_info_len > 3 && rsp_info[3]) {
2484 ql_dbg(ql_dbg_io, fcport->vha, 0x3019,
2485 "FCP I/O protocol failure (0x%x/0x%x).\n",
2486 rsp_info_len, rsp_info[3]);
2488 res = DID_BUS_BUSY << 16;
2493 /* Check for overrun. */
2494 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
2495 scsi_status & SS_RESIDUAL_OVER)
2496 comp_status = CS_DATA_OVERRUN;
2499 * Check retry_delay_timer value if we receive a busy or
2502 if (lscsi_status == SAM_STAT_TASK_SET_FULL ||
2503 lscsi_status == SAM_STAT_BUSY)
2504 qla2x00_set_retry_delay_timestamp(fcport, retry_delay);
2507 * Based on Host and scsi status generate status code for Linux
2509 switch (comp_status) {
2512 if (scsi_status == 0) {
2516 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
2518 scsi_set_resid(cp, resid);
2520 if (!lscsi_status &&
2521 ((unsigned)(scsi_bufflen(cp) - resid) <
2523 ql_dbg(ql_dbg_io, fcport->vha, 0x301a,
2524 "Mid-layer underflow detected (0x%x of 0x%x bytes).\n",
2525 resid, scsi_bufflen(cp));
2527 res = DID_ERROR << 16;
2531 res = DID_OK << 16 | lscsi_status;
2533 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
2534 ql_dbg(ql_dbg_io, fcport->vha, 0x301b,
2535 "QUEUE FULL detected.\n");
2539 if (lscsi_status != SS_CHECK_CONDITION)
2542 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
2543 if (!(scsi_status & SS_SENSE_LEN_VALID))
2546 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
2550 case CS_DATA_UNDERRUN:
2551 /* Use F/W calculated residual length. */
2552 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
2553 scsi_set_resid(cp, resid);
2554 if (scsi_status & SS_RESIDUAL_UNDER) {
2555 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
2556 ql_dbg(ql_dbg_io, fcport->vha, 0x301d,
2557 "Dropped frame(s) detected (0x%x of 0x%x bytes).\n",
2558 resid, scsi_bufflen(cp));
2560 res = DID_ERROR << 16 | lscsi_status;
2561 goto check_scsi_status;
2564 if (!lscsi_status &&
2565 ((unsigned)(scsi_bufflen(cp) - resid) <
2567 ql_dbg(ql_dbg_io, fcport->vha, 0x301e,
2568 "Mid-layer underflow detected (0x%x of 0x%x bytes).\n",
2569 resid, scsi_bufflen(cp));
2571 res = DID_ERROR << 16;
2574 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
2575 lscsi_status != SAM_STAT_BUSY) {
2577 * scsi status of task set and busy are considered to be
2578 * task not completed.
2581 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
2582 "Dropped frame(s) detected (0x%x of 0x%x bytes).\n",
2583 resid, scsi_bufflen(cp));
2585 res = DID_ERROR << 16 | lscsi_status;
2586 goto check_scsi_status;
2588 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
2589 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2590 scsi_status, lscsi_status);
2593 res = DID_OK << 16 | lscsi_status;
2598 * Check to see if SCSI Status is non zero. If so report SCSI
2601 if (lscsi_status != 0) {
2602 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
2603 ql_dbg(ql_dbg_io, fcport->vha, 0x3020,
2604 "QUEUE FULL detected.\n");
2608 if (lscsi_status != SS_CHECK_CONDITION)
2611 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
2612 if (!(scsi_status & SS_SENSE_LEN_VALID))
2615 qla2x00_handle_sense(sp, sense_data, par_sense_len,
2616 sense_len, rsp, res);
2620 case CS_PORT_LOGGED_OUT:
2621 case CS_PORT_CONFIG_CHG:
2624 case CS_PORT_UNAVAILABLE:
2629 * We are going to have the fc class block the rport
2630 * while we try to recover so instruct the mid layer
2631 * to requeue until the class decides how to handle this.
2633 res = DID_TRANSPORT_DISRUPTED << 16;
2635 if (comp_status == CS_TIMEOUT) {
2636 if (IS_FWI2_CAPABLE(ha))
2638 else if ((le16_to_cpu(sts->status_flags) &
2639 SF_LOGOUT_SENT) == 0)
2643 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2644 ql_dbg(ql_dbg_disc, fcport->vha, 0x3021,
2645 "Port to be marked lost on fcport=%02x%02x%02x, current "
2646 "port state= %s comp_status %x.\n", fcport->d_id.b.domain,
2647 fcport->d_id.b.area, fcport->d_id.b.al_pa,
2648 port_state_str[atomic_read(&fcport->state)],
2651 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
2652 qlt_schedule_sess_for_deletion_lock(fcport);
2658 res = DID_RESET << 16;
2662 logit = qla2x00_handle_dif_error(sp, sts24);
2667 res = DID_ERROR << 16;
2669 if (!IS_PI_SPLIT_DET_CAPABLE(ha))
2672 if (state_flags & BIT_4)
2673 scmd_printk(KERN_WARNING, cp,
2674 "Unsupported device '%s' found.\n",
2675 cp->device->vendor);
2679 res = DID_ERROR << 16;
2685 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
2686 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%llu "
2687 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
2688 "rsp_info=0x%x resid=0x%x fw_resid=0x%x sp=%p cp=%p.\n",
2689 comp_status, scsi_status, res, vha->host_no,
2690 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
2691 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
2692 cp->cmnd, scsi_bufflen(cp), rsp_info_len,
2693 resid_len, fw_resid_len, sp, cp);
2695 if (rsp->status_srb == NULL)
2700 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2701 * @ha: SCSI driver HA context
2702 * @pkt: Entry pointer
2704 * Extended sense data.
2707 qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
2709 uint8_t sense_sz = 0;
2710 struct qla_hw_data *ha = rsp->hw;
2711 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
2712 srb_t *sp = rsp->status_srb;
2713 struct scsi_cmnd *cp;
2717 if (!sp || !GET_CMD_SENSE_LEN(sp))
2720 sense_len = GET_CMD_SENSE_LEN(sp);
2721 sense_ptr = GET_CMD_SENSE_PTR(sp);
2723 cp = GET_CMD_SP(sp);
2725 ql_log(ql_log_warn, vha, 0x3025,
2726 "cmd is NULL: already returned to OS (sp=%p).\n", sp);
2728 rsp->status_srb = NULL;
2732 if (sense_len > sizeof(pkt->data))
2733 sense_sz = sizeof(pkt->data);
2735 sense_sz = sense_len;
2737 /* Move sense data. */
2738 if (IS_FWI2_CAPABLE(ha))
2739 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
2740 memcpy(sense_ptr, pkt->data, sense_sz);
2741 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
2742 sense_ptr, sense_sz);
2744 sense_len -= sense_sz;
2745 sense_ptr += sense_sz;
2747 SET_CMD_SENSE_PTR(sp, sense_ptr);
2748 SET_CMD_SENSE_LEN(sp, sense_len);
2750 /* Place command on done queue. */
2751 if (sense_len == 0) {
2752 rsp->status_srb = NULL;
2753 sp->done(sp, cp->result);
2758 * qla2x00_error_entry() - Process an error entry.
2759 * @ha: SCSI driver HA context
2760 * @pkt: Entry pointer
2761 * return : 1=allow further error analysis. 0=no additional error analysis.
2764 qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
2767 struct qla_hw_data *ha = vha->hw;
2768 const char func[] = "ERROR-IOCB";
2769 uint16_t que = MSW(pkt->handle);
2770 struct req_que *req = NULL;
2771 int res = DID_ERROR << 16;
2773 ql_dbg(ql_dbg_async, vha, 0x502a,
2774 "iocb type %xh with error status %xh, handle %xh, rspq id %d\n",
2775 pkt->entry_type, pkt->entry_status, pkt->handle, rsp->id);
2777 if (que >= ha->max_req_queues || !ha->req_q_map[que])
2780 req = ha->req_q_map[que];
2782 if (pkt->entry_status & RF_BUSY)
2783 res = DID_BUS_BUSY << 16;
2785 if ((pkt->handle & ~QLA_TGT_HANDLE_MASK) == QLA_TGT_SKIP_HANDLE)
2788 switch (pkt->entry_type) {
2789 case NOTIFY_ACK_TYPE:
2791 case STATUS_CONT_TYPE:
2792 case LOGINOUT_PORT_IOCB_TYPE:
2795 case ABORT_IOCB_TYPE:
2798 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2805 case ABTS_RESP_24XX:
2811 ql_log(ql_log_warn, vha, 0x5030,
2812 "Error entry - invalid handle/queue (%04x).\n", que);
2817 * qla24xx_mbx_completion() - Process mailbox command completions.
2818 * @ha: SCSI driver HA context
2819 * @mb0: Mailbox0 register
2822 qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
2826 uint16_t __iomem *wptr;
2827 struct qla_hw_data *ha = vha->hw;
2828 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2830 /* Read all mbox registers? */
2831 WARN_ON_ONCE(ha->mbx_count > 32);
2832 mboxes = (1ULL << ha->mbx_count) - 1;
2834 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n");
2836 mboxes = ha->mcp->in_mb;
2838 /* Load return mailbox registers. */
2839 ha->flags.mbox_int = 1;
2840 ha->mailbox_out[0] = mb0;
2842 wptr = (uint16_t __iomem *)®->mailbox1;
2844 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
2846 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2854 qla24xx_abort_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
2855 struct abort_entry_24xx *pkt)
2857 const char func[] = "ABT_IOCB";
2859 struct srb_iocb *abt;
2861 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2865 abt = &sp->u.iocb_cmd;
2866 abt->u.abt.comp_status = le16_to_cpu(pkt->nport_handle);
2870 void qla24xx_nvme_ls4_iocb(struct scsi_qla_host *vha,
2871 struct pt_ls4_request *pkt, struct req_que *req)
2874 const char func[] = "LS4_IOCB";
2875 uint16_t comp_status;
2877 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2881 comp_status = le16_to_cpu(pkt->status);
2882 sp->done(sp, comp_status);
2886 * qla24xx_process_response_queue() - Process response queue entries.
2887 * @ha: SCSI driver HA context
2889 void qla24xx_process_response_queue(struct scsi_qla_host *vha,
2890 struct rsp_que *rsp)
2892 struct sts_entry_24xx *pkt;
2893 struct qla_hw_data *ha = vha->hw;
2895 if (!ha->flags.fw_started)
2898 if (rsp->qpair->cpuid != smp_processor_id())
2899 qla_cpu_update(rsp->qpair, smp_processor_id());
2901 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2902 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
2905 if (rsp->ring_index == rsp->length) {
2906 rsp->ring_index = 0;
2907 rsp->ring_ptr = rsp->ring;
2912 if (pkt->entry_status != 0) {
2913 if (qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt))
2916 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2922 switch (pkt->entry_type) {
2924 qla2x00_status_entry(vha, rsp, pkt);
2926 case STATUS_CONT_TYPE:
2927 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
2929 case VP_RPT_ID_IOCB_TYPE:
2930 qla24xx_report_id_acquisition(vha,
2931 (struct vp_rpt_id_entry_24xx *)pkt);
2933 case LOGINOUT_PORT_IOCB_TYPE:
2934 qla24xx_logio_entry(vha, rsp->req,
2935 (struct logio_entry_24xx *)pkt);
2938 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
2941 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2943 case ABTS_RECV_24XX:
2944 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
2945 /* ensure that the ATIO queue is empty */
2946 qlt_handle_abts_recv(vha, rsp,
2951 qlt_24xx_process_atio_queue(vha, 1);
2953 case ABTS_RESP_24XX:
2956 qlt_response_pkt_all_vps(vha, rsp, (response_t *)pkt);
2958 case PT_LS4_REQUEST:
2959 qla24xx_nvme_ls4_iocb(vha, (struct pt_ls4_request *)pkt,
2962 case NOTIFY_ACK_TYPE:
2963 if (pkt->handle == QLA_TGT_SKIP_HANDLE)
2964 qlt_response_pkt_all_vps(vha, rsp,
2967 qla24xxx_nack_iocb_entry(vha, rsp->req,
2968 (struct nack_to_isp *)pkt);
2971 /* Do nothing in this case, this check is to prevent it
2972 * from falling into default case
2975 case ABORT_IOCB_TYPE:
2976 qla24xx_abort_iocb_entry(vha, rsp->req,
2977 (struct abort_entry_24xx *)pkt);
2980 qla24xx_mbx_iocb_entry(vha, rsp->req,
2981 (struct mbx_24xx_entry *)pkt);
2984 /* Type Not Supported. */
2985 ql_dbg(ql_dbg_async, vha, 0x5042,
2986 "Received unknown response pkt type %x "
2987 "entry status=%x.\n",
2988 pkt->entry_type, pkt->entry_status);
2991 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2995 /* Adjust ring index */
2996 if (IS_P3P_TYPE(ha)) {
2997 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2998 WRT_REG_DWORD(®->rsp_q_out[0], rsp->ring_index);
3000 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
3005 qla2xxx_check_risc_status(scsi_qla_host_t *vha)
3009 struct qla_hw_data *ha = vha->hw;
3010 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3012 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3017 WRT_REG_DWORD(®->iobase_addr, 0x7C00);
3018 RD_REG_DWORD(®->iobase_addr);
3019 WRT_REG_DWORD(®->iobase_window, 0x0001);
3020 for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
3021 rval == QLA_SUCCESS; cnt--) {
3023 WRT_REG_DWORD(®->iobase_window, 0x0001);
3026 rval = QLA_FUNCTION_TIMEOUT;
3028 if (rval == QLA_SUCCESS)
3032 WRT_REG_DWORD(®->iobase_window, 0x0003);
3033 for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
3034 rval == QLA_SUCCESS; cnt--) {
3036 WRT_REG_DWORD(®->iobase_window, 0x0003);
3039 rval = QLA_FUNCTION_TIMEOUT;
3041 if (rval != QLA_SUCCESS)
3045 if (RD_REG_DWORD(®->iobase_c8) & BIT_3)
3046 ql_log(ql_log_info, vha, 0x504c,
3047 "Additional code -- 0x55AA.\n");
3050 WRT_REG_DWORD(®->iobase_window, 0x0000);
3051 RD_REG_DWORD(®->iobase_window);
3055 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
3057 * @dev_id: SCSI driver HA context
3059 * Called by system whenever the host adapter generates an interrupt.
3061 * Returns handled flag.
3064 qla24xx_intr_handler(int irq, void *dev_id)
3066 scsi_qla_host_t *vha;
3067 struct qla_hw_data *ha;
3068 struct device_reg_24xx __iomem *reg;
3074 struct rsp_que *rsp;
3075 unsigned long flags;
3077 rsp = (struct rsp_que *) dev_id;
3079 ql_log(ql_log_info, NULL, 0x5059,
3080 "%s: NULL response queue pointer.\n", __func__);
3085 reg = &ha->iobase->isp24;
3088 if (unlikely(pci_channel_offline(ha->pdev)))
3091 spin_lock_irqsave(&ha->hardware_lock, flags);
3092 vha = pci_get_drvdata(ha->pdev);
3093 for (iter = 50; iter--; ) {
3094 stat = RD_REG_DWORD(®->host_status);
3095 if (qla2x00_check_reg32_for_disconnect(vha, stat))
3097 if (stat & HSRX_RISC_PAUSED) {
3098 if (unlikely(pci_channel_offline(ha->pdev)))
3101 hccr = RD_REG_DWORD(®->hccr);
3103 ql_log(ql_log_warn, vha, 0x504b,
3104 "RISC paused -- HCCR=%x, Dumping firmware.\n",
3107 qla2xxx_check_risc_status(vha);
3109 ha->isp_ops->fw_dump(vha, 1);
3110 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3112 } else if ((stat & HSRX_RISC_INT) == 0)
3115 switch (stat & 0xff) {
3116 case INTR_ROM_MB_SUCCESS:
3117 case INTR_ROM_MB_FAILED:
3118 case INTR_MB_SUCCESS:
3119 case INTR_MB_FAILED:
3120 qla24xx_mbx_completion(vha, MSW(stat));
3121 status |= MBX_INTERRUPT;
3124 case INTR_ASYNC_EVENT:
3126 mb[1] = RD_REG_WORD(®->mailbox1);
3127 mb[2] = RD_REG_WORD(®->mailbox2);
3128 mb[3] = RD_REG_WORD(®->mailbox3);
3129 qla2x00_async_event(vha, rsp, mb);
3131 case INTR_RSP_QUE_UPDATE:
3132 case INTR_RSP_QUE_UPDATE_83XX:
3133 qla24xx_process_response_queue(vha, rsp);
3135 case INTR_ATIO_QUE_UPDATE:{
3136 unsigned long flags2;
3137 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
3138 qlt_24xx_process_atio_queue(vha, 1);
3139 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
3142 case INTR_ATIO_RSP_QUE_UPDATE: {
3143 unsigned long flags2;
3144 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
3145 qlt_24xx_process_atio_queue(vha, 1);
3146 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
3148 qla24xx_process_response_queue(vha, rsp);
3152 ql_dbg(ql_dbg_async, vha, 0x504f,
3153 "Unrecognized interrupt type (%d).\n", stat * 0xff);
3156 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
3157 RD_REG_DWORD_RELAXED(®->hccr);
3158 if (unlikely(IS_QLA83XX(ha) && (ha->pdev->revision == 1)))
3161 qla2x00_handle_mbx_completion(ha, status);
3162 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3168 qla24xx_msix_rsp_q(int irq, void *dev_id)
3170 struct qla_hw_data *ha;
3171 struct rsp_que *rsp;
3172 struct device_reg_24xx __iomem *reg;
3173 struct scsi_qla_host *vha;
3174 unsigned long flags;
3176 rsp = (struct rsp_que *) dev_id;
3178 ql_log(ql_log_info, NULL, 0x505a,
3179 "%s: NULL response queue pointer.\n", __func__);
3183 reg = &ha->iobase->isp24;
3185 spin_lock_irqsave(&ha->hardware_lock, flags);
3187 vha = pci_get_drvdata(ha->pdev);
3188 qla24xx_process_response_queue(vha, rsp);
3189 if (!ha->flags.disable_msix_handshake) {
3190 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
3191 RD_REG_DWORD_RELAXED(®->hccr);
3193 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3199 qla24xx_msix_default(int irq, void *dev_id)
3201 scsi_qla_host_t *vha;
3202 struct qla_hw_data *ha;
3203 struct rsp_que *rsp;
3204 struct device_reg_24xx __iomem *reg;
3209 unsigned long flags;
3211 rsp = (struct rsp_que *) dev_id;
3213 ql_log(ql_log_info, NULL, 0x505c,
3214 "%s: NULL response queue pointer.\n", __func__);
3218 reg = &ha->iobase->isp24;
3221 spin_lock_irqsave(&ha->hardware_lock, flags);
3222 vha = pci_get_drvdata(ha->pdev);
3224 stat = RD_REG_DWORD(®->host_status);
3225 if (qla2x00_check_reg32_for_disconnect(vha, stat))
3227 if (stat & HSRX_RISC_PAUSED) {
3228 if (unlikely(pci_channel_offline(ha->pdev)))
3231 hccr = RD_REG_DWORD(®->hccr);
3233 ql_log(ql_log_info, vha, 0x5050,
3234 "RISC paused -- HCCR=%x, Dumping firmware.\n",
3237 qla2xxx_check_risc_status(vha);
3239 ha->isp_ops->fw_dump(vha, 1);
3240 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3242 } else if ((stat & HSRX_RISC_INT) == 0)
3245 switch (stat & 0xff) {
3246 case INTR_ROM_MB_SUCCESS:
3247 case INTR_ROM_MB_FAILED:
3248 case INTR_MB_SUCCESS:
3249 case INTR_MB_FAILED:
3250 qla24xx_mbx_completion(vha, MSW(stat));
3251 status |= MBX_INTERRUPT;
3254 case INTR_ASYNC_EVENT:
3256 mb[1] = RD_REG_WORD(®->mailbox1);
3257 mb[2] = RD_REG_WORD(®->mailbox2);
3258 mb[3] = RD_REG_WORD(®->mailbox3);
3259 qla2x00_async_event(vha, rsp, mb);
3261 case INTR_RSP_QUE_UPDATE:
3262 case INTR_RSP_QUE_UPDATE_83XX:
3263 qla24xx_process_response_queue(vha, rsp);
3265 case INTR_ATIO_QUE_UPDATE:{
3266 unsigned long flags2;
3267 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
3268 qlt_24xx_process_atio_queue(vha, 1);
3269 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
3272 case INTR_ATIO_RSP_QUE_UPDATE: {
3273 unsigned long flags2;
3274 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
3275 qlt_24xx_process_atio_queue(vha, 1);
3276 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
3278 qla24xx_process_response_queue(vha, rsp);
3282 ql_dbg(ql_dbg_async, vha, 0x5051,
3283 "Unrecognized interrupt type (%d).\n", stat & 0xff);
3286 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
3288 qla2x00_handle_mbx_completion(ha, status);
3289 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3295 qla2xxx_msix_rsp_q(int irq, void *dev_id)
3297 struct qla_hw_data *ha;
3298 struct qla_qpair *qpair;
3299 struct device_reg_24xx __iomem *reg;
3300 unsigned long flags;
3304 ql_log(ql_log_info, NULL, 0x505b,
3305 "%s: NULL response queue pointer.\n", __func__);
3310 /* Clear the interrupt, if enabled, for this response queue */
3311 if (unlikely(!ha->flags.disable_msix_handshake)) {
3312 reg = &ha->iobase->isp24;
3313 spin_lock_irqsave(&ha->hardware_lock, flags);
3314 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
3315 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3318 queue_work(ha->wq, &qpair->q_work);
3323 /* Interrupt handling helpers. */
3325 struct qla_init_msix_entry {
3327 irq_handler_t handler;
3330 static const struct qla_init_msix_entry msix_entries[] = {
3331 { "default", qla24xx_msix_default },
3332 { "rsp_q", qla24xx_msix_rsp_q },
3333 { "atio_q", qla83xx_msix_atio_q },
3334 { "qpair_multiq", qla2xxx_msix_rsp_q },
3337 static const struct qla_init_msix_entry qla82xx_msix_entries[] = {
3338 { "qla2xxx (default)", qla82xx_msix_default },
3339 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
3343 qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
3346 struct qla_msix_entry *qentry;
3347 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
3348 int min_vecs = QLA_BASE_VECTORS;
3349 struct irq_affinity desc = {
3350 .pre_vectors = QLA_BASE_VECTORS,
3353 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
3358 if (USER_CTRL_IRQ(ha)) {
3359 /* user wants to control IRQ setting for target mode */
3360 ret = pci_alloc_irq_vectors(ha->pdev, min_vecs,
3361 ha->msix_count, PCI_IRQ_MSIX);
3363 ret = pci_alloc_irq_vectors_affinity(ha->pdev, min_vecs,
3364 ha->msix_count, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY,
3368 ql_log(ql_log_fatal, vha, 0x00c7,
3369 "MSI-X: Failed to enable support, "
3370 "giving up -- %d/%d.\n",
3371 ha->msix_count, ret);
3373 } else if (ret < ha->msix_count) {
3374 ql_log(ql_log_info, vha, 0x00c6,
3375 "MSI-X: Using %d vectors\n", ret);
3376 ha->msix_count = ret;
3377 /* Recalculate queue values */
3378 if (ha->mqiobase && ql2xmqsupport) {
3379 ha->max_req_queues = ha->msix_count - 1;
3381 /* ATIOQ needs 1 vector. That's 1 less QPair */
3382 if (QLA_TGT_MODE_ENABLED())
3383 ha->max_req_queues--;
3385 ha->max_rsp_queues = ha->max_req_queues;
3387 ha->max_qpairs = ha->max_req_queues - 1;
3388 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0190,
3389 "Adjusted Max no of queues pairs: %d.\n", ha->max_qpairs);
3392 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
3393 ha->msix_count, GFP_KERNEL);
3394 if (!ha->msix_entries) {
3395 ql_log(ql_log_fatal, vha, 0x00c8,
3396 "Failed to allocate memory for ha->msix_entries.\n");
3400 ha->flags.msix_enabled = 1;
3402 for (i = 0; i < ha->msix_count; i++) {
3403 qentry = &ha->msix_entries[i];
3404 qentry->vector = pci_irq_vector(ha->pdev, i);
3406 qentry->have_irq = 0;
3408 qentry->handle = NULL;
3411 /* Enable MSI-X vectors for the base queue */
3412 for (i = 0; i < QLA_BASE_VECTORS; i++) {
3413 qentry = &ha->msix_entries[i];
3414 qentry->handle = rsp;
3416 scnprintf(qentry->name, sizeof(qentry->name),
3417 "qla2xxx%lu_%s", vha->host_no, msix_entries[i].name);
3418 if (IS_P3P_TYPE(ha))
3419 ret = request_irq(qentry->vector,
3420 qla82xx_msix_entries[i].handler,
3421 0, qla82xx_msix_entries[i].name, rsp);
3423 ret = request_irq(qentry->vector,
3424 msix_entries[i].handler,
3425 0, qentry->name, rsp);
3427 goto msix_register_fail;
3428 qentry->have_irq = 1;
3433 * If target mode is enable, also request the vector for the ATIO
3436 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
3437 qentry = &ha->msix_entries[QLA_ATIO_VECTOR];
3439 qentry->handle = rsp;
3440 scnprintf(qentry->name, sizeof(qentry->name),
3441 "qla2xxx%lu_%s", vha->host_no,
3442 msix_entries[QLA_ATIO_VECTOR].name);
3444 ret = request_irq(qentry->vector,
3445 msix_entries[QLA_ATIO_VECTOR].handler,
3446 0, qentry->name, rsp);
3447 qentry->have_irq = 1;
3452 ql_log(ql_log_fatal, vha, 0x00cb,
3453 "MSI-X: unable to register handler -- %x/%d.\n",
3454 qentry->vector, ret);
3455 qla2x00_free_irqs(vha);
3460 /* Enable MSI-X vector for response queue update for queue 0 */
3461 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3462 if (ha->msixbase && ha->mqiobase &&
3463 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1 ||
3468 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1 ||
3471 ql_dbg(ql_dbg_multiq, vha, 0xc005,
3472 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3473 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
3474 ql_dbg(ql_dbg_init, vha, 0x0055,
3475 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3476 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
3482 pci_free_irq_vectors(ha->pdev);
3487 qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
3489 int ret = QLA_FUNCTION_FAILED;
3490 device_reg_t *reg = ha->iobase;
3491 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
3493 /* If possible, enable MSI-X. */
3494 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
3495 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLAFX00(ha) &&
3499 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
3500 (ha->pdev->subsystem_device == 0x7040 ||
3501 ha->pdev->subsystem_device == 0x7041 ||
3502 ha->pdev->subsystem_device == 0x1705)) {
3503 ql_log(ql_log_warn, vha, 0x0034,
3504 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
3505 ha->pdev->subsystem_vendor,
3506 ha->pdev->subsystem_device);
3510 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
3511 ql_log(ql_log_warn, vha, 0x0035,
3512 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
3513 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
3517 ret = qla24xx_enable_msix(ha, rsp);
3519 ql_dbg(ql_dbg_init, vha, 0x0036,
3520 "MSI-X: Enabled (0x%X, 0x%X).\n",
3521 ha->chip_revision, ha->fw_attributes);
3522 goto clear_risc_ints;
3527 ql_log(ql_log_info, vha, 0x0037,
3528 "Falling back-to MSI mode -- ret=%d.\n", ret);
3530 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
3531 !IS_QLA8001(ha) && !IS_P3P_TYPE(ha) && !IS_QLAFX00(ha) &&
3535 ret = pci_alloc_irq_vectors(ha->pdev, 1, 1, PCI_IRQ_MSI);
3537 ql_dbg(ql_dbg_init, vha, 0x0038,
3539 ha->flags.msi_enabled = 1;
3541 ql_log(ql_log_warn, vha, 0x0039,
3542 "Falling back-to INTa mode -- ret=%d.\n", ret);
3545 /* Skip INTx on ISP82xx. */
3546 if (!ha->flags.msi_enabled && IS_QLA82XX(ha))
3547 return QLA_FUNCTION_FAILED;
3549 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
3550 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
3551 QLA2XXX_DRIVER_NAME, rsp);
3553 ql_log(ql_log_warn, vha, 0x003a,
3554 "Failed to reserve interrupt %d already in use.\n",
3557 } else if (!ha->flags.msi_enabled) {
3558 ql_dbg(ql_dbg_init, vha, 0x0125,
3559 "INTa mode: Enabled.\n");
3560 ha->flags.mr_intr_valid = 1;
3564 if (IS_FWI2_CAPABLE(ha) || IS_QLAFX00(ha))
3567 spin_lock_irq(&ha->hardware_lock);
3568 WRT_REG_WORD(®->isp.semaphore, 0);
3569 spin_unlock_irq(&ha->hardware_lock);
3576 qla2x00_free_irqs(scsi_qla_host_t *vha)
3578 struct qla_hw_data *ha = vha->hw;
3579 struct rsp_que *rsp;
3580 struct qla_msix_entry *qentry;
3584 * We need to check that ha->rsp_q_map is valid in case we are called
3585 * from a probe failure context.
3587 if (!ha->rsp_q_map || !ha->rsp_q_map[0])
3589 rsp = ha->rsp_q_map[0];
3591 if (ha->flags.msix_enabled) {
3592 for (i = 0; i < ha->msix_count; i++) {
3593 qentry = &ha->msix_entries[i];
3594 if (qentry->have_irq) {
3595 irq_set_affinity_notifier(qentry->vector, NULL);
3596 free_irq(pci_irq_vector(ha->pdev, i), qentry->handle);
3599 kfree(ha->msix_entries);
3600 ha->msix_entries = NULL;
3601 ha->flags.msix_enabled = 0;
3602 ql_dbg(ql_dbg_init, vha, 0x0042,
3603 "Disabled MSI-X.\n");
3605 free_irq(pci_irq_vector(ha->pdev, 0), rsp);
3609 pci_free_irq_vectors(ha->pdev);
3612 int qla25xx_request_irq(struct qla_hw_data *ha, struct qla_qpair *qpair,
3613 struct qla_msix_entry *msix, int vector_type)
3615 const struct qla_init_msix_entry *intr = &msix_entries[vector_type];
3616 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
3619 scnprintf(msix->name, sizeof(msix->name),
3620 "qla2xxx%lu_qpair%d", vha->host_no, qpair->id);
3621 ret = request_irq(msix->vector, intr->handler, 0, msix->name, qpair);
3623 ql_log(ql_log_fatal, vha, 0x00e6,
3624 "MSI-X: Unable to register handler -- %x/%d.\n",
3629 msix->handle = qpair;