2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 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"
21 * QLogic ISP2x00 Hardware Support Function Prototypes.
23 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
24 static int qla2x00_setup_chip(scsi_qla_host_t
*);
25 static int qla2x00_init_rings(scsi_qla_host_t
*);
26 static int qla2x00_fw_ready(scsi_qla_host_t
*);
27 static int qla2x00_configure_hba(scsi_qla_host_t
*);
28 static int qla2x00_configure_loop(scsi_qla_host_t
*);
29 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
30 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
32 static int qla2x00_device_resync(scsi_qla_host_t
*);
33 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
36 static int qla2x00_restart_isp(scsi_qla_host_t
*);
38 static int qla2x00_find_new_loop_id(scsi_qla_host_t
*, fc_port_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_ctx_sp_timeout(unsigned long __data
)
49 srb_t
*sp
= (srb_t
*)__data
;
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
;
61 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
67 qla2x00_ctx_sp_free(srb_t
*sp
)
69 struct srb_ctx
*ctx
= sp
->ctx
;
72 mempool_free(sp
, sp
->fcport
->vha
->hw
->srb_mempool
);
76 qla2x00_get_ctx_sp(scsi_qla_host_t
*vha
, fc_port_t
*fcport
, size_t size
,
80 struct qla_hw_data
*ha
= vha
->hw
;
83 sp
= mempool_alloc(ha
->srb_mempool
, GFP_KERNEL
);
86 ctx
= kzalloc(size
, GFP_KERNEL
);
88 mempool_free(sp
, ha
->srb_mempool
);
92 memset(sp
, 0, sizeof(*sp
));
95 ctx
->free
= qla2x00_ctx_sp_free
;
97 init_timer(&ctx
->timer
);
100 ctx
->timer
.expires
= jiffies
+ tmo
* HZ
;
101 ctx
->timer
.data
= (unsigned long)sp
;
102 ctx
->timer
.function
= qla2x00_ctx_sp_timeout
;
103 add_timer(&ctx
->timer
);
108 /* Asynchronous Login/Logout Routines -------------------------------------- */
110 #define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
113 qla2x00_async_logio_timeout(srb_t
*sp
)
115 fc_port_t
*fcport
= sp
->fcport
;
116 struct srb_logio
*lio
= sp
->ctx
;
118 DEBUG2(printk(KERN_WARNING
119 "scsi(%ld:%x): Async-%s timeout.\n",
120 fcport
->vha
->host_no
, sp
->handle
,
121 lio
->ctx
.type
== SRB_LOGIN_CMD
? "login": "logout"));
123 if (lio
->ctx
.type
== SRB_LOGIN_CMD
)
124 qla2x00_post_async_logout_work(fcport
->vha
, fcport
, NULL
);
128 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
131 struct qla_hw_data
*ha
= vha
->hw
;
133 struct srb_logio
*lio
;
136 rval
= QLA_FUNCTION_FAILED
;
137 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_logio
),
138 ELS_TMO_2_RATOV(ha
) + 2);
143 lio
->ctx
.type
= SRB_LOGIN_CMD
;
144 lio
->ctx
.timeout
= qla2x00_async_logio_timeout
;
145 lio
->flags
|= SRB_LOGIN_COND_PLOGI
;
146 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
147 lio
->flags
|= SRB_LOGIN_RETRIED
;
148 rval
= qla2x00_start_sp(sp
);
149 if (rval
!= QLA_SUCCESS
)
152 DEBUG2(printk(KERN_DEBUG
153 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
154 "retries=%d.\n", fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
155 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
156 fcport
->login_retry
));
160 del_timer_sync(&lio
->ctx
.timer
);
167 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
169 struct qla_hw_data
*ha
= vha
->hw
;
171 struct srb_logio
*lio
;
174 rval
= QLA_FUNCTION_FAILED
;
175 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_logio
),
176 ELS_TMO_2_RATOV(ha
) + 2);
181 lio
->ctx
.type
= SRB_LOGOUT_CMD
;
182 lio
->ctx
.timeout
= qla2x00_async_logio_timeout
;
183 rval
= qla2x00_start_sp(sp
);
184 if (rval
!= QLA_SUCCESS
)
187 DEBUG2(printk(KERN_DEBUG
188 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
189 fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
190 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
194 del_timer_sync(&lio
->ctx
.timer
);
201 qla2x00_async_login_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
208 case MBS_COMMAND_COMPLETE
:
209 if (fcport
->flags
& FCF_FCP2_DEVICE
)
211 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
212 if (rval
!= QLA_SUCCESS
)
213 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
215 qla2x00_update_fcport(vha
, fcport
);
217 case MBS_COMMAND_ERROR
:
218 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
219 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
221 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
223 case MBS_PORT_ID_USED
:
224 fcport
->loop_id
= data
[1];
225 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
227 case MBS_LOOP_ID_USED
:
229 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
230 if (rval
!= QLA_SUCCESS
) {
231 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
234 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
241 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
244 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
248 /****************************************************************************/
249 /* QLogic ISP2x00 Hardware Support Functions. */
250 /****************************************************************************/
253 * qla2x00_initialize_adapter
257 * ha = adapter block pointer.
263 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
266 struct qla_hw_data
*ha
= vha
->hw
;
267 struct req_que
*req
= ha
->req_q_map
[0];
269 /* Clear adapter flags. */
270 vha
->flags
.online
= 0;
271 ha
->flags
.chip_reset_done
= 0;
272 vha
->flags
.reset_active
= 0;
273 ha
->flags
.pci_channel_io_perm_failure
= 0;
274 ha
->flags
.eeh_busy
= 0;
275 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
276 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
277 vha
->device_flags
= DFLG_NO_CABLE
;
279 vha
->flags
.management_server_logged_in
= 0;
280 vha
->marker_needed
= 0;
281 ha
->isp_abort_cnt
= 0;
282 ha
->beacon_blink_led
= 0;
284 set_bit(0, ha
->req_qid_map
);
285 set_bit(0, ha
->rsp_qid_map
);
287 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
288 rval
= ha
->isp_ops
->pci_config(vha
);
290 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
295 ha
->isp_ops
->reset_chip(vha
);
297 rval
= qla2xxx_get_flash_info(vha
);
299 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
304 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
306 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
308 ha
->isp_ops
->nvram_config(vha
);
310 if (ha
->flags
.disable_serdes
) {
311 /* Mask HBA via NVRAM settings? */
312 qla_printk(KERN_INFO
, ha
, "Masking HBA WWPN "
313 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
314 vha
->port_name
[0], vha
->port_name
[1],
315 vha
->port_name
[2], vha
->port_name
[3],
316 vha
->port_name
[4], vha
->port_name
[5],
317 vha
->port_name
[6], vha
->port_name
[7]);
318 return QLA_FUNCTION_FAILED
;
321 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
323 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
324 rval
= ha
->isp_ops
->chip_diag(vha
);
327 rval
= qla2x00_setup_chip(vha
);
331 if (IS_QLA84XX(ha
)) {
332 ha
->cs84xx
= qla84xx_get_chip(vha
);
334 qla_printk(KERN_ERR
, ha
,
335 "Unable to configure ISP84XX.\n");
336 return QLA_FUNCTION_FAILED
;
339 rval
= qla2x00_init_rings(vha
);
340 ha
->flags
.chip_reset_done
= 1;
342 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
343 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
344 rval
= qla84xx_init_chip(vha
);
345 if (rval
!= QLA_SUCCESS
) {
346 qla_printk(KERN_ERR
, ha
,
347 "Unable to initialize ISP84XX.\n");
348 qla84xx_put_chip(vha
);
356 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
359 * Returns 0 on success.
362 qla2100_pci_config(scsi_qla_host_t
*vha
)
366 struct qla_hw_data
*ha
= vha
->hw
;
367 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
369 pci_set_master(ha
->pdev
);
370 pci_try_set_mwi(ha
->pdev
);
372 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
373 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
374 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
376 pci_disable_rom(ha
->pdev
);
378 /* Get PCI bus information. */
379 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
380 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
381 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
387 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
390 * Returns 0 on success.
393 qla2300_pci_config(scsi_qla_host_t
*vha
)
396 unsigned long flags
= 0;
398 struct qla_hw_data
*ha
= vha
->hw
;
399 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
401 pci_set_master(ha
->pdev
);
402 pci_try_set_mwi(ha
->pdev
);
404 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
405 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
407 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
408 w
&= ~PCI_COMMAND_INTX_DISABLE
;
409 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
412 * If this is a 2300 card and not 2312, reset the
413 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
414 * the 2310 also reports itself as a 2300 so we need to get the
415 * fb revision level -- a 6 indicates it really is a 2300 and
418 if (IS_QLA2300(ha
)) {
419 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
422 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
423 for (cnt
= 0; cnt
< 30000; cnt
++) {
424 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
430 /* Select FPM registers. */
431 WRT_REG_WORD(®
->ctrl_status
, 0x20);
432 RD_REG_WORD(®
->ctrl_status
);
434 /* Get the fb rev level */
435 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
437 if (ha
->fb_rev
== FPM_2300
)
438 pci_clear_mwi(ha
->pdev
);
440 /* Deselect FPM registers. */
441 WRT_REG_WORD(®
->ctrl_status
, 0x0);
442 RD_REG_WORD(®
->ctrl_status
);
444 /* Release RISC module. */
445 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
446 for (cnt
= 0; cnt
< 30000; cnt
++) {
447 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
453 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
456 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
458 pci_disable_rom(ha
->pdev
);
460 /* Get PCI bus information. */
461 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
462 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
463 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
469 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
472 * Returns 0 on success.
475 qla24xx_pci_config(scsi_qla_host_t
*vha
)
478 unsigned long flags
= 0;
479 struct qla_hw_data
*ha
= vha
->hw
;
480 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
482 pci_set_master(ha
->pdev
);
483 pci_try_set_mwi(ha
->pdev
);
485 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
486 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
487 w
&= ~PCI_COMMAND_INTX_DISABLE
;
488 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
490 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
492 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
493 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
494 pcix_set_mmrbc(ha
->pdev
, 2048);
496 /* PCIe -- adjust Maximum Read Request Size (2048). */
497 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
498 pcie_set_readrq(ha
->pdev
, 2048);
500 pci_disable_rom(ha
->pdev
);
502 ha
->chip_revision
= ha
->pdev
->revision
;
504 /* Get PCI bus information. */
505 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
506 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
507 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
513 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
516 * Returns 0 on success.
519 qla25xx_pci_config(scsi_qla_host_t
*vha
)
522 struct qla_hw_data
*ha
= vha
->hw
;
524 pci_set_master(ha
->pdev
);
525 pci_try_set_mwi(ha
->pdev
);
527 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
528 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
529 w
&= ~PCI_COMMAND_INTX_DISABLE
;
530 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
532 /* PCIe -- adjust Maximum Read Request Size (2048). */
533 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
534 pcie_set_readrq(ha
->pdev
, 2048);
536 pci_disable_rom(ha
->pdev
);
538 ha
->chip_revision
= ha
->pdev
->revision
;
544 * qla2x00_isp_firmware() - Choose firmware image.
547 * Returns 0 on success.
550 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
553 uint16_t loop_id
, topo
, sw_cap
;
554 uint8_t domain
, area
, al_pa
;
555 struct qla_hw_data
*ha
= vha
->hw
;
557 /* Assume loading risc code */
558 rval
= QLA_FUNCTION_FAILED
;
560 if (ha
->flags
.disable_risc_code_load
) {
561 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
563 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
565 /* Verify checksum of loaded RISC code. */
566 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
567 if (rval
== QLA_SUCCESS
) {
568 /* And, verify we are not in ROM code. */
569 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
570 &area
, &domain
, &topo
, &sw_cap
);
575 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
583 * qla2x00_reset_chip() - Reset ISP chip.
586 * Returns 0 on success.
589 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
591 unsigned long flags
= 0;
592 struct qla_hw_data
*ha
= vha
->hw
;
593 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
597 if (unlikely(pci_channel_offline(ha
->pdev
)))
600 ha
->isp_ops
->disable_intrs(ha
);
602 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
604 /* Turn off master enable */
606 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
607 cmd
&= ~PCI_COMMAND_MASTER
;
608 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
610 if (!IS_QLA2100(ha
)) {
612 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
613 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
614 for (cnt
= 0; cnt
< 30000; cnt
++) {
615 if ((RD_REG_WORD(®
->hccr
) &
616 HCCR_RISC_PAUSE
) != 0)
621 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
625 /* Select FPM registers. */
626 WRT_REG_WORD(®
->ctrl_status
, 0x20);
627 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
629 /* FPM Soft Reset. */
630 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
631 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
633 /* Toggle Fpm Reset. */
634 if (!IS_QLA2200(ha
)) {
635 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
636 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
639 /* Select frame buffer registers. */
640 WRT_REG_WORD(®
->ctrl_status
, 0x10);
641 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
643 /* Reset frame buffer FIFOs. */
644 if (IS_QLA2200(ha
)) {
645 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
646 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
648 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
650 /* Read back fb_cmd until zero or 3 seconds max */
651 for (cnt
= 0; cnt
< 3000; cnt
++) {
652 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
658 /* Select RISC module registers. */
659 WRT_REG_WORD(®
->ctrl_status
, 0);
660 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
662 /* Reset RISC processor. */
663 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
664 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
666 /* Release RISC processor. */
667 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
668 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
671 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
672 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
674 /* Reset ISP chip. */
675 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
677 /* Wait for RISC to recover from reset. */
678 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
680 * It is necessary to for a delay here since the card doesn't
681 * respond to PCI reads during a reset. On some architectures
682 * this will result in an MCA.
685 for (cnt
= 30000; cnt
; cnt
--) {
686 if ((RD_REG_WORD(®
->ctrl_status
) &
687 CSR_ISP_SOFT_RESET
) == 0)
694 /* Reset RISC processor. */
695 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
697 WRT_REG_WORD(®
->semaphore
, 0);
699 /* Release RISC processor. */
700 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
701 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
703 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
704 for (cnt
= 0; cnt
< 30000; cnt
++) {
705 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
713 /* Turn on master enable */
714 cmd
|= PCI_COMMAND_MASTER
;
715 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
717 /* Disable RISC pause on FPM parity error. */
718 if (!IS_QLA2100(ha
)) {
719 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
720 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
723 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
727 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
730 * Returns 0 on success.
733 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
735 unsigned long flags
= 0;
736 struct qla_hw_data
*ha
= vha
->hw
;
737 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
741 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
744 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
745 for (cnt
= 0; cnt
< 30000; cnt
++) {
746 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
752 WRT_REG_DWORD(®
->ctrl_status
,
753 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
754 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
757 /* Wait for firmware to complete NVRAM accesses. */
758 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
759 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
761 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
765 /* Wait for soft-reset to complete. */
766 d2
= RD_REG_DWORD(®
->ctrl_status
);
767 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
769 d2
= RD_REG_DWORD(®
->ctrl_status
);
773 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
774 RD_REG_DWORD(®
->hccr
);
776 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
777 RD_REG_DWORD(®
->hccr
);
779 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
780 RD_REG_DWORD(®
->hccr
);
782 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
783 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
785 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
789 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
791 if (IS_NOPOLLING_TYPE(ha
))
792 ha
->isp_ops
->enable_intrs(ha
);
796 * qla24xx_reset_chip() - Reset ISP24xx chip.
799 * Returns 0 on success.
802 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
804 struct qla_hw_data
*ha
= vha
->hw
;
806 if (pci_channel_offline(ha
->pdev
) &&
807 ha
->flags
.pci_channel_io_perm_failure
) {
811 ha
->isp_ops
->disable_intrs(ha
);
813 /* Perform RISC reset. */
814 qla24xx_reset_risc(vha
);
818 * qla2x00_chip_diag() - Test chip for proper operation.
821 * Returns 0 on success.
824 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
827 struct qla_hw_data
*ha
= vha
->hw
;
828 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
829 unsigned long flags
= 0;
833 struct req_que
*req
= ha
->req_q_map
[0];
835 /* Assume a failed state */
836 rval
= QLA_FUNCTION_FAILED
;
838 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
839 vha
->host_no
, (u_long
)®
->flash_address
));
841 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
843 /* Reset ISP chip. */
844 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
847 * We need to have a delay here since the card will not respond while
848 * in reset causing an MCA on some architectures.
851 data
= qla2x00_debounce_register(®
->ctrl_status
);
852 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
854 data
= RD_REG_WORD(®
->ctrl_status
);
859 goto chip_diag_failed
;
861 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
864 /* Reset RISC processor. */
865 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
866 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
868 /* Workaround for QLA2312 PCI parity error */
869 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
870 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
871 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
873 data
= RD_MAILBOX_REG(ha
, reg
, 0);
880 goto chip_diag_failed
;
882 /* Check product ID of chip */
883 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha
->host_no
));
885 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
886 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
887 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
888 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
889 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
890 mb
[3] != PROD_ID_3
) {
891 qla_printk(KERN_WARNING
, ha
,
892 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
894 goto chip_diag_failed
;
896 ha
->product_id
[0] = mb
[1];
897 ha
->product_id
[1] = mb
[2];
898 ha
->product_id
[2] = mb
[3];
899 ha
->product_id
[3] = mb
[4];
901 /* Adjust fw RISC transfer size */
902 if (req
->length
> 1024)
903 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
905 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
908 if (IS_QLA2200(ha
) &&
909 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
910 /* Limit firmware transfer size with a 2200A */
911 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
914 ha
->device_type
|= DT_ISP2200A
;
915 ha
->fw_transfer_size
= 128;
918 /* Wrap Incoming Mailboxes Test. */
919 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
921 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha
->host_no
));
922 rval
= qla2x00_mbx_reg_test(vha
);
924 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
926 qla_printk(KERN_WARNING
, ha
,
927 "Failed mailbox send register test\n");
930 /* Flag a successful rval */
933 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
937 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
938 "****\n", vha
->host_no
));
940 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
946 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
949 * Returns 0 on success.
952 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
955 struct qla_hw_data
*ha
= vha
->hw
;
956 struct req_que
*req
= ha
->req_q_map
[0];
958 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
960 rval
= qla2x00_mbx_reg_test(vha
);
962 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
964 qla_printk(KERN_WARNING
, ha
,
965 "Failed mailbox send register test\n");
967 /* Flag a successful rval */
975 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
978 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
979 eft_size
, fce_size
, mq_size
;
982 struct qla_hw_data
*ha
= vha
->hw
;
983 struct req_que
*req
= ha
->req_q_map
[0];
984 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
987 qla_printk(KERN_WARNING
, ha
,
988 "Firmware dump previously allocated.\n");
993 fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
994 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
995 fixed_size
= sizeof(struct qla2100_fw_dump
);
996 } else if (IS_QLA23XX(ha
)) {
997 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
998 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
1000 } else if (IS_FWI2_CAPABLE(ha
)) {
1002 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
1003 else if (IS_QLA25XX(ha
))
1004 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
1006 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
1007 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
1010 mq_size
= sizeof(struct qla2xxx_mq_chain
);
1011 /* Allocate memory for Fibre Channel Event Buffer. */
1012 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
))
1015 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
1018 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1019 "(%d KB) for FCE.\n", FCE_SIZE
/ 1024);
1023 memset(tc
, 0, FCE_SIZE
);
1024 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
1025 ha
->fce_mb
, &ha
->fce_bufs
);
1027 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1028 "FCE (%d).\n", rval
);
1029 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
1031 ha
->flags
.fce_enabled
= 0;
1035 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for FCE...\n",
1038 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
1039 ha
->flags
.fce_enabled
= 1;
1040 ha
->fce_dma
= tc_dma
;
1043 /* Allocate memory for Extended Trace Buffer. */
1044 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
1047 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1048 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
1052 memset(tc
, 0, EFT_SIZE
);
1053 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
1055 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1056 "EFT (%d).\n", rval
);
1057 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
1062 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
1065 eft_size
= EFT_SIZE
;
1066 ha
->eft_dma
= tc_dma
;
1070 req_q_size
= req
->length
* sizeof(request_t
);
1071 rsp_q_size
= rsp
->length
* sizeof(response_t
);
1073 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
1074 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
1075 ha
->chain_offset
= dump_size
;
1076 dump_size
+= mq_size
+ fce_size
;
1078 ha
->fw_dump
= vmalloc(dump_size
);
1080 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
1081 "firmware dump!!!\n", dump_size
/ 1024);
1084 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
1091 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
1094 ha
->fw_dump_len
= dump_size
;
1095 ha
->fw_dump
->signature
[0] = 'Q';
1096 ha
->fw_dump
->signature
[1] = 'L';
1097 ha
->fw_dump
->signature
[2] = 'G';
1098 ha
->fw_dump
->signature
[3] = 'C';
1099 ha
->fw_dump
->version
= __constant_htonl(1);
1101 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
1102 ha
->fw_dump
->mem_size
= htonl(mem_size
);
1103 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
1104 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
1106 ha
->fw_dump
->eft_size
= htonl(eft_size
);
1107 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
1108 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
1110 ha
->fw_dump
->header_size
=
1111 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
1115 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
1117 #define MPS_MASK 0xe0
1121 struct qla_hw_data
*ha
= vha
->hw
;
1123 if (!IS_QLA81XX(vha
->hw
))
1126 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
1127 if (rval
!= QLA_SUCCESS
) {
1128 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1129 "Sync-MPI: Unable to acquire semaphore.\n"));
1133 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
1134 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
1135 if (rval
!= QLA_SUCCESS
) {
1136 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1137 "Sync-MPI: Unable to read sync.\n"));
1142 if (dc
== (dw
& MPS_MASK
))
1147 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
1148 if (rval
!= QLA_SUCCESS
) {
1149 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1150 "Sync-MPI: Unable to gain sync.\n"));
1154 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
1155 if (rval
!= QLA_SUCCESS
) {
1156 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1157 "Sync-MPI: Unable to release semaphore.\n"));
1165 * qla2x00_setup_chip() - Load and start RISC firmware.
1168 * Returns 0 on success.
1171 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
1174 uint32_t srisc_address
= 0;
1175 struct qla_hw_data
*ha
= vha
->hw
;
1176 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1177 unsigned long flags
;
1178 uint16_t fw_major_version
;
1180 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1181 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1182 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1183 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
1184 RD_REG_WORD(®
->hccr
);
1185 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1188 qla81xx_mpi_sync(vha
);
1190 /* Load firmware sequences */
1191 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1192 if (rval
== QLA_SUCCESS
) {
1193 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
1194 "code.\n", vha
->host_no
));
1196 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
1197 if (rval
== QLA_SUCCESS
) {
1198 /* Start firmware execution. */
1199 DEBUG(printk("scsi(%ld): Checksum OK, start "
1200 "firmware.\n", vha
->host_no
));
1202 rval
= qla2x00_execute_fw(vha
, srisc_address
);
1203 /* Retrieve firmware information. */
1204 if (rval
== QLA_SUCCESS
) {
1205 fw_major_version
= ha
->fw_major_version
;
1206 rval
= qla2x00_get_fw_version(vha
,
1207 &ha
->fw_major_version
,
1208 &ha
->fw_minor_version
,
1209 &ha
->fw_subminor_version
,
1210 &ha
->fw_attributes
, &ha
->fw_memory_size
,
1211 ha
->mpi_version
, &ha
->mpi_capabilities
,
1213 if (rval
!= QLA_SUCCESS
)
1215 ha
->flags
.npiv_supported
= 0;
1216 if (IS_QLA2XXX_MIDTYPE(ha
) &&
1217 (ha
->fw_attributes
& BIT_2
)) {
1218 ha
->flags
.npiv_supported
= 1;
1219 if ((!ha
->max_npiv_vports
) ||
1220 ((ha
->max_npiv_vports
+ 1) %
1221 MIN_MULTI_ID_FABRIC
))
1222 ha
->max_npiv_vports
=
1223 MIN_MULTI_ID_FABRIC
- 1;
1225 qla2x00_get_resource_cnts(vha
, NULL
,
1226 &ha
->fw_xcb_count
, NULL
, NULL
,
1227 &ha
->max_npiv_vports
, NULL
);
1229 if (!fw_major_version
&& ql2xallocfwdump
)
1230 qla2x00_alloc_fw_dump(vha
);
1233 DEBUG2(printk(KERN_INFO
1234 "scsi(%ld): ISP Firmware failed checksum.\n",
1239 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1240 /* Enable proper parity. */
1241 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1244 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1246 /* SRAM, Instruction RAM and GP RAM parity */
1247 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1248 RD_REG_WORD(®
->hccr
);
1249 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1252 if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
1255 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
1256 if (rval
== QLA_SUCCESS
) {
1257 ha
->flags
.fac_supported
= 1;
1258 ha
->fdt_block_size
= size
<< 2;
1260 qla_printk(KERN_ERR
, ha
,
1261 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1262 ha
->fw_major_version
, ha
->fw_minor_version
,
1263 ha
->fw_subminor_version
);
1268 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1276 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1279 * Beginning of request ring has initialization control block already built
1280 * by nvram config routine.
1282 * Returns 0 on success.
1285 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1290 rsp
->ring_ptr
= rsp
->ring
;
1291 rsp
->ring_index
= 0;
1292 rsp
->status_srb
= NULL
;
1293 pkt
= rsp
->ring_ptr
;
1294 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1295 pkt
->signature
= RESPONSE_PROCESSED
;
1301 * qla2x00_update_fw_options() - Read and process firmware options.
1304 * Returns 0 on success.
1307 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1309 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1310 struct qla_hw_data
*ha
= vha
->hw
;
1312 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1313 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1315 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1318 /* Serial Link options. */
1319 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1321 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
1322 sizeof(ha
->fw_seriallink_options
)));
1324 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1325 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1326 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1329 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1330 emphasis
= (ha
->fw_seriallink_options
[2] &
1331 (BIT_4
| BIT_3
)) >> 3;
1332 tx_sens
= ha
->fw_seriallink_options
[0] &
1333 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1334 rx_sens
= (ha
->fw_seriallink_options
[0] &
1335 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1336 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1337 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1340 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1341 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1342 ha
->fw_options
[10] |= BIT_5
|
1343 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1344 (tx_sens
& (BIT_1
| BIT_0
));
1347 swing
= (ha
->fw_seriallink_options
[2] &
1348 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1349 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1350 tx_sens
= ha
->fw_seriallink_options
[1] &
1351 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1352 rx_sens
= (ha
->fw_seriallink_options
[1] &
1353 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1354 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1355 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1358 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1359 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1360 ha
->fw_options
[11] |= BIT_5
|
1361 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1362 (tx_sens
& (BIT_1
| BIT_0
));
1366 /* Return command IOCBs without waiting for an ABTS to complete. */
1367 ha
->fw_options
[3] |= BIT_13
;
1370 if (ha
->flags
.enable_led_scheme
)
1371 ha
->fw_options
[2] |= BIT_12
;
1373 /* Detect ISP6312. */
1375 ha
->fw_options
[2] |= BIT_13
;
1377 /* Update firmware options. */
1378 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1382 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1385 struct qla_hw_data
*ha
= vha
->hw
;
1387 /* Update Serial Link options. */
1388 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1391 rval
= qla2x00_set_serdes_params(vha
,
1392 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1393 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1394 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1395 if (rval
!= QLA_SUCCESS
) {
1396 qla_printk(KERN_WARNING
, ha
,
1397 "Unable to update Serial Link options (%x).\n", rval
);
1402 qla2x00_config_rings(struct scsi_qla_host
*vha
)
1404 struct qla_hw_data
*ha
= vha
->hw
;
1405 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1406 struct req_que
*req
= ha
->req_q_map
[0];
1407 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1409 /* Setup ring parameters in initialization control block. */
1410 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1411 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1412 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
1413 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
1414 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1415 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1416 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1417 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1419 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1420 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1421 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1422 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1423 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1427 qla24xx_config_rings(struct scsi_qla_host
*vha
)
1429 struct qla_hw_data
*ha
= vha
->hw
;
1430 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
1431 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
1432 struct qla_msix_entry
*msix
;
1433 struct init_cb_24xx
*icb
;
1435 struct req_que
*req
= ha
->req_q_map
[0];
1436 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1438 /* Setup ring parameters in initialization control block. */
1439 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1440 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1441 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1442 icb
->request_q_length
= cpu_to_le16(req
->length
);
1443 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
1444 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1445 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1446 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1447 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1450 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
1451 icb
->rid
= __constant_cpu_to_le16(rid
);
1452 if (ha
->flags
.msix_enabled
) {
1453 msix
= &ha
->msix_entries
[1];
1454 DEBUG2_17(printk(KERN_INFO
1455 "Registering vector 0x%x for base que\n", msix
->entry
));
1456 icb
->msix
= cpu_to_le16(msix
->entry
);
1458 /* Use alternate PCI bus number */
1460 icb
->firmware_options_2
|=
1461 __constant_cpu_to_le32(BIT_19
);
1462 /* Use alternate PCI devfn */
1464 icb
->firmware_options_2
|=
1465 __constant_cpu_to_le32(BIT_18
);
1467 /* Use Disable MSIX Handshake mode for capable adapters */
1468 if (IS_MSIX_NACK_CAPABLE(ha
)) {
1469 icb
->firmware_options_2
&=
1470 __constant_cpu_to_le32(~BIT_22
);
1471 ha
->flags
.disable_msix_handshake
= 1;
1472 qla_printk(KERN_INFO
, ha
,
1473 "MSIX Handshake Disable Mode turned on\n");
1475 icb
->firmware_options_2
|=
1476 __constant_cpu_to_le32(BIT_22
);
1478 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
1480 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
1481 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
1482 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
1483 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
1485 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
1486 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
1487 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
1488 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
1491 RD_REG_DWORD(&ioreg
->hccr
);
1495 * qla2x00_init_rings() - Initializes firmware.
1498 * Beginning of request ring has initialization control block already built
1499 * by nvram config routine.
1501 * Returns 0 on success.
1504 qla2x00_init_rings(scsi_qla_host_t
*vha
)
1507 unsigned long flags
= 0;
1509 struct qla_hw_data
*ha
= vha
->hw
;
1510 struct req_que
*req
;
1511 struct rsp_que
*rsp
;
1512 struct scsi_qla_host
*vp
;
1513 struct mid_init_cb_24xx
*mid_init_cb
=
1514 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1516 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1518 /* Clear outstanding commands array. */
1519 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1520 req
= ha
->req_q_map
[que
];
1523 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1524 req
->outstanding_cmds
[cnt
] = NULL
;
1526 req
->current_outstanding_cmd
= 1;
1528 /* Initialize firmware. */
1529 req
->ring_ptr
= req
->ring
;
1530 req
->ring_index
= 0;
1531 req
->cnt
= req
->length
;
1534 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
1535 rsp
= ha
->rsp_q_map
[que
];
1538 /* Initialize response queue entries */
1539 qla2x00_init_response_q_entries(rsp
);
1542 /* Clear RSCN queue. */
1543 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
1544 vp
->rscn_in_ptr
= 0;
1545 vp
->rscn_out_ptr
= 0;
1547 ha
->isp_ops
->config_rings(vha
);
1549 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1551 /* Update any ISP specific firmware options before initialization. */
1552 ha
->isp_ops
->update_fw_options(vha
);
1554 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha
->host_no
));
1556 if (ha
->flags
.npiv_supported
) {
1557 if (ha
->operating_mode
== LOOP
)
1558 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
1559 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1562 if (IS_FWI2_CAPABLE(ha
)) {
1563 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1564 mid_init_cb
->init_cb
.execution_throttle
=
1565 cpu_to_le16(ha
->fw_xcb_count
);
1568 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
1570 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1573 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1581 * qla2x00_fw_ready() - Waits for firmware ready.
1584 * Returns 0 on success.
1587 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
1590 unsigned long wtime
, mtime
, cs84xx_time
;
1591 uint16_t min_wait
; /* Minimum wait time if loop is down */
1592 uint16_t wait_time
; /* Wait time if loop is coming ready */
1594 struct qla_hw_data
*ha
= vha
->hw
;
1598 /* 20 seconds for loop down. */
1602 * Firmware should take at most one RATOV to login, plus 5 seconds for
1603 * our own processing.
1605 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1606 wait_time
= min_wait
;
1609 /* Min wait time if loop down */
1610 mtime
= jiffies
+ (min_wait
* HZ
);
1612 /* wait time before firmware ready */
1613 wtime
= jiffies
+ (wait_time
* HZ
);
1615 /* Wait for ISP to finish LIP */
1616 if (!vha
->flags
.init_done
)
1617 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1619 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1623 rval
= qla2x00_get_firmware_state(vha
, state
);
1624 if (rval
== QLA_SUCCESS
) {
1625 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
1626 vha
->device_flags
&= ~DFLG_NO_CABLE
;
1628 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
1629 DEBUG16(printk("scsi(%ld): fw_state=%x "
1630 "84xx=%x.\n", vha
->host_no
, state
[0],
1632 if ((state
[2] & FSTATE_LOGGED_IN
) &&
1633 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
1634 DEBUG16(printk("scsi(%ld): Sending "
1635 "verify iocb.\n", vha
->host_no
));
1637 cs84xx_time
= jiffies
;
1638 rval
= qla84xx_init_chip(vha
);
1639 if (rval
!= QLA_SUCCESS
)
1642 /* Add time taken to initialize. */
1643 cs84xx_time
= jiffies
- cs84xx_time
;
1644 wtime
+= cs84xx_time
;
1645 mtime
+= cs84xx_time
;
1646 DEBUG16(printk("scsi(%ld): Increasing "
1647 "wait time by %ld. New time %ld\n",
1648 vha
->host_no
, cs84xx_time
, wtime
));
1650 } else if (state
[0] == FSTATE_READY
) {
1651 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1654 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
1655 &ha
->login_timeout
, &ha
->r_a_tov
);
1661 rval
= QLA_FUNCTION_FAILED
;
1663 if (atomic_read(&vha
->loop_down_timer
) &&
1664 state
[0] != FSTATE_READY
) {
1665 /* Loop down. Timeout on min_wait for states
1666 * other than Wait for Login.
1668 if (time_after_eq(jiffies
, mtime
)) {
1669 qla_printk(KERN_INFO
, ha
,
1670 "Cable is unplugged...\n");
1672 vha
->device_flags
|= DFLG_NO_CABLE
;
1677 /* Mailbox cmd failed. Timeout on min_wait. */
1678 if (time_after_eq(jiffies
, mtime
))
1682 if (time_after_eq(jiffies
, wtime
))
1685 /* Delay for a while */
1688 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1689 vha
->host_no
, state
[0], jiffies
));
1692 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1693 vha
->host_no
, state
[0], state
[1], state
[2], state
[3], state
[4],
1697 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1705 * qla2x00_configure_hba
1706 * Setup adapter context.
1709 * ha = adapter state pointer.
1718 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
1727 char connect_type
[22];
1728 struct qla_hw_data
*ha
= vha
->hw
;
1730 /* Get host addresses. */
1731 rval
= qla2x00_get_adapter_id(vha
,
1732 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
1733 if (rval
!= QLA_SUCCESS
) {
1734 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
1735 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1736 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1737 __func__
, vha
->host_no
));
1739 qla_printk(KERN_WARNING
, ha
,
1740 "ERROR -- Unable to get host loop ID.\n");
1741 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1747 qla_printk(KERN_INFO
, ha
,
1748 "Cannot get topology - retrying.\n");
1749 return (QLA_FUNCTION_FAILED
);
1752 vha
->loop_id
= loop_id
;
1755 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1756 ha
->operating_mode
= LOOP
;
1761 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1763 ha
->current_topology
= ISP_CFG_NL
;
1764 strcpy(connect_type
, "(Loop)");
1768 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1770 ha
->switch_cap
= sw_cap
;
1771 ha
->current_topology
= ISP_CFG_FL
;
1772 strcpy(connect_type
, "(FL_Port)");
1776 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1778 ha
->operating_mode
= P2P
;
1779 ha
->current_topology
= ISP_CFG_N
;
1780 strcpy(connect_type
, "(N_Port-to-N_Port)");
1784 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1786 ha
->switch_cap
= sw_cap
;
1787 ha
->operating_mode
= P2P
;
1788 ha
->current_topology
= ISP_CFG_F
;
1789 strcpy(connect_type
, "(F_Port)");
1793 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1795 vha
->host_no
, topo
));
1796 ha
->current_topology
= ISP_CFG_NL
;
1797 strcpy(connect_type
, "(Loop)");
1801 /* Save Host port and loop ID. */
1802 /* byte order - Big Endian */
1803 vha
->d_id
.b
.domain
= domain
;
1804 vha
->d_id
.b
.area
= area
;
1805 vha
->d_id
.b
.al_pa
= al_pa
;
1807 if (!vha
->flags
.init_done
)
1808 qla_printk(KERN_INFO
, ha
,
1809 "Topology - %s, Host Loop address 0x%x\n",
1810 connect_type
, vha
->loop_id
);
1813 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha
->host_no
));
1815 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha
->host_no
));
1822 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
1827 struct qla_hw_data
*ha
= vha
->hw
;
1828 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
1831 if (memcmp(model
, BINZERO
, len
) != 0) {
1832 strncpy(ha
->model_number
, model
, len
);
1833 st
= en
= ha
->model_number
;
1836 if (*en
!= 0x20 && *en
!= 0x00)
1841 index
= (ha
->pdev
->subsystem_device
& 0xff);
1843 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1844 index
< QLA_MODEL_NAMES
)
1845 strncpy(ha
->model_desc
,
1846 qla2x00_model_name
[index
* 2 + 1],
1847 sizeof(ha
->model_desc
) - 1);
1849 index
= (ha
->pdev
->subsystem_device
& 0xff);
1851 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1852 index
< QLA_MODEL_NAMES
) {
1853 strcpy(ha
->model_number
,
1854 qla2x00_model_name
[index
* 2]);
1855 strncpy(ha
->model_desc
,
1856 qla2x00_model_name
[index
* 2 + 1],
1857 sizeof(ha
->model_desc
) - 1);
1859 strcpy(ha
->model_number
, def
);
1862 if (IS_FWI2_CAPABLE(ha
))
1863 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
1864 sizeof(ha
->model_desc
));
1867 /* On sparc systems, obtain port and node WWN from firmware
1870 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
1873 struct qla_hw_data
*ha
= vha
->hw
;
1874 struct pci_dev
*pdev
= ha
->pdev
;
1875 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
1879 val
= of_get_property(dp
, "port-wwn", &len
);
1880 if (val
&& len
>= WWN_SIZE
)
1881 memcpy(nv
->port_name
, val
, WWN_SIZE
);
1883 val
= of_get_property(dp
, "node-wwn", &len
);
1884 if (val
&& len
>= WWN_SIZE
)
1885 memcpy(nv
->node_name
, val
, WWN_SIZE
);
1890 * NVRAM configuration for ISP 2xxx
1893 * ha = adapter block pointer.
1896 * initialization control block in response_ring
1897 * host adapters parameters in host adapter block
1903 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
1908 uint8_t *dptr1
, *dptr2
;
1909 struct qla_hw_data
*ha
= vha
->hw
;
1910 init_cb_t
*icb
= ha
->init_cb
;
1911 nvram_t
*nv
= ha
->nvram
;
1912 uint8_t *ptr
= ha
->nvram
;
1913 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1917 /* Determine NVRAM starting address. */
1918 ha
->nvram_size
= sizeof(nvram_t
);
1920 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1921 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1922 ha
->nvram_base
= 0x80;
1924 /* Get NVRAM data and calculate checksum. */
1925 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1926 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1929 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
1930 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
1932 /* Bad NVRAM data, set defaults parameters. */
1933 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1934 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1935 /* Reset NVRAM data. */
1936 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1937 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1939 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1940 "invalid -- WWPN) defaults.\n");
1943 * Set default initialization control block.
1945 memset(nv
, 0, ha
->nvram_size
);
1946 nv
->parameter_block_version
= ICB_VERSION
;
1948 if (IS_QLA23XX(ha
)) {
1949 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1950 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1951 nv
->add_firmware_options
[0] = BIT_5
;
1952 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1953 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1954 nv
->special_options
[1] = BIT_7
;
1955 } else if (IS_QLA2200(ha
)) {
1956 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1957 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1958 nv
->add_firmware_options
[0] = BIT_5
;
1959 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1960 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1961 } else if (IS_QLA2100(ha
)) {
1962 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1963 nv
->firmware_options
[1] = BIT_5
;
1964 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1967 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1968 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1969 nv
->retry_count
= 8;
1970 nv
->retry_delay
= 1;
1972 nv
->port_name
[0] = 33;
1973 nv
->port_name
[3] = 224;
1974 nv
->port_name
[4] = 139;
1976 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
1978 nv
->login_timeout
= 4;
1981 * Set default host adapter parameters
1983 nv
->host_p
[1] = BIT_2
;
1984 nv
->reset_delay
= 5;
1985 nv
->port_down_retry_count
= 8;
1986 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1987 nv
->link_down_timeout
= 60;
1992 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1994 * The SN2 does not provide BIOS emulation which means you can't change
1995 * potentially bogus BIOS settings. Force the use of default settings
1996 * for link rate and frame size. Hope that the rest of the settings
1999 if (ia64_platform_is("sn2")) {
2000 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2002 nv
->special_options
[1] = BIT_7
;
2006 /* Reset Initialization control block */
2007 memset(icb
, 0, ha
->init_cb_size
);
2010 * Setup driver NVRAM options.
2012 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
2013 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
2014 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
2015 nv
->firmware_options
[1] &= ~BIT_4
;
2017 if (IS_QLA23XX(ha
)) {
2018 nv
->firmware_options
[0] |= BIT_2
;
2019 nv
->firmware_options
[0] &= ~BIT_3
;
2020 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
2022 if (IS_QLA2300(ha
)) {
2023 if (ha
->fb_rev
== FPM_2310
) {
2024 strcpy(ha
->model_number
, "QLA2310");
2026 strcpy(ha
->model_number
, "QLA2300");
2029 qla2x00_set_model_info(vha
, nv
->model_number
,
2030 sizeof(nv
->model_number
), "QLA23xx");
2032 } else if (IS_QLA2200(ha
)) {
2033 nv
->firmware_options
[0] |= BIT_2
;
2035 * 'Point-to-point preferred, else loop' is not a safe
2036 * connection mode setting.
2038 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
2040 /* Force 'loop preferred, else point-to-point'. */
2041 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
2042 nv
->add_firmware_options
[0] |= BIT_5
;
2044 strcpy(ha
->model_number
, "QLA22xx");
2045 } else /*if (IS_QLA2100(ha))*/ {
2046 strcpy(ha
->model_number
, "QLA2100");
2050 * Copy over NVRAM RISC parameter block to initialization control block.
2052 dptr1
= (uint8_t *)icb
;
2053 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
2054 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
2056 *dptr1
++ = *dptr2
++;
2058 /* Copy 2nd half. */
2059 dptr1
= (uint8_t *)icb
->add_firmware_options
;
2060 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
2062 *dptr1
++ = *dptr2
++;
2064 /* Use alternate WWN? */
2065 if (nv
->host_p
[1] & BIT_7
) {
2066 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
2067 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
2070 /* Prepare nodename */
2071 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
2073 * Firmware will apply the following mask if the nodename was
2076 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
2077 icb
->node_name
[0] &= 0xF0;
2081 * Set host adapter parameters.
2083 if (nv
->host_p
[0] & BIT_7
)
2084 ql2xextended_error_logging
= 1;
2085 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
2086 /* Always load RISC code on non ISP2[12]00 chips. */
2087 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2088 ha
->flags
.disable_risc_code_load
= 0;
2089 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
2090 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
2091 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
2092 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
2093 ha
->flags
.disable_serdes
= 0;
2095 ha
->operating_mode
=
2096 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
2098 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
2099 sizeof(ha
->fw_seriallink_options
));
2101 /* save HBA serial number */
2102 ha
->serial0
= icb
->port_name
[5];
2103 ha
->serial1
= icb
->port_name
[6];
2104 ha
->serial2
= icb
->port_name
[7];
2105 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
2106 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
2108 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
2110 ha
->retry_count
= nv
->retry_count
;
2112 /* Set minimum login_timeout to 4 seconds. */
2113 if (nv
->login_timeout
< ql2xlogintimeout
)
2114 nv
->login_timeout
= ql2xlogintimeout
;
2115 if (nv
->login_timeout
< 4)
2116 nv
->login_timeout
= 4;
2117 ha
->login_timeout
= nv
->login_timeout
;
2118 icb
->login_timeout
= nv
->login_timeout
;
2120 /* Set minimum RATOV to 100 tenths of a second. */
2123 ha
->loop_reset_delay
= nv
->reset_delay
;
2125 /* Link Down Timeout = 0:
2127 * When Port Down timer expires we will start returning
2128 * I/O's to OS with "DID_NO_CONNECT".
2130 * Link Down Timeout != 0:
2132 * The driver waits for the link to come up after link down
2133 * before returning I/Os to OS with "DID_NO_CONNECT".
2135 if (nv
->link_down_timeout
== 0) {
2136 ha
->loop_down_abort_time
=
2137 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
2139 ha
->link_down_timeout
= nv
->link_down_timeout
;
2140 ha
->loop_down_abort_time
=
2141 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
2145 * Need enough time to try and get the port back.
2147 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
2148 if (qlport_down_retry
)
2149 ha
->port_down_retry_count
= qlport_down_retry
;
2150 /* Set login_retry_count */
2151 ha
->login_retry_count
= nv
->retry_count
;
2152 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
2153 ha
->port_down_retry_count
> 3)
2154 ha
->login_retry_count
= ha
->port_down_retry_count
;
2155 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
2156 ha
->login_retry_count
= ha
->port_down_retry_count
;
2157 if (ql2xloginretrycount
)
2158 ha
->login_retry_count
= ql2xloginretrycount
;
2160 icb
->lun_enables
= __constant_cpu_to_le16(0);
2161 icb
->command_resource_count
= 0;
2162 icb
->immediate_notify_resource_count
= 0;
2163 icb
->timeout
= __constant_cpu_to_le16(0);
2165 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2167 icb
->firmware_options
[0] &= ~BIT_3
;
2168 icb
->add_firmware_options
[0] &=
2169 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2170 icb
->add_firmware_options
[0] |= BIT_2
;
2171 icb
->response_accumulation_timer
= 3;
2172 icb
->interrupt_delay_timer
= 5;
2174 vha
->flags
.process_response_queue
= 1;
2177 if (!vha
->flags
.init_done
) {
2178 ha
->zio_mode
= icb
->add_firmware_options
[0] &
2179 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2180 ha
->zio_timer
= icb
->interrupt_delay_timer
?
2181 icb
->interrupt_delay_timer
: 2;
2183 icb
->add_firmware_options
[0] &=
2184 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2185 vha
->flags
.process_response_queue
= 0;
2186 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
2187 ha
->zio_mode
= QLA_ZIO_MODE_6
;
2189 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
2190 "delay (%d us).\n", vha
->host_no
, ha
->zio_mode
,
2191 ha
->zio_timer
* 100));
2192 qla_printk(KERN_INFO
, ha
,
2193 "ZIO mode %d enabled; timer delay (%d us).\n",
2194 ha
->zio_mode
, ha
->zio_timer
* 100);
2196 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
2197 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
2198 vha
->flags
.process_response_queue
= 1;
2203 DEBUG2_3(printk(KERN_WARNING
2204 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
2210 qla2x00_rport_del(void *data
)
2212 fc_port_t
*fcport
= data
;
2213 struct fc_rport
*rport
;
2215 spin_lock_irq(fcport
->vha
->host
->host_lock
);
2216 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
2217 fcport
->drport
= NULL
;
2218 spin_unlock_irq(fcport
->vha
->host
->host_lock
);
2220 fc_remote_port_delete(rport
);
2224 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2226 * @flags: allocation flags
2228 * Returns a pointer to the allocated fcport, or NULL, if none available.
2231 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
2235 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
2239 /* Setup fcport template structure. */
2241 fcport
->vp_idx
= vha
->vp_idx
;
2242 fcport
->port_type
= FCT_UNKNOWN
;
2243 fcport
->loop_id
= FC_NO_LOOP_ID
;
2244 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
2245 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
2251 * qla2x00_configure_loop
2252 * Updates Fibre Channel Device Database with what is actually on loop.
2255 * ha = adapter block pointer.
2260 * 2 = database was full and device was not configured.
2263 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
2266 unsigned long flags
, save_flags
;
2267 struct qla_hw_data
*ha
= vha
->hw
;
2270 /* Get Initiator ID */
2271 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2272 rval
= qla2x00_configure_hba(vha
);
2273 if (rval
!= QLA_SUCCESS
) {
2274 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2280 save_flags
= flags
= vha
->dpc_flags
;
2281 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2282 vha
->host_no
, flags
));
2285 * If we have both an RSCN and PORT UPDATE pending then handle them
2286 * both at the same time.
2288 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2289 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2291 qla2x00_get_data_rate(vha
);
2293 /* Determine what we need to do */
2294 if (ha
->current_topology
== ISP_CFG_FL
&&
2295 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2297 vha
->flags
.rscn_queue_overflow
= 1;
2298 set_bit(RSCN_UPDATE
, &flags
);
2300 } else if (ha
->current_topology
== ISP_CFG_F
&&
2301 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2303 vha
->flags
.rscn_queue_overflow
= 1;
2304 set_bit(RSCN_UPDATE
, &flags
);
2305 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2307 } else if (ha
->current_topology
== ISP_CFG_N
) {
2308 clear_bit(RSCN_UPDATE
, &flags
);
2310 } else if (!vha
->flags
.online
||
2311 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2313 vha
->flags
.rscn_queue_overflow
= 1;
2314 set_bit(RSCN_UPDATE
, &flags
);
2315 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2318 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2319 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2320 rval
= QLA_FUNCTION_FAILED
;
2322 rval
= qla2x00_configure_local_loop(vha
);
2325 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2326 if (LOOP_TRANSITION(vha
))
2327 rval
= QLA_FUNCTION_FAILED
;
2329 rval
= qla2x00_configure_fabric(vha
);
2332 if (rval
== QLA_SUCCESS
) {
2333 if (atomic_read(&vha
->loop_down_timer
) ||
2334 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2335 rval
= QLA_FUNCTION_FAILED
;
2337 atomic_set(&vha
->loop_state
, LOOP_READY
);
2339 DEBUG(printk("scsi(%ld): LOOP READY\n", vha
->host_no
));
2344 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2345 __func__
, vha
->host_no
));
2347 DEBUG3(printk("%s: exiting normally\n", __func__
));
2350 /* Restore state if a resync event occurred during processing */
2351 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2352 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
2353 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2354 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
2355 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2356 vha
->flags
.rscn_queue_overflow
= 1;
2366 * qla2x00_configure_local_loop
2367 * Updates Fibre Channel Device Database with local loop devices.
2370 * ha = adapter block pointer.
2376 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
2381 fc_port_t
*fcport
, *new_fcport
;
2387 uint8_t domain
, area
, al_pa
;
2388 struct qla_hw_data
*ha
= vha
->hw
;
2392 entries
= MAX_FIBRE_DEVICES
;
2394 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha
->host_no
));
2395 DEBUG3(qla2x00_get_fcal_position_map(vha
, NULL
));
2397 /* Get list of logged in devices. */
2398 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
2399 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
2401 if (rval
!= QLA_SUCCESS
)
2402 goto cleanup_allocation
;
2404 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2405 vha
->host_no
, entries
));
2406 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
2407 entries
* sizeof(struct gid_list_info
)));
2409 /* Allocate temporary fcport for any new fcports discovered. */
2410 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2411 if (new_fcport
== NULL
) {
2412 rval
= QLA_MEMORY_ALLOC_FAILED
;
2413 goto cleanup_allocation
;
2415 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2418 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2420 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2421 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2422 fcport
->port_type
!= FCT_BROADCAST
&&
2423 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2425 DEBUG(printk("scsi(%ld): Marking port lost, "
2427 vha
->host_no
, fcport
->loop_id
));
2429 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2433 /* Add devices to port list. */
2434 id_iter
= (char *)ha
->gid_list
;
2435 for (index
= 0; index
< entries
; index
++) {
2436 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2437 area
= ((struct gid_list_info
*)id_iter
)->area
;
2438 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2439 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2440 loop_id
= (uint16_t)
2441 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2443 loop_id
= le16_to_cpu(
2444 ((struct gid_list_info
*)id_iter
)->loop_id
);
2445 id_iter
+= ha
->gid_list_info_size
;
2447 /* Bypass reserved domain fields. */
2448 if ((domain
& 0xf0) == 0xf0)
2451 /* Bypass if not same domain and area of adapter. */
2452 if (area
&& domain
&&
2453 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
2456 /* Bypass invalid local loop ID. */
2457 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2460 /* Fill in member data. */
2461 new_fcport
->d_id
.b
.domain
= domain
;
2462 new_fcport
->d_id
.b
.area
= area
;
2463 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2464 new_fcport
->loop_id
= loop_id
;
2465 new_fcport
->vp_idx
= vha
->vp_idx
;
2466 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
2467 if (rval2
!= QLA_SUCCESS
) {
2468 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2469 "information -- get_port_database=%x, "
2471 vha
->host_no
, rval2
, new_fcport
->loop_id
));
2472 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2474 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2478 /* Check for matching device in port list. */
2481 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2482 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2486 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2487 fcport
->loop_id
= new_fcport
->loop_id
;
2488 fcport
->port_type
= new_fcport
->port_type
;
2489 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2490 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2498 /* New device, add to fcports list. */
2500 new_fcport
->vha
= vha
;
2501 new_fcport
->vp_idx
= vha
->vp_idx
;
2503 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
2505 /* Allocate a new replacement fcport. */
2506 fcport
= new_fcport
;
2507 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2508 if (new_fcport
== NULL
) {
2509 rval
= QLA_MEMORY_ALLOC_FAILED
;
2510 goto cleanup_allocation
;
2512 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2515 /* Base iIDMA settings on HBA port speed. */
2516 fcport
->fp_speed
= ha
->link_data_rate
;
2518 qla2x00_update_fcport(vha
, fcport
);
2526 if (rval
!= QLA_SUCCESS
) {
2527 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2528 "rval=%x\n", vha
->host_no
, rval
));
2535 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2537 #define LS_UNKNOWN 2
2538 static char *link_speeds
[] = { "1", "2", "?", "4", "8", "10" };
2542 struct qla_hw_data
*ha
= vha
->hw
;
2544 if (!IS_IIDMA_CAPABLE(ha
))
2547 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2548 fcport
->fp_speed
> ha
->link_data_rate
)
2551 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
2553 if (rval
!= QLA_SUCCESS
) {
2554 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2555 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2556 vha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2557 fcport
->port_name
[2], fcport
->port_name
[3],
2558 fcport
->port_name
[4], fcport
->port_name
[5],
2559 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2560 fcport
->fp_speed
, mb
[0], mb
[1]));
2562 link_speed
= link_speeds
[LS_UNKNOWN
];
2563 if (fcport
->fp_speed
< 5)
2564 link_speed
= link_speeds
[fcport
->fp_speed
];
2565 else if (fcport
->fp_speed
== 0x13)
2566 link_speed
= link_speeds
[5];
2567 DEBUG2(qla_printk(KERN_INFO
, ha
,
2568 "iIDMA adjusted to %s GB/s on "
2569 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2570 link_speed
, fcport
->port_name
[0],
2571 fcport
->port_name
[1], fcport
->port_name
[2],
2572 fcport
->port_name
[3], fcport
->port_name
[4],
2573 fcport
->port_name
[5], fcport
->port_name
[6],
2574 fcport
->port_name
[7]));
2579 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2581 struct fc_rport_identifiers rport_ids
;
2582 struct fc_rport
*rport
;
2583 struct qla_hw_data
*ha
= vha
->hw
;
2585 qla2x00_rport_del(fcport
);
2587 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2588 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2589 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2590 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2591 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2592 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
2594 qla_printk(KERN_WARNING
, ha
,
2595 "Unable to allocate fc remote port!\n");
2598 spin_lock_irq(fcport
->vha
->host
->host_lock
);
2599 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2600 spin_unlock_irq(fcport
->vha
->host
->host_lock
);
2602 rport
->supported_classes
= fcport
->supported_classes
;
2604 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2605 if (fcport
->port_type
== FCT_INITIATOR
)
2606 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2607 if (fcport
->port_type
== FCT_TARGET
)
2608 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2609 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2613 * qla2x00_update_fcport
2614 * Updates device on list.
2617 * ha = adapter block pointer.
2618 * fcport = port structure pointer.
2628 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2630 struct qla_hw_data
*ha
= vha
->hw
;
2633 fcport
->login_retry
= 0;
2634 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2636 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2638 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2640 qla2x00_iidma_fcport(vha
, fcport
);
2642 atomic_set(&fcport
->state
, FCS_ONLINE
);
2644 qla2x00_reg_remote_port(vha
, fcport
);
2648 * qla2x00_configure_fabric
2649 * Setup SNS devices with loop ID's.
2652 * ha = adapter block pointer.
2659 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
2662 fc_port_t
*fcport
, *fcptemp
;
2663 uint16_t next_loopid
;
2664 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2666 LIST_HEAD(new_fcports
);
2667 struct qla_hw_data
*ha
= vha
->hw
;
2668 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2670 /* If FL port exists, then SNS is present */
2671 if (IS_FWI2_CAPABLE(ha
))
2672 loop_id
= NPH_F_PORT
;
2674 loop_id
= SNS_FL_PORT
;
2675 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
2676 if (rval
!= QLA_SUCCESS
) {
2677 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2678 "Port\n", vha
->host_no
));
2680 vha
->device_flags
&= ~SWITCH_FOUND
;
2681 return (QLA_SUCCESS
);
2683 vha
->device_flags
|= SWITCH_FOUND
;
2685 /* Mark devices that need re-synchronization. */
2686 rval2
= qla2x00_device_resync(vha
);
2687 if (rval2
== QLA_RSCNS_HANDLED
) {
2688 /* No point doing the scan, just continue. */
2689 return (QLA_SUCCESS
);
2693 if (ql2xfdmienable
&&
2694 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
2695 qla2x00_fdmi_register(vha
);
2697 /* Ensure we are logged into the SNS. */
2698 if (IS_FWI2_CAPABLE(ha
))
2701 loop_id
= SIMPLE_NAME_SERVER
;
2702 ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
2703 0xfc, mb
, BIT_1
| BIT_0
);
2704 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2705 DEBUG2(qla_printk(KERN_INFO
, ha
,
2706 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2707 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2708 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2709 return (QLA_SUCCESS
);
2712 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
2713 if (qla2x00_rft_id(vha
)) {
2715 DEBUG2(printk("scsi(%ld): Register FC-4 "
2716 "TYPE failed.\n", vha
->host_no
));
2718 if (qla2x00_rff_id(vha
)) {
2720 DEBUG2(printk("scsi(%ld): Register FC-4 "
2721 "Features failed.\n", vha
->host_no
));
2723 if (qla2x00_rnn_id(vha
)) {
2725 DEBUG2(printk("scsi(%ld): Register Node Name "
2726 "failed.\n", vha
->host_no
));
2727 } else if (qla2x00_rsnn_nn(vha
)) {
2729 DEBUG2(printk("scsi(%ld): Register Symbolic "
2730 "Node Name failed.\n", vha
->host_no
));
2734 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
2735 if (rval
!= QLA_SUCCESS
)
2739 * Logout all previous fabric devices marked lost, except
2742 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2743 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2746 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2749 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2750 qla2x00_mark_device_lost(vha
, fcport
,
2751 ql2xplogiabsentdevice
, 0);
2752 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2753 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
2754 fcport
->port_type
!= FCT_INITIATOR
&&
2755 fcport
->port_type
!= FCT_BROADCAST
) {
2756 ha
->isp_ops
->fabric_logout(vha
,
2758 fcport
->d_id
.b
.domain
,
2759 fcport
->d_id
.b
.area
,
2760 fcport
->d_id
.b
.al_pa
);
2761 fcport
->loop_id
= FC_NO_LOOP_ID
;
2766 /* Starting free loop ID. */
2767 next_loopid
= ha
->min_external_loopid
;
2770 * Scan through our port list and login entries that need to be
2773 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2774 if (atomic_read(&vha
->loop_down_timer
) ||
2775 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2778 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2779 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2782 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2783 fcport
->loop_id
= next_loopid
;
2784 rval
= qla2x00_find_new_loop_id(
2786 if (rval
!= QLA_SUCCESS
) {
2787 /* Ran out of IDs to use */
2791 /* Login and update database */
2792 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
2795 /* Exit if out of loop IDs. */
2796 if (rval
!= QLA_SUCCESS
) {
2801 * Login and add the new devices to our port list.
2803 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2804 if (atomic_read(&vha
->loop_down_timer
) ||
2805 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2808 /* Find a new loop ID to use. */
2809 fcport
->loop_id
= next_loopid
;
2810 rval
= qla2x00_find_new_loop_id(base_vha
, fcport
);
2811 if (rval
!= QLA_SUCCESS
) {
2812 /* Ran out of IDs to use */
2816 /* Login and update database */
2817 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
2821 fcport
->vp_idx
= vha
->vp_idx
;
2823 list_move_tail(&fcport
->list
, &vha
->vp_fcports
);
2827 /* Free all new device structures not processed. */
2828 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2829 list_del(&fcport
->list
);
2834 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2835 "rval=%d\n", vha
->host_no
, rval
));
2843 * qla2x00_find_all_fabric_devs
2846 * ha = adapter block pointer.
2847 * dev = database device entry pointer.
2856 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
2857 struct list_head
*new_fcports
)
2861 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2866 int first_dev
, last_dev
;
2867 port_id_t wrap
, nxt_d_id
;
2868 struct qla_hw_data
*ha
= vha
->hw
;
2869 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
2870 struct scsi_qla_host
*tvp
;
2874 /* Try GID_PT to get device list, else GAN. */
2875 swl
= kcalloc(MAX_FIBRE_DEVICES
, sizeof(sw_info_t
), GFP_KERNEL
);
2878 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2879 "on GA_NXT\n", vha
->host_no
));
2881 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
2884 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
2887 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
2890 } else if (ql2xiidmaenable
&&
2891 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
2892 qla2x00_gpsc(vha
, swl
);
2897 /* Allocate temporary fcport for any new fcports discovered. */
2898 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2899 if (new_fcport
== NULL
) {
2901 return (QLA_MEMORY_ALLOC_FAILED
);
2903 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2904 /* Set start port ID scan at adapter ID. */
2908 /* Starting free loop ID. */
2909 loop_id
= ha
->min_external_loopid
;
2910 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
2911 if (qla2x00_is_reserved_id(vha
, loop_id
))
2914 if (atomic_read(&vha
->loop_down_timer
) ||
2915 LOOP_TRANSITION(vha
)) {
2916 atomic_set(&vha
->loop_down_timer
, 0);
2917 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2918 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2924 wrap
.b24
= new_fcport
->d_id
.b24
;
2926 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2927 memcpy(new_fcport
->node_name
,
2928 swl
[swl_idx
].node_name
, WWN_SIZE
);
2929 memcpy(new_fcport
->port_name
,
2930 swl
[swl_idx
].port_name
, WWN_SIZE
);
2931 memcpy(new_fcport
->fabric_port_name
,
2932 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
2933 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
2935 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2941 /* Send GA_NXT to the switch */
2942 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
2943 if (rval
!= QLA_SUCCESS
) {
2944 qla_printk(KERN_WARNING
, ha
,
2945 "SNS scan failed -- assuming zero-entry "
2947 list_for_each_entry_safe(fcport
, fcptemp
,
2948 new_fcports
, list
) {
2949 list_del(&fcport
->list
);
2957 /* If wrap on switch device list, exit. */
2959 wrap
.b24
= new_fcport
->d_id
.b24
;
2961 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2962 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2963 vha
->host_no
, new_fcport
->d_id
.b
.domain
,
2964 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2968 /* Bypass if same physical adapter. */
2969 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
2972 /* Bypass virtual ports of the same host. */
2974 if (ha
->num_vhosts
) {
2975 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
2976 if (new_fcport
->d_id
.b24
== vp
->d_id
.b24
) {
2985 /* Bypass if same domain and area of adapter. */
2986 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2987 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2991 /* Bypass reserved domain fields. */
2992 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2995 /* Locate matching device in database. */
2997 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2998 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
3004 /* Update port state. */
3005 memcpy(fcport
->fabric_port_name
,
3006 new_fcport
->fabric_port_name
, WWN_SIZE
);
3007 fcport
->fp_speed
= new_fcport
->fp_speed
;
3010 * If address the same and state FCS_ONLINE, nothing
3013 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
3014 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3019 * If device was not a fabric device before.
3021 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
3022 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3023 fcport
->loop_id
= FC_NO_LOOP_ID
;
3024 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
3030 * Port ID changed or device was marked to be updated;
3031 * Log it out if still logged in and mark it for
3034 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3035 fcport
->flags
|= FCF_LOGIN_NEEDED
;
3036 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3037 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3038 fcport
->port_type
!= FCT_INITIATOR
&&
3039 fcport
->port_type
!= FCT_BROADCAST
) {
3040 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3041 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3042 fcport
->d_id
.b
.al_pa
);
3043 fcport
->loop_id
= FC_NO_LOOP_ID
;
3051 /* If device was not in our fcports list, then add it. */
3052 list_add_tail(&new_fcport
->list
, new_fcports
);
3054 /* Allocate a new replacement fcport. */
3055 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
3056 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3057 if (new_fcport
== NULL
) {
3059 return (QLA_MEMORY_ALLOC_FAILED
);
3061 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3062 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
3072 * qla2x00_find_new_loop_id
3073 * Scan through our port list and find a new usable loop ID.
3076 * ha: adapter state pointer.
3077 * dev: port structure pointer.
3080 * qla2x00 local function return status code.
3086 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
3091 uint16_t first_loop_id
;
3092 struct qla_hw_data
*ha
= vha
->hw
;
3093 struct scsi_qla_host
*vp
;
3094 struct scsi_qla_host
*tvp
;
3098 /* Save starting loop ID. */
3099 first_loop_id
= dev
->loop_id
;
3102 /* Skip loop ID if already used by adapter. */
3103 if (dev
->loop_id
== vha
->loop_id
)
3106 /* Skip reserved loop IDs. */
3107 while (qla2x00_is_reserved_id(vha
, dev
->loop_id
))
3110 /* Reset loop ID if passed the end. */
3111 if (dev
->loop_id
> ha
->max_loop_id
) {
3112 /* first loop ID. */
3113 dev
->loop_id
= ha
->min_external_loopid
;
3116 /* Check for loop ID being already in use. */
3119 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3120 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
) {
3121 if (fcport
->loop_id
== dev
->loop_id
&&
3123 /* ID possibly in use */
3132 /* If not in use then it is free to use. */
3137 /* ID in use. Try next value. */
3140 /* If wrap around. No free ID to use. */
3141 if (dev
->loop_id
== first_loop_id
) {
3142 dev
->loop_id
= FC_NO_LOOP_ID
;
3143 rval
= QLA_FUNCTION_FAILED
;
3152 * qla2x00_device_resync
3153 * Marks devices in the database that needs resynchronization.
3156 * ha = adapter block pointer.
3162 qla2x00_device_resync(scsi_qla_host_t
*vha
)
3167 uint32_t rscn_entry
;
3168 uint8_t rscn_out_iter
;
3172 rval
= QLA_RSCNS_HANDLED
;
3174 while (vha
->rscn_out_ptr
!= vha
->rscn_in_ptr
||
3175 vha
->flags
.rscn_queue_overflow
) {
3177 rscn_entry
= vha
->rscn_queue
[vha
->rscn_out_ptr
];
3178 format
= MSB(MSW(rscn_entry
));
3179 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
3180 d_id
.b
.area
= MSB(LSW(rscn_entry
));
3181 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
3183 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3184 "[%02x/%02x%02x%02x].\n",
3185 vha
->host_no
, vha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
3186 d_id
.b
.area
, d_id
.b
.al_pa
));
3188 vha
->rscn_out_ptr
++;
3189 if (vha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
3190 vha
->rscn_out_ptr
= 0;
3192 /* Skip duplicate entries. */
3193 for (rscn_out_iter
= vha
->rscn_out_ptr
;
3194 !vha
->flags
.rscn_queue_overflow
&&
3195 rscn_out_iter
!= vha
->rscn_in_ptr
;
3196 rscn_out_iter
= (rscn_out_iter
==
3197 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
3199 if (rscn_entry
!= vha
->rscn_queue
[rscn_out_iter
])
3202 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
3203 "entry found at [%d].\n", vha
->host_no
,
3206 vha
->rscn_out_ptr
= rscn_out_iter
;
3209 /* Queue overflow, set switch default case. */
3210 if (vha
->flags
.rscn_queue_overflow
) {
3211 DEBUG(printk("scsi(%ld): device_resync: rscn "
3212 "overflow.\n", vha
->host_no
));
3215 vha
->flags
.rscn_queue_overflow
= 0;
3231 vha
->rscn_out_ptr
= vha
->rscn_in_ptr
;
3237 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3238 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
3239 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
3240 fcport
->port_type
== FCT_BROADCAST
)
3243 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3245 fcport
->port_type
!= FCT_INITIATOR
) {
3246 qla2x00_mark_device_lost(vha
, fcport
,
3256 * qla2x00_fabric_dev_login
3257 * Login fabric target device and update FC port database.
3260 * ha: adapter state pointer.
3261 * fcport: port structure list pointer.
3262 * next_loopid: contains value of a new loop ID that can be used
3263 * by the next login attempt.
3266 * qla2x00 local function return status code.
3272 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3273 uint16_t *next_loopid
)
3278 struct qla_hw_data
*ha
= vha
->hw
;
3283 if (IS_ALOGIO_CAPABLE(ha
)) {
3284 rval
= qla2x00_post_async_login_work(vha
, fcport
, NULL
);
3289 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3290 if (rval
== QLA_SUCCESS
) {
3291 /* Send an ADISC to FCP2 devices.*/
3293 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3295 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3296 if (rval
!= QLA_SUCCESS
) {
3297 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3298 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3299 fcport
->d_id
.b
.al_pa
);
3300 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3302 qla2x00_update_fcport(vha
, fcport
);
3310 * qla2x00_fabric_login
3311 * Issue fabric login command.
3314 * ha = adapter block pointer.
3315 * device = pointer to FC device type structure.
3318 * 0 - Login successfully
3320 * 2 - Initiator device
3324 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3325 uint16_t *next_loopid
)
3329 uint16_t tmp_loopid
;
3330 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3331 struct qla_hw_data
*ha
= vha
->hw
;
3337 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3338 "for port %02x%02x%02x.\n",
3339 vha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3340 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3342 /* Login fcport on switch. */
3343 ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3344 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3345 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3346 if (mb
[0] == MBS_PORT_ID_USED
) {
3348 * Device has another loop ID. The firmware team
3349 * recommends the driver perform an implicit login with
3350 * the specified ID again. The ID we just used is save
3351 * here so we return with an ID that can be tried by
3355 tmp_loopid
= fcport
->loop_id
;
3356 fcport
->loop_id
= mb
[1];
3358 DEBUG(printk("Fabric Login: port in use - next "
3359 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3360 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3361 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3363 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3368 /* A retry occurred before. */
3369 *next_loopid
= tmp_loopid
;
3372 * No retry occurred before. Just increment the
3373 * ID value for next login.
3375 *next_loopid
= (fcport
->loop_id
+ 1);
3378 if (mb
[1] & BIT_0
) {
3379 fcport
->port_type
= FCT_INITIATOR
;
3381 fcport
->port_type
= FCT_TARGET
;
3382 if (mb
[1] & BIT_1
) {
3383 fcport
->flags
|= FCF_FCP2_DEVICE
;
3388 fcport
->supported_classes
|= FC_COS_CLASS2
;
3390 fcport
->supported_classes
|= FC_COS_CLASS3
;
3394 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3396 * Loop ID already used, try next loop ID.
3399 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3400 if (rval
!= QLA_SUCCESS
) {
3401 /* Ran out of loop IDs to use */
3404 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3406 * Firmware possibly timed out during login. If NO
3407 * retries are left to do then the device is declared
3410 *next_loopid
= fcport
->loop_id
;
3411 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3412 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3413 fcport
->d_id
.b
.al_pa
);
3414 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3420 * unrecoverable / not handled error
3422 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3423 "loop_id=%x jiffies=%lx.\n",
3424 __func__
, vha
->host_no
, mb
[0],
3425 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3426 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3428 *next_loopid
= fcport
->loop_id
;
3429 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3430 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3431 fcport
->d_id
.b
.al_pa
);
3432 fcport
->loop_id
= FC_NO_LOOP_ID
;
3433 fcport
->login_retry
= 0;
3444 * qla2x00_local_device_login
3445 * Issue local device login command.
3448 * ha = adapter block pointer.
3449 * loop_id = loop id of device to login to.
3451 * Returns (Where's the #define!!!!):
3452 * 0 - Login successfully
3457 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3460 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3462 memset(mb
, 0, sizeof(mb
));
3463 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3464 if (rval
== QLA_SUCCESS
) {
3465 /* Interrogate mailbox registers for any errors */
3466 if (mb
[0] == MBS_COMMAND_ERROR
)
3468 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3469 /* device not in PCB table */
3477 * qla2x00_loop_resync
3478 * Resync with fibre channel devices.
3481 * ha = adapter block pointer.
3487 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
3489 int rval
= QLA_SUCCESS
;
3491 struct req_que
*req
;
3492 struct rsp_que
*rsp
;
3494 if (vha
->hw
->flags
.cpu_affinity_enabled
)
3495 req
= vha
->hw
->req_q_map
[0];
3500 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3501 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3502 if (vha
->flags
.online
) {
3503 if (!(rval
= qla2x00_fw_ready(vha
))) {
3504 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3507 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3509 /* Issue a marker after FW becomes ready. */
3510 qla2x00_marker(vha
, req
, rsp
, 0, 0,
3512 vha
->marker_needed
= 0;
3514 /* Remap devices on Loop. */
3515 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3517 qla2x00_configure_loop(vha
);
3519 } while (!atomic_read(&vha
->loop_down_timer
) &&
3520 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3521 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3526 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3527 return (QLA_FUNCTION_FAILED
);
3530 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3536 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
3539 struct scsi_qla_host
*tvp
, *vha
;
3541 /* Go with deferred removal of rport references. */
3542 list_for_each_entry_safe(vha
, tvp
, &base_vha
->hw
->vp_list
, list
)
3543 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
3544 if (fcport
&& fcport
->drport
&&
3545 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
)
3546 qla2x00_rport_del(fcport
);
3551 * Resets ISP and aborts all outstanding commands.
3554 * ha = adapter block pointer.
3560 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
3564 struct qla_hw_data
*ha
= vha
->hw
;
3565 struct scsi_qla_host
*vp
;
3566 struct scsi_qla_host
*tvp
;
3567 struct req_que
*req
= ha
->req_q_map
[0];
3569 if (vha
->flags
.online
) {
3570 vha
->flags
.online
= 0;
3571 ha
->flags
.chip_reset_done
= 0;
3572 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3573 ha
->qla_stats
.total_isp_aborts
++;
3575 qla_printk(KERN_INFO
, ha
,
3576 "Performing ISP error recovery - ha= %p.\n", ha
);
3577 ha
->isp_ops
->reset_chip(vha
);
3579 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
3580 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3581 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3582 qla2x00_mark_all_devices_lost(vha
, 0);
3584 if (!atomic_read(&vha
->loop_down_timer
))
3585 atomic_set(&vha
->loop_down_timer
,
3589 /* Requeue all commands in outstanding command list. */
3590 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
3592 if (unlikely(pci_channel_offline(ha
->pdev
) &&
3593 ha
->flags
.pci_channel_io_perm_failure
)) {
3594 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3599 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
3601 ha
->isp_ops
->nvram_config(vha
);
3603 if (!qla2x00_restart_isp(vha
)) {
3604 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3606 if (!atomic_read(&vha
->loop_down_timer
)) {
3608 * Issue marker command only when we are going
3609 * to start the I/O .
3611 vha
->marker_needed
= 1;
3614 vha
->flags
.online
= 1;
3616 ha
->isp_ops
->enable_intrs(ha
);
3618 ha
->isp_abort_cnt
= 0;
3619 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3622 qla2x00_get_fw_version(vha
,
3623 &ha
->fw_major_version
,
3624 &ha
->fw_minor_version
,
3625 &ha
->fw_subminor_version
,
3626 &ha
->fw_attributes
, &ha
->fw_memory_size
,
3627 ha
->mpi_version
, &ha
->mpi_capabilities
,
3631 ha
->flags
.fce_enabled
= 1;
3633 fce_calc_size(ha
->fce_bufs
));
3634 rval
= qla2x00_enable_fce_trace(vha
,
3635 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
3638 qla_printk(KERN_WARNING
, ha
,
3639 "Unable to reinitialize FCE "
3641 ha
->flags
.fce_enabled
= 0;
3646 memset(ha
->eft
, 0, EFT_SIZE
);
3647 rval
= qla2x00_enable_eft_trace(vha
,
3648 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3650 qla_printk(KERN_WARNING
, ha
,
3651 "Unable to reinitialize EFT "
3655 } else { /* failed the ISP abort */
3656 vha
->flags
.online
= 1;
3657 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
3658 if (ha
->isp_abort_cnt
== 0) {
3659 qla_printk(KERN_WARNING
, ha
,
3660 "ISP error recovery failed - "
3661 "board disabled\n");
3663 * The next call disables the board
3666 ha
->isp_ops
->reset_adapter(vha
);
3667 vha
->flags
.online
= 0;
3668 clear_bit(ISP_ABORT_RETRY
,
3671 } else { /* schedule another ISP abort */
3672 ha
->isp_abort_cnt
--;
3673 DEBUG(printk("qla%ld: ISP abort - "
3674 "retry remaining %d\n",
3675 vha
->host_no
, ha
->isp_abort_cnt
));
3679 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3680 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3681 "- retrying (%d) more times\n",
3682 vha
->host_no
, ha
->isp_abort_cnt
));
3683 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3691 DEBUG(printk(KERN_INFO
3692 "qla2x00_abort_isp(%ld): succeeded.\n",
3694 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3696 qla2x00_vp_abort_isp(vp
);
3699 qla_printk(KERN_INFO
, ha
,
3700 "qla2x00_abort_isp: **** FAILED ****\n");
3707 * qla2x00_restart_isp
3708 * restarts the ISP after a reset
3711 * ha = adapter block pointer.
3717 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
3721 struct qla_hw_data
*ha
= vha
->hw
;
3722 struct req_que
*req
= ha
->req_q_map
[0];
3723 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3725 /* If firmware needs to be loaded */
3726 if (qla2x00_isp_firmware(vha
)) {
3727 vha
->flags
.online
= 0;
3728 status
= ha
->isp_ops
->chip_diag(vha
);
3730 status
= qla2x00_setup_chip(vha
);
3733 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
3734 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3735 ha
->flags
.chip_reset_done
= 1;
3736 /* Initialize the queues in use */
3737 qla25xx_init_queues(ha
);
3739 status
= qla2x00_fw_ready(vha
);
3741 DEBUG(printk("%s(): Start configure loop, "
3742 "status = %d\n", __func__
, status
));
3744 /* Issue a marker after FW becomes ready. */
3745 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
3747 vha
->flags
.online
= 1;
3748 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3751 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3752 qla2x00_configure_loop(vha
);
3754 } while (!atomic_read(&vha
->loop_down_timer
) &&
3755 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3756 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3760 /* if no cable then assume it's good */
3761 if ((vha
->device_flags
& DFLG_NO_CABLE
))
3764 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3772 qla25xx_init_queues(struct qla_hw_data
*ha
)
3774 struct rsp_que
*rsp
= NULL
;
3775 struct req_que
*req
= NULL
;
3776 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
3780 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
3781 rsp
= ha
->rsp_q_map
[i
];
3783 rsp
->options
&= ~BIT_0
;
3784 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
3785 if (ret
!= QLA_SUCCESS
)
3786 DEBUG2_17(printk(KERN_WARNING
3787 "%s Rsp que:%d init failed\n", __func__
,
3790 DEBUG2_17(printk(KERN_INFO
3791 "%s Rsp que:%d inited\n", __func__
,
3795 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
3796 req
= ha
->req_q_map
[i
];
3798 /* Clear outstanding commands array. */
3799 req
->options
&= ~BIT_0
;
3800 ret
= qla25xx_init_req_que(base_vha
, req
);
3801 if (ret
!= QLA_SUCCESS
)
3802 DEBUG2_17(printk(KERN_WARNING
3803 "%s Req que:%d init failed\n", __func__
,
3806 DEBUG2_17(printk(KERN_WARNING
3807 "%s Req que:%d inited\n", __func__
,
3815 * qla2x00_reset_adapter
3819 * ha = adapter block pointer.
3822 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
3824 unsigned long flags
= 0;
3825 struct qla_hw_data
*ha
= vha
->hw
;
3826 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3828 vha
->flags
.online
= 0;
3829 ha
->isp_ops
->disable_intrs(ha
);
3831 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3832 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3833 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3834 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3835 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3836 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3840 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
3842 unsigned long flags
= 0;
3843 struct qla_hw_data
*ha
= vha
->hw
;
3844 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3846 vha
->flags
.online
= 0;
3847 ha
->isp_ops
->disable_intrs(ha
);
3849 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3850 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3851 RD_REG_DWORD(®
->hccr
);
3852 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3853 RD_REG_DWORD(®
->hccr
);
3854 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3856 if (IS_NOPOLLING_TYPE(ha
))
3857 ha
->isp_ops
->enable_intrs(ha
);
3860 /* On sparc systems, obtain port and node WWN from firmware
3863 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
3864 struct nvram_24xx
*nv
)
3867 struct qla_hw_data
*ha
= vha
->hw
;
3868 struct pci_dev
*pdev
= ha
->pdev
;
3869 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
3873 val
= of_get_property(dp
, "port-wwn", &len
);
3874 if (val
&& len
>= WWN_SIZE
)
3875 memcpy(nv
->port_name
, val
, WWN_SIZE
);
3877 val
= of_get_property(dp
, "node-wwn", &len
);
3878 if (val
&& len
>= WWN_SIZE
)
3879 memcpy(nv
->node_name
, val
, WWN_SIZE
);
3884 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
3887 struct init_cb_24xx
*icb
;
3888 struct nvram_24xx
*nv
;
3890 uint8_t *dptr1
, *dptr2
;
3893 struct qla_hw_data
*ha
= vha
->hw
;
3896 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3899 /* Determine NVRAM starting address. */
3900 if (ha
->flags
.port0
) {
3901 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3902 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3904 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3905 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3907 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3908 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3910 /* Get VPD data into cache */
3911 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
3912 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
3913 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
3915 /* Get NVRAM data into cache and calculate checksum. */
3916 dptr
= (uint32_t *)nv
;
3917 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
3919 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3920 chksum
+= le32_to_cpu(*dptr
++);
3922 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
3923 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
3925 /* Bad NVRAM data, set defaults parameters. */
3926 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3927 || nv
->id
[3] != ' ' ||
3928 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3929 /* Reset NVRAM data. */
3930 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3931 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3932 le16_to_cpu(nv
->nvram_version
));
3933 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3934 "invalid -- WWPN) defaults.\n");
3937 * Set default initialization control block.
3939 memset(nv
, 0, ha
->nvram_size
);
3940 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3941 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3942 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3943 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3944 nv
->exchange_count
= __constant_cpu_to_le16(0);
3945 nv
->hard_address
= __constant_cpu_to_le16(124);
3946 nv
->port_name
[0] = 0x21;
3947 nv
->port_name
[1] = 0x00 + ha
->port_no
;
3948 nv
->port_name
[2] = 0x00;
3949 nv
->port_name
[3] = 0xe0;
3950 nv
->port_name
[4] = 0x8b;
3951 nv
->port_name
[5] = 0x1c;
3952 nv
->port_name
[6] = 0x55;
3953 nv
->port_name
[7] = 0x86;
3954 nv
->node_name
[0] = 0x20;
3955 nv
->node_name
[1] = 0x00;
3956 nv
->node_name
[2] = 0x00;
3957 nv
->node_name
[3] = 0xe0;
3958 nv
->node_name
[4] = 0x8b;
3959 nv
->node_name
[5] = 0x1c;
3960 nv
->node_name
[6] = 0x55;
3961 nv
->node_name
[7] = 0x86;
3962 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
3963 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3964 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3965 nv
->login_timeout
= __constant_cpu_to_le16(0);
3966 nv
->firmware_options_1
=
3967 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3968 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3969 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3970 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3971 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3972 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3973 nv
->reset_delay
= 5;
3974 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3975 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3976 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3981 /* Reset Initialization control block */
3982 memset(icb
, 0, ha
->init_cb_size
);
3984 /* Copy 1st segment. */
3985 dptr1
= (uint8_t *)icb
;
3986 dptr2
= (uint8_t *)&nv
->version
;
3987 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3989 *dptr1
++ = *dptr2
++;
3991 icb
->login_retry_count
= nv
->login_retry_count
;
3992 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
3994 /* Copy 2nd segment. */
3995 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3996 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3997 cnt
= (uint8_t *)&icb
->reserved_3
-
3998 (uint8_t *)&icb
->interrupt_delay_timer
;
4000 *dptr1
++ = *dptr2
++;
4003 * Setup driver NVRAM options.
4005 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
4008 /* Use alternate WWN? */
4009 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
4010 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4011 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4014 /* Prepare nodename */
4015 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
4017 * Firmware will apply the following mask if the nodename was
4020 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4021 icb
->node_name
[0] &= 0xF0;
4024 /* Set host adapter parameters. */
4025 ha
->flags
.disable_risc_code_load
= 0;
4026 ha
->flags
.enable_lip_reset
= 0;
4027 ha
->flags
.enable_lip_full_login
=
4028 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
4029 ha
->flags
.enable_target_reset
=
4030 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
4031 ha
->flags
.enable_led_scheme
= 0;
4032 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
4034 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
4035 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4037 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
4038 sizeof(ha
->fw_seriallink_options24
));
4040 /* save HBA serial number */
4041 ha
->serial0
= icb
->port_name
[5];
4042 ha
->serial1
= icb
->port_name
[6];
4043 ha
->serial2
= icb
->port_name
[7];
4044 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4045 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4047 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4049 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
4051 /* Set minimum login_timeout to 4 seconds. */
4052 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
4053 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
4054 if (le16_to_cpu(nv
->login_timeout
) < 4)
4055 nv
->login_timeout
= __constant_cpu_to_le16(4);
4056 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
4057 icb
->login_timeout
= nv
->login_timeout
;
4059 /* Set minimum RATOV to 100 tenths of a second. */
4062 ha
->loop_reset_delay
= nv
->reset_delay
;
4064 /* Link Down Timeout = 0:
4066 * When Port Down timer expires we will start returning
4067 * I/O's to OS with "DID_NO_CONNECT".
4069 * Link Down Timeout != 0:
4071 * The driver waits for the link to come up after link down
4072 * before returning I/Os to OS with "DID_NO_CONNECT".
4074 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
4075 ha
->loop_down_abort_time
=
4076 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4078 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
4079 ha
->loop_down_abort_time
=
4080 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4083 /* Need enough time to try and get the port back. */
4084 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
4085 if (qlport_down_retry
)
4086 ha
->port_down_retry_count
= qlport_down_retry
;
4088 /* Set login_retry_count */
4089 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
4090 if (ha
->port_down_retry_count
==
4091 le16_to_cpu(nv
->port_down_retry_count
) &&
4092 ha
->port_down_retry_count
> 3)
4093 ha
->login_retry_count
= ha
->port_down_retry_count
;
4094 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4095 ha
->login_retry_count
= ha
->port_down_retry_count
;
4096 if (ql2xloginretrycount
)
4097 ha
->login_retry_count
= ql2xloginretrycount
;
4100 if (!vha
->flags
.init_done
) {
4101 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
4102 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4103 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
4104 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
4106 icb
->firmware_options_2
&= __constant_cpu_to_le32(
4107 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
4108 vha
->flags
.process_response_queue
= 0;
4109 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4110 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4112 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4113 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
4114 ha
->zio_timer
* 100));
4115 qla_printk(KERN_INFO
, ha
,
4116 "ZIO mode %d enabled; timer delay (%d us).\n",
4117 ha
->zio_mode
, ha
->zio_timer
* 100);
4119 icb
->firmware_options_2
|= cpu_to_le32(
4120 (uint32_t)ha
->zio_mode
);
4121 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
4122 vha
->flags
.process_response_queue
= 1;
4126 DEBUG2_3(printk(KERN_WARNING
4127 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
4133 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
4136 int rval
= QLA_SUCCESS
;
4137 int segments
, fragment
;
4138 uint32_t *dcode
, dlen
;
4142 struct qla_hw_data
*ha
= vha
->hw
;
4143 struct req_que
*req
= ha
->req_q_map
[0];
4145 qla_printk(KERN_INFO
, ha
,
4146 "FW: Loading from flash (%x)...\n", faddr
);
4150 segments
= FA_RISC_CODE_SEGMENTS
;
4151 dcode
= (uint32_t *)req
->ring
;
4154 /* Validate firmware image by checking version. */
4155 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
4156 for (i
= 0; i
< 4; i
++)
4157 dcode
[i
] = be32_to_cpu(dcode
[i
]);
4158 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4159 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4160 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4162 qla_printk(KERN_WARNING
, ha
,
4163 "Unable to verify integrity of flash firmware image!\n");
4164 qla_printk(KERN_WARNING
, ha
,
4165 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4166 dcode
[1], dcode
[2], dcode
[3]);
4168 return QLA_FUNCTION_FAILED
;
4171 while (segments
&& rval
== QLA_SUCCESS
) {
4172 /* Read segment's load information. */
4173 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
4175 risc_addr
= be32_to_cpu(dcode
[2]);
4176 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4177 risc_size
= be32_to_cpu(dcode
[3]);
4180 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4181 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4182 if (dlen
> risc_size
)
4185 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4186 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
4187 vha
->host_no
, risc_addr
, dlen
, faddr
));
4189 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
4190 for (i
= 0; i
< dlen
; i
++)
4191 dcode
[i
] = swab32(dcode
[i
]);
4193 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4196 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4197 "segment %d of firmware\n", vha
->host_no
,
4199 qla_printk(KERN_WARNING
, ha
,
4200 "[ERROR] Failed to load segment %d of "
4201 "firmware\n", fragment
);
4218 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4221 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4225 uint16_t *wcode
, *fwcode
;
4226 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
4227 struct fw_blob
*blob
;
4228 struct qla_hw_data
*ha
= vha
->hw
;
4229 struct req_que
*req
= ha
->req_q_map
[0];
4231 /* Load firmware blob. */
4232 blob
= qla2x00_request_firmware(vha
);
4234 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4235 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4236 "from: " QLA_FW_URL
".\n");
4237 return QLA_FUNCTION_FAILED
;
4242 wcode
= (uint16_t *)req
->ring
;
4244 fwcode
= (uint16_t *)blob
->fw
->data
;
4247 /* Validate firmware image by checking version. */
4248 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
4249 qla_printk(KERN_WARNING
, ha
,
4250 "Unable to verify integrity of firmware image (%Zd)!\n",
4252 goto fail_fw_integrity
;
4254 for (i
= 0; i
< 4; i
++)
4255 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
4256 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
4257 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
4258 wcode
[2] == 0 && wcode
[3] == 0)) {
4259 qla_printk(KERN_WARNING
, ha
,
4260 "Unable to verify integrity of firmware image!\n");
4261 qla_printk(KERN_WARNING
, ha
,
4262 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
4263 wcode
[1], wcode
[2], wcode
[3]);
4264 goto fail_fw_integrity
;
4268 while (*seg
&& rval
== QLA_SUCCESS
) {
4270 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
4271 risc_size
= be16_to_cpu(fwcode
[3]);
4273 /* Validate firmware image size. */
4274 fwclen
+= risc_size
* sizeof(uint16_t);
4275 if (blob
->fw
->size
< fwclen
) {
4276 qla_printk(KERN_WARNING
, ha
,
4277 "Unable to verify integrity of firmware image "
4278 "(%Zd)!\n", blob
->fw
->size
);
4279 goto fail_fw_integrity
;
4283 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4284 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
4285 if (wlen
> risc_size
)
4288 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4289 "addr %x, number of words 0x%x.\n", vha
->host_no
,
4292 for (i
= 0; i
< wlen
; i
++)
4293 wcode
[i
] = swab16(fwcode
[i
]);
4295 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4298 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4299 "segment %d of firmware\n", vha
->host_no
,
4301 qla_printk(KERN_WARNING
, ha
,
4302 "[ERROR] Failed to load segment %d of "
4303 "firmware\n", fragment
);
4319 return QLA_FUNCTION_FAILED
;
4323 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4326 int segments
, fragment
;
4327 uint32_t *dcode
, dlen
;
4331 struct fw_blob
*blob
;
4332 uint32_t *fwcode
, fwclen
;
4333 struct qla_hw_data
*ha
= vha
->hw
;
4334 struct req_que
*req
= ha
->req_q_map
[0];
4336 /* Load firmware blob. */
4337 blob
= qla2x00_request_firmware(vha
);
4339 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4340 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4341 "from: " QLA_FW_URL
".\n");
4343 return QLA_FUNCTION_FAILED
;
4346 qla_printk(KERN_INFO
, ha
,
4347 "FW: Loading via request-firmware...\n");
4351 segments
= FA_RISC_CODE_SEGMENTS
;
4352 dcode
= (uint32_t *)req
->ring
;
4354 fwcode
= (uint32_t *)blob
->fw
->data
;
4357 /* Validate firmware image by checking version. */
4358 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
4359 qla_printk(KERN_WARNING
, ha
,
4360 "Unable to verify integrity of firmware image (%Zd)!\n",
4362 goto fail_fw_integrity
;
4364 for (i
= 0; i
< 4; i
++)
4365 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
4366 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4367 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4368 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4370 qla_printk(KERN_WARNING
, ha
,
4371 "Unable to verify integrity of firmware image!\n");
4372 qla_printk(KERN_WARNING
, ha
,
4373 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4374 dcode
[1], dcode
[2], dcode
[3]);
4375 goto fail_fw_integrity
;
4378 while (segments
&& rval
== QLA_SUCCESS
) {
4379 risc_addr
= be32_to_cpu(fwcode
[2]);
4380 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4381 risc_size
= be32_to_cpu(fwcode
[3]);
4383 /* Validate firmware image size. */
4384 fwclen
+= risc_size
* sizeof(uint32_t);
4385 if (blob
->fw
->size
< fwclen
) {
4386 qla_printk(KERN_WARNING
, ha
,
4387 "Unable to verify integrity of firmware image "
4388 "(%Zd)!\n", blob
->fw
->size
);
4390 goto fail_fw_integrity
;
4394 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4395 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4396 if (dlen
> risc_size
)
4399 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4400 "addr %x, number of dwords 0x%x.\n", vha
->host_no
,
4403 for (i
= 0; i
< dlen
; i
++)
4404 dcode
[i
] = swab32(fwcode
[i
]);
4406 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4409 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4410 "segment %d of firmware\n", vha
->host_no
,
4412 qla_printk(KERN_WARNING
, ha
,
4413 "[ERROR] Failed to load segment %d of "
4414 "firmware\n", fragment
);
4430 return QLA_FUNCTION_FAILED
;
4434 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4438 if (ql2xfwloadbin
== 1)
4439 return qla81xx_load_risc(vha
, srisc_addr
);
4443 * 1) Firmware via request-firmware interface (.bin file).
4444 * 2) Firmware residing in flash.
4446 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4447 if (rval
== QLA_SUCCESS
)
4450 return qla24xx_load_risc_flash(vha
, srisc_addr
,
4451 vha
->hw
->flt_region_fw
);
4455 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4458 struct qla_hw_data
*ha
= vha
->hw
;
4460 if (ql2xfwloadbin
== 2)
4465 * 1) Firmware residing in flash.
4466 * 2) Firmware via request-firmware interface (.bin file).
4467 * 3) Golden-Firmware residing in flash -- limited operation.
4469 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
4470 if (rval
== QLA_SUCCESS
)
4474 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4475 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
4478 qla_printk(KERN_ERR
, ha
,
4479 "FW: Attempting to fallback to golden firmware...\n");
4480 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
4481 if (rval
!= QLA_SUCCESS
)
4484 qla_printk(KERN_ERR
, ha
,
4485 "FW: Please update operational firmware...\n");
4486 ha
->flags
.running_gold_fw
= 1;
4492 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
4495 struct qla_hw_data
*ha
= vha
->hw
;
4497 if (ha
->flags
.pci_channel_io_perm_failure
)
4499 if (!IS_FWI2_CAPABLE(ha
))
4501 if (!ha
->fw_major_version
)
4504 ret
= qla2x00_stop_firmware(vha
);
4505 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
4506 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
4507 ha
->isp_ops
->reset_chip(vha
);
4508 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
4510 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
4512 qla_printk(KERN_INFO
, ha
,
4513 "Attempting retry of stop-firmware command...\n");
4514 ret
= qla2x00_stop_firmware(vha
);
4519 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
4521 int rval
= QLA_SUCCESS
;
4522 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4523 struct qla_hw_data
*ha
= vha
->hw
;
4524 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4525 struct req_que
*req
;
4526 struct rsp_que
*rsp
;
4531 rval
= qla2x00_fw_ready(base_vha
);
4532 if (ha
->flags
.cpu_affinity_enabled
)
4533 req
= ha
->req_q_map
[0];
4538 if (rval
== QLA_SUCCESS
) {
4539 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4540 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4543 vha
->flags
.management_server_logged_in
= 0;
4545 /* Login to SNS first */
4546 ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
, BIT_1
);
4547 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
4548 DEBUG15(qla_printk(KERN_INFO
, ha
,
4549 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4550 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS
,
4551 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
4552 return (QLA_FUNCTION_FAILED
);
4555 atomic_set(&vha
->loop_down_timer
, 0);
4556 atomic_set(&vha
->loop_state
, LOOP_UP
);
4557 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4558 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4559 rval
= qla2x00_loop_resync(base_vha
);
4564 /* 84XX Support **************************************************************/
4566 static LIST_HEAD(qla_cs84xx_list
);
4567 static DEFINE_MUTEX(qla_cs84xx_mutex
);
4569 static struct qla_chip_state_84xx
*
4570 qla84xx_get_chip(struct scsi_qla_host
*vha
)
4572 struct qla_chip_state_84xx
*cs84xx
;
4573 struct qla_hw_data
*ha
= vha
->hw
;
4575 mutex_lock(&qla_cs84xx_mutex
);
4577 /* Find any shared 84xx chip. */
4578 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
4579 if (cs84xx
->bus
== ha
->pdev
->bus
) {
4580 kref_get(&cs84xx
->kref
);
4585 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
4589 kref_init(&cs84xx
->kref
);
4590 spin_lock_init(&cs84xx
->access_lock
);
4591 mutex_init(&cs84xx
->fw_update_mutex
);
4592 cs84xx
->bus
= ha
->pdev
->bus
;
4594 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
4596 mutex_unlock(&qla_cs84xx_mutex
);
4601 __qla84xx_chip_release(struct kref
*kref
)
4603 struct qla_chip_state_84xx
*cs84xx
=
4604 container_of(kref
, struct qla_chip_state_84xx
, kref
);
4606 mutex_lock(&qla_cs84xx_mutex
);
4607 list_del(&cs84xx
->list
);
4608 mutex_unlock(&qla_cs84xx_mutex
);
4613 qla84xx_put_chip(struct scsi_qla_host
*vha
)
4615 struct qla_hw_data
*ha
= vha
->hw
;
4617 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
4621 qla84xx_init_chip(scsi_qla_host_t
*vha
)
4625 struct qla_hw_data
*ha
= vha
->hw
;
4627 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
4629 rval
= qla84xx_verify_chip(vha
, status
);
4631 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
4633 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
4637 /* 81XX Support **************************************************************/
4640 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
4643 struct init_cb_81xx
*icb
;
4644 struct nvram_81xx
*nv
;
4646 uint8_t *dptr1
, *dptr2
;
4649 struct qla_hw_data
*ha
= vha
->hw
;
4652 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
4655 /* Determine NVRAM starting address. */
4656 ha
->nvram_size
= sizeof(struct nvram_81xx
);
4657 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4659 /* Get VPD data into cache */
4660 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4661 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
4664 /* Get NVRAM data into cache and calculate checksum. */
4665 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
4667 dptr
= (uint32_t *)nv
;
4668 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4669 chksum
+= le32_to_cpu(*dptr
++);
4671 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
4672 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
4674 /* Bad NVRAM data, set defaults parameters. */
4675 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4676 || nv
->id
[3] != ' ' ||
4677 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4678 /* Reset NVRAM data. */
4679 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
4680 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
4681 le16_to_cpu(nv
->nvram_version
));
4682 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
4683 "invalid -- WWPN) defaults.\n");
4686 * Set default initialization control block.
4688 memset(nv
, 0, ha
->nvram_size
);
4689 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4690 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4691 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4692 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4693 nv
->exchange_count
= __constant_cpu_to_le16(0);
4694 nv
->port_name
[0] = 0x21;
4695 nv
->port_name
[1] = 0x00 + ha
->port_no
;
4696 nv
->port_name
[2] = 0x00;
4697 nv
->port_name
[3] = 0xe0;
4698 nv
->port_name
[4] = 0x8b;
4699 nv
->port_name
[5] = 0x1c;
4700 nv
->port_name
[6] = 0x55;
4701 nv
->port_name
[7] = 0x86;
4702 nv
->node_name
[0] = 0x20;
4703 nv
->node_name
[1] = 0x00;
4704 nv
->node_name
[2] = 0x00;
4705 nv
->node_name
[3] = 0xe0;
4706 nv
->node_name
[4] = 0x8b;
4707 nv
->node_name
[5] = 0x1c;
4708 nv
->node_name
[6] = 0x55;
4709 nv
->node_name
[7] = 0x86;
4710 nv
->login_retry_count
= __constant_cpu_to_le16(8);
4711 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
4712 nv
->login_timeout
= __constant_cpu_to_le16(0);
4713 nv
->firmware_options_1
=
4714 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
4715 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
4716 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4717 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
4718 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
4719 nv
->efi_parameters
= __constant_cpu_to_le32(0);
4720 nv
->reset_delay
= 5;
4721 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
4722 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
4723 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
4724 nv
->enode_mac
[0] = 0x00;
4725 nv
->enode_mac
[1] = 0x02;
4726 nv
->enode_mac
[2] = 0x03;
4727 nv
->enode_mac
[3] = 0x04;
4728 nv
->enode_mac
[4] = 0x05;
4729 nv
->enode_mac
[5] = 0x06 + ha
->port_no
;
4734 /* Reset Initialization control block */
4735 memset(icb
, 0, sizeof(struct init_cb_81xx
));
4737 /* Copy 1st segment. */
4738 dptr1
= (uint8_t *)icb
;
4739 dptr2
= (uint8_t *)&nv
->version
;
4740 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
4742 *dptr1
++ = *dptr2
++;
4744 icb
->login_retry_count
= nv
->login_retry_count
;
4746 /* Copy 2nd segment. */
4747 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
4748 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
4749 cnt
= (uint8_t *)&icb
->reserved_5
-
4750 (uint8_t *)&icb
->interrupt_delay_timer
;
4752 *dptr1
++ = *dptr2
++;
4754 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
4755 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4756 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
4757 icb
->enode_mac
[0] = 0x01;
4758 icb
->enode_mac
[1] = 0x02;
4759 icb
->enode_mac
[2] = 0x03;
4760 icb
->enode_mac
[3] = 0x04;
4761 icb
->enode_mac
[4] = 0x05;
4762 icb
->enode_mac
[5] = 0x06 + ha
->port_no
;
4765 /* Use extended-initialization control block. */
4766 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
4769 * Setup driver NVRAM options.
4771 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
4774 /* Use alternate WWN? */
4775 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
4776 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4777 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4780 /* Prepare nodename */
4781 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
4783 * Firmware will apply the following mask if the nodename was
4786 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4787 icb
->node_name
[0] &= 0xF0;
4790 /* Set host adapter parameters. */
4791 ha
->flags
.disable_risc_code_load
= 0;
4792 ha
->flags
.enable_lip_reset
= 0;
4793 ha
->flags
.enable_lip_full_login
=
4794 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
4795 ha
->flags
.enable_target_reset
=
4796 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
4797 ha
->flags
.enable_led_scheme
= 0;
4798 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
4800 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
4801 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4803 /* save HBA serial number */
4804 ha
->serial0
= icb
->port_name
[5];
4805 ha
->serial1
= icb
->port_name
[6];
4806 ha
->serial2
= icb
->port_name
[7];
4807 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4808 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4810 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4812 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
4814 /* Set minimum login_timeout to 4 seconds. */
4815 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
4816 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
4817 if (le16_to_cpu(nv
->login_timeout
) < 4)
4818 nv
->login_timeout
= __constant_cpu_to_le16(4);
4819 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
4820 icb
->login_timeout
= nv
->login_timeout
;
4822 /* Set minimum RATOV to 100 tenths of a second. */
4825 ha
->loop_reset_delay
= nv
->reset_delay
;
4827 /* Link Down Timeout = 0:
4829 * When Port Down timer expires we will start returning
4830 * I/O's to OS with "DID_NO_CONNECT".
4832 * Link Down Timeout != 0:
4834 * The driver waits for the link to come up after link down
4835 * before returning I/Os to OS with "DID_NO_CONNECT".
4837 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
4838 ha
->loop_down_abort_time
=
4839 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4841 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
4842 ha
->loop_down_abort_time
=
4843 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4846 /* Need enough time to try and get the port back. */
4847 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
4848 if (qlport_down_retry
)
4849 ha
->port_down_retry_count
= qlport_down_retry
;
4851 /* Set login_retry_count */
4852 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
4853 if (ha
->port_down_retry_count
==
4854 le16_to_cpu(nv
->port_down_retry_count
) &&
4855 ha
->port_down_retry_count
> 3)
4856 ha
->login_retry_count
= ha
->port_down_retry_count
;
4857 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4858 ha
->login_retry_count
= ha
->port_down_retry_count
;
4859 if (ql2xloginretrycount
)
4860 ha
->login_retry_count
= ql2xloginretrycount
;
4863 if (!vha
->flags
.init_done
) {
4864 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
4865 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4866 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
4867 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
4869 icb
->firmware_options_2
&= __constant_cpu_to_le32(
4870 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
4871 vha
->flags
.process_response_queue
= 0;
4872 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4873 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4875 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4876 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
4877 ha
->zio_timer
* 100));
4878 qla_printk(KERN_INFO
, ha
,
4879 "ZIO mode %d enabled; timer delay (%d us).\n",
4880 ha
->zio_mode
, ha
->zio_timer
* 100);
4882 icb
->firmware_options_2
|= cpu_to_le32(
4883 (uint32_t)ha
->zio_mode
);
4884 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
4885 vha
->flags
.process_response_queue
= 1;
4889 DEBUG2_3(printk(KERN_WARNING
4890 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
4896 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
4898 struct qla_hw_data
*ha
= vha
->hw
;
4903 /* Enable ETS Burst. */
4904 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
4905 ha
->fw_options
[2] |= BIT_9
;
4906 qla2x00_set_fw_options(vha
, ha
->fw_options
);