2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
20 #include <target/target_core_base.h>
21 #include "qla_target.h"
24 * QLogic ISP2x00 Hardware Support Function Prototypes.
26 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
27 static int qla2x00_setup_chip(scsi_qla_host_t
*);
28 static int qla2x00_init_rings(scsi_qla_host_t
*);
29 static int qla2x00_fw_ready(scsi_qla_host_t
*);
30 static int qla2x00_configure_hba(scsi_qla_host_t
*);
31 static int qla2x00_configure_loop(scsi_qla_host_t
*);
32 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
33 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
34 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
35 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
38 static int qla2x00_restart_isp(scsi_qla_host_t
*);
40 static struct qla_chip_state_84xx
*qla84xx_get_chip(struct scsi_qla_host
*);
41 static int qla84xx_init_chip(scsi_qla_host_t
*);
42 static int qla25xx_init_queues(struct qla_hw_data
*);
44 /* SRB Extensions ---------------------------------------------------------- */
47 qla2x00_sp_timeout(unsigned long __data
)
49 srb_t
*sp
= (srb_t
*)__data
;
50 struct srb_iocb
*iocb
;
51 fc_port_t
*fcport
= sp
->fcport
;
52 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
56 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
57 req
= ha
->req_q_map
[0];
58 req
->outstanding_cmds
[sp
->handle
] = NULL
;
59 iocb
= &sp
->u
.iocb_cmd
;
61 sp
->free(fcport
->vha
, sp
);
62 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
66 qla2x00_sp_free(void *data
, void *ptr
)
68 srb_t
*sp
= (srb_t
*)ptr
;
69 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
70 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
72 del_timer(&iocb
->timer
);
73 mempool_free(sp
, vha
->hw
->srb_mempool
);
75 QLA_VHA_MARK_NOT_BUSY(vha
);
78 /* Asynchronous Login/Logout Routines -------------------------------------- */
81 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
84 struct qla_hw_data
*ha
= vha
->hw
;
86 /* Firmware should use switch negotiated r_a_tov for timeout. */
87 tmo
= ha
->r_a_tov
/ 10 * 2;
88 if (!IS_FWI2_CAPABLE(ha
)) {
90 * Except for earlier ISPs where the timeout is seeded from the
91 * initialization control block.
93 tmo
= ha
->login_timeout
;
99 qla2x00_async_iocb_timeout(void *data
)
101 srb_t
*sp
= (srb_t
*)data
;
102 fc_port_t
*fcport
= sp
->fcport
;
104 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2071,
105 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
106 sp
->name
, sp
->handle
, fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
107 fcport
->d_id
.b
.al_pa
);
109 fcport
->flags
&= ~FCF_ASYNC_SENT
;
110 if (sp
->type
== SRB_LOGIN_CMD
) {
111 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
112 qla2x00_post_async_logout_work(fcport
->vha
, fcport
, NULL
);
113 /* Retry as needed. */
114 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
115 lio
->u
.logio
.data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
116 QLA_LOGIO_LOGIN_RETRIED
: 0;
117 qla2x00_post_async_login_done_work(fcport
->vha
, fcport
,
123 qla2x00_async_login_sp_done(void *data
, void *ptr
, int res
)
125 srb_t
*sp
= (srb_t
*)ptr
;
126 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
127 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
129 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
130 qla2x00_post_async_login_done_work(sp
->fcport
->vha
, sp
->fcport
,
132 sp
->free(sp
->fcport
->vha
, sp
);
136 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
140 struct srb_iocb
*lio
;
143 rval
= QLA_FUNCTION_FAILED
;
144 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
148 sp
->type
= SRB_LOGIN_CMD
;
150 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
152 lio
= &sp
->u
.iocb_cmd
;
153 lio
->timeout
= qla2x00_async_iocb_timeout
;
154 sp
->done
= qla2x00_async_login_sp_done
;
155 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
156 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
157 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
158 rval
= qla2x00_start_sp(sp
);
159 if (rval
!= QLA_SUCCESS
)
162 ql_dbg(ql_dbg_disc
, vha
, 0x2072,
163 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
164 "retries=%d.\n", sp
->handle
, fcport
->loop_id
,
165 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
166 fcport
->login_retry
);
170 sp
->free(fcport
->vha
, sp
);
176 qla2x00_async_logout_sp_done(void *data
, void *ptr
, int res
)
178 srb_t
*sp
= (srb_t
*)ptr
;
179 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
180 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
182 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
183 qla2x00_post_async_logout_done_work(sp
->fcport
->vha
, sp
->fcport
,
185 sp
->free(sp
->fcport
->vha
, sp
);
189 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
192 struct srb_iocb
*lio
;
195 rval
= QLA_FUNCTION_FAILED
;
196 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
200 sp
->type
= SRB_LOGOUT_CMD
;
202 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
204 lio
= &sp
->u
.iocb_cmd
;
205 lio
->timeout
= qla2x00_async_iocb_timeout
;
206 sp
->done
= qla2x00_async_logout_sp_done
;
207 rval
= qla2x00_start_sp(sp
);
208 if (rval
!= QLA_SUCCESS
)
211 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
212 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
213 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
214 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
218 sp
->free(fcport
->vha
, sp
);
224 qla2x00_async_adisc_sp_done(void *data
, void *ptr
, int res
)
226 srb_t
*sp
= (srb_t
*)ptr
;
227 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
228 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
230 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
231 qla2x00_post_async_adisc_done_work(sp
->fcport
->vha
, sp
->fcport
,
233 sp
->free(sp
->fcport
->vha
, sp
);
237 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
241 struct srb_iocb
*lio
;
244 rval
= QLA_FUNCTION_FAILED
;
245 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
249 sp
->type
= SRB_ADISC_CMD
;
251 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
253 lio
= &sp
->u
.iocb_cmd
;
254 lio
->timeout
= qla2x00_async_iocb_timeout
;
255 sp
->done
= qla2x00_async_adisc_sp_done
;
256 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
257 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
258 rval
= qla2x00_start_sp(sp
);
259 if (rval
!= QLA_SUCCESS
)
262 ql_dbg(ql_dbg_disc
, vha
, 0x206f,
263 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
264 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
265 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
269 sp
->free(fcport
->vha
, sp
);
275 qla2x00_async_tm_cmd_done(void *data
, void *ptr
, int res
)
277 srb_t
*sp
= (srb_t
*)ptr
;
278 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
279 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
284 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
285 flags
= iocb
->u
.tmf
.flags
;
286 lun
= (uint16_t)iocb
->u
.tmf
.lun
;
288 /* Issue Marker IOCB */
289 rval
= qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
290 vha
->hw
->rsp_q_map
[0], sp
->fcport
->loop_id
, lun
,
291 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
293 if ((rval
!= QLA_SUCCESS
) || iocb
->u
.tmf
.data
) {
294 ql_dbg(ql_dbg_taskm
, vha
, 0x8030,
295 "TM IOCB failed (%x).\n", rval
);
298 sp
->free(sp
->fcport
->vha
, sp
);
302 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t tm_flags
, uint32_t lun
,
305 struct scsi_qla_host
*vha
= fcport
->vha
;
307 struct srb_iocb
*tcf
;
310 rval
= QLA_FUNCTION_FAILED
;
311 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
315 sp
->type
= SRB_TM_CMD
;
317 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
319 tcf
= &sp
->u
.iocb_cmd
;
320 tcf
->u
.tmf
.flags
= tm_flags
;
321 tcf
->u
.tmf
.lun
= lun
;
322 tcf
->u
.tmf
.data
= tag
;
323 tcf
->timeout
= qla2x00_async_iocb_timeout
;
324 sp
->done
= qla2x00_async_tm_cmd_done
;
326 rval
= qla2x00_start_sp(sp
);
327 if (rval
!= QLA_SUCCESS
)
330 ql_dbg(ql_dbg_taskm
, vha
, 0x802f,
331 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
332 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
333 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
337 sp
->free(fcport
->vha
, sp
);
343 qla2x00_async_login_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
349 case MBS_COMMAND_COMPLETE
:
351 * Driver must validate login state - If PRLI not complete,
352 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
355 rval
= qla2x00_get_port_database(vha
, fcport
, 0);
356 if (rval
== QLA_NOT_LOGGED_IN
) {
357 fcport
->flags
&= ~FCF_ASYNC_SENT
;
358 fcport
->flags
|= FCF_LOGIN_NEEDED
;
359 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
363 if (rval
!= QLA_SUCCESS
) {
364 qla2x00_post_async_logout_work(vha
, fcport
, NULL
);
365 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
368 if (fcport
->flags
& FCF_FCP2_DEVICE
) {
369 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
372 qla2x00_update_fcport(vha
, fcport
);
374 case MBS_COMMAND_ERROR
:
375 fcport
->flags
&= ~FCF_ASYNC_SENT
;
376 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
377 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
379 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
381 case MBS_PORT_ID_USED
:
382 fcport
->loop_id
= data
[1];
383 qla2x00_post_async_logout_work(vha
, fcport
, NULL
);
384 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
386 case MBS_LOOP_ID_USED
:
388 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
389 if (rval
!= QLA_SUCCESS
) {
390 fcport
->flags
&= ~FCF_ASYNC_SENT
;
391 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
394 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
401 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
404 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
409 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
412 if (data
[0] == MBS_COMMAND_COMPLETE
) {
413 qla2x00_update_fcport(vha
, fcport
);
419 fcport
->flags
&= ~FCF_ASYNC_SENT
;
420 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
421 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
423 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
428 /****************************************************************************/
429 /* QLogic ISP2x00 Hardware Support Functions. */
430 /****************************************************************************/
433 qla83xx_nic_core_fw_load(scsi_qla_host_t
*vha
)
435 int rval
= QLA_SUCCESS
;
436 struct qla_hw_data
*ha
= vha
->hw
;
437 uint32_t idc_major_ver
, idc_minor_ver
;
439 qla83xx_idc_lock(vha
, 0);
441 /* SV: TODO: Assign initialization timeout from
442 * flash-info / other param
444 ha
->fcoe_dev_init_timeout
= QLA83XX_IDC_INITIALIZATION_TIMEOUT
;
445 ha
->fcoe_reset_timeout
= QLA83XX_IDC_RESET_ACK_TIMEOUT
;
447 /* Set our fcoe function presence */
448 if (__qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
) {
449 ql_dbg(ql_dbg_p3p
, vha
, 0xb077,
450 "Error while setting DRV-Presence.\n");
451 rval
= QLA_FUNCTION_FAILED
;
455 /* Decide the reset ownership */
456 qla83xx_reset_ownership(vha
);
459 * On first protocol driver load:
460 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
462 * Others: Check compatibility with current IDC Major version.
464 qla83xx_rd_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, &idc_major_ver
);
465 if (ha
->flags
.nic_core_reset_owner
) {
466 /* Set IDC Major version */
467 idc_major_ver
= QLA83XX_SUPP_IDC_MAJOR_VERSION
;
468 qla83xx_wr_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, idc_major_ver
);
470 /* Clearing IDC-Lock-Recovery register */
471 qla83xx_wr_reg(vha
, QLA83XX_IDC_LOCK_RECOVERY
, 0);
472 } else if (idc_major_ver
!= QLA83XX_SUPP_IDC_MAJOR_VERSION
) {
474 * Clear further IDC participation if we are not compatible with
475 * the current IDC Major Version.
477 ql_log(ql_log_warn
, vha
, 0xb07d,
478 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
479 idc_major_ver
, QLA83XX_SUPP_IDC_MAJOR_VERSION
);
480 __qla83xx_clear_drv_presence(vha
);
481 rval
= QLA_FUNCTION_FAILED
;
484 /* Each function sets its supported Minor version. */
485 qla83xx_rd_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, &idc_minor_ver
);
486 idc_minor_ver
|= (QLA83XX_SUPP_IDC_MINOR_VERSION
<< (ha
->portnum
* 2));
487 qla83xx_wr_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, idc_minor_ver
);
489 rval
= qla83xx_idc_state_handler(vha
);
492 qla83xx_idc_unlock(vha
, 0);
498 * qla2x00_initialize_adapter
502 * ha = adapter block pointer.
508 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
511 struct qla_hw_data
*ha
= vha
->hw
;
512 struct req_que
*req
= ha
->req_q_map
[0];
514 /* Clear adapter flags. */
515 vha
->flags
.online
= 0;
516 ha
->flags
.chip_reset_done
= 0;
517 vha
->flags
.reset_active
= 0;
518 ha
->flags
.pci_channel_io_perm_failure
= 0;
519 ha
->flags
.eeh_busy
= 0;
520 ha
->flags
.thermal_supported
= 1;
521 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
522 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
523 vha
->device_flags
= DFLG_NO_CABLE
;
525 vha
->flags
.management_server_logged_in
= 0;
526 vha
->marker_needed
= 0;
527 ha
->isp_abort_cnt
= 0;
528 ha
->beacon_blink_led
= 0;
530 set_bit(0, ha
->req_qid_map
);
531 set_bit(0, ha
->rsp_qid_map
);
533 ql_dbg(ql_dbg_init
, vha
, 0x0040,
534 "Configuring PCI space...\n");
535 rval
= ha
->isp_ops
->pci_config(vha
);
537 ql_log(ql_log_warn
, vha
, 0x0044,
538 "Unable to configure PCI space.\n");
542 ha
->isp_ops
->reset_chip(vha
);
544 rval
= qla2xxx_get_flash_info(vha
);
546 ql_log(ql_log_fatal
, vha
, 0x004f,
547 "Unable to validate FLASH data.\n");
551 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
552 ql_dbg(ql_dbg_init
, vha
, 0x0061,
553 "Configure NVRAM parameters...\n");
555 ha
->isp_ops
->nvram_config(vha
);
557 if (ha
->flags
.disable_serdes
) {
558 /* Mask HBA via NVRAM settings? */
559 ql_log(ql_log_info
, vha
, 0x0077,
561 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
562 vha
->port_name
[0], vha
->port_name
[1],
563 vha
->port_name
[2], vha
->port_name
[3],
564 vha
->port_name
[4], vha
->port_name
[5],
565 vha
->port_name
[6], vha
->port_name
[7]);
566 return QLA_FUNCTION_FAILED
;
569 ql_dbg(ql_dbg_init
, vha
, 0x0078,
570 "Verifying loaded RISC code...\n");
572 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
573 rval
= ha
->isp_ops
->chip_diag(vha
);
576 rval
= qla2x00_setup_chip(vha
);
581 if (IS_QLA84XX(ha
)) {
582 ha
->cs84xx
= qla84xx_get_chip(vha
);
584 ql_log(ql_log_warn
, vha
, 0x00d0,
585 "Unable to configure ISP84XX.\n");
586 return QLA_FUNCTION_FAILED
;
590 if (qla_ini_mode_enabled(vha
))
591 rval
= qla2x00_init_rings(vha
);
593 ha
->flags
.chip_reset_done
= 1;
595 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
596 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
597 rval
= qla84xx_init_chip(vha
);
598 if (rval
!= QLA_SUCCESS
) {
599 ql_log(ql_log_warn
, vha
, 0x00d4,
600 "Unable to initialize ISP84XX.\n");
601 qla84xx_put_chip(vha
);
605 /* Load the NIC Core f/w if we are the first protocol driver. */
606 if (IS_QLA8031(ha
)) {
607 rval
= qla83xx_nic_core_fw_load(vha
);
609 ql_log(ql_log_warn
, vha
, 0x0124,
610 "Error in initializing NIC Core f/w.\n");
613 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
614 qla24xx_read_fcp_prio_cfg(vha
);
620 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
623 * Returns 0 on success.
626 qla2100_pci_config(scsi_qla_host_t
*vha
)
630 struct qla_hw_data
*ha
= vha
->hw
;
631 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
633 pci_set_master(ha
->pdev
);
634 pci_try_set_mwi(ha
->pdev
);
636 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
637 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
638 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
640 pci_disable_rom(ha
->pdev
);
642 /* Get PCI bus information. */
643 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
644 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
645 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
651 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
654 * Returns 0 on success.
657 qla2300_pci_config(scsi_qla_host_t
*vha
)
660 unsigned long flags
= 0;
662 struct qla_hw_data
*ha
= vha
->hw
;
663 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
665 pci_set_master(ha
->pdev
);
666 pci_try_set_mwi(ha
->pdev
);
668 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
669 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
671 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
672 w
&= ~PCI_COMMAND_INTX_DISABLE
;
673 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
676 * If this is a 2300 card and not 2312, reset the
677 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
678 * the 2310 also reports itself as a 2300 so we need to get the
679 * fb revision level -- a 6 indicates it really is a 2300 and
682 if (IS_QLA2300(ha
)) {
683 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
686 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
687 for (cnt
= 0; cnt
< 30000; cnt
++) {
688 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
694 /* Select FPM registers. */
695 WRT_REG_WORD(®
->ctrl_status
, 0x20);
696 RD_REG_WORD(®
->ctrl_status
);
698 /* Get the fb rev level */
699 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
701 if (ha
->fb_rev
== FPM_2300
)
702 pci_clear_mwi(ha
->pdev
);
704 /* Deselect FPM registers. */
705 WRT_REG_WORD(®
->ctrl_status
, 0x0);
706 RD_REG_WORD(®
->ctrl_status
);
708 /* Release RISC module. */
709 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
710 for (cnt
= 0; cnt
< 30000; cnt
++) {
711 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
717 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
720 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
722 pci_disable_rom(ha
->pdev
);
724 /* Get PCI bus information. */
725 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
726 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
727 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
733 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
736 * Returns 0 on success.
739 qla24xx_pci_config(scsi_qla_host_t
*vha
)
742 unsigned long flags
= 0;
743 struct qla_hw_data
*ha
= vha
->hw
;
744 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
746 pci_set_master(ha
->pdev
);
747 pci_try_set_mwi(ha
->pdev
);
749 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
750 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
751 w
&= ~PCI_COMMAND_INTX_DISABLE
;
752 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
754 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
756 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
757 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
758 pcix_set_mmrbc(ha
->pdev
, 2048);
760 /* PCIe -- adjust Maximum Read Request Size (2048). */
761 if (pci_is_pcie(ha
->pdev
))
762 pcie_set_readrq(ha
->pdev
, 2048);
764 pci_disable_rom(ha
->pdev
);
766 ha
->chip_revision
= ha
->pdev
->revision
;
768 /* Get PCI bus information. */
769 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
770 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
771 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
777 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
780 * Returns 0 on success.
783 qla25xx_pci_config(scsi_qla_host_t
*vha
)
786 struct qla_hw_data
*ha
= vha
->hw
;
788 pci_set_master(ha
->pdev
);
789 pci_try_set_mwi(ha
->pdev
);
791 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
792 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
793 w
&= ~PCI_COMMAND_INTX_DISABLE
;
794 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
796 /* PCIe -- adjust Maximum Read Request Size (2048). */
797 if (pci_is_pcie(ha
->pdev
))
798 pcie_set_readrq(ha
->pdev
, 2048);
800 pci_disable_rom(ha
->pdev
);
802 ha
->chip_revision
= ha
->pdev
->revision
;
808 * qla2x00_isp_firmware() - Choose firmware image.
811 * Returns 0 on success.
814 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
817 uint16_t loop_id
, topo
, sw_cap
;
818 uint8_t domain
, area
, al_pa
;
819 struct qla_hw_data
*ha
= vha
->hw
;
821 /* Assume loading risc code */
822 rval
= QLA_FUNCTION_FAILED
;
824 if (ha
->flags
.disable_risc_code_load
) {
825 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
827 /* Verify checksum of loaded RISC code. */
828 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
829 if (rval
== QLA_SUCCESS
) {
830 /* And, verify we are not in ROM code. */
831 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
832 &area
, &domain
, &topo
, &sw_cap
);
837 ql_dbg(ql_dbg_init
, vha
, 0x007a,
838 "**** Load RISC code ****.\n");
844 * qla2x00_reset_chip() - Reset ISP chip.
847 * Returns 0 on success.
850 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
852 unsigned long flags
= 0;
853 struct qla_hw_data
*ha
= vha
->hw
;
854 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
858 if (unlikely(pci_channel_offline(ha
->pdev
)))
861 ha
->isp_ops
->disable_intrs(ha
);
863 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
865 /* Turn off master enable */
867 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
868 cmd
&= ~PCI_COMMAND_MASTER
;
869 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
871 if (!IS_QLA2100(ha
)) {
873 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
874 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
875 for (cnt
= 0; cnt
< 30000; cnt
++) {
876 if ((RD_REG_WORD(®
->hccr
) &
877 HCCR_RISC_PAUSE
) != 0)
882 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
886 /* Select FPM registers. */
887 WRT_REG_WORD(®
->ctrl_status
, 0x20);
888 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
890 /* FPM Soft Reset. */
891 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
892 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
894 /* Toggle Fpm Reset. */
895 if (!IS_QLA2200(ha
)) {
896 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
897 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
900 /* Select frame buffer registers. */
901 WRT_REG_WORD(®
->ctrl_status
, 0x10);
902 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
904 /* Reset frame buffer FIFOs. */
905 if (IS_QLA2200(ha
)) {
906 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
907 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
909 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
911 /* Read back fb_cmd until zero or 3 seconds max */
912 for (cnt
= 0; cnt
< 3000; cnt
++) {
913 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
919 /* Select RISC module registers. */
920 WRT_REG_WORD(®
->ctrl_status
, 0);
921 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
923 /* Reset RISC processor. */
924 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
925 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
927 /* Release RISC processor. */
928 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
929 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
932 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
933 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
935 /* Reset ISP chip. */
936 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
938 /* Wait for RISC to recover from reset. */
939 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
941 * It is necessary to for a delay here since the card doesn't
942 * respond to PCI reads during a reset. On some architectures
943 * this will result in an MCA.
946 for (cnt
= 30000; cnt
; cnt
--) {
947 if ((RD_REG_WORD(®
->ctrl_status
) &
948 CSR_ISP_SOFT_RESET
) == 0)
955 /* Reset RISC processor. */
956 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
958 WRT_REG_WORD(®
->semaphore
, 0);
960 /* Release RISC processor. */
961 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
962 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
964 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
965 for (cnt
= 0; cnt
< 30000; cnt
++) {
966 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
974 /* Turn on master enable */
975 cmd
|= PCI_COMMAND_MASTER
;
976 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
978 /* Disable RISC pause on FPM parity error. */
979 if (!IS_QLA2100(ha
)) {
980 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
981 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
984 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
988 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
990 * Returns 0 on success.
993 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
995 uint16_t mb
[4] = {0x1010, 0, 1, 0};
997 if (!IS_QLA81XX(vha
->hw
))
1000 return qla81xx_write_mpi_register(vha
, mb
);
1004 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
1007 * Returns 0 on success.
1010 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
1012 unsigned long flags
= 0;
1013 struct qla_hw_data
*ha
= vha
->hw
;
1014 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1017 static int abts_cnt
; /* ISP abort retry counts */
1019 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1022 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
1023 for (cnt
= 0; cnt
< 30000; cnt
++) {
1024 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
1030 WRT_REG_DWORD(®
->ctrl_status
,
1031 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
1032 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
1035 /* Wait for firmware to complete NVRAM accesses. */
1036 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1037 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
1039 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1043 /* Wait for soft-reset to complete. */
1044 d2
= RD_REG_DWORD(®
->ctrl_status
);
1045 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
1047 d2
= RD_REG_DWORD(®
->ctrl_status
);
1051 /* If required, do an MPI FW reset now */
1052 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
1053 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
1054 if (++abts_cnt
< 5) {
1055 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1056 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
1059 * We exhausted the ISP abort retries. We have to
1060 * set the board offline.
1063 vha
->flags
.online
= 0;
1068 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
1069 RD_REG_DWORD(®
->hccr
);
1071 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
1072 RD_REG_DWORD(®
->hccr
);
1074 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
1075 RD_REG_DWORD(®
->hccr
);
1077 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1078 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
1080 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1084 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1086 if (IS_NOPOLLING_TYPE(ha
))
1087 ha
->isp_ops
->enable_intrs(ha
);
1091 * qla24xx_reset_chip() - Reset ISP24xx chip.
1094 * Returns 0 on success.
1097 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
1099 struct qla_hw_data
*ha
= vha
->hw
;
1101 if (pci_channel_offline(ha
->pdev
) &&
1102 ha
->flags
.pci_channel_io_perm_failure
) {
1106 ha
->isp_ops
->disable_intrs(ha
);
1108 /* Perform RISC reset. */
1109 qla24xx_reset_risc(vha
);
1113 * qla2x00_chip_diag() - Test chip for proper operation.
1116 * Returns 0 on success.
1119 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
1122 struct qla_hw_data
*ha
= vha
->hw
;
1123 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1124 unsigned long flags
= 0;
1128 struct req_que
*req
= ha
->req_q_map
[0];
1130 /* Assume a failed state */
1131 rval
= QLA_FUNCTION_FAILED
;
1133 ql_dbg(ql_dbg_init
, vha
, 0x007b,
1134 "Testing device at %lx.\n", (u_long
)®
->flash_address
);
1136 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1138 /* Reset ISP chip. */
1139 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1142 * We need to have a delay here since the card will not respond while
1143 * in reset causing an MCA on some architectures.
1146 data
= qla2x00_debounce_register(®
->ctrl_status
);
1147 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
1149 data
= RD_REG_WORD(®
->ctrl_status
);
1154 goto chip_diag_failed
;
1156 ql_dbg(ql_dbg_init
, vha
, 0x007c,
1157 "Reset register cleared by chip reset.\n");
1159 /* Reset RISC processor. */
1160 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
1161 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
1163 /* Workaround for QLA2312 PCI parity error */
1164 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1165 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
1166 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
1168 data
= RD_MAILBOX_REG(ha
, reg
, 0);
1175 goto chip_diag_failed
;
1177 /* Check product ID of chip */
1178 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product Id of chip.\n");
1180 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
1181 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
1182 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
1183 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
1184 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
1185 mb
[3] != PROD_ID_3
) {
1186 ql_log(ql_log_warn
, vha
, 0x0062,
1187 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1188 mb
[1], mb
[2], mb
[3]);
1190 goto chip_diag_failed
;
1192 ha
->product_id
[0] = mb
[1];
1193 ha
->product_id
[1] = mb
[2];
1194 ha
->product_id
[2] = mb
[3];
1195 ha
->product_id
[3] = mb
[4];
1197 /* Adjust fw RISC transfer size */
1198 if (req
->length
> 1024)
1199 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
1201 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
1204 if (IS_QLA2200(ha
) &&
1205 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
1206 /* Limit firmware transfer size with a 2200A */
1207 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
1209 ha
->device_type
|= DT_ISP2200A
;
1210 ha
->fw_transfer_size
= 128;
1213 /* Wrap Incoming Mailboxes Test. */
1214 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1216 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
1217 rval
= qla2x00_mbx_reg_test(vha
);
1219 ql_log(ql_log_warn
, vha
, 0x0080,
1220 "Failed mailbox send register test.\n");
1222 /* Flag a successful rval */
1224 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1228 ql_log(ql_log_info
, vha
, 0x0081,
1229 "Chip diagnostics **** FAILED ****.\n");
1231 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1237 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1240 * Returns 0 on success.
1243 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
1246 struct qla_hw_data
*ha
= vha
->hw
;
1247 struct req_que
*req
= ha
->req_q_map
[0];
1252 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
1254 rval
= qla2x00_mbx_reg_test(vha
);
1256 ql_log(ql_log_warn
, vha
, 0x0082,
1257 "Failed mailbox send register test.\n");
1259 /* Flag a successful rval */
1267 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
1270 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
1271 eft_size
, fce_size
, mq_size
;
1274 struct qla_hw_data
*ha
= vha
->hw
;
1275 struct req_que
*req
= ha
->req_q_map
[0];
1276 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1279 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
1280 "Firmware dump already allocated.\n");
1285 fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
1286 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1287 fixed_size
= sizeof(struct qla2100_fw_dump
);
1288 } else if (IS_QLA23XX(ha
)) {
1289 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
1290 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
1292 } else if (IS_FWI2_CAPABLE(ha
)) {
1294 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
1295 else if (IS_QLA81XX(ha
))
1296 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
1297 else if (IS_QLA25XX(ha
))
1298 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
1300 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
1301 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
1304 if (!IS_QLA83XX(ha
))
1305 mq_size
= sizeof(struct qla2xxx_mq_chain
);
1307 * Allocate maximum buffer size for all queues.
1308 * Resizing must be done at end-of-dump processing.
1310 mq_size
+= ha
->max_req_queues
*
1311 (req
->length
* sizeof(request_t
));
1312 mq_size
+= ha
->max_rsp_queues
*
1313 (rsp
->length
* sizeof(response_t
));
1315 if (ha
->tgt
.atio_q_length
)
1316 mq_size
+= ha
->tgt
.atio_q_length
* sizeof(request_t
);
1317 /* Allocate memory for Fibre Channel Event Buffer. */
1318 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
))
1321 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
1324 ql_log(ql_log_warn
, vha
, 0x00be,
1325 "Unable to allocate (%d KB) for FCE.\n",
1330 memset(tc
, 0, FCE_SIZE
);
1331 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
1332 ha
->fce_mb
, &ha
->fce_bufs
);
1334 ql_log(ql_log_warn
, vha
, 0x00bf,
1335 "Unable to initialize FCE (%d).\n", rval
);
1336 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
1338 ha
->flags
.fce_enabled
= 0;
1341 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
1342 "Allocate (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
1344 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
1345 ha
->flags
.fce_enabled
= 1;
1346 ha
->fce_dma
= tc_dma
;
1349 /* Allocate memory for Extended Trace Buffer. */
1350 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
1353 ql_log(ql_log_warn
, vha
, 0x00c1,
1354 "Unable to allocate (%d KB) for EFT.\n",
1359 memset(tc
, 0, EFT_SIZE
);
1360 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
1362 ql_log(ql_log_warn
, vha
, 0x00c2,
1363 "Unable to initialize EFT (%d).\n", rval
);
1364 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
1368 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
1369 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
1371 eft_size
= EFT_SIZE
;
1372 ha
->eft_dma
= tc_dma
;
1376 req_q_size
= req
->length
* sizeof(request_t
);
1377 rsp_q_size
= rsp
->length
* sizeof(response_t
);
1379 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
1380 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
1381 ha
->chain_offset
= dump_size
;
1382 dump_size
+= mq_size
+ fce_size
;
1384 ha
->fw_dump
= vmalloc(dump_size
);
1386 ql_log(ql_log_warn
, vha
, 0x00c4,
1387 "Unable to allocate (%d KB) for firmware dump.\n",
1391 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
1398 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
1405 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
1406 "Allocated (%d KB) for firmware dump.\n", dump_size
/ 1024);
1408 ha
->fw_dump_len
= dump_size
;
1409 ha
->fw_dump
->signature
[0] = 'Q';
1410 ha
->fw_dump
->signature
[1] = 'L';
1411 ha
->fw_dump
->signature
[2] = 'G';
1412 ha
->fw_dump
->signature
[3] = 'C';
1413 ha
->fw_dump
->version
= __constant_htonl(1);
1415 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
1416 ha
->fw_dump
->mem_size
= htonl(mem_size
);
1417 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
1418 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
1420 ha
->fw_dump
->eft_size
= htonl(eft_size
);
1421 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
1422 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
1424 ha
->fw_dump
->header_size
=
1425 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
1429 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
1431 #define MPS_MASK 0xe0
1436 if (!IS_QLA81XX(vha
->hw
))
1439 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
1440 if (rval
!= QLA_SUCCESS
) {
1441 ql_log(ql_log_warn
, vha
, 0x0105,
1442 "Unable to acquire semaphore.\n");
1446 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
1447 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
1448 if (rval
!= QLA_SUCCESS
) {
1449 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
1454 if (dc
== (dw
& MPS_MASK
))
1459 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
1460 if (rval
!= QLA_SUCCESS
) {
1461 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
1465 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
1466 if (rval
!= QLA_SUCCESS
) {
1467 ql_log(ql_log_warn
, vha
, 0x006d,
1468 "Unable to release semaphore.\n");
1476 * qla2x00_setup_chip() - Load and start RISC firmware.
1479 * Returns 0 on success.
1482 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
1485 uint32_t srisc_address
= 0;
1486 struct qla_hw_data
*ha
= vha
->hw
;
1487 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1488 unsigned long flags
;
1489 uint16_t fw_major_version
;
1491 if (IS_QLA82XX(ha
)) {
1492 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1493 if (rval
== QLA_SUCCESS
) {
1494 qla2x00_stop_firmware(vha
);
1495 goto enable_82xx_npiv
;
1500 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1501 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1502 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1503 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
1504 RD_REG_WORD(®
->hccr
);
1505 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1508 qla81xx_mpi_sync(vha
);
1510 /* Load firmware sequences */
1511 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1512 if (rval
== QLA_SUCCESS
) {
1513 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
1514 "Verifying Checksum of loaded RISC code.\n");
1516 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
1517 if (rval
== QLA_SUCCESS
) {
1518 /* Start firmware execution. */
1519 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
1520 "Starting firmware.\n");
1522 rval
= qla2x00_execute_fw(vha
, srisc_address
);
1523 /* Retrieve firmware information. */
1524 if (rval
== QLA_SUCCESS
) {
1526 fw_major_version
= ha
->fw_major_version
;
1528 qla82xx_check_md_needed(vha
);
1530 rval
= qla2x00_get_fw_version(vha
);
1531 if (rval
!= QLA_SUCCESS
)
1533 ha
->flags
.npiv_supported
= 0;
1534 if (IS_QLA2XXX_MIDTYPE(ha
) &&
1535 (ha
->fw_attributes
& BIT_2
)) {
1536 ha
->flags
.npiv_supported
= 1;
1537 if ((!ha
->max_npiv_vports
) ||
1538 ((ha
->max_npiv_vports
+ 1) %
1539 MIN_MULTI_ID_FABRIC
))
1540 ha
->max_npiv_vports
=
1541 MIN_MULTI_ID_FABRIC
- 1;
1543 qla2x00_get_resource_cnts(vha
, NULL
,
1544 &ha
->fw_xcb_count
, NULL
, NULL
,
1545 &ha
->max_npiv_vports
, NULL
);
1547 if (!fw_major_version
&& ql2xallocfwdump
1549 qla2x00_alloc_fw_dump(vha
);
1552 ql_log(ql_log_fatal
, vha
, 0x00cd,
1553 "ISP Firmware failed checksum.\n");
1558 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1559 /* Enable proper parity. */
1560 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1563 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1565 /* SRAM, Instruction RAM and GP RAM parity */
1566 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1567 RD_REG_WORD(®
->hccr
);
1568 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1572 goto skip_fac_check
;
1574 if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
1577 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
1578 if (rval
== QLA_SUCCESS
) {
1579 ha
->flags
.fac_supported
= 1;
1580 ha
->fdt_block_size
= size
<< 2;
1582 ql_log(ql_log_warn
, vha
, 0x00ce,
1583 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1584 ha
->fw_major_version
, ha
->fw_minor_version
,
1585 ha
->fw_subminor_version
);
1587 if (IS_QLA83XX(ha
)) {
1588 ha
->flags
.fac_supported
= 0;
1595 ql_log(ql_log_fatal
, vha
, 0x00cf,
1596 "Setup chip ****FAILED****.\n");
1603 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1606 * Beginning of request ring has initialization control block already built
1607 * by nvram config routine.
1609 * Returns 0 on success.
1612 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1617 rsp
->ring_ptr
= rsp
->ring
;
1618 rsp
->ring_index
= 0;
1619 rsp
->status_srb
= NULL
;
1620 pkt
= rsp
->ring_ptr
;
1621 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1622 pkt
->signature
= RESPONSE_PROCESSED
;
1628 * qla2x00_update_fw_options() - Read and process firmware options.
1631 * Returns 0 on success.
1634 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1636 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1637 struct qla_hw_data
*ha
= vha
->hw
;
1639 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1640 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1642 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1645 /* Serial Link options. */
1646 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
1647 "Serial link options.\n");
1648 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
1649 (uint8_t *)&ha
->fw_seriallink_options
,
1650 sizeof(ha
->fw_seriallink_options
));
1652 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1653 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1654 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1657 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1658 emphasis
= (ha
->fw_seriallink_options
[2] &
1659 (BIT_4
| BIT_3
)) >> 3;
1660 tx_sens
= ha
->fw_seriallink_options
[0] &
1661 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1662 rx_sens
= (ha
->fw_seriallink_options
[0] &
1663 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1664 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1665 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1668 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1669 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1670 ha
->fw_options
[10] |= BIT_5
|
1671 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1672 (tx_sens
& (BIT_1
| BIT_0
));
1675 swing
= (ha
->fw_seriallink_options
[2] &
1676 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1677 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1678 tx_sens
= ha
->fw_seriallink_options
[1] &
1679 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1680 rx_sens
= (ha
->fw_seriallink_options
[1] &
1681 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1682 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1683 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1686 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1687 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1688 ha
->fw_options
[11] |= BIT_5
|
1689 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1690 (tx_sens
& (BIT_1
| BIT_0
));
1694 /* Return command IOCBs without waiting for an ABTS to complete. */
1695 ha
->fw_options
[3] |= BIT_13
;
1698 if (ha
->flags
.enable_led_scheme
)
1699 ha
->fw_options
[2] |= BIT_12
;
1701 /* Detect ISP6312. */
1703 ha
->fw_options
[2] |= BIT_13
;
1705 /* Update firmware options. */
1706 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1710 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1713 struct qla_hw_data
*ha
= vha
->hw
;
1718 /* Update Serial Link options. */
1719 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1722 rval
= qla2x00_set_serdes_params(vha
,
1723 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1724 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1725 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1726 if (rval
!= QLA_SUCCESS
) {
1727 ql_log(ql_log_warn
, vha
, 0x0104,
1728 "Unable to update Serial Link options (%x).\n", rval
);
1733 qla2x00_config_rings(struct scsi_qla_host
*vha
)
1735 struct qla_hw_data
*ha
= vha
->hw
;
1736 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1737 struct req_que
*req
= ha
->req_q_map
[0];
1738 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1740 /* Setup ring parameters in initialization control block. */
1741 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1742 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1743 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
1744 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
1745 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1746 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1747 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1748 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1750 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1751 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1752 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1753 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1754 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1758 qla24xx_config_rings(struct scsi_qla_host
*vha
)
1760 struct qla_hw_data
*ha
= vha
->hw
;
1761 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
1762 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
1763 struct qla_msix_entry
*msix
;
1764 struct init_cb_24xx
*icb
;
1766 struct req_que
*req
= ha
->req_q_map
[0];
1767 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1769 /* Setup ring parameters in initialization control block. */
1770 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1771 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1772 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1773 icb
->request_q_length
= cpu_to_le16(req
->length
);
1774 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
1775 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1776 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1777 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1778 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1780 /* Setup ATIO queue dma pointers for target mode */
1781 icb
->atio_q_inpointer
= __constant_cpu_to_le16(0);
1782 icb
->atio_q_length
= cpu_to_le16(ha
->tgt
.atio_q_length
);
1783 icb
->atio_q_address
[0] = cpu_to_le32(LSD(ha
->tgt
.atio_dma
));
1784 icb
->atio_q_address
[1] = cpu_to_le32(MSD(ha
->tgt
.atio_dma
));
1786 if (ha
->mqenable
|| IS_QLA83XX(ha
)) {
1787 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
1788 icb
->rid
= __constant_cpu_to_le16(rid
);
1789 if (ha
->flags
.msix_enabled
) {
1790 msix
= &ha
->msix_entries
[1];
1791 ql_dbg(ql_dbg_init
, vha
, 0x00fd,
1792 "Registering vector 0x%x for base que.\n",
1794 icb
->msix
= cpu_to_le16(msix
->entry
);
1796 /* Use alternate PCI bus number */
1798 icb
->firmware_options_2
|=
1799 __constant_cpu_to_le32(BIT_19
);
1800 /* Use alternate PCI devfn */
1802 icb
->firmware_options_2
|=
1803 __constant_cpu_to_le32(BIT_18
);
1805 /* Use Disable MSIX Handshake mode for capable adapters */
1806 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
1807 (ha
->flags
.msix_enabled
)) {
1808 icb
->firmware_options_2
&=
1809 __constant_cpu_to_le32(~BIT_22
);
1810 ha
->flags
.disable_msix_handshake
= 1;
1811 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
1812 "MSIX Handshake Disable Mode turned on.\n");
1814 icb
->firmware_options_2
|=
1815 __constant_cpu_to_le32(BIT_22
);
1817 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
1819 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
1820 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
1821 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
1822 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
1824 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
1825 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
1826 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
1827 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
1829 qlt_24xx_config_rings(vha
, reg
);
1832 RD_REG_DWORD(&ioreg
->hccr
);
1836 * qla2x00_init_rings() - Initializes firmware.
1839 * Beginning of request ring has initialization control block already built
1840 * by nvram config routine.
1842 * Returns 0 on success.
1845 qla2x00_init_rings(scsi_qla_host_t
*vha
)
1848 unsigned long flags
= 0;
1850 struct qla_hw_data
*ha
= vha
->hw
;
1851 struct req_que
*req
;
1852 struct rsp_que
*rsp
;
1853 struct mid_init_cb_24xx
*mid_init_cb
=
1854 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1856 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1858 /* Clear outstanding commands array. */
1859 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1860 req
= ha
->req_q_map
[que
];
1863 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1864 req
->outstanding_cmds
[cnt
] = NULL
;
1866 req
->current_outstanding_cmd
= 1;
1868 /* Initialize firmware. */
1869 req
->ring_ptr
= req
->ring
;
1870 req
->ring_index
= 0;
1871 req
->cnt
= req
->length
;
1874 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
1875 rsp
= ha
->rsp_q_map
[que
];
1878 /* Initialize response queue entries */
1879 qla2x00_init_response_q_entries(rsp
);
1882 spin_lock(&ha
->vport_slock
);
1884 spin_unlock(&ha
->vport_slock
);
1886 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
1887 ha
->tgt
.atio_ring_index
= 0;
1888 /* Initialize ATIO queue entries */
1889 qlt_init_atio_q_entries(vha
);
1891 ha
->isp_ops
->config_rings(vha
);
1893 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1895 /* Update any ISP specific firmware options before initialization. */
1896 ha
->isp_ops
->update_fw_options(vha
);
1898 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
1900 if (ha
->flags
.npiv_supported
) {
1901 if (ha
->operating_mode
== LOOP
)
1902 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
1903 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1906 if (IS_FWI2_CAPABLE(ha
)) {
1907 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1908 mid_init_cb
->init_cb
.execution_throttle
=
1909 cpu_to_le16(ha
->fw_xcb_count
);
1912 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
1914 ql_log(ql_log_fatal
, vha
, 0x00d2,
1915 "Init Firmware **** FAILED ****.\n");
1917 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
1918 "Init Firmware -- success.\n");
1925 * qla2x00_fw_ready() - Waits for firmware ready.
1928 * Returns 0 on success.
1931 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
1934 unsigned long wtime
, mtime
, cs84xx_time
;
1935 uint16_t min_wait
; /* Minimum wait time if loop is down */
1936 uint16_t wait_time
; /* Wait time if loop is coming ready */
1938 struct qla_hw_data
*ha
= vha
->hw
;
1942 /* 20 seconds for loop down. */
1946 * Firmware should take at most one RATOV to login, plus 5 seconds for
1947 * our own processing.
1949 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1950 wait_time
= min_wait
;
1953 /* Min wait time if loop down */
1954 mtime
= jiffies
+ (min_wait
* HZ
);
1956 /* wait time before firmware ready */
1957 wtime
= jiffies
+ (wait_time
* HZ
);
1959 /* Wait for ISP to finish LIP */
1960 if (!vha
->flags
.init_done
)
1961 ql_log(ql_log_info
, vha
, 0x801e,
1962 "Waiting for LIP to complete.\n");
1965 rval
= qla2x00_get_firmware_state(vha
, state
);
1966 if (rval
== QLA_SUCCESS
) {
1967 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
1968 vha
->device_flags
&= ~DFLG_NO_CABLE
;
1970 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
1971 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
1972 "fw_state=%x 84xx=%x.\n", state
[0],
1974 if ((state
[2] & FSTATE_LOGGED_IN
) &&
1975 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
1976 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
1977 "Sending verify iocb.\n");
1979 cs84xx_time
= jiffies
;
1980 rval
= qla84xx_init_chip(vha
);
1981 if (rval
!= QLA_SUCCESS
) {
1984 "Init chip failed.\n");
1988 /* Add time taken to initialize. */
1989 cs84xx_time
= jiffies
- cs84xx_time
;
1990 wtime
+= cs84xx_time
;
1991 mtime
+= cs84xx_time
;
1992 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
1993 "Increasing wait time by %ld. "
1994 "New time %ld.\n", cs84xx_time
,
1997 } else if (state
[0] == FSTATE_READY
) {
1998 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
1999 "F/W Ready - OK.\n");
2001 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
2002 &ha
->login_timeout
, &ha
->r_a_tov
);
2008 rval
= QLA_FUNCTION_FAILED
;
2010 if (atomic_read(&vha
->loop_down_timer
) &&
2011 state
[0] != FSTATE_READY
) {
2012 /* Loop down. Timeout on min_wait for states
2013 * other than Wait for Login.
2015 if (time_after_eq(jiffies
, mtime
)) {
2016 ql_log(ql_log_info
, vha
, 0x8038,
2017 "Cable is unplugged...\n");
2019 vha
->device_flags
|= DFLG_NO_CABLE
;
2024 /* Mailbox cmd failed. Timeout on min_wait. */
2025 if (time_after_eq(jiffies
, mtime
) ||
2026 ha
->flags
.isp82xx_fw_hung
)
2030 if (time_after_eq(jiffies
, wtime
))
2033 /* Delay for a while */
2037 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
2038 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state
[0],
2039 state
[1], state
[2], state
[3], state
[4], jiffies
);
2041 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
2042 ql_log(ql_log_warn
, vha
, 0x803b,
2043 "Firmware ready **** FAILED ****.\n");
2050 * qla2x00_configure_hba
2051 * Setup adapter context.
2054 * ha = adapter state pointer.
2063 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
2072 char connect_type
[22];
2073 struct qla_hw_data
*ha
= vha
->hw
;
2075 /* Get host addresses. */
2076 rval
= qla2x00_get_adapter_id(vha
,
2077 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
2078 if (rval
!= QLA_SUCCESS
) {
2079 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
2080 IS_CNA_CAPABLE(ha
) ||
2081 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
2082 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
2083 "Loop is in a transition state.\n");
2085 ql_log(ql_log_warn
, vha
, 0x2009,
2086 "Unable to get host loop ID.\n");
2087 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2093 ql_log(ql_log_info
, vha
, 0x200a,
2094 "Cannot get topology - retrying.\n");
2095 return (QLA_FUNCTION_FAILED
);
2098 vha
->loop_id
= loop_id
;
2101 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
2102 ha
->operating_mode
= LOOP
;
2107 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
2108 ha
->current_topology
= ISP_CFG_NL
;
2109 strcpy(connect_type
, "(Loop)");
2113 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
2114 ha
->switch_cap
= sw_cap
;
2115 ha
->current_topology
= ISP_CFG_FL
;
2116 strcpy(connect_type
, "(FL_Port)");
2120 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
2121 ha
->operating_mode
= P2P
;
2122 ha
->current_topology
= ISP_CFG_N
;
2123 strcpy(connect_type
, "(N_Port-to-N_Port)");
2127 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
2128 ha
->switch_cap
= sw_cap
;
2129 ha
->operating_mode
= P2P
;
2130 ha
->current_topology
= ISP_CFG_F
;
2131 strcpy(connect_type
, "(F_Port)");
2135 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
2136 "HBA in unknown topology %x, using NL.\n", topo
);
2137 ha
->current_topology
= ISP_CFG_NL
;
2138 strcpy(connect_type
, "(Loop)");
2142 /* Save Host port and loop ID. */
2143 /* byte order - Big Endian */
2144 vha
->d_id
.b
.domain
= domain
;
2145 vha
->d_id
.b
.area
= area
;
2146 vha
->d_id
.b
.al_pa
= al_pa
;
2148 spin_lock(&ha
->vport_slock
);
2149 qlt_update_vp_map(vha
, SET_AL_PA
);
2150 spin_unlock(&ha
->vport_slock
);
2152 if (!vha
->flags
.init_done
)
2153 ql_log(ql_log_info
, vha
, 0x2010,
2154 "Topology - %s, Host Loop address 0x%x.\n",
2155 connect_type
, vha
->loop_id
);
2158 ql_log(ql_log_warn
, vha
, 0x2011,
2159 "%s FAILED\n", __func__
);
2161 ql_dbg(ql_dbg_disc
, vha
, 0x2012,
2162 "%s success\n", __func__
);
2169 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
2174 struct qla_hw_data
*ha
= vha
->hw
;
2175 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
2176 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
2178 if (memcmp(model
, BINZERO
, len
) != 0) {
2179 strncpy(ha
->model_number
, model
, len
);
2180 st
= en
= ha
->model_number
;
2183 if (*en
!= 0x20 && *en
!= 0x00)
2188 index
= (ha
->pdev
->subsystem_device
& 0xff);
2190 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2191 index
< QLA_MODEL_NAMES
)
2192 strncpy(ha
->model_desc
,
2193 qla2x00_model_name
[index
* 2 + 1],
2194 sizeof(ha
->model_desc
) - 1);
2196 index
= (ha
->pdev
->subsystem_device
& 0xff);
2198 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2199 index
< QLA_MODEL_NAMES
) {
2200 strcpy(ha
->model_number
,
2201 qla2x00_model_name
[index
* 2]);
2202 strncpy(ha
->model_desc
,
2203 qla2x00_model_name
[index
* 2 + 1],
2204 sizeof(ha
->model_desc
) - 1);
2206 strcpy(ha
->model_number
, def
);
2209 if (IS_FWI2_CAPABLE(ha
))
2210 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
2211 sizeof(ha
->model_desc
));
2214 /* On sparc systems, obtain port and node WWN from firmware
2217 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
2220 struct qla_hw_data
*ha
= vha
->hw
;
2221 struct pci_dev
*pdev
= ha
->pdev
;
2222 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
2226 val
= of_get_property(dp
, "port-wwn", &len
);
2227 if (val
&& len
>= WWN_SIZE
)
2228 memcpy(nv
->port_name
, val
, WWN_SIZE
);
2230 val
= of_get_property(dp
, "node-wwn", &len
);
2231 if (val
&& len
>= WWN_SIZE
)
2232 memcpy(nv
->node_name
, val
, WWN_SIZE
);
2237 * NVRAM configuration for ISP 2xxx
2240 * ha = adapter block pointer.
2243 * initialization control block in response_ring
2244 * host adapters parameters in host adapter block
2250 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
2255 uint8_t *dptr1
, *dptr2
;
2256 struct qla_hw_data
*ha
= vha
->hw
;
2257 init_cb_t
*icb
= ha
->init_cb
;
2258 nvram_t
*nv
= ha
->nvram
;
2259 uint8_t *ptr
= ha
->nvram
;
2260 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2264 /* Determine NVRAM starting address. */
2265 ha
->nvram_size
= sizeof(nvram_t
);
2267 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
2268 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
2269 ha
->nvram_base
= 0x80;
2271 /* Get NVRAM data and calculate checksum. */
2272 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
2273 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
2276 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
2277 "Contents of NVRAM.\n");
2278 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
2279 (uint8_t *)nv
, ha
->nvram_size
);
2281 /* Bad NVRAM data, set defaults parameters. */
2282 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
2283 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
2284 /* Reset NVRAM data. */
2285 ql_log(ql_log_warn
, vha
, 0x0064,
2286 "Inconsistent NVRAM "
2287 "detected: checksum=0x%x id=%c version=0x%x.\n",
2288 chksum
, nv
->id
[0], nv
->nvram_version
);
2289 ql_log(ql_log_warn
, vha
, 0x0065,
2291 "functioning (yet invalid -- WWPN) defaults.\n");
2294 * Set default initialization control block.
2296 memset(nv
, 0, ha
->nvram_size
);
2297 nv
->parameter_block_version
= ICB_VERSION
;
2299 if (IS_QLA23XX(ha
)) {
2300 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2301 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2302 nv
->add_firmware_options
[0] = BIT_5
;
2303 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2304 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2305 nv
->special_options
[1] = BIT_7
;
2306 } else if (IS_QLA2200(ha
)) {
2307 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2308 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2309 nv
->add_firmware_options
[0] = BIT_5
;
2310 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2311 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2312 } else if (IS_QLA2100(ha
)) {
2313 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
2314 nv
->firmware_options
[1] = BIT_5
;
2315 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2318 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
2319 nv
->execution_throttle
= __constant_cpu_to_le16(16);
2320 nv
->retry_count
= 8;
2321 nv
->retry_delay
= 1;
2323 nv
->port_name
[0] = 33;
2324 nv
->port_name
[3] = 224;
2325 nv
->port_name
[4] = 139;
2327 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
2329 nv
->login_timeout
= 4;
2332 * Set default host adapter parameters
2334 nv
->host_p
[1] = BIT_2
;
2335 nv
->reset_delay
= 5;
2336 nv
->port_down_retry_count
= 8;
2337 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
2338 nv
->link_down_timeout
= 60;
2343 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2345 * The SN2 does not provide BIOS emulation which means you can't change
2346 * potentially bogus BIOS settings. Force the use of default settings
2347 * for link rate and frame size. Hope that the rest of the settings
2350 if (ia64_platform_is("sn2")) {
2351 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2353 nv
->special_options
[1] = BIT_7
;
2357 /* Reset Initialization control block */
2358 memset(icb
, 0, ha
->init_cb_size
);
2361 * Setup driver NVRAM options.
2363 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
2364 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
2365 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
2366 nv
->firmware_options
[1] &= ~BIT_4
;
2368 if (IS_QLA23XX(ha
)) {
2369 nv
->firmware_options
[0] |= BIT_2
;
2370 nv
->firmware_options
[0] &= ~BIT_3
;
2371 nv
->special_options
[0] &= ~BIT_6
;
2372 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
2374 if (IS_QLA2300(ha
)) {
2375 if (ha
->fb_rev
== FPM_2310
) {
2376 strcpy(ha
->model_number
, "QLA2310");
2378 strcpy(ha
->model_number
, "QLA2300");
2381 qla2x00_set_model_info(vha
, nv
->model_number
,
2382 sizeof(nv
->model_number
), "QLA23xx");
2384 } else if (IS_QLA2200(ha
)) {
2385 nv
->firmware_options
[0] |= BIT_2
;
2387 * 'Point-to-point preferred, else loop' is not a safe
2388 * connection mode setting.
2390 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
2392 /* Force 'loop preferred, else point-to-point'. */
2393 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
2394 nv
->add_firmware_options
[0] |= BIT_5
;
2396 strcpy(ha
->model_number
, "QLA22xx");
2397 } else /*if (IS_QLA2100(ha))*/ {
2398 strcpy(ha
->model_number
, "QLA2100");
2402 * Copy over NVRAM RISC parameter block to initialization control block.
2404 dptr1
= (uint8_t *)icb
;
2405 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
2406 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
2408 *dptr1
++ = *dptr2
++;
2410 /* Copy 2nd half. */
2411 dptr1
= (uint8_t *)icb
->add_firmware_options
;
2412 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
2414 *dptr1
++ = *dptr2
++;
2416 /* Use alternate WWN? */
2417 if (nv
->host_p
[1] & BIT_7
) {
2418 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
2419 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
2422 /* Prepare nodename */
2423 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
2425 * Firmware will apply the following mask if the nodename was
2428 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
2429 icb
->node_name
[0] &= 0xF0;
2433 * Set host adapter parameters.
2437 * BIT_7 in the host-parameters section allows for modification to
2438 * internal driver logging.
2440 if (nv
->host_p
[0] & BIT_7
)
2441 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
2442 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
2443 /* Always load RISC code on non ISP2[12]00 chips. */
2444 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2445 ha
->flags
.disable_risc_code_load
= 0;
2446 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
2447 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
2448 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
2449 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
2450 ha
->flags
.disable_serdes
= 0;
2452 ha
->operating_mode
=
2453 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
2455 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
2456 sizeof(ha
->fw_seriallink_options
));
2458 /* save HBA serial number */
2459 ha
->serial0
= icb
->port_name
[5];
2460 ha
->serial1
= icb
->port_name
[6];
2461 ha
->serial2
= icb
->port_name
[7];
2462 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
2463 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
2465 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
2467 ha
->retry_count
= nv
->retry_count
;
2469 /* Set minimum login_timeout to 4 seconds. */
2470 if (nv
->login_timeout
!= ql2xlogintimeout
)
2471 nv
->login_timeout
= ql2xlogintimeout
;
2472 if (nv
->login_timeout
< 4)
2473 nv
->login_timeout
= 4;
2474 ha
->login_timeout
= nv
->login_timeout
;
2475 icb
->login_timeout
= nv
->login_timeout
;
2477 /* Set minimum RATOV to 100 tenths of a second. */
2480 ha
->loop_reset_delay
= nv
->reset_delay
;
2482 /* Link Down Timeout = 0:
2484 * When Port Down timer expires we will start returning
2485 * I/O's to OS with "DID_NO_CONNECT".
2487 * Link Down Timeout != 0:
2489 * The driver waits for the link to come up after link down
2490 * before returning I/Os to OS with "DID_NO_CONNECT".
2492 if (nv
->link_down_timeout
== 0) {
2493 ha
->loop_down_abort_time
=
2494 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
2496 ha
->link_down_timeout
= nv
->link_down_timeout
;
2497 ha
->loop_down_abort_time
=
2498 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
2502 * Need enough time to try and get the port back.
2504 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
2505 if (qlport_down_retry
)
2506 ha
->port_down_retry_count
= qlport_down_retry
;
2507 /* Set login_retry_count */
2508 ha
->login_retry_count
= nv
->retry_count
;
2509 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
2510 ha
->port_down_retry_count
> 3)
2511 ha
->login_retry_count
= ha
->port_down_retry_count
;
2512 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
2513 ha
->login_retry_count
= ha
->port_down_retry_count
;
2514 if (ql2xloginretrycount
)
2515 ha
->login_retry_count
= ql2xloginretrycount
;
2517 icb
->lun_enables
= __constant_cpu_to_le16(0);
2518 icb
->command_resource_count
= 0;
2519 icb
->immediate_notify_resource_count
= 0;
2520 icb
->timeout
= __constant_cpu_to_le16(0);
2522 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2524 icb
->firmware_options
[0] &= ~BIT_3
;
2525 icb
->add_firmware_options
[0] &=
2526 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2527 icb
->add_firmware_options
[0] |= BIT_2
;
2528 icb
->response_accumulation_timer
= 3;
2529 icb
->interrupt_delay_timer
= 5;
2531 vha
->flags
.process_response_queue
= 1;
2534 if (!vha
->flags
.init_done
) {
2535 ha
->zio_mode
= icb
->add_firmware_options
[0] &
2536 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2537 ha
->zio_timer
= icb
->interrupt_delay_timer
?
2538 icb
->interrupt_delay_timer
: 2;
2540 icb
->add_firmware_options
[0] &=
2541 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2542 vha
->flags
.process_response_queue
= 0;
2543 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
2544 ha
->zio_mode
= QLA_ZIO_MODE_6
;
2546 ql_log(ql_log_info
, vha
, 0x0068,
2547 "ZIO mode %d enabled; timer delay (%d us).\n",
2548 ha
->zio_mode
, ha
->zio_timer
* 100);
2550 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
2551 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
2552 vha
->flags
.process_response_queue
= 1;
2557 ql_log(ql_log_warn
, vha
, 0x0069,
2558 "NVRAM configuration failed.\n");
2564 qla2x00_rport_del(void *data
)
2566 fc_port_t
*fcport
= data
;
2567 struct fc_rport
*rport
;
2568 scsi_qla_host_t
*vha
= fcport
->vha
;
2569 unsigned long flags
;
2571 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2572 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
2573 fcport
->drport
= NULL
;
2574 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2576 fc_remote_port_delete(rport
);
2578 * Release the target mode FC NEXUS in qla_target.c code
2579 * if target mod is enabled.
2581 qlt_fc_port_deleted(vha
, fcport
);
2586 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2588 * @flags: allocation flags
2590 * Returns a pointer to the allocated fcport, or NULL, if none available.
2593 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
2597 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
2601 /* Setup fcport template structure. */
2603 fcport
->port_type
= FCT_UNKNOWN
;
2604 fcport
->loop_id
= FC_NO_LOOP_ID
;
2605 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
2606 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
2607 fcport
->scan_state
= QLA_FCPORT_SCAN_NONE
;
2613 * qla2x00_configure_loop
2614 * Updates Fibre Channel Device Database with what is actually on loop.
2617 * ha = adapter block pointer.
2622 * 2 = database was full and device was not configured.
2625 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
2628 unsigned long flags
, save_flags
;
2629 struct qla_hw_data
*ha
= vha
->hw
;
2632 /* Get Initiator ID */
2633 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2634 rval
= qla2x00_configure_hba(vha
);
2635 if (rval
!= QLA_SUCCESS
) {
2636 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
2637 "Unable to configure HBA.\n");
2642 save_flags
= flags
= vha
->dpc_flags
;
2643 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
2644 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
2647 * If we have both an RSCN and PORT UPDATE pending then handle them
2648 * both at the same time.
2650 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2651 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2653 qla2x00_get_data_rate(vha
);
2655 /* Determine what we need to do */
2656 if (ha
->current_topology
== ISP_CFG_FL
&&
2657 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2659 set_bit(RSCN_UPDATE
, &flags
);
2661 } else if (ha
->current_topology
== ISP_CFG_F
&&
2662 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2664 set_bit(RSCN_UPDATE
, &flags
);
2665 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2667 } else if (ha
->current_topology
== ISP_CFG_N
) {
2668 clear_bit(RSCN_UPDATE
, &flags
);
2670 } else if (!vha
->flags
.online
||
2671 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2673 set_bit(RSCN_UPDATE
, &flags
);
2674 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2677 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2678 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2679 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
2680 "Loop resync needed, failing.\n");
2681 rval
= QLA_FUNCTION_FAILED
;
2683 rval
= qla2x00_configure_local_loop(vha
);
2686 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2687 if (LOOP_TRANSITION(vha
)) {
2688 ql_dbg(ql_dbg_disc
, vha
, 0x201e,
2689 "Needs RSCN update and loop transition.\n");
2690 rval
= QLA_FUNCTION_FAILED
;
2693 rval
= qla2x00_configure_fabric(vha
);
2696 if (rval
== QLA_SUCCESS
) {
2697 if (atomic_read(&vha
->loop_down_timer
) ||
2698 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2699 rval
= QLA_FUNCTION_FAILED
;
2701 atomic_set(&vha
->loop_state
, LOOP_READY
);
2702 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
2708 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
2709 "%s *** FAILED ***.\n", __func__
);
2711 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
2712 "%s: exiting normally.\n", __func__
);
2715 /* Restore state if a resync event occurred during processing */
2716 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2717 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
2718 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2719 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
2720 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2730 * qla2x00_configure_local_loop
2731 * Updates Fibre Channel Device Database with local loop devices.
2734 * ha = adapter block pointer.
2740 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
2745 fc_port_t
*fcport
, *new_fcport
;
2751 uint8_t domain
, area
, al_pa
;
2752 struct qla_hw_data
*ha
= vha
->hw
;
2756 entries
= MAX_FIBRE_DEVICES_LOOP
;
2758 ql_dbg(ql_dbg_disc
, vha
, 0x2016,
2759 "Getting FCAL position map.\n");
2760 if (ql2xextended_error_logging
& ql_dbg_disc
)
2761 qla2x00_get_fcal_position_map(vha
, NULL
);
2763 /* Get list of logged in devices. */
2764 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
2765 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
2767 if (rval
!= QLA_SUCCESS
)
2768 goto cleanup_allocation
;
2770 ql_dbg(ql_dbg_disc
, vha
, 0x2017,
2771 "Entries in ID list (%d).\n", entries
);
2772 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
2773 (uint8_t *)ha
->gid_list
,
2774 entries
* sizeof(struct gid_list_info
));
2776 /* Allocate temporary fcport for any new fcports discovered. */
2777 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2778 if (new_fcport
== NULL
) {
2779 ql_log(ql_log_warn
, vha
, 0x2018,
2780 "Memory allocation failed for fcport.\n");
2781 rval
= QLA_MEMORY_ALLOC_FAILED
;
2782 goto cleanup_allocation
;
2784 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2787 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2789 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2790 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2791 fcport
->port_type
!= FCT_BROADCAST
&&
2792 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2794 ql_dbg(ql_dbg_disc
, vha
, 0x2019,
2795 "Marking port lost loop_id=0x%04x.\n",
2798 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
2802 /* Add devices to port list. */
2803 id_iter
= (char *)ha
->gid_list
;
2804 for (index
= 0; index
< entries
; index
++) {
2805 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2806 area
= ((struct gid_list_info
*)id_iter
)->area
;
2807 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2808 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2809 loop_id
= (uint16_t)
2810 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2812 loop_id
= le16_to_cpu(
2813 ((struct gid_list_info
*)id_iter
)->loop_id
);
2814 id_iter
+= ha
->gid_list_info_size
;
2816 /* Bypass reserved domain fields. */
2817 if ((domain
& 0xf0) == 0xf0)
2820 /* Bypass if not same domain and area of adapter. */
2821 if (area
&& domain
&&
2822 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
2825 /* Bypass invalid local loop ID. */
2826 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2829 /* Fill in member data. */
2830 new_fcport
->d_id
.b
.domain
= domain
;
2831 new_fcport
->d_id
.b
.area
= area
;
2832 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2833 new_fcport
->loop_id
= loop_id
;
2834 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
2835 if (rval2
!= QLA_SUCCESS
) {
2836 ql_dbg(ql_dbg_disc
, vha
, 0x201a,
2837 "Failed to retrieve fcport information "
2838 "-- get_port_database=%x, loop_id=0x%04x.\n",
2839 rval2
, new_fcport
->loop_id
);
2840 ql_dbg(ql_dbg_disc
, vha
, 0x201b,
2841 "Scheduling resync.\n");
2842 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2846 /* Check for matching device in port list. */
2849 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2850 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2854 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2855 fcport
->loop_id
= new_fcport
->loop_id
;
2856 fcport
->port_type
= new_fcport
->port_type
;
2857 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2858 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2866 /* New device, add to fcports list. */
2867 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
2869 /* Allocate a new replacement fcport. */
2870 fcport
= new_fcport
;
2871 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2872 if (new_fcport
== NULL
) {
2873 ql_log(ql_log_warn
, vha
, 0x201c,
2874 "Failed to allocate memory for fcport.\n");
2875 rval
= QLA_MEMORY_ALLOC_FAILED
;
2876 goto cleanup_allocation
;
2878 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2881 /* Base iIDMA settings on HBA port speed. */
2882 fcport
->fp_speed
= ha
->link_data_rate
;
2884 qla2x00_update_fcport(vha
, fcport
);
2892 if (rval
!= QLA_SUCCESS
) {
2893 ql_dbg(ql_dbg_disc
, vha
, 0x201d,
2894 "Configure local loop error exit: rval=%x.\n", rval
);
2901 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2906 struct qla_hw_data
*ha
= vha
->hw
;
2908 if (!IS_IIDMA_CAPABLE(ha
))
2911 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
2914 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2915 fcport
->fp_speed
> ha
->link_data_rate
)
2918 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
2920 if (rval
!= QLA_SUCCESS
) {
2921 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
2922 "Unable to adjust iIDMA "
2923 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
2924 "%04x.\n", fcport
->port_name
[0], fcport
->port_name
[1],
2925 fcport
->port_name
[2], fcport
->port_name
[3],
2926 fcport
->port_name
[4], fcport
->port_name
[5],
2927 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2928 fcport
->fp_speed
, mb
[0], mb
[1]);
2930 link_speed
= qla2x00_get_link_speed_str(ha
);
2931 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
2932 "iIDMA adjusted to %s GB/s "
2933 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed
,
2934 fcport
->port_name
[0], fcport
->port_name
[1],
2935 fcport
->port_name
[2], fcport
->port_name
[3],
2936 fcport
->port_name
[4], fcport
->port_name
[5],
2937 fcport
->port_name
[6], fcport
->port_name
[7]);
2942 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2944 struct fc_rport_identifiers rport_ids
;
2945 struct fc_rport
*rport
;
2946 unsigned long flags
;
2948 qla2x00_rport_del(fcport
);
2950 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2951 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2952 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2953 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2954 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2955 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
2957 ql_log(ql_log_warn
, vha
, 0x2006,
2958 "Unable to allocate fc remote port.\n");
2962 * Create target mode FC NEXUS in qla_target.c if target mode is
2965 qlt_fc_port_added(vha
, fcport
);
2967 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2968 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2969 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2971 rport
->supported_classes
= fcport
->supported_classes
;
2973 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2974 if (fcport
->port_type
== FCT_INITIATOR
)
2975 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2976 if (fcport
->port_type
== FCT_TARGET
)
2977 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2978 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2982 * qla2x00_update_fcport
2983 * Updates device on list.
2986 * ha = adapter block pointer.
2987 * fcport = port structure pointer.
2997 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3000 fcport
->login_retry
= 0;
3001 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
3003 qla2x00_iidma_fcport(vha
, fcport
);
3004 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
3005 qla2x00_reg_remote_port(vha
, fcport
);
3006 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
3010 * qla2x00_configure_fabric
3011 * Setup SNS devices with loop ID's.
3014 * ha = adapter block pointer.
3021 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
3025 uint16_t next_loopid
;
3026 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3028 LIST_HEAD(new_fcports
);
3029 struct qla_hw_data
*ha
= vha
->hw
;
3030 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
3032 /* If FL port exists, then SNS is present */
3033 if (IS_FWI2_CAPABLE(ha
))
3034 loop_id
= NPH_F_PORT
;
3036 loop_id
= SNS_FL_PORT
;
3037 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
3038 if (rval
!= QLA_SUCCESS
) {
3039 ql_dbg(ql_dbg_disc
, vha
, 0x201f,
3040 "MBX_GET_PORT_NAME failed, No FL Port.\n");
3042 vha
->device_flags
&= ~SWITCH_FOUND
;
3043 return (QLA_SUCCESS
);
3045 vha
->device_flags
|= SWITCH_FOUND
;
3049 if (ql2xfdmienable
&&
3050 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
3051 qla2x00_fdmi_register(vha
);
3053 /* Ensure we are logged into the SNS. */
3054 if (IS_FWI2_CAPABLE(ha
))
3057 loop_id
= SIMPLE_NAME_SERVER
;
3058 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
3059 0xfc, mb
, BIT_1
|BIT_0
);
3060 if (rval
!= QLA_SUCCESS
) {
3061 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3064 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
3065 ql_dbg(ql_dbg_disc
, vha
, 0x2042,
3066 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3067 "mb[6]=%x mb[7]=%x.\n", loop_id
, mb
[0], mb
[1],
3068 mb
[2], mb
[6], mb
[7]);
3069 return (QLA_SUCCESS
);
3072 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
3073 if (qla2x00_rft_id(vha
)) {
3075 ql_dbg(ql_dbg_disc
, vha
, 0x2045,
3076 "Register FC-4 TYPE failed.\n");
3078 if (qla2x00_rff_id(vha
)) {
3080 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
3081 "Register FC-4 Features failed.\n");
3083 if (qla2x00_rnn_id(vha
)) {
3085 ql_dbg(ql_dbg_disc
, vha
, 0x204f,
3086 "Register Node Name failed.\n");
3087 } else if (qla2x00_rsnn_nn(vha
)) {
3089 ql_dbg(ql_dbg_disc
, vha
, 0x2053,
3090 "Register Symobilic Node Name failed.\n");
3094 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
3095 if (rval
!= QLA_SUCCESS
)
3098 /* Add new ports to existing port list */
3099 list_splice_tail_init(&new_fcports
, &vha
->vp_fcports
);
3101 /* Starting free loop ID. */
3102 next_loopid
= ha
->min_external_loopid
;
3104 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3105 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3108 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
3111 /* Logout lost/gone fabric devices (non-FCP2) */
3112 if (fcport
->scan_state
!= QLA_FCPORT_SCAN_FOUND
&&
3113 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3114 qla2x00_mark_device_lost(vha
, fcport
,
3115 ql2xplogiabsentdevice
, 0);
3116 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3117 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3118 fcport
->port_type
!= FCT_INITIATOR
&&
3119 fcport
->port_type
!= FCT_BROADCAST
) {
3120 ha
->isp_ops
->fabric_logout(vha
,
3122 fcport
->d_id
.b
.domain
,
3123 fcport
->d_id
.b
.area
,
3124 fcport
->d_id
.b
.al_pa
);
3128 fcport
->scan_state
= QLA_FCPORT_SCAN_NONE
;
3130 /* Login fabric devices that need a login */
3131 if ((fcport
->flags
& FCF_LOGIN_NEEDED
) != 0 &&
3132 atomic_read(&vha
->loop_down_timer
) == 0) {
3133 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
3134 fcport
->loop_id
= next_loopid
;
3135 rval
= qla2x00_find_new_loop_id(
3137 if (rval
!= QLA_SUCCESS
) {
3138 /* Ran out of IDs to use */
3144 /* Login and update database */
3145 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3150 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
3151 "Configure fabric error exit rval=%d.\n", rval
);
3158 * qla2x00_find_all_fabric_devs
3161 * ha = adapter block pointer.
3162 * dev = database device entry pointer.
3171 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
3172 struct list_head
*new_fcports
)
3176 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
3181 int first_dev
, last_dev
;
3182 port_id_t wrap
= {}, nxt_d_id
;
3183 struct qla_hw_data
*ha
= vha
->hw
;
3184 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
3185 struct scsi_qla_host
*tvp
;
3189 /* Try GID_PT to get device list, else GAN. */
3191 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
3196 ql_dbg(ql_dbg_disc
, vha
, 0x2054,
3197 "GID_PT allocations failed, fallback on GA_NXT.\n");
3199 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
3200 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
3202 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
3204 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
3206 } else if (ql2xiidmaenable
&&
3207 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
3208 qla2x00_gpsc(vha
, swl
);
3211 /* If other queries succeeded probe for FC-4 type */
3213 qla2x00_gff_id(vha
, swl
);
3217 /* Allocate temporary fcport for any new fcports discovered. */
3218 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3219 if (new_fcport
== NULL
) {
3220 ql_log(ql_log_warn
, vha
, 0x205e,
3221 "Failed to allocate memory for fcport.\n");
3222 return (QLA_MEMORY_ALLOC_FAILED
);
3224 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3225 /* Set start port ID scan at adapter ID. */
3229 /* Starting free loop ID. */
3230 loop_id
= ha
->min_external_loopid
;
3231 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
3232 if (qla2x00_is_reserved_id(vha
, loop_id
))
3235 if (ha
->current_topology
== ISP_CFG_FL
&&
3236 (atomic_read(&vha
->loop_down_timer
) ||
3237 LOOP_TRANSITION(vha
))) {
3238 atomic_set(&vha
->loop_down_timer
, 0);
3239 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3240 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
3246 wrap
.b24
= new_fcport
->d_id
.b24
;
3248 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
3249 memcpy(new_fcport
->node_name
,
3250 swl
[swl_idx
].node_name
, WWN_SIZE
);
3251 memcpy(new_fcport
->port_name
,
3252 swl
[swl_idx
].port_name
, WWN_SIZE
);
3253 memcpy(new_fcport
->fabric_port_name
,
3254 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
3255 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
3256 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
3258 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
3264 /* Send GA_NXT to the switch */
3265 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
3266 if (rval
!= QLA_SUCCESS
) {
3267 ql_log(ql_log_warn
, vha
, 0x2064,
3268 "SNS scan failed -- assuming "
3269 "zero-entry result.\n");
3270 list_for_each_entry_safe(fcport
, fcptemp
,
3271 new_fcports
, list
) {
3272 list_del(&fcport
->list
);
3280 /* If wrap on switch device list, exit. */
3282 wrap
.b24
= new_fcport
->d_id
.b24
;
3284 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
3285 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
3286 "Device wrap (%02x%02x%02x).\n",
3287 new_fcport
->d_id
.b
.domain
,
3288 new_fcport
->d_id
.b
.area
,
3289 new_fcport
->d_id
.b
.al_pa
);
3293 /* Bypass if same physical adapter. */
3294 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
3297 /* Bypass virtual ports of the same host. */
3299 if (ha
->num_vhosts
) {
3300 unsigned long flags
;
3302 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3303 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3304 if (new_fcport
->d_id
.b24
== vp
->d_id
.b24
) {
3309 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3315 /* Bypass if same domain and area of adapter. */
3316 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
3317 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
3321 /* Bypass reserved domain fields. */
3322 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
3325 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3326 if (ql2xgffidenable
&&
3327 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
3328 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
3331 /* Locate matching device in database. */
3333 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3334 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
3338 fcport
->scan_state
= QLA_FCPORT_SCAN_FOUND
;
3342 /* Update port state. */
3343 memcpy(fcport
->fabric_port_name
,
3344 new_fcport
->fabric_port_name
, WWN_SIZE
);
3345 fcport
->fp_speed
= new_fcport
->fp_speed
;
3348 * If address the same and state FCS_ONLINE, nothing
3351 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
3352 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3357 * If device was not a fabric device before.
3359 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
3360 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3361 qla2x00_clear_loop_id(fcport
);
3362 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
3368 * Port ID changed or device was marked to be updated;
3369 * Log it out if still logged in and mark it for
3372 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3373 fcport
->flags
|= FCF_LOGIN_NEEDED
;
3374 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3375 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3376 (fcport
->flags
& FCF_ASYNC_SENT
) == 0 &&
3377 fcport
->port_type
!= FCT_INITIATOR
&&
3378 fcport
->port_type
!= FCT_BROADCAST
) {
3379 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3380 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3381 fcport
->d_id
.b
.al_pa
);
3382 qla2x00_clear_loop_id(fcport
);
3390 /* If device was not in our fcports list, then add it. */
3391 list_add_tail(&new_fcport
->list
, new_fcports
);
3393 /* Allocate a new replacement fcport. */
3394 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
3395 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3396 if (new_fcport
== NULL
) {
3397 ql_log(ql_log_warn
, vha
, 0x2066,
3398 "Memory allocation failed for fcport.\n");
3399 return (QLA_MEMORY_ALLOC_FAILED
);
3401 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3402 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
3411 * qla2x00_find_new_loop_id
3412 * Scan through our port list and find a new usable loop ID.
3415 * ha: adapter state pointer.
3416 * dev: port structure pointer.
3419 * qla2x00 local function return status code.
3425 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
3428 struct qla_hw_data
*ha
= vha
->hw
;
3429 unsigned long flags
= 0;
3433 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3435 dev
->loop_id
= find_first_zero_bit(ha
->loop_id_map
,
3437 if (dev
->loop_id
>= LOOPID_MAP_SIZE
||
3438 qla2x00_is_reserved_id(vha
, dev
->loop_id
)) {
3439 dev
->loop_id
= FC_NO_LOOP_ID
;
3440 rval
= QLA_FUNCTION_FAILED
;
3442 set_bit(dev
->loop_id
, ha
->loop_id_map
);
3444 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3446 if (rval
== QLA_SUCCESS
)
3447 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
3448 "Assigning new loopid=%x, portid=%x.\n",
3449 dev
->loop_id
, dev
->d_id
.b24
);
3451 ql_log(ql_log_warn
, dev
->vha
, 0x2087,
3452 "No loop_id's available, portid=%x.\n",
3459 * qla2x00_fabric_dev_login
3460 * Login fabric target device and update FC port database.
3463 * ha: adapter state pointer.
3464 * fcport: port structure list pointer.
3465 * next_loopid: contains value of a new loop ID that can be used
3466 * by the next login attempt.
3469 * qla2x00 local function return status code.
3475 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3476 uint16_t *next_loopid
)
3481 struct qla_hw_data
*ha
= vha
->hw
;
3486 if (IS_ALOGIO_CAPABLE(ha
)) {
3487 if (fcport
->flags
& FCF_ASYNC_SENT
)
3489 fcport
->flags
|= FCF_ASYNC_SENT
;
3490 rval
= qla2x00_post_async_login_work(vha
, fcport
, NULL
);
3495 fcport
->flags
&= ~FCF_ASYNC_SENT
;
3496 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3497 if (rval
== QLA_SUCCESS
) {
3498 /* Send an ADISC to FCP2 devices.*/
3500 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3502 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3503 if (rval
!= QLA_SUCCESS
) {
3504 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3505 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3506 fcport
->d_id
.b
.al_pa
);
3507 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3509 qla2x00_update_fcport(vha
, fcport
);
3513 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3520 * qla2x00_fabric_login
3521 * Issue fabric login command.
3524 * ha = adapter block pointer.
3525 * device = pointer to FC device type structure.
3528 * 0 - Login successfully
3530 * 2 - Initiator device
3534 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3535 uint16_t *next_loopid
)
3539 uint16_t tmp_loopid
;
3540 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3541 struct qla_hw_data
*ha
= vha
->hw
;
3547 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
3548 "Trying Fabric Login w/loop id 0x%04x for port "
3550 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3551 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
3553 /* Login fcport on switch. */
3554 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3555 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3556 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3557 if (rval
!= QLA_SUCCESS
) {
3560 if (mb
[0] == MBS_PORT_ID_USED
) {
3562 * Device has another loop ID. The firmware team
3563 * recommends the driver perform an implicit login with
3564 * the specified ID again. The ID we just used is save
3565 * here so we return with an ID that can be tried by
3569 tmp_loopid
= fcport
->loop_id
;
3570 fcport
->loop_id
= mb
[1];
3572 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
3573 "Fabric Login: port in use - next loop "
3574 "id=0x%04x, port id= %02x%02x%02x.\n",
3575 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3576 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
3578 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3583 /* A retry occurred before. */
3584 *next_loopid
= tmp_loopid
;
3587 * No retry occurred before. Just increment the
3588 * ID value for next login.
3590 *next_loopid
= (fcport
->loop_id
+ 1);
3593 if (mb
[1] & BIT_0
) {
3594 fcport
->port_type
= FCT_INITIATOR
;
3596 fcport
->port_type
= FCT_TARGET
;
3597 if (mb
[1] & BIT_1
) {
3598 fcport
->flags
|= FCF_FCP2_DEVICE
;
3603 fcport
->supported_classes
|= FC_COS_CLASS2
;
3605 fcport
->supported_classes
|= FC_COS_CLASS3
;
3607 if (IS_FWI2_CAPABLE(ha
)) {
3610 FCF_CONF_COMP_SUPPORTED
;
3615 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3617 * Loop ID already used, try next loop ID.
3620 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3621 if (rval
!= QLA_SUCCESS
) {
3622 /* Ran out of loop IDs to use */
3625 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3627 * Firmware possibly timed out during login. If NO
3628 * retries are left to do then the device is declared
3631 *next_loopid
= fcport
->loop_id
;
3632 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3633 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3634 fcport
->d_id
.b
.al_pa
);
3635 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3641 * unrecoverable / not handled error
3643 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
3644 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3645 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
3646 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
3647 fcport
->loop_id
, jiffies
);
3649 *next_loopid
= fcport
->loop_id
;
3650 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3651 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3652 fcport
->d_id
.b
.al_pa
);
3653 qla2x00_clear_loop_id(fcport
);
3654 fcport
->login_retry
= 0;
3665 * qla2x00_local_device_login
3666 * Issue local device login command.
3669 * ha = adapter block pointer.
3670 * loop_id = loop id of device to login to.
3672 * Returns (Where's the #define!!!!):
3673 * 0 - Login successfully
3678 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3681 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3683 memset(mb
, 0, sizeof(mb
));
3684 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3685 if (rval
== QLA_SUCCESS
) {
3686 /* Interrogate mailbox registers for any errors */
3687 if (mb
[0] == MBS_COMMAND_ERROR
)
3689 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3690 /* device not in PCB table */
3698 * qla2x00_loop_resync
3699 * Resync with fibre channel devices.
3702 * ha = adapter block pointer.
3708 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
3710 int rval
= QLA_SUCCESS
;
3712 struct req_que
*req
;
3713 struct rsp_que
*rsp
;
3715 if (vha
->hw
->flags
.cpu_affinity_enabled
)
3716 req
= vha
->hw
->req_q_map
[0];
3721 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3722 if (vha
->flags
.online
) {
3723 if (!(rval
= qla2x00_fw_ready(vha
))) {
3724 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3727 /* Issue a marker after FW becomes ready. */
3728 qla2x00_marker(vha
, req
, rsp
, 0, 0,
3730 vha
->marker_needed
= 0;
3732 /* Remap devices on Loop. */
3733 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3735 qla2x00_configure_loop(vha
);
3737 } while (!atomic_read(&vha
->loop_down_timer
) &&
3738 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3739 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3744 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3745 return (QLA_FUNCTION_FAILED
);
3748 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
3749 "%s *** FAILED ***.\n", __func__
);
3755 * qla2x00_perform_loop_resync
3756 * Description: This function will set the appropriate flags and call
3757 * qla2x00_loop_resync. If successful loop will be resynced
3758 * Arguments : scsi_qla_host_t pointer
3759 * returm : Success or Failure
3762 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
3766 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
3767 /*Configure the flags so that resync happens properly*/
3768 atomic_set(&ha
->loop_down_timer
, 0);
3769 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
3770 atomic_set(&ha
->loop_state
, LOOP_UP
);
3771 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
3772 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
3773 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3775 rval
= qla2x00_loop_resync(ha
);
3777 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
3779 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
3786 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
3789 struct scsi_qla_host
*vha
;
3790 struct qla_hw_data
*ha
= base_vha
->hw
;
3791 unsigned long flags
;
3793 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3794 /* Go with deferred removal of rport references. */
3795 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
3796 atomic_inc(&vha
->vref_count
);
3797 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3798 if (fcport
->drport
&&
3799 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
3800 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3802 qla2x00_rport_del(fcport
);
3804 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3807 atomic_dec(&vha
->vref_count
);
3809 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3812 /* Assumes idc_lock always held on entry */
3814 qla83xx_reset_ownership(scsi_qla_host_t
*vha
)
3816 struct qla_hw_data
*ha
= vha
->hw
;
3817 uint32_t drv_presence
, drv_presence_mask
;
3818 uint32_t dev_part_info1
, dev_part_info2
, class_type
;
3819 uint32_t class_type_mask
= 0x3;
3820 uint16_t fcoe_other_function
= 0xffff, i
;
3822 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
3824 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO1
, &dev_part_info1
);
3825 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO2
, &dev_part_info2
);
3826 for (i
= 0; i
< 8; i
++) {
3827 class_type
= ((dev_part_info1
>> (i
* 4)) & class_type_mask
);
3828 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
3829 (i
!= ha
->portnum
)) {
3830 fcoe_other_function
= i
;
3834 if (fcoe_other_function
== 0xffff) {
3835 for (i
= 0; i
< 8; i
++) {
3836 class_type
= ((dev_part_info2
>> (i
* 4)) &
3838 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
3839 ((i
+ 8) != ha
->portnum
)) {
3840 fcoe_other_function
= i
+ 8;
3846 * Prepare drv-presence mask based on fcoe functions present.
3847 * However consider only valid physical fcoe function numbers (0-15).
3849 drv_presence_mask
= ~((1 << (ha
->portnum
)) |
3850 ((fcoe_other_function
== 0xffff) ?
3851 0 : (1 << (fcoe_other_function
))));
3853 /* We are the reset owner iff:
3854 * - No other protocol drivers present.
3855 * - This is the lowest among fcoe functions. */
3856 if (!(drv_presence
& drv_presence_mask
) &&
3857 (ha
->portnum
< fcoe_other_function
)) {
3858 ql_dbg(ql_dbg_p3p
, vha
, 0xb07f,
3859 "This host is Reset owner.\n");
3860 ha
->flags
.nic_core_reset_owner
= 1;
3865 __qla83xx_set_drv_ack(scsi_qla_host_t
*vha
)
3867 int rval
= QLA_SUCCESS
;
3868 struct qla_hw_data
*ha
= vha
->hw
;
3871 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
3872 if (rval
== QLA_SUCCESS
) {
3873 drv_ack
|= (1 << ha
->portnum
);
3874 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
3881 qla83xx_set_drv_ack(scsi_qla_host_t
*vha
)
3883 int rval
= QLA_SUCCESS
;
3885 qla83xx_idc_lock(vha
, 0);
3886 rval
= __qla83xx_set_drv_ack(vha
);
3887 qla83xx_idc_unlock(vha
, 0);
3893 __qla83xx_clear_drv_ack(scsi_qla_host_t
*vha
)
3895 int rval
= QLA_SUCCESS
;
3896 struct qla_hw_data
*ha
= vha
->hw
;
3899 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
3900 if (rval
== QLA_SUCCESS
) {
3901 drv_ack
&= ~(1 << ha
->portnum
);
3902 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
3909 qla83xx_clear_drv_ack(scsi_qla_host_t
*vha
)
3911 int rval
= QLA_SUCCESS
;
3913 qla83xx_idc_lock(vha
, 0);
3914 rval
= __qla83xx_clear_drv_ack(vha
);
3915 qla83xx_idc_unlock(vha
, 0);
3921 qla83xx_dev_state_to_string(uint32_t dev_state
)
3923 switch (dev_state
) {
3924 case QLA8XXX_DEV_COLD
:
3925 return "COLD/RE-INIT";
3926 case QLA8XXX_DEV_INITIALIZING
:
3927 return "INITIALIZING";
3928 case QLA8XXX_DEV_READY
:
3930 case QLA8XXX_DEV_NEED_RESET
:
3931 return "NEED RESET";
3932 case QLA8XXX_DEV_NEED_QUIESCENT
:
3933 return "NEED QUIESCENT";
3934 case QLA8XXX_DEV_FAILED
:
3936 case QLA8XXX_DEV_QUIESCENT
:
3943 /* Assumes idc-lock always held on entry */
3945 qla83xx_idc_audit(scsi_qla_host_t
*vha
, int audit_type
)
3947 struct qla_hw_data
*ha
= vha
->hw
;
3948 uint32_t idc_audit_reg
= 0, duration_secs
= 0;
3950 switch (audit_type
) {
3951 case IDC_AUDIT_TIMESTAMP
:
3952 ha
->idc_audit_ts
= (jiffies_to_msecs(jiffies
) / 1000);
3953 idc_audit_reg
= (ha
->portnum
) |
3954 (IDC_AUDIT_TIMESTAMP
<< 7) | (ha
->idc_audit_ts
<< 8);
3955 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
3958 case IDC_AUDIT_COMPLETION
:
3959 duration_secs
= ((jiffies_to_msecs(jiffies
) -
3960 jiffies_to_msecs(ha
->idc_audit_ts
)) / 1000);
3961 idc_audit_reg
= (ha
->portnum
) |
3962 (IDC_AUDIT_COMPLETION
<< 7) | (duration_secs
<< 8);
3963 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
3967 ql_log(ql_log_warn
, vha
, 0xb078,
3968 "Invalid audit type specified.\n");
3973 /* Assumes idc_lock always held on entry */
3975 qla83xx_initiating_reset(scsi_qla_host_t
*vha
)
3977 struct qla_hw_data
*ha
= vha
->hw
;
3978 uint32_t idc_control
, dev_state
;
3980 __qla83xx_get_idc_control(vha
, &idc_control
);
3981 if ((idc_control
& QLA83XX_IDC_RESET_DISABLED
)) {
3982 ql_log(ql_log_info
, vha
, 0xb080,
3983 "NIC Core reset has been disabled. idc-control=0x%x\n",
3985 return QLA_FUNCTION_FAILED
;
3988 /* Set NEED-RESET iff in READY state and we are the reset-owner */
3989 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
3990 if (ha
->flags
.nic_core_reset_owner
&& dev_state
== QLA8XXX_DEV_READY
) {
3991 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
3992 QLA8XXX_DEV_NEED_RESET
);
3993 ql_log(ql_log_info
, vha
, 0xb056, "HW State: NEED RESET.\n");
3994 qla83xx_idc_audit(vha
, IDC_AUDIT_TIMESTAMP
);
3996 const char *state
= qla83xx_dev_state_to_string(dev_state
);
3997 ql_log(ql_log_info
, vha
, 0xb057, "HW State: %s.\n", state
);
3999 /* SV: XXX: Is timeout required here? */
4000 /* Wait for IDC state change READY -> NEED_RESET */
4001 while (dev_state
== QLA8XXX_DEV_READY
) {
4002 qla83xx_idc_unlock(vha
, 0);
4004 qla83xx_idc_lock(vha
, 0);
4005 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
4009 /* Send IDC ack by writing to drv-ack register */
4010 __qla83xx_set_drv_ack(vha
);
4016 __qla83xx_set_idc_control(scsi_qla_host_t
*vha
, uint32_t idc_control
)
4018 return qla83xx_wr_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
4022 qla83xx_set_idc_control(scsi_qla_host_t
*vha
, uint32_t idc_control
)
4024 int rval
= QLA_SUCCESS
;
4026 qla83xx_idc_lock(vha
, 0);
4027 rval
= __qla83xx_set_idc_control(vha
, idc_control
);
4028 qla83xx_idc_unlock(vha
, 0);
4034 __qla83xx_get_idc_control(scsi_qla_host_t
*vha
, uint32_t *idc_control
)
4036 return qla83xx_rd_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
4040 qla83xx_get_idc_control(scsi_qla_host_t
*vha
, uint32_t *idc_control
)
4042 int rval
= QLA_SUCCESS
;
4044 qla83xx_idc_lock(vha
, 0);
4045 rval
= __qla83xx_get_idc_control(vha
, idc_control
);
4046 qla83xx_idc_unlock(vha
, 0);
4052 qla83xx_check_driver_presence(scsi_qla_host_t
*vha
)
4054 uint32_t drv_presence
= 0;
4055 struct qla_hw_data
*ha
= vha
->hw
;
4057 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
4058 if (drv_presence
& (1 << ha
->portnum
))
4061 return QLA_TEST_FAILED
;
4065 qla83xx_nic_core_reset(scsi_qla_host_t
*vha
)
4067 int rval
= QLA_SUCCESS
;
4068 struct qla_hw_data
*ha
= vha
->hw
;
4070 ql_dbg(ql_dbg_p3p
, vha
, 0xb058,
4071 "Entered %s().\n", __func__
);
4073 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
4074 ql_log(ql_log_warn
, vha
, 0xb059,
4075 "Device in unrecoverable FAILED state.\n");
4076 return QLA_FUNCTION_FAILED
;
4079 qla83xx_idc_lock(vha
, 0);
4081 if (qla83xx_check_driver_presence(vha
) != QLA_SUCCESS
) {
4082 ql_log(ql_log_warn
, vha
, 0xb05a,
4083 "Function=0x%x has been removed from IDC participation.\n",
4085 rval
= QLA_FUNCTION_FAILED
;
4089 qla83xx_reset_ownership(vha
);
4091 rval
= qla83xx_initiating_reset(vha
);
4094 * Perform reset if we are the reset-owner,
4095 * else wait till IDC state changes to READY/FAILED.
4097 if (rval
== QLA_SUCCESS
) {
4098 rval
= qla83xx_idc_state_handler(vha
);
4100 if (rval
== QLA_SUCCESS
)
4101 ha
->flags
.nic_core_hung
= 0;
4102 __qla83xx_clear_drv_ack(vha
);
4106 qla83xx_idc_unlock(vha
, 0);
4108 ql_dbg(ql_dbg_p3p
, vha
, 0xb05b, "Exiting %s.\n", __func__
);
4114 qla2xxx_mctp_dump(scsi_qla_host_t
*vha
)
4116 struct qla_hw_data
*ha
= vha
->hw
;
4117 int rval
= QLA_FUNCTION_FAILED
;
4119 if (!IS_MCTP_CAPABLE(ha
)) {
4120 /* This message can be removed from the final version */
4121 ql_log(ql_log_info
, vha
, 0x506d,
4122 "This board is not MCTP capable\n");
4126 if (!ha
->mctp_dump
) {
4127 ha
->mctp_dump
= dma_alloc_coherent(&ha
->pdev
->dev
,
4128 MCTP_DUMP_SIZE
, &ha
->mctp_dump_dma
, GFP_KERNEL
);
4130 if (!ha
->mctp_dump
) {
4131 ql_log(ql_log_warn
, vha
, 0x506e,
4132 "Failed to allocate memory for mctp dump\n");
4137 #define MCTP_DUMP_STR_ADDR 0x00000000
4138 rval
= qla2x00_dump_mctp_data(vha
, ha
->mctp_dump_dma
,
4139 MCTP_DUMP_STR_ADDR
, MCTP_DUMP_SIZE
/4);
4140 if (rval
!= QLA_SUCCESS
) {
4141 ql_log(ql_log_warn
, vha
, 0x506f,
4142 "Failed to capture mctp dump\n");
4144 ql_log(ql_log_info
, vha
, 0x5070,
4145 "Mctp dump capture for host (%ld/%p).\n",
4146 vha
->host_no
, ha
->mctp_dump
);
4147 ha
->mctp_dumped
= 1;
4150 if (!ha
->flags
.nic_core_reset_hdlr_active
) {
4151 ha
->flags
.nic_core_reset_hdlr_active
= 1;
4152 rval
= qla83xx_restart_nic_firmware(vha
);
4154 /* NIC Core reset failed. */
4155 ql_log(ql_log_warn
, vha
, 0x5071,
4156 "Failed to restart nic firmware\n");
4158 ql_dbg(ql_dbg_p3p
, vha
, 0xb084,
4159 "Restarted NIC firmware successfully.\n");
4160 ha
->flags
.nic_core_reset_hdlr_active
= 0;
4168 * qla2x00_quiesce_io
4169 * Description: This function will block the new I/Os
4170 * Its not aborting any I/Os as context
4171 * is not destroyed during quiescence
4172 * Arguments: scsi_qla_host_t
4176 qla2x00_quiesce_io(scsi_qla_host_t
*vha
)
4178 struct qla_hw_data
*ha
= vha
->hw
;
4179 struct scsi_qla_host
*vp
;
4181 ql_dbg(ql_dbg_dpc
, vha
, 0x401d,
4182 "Quiescing I/O - ha=%p.\n", ha
);
4184 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
4185 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
4186 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
4187 qla2x00_mark_all_devices_lost(vha
, 0);
4188 list_for_each_entry(vp
, &ha
->vp_list
, list
)
4189 qla2x00_mark_all_devices_lost(vp
, 0);
4191 if (!atomic_read(&vha
->loop_down_timer
))
4192 atomic_set(&vha
->loop_down_timer
,
4195 /* Wait for pending cmds to complete */
4196 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
4200 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
4202 struct qla_hw_data
*ha
= vha
->hw
;
4203 struct scsi_qla_host
*vp
;
4204 unsigned long flags
;
4207 /* For ISP82XX, driver waits for completion of the commands.
4208 * online flag should be set.
4210 if (!IS_QLA82XX(ha
))
4211 vha
->flags
.online
= 0;
4212 ha
->flags
.chip_reset_done
= 0;
4213 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
4214 vha
->qla_stats
.total_isp_aborts
++;
4216 ql_log(ql_log_info
, vha
, 0x00af,
4217 "Performing ISP error recovery - ha=%p.\n", ha
);
4219 /* For ISP82XX, reset_chip is just disabling interrupts.
4220 * Driver waits for the completion of the commands.
4221 * the interrupts need to be enabled.
4223 if (!IS_QLA82XX(ha
))
4224 ha
->isp_ops
->reset_chip(vha
);
4226 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
4227 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
4228 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
4229 qla2x00_mark_all_devices_lost(vha
, 0);
4231 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4232 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
4233 atomic_inc(&vp
->vref_count
);
4234 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4236 qla2x00_mark_all_devices_lost(vp
, 0);
4238 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4239 atomic_dec(&vp
->vref_count
);
4241 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4243 if (!atomic_read(&vha
->loop_down_timer
))
4244 atomic_set(&vha
->loop_down_timer
,
4248 /* Clear all async request states across all VPs. */
4249 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
4250 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
4251 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4252 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
4253 atomic_inc(&vp
->vref_count
);
4254 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4256 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
4257 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
4259 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4260 atomic_dec(&vp
->vref_count
);
4262 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4264 if (!ha
->flags
.eeh_busy
) {
4265 /* Make sure for ISP 82XX IO DMA is complete */
4266 if (IS_QLA82XX(ha
)) {
4267 qla82xx_chip_reset_cleanup(vha
);
4268 ql_log(ql_log_info
, vha
, 0x00b4,
4269 "Done chip reset cleanup.\n");
4271 /* Done waiting for pending commands.
4272 * Reset the online flag.
4274 vha
->flags
.online
= 0;
4277 /* Requeue all commands in outstanding command list. */
4278 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
4284 * Resets ISP and aborts all outstanding commands.
4287 * ha = adapter block pointer.
4293 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
4297 struct qla_hw_data
*ha
= vha
->hw
;
4298 struct scsi_qla_host
*vp
;
4299 struct req_que
*req
= ha
->req_q_map
[0];
4300 unsigned long flags
;
4302 if (IS_QLA8031(ha
)) {
4303 ql_dbg(ql_dbg_p3p
, vha
, 0xb05c,
4304 "Clearing fcoe driver presence.\n");
4305 if (qla83xx_clear_drv_presence(vha
) != QLA_SUCCESS
)
4306 ql_dbg(ql_dbg_p3p
, vha
, 0xb073,
4307 "Erro while clearing DRV-Presence.\n");
4310 if (vha
->flags
.online
) {
4311 qla2x00_abort_isp_cleanup(vha
);
4313 if (unlikely(pci_channel_offline(ha
->pdev
) &&
4314 ha
->flags
.pci_channel_io_perm_failure
)) {
4315 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4320 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
4322 ha
->isp_ops
->nvram_config(vha
);
4324 if (!qla2x00_restart_isp(vha
)) {
4325 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4327 if (!atomic_read(&vha
->loop_down_timer
)) {
4329 * Issue marker command only when we are going
4330 * to start the I/O .
4332 vha
->marker_needed
= 1;
4335 vha
->flags
.online
= 1;
4337 ha
->isp_ops
->enable_intrs(ha
);
4339 ha
->isp_abort_cnt
= 0;
4340 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4342 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
4343 qla2x00_get_fw_version(vha
);
4345 ha
->flags
.fce_enabled
= 1;
4347 fce_calc_size(ha
->fce_bufs
));
4348 rval
= qla2x00_enable_fce_trace(vha
,
4349 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
4352 ql_log(ql_log_warn
, vha
, 0x8033,
4353 "Unable to reinitialize FCE "
4355 ha
->flags
.fce_enabled
= 0;
4360 memset(ha
->eft
, 0, EFT_SIZE
);
4361 rval
= qla2x00_enable_eft_trace(vha
,
4362 ha
->eft_dma
, EFT_NUM_BUFFERS
);
4364 ql_log(ql_log_warn
, vha
, 0x8034,
4365 "Unable to reinitialize EFT "
4369 } else { /* failed the ISP abort */
4370 vha
->flags
.online
= 1;
4371 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
4372 if (ha
->isp_abort_cnt
== 0) {
4373 ql_log(ql_log_fatal
, vha
, 0x8035,
4374 "ISP error recover failed - "
4375 "board disabled.\n");
4377 * The next call disables the board
4380 ha
->isp_ops
->reset_adapter(vha
);
4381 vha
->flags
.online
= 0;
4382 clear_bit(ISP_ABORT_RETRY
,
4385 } else { /* schedule another ISP abort */
4386 ha
->isp_abort_cnt
--;
4387 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
4388 "ISP abort - retry remaining %d.\n",
4393 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
4394 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
4395 "ISP error recovery - retrying (%d) "
4396 "more times.\n", ha
->isp_abort_cnt
);
4397 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4405 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
4407 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4408 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
4410 atomic_inc(&vp
->vref_count
);
4411 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4413 qla2x00_vp_abort_isp(vp
);
4415 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4416 atomic_dec(&vp
->vref_count
);
4419 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4421 if (IS_QLA8031(ha
)) {
4422 ql_dbg(ql_dbg_p3p
, vha
, 0xb05d,
4423 "Setting back fcoe driver presence.\n");
4424 if (qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
)
4425 ql_dbg(ql_dbg_p3p
, vha
, 0xb074,
4426 "Error while setting DRV-Presence.\n");
4429 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
4437 * qla2x00_restart_isp
4438 * restarts the ISP after a reset
4441 * ha = adapter block pointer.
4447 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
4451 struct qla_hw_data
*ha
= vha
->hw
;
4452 struct req_que
*req
= ha
->req_q_map
[0];
4453 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4454 unsigned long flags
;
4456 /* If firmware needs to be loaded */
4457 if (qla2x00_isp_firmware(vha
)) {
4458 vha
->flags
.online
= 0;
4459 status
= ha
->isp_ops
->chip_diag(vha
);
4461 status
= qla2x00_setup_chip(vha
);
4464 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
4465 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4466 ha
->flags
.chip_reset_done
= 1;
4467 /* Initialize the queues in use */
4468 qla25xx_init_queues(ha
);
4470 status
= qla2x00_fw_ready(vha
);
4472 ql_dbg(ql_dbg_taskm
, vha
, 0x8031,
4473 "Start configure loop status = %d.\n", status
);
4475 /* Issue a marker after FW becomes ready. */
4476 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4478 vha
->flags
.online
= 1;
4481 * Process any ATIO queue entries that came in
4482 * while we weren't online.
4484 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4485 if (qla_tgt_mode_enabled(vha
))
4486 qlt_24xx_process_atio_queue(vha
);
4487 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4489 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4492 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4493 qla2x00_configure_loop(vha
);
4495 } while (!atomic_read(&vha
->loop_down_timer
) &&
4496 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
4497 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
4501 /* if no cable then assume it's good */
4502 if ((vha
->device_flags
& DFLG_NO_CABLE
))
4505 ql_dbg(ql_dbg_taskm
, vha
, 0x8032,
4506 "Configure loop done, status = 0x%x.\n", status
);
4512 qla25xx_init_queues(struct qla_hw_data
*ha
)
4514 struct rsp_que
*rsp
= NULL
;
4515 struct req_que
*req
= NULL
;
4516 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4520 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
4521 rsp
= ha
->rsp_q_map
[i
];
4523 rsp
->options
&= ~BIT_0
;
4524 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
4525 if (ret
!= QLA_SUCCESS
)
4526 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
4527 "%s Rsp que: %d init failed.\n",
4530 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
4531 "%s Rsp que: %d inited.\n",
4535 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
4536 req
= ha
->req_q_map
[i
];
4538 /* Clear outstanding commands array. */
4539 req
->options
&= ~BIT_0
;
4540 ret
= qla25xx_init_req_que(base_vha
, req
);
4541 if (ret
!= QLA_SUCCESS
)
4542 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
4543 "%s Req que: %d init failed.\n",
4546 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
4547 "%s Req que: %d inited.\n",
4555 * qla2x00_reset_adapter
4559 * ha = adapter block pointer.
4562 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
4564 unsigned long flags
= 0;
4565 struct qla_hw_data
*ha
= vha
->hw
;
4566 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4568 vha
->flags
.online
= 0;
4569 ha
->isp_ops
->disable_intrs(ha
);
4571 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4572 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
4573 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4574 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
4575 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4576 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4580 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
4582 unsigned long flags
= 0;
4583 struct qla_hw_data
*ha
= vha
->hw
;
4584 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
4589 vha
->flags
.online
= 0;
4590 ha
->isp_ops
->disable_intrs(ha
);
4592 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4593 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
4594 RD_REG_DWORD(®
->hccr
);
4595 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
4596 RD_REG_DWORD(®
->hccr
);
4597 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4599 if (IS_NOPOLLING_TYPE(ha
))
4600 ha
->isp_ops
->enable_intrs(ha
);
4603 /* On sparc systems, obtain port and node WWN from firmware
4606 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
4607 struct nvram_24xx
*nv
)
4610 struct qla_hw_data
*ha
= vha
->hw
;
4611 struct pci_dev
*pdev
= ha
->pdev
;
4612 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4616 val
= of_get_property(dp
, "port-wwn", &len
);
4617 if (val
&& len
>= WWN_SIZE
)
4618 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4620 val
= of_get_property(dp
, "node-wwn", &len
);
4621 if (val
&& len
>= WWN_SIZE
)
4622 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4627 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
4630 struct init_cb_24xx
*icb
;
4631 struct nvram_24xx
*nv
;
4633 uint8_t *dptr1
, *dptr2
;
4636 struct qla_hw_data
*ha
= vha
->hw
;
4639 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
4642 /* Determine NVRAM starting address. */
4643 if (ha
->flags
.port0
) {
4644 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
4645 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
4647 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
4648 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
4650 ha
->nvram_size
= sizeof(struct nvram_24xx
);
4651 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4653 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
4655 /* Get VPD data into cache */
4656 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4657 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
4658 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
4660 /* Get NVRAM data into cache and calculate checksum. */
4661 dptr
= (uint32_t *)nv
;
4662 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
4664 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4665 chksum
+= le32_to_cpu(*dptr
++);
4667 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
4668 "Contents of NVRAM\n");
4669 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
4670 (uint8_t *)nv
, ha
->nvram_size
);
4672 /* Bad NVRAM data, set defaults parameters. */
4673 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4674 || nv
->id
[3] != ' ' ||
4675 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4676 /* Reset NVRAM data. */
4677 ql_log(ql_log_warn
, vha
, 0x006b,
4678 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
4679 "version=0x%x.\n", chksum
, nv
->id
[0], nv
->nvram_version
);
4680 ql_log(ql_log_warn
, vha
, 0x006c,
4681 "Falling back to functioning (yet invalid -- WWPN) "
4685 * Set default initialization control block.
4687 memset(nv
, 0, ha
->nvram_size
);
4688 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4689 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4690 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4691 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4692 nv
->exchange_count
= __constant_cpu_to_le16(0);
4693 nv
->hard_address
= __constant_cpu_to_le16(124);
4694 nv
->port_name
[0] = 0x21;
4695 nv
->port_name
[1] = 0x00 + ha
->port_no
;
4696 nv
->port_name
[2] = 0x00;
4697 nv
->port_name
[3] = 0xe0;
4698 nv
->port_name
[4] = 0x8b;
4699 nv
->port_name
[5] = 0x1c;
4700 nv
->port_name
[6] = 0x55;
4701 nv
->port_name
[7] = 0x86;
4702 nv
->node_name
[0] = 0x20;
4703 nv
->node_name
[1] = 0x00;
4704 nv
->node_name
[2] = 0x00;
4705 nv
->node_name
[3] = 0xe0;
4706 nv
->node_name
[4] = 0x8b;
4707 nv
->node_name
[5] = 0x1c;
4708 nv
->node_name
[6] = 0x55;
4709 nv
->node_name
[7] = 0x86;
4710 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
4711 nv
->login_retry_count
= __constant_cpu_to_le16(8);
4712 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
4713 nv
->login_timeout
= __constant_cpu_to_le16(0);
4714 nv
->firmware_options_1
=
4715 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
4716 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
4717 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4718 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
4719 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
4720 nv
->efi_parameters
= __constant_cpu_to_le32(0);
4721 nv
->reset_delay
= 5;
4722 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
4723 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
4724 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
4729 if (!qla_ini_mode_enabled(vha
)) {
4730 /* Don't enable full login after initial LIP */
4731 nv
->firmware_options_1
&= __constant_cpu_to_le32(~BIT_13
);
4732 /* Don't enable LIP full login for initiator */
4733 nv
->host_p
&= __constant_cpu_to_le32(~BIT_10
);
4736 qlt_24xx_config_nvram_stage1(vha
, nv
);
4738 /* Reset Initialization control block */
4739 memset(icb
, 0, ha
->init_cb_size
);
4741 /* Copy 1st segment. */
4742 dptr1
= (uint8_t *)icb
;
4743 dptr2
= (uint8_t *)&nv
->version
;
4744 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
4746 *dptr1
++ = *dptr2
++;
4748 icb
->login_retry_count
= nv
->login_retry_count
;
4749 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
4751 /* Copy 2nd segment. */
4752 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
4753 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
4754 cnt
= (uint8_t *)&icb
->reserved_3
-
4755 (uint8_t *)&icb
->interrupt_delay_timer
;
4757 *dptr1
++ = *dptr2
++;
4760 * Setup driver NVRAM options.
4762 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
4765 qlt_24xx_config_nvram_stage2(vha
, icb
);
4767 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
4768 /* Use alternate WWN? */
4769 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4770 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4773 /* Prepare nodename */
4774 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
4776 * Firmware will apply the following mask if the nodename was
4779 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4780 icb
->node_name
[0] &= 0xF0;
4783 /* Set host adapter parameters. */
4784 ha
->flags
.disable_risc_code_load
= 0;
4785 ha
->flags
.enable_lip_reset
= 0;
4786 ha
->flags
.enable_lip_full_login
=
4787 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
4788 ha
->flags
.enable_target_reset
=
4789 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
4790 ha
->flags
.enable_led_scheme
= 0;
4791 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
4793 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
4794 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4796 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
4797 sizeof(ha
->fw_seriallink_options24
));
4799 /* save HBA serial number */
4800 ha
->serial0
= icb
->port_name
[5];
4801 ha
->serial1
= icb
->port_name
[6];
4802 ha
->serial2
= icb
->port_name
[7];
4803 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4804 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4806 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4808 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
4810 /* Set minimum login_timeout to 4 seconds. */
4811 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
4812 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
4813 if (le16_to_cpu(nv
->login_timeout
) < 4)
4814 nv
->login_timeout
= __constant_cpu_to_le16(4);
4815 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
4816 icb
->login_timeout
= nv
->login_timeout
;
4818 /* Set minimum RATOV to 100 tenths of a second. */
4821 ha
->loop_reset_delay
= nv
->reset_delay
;
4823 /* Link Down Timeout = 0:
4825 * When Port Down timer expires we will start returning
4826 * I/O's to OS with "DID_NO_CONNECT".
4828 * Link Down Timeout != 0:
4830 * The driver waits for the link to come up after link down
4831 * before returning I/Os to OS with "DID_NO_CONNECT".
4833 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
4834 ha
->loop_down_abort_time
=
4835 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4837 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
4838 ha
->loop_down_abort_time
=
4839 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4842 /* Need enough time to try and get the port back. */
4843 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
4844 if (qlport_down_retry
)
4845 ha
->port_down_retry_count
= qlport_down_retry
;
4847 /* Set login_retry_count */
4848 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
4849 if (ha
->port_down_retry_count
==
4850 le16_to_cpu(nv
->port_down_retry_count
) &&
4851 ha
->port_down_retry_count
> 3)
4852 ha
->login_retry_count
= ha
->port_down_retry_count
;
4853 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4854 ha
->login_retry_count
= ha
->port_down_retry_count
;
4855 if (ql2xloginretrycount
)
4856 ha
->login_retry_count
= ql2xloginretrycount
;
4859 if (!vha
->flags
.init_done
) {
4860 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
4861 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4862 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
4863 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
4865 icb
->firmware_options_2
&= __constant_cpu_to_le32(
4866 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
4867 vha
->flags
.process_response_queue
= 0;
4868 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4869 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4871 ql_log(ql_log_info
, vha
, 0x006f,
4872 "ZIO mode %d enabled; timer delay (%d us).\n",
4873 ha
->zio_mode
, ha
->zio_timer
* 100);
4875 icb
->firmware_options_2
|= cpu_to_le32(
4876 (uint32_t)ha
->zio_mode
);
4877 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
4878 vha
->flags
.process_response_queue
= 1;
4882 ql_log(ql_log_warn
, vha
, 0x0070,
4883 "NVRAM configuration failed.\n");
4889 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
4892 int rval
= QLA_SUCCESS
;
4893 int segments
, fragment
;
4894 uint32_t *dcode
, dlen
;
4898 struct qla_hw_data
*ha
= vha
->hw
;
4899 struct req_que
*req
= ha
->req_q_map
[0];
4901 ql_dbg(ql_dbg_init
, vha
, 0x008b,
4902 "FW: Loading firmware from flash (%x).\n", faddr
);
4906 segments
= FA_RISC_CODE_SEGMENTS
;
4907 dcode
= (uint32_t *)req
->ring
;
4910 /* Validate firmware image by checking version. */
4911 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
4912 for (i
= 0; i
< 4; i
++)
4913 dcode
[i
] = be32_to_cpu(dcode
[i
]);
4914 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4915 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4916 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4918 ql_log(ql_log_fatal
, vha
, 0x008c,
4919 "Unable to verify the integrity of flash firmware "
4921 ql_log(ql_log_fatal
, vha
, 0x008d,
4922 "Firmware data: %08x %08x %08x %08x.\n",
4923 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
4925 return QLA_FUNCTION_FAILED
;
4928 while (segments
&& rval
== QLA_SUCCESS
) {
4929 /* Read segment's load information. */
4930 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
4932 risc_addr
= be32_to_cpu(dcode
[2]);
4933 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4934 risc_size
= be32_to_cpu(dcode
[3]);
4937 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4938 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4939 if (dlen
> risc_size
)
4942 ql_dbg(ql_dbg_init
, vha
, 0x008e,
4943 "Loading risc segment@ risc addr %x "
4944 "number of dwords 0x%x offset 0x%x.\n",
4945 risc_addr
, dlen
, faddr
);
4947 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
4948 for (i
= 0; i
< dlen
; i
++)
4949 dcode
[i
] = swab32(dcode
[i
]);
4951 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4954 ql_log(ql_log_fatal
, vha
, 0x008f,
4955 "Failed to load segment %d of firmware.\n",
4973 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4976 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4980 uint16_t *wcode
, *fwcode
;
4981 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
4982 struct fw_blob
*blob
;
4983 struct qla_hw_data
*ha
= vha
->hw
;
4984 struct req_que
*req
= ha
->req_q_map
[0];
4986 /* Load firmware blob. */
4987 blob
= qla2x00_request_firmware(vha
);
4989 ql_log(ql_log_info
, vha
, 0x0083,
4990 "Fimware image unavailable.\n");
4991 ql_log(ql_log_info
, vha
, 0x0084,
4992 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
4993 return QLA_FUNCTION_FAILED
;
4998 wcode
= (uint16_t *)req
->ring
;
5000 fwcode
= (uint16_t *)blob
->fw
->data
;
5003 /* Validate firmware image by checking version. */
5004 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
5005 ql_log(ql_log_fatal
, vha
, 0x0085,
5006 "Unable to verify integrity of firmware image (%Zd).\n",
5008 goto fail_fw_integrity
;
5010 for (i
= 0; i
< 4; i
++)
5011 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
5012 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
5013 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
5014 wcode
[2] == 0 && wcode
[3] == 0)) {
5015 ql_log(ql_log_fatal
, vha
, 0x0086,
5016 "Unable to verify integrity of firmware image.\n");
5017 ql_log(ql_log_fatal
, vha
, 0x0087,
5018 "Firmware data: %04x %04x %04x %04x.\n",
5019 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
5020 goto fail_fw_integrity
;
5024 while (*seg
&& rval
== QLA_SUCCESS
) {
5026 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
5027 risc_size
= be16_to_cpu(fwcode
[3]);
5029 /* Validate firmware image size. */
5030 fwclen
+= risc_size
* sizeof(uint16_t);
5031 if (blob
->fw
->size
< fwclen
) {
5032 ql_log(ql_log_fatal
, vha
, 0x0088,
5033 "Unable to verify integrity of firmware image "
5034 "(%Zd).\n", blob
->fw
->size
);
5035 goto fail_fw_integrity
;
5039 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
5040 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
5041 if (wlen
> risc_size
)
5043 ql_dbg(ql_dbg_init
, vha
, 0x0089,
5044 "Loading risc segment@ risc addr %x number of "
5045 "words 0x%x.\n", risc_addr
, wlen
);
5047 for (i
= 0; i
< wlen
; i
++)
5048 wcode
[i
] = swab16(fwcode
[i
]);
5050 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
5053 ql_log(ql_log_fatal
, vha
, 0x008a,
5054 "Failed to load segment %d of firmware.\n",
5071 return QLA_FUNCTION_FAILED
;
5075 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
5078 int segments
, fragment
;
5079 uint32_t *dcode
, dlen
;
5083 struct fw_blob
*blob
;
5084 uint32_t *fwcode
, fwclen
;
5085 struct qla_hw_data
*ha
= vha
->hw
;
5086 struct req_que
*req
= ha
->req_q_map
[0];
5088 /* Load firmware blob. */
5089 blob
= qla2x00_request_firmware(vha
);
5091 ql_log(ql_log_warn
, vha
, 0x0090,
5092 "Fimware image unavailable.\n");
5093 ql_log(ql_log_warn
, vha
, 0x0091,
5094 "Firmware images can be retrieved from: "
5097 return QLA_FUNCTION_FAILED
;
5100 ql_dbg(ql_dbg_init
, vha
, 0x0092,
5101 "FW: Loading via request-firmware.\n");
5105 segments
= FA_RISC_CODE_SEGMENTS
;
5106 dcode
= (uint32_t *)req
->ring
;
5108 fwcode
= (uint32_t *)blob
->fw
->data
;
5111 /* Validate firmware image by checking version. */
5112 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
5113 ql_log(ql_log_fatal
, vha
, 0x0093,
5114 "Unable to verify integrity of firmware image (%Zd).\n",
5116 goto fail_fw_integrity
;
5118 for (i
= 0; i
< 4; i
++)
5119 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
5120 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
5121 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
5122 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
5124 ql_log(ql_log_fatal
, vha
, 0x0094,
5125 "Unable to verify integrity of firmware image (%Zd).\n",
5127 ql_log(ql_log_fatal
, vha
, 0x0095,
5128 "Firmware data: %08x %08x %08x %08x.\n",
5129 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
5130 goto fail_fw_integrity
;
5133 while (segments
&& rval
== QLA_SUCCESS
) {
5134 risc_addr
= be32_to_cpu(fwcode
[2]);
5135 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
5136 risc_size
= be32_to_cpu(fwcode
[3]);
5138 /* Validate firmware image size. */
5139 fwclen
+= risc_size
* sizeof(uint32_t);
5140 if (blob
->fw
->size
< fwclen
) {
5141 ql_log(ql_log_fatal
, vha
, 0x0096,
5142 "Unable to verify integrity of firmware image "
5143 "(%Zd).\n", blob
->fw
->size
);
5145 goto fail_fw_integrity
;
5149 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
5150 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
5151 if (dlen
> risc_size
)
5154 ql_dbg(ql_dbg_init
, vha
, 0x0097,
5155 "Loading risc segment@ risc addr %x "
5156 "number of dwords 0x%x.\n", risc_addr
, dlen
);
5158 for (i
= 0; i
< dlen
; i
++)
5159 dcode
[i
] = swab32(fwcode
[i
]);
5161 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
5164 ql_log(ql_log_fatal
, vha
, 0x0098,
5165 "Failed to load segment %d of firmware.\n",
5182 return QLA_FUNCTION_FAILED
;
5186 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
5190 if (ql2xfwloadbin
== 1)
5191 return qla81xx_load_risc(vha
, srisc_addr
);
5195 * 1) Firmware via request-firmware interface (.bin file).
5196 * 2) Firmware residing in flash.
5198 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
5199 if (rval
== QLA_SUCCESS
)
5202 return qla24xx_load_risc_flash(vha
, srisc_addr
,
5203 vha
->hw
->flt_region_fw
);
5207 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
5210 struct qla_hw_data
*ha
= vha
->hw
;
5212 if (ql2xfwloadbin
== 2)
5217 * 1) Firmware residing in flash.
5218 * 2) Firmware via request-firmware interface (.bin file).
5219 * 3) Golden-Firmware residing in flash -- limited operation.
5221 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
5222 if (rval
== QLA_SUCCESS
)
5226 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
5227 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
5230 ql_log(ql_log_info
, vha
, 0x0099,
5231 "Attempting to fallback to golden firmware.\n");
5232 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
5233 if (rval
!= QLA_SUCCESS
)
5236 ql_log(ql_log_info
, vha
, 0x009a, "Update operational firmware.\n");
5237 ha
->flags
.running_gold_fw
= 1;
5242 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
5245 struct qla_hw_data
*ha
= vha
->hw
;
5247 if (ha
->flags
.pci_channel_io_perm_failure
)
5249 if (!IS_FWI2_CAPABLE(ha
))
5251 if (!ha
->fw_major_version
)
5254 ret
= qla2x00_stop_firmware(vha
);
5255 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
5256 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
5257 ha
->isp_ops
->reset_chip(vha
);
5258 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
5260 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
5262 ql_log(ql_log_info
, vha
, 0x8015,
5263 "Attempting retry of stop-firmware command.\n");
5264 ret
= qla2x00_stop_firmware(vha
);
5269 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
5271 int rval
= QLA_SUCCESS
;
5273 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5274 struct qla_hw_data
*ha
= vha
->hw
;
5275 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
5276 struct req_que
*req
;
5277 struct rsp_que
*rsp
;
5282 rval
= qla2x00_fw_ready(base_vha
);
5283 if (ha
->flags
.cpu_affinity_enabled
)
5284 req
= ha
->req_q_map
[0];
5289 if (rval
== QLA_SUCCESS
) {
5290 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5291 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5294 vha
->flags
.management_server_logged_in
= 0;
5296 /* Login to SNS first */
5297 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
5299 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
5300 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
5301 ql_dbg(ql_dbg_init
, vha
, 0x0120,
5302 "Failed SNS login: loop_id=%x, rval2=%d\n",
5305 ql_dbg(ql_dbg_init
, vha
, 0x0103,
5306 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5307 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5308 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
5309 return (QLA_FUNCTION_FAILED
);
5312 atomic_set(&vha
->loop_down_timer
, 0);
5313 atomic_set(&vha
->loop_state
, LOOP_UP
);
5314 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5315 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5316 rval
= qla2x00_loop_resync(base_vha
);
5321 /* 84XX Support **************************************************************/
5323 static LIST_HEAD(qla_cs84xx_list
);
5324 static DEFINE_MUTEX(qla_cs84xx_mutex
);
5326 static struct qla_chip_state_84xx
*
5327 qla84xx_get_chip(struct scsi_qla_host
*vha
)
5329 struct qla_chip_state_84xx
*cs84xx
;
5330 struct qla_hw_data
*ha
= vha
->hw
;
5332 mutex_lock(&qla_cs84xx_mutex
);
5334 /* Find any shared 84xx chip. */
5335 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
5336 if (cs84xx
->bus
== ha
->pdev
->bus
) {
5337 kref_get(&cs84xx
->kref
);
5342 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
5346 kref_init(&cs84xx
->kref
);
5347 spin_lock_init(&cs84xx
->access_lock
);
5348 mutex_init(&cs84xx
->fw_update_mutex
);
5349 cs84xx
->bus
= ha
->pdev
->bus
;
5351 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
5353 mutex_unlock(&qla_cs84xx_mutex
);
5358 __qla84xx_chip_release(struct kref
*kref
)
5360 struct qla_chip_state_84xx
*cs84xx
=
5361 container_of(kref
, struct qla_chip_state_84xx
, kref
);
5363 mutex_lock(&qla_cs84xx_mutex
);
5364 list_del(&cs84xx
->list
);
5365 mutex_unlock(&qla_cs84xx_mutex
);
5370 qla84xx_put_chip(struct scsi_qla_host
*vha
)
5372 struct qla_hw_data
*ha
= vha
->hw
;
5374 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
5378 qla84xx_init_chip(scsi_qla_host_t
*vha
)
5382 struct qla_hw_data
*ha
= vha
->hw
;
5384 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
5386 rval
= qla84xx_verify_chip(vha
, status
);
5388 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
5390 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
5394 /* 81XX Support **************************************************************/
5397 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
5400 struct init_cb_81xx
*icb
;
5401 struct nvram_81xx
*nv
;
5403 uint8_t *dptr1
, *dptr2
;
5406 struct qla_hw_data
*ha
= vha
->hw
;
5409 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
5412 /* Determine NVRAM starting address. */
5413 ha
->nvram_size
= sizeof(struct nvram_81xx
);
5414 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
5416 /* Get VPD data into cache */
5417 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
5418 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
5421 /* Get NVRAM data into cache and calculate checksum. */
5422 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
5424 dptr
= (uint32_t *)nv
;
5425 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
5426 chksum
+= le32_to_cpu(*dptr
++);
5428 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
5429 "Contents of NVRAM:\n");
5430 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
5431 (uint8_t *)nv
, ha
->nvram_size
);
5433 /* Bad NVRAM data, set defaults parameters. */
5434 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
5435 || nv
->id
[3] != ' ' ||
5436 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
5437 /* Reset NVRAM data. */
5438 ql_log(ql_log_info
, vha
, 0x0073,
5439 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
5440 "version=0x%x.\n", chksum
, nv
->id
[0],
5441 le16_to_cpu(nv
->nvram_version
));
5442 ql_log(ql_log_info
, vha
, 0x0074,
5443 "Falling back to functioning (yet invalid -- WWPN) "
5447 * Set default initialization control block.
5449 memset(nv
, 0, ha
->nvram_size
);
5450 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
5451 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
5452 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
5453 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5454 nv
->exchange_count
= __constant_cpu_to_le16(0);
5455 nv
->port_name
[0] = 0x21;
5456 nv
->port_name
[1] = 0x00 + ha
->port_no
;
5457 nv
->port_name
[2] = 0x00;
5458 nv
->port_name
[3] = 0xe0;
5459 nv
->port_name
[4] = 0x8b;
5460 nv
->port_name
[5] = 0x1c;
5461 nv
->port_name
[6] = 0x55;
5462 nv
->port_name
[7] = 0x86;
5463 nv
->node_name
[0] = 0x20;
5464 nv
->node_name
[1] = 0x00;
5465 nv
->node_name
[2] = 0x00;
5466 nv
->node_name
[3] = 0xe0;
5467 nv
->node_name
[4] = 0x8b;
5468 nv
->node_name
[5] = 0x1c;
5469 nv
->node_name
[6] = 0x55;
5470 nv
->node_name
[7] = 0x86;
5471 nv
->login_retry_count
= __constant_cpu_to_le16(8);
5472 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
5473 nv
->login_timeout
= __constant_cpu_to_le16(0);
5474 nv
->firmware_options_1
=
5475 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
5476 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
5477 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
5478 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
5479 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
5480 nv
->efi_parameters
= __constant_cpu_to_le32(0);
5481 nv
->reset_delay
= 5;
5482 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
5483 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
5484 nv
->link_down_timeout
= __constant_cpu_to_le16(180);
5485 nv
->enode_mac
[0] = 0x00;
5486 nv
->enode_mac
[1] = 0xC0;
5487 nv
->enode_mac
[2] = 0xDD;
5488 nv
->enode_mac
[3] = 0x04;
5489 nv
->enode_mac
[4] = 0x05;
5490 nv
->enode_mac
[5] = 0x06 + ha
->port_no
;
5495 /* Reset Initialization control block */
5496 memset(icb
, 0, ha
->init_cb_size
);
5498 /* Copy 1st segment. */
5499 dptr1
= (uint8_t *)icb
;
5500 dptr2
= (uint8_t *)&nv
->version
;
5501 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
5503 *dptr1
++ = *dptr2
++;
5505 icb
->login_retry_count
= nv
->login_retry_count
;
5507 /* Copy 2nd segment. */
5508 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
5509 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
5510 cnt
= (uint8_t *)&icb
->reserved_5
-
5511 (uint8_t *)&icb
->interrupt_delay_timer
;
5513 *dptr1
++ = *dptr2
++;
5515 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
5516 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5517 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
5518 icb
->enode_mac
[0] = 0x00;
5519 icb
->enode_mac
[1] = 0xC0;
5520 icb
->enode_mac
[2] = 0xDD;
5521 icb
->enode_mac
[3] = 0x04;
5522 icb
->enode_mac
[4] = 0x05;
5523 icb
->enode_mac
[5] = 0x06 + ha
->port_no
;
5526 /* Use extended-initialization control block. */
5527 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
5530 * Setup driver NVRAM options.
5532 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
5535 /* Use alternate WWN? */
5536 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
5537 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
5538 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
5541 /* Prepare nodename */
5542 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
5544 * Firmware will apply the following mask if the nodename was
5547 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
5548 icb
->node_name
[0] &= 0xF0;
5551 /* Set host adapter parameters. */
5552 ha
->flags
.disable_risc_code_load
= 0;
5553 ha
->flags
.enable_lip_reset
= 0;
5554 ha
->flags
.enable_lip_full_login
=
5555 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
5556 ha
->flags
.enable_target_reset
=
5557 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
5558 ha
->flags
.enable_led_scheme
= 0;
5559 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
5561 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
5562 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
5564 /* save HBA serial number */
5565 ha
->serial0
= icb
->port_name
[5];
5566 ha
->serial1
= icb
->port_name
[6];
5567 ha
->serial2
= icb
->port_name
[7];
5568 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
5569 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
5571 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5573 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
5575 /* Set minimum login_timeout to 4 seconds. */
5576 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
5577 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
5578 if (le16_to_cpu(nv
->login_timeout
) < 4)
5579 nv
->login_timeout
= __constant_cpu_to_le16(4);
5580 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
5581 icb
->login_timeout
= nv
->login_timeout
;
5583 /* Set minimum RATOV to 100 tenths of a second. */
5586 ha
->loop_reset_delay
= nv
->reset_delay
;
5588 /* Link Down Timeout = 0:
5590 * When Port Down timer expires we will start returning
5591 * I/O's to OS with "DID_NO_CONNECT".
5593 * Link Down Timeout != 0:
5595 * The driver waits for the link to come up after link down
5596 * before returning I/Os to OS with "DID_NO_CONNECT".
5598 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
5599 ha
->loop_down_abort_time
=
5600 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
5602 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
5603 ha
->loop_down_abort_time
=
5604 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
5607 /* Need enough time to try and get the port back. */
5608 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
5609 if (qlport_down_retry
)
5610 ha
->port_down_retry_count
= qlport_down_retry
;
5612 /* Set login_retry_count */
5613 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
5614 if (ha
->port_down_retry_count
==
5615 le16_to_cpu(nv
->port_down_retry_count
) &&
5616 ha
->port_down_retry_count
> 3)
5617 ha
->login_retry_count
= ha
->port_down_retry_count
;
5618 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
5619 ha
->login_retry_count
= ha
->port_down_retry_count
;
5620 if (ql2xloginretrycount
)
5621 ha
->login_retry_count
= ql2xloginretrycount
;
5623 /* if not running MSI-X we need handshaking on interrupts */
5624 if (!vha
->hw
->flags
.msix_enabled
&& IS_QLA83XX(ha
))
5625 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_22
);
5628 if (!vha
->flags
.init_done
) {
5629 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
5630 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
5631 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
5632 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
5634 icb
->firmware_options_2
&= __constant_cpu_to_le32(
5635 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
5636 vha
->flags
.process_response_queue
= 0;
5637 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
5638 ha
->zio_mode
= QLA_ZIO_MODE_6
;
5640 ql_log(ql_log_info
, vha
, 0x0075,
5641 "ZIO mode %d enabled; timer delay (%d us).\n",
5643 ha
->zio_timer
* 100);
5645 icb
->firmware_options_2
|= cpu_to_le32(
5646 (uint32_t)ha
->zio_mode
);
5647 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
5648 vha
->flags
.process_response_queue
= 1;
5652 ql_log(ql_log_warn
, vha
, 0x0076,
5653 "NVRAM configuration failed.\n");
5659 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
5663 struct qla_hw_data
*ha
= vha
->hw
;
5664 struct req_que
*req
= ha
->req_q_map
[0];
5665 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
5666 struct scsi_qla_host
*vp
;
5667 unsigned long flags
;
5669 status
= qla2x00_init_rings(vha
);
5671 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5672 ha
->flags
.chip_reset_done
= 1;
5674 status
= qla2x00_fw_ready(vha
);
5676 ql_log(ql_log_info
, vha
, 0x803c,
5677 "Start configure loop, status =%d.\n", status
);
5679 /* Issue a marker after FW becomes ready. */
5680 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5682 vha
->flags
.online
= 1;
5683 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5686 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5687 qla2x00_configure_loop(vha
);
5689 } while (!atomic_read(&vha
->loop_down_timer
) &&
5690 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
)) &&
5692 (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)));
5695 /* if no cable then assume it's good */
5696 if ((vha
->device_flags
& DFLG_NO_CABLE
))
5699 ql_log(ql_log_info
, vha
, 0x8000,
5700 "Configure loop done, status = 0x%x.\n", status
);
5704 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5706 if (!atomic_read(&vha
->loop_down_timer
)) {
5708 * Issue marker command only when we are going
5709 * to start the I/O .
5711 vha
->marker_needed
= 1;
5714 vha
->flags
.online
= 1;
5716 ha
->isp_ops
->enable_intrs(ha
);
5718 ha
->isp_abort_cnt
= 0;
5719 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5721 /* Update the firmware version */
5722 status
= qla82xx_check_md_needed(vha
);
5725 ha
->flags
.fce_enabled
= 1;
5727 fce_calc_size(ha
->fce_bufs
));
5728 rval
= qla2x00_enable_fce_trace(vha
,
5729 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
5732 ql_log(ql_log_warn
, vha
, 0x8001,
5733 "Unable to reinitialize FCE (%d).\n",
5735 ha
->flags
.fce_enabled
= 0;
5740 memset(ha
->eft
, 0, EFT_SIZE
);
5741 rval
= qla2x00_enable_eft_trace(vha
,
5742 ha
->eft_dma
, EFT_NUM_BUFFERS
);
5744 ql_log(ql_log_warn
, vha
, 0x8010,
5745 "Unable to reinitialize EFT (%d).\n",
5752 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
5753 "qla82xx_restart_isp succeeded.\n");
5755 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5756 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
5758 atomic_inc(&vp
->vref_count
);
5759 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5761 qla2x00_vp_abort_isp(vp
);
5763 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5764 atomic_dec(&vp
->vref_count
);
5767 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5770 ql_log(ql_log_warn
, vha
, 0x8016,
5771 "qla82xx_restart_isp **** FAILED ****.\n");
5778 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
5780 struct qla_hw_data
*ha
= vha
->hw
;
5785 /* Enable ETS Burst. */
5786 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
5787 ha
->fw_options
[2] |= BIT_9
;
5788 qla2x00_set_fw_options(vha
, ha
->fw_options
);
5792 * qla24xx_get_fcp_prio
5793 * Gets the fcp cmd priority value for the logged in port.
5794 * Looks for a match of the port descriptors within
5795 * each of the fcp prio config entries. If a match is found,
5796 * the tag (priority) value is returned.
5799 * vha = scsi host structure pointer.
5800 * fcport = port structure pointer.
5803 * non-zero (if found)
5810 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5813 uint8_t pid_match
, wwn_match
;
5815 uint32_t pid1
, pid2
;
5816 uint64_t wwn1
, wwn2
;
5817 struct qla_fcp_prio_entry
*pri_entry
;
5818 struct qla_hw_data
*ha
= vha
->hw
;
5820 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
5824 entries
= ha
->fcp_prio_cfg
->num_entries
;
5825 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
5827 for (i
= 0; i
< entries
; i
++) {
5828 pid_match
= wwn_match
= 0;
5830 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
5835 /* check source pid for a match */
5836 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
5837 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
5838 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
5839 if (pid1
== INVALID_PORT_ID
)
5841 else if (pid1
== pid2
)
5845 /* check destination pid for a match */
5846 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
5847 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
5848 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
5849 if (pid1
== INVALID_PORT_ID
)
5851 else if (pid1
== pid2
)
5855 /* check source WWN for a match */
5856 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
5857 wwn1
= wwn_to_u64(vha
->port_name
);
5858 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
5859 if (wwn2
== (uint64_t)-1)
5861 else if (wwn1
== wwn2
)
5865 /* check destination WWN for a match */
5866 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
5867 wwn1
= wwn_to_u64(fcport
->port_name
);
5868 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
5869 if (wwn2
== (uint64_t)-1)
5871 else if (wwn1
== wwn2
)
5875 if (pid_match
== 2 || wwn_match
== 2) {
5876 /* Found a matching entry */
5877 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
5878 priority
= pri_entry
->tag
;
5889 * qla24xx_update_fcport_fcp_prio
5890 * Activates fcp priority for the logged in fc port
5893 * vha = scsi host structure pointer.
5894 * fcp = port structure pointer.
5897 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5903 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5909 if (fcport
->port_type
!= FCT_TARGET
||
5910 fcport
->loop_id
== FC_NO_LOOP_ID
)
5911 return QLA_FUNCTION_FAILED
;
5913 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
5915 return QLA_FUNCTION_FAILED
;
5917 if (IS_QLA82XX(vha
->hw
)) {
5918 fcport
->fcp_prio
= priority
& 0xf;
5922 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
5923 if (ret
== QLA_SUCCESS
) {
5924 if (fcport
->fcp_prio
!= priority
)
5925 ql_dbg(ql_dbg_user
, vha
, 0x709e,
5926 "Updated FCP_CMND priority - value=%d loop_id=%d "
5927 "port_id=%02x%02x%02x.\n", priority
,
5928 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5929 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5930 fcport
->fcp_prio
= priority
& 0xf;
5932 ql_dbg(ql_dbg_user
, vha
, 0x704f,
5933 "Unable to update FCP_CMND priority - ret=0x%x for "
5934 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
5935 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5936 fcport
->d_id
.b
.al_pa
);
5941 * qla24xx_update_all_fcp_prio
5942 * Activates fcp priority for all the logged in ports
5945 * ha = adapter block pointer.
5948 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5954 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
5959 ret
= QLA_FUNCTION_FAILED
;
5960 /* We need to set priority for all logged in ports */
5961 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5962 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);