2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
8 #include "qla_target.h"
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <scsi/scsi_tcq.h>
13 #include <scsi/scsi_bsg_fc.h>
14 #include <scsi/scsi_eh.h>
16 static void qla2x00_mbx_completion(scsi_qla_host_t
*, uint16_t);
17 static void qla2x00_status_entry(scsi_qla_host_t
*, struct rsp_que
*, void *);
18 static void qla2x00_status_cont_entry(struct rsp_que
*, sts_cont_entry_t
*);
19 static void qla2x00_error_entry(scsi_qla_host_t
*, struct rsp_que
*,
23 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
25 * @dev_id: SCSI driver HA context
27 * Called by system whenever the host adapter generates an interrupt.
29 * Returns handled flag.
32 qla2100_intr_handler(int irq
, void *dev_id
)
35 struct qla_hw_data
*ha
;
36 struct device_reg_2xxx __iomem
*reg
;
44 rsp
= (struct rsp_que
*) dev_id
;
46 ql_log(ql_log_info
, NULL
, 0x505d,
47 "%s: NULL response queue pointer.\n", __func__
);
52 reg
= &ha
->iobase
->isp
;
55 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
56 vha
= pci_get_drvdata(ha
->pdev
);
57 for (iter
= 50; iter
--; ) {
58 hccr
= RD_REG_WORD(®
->hccr
);
59 if (qla2x00_check_reg16_for_disconnect(vha
, hccr
))
61 if (hccr
& HCCR_RISC_PAUSE
) {
62 if (pci_channel_offline(ha
->pdev
))
66 * Issue a "HARD" reset in order for the RISC interrupt
67 * bit to be cleared. Schedule a big hammer to get
68 * out of the RISC PAUSED state.
70 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
71 RD_REG_WORD(®
->hccr
);
73 ha
->isp_ops
->fw_dump(vha
, 1);
74 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
76 } else if ((RD_REG_WORD(®
->istatus
) & ISR_RISC_INT
) == 0)
79 if (RD_REG_WORD(®
->semaphore
) & BIT_0
) {
80 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
81 RD_REG_WORD(®
->hccr
);
83 /* Get mailbox data. */
84 mb
[0] = RD_MAILBOX_REG(ha
, reg
, 0);
85 if (mb
[0] > 0x3fff && mb
[0] < 0x8000) {
86 qla2x00_mbx_completion(vha
, mb
[0]);
87 status
|= MBX_INTERRUPT
;
88 } else if (mb
[0] > 0x7fff && mb
[0] < 0xc000) {
89 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
90 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
91 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
92 qla2x00_async_event(vha
, rsp
, mb
);
95 ql_dbg(ql_dbg_async
, vha
, 0x5025,
96 "Unrecognized interrupt type (%d).\n",
99 /* Release mailbox registers. */
100 WRT_REG_WORD(®
->semaphore
, 0);
101 RD_REG_WORD(®
->semaphore
);
103 qla2x00_process_response_queue(rsp
);
105 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
106 RD_REG_WORD(®
->hccr
);
109 qla2x00_handle_mbx_completion(ha
, status
);
110 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
112 return (IRQ_HANDLED
);
116 qla2x00_check_reg32_for_disconnect(scsi_qla_host_t
*vha
, uint32_t reg
)
118 /* Check for PCI disconnection */
119 if (reg
== 0xffffffff) {
121 * Schedule this on the default system workqueue so that all the
122 * adapter workqueues and the DPC thread can be shutdown
125 schedule_work(&vha
->hw
->board_disable
);
132 qla2x00_check_reg16_for_disconnect(scsi_qla_host_t
*vha
, uint16_t reg
)
134 return qla2x00_check_reg32_for_disconnect(vha
, 0xffff0000 | reg
);
138 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
140 * @dev_id: SCSI driver HA context
142 * Called by system whenever the host adapter generates an interrupt.
144 * Returns handled flag.
147 qla2300_intr_handler(int irq
, void *dev_id
)
149 scsi_qla_host_t
*vha
;
150 struct device_reg_2xxx __iomem
*reg
;
157 struct qla_hw_data
*ha
;
160 rsp
= (struct rsp_que
*) dev_id
;
162 ql_log(ql_log_info
, NULL
, 0x5058,
163 "%s: NULL response queue pointer.\n", __func__
);
168 reg
= &ha
->iobase
->isp
;
171 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
172 vha
= pci_get_drvdata(ha
->pdev
);
173 for (iter
= 50; iter
--; ) {
174 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
175 if (qla2x00_check_reg32_for_disconnect(vha
, stat
))
177 if (stat
& HSR_RISC_PAUSED
) {
178 if (unlikely(pci_channel_offline(ha
->pdev
)))
181 hccr
= RD_REG_WORD(®
->hccr
);
183 if (hccr
& (BIT_15
| BIT_13
| BIT_11
| BIT_8
))
184 ql_log(ql_log_warn
, vha
, 0x5026,
185 "Parity error -- HCCR=%x, Dumping "
186 "firmware.\n", hccr
);
188 ql_log(ql_log_warn
, vha
, 0x5027,
189 "RISC paused -- HCCR=%x, Dumping "
190 "firmware.\n", hccr
);
193 * Issue a "HARD" reset in order for the RISC
194 * interrupt bit to be cleared. Schedule a big
195 * hammer to get out of the RISC PAUSED state.
197 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
198 RD_REG_WORD(®
->hccr
);
200 ha
->isp_ops
->fw_dump(vha
, 1);
201 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
203 } else if ((stat
& HSR_RISC_INT
) == 0)
206 switch (stat
& 0xff) {
211 qla2x00_mbx_completion(vha
, MSW(stat
));
212 status
|= MBX_INTERRUPT
;
214 /* Release mailbox registers. */
215 WRT_REG_WORD(®
->semaphore
, 0);
219 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
220 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
221 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
222 qla2x00_async_event(vha
, rsp
, mb
);
225 qla2x00_process_response_queue(rsp
);
228 mb
[0] = MBA_CMPLT_1_16BIT
;
230 qla2x00_async_event(vha
, rsp
, mb
);
233 mb
[0] = MBA_SCSI_COMPLETION
;
235 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
236 qla2x00_async_event(vha
, rsp
, mb
);
239 ql_dbg(ql_dbg_async
, vha
, 0x5028,
240 "Unrecognized interrupt type (%d).\n", stat
& 0xff);
243 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
244 RD_REG_WORD_RELAXED(®
->hccr
);
246 qla2x00_handle_mbx_completion(ha
, status
);
247 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
249 return (IRQ_HANDLED
);
253 * qla2x00_mbx_completion() - Process mailbox command completions.
254 * @ha: SCSI driver HA context
255 * @mb0: Mailbox0 register
258 qla2x00_mbx_completion(scsi_qla_host_t
*vha
, uint16_t mb0
)
262 uint16_t __iomem
*wptr
;
263 struct qla_hw_data
*ha
= vha
->hw
;
264 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
266 /* Read all mbox registers? */
267 mboxes
= (1 << ha
->mbx_count
) - 1;
269 ql_dbg(ql_dbg_async
, vha
, 0x5001, "MBX pointer ERROR.\n");
271 mboxes
= ha
->mcp
->in_mb
;
273 /* Load return mailbox registers. */
274 ha
->flags
.mbox_int
= 1;
275 ha
->mailbox_out
[0] = mb0
;
277 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 1);
279 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
280 if (IS_QLA2200(ha
) && cnt
== 8)
281 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 8);
282 if ((cnt
== 4 || cnt
== 5) && (mboxes
& BIT_0
))
283 ha
->mailbox_out
[cnt
] = qla2x00_debounce_register(wptr
);
284 else if (mboxes
& BIT_0
)
285 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
293 qla81xx_idc_event(scsi_qla_host_t
*vha
, uint16_t aen
, uint16_t descr
)
295 static char *event
[] =
296 { "Complete", "Request Notification", "Time Extension" };
298 struct device_reg_24xx __iomem
*reg24
= &vha
->hw
->iobase
->isp24
;
299 struct device_reg_82xx __iomem
*reg82
= &vha
->hw
->iobase
->isp82
;
300 uint16_t __iomem
*wptr
;
301 uint16_t cnt
, timeout
, mb
[QLA_IDC_ACK_REGS
];
303 /* Seed data -- mailbox1 -> mailbox7. */
304 if (IS_QLA81XX(vha
->hw
) || IS_QLA83XX(vha
->hw
))
305 wptr
= (uint16_t __iomem
*)®24
->mailbox1
;
306 else if (IS_QLA8044(vha
->hw
))
307 wptr
= (uint16_t __iomem
*)®82
->mailbox_out
[1];
311 for (cnt
= 0; cnt
< QLA_IDC_ACK_REGS
; cnt
++, wptr
++)
312 mb
[cnt
] = RD_REG_WORD(wptr
);
314 ql_dbg(ql_dbg_async
, vha
, 0x5021,
315 "Inter-Driver Communication %s -- "
316 "%04x %04x %04x %04x %04x %04x %04x.\n",
317 event
[aen
& 0xff], mb
[0], mb
[1], mb
[2], mb
[3],
318 mb
[4], mb
[5], mb
[6]);
320 /* Handle IDC Error completion case. */
321 case MBA_IDC_COMPLETE
:
323 vha
->hw
->flags
.idc_compl_status
= 1;
324 if (vha
->hw
->notify_dcbx_comp
&& !vha
->vp_idx
)
325 complete(&vha
->hw
->dcbx_comp
);
330 /* Acknowledgement needed? [Notify && non-zero timeout]. */
331 timeout
= (descr
>> 8) & 0xf;
332 ql_dbg(ql_dbg_async
, vha
, 0x5022,
333 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
334 vha
->host_no
, event
[aen
& 0xff], timeout
);
338 rval
= qla2x00_post_idc_ack_work(vha
, mb
);
339 if (rval
!= QLA_SUCCESS
)
340 ql_log(ql_log_warn
, vha
, 0x5023,
341 "IDC failed to post ACK.\n");
343 case MBA_IDC_TIME_EXT
:
344 vha
->hw
->idc_extend_tmo
= descr
;
345 ql_dbg(ql_dbg_async
, vha
, 0x5087,
346 "%lu Inter-Driver Communication %s -- "
347 "Extend timeout by=%d.\n",
348 vha
->host_no
, event
[aen
& 0xff], vha
->hw
->idc_extend_tmo
);
355 qla2x00_get_link_speed_str(struct qla_hw_data
*ha
, uint16_t speed
)
357 static const char *const link_speeds
[] = {
358 "1", "2", "?", "4", "8", "16", "32", "10"
360 #define QLA_LAST_SPEED 7
362 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
363 return link_speeds
[0];
364 else if (speed
== 0x13)
365 return link_speeds
[QLA_LAST_SPEED
];
366 else if (speed
< QLA_LAST_SPEED
)
367 return link_speeds
[speed
];
369 return link_speeds
[LS_UNKNOWN
];
373 qla83xx_handle_8200_aen(scsi_qla_host_t
*vha
, uint16_t *mb
)
375 struct qla_hw_data
*ha
= vha
->hw
;
378 * 8200 AEN Interpretation:
380 * mb[1] = AEN Reason code
381 * mb[2] = LSW of Peg-Halt Status-1 Register
382 * mb[6] = MSW of Peg-Halt Status-1 Register
383 * mb[3] = LSW of Peg-Halt Status-2 register
384 * mb[7] = MSW of Peg-Halt Status-2 register
385 * mb[4] = IDC Device-State Register value
386 * mb[5] = IDC Driver-Presence Register value
388 ql_dbg(ql_dbg_async
, vha
, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: "
389 "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n",
390 mb
[0], mb
[1], mb
[2], mb
[6]);
391 ql_dbg(ql_dbg_async
, vha
, 0x506c, "PH-status2: mb[3] = 0x%x "
392 "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x "
393 "Drv-Presence: mb[5] = 0x%x.\n", mb
[3], mb
[7], mb
[4], mb
[5]);
395 if (mb
[1] & (IDC_PEG_HALT_STATUS_CHANGE
| IDC_NIC_FW_REPORTED_FAILURE
|
396 IDC_HEARTBEAT_FAILURE
)) {
397 ha
->flags
.nic_core_hung
= 1;
398 ql_log(ql_log_warn
, vha
, 0x5060,
399 "83XX: F/W Error Reported: Check if reset required.\n");
401 if (mb
[1] & IDC_PEG_HALT_STATUS_CHANGE
) {
402 uint32_t protocol_engine_id
, fw_err_code
, err_level
;
405 * IDC_PEG_HALT_STATUS_CHANGE interpretation:
406 * - PEG-Halt Status-1 Register:
407 * (LSW = mb[2], MSW = mb[6])
408 * Bits 0-7 = protocol-engine ID
409 * Bits 8-28 = f/w error code
410 * Bits 29-31 = Error-level
411 * Error-level 0x1 = Non-Fatal error
412 * Error-level 0x2 = Recoverable Fatal error
413 * Error-level 0x4 = UnRecoverable Fatal error
414 * - PEG-Halt Status-2 Register:
415 * (LSW = mb[3], MSW = mb[7])
417 protocol_engine_id
= (mb
[2] & 0xff);
418 fw_err_code
= (((mb
[2] & 0xff00) >> 8) |
419 ((mb
[6] & 0x1fff) << 8));
420 err_level
= ((mb
[6] & 0xe000) >> 13);
421 ql_log(ql_log_warn
, vha
, 0x5061, "PegHalt Status-1 "
422 "Register: protocol_engine_id=0x%x "
423 "fw_err_code=0x%x err_level=0x%x.\n",
424 protocol_engine_id
, fw_err_code
, err_level
);
425 ql_log(ql_log_warn
, vha
, 0x5062, "PegHalt Status-2 "
426 "Register: 0x%x%x.\n", mb
[7], mb
[3]);
427 if (err_level
== ERR_LEVEL_NON_FATAL
) {
428 ql_log(ql_log_warn
, vha
, 0x5063,
429 "Not a fatal error, f/w has recovered "
431 } else if (err_level
== ERR_LEVEL_RECOVERABLE_FATAL
) {
432 ql_log(ql_log_fatal
, vha
, 0x5064,
433 "Recoverable Fatal error: Chip reset "
435 qla83xx_schedule_work(vha
,
436 QLA83XX_NIC_CORE_RESET
);
437 } else if (err_level
== ERR_LEVEL_UNRECOVERABLE_FATAL
) {
438 ql_log(ql_log_fatal
, vha
, 0x5065,
439 "Unrecoverable Fatal error: Set FAILED "
440 "state, reboot required.\n");
441 qla83xx_schedule_work(vha
,
442 QLA83XX_NIC_CORE_UNRECOVERABLE
);
446 if (mb
[1] & IDC_NIC_FW_REPORTED_FAILURE
) {
447 uint16_t peg_fw_state
, nw_interface_link_up
;
448 uint16_t nw_interface_signal_detect
, sfp_status
;
449 uint16_t htbt_counter
, htbt_monitor_enable
;
450 uint16_t sfp_additonal_info
, sfp_multirate
;
451 uint16_t sfp_tx_fault
, link_speed
, dcbx_status
;
454 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
455 * - PEG-to-FC Status Register:
456 * (LSW = mb[2], MSW = mb[6])
457 * Bits 0-7 = Peg-Firmware state
458 * Bit 8 = N/W Interface Link-up
459 * Bit 9 = N/W Interface signal detected
460 * Bits 10-11 = SFP Status
461 * SFP Status 0x0 = SFP+ transceiver not expected
462 * SFP Status 0x1 = SFP+ transceiver not present
463 * SFP Status 0x2 = SFP+ transceiver invalid
464 * SFP Status 0x3 = SFP+ transceiver present and
466 * Bits 12-14 = Heartbeat Counter
467 * Bit 15 = Heartbeat Monitor Enable
468 * Bits 16-17 = SFP Additional Info
469 * SFP info 0x0 = Unregocnized transceiver for
471 * SFP info 0x1 = SFP+ brand validation failed
472 * SFP info 0x2 = SFP+ speed validation failed
473 * SFP info 0x3 = SFP+ access error
474 * Bit 18 = SFP Multirate
475 * Bit 19 = SFP Tx Fault
476 * Bits 20-22 = Link Speed
477 * Bits 23-27 = Reserved
478 * Bits 28-30 = DCBX Status
479 * DCBX Status 0x0 = DCBX Disabled
480 * DCBX Status 0x1 = DCBX Enabled
481 * DCBX Status 0x2 = DCBX Exchange error
484 peg_fw_state
= (mb
[2] & 0x00ff);
485 nw_interface_link_up
= ((mb
[2] & 0x0100) >> 8);
486 nw_interface_signal_detect
= ((mb
[2] & 0x0200) >> 9);
487 sfp_status
= ((mb
[2] & 0x0c00) >> 10);
488 htbt_counter
= ((mb
[2] & 0x7000) >> 12);
489 htbt_monitor_enable
= ((mb
[2] & 0x8000) >> 15);
490 sfp_additonal_info
= (mb
[6] & 0x0003);
491 sfp_multirate
= ((mb
[6] & 0x0004) >> 2);
492 sfp_tx_fault
= ((mb
[6] & 0x0008) >> 3);
493 link_speed
= ((mb
[6] & 0x0070) >> 4);
494 dcbx_status
= ((mb
[6] & 0x7000) >> 12);
496 ql_log(ql_log_warn
, vha
, 0x5066,
497 "Peg-to-Fc Status Register:\n"
498 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
499 "nw_interface_signal_detect=0x%x"
500 "\nsfp_statis=0x%x.\n ", peg_fw_state
,
501 nw_interface_link_up
, nw_interface_signal_detect
,
503 ql_log(ql_log_warn
, vha
, 0x5067,
504 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
505 "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ",
506 htbt_counter
, htbt_monitor_enable
,
507 sfp_additonal_info
, sfp_multirate
);
508 ql_log(ql_log_warn
, vha
, 0x5068,
509 "sfp_tx_fault=0x%x, link_state=0x%x, "
510 "dcbx_status=0x%x.\n", sfp_tx_fault
, link_speed
,
513 qla83xx_schedule_work(vha
, QLA83XX_NIC_CORE_RESET
);
516 if (mb
[1] & IDC_HEARTBEAT_FAILURE
) {
517 ql_log(ql_log_warn
, vha
, 0x5069,
518 "Heartbeat Failure encountered, chip reset "
521 qla83xx_schedule_work(vha
, QLA83XX_NIC_CORE_RESET
);
525 if (mb
[1] & IDC_DEVICE_STATE_CHANGE
) {
526 ql_log(ql_log_info
, vha
, 0x506a,
527 "IDC Device-State changed = 0x%x.\n", mb
[4]);
528 if (ha
->flags
.nic_core_reset_owner
)
530 qla83xx_schedule_work(vha
, MBA_IDC_AEN
);
535 qla2x00_is_a_vp_did(scsi_qla_host_t
*vha
, uint32_t rscn_entry
)
537 struct qla_hw_data
*ha
= vha
->hw
;
546 spin_lock_irqsave(&ha
->vport_slock
, flags
);
547 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
548 vp_did
= vp
->d_id
.b24
;
549 if (vp_did
== rscn_entry
) {
554 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
560 * qla2x00_async_event() - Process aynchronous events.
561 * @ha: SCSI driver HA context
562 * @mb: Mailbox registers (0 - 3)
565 qla2x00_async_event(scsi_qla_host_t
*vha
, struct rsp_que
*rsp
, uint16_t *mb
)
570 struct qla_hw_data
*ha
= vha
->hw
;
571 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
572 struct device_reg_24xx __iomem
*reg24
= &ha
->iobase
->isp24
;
573 struct device_reg_82xx __iomem
*reg82
= &ha
->iobase
->isp82
;
574 uint32_t rscn_entry
, host_pid
;
577 /* Setup to process RIO completion. */
579 if (IS_CNA_CAPABLE(ha
))
582 case MBA_SCSI_COMPLETION
:
583 handles
[0] = le32_to_cpu((uint32_t)((mb
[2] << 16) | mb
[1]));
586 case MBA_CMPLT_1_16BIT
:
589 mb
[0] = MBA_SCSI_COMPLETION
;
591 case MBA_CMPLT_2_16BIT
:
595 mb
[0] = MBA_SCSI_COMPLETION
;
597 case MBA_CMPLT_3_16BIT
:
602 mb
[0] = MBA_SCSI_COMPLETION
;
604 case MBA_CMPLT_4_16BIT
:
608 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
610 mb
[0] = MBA_SCSI_COMPLETION
;
612 case MBA_CMPLT_5_16BIT
:
616 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
617 handles
[4] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 7);
619 mb
[0] = MBA_SCSI_COMPLETION
;
621 case MBA_CMPLT_2_32BIT
:
622 handles
[0] = le32_to_cpu((uint32_t)((mb
[2] << 16) | mb
[1]));
623 handles
[1] = le32_to_cpu(
624 ((uint32_t)(RD_MAILBOX_REG(ha
, reg
, 7) << 16)) |
625 RD_MAILBOX_REG(ha
, reg
, 6));
627 mb
[0] = MBA_SCSI_COMPLETION
;
634 case MBA_SCSI_COMPLETION
: /* Fast Post */
635 if (!vha
->flags
.online
)
638 for (cnt
= 0; cnt
< handle_cnt
; cnt
++)
639 qla2x00_process_completed_request(vha
, rsp
->req
,
643 case MBA_RESET
: /* Reset */
644 ql_dbg(ql_dbg_async
, vha
, 0x5002,
645 "Asynchronous RESET.\n");
647 set_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
650 case MBA_SYSTEM_ERR
: /* System Error */
651 mbx
= (IS_QLA81XX(ha
) || IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) ?
652 RD_REG_WORD(®24
->mailbox7
) : 0;
653 ql_log(ql_log_warn
, vha
, 0x5003,
654 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
655 "mbx7=%xh.\n", mb
[1], mb
[2], mb
[3], mbx
);
657 ha
->isp_ops
->fw_dump(vha
, 1);
659 if (IS_FWI2_CAPABLE(ha
)) {
660 if (mb
[1] == 0 && mb
[2] == 0) {
661 ql_log(ql_log_fatal
, vha
, 0x5004,
662 "Unrecoverable Hardware Error: adapter "
663 "marked OFFLINE!\n");
664 vha
->flags
.online
= 0;
665 vha
->device_flags
|= DFLG_DEV_FAILED
;
667 /* Check to see if MPI timeout occurred */
668 if ((mbx
& MBX_3
) && (ha
->port_no
== 0))
669 set_bit(MPI_RESET_NEEDED
,
672 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
674 } else if (mb
[1] == 0) {
675 ql_log(ql_log_fatal
, vha
, 0x5005,
676 "Unrecoverable Hardware Error: adapter marked "
678 vha
->flags
.online
= 0;
679 vha
->device_flags
|= DFLG_DEV_FAILED
;
681 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
684 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
685 ql_log(ql_log_warn
, vha
, 0x5006,
686 "ISP Request Transfer Error (%x).\n", mb
[1]);
688 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
691 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
692 ql_log(ql_log_warn
, vha
, 0x5007,
693 "ISP Response Transfer Error.\n");
695 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
698 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
699 ql_dbg(ql_dbg_async
, vha
, 0x5008,
700 "Asynchronous WAKEUP_THRES.\n");
703 case MBA_LIP_OCCURRED
: /* Loop Initialization Procedure */
704 ql_dbg(ql_dbg_async
, vha
, 0x5009,
705 "LIP occurred (%x).\n", mb
[1]);
707 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
708 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
709 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
710 qla2x00_mark_all_devices_lost(vha
, 1);
714 atomic_set(&vha
->vp_state
, VP_FAILED
);
715 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
718 set_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
);
719 set_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
);
721 vha
->flags
.management_server_logged_in
= 0;
722 qla2x00_post_aen_work(vha
, FCH_EVT_LIP
, mb
[1]);
725 case MBA_LOOP_UP
: /* Loop Up Event */
726 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
727 ha
->link_data_rate
= PORT_SPEED_1GB
;
729 ha
->link_data_rate
= mb
[1];
731 ql_log(ql_log_info
, vha
, 0x500a,
732 "LOOP UP detected (%s Gbps).\n",
733 qla2x00_get_link_speed_str(ha
, ha
->link_data_rate
));
735 vha
->flags
.management_server_logged_in
= 0;
736 qla2x00_post_aen_work(vha
, FCH_EVT_LINKUP
, ha
->link_data_rate
);
739 case MBA_LOOP_DOWN
: /* Loop Down Event */
740 mbx
= (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
741 ? RD_REG_WORD(®24
->mailbox4
) : 0;
742 mbx
= (IS_P3P_TYPE(ha
)) ? RD_REG_WORD(®82
->mailbox_out
[4])
744 ql_log(ql_log_info
, vha
, 0x500b,
745 "LOOP DOWN detected (%x %x %x %x).\n",
746 mb
[1], mb
[2], mb
[3], mbx
);
748 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
749 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
750 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
751 vha
->device_flags
|= DFLG_NO_CABLE
;
752 qla2x00_mark_all_devices_lost(vha
, 1);
756 atomic_set(&vha
->vp_state
, VP_FAILED
);
757 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
760 vha
->flags
.management_server_logged_in
= 0;
761 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
762 qla2x00_post_aen_work(vha
, FCH_EVT_LINKDOWN
, 0);
765 case MBA_LIP_RESET
: /* LIP reset occurred */
766 ql_dbg(ql_dbg_async
, vha
, 0x500c,
767 "LIP reset occurred (%x).\n", mb
[1]);
769 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
770 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
771 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
772 qla2x00_mark_all_devices_lost(vha
, 1);
776 atomic_set(&vha
->vp_state
, VP_FAILED
);
777 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
780 set_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
782 ha
->operating_mode
= LOOP
;
783 vha
->flags
.management_server_logged_in
= 0;
784 qla2x00_post_aen_work(vha
, FCH_EVT_LIPRESET
, mb
[1]);
787 /* case MBA_DCBX_COMPLETE: */
788 case MBA_POINT_TO_POINT
: /* Point-to-Point */
792 if (IS_CNA_CAPABLE(ha
)) {
793 ql_dbg(ql_dbg_async
, vha
, 0x500d,
794 "DCBX Completed -- %04x %04x %04x.\n",
795 mb
[1], mb
[2], mb
[3]);
796 if (ha
->notify_dcbx_comp
&& !vha
->vp_idx
)
797 complete(&ha
->dcbx_comp
);
800 ql_dbg(ql_dbg_async
, vha
, 0x500e,
801 "Asynchronous P2P MODE received.\n");
804 * Until there's a transition from loop down to loop up, treat
805 * this as loop down only.
807 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
808 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
809 if (!atomic_read(&vha
->loop_down_timer
))
810 atomic_set(&vha
->loop_down_timer
,
812 qla2x00_mark_all_devices_lost(vha
, 1);
816 atomic_set(&vha
->vp_state
, VP_FAILED
);
817 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
820 if (!(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)))
821 set_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
823 set_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
);
824 set_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
);
826 ha
->flags
.gpsc_supported
= 1;
827 vha
->flags
.management_server_logged_in
= 0;
830 case MBA_CHG_IN_CONNECTION
: /* Change in connection mode */
834 ql_dbg(ql_dbg_async
, vha
, 0x500f,
835 "Configuration change detected: value=%x.\n", mb
[1]);
837 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
838 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
839 if (!atomic_read(&vha
->loop_down_timer
))
840 atomic_set(&vha
->loop_down_timer
,
842 qla2x00_mark_all_devices_lost(vha
, 1);
846 atomic_set(&vha
->vp_state
, VP_FAILED
);
847 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
850 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
851 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
854 case MBA_PORT_UPDATE
: /* Port database update */
856 * Handle only global and vn-port update events
859 * mb[1] = N_Port handle of changed port
860 * OR 0xffff for global event
861 * mb[2] = New login state
862 * 7 = Port logged out
863 * mb[3] = LSB is vp_idx, 0xff = all vps
865 * Skip processing if:
866 * Event is global, vp_idx is NOT all vps,
867 * vp_idx does not match
868 * Event is not global, vp_idx does not match
870 if (IS_QLA2XXX_MIDTYPE(ha
) &&
871 ((mb
[1] == 0xffff && (mb
[3] & 0xff) != 0xff) ||
872 (mb
[1] != 0xffff)) && vha
->vp_idx
!= (mb
[3] & 0xff))
875 /* Global event -- port logout or port unavailable. */
876 if (mb
[1] == 0xffff && mb
[2] == 0x7) {
877 ql_dbg(ql_dbg_async
, vha
, 0x5010,
878 "Port unavailable %04x %04x %04x.\n",
879 mb
[1], mb
[2], mb
[3]);
880 ql_log(ql_log_warn
, vha
, 0x505e,
881 "Link is offline.\n");
883 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
884 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
885 atomic_set(&vha
->loop_down_timer
,
887 vha
->device_flags
|= DFLG_NO_CABLE
;
888 qla2x00_mark_all_devices_lost(vha
, 1);
892 atomic_set(&vha
->vp_state
, VP_FAILED
);
893 fc_vport_set_state(vha
->fc_vport
,
895 qla2x00_mark_all_devices_lost(vha
, 1);
898 vha
->flags
.management_server_logged_in
= 0;
899 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
904 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
905 * event etc. earlier indicating loop is down) then process
906 * it. Otherwise ignore it and Wait for RSCN to come in.
908 atomic_set(&vha
->loop_down_timer
, 0);
909 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
&&
910 atomic_read(&vha
->loop_state
) != LOOP_DEAD
) {
911 ql_dbg(ql_dbg_async
, vha
, 0x5011,
912 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
913 mb
[1], mb
[2], mb
[3]);
915 qlt_async_event(mb
[0], vha
, mb
);
919 ql_dbg(ql_dbg_async
, vha
, 0x5012,
920 "Port database changed %04x %04x %04x.\n",
921 mb
[1], mb
[2], mb
[3]);
924 * Mark all devices as missing so we will login again.
926 atomic_set(&vha
->loop_state
, LOOP_UP
);
928 qla2x00_mark_all_devices_lost(vha
, 1);
930 if (vha
->vp_idx
== 0 && !qla_ini_mode_enabled(vha
))
931 set_bit(SCR_PENDING
, &vha
->dpc_flags
);
933 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
934 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
936 qlt_async_event(mb
[0], vha
, mb
);
939 case MBA_RSCN_UPDATE
: /* State Change Registration */
940 /* Check if the Vport has issued a SCR */
941 if (vha
->vp_idx
&& test_bit(VP_SCR_NEEDED
, &vha
->vp_flags
))
943 /* Only handle SCNs for our Vport index. */
944 if (ha
->flags
.npiv_supported
&& vha
->vp_idx
!= (mb
[3] & 0xff))
947 ql_dbg(ql_dbg_async
, vha
, 0x5013,
948 "RSCN database changed -- %04x %04x %04x.\n",
949 mb
[1], mb
[2], mb
[3]);
951 rscn_entry
= ((mb
[1] & 0xff) << 16) | mb
[2];
952 host_pid
= (vha
->d_id
.b
.domain
<< 16) | (vha
->d_id
.b
.area
<< 8)
954 if (rscn_entry
== host_pid
) {
955 ql_dbg(ql_dbg_async
, vha
, 0x5014,
956 "Ignoring RSCN update to local host "
957 "port ID (%06x).\n", host_pid
);
961 /* Ignore reserved bits from RSCN-payload. */
962 rscn_entry
= ((mb
[1] & 0x3ff) << 16) | mb
[2];
964 /* Skip RSCNs for virtual ports on the same physical port */
965 if (qla2x00_is_a_vp_did(vha
, rscn_entry
))
968 atomic_set(&vha
->loop_down_timer
, 0);
969 vha
->flags
.management_server_logged_in
= 0;
971 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
972 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
973 qla2x00_post_aen_work(vha
, FCH_EVT_RSCN
, rscn_entry
);
976 /* case MBA_RIO_RESPONSE: */
977 case MBA_ZIO_RESPONSE
:
978 ql_dbg(ql_dbg_async
, vha
, 0x5015,
979 "[R|Z]IO update completion.\n");
981 if (IS_FWI2_CAPABLE(ha
))
982 qla24xx_process_response_queue(vha
, rsp
);
984 qla2x00_process_response_queue(rsp
);
987 case MBA_DISCARD_RND_FRAME
:
988 ql_dbg(ql_dbg_async
, vha
, 0x5016,
989 "Discard RND Frame -- %04x %04x %04x.\n",
990 mb
[1], mb
[2], mb
[3]);
993 case MBA_TRACE_NOTIFICATION
:
994 ql_dbg(ql_dbg_async
, vha
, 0x5017,
995 "Trace Notification -- %04x %04x.\n", mb
[1], mb
[2]);
998 case MBA_ISP84XX_ALERT
:
999 ql_dbg(ql_dbg_async
, vha
, 0x5018,
1000 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
1001 mb
[1], mb
[2], mb
[3]);
1003 spin_lock_irqsave(&ha
->cs84xx
->access_lock
, flags
);
1005 case A84_PANIC_RECOVERY
:
1006 ql_log(ql_log_info
, vha
, 0x5019,
1007 "Alert 84XX: panic recovery %04x %04x.\n",
1010 case A84_OP_LOGIN_COMPLETE
:
1011 ha
->cs84xx
->op_fw_version
= mb
[3] << 16 | mb
[2];
1012 ql_log(ql_log_info
, vha
, 0x501a,
1013 "Alert 84XX: firmware version %x.\n",
1014 ha
->cs84xx
->op_fw_version
);
1016 case A84_DIAG_LOGIN_COMPLETE
:
1017 ha
->cs84xx
->diag_fw_version
= mb
[3] << 16 | mb
[2];
1018 ql_log(ql_log_info
, vha
, 0x501b,
1019 "Alert 84XX: diagnostic firmware version %x.\n",
1020 ha
->cs84xx
->diag_fw_version
);
1022 case A84_GOLD_LOGIN_COMPLETE
:
1023 ha
->cs84xx
->diag_fw_version
= mb
[3] << 16 | mb
[2];
1024 ha
->cs84xx
->fw_update
= 1;
1025 ql_log(ql_log_info
, vha
, 0x501c,
1026 "Alert 84XX: gold firmware version %x.\n",
1027 ha
->cs84xx
->gold_fw_version
);
1030 ql_log(ql_log_warn
, vha
, 0x501d,
1031 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
1032 mb
[1], mb
[2], mb
[3]);
1034 spin_unlock_irqrestore(&ha
->cs84xx
->access_lock
, flags
);
1036 case MBA_DCBX_START
:
1037 ql_dbg(ql_dbg_async
, vha
, 0x501e,
1038 "DCBX Started -- %04x %04x %04x.\n",
1039 mb
[1], mb
[2], mb
[3]);
1041 case MBA_DCBX_PARAM_UPDATE
:
1042 ql_dbg(ql_dbg_async
, vha
, 0x501f,
1043 "DCBX Parameters Updated -- %04x %04x %04x.\n",
1044 mb
[1], mb
[2], mb
[3]);
1046 case MBA_FCF_CONF_ERR
:
1047 ql_dbg(ql_dbg_async
, vha
, 0x5020,
1048 "FCF Configuration Error -- %04x %04x %04x.\n",
1049 mb
[1], mb
[2], mb
[3]);
1051 case MBA_IDC_NOTIFY
:
1052 if (IS_QLA8031(vha
->hw
) || IS_QLA8044(ha
)) {
1053 mb
[4] = RD_REG_WORD(®24
->mailbox4
);
1054 if (((mb
[2] & 0x7fff) == MBC_PORT_RESET
||
1055 (mb
[2] & 0x7fff) == MBC_SET_PORT_CONFIG
) &&
1056 (mb
[4] & INTERNAL_LOOPBACK_MASK
) != 0) {
1057 set_bit(ISP_QUIESCE_NEEDED
, &vha
->dpc_flags
);
1059 * Extend loop down timer since port is active.
1061 if (atomic_read(&vha
->loop_state
) == LOOP_DOWN
)
1062 atomic_set(&vha
->loop_down_timer
,
1064 qla2xxx_wake_dpc(vha
);
1067 case MBA_IDC_COMPLETE
:
1068 if (ha
->notify_lb_portup_comp
&& !vha
->vp_idx
)
1069 complete(&ha
->lb_portup_comp
);
1071 case MBA_IDC_TIME_EXT
:
1072 if (IS_QLA81XX(vha
->hw
) || IS_QLA8031(vha
->hw
) ||
1074 qla81xx_idc_event(vha
, mb
[0], mb
[1]);
1078 mb
[4] = RD_REG_WORD(®24
->mailbox4
);
1079 mb
[5] = RD_REG_WORD(®24
->mailbox5
);
1080 mb
[6] = RD_REG_WORD(®24
->mailbox6
);
1081 mb
[7] = RD_REG_WORD(®24
->mailbox7
);
1082 qla83xx_handle_8200_aen(vha
, mb
);
1086 ql_dbg(ql_dbg_async
, vha
, 0x5057,
1087 "Unknown AEN:%04x %04x %04x %04x\n",
1088 mb
[0], mb
[1], mb
[2], mb
[3]);
1091 qlt_async_event(mb
[0], vha
, mb
);
1093 if (!vha
->vp_idx
&& ha
->num_vhosts
)
1094 qla2x00_alert_all_vps(rsp
, mb
);
1098 * qla2x00_process_completed_request() - Process a Fast Post response.
1099 * @ha: SCSI driver HA context
1103 qla2x00_process_completed_request(struct scsi_qla_host
*vha
,
1104 struct req_que
*req
, uint32_t index
)
1107 struct qla_hw_data
*ha
= vha
->hw
;
1109 /* Validate handle. */
1110 if (index
>= req
->num_outstanding_cmds
) {
1111 ql_log(ql_log_warn
, vha
, 0x3014,
1112 "Invalid SCSI command index (%x).\n", index
);
1114 if (IS_P3P_TYPE(ha
))
1115 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
1117 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1121 sp
= req
->outstanding_cmds
[index
];
1123 /* Free outstanding command slot. */
1124 req
->outstanding_cmds
[index
] = NULL
;
1126 /* Save ISP completion status */
1127 sp
->done(ha
, sp
, DID_OK
<< 16);
1129 ql_log(ql_log_warn
, vha
, 0x3016, "Invalid SCSI SRB.\n");
1131 if (IS_P3P_TYPE(ha
))
1132 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
1134 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1139 qla2x00_get_sp_from_handle(scsi_qla_host_t
*vha
, const char *func
,
1140 struct req_que
*req
, void *iocb
)
1142 struct qla_hw_data
*ha
= vha
->hw
;
1143 sts_entry_t
*pkt
= iocb
;
1147 index
= LSW(pkt
->handle
);
1148 if (index
>= req
->num_outstanding_cmds
) {
1149 ql_log(ql_log_warn
, vha
, 0x5031,
1150 "Invalid command index (%x).\n", index
);
1151 if (IS_P3P_TYPE(ha
))
1152 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
1154 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1157 sp
= req
->outstanding_cmds
[index
];
1159 ql_log(ql_log_warn
, vha
, 0x5032,
1160 "Invalid completion handle (%x) -- timed-out.\n", index
);
1163 if (sp
->handle
!= index
) {
1164 ql_log(ql_log_warn
, vha
, 0x5033,
1165 "SRB handle (%x) mismatch %x.\n", sp
->handle
, index
);
1169 req
->outstanding_cmds
[index
] = NULL
;
1176 qla2x00_mbx_iocb_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
1177 struct mbx_entry
*mbx
)
1179 const char func
[] = "MBX-IOCB";
1183 struct srb_iocb
*lio
;
1187 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, mbx
);
1191 lio
= &sp
->u
.iocb_cmd
;
1193 fcport
= sp
->fcport
;
1194 data
= lio
->u
.logio
.data
;
1196 data
[0] = MBS_COMMAND_ERROR
;
1197 data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
1198 QLA_LOGIO_LOGIN_RETRIED
: 0;
1199 if (mbx
->entry_status
) {
1200 ql_dbg(ql_dbg_async
, vha
, 0x5043,
1201 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
1202 "entry-status=%x status=%x state-flag=%x "
1203 "status-flags=%x.\n", type
, sp
->handle
,
1204 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
1205 fcport
->d_id
.b
.al_pa
, mbx
->entry_status
,
1206 le16_to_cpu(mbx
->status
), le16_to_cpu(mbx
->state_flags
),
1207 le16_to_cpu(mbx
->status_flags
));
1209 ql_dump_buffer(ql_dbg_async
+ ql_dbg_buffer
, vha
, 0x5029,
1210 (uint8_t *)mbx
, sizeof(*mbx
));
1215 status
= le16_to_cpu(mbx
->status
);
1216 if (status
== 0x30 && sp
->type
== SRB_LOGIN_CMD
&&
1217 le16_to_cpu(mbx
->mb0
) == MBS_COMMAND_COMPLETE
)
1219 if (!status
&& le16_to_cpu(mbx
->mb0
) == MBS_COMMAND_COMPLETE
) {
1220 ql_dbg(ql_dbg_async
, vha
, 0x5045,
1221 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1222 type
, sp
->handle
, fcport
->d_id
.b
.domain
,
1223 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
1224 le16_to_cpu(mbx
->mb1
));
1226 data
[0] = MBS_COMMAND_COMPLETE
;
1227 if (sp
->type
== SRB_LOGIN_CMD
) {
1228 fcport
->port_type
= FCT_TARGET
;
1229 if (le16_to_cpu(mbx
->mb1
) & BIT_0
)
1230 fcport
->port_type
= FCT_INITIATOR
;
1231 else if (le16_to_cpu(mbx
->mb1
) & BIT_1
)
1232 fcport
->flags
|= FCF_FCP2_DEVICE
;
1237 data
[0] = le16_to_cpu(mbx
->mb0
);
1239 case MBS_PORT_ID_USED
:
1240 data
[1] = le16_to_cpu(mbx
->mb1
);
1242 case MBS_LOOP_ID_USED
:
1245 data
[0] = MBS_COMMAND_ERROR
;
1249 ql_log(ql_log_warn
, vha
, 0x5046,
1250 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1251 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type
, sp
->handle
,
1252 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
1253 status
, le16_to_cpu(mbx
->mb0
), le16_to_cpu(mbx
->mb1
),
1254 le16_to_cpu(mbx
->mb2
), le16_to_cpu(mbx
->mb6
),
1255 le16_to_cpu(mbx
->mb7
));
1258 sp
->done(vha
, sp
, 0);
1262 qla2x00_ct_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
1263 sts_entry_t
*pkt
, int iocb_type
)
1265 const char func
[] = "CT_IOCB";
1268 struct fc_bsg_job
*bsg_job
;
1269 uint16_t comp_status
;
1272 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, pkt
);
1276 bsg_job
= sp
->u
.bsg_job
;
1278 type
= "ct pass-through";
1280 comp_status
= le16_to_cpu(pkt
->comp_status
);
1282 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1283 * fc payload to the caller
1285 bsg_job
->reply
->reply_data
.ctels_reply
.status
= FC_CTELS_STATUS_OK
;
1286 bsg_job
->reply_len
= sizeof(struct fc_bsg_reply
);
1288 if (comp_status
!= CS_COMPLETE
) {
1289 if (comp_status
== CS_DATA_UNDERRUN
) {
1291 bsg_job
->reply
->reply_payload_rcv_len
=
1292 le16_to_cpu(((sts_entry_t
*)pkt
)->rsp_info_len
);
1294 ql_log(ql_log_warn
, vha
, 0x5048,
1295 "CT pass-through-%s error "
1296 "comp_status-status=0x%x total_byte = 0x%x.\n",
1298 bsg_job
->reply
->reply_payload_rcv_len
);
1300 ql_log(ql_log_warn
, vha
, 0x5049,
1301 "CT pass-through-%s error "
1302 "comp_status-status=0x%x.\n", type
, comp_status
);
1303 res
= DID_ERROR
<< 16;
1304 bsg_job
->reply
->reply_payload_rcv_len
= 0;
1306 ql_dump_buffer(ql_dbg_async
+ ql_dbg_buffer
, vha
, 0x5035,
1307 (uint8_t *)pkt
, sizeof(*pkt
));
1310 bsg_job
->reply
->reply_payload_rcv_len
=
1311 bsg_job
->reply_payload
.payload_len
;
1312 bsg_job
->reply_len
= 0;
1315 sp
->done(vha
, sp
, res
);
1319 qla24xx_els_ct_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
1320 struct sts_entry_24xx
*pkt
, int iocb_type
)
1322 const char func
[] = "ELS_CT_IOCB";
1325 struct fc_bsg_job
*bsg_job
;
1326 uint16_t comp_status
;
1327 uint32_t fw_status
[3];
1328 uint8_t* fw_sts_ptr
;
1331 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, pkt
);
1334 bsg_job
= sp
->u
.bsg_job
;
1338 case SRB_ELS_CMD_RPT
:
1339 case SRB_ELS_CMD_HST
:
1343 type
= "ct pass-through";
1346 ql_dbg(ql_dbg_user
, vha
, 0x503e,
1347 "Unrecognized SRB: (%p) type=%d.\n", sp
, sp
->type
);
1351 comp_status
= fw_status
[0] = le16_to_cpu(pkt
->comp_status
);
1352 fw_status
[1] = le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->error_subcode_1
);
1353 fw_status
[2] = le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->error_subcode_2
);
1355 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1356 * fc payload to the caller
1358 bsg_job
->reply
->reply_data
.ctels_reply
.status
= FC_CTELS_STATUS_OK
;
1359 bsg_job
->reply_len
= sizeof(struct fc_bsg_reply
) + sizeof(fw_status
);
1361 if (comp_status
!= CS_COMPLETE
) {
1362 if (comp_status
== CS_DATA_UNDERRUN
) {
1364 bsg_job
->reply
->reply_payload_rcv_len
=
1365 le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->total_byte_count
);
1367 ql_dbg(ql_dbg_user
, vha
, 0x503f,
1368 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
1369 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
1370 type
, sp
->handle
, comp_status
, fw_status
[1], fw_status
[2],
1371 le16_to_cpu(((struct els_sts_entry_24xx
*)
1372 pkt
)->total_byte_count
));
1373 fw_sts_ptr
= ((uint8_t*)bsg_job
->req
->sense
) + sizeof(struct fc_bsg_reply
);
1374 memcpy( fw_sts_ptr
, fw_status
, sizeof(fw_status
));
1377 ql_dbg(ql_dbg_user
, vha
, 0x5040,
1378 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
1379 "error subcode 1=0x%x error subcode 2=0x%x.\n",
1380 type
, sp
->handle
, comp_status
,
1381 le16_to_cpu(((struct els_sts_entry_24xx
*)
1382 pkt
)->error_subcode_1
),
1383 le16_to_cpu(((struct els_sts_entry_24xx
*)
1384 pkt
)->error_subcode_2
));
1385 res
= DID_ERROR
<< 16;
1386 bsg_job
->reply
->reply_payload_rcv_len
= 0;
1387 fw_sts_ptr
= ((uint8_t*)bsg_job
->req
->sense
) + sizeof(struct fc_bsg_reply
);
1388 memcpy( fw_sts_ptr
, fw_status
, sizeof(fw_status
));
1390 ql_dump_buffer(ql_dbg_user
+ ql_dbg_buffer
, vha
, 0x5056,
1391 (uint8_t *)pkt
, sizeof(*pkt
));
1395 bsg_job
->reply
->reply_payload_rcv_len
= bsg_job
->reply_payload
.payload_len
;
1396 bsg_job
->reply_len
= 0;
1399 sp
->done(vha
, sp
, res
);
1403 qla24xx_logio_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
1404 struct logio_entry_24xx
*logio
)
1406 const char func
[] = "LOGIO-IOCB";
1410 struct srb_iocb
*lio
;
1414 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, logio
);
1418 lio
= &sp
->u
.iocb_cmd
;
1420 fcport
= sp
->fcport
;
1421 data
= lio
->u
.logio
.data
;
1423 data
[0] = MBS_COMMAND_ERROR
;
1424 data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
1425 QLA_LOGIO_LOGIN_RETRIED
: 0;
1426 if (logio
->entry_status
) {
1427 ql_log(ql_log_warn
, fcport
->vha
, 0x5034,
1428 "Async-%s error entry - hdl=%x"
1429 "portid=%02x%02x%02x entry-status=%x.\n",
1430 type
, sp
->handle
, fcport
->d_id
.b
.domain
,
1431 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
1432 logio
->entry_status
);
1433 ql_dump_buffer(ql_dbg_async
+ ql_dbg_buffer
, vha
, 0x504d,
1434 (uint8_t *)logio
, sizeof(*logio
));
1439 if (le16_to_cpu(logio
->comp_status
) == CS_COMPLETE
) {
1440 ql_dbg(ql_dbg_async
, fcport
->vha
, 0x5036,
1441 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1442 "iop0=%x.\n", type
, sp
->handle
, fcport
->d_id
.b
.domain
,
1443 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
1444 le32_to_cpu(logio
->io_parameter
[0]));
1446 data
[0] = MBS_COMMAND_COMPLETE
;
1447 if (sp
->type
!= SRB_LOGIN_CMD
)
1450 iop
[0] = le32_to_cpu(logio
->io_parameter
[0]);
1451 if (iop
[0] & BIT_4
) {
1452 fcport
->port_type
= FCT_TARGET
;
1454 fcport
->flags
|= FCF_FCP2_DEVICE
;
1455 } else if (iop
[0] & BIT_5
)
1456 fcport
->port_type
= FCT_INITIATOR
;
1459 fcport
->flags
|= FCF_CONF_COMP_SUPPORTED
;
1461 if (logio
->io_parameter
[7] || logio
->io_parameter
[8])
1462 fcport
->supported_classes
|= FC_COS_CLASS2
;
1463 if (logio
->io_parameter
[9] || logio
->io_parameter
[10])
1464 fcport
->supported_classes
|= FC_COS_CLASS3
;
1469 iop
[0] = le32_to_cpu(logio
->io_parameter
[0]);
1470 iop
[1] = le32_to_cpu(logio
->io_parameter
[1]);
1472 case LSC_SCODE_PORTID_USED
:
1473 data
[0] = MBS_PORT_ID_USED
;
1474 data
[1] = LSW(iop
[1]);
1476 case LSC_SCODE_NPORT_USED
:
1477 data
[0] = MBS_LOOP_ID_USED
;
1480 data
[0] = MBS_COMMAND_ERROR
;
1484 ql_dbg(ql_dbg_async
, fcport
->vha
, 0x5037,
1485 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1486 "iop0=%x iop1=%x.\n", type
, sp
->handle
, fcport
->d_id
.b
.domain
,
1487 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
1488 le16_to_cpu(logio
->comp_status
),
1489 le32_to_cpu(logio
->io_parameter
[0]),
1490 le32_to_cpu(logio
->io_parameter
[1]));
1493 sp
->done(vha
, sp
, 0);
1497 qla24xx_tm_iocb_entry(scsi_qla_host_t
*vha
, struct req_que
*req
, void *tsk
)
1499 const char func
[] = "TMF-IOCB";
1503 struct srb_iocb
*iocb
;
1504 struct sts_entry_24xx
*sts
= (struct sts_entry_24xx
*)tsk
;
1506 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, tsk
);
1510 iocb
= &sp
->u
.iocb_cmd
;
1512 fcport
= sp
->fcport
;
1513 iocb
->u
.tmf
.data
= QLA_SUCCESS
;
1515 if (sts
->entry_status
) {
1516 ql_log(ql_log_warn
, fcport
->vha
, 0x5038,
1517 "Async-%s error - hdl=%x entry-status(%x).\n",
1518 type
, sp
->handle
, sts
->entry_status
);
1519 iocb
->u
.tmf
.data
= QLA_FUNCTION_FAILED
;
1520 } else if (sts
->comp_status
!= __constant_cpu_to_le16(CS_COMPLETE
)) {
1521 ql_log(ql_log_warn
, fcport
->vha
, 0x5039,
1522 "Async-%s error - hdl=%x completion status(%x).\n",
1523 type
, sp
->handle
, sts
->comp_status
);
1524 iocb
->u
.tmf
.data
= QLA_FUNCTION_FAILED
;
1525 } else if ((le16_to_cpu(sts
->scsi_status
) &
1526 SS_RESPONSE_INFO_LEN_VALID
)) {
1527 if (le32_to_cpu(sts
->rsp_data_len
) < 4) {
1528 ql_log(ql_log_warn
, fcport
->vha
, 0x503b,
1529 "Async-%s error - hdl=%x not enough response(%d).\n",
1530 type
, sp
->handle
, sts
->rsp_data_len
);
1531 } else if (sts
->data
[3]) {
1532 ql_log(ql_log_warn
, fcport
->vha
, 0x503c,
1533 "Async-%s error - hdl=%x response(%x).\n",
1534 type
, sp
->handle
, sts
->data
[3]);
1535 iocb
->u
.tmf
.data
= QLA_FUNCTION_FAILED
;
1539 if (iocb
->u
.tmf
.data
!= QLA_SUCCESS
)
1540 ql_dump_buffer(ql_dbg_async
+ ql_dbg_buffer
, vha
, 0x5055,
1541 (uint8_t *)sts
, sizeof(*sts
));
1543 sp
->done(vha
, sp
, 0);
1547 * qla2x00_process_response_queue() - Process response queue entries.
1548 * @ha: SCSI driver HA context
1551 qla2x00_process_response_queue(struct rsp_que
*rsp
)
1553 struct scsi_qla_host
*vha
;
1554 struct qla_hw_data
*ha
= rsp
->hw
;
1555 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1557 uint16_t handle_cnt
;
1560 vha
= pci_get_drvdata(ha
->pdev
);
1562 if (!vha
->flags
.online
)
1565 while (rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
1566 pkt
= (sts_entry_t
*)rsp
->ring_ptr
;
1569 if (rsp
->ring_index
== rsp
->length
) {
1570 rsp
->ring_index
= 0;
1571 rsp
->ring_ptr
= rsp
->ring
;
1576 if (pkt
->entry_status
!= 0) {
1577 qla2x00_error_entry(vha
, rsp
, pkt
);
1578 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1583 switch (pkt
->entry_type
) {
1585 qla2x00_status_entry(vha
, rsp
, pkt
);
1587 case STATUS_TYPE_21
:
1588 handle_cnt
= ((sts21_entry_t
*)pkt
)->handle_count
;
1589 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
1590 qla2x00_process_completed_request(vha
, rsp
->req
,
1591 ((sts21_entry_t
*)pkt
)->handle
[cnt
]);
1594 case STATUS_TYPE_22
:
1595 handle_cnt
= ((sts22_entry_t
*)pkt
)->handle_count
;
1596 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
1597 qla2x00_process_completed_request(vha
, rsp
->req
,
1598 ((sts22_entry_t
*)pkt
)->handle
[cnt
]);
1601 case STATUS_CONT_TYPE
:
1602 qla2x00_status_cont_entry(rsp
, (sts_cont_entry_t
*)pkt
);
1605 qla2x00_mbx_iocb_entry(vha
, rsp
->req
,
1606 (struct mbx_entry
*)pkt
);
1609 qla2x00_ct_entry(vha
, rsp
->req
, pkt
, CT_IOCB_TYPE
);
1612 /* Type Not Supported. */
1613 ql_log(ql_log_warn
, vha
, 0x504a,
1614 "Received unknown response pkt type %x "
1615 "entry status=%x.\n",
1616 pkt
->entry_type
, pkt
->entry_status
);
1619 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1623 /* Adjust ring index */
1624 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), rsp
->ring_index
);
1628 qla2x00_handle_sense(srb_t
*sp
, uint8_t *sense_data
, uint32_t par_sense_len
,
1629 uint32_t sense_len
, struct rsp_que
*rsp
, int res
)
1631 struct scsi_qla_host
*vha
= sp
->fcport
->vha
;
1632 struct scsi_cmnd
*cp
= GET_CMD_SP(sp
);
1633 uint32_t track_sense_len
;
1635 if (sense_len
>= SCSI_SENSE_BUFFERSIZE
)
1636 sense_len
= SCSI_SENSE_BUFFERSIZE
;
1638 SET_CMD_SENSE_LEN(sp
, sense_len
);
1639 SET_CMD_SENSE_PTR(sp
, cp
->sense_buffer
);
1640 track_sense_len
= sense_len
;
1642 if (sense_len
> par_sense_len
)
1643 sense_len
= par_sense_len
;
1645 memcpy(cp
->sense_buffer
, sense_data
, sense_len
);
1647 SET_CMD_SENSE_PTR(sp
, cp
->sense_buffer
+ sense_len
);
1648 track_sense_len
-= sense_len
;
1649 SET_CMD_SENSE_LEN(sp
, track_sense_len
);
1651 if (track_sense_len
!= 0) {
1652 rsp
->status_srb
= sp
;
1657 ql_dbg(ql_dbg_io
+ ql_dbg_buffer
, vha
, 0x301c,
1658 "Check condition Sense data, nexus%ld:%d:%llu cmd=%p.\n",
1659 sp
->fcport
->vha
->host_no
, cp
->device
->id
, cp
->device
->lun
,
1661 ql_dump_buffer(ql_dbg_io
+ ql_dbg_buffer
, vha
, 0x302b,
1662 cp
->sense_buffer
, sense_len
);
1666 struct scsi_dif_tuple
{
1667 __be16 guard
; /* Checksum */
1668 __be16 app_tag
; /* APPL identifier */
1669 __be32 ref_tag
; /* Target LBA or indirect LBA */
1673 * Checks the guard or meta-data for the type of error
1674 * detected by the HBA. In case of errors, we set the
1675 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1676 * to indicate to the kernel that the HBA detected error.
1679 qla2x00_handle_dif_error(srb_t
*sp
, struct sts_entry_24xx
*sts24
)
1681 struct scsi_qla_host
*vha
= sp
->fcport
->vha
;
1682 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
1683 uint8_t *ap
= &sts24
->data
[12];
1684 uint8_t *ep
= &sts24
->data
[20];
1685 uint32_t e_ref_tag
, a_ref_tag
;
1686 uint16_t e_app_tag
, a_app_tag
;
1687 uint16_t e_guard
, a_guard
;
1690 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1691 * would make guard field appear at offset 2
1693 a_guard
= le16_to_cpu(*(uint16_t *)(ap
+ 2));
1694 a_app_tag
= le16_to_cpu(*(uint16_t *)(ap
+ 0));
1695 a_ref_tag
= le32_to_cpu(*(uint32_t *)(ap
+ 4));
1696 e_guard
= le16_to_cpu(*(uint16_t *)(ep
+ 2));
1697 e_app_tag
= le16_to_cpu(*(uint16_t *)(ep
+ 0));
1698 e_ref_tag
= le32_to_cpu(*(uint32_t *)(ep
+ 4));
1700 ql_dbg(ql_dbg_io
, vha
, 0x3023,
1701 "iocb(s) %p Returned STATUS.\n", sts24
);
1703 ql_dbg(ql_dbg_io
, vha
, 0x3024,
1704 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
1705 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
1706 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
1707 cmd
->cmnd
[0], (u64
)scsi_get_lba(cmd
), a_ref_tag
, e_ref_tag
,
1708 a_app_tag
, e_app_tag
, a_guard
, e_guard
);
1712 * For type 3: ref & app tag is all 'f's
1713 * For type 0,1,2: app tag is all 'f's
1715 if ((a_app_tag
== 0xffff) &&
1716 ((scsi_get_prot_type(cmd
) != SCSI_PROT_DIF_TYPE3
) ||
1717 (a_ref_tag
== 0xffffffff))) {
1718 uint32_t blocks_done
, resid
;
1719 sector_t lba_s
= scsi_get_lba(cmd
);
1721 /* 2TB boundary case covered automatically with this */
1722 blocks_done
= e_ref_tag
- (uint32_t)lba_s
+ 1;
1724 resid
= scsi_bufflen(cmd
) - (blocks_done
*
1725 cmd
->device
->sector_size
);
1727 scsi_set_resid(cmd
, resid
);
1728 cmd
->result
= DID_OK
<< 16;
1730 /* Update protection tag */
1731 if (scsi_prot_sg_count(cmd
)) {
1732 uint32_t i
, j
= 0, k
= 0, num_ent
;
1733 struct scatterlist
*sg
;
1734 struct sd_dif_tuple
*spt
;
1736 /* Patch the corresponding protection tags */
1737 scsi_for_each_prot_sg(cmd
, sg
,
1738 scsi_prot_sg_count(cmd
), i
) {
1739 num_ent
= sg_dma_len(sg
) / 8;
1740 if (k
+ num_ent
< blocks_done
) {
1744 j
= blocks_done
- k
- 1;
1749 if (k
!= blocks_done
) {
1750 ql_log(ql_log_warn
, vha
, 0x302f,
1751 "unexpected tag values tag:lba=%x:%llx)\n",
1752 e_ref_tag
, (unsigned long long)lba_s
);
1756 spt
= page_address(sg_page(sg
)) + sg
->offset
;
1759 spt
->app_tag
= 0xffff;
1760 if (scsi_get_prot_type(cmd
) == SCSI_PROT_DIF_TYPE3
)
1761 spt
->ref_tag
= 0xffffffff;
1768 if (e_guard
!= a_guard
) {
1769 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
1771 set_driver_byte(cmd
, DRIVER_SENSE
);
1772 set_host_byte(cmd
, DID_ABORT
);
1773 cmd
->result
|= SAM_STAT_CHECK_CONDITION
<< 1;
1778 if (e_ref_tag
!= a_ref_tag
) {
1779 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
1781 set_driver_byte(cmd
, DRIVER_SENSE
);
1782 set_host_byte(cmd
, DID_ABORT
);
1783 cmd
->result
|= SAM_STAT_CHECK_CONDITION
<< 1;
1787 /* check appl tag */
1788 if (e_app_tag
!= a_app_tag
) {
1789 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
1791 set_driver_byte(cmd
, DRIVER_SENSE
);
1792 set_host_byte(cmd
, DID_ABORT
);
1793 cmd
->result
|= SAM_STAT_CHECK_CONDITION
<< 1;
1801 qla25xx_process_bidir_status_iocb(scsi_qla_host_t
*vha
, void *pkt
,
1802 struct req_que
*req
, uint32_t index
)
1804 struct qla_hw_data
*ha
= vha
->hw
;
1806 uint16_t comp_status
;
1807 uint16_t scsi_status
;
1809 uint32_t rval
= EXT_STATUS_OK
;
1810 struct fc_bsg_job
*bsg_job
= NULL
;
1812 struct sts_entry_24xx
*sts24
;
1813 sts
= (sts_entry_t
*) pkt
;
1814 sts24
= (struct sts_entry_24xx
*) pkt
;
1816 /* Validate handle. */
1817 if (index
>= req
->num_outstanding_cmds
) {
1818 ql_log(ql_log_warn
, vha
, 0x70af,
1819 "Invalid SCSI completion handle 0x%x.\n", index
);
1820 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1824 sp
= req
->outstanding_cmds
[index
];
1826 /* Free outstanding command slot. */
1827 req
->outstanding_cmds
[index
] = NULL
;
1828 bsg_job
= sp
->u
.bsg_job
;
1830 ql_log(ql_log_warn
, vha
, 0x70b0,
1831 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
1834 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1838 if (IS_FWI2_CAPABLE(ha
)) {
1839 comp_status
= le16_to_cpu(sts24
->comp_status
);
1840 scsi_status
= le16_to_cpu(sts24
->scsi_status
) & SS_MASK
;
1842 comp_status
= le16_to_cpu(sts
->comp_status
);
1843 scsi_status
= le16_to_cpu(sts
->scsi_status
) & SS_MASK
;
1846 thread_id
= bsg_job
->request
->rqst_data
.h_vendor
.vendor_cmd
[1];
1847 switch (comp_status
) {
1849 if (scsi_status
== 0) {
1850 bsg_job
->reply
->reply_payload_rcv_len
=
1851 bsg_job
->reply_payload
.payload_len
;
1852 vha
->qla_stats
.input_bytes
+=
1853 bsg_job
->reply
->reply_payload_rcv_len
;
1854 vha
->qla_stats
.input_requests
++;
1855 rval
= EXT_STATUS_OK
;
1859 case CS_DATA_OVERRUN
:
1860 ql_dbg(ql_dbg_user
, vha
, 0x70b1,
1861 "Command completed with date overrun thread_id=%d\n",
1863 rval
= EXT_STATUS_DATA_OVERRUN
;
1866 case CS_DATA_UNDERRUN
:
1867 ql_dbg(ql_dbg_user
, vha
, 0x70b2,
1868 "Command completed with date underrun thread_id=%d\n",
1870 rval
= EXT_STATUS_DATA_UNDERRUN
;
1872 case CS_BIDIR_RD_OVERRUN
:
1873 ql_dbg(ql_dbg_user
, vha
, 0x70b3,
1874 "Command completed with read data overrun thread_id=%d\n",
1876 rval
= EXT_STATUS_DATA_OVERRUN
;
1879 case CS_BIDIR_RD_WR_OVERRUN
:
1880 ql_dbg(ql_dbg_user
, vha
, 0x70b4,
1881 "Command completed with read and write data overrun "
1882 "thread_id=%d\n", thread_id
);
1883 rval
= EXT_STATUS_DATA_OVERRUN
;
1886 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN
:
1887 ql_dbg(ql_dbg_user
, vha
, 0x70b5,
1888 "Command completed with read data over and write data "
1889 "underrun thread_id=%d\n", thread_id
);
1890 rval
= EXT_STATUS_DATA_OVERRUN
;
1893 case CS_BIDIR_RD_UNDERRUN
:
1894 ql_dbg(ql_dbg_user
, vha
, 0x70b6,
1895 "Command completed with read data data underrun "
1896 "thread_id=%d\n", thread_id
);
1897 rval
= EXT_STATUS_DATA_UNDERRUN
;
1900 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN
:
1901 ql_dbg(ql_dbg_user
, vha
, 0x70b7,
1902 "Command completed with read data under and write data "
1903 "overrun thread_id=%d\n", thread_id
);
1904 rval
= EXT_STATUS_DATA_UNDERRUN
;
1907 case CS_BIDIR_RD_WR_UNDERRUN
:
1908 ql_dbg(ql_dbg_user
, vha
, 0x70b8,
1909 "Command completed with read and write data underrun "
1910 "thread_id=%d\n", thread_id
);
1911 rval
= EXT_STATUS_DATA_UNDERRUN
;
1915 ql_dbg(ql_dbg_user
, vha
, 0x70b9,
1916 "Command completed with data DMA error thread_id=%d\n",
1918 rval
= EXT_STATUS_DMA_ERR
;
1922 ql_dbg(ql_dbg_user
, vha
, 0x70ba,
1923 "Command completed with timeout thread_id=%d\n",
1925 rval
= EXT_STATUS_TIMEOUT
;
1928 ql_dbg(ql_dbg_user
, vha
, 0x70bb,
1929 "Command completed with completion status=0x%x "
1930 "thread_id=%d\n", comp_status
, thread_id
);
1931 rval
= EXT_STATUS_ERR
;
1934 bsg_job
->reply
->reply_payload_rcv_len
= 0;
1937 /* Return the vendor specific reply to API */
1938 bsg_job
->reply
->reply_data
.vendor_reply
.vendor_rsp
[0] = rval
;
1939 bsg_job
->reply_len
= sizeof(struct fc_bsg_reply
);
1940 /* Always return DID_OK, bsg will send the vendor specific response
1941 * in this case only */
1942 sp
->done(vha
, sp
, (DID_OK
<< 6));
1947 * qla2x00_status_entry() - Process a Status IOCB entry.
1948 * @ha: SCSI driver HA context
1949 * @pkt: Entry pointer
1952 qla2x00_status_entry(scsi_qla_host_t
*vha
, struct rsp_que
*rsp
, void *pkt
)
1956 struct scsi_cmnd
*cp
;
1958 struct sts_entry_24xx
*sts24
;
1959 uint16_t comp_status
;
1960 uint16_t scsi_status
;
1962 uint8_t lscsi_status
;
1964 uint32_t sense_len
, par_sense_len
, rsp_info_len
, resid_len
,
1966 uint8_t *rsp_info
, *sense_data
;
1967 struct qla_hw_data
*ha
= vha
->hw
;
1970 struct req_que
*req
;
1973 uint16_t state_flags
= 0;
1975 sts
= (sts_entry_t
*) pkt
;
1976 sts24
= (struct sts_entry_24xx
*) pkt
;
1977 if (IS_FWI2_CAPABLE(ha
)) {
1978 comp_status
= le16_to_cpu(sts24
->comp_status
);
1979 scsi_status
= le16_to_cpu(sts24
->scsi_status
) & SS_MASK
;
1980 state_flags
= le16_to_cpu(sts24
->state_flags
);
1982 comp_status
= le16_to_cpu(sts
->comp_status
);
1983 scsi_status
= le16_to_cpu(sts
->scsi_status
) & SS_MASK
;
1985 handle
= (uint32_t) LSW(sts
->handle
);
1986 que
= MSW(sts
->handle
);
1987 req
= ha
->req_q_map
[que
];
1989 /* Check for invalid queue pointer */
1991 que
>= find_first_zero_bit(ha
->req_qid_map
, ha
->max_req_queues
)) {
1992 ql_dbg(ql_dbg_io
, vha
, 0x3059,
1993 "Invalid status handle (0x%x): Bad req pointer. req=%p, "
1994 "que=%u.\n", sts
->handle
, req
, que
);
1998 /* Validate handle. */
1999 if (handle
< req
->num_outstanding_cmds
)
2000 sp
= req
->outstanding_cmds
[handle
];
2005 ql_dbg(ql_dbg_io
, vha
, 0x3017,
2006 "Invalid status handle (0x%x).\n", sts
->handle
);
2008 if (!test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)) {
2009 if (IS_P3P_TYPE(ha
))
2010 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
2012 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2013 qla2xxx_wake_dpc(vha
);
2018 if (unlikely((state_flags
& BIT_1
) && (sp
->type
== SRB_BIDI_CMD
))) {
2019 qla25xx_process_bidir_status_iocb(vha
, pkt
, req
, handle
);
2023 /* Task Management completion. */
2024 if (sp
->type
== SRB_TM_CMD
) {
2025 qla24xx_tm_iocb_entry(vha
, req
, pkt
);
2029 /* Fast path completion. */
2030 if (comp_status
== CS_COMPLETE
&& scsi_status
== 0) {
2031 qla2x00_process_completed_request(vha
, req
, handle
);
2036 req
->outstanding_cmds
[handle
] = NULL
;
2037 cp
= GET_CMD_SP(sp
);
2039 ql_dbg(ql_dbg_io
, vha
, 0x3018,
2040 "Command already returned (0x%x/%p).\n",
2046 lscsi_status
= scsi_status
& STATUS_MASK
;
2048 fcport
= sp
->fcport
;
2051 sense_len
= par_sense_len
= rsp_info_len
= resid_len
=
2053 if (IS_FWI2_CAPABLE(ha
)) {
2054 if (scsi_status
& SS_SENSE_LEN_VALID
)
2055 sense_len
= le32_to_cpu(sts24
->sense_len
);
2056 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
)
2057 rsp_info_len
= le32_to_cpu(sts24
->rsp_data_len
);
2058 if (scsi_status
& (SS_RESIDUAL_UNDER
| SS_RESIDUAL_OVER
))
2059 resid_len
= le32_to_cpu(sts24
->rsp_residual_count
);
2060 if (comp_status
== CS_DATA_UNDERRUN
)
2061 fw_resid_len
= le32_to_cpu(sts24
->residual_len
);
2062 rsp_info
= sts24
->data
;
2063 sense_data
= sts24
->data
;
2064 host_to_fcp_swap(sts24
->data
, sizeof(sts24
->data
));
2065 ox_id
= le16_to_cpu(sts24
->ox_id
);
2066 par_sense_len
= sizeof(sts24
->data
);
2068 if (scsi_status
& SS_SENSE_LEN_VALID
)
2069 sense_len
= le16_to_cpu(sts
->req_sense_length
);
2070 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
)
2071 rsp_info_len
= le16_to_cpu(sts
->rsp_info_len
);
2072 resid_len
= le32_to_cpu(sts
->residual_length
);
2073 rsp_info
= sts
->rsp_info
;
2074 sense_data
= sts
->req_sense_data
;
2075 par_sense_len
= sizeof(sts
->req_sense_data
);
2078 /* Check for any FCP transport errors. */
2079 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
) {
2080 /* Sense data lies beyond any FCP RESPONSE data. */
2081 if (IS_FWI2_CAPABLE(ha
)) {
2082 sense_data
+= rsp_info_len
;
2083 par_sense_len
-= rsp_info_len
;
2085 if (rsp_info_len
> 3 && rsp_info
[3]) {
2086 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x3019,
2087 "FCP I/O protocol failure (0x%x/0x%x).\n",
2088 rsp_info_len
, rsp_info
[3]);
2090 res
= DID_BUS_BUSY
<< 16;
2095 /* Check for overrun. */
2096 if (IS_FWI2_CAPABLE(ha
) && comp_status
== CS_COMPLETE
&&
2097 scsi_status
& SS_RESIDUAL_OVER
)
2098 comp_status
= CS_DATA_OVERRUN
;
2101 * Based on Host and scsi status generate status code for Linux
2103 switch (comp_status
) {
2106 if (scsi_status
== 0) {
2110 if (scsi_status
& (SS_RESIDUAL_UNDER
| SS_RESIDUAL_OVER
)) {
2112 scsi_set_resid(cp
, resid
);
2114 if (!lscsi_status
&&
2115 ((unsigned)(scsi_bufflen(cp
) - resid
) <
2117 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x301a,
2118 "Mid-layer underflow "
2119 "detected (0x%x of 0x%x bytes).\n",
2120 resid
, scsi_bufflen(cp
));
2122 res
= DID_ERROR
<< 16;
2126 res
= DID_OK
<< 16 | lscsi_status
;
2128 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
) {
2129 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x301b,
2130 "QUEUE FULL detected.\n");
2134 if (lscsi_status
!= SS_CHECK_CONDITION
)
2137 memset(cp
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
2138 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
2141 qla2x00_handle_sense(sp
, sense_data
, par_sense_len
, sense_len
,
2145 case CS_DATA_UNDERRUN
:
2146 /* Use F/W calculated residual length. */
2147 resid
= IS_FWI2_CAPABLE(ha
) ? fw_resid_len
: resid_len
;
2148 scsi_set_resid(cp
, resid
);
2149 if (scsi_status
& SS_RESIDUAL_UNDER
) {
2150 if (IS_FWI2_CAPABLE(ha
) && fw_resid_len
!= resid_len
) {
2151 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x301d,
2152 "Dropped frame(s) detected "
2153 "(0x%x of 0x%x bytes).\n",
2154 resid
, scsi_bufflen(cp
));
2156 res
= DID_ERROR
<< 16 | lscsi_status
;
2157 goto check_scsi_status
;
2160 if (!lscsi_status
&&
2161 ((unsigned)(scsi_bufflen(cp
) - resid
) <
2163 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x301e,
2164 "Mid-layer underflow "
2165 "detected (0x%x of 0x%x bytes).\n",
2166 resid
, scsi_bufflen(cp
));
2168 res
= DID_ERROR
<< 16;
2171 } else if (lscsi_status
!= SAM_STAT_TASK_SET_FULL
&&
2172 lscsi_status
!= SAM_STAT_BUSY
) {
2174 * scsi status of task set and busy are considered to be
2175 * task not completed.
2178 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x301f,
2179 "Dropped frame(s) detected (0x%x "
2180 "of 0x%x bytes).\n", resid
,
2183 res
= DID_ERROR
<< 16 | lscsi_status
;
2184 goto check_scsi_status
;
2186 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x3030,
2187 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2188 scsi_status
, lscsi_status
);
2191 res
= DID_OK
<< 16 | lscsi_status
;
2196 * Check to see if SCSI Status is non zero. If so report SCSI
2199 if (lscsi_status
!= 0) {
2200 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
) {
2201 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x3020,
2202 "QUEUE FULL detected.\n");
2206 if (lscsi_status
!= SS_CHECK_CONDITION
)
2209 memset(cp
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
2210 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
2213 qla2x00_handle_sense(sp
, sense_data
, par_sense_len
,
2214 sense_len
, rsp
, res
);
2218 case CS_PORT_LOGGED_OUT
:
2219 case CS_PORT_CONFIG_CHG
:
2222 case CS_PORT_UNAVAILABLE
:
2227 * We are going to have the fc class block the rport
2228 * while we try to recover so instruct the mid layer
2229 * to requeue until the class decides how to handle this.
2231 res
= DID_TRANSPORT_DISRUPTED
<< 16;
2233 if (comp_status
== CS_TIMEOUT
) {
2234 if (IS_FWI2_CAPABLE(ha
))
2236 else if ((le16_to_cpu(sts
->status_flags
) &
2237 SF_LOGOUT_SENT
) == 0)
2241 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x3021,
2242 "Port to be marked lost on fcport=%02x%02x%02x, current "
2243 "port state= %s.\n", fcport
->d_id
.b
.domain
,
2244 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
2245 port_state_str
[atomic_read(&fcport
->state
)]);
2247 if (atomic_read(&fcport
->state
) == FCS_ONLINE
)
2248 qla2x00_mark_device_lost(fcport
->vha
, fcport
, 1, 1);
2252 res
= DID_RESET
<< 16;
2256 logit
= qla2x00_handle_dif_error(sp
, sts24
);
2261 res
= DID_ERROR
<< 16;
2263 if (!IS_PI_SPLIT_DET_CAPABLE(ha
))
2266 if (state_flags
& BIT_4
)
2267 scmd_printk(KERN_WARNING
, cp
,
2268 "Unsupported device '%s' found.\n",
2269 cp
->device
->vendor
);
2273 res
= DID_ERROR
<< 16;
2279 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x3022,
2280 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%llu "
2281 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
2282 "rsp_info=0x%x resid=0x%x fw_resid=0x%x.\n",
2283 comp_status
, scsi_status
, res
, vha
->host_no
,
2284 cp
->device
->id
, cp
->device
->lun
, fcport
->d_id
.b
.domain
,
2285 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
, ox_id
,
2286 cp
->cmnd
, scsi_bufflen(cp
), rsp_info_len
,
2287 resid_len
, fw_resid_len
);
2289 if (rsp
->status_srb
== NULL
)
2290 sp
->done(ha
, sp
, res
);
2294 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2295 * @ha: SCSI driver HA context
2296 * @pkt: Entry pointer
2298 * Extended sense data.
2301 qla2x00_status_cont_entry(struct rsp_que
*rsp
, sts_cont_entry_t
*pkt
)
2303 uint8_t sense_sz
= 0;
2304 struct qla_hw_data
*ha
= rsp
->hw
;
2305 struct scsi_qla_host
*vha
= pci_get_drvdata(ha
->pdev
);
2306 srb_t
*sp
= rsp
->status_srb
;
2307 struct scsi_cmnd
*cp
;
2311 if (!sp
|| !GET_CMD_SENSE_LEN(sp
))
2314 sense_len
= GET_CMD_SENSE_LEN(sp
);
2315 sense_ptr
= GET_CMD_SENSE_PTR(sp
);
2317 cp
= GET_CMD_SP(sp
);
2319 ql_log(ql_log_warn
, vha
, 0x3025,
2320 "cmd is NULL: already returned to OS (sp=%p).\n", sp
);
2322 rsp
->status_srb
= NULL
;
2326 if (sense_len
> sizeof(pkt
->data
))
2327 sense_sz
= sizeof(pkt
->data
);
2329 sense_sz
= sense_len
;
2331 /* Move sense data. */
2332 if (IS_FWI2_CAPABLE(ha
))
2333 host_to_fcp_swap(pkt
->data
, sizeof(pkt
->data
));
2334 memcpy(sense_ptr
, pkt
->data
, sense_sz
);
2335 ql_dump_buffer(ql_dbg_io
+ ql_dbg_buffer
, vha
, 0x302c,
2336 sense_ptr
, sense_sz
);
2338 sense_len
-= sense_sz
;
2339 sense_ptr
+= sense_sz
;
2341 SET_CMD_SENSE_PTR(sp
, sense_ptr
);
2342 SET_CMD_SENSE_LEN(sp
, sense_len
);
2344 /* Place command on done queue. */
2345 if (sense_len
== 0) {
2346 rsp
->status_srb
= NULL
;
2347 sp
->done(ha
, sp
, cp
->result
);
2352 * qla2x00_error_entry() - Process an error entry.
2353 * @ha: SCSI driver HA context
2354 * @pkt: Entry pointer
2357 qla2x00_error_entry(scsi_qla_host_t
*vha
, struct rsp_que
*rsp
, sts_entry_t
*pkt
)
2360 struct qla_hw_data
*ha
= vha
->hw
;
2361 const char func
[] = "ERROR-IOCB";
2362 uint16_t que
= MSW(pkt
->handle
);
2363 struct req_que
*req
= NULL
;
2364 int res
= DID_ERROR
<< 16;
2366 ql_dbg(ql_dbg_async
, vha
, 0x502a,
2367 "type of error status in response: 0x%x\n", pkt
->entry_status
);
2369 if (que
>= ha
->max_req_queues
|| !ha
->req_q_map
[que
])
2372 req
= ha
->req_q_map
[que
];
2374 if (pkt
->entry_status
& RF_BUSY
)
2375 res
= DID_BUS_BUSY
<< 16;
2377 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, pkt
);
2379 sp
->done(ha
, sp
, res
);
2383 ql_log(ql_log_warn
, vha
, 0x5030,
2384 "Error entry - invalid handle/queue.\n");
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
);
2394 * qla24xx_mbx_completion() - Process mailbox command completions.
2395 * @ha: SCSI driver HA context
2396 * @mb0: Mailbox0 register
2399 qla24xx_mbx_completion(scsi_qla_host_t
*vha
, uint16_t mb0
)
2403 uint16_t __iomem
*wptr
;
2404 struct qla_hw_data
*ha
= vha
->hw
;
2405 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2407 /* Read all mbox registers? */
2408 mboxes
= (1 << ha
->mbx_count
) - 1;
2410 ql_dbg(ql_dbg_async
, vha
, 0x504e, "MBX pointer ERROR.\n");
2412 mboxes
= ha
->mcp
->in_mb
;
2414 /* Load return mailbox registers. */
2415 ha
->flags
.mbox_int
= 1;
2416 ha
->mailbox_out
[0] = mb0
;
2418 wptr
= (uint16_t __iomem
*)®
->mailbox1
;
2420 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
2422 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
2430 qla24xx_abort_iocb_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
2431 struct abort_entry_24xx
*pkt
)
2433 const char func
[] = "ABT_IOCB";
2435 struct srb_iocb
*abt
;
2437 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, pkt
);
2441 abt
= &sp
->u
.iocb_cmd
;
2442 abt
->u
.abt
.comp_status
= le32_to_cpu(pkt
->nport_handle
);
2443 sp
->done(vha
, sp
, 0);
2447 * qla24xx_process_response_queue() - Process response queue entries.
2448 * @ha: SCSI driver HA context
2450 void qla24xx_process_response_queue(struct scsi_qla_host
*vha
,
2451 struct rsp_que
*rsp
)
2453 struct sts_entry_24xx
*pkt
;
2454 struct qla_hw_data
*ha
= vha
->hw
;
2456 if (!vha
->flags
.online
)
2459 while (rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
2460 pkt
= (struct sts_entry_24xx
*)rsp
->ring_ptr
;
2463 if (rsp
->ring_index
== rsp
->length
) {
2464 rsp
->ring_index
= 0;
2465 rsp
->ring_ptr
= rsp
->ring
;
2470 if (pkt
->entry_status
!= 0) {
2471 qla2x00_error_entry(vha
, rsp
, (sts_entry_t
*) pkt
);
2473 if (qlt_24xx_process_response_error(vha
, pkt
))
2476 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
2482 switch (pkt
->entry_type
) {
2484 qla2x00_status_entry(vha
, rsp
, pkt
);
2486 case STATUS_CONT_TYPE
:
2487 qla2x00_status_cont_entry(rsp
, (sts_cont_entry_t
*)pkt
);
2489 case VP_RPT_ID_IOCB_TYPE
:
2490 qla24xx_report_id_acquisition(vha
,
2491 (struct vp_rpt_id_entry_24xx
*)pkt
);
2493 case LOGINOUT_PORT_IOCB_TYPE
:
2494 qla24xx_logio_entry(vha
, rsp
->req
,
2495 (struct logio_entry_24xx
*)pkt
);
2498 qla24xx_els_ct_entry(vha
, rsp
->req
, pkt
, CT_IOCB_TYPE
);
2501 qla24xx_els_ct_entry(vha
, rsp
->req
, pkt
, ELS_IOCB_TYPE
);
2503 case ABTS_RECV_24XX
:
2504 /* ensure that the ATIO queue is empty */
2505 qlt_24xx_process_atio_queue(vha
);
2506 case ABTS_RESP_24XX
:
2508 case NOTIFY_ACK_TYPE
:
2510 qlt_response_pkt_all_vps(vha
, (response_t
*)pkt
);
2513 /* Do nothing in this case, this check is to prevent it
2514 * from falling into default case
2517 case ABORT_IOCB_TYPE
:
2518 qla24xx_abort_iocb_entry(vha
, rsp
->req
,
2519 (struct abort_entry_24xx
*)pkt
);
2522 /* Type Not Supported. */
2523 ql_dbg(ql_dbg_async
, vha
, 0x5042,
2524 "Received unknown response pkt type %x "
2525 "entry status=%x.\n",
2526 pkt
->entry_type
, pkt
->entry_status
);
2529 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
2533 /* Adjust ring index */
2534 if (IS_P3P_TYPE(ha
)) {
2535 struct device_reg_82xx __iomem
*reg
= &ha
->iobase
->isp82
;
2536 WRT_REG_DWORD(®
->rsp_q_out
[0], rsp
->ring_index
);
2538 WRT_REG_DWORD(rsp
->rsp_q_out
, rsp
->ring_index
);
2542 qla2xxx_check_risc_status(scsi_qla_host_t
*vha
)
2546 struct qla_hw_data
*ha
= vha
->hw
;
2547 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2549 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
2554 WRT_REG_DWORD(®
->iobase_addr
, 0x7C00);
2555 RD_REG_DWORD(®
->iobase_addr
);
2556 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
2557 for (cnt
= 10000; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
2558 rval
== QLA_SUCCESS
; cnt
--) {
2560 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
2563 rval
= QLA_FUNCTION_TIMEOUT
;
2565 if (rval
== QLA_SUCCESS
)
2569 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
2570 for (cnt
= 100; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
2571 rval
== QLA_SUCCESS
; cnt
--) {
2573 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
2576 rval
= QLA_FUNCTION_TIMEOUT
;
2578 if (rval
!= QLA_SUCCESS
)
2582 if (RD_REG_DWORD(®
->iobase_c8
) & BIT_3
)
2583 ql_log(ql_log_info
, vha
, 0x504c,
2584 "Additional code -- 0x55AA.\n");
2587 WRT_REG_DWORD(®
->iobase_window
, 0x0000);
2588 RD_REG_DWORD(®
->iobase_window
);
2592 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
2594 * @dev_id: SCSI driver HA context
2596 * Called by system whenever the host adapter generates an interrupt.
2598 * Returns handled flag.
2601 qla24xx_intr_handler(int irq
, void *dev_id
)
2603 scsi_qla_host_t
*vha
;
2604 struct qla_hw_data
*ha
;
2605 struct device_reg_24xx __iomem
*reg
;
2611 struct rsp_que
*rsp
;
2612 unsigned long flags
;
2614 rsp
= (struct rsp_que
*) dev_id
;
2616 ql_log(ql_log_info
, NULL
, 0x5059,
2617 "%s: NULL response queue pointer.\n", __func__
);
2622 reg
= &ha
->iobase
->isp24
;
2625 if (unlikely(pci_channel_offline(ha
->pdev
)))
2628 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2629 vha
= pci_get_drvdata(ha
->pdev
);
2630 for (iter
= 50; iter
--; ) {
2631 stat
= RD_REG_DWORD(®
->host_status
);
2632 if (qla2x00_check_reg32_for_disconnect(vha
, stat
))
2634 if (stat
& HSRX_RISC_PAUSED
) {
2635 if (unlikely(pci_channel_offline(ha
->pdev
)))
2638 hccr
= RD_REG_DWORD(®
->hccr
);
2640 ql_log(ql_log_warn
, vha
, 0x504b,
2641 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2644 qla2xxx_check_risc_status(vha
);
2646 ha
->isp_ops
->fw_dump(vha
, 1);
2647 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2649 } else if ((stat
& HSRX_RISC_INT
) == 0)
2652 switch (stat
& 0xff) {
2653 case INTR_ROM_MB_SUCCESS
:
2654 case INTR_ROM_MB_FAILED
:
2655 case INTR_MB_SUCCESS
:
2656 case INTR_MB_FAILED
:
2657 qla24xx_mbx_completion(vha
, MSW(stat
));
2658 status
|= MBX_INTERRUPT
;
2661 case INTR_ASYNC_EVENT
:
2663 mb
[1] = RD_REG_WORD(®
->mailbox1
);
2664 mb
[2] = RD_REG_WORD(®
->mailbox2
);
2665 mb
[3] = RD_REG_WORD(®
->mailbox3
);
2666 qla2x00_async_event(vha
, rsp
, mb
);
2668 case INTR_RSP_QUE_UPDATE
:
2669 case INTR_RSP_QUE_UPDATE_83XX
:
2670 qla24xx_process_response_queue(vha
, rsp
);
2672 case INTR_ATIO_QUE_UPDATE
:
2673 qlt_24xx_process_atio_queue(vha
);
2675 case INTR_ATIO_RSP_QUE_UPDATE
:
2676 qlt_24xx_process_atio_queue(vha
);
2677 qla24xx_process_response_queue(vha
, rsp
);
2680 ql_dbg(ql_dbg_async
, vha
, 0x504f,
2681 "Unrecognized interrupt type (%d).\n", stat
* 0xff);
2684 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2685 RD_REG_DWORD_RELAXED(®
->hccr
);
2686 if (unlikely(IS_QLA83XX(ha
) && (ha
->pdev
->revision
== 1)))
2689 qla2x00_handle_mbx_completion(ha
, status
);
2690 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2696 qla24xx_msix_rsp_q(int irq
, void *dev_id
)
2698 struct qla_hw_data
*ha
;
2699 struct rsp_que
*rsp
;
2700 struct device_reg_24xx __iomem
*reg
;
2701 struct scsi_qla_host
*vha
;
2702 unsigned long flags
;
2705 rsp
= (struct rsp_que
*) dev_id
;
2707 ql_log(ql_log_info
, NULL
, 0x505a,
2708 "%s: NULL response queue pointer.\n", __func__
);
2712 reg
= &ha
->iobase
->isp24
;
2714 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2716 vha
= pci_get_drvdata(ha
->pdev
);
2718 * Use host_status register to check to PCI disconnection before we
2719 * we process the response queue.
2721 stat
= RD_REG_DWORD(®
->host_status
);
2722 if (qla2x00_check_reg32_for_disconnect(vha
, stat
))
2724 qla24xx_process_response_queue(vha
, rsp
);
2725 if (!ha
->flags
.disable_msix_handshake
) {
2726 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2727 RD_REG_DWORD_RELAXED(®
->hccr
);
2730 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2736 qla25xx_msix_rsp_q(int irq
, void *dev_id
)
2738 struct qla_hw_data
*ha
;
2739 scsi_qla_host_t
*vha
;
2740 struct rsp_que
*rsp
;
2741 struct device_reg_24xx __iomem
*reg
;
2742 unsigned long flags
;
2745 rsp
= (struct rsp_que
*) dev_id
;
2747 ql_log(ql_log_info
, NULL
, 0x505b,
2748 "%s: NULL response queue pointer.\n", __func__
);
2752 vha
= pci_get_drvdata(ha
->pdev
);
2754 /* Clear the interrupt, if enabled, for this response queue */
2755 if (!ha
->flags
.disable_msix_handshake
) {
2756 reg
= &ha
->iobase
->isp24
;
2757 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2758 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2759 hccr
= RD_REG_DWORD_RELAXED(®
->hccr
);
2760 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2762 if (qla2x00_check_reg32_for_disconnect(vha
, hccr
))
2764 queue_work_on((int) (rsp
->id
- 1), ha
->wq
, &rsp
->q_work
);
2771 qla24xx_msix_default(int irq
, void *dev_id
)
2773 scsi_qla_host_t
*vha
;
2774 struct qla_hw_data
*ha
;
2775 struct rsp_que
*rsp
;
2776 struct device_reg_24xx __iomem
*reg
;
2781 unsigned long flags
;
2783 rsp
= (struct rsp_que
*) dev_id
;
2785 ql_log(ql_log_info
, NULL
, 0x505c,
2786 "%s: NULL response queue pointer.\n", __func__
);
2790 reg
= &ha
->iobase
->isp24
;
2793 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2794 vha
= pci_get_drvdata(ha
->pdev
);
2796 stat
= RD_REG_DWORD(®
->host_status
);
2797 if (qla2x00_check_reg32_for_disconnect(vha
, stat
))
2799 if (stat
& HSRX_RISC_PAUSED
) {
2800 if (unlikely(pci_channel_offline(ha
->pdev
)))
2803 hccr
= RD_REG_DWORD(®
->hccr
);
2805 ql_log(ql_log_info
, vha
, 0x5050,
2806 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2809 qla2xxx_check_risc_status(vha
);
2811 ha
->isp_ops
->fw_dump(vha
, 1);
2812 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2814 } else if ((stat
& HSRX_RISC_INT
) == 0)
2817 switch (stat
& 0xff) {
2818 case INTR_ROM_MB_SUCCESS
:
2819 case INTR_ROM_MB_FAILED
:
2820 case INTR_MB_SUCCESS
:
2821 case INTR_MB_FAILED
:
2822 qla24xx_mbx_completion(vha
, MSW(stat
));
2823 status
|= MBX_INTERRUPT
;
2826 case INTR_ASYNC_EVENT
:
2828 mb
[1] = RD_REG_WORD(®
->mailbox1
);
2829 mb
[2] = RD_REG_WORD(®
->mailbox2
);
2830 mb
[3] = RD_REG_WORD(®
->mailbox3
);
2831 qla2x00_async_event(vha
, rsp
, mb
);
2833 case INTR_RSP_QUE_UPDATE
:
2834 case INTR_RSP_QUE_UPDATE_83XX
:
2835 qla24xx_process_response_queue(vha
, rsp
);
2837 case INTR_ATIO_QUE_UPDATE
:
2838 qlt_24xx_process_atio_queue(vha
);
2840 case INTR_ATIO_RSP_QUE_UPDATE
:
2841 qlt_24xx_process_atio_queue(vha
);
2842 qla24xx_process_response_queue(vha
, rsp
);
2845 ql_dbg(ql_dbg_async
, vha
, 0x5051,
2846 "Unrecognized interrupt type (%d).\n", stat
& 0xff);
2849 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2851 qla2x00_handle_mbx_completion(ha
, status
);
2852 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2857 /* Interrupt handling helpers. */
2859 struct qla_init_msix_entry
{
2861 irq_handler_t handler
;
2864 static struct qla_init_msix_entry msix_entries
[3] = {
2865 { "qla2xxx (default)", qla24xx_msix_default
},
2866 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q
},
2867 { "qla2xxx (multiq)", qla25xx_msix_rsp_q
},
2870 static struct qla_init_msix_entry qla82xx_msix_entries
[2] = {
2871 { "qla2xxx (default)", qla82xx_msix_default
},
2872 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q
},
2875 static struct qla_init_msix_entry qla83xx_msix_entries
[3] = {
2876 { "qla2xxx (default)", qla24xx_msix_default
},
2877 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q
},
2878 { "qla2xxx (atio_q)", qla83xx_msix_atio_q
},
2882 qla24xx_disable_msix(struct qla_hw_data
*ha
)
2885 struct qla_msix_entry
*qentry
;
2886 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
2888 for (i
= 0; i
< ha
->msix_count
; i
++) {
2889 qentry
= &ha
->msix_entries
[i
];
2890 if (qentry
->have_irq
)
2891 free_irq(qentry
->vector
, qentry
->rsp
);
2893 pci_disable_msix(ha
->pdev
);
2894 kfree(ha
->msix_entries
);
2895 ha
->msix_entries
= NULL
;
2896 ha
->flags
.msix_enabled
= 0;
2897 ql_dbg(ql_dbg_init
, vha
, 0x0042,
2898 "Disabled the MSI.\n");
2902 qla24xx_enable_msix(struct qla_hw_data
*ha
, struct rsp_que
*rsp
)
2904 #define MIN_MSIX_COUNT 2
2905 #define ATIO_VECTOR 2
2907 struct msix_entry
*entries
;
2908 struct qla_msix_entry
*qentry
;
2909 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
2911 entries
= kzalloc(sizeof(struct msix_entry
) * ha
->msix_count
,
2914 ql_log(ql_log_warn
, vha
, 0x00bc,
2915 "Failed to allocate memory for msix_entry.\n");
2919 for (i
= 0; i
< ha
->msix_count
; i
++)
2920 entries
[i
].entry
= i
;
2922 ret
= pci_enable_msix_range(ha
->pdev
,
2923 entries
, MIN_MSIX_COUNT
, ha
->msix_count
);
2925 ql_log(ql_log_fatal
, vha
, 0x00c7,
2926 "MSI-X: Failed to enable support, "
2927 "giving up -- %d/%d.\n",
2928 ha
->msix_count
, ret
);
2930 } else if (ret
< ha
->msix_count
) {
2931 ql_log(ql_log_warn
, vha
, 0x00c6,
2932 "MSI-X: Failed to enable support "
2933 "-- %d/%d\n Retry with %d vectors.\n",
2934 ha
->msix_count
, ret
, ret
);
2936 ha
->msix_count
= ret
;
2937 ha
->max_rsp_queues
= ha
->msix_count
- 1;
2938 ha
->msix_entries
= kzalloc(sizeof(struct qla_msix_entry
) *
2939 ha
->msix_count
, GFP_KERNEL
);
2940 if (!ha
->msix_entries
) {
2941 ql_log(ql_log_fatal
, vha
, 0x00c8,
2942 "Failed to allocate memory for ha->msix_entries.\n");
2946 ha
->flags
.msix_enabled
= 1;
2948 for (i
= 0; i
< ha
->msix_count
; i
++) {
2949 qentry
= &ha
->msix_entries
[i
];
2950 qentry
->vector
= entries
[i
].vector
;
2951 qentry
->entry
= entries
[i
].entry
;
2952 qentry
->have_irq
= 0;
2956 /* Enable MSI-X vectors for the base queue */
2957 for (i
= 0; i
< 2; i
++) {
2958 qentry
= &ha
->msix_entries
[i
];
2959 if (IS_P3P_TYPE(ha
))
2960 ret
= request_irq(qentry
->vector
,
2961 qla82xx_msix_entries
[i
].handler
,
2962 0, qla82xx_msix_entries
[i
].name
, rsp
);
2964 ret
= request_irq(qentry
->vector
,
2965 msix_entries
[i
].handler
,
2966 0, msix_entries
[i
].name
, rsp
);
2968 goto msix_register_fail
;
2969 qentry
->have_irq
= 1;
2975 * If target mode is enable, also request the vector for the ATIO
2978 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha
)) {
2979 qentry
= &ha
->msix_entries
[ATIO_VECTOR
];
2980 ret
= request_irq(qentry
->vector
,
2981 qla83xx_msix_entries
[ATIO_VECTOR
].handler
,
2982 0, qla83xx_msix_entries
[ATIO_VECTOR
].name
, rsp
);
2983 qentry
->have_irq
= 1;
2990 ql_log(ql_log_fatal
, vha
, 0x00cb,
2991 "MSI-X: unable to register handler -- %x/%d.\n",
2992 qentry
->vector
, ret
);
2993 qla24xx_disable_msix(ha
);
2998 /* Enable MSI-X vector for response queue update for queue 0 */
2999 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3000 if (ha
->msixbase
&& ha
->mqiobase
&&
3001 (ha
->max_rsp_queues
> 1 || ha
->max_req_queues
> 1))
3005 && (ha
->max_rsp_queues
> 1 || ha
->max_req_queues
> 1))
3007 ql_dbg(ql_dbg_multiq
, vha
, 0xc005,
3008 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3009 ha
->mqiobase
, ha
->max_rsp_queues
, ha
->max_req_queues
);
3010 ql_dbg(ql_dbg_init
, vha
, 0x0055,
3011 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3012 ha
->mqiobase
, ha
->max_rsp_queues
, ha
->max_req_queues
);
3020 qla2x00_request_irqs(struct qla_hw_data
*ha
, struct rsp_que
*rsp
)
3022 int ret
= QLA_FUNCTION_FAILED
;
3023 device_reg_t
*reg
= ha
->iobase
;
3024 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
3026 /* If possible, enable MSI-X. */
3027 if (!IS_QLA2432(ha
) && !IS_QLA2532(ha
) && !IS_QLA8432(ha
) &&
3028 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
) && !IS_QLAFX00(ha
) &&
3032 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_HP
&&
3033 (ha
->pdev
->subsystem_device
== 0x7040 ||
3034 ha
->pdev
->subsystem_device
== 0x7041 ||
3035 ha
->pdev
->subsystem_device
== 0x1705)) {
3036 ql_log(ql_log_warn
, vha
, 0x0034,
3037 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
3038 ha
->pdev
->subsystem_vendor
,
3039 ha
->pdev
->subsystem_device
);
3043 if (IS_QLA2432(ha
) && (ha
->pdev
->revision
< QLA_MSIX_CHIP_REV_24XX
)) {
3044 ql_log(ql_log_warn
, vha
, 0x0035,
3045 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
3046 ha
->pdev
->revision
, QLA_MSIX_CHIP_REV_24XX
);
3050 ret
= qla24xx_enable_msix(ha
, rsp
);
3052 ql_dbg(ql_dbg_init
, vha
, 0x0036,
3053 "MSI-X: Enabled (0x%X, 0x%X).\n",
3054 ha
->chip_revision
, ha
->fw_attributes
);
3055 goto clear_risc_ints
;
3060 ql_log(ql_log_info
, vha
, 0x0037,
3061 "Falling back-to MSI mode -%d.\n", ret
);
3063 if (!IS_QLA24XX(ha
) && !IS_QLA2532(ha
) && !IS_QLA8432(ha
) &&
3064 !IS_QLA8001(ha
) && !IS_P3P_TYPE(ha
) && !IS_QLAFX00(ha
) &&
3068 ret
= pci_enable_msi(ha
->pdev
);
3070 ql_dbg(ql_dbg_init
, vha
, 0x0038,
3072 ha
->flags
.msi_enabled
= 1;
3074 ql_log(ql_log_warn
, vha
, 0x0039,
3075 "Falling back-to INTa mode -- %d.\n", ret
);
3078 /* Skip INTx on ISP82xx. */
3079 if (!ha
->flags
.msi_enabled
&& IS_QLA82XX(ha
))
3080 return QLA_FUNCTION_FAILED
;
3082 ret
= request_irq(ha
->pdev
->irq
, ha
->isp_ops
->intr_handler
,
3083 ha
->flags
.msi_enabled
? 0 : IRQF_SHARED
,
3084 QLA2XXX_DRIVER_NAME
, rsp
);
3086 ql_log(ql_log_warn
, vha
, 0x003a,
3087 "Failed to reserve interrupt %d already in use.\n",
3090 } else if (!ha
->flags
.msi_enabled
) {
3091 ql_dbg(ql_dbg_init
, vha
, 0x0125,
3092 "INTa mode: Enabled.\n");
3093 ha
->flags
.mr_intr_valid
= 1;
3098 spin_lock_irq(&ha
->hardware_lock
);
3099 if (!IS_FWI2_CAPABLE(ha
))
3100 WRT_REG_WORD(®
->isp
.semaphore
, 0);
3101 spin_unlock_irq(&ha
->hardware_lock
);
3108 qla2x00_free_irqs(scsi_qla_host_t
*vha
)
3110 struct qla_hw_data
*ha
= vha
->hw
;
3111 struct rsp_que
*rsp
;
3114 * We need to check that ha->rsp_q_map is valid in case we are called
3115 * from a probe failure context.
3117 if (!ha
->rsp_q_map
|| !ha
->rsp_q_map
[0])
3119 rsp
= ha
->rsp_q_map
[0];
3121 if (ha
->flags
.msix_enabled
)
3122 qla24xx_disable_msix(ha
);
3123 else if (ha
->flags
.msi_enabled
) {
3124 free_irq(ha
->pdev
->irq
, rsp
);
3125 pci_disable_msi(ha
->pdev
);
3127 free_irq(ha
->pdev
->irq
, rsp
);
3131 int qla25xx_request_irq(struct rsp_que
*rsp
)
3133 struct qla_hw_data
*ha
= rsp
->hw
;
3134 struct qla_init_msix_entry
*intr
= &msix_entries
[2];
3135 struct qla_msix_entry
*msix
= rsp
->msix
;
3136 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
3139 ret
= request_irq(msix
->vector
, intr
->handler
, 0, intr
->name
, rsp
);
3141 ql_log(ql_log_fatal
, vha
, 0x00e6,
3142 "MSI-X: Unable to register handler -- %x/%d.\n",