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 -------------------------------------- */
80 static inline unsigned long
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 * qla2x00_initialize_adapter
437 * ha = adapter block pointer.
443 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
446 struct qla_hw_data
*ha
= vha
->hw
;
447 struct req_que
*req
= ha
->req_q_map
[0];
449 /* Clear adapter flags. */
450 vha
->flags
.online
= 0;
451 ha
->flags
.chip_reset_done
= 0;
452 vha
->flags
.reset_active
= 0;
453 ha
->flags
.pci_channel_io_perm_failure
= 0;
454 ha
->flags
.eeh_busy
= 0;
455 ha
->flags
.thermal_supported
= 1;
456 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
457 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
458 vha
->device_flags
= DFLG_NO_CABLE
;
460 vha
->flags
.management_server_logged_in
= 0;
461 vha
->marker_needed
= 0;
462 ha
->isp_abort_cnt
= 0;
463 ha
->beacon_blink_led
= 0;
465 set_bit(0, ha
->req_qid_map
);
466 set_bit(0, ha
->rsp_qid_map
);
468 ql_dbg(ql_dbg_init
, vha
, 0x0040,
469 "Configuring PCI space...\n");
470 rval
= ha
->isp_ops
->pci_config(vha
);
472 ql_log(ql_log_warn
, vha
, 0x0044,
473 "Unable to configure PCI space.\n");
477 ha
->isp_ops
->reset_chip(vha
);
479 rval
= qla2xxx_get_flash_info(vha
);
481 ql_log(ql_log_fatal
, vha
, 0x004f,
482 "Unable to validate FLASH data.\n");
486 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
487 ql_dbg(ql_dbg_init
, vha
, 0x0061,
488 "Configure NVRAM parameters...\n");
490 ha
->isp_ops
->nvram_config(vha
);
492 if (ha
->flags
.disable_serdes
) {
493 /* Mask HBA via NVRAM settings? */
494 ql_log(ql_log_info
, vha
, 0x0077,
496 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
497 vha
->port_name
[0], vha
->port_name
[1],
498 vha
->port_name
[2], vha
->port_name
[3],
499 vha
->port_name
[4], vha
->port_name
[5],
500 vha
->port_name
[6], vha
->port_name
[7]);
501 return QLA_FUNCTION_FAILED
;
504 ql_dbg(ql_dbg_init
, vha
, 0x0078,
505 "Verifying loaded RISC code...\n");
507 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
508 rval
= ha
->isp_ops
->chip_diag(vha
);
511 rval
= qla2x00_setup_chip(vha
);
516 if (IS_QLA84XX(ha
)) {
517 ha
->cs84xx
= qla84xx_get_chip(vha
);
519 ql_log(ql_log_warn
, vha
, 0x00d0,
520 "Unable to configure ISP84XX.\n");
521 return QLA_FUNCTION_FAILED
;
525 if (qla_ini_mode_enabled(vha
))
526 rval
= qla2x00_init_rings(vha
);
528 ha
->flags
.chip_reset_done
= 1;
530 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
531 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
532 rval
= qla84xx_init_chip(vha
);
533 if (rval
!= QLA_SUCCESS
) {
534 ql_log(ql_log_warn
, vha
, 0x00d4,
535 "Unable to initialize ISP84XX.\n");
536 qla84xx_put_chip(vha
);
540 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
541 qla24xx_read_fcp_prio_cfg(vha
);
547 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
550 * Returns 0 on success.
553 qla2100_pci_config(scsi_qla_host_t
*vha
)
557 struct qla_hw_data
*ha
= vha
->hw
;
558 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
560 pci_set_master(ha
->pdev
);
561 pci_try_set_mwi(ha
->pdev
);
563 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
564 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
565 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
567 pci_disable_rom(ha
->pdev
);
569 /* Get PCI bus information. */
570 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
571 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
572 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
578 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
581 * Returns 0 on success.
584 qla2300_pci_config(scsi_qla_host_t
*vha
)
587 unsigned long flags
= 0;
589 struct qla_hw_data
*ha
= vha
->hw
;
590 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
592 pci_set_master(ha
->pdev
);
593 pci_try_set_mwi(ha
->pdev
);
595 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
596 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
598 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
599 w
&= ~PCI_COMMAND_INTX_DISABLE
;
600 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
603 * If this is a 2300 card and not 2312, reset the
604 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
605 * the 2310 also reports itself as a 2300 so we need to get the
606 * fb revision level -- a 6 indicates it really is a 2300 and
609 if (IS_QLA2300(ha
)) {
610 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
613 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
614 for (cnt
= 0; cnt
< 30000; cnt
++) {
615 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
621 /* Select FPM registers. */
622 WRT_REG_WORD(®
->ctrl_status
, 0x20);
623 RD_REG_WORD(®
->ctrl_status
);
625 /* Get the fb rev level */
626 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
628 if (ha
->fb_rev
== FPM_2300
)
629 pci_clear_mwi(ha
->pdev
);
631 /* Deselect FPM registers. */
632 WRT_REG_WORD(®
->ctrl_status
, 0x0);
633 RD_REG_WORD(®
->ctrl_status
);
635 /* Release RISC module. */
636 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
637 for (cnt
= 0; cnt
< 30000; cnt
++) {
638 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
644 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
647 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
649 pci_disable_rom(ha
->pdev
);
651 /* Get PCI bus information. */
652 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
653 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
654 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
660 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
663 * Returns 0 on success.
666 qla24xx_pci_config(scsi_qla_host_t
*vha
)
669 unsigned long flags
= 0;
670 struct qla_hw_data
*ha
= vha
->hw
;
671 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
673 pci_set_master(ha
->pdev
);
674 pci_try_set_mwi(ha
->pdev
);
676 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
677 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
678 w
&= ~PCI_COMMAND_INTX_DISABLE
;
679 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
681 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
683 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
684 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
685 pcix_set_mmrbc(ha
->pdev
, 2048);
687 /* PCIe -- adjust Maximum Read Request Size (2048). */
688 if (pci_is_pcie(ha
->pdev
))
689 pcie_set_readrq(ha
->pdev
, 2048);
691 pci_disable_rom(ha
->pdev
);
693 ha
->chip_revision
= ha
->pdev
->revision
;
695 /* Get PCI bus information. */
696 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
697 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
698 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
704 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
707 * Returns 0 on success.
710 qla25xx_pci_config(scsi_qla_host_t
*vha
)
713 struct qla_hw_data
*ha
= vha
->hw
;
715 pci_set_master(ha
->pdev
);
716 pci_try_set_mwi(ha
->pdev
);
718 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
719 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
720 w
&= ~PCI_COMMAND_INTX_DISABLE
;
721 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
723 /* PCIe -- adjust Maximum Read Request Size (2048). */
724 if (pci_is_pcie(ha
->pdev
))
725 pcie_set_readrq(ha
->pdev
, 2048);
727 pci_disable_rom(ha
->pdev
);
729 ha
->chip_revision
= ha
->pdev
->revision
;
735 * qla2x00_isp_firmware() - Choose firmware image.
738 * Returns 0 on success.
741 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
744 uint16_t loop_id
, topo
, sw_cap
;
745 uint8_t domain
, area
, al_pa
;
746 struct qla_hw_data
*ha
= vha
->hw
;
748 /* Assume loading risc code */
749 rval
= QLA_FUNCTION_FAILED
;
751 if (ha
->flags
.disable_risc_code_load
) {
752 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
754 /* Verify checksum of loaded RISC code. */
755 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
756 if (rval
== QLA_SUCCESS
) {
757 /* And, verify we are not in ROM code. */
758 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
759 &area
, &domain
, &topo
, &sw_cap
);
764 ql_dbg(ql_dbg_init
, vha
, 0x007a,
765 "**** Load RISC code ****.\n");
771 * qla2x00_reset_chip() - Reset ISP chip.
774 * Returns 0 on success.
777 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
779 unsigned long flags
= 0;
780 struct qla_hw_data
*ha
= vha
->hw
;
781 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
785 if (unlikely(pci_channel_offline(ha
->pdev
)))
788 ha
->isp_ops
->disable_intrs(ha
);
790 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
792 /* Turn off master enable */
794 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
795 cmd
&= ~PCI_COMMAND_MASTER
;
796 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
798 if (!IS_QLA2100(ha
)) {
800 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
801 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
802 for (cnt
= 0; cnt
< 30000; cnt
++) {
803 if ((RD_REG_WORD(®
->hccr
) &
804 HCCR_RISC_PAUSE
) != 0)
809 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
813 /* Select FPM registers. */
814 WRT_REG_WORD(®
->ctrl_status
, 0x20);
815 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
817 /* FPM Soft Reset. */
818 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
819 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
821 /* Toggle Fpm Reset. */
822 if (!IS_QLA2200(ha
)) {
823 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
824 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
827 /* Select frame buffer registers. */
828 WRT_REG_WORD(®
->ctrl_status
, 0x10);
829 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
831 /* Reset frame buffer FIFOs. */
832 if (IS_QLA2200(ha
)) {
833 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
834 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
836 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
838 /* Read back fb_cmd until zero or 3 seconds max */
839 for (cnt
= 0; cnt
< 3000; cnt
++) {
840 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
846 /* Select RISC module registers. */
847 WRT_REG_WORD(®
->ctrl_status
, 0);
848 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
850 /* Reset RISC processor. */
851 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
852 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
854 /* Release RISC processor. */
855 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
856 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
859 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
860 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
862 /* Reset ISP chip. */
863 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
865 /* Wait for RISC to recover from reset. */
866 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
868 * It is necessary to for a delay here since the card doesn't
869 * respond to PCI reads during a reset. On some architectures
870 * this will result in an MCA.
873 for (cnt
= 30000; cnt
; cnt
--) {
874 if ((RD_REG_WORD(®
->ctrl_status
) &
875 CSR_ISP_SOFT_RESET
) == 0)
882 /* Reset RISC processor. */
883 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
885 WRT_REG_WORD(®
->semaphore
, 0);
887 /* Release RISC processor. */
888 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
889 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
891 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
892 for (cnt
= 0; cnt
< 30000; cnt
++) {
893 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
901 /* Turn on master enable */
902 cmd
|= PCI_COMMAND_MASTER
;
903 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
905 /* Disable RISC pause on FPM parity error. */
906 if (!IS_QLA2100(ha
)) {
907 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
908 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
911 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
915 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
917 * Returns 0 on success.
920 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
922 uint16_t mb
[4] = {0x1010, 0, 1, 0};
924 if (!IS_QLA81XX(vha
->hw
))
927 return qla81xx_write_mpi_register(vha
, mb
);
931 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
934 * Returns 0 on success.
937 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
939 unsigned long flags
= 0;
940 struct qla_hw_data
*ha
= vha
->hw
;
941 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
944 static int abts_cnt
; /* ISP abort retry counts */
946 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
949 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
950 for (cnt
= 0; cnt
< 30000; cnt
++) {
951 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
957 WRT_REG_DWORD(®
->ctrl_status
,
958 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
959 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
962 /* Wait for firmware to complete NVRAM accesses. */
963 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
964 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
966 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
970 /* Wait for soft-reset to complete. */
971 d2
= RD_REG_DWORD(®
->ctrl_status
);
972 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
974 d2
= RD_REG_DWORD(®
->ctrl_status
);
978 /* If required, do an MPI FW reset now */
979 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
980 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
981 if (++abts_cnt
< 5) {
982 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
983 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
986 * We exhausted the ISP abort retries. We have to
987 * set the board offline.
990 vha
->flags
.online
= 0;
995 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
996 RD_REG_DWORD(®
->hccr
);
998 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
999 RD_REG_DWORD(®
->hccr
);
1001 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
1002 RD_REG_DWORD(®
->hccr
);
1004 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1005 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
1007 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1011 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1013 if (IS_NOPOLLING_TYPE(ha
))
1014 ha
->isp_ops
->enable_intrs(ha
);
1018 * qla24xx_reset_chip() - Reset ISP24xx chip.
1021 * Returns 0 on success.
1024 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
1026 struct qla_hw_data
*ha
= vha
->hw
;
1028 if (pci_channel_offline(ha
->pdev
) &&
1029 ha
->flags
.pci_channel_io_perm_failure
) {
1033 ha
->isp_ops
->disable_intrs(ha
);
1035 /* Perform RISC reset. */
1036 qla24xx_reset_risc(vha
);
1040 * qla2x00_chip_diag() - Test chip for proper operation.
1043 * Returns 0 on success.
1046 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
1049 struct qla_hw_data
*ha
= vha
->hw
;
1050 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1051 unsigned long flags
= 0;
1055 struct req_que
*req
= ha
->req_q_map
[0];
1057 /* Assume a failed state */
1058 rval
= QLA_FUNCTION_FAILED
;
1060 ql_dbg(ql_dbg_init
, vha
, 0x007b,
1061 "Testing device at %lx.\n", (u_long
)®
->flash_address
);
1063 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1065 /* Reset ISP chip. */
1066 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1069 * We need to have a delay here since the card will not respond while
1070 * in reset causing an MCA on some architectures.
1073 data
= qla2x00_debounce_register(®
->ctrl_status
);
1074 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
1076 data
= RD_REG_WORD(®
->ctrl_status
);
1081 goto chip_diag_failed
;
1083 ql_dbg(ql_dbg_init
, vha
, 0x007c,
1084 "Reset register cleared by chip reset.\n");
1086 /* Reset RISC processor. */
1087 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
1088 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
1090 /* Workaround for QLA2312 PCI parity error */
1091 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1092 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
1093 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
1095 data
= RD_MAILBOX_REG(ha
, reg
, 0);
1102 goto chip_diag_failed
;
1104 /* Check product ID of chip */
1105 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product Id of chip.\n");
1107 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
1108 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
1109 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
1110 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
1111 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
1112 mb
[3] != PROD_ID_3
) {
1113 ql_log(ql_log_warn
, vha
, 0x0062,
1114 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1115 mb
[1], mb
[2], mb
[3]);
1117 goto chip_diag_failed
;
1119 ha
->product_id
[0] = mb
[1];
1120 ha
->product_id
[1] = mb
[2];
1121 ha
->product_id
[2] = mb
[3];
1122 ha
->product_id
[3] = mb
[4];
1124 /* Adjust fw RISC transfer size */
1125 if (req
->length
> 1024)
1126 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
1128 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
1131 if (IS_QLA2200(ha
) &&
1132 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
1133 /* Limit firmware transfer size with a 2200A */
1134 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
1136 ha
->device_type
|= DT_ISP2200A
;
1137 ha
->fw_transfer_size
= 128;
1140 /* Wrap Incoming Mailboxes Test. */
1141 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1143 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
1144 rval
= qla2x00_mbx_reg_test(vha
);
1146 ql_log(ql_log_warn
, vha
, 0x0080,
1147 "Failed mailbox send register test.\n");
1149 /* Flag a successful rval */
1151 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1155 ql_log(ql_log_info
, vha
, 0x0081,
1156 "Chip diagnostics **** FAILED ****.\n");
1158 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1164 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1167 * Returns 0 on success.
1170 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
1173 struct qla_hw_data
*ha
= vha
->hw
;
1174 struct req_que
*req
= ha
->req_q_map
[0];
1179 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
1181 rval
= qla2x00_mbx_reg_test(vha
);
1183 ql_log(ql_log_warn
, vha
, 0x0082,
1184 "Failed mailbox send register test.\n");
1186 /* Flag a successful rval */
1194 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
1197 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
1198 eft_size
, fce_size
, mq_size
;
1201 struct qla_hw_data
*ha
= vha
->hw
;
1202 struct req_que
*req
= ha
->req_q_map
[0];
1203 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1206 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
1207 "Firmware dump already allocated.\n");
1212 fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
1213 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1214 fixed_size
= sizeof(struct qla2100_fw_dump
);
1215 } else if (IS_QLA23XX(ha
)) {
1216 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
1217 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
1219 } else if (IS_FWI2_CAPABLE(ha
)) {
1221 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
1222 else if (IS_QLA81XX(ha
))
1223 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
1224 else if (IS_QLA25XX(ha
))
1225 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
1227 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
1228 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
1231 if (!IS_QLA83XX(ha
))
1232 mq_size
= sizeof(struct qla2xxx_mq_chain
);
1234 * Allocate maximum buffer size for all queues.
1235 * Resizing must be done at end-of-dump processing.
1237 mq_size
+= ha
->max_req_queues
*
1238 (req
->length
* sizeof(request_t
));
1239 mq_size
+= ha
->max_rsp_queues
*
1240 (rsp
->length
* sizeof(response_t
));
1242 if (ha
->tgt
.atio_q_length
)
1243 mq_size
+= ha
->tgt
.atio_q_length
* sizeof(request_t
);
1244 /* Allocate memory for Fibre Channel Event Buffer. */
1245 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
))
1248 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
1251 ql_log(ql_log_warn
, vha
, 0x00be,
1252 "Unable to allocate (%d KB) for FCE.\n",
1257 memset(tc
, 0, FCE_SIZE
);
1258 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
1259 ha
->fce_mb
, &ha
->fce_bufs
);
1261 ql_log(ql_log_warn
, vha
, 0x00bf,
1262 "Unable to initialize FCE (%d).\n", rval
);
1263 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
1265 ha
->flags
.fce_enabled
= 0;
1268 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
1269 "Allocate (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
1271 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
1272 ha
->flags
.fce_enabled
= 1;
1273 ha
->fce_dma
= tc_dma
;
1276 /* Allocate memory for Extended Trace Buffer. */
1277 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
1280 ql_log(ql_log_warn
, vha
, 0x00c1,
1281 "Unable to allocate (%d KB) for EFT.\n",
1286 memset(tc
, 0, EFT_SIZE
);
1287 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
1289 ql_log(ql_log_warn
, vha
, 0x00c2,
1290 "Unable to initialize EFT (%d).\n", rval
);
1291 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
1295 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
1296 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
1298 eft_size
= EFT_SIZE
;
1299 ha
->eft_dma
= tc_dma
;
1303 req_q_size
= req
->length
* sizeof(request_t
);
1304 rsp_q_size
= rsp
->length
* sizeof(response_t
);
1306 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
1307 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
1308 ha
->chain_offset
= dump_size
;
1309 dump_size
+= mq_size
+ fce_size
;
1311 ha
->fw_dump
= vmalloc(dump_size
);
1313 ql_log(ql_log_warn
, vha
, 0x00c4,
1314 "Unable to allocate (%d KB) for firmware dump.\n",
1318 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
1325 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
1332 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
1333 "Allocated (%d KB) for firmware dump.\n", dump_size
/ 1024);
1335 ha
->fw_dump_len
= dump_size
;
1336 ha
->fw_dump
->signature
[0] = 'Q';
1337 ha
->fw_dump
->signature
[1] = 'L';
1338 ha
->fw_dump
->signature
[2] = 'G';
1339 ha
->fw_dump
->signature
[3] = 'C';
1340 ha
->fw_dump
->version
= __constant_htonl(1);
1342 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
1343 ha
->fw_dump
->mem_size
= htonl(mem_size
);
1344 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
1345 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
1347 ha
->fw_dump
->eft_size
= htonl(eft_size
);
1348 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
1349 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
1351 ha
->fw_dump
->header_size
=
1352 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
1356 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
1358 #define MPS_MASK 0xe0
1363 if (!IS_QLA81XX(vha
->hw
))
1366 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
1367 if (rval
!= QLA_SUCCESS
) {
1368 ql_log(ql_log_warn
, vha
, 0x0105,
1369 "Unable to acquire semaphore.\n");
1373 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
1374 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
1375 if (rval
!= QLA_SUCCESS
) {
1376 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
1381 if (dc
== (dw
& MPS_MASK
))
1386 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
1387 if (rval
!= QLA_SUCCESS
) {
1388 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
1392 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
1393 if (rval
!= QLA_SUCCESS
) {
1394 ql_log(ql_log_warn
, vha
, 0x006d,
1395 "Unable to release semaphore.\n");
1403 * qla2x00_setup_chip() - Load and start RISC firmware.
1406 * Returns 0 on success.
1409 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
1412 uint32_t srisc_address
= 0;
1413 struct qla_hw_data
*ha
= vha
->hw
;
1414 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1415 unsigned long flags
;
1416 uint16_t fw_major_version
;
1418 if (IS_QLA82XX(ha
)) {
1419 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1420 if (rval
== QLA_SUCCESS
) {
1421 qla2x00_stop_firmware(vha
);
1422 goto enable_82xx_npiv
;
1427 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1428 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1429 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1430 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
1431 RD_REG_WORD(®
->hccr
);
1432 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1435 qla81xx_mpi_sync(vha
);
1437 /* Load firmware sequences */
1438 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1439 if (rval
== QLA_SUCCESS
) {
1440 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
1441 "Verifying Checksum of loaded RISC code.\n");
1443 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
1444 if (rval
== QLA_SUCCESS
) {
1445 /* Start firmware execution. */
1446 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
1447 "Starting firmware.\n");
1449 rval
= qla2x00_execute_fw(vha
, srisc_address
);
1450 /* Retrieve firmware information. */
1451 if (rval
== QLA_SUCCESS
) {
1453 fw_major_version
= ha
->fw_major_version
;
1455 qla82xx_check_md_needed(vha
);
1457 rval
= qla2x00_get_fw_version(vha
);
1458 if (rval
!= QLA_SUCCESS
)
1460 ha
->flags
.npiv_supported
= 0;
1461 if (IS_QLA2XXX_MIDTYPE(ha
) &&
1462 (ha
->fw_attributes
& BIT_2
)) {
1463 ha
->flags
.npiv_supported
= 1;
1464 if ((!ha
->max_npiv_vports
) ||
1465 ((ha
->max_npiv_vports
+ 1) %
1466 MIN_MULTI_ID_FABRIC
))
1467 ha
->max_npiv_vports
=
1468 MIN_MULTI_ID_FABRIC
- 1;
1470 qla2x00_get_resource_cnts(vha
, NULL
,
1471 &ha
->fw_xcb_count
, NULL
, NULL
,
1472 &ha
->max_npiv_vports
, NULL
);
1474 if (!fw_major_version
&& ql2xallocfwdump
1476 qla2x00_alloc_fw_dump(vha
);
1479 ql_log(ql_log_fatal
, vha
, 0x00cd,
1480 "ISP Firmware failed checksum.\n");
1485 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1486 /* Enable proper parity. */
1487 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1490 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1492 /* SRAM, Instruction RAM and GP RAM parity */
1493 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1494 RD_REG_WORD(®
->hccr
);
1495 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1499 goto skip_fac_check
;
1501 if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
1504 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
1505 if (rval
== QLA_SUCCESS
) {
1506 ha
->flags
.fac_supported
= 1;
1507 ha
->fdt_block_size
= size
<< 2;
1509 ql_log(ql_log_warn
, vha
, 0x00ce,
1510 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1511 ha
->fw_major_version
, ha
->fw_minor_version
,
1512 ha
->fw_subminor_version
);
1514 if (IS_QLA83XX(ha
)) {
1515 ha
->flags
.fac_supported
= 0;
1522 ql_log(ql_log_fatal
, vha
, 0x00cf,
1523 "Setup chip ****FAILED****.\n");
1530 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1533 * Beginning of request ring has initialization control block already built
1534 * by nvram config routine.
1536 * Returns 0 on success.
1539 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1544 rsp
->ring_ptr
= rsp
->ring
;
1545 rsp
->ring_index
= 0;
1546 rsp
->status_srb
= NULL
;
1547 pkt
= rsp
->ring_ptr
;
1548 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1549 pkt
->signature
= RESPONSE_PROCESSED
;
1555 * qla2x00_update_fw_options() - Read and process firmware options.
1558 * Returns 0 on success.
1561 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1563 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1564 struct qla_hw_data
*ha
= vha
->hw
;
1566 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1567 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1569 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1572 /* Serial Link options. */
1573 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
1574 "Serial link options.\n");
1575 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
1576 (uint8_t *)&ha
->fw_seriallink_options
,
1577 sizeof(ha
->fw_seriallink_options
));
1579 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1580 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1581 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1584 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1585 emphasis
= (ha
->fw_seriallink_options
[2] &
1586 (BIT_4
| BIT_3
)) >> 3;
1587 tx_sens
= ha
->fw_seriallink_options
[0] &
1588 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1589 rx_sens
= (ha
->fw_seriallink_options
[0] &
1590 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1591 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1592 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1595 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1596 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1597 ha
->fw_options
[10] |= BIT_5
|
1598 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1599 (tx_sens
& (BIT_1
| BIT_0
));
1602 swing
= (ha
->fw_seriallink_options
[2] &
1603 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1604 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1605 tx_sens
= ha
->fw_seriallink_options
[1] &
1606 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1607 rx_sens
= (ha
->fw_seriallink_options
[1] &
1608 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1609 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1610 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1613 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1614 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1615 ha
->fw_options
[11] |= BIT_5
|
1616 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1617 (tx_sens
& (BIT_1
| BIT_0
));
1621 /* Return command IOCBs without waiting for an ABTS to complete. */
1622 ha
->fw_options
[3] |= BIT_13
;
1625 if (ha
->flags
.enable_led_scheme
)
1626 ha
->fw_options
[2] |= BIT_12
;
1628 /* Detect ISP6312. */
1630 ha
->fw_options
[2] |= BIT_13
;
1632 /* Update firmware options. */
1633 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1637 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1640 struct qla_hw_data
*ha
= vha
->hw
;
1645 /* Update Serial Link options. */
1646 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1649 rval
= qla2x00_set_serdes_params(vha
,
1650 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1651 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1652 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1653 if (rval
!= QLA_SUCCESS
) {
1654 ql_log(ql_log_warn
, vha
, 0x0104,
1655 "Unable to update Serial Link options (%x).\n", rval
);
1660 qla2x00_config_rings(struct scsi_qla_host
*vha
)
1662 struct qla_hw_data
*ha
= vha
->hw
;
1663 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1664 struct req_que
*req
= ha
->req_q_map
[0];
1665 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1667 /* Setup ring parameters in initialization control block. */
1668 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1669 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1670 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
1671 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
1672 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1673 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1674 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1675 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1677 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1678 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1679 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1680 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1681 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1685 qla24xx_config_rings(struct scsi_qla_host
*vha
)
1687 struct qla_hw_data
*ha
= vha
->hw
;
1688 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
1689 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
1690 struct qla_msix_entry
*msix
;
1691 struct init_cb_24xx
*icb
;
1693 struct req_que
*req
= ha
->req_q_map
[0];
1694 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1696 /* Setup ring parameters in initialization control block. */
1697 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1698 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1699 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1700 icb
->request_q_length
= cpu_to_le16(req
->length
);
1701 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
1702 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1703 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1704 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1705 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1707 /* Setup ATIO queue dma pointers for target mode */
1708 icb
->atio_q_inpointer
= __constant_cpu_to_le16(0);
1709 icb
->atio_q_length
= cpu_to_le16(ha
->tgt
.atio_q_length
);
1710 icb
->atio_q_address
[0] = cpu_to_le32(LSD(ha
->tgt
.atio_dma
));
1711 icb
->atio_q_address
[1] = cpu_to_le32(MSD(ha
->tgt
.atio_dma
));
1713 if (ha
->mqenable
|| IS_QLA83XX(ha
)) {
1714 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
1715 icb
->rid
= __constant_cpu_to_le16(rid
);
1716 if (ha
->flags
.msix_enabled
) {
1717 msix
= &ha
->msix_entries
[1];
1718 ql_dbg(ql_dbg_init
, vha
, 0x00fd,
1719 "Registering vector 0x%x for base que.\n",
1721 icb
->msix
= cpu_to_le16(msix
->entry
);
1723 /* Use alternate PCI bus number */
1725 icb
->firmware_options_2
|=
1726 __constant_cpu_to_le32(BIT_19
);
1727 /* Use alternate PCI devfn */
1729 icb
->firmware_options_2
|=
1730 __constant_cpu_to_le32(BIT_18
);
1732 /* Use Disable MSIX Handshake mode for capable adapters */
1733 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
1734 (ha
->flags
.msix_enabled
)) {
1735 icb
->firmware_options_2
&=
1736 __constant_cpu_to_le32(~BIT_22
);
1737 ha
->flags
.disable_msix_handshake
= 1;
1738 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
1739 "MSIX Handshake Disable Mode turned on.\n");
1741 icb
->firmware_options_2
|=
1742 __constant_cpu_to_le32(BIT_22
);
1744 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
1746 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
1747 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
1748 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
1749 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
1751 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
1752 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
1753 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
1754 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
1756 qlt_24xx_config_rings(vha
, reg
);
1759 RD_REG_DWORD(&ioreg
->hccr
);
1763 * qla2x00_init_rings() - Initializes firmware.
1766 * Beginning of request ring has initialization control block already built
1767 * by nvram config routine.
1769 * Returns 0 on success.
1772 qla2x00_init_rings(scsi_qla_host_t
*vha
)
1775 unsigned long flags
= 0;
1777 struct qla_hw_data
*ha
= vha
->hw
;
1778 struct req_que
*req
;
1779 struct rsp_que
*rsp
;
1780 struct mid_init_cb_24xx
*mid_init_cb
=
1781 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1783 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1785 /* Clear outstanding commands array. */
1786 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1787 req
= ha
->req_q_map
[que
];
1790 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1791 req
->outstanding_cmds
[cnt
] = NULL
;
1793 req
->current_outstanding_cmd
= 1;
1795 /* Initialize firmware. */
1796 req
->ring_ptr
= req
->ring
;
1797 req
->ring_index
= 0;
1798 req
->cnt
= req
->length
;
1801 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
1802 rsp
= ha
->rsp_q_map
[que
];
1805 /* Initialize response queue entries */
1806 qla2x00_init_response_q_entries(rsp
);
1809 spin_lock(&ha
->vport_slock
);
1811 spin_unlock(&ha
->vport_slock
);
1813 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
1814 ha
->tgt
.atio_ring_index
= 0;
1815 /* Initialize ATIO queue entries */
1816 qlt_init_atio_q_entries(vha
);
1818 ha
->isp_ops
->config_rings(vha
);
1820 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1822 /* Update any ISP specific firmware options before initialization. */
1823 ha
->isp_ops
->update_fw_options(vha
);
1825 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
1827 if (ha
->flags
.npiv_supported
) {
1828 if (ha
->operating_mode
== LOOP
)
1829 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
1830 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1833 if (IS_FWI2_CAPABLE(ha
)) {
1834 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1835 mid_init_cb
->init_cb
.execution_throttle
=
1836 cpu_to_le16(ha
->fw_xcb_count
);
1839 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
1841 ql_log(ql_log_fatal
, vha
, 0x00d2,
1842 "Init Firmware **** FAILED ****.\n");
1844 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
1845 "Init Firmware -- success.\n");
1852 * qla2x00_fw_ready() - Waits for firmware ready.
1855 * Returns 0 on success.
1858 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
1861 unsigned long wtime
, mtime
, cs84xx_time
;
1862 uint16_t min_wait
; /* Minimum wait time if loop is down */
1863 uint16_t wait_time
; /* Wait time if loop is coming ready */
1865 struct qla_hw_data
*ha
= vha
->hw
;
1869 /* 20 seconds for loop down. */
1873 * Firmware should take at most one RATOV to login, plus 5 seconds for
1874 * our own processing.
1876 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1877 wait_time
= min_wait
;
1880 /* Min wait time if loop down */
1881 mtime
= jiffies
+ (min_wait
* HZ
);
1883 /* wait time before firmware ready */
1884 wtime
= jiffies
+ (wait_time
* HZ
);
1886 /* Wait for ISP to finish LIP */
1887 if (!vha
->flags
.init_done
)
1888 ql_log(ql_log_info
, vha
, 0x801e,
1889 "Waiting for LIP to complete.\n");
1892 rval
= qla2x00_get_firmware_state(vha
, state
);
1893 if (rval
== QLA_SUCCESS
) {
1894 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
1895 vha
->device_flags
&= ~DFLG_NO_CABLE
;
1897 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
1898 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
1899 "fw_state=%x 84xx=%x.\n", state
[0],
1901 if ((state
[2] & FSTATE_LOGGED_IN
) &&
1902 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
1903 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
1904 "Sending verify iocb.\n");
1906 cs84xx_time
= jiffies
;
1907 rval
= qla84xx_init_chip(vha
);
1908 if (rval
!= QLA_SUCCESS
) {
1911 "Init chip failed.\n");
1915 /* Add time taken to initialize. */
1916 cs84xx_time
= jiffies
- cs84xx_time
;
1917 wtime
+= cs84xx_time
;
1918 mtime
+= cs84xx_time
;
1919 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
1920 "Increasing wait time by %ld. "
1921 "New time %ld.\n", cs84xx_time
,
1924 } else if (state
[0] == FSTATE_READY
) {
1925 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
1926 "F/W Ready - OK.\n");
1928 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
1929 &ha
->login_timeout
, &ha
->r_a_tov
);
1935 rval
= QLA_FUNCTION_FAILED
;
1937 if (atomic_read(&vha
->loop_down_timer
) &&
1938 state
[0] != FSTATE_READY
) {
1939 /* Loop down. Timeout on min_wait for states
1940 * other than Wait for Login.
1942 if (time_after_eq(jiffies
, mtime
)) {
1943 ql_log(ql_log_info
, vha
, 0x8038,
1944 "Cable is unplugged...\n");
1946 vha
->device_flags
|= DFLG_NO_CABLE
;
1951 /* Mailbox cmd failed. Timeout on min_wait. */
1952 if (time_after_eq(jiffies
, mtime
) ||
1953 ha
->flags
.isp82xx_fw_hung
)
1957 if (time_after_eq(jiffies
, wtime
))
1960 /* Delay for a while */
1964 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
1965 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state
[0],
1966 state
[1], state
[2], state
[3], state
[4], jiffies
);
1968 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
1969 ql_log(ql_log_warn
, vha
, 0x803b,
1970 "Firmware ready **** FAILED ****.\n");
1977 * qla2x00_configure_hba
1978 * Setup adapter context.
1981 * ha = adapter state pointer.
1990 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
1999 char connect_type
[22];
2000 struct qla_hw_data
*ha
= vha
->hw
;
2002 /* Get host addresses. */
2003 rval
= qla2x00_get_adapter_id(vha
,
2004 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
2005 if (rval
!= QLA_SUCCESS
) {
2006 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
2007 IS_CNA_CAPABLE(ha
) ||
2008 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
2009 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
2010 "Loop is in a transition state.\n");
2012 ql_log(ql_log_warn
, vha
, 0x2009,
2013 "Unable to get host loop ID.\n");
2014 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2020 ql_log(ql_log_info
, vha
, 0x200a,
2021 "Cannot get topology - retrying.\n");
2022 return (QLA_FUNCTION_FAILED
);
2025 vha
->loop_id
= loop_id
;
2028 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
2029 ha
->operating_mode
= LOOP
;
2034 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
2035 ha
->current_topology
= ISP_CFG_NL
;
2036 strcpy(connect_type
, "(Loop)");
2040 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
2041 ha
->switch_cap
= sw_cap
;
2042 ha
->current_topology
= ISP_CFG_FL
;
2043 strcpy(connect_type
, "(FL_Port)");
2047 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
2048 ha
->operating_mode
= P2P
;
2049 ha
->current_topology
= ISP_CFG_N
;
2050 strcpy(connect_type
, "(N_Port-to-N_Port)");
2054 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
2055 ha
->switch_cap
= sw_cap
;
2056 ha
->operating_mode
= P2P
;
2057 ha
->current_topology
= ISP_CFG_F
;
2058 strcpy(connect_type
, "(F_Port)");
2062 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
2063 "HBA in unknown topology %x, using NL.\n", topo
);
2064 ha
->current_topology
= ISP_CFG_NL
;
2065 strcpy(connect_type
, "(Loop)");
2069 /* Save Host port and loop ID. */
2070 /* byte order - Big Endian */
2071 vha
->d_id
.b
.domain
= domain
;
2072 vha
->d_id
.b
.area
= area
;
2073 vha
->d_id
.b
.al_pa
= al_pa
;
2075 spin_lock(&ha
->vport_slock
);
2076 qlt_update_vp_map(vha
, SET_AL_PA
);
2077 spin_unlock(&ha
->vport_slock
);
2079 if (!vha
->flags
.init_done
)
2080 ql_log(ql_log_info
, vha
, 0x2010,
2081 "Topology - %s, Host Loop address 0x%x.\n",
2082 connect_type
, vha
->loop_id
);
2085 ql_log(ql_log_warn
, vha
, 0x2011,
2086 "%s FAILED\n", __func__
);
2088 ql_dbg(ql_dbg_disc
, vha
, 0x2012,
2089 "%s success\n", __func__
);
2096 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
2101 struct qla_hw_data
*ha
= vha
->hw
;
2102 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
2103 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
2105 if (memcmp(model
, BINZERO
, len
) != 0) {
2106 strncpy(ha
->model_number
, model
, len
);
2107 st
= en
= ha
->model_number
;
2110 if (*en
!= 0x20 && *en
!= 0x00)
2115 index
= (ha
->pdev
->subsystem_device
& 0xff);
2117 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2118 index
< QLA_MODEL_NAMES
)
2119 strncpy(ha
->model_desc
,
2120 qla2x00_model_name
[index
* 2 + 1],
2121 sizeof(ha
->model_desc
) - 1);
2123 index
= (ha
->pdev
->subsystem_device
& 0xff);
2125 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2126 index
< QLA_MODEL_NAMES
) {
2127 strcpy(ha
->model_number
,
2128 qla2x00_model_name
[index
* 2]);
2129 strncpy(ha
->model_desc
,
2130 qla2x00_model_name
[index
* 2 + 1],
2131 sizeof(ha
->model_desc
) - 1);
2133 strcpy(ha
->model_number
, def
);
2136 if (IS_FWI2_CAPABLE(ha
))
2137 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
2138 sizeof(ha
->model_desc
));
2141 /* On sparc systems, obtain port and node WWN from firmware
2144 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
2147 struct qla_hw_data
*ha
= vha
->hw
;
2148 struct pci_dev
*pdev
= ha
->pdev
;
2149 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
2153 val
= of_get_property(dp
, "port-wwn", &len
);
2154 if (val
&& len
>= WWN_SIZE
)
2155 memcpy(nv
->port_name
, val
, WWN_SIZE
);
2157 val
= of_get_property(dp
, "node-wwn", &len
);
2158 if (val
&& len
>= WWN_SIZE
)
2159 memcpy(nv
->node_name
, val
, WWN_SIZE
);
2164 * NVRAM configuration for ISP 2xxx
2167 * ha = adapter block pointer.
2170 * initialization control block in response_ring
2171 * host adapters parameters in host adapter block
2177 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
2182 uint8_t *dptr1
, *dptr2
;
2183 struct qla_hw_data
*ha
= vha
->hw
;
2184 init_cb_t
*icb
= ha
->init_cb
;
2185 nvram_t
*nv
= ha
->nvram
;
2186 uint8_t *ptr
= ha
->nvram
;
2187 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2191 /* Determine NVRAM starting address. */
2192 ha
->nvram_size
= sizeof(nvram_t
);
2194 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
2195 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
2196 ha
->nvram_base
= 0x80;
2198 /* Get NVRAM data and calculate checksum. */
2199 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
2200 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
2203 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
2204 "Contents of NVRAM.\n");
2205 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
2206 (uint8_t *)nv
, ha
->nvram_size
);
2208 /* Bad NVRAM data, set defaults parameters. */
2209 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
2210 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
2211 /* Reset NVRAM data. */
2212 ql_log(ql_log_warn
, vha
, 0x0064,
2213 "Inconsistent NVRAM "
2214 "detected: checksum=0x%x id=%c version=0x%x.\n",
2215 chksum
, nv
->id
[0], nv
->nvram_version
);
2216 ql_log(ql_log_warn
, vha
, 0x0065,
2218 "functioning (yet invalid -- WWPN) defaults.\n");
2221 * Set default initialization control block.
2223 memset(nv
, 0, ha
->nvram_size
);
2224 nv
->parameter_block_version
= ICB_VERSION
;
2226 if (IS_QLA23XX(ha
)) {
2227 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2228 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2229 nv
->add_firmware_options
[0] = BIT_5
;
2230 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2231 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2232 nv
->special_options
[1] = BIT_7
;
2233 } else if (IS_QLA2200(ha
)) {
2234 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2235 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2236 nv
->add_firmware_options
[0] = BIT_5
;
2237 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2238 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2239 } else if (IS_QLA2100(ha
)) {
2240 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
2241 nv
->firmware_options
[1] = BIT_5
;
2242 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2245 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
2246 nv
->execution_throttle
= __constant_cpu_to_le16(16);
2247 nv
->retry_count
= 8;
2248 nv
->retry_delay
= 1;
2250 nv
->port_name
[0] = 33;
2251 nv
->port_name
[3] = 224;
2252 nv
->port_name
[4] = 139;
2254 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
2256 nv
->login_timeout
= 4;
2259 * Set default host adapter parameters
2261 nv
->host_p
[1] = BIT_2
;
2262 nv
->reset_delay
= 5;
2263 nv
->port_down_retry_count
= 8;
2264 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
2265 nv
->link_down_timeout
= 60;
2270 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2272 * The SN2 does not provide BIOS emulation which means you can't change
2273 * potentially bogus BIOS settings. Force the use of default settings
2274 * for link rate and frame size. Hope that the rest of the settings
2277 if (ia64_platform_is("sn2")) {
2278 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2280 nv
->special_options
[1] = BIT_7
;
2284 /* Reset Initialization control block */
2285 memset(icb
, 0, ha
->init_cb_size
);
2288 * Setup driver NVRAM options.
2290 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
2291 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
2292 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
2293 nv
->firmware_options
[1] &= ~BIT_4
;
2295 if (IS_QLA23XX(ha
)) {
2296 nv
->firmware_options
[0] |= BIT_2
;
2297 nv
->firmware_options
[0] &= ~BIT_3
;
2298 nv
->special_options
[0] &= ~BIT_6
;
2299 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
2301 if (IS_QLA2300(ha
)) {
2302 if (ha
->fb_rev
== FPM_2310
) {
2303 strcpy(ha
->model_number
, "QLA2310");
2305 strcpy(ha
->model_number
, "QLA2300");
2308 qla2x00_set_model_info(vha
, nv
->model_number
,
2309 sizeof(nv
->model_number
), "QLA23xx");
2311 } else if (IS_QLA2200(ha
)) {
2312 nv
->firmware_options
[0] |= BIT_2
;
2314 * 'Point-to-point preferred, else loop' is not a safe
2315 * connection mode setting.
2317 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
2319 /* Force 'loop preferred, else point-to-point'. */
2320 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
2321 nv
->add_firmware_options
[0] |= BIT_5
;
2323 strcpy(ha
->model_number
, "QLA22xx");
2324 } else /*if (IS_QLA2100(ha))*/ {
2325 strcpy(ha
->model_number
, "QLA2100");
2329 * Copy over NVRAM RISC parameter block to initialization control block.
2331 dptr1
= (uint8_t *)icb
;
2332 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
2333 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
2335 *dptr1
++ = *dptr2
++;
2337 /* Copy 2nd half. */
2338 dptr1
= (uint8_t *)icb
->add_firmware_options
;
2339 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
2341 *dptr1
++ = *dptr2
++;
2343 /* Use alternate WWN? */
2344 if (nv
->host_p
[1] & BIT_7
) {
2345 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
2346 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
2349 /* Prepare nodename */
2350 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
2352 * Firmware will apply the following mask if the nodename was
2355 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
2356 icb
->node_name
[0] &= 0xF0;
2360 * Set host adapter parameters.
2364 * BIT_7 in the host-parameters section allows for modification to
2365 * internal driver logging.
2367 if (nv
->host_p
[0] & BIT_7
)
2368 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
2369 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
2370 /* Always load RISC code on non ISP2[12]00 chips. */
2371 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2372 ha
->flags
.disable_risc_code_load
= 0;
2373 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
2374 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
2375 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
2376 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
2377 ha
->flags
.disable_serdes
= 0;
2379 ha
->operating_mode
=
2380 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
2382 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
2383 sizeof(ha
->fw_seriallink_options
));
2385 /* save HBA serial number */
2386 ha
->serial0
= icb
->port_name
[5];
2387 ha
->serial1
= icb
->port_name
[6];
2388 ha
->serial2
= icb
->port_name
[7];
2389 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
2390 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
2392 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
2394 ha
->retry_count
= nv
->retry_count
;
2396 /* Set minimum login_timeout to 4 seconds. */
2397 if (nv
->login_timeout
!= ql2xlogintimeout
)
2398 nv
->login_timeout
= ql2xlogintimeout
;
2399 if (nv
->login_timeout
< 4)
2400 nv
->login_timeout
= 4;
2401 ha
->login_timeout
= nv
->login_timeout
;
2402 icb
->login_timeout
= nv
->login_timeout
;
2404 /* Set minimum RATOV to 100 tenths of a second. */
2407 ha
->loop_reset_delay
= nv
->reset_delay
;
2409 /* Link Down Timeout = 0:
2411 * When Port Down timer expires we will start returning
2412 * I/O's to OS with "DID_NO_CONNECT".
2414 * Link Down Timeout != 0:
2416 * The driver waits for the link to come up after link down
2417 * before returning I/Os to OS with "DID_NO_CONNECT".
2419 if (nv
->link_down_timeout
== 0) {
2420 ha
->loop_down_abort_time
=
2421 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
2423 ha
->link_down_timeout
= nv
->link_down_timeout
;
2424 ha
->loop_down_abort_time
=
2425 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
2429 * Need enough time to try and get the port back.
2431 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
2432 if (qlport_down_retry
)
2433 ha
->port_down_retry_count
= qlport_down_retry
;
2434 /* Set login_retry_count */
2435 ha
->login_retry_count
= nv
->retry_count
;
2436 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
2437 ha
->port_down_retry_count
> 3)
2438 ha
->login_retry_count
= ha
->port_down_retry_count
;
2439 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
2440 ha
->login_retry_count
= ha
->port_down_retry_count
;
2441 if (ql2xloginretrycount
)
2442 ha
->login_retry_count
= ql2xloginretrycount
;
2444 icb
->lun_enables
= __constant_cpu_to_le16(0);
2445 icb
->command_resource_count
= 0;
2446 icb
->immediate_notify_resource_count
= 0;
2447 icb
->timeout
= __constant_cpu_to_le16(0);
2449 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2451 icb
->firmware_options
[0] &= ~BIT_3
;
2452 icb
->add_firmware_options
[0] &=
2453 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2454 icb
->add_firmware_options
[0] |= BIT_2
;
2455 icb
->response_accumulation_timer
= 3;
2456 icb
->interrupt_delay_timer
= 5;
2458 vha
->flags
.process_response_queue
= 1;
2461 if (!vha
->flags
.init_done
) {
2462 ha
->zio_mode
= icb
->add_firmware_options
[0] &
2463 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2464 ha
->zio_timer
= icb
->interrupt_delay_timer
?
2465 icb
->interrupt_delay_timer
: 2;
2467 icb
->add_firmware_options
[0] &=
2468 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2469 vha
->flags
.process_response_queue
= 0;
2470 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
2471 ha
->zio_mode
= QLA_ZIO_MODE_6
;
2473 ql_log(ql_log_info
, vha
, 0x0068,
2474 "ZIO mode %d enabled; timer delay (%d us).\n",
2475 ha
->zio_mode
, ha
->zio_timer
* 100);
2477 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
2478 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
2479 vha
->flags
.process_response_queue
= 1;
2484 ql_log(ql_log_warn
, vha
, 0x0069,
2485 "NVRAM configuration failed.\n");
2491 qla2x00_rport_del(void *data
)
2493 fc_port_t
*fcport
= data
;
2494 struct fc_rport
*rport
;
2495 scsi_qla_host_t
*vha
= fcport
->vha
;
2496 unsigned long flags
;
2498 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2499 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
2500 fcport
->drport
= NULL
;
2501 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2503 fc_remote_port_delete(rport
);
2505 * Release the target mode FC NEXUS in qla_target.c code
2506 * if target mod is enabled.
2508 qlt_fc_port_deleted(vha
, fcport
);
2513 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2515 * @flags: allocation flags
2517 * Returns a pointer to the allocated fcport, or NULL, if none available.
2520 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
2524 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
2528 /* Setup fcport template structure. */
2530 fcport
->port_type
= FCT_UNKNOWN
;
2531 fcport
->loop_id
= FC_NO_LOOP_ID
;
2532 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
2533 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
2534 fcport
->scan_state
= QLA_FCPORT_SCAN_NONE
;
2540 * qla2x00_configure_loop
2541 * Updates Fibre Channel Device Database with what is actually on loop.
2544 * ha = adapter block pointer.
2549 * 2 = database was full and device was not configured.
2552 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
2555 unsigned long flags
, save_flags
;
2556 struct qla_hw_data
*ha
= vha
->hw
;
2559 /* Get Initiator ID */
2560 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2561 rval
= qla2x00_configure_hba(vha
);
2562 if (rval
!= QLA_SUCCESS
) {
2563 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
2564 "Unable to configure HBA.\n");
2569 save_flags
= flags
= vha
->dpc_flags
;
2570 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
2571 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
2574 * If we have both an RSCN and PORT UPDATE pending then handle them
2575 * both at the same time.
2577 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2578 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2580 qla2x00_get_data_rate(vha
);
2582 /* Determine what we need to do */
2583 if (ha
->current_topology
== ISP_CFG_FL
&&
2584 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2586 set_bit(RSCN_UPDATE
, &flags
);
2588 } else if (ha
->current_topology
== ISP_CFG_F
&&
2589 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2591 set_bit(RSCN_UPDATE
, &flags
);
2592 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2594 } else if (ha
->current_topology
== ISP_CFG_N
) {
2595 clear_bit(RSCN_UPDATE
, &flags
);
2597 } else if (!vha
->flags
.online
||
2598 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2600 set_bit(RSCN_UPDATE
, &flags
);
2601 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2604 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2605 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2606 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
2607 "Loop resync needed, failing.\n");
2608 rval
= QLA_FUNCTION_FAILED
;
2610 rval
= qla2x00_configure_local_loop(vha
);
2613 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2614 if (LOOP_TRANSITION(vha
)) {
2615 ql_dbg(ql_dbg_disc
, vha
, 0x201e,
2616 "Needs RSCN update and loop transition.\n");
2617 rval
= QLA_FUNCTION_FAILED
;
2620 rval
= qla2x00_configure_fabric(vha
);
2623 if (rval
== QLA_SUCCESS
) {
2624 if (atomic_read(&vha
->loop_down_timer
) ||
2625 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2626 rval
= QLA_FUNCTION_FAILED
;
2628 atomic_set(&vha
->loop_state
, LOOP_READY
);
2629 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
2635 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
2636 "%s *** FAILED ***.\n", __func__
);
2638 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
2639 "%s: exiting normally.\n", __func__
);
2642 /* Restore state if a resync event occurred during processing */
2643 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2644 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
2645 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2646 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
2647 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2657 * qla2x00_configure_local_loop
2658 * Updates Fibre Channel Device Database with local loop devices.
2661 * ha = adapter block pointer.
2667 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
2672 fc_port_t
*fcport
, *new_fcport
;
2678 uint8_t domain
, area
, al_pa
;
2679 struct qla_hw_data
*ha
= vha
->hw
;
2683 entries
= MAX_FIBRE_DEVICES_LOOP
;
2685 ql_dbg(ql_dbg_disc
, vha
, 0x2016,
2686 "Getting FCAL position map.\n");
2687 if (ql2xextended_error_logging
& ql_dbg_disc
)
2688 qla2x00_get_fcal_position_map(vha
, NULL
);
2690 /* Get list of logged in devices. */
2691 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
2692 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
2694 if (rval
!= QLA_SUCCESS
)
2695 goto cleanup_allocation
;
2697 ql_dbg(ql_dbg_disc
, vha
, 0x2017,
2698 "Entries in ID list (%d).\n", entries
);
2699 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
2700 (uint8_t *)ha
->gid_list
,
2701 entries
* sizeof(struct gid_list_info
));
2703 /* Allocate temporary fcport for any new fcports discovered. */
2704 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2705 if (new_fcport
== NULL
) {
2706 ql_log(ql_log_warn
, vha
, 0x2018,
2707 "Memory allocation failed for fcport.\n");
2708 rval
= QLA_MEMORY_ALLOC_FAILED
;
2709 goto cleanup_allocation
;
2711 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2714 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2716 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2717 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2718 fcport
->port_type
!= FCT_BROADCAST
&&
2719 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2721 ql_dbg(ql_dbg_disc
, vha
, 0x2019,
2722 "Marking port lost loop_id=0x%04x.\n",
2725 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
2729 /* Add devices to port list. */
2730 id_iter
= (char *)ha
->gid_list
;
2731 for (index
= 0; index
< entries
; index
++) {
2732 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2733 area
= ((struct gid_list_info
*)id_iter
)->area
;
2734 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2735 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2736 loop_id
= (uint16_t)
2737 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2739 loop_id
= le16_to_cpu(
2740 ((struct gid_list_info
*)id_iter
)->loop_id
);
2741 id_iter
+= ha
->gid_list_info_size
;
2743 /* Bypass reserved domain fields. */
2744 if ((domain
& 0xf0) == 0xf0)
2747 /* Bypass if not same domain and area of adapter. */
2748 if (area
&& domain
&&
2749 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
2752 /* Bypass invalid local loop ID. */
2753 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2756 /* Fill in member data. */
2757 new_fcport
->d_id
.b
.domain
= domain
;
2758 new_fcport
->d_id
.b
.area
= area
;
2759 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2760 new_fcport
->loop_id
= loop_id
;
2761 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
2762 if (rval2
!= QLA_SUCCESS
) {
2763 ql_dbg(ql_dbg_disc
, vha
, 0x201a,
2764 "Failed to retrieve fcport information "
2765 "-- get_port_database=%x, loop_id=0x%04x.\n",
2766 rval2
, new_fcport
->loop_id
);
2767 ql_dbg(ql_dbg_disc
, vha
, 0x201b,
2768 "Scheduling resync.\n");
2769 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2773 /* Check for matching device in port list. */
2776 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2777 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2781 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2782 fcport
->loop_id
= new_fcport
->loop_id
;
2783 fcport
->port_type
= new_fcport
->port_type
;
2784 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2785 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2793 /* New device, add to fcports list. */
2794 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
2796 /* Allocate a new replacement fcport. */
2797 fcport
= new_fcport
;
2798 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2799 if (new_fcport
== NULL
) {
2800 ql_log(ql_log_warn
, vha
, 0x201c,
2801 "Failed to allocate memory for fcport.\n");
2802 rval
= QLA_MEMORY_ALLOC_FAILED
;
2803 goto cleanup_allocation
;
2805 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2808 /* Base iIDMA settings on HBA port speed. */
2809 fcport
->fp_speed
= ha
->link_data_rate
;
2811 qla2x00_update_fcport(vha
, fcport
);
2819 if (rval
!= QLA_SUCCESS
) {
2820 ql_dbg(ql_dbg_disc
, vha
, 0x201d,
2821 "Configure local loop error exit: rval=%x.\n", rval
);
2828 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2833 struct qla_hw_data
*ha
= vha
->hw
;
2835 if (!IS_IIDMA_CAPABLE(ha
))
2838 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
2841 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2842 fcport
->fp_speed
> ha
->link_data_rate
)
2845 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
2847 if (rval
!= QLA_SUCCESS
) {
2848 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
2849 "Unable to adjust iIDMA "
2850 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
2851 "%04x.\n", fcport
->port_name
[0], fcport
->port_name
[1],
2852 fcport
->port_name
[2], fcport
->port_name
[3],
2853 fcport
->port_name
[4], fcport
->port_name
[5],
2854 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2855 fcport
->fp_speed
, mb
[0], mb
[1]);
2857 link_speed
= qla2x00_get_link_speed_str(ha
);
2858 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
2859 "iIDMA adjusted to %s GB/s "
2860 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed
,
2861 fcport
->port_name
[0], fcport
->port_name
[1],
2862 fcport
->port_name
[2], fcport
->port_name
[3],
2863 fcport
->port_name
[4], fcport
->port_name
[5],
2864 fcport
->port_name
[6], fcport
->port_name
[7]);
2869 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2871 struct fc_rport_identifiers rport_ids
;
2872 struct fc_rport
*rport
;
2873 unsigned long flags
;
2875 qla2x00_rport_del(fcport
);
2877 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2878 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2879 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2880 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2881 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2882 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
2884 ql_log(ql_log_warn
, vha
, 0x2006,
2885 "Unable to allocate fc remote port.\n");
2889 * Create target mode FC NEXUS in qla_target.c if target mode is
2892 qlt_fc_port_added(vha
, fcport
);
2894 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2895 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2896 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2898 rport
->supported_classes
= fcport
->supported_classes
;
2900 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2901 if (fcport
->port_type
== FCT_INITIATOR
)
2902 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2903 if (fcport
->port_type
== FCT_TARGET
)
2904 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2905 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2909 * qla2x00_update_fcport
2910 * Updates device on list.
2913 * ha = adapter block pointer.
2914 * fcport = port structure pointer.
2924 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2927 fcport
->login_retry
= 0;
2928 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
2930 qla2x00_iidma_fcport(vha
, fcport
);
2931 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
2932 qla2x00_reg_remote_port(vha
, fcport
);
2933 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
2937 * qla2x00_configure_fabric
2938 * Setup SNS devices with loop ID's.
2941 * ha = adapter block pointer.
2948 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
2952 uint16_t next_loopid
;
2953 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2955 LIST_HEAD(new_fcports
);
2956 struct qla_hw_data
*ha
= vha
->hw
;
2957 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2959 /* If FL port exists, then SNS is present */
2960 if (IS_FWI2_CAPABLE(ha
))
2961 loop_id
= NPH_F_PORT
;
2963 loop_id
= SNS_FL_PORT
;
2964 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
2965 if (rval
!= QLA_SUCCESS
) {
2966 ql_dbg(ql_dbg_disc
, vha
, 0x201f,
2967 "MBX_GET_PORT_NAME failed, No FL Port.\n");
2969 vha
->device_flags
&= ~SWITCH_FOUND
;
2970 return (QLA_SUCCESS
);
2972 vha
->device_flags
|= SWITCH_FOUND
;
2976 if (ql2xfdmienable
&&
2977 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
2978 qla2x00_fdmi_register(vha
);
2980 /* Ensure we are logged into the SNS. */
2981 if (IS_FWI2_CAPABLE(ha
))
2984 loop_id
= SIMPLE_NAME_SERVER
;
2985 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
2986 0xfc, mb
, BIT_1
|BIT_0
);
2987 if (rval
!= QLA_SUCCESS
) {
2988 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2991 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2992 ql_dbg(ql_dbg_disc
, vha
, 0x2042,
2993 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
2994 "mb[6]=%x mb[7]=%x.\n", loop_id
, mb
[0], mb
[1],
2995 mb
[2], mb
[6], mb
[7]);
2996 return (QLA_SUCCESS
);
2999 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
3000 if (qla2x00_rft_id(vha
)) {
3002 ql_dbg(ql_dbg_disc
, vha
, 0x2045,
3003 "Register FC-4 TYPE failed.\n");
3005 if (qla2x00_rff_id(vha
)) {
3007 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
3008 "Register FC-4 Features failed.\n");
3010 if (qla2x00_rnn_id(vha
)) {
3012 ql_dbg(ql_dbg_disc
, vha
, 0x204f,
3013 "Register Node Name failed.\n");
3014 } else if (qla2x00_rsnn_nn(vha
)) {
3016 ql_dbg(ql_dbg_disc
, vha
, 0x2053,
3017 "Register Symobilic Node Name failed.\n");
3021 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
3022 if (rval
!= QLA_SUCCESS
)
3025 /* Add new ports to existing port list */
3026 list_splice_tail_init(&new_fcports
, &vha
->vp_fcports
);
3028 /* Starting free loop ID. */
3029 next_loopid
= ha
->min_external_loopid
;
3031 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3032 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3035 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
3038 /* Logout lost/gone fabric devices (non-FCP2) */
3039 if (fcport
->scan_state
!= QLA_FCPORT_SCAN_FOUND
&&
3040 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3041 qla2x00_mark_device_lost(vha
, fcport
,
3042 ql2xplogiabsentdevice
, 0);
3043 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3044 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3045 fcport
->port_type
!= FCT_INITIATOR
&&
3046 fcport
->port_type
!= FCT_BROADCAST
) {
3047 ha
->isp_ops
->fabric_logout(vha
,
3049 fcport
->d_id
.b
.domain
,
3050 fcport
->d_id
.b
.area
,
3051 fcport
->d_id
.b
.al_pa
);
3055 fcport
->scan_state
= QLA_FCPORT_SCAN_NONE
;
3057 /* Login fabric devices that need a login */
3058 if ((fcport
->flags
& FCF_LOGIN_NEEDED
) != 0 &&
3059 atomic_read(&vha
->loop_down_timer
) == 0) {
3060 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
3061 fcport
->loop_id
= next_loopid
;
3062 rval
= qla2x00_find_new_loop_id(
3064 if (rval
!= QLA_SUCCESS
) {
3065 /* Ran out of IDs to use */
3071 /* Login and update database */
3072 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3077 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
3078 "Configure fabric error exit rval=%d.\n", rval
);
3085 * qla2x00_find_all_fabric_devs
3088 * ha = adapter block pointer.
3089 * dev = database device entry pointer.
3098 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
3099 struct list_head
*new_fcports
)
3103 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
3108 int first_dev
, last_dev
;
3109 port_id_t wrap
= {}, nxt_d_id
;
3110 struct qla_hw_data
*ha
= vha
->hw
;
3111 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
3112 struct scsi_qla_host
*tvp
;
3116 /* Try GID_PT to get device list, else GAN. */
3118 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
3123 ql_dbg(ql_dbg_disc
, vha
, 0x2054,
3124 "GID_PT allocations failed, fallback on GA_NXT.\n");
3126 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
3127 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
3129 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
3131 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
3133 } else if (ql2xiidmaenable
&&
3134 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
3135 qla2x00_gpsc(vha
, swl
);
3138 /* If other queries succeeded probe for FC-4 type */
3140 qla2x00_gff_id(vha
, swl
);
3144 /* Allocate temporary fcport for any new fcports discovered. */
3145 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3146 if (new_fcport
== NULL
) {
3147 ql_log(ql_log_warn
, vha
, 0x205e,
3148 "Failed to allocate memory for fcport.\n");
3149 return (QLA_MEMORY_ALLOC_FAILED
);
3151 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3152 /* Set start port ID scan at adapter ID. */
3156 /* Starting free loop ID. */
3157 loop_id
= ha
->min_external_loopid
;
3158 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
3159 if (qla2x00_is_reserved_id(vha
, loop_id
))
3162 if (ha
->current_topology
== ISP_CFG_FL
&&
3163 (atomic_read(&vha
->loop_down_timer
) ||
3164 LOOP_TRANSITION(vha
))) {
3165 atomic_set(&vha
->loop_down_timer
, 0);
3166 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3167 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
3173 wrap
.b24
= new_fcport
->d_id
.b24
;
3175 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
3176 memcpy(new_fcport
->node_name
,
3177 swl
[swl_idx
].node_name
, WWN_SIZE
);
3178 memcpy(new_fcport
->port_name
,
3179 swl
[swl_idx
].port_name
, WWN_SIZE
);
3180 memcpy(new_fcport
->fabric_port_name
,
3181 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
3182 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
3183 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
3185 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
3191 /* Send GA_NXT to the switch */
3192 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
3193 if (rval
!= QLA_SUCCESS
) {
3194 ql_log(ql_log_warn
, vha
, 0x2064,
3195 "SNS scan failed -- assuming "
3196 "zero-entry result.\n");
3197 list_for_each_entry_safe(fcport
, fcptemp
,
3198 new_fcports
, list
) {
3199 list_del(&fcport
->list
);
3207 /* If wrap on switch device list, exit. */
3209 wrap
.b24
= new_fcport
->d_id
.b24
;
3211 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
3212 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
3213 "Device wrap (%02x%02x%02x).\n",
3214 new_fcport
->d_id
.b
.domain
,
3215 new_fcport
->d_id
.b
.area
,
3216 new_fcport
->d_id
.b
.al_pa
);
3220 /* Bypass if same physical adapter. */
3221 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
3224 /* Bypass virtual ports of the same host. */
3226 if (ha
->num_vhosts
) {
3227 unsigned long flags
;
3229 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3230 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3231 if (new_fcport
->d_id
.b24
== vp
->d_id
.b24
) {
3236 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3242 /* Bypass if same domain and area of adapter. */
3243 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
3244 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
3248 /* Bypass reserved domain fields. */
3249 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
3252 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3253 if (ql2xgffidenable
&&
3254 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
3255 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
3258 /* Locate matching device in database. */
3260 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3261 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
3265 fcport
->scan_state
= QLA_FCPORT_SCAN_FOUND
;
3269 /* Update port state. */
3270 memcpy(fcport
->fabric_port_name
,
3271 new_fcport
->fabric_port_name
, WWN_SIZE
);
3272 fcport
->fp_speed
= new_fcport
->fp_speed
;
3275 * If address the same and state FCS_ONLINE, nothing
3278 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
3279 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3284 * If device was not a fabric device before.
3286 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
3287 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3288 qla2x00_clear_loop_id(fcport
);
3289 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
3295 * Port ID changed or device was marked to be updated;
3296 * Log it out if still logged in and mark it for
3299 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3300 fcport
->flags
|= FCF_LOGIN_NEEDED
;
3301 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3302 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3303 (fcport
->flags
& FCF_ASYNC_SENT
) == 0 &&
3304 fcport
->port_type
!= FCT_INITIATOR
&&
3305 fcport
->port_type
!= FCT_BROADCAST
) {
3306 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3307 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3308 fcport
->d_id
.b
.al_pa
);
3309 qla2x00_clear_loop_id(fcport
);
3317 /* If device was not in our fcports list, then add it. */
3318 list_add_tail(&new_fcport
->list
, new_fcports
);
3320 /* Allocate a new replacement fcport. */
3321 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
3322 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3323 if (new_fcport
== NULL
) {
3324 ql_log(ql_log_warn
, vha
, 0x2066,
3325 "Memory allocation failed for fcport.\n");
3326 return (QLA_MEMORY_ALLOC_FAILED
);
3328 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3329 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
3338 * qla2x00_find_new_loop_id
3339 * Scan through our port list and find a new usable loop ID.
3342 * ha: adapter state pointer.
3343 * dev: port structure pointer.
3346 * qla2x00 local function return status code.
3352 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
3355 struct qla_hw_data
*ha
= vha
->hw
;
3356 unsigned long flags
= 0;
3360 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3362 dev
->loop_id
= find_first_zero_bit(ha
->loop_id_map
,
3364 if (dev
->loop_id
>= LOOPID_MAP_SIZE
||
3365 qla2x00_is_reserved_id(vha
, dev
->loop_id
)) {
3366 dev
->loop_id
= FC_NO_LOOP_ID
;
3367 rval
= QLA_FUNCTION_FAILED
;
3369 set_bit(dev
->loop_id
, ha
->loop_id_map
);
3371 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3373 if (rval
== QLA_SUCCESS
)
3374 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
3375 "Assigning new loopid=%x, portid=%x.\n",
3376 dev
->loop_id
, dev
->d_id
.b24
);
3378 ql_log(ql_log_warn
, dev
->vha
, 0x2087,
3379 "No loop_id's available, portid=%x.\n",
3386 * qla2x00_fabric_dev_login
3387 * Login fabric target device and update FC port database.
3390 * ha: adapter state pointer.
3391 * fcport: port structure list pointer.
3392 * next_loopid: contains value of a new loop ID that can be used
3393 * by the next login attempt.
3396 * qla2x00 local function return status code.
3402 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3403 uint16_t *next_loopid
)
3408 struct qla_hw_data
*ha
= vha
->hw
;
3413 if (IS_ALOGIO_CAPABLE(ha
)) {
3414 if (fcport
->flags
& FCF_ASYNC_SENT
)
3416 fcport
->flags
|= FCF_ASYNC_SENT
;
3417 rval
= qla2x00_post_async_login_work(vha
, fcport
, NULL
);
3422 fcport
->flags
&= ~FCF_ASYNC_SENT
;
3423 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3424 if (rval
== QLA_SUCCESS
) {
3425 /* Send an ADISC to FCP2 devices.*/
3427 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3429 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3430 if (rval
!= QLA_SUCCESS
) {
3431 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3432 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3433 fcport
->d_id
.b
.al_pa
);
3434 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3436 qla2x00_update_fcport(vha
, fcport
);
3440 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3447 * qla2x00_fabric_login
3448 * Issue fabric login command.
3451 * ha = adapter block pointer.
3452 * device = pointer to FC device type structure.
3455 * 0 - Login successfully
3457 * 2 - Initiator device
3461 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3462 uint16_t *next_loopid
)
3466 uint16_t tmp_loopid
;
3467 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3468 struct qla_hw_data
*ha
= vha
->hw
;
3474 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
3475 "Trying Fabric Login w/loop id 0x%04x for port "
3477 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3478 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
3480 /* Login fcport on switch. */
3481 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3482 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3483 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3484 if (rval
!= QLA_SUCCESS
) {
3487 if (mb
[0] == MBS_PORT_ID_USED
) {
3489 * Device has another loop ID. The firmware team
3490 * recommends the driver perform an implicit login with
3491 * the specified ID again. The ID we just used is save
3492 * here so we return with an ID that can be tried by
3496 tmp_loopid
= fcport
->loop_id
;
3497 fcport
->loop_id
= mb
[1];
3499 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
3500 "Fabric Login: port in use - next loop "
3501 "id=0x%04x, port id= %02x%02x%02x.\n",
3502 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3503 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
3505 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3510 /* A retry occurred before. */
3511 *next_loopid
= tmp_loopid
;
3514 * No retry occurred before. Just increment the
3515 * ID value for next login.
3517 *next_loopid
= (fcport
->loop_id
+ 1);
3520 if (mb
[1] & BIT_0
) {
3521 fcport
->port_type
= FCT_INITIATOR
;
3523 fcport
->port_type
= FCT_TARGET
;
3524 if (mb
[1] & BIT_1
) {
3525 fcport
->flags
|= FCF_FCP2_DEVICE
;
3530 fcport
->supported_classes
|= FC_COS_CLASS2
;
3532 fcport
->supported_classes
|= FC_COS_CLASS3
;
3534 if (IS_FWI2_CAPABLE(ha
)) {
3537 FCF_CONF_COMP_SUPPORTED
;
3542 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3544 * Loop ID already used, try next loop ID.
3547 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3548 if (rval
!= QLA_SUCCESS
) {
3549 /* Ran out of loop IDs to use */
3552 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3554 * Firmware possibly timed out during login. If NO
3555 * retries are left to do then the device is declared
3558 *next_loopid
= fcport
->loop_id
;
3559 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3560 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3561 fcport
->d_id
.b
.al_pa
);
3562 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3568 * unrecoverable / not handled error
3570 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
3571 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3572 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
3573 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
3574 fcport
->loop_id
, jiffies
);
3576 *next_loopid
= fcport
->loop_id
;
3577 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3578 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3579 fcport
->d_id
.b
.al_pa
);
3580 qla2x00_clear_loop_id(fcport
);
3581 fcport
->login_retry
= 0;
3592 * qla2x00_local_device_login
3593 * Issue local device login command.
3596 * ha = adapter block pointer.
3597 * loop_id = loop id of device to login to.
3599 * Returns (Where's the #define!!!!):
3600 * 0 - Login successfully
3605 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3608 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3610 memset(mb
, 0, sizeof(mb
));
3611 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3612 if (rval
== QLA_SUCCESS
) {
3613 /* Interrogate mailbox registers for any errors */
3614 if (mb
[0] == MBS_COMMAND_ERROR
)
3616 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3617 /* device not in PCB table */
3625 * qla2x00_loop_resync
3626 * Resync with fibre channel devices.
3629 * ha = adapter block pointer.
3635 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
3637 int rval
= QLA_SUCCESS
;
3639 struct req_que
*req
;
3640 struct rsp_que
*rsp
;
3642 if (vha
->hw
->flags
.cpu_affinity_enabled
)
3643 req
= vha
->hw
->req_q_map
[0];
3648 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3649 if (vha
->flags
.online
) {
3650 if (!(rval
= qla2x00_fw_ready(vha
))) {
3651 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3654 /* Issue a marker after FW becomes ready. */
3655 qla2x00_marker(vha
, req
, rsp
, 0, 0,
3657 vha
->marker_needed
= 0;
3659 /* Remap devices on Loop. */
3660 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3662 qla2x00_configure_loop(vha
);
3664 } while (!atomic_read(&vha
->loop_down_timer
) &&
3665 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3666 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3671 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3672 return (QLA_FUNCTION_FAILED
);
3675 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
3676 "%s *** FAILED ***.\n", __func__
);
3682 * qla2x00_perform_loop_resync
3683 * Description: This function will set the appropriate flags and call
3684 * qla2x00_loop_resync. If successful loop will be resynced
3685 * Arguments : scsi_qla_host_t pointer
3686 * returm : Success or Failure
3689 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
3693 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
3694 /*Configure the flags so that resync happens properly*/
3695 atomic_set(&ha
->loop_down_timer
, 0);
3696 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
3697 atomic_set(&ha
->loop_state
, LOOP_UP
);
3698 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
3699 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
3700 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3702 rval
= qla2x00_loop_resync(ha
);
3704 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
3706 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
3713 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
3716 struct scsi_qla_host
*vha
;
3717 struct qla_hw_data
*ha
= base_vha
->hw
;
3718 unsigned long flags
;
3720 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3721 /* Go with deferred removal of rport references. */
3722 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
3723 atomic_inc(&vha
->vref_count
);
3724 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3725 if (fcport
->drport
&&
3726 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
3727 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3729 qla2x00_rport_del(fcport
);
3731 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3734 atomic_dec(&vha
->vref_count
);
3736 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3740 * qla82xx_quiescent_state_cleanup
3741 * Description: This function will block the new I/Os
3742 * Its not aborting any I/Os as context
3743 * is not destroyed during quiescence
3744 * Arguments: scsi_qla_host_t
3748 qla82xx_quiescent_state_cleanup(scsi_qla_host_t
*vha
)
3750 struct qla_hw_data
*ha
= vha
->hw
;
3751 struct scsi_qla_host
*vp
;
3753 ql_dbg(ql_dbg_p3p
, vha
, 0xb002,
3754 "Performing ISP error recovery - ha=%p.\n", ha
);
3756 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3757 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3758 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3759 qla2x00_mark_all_devices_lost(vha
, 0);
3760 list_for_each_entry(vp
, &ha
->vp_list
, list
)
3761 qla2x00_mark_all_devices_lost(vha
, 0);
3763 if (!atomic_read(&vha
->loop_down_timer
))
3764 atomic_set(&vha
->loop_down_timer
,
3767 /* Wait for pending cmds to complete */
3768 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
3772 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
3774 struct qla_hw_data
*ha
= vha
->hw
;
3775 struct scsi_qla_host
*vp
;
3776 unsigned long flags
;
3779 /* For ISP82XX, driver waits for completion of the commands.
3780 * online flag should be set.
3782 if (!IS_QLA82XX(ha
))
3783 vha
->flags
.online
= 0;
3784 ha
->flags
.chip_reset_done
= 0;
3785 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3786 vha
->qla_stats
.total_isp_aborts
++;
3788 ql_log(ql_log_info
, vha
, 0x00af,
3789 "Performing ISP error recovery - ha=%p.\n", ha
);
3791 /* For ISP82XX, reset_chip is just disabling interrupts.
3792 * Driver waits for the completion of the commands.
3793 * the interrupts need to be enabled.
3795 if (!IS_QLA82XX(ha
))
3796 ha
->isp_ops
->reset_chip(vha
);
3798 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
3799 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3800 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3801 qla2x00_mark_all_devices_lost(vha
, 0);
3803 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3804 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3805 atomic_inc(&vp
->vref_count
);
3806 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3808 qla2x00_mark_all_devices_lost(vp
, 0);
3810 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3811 atomic_dec(&vp
->vref_count
);
3813 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3815 if (!atomic_read(&vha
->loop_down_timer
))
3816 atomic_set(&vha
->loop_down_timer
,
3820 /* Clear all async request states across all VPs. */
3821 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
3822 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
3823 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3824 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3825 atomic_inc(&vp
->vref_count
);
3826 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3828 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
3829 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
3831 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3832 atomic_dec(&vp
->vref_count
);
3834 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3836 if (!ha
->flags
.eeh_busy
) {
3837 /* Make sure for ISP 82XX IO DMA is complete */
3838 if (IS_QLA82XX(ha
)) {
3839 qla82xx_chip_reset_cleanup(vha
);
3840 ql_log(ql_log_info
, vha
, 0x00b4,
3841 "Done chip reset cleanup.\n");
3843 /* Done waiting for pending commands.
3844 * Reset the online flag.
3846 vha
->flags
.online
= 0;
3849 /* Requeue all commands in outstanding command list. */
3850 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
3856 * Resets ISP and aborts all outstanding commands.
3859 * ha = adapter block pointer.
3865 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
3869 struct qla_hw_data
*ha
= vha
->hw
;
3870 struct scsi_qla_host
*vp
;
3871 struct req_que
*req
= ha
->req_q_map
[0];
3872 unsigned long flags
;
3874 if (vha
->flags
.online
) {
3875 qla2x00_abort_isp_cleanup(vha
);
3877 if (unlikely(pci_channel_offline(ha
->pdev
) &&
3878 ha
->flags
.pci_channel_io_perm_failure
)) {
3879 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3884 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
3886 ha
->isp_ops
->nvram_config(vha
);
3888 if (!qla2x00_restart_isp(vha
)) {
3889 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3891 if (!atomic_read(&vha
->loop_down_timer
)) {
3893 * Issue marker command only when we are going
3894 * to start the I/O .
3896 vha
->marker_needed
= 1;
3899 vha
->flags
.online
= 1;
3901 ha
->isp_ops
->enable_intrs(ha
);
3903 ha
->isp_abort_cnt
= 0;
3904 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3906 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
3907 qla2x00_get_fw_version(vha
);
3909 ha
->flags
.fce_enabled
= 1;
3911 fce_calc_size(ha
->fce_bufs
));
3912 rval
= qla2x00_enable_fce_trace(vha
,
3913 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
3916 ql_log(ql_log_warn
, vha
, 0x8033,
3917 "Unable to reinitialize FCE "
3919 ha
->flags
.fce_enabled
= 0;
3924 memset(ha
->eft
, 0, EFT_SIZE
);
3925 rval
= qla2x00_enable_eft_trace(vha
,
3926 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3928 ql_log(ql_log_warn
, vha
, 0x8034,
3929 "Unable to reinitialize EFT "
3933 } else { /* failed the ISP abort */
3934 vha
->flags
.online
= 1;
3935 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
3936 if (ha
->isp_abort_cnt
== 0) {
3937 ql_log(ql_log_fatal
, vha
, 0x8035,
3938 "ISP error recover failed - "
3939 "board disabled.\n");
3941 * The next call disables the board
3944 ha
->isp_ops
->reset_adapter(vha
);
3945 vha
->flags
.online
= 0;
3946 clear_bit(ISP_ABORT_RETRY
,
3949 } else { /* schedule another ISP abort */
3950 ha
->isp_abort_cnt
--;
3951 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
3952 "ISP abort - retry remaining %d.\n",
3957 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3958 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
3959 "ISP error recovery - retrying (%d) "
3960 "more times.\n", ha
->isp_abort_cnt
);
3961 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3969 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
3971 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3972 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3974 atomic_inc(&vp
->vref_count
);
3975 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3977 qla2x00_vp_abort_isp(vp
);
3979 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3980 atomic_dec(&vp
->vref_count
);
3983 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3986 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
3994 * qla2x00_restart_isp
3995 * restarts the ISP after a reset
3998 * ha = adapter block pointer.
4004 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
4008 struct qla_hw_data
*ha
= vha
->hw
;
4009 struct req_que
*req
= ha
->req_q_map
[0];
4010 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4011 unsigned long flags
;
4013 /* If firmware needs to be loaded */
4014 if (qla2x00_isp_firmware(vha
)) {
4015 vha
->flags
.online
= 0;
4016 status
= ha
->isp_ops
->chip_diag(vha
);
4018 status
= qla2x00_setup_chip(vha
);
4021 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
4022 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4023 ha
->flags
.chip_reset_done
= 1;
4024 /* Initialize the queues in use */
4025 qla25xx_init_queues(ha
);
4027 status
= qla2x00_fw_ready(vha
);
4029 ql_dbg(ql_dbg_taskm
, vha
, 0x8031,
4030 "Start configure loop status = %d.\n", status
);
4032 /* Issue a marker after FW becomes ready. */
4033 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4035 vha
->flags
.online
= 1;
4038 * Process any ATIO queue entries that came in
4039 * while we weren't online.
4041 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4042 if (qla_tgt_mode_enabled(vha
))
4043 qlt_24xx_process_atio_queue(vha
);
4044 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4046 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4049 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4050 qla2x00_configure_loop(vha
);
4052 } while (!atomic_read(&vha
->loop_down_timer
) &&
4053 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
4054 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
4058 /* if no cable then assume it's good */
4059 if ((vha
->device_flags
& DFLG_NO_CABLE
))
4062 ql_dbg(ql_dbg_taskm
, vha
, 0x8032,
4063 "Configure loop done, status = 0x%x.\n", status
);
4069 qla25xx_init_queues(struct qla_hw_data
*ha
)
4071 struct rsp_que
*rsp
= NULL
;
4072 struct req_que
*req
= NULL
;
4073 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4077 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
4078 rsp
= ha
->rsp_q_map
[i
];
4080 rsp
->options
&= ~BIT_0
;
4081 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
4082 if (ret
!= QLA_SUCCESS
)
4083 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
4084 "%s Rsp que: %d init failed.\n",
4087 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
4088 "%s Rsp que: %d inited.\n",
4092 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
4093 req
= ha
->req_q_map
[i
];
4095 /* Clear outstanding commands array. */
4096 req
->options
&= ~BIT_0
;
4097 ret
= qla25xx_init_req_que(base_vha
, req
);
4098 if (ret
!= QLA_SUCCESS
)
4099 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
4100 "%s Req que: %d init failed.\n",
4103 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
4104 "%s Req que: %d inited.\n",
4112 * qla2x00_reset_adapter
4116 * ha = adapter block pointer.
4119 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
4121 unsigned long flags
= 0;
4122 struct qla_hw_data
*ha
= vha
->hw
;
4123 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4125 vha
->flags
.online
= 0;
4126 ha
->isp_ops
->disable_intrs(ha
);
4128 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4129 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
4130 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4131 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
4132 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4133 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4137 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
4139 unsigned long flags
= 0;
4140 struct qla_hw_data
*ha
= vha
->hw
;
4141 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
4146 vha
->flags
.online
= 0;
4147 ha
->isp_ops
->disable_intrs(ha
);
4149 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4150 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
4151 RD_REG_DWORD(®
->hccr
);
4152 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
4153 RD_REG_DWORD(®
->hccr
);
4154 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4156 if (IS_NOPOLLING_TYPE(ha
))
4157 ha
->isp_ops
->enable_intrs(ha
);
4160 /* On sparc systems, obtain port and node WWN from firmware
4163 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
4164 struct nvram_24xx
*nv
)
4167 struct qla_hw_data
*ha
= vha
->hw
;
4168 struct pci_dev
*pdev
= ha
->pdev
;
4169 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4173 val
= of_get_property(dp
, "port-wwn", &len
);
4174 if (val
&& len
>= WWN_SIZE
)
4175 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4177 val
= of_get_property(dp
, "node-wwn", &len
);
4178 if (val
&& len
>= WWN_SIZE
)
4179 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4184 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
4187 struct init_cb_24xx
*icb
;
4188 struct nvram_24xx
*nv
;
4190 uint8_t *dptr1
, *dptr2
;
4193 struct qla_hw_data
*ha
= vha
->hw
;
4196 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
4199 /* Determine NVRAM starting address. */
4200 if (ha
->flags
.port0
) {
4201 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
4202 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
4204 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
4205 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
4207 ha
->nvram_size
= sizeof(struct nvram_24xx
);
4208 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4210 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
4212 /* Get VPD data into cache */
4213 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4214 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
4215 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
4217 /* Get NVRAM data into cache and calculate checksum. */
4218 dptr
= (uint32_t *)nv
;
4219 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
4221 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4222 chksum
+= le32_to_cpu(*dptr
++);
4224 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
4225 "Contents of NVRAM\n");
4226 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
4227 (uint8_t *)nv
, ha
->nvram_size
);
4229 /* Bad NVRAM data, set defaults parameters. */
4230 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4231 || nv
->id
[3] != ' ' ||
4232 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4233 /* Reset NVRAM data. */
4234 ql_log(ql_log_warn
, vha
, 0x006b,
4235 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
4236 "version=0x%x.\n", chksum
, nv
->id
[0], nv
->nvram_version
);
4237 ql_log(ql_log_warn
, vha
, 0x006c,
4238 "Falling back to functioning (yet invalid -- WWPN) "
4242 * Set default initialization control block.
4244 memset(nv
, 0, ha
->nvram_size
);
4245 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4246 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4247 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4248 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4249 nv
->exchange_count
= __constant_cpu_to_le16(0);
4250 nv
->hard_address
= __constant_cpu_to_le16(124);
4251 nv
->port_name
[0] = 0x21;
4252 nv
->port_name
[1] = 0x00 + ha
->port_no
;
4253 nv
->port_name
[2] = 0x00;
4254 nv
->port_name
[3] = 0xe0;
4255 nv
->port_name
[4] = 0x8b;
4256 nv
->port_name
[5] = 0x1c;
4257 nv
->port_name
[6] = 0x55;
4258 nv
->port_name
[7] = 0x86;
4259 nv
->node_name
[0] = 0x20;
4260 nv
->node_name
[1] = 0x00;
4261 nv
->node_name
[2] = 0x00;
4262 nv
->node_name
[3] = 0xe0;
4263 nv
->node_name
[4] = 0x8b;
4264 nv
->node_name
[5] = 0x1c;
4265 nv
->node_name
[6] = 0x55;
4266 nv
->node_name
[7] = 0x86;
4267 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
4268 nv
->login_retry_count
= __constant_cpu_to_le16(8);
4269 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
4270 nv
->login_timeout
= __constant_cpu_to_le16(0);
4271 nv
->firmware_options_1
=
4272 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
4273 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
4274 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4275 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
4276 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
4277 nv
->efi_parameters
= __constant_cpu_to_le32(0);
4278 nv
->reset_delay
= 5;
4279 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
4280 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
4281 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
4286 if (!qla_ini_mode_enabled(vha
)) {
4287 /* Don't enable full login after initial LIP */
4288 nv
->firmware_options_1
&= __constant_cpu_to_le32(~BIT_13
);
4289 /* Don't enable LIP full login for initiator */
4290 nv
->host_p
&= __constant_cpu_to_le32(~BIT_10
);
4293 qlt_24xx_config_nvram_stage1(vha
, nv
);
4295 /* Reset Initialization control block */
4296 memset(icb
, 0, ha
->init_cb_size
);
4298 /* Copy 1st segment. */
4299 dptr1
= (uint8_t *)icb
;
4300 dptr2
= (uint8_t *)&nv
->version
;
4301 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
4303 *dptr1
++ = *dptr2
++;
4305 icb
->login_retry_count
= nv
->login_retry_count
;
4306 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
4308 /* Copy 2nd segment. */
4309 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
4310 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
4311 cnt
= (uint8_t *)&icb
->reserved_3
-
4312 (uint8_t *)&icb
->interrupt_delay_timer
;
4314 *dptr1
++ = *dptr2
++;
4317 * Setup driver NVRAM options.
4319 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
4322 qlt_24xx_config_nvram_stage2(vha
, icb
);
4324 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
4325 /* Use alternate WWN? */
4326 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4327 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4330 /* Prepare nodename */
4331 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
4333 * Firmware will apply the following mask if the nodename was
4336 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4337 icb
->node_name
[0] &= 0xF0;
4340 /* Set host adapter parameters. */
4341 ha
->flags
.disable_risc_code_load
= 0;
4342 ha
->flags
.enable_lip_reset
= 0;
4343 ha
->flags
.enable_lip_full_login
=
4344 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
4345 ha
->flags
.enable_target_reset
=
4346 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
4347 ha
->flags
.enable_led_scheme
= 0;
4348 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
4350 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
4351 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4353 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
4354 sizeof(ha
->fw_seriallink_options24
));
4356 /* save HBA serial number */
4357 ha
->serial0
= icb
->port_name
[5];
4358 ha
->serial1
= icb
->port_name
[6];
4359 ha
->serial2
= icb
->port_name
[7];
4360 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4361 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4363 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4365 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
4367 /* Set minimum login_timeout to 4 seconds. */
4368 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
4369 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
4370 if (le16_to_cpu(nv
->login_timeout
) < 4)
4371 nv
->login_timeout
= __constant_cpu_to_le16(4);
4372 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
4373 icb
->login_timeout
= nv
->login_timeout
;
4375 /* Set minimum RATOV to 100 tenths of a second. */
4378 ha
->loop_reset_delay
= nv
->reset_delay
;
4380 /* Link Down Timeout = 0:
4382 * When Port Down timer expires we will start returning
4383 * I/O's to OS with "DID_NO_CONNECT".
4385 * Link Down Timeout != 0:
4387 * The driver waits for the link to come up after link down
4388 * before returning I/Os to OS with "DID_NO_CONNECT".
4390 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
4391 ha
->loop_down_abort_time
=
4392 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4394 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
4395 ha
->loop_down_abort_time
=
4396 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4399 /* Need enough time to try and get the port back. */
4400 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
4401 if (qlport_down_retry
)
4402 ha
->port_down_retry_count
= qlport_down_retry
;
4404 /* Set login_retry_count */
4405 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
4406 if (ha
->port_down_retry_count
==
4407 le16_to_cpu(nv
->port_down_retry_count
) &&
4408 ha
->port_down_retry_count
> 3)
4409 ha
->login_retry_count
= ha
->port_down_retry_count
;
4410 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4411 ha
->login_retry_count
= ha
->port_down_retry_count
;
4412 if (ql2xloginretrycount
)
4413 ha
->login_retry_count
= ql2xloginretrycount
;
4416 if (!vha
->flags
.init_done
) {
4417 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
4418 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4419 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
4420 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
4422 icb
->firmware_options_2
&= __constant_cpu_to_le32(
4423 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
4424 vha
->flags
.process_response_queue
= 0;
4425 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4426 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4428 ql_log(ql_log_info
, vha
, 0x006f,
4429 "ZIO mode %d enabled; timer delay (%d us).\n",
4430 ha
->zio_mode
, ha
->zio_timer
* 100);
4432 icb
->firmware_options_2
|= cpu_to_le32(
4433 (uint32_t)ha
->zio_mode
);
4434 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
4435 vha
->flags
.process_response_queue
= 1;
4439 ql_log(ql_log_warn
, vha
, 0x0070,
4440 "NVRAM configuration failed.\n");
4446 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
4449 int rval
= QLA_SUCCESS
;
4450 int segments
, fragment
;
4451 uint32_t *dcode
, dlen
;
4455 struct qla_hw_data
*ha
= vha
->hw
;
4456 struct req_que
*req
= ha
->req_q_map
[0];
4458 ql_dbg(ql_dbg_init
, vha
, 0x008b,
4459 "FW: Loading firmware from flash (%x).\n", faddr
);
4463 segments
= FA_RISC_CODE_SEGMENTS
;
4464 dcode
= (uint32_t *)req
->ring
;
4467 /* Validate firmware image by checking version. */
4468 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
4469 for (i
= 0; i
< 4; i
++)
4470 dcode
[i
] = be32_to_cpu(dcode
[i
]);
4471 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4472 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4473 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4475 ql_log(ql_log_fatal
, vha
, 0x008c,
4476 "Unable to verify the integrity of flash firmware "
4478 ql_log(ql_log_fatal
, vha
, 0x008d,
4479 "Firmware data: %08x %08x %08x %08x.\n",
4480 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
4482 return QLA_FUNCTION_FAILED
;
4485 while (segments
&& rval
== QLA_SUCCESS
) {
4486 /* Read segment's load information. */
4487 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
4489 risc_addr
= be32_to_cpu(dcode
[2]);
4490 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4491 risc_size
= be32_to_cpu(dcode
[3]);
4494 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4495 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4496 if (dlen
> risc_size
)
4499 ql_dbg(ql_dbg_init
, vha
, 0x008e,
4500 "Loading risc segment@ risc addr %x "
4501 "number of dwords 0x%x offset 0x%x.\n",
4502 risc_addr
, dlen
, faddr
);
4504 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
4505 for (i
= 0; i
< dlen
; i
++)
4506 dcode
[i
] = swab32(dcode
[i
]);
4508 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4511 ql_log(ql_log_fatal
, vha
, 0x008f,
4512 "Failed to load segment %d of firmware.\n",
4530 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4533 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4537 uint16_t *wcode
, *fwcode
;
4538 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
4539 struct fw_blob
*blob
;
4540 struct qla_hw_data
*ha
= vha
->hw
;
4541 struct req_que
*req
= ha
->req_q_map
[0];
4543 /* Load firmware blob. */
4544 blob
= qla2x00_request_firmware(vha
);
4546 ql_log(ql_log_info
, vha
, 0x0083,
4547 "Fimware image unavailable.\n");
4548 ql_log(ql_log_info
, vha
, 0x0084,
4549 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
4550 return QLA_FUNCTION_FAILED
;
4555 wcode
= (uint16_t *)req
->ring
;
4557 fwcode
= (uint16_t *)blob
->fw
->data
;
4560 /* Validate firmware image by checking version. */
4561 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
4562 ql_log(ql_log_fatal
, vha
, 0x0085,
4563 "Unable to verify integrity of firmware image (%Zd).\n",
4565 goto fail_fw_integrity
;
4567 for (i
= 0; i
< 4; i
++)
4568 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
4569 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
4570 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
4571 wcode
[2] == 0 && wcode
[3] == 0)) {
4572 ql_log(ql_log_fatal
, vha
, 0x0086,
4573 "Unable to verify integrity of firmware image.\n");
4574 ql_log(ql_log_fatal
, vha
, 0x0087,
4575 "Firmware data: %04x %04x %04x %04x.\n",
4576 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
4577 goto fail_fw_integrity
;
4581 while (*seg
&& rval
== QLA_SUCCESS
) {
4583 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
4584 risc_size
= be16_to_cpu(fwcode
[3]);
4586 /* Validate firmware image size. */
4587 fwclen
+= risc_size
* sizeof(uint16_t);
4588 if (blob
->fw
->size
< fwclen
) {
4589 ql_log(ql_log_fatal
, vha
, 0x0088,
4590 "Unable to verify integrity of firmware image "
4591 "(%Zd).\n", blob
->fw
->size
);
4592 goto fail_fw_integrity
;
4596 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4597 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
4598 if (wlen
> risc_size
)
4600 ql_dbg(ql_dbg_init
, vha
, 0x0089,
4601 "Loading risc segment@ risc addr %x number of "
4602 "words 0x%x.\n", risc_addr
, wlen
);
4604 for (i
= 0; i
< wlen
; i
++)
4605 wcode
[i
] = swab16(fwcode
[i
]);
4607 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4610 ql_log(ql_log_fatal
, vha
, 0x008a,
4611 "Failed to load segment %d of firmware.\n",
4628 return QLA_FUNCTION_FAILED
;
4632 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4635 int segments
, fragment
;
4636 uint32_t *dcode
, dlen
;
4640 struct fw_blob
*blob
;
4641 uint32_t *fwcode
, fwclen
;
4642 struct qla_hw_data
*ha
= vha
->hw
;
4643 struct req_que
*req
= ha
->req_q_map
[0];
4645 /* Load firmware blob. */
4646 blob
= qla2x00_request_firmware(vha
);
4648 ql_log(ql_log_warn
, vha
, 0x0090,
4649 "Fimware image unavailable.\n");
4650 ql_log(ql_log_warn
, vha
, 0x0091,
4651 "Firmware images can be retrieved from: "
4654 return QLA_FUNCTION_FAILED
;
4657 ql_dbg(ql_dbg_init
, vha
, 0x0092,
4658 "FW: Loading via request-firmware.\n");
4662 segments
= FA_RISC_CODE_SEGMENTS
;
4663 dcode
= (uint32_t *)req
->ring
;
4665 fwcode
= (uint32_t *)blob
->fw
->data
;
4668 /* Validate firmware image by checking version. */
4669 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
4670 ql_log(ql_log_fatal
, vha
, 0x0093,
4671 "Unable to verify integrity of firmware image (%Zd).\n",
4673 goto fail_fw_integrity
;
4675 for (i
= 0; i
< 4; i
++)
4676 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
4677 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4678 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4679 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4681 ql_log(ql_log_fatal
, vha
, 0x0094,
4682 "Unable to verify integrity of firmware image (%Zd).\n",
4684 ql_log(ql_log_fatal
, vha
, 0x0095,
4685 "Firmware data: %08x %08x %08x %08x.\n",
4686 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
4687 goto fail_fw_integrity
;
4690 while (segments
&& rval
== QLA_SUCCESS
) {
4691 risc_addr
= be32_to_cpu(fwcode
[2]);
4692 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4693 risc_size
= be32_to_cpu(fwcode
[3]);
4695 /* Validate firmware image size. */
4696 fwclen
+= risc_size
* sizeof(uint32_t);
4697 if (blob
->fw
->size
< fwclen
) {
4698 ql_log(ql_log_fatal
, vha
, 0x0096,
4699 "Unable to verify integrity of firmware image "
4700 "(%Zd).\n", blob
->fw
->size
);
4702 goto fail_fw_integrity
;
4706 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4707 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4708 if (dlen
> risc_size
)
4711 ql_dbg(ql_dbg_init
, vha
, 0x0097,
4712 "Loading risc segment@ risc addr %x "
4713 "number of dwords 0x%x.\n", risc_addr
, dlen
);
4715 for (i
= 0; i
< dlen
; i
++)
4716 dcode
[i
] = swab32(fwcode
[i
]);
4718 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4721 ql_log(ql_log_fatal
, vha
, 0x0098,
4722 "Failed to load segment %d of firmware.\n",
4739 return QLA_FUNCTION_FAILED
;
4743 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4747 if (ql2xfwloadbin
== 1)
4748 return qla81xx_load_risc(vha
, srisc_addr
);
4752 * 1) Firmware via request-firmware interface (.bin file).
4753 * 2) Firmware residing in flash.
4755 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4756 if (rval
== QLA_SUCCESS
)
4759 return qla24xx_load_risc_flash(vha
, srisc_addr
,
4760 vha
->hw
->flt_region_fw
);
4764 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4767 struct qla_hw_data
*ha
= vha
->hw
;
4769 if (ql2xfwloadbin
== 2)
4774 * 1) Firmware residing in flash.
4775 * 2) Firmware via request-firmware interface (.bin file).
4776 * 3) Golden-Firmware residing in flash -- limited operation.
4778 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
4779 if (rval
== QLA_SUCCESS
)
4783 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4784 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
4787 ql_log(ql_log_info
, vha
, 0x0099,
4788 "Attempting to fallback to golden firmware.\n");
4789 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
4790 if (rval
!= QLA_SUCCESS
)
4793 ql_log(ql_log_info
, vha
, 0x009a, "Update operational firmware.\n");
4794 ha
->flags
.running_gold_fw
= 1;
4799 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
4802 struct qla_hw_data
*ha
= vha
->hw
;
4804 if (ha
->flags
.pci_channel_io_perm_failure
)
4806 if (!IS_FWI2_CAPABLE(ha
))
4808 if (!ha
->fw_major_version
)
4811 ret
= qla2x00_stop_firmware(vha
);
4812 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
4813 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
4814 ha
->isp_ops
->reset_chip(vha
);
4815 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
4817 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
4819 ql_log(ql_log_info
, vha
, 0x8015,
4820 "Attempting retry of stop-firmware command.\n");
4821 ret
= qla2x00_stop_firmware(vha
);
4826 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
4828 int rval
= QLA_SUCCESS
;
4830 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4831 struct qla_hw_data
*ha
= vha
->hw
;
4832 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4833 struct req_que
*req
;
4834 struct rsp_que
*rsp
;
4839 rval
= qla2x00_fw_ready(base_vha
);
4840 if (ha
->flags
.cpu_affinity_enabled
)
4841 req
= ha
->req_q_map
[0];
4846 if (rval
== QLA_SUCCESS
) {
4847 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4848 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4851 vha
->flags
.management_server_logged_in
= 0;
4853 /* Login to SNS first */
4854 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
4856 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
4857 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
4858 ql_dbg(ql_dbg_init
, vha
, 0x0120,
4859 "Failed SNS login: loop_id=%x, rval2=%d\n",
4862 ql_dbg(ql_dbg_init
, vha
, 0x0103,
4863 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4864 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
4865 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
4866 return (QLA_FUNCTION_FAILED
);
4869 atomic_set(&vha
->loop_down_timer
, 0);
4870 atomic_set(&vha
->loop_state
, LOOP_UP
);
4871 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4872 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4873 rval
= qla2x00_loop_resync(base_vha
);
4878 /* 84XX Support **************************************************************/
4880 static LIST_HEAD(qla_cs84xx_list
);
4881 static DEFINE_MUTEX(qla_cs84xx_mutex
);
4883 static struct qla_chip_state_84xx
*
4884 qla84xx_get_chip(struct scsi_qla_host
*vha
)
4886 struct qla_chip_state_84xx
*cs84xx
;
4887 struct qla_hw_data
*ha
= vha
->hw
;
4889 mutex_lock(&qla_cs84xx_mutex
);
4891 /* Find any shared 84xx chip. */
4892 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
4893 if (cs84xx
->bus
== ha
->pdev
->bus
) {
4894 kref_get(&cs84xx
->kref
);
4899 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
4903 kref_init(&cs84xx
->kref
);
4904 spin_lock_init(&cs84xx
->access_lock
);
4905 mutex_init(&cs84xx
->fw_update_mutex
);
4906 cs84xx
->bus
= ha
->pdev
->bus
;
4908 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
4910 mutex_unlock(&qla_cs84xx_mutex
);
4915 __qla84xx_chip_release(struct kref
*kref
)
4917 struct qla_chip_state_84xx
*cs84xx
=
4918 container_of(kref
, struct qla_chip_state_84xx
, kref
);
4920 mutex_lock(&qla_cs84xx_mutex
);
4921 list_del(&cs84xx
->list
);
4922 mutex_unlock(&qla_cs84xx_mutex
);
4927 qla84xx_put_chip(struct scsi_qla_host
*vha
)
4929 struct qla_hw_data
*ha
= vha
->hw
;
4931 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
4935 qla84xx_init_chip(scsi_qla_host_t
*vha
)
4939 struct qla_hw_data
*ha
= vha
->hw
;
4941 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
4943 rval
= qla84xx_verify_chip(vha
, status
);
4945 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
4947 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
4951 /* 81XX Support **************************************************************/
4954 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
4957 struct init_cb_81xx
*icb
;
4958 struct nvram_81xx
*nv
;
4960 uint8_t *dptr1
, *dptr2
;
4963 struct qla_hw_data
*ha
= vha
->hw
;
4966 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
4969 /* Determine NVRAM starting address. */
4970 ha
->nvram_size
= sizeof(struct nvram_81xx
);
4971 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4973 /* Get VPD data into cache */
4974 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4975 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
4978 /* Get NVRAM data into cache and calculate checksum. */
4979 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
4981 dptr
= (uint32_t *)nv
;
4982 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4983 chksum
+= le32_to_cpu(*dptr
++);
4985 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
4986 "Contents of NVRAM:\n");
4987 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
4988 (uint8_t *)nv
, ha
->nvram_size
);
4990 /* Bad NVRAM data, set defaults parameters. */
4991 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4992 || nv
->id
[3] != ' ' ||
4993 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4994 /* Reset NVRAM data. */
4995 ql_log(ql_log_info
, vha
, 0x0073,
4996 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
4997 "version=0x%x.\n", chksum
, nv
->id
[0],
4998 le16_to_cpu(nv
->nvram_version
));
4999 ql_log(ql_log_info
, vha
, 0x0074,
5000 "Falling back to functioning (yet invalid -- WWPN) "
5004 * Set default initialization control block.
5006 memset(nv
, 0, ha
->nvram_size
);
5007 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
5008 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
5009 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
5010 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5011 nv
->exchange_count
= __constant_cpu_to_le16(0);
5012 nv
->port_name
[0] = 0x21;
5013 nv
->port_name
[1] = 0x00 + ha
->port_no
;
5014 nv
->port_name
[2] = 0x00;
5015 nv
->port_name
[3] = 0xe0;
5016 nv
->port_name
[4] = 0x8b;
5017 nv
->port_name
[5] = 0x1c;
5018 nv
->port_name
[6] = 0x55;
5019 nv
->port_name
[7] = 0x86;
5020 nv
->node_name
[0] = 0x20;
5021 nv
->node_name
[1] = 0x00;
5022 nv
->node_name
[2] = 0x00;
5023 nv
->node_name
[3] = 0xe0;
5024 nv
->node_name
[4] = 0x8b;
5025 nv
->node_name
[5] = 0x1c;
5026 nv
->node_name
[6] = 0x55;
5027 nv
->node_name
[7] = 0x86;
5028 nv
->login_retry_count
= __constant_cpu_to_le16(8);
5029 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
5030 nv
->login_timeout
= __constant_cpu_to_le16(0);
5031 nv
->firmware_options_1
=
5032 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
5033 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
5034 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
5035 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
5036 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
5037 nv
->efi_parameters
= __constant_cpu_to_le32(0);
5038 nv
->reset_delay
= 5;
5039 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
5040 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
5041 nv
->link_down_timeout
= __constant_cpu_to_le16(180);
5042 nv
->enode_mac
[0] = 0x00;
5043 nv
->enode_mac
[1] = 0xC0;
5044 nv
->enode_mac
[2] = 0xDD;
5045 nv
->enode_mac
[3] = 0x04;
5046 nv
->enode_mac
[4] = 0x05;
5047 nv
->enode_mac
[5] = 0x06 + ha
->port_no
;
5052 /* Reset Initialization control block */
5053 memset(icb
, 0, ha
->init_cb_size
);
5055 /* Copy 1st segment. */
5056 dptr1
= (uint8_t *)icb
;
5057 dptr2
= (uint8_t *)&nv
->version
;
5058 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
5060 *dptr1
++ = *dptr2
++;
5062 icb
->login_retry_count
= nv
->login_retry_count
;
5064 /* Copy 2nd segment. */
5065 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
5066 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
5067 cnt
= (uint8_t *)&icb
->reserved_5
-
5068 (uint8_t *)&icb
->interrupt_delay_timer
;
5070 *dptr1
++ = *dptr2
++;
5072 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
5073 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5074 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
5075 icb
->enode_mac
[0] = 0x00;
5076 icb
->enode_mac
[1] = 0xC0;
5077 icb
->enode_mac
[2] = 0xDD;
5078 icb
->enode_mac
[3] = 0x04;
5079 icb
->enode_mac
[4] = 0x05;
5080 icb
->enode_mac
[5] = 0x06 + ha
->port_no
;
5083 /* Use extended-initialization control block. */
5084 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
5087 * Setup driver NVRAM options.
5089 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
5092 /* Use alternate WWN? */
5093 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
5094 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
5095 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
5098 /* Prepare nodename */
5099 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
5101 * Firmware will apply the following mask if the nodename was
5104 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
5105 icb
->node_name
[0] &= 0xF0;
5108 /* Set host adapter parameters. */
5109 ha
->flags
.disable_risc_code_load
= 0;
5110 ha
->flags
.enable_lip_reset
= 0;
5111 ha
->flags
.enable_lip_full_login
=
5112 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
5113 ha
->flags
.enable_target_reset
=
5114 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
5115 ha
->flags
.enable_led_scheme
= 0;
5116 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
5118 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
5119 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
5121 /* save HBA serial number */
5122 ha
->serial0
= icb
->port_name
[5];
5123 ha
->serial1
= icb
->port_name
[6];
5124 ha
->serial2
= icb
->port_name
[7];
5125 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
5126 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
5128 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5130 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
5132 /* Set minimum login_timeout to 4 seconds. */
5133 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
5134 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
5135 if (le16_to_cpu(nv
->login_timeout
) < 4)
5136 nv
->login_timeout
= __constant_cpu_to_le16(4);
5137 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
5138 icb
->login_timeout
= nv
->login_timeout
;
5140 /* Set minimum RATOV to 100 tenths of a second. */
5143 ha
->loop_reset_delay
= nv
->reset_delay
;
5145 /* Link Down Timeout = 0:
5147 * When Port Down timer expires we will start returning
5148 * I/O's to OS with "DID_NO_CONNECT".
5150 * Link Down Timeout != 0:
5152 * The driver waits for the link to come up after link down
5153 * before returning I/Os to OS with "DID_NO_CONNECT".
5155 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
5156 ha
->loop_down_abort_time
=
5157 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
5159 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
5160 ha
->loop_down_abort_time
=
5161 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
5164 /* Need enough time to try and get the port back. */
5165 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
5166 if (qlport_down_retry
)
5167 ha
->port_down_retry_count
= qlport_down_retry
;
5169 /* Set login_retry_count */
5170 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
5171 if (ha
->port_down_retry_count
==
5172 le16_to_cpu(nv
->port_down_retry_count
) &&
5173 ha
->port_down_retry_count
> 3)
5174 ha
->login_retry_count
= ha
->port_down_retry_count
;
5175 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
5176 ha
->login_retry_count
= ha
->port_down_retry_count
;
5177 if (ql2xloginretrycount
)
5178 ha
->login_retry_count
= ql2xloginretrycount
;
5180 /* if not running MSI-X we need handshaking on interrupts */
5181 if (!vha
->hw
->flags
.msix_enabled
&& IS_QLA83XX(ha
))
5182 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_22
);
5185 if (!vha
->flags
.init_done
) {
5186 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
5187 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
5188 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
5189 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
5191 icb
->firmware_options_2
&= __constant_cpu_to_le32(
5192 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
5193 vha
->flags
.process_response_queue
= 0;
5194 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
5195 ha
->zio_mode
= QLA_ZIO_MODE_6
;
5197 ql_log(ql_log_info
, vha
, 0x0075,
5198 "ZIO mode %d enabled; timer delay (%d us).\n",
5200 ha
->zio_timer
* 100);
5202 icb
->firmware_options_2
|= cpu_to_le32(
5203 (uint32_t)ha
->zio_mode
);
5204 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
5205 vha
->flags
.process_response_queue
= 1;
5209 ql_log(ql_log_warn
, vha
, 0x0076,
5210 "NVRAM configuration failed.\n");
5216 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
5220 struct qla_hw_data
*ha
= vha
->hw
;
5221 struct req_que
*req
= ha
->req_q_map
[0];
5222 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
5223 struct scsi_qla_host
*vp
;
5224 unsigned long flags
;
5226 status
= qla2x00_init_rings(vha
);
5228 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5229 ha
->flags
.chip_reset_done
= 1;
5231 status
= qla2x00_fw_ready(vha
);
5233 ql_log(ql_log_info
, vha
, 0x803c,
5234 "Start configure loop, status =%d.\n", status
);
5236 /* Issue a marker after FW becomes ready. */
5237 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5239 vha
->flags
.online
= 1;
5240 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5243 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5244 qla2x00_configure_loop(vha
);
5246 } while (!atomic_read(&vha
->loop_down_timer
) &&
5247 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
)) &&
5249 (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)));
5252 /* if no cable then assume it's good */
5253 if ((vha
->device_flags
& DFLG_NO_CABLE
))
5256 ql_log(ql_log_info
, vha
, 0x8000,
5257 "Configure loop done, status = 0x%x.\n", status
);
5261 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5263 if (!atomic_read(&vha
->loop_down_timer
)) {
5265 * Issue marker command only when we are going
5266 * to start the I/O .
5268 vha
->marker_needed
= 1;
5271 vha
->flags
.online
= 1;
5273 ha
->isp_ops
->enable_intrs(ha
);
5275 ha
->isp_abort_cnt
= 0;
5276 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5278 /* Update the firmware version */
5279 status
= qla82xx_check_md_needed(vha
);
5282 ha
->flags
.fce_enabled
= 1;
5284 fce_calc_size(ha
->fce_bufs
));
5285 rval
= qla2x00_enable_fce_trace(vha
,
5286 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
5289 ql_log(ql_log_warn
, vha
, 0x8001,
5290 "Unable to reinitialize FCE (%d).\n",
5292 ha
->flags
.fce_enabled
= 0;
5297 memset(ha
->eft
, 0, EFT_SIZE
);
5298 rval
= qla2x00_enable_eft_trace(vha
,
5299 ha
->eft_dma
, EFT_NUM_BUFFERS
);
5301 ql_log(ql_log_warn
, vha
, 0x8010,
5302 "Unable to reinitialize EFT (%d).\n",
5309 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
5310 "qla82xx_restart_isp succeeded.\n");
5312 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5313 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
5315 atomic_inc(&vp
->vref_count
);
5316 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5318 qla2x00_vp_abort_isp(vp
);
5320 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5321 atomic_dec(&vp
->vref_count
);
5324 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5327 ql_log(ql_log_warn
, vha
, 0x8016,
5328 "qla82xx_restart_isp **** FAILED ****.\n");
5335 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
5337 struct qla_hw_data
*ha
= vha
->hw
;
5342 /* Enable ETS Burst. */
5343 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
5344 ha
->fw_options
[2] |= BIT_9
;
5345 qla2x00_set_fw_options(vha
, ha
->fw_options
);
5349 * qla24xx_get_fcp_prio
5350 * Gets the fcp cmd priority value for the logged in port.
5351 * Looks for a match of the port descriptors within
5352 * each of the fcp prio config entries. If a match is found,
5353 * the tag (priority) value is returned.
5356 * vha = scsi host structure pointer.
5357 * fcport = port structure pointer.
5360 * non-zero (if found)
5367 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5370 uint8_t pid_match
, wwn_match
;
5372 uint32_t pid1
, pid2
;
5373 uint64_t wwn1
, wwn2
;
5374 struct qla_fcp_prio_entry
*pri_entry
;
5375 struct qla_hw_data
*ha
= vha
->hw
;
5377 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
5381 entries
= ha
->fcp_prio_cfg
->num_entries
;
5382 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
5384 for (i
= 0; i
< entries
; i
++) {
5385 pid_match
= wwn_match
= 0;
5387 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
5392 /* check source pid for a match */
5393 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
5394 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
5395 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
5396 if (pid1
== INVALID_PORT_ID
)
5398 else if (pid1
== pid2
)
5402 /* check destination pid for a match */
5403 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
5404 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
5405 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
5406 if (pid1
== INVALID_PORT_ID
)
5408 else if (pid1
== pid2
)
5412 /* check source WWN for a match */
5413 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
5414 wwn1
= wwn_to_u64(vha
->port_name
);
5415 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
5416 if (wwn2
== (uint64_t)-1)
5418 else if (wwn1
== wwn2
)
5422 /* check destination WWN for a match */
5423 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
5424 wwn1
= wwn_to_u64(fcport
->port_name
);
5425 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
5426 if (wwn2
== (uint64_t)-1)
5428 else if (wwn1
== wwn2
)
5432 if (pid_match
== 2 || wwn_match
== 2) {
5433 /* Found a matching entry */
5434 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
5435 priority
= pri_entry
->tag
;
5446 * qla24xx_update_fcport_fcp_prio
5447 * Activates fcp priority for the logged in fc port
5450 * vha = scsi host structure pointer.
5451 * fcp = port structure pointer.
5454 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5460 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5466 if (fcport
->port_type
!= FCT_TARGET
||
5467 fcport
->loop_id
== FC_NO_LOOP_ID
)
5468 return QLA_FUNCTION_FAILED
;
5470 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
5472 return QLA_FUNCTION_FAILED
;
5474 if (IS_QLA82XX(vha
->hw
)) {
5475 fcport
->fcp_prio
= priority
& 0xf;
5479 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
5480 if (ret
== QLA_SUCCESS
) {
5481 if (fcport
->fcp_prio
!= priority
)
5482 ql_dbg(ql_dbg_user
, vha
, 0x709e,
5483 "Updated FCP_CMND priority - value=%d loop_id=%d "
5484 "port_id=%02x%02x%02x.\n", priority
,
5485 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5486 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5487 fcport
->fcp_prio
= priority
& 0xf;
5489 ql_dbg(ql_dbg_user
, vha
, 0x704f,
5490 "Unable to update FCP_CMND priority - ret=0x%x for "
5491 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
5492 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5493 fcport
->d_id
.b
.al_pa
);
5498 * qla24xx_update_all_fcp_prio
5499 * Activates fcp priority for all the logged in ports
5502 * ha = adapter block pointer.
5505 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5511 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
5516 ret
= QLA_FUNCTION_FAILED
;
5517 /* We need to set priority for all logged in ports */
5518 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5519 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);