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 mboxes
= (1 << ha
->mbx_count
) - 1;
277 ql_dbg(ql_dbg_async
, vha
, 0x5001, "MBX pointer ERROR.\n");
279 mboxes
= ha
->mcp
->in_mb
;
281 /* Load return mailbox registers. */
282 ha
->flags
.mbox_int
= 1;
283 ha
->mailbox_out
[0] = mb0
;
285 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 1);
287 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
288 if (IS_QLA2200(ha
) && cnt
== 8)
289 wptr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 8);
290 if ((cnt
== 4 || cnt
== 5) && (mboxes
& BIT_0
))
291 ha
->mailbox_out
[cnt
] = qla2x00_debounce_register(wptr
);
292 else if (mboxes
& BIT_0
)
293 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
301 qla81xx_idc_event(scsi_qla_host_t
*vha
, uint16_t aen
, uint16_t descr
)
303 static char *event
[] =
304 { "Complete", "Request Notification", "Time Extension" };
306 struct device_reg_24xx __iomem
*reg24
= &vha
->hw
->iobase
->isp24
;
307 struct device_reg_82xx __iomem
*reg82
= &vha
->hw
->iobase
->isp82
;
308 uint16_t __iomem
*wptr
;
309 uint16_t cnt
, timeout
, mb
[QLA_IDC_ACK_REGS
];
311 /* Seed data -- mailbox1 -> mailbox7. */
312 if (IS_QLA81XX(vha
->hw
) || IS_QLA83XX(vha
->hw
))
313 wptr
= (uint16_t __iomem
*)®24
->mailbox1
;
314 else if (IS_QLA8044(vha
->hw
))
315 wptr
= (uint16_t __iomem
*)®82
->mailbox_out
[1];
319 for (cnt
= 0; cnt
< QLA_IDC_ACK_REGS
; cnt
++, wptr
++)
320 mb
[cnt
] = RD_REG_WORD(wptr
);
322 ql_dbg(ql_dbg_async
, vha
, 0x5021,
323 "Inter-Driver Communication %s -- "
324 "%04x %04x %04x %04x %04x %04x %04x.\n",
325 event
[aen
& 0xff], mb
[0], mb
[1], mb
[2], mb
[3],
326 mb
[4], mb
[5], mb
[6]);
328 /* Handle IDC Error completion case. */
329 case MBA_IDC_COMPLETE
:
331 vha
->hw
->flags
.idc_compl_status
= 1;
332 if (vha
->hw
->notify_dcbx_comp
&& !vha
->vp_idx
)
333 complete(&vha
->hw
->dcbx_comp
);
338 /* Acknowledgement needed? [Notify && non-zero timeout]. */
339 timeout
= (descr
>> 8) & 0xf;
340 ql_dbg(ql_dbg_async
, vha
, 0x5022,
341 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
342 vha
->host_no
, event
[aen
& 0xff], timeout
);
346 rval
= qla2x00_post_idc_ack_work(vha
, mb
);
347 if (rval
!= QLA_SUCCESS
)
348 ql_log(ql_log_warn
, vha
, 0x5023,
349 "IDC failed to post ACK.\n");
351 case MBA_IDC_TIME_EXT
:
352 vha
->hw
->idc_extend_tmo
= descr
;
353 ql_dbg(ql_dbg_async
, vha
, 0x5087,
354 "%lu Inter-Driver Communication %s -- "
355 "Extend timeout by=%d.\n",
356 vha
->host_no
, event
[aen
& 0xff], vha
->hw
->idc_extend_tmo
);
363 qla2x00_get_link_speed_str(struct qla_hw_data
*ha
, uint16_t speed
)
365 static const char *const link_speeds
[] = {
366 "1", "2", "?", "4", "8", "16", "32", "10"
368 #define QLA_LAST_SPEED 7
370 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
371 return link_speeds
[0];
372 else if (speed
== 0x13)
373 return link_speeds
[QLA_LAST_SPEED
];
374 else if (speed
< QLA_LAST_SPEED
)
375 return link_speeds
[speed
];
377 return link_speeds
[LS_UNKNOWN
];
381 qla83xx_handle_8200_aen(scsi_qla_host_t
*vha
, uint16_t *mb
)
383 struct qla_hw_data
*ha
= vha
->hw
;
386 * 8200 AEN Interpretation:
388 * mb[1] = AEN Reason code
389 * mb[2] = LSW of Peg-Halt Status-1 Register
390 * mb[6] = MSW of Peg-Halt Status-1 Register
391 * mb[3] = LSW of Peg-Halt Status-2 register
392 * mb[7] = MSW of Peg-Halt Status-2 register
393 * mb[4] = IDC Device-State Register value
394 * mb[5] = IDC Driver-Presence Register value
396 ql_dbg(ql_dbg_async
, vha
, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: "
397 "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n",
398 mb
[0], mb
[1], mb
[2], mb
[6]);
399 ql_dbg(ql_dbg_async
, vha
, 0x506c, "PH-status2: mb[3] = 0x%x "
400 "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x "
401 "Drv-Presence: mb[5] = 0x%x.\n", mb
[3], mb
[7], mb
[4], mb
[5]);
403 if (mb
[1] & (IDC_PEG_HALT_STATUS_CHANGE
| IDC_NIC_FW_REPORTED_FAILURE
|
404 IDC_HEARTBEAT_FAILURE
)) {
405 ha
->flags
.nic_core_hung
= 1;
406 ql_log(ql_log_warn
, vha
, 0x5060,
407 "83XX: F/W Error Reported: Check if reset required.\n");
409 if (mb
[1] & IDC_PEG_HALT_STATUS_CHANGE
) {
410 uint32_t protocol_engine_id
, fw_err_code
, err_level
;
413 * IDC_PEG_HALT_STATUS_CHANGE interpretation:
414 * - PEG-Halt Status-1 Register:
415 * (LSW = mb[2], MSW = mb[6])
416 * Bits 0-7 = protocol-engine ID
417 * Bits 8-28 = f/w error code
418 * Bits 29-31 = Error-level
419 * Error-level 0x1 = Non-Fatal error
420 * Error-level 0x2 = Recoverable Fatal error
421 * Error-level 0x4 = UnRecoverable Fatal error
422 * - PEG-Halt Status-2 Register:
423 * (LSW = mb[3], MSW = mb[7])
425 protocol_engine_id
= (mb
[2] & 0xff);
426 fw_err_code
= (((mb
[2] & 0xff00) >> 8) |
427 ((mb
[6] & 0x1fff) << 8));
428 err_level
= ((mb
[6] & 0xe000) >> 13);
429 ql_log(ql_log_warn
, vha
, 0x5061, "PegHalt Status-1 "
430 "Register: protocol_engine_id=0x%x "
431 "fw_err_code=0x%x err_level=0x%x.\n",
432 protocol_engine_id
, fw_err_code
, err_level
);
433 ql_log(ql_log_warn
, vha
, 0x5062, "PegHalt Status-2 "
434 "Register: 0x%x%x.\n", mb
[7], mb
[3]);
435 if (err_level
== ERR_LEVEL_NON_FATAL
) {
436 ql_log(ql_log_warn
, vha
, 0x5063,
437 "Not a fatal error, f/w has recovered "
439 } else if (err_level
== ERR_LEVEL_RECOVERABLE_FATAL
) {
440 ql_log(ql_log_fatal
, vha
, 0x5064,
441 "Recoverable Fatal error: Chip reset "
443 qla83xx_schedule_work(vha
,
444 QLA83XX_NIC_CORE_RESET
);
445 } else if (err_level
== ERR_LEVEL_UNRECOVERABLE_FATAL
) {
446 ql_log(ql_log_fatal
, vha
, 0x5065,
447 "Unrecoverable Fatal error: Set FAILED "
448 "state, reboot required.\n");
449 qla83xx_schedule_work(vha
,
450 QLA83XX_NIC_CORE_UNRECOVERABLE
);
454 if (mb
[1] & IDC_NIC_FW_REPORTED_FAILURE
) {
455 uint16_t peg_fw_state
, nw_interface_link_up
;
456 uint16_t nw_interface_signal_detect
, sfp_status
;
457 uint16_t htbt_counter
, htbt_monitor_enable
;
458 uint16_t sfp_additonal_info
, sfp_multirate
;
459 uint16_t sfp_tx_fault
, link_speed
, dcbx_status
;
462 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
463 * - PEG-to-FC Status Register:
464 * (LSW = mb[2], MSW = mb[6])
465 * Bits 0-7 = Peg-Firmware state
466 * Bit 8 = N/W Interface Link-up
467 * Bit 9 = N/W Interface signal detected
468 * Bits 10-11 = SFP Status
469 * SFP Status 0x0 = SFP+ transceiver not expected
470 * SFP Status 0x1 = SFP+ transceiver not present
471 * SFP Status 0x2 = SFP+ transceiver invalid
472 * SFP Status 0x3 = SFP+ transceiver present and
474 * Bits 12-14 = Heartbeat Counter
475 * Bit 15 = Heartbeat Monitor Enable
476 * Bits 16-17 = SFP Additional Info
477 * SFP info 0x0 = Unregocnized transceiver for
479 * SFP info 0x1 = SFP+ brand validation failed
480 * SFP info 0x2 = SFP+ speed validation failed
481 * SFP info 0x3 = SFP+ access error
482 * Bit 18 = SFP Multirate
483 * Bit 19 = SFP Tx Fault
484 * Bits 20-22 = Link Speed
485 * Bits 23-27 = Reserved
486 * Bits 28-30 = DCBX Status
487 * DCBX Status 0x0 = DCBX Disabled
488 * DCBX Status 0x1 = DCBX Enabled
489 * DCBX Status 0x2 = DCBX Exchange error
492 peg_fw_state
= (mb
[2] & 0x00ff);
493 nw_interface_link_up
= ((mb
[2] & 0x0100) >> 8);
494 nw_interface_signal_detect
= ((mb
[2] & 0x0200) >> 9);
495 sfp_status
= ((mb
[2] & 0x0c00) >> 10);
496 htbt_counter
= ((mb
[2] & 0x7000) >> 12);
497 htbt_monitor_enable
= ((mb
[2] & 0x8000) >> 15);
498 sfp_additonal_info
= (mb
[6] & 0x0003);
499 sfp_multirate
= ((mb
[6] & 0x0004) >> 2);
500 sfp_tx_fault
= ((mb
[6] & 0x0008) >> 3);
501 link_speed
= ((mb
[6] & 0x0070) >> 4);
502 dcbx_status
= ((mb
[6] & 0x7000) >> 12);
504 ql_log(ql_log_warn
, vha
, 0x5066,
505 "Peg-to-Fc Status Register:\n"
506 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
507 "nw_interface_signal_detect=0x%x"
508 "\nsfp_statis=0x%x.\n ", peg_fw_state
,
509 nw_interface_link_up
, nw_interface_signal_detect
,
511 ql_log(ql_log_warn
, vha
, 0x5067,
512 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
513 "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ",
514 htbt_counter
, htbt_monitor_enable
,
515 sfp_additonal_info
, sfp_multirate
);
516 ql_log(ql_log_warn
, vha
, 0x5068,
517 "sfp_tx_fault=0x%x, link_state=0x%x, "
518 "dcbx_status=0x%x.\n", sfp_tx_fault
, link_speed
,
521 qla83xx_schedule_work(vha
, QLA83XX_NIC_CORE_RESET
);
524 if (mb
[1] & IDC_HEARTBEAT_FAILURE
) {
525 ql_log(ql_log_warn
, vha
, 0x5069,
526 "Heartbeat Failure encountered, chip reset "
529 qla83xx_schedule_work(vha
, QLA83XX_NIC_CORE_RESET
);
533 if (mb
[1] & IDC_DEVICE_STATE_CHANGE
) {
534 ql_log(ql_log_info
, vha
, 0x506a,
535 "IDC Device-State changed = 0x%x.\n", mb
[4]);
536 if (ha
->flags
.nic_core_reset_owner
)
538 qla83xx_schedule_work(vha
, MBA_IDC_AEN
);
543 qla2x00_is_a_vp_did(scsi_qla_host_t
*vha
, uint32_t rscn_entry
)
545 struct qla_hw_data
*ha
= vha
->hw
;
554 spin_lock_irqsave(&ha
->vport_slock
, flags
);
555 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
556 vp_did
= vp
->d_id
.b24
;
557 if (vp_did
== rscn_entry
) {
562 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
567 static inline fc_port_t
*
568 qla2x00_find_fcport_by_loopid(scsi_qla_host_t
*vha
, uint16_t loop_id
)
572 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
573 if (fcport
->loop_id
== loop_id
)
579 * qla2x00_async_event() - Process aynchronous events.
580 * @ha: SCSI driver HA context
581 * @mb: Mailbox registers (0 - 3)
584 qla2x00_async_event(scsi_qla_host_t
*vha
, struct rsp_que
*rsp
, uint16_t *mb
)
589 struct qla_hw_data
*ha
= vha
->hw
;
590 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
591 struct device_reg_24xx __iomem
*reg24
= &ha
->iobase
->isp24
;
592 struct device_reg_82xx __iomem
*reg82
= &ha
->iobase
->isp82
;
593 uint32_t rscn_entry
, host_pid
;
595 fc_port_t
*fcport
= NULL
;
597 /* Setup to process RIO completion. */
599 if (IS_CNA_CAPABLE(ha
))
602 case MBA_SCSI_COMPLETION
:
603 handles
[0] = le32_to_cpu((uint32_t)((mb
[2] << 16) | mb
[1]));
606 case MBA_CMPLT_1_16BIT
:
609 mb
[0] = MBA_SCSI_COMPLETION
;
611 case MBA_CMPLT_2_16BIT
:
615 mb
[0] = MBA_SCSI_COMPLETION
;
617 case MBA_CMPLT_3_16BIT
:
622 mb
[0] = MBA_SCSI_COMPLETION
;
624 case MBA_CMPLT_4_16BIT
:
628 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
630 mb
[0] = MBA_SCSI_COMPLETION
;
632 case MBA_CMPLT_5_16BIT
:
636 handles
[3] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 6);
637 handles
[4] = (uint32_t)RD_MAILBOX_REG(ha
, reg
, 7);
639 mb
[0] = MBA_SCSI_COMPLETION
;
641 case MBA_CMPLT_2_32BIT
:
642 handles
[0] = le32_to_cpu((uint32_t)((mb
[2] << 16) | mb
[1]));
643 handles
[1] = le32_to_cpu(
644 ((uint32_t)(RD_MAILBOX_REG(ha
, reg
, 7) << 16)) |
645 RD_MAILBOX_REG(ha
, reg
, 6));
647 mb
[0] = MBA_SCSI_COMPLETION
;
654 case MBA_SCSI_COMPLETION
: /* Fast Post */
655 if (!vha
->flags
.online
)
658 for (cnt
= 0; cnt
< handle_cnt
; cnt
++)
659 qla2x00_process_completed_request(vha
, rsp
->req
,
663 case MBA_RESET
: /* Reset */
664 ql_dbg(ql_dbg_async
, vha
, 0x5002,
665 "Asynchronous RESET.\n");
667 set_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
670 case MBA_SYSTEM_ERR
: /* System Error */
671 mbx
= (IS_QLA81XX(ha
) || IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) ?
672 RD_REG_WORD(®24
->mailbox7
) : 0;
673 ql_log(ql_log_warn
, vha
, 0x5003,
674 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
675 "mbx7=%xh.\n", mb
[1], mb
[2], mb
[3], mbx
);
677 ha
->isp_ops
->fw_dump(vha
, 1);
679 if (IS_FWI2_CAPABLE(ha
)) {
680 if (mb
[1] == 0 && mb
[2] == 0) {
681 ql_log(ql_log_fatal
, vha
, 0x5004,
682 "Unrecoverable Hardware Error: adapter "
683 "marked OFFLINE!\n");
684 vha
->flags
.online
= 0;
685 vha
->device_flags
|= DFLG_DEV_FAILED
;
687 /* Check to see if MPI timeout occurred */
688 if ((mbx
& MBX_3
) && (ha
->port_no
== 0))
689 set_bit(MPI_RESET_NEEDED
,
692 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
694 } else if (mb
[1] == 0) {
695 ql_log(ql_log_fatal
, vha
, 0x5005,
696 "Unrecoverable Hardware Error: adapter marked "
698 vha
->flags
.online
= 0;
699 vha
->device_flags
|= DFLG_DEV_FAILED
;
701 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
704 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
705 ql_log(ql_log_warn
, vha
, 0x5006,
706 "ISP Request Transfer Error (%x).\n", mb
[1]);
708 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
711 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
712 ql_log(ql_log_warn
, vha
, 0x5007,
713 "ISP Response Transfer Error.\n");
715 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
718 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
719 ql_dbg(ql_dbg_async
, vha
, 0x5008,
720 "Asynchronous WAKEUP_THRES.\n");
723 case MBA_LIP_OCCURRED
: /* Loop Initialization Procedure */
724 ql_dbg(ql_dbg_async
, vha
, 0x5009,
725 "LIP occurred (%x).\n", mb
[1]);
727 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
728 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
729 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
730 qla2x00_mark_all_devices_lost(vha
, 1);
734 atomic_set(&vha
->vp_state
, VP_FAILED
);
735 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
738 set_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
);
739 set_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
);
741 vha
->flags
.management_server_logged_in
= 0;
742 qla2x00_post_aen_work(vha
, FCH_EVT_LIP
, mb
[1]);
745 case MBA_LOOP_UP
: /* Loop Up Event */
746 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
747 ha
->link_data_rate
= PORT_SPEED_1GB
;
749 ha
->link_data_rate
= mb
[1];
751 ql_log(ql_log_info
, vha
, 0x500a,
752 "LOOP UP detected (%s Gbps).\n",
753 qla2x00_get_link_speed_str(ha
, ha
->link_data_rate
));
755 vha
->flags
.management_server_logged_in
= 0;
756 qla2x00_post_aen_work(vha
, FCH_EVT_LINKUP
, ha
->link_data_rate
);
759 case MBA_LOOP_DOWN
: /* Loop Down Event */
760 mbx
= (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
761 ? RD_REG_WORD(®24
->mailbox4
) : 0;
762 mbx
= (IS_P3P_TYPE(ha
)) ? RD_REG_WORD(®82
->mailbox_out
[4])
764 ql_log(ql_log_info
, vha
, 0x500b,
765 "LOOP DOWN detected (%x %x %x %x).\n",
766 mb
[1], mb
[2], mb
[3], mbx
);
768 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
769 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
770 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
772 * In case of loop down, restore WWPN from
773 * NVRAM in case of FA-WWPN capable ISP
774 * Restore for Physical Port only
777 if (ha
->flags
.fawwpn_enabled
) {
778 void *wwpn
= ha
->init_cb
->port_name
;
779 memcpy(vha
->port_name
, wwpn
, WWN_SIZE
);
780 fc_host_port_name(vha
->host
) =
781 wwn_to_u64(vha
->port_name
);
782 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
,
783 vha
, 0x0144, "LOOP DOWN detected,"
784 "restore WWPN %016llx\n",
785 wwn_to_u64(vha
->port_name
));
788 clear_bit(VP_CONFIG_OK
, &vha
->vp_flags
);
791 vha
->device_flags
|= DFLG_NO_CABLE
;
792 qla2x00_mark_all_devices_lost(vha
, 1);
796 atomic_set(&vha
->vp_state
, VP_FAILED
);
797 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
800 vha
->flags
.management_server_logged_in
= 0;
801 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
802 qla2x00_post_aen_work(vha
, FCH_EVT_LINKDOWN
, 0);
805 case MBA_LIP_RESET
: /* LIP reset occurred */
806 ql_dbg(ql_dbg_async
, vha
, 0x500c,
807 "LIP reset occurred (%x).\n", mb
[1]);
809 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
810 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
811 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
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 set_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
822 ha
->operating_mode
= LOOP
;
823 vha
->flags
.management_server_logged_in
= 0;
824 qla2x00_post_aen_work(vha
, FCH_EVT_LIPRESET
, mb
[1]);
827 /* case MBA_DCBX_COMPLETE: */
828 case MBA_POINT_TO_POINT
: /* Point-to-Point */
832 if (IS_CNA_CAPABLE(ha
)) {
833 ql_dbg(ql_dbg_async
, vha
, 0x500d,
834 "DCBX Completed -- %04x %04x %04x.\n",
835 mb
[1], mb
[2], mb
[3]);
836 if (ha
->notify_dcbx_comp
&& !vha
->vp_idx
)
837 complete(&ha
->dcbx_comp
);
840 ql_dbg(ql_dbg_async
, vha
, 0x500e,
841 "Asynchronous P2P MODE received.\n");
844 * Until there's a transition from loop down to loop up, treat
845 * this as loop down only.
847 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
848 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
849 if (!atomic_read(&vha
->loop_down_timer
))
850 atomic_set(&vha
->loop_down_timer
,
852 qla2x00_mark_all_devices_lost(vha
, 1);
856 atomic_set(&vha
->vp_state
, VP_FAILED
);
857 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
860 if (!(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)))
861 set_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
863 set_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
);
864 set_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
);
866 ha
->flags
.gpsc_supported
= 1;
867 vha
->flags
.management_server_logged_in
= 0;
870 case MBA_CHG_IN_CONNECTION
: /* Change in connection mode */
874 ql_dbg(ql_dbg_async
, vha
, 0x500f,
875 "Configuration change detected: value=%x.\n", mb
[1]);
877 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
878 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
879 if (!atomic_read(&vha
->loop_down_timer
))
880 atomic_set(&vha
->loop_down_timer
,
882 qla2x00_mark_all_devices_lost(vha
, 1);
886 atomic_set(&vha
->vp_state
, VP_FAILED
);
887 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
890 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
891 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
894 case MBA_PORT_UPDATE
: /* Port database update */
896 * Handle only global and vn-port update events
899 * mb[1] = N_Port handle of changed port
900 * OR 0xffff for global event
901 * mb[2] = New login state
902 * 7 = Port logged out
903 * mb[3] = LSB is vp_idx, 0xff = all vps
905 * Skip processing if:
906 * Event is global, vp_idx is NOT all vps,
907 * vp_idx does not match
908 * Event is not global, vp_idx does not match
910 if (IS_QLA2XXX_MIDTYPE(ha
) &&
911 ((mb
[1] == 0xffff && (mb
[3] & 0xff) != 0xff) ||
912 (mb
[1] != 0xffff)) && vha
->vp_idx
!= (mb
[3] & 0xff))
916 ql_dbg(ql_dbg_async
, vha
, 0x5010,
917 "Port %s %04x %04x %04x.\n",
918 mb
[1] == 0xffff ? "unavailable" : "logout",
919 mb
[1], mb
[2], mb
[3]);
922 goto global_port_update
;
925 fcport
= qla2x00_find_fcport_by_loopid(vha
, mb
[1]);
928 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
930 ql_dbg(ql_dbg_async
, vha
, 0x508a,
931 "Marking port lost loopid=%04x portid=%06x.\n",
932 fcport
->loop_id
, fcport
->d_id
.b24
);
933 qla2x00_mark_device_lost(fcport
->vha
, fcport
, 1, 1);
937 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
938 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
939 atomic_set(&vha
->loop_down_timer
,
941 vha
->device_flags
|= DFLG_NO_CABLE
;
942 qla2x00_mark_all_devices_lost(vha
, 1);
946 atomic_set(&vha
->vp_state
, VP_FAILED
);
947 fc_vport_set_state(vha
->fc_vport
,
949 qla2x00_mark_all_devices_lost(vha
, 1);
952 vha
->flags
.management_server_logged_in
= 0;
953 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
958 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
959 * event etc. earlier indicating loop is down) then process
960 * it. Otherwise ignore it and Wait for RSCN to come in.
962 atomic_set(&vha
->loop_down_timer
, 0);
963 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
&&
964 atomic_read(&vha
->loop_state
) != LOOP_DEAD
) {
965 ql_dbg(ql_dbg_async
, vha
, 0x5011,
966 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
967 mb
[1], mb
[2], mb
[3]);
969 qlt_async_event(mb
[0], vha
, mb
);
973 ql_dbg(ql_dbg_async
, vha
, 0x5012,
974 "Port database changed %04x %04x %04x.\n",
975 mb
[1], mb
[2], mb
[3]);
978 * Mark all devices as missing so we will login again.
980 atomic_set(&vha
->loop_state
, LOOP_UP
);
982 qla2x00_mark_all_devices_lost(vha
, 1);
984 if (vha
->vp_idx
== 0 && !qla_ini_mode_enabled(vha
))
985 set_bit(SCR_PENDING
, &vha
->dpc_flags
);
987 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
988 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
989 set_bit(VP_CONFIG_OK
, &vha
->vp_flags
);
991 qlt_async_event(mb
[0], vha
, mb
);
994 case MBA_RSCN_UPDATE
: /* State Change Registration */
995 /* Check if the Vport has issued a SCR */
996 if (vha
->vp_idx
&& test_bit(VP_SCR_NEEDED
, &vha
->vp_flags
))
998 /* Only handle SCNs for our Vport index. */
999 if (ha
->flags
.npiv_supported
&& vha
->vp_idx
!= (mb
[3] & 0xff))
1002 ql_dbg(ql_dbg_async
, vha
, 0x5013,
1003 "RSCN database changed -- %04x %04x %04x.\n",
1004 mb
[1], mb
[2], mb
[3]);
1006 rscn_entry
= ((mb
[1] & 0xff) << 16) | mb
[2];
1007 host_pid
= (vha
->d_id
.b
.domain
<< 16) | (vha
->d_id
.b
.area
<< 8)
1008 | vha
->d_id
.b
.al_pa
;
1009 if (rscn_entry
== host_pid
) {
1010 ql_dbg(ql_dbg_async
, vha
, 0x5014,
1011 "Ignoring RSCN update to local host "
1012 "port ID (%06x).\n", host_pid
);
1016 /* Ignore reserved bits from RSCN-payload. */
1017 rscn_entry
= ((mb
[1] & 0x3ff) << 16) | mb
[2];
1019 /* Skip RSCNs for virtual ports on the same physical port */
1020 if (qla2x00_is_a_vp_did(vha
, rscn_entry
))
1024 * Search for the rport related to this RSCN entry and mark it
1027 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1028 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
1030 if (fcport
->d_id
.b24
== rscn_entry
) {
1031 qla2x00_mark_device_lost(vha
, fcport
, 0, 0);
1036 atomic_set(&vha
->loop_down_timer
, 0);
1037 vha
->flags
.management_server_logged_in
= 0;
1039 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1040 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
1041 qla2x00_post_aen_work(vha
, FCH_EVT_RSCN
, rscn_entry
);
1044 /* case MBA_RIO_RESPONSE: */
1045 case MBA_ZIO_RESPONSE
:
1046 ql_dbg(ql_dbg_async
, vha
, 0x5015,
1047 "[R|Z]IO update completion.\n");
1049 if (IS_FWI2_CAPABLE(ha
))
1050 qla24xx_process_response_queue(vha
, rsp
);
1052 qla2x00_process_response_queue(rsp
);
1055 case MBA_DISCARD_RND_FRAME
:
1056 ql_dbg(ql_dbg_async
, vha
, 0x5016,
1057 "Discard RND Frame -- %04x %04x %04x.\n",
1058 mb
[1], mb
[2], mb
[3]);
1061 case MBA_TRACE_NOTIFICATION
:
1062 ql_dbg(ql_dbg_async
, vha
, 0x5017,
1063 "Trace Notification -- %04x %04x.\n", mb
[1], mb
[2]);
1066 case MBA_ISP84XX_ALERT
:
1067 ql_dbg(ql_dbg_async
, vha
, 0x5018,
1068 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
1069 mb
[1], mb
[2], mb
[3]);
1071 spin_lock_irqsave(&ha
->cs84xx
->access_lock
, flags
);
1073 case A84_PANIC_RECOVERY
:
1074 ql_log(ql_log_info
, vha
, 0x5019,
1075 "Alert 84XX: panic recovery %04x %04x.\n",
1078 case A84_OP_LOGIN_COMPLETE
:
1079 ha
->cs84xx
->op_fw_version
= mb
[3] << 16 | mb
[2];
1080 ql_log(ql_log_info
, vha
, 0x501a,
1081 "Alert 84XX: firmware version %x.\n",
1082 ha
->cs84xx
->op_fw_version
);
1084 case A84_DIAG_LOGIN_COMPLETE
:
1085 ha
->cs84xx
->diag_fw_version
= mb
[3] << 16 | mb
[2];
1086 ql_log(ql_log_info
, vha
, 0x501b,
1087 "Alert 84XX: diagnostic firmware version %x.\n",
1088 ha
->cs84xx
->diag_fw_version
);
1090 case A84_GOLD_LOGIN_COMPLETE
:
1091 ha
->cs84xx
->diag_fw_version
= mb
[3] << 16 | mb
[2];
1092 ha
->cs84xx
->fw_update
= 1;
1093 ql_log(ql_log_info
, vha
, 0x501c,
1094 "Alert 84XX: gold firmware version %x.\n",
1095 ha
->cs84xx
->gold_fw_version
);
1098 ql_log(ql_log_warn
, vha
, 0x501d,
1099 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
1100 mb
[1], mb
[2], mb
[3]);
1102 spin_unlock_irqrestore(&ha
->cs84xx
->access_lock
, flags
);
1104 case MBA_DCBX_START
:
1105 ql_dbg(ql_dbg_async
, vha
, 0x501e,
1106 "DCBX Started -- %04x %04x %04x.\n",
1107 mb
[1], mb
[2], mb
[3]);
1109 case MBA_DCBX_PARAM_UPDATE
:
1110 ql_dbg(ql_dbg_async
, vha
, 0x501f,
1111 "DCBX Parameters Updated -- %04x %04x %04x.\n",
1112 mb
[1], mb
[2], mb
[3]);
1114 case MBA_FCF_CONF_ERR
:
1115 ql_dbg(ql_dbg_async
, vha
, 0x5020,
1116 "FCF Configuration Error -- %04x %04x %04x.\n",
1117 mb
[1], mb
[2], mb
[3]);
1119 case MBA_IDC_NOTIFY
:
1120 if (IS_QLA8031(vha
->hw
) || IS_QLA8044(ha
)) {
1121 mb
[4] = RD_REG_WORD(®24
->mailbox4
);
1122 if (((mb
[2] & 0x7fff) == MBC_PORT_RESET
||
1123 (mb
[2] & 0x7fff) == MBC_SET_PORT_CONFIG
) &&
1124 (mb
[4] & INTERNAL_LOOPBACK_MASK
) != 0) {
1125 set_bit(ISP_QUIESCE_NEEDED
, &vha
->dpc_flags
);
1127 * Extend loop down timer since port is active.
1129 if (atomic_read(&vha
->loop_state
) == LOOP_DOWN
)
1130 atomic_set(&vha
->loop_down_timer
,
1132 qla2xxx_wake_dpc(vha
);
1135 case MBA_IDC_COMPLETE
:
1136 if (ha
->notify_lb_portup_comp
&& !vha
->vp_idx
)
1137 complete(&ha
->lb_portup_comp
);
1139 case MBA_IDC_TIME_EXT
:
1140 if (IS_QLA81XX(vha
->hw
) || IS_QLA8031(vha
->hw
) ||
1142 qla81xx_idc_event(vha
, mb
[0], mb
[1]);
1146 mb
[4] = RD_REG_WORD(®24
->mailbox4
);
1147 mb
[5] = RD_REG_WORD(®24
->mailbox5
);
1148 mb
[6] = RD_REG_WORD(®24
->mailbox6
);
1149 mb
[7] = RD_REG_WORD(®24
->mailbox7
);
1150 qla83xx_handle_8200_aen(vha
, mb
);
1153 case MBA_DPORT_DIAGNOSTICS
:
1154 ql_dbg(ql_dbg_async
, vha
, 0x5052,
1155 "D-Port Diagnostics: %04x %04x=%s\n", mb
[0], mb
[1],
1156 mb
[1] == 0 ? "start" :
1157 mb
[1] == 1 ? "done (ok)" :
1158 mb
[1] == 2 ? "done (error)" : "other");
1162 ql_dbg(ql_dbg_async
, vha
, 0x5057,
1163 "Unknown AEN:%04x %04x %04x %04x\n",
1164 mb
[0], mb
[1], mb
[2], mb
[3]);
1167 qlt_async_event(mb
[0], vha
, mb
);
1169 if (!vha
->vp_idx
&& ha
->num_vhosts
)
1170 qla2x00_alert_all_vps(rsp
, mb
);
1174 * qla2x00_process_completed_request() - Process a Fast Post response.
1175 * @ha: SCSI driver HA context
1179 qla2x00_process_completed_request(struct scsi_qla_host
*vha
,
1180 struct req_que
*req
, uint32_t index
)
1183 struct qla_hw_data
*ha
= vha
->hw
;
1185 /* Validate handle. */
1186 if (index
>= req
->num_outstanding_cmds
) {
1187 ql_log(ql_log_warn
, vha
, 0x3014,
1188 "Invalid SCSI command index (%x).\n", index
);
1190 if (IS_P3P_TYPE(ha
))
1191 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
1193 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1197 sp
= req
->outstanding_cmds
[index
];
1199 /* Free outstanding command slot. */
1200 req
->outstanding_cmds
[index
] = NULL
;
1202 /* Save ISP completion status */
1203 sp
->done(ha
, sp
, DID_OK
<< 16);
1205 ql_log(ql_log_warn
, vha
, 0x3016, "Invalid SCSI SRB.\n");
1207 if (IS_P3P_TYPE(ha
))
1208 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
1210 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1215 qla2x00_get_sp_from_handle(scsi_qla_host_t
*vha
, const char *func
,
1216 struct req_que
*req
, void *iocb
)
1218 struct qla_hw_data
*ha
= vha
->hw
;
1219 sts_entry_t
*pkt
= iocb
;
1223 index
= LSW(pkt
->handle
);
1224 if (index
>= req
->num_outstanding_cmds
) {
1225 ql_log(ql_log_warn
, vha
, 0x5031,
1226 "Invalid command index (%x).\n", index
);
1227 if (IS_P3P_TYPE(ha
))
1228 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
1230 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1233 sp
= req
->outstanding_cmds
[index
];
1235 ql_log(ql_log_warn
, vha
, 0x5032,
1236 "Invalid completion handle (%x) -- timed-out.\n", index
);
1239 if (sp
->handle
!= index
) {
1240 ql_log(ql_log_warn
, vha
, 0x5033,
1241 "SRB handle (%x) mismatch %x.\n", sp
->handle
, index
);
1245 req
->outstanding_cmds
[index
] = NULL
;
1252 qla2x00_mbx_iocb_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
1253 struct mbx_entry
*mbx
)
1255 const char func
[] = "MBX-IOCB";
1259 struct srb_iocb
*lio
;
1263 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, mbx
);
1267 lio
= &sp
->u
.iocb_cmd
;
1269 fcport
= sp
->fcport
;
1270 data
= lio
->u
.logio
.data
;
1272 data
[0] = MBS_COMMAND_ERROR
;
1273 data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
1274 QLA_LOGIO_LOGIN_RETRIED
: 0;
1275 if (mbx
->entry_status
) {
1276 ql_dbg(ql_dbg_async
, vha
, 0x5043,
1277 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
1278 "entry-status=%x status=%x state-flag=%x "
1279 "status-flags=%x.\n", type
, sp
->handle
,
1280 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
1281 fcport
->d_id
.b
.al_pa
, mbx
->entry_status
,
1282 le16_to_cpu(mbx
->status
), le16_to_cpu(mbx
->state_flags
),
1283 le16_to_cpu(mbx
->status_flags
));
1285 ql_dump_buffer(ql_dbg_async
+ ql_dbg_buffer
, vha
, 0x5029,
1286 (uint8_t *)mbx
, sizeof(*mbx
));
1291 status
= le16_to_cpu(mbx
->status
);
1292 if (status
== 0x30 && sp
->type
== SRB_LOGIN_CMD
&&
1293 le16_to_cpu(mbx
->mb0
) == MBS_COMMAND_COMPLETE
)
1295 if (!status
&& le16_to_cpu(mbx
->mb0
) == MBS_COMMAND_COMPLETE
) {
1296 ql_dbg(ql_dbg_async
, vha
, 0x5045,
1297 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1298 type
, sp
->handle
, fcport
->d_id
.b
.domain
,
1299 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
1300 le16_to_cpu(mbx
->mb1
));
1302 data
[0] = MBS_COMMAND_COMPLETE
;
1303 if (sp
->type
== SRB_LOGIN_CMD
) {
1304 fcport
->port_type
= FCT_TARGET
;
1305 if (le16_to_cpu(mbx
->mb1
) & BIT_0
)
1306 fcport
->port_type
= FCT_INITIATOR
;
1307 else if (le16_to_cpu(mbx
->mb1
) & BIT_1
)
1308 fcport
->flags
|= FCF_FCP2_DEVICE
;
1313 data
[0] = le16_to_cpu(mbx
->mb0
);
1315 case MBS_PORT_ID_USED
:
1316 data
[1] = le16_to_cpu(mbx
->mb1
);
1318 case MBS_LOOP_ID_USED
:
1321 data
[0] = MBS_COMMAND_ERROR
;
1325 ql_log(ql_log_warn
, vha
, 0x5046,
1326 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1327 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type
, sp
->handle
,
1328 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
1329 status
, le16_to_cpu(mbx
->mb0
), le16_to_cpu(mbx
->mb1
),
1330 le16_to_cpu(mbx
->mb2
), le16_to_cpu(mbx
->mb6
),
1331 le16_to_cpu(mbx
->mb7
));
1334 sp
->done(vha
, sp
, 0);
1338 qla2x00_ct_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
1339 sts_entry_t
*pkt
, int iocb_type
)
1341 const char func
[] = "CT_IOCB";
1344 struct fc_bsg_job
*bsg_job
;
1345 uint16_t comp_status
;
1348 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, pkt
);
1352 bsg_job
= sp
->u
.bsg_job
;
1354 type
= "ct pass-through";
1356 comp_status
= le16_to_cpu(pkt
->comp_status
);
1358 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1359 * fc payload to the caller
1361 bsg_job
->reply
->reply_data
.ctels_reply
.status
= FC_CTELS_STATUS_OK
;
1362 bsg_job
->reply_len
= sizeof(struct fc_bsg_reply
);
1364 if (comp_status
!= CS_COMPLETE
) {
1365 if (comp_status
== CS_DATA_UNDERRUN
) {
1367 bsg_job
->reply
->reply_payload_rcv_len
=
1368 le16_to_cpu(((sts_entry_t
*)pkt
)->rsp_info_len
);
1370 ql_log(ql_log_warn
, vha
, 0x5048,
1371 "CT pass-through-%s error "
1372 "comp_status-status=0x%x total_byte = 0x%x.\n",
1374 bsg_job
->reply
->reply_payload_rcv_len
);
1376 ql_log(ql_log_warn
, vha
, 0x5049,
1377 "CT pass-through-%s error "
1378 "comp_status-status=0x%x.\n", type
, comp_status
);
1379 res
= DID_ERROR
<< 16;
1380 bsg_job
->reply
->reply_payload_rcv_len
= 0;
1382 ql_dump_buffer(ql_dbg_async
+ ql_dbg_buffer
, vha
, 0x5035,
1383 (uint8_t *)pkt
, sizeof(*pkt
));
1386 bsg_job
->reply
->reply_payload_rcv_len
=
1387 bsg_job
->reply_payload
.payload_len
;
1388 bsg_job
->reply_len
= 0;
1391 sp
->done(vha
, sp
, res
);
1395 qla24xx_els_ct_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
1396 struct sts_entry_24xx
*pkt
, int iocb_type
)
1398 const char func
[] = "ELS_CT_IOCB";
1401 struct fc_bsg_job
*bsg_job
;
1402 uint16_t comp_status
;
1403 uint32_t fw_status
[3];
1404 uint8_t* fw_sts_ptr
;
1407 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, pkt
);
1410 bsg_job
= sp
->u
.bsg_job
;
1414 case SRB_ELS_CMD_RPT
:
1415 case SRB_ELS_CMD_HST
:
1419 type
= "ct pass-through";
1422 type
= "Driver ELS logo";
1423 ql_dbg(ql_dbg_user
, vha
, 0x5047,
1424 "Completing %s: (%p) type=%d.\n", type
, sp
, sp
->type
);
1425 sp
->done(vha
, sp
, 0);
1428 ql_dbg(ql_dbg_user
, vha
, 0x503e,
1429 "Unrecognized SRB: (%p) type=%d.\n", sp
, sp
->type
);
1433 comp_status
= fw_status
[0] = le16_to_cpu(pkt
->comp_status
);
1434 fw_status
[1] = le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->error_subcode_1
);
1435 fw_status
[2] = le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->error_subcode_2
);
1437 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1438 * fc payload to the caller
1440 bsg_job
->reply
->reply_data
.ctels_reply
.status
= FC_CTELS_STATUS_OK
;
1441 bsg_job
->reply_len
= sizeof(struct fc_bsg_reply
) + sizeof(fw_status
);
1443 if (comp_status
!= CS_COMPLETE
) {
1444 if (comp_status
== CS_DATA_UNDERRUN
) {
1446 bsg_job
->reply
->reply_payload_rcv_len
=
1447 le16_to_cpu(((struct els_sts_entry_24xx
*)pkt
)->total_byte_count
);
1449 ql_dbg(ql_dbg_user
, vha
, 0x503f,
1450 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
1451 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
1452 type
, sp
->handle
, comp_status
, fw_status
[1], fw_status
[2],
1453 le16_to_cpu(((struct els_sts_entry_24xx
*)
1454 pkt
)->total_byte_count
));
1455 fw_sts_ptr
= ((uint8_t*)bsg_job
->req
->sense
) + sizeof(struct fc_bsg_reply
);
1456 memcpy( fw_sts_ptr
, fw_status
, sizeof(fw_status
));
1459 ql_dbg(ql_dbg_user
, vha
, 0x5040,
1460 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
1461 "error subcode 1=0x%x error subcode 2=0x%x.\n",
1462 type
, sp
->handle
, comp_status
,
1463 le16_to_cpu(((struct els_sts_entry_24xx
*)
1464 pkt
)->error_subcode_1
),
1465 le16_to_cpu(((struct els_sts_entry_24xx
*)
1466 pkt
)->error_subcode_2
));
1467 res
= DID_ERROR
<< 16;
1468 bsg_job
->reply
->reply_payload_rcv_len
= 0;
1469 fw_sts_ptr
= ((uint8_t*)bsg_job
->req
->sense
) + sizeof(struct fc_bsg_reply
);
1470 memcpy( fw_sts_ptr
, fw_status
, sizeof(fw_status
));
1472 ql_dump_buffer(ql_dbg_user
+ ql_dbg_buffer
, vha
, 0x5056,
1473 (uint8_t *)pkt
, sizeof(*pkt
));
1477 bsg_job
->reply
->reply_payload_rcv_len
= bsg_job
->reply_payload
.payload_len
;
1478 bsg_job
->reply_len
= 0;
1481 sp
->done(vha
, sp
, res
);
1485 qla24xx_logio_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
1486 struct logio_entry_24xx
*logio
)
1488 const char func
[] = "LOGIO-IOCB";
1492 struct srb_iocb
*lio
;
1496 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, logio
);
1500 lio
= &sp
->u
.iocb_cmd
;
1502 fcport
= sp
->fcport
;
1503 data
= lio
->u
.logio
.data
;
1505 data
[0] = MBS_COMMAND_ERROR
;
1506 data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
1507 QLA_LOGIO_LOGIN_RETRIED
: 0;
1508 if (logio
->entry_status
) {
1509 ql_log(ql_log_warn
, fcport
->vha
, 0x5034,
1510 "Async-%s error entry - hdl=%x"
1511 "portid=%02x%02x%02x entry-status=%x.\n",
1512 type
, sp
->handle
, fcport
->d_id
.b
.domain
,
1513 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
1514 logio
->entry_status
);
1515 ql_dump_buffer(ql_dbg_async
+ ql_dbg_buffer
, vha
, 0x504d,
1516 (uint8_t *)logio
, sizeof(*logio
));
1521 if (le16_to_cpu(logio
->comp_status
) == CS_COMPLETE
) {
1522 ql_dbg(ql_dbg_async
, fcport
->vha
, 0x5036,
1523 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1524 "iop0=%x.\n", type
, sp
->handle
, fcport
->d_id
.b
.domain
,
1525 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
1526 le32_to_cpu(logio
->io_parameter
[0]));
1528 data
[0] = MBS_COMMAND_COMPLETE
;
1529 if (sp
->type
!= SRB_LOGIN_CMD
)
1532 iop
[0] = le32_to_cpu(logio
->io_parameter
[0]);
1533 if (iop
[0] & BIT_4
) {
1534 fcport
->port_type
= FCT_TARGET
;
1536 fcport
->flags
|= FCF_FCP2_DEVICE
;
1537 } else if (iop
[0] & BIT_5
)
1538 fcport
->port_type
= FCT_INITIATOR
;
1541 fcport
->flags
|= FCF_CONF_COMP_SUPPORTED
;
1543 if (logio
->io_parameter
[7] || logio
->io_parameter
[8])
1544 fcport
->supported_classes
|= FC_COS_CLASS2
;
1545 if (logio
->io_parameter
[9] || logio
->io_parameter
[10])
1546 fcport
->supported_classes
|= FC_COS_CLASS3
;
1551 iop
[0] = le32_to_cpu(logio
->io_parameter
[0]);
1552 iop
[1] = le32_to_cpu(logio
->io_parameter
[1]);
1554 case LSC_SCODE_PORTID_USED
:
1555 data
[0] = MBS_PORT_ID_USED
;
1556 data
[1] = LSW(iop
[1]);
1558 case LSC_SCODE_NPORT_USED
:
1559 data
[0] = MBS_LOOP_ID_USED
;
1562 data
[0] = MBS_COMMAND_ERROR
;
1566 ql_dbg(ql_dbg_async
, fcport
->vha
, 0x5037,
1567 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1568 "iop0=%x iop1=%x.\n", type
, sp
->handle
, fcport
->d_id
.b
.domain
,
1569 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
1570 le16_to_cpu(logio
->comp_status
),
1571 le32_to_cpu(logio
->io_parameter
[0]),
1572 le32_to_cpu(logio
->io_parameter
[1]));
1575 sp
->done(vha
, sp
, 0);
1579 qla24xx_tm_iocb_entry(scsi_qla_host_t
*vha
, struct req_que
*req
, void *tsk
)
1581 const char func
[] = "TMF-IOCB";
1585 struct srb_iocb
*iocb
;
1586 struct sts_entry_24xx
*sts
= (struct sts_entry_24xx
*)tsk
;
1588 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, tsk
);
1592 iocb
= &sp
->u
.iocb_cmd
;
1594 fcport
= sp
->fcport
;
1595 iocb
->u
.tmf
.data
= QLA_SUCCESS
;
1597 if (sts
->entry_status
) {
1598 ql_log(ql_log_warn
, fcport
->vha
, 0x5038,
1599 "Async-%s error - hdl=%x entry-status(%x).\n",
1600 type
, sp
->handle
, sts
->entry_status
);
1601 iocb
->u
.tmf
.data
= QLA_FUNCTION_FAILED
;
1602 } else if (sts
->comp_status
!= cpu_to_le16(CS_COMPLETE
)) {
1603 ql_log(ql_log_warn
, fcport
->vha
, 0x5039,
1604 "Async-%s error - hdl=%x completion status(%x).\n",
1605 type
, sp
->handle
, sts
->comp_status
);
1606 iocb
->u
.tmf
.data
= QLA_FUNCTION_FAILED
;
1607 } else if ((le16_to_cpu(sts
->scsi_status
) &
1608 SS_RESPONSE_INFO_LEN_VALID
)) {
1609 if (le32_to_cpu(sts
->rsp_data_len
) < 4) {
1610 ql_log(ql_log_warn
, fcport
->vha
, 0x503b,
1611 "Async-%s error - hdl=%x not enough response(%d).\n",
1612 type
, sp
->handle
, sts
->rsp_data_len
);
1613 } else if (sts
->data
[3]) {
1614 ql_log(ql_log_warn
, fcport
->vha
, 0x503c,
1615 "Async-%s error - hdl=%x response(%x).\n",
1616 type
, sp
->handle
, sts
->data
[3]);
1617 iocb
->u
.tmf
.data
= QLA_FUNCTION_FAILED
;
1621 if (iocb
->u
.tmf
.data
!= QLA_SUCCESS
)
1622 ql_dump_buffer(ql_dbg_async
+ ql_dbg_buffer
, vha
, 0x5055,
1623 (uint8_t *)sts
, sizeof(*sts
));
1625 sp
->done(vha
, sp
, 0);
1629 * qla2x00_process_response_queue() - Process response queue entries.
1630 * @ha: SCSI driver HA context
1633 qla2x00_process_response_queue(struct rsp_que
*rsp
)
1635 struct scsi_qla_host
*vha
;
1636 struct qla_hw_data
*ha
= rsp
->hw
;
1637 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1639 uint16_t handle_cnt
;
1642 vha
= pci_get_drvdata(ha
->pdev
);
1644 if (!vha
->flags
.online
)
1647 while (rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
1648 pkt
= (sts_entry_t
*)rsp
->ring_ptr
;
1651 if (rsp
->ring_index
== rsp
->length
) {
1652 rsp
->ring_index
= 0;
1653 rsp
->ring_ptr
= rsp
->ring
;
1658 if (pkt
->entry_status
!= 0) {
1659 qla2x00_error_entry(vha
, rsp
, pkt
);
1660 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1665 switch (pkt
->entry_type
) {
1667 qla2x00_status_entry(vha
, rsp
, pkt
);
1669 case STATUS_TYPE_21
:
1670 handle_cnt
= ((sts21_entry_t
*)pkt
)->handle_count
;
1671 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
1672 qla2x00_process_completed_request(vha
, rsp
->req
,
1673 ((sts21_entry_t
*)pkt
)->handle
[cnt
]);
1676 case STATUS_TYPE_22
:
1677 handle_cnt
= ((sts22_entry_t
*)pkt
)->handle_count
;
1678 for (cnt
= 0; cnt
< handle_cnt
; cnt
++) {
1679 qla2x00_process_completed_request(vha
, rsp
->req
,
1680 ((sts22_entry_t
*)pkt
)->handle
[cnt
]);
1683 case STATUS_CONT_TYPE
:
1684 qla2x00_status_cont_entry(rsp
, (sts_cont_entry_t
*)pkt
);
1687 qla2x00_mbx_iocb_entry(vha
, rsp
->req
,
1688 (struct mbx_entry
*)pkt
);
1691 qla2x00_ct_entry(vha
, rsp
->req
, pkt
, CT_IOCB_TYPE
);
1694 /* Type Not Supported. */
1695 ql_log(ql_log_warn
, vha
, 0x504a,
1696 "Received unknown response pkt type %x "
1697 "entry status=%x.\n",
1698 pkt
->entry_type
, pkt
->entry_status
);
1701 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
1705 /* Adjust ring index */
1706 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), rsp
->ring_index
);
1710 qla2x00_handle_sense(srb_t
*sp
, uint8_t *sense_data
, uint32_t par_sense_len
,
1711 uint32_t sense_len
, struct rsp_que
*rsp
, int res
)
1713 struct scsi_qla_host
*vha
= sp
->fcport
->vha
;
1714 struct scsi_cmnd
*cp
= GET_CMD_SP(sp
);
1715 uint32_t track_sense_len
;
1717 if (sense_len
>= SCSI_SENSE_BUFFERSIZE
)
1718 sense_len
= SCSI_SENSE_BUFFERSIZE
;
1720 SET_CMD_SENSE_LEN(sp
, sense_len
);
1721 SET_CMD_SENSE_PTR(sp
, cp
->sense_buffer
);
1722 track_sense_len
= sense_len
;
1724 if (sense_len
> par_sense_len
)
1725 sense_len
= par_sense_len
;
1727 memcpy(cp
->sense_buffer
, sense_data
, sense_len
);
1729 SET_CMD_SENSE_PTR(sp
, cp
->sense_buffer
+ sense_len
);
1730 track_sense_len
-= sense_len
;
1731 SET_CMD_SENSE_LEN(sp
, track_sense_len
);
1733 if (track_sense_len
!= 0) {
1734 rsp
->status_srb
= sp
;
1739 ql_dbg(ql_dbg_io
+ ql_dbg_buffer
, vha
, 0x301c,
1740 "Check condition Sense data, nexus%ld:%d:%llu cmd=%p.\n",
1741 sp
->fcport
->vha
->host_no
, cp
->device
->id
, cp
->device
->lun
,
1743 ql_dump_buffer(ql_dbg_io
+ ql_dbg_buffer
, vha
, 0x302b,
1744 cp
->sense_buffer
, sense_len
);
1748 struct scsi_dif_tuple
{
1749 __be16 guard
; /* Checksum */
1750 __be16 app_tag
; /* APPL identifier */
1751 __be32 ref_tag
; /* Target LBA or indirect LBA */
1755 * Checks the guard or meta-data for the type of error
1756 * detected by the HBA. In case of errors, we set the
1757 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1758 * to indicate to the kernel that the HBA detected error.
1761 qla2x00_handle_dif_error(srb_t
*sp
, struct sts_entry_24xx
*sts24
)
1763 struct scsi_qla_host
*vha
= sp
->fcport
->vha
;
1764 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
1765 uint8_t *ap
= &sts24
->data
[12];
1766 uint8_t *ep
= &sts24
->data
[20];
1767 uint32_t e_ref_tag
, a_ref_tag
;
1768 uint16_t e_app_tag
, a_app_tag
;
1769 uint16_t e_guard
, a_guard
;
1772 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1773 * would make guard field appear at offset 2
1775 a_guard
= le16_to_cpu(*(uint16_t *)(ap
+ 2));
1776 a_app_tag
= le16_to_cpu(*(uint16_t *)(ap
+ 0));
1777 a_ref_tag
= le32_to_cpu(*(uint32_t *)(ap
+ 4));
1778 e_guard
= le16_to_cpu(*(uint16_t *)(ep
+ 2));
1779 e_app_tag
= le16_to_cpu(*(uint16_t *)(ep
+ 0));
1780 e_ref_tag
= le32_to_cpu(*(uint32_t *)(ep
+ 4));
1782 ql_dbg(ql_dbg_io
, vha
, 0x3023,
1783 "iocb(s) %p Returned STATUS.\n", sts24
);
1785 ql_dbg(ql_dbg_io
, vha
, 0x3024,
1786 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
1787 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
1788 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
1789 cmd
->cmnd
[0], (u64
)scsi_get_lba(cmd
), a_ref_tag
, e_ref_tag
,
1790 a_app_tag
, e_app_tag
, a_guard
, e_guard
);
1794 * For type 3: ref & app tag is all 'f's
1795 * For type 0,1,2: app tag is all 'f's
1797 if ((a_app_tag
== 0xffff) &&
1798 ((scsi_get_prot_type(cmd
) != SCSI_PROT_DIF_TYPE3
) ||
1799 (a_ref_tag
== 0xffffffff))) {
1800 uint32_t blocks_done
, resid
;
1801 sector_t lba_s
= scsi_get_lba(cmd
);
1803 /* 2TB boundary case covered automatically with this */
1804 blocks_done
= e_ref_tag
- (uint32_t)lba_s
+ 1;
1806 resid
= scsi_bufflen(cmd
) - (blocks_done
*
1807 cmd
->device
->sector_size
);
1809 scsi_set_resid(cmd
, resid
);
1810 cmd
->result
= DID_OK
<< 16;
1812 /* Update protection tag */
1813 if (scsi_prot_sg_count(cmd
)) {
1814 uint32_t i
, j
= 0, k
= 0, num_ent
;
1815 struct scatterlist
*sg
;
1816 struct sd_dif_tuple
*spt
;
1818 /* Patch the corresponding protection tags */
1819 scsi_for_each_prot_sg(cmd
, sg
,
1820 scsi_prot_sg_count(cmd
), i
) {
1821 num_ent
= sg_dma_len(sg
) / 8;
1822 if (k
+ num_ent
< blocks_done
) {
1826 j
= blocks_done
- k
- 1;
1831 if (k
!= blocks_done
) {
1832 ql_log(ql_log_warn
, vha
, 0x302f,
1833 "unexpected tag values tag:lba=%x:%llx)\n",
1834 e_ref_tag
, (unsigned long long)lba_s
);
1838 spt
= page_address(sg_page(sg
)) + sg
->offset
;
1841 spt
->app_tag
= 0xffff;
1842 if (scsi_get_prot_type(cmd
) == SCSI_PROT_DIF_TYPE3
)
1843 spt
->ref_tag
= 0xffffffff;
1850 if (e_guard
!= a_guard
) {
1851 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
1853 set_driver_byte(cmd
, DRIVER_SENSE
);
1854 set_host_byte(cmd
, DID_ABORT
);
1855 cmd
->result
|= SAM_STAT_CHECK_CONDITION
<< 1;
1860 if (e_ref_tag
!= a_ref_tag
) {
1861 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
1863 set_driver_byte(cmd
, DRIVER_SENSE
);
1864 set_host_byte(cmd
, DID_ABORT
);
1865 cmd
->result
|= SAM_STAT_CHECK_CONDITION
<< 1;
1869 /* check appl tag */
1870 if (e_app_tag
!= a_app_tag
) {
1871 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
1873 set_driver_byte(cmd
, DRIVER_SENSE
);
1874 set_host_byte(cmd
, DID_ABORT
);
1875 cmd
->result
|= SAM_STAT_CHECK_CONDITION
<< 1;
1883 qla25xx_process_bidir_status_iocb(scsi_qla_host_t
*vha
, void *pkt
,
1884 struct req_que
*req
, uint32_t index
)
1886 struct qla_hw_data
*ha
= vha
->hw
;
1888 uint16_t comp_status
;
1889 uint16_t scsi_status
;
1891 uint32_t rval
= EXT_STATUS_OK
;
1892 struct fc_bsg_job
*bsg_job
= NULL
;
1894 struct sts_entry_24xx
*sts24
;
1895 sts
= (sts_entry_t
*) pkt
;
1896 sts24
= (struct sts_entry_24xx
*) pkt
;
1898 /* Validate handle. */
1899 if (index
>= req
->num_outstanding_cmds
) {
1900 ql_log(ql_log_warn
, vha
, 0x70af,
1901 "Invalid SCSI completion handle 0x%x.\n", index
);
1902 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1906 sp
= req
->outstanding_cmds
[index
];
1908 /* Free outstanding command slot. */
1909 req
->outstanding_cmds
[index
] = NULL
;
1910 bsg_job
= sp
->u
.bsg_job
;
1912 ql_log(ql_log_warn
, vha
, 0x70b0,
1913 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
1916 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1920 if (IS_FWI2_CAPABLE(ha
)) {
1921 comp_status
= le16_to_cpu(sts24
->comp_status
);
1922 scsi_status
= le16_to_cpu(sts24
->scsi_status
) & SS_MASK
;
1924 comp_status
= le16_to_cpu(sts
->comp_status
);
1925 scsi_status
= le16_to_cpu(sts
->scsi_status
) & SS_MASK
;
1928 thread_id
= bsg_job
->request
->rqst_data
.h_vendor
.vendor_cmd
[1];
1929 switch (comp_status
) {
1931 if (scsi_status
== 0) {
1932 bsg_job
->reply
->reply_payload_rcv_len
=
1933 bsg_job
->reply_payload
.payload_len
;
1934 vha
->qla_stats
.input_bytes
+=
1935 bsg_job
->reply
->reply_payload_rcv_len
;
1936 vha
->qla_stats
.input_requests
++;
1937 rval
= EXT_STATUS_OK
;
1941 case CS_DATA_OVERRUN
:
1942 ql_dbg(ql_dbg_user
, vha
, 0x70b1,
1943 "Command completed with date overrun thread_id=%d\n",
1945 rval
= EXT_STATUS_DATA_OVERRUN
;
1948 case CS_DATA_UNDERRUN
:
1949 ql_dbg(ql_dbg_user
, vha
, 0x70b2,
1950 "Command completed with date underrun thread_id=%d\n",
1952 rval
= EXT_STATUS_DATA_UNDERRUN
;
1954 case CS_BIDIR_RD_OVERRUN
:
1955 ql_dbg(ql_dbg_user
, vha
, 0x70b3,
1956 "Command completed with read data overrun thread_id=%d\n",
1958 rval
= EXT_STATUS_DATA_OVERRUN
;
1961 case CS_BIDIR_RD_WR_OVERRUN
:
1962 ql_dbg(ql_dbg_user
, vha
, 0x70b4,
1963 "Command completed with read and write data overrun "
1964 "thread_id=%d\n", thread_id
);
1965 rval
= EXT_STATUS_DATA_OVERRUN
;
1968 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN
:
1969 ql_dbg(ql_dbg_user
, vha
, 0x70b5,
1970 "Command completed with read data over and write data "
1971 "underrun thread_id=%d\n", thread_id
);
1972 rval
= EXT_STATUS_DATA_OVERRUN
;
1975 case CS_BIDIR_RD_UNDERRUN
:
1976 ql_dbg(ql_dbg_user
, vha
, 0x70b6,
1977 "Command completed with read data data underrun "
1978 "thread_id=%d\n", thread_id
);
1979 rval
= EXT_STATUS_DATA_UNDERRUN
;
1982 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN
:
1983 ql_dbg(ql_dbg_user
, vha
, 0x70b7,
1984 "Command completed with read data under and write data "
1985 "overrun thread_id=%d\n", thread_id
);
1986 rval
= EXT_STATUS_DATA_UNDERRUN
;
1989 case CS_BIDIR_RD_WR_UNDERRUN
:
1990 ql_dbg(ql_dbg_user
, vha
, 0x70b8,
1991 "Command completed with read and write data underrun "
1992 "thread_id=%d\n", thread_id
);
1993 rval
= EXT_STATUS_DATA_UNDERRUN
;
1997 ql_dbg(ql_dbg_user
, vha
, 0x70b9,
1998 "Command completed with data DMA error thread_id=%d\n",
2000 rval
= EXT_STATUS_DMA_ERR
;
2004 ql_dbg(ql_dbg_user
, vha
, 0x70ba,
2005 "Command completed with timeout thread_id=%d\n",
2007 rval
= EXT_STATUS_TIMEOUT
;
2010 ql_dbg(ql_dbg_user
, vha
, 0x70bb,
2011 "Command completed with completion status=0x%x "
2012 "thread_id=%d\n", comp_status
, thread_id
);
2013 rval
= EXT_STATUS_ERR
;
2016 bsg_job
->reply
->reply_payload_rcv_len
= 0;
2019 /* Return the vendor specific reply to API */
2020 bsg_job
->reply
->reply_data
.vendor_reply
.vendor_rsp
[0] = rval
;
2021 bsg_job
->reply_len
= sizeof(struct fc_bsg_reply
);
2022 /* Always return DID_OK, bsg will send the vendor specific response
2023 * in this case only */
2024 sp
->done(vha
, sp
, (DID_OK
<< 6));
2029 * qla2x00_status_entry() - Process a Status IOCB entry.
2030 * @ha: SCSI driver HA context
2031 * @pkt: Entry pointer
2034 qla2x00_status_entry(scsi_qla_host_t
*vha
, struct rsp_que
*rsp
, void *pkt
)
2038 struct scsi_cmnd
*cp
;
2040 struct sts_entry_24xx
*sts24
;
2041 uint16_t comp_status
;
2042 uint16_t scsi_status
;
2044 uint8_t lscsi_status
;
2046 uint32_t sense_len
, par_sense_len
, rsp_info_len
, resid_len
,
2048 uint8_t *rsp_info
, *sense_data
;
2049 struct qla_hw_data
*ha
= vha
->hw
;
2052 struct req_que
*req
;
2055 uint16_t state_flags
= 0;
2056 uint16_t retry_delay
= 0;
2058 sts
= (sts_entry_t
*) pkt
;
2059 sts24
= (struct sts_entry_24xx
*) pkt
;
2060 if (IS_FWI2_CAPABLE(ha
)) {
2061 comp_status
= le16_to_cpu(sts24
->comp_status
);
2062 scsi_status
= le16_to_cpu(sts24
->scsi_status
) & SS_MASK
;
2063 state_flags
= le16_to_cpu(sts24
->state_flags
);
2065 comp_status
= le16_to_cpu(sts
->comp_status
);
2066 scsi_status
= le16_to_cpu(sts
->scsi_status
) & SS_MASK
;
2068 handle
= (uint32_t) LSW(sts
->handle
);
2069 que
= MSW(sts
->handle
);
2070 req
= ha
->req_q_map
[que
];
2072 /* Check for invalid queue pointer */
2074 que
>= find_first_zero_bit(ha
->req_qid_map
, ha
->max_req_queues
)) {
2075 ql_dbg(ql_dbg_io
, vha
, 0x3059,
2076 "Invalid status handle (0x%x): Bad req pointer. req=%p, "
2077 "que=%u.\n", sts
->handle
, req
, que
);
2081 /* Validate handle. */
2082 if (handle
< req
->num_outstanding_cmds
) {
2083 sp
= req
->outstanding_cmds
[handle
];
2085 ql_dbg(ql_dbg_io
, vha
, 0x3075,
2086 "%s(%ld): Already returned command for status handle (0x%x).\n",
2087 __func__
, vha
->host_no
, sts
->handle
);
2091 ql_dbg(ql_dbg_io
, vha
, 0x3017,
2092 "Invalid status handle, out of range (0x%x).\n",
2095 if (!test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)) {
2096 if (IS_P3P_TYPE(ha
))
2097 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
2099 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2100 qla2xxx_wake_dpc(vha
);
2105 if (unlikely((state_flags
& BIT_1
) && (sp
->type
== SRB_BIDI_CMD
))) {
2106 qla25xx_process_bidir_status_iocb(vha
, pkt
, req
, handle
);
2110 /* Task Management completion. */
2111 if (sp
->type
== SRB_TM_CMD
) {
2112 qla24xx_tm_iocb_entry(vha
, req
, pkt
);
2116 /* Fast path completion. */
2117 if (comp_status
== CS_COMPLETE
&& scsi_status
== 0) {
2118 qla2x00_process_completed_request(vha
, req
, handle
);
2123 req
->outstanding_cmds
[handle
] = NULL
;
2124 cp
= GET_CMD_SP(sp
);
2126 ql_dbg(ql_dbg_io
, vha
, 0x3018,
2127 "Command already returned (0x%x/%p).\n",
2133 lscsi_status
= scsi_status
& STATUS_MASK
;
2135 fcport
= sp
->fcport
;
2138 sense_len
= par_sense_len
= rsp_info_len
= resid_len
=
2140 if (IS_FWI2_CAPABLE(ha
)) {
2141 if (scsi_status
& SS_SENSE_LEN_VALID
)
2142 sense_len
= le32_to_cpu(sts24
->sense_len
);
2143 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
)
2144 rsp_info_len
= le32_to_cpu(sts24
->rsp_data_len
);
2145 if (scsi_status
& (SS_RESIDUAL_UNDER
| SS_RESIDUAL_OVER
))
2146 resid_len
= le32_to_cpu(sts24
->rsp_residual_count
);
2147 if (comp_status
== CS_DATA_UNDERRUN
)
2148 fw_resid_len
= le32_to_cpu(sts24
->residual_len
);
2149 rsp_info
= sts24
->data
;
2150 sense_data
= sts24
->data
;
2151 host_to_fcp_swap(sts24
->data
, sizeof(sts24
->data
));
2152 ox_id
= le16_to_cpu(sts24
->ox_id
);
2153 par_sense_len
= sizeof(sts24
->data
);
2154 /* Valid values of the retry delay timer are 0x1-0xffef */
2155 if (sts24
->retry_delay
> 0 && sts24
->retry_delay
< 0xfff1)
2156 retry_delay
= sts24
->retry_delay
;
2158 if (scsi_status
& SS_SENSE_LEN_VALID
)
2159 sense_len
= le16_to_cpu(sts
->req_sense_length
);
2160 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
)
2161 rsp_info_len
= le16_to_cpu(sts
->rsp_info_len
);
2162 resid_len
= le32_to_cpu(sts
->residual_length
);
2163 rsp_info
= sts
->rsp_info
;
2164 sense_data
= sts
->req_sense_data
;
2165 par_sense_len
= sizeof(sts
->req_sense_data
);
2168 /* Check for any FCP transport errors. */
2169 if (scsi_status
& SS_RESPONSE_INFO_LEN_VALID
) {
2170 /* Sense data lies beyond any FCP RESPONSE data. */
2171 if (IS_FWI2_CAPABLE(ha
)) {
2172 sense_data
+= rsp_info_len
;
2173 par_sense_len
-= rsp_info_len
;
2175 if (rsp_info_len
> 3 && rsp_info
[3]) {
2176 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x3019,
2177 "FCP I/O protocol failure (0x%x/0x%x).\n",
2178 rsp_info_len
, rsp_info
[3]);
2180 res
= DID_BUS_BUSY
<< 16;
2185 /* Check for overrun. */
2186 if (IS_FWI2_CAPABLE(ha
) && comp_status
== CS_COMPLETE
&&
2187 scsi_status
& SS_RESIDUAL_OVER
)
2188 comp_status
= CS_DATA_OVERRUN
;
2191 * Check retry_delay_timer value if we receive a busy or
2194 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
||
2195 lscsi_status
== SAM_STAT_BUSY
)
2196 qla2x00_set_retry_delay_timestamp(fcport
, retry_delay
);
2199 * Based on Host and scsi status generate status code for Linux
2201 switch (comp_status
) {
2204 if (scsi_status
== 0) {
2208 if (scsi_status
& (SS_RESIDUAL_UNDER
| SS_RESIDUAL_OVER
)) {
2210 scsi_set_resid(cp
, resid
);
2212 if (!lscsi_status
&&
2213 ((unsigned)(scsi_bufflen(cp
) - resid
) <
2215 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x301a,
2216 "Mid-layer underflow "
2217 "detected (0x%x of 0x%x bytes).\n",
2218 resid
, scsi_bufflen(cp
));
2220 res
= DID_ERROR
<< 16;
2224 res
= DID_OK
<< 16 | lscsi_status
;
2226 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
) {
2227 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x301b,
2228 "QUEUE FULL detected.\n");
2232 if (lscsi_status
!= SS_CHECK_CONDITION
)
2235 memset(cp
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
2236 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
2239 qla2x00_handle_sense(sp
, sense_data
, par_sense_len
, sense_len
,
2243 case CS_DATA_UNDERRUN
:
2244 /* Use F/W calculated residual length. */
2245 resid
= IS_FWI2_CAPABLE(ha
) ? fw_resid_len
: resid_len
;
2246 scsi_set_resid(cp
, resid
);
2247 if (scsi_status
& SS_RESIDUAL_UNDER
) {
2248 if (IS_FWI2_CAPABLE(ha
) && fw_resid_len
!= resid_len
) {
2249 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x301d,
2250 "Dropped frame(s) detected "
2251 "(0x%x of 0x%x bytes).\n",
2252 resid
, scsi_bufflen(cp
));
2254 res
= DID_ERROR
<< 16 | lscsi_status
;
2255 goto check_scsi_status
;
2258 if (!lscsi_status
&&
2259 ((unsigned)(scsi_bufflen(cp
) - resid
) <
2261 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x301e,
2262 "Mid-layer underflow "
2263 "detected (0x%x of 0x%x bytes).\n",
2264 resid
, scsi_bufflen(cp
));
2266 res
= DID_ERROR
<< 16;
2269 } else if (lscsi_status
!= SAM_STAT_TASK_SET_FULL
&&
2270 lscsi_status
!= SAM_STAT_BUSY
) {
2272 * scsi status of task set and busy are considered to be
2273 * task not completed.
2276 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x301f,
2277 "Dropped frame(s) detected (0x%x "
2278 "of 0x%x bytes).\n", resid
,
2281 res
= DID_ERROR
<< 16 | lscsi_status
;
2282 goto check_scsi_status
;
2284 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x3030,
2285 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2286 scsi_status
, lscsi_status
);
2289 res
= DID_OK
<< 16 | lscsi_status
;
2294 * Check to see if SCSI Status is non zero. If so report SCSI
2297 if (lscsi_status
!= 0) {
2298 if (lscsi_status
== SAM_STAT_TASK_SET_FULL
) {
2299 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x3020,
2300 "QUEUE FULL detected.\n");
2304 if (lscsi_status
!= SS_CHECK_CONDITION
)
2307 memset(cp
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
2308 if (!(scsi_status
& SS_SENSE_LEN_VALID
))
2311 qla2x00_handle_sense(sp
, sense_data
, par_sense_len
,
2312 sense_len
, rsp
, res
);
2316 case CS_PORT_LOGGED_OUT
:
2317 case CS_PORT_CONFIG_CHG
:
2320 case CS_PORT_UNAVAILABLE
:
2325 * We are going to have the fc class block the rport
2326 * while we try to recover so instruct the mid layer
2327 * to requeue until the class decides how to handle this.
2329 res
= DID_TRANSPORT_DISRUPTED
<< 16;
2331 if (comp_status
== CS_TIMEOUT
) {
2332 if (IS_FWI2_CAPABLE(ha
))
2334 else if ((le16_to_cpu(sts
->status_flags
) &
2335 SF_LOGOUT_SENT
) == 0)
2339 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x3021,
2340 "Port to be marked lost on fcport=%02x%02x%02x, current "
2341 "port state= %s.\n", fcport
->d_id
.b
.domain
,
2342 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
2343 port_state_str
[atomic_read(&fcport
->state
)]);
2345 if (atomic_read(&fcport
->state
) == FCS_ONLINE
)
2346 qla2x00_mark_device_lost(fcport
->vha
, fcport
, 1, 1);
2350 res
= DID_RESET
<< 16;
2354 logit
= qla2x00_handle_dif_error(sp
, sts24
);
2359 res
= DID_ERROR
<< 16;
2361 if (!IS_PI_SPLIT_DET_CAPABLE(ha
))
2364 if (state_flags
& BIT_4
)
2365 scmd_printk(KERN_WARNING
, cp
,
2366 "Unsupported device '%s' found.\n",
2367 cp
->device
->vendor
);
2371 res
= DID_ERROR
<< 16;
2377 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x3022,
2378 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%llu "
2379 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
2380 "rsp_info=0x%x resid=0x%x fw_resid=0x%x sp=%p cp=%p.\n",
2381 comp_status
, scsi_status
, res
, vha
->host_no
,
2382 cp
->device
->id
, cp
->device
->lun
, fcport
->d_id
.b
.domain
,
2383 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
, ox_id
,
2384 cp
->cmnd
, scsi_bufflen(cp
), rsp_info_len
,
2385 resid_len
, fw_resid_len
, sp
, cp
);
2387 if (rsp
->status_srb
== NULL
)
2388 sp
->done(ha
, sp
, res
);
2392 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2393 * @ha: SCSI driver HA context
2394 * @pkt: Entry pointer
2396 * Extended sense data.
2399 qla2x00_status_cont_entry(struct rsp_que
*rsp
, sts_cont_entry_t
*pkt
)
2401 uint8_t sense_sz
= 0;
2402 struct qla_hw_data
*ha
= rsp
->hw
;
2403 struct scsi_qla_host
*vha
= pci_get_drvdata(ha
->pdev
);
2404 srb_t
*sp
= rsp
->status_srb
;
2405 struct scsi_cmnd
*cp
;
2409 if (!sp
|| !GET_CMD_SENSE_LEN(sp
))
2412 sense_len
= GET_CMD_SENSE_LEN(sp
);
2413 sense_ptr
= GET_CMD_SENSE_PTR(sp
);
2415 cp
= GET_CMD_SP(sp
);
2417 ql_log(ql_log_warn
, vha
, 0x3025,
2418 "cmd is NULL: already returned to OS (sp=%p).\n", sp
);
2420 rsp
->status_srb
= NULL
;
2424 if (sense_len
> sizeof(pkt
->data
))
2425 sense_sz
= sizeof(pkt
->data
);
2427 sense_sz
= sense_len
;
2429 /* Move sense data. */
2430 if (IS_FWI2_CAPABLE(ha
))
2431 host_to_fcp_swap(pkt
->data
, sizeof(pkt
->data
));
2432 memcpy(sense_ptr
, pkt
->data
, sense_sz
);
2433 ql_dump_buffer(ql_dbg_io
+ ql_dbg_buffer
, vha
, 0x302c,
2434 sense_ptr
, sense_sz
);
2436 sense_len
-= sense_sz
;
2437 sense_ptr
+= sense_sz
;
2439 SET_CMD_SENSE_PTR(sp
, sense_ptr
);
2440 SET_CMD_SENSE_LEN(sp
, sense_len
);
2442 /* Place command on done queue. */
2443 if (sense_len
== 0) {
2444 rsp
->status_srb
= NULL
;
2445 sp
->done(ha
, sp
, cp
->result
);
2450 * qla2x00_error_entry() - Process an error entry.
2451 * @ha: SCSI driver HA context
2452 * @pkt: Entry pointer
2455 qla2x00_error_entry(scsi_qla_host_t
*vha
, struct rsp_que
*rsp
, sts_entry_t
*pkt
)
2458 struct qla_hw_data
*ha
= vha
->hw
;
2459 const char func
[] = "ERROR-IOCB";
2460 uint16_t que
= MSW(pkt
->handle
);
2461 struct req_que
*req
= NULL
;
2462 int res
= DID_ERROR
<< 16;
2464 ql_dbg(ql_dbg_async
, vha
, 0x502a,
2465 "type of error status in response: 0x%x\n", pkt
->entry_status
);
2467 if (que
>= ha
->max_req_queues
|| !ha
->req_q_map
[que
])
2470 req
= ha
->req_q_map
[que
];
2472 if (pkt
->entry_status
& RF_BUSY
)
2473 res
= DID_BUS_BUSY
<< 16;
2475 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, pkt
);
2477 sp
->done(ha
, sp
, res
);
2481 ql_log(ql_log_warn
, vha
, 0x5030,
2482 "Error entry - invalid handle/queue (%04x).\n", que
);
2486 * qla24xx_mbx_completion() - Process mailbox command completions.
2487 * @ha: SCSI driver HA context
2488 * @mb0: Mailbox0 register
2491 qla24xx_mbx_completion(scsi_qla_host_t
*vha
, uint16_t mb0
)
2495 uint16_t __iomem
*wptr
;
2496 struct qla_hw_data
*ha
= vha
->hw
;
2497 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2499 /* Read all mbox registers? */
2500 mboxes
= (1 << ha
->mbx_count
) - 1;
2502 ql_dbg(ql_dbg_async
, vha
, 0x504e, "MBX pointer ERROR.\n");
2504 mboxes
= ha
->mcp
->in_mb
;
2506 /* Load return mailbox registers. */
2507 ha
->flags
.mbox_int
= 1;
2508 ha
->mailbox_out
[0] = mb0
;
2510 wptr
= (uint16_t __iomem
*)®
->mailbox1
;
2512 for (cnt
= 1; cnt
< ha
->mbx_count
; cnt
++) {
2514 ha
->mailbox_out
[cnt
] = RD_REG_WORD(wptr
);
2522 qla24xx_abort_iocb_entry(scsi_qla_host_t
*vha
, struct req_que
*req
,
2523 struct abort_entry_24xx
*pkt
)
2525 const char func
[] = "ABT_IOCB";
2527 struct srb_iocb
*abt
;
2529 sp
= qla2x00_get_sp_from_handle(vha
, func
, req
, pkt
);
2533 abt
= &sp
->u
.iocb_cmd
;
2534 abt
->u
.abt
.comp_status
= le32_to_cpu(pkt
->nport_handle
);
2535 sp
->done(vha
, sp
, 0);
2539 * qla24xx_process_response_queue() - Process response queue entries.
2540 * @ha: SCSI driver HA context
2542 void qla24xx_process_response_queue(struct scsi_qla_host
*vha
,
2543 struct rsp_que
*rsp
)
2545 struct sts_entry_24xx
*pkt
;
2546 struct qla_hw_data
*ha
= vha
->hw
;
2548 if (!vha
->flags
.online
)
2551 if (rsp
->msix
->cpuid
!= smp_processor_id()) {
2552 /* if kernel does not notify qla of IRQ's CPU change,
2555 rsp
->msix
->cpuid
= smp_processor_id();
2556 ha
->tgt
.rspq_vector_cpuid
= rsp
->msix
->cpuid
;
2559 while (rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
2560 pkt
= (struct sts_entry_24xx
*)rsp
->ring_ptr
;
2563 if (rsp
->ring_index
== rsp
->length
) {
2564 rsp
->ring_index
= 0;
2565 rsp
->ring_ptr
= rsp
->ring
;
2570 if (pkt
->entry_status
!= 0) {
2571 qla2x00_error_entry(vha
, rsp
, (sts_entry_t
*) pkt
);
2573 if (qlt_24xx_process_response_error(vha
, pkt
))
2576 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
2582 switch (pkt
->entry_type
) {
2584 qla2x00_status_entry(vha
, rsp
, pkt
);
2586 case STATUS_CONT_TYPE
:
2587 qla2x00_status_cont_entry(rsp
, (sts_cont_entry_t
*)pkt
);
2589 case VP_RPT_ID_IOCB_TYPE
:
2590 qla24xx_report_id_acquisition(vha
,
2591 (struct vp_rpt_id_entry_24xx
*)pkt
);
2593 case LOGINOUT_PORT_IOCB_TYPE
:
2594 qla24xx_logio_entry(vha
, rsp
->req
,
2595 (struct logio_entry_24xx
*)pkt
);
2598 qla24xx_els_ct_entry(vha
, rsp
->req
, pkt
, CT_IOCB_TYPE
);
2601 qla24xx_els_ct_entry(vha
, rsp
->req
, pkt
, ELS_IOCB_TYPE
);
2603 case ABTS_RECV_24XX
:
2604 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
2605 /* ensure that the ATIO queue is empty */
2606 qlt_handle_abts_recv(vha
, (response_t
*)pkt
);
2610 qlt_24xx_process_atio_queue(vha
, 1);
2612 case ABTS_RESP_24XX
:
2614 case NOTIFY_ACK_TYPE
:
2616 qlt_response_pkt_all_vps(vha
, (response_t
*)pkt
);
2619 /* Do nothing in this case, this check is to prevent it
2620 * from falling into default case
2623 case ABORT_IOCB_TYPE
:
2624 qla24xx_abort_iocb_entry(vha
, rsp
->req
,
2625 (struct abort_entry_24xx
*)pkt
);
2628 /* Type Not Supported. */
2629 ql_dbg(ql_dbg_async
, vha
, 0x5042,
2630 "Received unknown response pkt type %x "
2631 "entry status=%x.\n",
2632 pkt
->entry_type
, pkt
->entry_status
);
2635 ((response_t
*)pkt
)->signature
= RESPONSE_PROCESSED
;
2639 /* Adjust ring index */
2640 if (IS_P3P_TYPE(ha
)) {
2641 struct device_reg_82xx __iomem
*reg
= &ha
->iobase
->isp82
;
2642 WRT_REG_DWORD(®
->rsp_q_out
[0], rsp
->ring_index
);
2644 WRT_REG_DWORD(rsp
->rsp_q_out
, rsp
->ring_index
);
2648 qla2xxx_check_risc_status(scsi_qla_host_t
*vha
)
2652 struct qla_hw_data
*ha
= vha
->hw
;
2653 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2655 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
2660 WRT_REG_DWORD(®
->iobase_addr
, 0x7C00);
2661 RD_REG_DWORD(®
->iobase_addr
);
2662 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
2663 for (cnt
= 10000; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
2664 rval
== QLA_SUCCESS
; cnt
--) {
2666 WRT_REG_DWORD(®
->iobase_window
, 0x0001);
2669 rval
= QLA_FUNCTION_TIMEOUT
;
2671 if (rval
== QLA_SUCCESS
)
2675 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
2676 for (cnt
= 100; (RD_REG_DWORD(®
->iobase_window
) & BIT_0
) == 0 &&
2677 rval
== QLA_SUCCESS
; cnt
--) {
2679 WRT_REG_DWORD(®
->iobase_window
, 0x0003);
2682 rval
= QLA_FUNCTION_TIMEOUT
;
2684 if (rval
!= QLA_SUCCESS
)
2688 if (RD_REG_DWORD(®
->iobase_c8
) & BIT_3
)
2689 ql_log(ql_log_info
, vha
, 0x504c,
2690 "Additional code -- 0x55AA.\n");
2693 WRT_REG_DWORD(®
->iobase_window
, 0x0000);
2694 RD_REG_DWORD(®
->iobase_window
);
2698 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
2700 * @dev_id: SCSI driver HA context
2702 * Called by system whenever the host adapter generates an interrupt.
2704 * Returns handled flag.
2707 qla24xx_intr_handler(int irq
, void *dev_id
)
2709 scsi_qla_host_t
*vha
;
2710 struct qla_hw_data
*ha
;
2711 struct device_reg_24xx __iomem
*reg
;
2717 struct rsp_que
*rsp
;
2718 unsigned long flags
;
2720 rsp
= (struct rsp_que
*) dev_id
;
2722 ql_log(ql_log_info
, NULL
, 0x5059,
2723 "%s: NULL response queue pointer.\n", __func__
);
2728 reg
= &ha
->iobase
->isp24
;
2731 if (unlikely(pci_channel_offline(ha
->pdev
)))
2734 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2735 vha
= pci_get_drvdata(ha
->pdev
);
2736 for (iter
= 50; iter
--; ) {
2737 stat
= RD_REG_DWORD(®
->host_status
);
2738 if (qla2x00_check_reg32_for_disconnect(vha
, stat
))
2740 if (stat
& HSRX_RISC_PAUSED
) {
2741 if (unlikely(pci_channel_offline(ha
->pdev
)))
2744 hccr
= RD_REG_DWORD(®
->hccr
);
2746 ql_log(ql_log_warn
, vha
, 0x504b,
2747 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2750 qla2xxx_check_risc_status(vha
);
2752 ha
->isp_ops
->fw_dump(vha
, 1);
2753 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2755 } else if ((stat
& HSRX_RISC_INT
) == 0)
2758 switch (stat
& 0xff) {
2759 case INTR_ROM_MB_SUCCESS
:
2760 case INTR_ROM_MB_FAILED
:
2761 case INTR_MB_SUCCESS
:
2762 case INTR_MB_FAILED
:
2763 qla24xx_mbx_completion(vha
, MSW(stat
));
2764 status
|= MBX_INTERRUPT
;
2767 case INTR_ASYNC_EVENT
:
2769 mb
[1] = RD_REG_WORD(®
->mailbox1
);
2770 mb
[2] = RD_REG_WORD(®
->mailbox2
);
2771 mb
[3] = RD_REG_WORD(®
->mailbox3
);
2772 qla2x00_async_event(vha
, rsp
, mb
);
2774 case INTR_RSP_QUE_UPDATE
:
2775 case INTR_RSP_QUE_UPDATE_83XX
:
2776 qla24xx_process_response_queue(vha
, rsp
);
2778 case INTR_ATIO_QUE_UPDATE
:{
2779 unsigned long flags2
;
2780 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags2
);
2781 qlt_24xx_process_atio_queue(vha
, 1);
2782 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags2
);
2785 case INTR_ATIO_RSP_QUE_UPDATE
: {
2786 unsigned long flags2
;
2787 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags2
);
2788 qlt_24xx_process_atio_queue(vha
, 1);
2789 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags2
);
2791 qla24xx_process_response_queue(vha
, rsp
);
2795 ql_dbg(ql_dbg_async
, vha
, 0x504f,
2796 "Unrecognized interrupt type (%d).\n", stat
* 0xff);
2799 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2800 RD_REG_DWORD_RELAXED(®
->hccr
);
2801 if (unlikely(IS_QLA83XX(ha
) && (ha
->pdev
->revision
== 1)))
2804 qla2x00_handle_mbx_completion(ha
, status
);
2805 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2811 qla24xx_msix_rsp_q(int irq
, void *dev_id
)
2813 struct qla_hw_data
*ha
;
2814 struct rsp_que
*rsp
;
2815 struct device_reg_24xx __iomem
*reg
;
2816 struct scsi_qla_host
*vha
;
2817 unsigned long flags
;
2820 rsp
= (struct rsp_que
*) dev_id
;
2822 ql_log(ql_log_info
, NULL
, 0x505a,
2823 "%s: NULL response queue pointer.\n", __func__
);
2827 reg
= &ha
->iobase
->isp24
;
2829 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2831 vha
= pci_get_drvdata(ha
->pdev
);
2833 * Use host_status register to check to PCI disconnection before we
2834 * we process the response queue.
2836 stat
= RD_REG_DWORD(®
->host_status
);
2837 if (qla2x00_check_reg32_for_disconnect(vha
, stat
))
2839 qla24xx_process_response_queue(vha
, rsp
);
2840 if (!ha
->flags
.disable_msix_handshake
) {
2841 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2842 RD_REG_DWORD_RELAXED(®
->hccr
);
2845 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2851 qla25xx_msix_rsp_q(int irq
, void *dev_id
)
2853 struct qla_hw_data
*ha
;
2854 scsi_qla_host_t
*vha
;
2855 struct rsp_que
*rsp
;
2856 struct device_reg_24xx __iomem
*reg
;
2857 unsigned long flags
;
2860 rsp
= (struct rsp_que
*) dev_id
;
2862 ql_log(ql_log_info
, NULL
, 0x505b,
2863 "%s: NULL response queue pointer.\n", __func__
);
2867 vha
= pci_get_drvdata(ha
->pdev
);
2869 /* Clear the interrupt, if enabled, for this response queue */
2870 if (!ha
->flags
.disable_msix_handshake
) {
2871 reg
= &ha
->iobase
->isp24
;
2872 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2873 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2874 hccr
= RD_REG_DWORD_RELAXED(®
->hccr
);
2875 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2877 if (qla2x00_check_reg32_for_disconnect(vha
, hccr
))
2879 queue_work_on((int) (rsp
->id
- 1), ha
->wq
, &rsp
->q_work
);
2886 qla24xx_msix_default(int irq
, void *dev_id
)
2888 scsi_qla_host_t
*vha
;
2889 struct qla_hw_data
*ha
;
2890 struct rsp_que
*rsp
;
2891 struct device_reg_24xx __iomem
*reg
;
2896 unsigned long flags
;
2898 rsp
= (struct rsp_que
*) dev_id
;
2900 ql_log(ql_log_info
, NULL
, 0x505c,
2901 "%s: NULL response queue pointer.\n", __func__
);
2905 reg
= &ha
->iobase
->isp24
;
2908 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2909 vha
= pci_get_drvdata(ha
->pdev
);
2911 stat
= RD_REG_DWORD(®
->host_status
);
2912 if (qla2x00_check_reg32_for_disconnect(vha
, stat
))
2914 if (stat
& HSRX_RISC_PAUSED
) {
2915 if (unlikely(pci_channel_offline(ha
->pdev
)))
2918 hccr
= RD_REG_DWORD(®
->hccr
);
2920 ql_log(ql_log_info
, vha
, 0x5050,
2921 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2924 qla2xxx_check_risc_status(vha
);
2926 ha
->isp_ops
->fw_dump(vha
, 1);
2927 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2929 } else if ((stat
& HSRX_RISC_INT
) == 0)
2932 switch (stat
& 0xff) {
2933 case INTR_ROM_MB_SUCCESS
:
2934 case INTR_ROM_MB_FAILED
:
2935 case INTR_MB_SUCCESS
:
2936 case INTR_MB_FAILED
:
2937 qla24xx_mbx_completion(vha
, MSW(stat
));
2938 status
|= MBX_INTERRUPT
;
2941 case INTR_ASYNC_EVENT
:
2943 mb
[1] = RD_REG_WORD(®
->mailbox1
);
2944 mb
[2] = RD_REG_WORD(®
->mailbox2
);
2945 mb
[3] = RD_REG_WORD(®
->mailbox3
);
2946 qla2x00_async_event(vha
, rsp
, mb
);
2948 case INTR_RSP_QUE_UPDATE
:
2949 case INTR_RSP_QUE_UPDATE_83XX
:
2950 qla24xx_process_response_queue(vha
, rsp
);
2952 case INTR_ATIO_QUE_UPDATE
:{
2953 unsigned long flags2
;
2954 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags2
);
2955 qlt_24xx_process_atio_queue(vha
, 1);
2956 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags2
);
2959 case INTR_ATIO_RSP_QUE_UPDATE
: {
2960 unsigned long flags2
;
2961 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags2
);
2962 qlt_24xx_process_atio_queue(vha
, 1);
2963 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags2
);
2965 qla24xx_process_response_queue(vha
, rsp
);
2969 ql_dbg(ql_dbg_async
, vha
, 0x5051,
2970 "Unrecognized interrupt type (%d).\n", stat
& 0xff);
2973 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_INT
);
2975 qla2x00_handle_mbx_completion(ha
, status
);
2976 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2981 /* Interrupt handling helpers. */
2983 struct qla_init_msix_entry
{
2985 irq_handler_t handler
;
2988 static struct qla_init_msix_entry msix_entries
[3] = {
2989 { "qla2xxx (default)", qla24xx_msix_default
},
2990 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q
},
2991 { "qla2xxx (multiq)", qla25xx_msix_rsp_q
},
2994 static struct qla_init_msix_entry qla82xx_msix_entries
[2] = {
2995 { "qla2xxx (default)", qla82xx_msix_default
},
2996 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q
},
2999 static struct qla_init_msix_entry qla83xx_msix_entries
[3] = {
3000 { "qla2xxx (default)", qla24xx_msix_default
},
3001 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q
},
3002 { "qla2xxx (atio_q)", qla83xx_msix_atio_q
},
3006 qla24xx_disable_msix(struct qla_hw_data
*ha
)
3009 struct qla_msix_entry
*qentry
;
3010 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
3012 for (i
= 0; i
< ha
->msix_count
; i
++) {
3013 qentry
= &ha
->msix_entries
[i
];
3014 if (qentry
->have_irq
) {
3015 /* un-register irq cpu affinity notification */
3016 irq_set_affinity_notifier(qentry
->vector
, NULL
);
3017 free_irq(qentry
->vector
, qentry
->rsp
);
3020 pci_disable_msix(ha
->pdev
);
3021 kfree(ha
->msix_entries
);
3022 ha
->msix_entries
= NULL
;
3023 ha
->flags
.msix_enabled
= 0;
3024 ql_dbg(ql_dbg_init
, vha
, 0x0042,
3025 "Disabled the MSI.\n");
3029 qla24xx_enable_msix(struct qla_hw_data
*ha
, struct rsp_que
*rsp
)
3031 #define MIN_MSIX_COUNT 2
3032 #define ATIO_VECTOR 2
3034 struct msix_entry
*entries
;
3035 struct qla_msix_entry
*qentry
;
3036 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
3038 entries
= kzalloc(sizeof(struct msix_entry
) * ha
->msix_count
,
3041 ql_log(ql_log_warn
, vha
, 0x00bc,
3042 "Failed to allocate memory for msix_entry.\n");
3046 for (i
= 0; i
< ha
->msix_count
; i
++)
3047 entries
[i
].entry
= i
;
3049 ret
= pci_enable_msix_range(ha
->pdev
,
3050 entries
, MIN_MSIX_COUNT
, ha
->msix_count
);
3052 ql_log(ql_log_fatal
, vha
, 0x00c7,
3053 "MSI-X: Failed to enable support, "
3054 "giving up -- %d/%d.\n",
3055 ha
->msix_count
, ret
);
3057 } else if (ret
< ha
->msix_count
) {
3058 ql_log(ql_log_warn
, vha
, 0x00c6,
3059 "MSI-X: Failed to enable support "
3060 "-- %d/%d\n Retry with %d vectors.\n",
3061 ha
->msix_count
, ret
, ret
);
3062 ha
->msix_count
= ret
;
3063 ha
->max_rsp_queues
= ha
->msix_count
- 1;
3065 ha
->msix_entries
= kzalloc(sizeof(struct qla_msix_entry
) *
3066 ha
->msix_count
, GFP_KERNEL
);
3067 if (!ha
->msix_entries
) {
3068 ql_log(ql_log_fatal
, vha
, 0x00c8,
3069 "Failed to allocate memory for ha->msix_entries.\n");
3073 ha
->flags
.msix_enabled
= 1;
3075 for (i
= 0; i
< ha
->msix_count
; i
++) {
3076 qentry
= &ha
->msix_entries
[i
];
3077 qentry
->vector
= entries
[i
].vector
;
3078 qentry
->entry
= entries
[i
].entry
;
3079 qentry
->have_irq
= 0;
3081 qentry
->irq_notify
.notify
= qla_irq_affinity_notify
;
3082 qentry
->irq_notify
.release
= qla_irq_affinity_release
;
3086 /* Enable MSI-X vectors for the base queue */
3087 for (i
= 0; i
< 2; i
++) {
3088 qentry
= &ha
->msix_entries
[i
];
3089 if (IS_P3P_TYPE(ha
))
3090 ret
= request_irq(qentry
->vector
,
3091 qla82xx_msix_entries
[i
].handler
,
3092 0, qla82xx_msix_entries
[i
].name
, rsp
);
3094 ret
= request_irq(qentry
->vector
,
3095 msix_entries
[i
].handler
,
3096 0, msix_entries
[i
].name
, rsp
);
3098 goto msix_register_fail
;
3099 qentry
->have_irq
= 1;
3103 /* Register for CPU affinity notification. */
3104 irq_set_affinity_notifier(qentry
->vector
, &qentry
->irq_notify
);
3106 /* Schedule work (ie. trigger a notification) to read cpu
3107 * mask for this specific irq.
3108 * kref_get is required because
3109 * irq_affinity_notify() will do
3112 kref_get(&qentry
->irq_notify
.kref
);
3113 schedule_work(&qentry
->irq_notify
.work
);
3117 * If target mode is enable, also request the vector for the ATIO
3120 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha
)) {
3121 qentry
= &ha
->msix_entries
[ATIO_VECTOR
];
3122 ret
= request_irq(qentry
->vector
,
3123 qla83xx_msix_entries
[ATIO_VECTOR
].handler
,
3124 0, qla83xx_msix_entries
[ATIO_VECTOR
].name
, rsp
);
3125 qentry
->have_irq
= 1;
3132 ql_log(ql_log_fatal
, vha
, 0x00cb,
3133 "MSI-X: unable to register handler -- %x/%d.\n",
3134 qentry
->vector
, ret
);
3135 qla24xx_disable_msix(ha
);
3140 /* Enable MSI-X vector for response queue update for queue 0 */
3141 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3142 if (ha
->msixbase
&& ha
->mqiobase
&&
3143 (ha
->max_rsp_queues
> 1 || ha
->max_req_queues
> 1))
3147 && (ha
->max_rsp_queues
> 1 || ha
->max_req_queues
> 1))
3149 ql_dbg(ql_dbg_multiq
, vha
, 0xc005,
3150 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3151 ha
->mqiobase
, ha
->max_rsp_queues
, ha
->max_req_queues
);
3152 ql_dbg(ql_dbg_init
, vha
, 0x0055,
3153 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3154 ha
->mqiobase
, ha
->max_rsp_queues
, ha
->max_req_queues
);
3162 qla2x00_request_irqs(struct qla_hw_data
*ha
, struct rsp_que
*rsp
)
3164 int ret
= QLA_FUNCTION_FAILED
;
3165 device_reg_t
*reg
= ha
->iobase
;
3166 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
3168 /* If possible, enable MSI-X. */
3169 if (!IS_QLA2432(ha
) && !IS_QLA2532(ha
) && !IS_QLA8432(ha
) &&
3170 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
) && !IS_QLAFX00(ha
) &&
3174 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_HP
&&
3175 (ha
->pdev
->subsystem_device
== 0x7040 ||
3176 ha
->pdev
->subsystem_device
== 0x7041 ||
3177 ha
->pdev
->subsystem_device
== 0x1705)) {
3178 ql_log(ql_log_warn
, vha
, 0x0034,
3179 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
3180 ha
->pdev
->subsystem_vendor
,
3181 ha
->pdev
->subsystem_device
);
3185 if (IS_QLA2432(ha
) && (ha
->pdev
->revision
< QLA_MSIX_CHIP_REV_24XX
)) {
3186 ql_log(ql_log_warn
, vha
, 0x0035,
3187 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
3188 ha
->pdev
->revision
, QLA_MSIX_CHIP_REV_24XX
);
3192 ret
= qla24xx_enable_msix(ha
, rsp
);
3194 ql_dbg(ql_dbg_init
, vha
, 0x0036,
3195 "MSI-X: Enabled (0x%X, 0x%X).\n",
3196 ha
->chip_revision
, ha
->fw_attributes
);
3197 goto clear_risc_ints
;
3202 ql_log(ql_log_info
, vha
, 0x0037,
3203 "Falling back-to MSI mode -%d.\n", ret
);
3205 if (!IS_QLA24XX(ha
) && !IS_QLA2532(ha
) && !IS_QLA8432(ha
) &&
3206 !IS_QLA8001(ha
) && !IS_P3P_TYPE(ha
) && !IS_QLAFX00(ha
) &&
3210 ret
= pci_enable_msi(ha
->pdev
);
3212 ql_dbg(ql_dbg_init
, vha
, 0x0038,
3214 ha
->flags
.msi_enabled
= 1;
3216 ql_log(ql_log_warn
, vha
, 0x0039,
3217 "Falling back-to INTa mode -- %d.\n", ret
);
3220 /* Skip INTx on ISP82xx. */
3221 if (!ha
->flags
.msi_enabled
&& IS_QLA82XX(ha
))
3222 return QLA_FUNCTION_FAILED
;
3224 ret
= request_irq(ha
->pdev
->irq
, ha
->isp_ops
->intr_handler
,
3225 ha
->flags
.msi_enabled
? 0 : IRQF_SHARED
,
3226 QLA2XXX_DRIVER_NAME
, rsp
);
3228 ql_log(ql_log_warn
, vha
, 0x003a,
3229 "Failed to reserve interrupt %d already in use.\n",
3232 } else if (!ha
->flags
.msi_enabled
) {
3233 ql_dbg(ql_dbg_init
, vha
, 0x0125,
3234 "INTa mode: Enabled.\n");
3235 ha
->flags
.mr_intr_valid
= 1;
3239 if (IS_FWI2_CAPABLE(ha
) || IS_QLAFX00(ha
))
3242 spin_lock_irq(&ha
->hardware_lock
);
3243 WRT_REG_WORD(®
->isp
.semaphore
, 0);
3244 spin_unlock_irq(&ha
->hardware_lock
);
3251 qla2x00_free_irqs(scsi_qla_host_t
*vha
)
3253 struct qla_hw_data
*ha
= vha
->hw
;
3254 struct rsp_que
*rsp
;
3257 * We need to check that ha->rsp_q_map is valid in case we are called
3258 * from a probe failure context.
3260 if (!ha
->rsp_q_map
|| !ha
->rsp_q_map
[0])
3262 rsp
= ha
->rsp_q_map
[0];
3264 if (ha
->flags
.msix_enabled
)
3265 qla24xx_disable_msix(ha
);
3266 else if (ha
->flags
.msi_enabled
) {
3267 free_irq(ha
->pdev
->irq
, rsp
);
3268 pci_disable_msi(ha
->pdev
);
3270 free_irq(ha
->pdev
->irq
, rsp
);
3274 int qla25xx_request_irq(struct rsp_que
*rsp
)
3276 struct qla_hw_data
*ha
= rsp
->hw
;
3277 struct qla_init_msix_entry
*intr
= &msix_entries
[2];
3278 struct qla_msix_entry
*msix
= rsp
->msix
;
3279 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
3282 ret
= request_irq(msix
->vector
, intr
->handler
, 0, intr
->name
, rsp
);
3284 ql_log(ql_log_fatal
, vha
, 0x00e6,
3285 "MSI-X: Unable to register handler -- %x/%d.\n",
3295 /* irq_set_affinity/irqbalance will trigger notification of cpu mask update */
3296 static void qla_irq_affinity_notify(struct irq_affinity_notify
*notify
,
3297 const cpumask_t
*mask
)
3299 struct qla_msix_entry
*e
=
3300 container_of(notify
, struct qla_msix_entry
, irq_notify
);
3301 struct qla_hw_data
*ha
;
3302 struct scsi_qla_host
*base_vha
;
3304 /* user is recommended to set mask to just 1 cpu */
3305 e
->cpuid
= cpumask_first(mask
);
3308 base_vha
= pci_get_drvdata(ha
->pdev
);
3310 ql_dbg(ql_dbg_init
, base_vha
, 0xffff,
3311 "%s: host %ld : vector %d cpu %d \n", __func__
,
3312 base_vha
->host_no
, e
->vector
, e
->cpuid
);
3315 if ((IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) &&
3316 (e
->entry
== QLA83XX_RSPQ_MSIX_ENTRY_NUMBER
)) {
3317 ha
->tgt
.rspq_vector_cpuid
= e
->cpuid
;
3318 ql_dbg(ql_dbg_init
, base_vha
, 0xffff,
3319 "%s: host%ld: rspq vector %d cpu %d runtime change\n",
3320 __func__
, base_vha
->host_no
, e
->vector
, e
->cpuid
);
3325 static void qla_irq_affinity_release(struct kref
*ref
)
3327 struct irq_affinity_notify
*notify
=
3328 container_of(ref
, struct irq_affinity_notify
, kref
);
3329 struct qla_msix_entry
*e
=
3330 container_of(notify
, struct qla_msix_entry
, irq_notify
);
3331 struct scsi_qla_host
*base_vha
= pci_get_drvdata(e
->rsp
->hw
->pdev
);
3333 ql_dbg(ql_dbg_init
, base_vha
, 0xffff,
3334 "%s: host%ld: vector %d cpu %d \n", __func__
,
3335 base_vha
->host_no
, e
->vector
, e
->cpuid
);