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 *,
21 static void qla_irq_affinity_notify(struct irq_affinity_notify *,
23 static void qla_irq_affinity_release(struct kref *);
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 "
440 } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
441 ql_log(ql_log_fatal, vha, 0x5064,
442 "Recoverable Fatal error: Chip reset "
444 qla83xx_schedule_work(vha,
445 QLA83XX_NIC_CORE_RESET);
446 } else if (err_level == ERR_LEVEL_UNRECOVERABLE_FATAL) {
447 ql_log(ql_log_fatal, vha, 0x5065,
448 "Unrecoverable Fatal error: Set FAILED "
449 "state, reboot required.\n");
450 qla83xx_schedule_work(vha,
451 QLA83XX_NIC_CORE_UNRECOVERABLE);
455 if (mb[1] & IDC_NIC_FW_REPORTED_FAILURE) {
456 uint16_t peg_fw_state, nw_interface_link_up;
457 uint16_t nw_interface_signal_detect, sfp_status;
458 uint16_t htbt_counter, htbt_monitor_enable;
459 uint16_t sfp_additonal_info, sfp_multirate;
460 uint16_t sfp_tx_fault, link_speed, dcbx_status;
463 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
464 * - PEG-to-FC Status Register:
465 * (LSW = mb[2], MSW = mb[6])
466 * Bits 0-7 = Peg-Firmware state
467 * Bit 8 = N/W Interface Link-up
468 * Bit 9 = N/W Interface signal detected
469 * Bits 10-11 = SFP Status
470 * SFP Status 0x0 = SFP+ transceiver not expected
471 * SFP Status 0x1 = SFP+ transceiver not present
472 * SFP Status 0x2 = SFP+ transceiver invalid
473 * SFP Status 0x3 = SFP+ transceiver present and
475 * Bits 12-14 = Heartbeat Counter
476 * Bit 15 = Heartbeat Monitor Enable
477 * Bits 16-17 = SFP Additional Info
478 * SFP info 0x0 = Unregocnized transceiver for
480 * SFP info 0x1 = SFP+ brand validation failed
481 * SFP info 0x2 = SFP+ speed validation failed
482 * SFP info 0x3 = SFP+ access error
483 * Bit 18 = SFP Multirate
484 * Bit 19 = SFP Tx Fault
485 * Bits 20-22 = Link Speed
486 * Bits 23-27 = Reserved
487 * Bits 28-30 = DCBX Status
488 * DCBX Status 0x0 = DCBX Disabled
489 * DCBX Status 0x1 = DCBX Enabled
490 * DCBX Status 0x2 = DCBX Exchange error
493 peg_fw_state = (mb[2] & 0x00ff);
494 nw_interface_link_up = ((mb[2] & 0x0100) >> 8);
495 nw_interface_signal_detect = ((mb[2] & 0x0200) >> 9);
496 sfp_status = ((mb[2] & 0x0c00) >> 10);
497 htbt_counter = ((mb[2] & 0x7000) >> 12);
498 htbt_monitor_enable = ((mb[2] & 0x8000) >> 15);
499 sfp_additonal_info = (mb[6] & 0x0003);
500 sfp_multirate = ((mb[6] & 0x0004) >> 2);
501 sfp_tx_fault = ((mb[6] & 0x0008) >> 3);
502 link_speed = ((mb[6] & 0x0070) >> 4);
503 dcbx_status = ((mb[6] & 0x7000) >> 12);
505 ql_log(ql_log_warn, vha, 0x5066,
506 "Peg-to-Fc Status Register:\n"
507 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
508 "nw_interface_signal_detect=0x%x"
509 "\nsfp_statis=0x%x.\n ", peg_fw_state,
510 nw_interface_link_up, nw_interface_signal_detect,
512 ql_log(ql_log_warn, vha, 0x5067,
513 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
514 "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ",
515 htbt_counter, htbt_monitor_enable,
516 sfp_additonal_info, sfp_multirate);
517 ql_log(ql_log_warn, vha, 0x5068,
518 "sfp_tx_fault=0x%x, link_state=0x%x, "
519 "dcbx_status=0x%x.\n", sfp_tx_fault, link_speed,
522 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
525 if (mb[1] & IDC_HEARTBEAT_FAILURE) {
526 ql_log(ql_log_warn, vha, 0x5069,
527 "Heartbeat Failure encountered, chip reset "
530 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
534 if (mb[1] & IDC_DEVICE_STATE_CHANGE) {
535 ql_log(ql_log_info, vha, 0x506a,
536 "IDC Device-State changed = 0x%x.\n", mb[4]);
537 if (ha->flags.nic_core_reset_owner)
539 qla83xx_schedule_work(vha, MBA_IDC_AEN);
544 qla2x00_is_a_vp_did(scsi_qla_host_t *vha, uint32_t rscn_entry)
546 struct qla_hw_data *ha = vha->hw;
555 spin_lock_irqsave(&ha->vport_slock, flags);
556 list_for_each_entry(vp, &ha->vp_list, list) {
557 vp_did = vp->d_id.b24;
558 if (vp_did == rscn_entry) {
563 spin_unlock_irqrestore(&ha->vport_slock, flags);
568 static inline fc_port_t *
569 qla2x00_find_fcport_by_loopid(scsi_qla_host_t *vha, uint16_t loop_id)
573 list_for_each_entry(fcport, &vha->vp_fcports, list)
574 if (fcport->loop_id == loop_id)
580 * qla2x00_async_event() - Process aynchronous events.
581 * @ha: SCSI driver HA context
582 * @mb: Mailbox registers (0 - 3)
585 qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
590 struct qla_hw_data *ha = vha->hw;
591 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
592 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
593 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
594 uint32_t rscn_entry, host_pid;
596 fc_port_t *fcport = NULL;
598 /* Setup to process RIO completion. */
600 if (IS_CNA_CAPABLE(ha))
603 case MBA_SCSI_COMPLETION:
604 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
607 case MBA_CMPLT_1_16BIT:
610 mb[0] = MBA_SCSI_COMPLETION;
612 case MBA_CMPLT_2_16BIT:
616 mb[0] = MBA_SCSI_COMPLETION;
618 case MBA_CMPLT_3_16BIT:
623 mb[0] = MBA_SCSI_COMPLETION;
625 case MBA_CMPLT_4_16BIT:
629 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
631 mb[0] = MBA_SCSI_COMPLETION;
633 case MBA_CMPLT_5_16BIT:
637 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
638 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
640 mb[0] = MBA_SCSI_COMPLETION;
642 case MBA_CMPLT_2_32BIT:
643 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
644 handles[1] = le32_to_cpu(
645 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
646 RD_MAILBOX_REG(ha, reg, 6));
648 mb[0] = MBA_SCSI_COMPLETION;
655 case MBA_SCSI_COMPLETION: /* Fast Post */
656 if (!vha->flags.online)
659 for (cnt = 0; cnt < handle_cnt; cnt++)
660 qla2x00_process_completed_request(vha, rsp->req,
664 case MBA_RESET: /* Reset */
665 ql_dbg(ql_dbg_async, vha, 0x5002,
666 "Asynchronous RESET.\n");
668 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
671 case MBA_SYSTEM_ERR: /* System Error */
672 mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) ?
673 RD_REG_WORD(®24->mailbox7) : 0;
674 ql_log(ql_log_warn, vha, 0x5003,
675 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
676 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
678 ha->isp_ops->fw_dump(vha, 1);
680 if (IS_FWI2_CAPABLE(ha)) {
681 if (mb[1] == 0 && mb[2] == 0) {
682 ql_log(ql_log_fatal, vha, 0x5004,
683 "Unrecoverable Hardware Error: adapter "
684 "marked OFFLINE!\n");
685 vha->flags.online = 0;
686 vha->device_flags |= DFLG_DEV_FAILED;
688 /* Check to see if MPI timeout occurred */
689 if ((mbx & MBX_3) && (ha->port_no == 0))
690 set_bit(MPI_RESET_NEEDED,
693 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
695 } else if (mb[1] == 0) {
696 ql_log(ql_log_fatal, vha, 0x5005,
697 "Unrecoverable Hardware Error: adapter marked "
699 vha->flags.online = 0;
700 vha->device_flags |= DFLG_DEV_FAILED;
702 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
705 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
706 ql_log(ql_log_warn, vha, 0x5006,
707 "ISP Request Transfer Error (%x).\n", mb[1]);
709 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
712 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
713 ql_log(ql_log_warn, vha, 0x5007,
714 "ISP Response Transfer Error (%x).\n", mb[1]);
716 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
719 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
720 ql_dbg(ql_dbg_async, vha, 0x5008,
721 "Asynchronous WAKEUP_THRES (%x).\n", mb[1]);
724 case MBA_LOOP_INIT_ERR:
725 ql_log(ql_log_warn, vha, 0x5090,
726 "LOOP INIT ERROR (%x).\n", mb[1]);
727 ha->isp_ops->fw_dump(vha, 1);
728 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
731 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
732 ql_dbg(ql_dbg_async, vha, 0x5009,
733 "LIP occurred (%x).\n", mb[1]);
735 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
736 atomic_set(&vha->loop_state, LOOP_DOWN);
737 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
738 qla2x00_mark_all_devices_lost(vha, 1);
742 atomic_set(&vha->vp_state, VP_FAILED);
743 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
746 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
747 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
749 vha->flags.management_server_logged_in = 0;
750 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
753 case MBA_LOOP_UP: /* Loop Up Event */
754 if (IS_QLA2100(ha) || IS_QLA2200(ha))
755 ha->link_data_rate = PORT_SPEED_1GB;
757 ha->link_data_rate = mb[1];
759 ql_log(ql_log_info, vha, 0x500a,
760 "LOOP UP detected (%s Gbps).\n",
761 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
763 vha->flags.management_server_logged_in = 0;
764 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
767 case MBA_LOOP_DOWN: /* Loop Down Event */
768 mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha))
769 ? RD_REG_WORD(®24->mailbox4) : 0;
770 mbx = (IS_P3P_TYPE(ha)) ? RD_REG_WORD(®82->mailbox_out[4])
772 ql_log(ql_log_info, vha, 0x500b,
773 "LOOP DOWN detected (%x %x %x %x).\n",
774 mb[1], mb[2], mb[3], mbx);
776 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
777 atomic_set(&vha->loop_state, LOOP_DOWN);
778 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
780 * In case of loop down, restore WWPN from
781 * NVRAM in case of FA-WWPN capable ISP
782 * Restore for Physical Port only
785 if (ha->flags.fawwpn_enabled) {
786 void *wwpn = ha->init_cb->port_name;
787 memcpy(vha->port_name, wwpn, WWN_SIZE);
788 fc_host_port_name(vha->host) =
789 wwn_to_u64(vha->port_name);
790 ql_dbg(ql_dbg_init + ql_dbg_verbose,
791 vha, 0x0144, "LOOP DOWN detected,"
792 "restore WWPN %016llx\n",
793 wwn_to_u64(vha->port_name));
796 clear_bit(VP_CONFIG_OK, &vha->vp_flags);
799 vha->device_flags |= DFLG_NO_CABLE;
800 qla2x00_mark_all_devices_lost(vha, 1);
804 atomic_set(&vha->vp_state, VP_FAILED);
805 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
808 vha->flags.management_server_logged_in = 0;
809 ha->link_data_rate = PORT_SPEED_UNKNOWN;
810 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
813 case MBA_LIP_RESET: /* LIP reset occurred */
814 ql_dbg(ql_dbg_async, vha, 0x500c,
815 "LIP reset occurred (%x).\n", mb[1]);
817 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
818 atomic_set(&vha->loop_state, LOOP_DOWN);
819 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
820 qla2x00_mark_all_devices_lost(vha, 1);
824 atomic_set(&vha->vp_state, VP_FAILED);
825 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
828 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
830 ha->operating_mode = LOOP;
831 vha->flags.management_server_logged_in = 0;
832 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
835 /* case MBA_DCBX_COMPLETE: */
836 case MBA_POINT_TO_POINT: /* Point-to-Point */
840 if (IS_CNA_CAPABLE(ha)) {
841 ql_dbg(ql_dbg_async, vha, 0x500d,
842 "DCBX Completed -- %04x %04x %04x.\n",
843 mb[1], mb[2], mb[3]);
844 if (ha->notify_dcbx_comp && !vha->vp_idx)
845 complete(&ha->dcbx_comp);
848 ql_dbg(ql_dbg_async, vha, 0x500e,
849 "Asynchronous P2P MODE received.\n");
852 * Until there's a transition from loop down to loop up, treat
853 * this as loop down only.
855 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
856 atomic_set(&vha->loop_state, LOOP_DOWN);
857 if (!atomic_read(&vha->loop_down_timer))
858 atomic_set(&vha->loop_down_timer,
860 qla2x00_mark_all_devices_lost(vha, 1);
864 atomic_set(&vha->vp_state, VP_FAILED);
865 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
868 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
869 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
871 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
872 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
874 ha->flags.gpsc_supported = 1;
875 vha->flags.management_server_logged_in = 0;
878 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
882 ql_dbg(ql_dbg_async, vha, 0x500f,
883 "Configuration change detected: value=%x.\n", mb[1]);
885 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
886 atomic_set(&vha->loop_state, LOOP_DOWN);
887 if (!atomic_read(&vha->loop_down_timer))
888 atomic_set(&vha->loop_down_timer,
890 qla2x00_mark_all_devices_lost(vha, 1);
894 atomic_set(&vha->vp_state, VP_FAILED);
895 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
898 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
899 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
902 case MBA_PORT_UPDATE: /* Port database update */
904 * Handle only global and vn-port update events
907 * mb[1] = N_Port handle of changed port
908 * OR 0xffff for global event
909 * mb[2] = New login state
910 * 7 = Port logged out
911 * mb[3] = LSB is vp_idx, 0xff = all vps
913 * Skip processing if:
914 * Event is global, vp_idx is NOT all vps,
915 * vp_idx does not match
916 * Event is not global, vp_idx does not match
918 if (IS_QLA2XXX_MIDTYPE(ha) &&
919 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
920 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
924 ql_dbg(ql_dbg_async, vha, 0x5010,
925 "Port %s %04x %04x %04x.\n",
926 mb[1] == 0xffff ? "unavailable" : "logout",
927 mb[1], mb[2], mb[3]);
930 goto global_port_update;
933 fcport = qla2x00_find_fcport_by_loopid(vha, mb[1]);
936 if (atomic_read(&fcport->state) != FCS_ONLINE)
938 ql_dbg(ql_dbg_async, vha, 0x508a,
939 "Marking port lost loopid=%04x portid=%06x.\n",
940 fcport->loop_id, fcport->d_id.b24);
941 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
945 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
946 atomic_set(&vha->loop_state, LOOP_DOWN);
947 atomic_set(&vha->loop_down_timer,
949 vha->device_flags |= DFLG_NO_CABLE;
950 qla2x00_mark_all_devices_lost(vha, 1);
954 atomic_set(&vha->vp_state, VP_FAILED);
955 fc_vport_set_state(vha->fc_vport,
957 qla2x00_mark_all_devices_lost(vha, 1);
960 vha->flags.management_server_logged_in = 0;
961 ha->link_data_rate = PORT_SPEED_UNKNOWN;
966 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
967 * event etc. earlier indicating loop is down) then process
968 * it. Otherwise ignore it and Wait for RSCN to come in.
970 atomic_set(&vha->loop_down_timer, 0);
971 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
972 atomic_read(&vha->loop_state) != LOOP_DEAD) {
973 ql_dbg(ql_dbg_async, vha, 0x5011,
974 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
975 mb[1], mb[2], mb[3]);
979 ql_dbg(ql_dbg_async, vha, 0x5012,
980 "Port database changed %04x %04x %04x.\n",
981 mb[1], mb[2], mb[3]);
984 * Mark all devices as missing so we will login again.
986 atomic_set(&vha->loop_state, LOOP_UP);
988 qla2x00_mark_all_devices_lost(vha, 1);
990 if (vha->vp_idx == 0 && !qla_ini_mode_enabled(vha))
991 set_bit(SCR_PENDING, &vha->dpc_flags);
993 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
994 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
995 set_bit(VP_CONFIG_OK, &vha->vp_flags);
998 case MBA_RSCN_UPDATE: /* State Change Registration */
999 /* Check if the Vport has issued a SCR */
1000 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
1002 /* Only handle SCNs for our Vport index. */
1003 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
1006 ql_dbg(ql_dbg_async, vha, 0x5013,
1007 "RSCN database changed -- %04x %04x %04x.\n",
1008 mb[1], mb[2], mb[3]);
1010 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
1011 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
1012 | vha->d_id.b.al_pa;
1013 if (rscn_entry == host_pid) {
1014 ql_dbg(ql_dbg_async, vha, 0x5014,
1015 "Ignoring RSCN update to local host "
1016 "port ID (%06x).\n", host_pid);
1020 /* Ignore reserved bits from RSCN-payload. */
1021 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
1023 /* Skip RSCNs for virtual ports on the same physical port */
1024 if (qla2x00_is_a_vp_did(vha, rscn_entry))
1028 * Search for the rport related to this RSCN entry and mark it
1031 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1032 if (atomic_read(&fcport->state) != FCS_ONLINE)
1034 if (fcport->d_id.b24 == rscn_entry) {
1035 qla2x00_mark_device_lost(vha, fcport, 0, 0);
1040 atomic_set(&vha->loop_down_timer, 0);
1041 vha->flags.management_server_logged_in = 0;
1043 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1044 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1045 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
1048 /* case MBA_RIO_RESPONSE: */
1049 case MBA_ZIO_RESPONSE:
1050 ql_dbg(ql_dbg_async, vha, 0x5015,
1051 "[R|Z]IO update completion.\n");
1053 if (IS_FWI2_CAPABLE(ha))
1054 qla24xx_process_response_queue(vha, rsp);
1056 qla2x00_process_response_queue(rsp);
1059 case MBA_DISCARD_RND_FRAME:
1060 ql_dbg(ql_dbg_async, vha, 0x5016,
1061 "Discard RND Frame -- %04x %04x %04x.\n",
1062 mb[1], mb[2], mb[3]);
1065 case MBA_TRACE_NOTIFICATION:
1066 ql_dbg(ql_dbg_async, vha, 0x5017,
1067 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
1070 case MBA_ISP84XX_ALERT:
1071 ql_dbg(ql_dbg_async, vha, 0x5018,
1072 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
1073 mb[1], mb[2], mb[3]);
1075 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
1077 case A84_PANIC_RECOVERY:
1078 ql_log(ql_log_info, vha, 0x5019,
1079 "Alert 84XX: panic recovery %04x %04x.\n",
1082 case A84_OP_LOGIN_COMPLETE:
1083 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
1084 ql_log(ql_log_info, vha, 0x501a,
1085 "Alert 84XX: firmware version %x.\n",
1086 ha->cs84xx->op_fw_version);
1088 case A84_DIAG_LOGIN_COMPLETE:
1089 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
1090 ql_log(ql_log_info, vha, 0x501b,
1091 "Alert 84XX: diagnostic firmware version %x.\n",
1092 ha->cs84xx->diag_fw_version);
1094 case A84_GOLD_LOGIN_COMPLETE:
1095 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
1096 ha->cs84xx->fw_update = 1;
1097 ql_log(ql_log_info, vha, 0x501c,
1098 "Alert 84XX: gold firmware version %x.\n",
1099 ha->cs84xx->gold_fw_version);
1102 ql_log(ql_log_warn, vha, 0x501d,
1103 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
1104 mb[1], mb[2], mb[3]);
1106 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
1108 case MBA_DCBX_START:
1109 ql_dbg(ql_dbg_async, vha, 0x501e,
1110 "DCBX Started -- %04x %04x %04x.\n",
1111 mb[1], mb[2], mb[3]);
1113 case MBA_DCBX_PARAM_UPDATE:
1114 ql_dbg(ql_dbg_async, vha, 0x501f,
1115 "DCBX Parameters Updated -- %04x %04x %04x.\n",
1116 mb[1], mb[2], mb[3]);
1118 case MBA_FCF_CONF_ERR:
1119 ql_dbg(ql_dbg_async, vha, 0x5020,
1120 "FCF Configuration Error -- %04x %04x %04x.\n",
1121 mb[1], mb[2], mb[3]);
1123 case MBA_IDC_NOTIFY:
1124 if (IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
1125 mb[4] = RD_REG_WORD(®24->mailbox4);
1126 if (((mb[2] & 0x7fff) == MBC_PORT_RESET ||
1127 (mb[2] & 0x7fff) == MBC_SET_PORT_CONFIG) &&
1128 (mb[4] & INTERNAL_LOOPBACK_MASK) != 0) {
1129 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
1131 * Extend loop down timer since port is active.
1133 if (atomic_read(&vha->loop_state) == LOOP_DOWN)
1134 atomic_set(&vha->loop_down_timer,
1136 qla2xxx_wake_dpc(vha);
1139 case MBA_IDC_COMPLETE:
1140 if (ha->notify_lb_portup_comp && !vha->vp_idx)
1141 complete(&ha->lb_portup_comp);
1143 case MBA_IDC_TIME_EXT:
1144 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) ||
1146 qla81xx_idc_event(vha, mb[0], mb[1]);
1150 mb[4] = RD_REG_WORD(®24->mailbox4);
1151 mb[5] = RD_REG_WORD(®24->mailbox5);
1152 mb[6] = RD_REG_WORD(®24->mailbox6);
1153 mb[7] = RD_REG_WORD(®24->mailbox7);
1154 qla83xx_handle_8200_aen(vha, mb);
1157 case MBA_DPORT_DIAGNOSTICS:
1158 ql_dbg(ql_dbg_async, vha, 0x5052,
1159 "D-Port Diagnostics: %04x result=%s\n",
1161 mb[1] == 0 ? "start" :
1162 mb[1] == 1 ? "done (pass)" :
1163 mb[1] == 2 ? "done (error)" : "other");
1166 case MBA_TEMPERATURE_ALERT:
1167 ql_dbg(ql_dbg_async, vha, 0x505e,
1168 "TEMPERATURE ALERT: %04x %04x %04x\n", mb[1], mb[2], mb[3]);
1170 schedule_work(&ha->board_disable);
1174 ql_dbg(ql_dbg_async, vha, 0x5057,
1175 "Unknown AEN:%04x %04x %04x %04x\n",
1176 mb[0], mb[1], mb[2], mb[3]);
1179 qlt_async_event(mb[0], vha, mb);
1181 if (!vha->vp_idx && ha->num_vhosts)
1182 qla2x00_alert_all_vps(rsp, mb);
1186 * qla2x00_process_completed_request() - Process a Fast Post response.
1187 * @ha: SCSI driver HA context
1191 qla2x00_process_completed_request(struct scsi_qla_host *vha,
1192 struct req_que *req, uint32_t index)
1195 struct qla_hw_data *ha = vha->hw;
1197 /* Validate handle. */
1198 if (index >= req->num_outstanding_cmds) {
1199 ql_log(ql_log_warn, vha, 0x3014,
1200 "Invalid SCSI command index (%x).\n", index);
1202 if (IS_P3P_TYPE(ha))
1203 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1205 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1209 sp = req->outstanding_cmds[index];
1211 /* Free outstanding command slot. */
1212 req->outstanding_cmds[index] = NULL;
1214 /* Save ISP completion status */
1215 sp->done(ha, sp, DID_OK << 16);
1217 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
1219 if (IS_P3P_TYPE(ha))
1220 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1222 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1227 qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
1228 struct req_que *req, void *iocb)
1230 struct qla_hw_data *ha = vha->hw;
1231 sts_entry_t *pkt = iocb;
1235 index = LSW(pkt->handle);
1236 if (index >= req->num_outstanding_cmds) {
1237 ql_log(ql_log_warn, vha, 0x5031,
1238 "Invalid command index (%x).\n", index);
1239 if (IS_P3P_TYPE(ha))
1240 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1242 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1245 sp = req->outstanding_cmds[index];
1247 ql_log(ql_log_warn, vha, 0x5032,
1248 "Invalid completion handle (%x) -- timed-out.\n", index);
1251 if (sp->handle != index) {
1252 ql_log(ql_log_warn, vha, 0x5033,
1253 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
1257 req->outstanding_cmds[index] = NULL;
1264 qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1265 struct mbx_entry *mbx)
1267 const char func[] = "MBX-IOCB";
1271 struct srb_iocb *lio;
1275 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
1279 lio = &sp->u.iocb_cmd;
1281 fcport = sp->fcport;
1282 data = lio->u.logio.data;
1284 data[0] = MBS_COMMAND_ERROR;
1285 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
1286 QLA_LOGIO_LOGIN_RETRIED : 0;
1287 if (mbx->entry_status) {
1288 ql_dbg(ql_dbg_async, vha, 0x5043,
1289 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
1290 "entry-status=%x status=%x state-flag=%x "
1291 "status-flags=%x.\n", type, sp->handle,
1292 fcport->d_id.b.domain, fcport->d_id.b.area,
1293 fcport->d_id.b.al_pa, mbx->entry_status,
1294 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
1295 le16_to_cpu(mbx->status_flags));
1297 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
1298 (uint8_t *)mbx, sizeof(*mbx));
1303 status = le16_to_cpu(mbx->status);
1304 if (status == 0x30 && sp->type == SRB_LOGIN_CMD &&
1305 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
1307 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
1308 ql_dbg(ql_dbg_async, vha, 0x5045,
1309 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1310 type, sp->handle, fcport->d_id.b.domain,
1311 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1312 le16_to_cpu(mbx->mb1));
1314 data[0] = MBS_COMMAND_COMPLETE;
1315 if (sp->type == SRB_LOGIN_CMD) {
1316 fcport->port_type = FCT_TARGET;
1317 if (le16_to_cpu(mbx->mb1) & BIT_0)
1318 fcport->port_type = FCT_INITIATOR;
1319 else if (le16_to_cpu(mbx->mb1) & BIT_1)
1320 fcport->flags |= FCF_FCP2_DEVICE;
1325 data[0] = le16_to_cpu(mbx->mb0);
1327 case MBS_PORT_ID_USED:
1328 data[1] = le16_to_cpu(mbx->mb1);
1330 case MBS_LOOP_ID_USED:
1333 data[0] = MBS_COMMAND_ERROR;
1337 ql_log(ql_log_warn, vha, 0x5046,
1338 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1339 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
1340 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
1341 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
1342 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
1343 le16_to_cpu(mbx->mb7));
1346 sp->done(vha, sp, 0);
1350 qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1351 sts_entry_t *pkt, int iocb_type)
1353 const char func[] = "CT_IOCB";
1356 struct fc_bsg_job *bsg_job;
1357 uint16_t comp_status;
1360 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1364 bsg_job = sp->u.bsg_job;
1366 type = "ct pass-through";
1368 comp_status = le16_to_cpu(pkt->comp_status);
1370 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1371 * fc payload to the caller
1373 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1374 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1376 if (comp_status != CS_COMPLETE) {
1377 if (comp_status == CS_DATA_UNDERRUN) {
1379 bsg_job->reply->reply_payload_rcv_len =
1380 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
1382 ql_log(ql_log_warn, vha, 0x5048,
1383 "CT pass-through-%s error "
1384 "comp_status-status=0x%x total_byte = 0x%x.\n",
1386 bsg_job->reply->reply_payload_rcv_len);
1388 ql_log(ql_log_warn, vha, 0x5049,
1389 "CT pass-through-%s error "
1390 "comp_status-status=0x%x.\n", type, comp_status);
1391 res = DID_ERROR << 16;
1392 bsg_job->reply->reply_payload_rcv_len = 0;
1394 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
1395 (uint8_t *)pkt, sizeof(*pkt));
1398 bsg_job->reply->reply_payload_rcv_len =
1399 bsg_job->reply_payload.payload_len;
1400 bsg_job->reply_len = 0;
1403 sp->done(vha, sp, res);
1407 qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1408 struct sts_entry_24xx *pkt, int iocb_type)
1410 const char func[] = "ELS_CT_IOCB";
1413 struct fc_bsg_job *bsg_job;
1414 uint16_t comp_status;
1415 uint32_t fw_status[3];
1416 uint8_t* fw_sts_ptr;
1419 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1422 bsg_job = sp->u.bsg_job;
1426 case SRB_ELS_CMD_RPT:
1427 case SRB_ELS_CMD_HST:
1431 type = "ct pass-through";
1434 type = "Driver ELS logo";
1435 ql_dbg(ql_dbg_user, vha, 0x5047,
1436 "Completing %s: (%p) type=%d.\n", type, sp, sp->type);
1437 sp->done(vha, sp, 0);
1440 ql_dbg(ql_dbg_user, vha, 0x503e,
1441 "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type);
1445 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1446 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1447 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1449 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1450 * fc payload to the caller
1452 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1453 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1455 if (comp_status != CS_COMPLETE) {
1456 if (comp_status == CS_DATA_UNDERRUN) {
1458 bsg_job->reply->reply_payload_rcv_len =
1459 le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count);
1461 ql_dbg(ql_dbg_user, vha, 0x503f,
1462 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
1463 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
1464 type, sp->handle, comp_status, fw_status[1], fw_status[2],
1465 le16_to_cpu(((struct els_sts_entry_24xx *)
1466 pkt)->total_byte_count));
1467 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1468 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1471 ql_dbg(ql_dbg_user, vha, 0x5040,
1472 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
1473 "error subcode 1=0x%x error subcode 2=0x%x.\n",
1474 type, sp->handle, comp_status,
1475 le16_to_cpu(((struct els_sts_entry_24xx *)
1476 pkt)->error_subcode_1),
1477 le16_to_cpu(((struct els_sts_entry_24xx *)
1478 pkt)->error_subcode_2));
1479 res = DID_ERROR << 16;
1480 bsg_job->reply->reply_payload_rcv_len = 0;
1481 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1482 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1484 ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056,
1485 (uint8_t *)pkt, sizeof(*pkt));
1489 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1490 bsg_job->reply_len = 0;
1493 sp->done(vha, sp, res);
1497 qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1498 struct logio_entry_24xx *logio)
1500 const char func[] = "LOGIO-IOCB";
1504 struct srb_iocb *lio;
1508 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1512 lio = &sp->u.iocb_cmd;
1514 fcport = sp->fcport;
1515 data = lio->u.logio.data;
1517 data[0] = MBS_COMMAND_ERROR;
1518 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
1519 QLA_LOGIO_LOGIN_RETRIED : 0;
1520 if (logio->entry_status) {
1521 ql_log(ql_log_warn, fcport->vha, 0x5034,
1522 "Async-%s error entry - hdl=%x"
1523 "portid=%02x%02x%02x entry-status=%x.\n",
1524 type, sp->handle, fcport->d_id.b.domain,
1525 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1526 logio->entry_status);
1527 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
1528 (uint8_t *)logio, sizeof(*logio));
1533 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
1534 ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
1535 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1536 "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1537 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1538 le32_to_cpu(logio->io_parameter[0]));
1540 data[0] = MBS_COMMAND_COMPLETE;
1541 if (sp->type != SRB_LOGIN_CMD)
1544 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1545 if (iop[0] & BIT_4) {
1546 fcport->port_type = FCT_TARGET;
1548 fcport->flags |= FCF_FCP2_DEVICE;
1549 } else if (iop[0] & BIT_5)
1550 fcport->port_type = FCT_INITIATOR;
1553 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1555 if (logio->io_parameter[7] || logio->io_parameter[8])
1556 fcport->supported_classes |= FC_COS_CLASS2;
1557 if (logio->io_parameter[9] || logio->io_parameter[10])
1558 fcport->supported_classes |= FC_COS_CLASS3;
1563 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1564 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1566 case LSC_SCODE_PORTID_USED:
1567 data[0] = MBS_PORT_ID_USED;
1568 data[1] = LSW(iop[1]);
1570 case LSC_SCODE_NPORT_USED:
1571 data[0] = MBS_LOOP_ID_USED;
1574 data[0] = MBS_COMMAND_ERROR;
1578 ql_dbg(ql_dbg_async, fcport->vha, 0x5037,
1579 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1580 "iop0=%x iop1=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1581 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1582 le16_to_cpu(logio->comp_status),
1583 le32_to_cpu(logio->io_parameter[0]),
1584 le32_to_cpu(logio->io_parameter[1]));
1587 sp->done(vha, sp, 0);
1591 qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, void *tsk)
1593 const char func[] = "TMF-IOCB";
1597 struct srb_iocb *iocb;
1598 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1600 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1604 iocb = &sp->u.iocb_cmd;
1606 fcport = sp->fcport;
1607 iocb->u.tmf.data = QLA_SUCCESS;
1609 if (sts->entry_status) {
1610 ql_log(ql_log_warn, fcport->vha, 0x5038,
1611 "Async-%s error - hdl=%x entry-status(%x).\n",
1612 type, sp->handle, sts->entry_status);
1613 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1614 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
1615 ql_log(ql_log_warn, fcport->vha, 0x5039,
1616 "Async-%s error - hdl=%x completion status(%x).\n",
1617 type, sp->handle, sts->comp_status);
1618 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1619 } else if ((le16_to_cpu(sts->scsi_status) &
1620 SS_RESPONSE_INFO_LEN_VALID)) {
1621 host_to_fcp_swap(sts->data, sizeof(sts->data));
1622 if (le32_to_cpu(sts->rsp_data_len) < 4) {
1623 ql_log(ql_log_warn, fcport->vha, 0x503b,
1624 "Async-%s error - hdl=%x not enough response(%d).\n",
1625 type, sp->handle, sts->rsp_data_len);
1626 } else if (sts->data[3]) {
1627 ql_log(ql_log_warn, fcport->vha, 0x503c,
1628 "Async-%s error - hdl=%x response(%x).\n",
1629 type, sp->handle, sts->data[3]);
1630 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1634 if (iocb->u.tmf.data != QLA_SUCCESS)
1635 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1636 (uint8_t *)sts, sizeof(*sts));
1638 sp->done(vha, sp, 0);
1642 * qla2x00_process_response_queue() - Process response queue entries.
1643 * @ha: SCSI driver HA context
1646 qla2x00_process_response_queue(struct rsp_que *rsp)
1648 struct scsi_qla_host *vha;
1649 struct qla_hw_data *ha = rsp->hw;
1650 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1652 uint16_t handle_cnt;
1655 vha = pci_get_drvdata(ha->pdev);
1657 if (!vha->flags.online)
1660 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1661 pkt = (sts_entry_t *)rsp->ring_ptr;
1664 if (rsp->ring_index == rsp->length) {
1665 rsp->ring_index = 0;
1666 rsp->ring_ptr = rsp->ring;
1671 if (pkt->entry_status != 0) {
1672 qla2x00_error_entry(vha, rsp, pkt);
1673 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1678 switch (pkt->entry_type) {
1680 qla2x00_status_entry(vha, rsp, pkt);
1682 case STATUS_TYPE_21:
1683 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1684 for (cnt = 0; cnt < handle_cnt; cnt++) {
1685 qla2x00_process_completed_request(vha, rsp->req,
1686 ((sts21_entry_t *)pkt)->handle[cnt]);
1689 case STATUS_TYPE_22:
1690 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1691 for (cnt = 0; cnt < handle_cnt; cnt++) {
1692 qla2x00_process_completed_request(vha, rsp->req,
1693 ((sts22_entry_t *)pkt)->handle[cnt]);
1696 case STATUS_CONT_TYPE:
1697 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
1700 qla2x00_mbx_iocb_entry(vha, rsp->req,
1701 (struct mbx_entry *)pkt);
1704 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1707 /* Type Not Supported. */
1708 ql_log(ql_log_warn, vha, 0x504a,
1709 "Received unknown response pkt type %x "
1710 "entry status=%x.\n",
1711 pkt->entry_type, pkt->entry_status);
1714 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1718 /* Adjust ring index */
1719 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
1723 qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
1724 uint32_t sense_len, struct rsp_que *rsp, int res)
1726 struct scsi_qla_host *vha = sp->fcport->vha;
1727 struct scsi_cmnd *cp = GET_CMD_SP(sp);
1728 uint32_t track_sense_len;
1730 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1731 sense_len = SCSI_SENSE_BUFFERSIZE;
1733 SET_CMD_SENSE_LEN(sp, sense_len);
1734 SET_CMD_SENSE_PTR(sp, cp->sense_buffer);
1735 track_sense_len = sense_len;
1737 if (sense_len > par_sense_len)
1738 sense_len = par_sense_len;
1740 memcpy(cp->sense_buffer, sense_data, sense_len);
1742 SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len);
1743 track_sense_len -= sense_len;
1744 SET_CMD_SENSE_LEN(sp, track_sense_len);
1746 if (track_sense_len != 0) {
1747 rsp->status_srb = sp;
1752 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
1753 "Check condition Sense data, nexus%ld:%d:%llu cmd=%p.\n",
1754 sp->fcport->vha->host_no, cp->device->id, cp->device->lun,
1756 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
1757 cp->sense_buffer, sense_len);
1761 struct scsi_dif_tuple {
1762 __be16 guard; /* Checksum */
1763 __be16 app_tag; /* APPL identifier */
1764 __be32 ref_tag; /* Target LBA or indirect LBA */
1768 * Checks the guard or meta-data for the type of error
1769 * detected by the HBA. In case of errors, we set the
1770 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1771 * to indicate to the kernel that the HBA detected error.
1774 qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
1776 struct scsi_qla_host *vha = sp->fcport->vha;
1777 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
1778 uint8_t *ap = &sts24->data[12];
1779 uint8_t *ep = &sts24->data[20];
1780 uint32_t e_ref_tag, a_ref_tag;
1781 uint16_t e_app_tag, a_app_tag;
1782 uint16_t e_guard, a_guard;
1785 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1786 * would make guard field appear at offset 2
1788 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
1789 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
1790 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
1791 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
1792 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
1793 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
1795 ql_dbg(ql_dbg_io, vha, 0x3023,
1796 "iocb(s) %p Returned STATUS.\n", sts24);
1798 ql_dbg(ql_dbg_io, vha, 0x3024,
1799 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
1800 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
1801 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
1802 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
1803 a_app_tag, e_app_tag, a_guard, e_guard);
1807 * For type 3: ref & app tag is all 'f's
1808 * For type 0,1,2: app tag is all 'f's
1810 if ((a_app_tag == 0xffff) &&
1811 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
1812 (a_ref_tag == 0xffffffff))) {
1813 uint32_t blocks_done, resid;
1814 sector_t lba_s = scsi_get_lba(cmd);
1816 /* 2TB boundary case covered automatically with this */
1817 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
1819 resid = scsi_bufflen(cmd) - (blocks_done *
1820 cmd->device->sector_size);
1822 scsi_set_resid(cmd, resid);
1823 cmd->result = DID_OK << 16;
1825 /* Update protection tag */
1826 if (scsi_prot_sg_count(cmd)) {
1827 uint32_t i, j = 0, k = 0, num_ent;
1828 struct scatterlist *sg;
1829 struct t10_pi_tuple *spt;
1831 /* Patch the corresponding protection tags */
1832 scsi_for_each_prot_sg(cmd, sg,
1833 scsi_prot_sg_count(cmd), i) {
1834 num_ent = sg_dma_len(sg) / 8;
1835 if (k + num_ent < blocks_done) {
1839 j = blocks_done - k - 1;
1844 if (k != blocks_done) {
1845 ql_log(ql_log_warn, vha, 0x302f,
1846 "unexpected tag values tag:lba=%x:%llx)\n",
1847 e_ref_tag, (unsigned long long)lba_s);
1851 spt = page_address(sg_page(sg)) + sg->offset;
1854 spt->app_tag = 0xffff;
1855 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
1856 spt->ref_tag = 0xffffffff;
1863 if (e_guard != a_guard) {
1864 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1866 set_driver_byte(cmd, DRIVER_SENSE);
1867 set_host_byte(cmd, DID_ABORT);
1868 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1873 if (e_ref_tag != a_ref_tag) {
1874 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1876 set_driver_byte(cmd, DRIVER_SENSE);
1877 set_host_byte(cmd, DID_ABORT);
1878 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1882 /* check appl tag */
1883 if (e_app_tag != a_app_tag) {
1884 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1886 set_driver_byte(cmd, DRIVER_SENSE);
1887 set_host_byte(cmd, DID_ABORT);
1888 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1896 qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, void *pkt,
1897 struct req_que *req, uint32_t index)
1899 struct qla_hw_data *ha = vha->hw;
1901 uint16_t comp_status;
1902 uint16_t scsi_status;
1904 uint32_t rval = EXT_STATUS_OK;
1905 struct fc_bsg_job *bsg_job = NULL;
1907 struct sts_entry_24xx *sts24;
1908 sts = (sts_entry_t *) pkt;
1909 sts24 = (struct sts_entry_24xx *) pkt;
1911 /* Validate handle. */
1912 if (index >= req->num_outstanding_cmds) {
1913 ql_log(ql_log_warn, vha, 0x70af,
1914 "Invalid SCSI completion handle 0x%x.\n", index);
1915 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1919 sp = req->outstanding_cmds[index];
1921 /* Free outstanding command slot. */
1922 req->outstanding_cmds[index] = NULL;
1923 bsg_job = sp->u.bsg_job;
1925 ql_log(ql_log_warn, vha, 0x70b0,
1926 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
1929 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1933 if (IS_FWI2_CAPABLE(ha)) {
1934 comp_status = le16_to_cpu(sts24->comp_status);
1935 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1937 comp_status = le16_to_cpu(sts->comp_status);
1938 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1941 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1942 switch (comp_status) {
1944 if (scsi_status == 0) {
1945 bsg_job->reply->reply_payload_rcv_len =
1946 bsg_job->reply_payload.payload_len;
1947 vha->qla_stats.input_bytes +=
1948 bsg_job->reply->reply_payload_rcv_len;
1949 vha->qla_stats.input_requests++;
1950 rval = EXT_STATUS_OK;
1954 case CS_DATA_OVERRUN:
1955 ql_dbg(ql_dbg_user, vha, 0x70b1,
1956 "Command completed with date overrun thread_id=%d\n",
1958 rval = EXT_STATUS_DATA_OVERRUN;
1961 case CS_DATA_UNDERRUN:
1962 ql_dbg(ql_dbg_user, vha, 0x70b2,
1963 "Command completed with date underrun thread_id=%d\n",
1965 rval = EXT_STATUS_DATA_UNDERRUN;
1967 case CS_BIDIR_RD_OVERRUN:
1968 ql_dbg(ql_dbg_user, vha, 0x70b3,
1969 "Command completed with read data overrun thread_id=%d\n",
1971 rval = EXT_STATUS_DATA_OVERRUN;
1974 case CS_BIDIR_RD_WR_OVERRUN:
1975 ql_dbg(ql_dbg_user, vha, 0x70b4,
1976 "Command completed with read and write data overrun "
1977 "thread_id=%d\n", thread_id);
1978 rval = EXT_STATUS_DATA_OVERRUN;
1981 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN:
1982 ql_dbg(ql_dbg_user, vha, 0x70b5,
1983 "Command completed with read data over and write data "
1984 "underrun thread_id=%d\n", thread_id);
1985 rval = EXT_STATUS_DATA_OVERRUN;
1988 case CS_BIDIR_RD_UNDERRUN:
1989 ql_dbg(ql_dbg_user, vha, 0x70b6,
1990 "Command completed with read data data underrun "
1991 "thread_id=%d\n", thread_id);
1992 rval = EXT_STATUS_DATA_UNDERRUN;
1995 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN:
1996 ql_dbg(ql_dbg_user, vha, 0x70b7,
1997 "Command completed with read data under and write data "
1998 "overrun thread_id=%d\n", thread_id);
1999 rval = EXT_STATUS_DATA_UNDERRUN;
2002 case CS_BIDIR_RD_WR_UNDERRUN:
2003 ql_dbg(ql_dbg_user, vha, 0x70b8,
2004 "Command completed with read and write data underrun "
2005 "thread_id=%d\n", thread_id);
2006 rval = EXT_STATUS_DATA_UNDERRUN;
2010 ql_dbg(ql_dbg_user, vha, 0x70b9,
2011 "Command completed with data DMA error thread_id=%d\n",
2013 rval = EXT_STATUS_DMA_ERR;
2017 ql_dbg(ql_dbg_user, vha, 0x70ba,
2018 "Command completed with timeout thread_id=%d\n",
2020 rval = EXT_STATUS_TIMEOUT;
2023 ql_dbg(ql_dbg_user, vha, 0x70bb,
2024 "Command completed with completion status=0x%x "
2025 "thread_id=%d\n", comp_status, thread_id);
2026 rval = EXT_STATUS_ERR;
2029 bsg_job->reply->reply_payload_rcv_len = 0;
2032 /* Return the vendor specific reply to API */
2033 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
2034 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2035 /* Always return DID_OK, bsg will send the vendor specific response
2036 * in this case only */
2037 sp->done(vha, sp, (DID_OK << 6));
2042 * qla2x00_status_entry() - Process a Status IOCB entry.
2043 * @ha: SCSI driver HA context
2044 * @pkt: Entry pointer
2047 qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
2051 struct scsi_cmnd *cp;
2053 struct sts_entry_24xx *sts24;
2054 uint16_t comp_status;
2055 uint16_t scsi_status;
2057 uint8_t lscsi_status;
2059 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
2061 uint8_t *rsp_info, *sense_data;
2062 struct qla_hw_data *ha = vha->hw;
2065 struct req_que *req;
2068 uint16_t state_flags = 0;
2069 uint16_t retry_delay = 0;
2071 sts = (sts_entry_t *) pkt;
2072 sts24 = (struct sts_entry_24xx *) pkt;
2073 if (IS_FWI2_CAPABLE(ha)) {
2074 comp_status = le16_to_cpu(sts24->comp_status);
2075 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
2076 state_flags = le16_to_cpu(sts24->state_flags);
2078 comp_status = le16_to_cpu(sts->comp_status);
2079 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
2081 handle = (uint32_t) LSW(sts->handle);
2082 que = MSW(sts->handle);
2083 req = ha->req_q_map[que];
2085 /* Check for invalid queue pointer */
2087 que >= find_first_zero_bit(ha->req_qid_map, ha->max_req_queues)) {
2088 ql_dbg(ql_dbg_io, vha, 0x3059,
2089 "Invalid status handle (0x%x): Bad req pointer. req=%p, "
2090 "que=%u.\n", sts->handle, req, que);
2094 /* Validate handle. */
2095 if (handle < req->num_outstanding_cmds) {
2096 sp = req->outstanding_cmds[handle];
2098 ql_dbg(ql_dbg_io, vha, 0x3075,
2099 "%s(%ld): Already returned command for status handle (0x%x).\n",
2100 __func__, vha->host_no, sts->handle);
2104 ql_dbg(ql_dbg_io, vha, 0x3017,
2105 "Invalid status handle, out of range (0x%x).\n",
2108 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
2109 if (IS_P3P_TYPE(ha))
2110 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2112 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2113 qla2xxx_wake_dpc(vha);
2118 if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) {
2119 qla25xx_process_bidir_status_iocb(vha, pkt, req, handle);
2123 /* Task Management completion. */
2124 if (sp->type == SRB_TM_CMD) {
2125 qla24xx_tm_iocb_entry(vha, req, pkt);
2129 /* Fast path completion. */
2130 if (comp_status == CS_COMPLETE && scsi_status == 0) {
2131 qla2x00_process_completed_request(vha, req, handle);
2136 req->outstanding_cmds[handle] = NULL;
2137 cp = GET_CMD_SP(sp);
2139 ql_dbg(ql_dbg_io, vha, 0x3018,
2140 "Command already returned (0x%x/%p).\n",
2146 lscsi_status = scsi_status & STATUS_MASK;
2148 fcport = sp->fcport;
2151 sense_len = par_sense_len = rsp_info_len = resid_len =
2153 if (IS_FWI2_CAPABLE(ha)) {
2154 if (scsi_status & SS_SENSE_LEN_VALID)
2155 sense_len = le32_to_cpu(sts24->sense_len);
2156 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2157 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
2158 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
2159 resid_len = le32_to_cpu(sts24->rsp_residual_count);
2160 if (comp_status == CS_DATA_UNDERRUN)
2161 fw_resid_len = le32_to_cpu(sts24->residual_len);
2162 rsp_info = sts24->data;
2163 sense_data = sts24->data;
2164 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
2165 ox_id = le16_to_cpu(sts24->ox_id);
2166 par_sense_len = sizeof(sts24->data);
2167 /* Valid values of the retry delay timer are 0x1-0xffef */
2168 if (sts24->retry_delay > 0 && sts24->retry_delay < 0xfff1)
2169 retry_delay = sts24->retry_delay;
2171 if (scsi_status & SS_SENSE_LEN_VALID)
2172 sense_len = le16_to_cpu(sts->req_sense_length);
2173 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2174 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
2175 resid_len = le32_to_cpu(sts->residual_length);
2176 rsp_info = sts->rsp_info;
2177 sense_data = sts->req_sense_data;
2178 par_sense_len = sizeof(sts->req_sense_data);
2181 /* Check for any FCP transport errors. */
2182 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
2183 /* Sense data lies beyond any FCP RESPONSE data. */
2184 if (IS_FWI2_CAPABLE(ha)) {
2185 sense_data += rsp_info_len;
2186 par_sense_len -= rsp_info_len;
2188 if (rsp_info_len > 3 && rsp_info[3]) {
2189 ql_dbg(ql_dbg_io, fcport->vha, 0x3019,
2190 "FCP I/O protocol failure (0x%x/0x%x).\n",
2191 rsp_info_len, rsp_info[3]);
2193 res = DID_BUS_BUSY << 16;
2198 /* Check for overrun. */
2199 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
2200 scsi_status & SS_RESIDUAL_OVER)
2201 comp_status = CS_DATA_OVERRUN;
2204 * Check retry_delay_timer value if we receive a busy or
2207 if (lscsi_status == SAM_STAT_TASK_SET_FULL ||
2208 lscsi_status == SAM_STAT_BUSY)
2209 qla2x00_set_retry_delay_timestamp(fcport, retry_delay);
2212 * Based on Host and scsi status generate status code for Linux
2214 switch (comp_status) {
2217 if (scsi_status == 0) {
2221 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
2223 scsi_set_resid(cp, resid);
2225 if (!lscsi_status &&
2226 ((unsigned)(scsi_bufflen(cp) - resid) <
2228 ql_dbg(ql_dbg_io, fcport->vha, 0x301a,
2229 "Mid-layer underflow "
2230 "detected (0x%x of 0x%x bytes).\n",
2231 resid, scsi_bufflen(cp));
2233 res = DID_ERROR << 16;
2237 res = DID_OK << 16 | lscsi_status;
2239 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
2240 ql_dbg(ql_dbg_io, fcport->vha, 0x301b,
2241 "QUEUE FULL detected.\n");
2245 if (lscsi_status != SS_CHECK_CONDITION)
2248 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
2249 if (!(scsi_status & SS_SENSE_LEN_VALID))
2252 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
2256 case CS_DATA_UNDERRUN:
2257 /* Use F/W calculated residual length. */
2258 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
2259 scsi_set_resid(cp, resid);
2260 if (scsi_status & SS_RESIDUAL_UNDER) {
2261 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
2262 ql_dbg(ql_dbg_io, fcport->vha, 0x301d,
2263 "Dropped frame(s) detected "
2264 "(0x%x of 0x%x bytes).\n",
2265 resid, scsi_bufflen(cp));
2267 res = DID_ERROR << 16 | lscsi_status;
2268 goto check_scsi_status;
2271 if (!lscsi_status &&
2272 ((unsigned)(scsi_bufflen(cp) - resid) <
2274 ql_dbg(ql_dbg_io, fcport->vha, 0x301e,
2275 "Mid-layer underflow "
2276 "detected (0x%x of 0x%x bytes).\n",
2277 resid, scsi_bufflen(cp));
2279 res = DID_ERROR << 16;
2282 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
2283 lscsi_status != SAM_STAT_BUSY) {
2285 * scsi status of task set and busy are considered to be
2286 * task not completed.
2289 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
2290 "Dropped frame(s) detected (0x%x "
2291 "of 0x%x bytes).\n", resid,
2294 res = DID_ERROR << 16 | lscsi_status;
2295 goto check_scsi_status;
2297 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
2298 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2299 scsi_status, lscsi_status);
2302 res = DID_OK << 16 | lscsi_status;
2307 * Check to see if SCSI Status is non zero. If so report SCSI
2310 if (lscsi_status != 0) {
2311 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
2312 ql_dbg(ql_dbg_io, fcport->vha, 0x3020,
2313 "QUEUE FULL detected.\n");
2317 if (lscsi_status != SS_CHECK_CONDITION)
2320 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
2321 if (!(scsi_status & SS_SENSE_LEN_VALID))
2324 qla2x00_handle_sense(sp, sense_data, par_sense_len,
2325 sense_len, rsp, res);
2329 case CS_PORT_LOGGED_OUT:
2330 case CS_PORT_CONFIG_CHG:
2333 case CS_PORT_UNAVAILABLE:
2338 * We are going to have the fc class block the rport
2339 * while we try to recover so instruct the mid layer
2340 * to requeue until the class decides how to handle this.
2342 res = DID_TRANSPORT_DISRUPTED << 16;
2344 if (comp_status == CS_TIMEOUT) {
2345 if (IS_FWI2_CAPABLE(ha))
2347 else if ((le16_to_cpu(sts->status_flags) &
2348 SF_LOGOUT_SENT) == 0)
2352 ql_dbg(ql_dbg_io, fcport->vha, 0x3021,
2353 "Port to be marked lost on fcport=%02x%02x%02x, current "
2354 "port state= %s.\n", fcport->d_id.b.domain,
2355 fcport->d_id.b.area, fcport->d_id.b.al_pa,
2356 port_state_str[atomic_read(&fcport->state)]);
2358 if (atomic_read(&fcport->state) == FCS_ONLINE)
2359 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
2363 res = DID_RESET << 16;
2367 logit = qla2x00_handle_dif_error(sp, sts24);
2372 res = DID_ERROR << 16;
2374 if (!IS_PI_SPLIT_DET_CAPABLE(ha))
2377 if (state_flags & BIT_4)
2378 scmd_printk(KERN_WARNING, cp,
2379 "Unsupported device '%s' found.\n",
2380 cp->device->vendor);
2384 res = DID_ERROR << 16;
2390 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
2391 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%llu "
2392 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
2393 "rsp_info=0x%x resid=0x%x fw_resid=0x%x sp=%p cp=%p.\n",
2394 comp_status, scsi_status, res, vha->host_no,
2395 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
2396 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
2397 cp->cmnd, scsi_bufflen(cp), rsp_info_len,
2398 resid_len, fw_resid_len, sp, cp);
2400 if (rsp->status_srb == NULL)
2401 sp->done(ha, sp, res);
2405 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2406 * @ha: SCSI driver HA context
2407 * @pkt: Entry pointer
2409 * Extended sense data.
2412 qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
2414 uint8_t sense_sz = 0;
2415 struct qla_hw_data *ha = rsp->hw;
2416 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
2417 srb_t *sp = rsp->status_srb;
2418 struct scsi_cmnd *cp;
2422 if (!sp || !GET_CMD_SENSE_LEN(sp))
2425 sense_len = GET_CMD_SENSE_LEN(sp);
2426 sense_ptr = GET_CMD_SENSE_PTR(sp);
2428 cp = GET_CMD_SP(sp);
2430 ql_log(ql_log_warn, vha, 0x3025,
2431 "cmd is NULL: already returned to OS (sp=%p).\n", sp);
2433 rsp->status_srb = NULL;
2437 if (sense_len > sizeof(pkt->data))
2438 sense_sz = sizeof(pkt->data);
2440 sense_sz = sense_len;
2442 /* Move sense data. */
2443 if (IS_FWI2_CAPABLE(ha))
2444 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
2445 memcpy(sense_ptr, pkt->data, sense_sz);
2446 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
2447 sense_ptr, sense_sz);
2449 sense_len -= sense_sz;
2450 sense_ptr += sense_sz;
2452 SET_CMD_SENSE_PTR(sp, sense_ptr);
2453 SET_CMD_SENSE_LEN(sp, sense_len);
2455 /* Place command on done queue. */
2456 if (sense_len == 0) {
2457 rsp->status_srb = NULL;
2458 sp->done(ha, sp, cp->result);
2463 * qla2x00_error_entry() - Process an error entry.
2464 * @ha: SCSI driver HA context
2465 * @pkt: Entry pointer
2468 qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
2471 struct qla_hw_data *ha = vha->hw;
2472 const char func[] = "ERROR-IOCB";
2473 uint16_t que = MSW(pkt->handle);
2474 struct req_que *req = NULL;
2475 int res = DID_ERROR << 16;
2477 ql_dbg(ql_dbg_async, vha, 0x502a,
2478 "type of error status in response: 0x%x\n", pkt->entry_status);
2480 if (que >= ha->max_req_queues || !ha->req_q_map[que])
2483 req = ha->req_q_map[que];
2485 if (pkt->entry_status & RF_BUSY)
2486 res = DID_BUS_BUSY << 16;
2488 if (pkt->entry_type == NOTIFY_ACK_TYPE &&
2489 pkt->handle == QLA_TGT_SKIP_HANDLE)
2492 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2494 sp->done(ha, sp, res);
2498 ql_log(ql_log_warn, vha, 0x5030,
2499 "Error entry - invalid handle/queue (%04x).\n", que);
2503 * qla24xx_mbx_completion() - Process mailbox command completions.
2504 * @ha: SCSI driver HA context
2505 * @mb0: Mailbox0 register
2508 qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
2512 uint16_t __iomem *wptr;
2513 struct qla_hw_data *ha = vha->hw;
2514 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2516 /* Read all mbox registers? */
2517 WARN_ON_ONCE(ha->mbx_count > 32);
2518 mboxes = (1ULL << ha->mbx_count) - 1;
2520 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n");
2522 mboxes = ha->mcp->in_mb;
2524 /* Load return mailbox registers. */
2525 ha->flags.mbox_int = 1;
2526 ha->mailbox_out[0] = mb0;
2528 wptr = (uint16_t __iomem *)®->mailbox1;
2530 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
2532 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2540 qla24xx_abort_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
2541 struct abort_entry_24xx *pkt)
2543 const char func[] = "ABT_IOCB";
2545 struct srb_iocb *abt;
2547 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2551 abt = &sp->u.iocb_cmd;
2552 abt->u.abt.comp_status = le32_to_cpu(pkt->nport_handle);
2553 sp->done(vha, sp, 0);
2557 * qla24xx_process_response_queue() - Process response queue entries.
2558 * @ha: SCSI driver HA context
2560 void qla24xx_process_response_queue(struct scsi_qla_host *vha,
2561 struct rsp_que *rsp)
2563 struct sts_entry_24xx *pkt;
2564 struct qla_hw_data *ha = vha->hw;
2566 if (!vha->flags.online)
2569 if (rsp->msix && rsp->msix->cpuid != smp_processor_id()) {
2570 /* if kernel does not notify qla of IRQ's CPU change,
2573 rsp->msix->cpuid = smp_processor_id();
2574 ha->tgt.rspq_vector_cpuid = rsp->msix->cpuid;
2577 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2578 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
2581 if (rsp->ring_index == rsp->length) {
2582 rsp->ring_index = 0;
2583 rsp->ring_ptr = rsp->ring;
2588 if (pkt->entry_status != 0) {
2589 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
2591 if (qlt_24xx_process_response_error(vha, pkt))
2594 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2600 switch (pkt->entry_type) {
2602 qla2x00_status_entry(vha, rsp, pkt);
2604 case STATUS_CONT_TYPE:
2605 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
2607 case VP_RPT_ID_IOCB_TYPE:
2608 qla24xx_report_id_acquisition(vha,
2609 (struct vp_rpt_id_entry_24xx *)pkt);
2611 case LOGINOUT_PORT_IOCB_TYPE:
2612 qla24xx_logio_entry(vha, rsp->req,
2613 (struct logio_entry_24xx *)pkt);
2616 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
2619 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2621 case ABTS_RECV_24XX:
2622 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
2623 /* ensure that the ATIO queue is empty */
2624 qlt_handle_abts_recv(vha, (response_t *)pkt);
2628 qlt_24xx_process_atio_queue(vha, 1);
2630 case ABTS_RESP_24XX:
2632 case NOTIFY_ACK_TYPE:
2634 qlt_response_pkt_all_vps(vha, (response_t *)pkt);
2637 /* Do nothing in this case, this check is to prevent it
2638 * from falling into default case
2641 case ABORT_IOCB_TYPE:
2642 qla24xx_abort_iocb_entry(vha, rsp->req,
2643 (struct abort_entry_24xx *)pkt);
2646 /* Type Not Supported. */
2647 ql_dbg(ql_dbg_async, vha, 0x5042,
2648 "Received unknown response pkt type %x "
2649 "entry status=%x.\n",
2650 pkt->entry_type, pkt->entry_status);
2653 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2657 /* Adjust ring index */
2658 if (IS_P3P_TYPE(ha)) {
2659 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2660 WRT_REG_DWORD(®->rsp_q_out[0], rsp->ring_index);
2662 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
2666 qla2xxx_check_risc_status(scsi_qla_host_t *vha)
2670 struct qla_hw_data *ha = vha->hw;
2671 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2673 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2678 WRT_REG_DWORD(®->iobase_addr, 0x7C00);
2679 RD_REG_DWORD(®->iobase_addr);
2680 WRT_REG_DWORD(®->iobase_window, 0x0001);
2681 for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
2682 rval == QLA_SUCCESS; cnt--) {
2684 WRT_REG_DWORD(®->iobase_window, 0x0001);
2687 rval = QLA_FUNCTION_TIMEOUT;
2689 if (rval == QLA_SUCCESS)
2693 WRT_REG_DWORD(®->iobase_window, 0x0003);
2694 for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 &&
2695 rval == QLA_SUCCESS; cnt--) {
2697 WRT_REG_DWORD(®->iobase_window, 0x0003);
2700 rval = QLA_FUNCTION_TIMEOUT;
2702 if (rval != QLA_SUCCESS)
2706 if (RD_REG_DWORD(®->iobase_c8) & BIT_3)
2707 ql_log(ql_log_info, vha, 0x504c,
2708 "Additional code -- 0x55AA.\n");
2711 WRT_REG_DWORD(®->iobase_window, 0x0000);
2712 RD_REG_DWORD(®->iobase_window);
2716 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
2718 * @dev_id: SCSI driver HA context
2720 * Called by system whenever the host adapter generates an interrupt.
2722 * Returns handled flag.
2725 qla24xx_intr_handler(int irq, void *dev_id)
2727 scsi_qla_host_t *vha;
2728 struct qla_hw_data *ha;
2729 struct device_reg_24xx __iomem *reg;
2735 struct rsp_que *rsp;
2736 unsigned long flags;
2738 rsp = (struct rsp_que *) dev_id;
2740 ql_log(ql_log_info, NULL, 0x5059,
2741 "%s: NULL response queue pointer.\n", __func__);
2746 reg = &ha->iobase->isp24;
2749 if (unlikely(pci_channel_offline(ha->pdev)))
2752 spin_lock_irqsave(&ha->hardware_lock, flags);
2753 vha = pci_get_drvdata(ha->pdev);
2754 for (iter = 50; iter--; ) {
2755 stat = RD_REG_DWORD(®->host_status);
2756 if (qla2x00_check_reg32_for_disconnect(vha, stat))
2758 if (stat & HSRX_RISC_PAUSED) {
2759 if (unlikely(pci_channel_offline(ha->pdev)))
2762 hccr = RD_REG_DWORD(®->hccr);
2764 ql_log(ql_log_warn, vha, 0x504b,
2765 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2768 qla2xxx_check_risc_status(vha);
2770 ha->isp_ops->fw_dump(vha, 1);
2771 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2773 } else if ((stat & HSRX_RISC_INT) == 0)
2776 switch (stat & 0xff) {
2777 case INTR_ROM_MB_SUCCESS:
2778 case INTR_ROM_MB_FAILED:
2779 case INTR_MB_SUCCESS:
2780 case INTR_MB_FAILED:
2781 qla24xx_mbx_completion(vha, MSW(stat));
2782 status |= MBX_INTERRUPT;
2785 case INTR_ASYNC_EVENT:
2787 mb[1] = RD_REG_WORD(®->mailbox1);
2788 mb[2] = RD_REG_WORD(®->mailbox2);
2789 mb[3] = RD_REG_WORD(®->mailbox3);
2790 qla2x00_async_event(vha, rsp, mb);
2792 case INTR_RSP_QUE_UPDATE:
2793 case INTR_RSP_QUE_UPDATE_83XX:
2794 qla24xx_process_response_queue(vha, rsp);
2796 case INTR_ATIO_QUE_UPDATE:{
2797 unsigned long flags2;
2798 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
2799 qlt_24xx_process_atio_queue(vha, 1);
2800 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
2803 case INTR_ATIO_RSP_QUE_UPDATE: {
2804 unsigned long flags2;
2805 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
2806 qlt_24xx_process_atio_queue(vha, 1);
2807 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
2809 qla24xx_process_response_queue(vha, rsp);
2813 ql_dbg(ql_dbg_async, vha, 0x504f,
2814 "Unrecognized interrupt type (%d).\n", stat * 0xff);
2817 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2818 RD_REG_DWORD_RELAXED(®->hccr);
2819 if (unlikely(IS_QLA83XX(ha) && (ha->pdev->revision == 1)))
2822 qla2x00_handle_mbx_completion(ha, status);
2823 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2829 qla24xx_msix_rsp_q(int irq, void *dev_id)
2831 struct qla_hw_data *ha;
2832 struct rsp_que *rsp;
2833 struct device_reg_24xx __iomem *reg;
2834 struct scsi_qla_host *vha;
2835 unsigned long flags;
2838 rsp = (struct rsp_que *) dev_id;
2840 ql_log(ql_log_info, NULL, 0x505a,
2841 "%s: NULL response queue pointer.\n", __func__);
2845 reg = &ha->iobase->isp24;
2847 spin_lock_irqsave(&ha->hardware_lock, flags);
2849 vha = pci_get_drvdata(ha->pdev);
2851 * Use host_status register to check to PCI disconnection before we
2852 * we process the response queue.
2854 stat = RD_REG_DWORD(®->host_status);
2855 if (qla2x00_check_reg32_for_disconnect(vha, stat))
2857 qla24xx_process_response_queue(vha, rsp);
2858 if (!ha->flags.disable_msix_handshake) {
2859 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2860 RD_REG_DWORD_RELAXED(®->hccr);
2863 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2869 qla25xx_msix_rsp_q(int irq, void *dev_id)
2871 struct qla_hw_data *ha;
2872 scsi_qla_host_t *vha;
2873 struct rsp_que *rsp;
2874 struct device_reg_24xx __iomem *reg;
2875 unsigned long flags;
2878 rsp = (struct rsp_que *) dev_id;
2880 ql_log(ql_log_info, NULL, 0x505b,
2881 "%s: NULL response queue pointer.\n", __func__);
2885 vha = pci_get_drvdata(ha->pdev);
2887 /* Clear the interrupt, if enabled, for this response queue */
2888 if (!ha->flags.disable_msix_handshake) {
2889 reg = &ha->iobase->isp24;
2890 spin_lock_irqsave(&ha->hardware_lock, flags);
2891 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2892 hccr = RD_REG_DWORD_RELAXED(®->hccr);
2893 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2895 if (qla2x00_check_reg32_for_disconnect(vha, hccr))
2897 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2904 qla24xx_msix_default(int irq, void *dev_id)
2906 scsi_qla_host_t *vha;
2907 struct qla_hw_data *ha;
2908 struct rsp_que *rsp;
2909 struct device_reg_24xx __iomem *reg;
2914 unsigned long flags;
2916 rsp = (struct rsp_que *) dev_id;
2918 ql_log(ql_log_info, NULL, 0x505c,
2919 "%s: NULL response queue pointer.\n", __func__);
2923 reg = &ha->iobase->isp24;
2926 spin_lock_irqsave(&ha->hardware_lock, flags);
2927 vha = pci_get_drvdata(ha->pdev);
2929 stat = RD_REG_DWORD(®->host_status);
2930 if (qla2x00_check_reg32_for_disconnect(vha, stat))
2932 if (stat & HSRX_RISC_PAUSED) {
2933 if (unlikely(pci_channel_offline(ha->pdev)))
2936 hccr = RD_REG_DWORD(®->hccr);
2938 ql_log(ql_log_info, vha, 0x5050,
2939 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2942 qla2xxx_check_risc_status(vha);
2944 ha->isp_ops->fw_dump(vha, 1);
2945 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2947 } else if ((stat & HSRX_RISC_INT) == 0)
2950 switch (stat & 0xff) {
2951 case INTR_ROM_MB_SUCCESS:
2952 case INTR_ROM_MB_FAILED:
2953 case INTR_MB_SUCCESS:
2954 case INTR_MB_FAILED:
2955 qla24xx_mbx_completion(vha, MSW(stat));
2956 status |= MBX_INTERRUPT;
2959 case INTR_ASYNC_EVENT:
2961 mb[1] = RD_REG_WORD(®->mailbox1);
2962 mb[2] = RD_REG_WORD(®->mailbox2);
2963 mb[3] = RD_REG_WORD(®->mailbox3);
2964 qla2x00_async_event(vha, rsp, mb);
2966 case INTR_RSP_QUE_UPDATE:
2967 case INTR_RSP_QUE_UPDATE_83XX:
2968 qla24xx_process_response_queue(vha, rsp);
2970 case INTR_ATIO_QUE_UPDATE:{
2971 unsigned long flags2;
2972 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
2973 qlt_24xx_process_atio_queue(vha, 1);
2974 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
2977 case INTR_ATIO_RSP_QUE_UPDATE: {
2978 unsigned long flags2;
2979 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
2980 qlt_24xx_process_atio_queue(vha, 1);
2981 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
2983 qla24xx_process_response_queue(vha, rsp);
2987 ql_dbg(ql_dbg_async, vha, 0x5051,
2988 "Unrecognized interrupt type (%d).\n", stat & 0xff);
2991 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
2993 qla2x00_handle_mbx_completion(ha, status);
2994 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2999 /* Interrupt handling helpers. */
3001 struct qla_init_msix_entry {
3003 irq_handler_t handler;
3006 static struct qla_init_msix_entry msix_entries[3] = {
3007 { "qla2xxx (default)", qla24xx_msix_default },
3008 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
3009 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
3012 static struct qla_init_msix_entry qla82xx_msix_entries[2] = {
3013 { "qla2xxx (default)", qla82xx_msix_default },
3014 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
3017 static struct qla_init_msix_entry qla83xx_msix_entries[3] = {
3018 { "qla2xxx (default)", qla24xx_msix_default },
3019 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
3020 { "qla2xxx (atio_q)", qla83xx_msix_atio_q },
3024 qla24xx_disable_msix(struct qla_hw_data *ha)
3027 struct qla_msix_entry *qentry;
3028 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
3030 for (i = 0; i < ha->msix_count; i++) {
3031 qentry = &ha->msix_entries[i];
3032 if (qentry->have_irq) {
3033 /* un-register irq cpu affinity notification */
3034 irq_set_affinity_notifier(qentry->vector, NULL);
3035 free_irq(qentry->vector, qentry->rsp);
3038 pci_disable_msix(ha->pdev);
3039 kfree(ha->msix_entries);
3040 ha->msix_entries = NULL;
3041 ha->flags.msix_enabled = 0;
3042 ql_dbg(ql_dbg_init, vha, 0x0042,
3043 "Disabled the MSI.\n");
3047 qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
3049 #define MIN_MSIX_COUNT 2
3050 #define ATIO_VECTOR 2
3052 struct msix_entry *entries;
3053 struct qla_msix_entry *qentry;
3054 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
3056 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
3059 ql_log(ql_log_warn, vha, 0x00bc,
3060 "Failed to allocate memory for msix_entry.\n");
3064 for (i = 0; i < ha->msix_count; i++)
3065 entries[i].entry = i;
3067 ret = pci_enable_msix_range(ha->pdev,
3068 entries, MIN_MSIX_COUNT, ha->msix_count);
3070 ql_log(ql_log_fatal, vha, 0x00c7,
3071 "MSI-X: Failed to enable support, "
3072 "giving up -- %d/%d.\n",
3073 ha->msix_count, ret);
3075 } else if (ret < ha->msix_count) {
3076 ql_log(ql_log_warn, vha, 0x00c6,
3077 "MSI-X: Failed to enable support "
3078 "-- %d/%d\n Retry with %d vectors.\n",
3079 ha->msix_count, ret, ret);
3080 ha->msix_count = ret;
3081 ha->max_rsp_queues = ha->msix_count - 1;
3083 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
3084 ha->msix_count, GFP_KERNEL);
3085 if (!ha->msix_entries) {
3086 ql_log(ql_log_fatal, vha, 0x00c8,
3087 "Failed to allocate memory for ha->msix_entries.\n");
3091 ha->flags.msix_enabled = 1;
3093 for (i = 0; i < ha->msix_count; i++) {
3094 qentry = &ha->msix_entries[i];
3095 qentry->vector = entries[i].vector;
3096 qentry->entry = entries[i].entry;
3097 qentry->have_irq = 0;
3099 qentry->irq_notify.notify = qla_irq_affinity_notify;
3100 qentry->irq_notify.release = qla_irq_affinity_release;
3104 /* Enable MSI-X vectors for the base queue */
3105 for (i = 0; i < 2; i++) {
3106 qentry = &ha->msix_entries[i];
3109 if (IS_P3P_TYPE(ha))
3110 ret = request_irq(qentry->vector,
3111 qla82xx_msix_entries[i].handler,
3112 0, qla82xx_msix_entries[i].name, rsp);
3114 ret = request_irq(qentry->vector,
3115 msix_entries[i].handler,
3116 0, msix_entries[i].name, rsp);
3118 goto msix_register_fail;
3119 qentry->have_irq = 1;
3121 /* Register for CPU affinity notification. */
3122 irq_set_affinity_notifier(qentry->vector, &qentry->irq_notify);
3124 /* Schedule work (ie. trigger a notification) to read cpu
3125 * mask for this specific irq.
3126 * kref_get is required because
3127 * irq_affinity_notify() will do
3130 kref_get(&qentry->irq_notify.kref);
3131 schedule_work(&qentry->irq_notify.work);
3135 * If target mode is enable, also request the vector for the ATIO
3138 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
3139 qentry = &ha->msix_entries[ATIO_VECTOR];
3142 ret = request_irq(qentry->vector,
3143 qla83xx_msix_entries[ATIO_VECTOR].handler,
3144 0, qla83xx_msix_entries[ATIO_VECTOR].name, rsp);
3145 qentry->have_irq = 1;
3150 ql_log(ql_log_fatal, vha, 0x00cb,
3151 "MSI-X: unable to register handler -- %x/%d.\n",
3152 qentry->vector, ret);
3153 qla24xx_disable_msix(ha);
3158 /* Enable MSI-X vector for response queue update for queue 0 */
3159 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3160 if (ha->msixbase && ha->mqiobase &&
3161 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
3165 && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
3167 ql_dbg(ql_dbg_multiq, vha, 0xc005,
3168 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3169 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
3170 ql_dbg(ql_dbg_init, vha, 0x0055,
3171 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3172 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
3179 pci_free_irq_vectors(ha->pdev);
3184 qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
3186 int ret = QLA_FUNCTION_FAILED;
3187 device_reg_t *reg = ha->iobase;
3188 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
3190 /* If possible, enable MSI-X. */
3191 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
3192 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLAFX00(ha) &&
3196 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
3197 (ha->pdev->subsystem_device == 0x7040 ||
3198 ha->pdev->subsystem_device == 0x7041 ||
3199 ha->pdev->subsystem_device == 0x1705)) {
3200 ql_log(ql_log_warn, vha, 0x0034,
3201 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
3202 ha->pdev->subsystem_vendor,
3203 ha->pdev->subsystem_device);
3207 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
3208 ql_log(ql_log_warn, vha, 0x0035,
3209 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
3210 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
3214 ret = qla24xx_enable_msix(ha, rsp);
3216 ql_dbg(ql_dbg_init, vha, 0x0036,
3217 "MSI-X: Enabled (0x%X, 0x%X).\n",
3218 ha->chip_revision, ha->fw_attributes);
3219 goto clear_risc_ints;
3224 ql_log(ql_log_info, vha, 0x0037,
3225 "Falling back-to MSI mode -%d.\n", ret);
3227 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
3228 !IS_QLA8001(ha) && !IS_P3P_TYPE(ha) && !IS_QLAFX00(ha) &&
3232 ret = pci_enable_msi(ha->pdev);
3234 ql_dbg(ql_dbg_init, vha, 0x0038,
3236 ha->flags.msi_enabled = 1;
3238 ql_log(ql_log_warn, vha, 0x0039,
3239 "Falling back-to INTa mode -- %d.\n", ret);
3242 /* Skip INTx on ISP82xx. */
3243 if (!ha->flags.msi_enabled && IS_QLA82XX(ha))
3244 return QLA_FUNCTION_FAILED;
3246 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
3247 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
3248 QLA2XXX_DRIVER_NAME, rsp);
3250 ql_log(ql_log_warn, vha, 0x003a,
3251 "Failed to reserve interrupt %d already in use.\n",
3254 } else if (!ha->flags.msi_enabled) {
3255 ql_dbg(ql_dbg_init, vha, 0x0125,
3256 "INTa mode: Enabled.\n");
3257 ha->flags.mr_intr_valid = 1;
3261 if (IS_FWI2_CAPABLE(ha) || IS_QLAFX00(ha))
3264 spin_lock_irq(&ha->hardware_lock);
3265 WRT_REG_WORD(®->isp.semaphore, 0);
3266 spin_unlock_irq(&ha->hardware_lock);
3273 qla2x00_free_irqs(scsi_qla_host_t *vha)
3275 struct qla_hw_data *ha = vha->hw;
3276 struct rsp_que *rsp;
3279 * We need to check that ha->rsp_q_map is valid in case we are called
3280 * from a probe failure context.
3282 if (!ha->rsp_q_map || !ha->rsp_q_map[0])
3284 rsp = ha->rsp_q_map[0];
3286 if (ha->flags.msix_enabled)
3287 qla24xx_disable_msix(ha);
3288 else if (ha->flags.msi_enabled) {
3289 free_irq(ha->pdev->irq, rsp);
3290 pci_disable_msi(ha->pdev);
3292 free_irq(ha->pdev->irq, rsp);
3296 int qla25xx_request_irq(struct rsp_que *rsp)
3298 struct qla_hw_data *ha = rsp->hw;
3299 struct qla_init_msix_entry *intr = &msix_entries[2];
3300 struct qla_msix_entry *msix = rsp->msix;
3301 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
3304 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
3306 ql_log(ql_log_fatal, vha, 0x00e6,
3307 "MSI-X: Unable to register handler -- %x/%d.\n",
3317 /* irq_set_affinity/irqbalance will trigger notification of cpu mask update */
3318 static void qla_irq_affinity_notify(struct irq_affinity_notify *notify,
3319 const cpumask_t *mask)
3321 struct qla_msix_entry *e =
3322 container_of(notify, struct qla_msix_entry, irq_notify);
3323 struct qla_hw_data *ha;
3324 struct scsi_qla_host *base_vha;
3326 /* user is recommended to set mask to just 1 cpu */
3327 e->cpuid = cpumask_first(mask);
3330 base_vha = pci_get_drvdata(ha->pdev);
3332 ql_dbg(ql_dbg_init, base_vha, 0xffff,
3333 "%s: host %ld : vector %d cpu %d \n", __func__,
3334 base_vha->host_no, e->vector, e->cpuid);
3337 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) &&
3338 (e->entry == QLA83XX_RSPQ_MSIX_ENTRY_NUMBER)) {
3339 ha->tgt.rspq_vector_cpuid = e->cpuid;
3340 ql_dbg(ql_dbg_init, base_vha, 0xffff,
3341 "%s: host%ld: rspq vector %d cpu %d runtime change\n",
3342 __func__, base_vha->host_no, e->vector, e->cpuid);
3347 static void qla_irq_affinity_release(struct kref *ref)
3349 struct irq_affinity_notify *notify =
3350 container_of(ref, struct irq_affinity_notify, kref);
3351 struct qla_msix_entry *e =
3352 container_of(notify, struct qla_msix_entry, irq_notify);
3353 struct scsi_qla_host *base_vha = pci_get_drvdata(e->rsp->hw->pdev);
3355 ql_dbg(ql_dbg_init, base_vha, 0xffff,
3356 "%s: host%ld: vector %d cpu %d \n", __func__,
3357 base_vha->host_no, e->vector, e->cpuid);