2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/vmalloc.h>
12 #include "qla_devtbl.h"
18 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
19 #ifndef EXT_IS_LUN_BIT_SET
20 #define EXT_IS_LUN_BIT_SET(P,L) \
21 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
22 #define EXT_SET_LUN_BIT(P,L) \
23 ((P)->mask[L/8] |= (0x80 >> (L%8)))
27 * QLogic ISP2x00 Hardware Support Function Prototypes.
29 static int qla2x00_isp_firmware(scsi_qla_host_t *);
30 static void qla2x00_resize_request_q(scsi_qla_host_t *);
31 static int qla2x00_setup_chip(scsi_qla_host_t *);
32 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
33 static int qla2x00_init_rings(scsi_qla_host_t *);
34 static int qla2x00_fw_ready(scsi_qla_host_t *);
35 static int qla2x00_configure_hba(scsi_qla_host_t *);
36 static int qla2x00_configure_loop(scsi_qla_host_t *);
37 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
38 static int qla2x00_configure_fabric(scsi_qla_host_t *);
39 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
40 static int qla2x00_device_resync(scsi_qla_host_t *);
41 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
44 static int qla2x00_restart_isp(scsi_qla_host_t *);
46 static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
48 /****************************************************************************/
49 /* QLogic ISP2x00 Hardware Support Functions. */
50 /****************************************************************************/
53 * qla2x00_initialize_adapter
57 * ha = adapter block pointer.
63 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
67 /* Clear adapter flags. */
69 ha->flags.reset_active = 0;
70 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
71 atomic_set(&ha->loop_state, LOOP_DOWN);
72 ha->device_flags = DFLG_NO_CABLE;
74 ha->flags.management_server_logged_in = 0;
75 ha->marker_needed = 0;
77 ha->isp_abort_cnt = 0;
78 ha->beacon_blink_led = 0;
79 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
81 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
82 rval = ha->isp_ops->pci_config(ha);
84 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
89 ha->isp_ops->reset_chip(ha);
91 ha->isp_ops->get_flash_version(ha, ha->request_ring);
93 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
95 ha->isp_ops->nvram_config(ha);
97 if (ha->flags.disable_serdes) {
98 /* Mask HBA via NVRAM settings? */
99 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
100 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
101 ha->port_name[0], ha->port_name[1],
102 ha->port_name[2], ha->port_name[3],
103 ha->port_name[4], ha->port_name[5],
104 ha->port_name[6], ha->port_name[7]);
105 return QLA_FUNCTION_FAILED;
108 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
110 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
111 rval = ha->isp_ops->chip_diag(ha);
114 rval = qla2x00_setup_chip(ha);
118 rval = qla2x00_init_rings(ha);
124 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
127 * Returns 0 on success.
130 qla2100_pci_config(scsi_qla_host_t *ha)
135 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
137 pci_set_master(ha->pdev);
138 pci_try_set_mwi(ha->pdev);
140 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
141 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
142 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
144 /* Reset expansion ROM address decode enable */
145 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
146 d &= ~PCI_ROM_ADDRESS_ENABLE;
147 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
149 /* Get PCI bus information. */
150 spin_lock_irqsave(&ha->hardware_lock, flags);
151 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
152 spin_unlock_irqrestore(&ha->hardware_lock, flags);
158 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
161 * Returns 0 on success.
164 qla2300_pci_config(scsi_qla_host_t *ha)
168 unsigned long flags = 0;
170 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
172 pci_set_master(ha->pdev);
173 pci_try_set_mwi(ha->pdev);
175 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
176 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
178 if (IS_QLA2322(ha) || IS_QLA6322(ha))
179 w &= ~PCI_COMMAND_INTX_DISABLE;
180 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
183 * If this is a 2300 card and not 2312, reset the
184 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
185 * the 2310 also reports itself as a 2300 so we need to get the
186 * fb revision level -- a 6 indicates it really is a 2300 and
189 if (IS_QLA2300(ha)) {
190 spin_lock_irqsave(&ha->hardware_lock, flags);
193 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
194 for (cnt = 0; cnt < 30000; cnt++) {
195 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
201 /* Select FPM registers. */
202 WRT_REG_WORD(®->ctrl_status, 0x20);
203 RD_REG_WORD(®->ctrl_status);
205 /* Get the fb rev level */
206 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
208 if (ha->fb_rev == FPM_2300)
209 pci_clear_mwi(ha->pdev);
211 /* Deselect FPM registers. */
212 WRT_REG_WORD(®->ctrl_status, 0x0);
213 RD_REG_WORD(®->ctrl_status);
215 /* Release RISC module. */
216 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
217 for (cnt = 0; cnt < 30000; cnt++) {
218 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
224 spin_unlock_irqrestore(&ha->hardware_lock, flags);
227 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
229 /* Reset expansion ROM address decode enable */
230 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
231 d &= ~PCI_ROM_ADDRESS_ENABLE;
232 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
234 /* Get PCI bus information. */
235 spin_lock_irqsave(&ha->hardware_lock, flags);
236 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
237 spin_unlock_irqrestore(&ha->hardware_lock, flags);
243 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
246 * Returns 0 on success.
249 qla24xx_pci_config(scsi_qla_host_t *ha)
253 unsigned long flags = 0;
254 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
256 pci_set_master(ha->pdev);
257 pci_try_set_mwi(ha->pdev);
259 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
260 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
261 w &= ~PCI_COMMAND_INTX_DISABLE;
262 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
264 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
266 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
267 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
268 pcix_set_mmrbc(ha->pdev, 2048);
270 /* PCIe -- adjust Maximum Read Request Size (2048). */
271 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
272 pcie_set_readrq(ha->pdev, 2048);
274 /* Reset expansion ROM address decode enable */
275 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
276 d &= ~PCI_ROM_ADDRESS_ENABLE;
277 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
279 ha->chip_revision = ha->pdev->revision;
281 /* Get PCI bus information. */
282 spin_lock_irqsave(&ha->hardware_lock, flags);
283 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
284 spin_unlock_irqrestore(&ha->hardware_lock, flags);
290 * qla2x00_isp_firmware() - Choose firmware image.
293 * Returns 0 on success.
296 qla2x00_isp_firmware(scsi_qla_host_t *ha)
300 /* Assume loading risc code */
301 rval = QLA_FUNCTION_FAILED;
303 if (ha->flags.disable_risc_code_load) {
304 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
306 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
308 /* Verify checksum of loaded RISC code. */
309 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
313 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
321 * qla2x00_reset_chip() - Reset ISP chip.
324 * Returns 0 on success.
327 qla2x00_reset_chip(scsi_qla_host_t *ha)
329 unsigned long flags = 0;
330 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
334 ha->isp_ops->disable_intrs(ha);
336 spin_lock_irqsave(&ha->hardware_lock, flags);
338 /* Turn off master enable */
340 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
341 cmd &= ~PCI_COMMAND_MASTER;
342 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
344 if (!IS_QLA2100(ha)) {
346 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
347 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
348 for (cnt = 0; cnt < 30000; cnt++) {
349 if ((RD_REG_WORD(®->hccr) &
350 HCCR_RISC_PAUSE) != 0)
355 RD_REG_WORD(®->hccr); /* PCI Posting. */
359 /* Select FPM registers. */
360 WRT_REG_WORD(®->ctrl_status, 0x20);
361 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
363 /* FPM Soft Reset. */
364 WRT_REG_WORD(®->fpm_diag_config, 0x100);
365 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
367 /* Toggle Fpm Reset. */
368 if (!IS_QLA2200(ha)) {
369 WRT_REG_WORD(®->fpm_diag_config, 0x0);
370 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
373 /* Select frame buffer registers. */
374 WRT_REG_WORD(®->ctrl_status, 0x10);
375 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
377 /* Reset frame buffer FIFOs. */
378 if (IS_QLA2200(ha)) {
379 WRT_FB_CMD_REG(ha, reg, 0xa000);
380 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
382 WRT_FB_CMD_REG(ha, reg, 0x00fc);
384 /* Read back fb_cmd until zero or 3 seconds max */
385 for (cnt = 0; cnt < 3000; cnt++) {
386 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
392 /* Select RISC module registers. */
393 WRT_REG_WORD(®->ctrl_status, 0);
394 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
396 /* Reset RISC processor. */
397 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
398 RD_REG_WORD(®->hccr); /* PCI Posting. */
400 /* Release RISC processor. */
401 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
402 RD_REG_WORD(®->hccr); /* PCI Posting. */
405 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
406 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
408 /* Reset ISP chip. */
409 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
411 /* Wait for RISC to recover from reset. */
412 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
414 * It is necessary to for a delay here since the card doesn't
415 * respond to PCI reads during a reset. On some architectures
416 * this will result in an MCA.
419 for (cnt = 30000; cnt; cnt--) {
420 if ((RD_REG_WORD(®->ctrl_status) &
421 CSR_ISP_SOFT_RESET) == 0)
428 /* Reset RISC processor. */
429 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
431 WRT_REG_WORD(®->semaphore, 0);
433 /* Release RISC processor. */
434 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
435 RD_REG_WORD(®->hccr); /* PCI Posting. */
437 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
438 for (cnt = 0; cnt < 30000; cnt++) {
439 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
447 /* Turn on master enable */
448 cmd |= PCI_COMMAND_MASTER;
449 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
451 /* Disable RISC pause on FPM parity error. */
452 if (!IS_QLA2100(ha)) {
453 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
454 RD_REG_WORD(®->hccr); /* PCI Posting. */
457 spin_unlock_irqrestore(&ha->hardware_lock, flags);
461 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
464 * Returns 0 on success.
467 qla24xx_reset_risc(scsi_qla_host_t *ha)
469 unsigned long flags = 0;
470 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
474 spin_lock_irqsave(&ha->hardware_lock, flags);
477 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
478 for (cnt = 0; cnt < 30000; cnt++) {
479 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
485 WRT_REG_DWORD(®->ctrl_status,
486 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
487 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
490 /* Wait for firmware to complete NVRAM accesses. */
491 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
492 for (cnt = 10000 ; cnt && d2; cnt--) {
494 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
498 /* Wait for soft-reset to complete. */
499 d2 = RD_REG_DWORD(®->ctrl_status);
500 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
502 d2 = RD_REG_DWORD(®->ctrl_status);
506 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
507 RD_REG_DWORD(®->hccr);
509 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
510 RD_REG_DWORD(®->hccr);
512 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
513 RD_REG_DWORD(®->hccr);
515 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
516 for (cnt = 6000000 ; cnt && d2; cnt--) {
518 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
522 spin_unlock_irqrestore(&ha->hardware_lock, flags);
526 * qla24xx_reset_chip() - Reset ISP24xx chip.
529 * Returns 0 on success.
532 qla24xx_reset_chip(scsi_qla_host_t *ha)
534 ha->isp_ops->disable_intrs(ha);
536 /* Perform RISC reset. */
537 qla24xx_reset_risc(ha);
541 * qla2x00_chip_diag() - Test chip for proper operation.
544 * Returns 0 on success.
547 qla2x00_chip_diag(scsi_qla_host_t *ha)
550 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
551 unsigned long flags = 0;
556 /* Assume a failed state */
557 rval = QLA_FUNCTION_FAILED;
559 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
560 ha->host_no, (u_long)®->flash_address));
562 spin_lock_irqsave(&ha->hardware_lock, flags);
564 /* Reset ISP chip. */
565 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
568 * We need to have a delay here since the card will not respond while
569 * in reset causing an MCA on some architectures.
572 data = qla2x00_debounce_register(®->ctrl_status);
573 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
575 data = RD_REG_WORD(®->ctrl_status);
580 goto chip_diag_failed;
582 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
585 /* Reset RISC processor. */
586 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
587 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
589 /* Workaround for QLA2312 PCI parity error */
590 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
591 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
592 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
594 data = RD_MAILBOX_REG(ha, reg, 0);
601 goto chip_diag_failed;
603 /* Check product ID of chip */
604 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
606 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
607 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
608 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
609 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
610 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
611 mb[3] != PROD_ID_3) {
612 qla_printk(KERN_WARNING, ha,
613 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
615 goto chip_diag_failed;
617 ha->product_id[0] = mb[1];
618 ha->product_id[1] = mb[2];
619 ha->product_id[2] = mb[3];
620 ha->product_id[3] = mb[4];
622 /* Adjust fw RISC transfer size */
623 if (ha->request_q_length > 1024)
624 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
626 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
627 ha->request_q_length;
629 if (IS_QLA2200(ha) &&
630 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
631 /* Limit firmware transfer size with a 2200A */
632 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
635 ha->device_type |= DT_ISP2200A;
636 ha->fw_transfer_size = 128;
639 /* Wrap Incoming Mailboxes Test. */
640 spin_unlock_irqrestore(&ha->hardware_lock, flags);
642 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
643 rval = qla2x00_mbx_reg_test(ha);
645 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
647 qla_printk(KERN_WARNING, ha,
648 "Failed mailbox send register test\n");
651 /* Flag a successful rval */
654 spin_lock_irqsave(&ha->hardware_lock, flags);
658 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
659 "****\n", ha->host_no));
661 spin_unlock_irqrestore(&ha->hardware_lock, flags);
667 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
670 * Returns 0 on success.
673 qla24xx_chip_diag(scsi_qla_host_t *ha)
677 /* Perform RISC reset. */
678 qla24xx_reset_risc(ha);
680 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
682 rval = qla2x00_mbx_reg_test(ha);
684 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
686 qla_printk(KERN_WARNING, ha,
687 "Failed mailbox send register test\n");
689 /* Flag a successful rval */
697 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
700 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
706 qla_printk(KERN_WARNING, ha,
707 "Firmware dump previously allocated.\n");
712 fixed_size = mem_size = eft_size = 0;
713 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
714 fixed_size = sizeof(struct qla2100_fw_dump);
715 } else if (IS_QLA23XX(ha)) {
716 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
717 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
719 } else if (IS_FWI2_CAPABLE(ha)) {
720 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
721 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
724 /* Allocate memory for Extended Trace Buffer. */
725 eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
728 qla_printk(KERN_WARNING, ha, "Unable to allocate "
729 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
733 rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
736 qla_printk(KERN_WARNING, ha, "Unable to initialize "
737 "EFT (%d).\n", rval);
738 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
743 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
747 memset(eft, 0, eft_size);
748 ha->eft_dma = eft_dma;
752 req_q_size = ha->request_q_length * sizeof(request_t);
753 rsp_q_size = ha->response_q_length * sizeof(response_t);
755 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
756 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
759 ha->fw_dump = vmalloc(dump_size);
761 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
762 "firmware dump!!!\n", dump_size / 1024);
765 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
773 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
776 ha->fw_dump_len = dump_size;
777 ha->fw_dump->signature[0] = 'Q';
778 ha->fw_dump->signature[1] = 'L';
779 ha->fw_dump->signature[2] = 'G';
780 ha->fw_dump->signature[3] = 'C';
781 ha->fw_dump->version = __constant_htonl(1);
783 ha->fw_dump->fixed_size = htonl(fixed_size);
784 ha->fw_dump->mem_size = htonl(mem_size);
785 ha->fw_dump->req_q_size = htonl(req_q_size);
786 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
788 ha->fw_dump->eft_size = htonl(eft_size);
789 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
790 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
792 ha->fw_dump->header_size =
793 htonl(offsetof(struct qla2xxx_fw_dump, isp));
797 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
800 * Returns 0 on success.
803 qla2x00_resize_request_q(scsi_qla_host_t *ha)
806 uint16_t fw_iocb_cnt = 0;
807 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
808 dma_addr_t request_dma;
809 request_t *request_ring;
811 /* Valid only on recent ISPs. */
812 if (IS_QLA2100(ha) || IS_QLA2200(ha))
815 /* Retrieve IOCB counts available to the firmware. */
816 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
819 /* No point in continuing if current settings are sufficient. */
820 if (fw_iocb_cnt < 1024)
822 if (ha->request_q_length >= request_q_length)
825 /* Attempt to claim larger area for request queue. */
826 request_ring = dma_alloc_coherent(&ha->pdev->dev,
827 (request_q_length + 1) * sizeof(request_t), &request_dma,
829 if (request_ring == NULL)
832 /* Resize successful, report extensions. */
833 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
834 (ha->fw_memory_size + 1) / 1024);
835 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
836 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
838 /* Clear old allocations. */
839 dma_free_coherent(&ha->pdev->dev,
840 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
843 /* Begin using larger queue. */
844 ha->request_q_length = request_q_length;
845 ha->request_ring = request_ring;
846 ha->request_dma = request_dma;
850 * qla2x00_setup_chip() - Load and start RISC firmware.
853 * Returns 0 on success.
856 qla2x00_setup_chip(scsi_qla_host_t *ha)
859 uint32_t srisc_address = 0;
861 /* Load firmware sequences */
862 rval = ha->isp_ops->load_risc(ha, &srisc_address);
863 if (rval == QLA_SUCCESS) {
864 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
865 "code.\n", ha->host_no));
867 rval = qla2x00_verify_checksum(ha, srisc_address);
868 if (rval == QLA_SUCCESS) {
869 /* Start firmware execution. */
870 DEBUG(printk("scsi(%ld): Checksum OK, start "
871 "firmware.\n", ha->host_no));
873 rval = qla2x00_execute_fw(ha, srisc_address);
874 /* Retrieve firmware information. */
875 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
876 qla2x00_get_fw_version(ha,
877 &ha->fw_major_version,
878 &ha->fw_minor_version,
879 &ha->fw_subminor_version,
880 &ha->fw_attributes, &ha->fw_memory_size);
881 qla2x00_resize_request_q(ha);
882 ha->flags.npiv_supported = 0;
883 if (IS_QLA24XX(ha) &&
884 (ha->fw_attributes & BIT_2))
885 ha->flags.npiv_supported = 1;
888 qla2x00_alloc_fw_dump(ha);
891 DEBUG2(printk(KERN_INFO
892 "scsi(%ld): ISP Firmware failed checksum.\n",
898 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
906 * qla2x00_init_response_q_entries() - Initializes response queue entries.
909 * Beginning of request ring has initialization control block already built
910 * by nvram config routine.
912 * Returns 0 on success.
915 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
920 pkt = ha->response_ring_ptr;
921 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
922 pkt->signature = RESPONSE_PROCESSED;
929 * qla2x00_update_fw_options() - Read and process firmware options.
932 * Returns 0 on success.
935 qla2x00_update_fw_options(scsi_qla_host_t *ha)
937 uint16_t swing, emphasis, tx_sens, rx_sens;
939 memset(ha->fw_options, 0, sizeof(ha->fw_options));
940 qla2x00_get_fw_options(ha, ha->fw_options);
942 if (IS_QLA2100(ha) || IS_QLA2200(ha))
945 /* Serial Link options. */
946 DEBUG3(printk("scsi(%ld): Serial link options:\n",
948 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
949 sizeof(ha->fw_seriallink_options)));
951 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
952 if (ha->fw_seriallink_options[3] & BIT_2) {
953 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
956 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
957 emphasis = (ha->fw_seriallink_options[2] &
958 (BIT_4 | BIT_3)) >> 3;
959 tx_sens = ha->fw_seriallink_options[0] &
960 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
961 rx_sens = (ha->fw_seriallink_options[0] &
962 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
963 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
964 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
967 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
968 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
969 ha->fw_options[10] |= BIT_5 |
970 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
971 (tx_sens & (BIT_1 | BIT_0));
974 swing = (ha->fw_seriallink_options[2] &
975 (BIT_7 | BIT_6 | BIT_5)) >> 5;
976 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
977 tx_sens = ha->fw_seriallink_options[1] &
978 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
979 rx_sens = (ha->fw_seriallink_options[1] &
980 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
981 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
982 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
985 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
986 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
987 ha->fw_options[11] |= BIT_5 |
988 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
989 (tx_sens & (BIT_1 | BIT_0));
993 /* Return command IOCBs without waiting for an ABTS to complete. */
994 ha->fw_options[3] |= BIT_13;
997 if (ha->flags.enable_led_scheme)
998 ha->fw_options[2] |= BIT_12;
1000 /* Detect ISP6312. */
1002 ha->fw_options[2] |= BIT_13;
1004 /* Update firmware options. */
1005 qla2x00_set_fw_options(ha, ha->fw_options);
1009 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1013 /* Update Serial Link options. */
1014 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1017 rval = qla2x00_set_serdes_params(ha,
1018 le16_to_cpu(ha->fw_seriallink_options24[1]),
1019 le16_to_cpu(ha->fw_seriallink_options24[2]),
1020 le16_to_cpu(ha->fw_seriallink_options24[3]));
1021 if (rval != QLA_SUCCESS) {
1022 qla_printk(KERN_WARNING, ha,
1023 "Unable to update Serial Link options (%x).\n", rval);
1028 qla2x00_config_rings(struct scsi_qla_host *ha)
1030 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1032 /* Setup ring parameters in initialization control block. */
1033 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1034 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1035 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1036 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1037 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1038 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1039 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1040 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1042 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1043 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1044 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1045 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1046 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1050 qla24xx_config_rings(struct scsi_qla_host *ha)
1052 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1053 struct init_cb_24xx *icb;
1055 /* Setup ring parameters in initialization control block. */
1056 icb = (struct init_cb_24xx *)ha->init_cb;
1057 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1058 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1059 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1060 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1061 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1062 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1063 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1064 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1066 WRT_REG_DWORD(®->req_q_in, 0);
1067 WRT_REG_DWORD(®->req_q_out, 0);
1068 WRT_REG_DWORD(®->rsp_q_in, 0);
1069 WRT_REG_DWORD(®->rsp_q_out, 0);
1070 RD_REG_DWORD(®->rsp_q_out);
1074 * qla2x00_init_rings() - Initializes firmware.
1077 * Beginning of request ring has initialization control block already built
1078 * by nvram config routine.
1080 * Returns 0 on success.
1083 qla2x00_init_rings(scsi_qla_host_t *ha)
1086 unsigned long flags = 0;
1088 struct mid_init_cb_24xx *mid_init_cb =
1089 (struct mid_init_cb_24xx *) ha->init_cb;
1091 spin_lock_irqsave(&ha->hardware_lock, flags);
1093 /* Clear outstanding commands array. */
1094 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1095 ha->outstanding_cmds[cnt] = NULL;
1097 ha->current_outstanding_cmd = 0;
1099 /* Clear RSCN queue. */
1100 ha->rscn_in_ptr = 0;
1101 ha->rscn_out_ptr = 0;
1103 /* Initialize firmware. */
1104 ha->request_ring_ptr = ha->request_ring;
1105 ha->req_ring_index = 0;
1106 ha->req_q_cnt = ha->request_q_length;
1107 ha->response_ring_ptr = ha->response_ring;
1108 ha->rsp_ring_index = 0;
1110 /* Initialize response queue entries */
1111 qla2x00_init_response_q_entries(ha);
1113 ha->isp_ops->config_rings(ha);
1115 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1117 /* Update any ISP specific firmware options before initialization. */
1118 ha->isp_ops->update_fw_options(ha);
1120 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1122 mid_init_cb->count = MAX_NUM_VPORT_FABRIC;
1123 ha->max_npiv_vports = MAX_NUM_VPORT_FABRIC;
1125 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1127 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1130 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1138 * qla2x00_fw_ready() - Waits for firmware ready.
1141 * Returns 0 on success.
1144 qla2x00_fw_ready(scsi_qla_host_t *ha)
1147 unsigned long wtime, mtime;
1148 uint16_t min_wait; /* Minimum wait time if loop is down */
1149 uint16_t wait_time; /* Wait time if loop is coming ready */
1154 /* 20 seconds for loop down. */
1158 * Firmware should take at most one RATOV to login, plus 5 seconds for
1159 * our own processing.
1161 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1162 wait_time = min_wait;
1165 /* Min wait time if loop down */
1166 mtime = jiffies + (min_wait * HZ);
1168 /* wait time before firmware ready */
1169 wtime = jiffies + (wait_time * HZ);
1171 /* Wait for ISP to finish LIP */
1172 if (!ha->flags.init_done)
1173 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1175 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1179 rval = qla2x00_get_firmware_state(ha, &fw_state);
1180 if (rval == QLA_SUCCESS) {
1181 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1182 ha->device_flags &= ~DFLG_NO_CABLE;
1184 if (fw_state == FSTATE_READY) {
1185 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1188 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1189 &ha->login_timeout, &ha->r_a_tov);
1195 rval = QLA_FUNCTION_FAILED;
1197 if (atomic_read(&ha->loop_down_timer) &&
1198 fw_state != FSTATE_READY) {
1199 /* Loop down. Timeout on min_wait for states
1200 * other than Wait for Login.
1202 if (time_after_eq(jiffies, mtime)) {
1203 qla_printk(KERN_INFO, ha,
1204 "Cable is unplugged...\n");
1206 ha->device_flags |= DFLG_NO_CABLE;
1211 /* Mailbox cmd failed. Timeout on min_wait. */
1212 if (time_after_eq(jiffies, mtime))
1216 if (time_after_eq(jiffies, wtime))
1219 /* Delay for a while */
1222 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1223 ha->host_no, fw_state, jiffies));
1226 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1227 ha->host_no, fw_state, jiffies));
1230 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1238 * qla2x00_configure_hba
1239 * Setup adapter context.
1242 * ha = adapter state pointer.
1251 qla2x00_configure_hba(scsi_qla_host_t *ha)
1260 char connect_type[22];
1262 /* Get host addresses. */
1263 rval = qla2x00_get_adapter_id(ha,
1264 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1265 if (rval != QLA_SUCCESS) {
1266 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1267 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1268 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1269 __func__, ha->host_no));
1271 qla_printk(KERN_WARNING, ha,
1272 "ERROR -- Unable to get host loop ID.\n");
1273 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1279 qla_printk(KERN_INFO, ha,
1280 "Cannot get topology - retrying.\n");
1281 return (QLA_FUNCTION_FAILED);
1284 ha->loop_id = loop_id;
1287 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1288 ha->operating_mode = LOOP;
1293 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1295 ha->current_topology = ISP_CFG_NL;
1296 strcpy(connect_type, "(Loop)");
1300 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1302 ha->switch_cap = sw_cap;
1303 ha->current_topology = ISP_CFG_FL;
1304 strcpy(connect_type, "(FL_Port)");
1308 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1310 ha->operating_mode = P2P;
1311 ha->current_topology = ISP_CFG_N;
1312 strcpy(connect_type, "(N_Port-to-N_Port)");
1316 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1318 ha->switch_cap = sw_cap;
1319 ha->operating_mode = P2P;
1320 ha->current_topology = ISP_CFG_F;
1321 strcpy(connect_type, "(F_Port)");
1325 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1327 ha->host_no, topo));
1328 ha->current_topology = ISP_CFG_NL;
1329 strcpy(connect_type, "(Loop)");
1333 /* Save Host port and loop ID. */
1334 /* byte order - Big Endian */
1335 ha->d_id.b.domain = domain;
1336 ha->d_id.b.area = area;
1337 ha->d_id.b.al_pa = al_pa;
1339 if (!ha->flags.init_done)
1340 qla_printk(KERN_INFO, ha,
1341 "Topology - %s, Host Loop address 0x%x\n",
1342 connect_type, ha->loop_id);
1345 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1347 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1354 qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1359 if (memcmp(model, BINZERO, len) != 0) {
1360 strncpy(ha->model_number, model, len);
1361 st = en = ha->model_number;
1364 if (*en != 0x20 && *en != 0x00)
1369 index = (ha->pdev->subsystem_device & 0xff);
1370 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1371 index < QLA_MODEL_NAMES)
1372 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1374 index = (ha->pdev->subsystem_device & 0xff);
1375 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1376 index < QLA_MODEL_NAMES) {
1377 strcpy(ha->model_number,
1378 qla2x00_model_name[index * 2]);
1379 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1381 strcpy(ha->model_number, def);
1386 /* On sparc systems, obtain port and node WWN from firmware
1389 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1392 struct pci_dev *pdev = ha->pdev;
1393 struct device_node *dp = pci_device_to_OF_node(pdev);
1397 val = of_get_property(dp, "port-wwn", &len);
1398 if (val && len >= WWN_SIZE)
1399 memcpy(nv->port_name, val, WWN_SIZE);
1401 val = of_get_property(dp, "node-wwn", &len);
1402 if (val && len >= WWN_SIZE)
1403 memcpy(nv->node_name, val, WWN_SIZE);
1408 * NVRAM configuration for ISP 2xxx
1411 * ha = adapter block pointer.
1414 * initialization control block in response_ring
1415 * host adapters parameters in host adapter block
1421 qla2x00_nvram_config(scsi_qla_host_t *ha)
1426 uint8_t *dptr1, *dptr2;
1427 init_cb_t *icb = ha->init_cb;
1428 nvram_t *nv = (nvram_t *)ha->request_ring;
1429 uint8_t *ptr = (uint8_t *)ha->request_ring;
1430 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1434 /* Determine NVRAM starting address. */
1435 ha->nvram_size = sizeof(nvram_t);
1437 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1438 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1439 ha->nvram_base = 0x80;
1441 /* Get NVRAM data and calculate checksum. */
1442 ha->isp_ops->read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1443 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1446 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1447 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1450 /* Bad NVRAM data, set defaults parameters. */
1451 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1452 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1453 /* Reset NVRAM data. */
1454 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1455 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1457 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1458 "invalid -- WWPN) defaults.\n");
1461 * Set default initialization control block.
1463 memset(nv, 0, ha->nvram_size);
1464 nv->parameter_block_version = ICB_VERSION;
1466 if (IS_QLA23XX(ha)) {
1467 nv->firmware_options[0] = BIT_2 | BIT_1;
1468 nv->firmware_options[1] = BIT_7 | BIT_5;
1469 nv->add_firmware_options[0] = BIT_5;
1470 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1471 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1472 nv->special_options[1] = BIT_7;
1473 } else if (IS_QLA2200(ha)) {
1474 nv->firmware_options[0] = BIT_2 | BIT_1;
1475 nv->firmware_options[1] = BIT_7 | BIT_5;
1476 nv->add_firmware_options[0] = BIT_5;
1477 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1478 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1479 } else if (IS_QLA2100(ha)) {
1480 nv->firmware_options[0] = BIT_3 | BIT_1;
1481 nv->firmware_options[1] = BIT_5;
1482 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1485 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1486 nv->execution_throttle = __constant_cpu_to_le16(16);
1487 nv->retry_count = 8;
1488 nv->retry_delay = 1;
1490 nv->port_name[0] = 33;
1491 nv->port_name[3] = 224;
1492 nv->port_name[4] = 139;
1494 qla2xxx_nvram_wwn_from_ofw(ha, nv);
1496 nv->login_timeout = 4;
1499 * Set default host adapter parameters
1501 nv->host_p[1] = BIT_2;
1502 nv->reset_delay = 5;
1503 nv->port_down_retry_count = 8;
1504 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1505 nv->link_down_timeout = 60;
1510 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1512 * The SN2 does not provide BIOS emulation which means you can't change
1513 * potentially bogus BIOS settings. Force the use of default settings
1514 * for link rate and frame size. Hope that the rest of the settings
1517 if (ia64_platform_is("sn2")) {
1518 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1520 nv->special_options[1] = BIT_7;
1524 /* Reset Initialization control block */
1525 memset(icb, 0, ha->init_cb_size);
1528 * Setup driver NVRAM options.
1530 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1531 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1532 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1533 nv->firmware_options[1] &= ~BIT_4;
1535 if (IS_QLA23XX(ha)) {
1536 nv->firmware_options[0] |= BIT_2;
1537 nv->firmware_options[0] &= ~BIT_3;
1538 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1540 if (IS_QLA2300(ha)) {
1541 if (ha->fb_rev == FPM_2310) {
1542 strcpy(ha->model_number, "QLA2310");
1544 strcpy(ha->model_number, "QLA2300");
1547 qla2x00_set_model_info(ha, nv->model_number,
1548 sizeof(nv->model_number), "QLA23xx");
1550 } else if (IS_QLA2200(ha)) {
1551 nv->firmware_options[0] |= BIT_2;
1553 * 'Point-to-point preferred, else loop' is not a safe
1554 * connection mode setting.
1556 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1558 /* Force 'loop preferred, else point-to-point'. */
1559 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1560 nv->add_firmware_options[0] |= BIT_5;
1562 strcpy(ha->model_number, "QLA22xx");
1563 } else /*if (IS_QLA2100(ha))*/ {
1564 strcpy(ha->model_number, "QLA2100");
1568 * Copy over NVRAM RISC parameter block to initialization control block.
1570 dptr1 = (uint8_t *)icb;
1571 dptr2 = (uint8_t *)&nv->parameter_block_version;
1572 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1574 *dptr1++ = *dptr2++;
1576 /* Copy 2nd half. */
1577 dptr1 = (uint8_t *)icb->add_firmware_options;
1578 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1580 *dptr1++ = *dptr2++;
1582 /* Use alternate WWN? */
1583 if (nv->host_p[1] & BIT_7) {
1584 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1585 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1588 /* Prepare nodename */
1589 if ((icb->firmware_options[1] & BIT_6) == 0) {
1591 * Firmware will apply the following mask if the nodename was
1594 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1595 icb->node_name[0] &= 0xF0;
1599 * Set host adapter parameters.
1601 if (nv->host_p[0] & BIT_7)
1602 ql2xextended_error_logging = 1;
1603 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1604 /* Always load RISC code on non ISP2[12]00 chips. */
1605 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1606 ha->flags.disable_risc_code_load = 0;
1607 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1608 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1609 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1610 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1611 ha->flags.disable_serdes = 0;
1613 ha->operating_mode =
1614 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1616 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1617 sizeof(ha->fw_seriallink_options));
1619 /* save HBA serial number */
1620 ha->serial0 = icb->port_name[5];
1621 ha->serial1 = icb->port_name[6];
1622 ha->serial2 = icb->port_name[7];
1623 ha->node_name = icb->node_name;
1624 ha->port_name = icb->port_name;
1626 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1628 ha->retry_count = nv->retry_count;
1630 /* Set minimum login_timeout to 4 seconds. */
1631 if (nv->login_timeout < ql2xlogintimeout)
1632 nv->login_timeout = ql2xlogintimeout;
1633 if (nv->login_timeout < 4)
1634 nv->login_timeout = 4;
1635 ha->login_timeout = nv->login_timeout;
1636 icb->login_timeout = nv->login_timeout;
1638 /* Set minimum RATOV to 200 tenths of a second. */
1641 ha->loop_reset_delay = nv->reset_delay;
1643 /* Link Down Timeout = 0:
1645 * When Port Down timer expires we will start returning
1646 * I/O's to OS with "DID_NO_CONNECT".
1648 * Link Down Timeout != 0:
1650 * The driver waits for the link to come up after link down
1651 * before returning I/Os to OS with "DID_NO_CONNECT".
1653 if (nv->link_down_timeout == 0) {
1654 ha->loop_down_abort_time =
1655 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1657 ha->link_down_timeout = nv->link_down_timeout;
1658 ha->loop_down_abort_time =
1659 (LOOP_DOWN_TIME - ha->link_down_timeout);
1663 * Need enough time to try and get the port back.
1665 ha->port_down_retry_count = nv->port_down_retry_count;
1666 if (qlport_down_retry)
1667 ha->port_down_retry_count = qlport_down_retry;
1668 /* Set login_retry_count */
1669 ha->login_retry_count = nv->retry_count;
1670 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1671 ha->port_down_retry_count > 3)
1672 ha->login_retry_count = ha->port_down_retry_count;
1673 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1674 ha->login_retry_count = ha->port_down_retry_count;
1675 if (ql2xloginretrycount)
1676 ha->login_retry_count = ql2xloginretrycount;
1678 icb->lun_enables = __constant_cpu_to_le16(0);
1679 icb->command_resource_count = 0;
1680 icb->immediate_notify_resource_count = 0;
1681 icb->timeout = __constant_cpu_to_le16(0);
1683 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1685 icb->firmware_options[0] &= ~BIT_3;
1686 icb->add_firmware_options[0] &=
1687 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1688 icb->add_firmware_options[0] |= BIT_2;
1689 icb->response_accumulation_timer = 3;
1690 icb->interrupt_delay_timer = 5;
1692 ha->flags.process_response_queue = 1;
1695 if (!ha->flags.init_done) {
1696 ha->zio_mode = icb->add_firmware_options[0] &
1697 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1698 ha->zio_timer = icb->interrupt_delay_timer ?
1699 icb->interrupt_delay_timer: 2;
1701 icb->add_firmware_options[0] &=
1702 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1703 ha->flags.process_response_queue = 0;
1704 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1705 ha->zio_mode = QLA_ZIO_MODE_6;
1707 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1708 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1709 ha->zio_timer * 100));
1710 qla_printk(KERN_INFO, ha,
1711 "ZIO mode %d enabled; timer delay (%d us).\n",
1712 ha->zio_mode, ha->zio_timer * 100);
1714 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1715 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1716 ha->flags.process_response_queue = 1;
1721 DEBUG2_3(printk(KERN_WARNING
1722 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1728 qla2x00_rport_del(void *data)
1730 fc_port_t *fcport = data;
1731 struct fc_rport *rport;
1732 unsigned long flags;
1734 spin_lock_irqsave(&fcport->rport_lock, flags);
1735 rport = fcport->drport;
1736 fcport->drport = NULL;
1737 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1739 fc_remote_port_delete(rport);
1743 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1745 * @flags: allocation flags
1747 * Returns a pointer to the allocated fcport, or NULL, if none available.
1750 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1754 fcport = kmalloc(sizeof(fc_port_t), flags);
1758 /* Setup fcport template structure. */
1759 memset(fcport, 0, sizeof (fc_port_t));
1761 fcport->vp_idx = ha->vp_idx;
1762 fcport->port_type = FCT_UNKNOWN;
1763 fcport->loop_id = FC_NO_LOOP_ID;
1764 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1765 fcport->flags = FCF_RLC_SUPPORT;
1766 fcport->supported_classes = FC_COS_UNSPECIFIED;
1767 spin_lock_init(&fcport->rport_lock);
1773 * qla2x00_configure_loop
1774 * Updates Fibre Channel Device Database with what is actually on loop.
1777 * ha = adapter block pointer.
1782 * 2 = database was full and device was not configured.
1785 qla2x00_configure_loop(scsi_qla_host_t *ha)
1788 unsigned long flags, save_flags;
1792 /* Get Initiator ID */
1793 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1794 rval = qla2x00_configure_hba(ha);
1795 if (rval != QLA_SUCCESS) {
1796 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1802 save_flags = flags = ha->dpc_flags;
1803 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1804 ha->host_no, flags));
1807 * If we have both an RSCN and PORT UPDATE pending then handle them
1808 * both at the same time.
1810 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1811 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1813 /* Determine what we need to do */
1814 if (ha->current_topology == ISP_CFG_FL &&
1815 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1817 ha->flags.rscn_queue_overflow = 1;
1818 set_bit(RSCN_UPDATE, &flags);
1820 } else if (ha->current_topology == ISP_CFG_F &&
1821 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1823 ha->flags.rscn_queue_overflow = 1;
1824 set_bit(RSCN_UPDATE, &flags);
1825 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1827 } else if (ha->current_topology == ISP_CFG_N) {
1828 clear_bit(RSCN_UPDATE, &flags);
1830 } else if (!ha->flags.online ||
1831 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1833 ha->flags.rscn_queue_overflow = 1;
1834 set_bit(RSCN_UPDATE, &flags);
1835 set_bit(LOCAL_LOOP_UPDATE, &flags);
1838 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1839 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1840 rval = QLA_FUNCTION_FAILED;
1842 rval = qla2x00_configure_local_loop(ha);
1846 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1847 if (LOOP_TRANSITION(ha)) {
1848 rval = QLA_FUNCTION_FAILED;
1850 rval = qla2x00_configure_fabric(ha);
1854 if (rval == QLA_SUCCESS) {
1855 if (atomic_read(&ha->loop_down_timer) ||
1856 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1857 rval = QLA_FUNCTION_FAILED;
1859 atomic_set(&ha->loop_state, LOOP_READY);
1861 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1866 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1867 __func__, ha->host_no));
1869 DEBUG3(printk("%s: exiting normally\n", __func__));
1872 /* Restore state if a resync event occured during processing */
1873 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1874 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1875 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1876 if (test_bit(RSCN_UPDATE, &save_flags))
1877 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1886 * qla2x00_configure_local_loop
1887 * Updates Fibre Channel Device Database with local loop devices.
1890 * ha = adapter block pointer.
1896 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1901 fc_port_t *fcport, *new_fcport;
1907 uint8_t domain, area, al_pa;
1908 scsi_qla_host_t *pha = to_qla_parent(ha);
1912 entries = MAX_FIBRE_DEVICES;
1914 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1915 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1917 /* Get list of logged in devices. */
1918 memset(ha->gid_list, 0, GID_LIST_SIZE);
1919 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1921 if (rval != QLA_SUCCESS)
1922 goto cleanup_allocation;
1924 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1925 ha->host_no, entries));
1926 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1927 entries * sizeof(struct gid_list_info)));
1929 /* Allocate temporary fcport for any new fcports discovered. */
1930 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1931 if (new_fcport == NULL) {
1932 rval = QLA_MEMORY_ALLOC_FAILED;
1933 goto cleanup_allocation;
1935 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1938 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1940 list_for_each_entry(fcport, &pha->fcports, list) {
1941 if (fcport->vp_idx != ha->vp_idx)
1944 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1945 fcport->port_type != FCT_BROADCAST &&
1946 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1948 DEBUG(printk("scsi(%ld): Marking port lost, "
1950 ha->host_no, fcport->loop_id));
1952 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1953 fcport->flags &= ~FCF_FARP_DONE;
1957 /* Add devices to port list. */
1958 id_iter = (char *)ha->gid_list;
1959 for (index = 0; index < entries; index++) {
1960 domain = ((struct gid_list_info *)id_iter)->domain;
1961 area = ((struct gid_list_info *)id_iter)->area;
1962 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1963 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1964 loop_id = (uint16_t)
1965 ((struct gid_list_info *)id_iter)->loop_id_2100;
1967 loop_id = le16_to_cpu(
1968 ((struct gid_list_info *)id_iter)->loop_id);
1969 id_iter += ha->gid_list_info_size;
1971 /* Bypass reserved domain fields. */
1972 if ((domain & 0xf0) == 0xf0)
1975 /* Bypass if not same domain and area of adapter. */
1976 if (area && domain &&
1977 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1980 /* Bypass invalid local loop ID. */
1981 if (loop_id > LAST_LOCAL_LOOP_ID)
1984 /* Fill in member data. */
1985 new_fcport->d_id.b.domain = domain;
1986 new_fcport->d_id.b.area = area;
1987 new_fcport->d_id.b.al_pa = al_pa;
1988 new_fcport->loop_id = loop_id;
1989 new_fcport->vp_idx = ha->vp_idx;
1990 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1991 if (rval2 != QLA_SUCCESS) {
1992 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1993 "information -- get_port_database=%x, "
1995 ha->host_no, rval2, new_fcport->loop_id));
1996 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1998 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2002 /* Check for matching device in port list. */
2005 list_for_each_entry(fcport, &pha->fcports, list) {
2006 if (fcport->vp_idx != ha->vp_idx)
2009 if (memcmp(new_fcport->port_name, fcport->port_name,
2013 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2014 FCF_PERSISTENT_BOUND);
2015 fcport->loop_id = new_fcport->loop_id;
2016 fcport->port_type = new_fcport->port_type;
2017 fcport->d_id.b24 = new_fcport->d_id.b24;
2018 memcpy(fcport->node_name, new_fcport->node_name,
2026 /* New device, add to fcports list. */
2027 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2029 new_fcport->ha = ha;
2030 new_fcport->vp_idx = ha->vp_idx;
2031 list_add_tail(&new_fcport->vp_fcport,
2034 list_add_tail(&new_fcport->list, &pha->fcports);
2036 /* Allocate a new replacement fcport. */
2037 fcport = new_fcport;
2038 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2039 if (new_fcport == NULL) {
2040 rval = QLA_MEMORY_ALLOC_FAILED;
2041 goto cleanup_allocation;
2043 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2046 /* Base iIDMA settings on HBA port speed. */
2047 switch (ha->link_data_rate) {
2048 case PORT_SPEED_1GB:
2049 fcport->fp_speed = cpu_to_be16(BIT_15);
2051 case PORT_SPEED_2GB:
2052 fcport->fp_speed = cpu_to_be16(BIT_14);
2054 case PORT_SPEED_4GB:
2055 fcport->fp_speed = cpu_to_be16(BIT_13);
2059 qla2x00_update_fcport(ha, fcport);
2067 if (rval != QLA_SUCCESS) {
2068 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2069 "rval=%x\n", ha->host_no, rval));
2073 ha->device_flags |= DFLG_LOCAL_DEVICES;
2074 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2081 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2085 qla2x00_mark_all_devices_lost(ha, 0);
2086 list_for_each_entry(fcport, &ha->fcports, list) {
2087 if (fcport->port_type != FCT_TARGET)
2090 qla2x00_update_fcport(ha, fcport);
2095 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2097 #define LS_UNKNOWN 2
2098 static char *link_speeds[5] = { "1", "2", "?", "4" };
2100 uint16_t port_speed, mb[6];
2102 if (!IS_IIDMA_CAPABLE(ha))
2105 switch (be16_to_cpu(fcport->fp_speed)) {
2107 port_speed = PORT_SPEED_1GB;
2110 port_speed = PORT_SPEED_2GB;
2113 port_speed = PORT_SPEED_4GB;
2116 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2117 "unsupported FM port operating speed (%04x).\n",
2118 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2119 fcport->port_name[2], fcport->port_name[3],
2120 fcport->port_name[4], fcport->port_name[5],
2121 fcport->port_name[6], fcport->port_name[7],
2122 be16_to_cpu(fcport->fp_speed)));
2123 port_speed = PORT_SPEED_UNKNOWN;
2126 if (port_speed == PORT_SPEED_UNKNOWN)
2129 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, port_speed, mb);
2130 if (rval != QLA_SUCCESS) {
2131 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2132 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2133 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2134 fcport->port_name[2], fcport->port_name[3],
2135 fcport->port_name[4], fcport->port_name[5],
2136 fcport->port_name[6], fcport->port_name[7], rval,
2137 port_speed, mb[0], mb[1]));
2139 DEBUG2(qla_printk(KERN_INFO, ha,
2140 "iIDMA adjusted to %s GB/s on "
2141 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2142 link_speeds[port_speed], fcport->port_name[0],
2143 fcport->port_name[1], fcport->port_name[2],
2144 fcport->port_name[3], fcport->port_name[4],
2145 fcport->port_name[5], fcport->port_name[6],
2146 fcport->port_name[7]));
2151 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2153 struct fc_rport_identifiers rport_ids;
2154 struct fc_rport *rport;
2155 unsigned long flags;
2158 qla2x00_rport_del(fcport);
2162 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2163 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2164 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2165 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2166 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2167 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2169 qla_printk(KERN_WARNING, ha,
2170 "Unable to allocate fc remote port!\n");
2173 spin_lock_irqsave(&fcport->rport_lock, flags);
2174 fcport->rport = rport;
2175 *((fc_port_t **)rport->dd_data) = fcport;
2176 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2178 rport->supported_classes = fcport->supported_classes;
2180 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2181 if (fcport->port_type == FCT_INITIATOR)
2182 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2183 if (fcport->port_type == FCT_TARGET)
2184 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2185 fc_remote_port_rolechg(rport, rport_ids.roles);
2187 if (rport->scsi_target_id != -1 &&
2188 rport->scsi_target_id < ha->host->max_id)
2189 fcport->os_target_id = rport->scsi_target_id;
2193 * qla2x00_update_fcport
2194 * Updates device on list.
2197 * ha = adapter block pointer.
2198 * fcport = port structure pointer.
2208 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2210 scsi_qla_host_t *pha = to_qla_parent(ha);
2213 fcport->login_retry = 0;
2214 fcport->port_login_retry_count = pha->port_down_retry_count *
2216 atomic_set(&fcport->port_down_timer, pha->port_down_retry_count *
2218 fcport->flags &= ~FCF_LOGIN_NEEDED;
2220 qla2x00_iidma_fcport(ha, fcport);
2222 atomic_set(&fcport->state, FCS_ONLINE);
2224 qla2x00_reg_remote_port(ha, fcport);
2228 * qla2x00_configure_fabric
2229 * Setup SNS devices with loop ID's.
2232 * ha = adapter block pointer.
2239 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2242 fc_port_t *fcport, *fcptemp;
2243 uint16_t next_loopid;
2244 uint16_t mb[MAILBOX_REGISTER_COUNT];
2246 LIST_HEAD(new_fcports);
2247 scsi_qla_host_t *pha = to_qla_parent(ha);
2249 /* If FL port exists, then SNS is present */
2250 if (IS_FWI2_CAPABLE(ha))
2251 loop_id = NPH_F_PORT;
2253 loop_id = SNS_FL_PORT;
2254 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2255 if (rval != QLA_SUCCESS) {
2256 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2257 "Port\n", ha->host_no));
2259 ha->device_flags &= ~SWITCH_FOUND;
2260 return (QLA_SUCCESS);
2262 ha->device_flags |= SWITCH_FOUND;
2264 /* Mark devices that need re-synchronization. */
2265 rval2 = qla2x00_device_resync(ha);
2266 if (rval2 == QLA_RSCNS_HANDLED) {
2267 /* No point doing the scan, just continue. */
2268 return (QLA_SUCCESS);
2272 if (ql2xfdmienable &&
2273 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2274 qla2x00_fdmi_register(ha);
2276 /* Ensure we are logged into the SNS. */
2277 if (IS_FWI2_CAPABLE(ha))
2280 loop_id = SIMPLE_NAME_SERVER;
2281 ha->isp_ops->fabric_login(ha, loop_id, 0xff, 0xff,
2282 0xfc, mb, BIT_1 | BIT_0);
2283 if (mb[0] != MBS_COMMAND_COMPLETE) {
2284 DEBUG2(qla_printk(KERN_INFO, ha,
2285 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2286 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2287 mb[0], mb[1], mb[2], mb[6], mb[7]));
2288 return (QLA_SUCCESS);
2291 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2292 if (qla2x00_rft_id(ha)) {
2294 DEBUG2(printk("scsi(%ld): Register FC-4 "
2295 "TYPE failed.\n", ha->host_no));
2297 if (qla2x00_rff_id(ha)) {
2299 DEBUG2(printk("scsi(%ld): Register FC-4 "
2300 "Features failed.\n", ha->host_no));
2302 if (qla2x00_rnn_id(ha)) {
2304 DEBUG2(printk("scsi(%ld): Register Node Name "
2305 "failed.\n", ha->host_no));
2306 } else if (qla2x00_rsnn_nn(ha)) {
2308 DEBUG2(printk("scsi(%ld): Register Symbolic "
2309 "Node Name failed.\n", ha->host_no));
2313 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2314 if (rval != QLA_SUCCESS)
2318 * Logout all previous fabric devices marked lost, except
2321 list_for_each_entry(fcport, &pha->fcports, list) {
2322 if (fcport->vp_idx !=ha->vp_idx)
2325 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2328 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2331 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2332 qla2x00_mark_device_lost(ha, fcport,
2333 ql2xplogiabsentdevice, 0);
2334 if (fcport->loop_id != FC_NO_LOOP_ID &&
2335 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2336 fcport->port_type != FCT_INITIATOR &&
2337 fcport->port_type != FCT_BROADCAST) {
2338 ha->isp_ops->fabric_logout(ha,
2340 fcport->d_id.b.domain,
2341 fcport->d_id.b.area,
2342 fcport->d_id.b.al_pa);
2343 fcport->loop_id = FC_NO_LOOP_ID;
2348 /* Starting free loop ID. */
2349 next_loopid = pha->min_external_loopid;
2352 * Scan through our port list and login entries that need to be
2355 list_for_each_entry(fcport, &pha->fcports, list) {
2356 if (fcport->vp_idx != ha->vp_idx)
2359 if (atomic_read(&ha->loop_down_timer) ||
2360 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2363 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2364 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2367 if (fcport->loop_id == FC_NO_LOOP_ID) {
2368 fcport->loop_id = next_loopid;
2369 rval = qla2x00_find_new_loop_id(ha, fcport);
2370 if (rval != QLA_SUCCESS) {
2371 /* Ran out of IDs to use */
2375 /* Login and update database */
2376 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2379 /* Exit if out of loop IDs. */
2380 if (rval != QLA_SUCCESS) {
2385 * Login and add the new devices to our port list.
2387 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2388 if (atomic_read(&ha->loop_down_timer) ||
2389 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2392 /* Find a new loop ID to use. */
2393 fcport->loop_id = next_loopid;
2394 rval = qla2x00_find_new_loop_id(ha, fcport);
2395 if (rval != QLA_SUCCESS) {
2396 /* Ran out of IDs to use */
2400 /* Login and update database */
2401 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2405 fcport->vp_idx = ha->vp_idx;
2406 list_add_tail(&fcport->vp_fcport,
2408 list_move_tail(&fcport->list,
2409 &ha->parent->fcports);
2411 list_move_tail(&fcport->list, &ha->fcports);
2415 /* Free all new device structures not processed. */
2416 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2417 list_del(&fcport->list);
2422 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2423 "rval=%d\n", ha->host_no, rval));
2431 * qla2x00_find_all_fabric_devs
2434 * ha = adapter block pointer.
2435 * dev = database device entry pointer.
2444 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2448 fc_port_t *fcport, *new_fcport, *fcptemp;
2453 int first_dev, last_dev;
2454 port_id_t wrap, nxt_d_id;
2458 scsi_qla_host_t *vha;
2459 scsi_qla_host_t *pha = to_qla_parent(ha);
2463 /* Try GID_PT to get device list, else GAN. */
2464 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2467 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2468 "on GA_NXT\n", ha->host_no));
2470 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2471 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2474 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2477 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2480 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2481 qla2x00_gpsc(ha, swl);
2486 /* Allocate temporary fcport for any new fcports discovered. */
2487 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2488 if (new_fcport == NULL) {
2490 return (QLA_MEMORY_ALLOC_FAILED);
2492 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2493 new_fcport->vp_idx = ha->vp_idx;
2494 /* Set start port ID scan at adapter ID. */
2498 /* Starting free loop ID. */
2499 loop_id = pha->min_external_loopid;
2500 for (; loop_id <= ha->last_loop_id; loop_id++) {
2501 if (qla2x00_is_reserved_id(ha, loop_id))
2504 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2509 wrap.b24 = new_fcport->d_id.b24;
2511 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2512 memcpy(new_fcport->node_name,
2513 swl[swl_idx].node_name, WWN_SIZE);
2514 memcpy(new_fcport->port_name,
2515 swl[swl_idx].port_name, WWN_SIZE);
2516 memcpy(new_fcport->fabric_port_name,
2517 swl[swl_idx].fabric_port_name, WWN_SIZE);
2518 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2520 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2526 /* Send GA_NXT to the switch */
2527 rval = qla2x00_ga_nxt(ha, new_fcport);
2528 if (rval != QLA_SUCCESS) {
2529 qla_printk(KERN_WARNING, ha,
2530 "SNS scan failed -- assuming zero-entry "
2532 list_for_each_entry_safe(fcport, fcptemp,
2533 new_fcports, list) {
2534 list_del(&fcport->list);
2542 /* If wrap on switch device list, exit. */
2544 wrap.b24 = new_fcport->d_id.b24;
2546 } else if (new_fcport->d_id.b24 == wrap.b24) {
2547 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2548 ha->host_no, new_fcport->d_id.b.domain,
2549 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2553 /* Bypass if same physical adapter. */
2554 if (new_fcport->d_id.b24 == pha->d_id.b24)
2557 /* Bypass virtual ports of the same host. */
2558 if (pha->num_vhosts) {
2559 vp_index = find_next_bit(
2560 (unsigned long *)pha->vp_idx_map,
2561 MAX_MULTI_ID_FABRIC + 1, 1);
2563 for (;vp_index <= MAX_MULTI_ID_FABRIC;
2564 vp_index = find_next_bit(
2565 (unsigned long *)pha->vp_idx_map,
2566 MAX_MULTI_ID_FABRIC + 1, vp_index + 1)) {
2569 list_for_each_entry(vha, &pha->vp_list,
2571 if (vp_index == vha->vp_idx) {
2582 new_fcport->d_id.b24 == vha->d_id.b24)
2585 if (vp_index <= MAX_MULTI_ID_FABRIC)
2589 /* Bypass if same domain and area of adapter. */
2590 if (((new_fcport->d_id.b24 & 0xffff00) ==
2591 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2595 /* Bypass reserved domain fields. */
2596 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2599 /* Locate matching device in database. */
2601 list_for_each_entry(fcport, &pha->fcports, list) {
2602 if (new_fcport->vp_idx != fcport->vp_idx)
2604 if (memcmp(new_fcport->port_name, fcport->port_name,
2610 /* Update port state. */
2611 memcpy(fcport->fabric_port_name,
2612 new_fcport->fabric_port_name, WWN_SIZE);
2613 fcport->fp_speed = new_fcport->fp_speed;
2616 * If address the same and state FCS_ONLINE, nothing
2619 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2620 atomic_read(&fcport->state) == FCS_ONLINE) {
2625 * If device was not a fabric device before.
2627 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2628 fcport->d_id.b24 = new_fcport->d_id.b24;
2629 fcport->loop_id = FC_NO_LOOP_ID;
2630 fcport->flags |= (FCF_FABRIC_DEVICE |
2632 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2637 * Port ID changed or device was marked to be updated;
2638 * Log it out if still logged in and mark it for
2641 fcport->d_id.b24 = new_fcport->d_id.b24;
2642 fcport->flags |= FCF_LOGIN_NEEDED;
2643 if (fcport->loop_id != FC_NO_LOOP_ID &&
2644 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2645 fcport->port_type != FCT_INITIATOR &&
2646 fcport->port_type != FCT_BROADCAST) {
2647 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
2648 fcport->d_id.b.domain, fcport->d_id.b.area,
2649 fcport->d_id.b.al_pa);
2650 fcport->loop_id = FC_NO_LOOP_ID;
2659 /* If device was not in our fcports list, then add it. */
2660 list_add_tail(&new_fcport->list, new_fcports);
2662 /* Allocate a new replacement fcport. */
2663 nxt_d_id.b24 = new_fcport->d_id.b24;
2664 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2665 if (new_fcport == NULL) {
2667 return (QLA_MEMORY_ALLOC_FAILED);
2669 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2670 new_fcport->d_id.b24 = nxt_d_id.b24;
2671 new_fcport->vp_idx = ha->vp_idx;
2677 if (!list_empty(new_fcports))
2678 ha->device_flags |= DFLG_FABRIC_DEVICES;
2684 * qla2x00_find_new_loop_id
2685 * Scan through our port list and find a new usable loop ID.
2688 * ha: adapter state pointer.
2689 * dev: port structure pointer.
2692 * qla2x00 local function return status code.
2698 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2703 uint16_t first_loop_id;
2704 scsi_qla_host_t *pha = to_qla_parent(ha);
2708 /* Save starting loop ID. */
2709 first_loop_id = dev->loop_id;
2712 /* Skip loop ID if already used by adapter. */
2713 if (dev->loop_id == ha->loop_id) {
2717 /* Skip reserved loop IDs. */
2718 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2722 /* Reset loop ID if passed the end. */
2723 if (dev->loop_id > ha->last_loop_id) {
2724 /* first loop ID. */
2725 dev->loop_id = ha->min_external_loopid;
2728 /* Check for loop ID being already in use. */
2731 list_for_each_entry(fcport, &pha->fcports, list) {
2732 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2733 /* ID possibly in use */
2739 /* If not in use then it is free to use. */
2744 /* ID in use. Try next value. */
2747 /* If wrap around. No free ID to use. */
2748 if (dev->loop_id == first_loop_id) {
2749 dev->loop_id = FC_NO_LOOP_ID;
2750 rval = QLA_FUNCTION_FAILED;
2759 * qla2x00_device_resync
2760 * Marks devices in the database that needs resynchronization.
2763 * ha = adapter block pointer.
2769 qla2x00_device_resync(scsi_qla_host_t *ha)
2774 uint32_t rscn_entry;
2775 uint8_t rscn_out_iter;
2778 scsi_qla_host_t *pha = to_qla_parent(ha);
2780 rval = QLA_RSCNS_HANDLED;
2782 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2783 ha->flags.rscn_queue_overflow) {
2785 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2786 format = MSB(MSW(rscn_entry));
2787 d_id.b.domain = LSB(MSW(rscn_entry));
2788 d_id.b.area = MSB(LSW(rscn_entry));
2789 d_id.b.al_pa = LSB(LSW(rscn_entry));
2791 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2792 "[%02x/%02x%02x%02x].\n",
2793 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2794 d_id.b.area, d_id.b.al_pa));
2797 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2798 ha->rscn_out_ptr = 0;
2800 /* Skip duplicate entries. */
2801 for (rscn_out_iter = ha->rscn_out_ptr;
2802 !ha->flags.rscn_queue_overflow &&
2803 rscn_out_iter != ha->rscn_in_ptr;
2804 rscn_out_iter = (rscn_out_iter ==
2805 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2807 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2810 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2811 "entry found at [%d].\n", ha->host_no,
2814 ha->rscn_out_ptr = rscn_out_iter;
2817 /* Queue overflow, set switch default case. */
2818 if (ha->flags.rscn_queue_overflow) {
2819 DEBUG(printk("scsi(%ld): device_resync: rscn "
2820 "overflow.\n", ha->host_no));
2823 ha->flags.rscn_queue_overflow = 0;
2839 ha->rscn_out_ptr = ha->rscn_in_ptr;
2845 list_for_each_entry(fcport, &pha->fcports, list) {
2846 if (fcport->vp_idx != ha->vp_idx)
2849 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2850 (fcport->d_id.b24 & mask) != d_id.b24 ||
2851 fcport->port_type == FCT_BROADCAST)
2854 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2856 fcport->port_type != FCT_INITIATOR) {
2857 qla2x00_mark_device_lost(ha, fcport,
2861 fcport->flags &= ~FCF_FARP_DONE;
2868 * qla2x00_fabric_dev_login
2869 * Login fabric target device and update FC port database.
2872 * ha: adapter state pointer.
2873 * fcport: port structure list pointer.
2874 * next_loopid: contains value of a new loop ID that can be used
2875 * by the next login attempt.
2878 * qla2x00 local function return status code.
2884 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2885 uint16_t *next_loopid)
2894 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2895 if (rval == QLA_SUCCESS) {
2896 /* Send an ADISC to tape devices.*/
2898 if (fcport->flags & FCF_TAPE_PRESENT)
2900 rval = qla2x00_get_port_database(ha, fcport, opts);
2901 if (rval != QLA_SUCCESS) {
2902 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
2903 fcport->d_id.b.domain, fcport->d_id.b.area,
2904 fcport->d_id.b.al_pa);
2905 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2907 qla2x00_update_fcport(ha, fcport);
2915 * qla2x00_fabric_login
2916 * Issue fabric login command.
2919 * ha = adapter block pointer.
2920 * device = pointer to FC device type structure.
2923 * 0 - Login successfully
2925 * 2 - Initiator device
2929 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2930 uint16_t *next_loopid)
2934 uint16_t tmp_loopid;
2935 uint16_t mb[MAILBOX_REGISTER_COUNT];
2941 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2942 "for port %02x%02x%02x.\n",
2943 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2944 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2946 /* Login fcport on switch. */
2947 ha->isp_ops->fabric_login(ha, fcport->loop_id,
2948 fcport->d_id.b.domain, fcport->d_id.b.area,
2949 fcport->d_id.b.al_pa, mb, BIT_0);
2950 if (mb[0] == MBS_PORT_ID_USED) {
2952 * Device has another loop ID. The firmware team
2953 * recommends the driver perform an implicit login with
2954 * the specified ID again. The ID we just used is save
2955 * here so we return with an ID that can be tried by
2959 tmp_loopid = fcport->loop_id;
2960 fcport->loop_id = mb[1];
2962 DEBUG(printk("Fabric Login: port in use - next "
2963 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2964 fcport->loop_id, fcport->d_id.b.domain,
2965 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2967 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2972 /* A retry occurred before. */
2973 *next_loopid = tmp_loopid;
2976 * No retry occurred before. Just increment the
2977 * ID value for next login.
2979 *next_loopid = (fcport->loop_id + 1);
2982 if (mb[1] & BIT_0) {
2983 fcport->port_type = FCT_INITIATOR;
2985 fcport->port_type = FCT_TARGET;
2986 if (mb[1] & BIT_1) {
2987 fcport->flags |= FCF_TAPE_PRESENT;
2992 fcport->supported_classes |= FC_COS_CLASS2;
2994 fcport->supported_classes |= FC_COS_CLASS3;
2998 } else if (mb[0] == MBS_LOOP_ID_USED) {
3000 * Loop ID already used, try next loop ID.
3003 rval = qla2x00_find_new_loop_id(ha, fcport);
3004 if (rval != QLA_SUCCESS) {
3005 /* Ran out of loop IDs to use */
3008 } else if (mb[0] == MBS_COMMAND_ERROR) {
3010 * Firmware possibly timed out during login. If NO
3011 * retries are left to do then the device is declared
3014 *next_loopid = fcport->loop_id;
3015 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3016 fcport->d_id.b.domain, fcport->d_id.b.area,
3017 fcport->d_id.b.al_pa);
3018 qla2x00_mark_device_lost(ha, fcport, 1, 0);
3024 * unrecoverable / not handled error
3026 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3027 "loop_id=%x jiffies=%lx.\n",
3028 __func__, ha->host_no, mb[0],
3029 fcport->d_id.b.domain, fcport->d_id.b.area,
3030 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3032 *next_loopid = fcport->loop_id;
3033 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3034 fcport->d_id.b.domain, fcport->d_id.b.area,
3035 fcport->d_id.b.al_pa);
3036 fcport->loop_id = FC_NO_LOOP_ID;
3037 fcport->login_retry = 0;
3048 * qla2x00_local_device_login
3049 * Issue local device login command.
3052 * ha = adapter block pointer.
3053 * loop_id = loop id of device to login to.
3055 * Returns (Where's the #define!!!!):
3056 * 0 - Login successfully
3061 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
3064 uint16_t mb[MAILBOX_REGISTER_COUNT];
3066 memset(mb, 0, sizeof(mb));
3067 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
3068 if (rval == QLA_SUCCESS) {
3069 /* Interrogate mailbox registers for any errors */
3070 if (mb[0] == MBS_COMMAND_ERROR)
3072 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3073 /* device not in PCB table */
3081 * qla2x00_loop_resync
3082 * Resync with fibre channel devices.
3085 * ha = adapter block pointer.
3091 qla2x00_loop_resync(scsi_qla_host_t *ha)
3098 atomic_set(&ha->loop_state, LOOP_UPDATE);
3099 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3100 if (ha->flags.online) {
3101 if (!(rval = qla2x00_fw_ready(ha))) {
3102 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3105 atomic_set(&ha->loop_state, LOOP_UPDATE);
3107 /* Issue a marker after FW becomes ready. */
3108 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3109 ha->marker_needed = 0;
3111 /* Remap devices on Loop. */
3112 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3114 qla2x00_configure_loop(ha);
3116 } while (!atomic_read(&ha->loop_down_timer) &&
3117 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3119 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3123 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3124 return (QLA_FUNCTION_FAILED);
3128 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3135 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3141 list_for_each_entry(fcport, &ha->fcports, list) {
3142 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3145 qla2x00_update_fcport(ha, fcport);
3146 fcport->flags &= ~FCF_RESCAN_NEEDED;
3150 qla2x00_probe_for_all_luns(ha);
3154 qla2x00_update_fcports(scsi_qla_host_t *ha)
3158 /* Go with deferred removal of rport references. */
3159 list_for_each_entry(fcport, &ha->fcports, list)
3161 qla2x00_rport_del(fcport);
3166 * Resets ISP and aborts all outstanding commands.
3169 * ha = adapter block pointer.
3175 qla2x00_abort_isp(scsi_qla_host_t *ha)
3178 unsigned long flags = 0;
3183 if (ha->flags.online) {
3184 ha->flags.online = 0;
3185 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3187 qla_printk(KERN_INFO, ha,
3188 "Performing ISP error recovery - ha= %p.\n", ha);
3189 ha->isp_ops->reset_chip(ha);
3191 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3192 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3193 atomic_set(&ha->loop_state, LOOP_DOWN);
3194 qla2x00_mark_all_devices_lost(ha, 0);
3196 if (!atomic_read(&ha->loop_down_timer))
3197 atomic_set(&ha->loop_down_timer,
3201 spin_lock_irqsave(&ha->hardware_lock, flags);
3202 /* Requeue all commands in outstanding command list. */
3203 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3204 sp = ha->outstanding_cmds[cnt];
3206 ha->outstanding_cmds[cnt] = NULL;
3208 sp->cmd->result = DID_RESET << 16;
3209 sp->cmd->host_scribble = (unsigned char *)NULL;
3210 qla2x00_sp_compl(ha, sp);
3213 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3215 ha->isp_ops->get_flash_version(ha, ha->request_ring);
3217 ha->isp_ops->nvram_config(ha);
3219 if (!qla2x00_restart_isp(ha)) {
3220 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3222 if (!atomic_read(&ha->loop_down_timer)) {
3224 * Issue marker command only when we are going
3225 * to start the I/O .
3227 ha->marker_needed = 1;
3230 ha->flags.online = 1;
3232 ha->isp_ops->enable_intrs(ha);
3234 ha->isp_abort_cnt = 0;
3235 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3238 rval = qla2x00_trace_control(ha, TC_ENABLE,
3239 ha->eft_dma, EFT_NUM_BUFFERS);
3241 qla_printk(KERN_WARNING, ha,
3242 "Unable to reinitialize EFT "
3246 } else { /* failed the ISP abort */
3247 ha->flags.online = 1;
3248 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3249 if (ha->isp_abort_cnt == 0) {
3250 qla_printk(KERN_WARNING, ha,
3251 "ISP error recovery failed - "
3252 "board disabled\n");
3254 * The next call disables the board
3257 ha->isp_ops->reset_adapter(ha);
3258 ha->flags.online = 0;
3259 clear_bit(ISP_ABORT_RETRY,
3262 } else { /* schedule another ISP abort */
3263 ha->isp_abort_cnt--;
3264 DEBUG(printk("qla%ld: ISP abort - "
3265 "retry remaining %d\n",
3266 ha->host_no, ha->isp_abort_cnt));
3270 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3271 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3272 "- retrying (%d) more times\n",
3273 ha->host_no, ha->isp_abort_cnt));
3274 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3282 qla_printk(KERN_INFO, ha,
3283 "qla2x00_abort_isp: **** FAILED ****\n");
3285 DEBUG(printk(KERN_INFO
3286 "qla2x00_abort_isp(%ld): exiting.\n",
3294 * qla2x00_restart_isp
3295 * restarts the ISP after a reset
3298 * ha = adapter block pointer.
3304 qla2x00_restart_isp(scsi_qla_host_t *ha)
3307 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3308 unsigned long flags = 0;
3311 /* If firmware needs to be loaded */
3312 if (qla2x00_isp_firmware(ha)) {
3313 ha->flags.online = 0;
3314 if (!(status = ha->isp_ops->chip_diag(ha))) {
3315 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3316 status = qla2x00_setup_chip(ha);
3320 spin_lock_irqsave(&ha->hardware_lock, flags);
3322 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3324 * Disable SRAM, Instruction RAM and GP RAM
3327 WRT_REG_WORD(®->hccr,
3328 (HCCR_ENABLE_PARITY + 0x0));
3329 RD_REG_WORD(®->hccr);
3332 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3334 status = qla2x00_setup_chip(ha);
3336 spin_lock_irqsave(&ha->hardware_lock, flags);
3338 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3339 /* Enable proper parity */
3342 WRT_REG_WORD(®->hccr,
3343 (HCCR_ENABLE_PARITY + 0x1));
3346 * SRAM, Instruction RAM and GP RAM
3349 WRT_REG_WORD(®->hccr,
3350 (HCCR_ENABLE_PARITY + 0x7));
3351 RD_REG_WORD(®->hccr);
3354 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3359 if (!status && !(status = qla2x00_init_rings(ha))) {
3360 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3361 if (!(status = qla2x00_fw_ready(ha))) {
3362 DEBUG(printk("%s(): Start configure loop, "
3363 "status = %d\n", __func__, status));
3365 /* Issue a marker after FW becomes ready. */
3366 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3368 ha->flags.online = 1;
3369 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3372 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3373 qla2x00_configure_loop(ha);
3375 } while (!atomic_read(&ha->loop_down_timer) &&
3376 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3378 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3381 /* if no cable then assume it's good */
3382 if ((ha->device_flags & DFLG_NO_CABLE))
3385 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3393 * qla2x00_reset_adapter
3397 * ha = adapter block pointer.
3400 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3402 unsigned long flags = 0;
3403 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3405 ha->flags.online = 0;
3406 ha->isp_ops->disable_intrs(ha);
3408 spin_lock_irqsave(&ha->hardware_lock, flags);
3409 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3410 RD_REG_WORD(®->hccr); /* PCI Posting. */
3411 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3412 RD_REG_WORD(®->hccr); /* PCI Posting. */
3413 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3417 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3419 unsigned long flags = 0;
3420 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3422 ha->flags.online = 0;
3423 ha->isp_ops->disable_intrs(ha);
3425 spin_lock_irqsave(&ha->hardware_lock, flags);
3426 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3427 RD_REG_DWORD(®->hccr);
3428 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3429 RD_REG_DWORD(®->hccr);
3430 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3433 /* On sparc systems, obtain port and node WWN from firmware
3436 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv)
3439 struct pci_dev *pdev = ha->pdev;
3440 struct device_node *dp = pci_device_to_OF_node(pdev);
3444 val = of_get_property(dp, "port-wwn", &len);
3445 if (val && len >= WWN_SIZE)
3446 memcpy(nv->port_name, val, WWN_SIZE);
3448 val = of_get_property(dp, "node-wwn", &len);
3449 if (val && len >= WWN_SIZE)
3450 memcpy(nv->node_name, val, WWN_SIZE);
3455 qla24xx_nvram_config(scsi_qla_host_t *ha)
3458 struct init_cb_24xx *icb;
3459 struct nvram_24xx *nv;
3461 uint8_t *dptr1, *dptr2;
3466 icb = (struct init_cb_24xx *)ha->init_cb;
3467 nv = (struct nvram_24xx *)ha->request_ring;
3469 /* Determine NVRAM starting address. */
3470 ha->nvram_size = sizeof(struct nvram_24xx);
3471 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3472 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3473 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3474 if (PCI_FUNC(ha->pdev->devfn)) {
3475 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3476 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3479 /* Get NVRAM data and calculate checksum. */
3480 dptr = (uint32_t *)nv;
3481 ha->isp_ops->read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3483 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3484 chksum += le32_to_cpu(*dptr++);
3486 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3487 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3490 /* Bad NVRAM data, set defaults parameters. */
3491 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3492 || nv->id[3] != ' ' ||
3493 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3494 /* Reset NVRAM data. */
3495 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3496 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3497 le16_to_cpu(nv->nvram_version));
3498 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3499 "invalid -- WWPN) defaults.\n");
3502 * Set default initialization control block.
3504 memset(nv, 0, ha->nvram_size);
3505 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3506 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3507 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3508 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3509 nv->exchange_count = __constant_cpu_to_le16(0);
3510 nv->hard_address = __constant_cpu_to_le16(124);
3511 nv->port_name[0] = 0x21;
3512 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3513 nv->port_name[2] = 0x00;
3514 nv->port_name[3] = 0xe0;
3515 nv->port_name[4] = 0x8b;
3516 nv->port_name[5] = 0x1c;
3517 nv->port_name[6] = 0x55;
3518 nv->port_name[7] = 0x86;
3519 nv->node_name[0] = 0x20;
3520 nv->node_name[1] = 0x00;
3521 nv->node_name[2] = 0x00;
3522 nv->node_name[3] = 0xe0;
3523 nv->node_name[4] = 0x8b;
3524 nv->node_name[5] = 0x1c;
3525 nv->node_name[6] = 0x55;
3526 nv->node_name[7] = 0x86;
3527 qla24xx_nvram_wwn_from_ofw(ha, nv);
3528 nv->login_retry_count = __constant_cpu_to_le16(8);
3529 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3530 nv->login_timeout = __constant_cpu_to_le16(0);
3531 nv->firmware_options_1 =
3532 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3533 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3534 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3535 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3536 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3537 nv->efi_parameters = __constant_cpu_to_le32(0);
3538 nv->reset_delay = 5;
3539 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3540 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3541 nv->link_down_timeout = __constant_cpu_to_le16(30);
3546 /* Reset Initialization control block */
3547 memset(icb, 0, sizeof(struct init_cb_24xx));
3549 /* Copy 1st segment. */
3550 dptr1 = (uint8_t *)icb;
3551 dptr2 = (uint8_t *)&nv->version;
3552 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3554 *dptr1++ = *dptr2++;
3556 icb->login_retry_count = nv->login_retry_count;
3557 icb->link_down_on_nos = nv->link_down_on_nos;
3559 /* Copy 2nd segment. */
3560 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3561 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3562 cnt = (uint8_t *)&icb->reserved_3 -
3563 (uint8_t *)&icb->interrupt_delay_timer;
3565 *dptr1++ = *dptr2++;
3568 * Setup driver NVRAM options.
3570 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3573 /* Use alternate WWN? */
3574 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3575 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3576 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3579 /* Prepare nodename */
3580 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3582 * Firmware will apply the following mask if the nodename was
3585 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3586 icb->node_name[0] &= 0xF0;
3589 /* Set host adapter parameters. */
3590 ha->flags.disable_risc_code_load = 0;
3591 ha->flags.enable_lip_reset = 0;
3592 ha->flags.enable_lip_full_login =
3593 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3594 ha->flags.enable_target_reset =
3595 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3596 ha->flags.enable_led_scheme = 0;
3597 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3599 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3600 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3602 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3603 sizeof(ha->fw_seriallink_options24));
3605 /* save HBA serial number */
3606 ha->serial0 = icb->port_name[5];
3607 ha->serial1 = icb->port_name[6];
3608 ha->serial2 = icb->port_name[7];
3609 ha->node_name = icb->node_name;
3610 ha->port_name = icb->port_name;
3612 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3614 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3616 /* Set minimum login_timeout to 4 seconds. */
3617 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3618 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3619 if (le16_to_cpu(nv->login_timeout) < 4)
3620 nv->login_timeout = __constant_cpu_to_le16(4);
3621 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3622 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3624 /* Set minimum RATOV to 200 tenths of a second. */
3627 ha->loop_reset_delay = nv->reset_delay;
3629 /* Link Down Timeout = 0:
3631 * When Port Down timer expires we will start returning
3632 * I/O's to OS with "DID_NO_CONNECT".
3634 * Link Down Timeout != 0:
3636 * The driver waits for the link to come up after link down
3637 * before returning I/Os to OS with "DID_NO_CONNECT".
3639 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3640 ha->loop_down_abort_time =
3641 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3643 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3644 ha->loop_down_abort_time =
3645 (LOOP_DOWN_TIME - ha->link_down_timeout);
3648 /* Need enough time to try and get the port back. */
3649 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3650 if (qlport_down_retry)
3651 ha->port_down_retry_count = qlport_down_retry;
3653 /* Set login_retry_count */
3654 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3655 if (ha->port_down_retry_count ==
3656 le16_to_cpu(nv->port_down_retry_count) &&
3657 ha->port_down_retry_count > 3)
3658 ha->login_retry_count = ha->port_down_retry_count;
3659 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3660 ha->login_retry_count = ha->port_down_retry_count;
3661 if (ql2xloginretrycount)
3662 ha->login_retry_count = ql2xloginretrycount;
3665 if (!ha->flags.init_done) {
3666 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3667 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3668 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3669 le16_to_cpu(icb->interrupt_delay_timer): 2;
3671 icb->firmware_options_2 &= __constant_cpu_to_le32(
3672 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3673 ha->flags.process_response_queue = 0;
3674 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3675 ha->zio_mode = QLA_ZIO_MODE_6;
3677 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3678 "(%d us).\n", ha->host_no, ha->zio_mode,
3679 ha->zio_timer * 100));
3680 qla_printk(KERN_INFO, ha,
3681 "ZIO mode %d enabled; timer delay (%d us).\n",
3682 ha->zio_mode, ha->zio_timer * 100);
3684 icb->firmware_options_2 |= cpu_to_le32(
3685 (uint32_t)ha->zio_mode);
3686 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3687 ha->flags.process_response_queue = 1;
3691 DEBUG2_3(printk(KERN_WARNING
3692 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3698 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3701 int segments, fragment;
3703 uint32_t *dcode, dlen;
3710 segments = FA_RISC_CODE_SEGMENTS;
3711 faddr = FA_RISC_CODE_ADDR;
3712 dcode = (uint32_t *)ha->request_ring;
3715 /* Validate firmware image by checking version. */
3716 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3717 for (i = 0; i < 4; i++)
3718 dcode[i] = be32_to_cpu(dcode[i]);
3719 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3720 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3721 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3723 qla_printk(KERN_WARNING, ha,
3724 "Unable to verify integrity of flash firmware image!\n");
3725 qla_printk(KERN_WARNING, ha,
3726 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3727 dcode[1], dcode[2], dcode[3]);
3729 return QLA_FUNCTION_FAILED;
3732 while (segments && rval == QLA_SUCCESS) {
3733 /* Read segment's load information. */
3734 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3736 risc_addr = be32_to_cpu(dcode[2]);
3737 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3738 risc_size = be32_to_cpu(dcode[3]);
3741 while (risc_size > 0 && rval == QLA_SUCCESS) {
3742 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3743 if (dlen > risc_size)
3746 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3747 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3748 ha->host_no, risc_addr, dlen, faddr));
3750 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3751 for (i = 0; i < dlen; i++)
3752 dcode[i] = swab32(dcode[i]);
3754 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3757 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3758 "segment %d of firmware\n", ha->host_no,
3760 qla_printk(KERN_WARNING, ha,
3761 "[ERROR] Failed to load segment %d of "
3762 "firmware\n", fragment);
3779 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3782 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3786 uint16_t *wcode, *fwcode;
3787 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3788 struct fw_blob *blob;
3790 /* Load firmware blob. */
3791 blob = qla2x00_request_firmware(ha);
3793 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3794 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3795 "from: " QLA_FW_URL ".\n");
3796 return QLA_FUNCTION_FAILED;
3801 wcode = (uint16_t *)ha->request_ring;
3803 fwcode = (uint16_t *)blob->fw->data;
3806 /* Validate firmware image by checking version. */
3807 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3808 qla_printk(KERN_WARNING, ha,
3809 "Unable to verify integrity of firmware image (%Zd)!\n",
3811 goto fail_fw_integrity;
3813 for (i = 0; i < 4; i++)
3814 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3815 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3816 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3817 wcode[2] == 0 && wcode[3] == 0)) {
3818 qla_printk(KERN_WARNING, ha,
3819 "Unable to verify integrity of firmware image!\n");
3820 qla_printk(KERN_WARNING, ha,
3821 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3822 wcode[1], wcode[2], wcode[3]);
3823 goto fail_fw_integrity;
3827 while (*seg && rval == QLA_SUCCESS) {
3829 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3830 risc_size = be16_to_cpu(fwcode[3]);
3832 /* Validate firmware image size. */
3833 fwclen += risc_size * sizeof(uint16_t);
3834 if (blob->fw->size < fwclen) {
3835 qla_printk(KERN_WARNING, ha,
3836 "Unable to verify integrity of firmware image "
3837 "(%Zd)!\n", blob->fw->size);
3838 goto fail_fw_integrity;
3842 while (risc_size > 0 && rval == QLA_SUCCESS) {
3843 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3844 if (wlen > risc_size)
3847 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3848 "addr %x, number of words 0x%x.\n", ha->host_no,
3851 for (i = 0; i < wlen; i++)
3852 wcode[i] = swab16(fwcode[i]);
3854 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3857 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3858 "segment %d of firmware\n", ha->host_no,
3860 qla_printk(KERN_WARNING, ha,
3861 "[ERROR] Failed to load segment %d of "
3862 "firmware\n", fragment);
3878 return QLA_FUNCTION_FAILED;
3882 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3885 int segments, fragment;
3886 uint32_t *dcode, dlen;
3890 struct fw_blob *blob;
3891 uint32_t *fwcode, fwclen;
3893 /* Load firmware blob. */
3894 blob = qla2x00_request_firmware(ha);
3896 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3897 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3898 "from: " QLA_FW_URL ".\n");
3900 /* Try to load RISC code from flash. */
3901 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3902 "outdated) firmware from flash.\n");
3903 return qla24xx_load_risc_flash(ha, srisc_addr);
3908 segments = FA_RISC_CODE_SEGMENTS;
3909 dcode = (uint32_t *)ha->request_ring;
3911 fwcode = (uint32_t *)blob->fw->data;
3914 /* Validate firmware image by checking version. */
3915 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3916 qla_printk(KERN_WARNING, ha,
3917 "Unable to verify integrity of firmware image (%Zd)!\n",
3919 goto fail_fw_integrity;
3921 for (i = 0; i < 4; i++)
3922 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3923 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3924 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3925 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3927 qla_printk(KERN_WARNING, ha,
3928 "Unable to verify integrity of firmware image!\n");
3929 qla_printk(KERN_WARNING, ha,
3930 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3931 dcode[1], dcode[2], dcode[3]);
3932 goto fail_fw_integrity;
3935 while (segments && rval == QLA_SUCCESS) {
3936 risc_addr = be32_to_cpu(fwcode[2]);
3937 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3938 risc_size = be32_to_cpu(fwcode[3]);
3940 /* Validate firmware image size. */
3941 fwclen += risc_size * sizeof(uint32_t);
3942 if (blob->fw->size < fwclen) {
3943 qla_printk(KERN_WARNING, ha,
3944 "Unable to verify integrity of firmware image "
3945 "(%Zd)!\n", blob->fw->size);
3947 goto fail_fw_integrity;
3951 while (risc_size > 0 && rval == QLA_SUCCESS) {
3952 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3953 if (dlen > risc_size)
3956 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3957 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3960 for (i = 0; i < dlen; i++)
3961 dcode[i] = swab32(fwcode[i]);
3963 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3966 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3967 "segment %d of firmware\n", ha->host_no,
3969 qla_printk(KERN_WARNING, ha,
3970 "[ERROR] Failed to load segment %d of "
3971 "firmware\n", fragment);
3987 return QLA_FUNCTION_FAILED;
3991 qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
3995 if (!IS_FWI2_CAPABLE(ha))
3997 if (!ha->fw_major_version)
4000 ret = qla2x00_stop_firmware(ha);
4001 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) {
4002 qla2x00_reset_chip(ha);
4003 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
4005 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
4007 qla_printk(KERN_INFO, ha,
4008 "Attempting retry of stop-firmware command...\n");
4009 ret = qla2x00_stop_firmware(ha);
4014 qla24xx_configure_vhba(scsi_qla_host_t *ha)
4016 int rval = QLA_SUCCESS;
4017 uint16_t mb[MAILBOX_REGISTER_COUNT];
4022 rval = qla2x00_fw_ready(ha);
4023 if (rval == QLA_SUCCESS) {
4024 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4025 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
4028 ha->flags.management_server_logged_in = 0;
4030 /* Login to SNS first */
4031 qla24xx_login_fabric(ha, NPH_SNS, 0xff, 0xff, 0xfc,
4033 if (mb[0] != MBS_COMMAND_COMPLETE) {
4034 DEBUG15(qla_printk(KERN_INFO, ha,
4035 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4036 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4037 mb[0], mb[1], mb[2], mb[6], mb[7]));
4038 return (QLA_FUNCTION_FAILED);
4041 atomic_set(&ha->loop_down_timer, 0);
4042 atomic_set(&ha->loop_state, LOOP_UP);
4043 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4044 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4045 rval = qla2x00_loop_resync(ha);