Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2008 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
| 8 | |
| 9 | #include <linux/delay.h> |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 10 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 12 | #include "qla_devtbl.h" |
| 13 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 14 | #ifdef CONFIG_SPARC |
| 15 | #include <asm/prom.h> |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 16 | #endif |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | /* |
| 19 | * QLogic ISP2x00 Hardware Support Function Prototypes. |
| 20 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | static int qla2x00_isp_firmware(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | static void qla2x00_resize_request_q(scsi_qla_host_t *); |
| 23 | static int qla2x00_setup_chip(scsi_qla_host_t *); |
| 24 | static void qla2x00_init_response_q_entries(scsi_qla_host_t *); |
| 25 | static int qla2x00_init_rings(scsi_qla_host_t *); |
| 26 | static int qla2x00_fw_ready(scsi_qla_host_t *); |
| 27 | static int qla2x00_configure_hba(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static int qla2x00_configure_loop(scsi_qla_host_t *); |
| 29 | static int qla2x00_configure_local_loop(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | static int qla2x00_configure_fabric(scsi_qla_host_t *); |
| 31 | static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *); |
| 32 | static int qla2x00_device_resync(scsi_qla_host_t *); |
| 33 | static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *, |
| 34 | uint16_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | static int qla2x00_restart_isp(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 38 | static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev); |
| 39 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 40 | static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); |
| 41 | static int qla84xx_init_chip(scsi_qla_host_t *); |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /****************************************************************************/ |
| 44 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 45 | /****************************************************************************/ |
| 46 | |
| 47 | /* |
| 48 | * qla2x00_initialize_adapter |
| 49 | * Initialize board. |
| 50 | * |
| 51 | * Input: |
| 52 | * ha = adapter block pointer. |
| 53 | * |
| 54 | * Returns: |
| 55 | * 0 = success |
| 56 | */ |
| 57 | int |
| 58 | qla2x00_initialize_adapter(scsi_qla_host_t *ha) |
| 59 | { |
| 60 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | /* Clear adapter flags. */ |
| 63 | ha->flags.online = 0; |
| 64 | ha->flags.reset_active = 0; |
| 65 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 66 | atomic_set(&ha->loop_state, LOOP_DOWN); |
Andrew Vasquez | 2603221 | 2007-01-29 10:22:23 -0800 | [diff] [blame] | 67 | ha->device_flags = DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | ha->dpc_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | ha->flags.management_server_logged_in = 0; |
| 70 | ha->marker_needed = 0; |
| 71 | ha->mbx_flags = 0; |
| 72 | ha->isp_abort_cnt = 0; |
| 73 | ha->beacon_blink_led = 0; |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 74 | set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 76 | qla_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 77 | rval = ha->isp_ops->pci_config(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | if (rval) { |
Andrew Vasquez | 7c98a04 | 2007-01-29 10:22:29 -0800 | [diff] [blame] | 79 | DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | ha->host_no)); |
| 81 | return (rval); |
| 82 | } |
| 83 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 84 | ha->isp_ops->reset_chip(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 86 | ha->isp_ops->get_flash_version(ha, ha->request_ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 89 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 90 | ha->isp_ops->nvram_config(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 92 | if (ha->flags.disable_serdes) { |
| 93 | /* Mask HBA via NVRAM settings? */ |
| 94 | qla_printk(KERN_INFO, ha, "Masking HBA WWPN " |
| 95 | "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n", |
| 96 | ha->port_name[0], ha->port_name[1], |
| 97 | ha->port_name[2], ha->port_name[3], |
| 98 | ha->port_name[4], ha->port_name[5], |
| 99 | ha->port_name[6], ha->port_name[7]); |
| 100 | return QLA_FUNCTION_FAILED; |
| 101 | } |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n"); |
| 104 | |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 105 | if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) { |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 106 | rval = ha->isp_ops->chip_diag(ha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 107 | if (rval) |
| 108 | return (rval); |
| 109 | rval = qla2x00_setup_chip(ha); |
| 110 | if (rval) |
| 111 | return (rval); |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 112 | qla2xxx_get_flash_info(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 114 | if (IS_QLA84XX(ha)) { |
| 115 | ha->cs84xx = qla84xx_get_chip(ha); |
| 116 | if (!ha->cs84xx) { |
| 117 | qla_printk(KERN_ERR, ha, |
| 118 | "Unable to configure ISP84XX.\n"); |
| 119 | return QLA_FUNCTION_FAILED; |
| 120 | } |
| 121 | } |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 122 | rval = qla2x00_init_rings(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | return (rval); |
| 125 | } |
| 126 | |
| 127 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 128 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | * @ha: HA context |
| 130 | * |
| 131 | * Returns 0 on success. |
| 132 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 133 | int |
| 134 | qla2100_pci_config(scsi_qla_host_t *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 136 | uint16_t w; |
Adam Kropelin | 27b2f67 | 2005-09-16 19:28:20 -0700 | [diff] [blame] | 137 | uint32_t d; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 138 | unsigned long flags; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 139 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 142 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 145 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 147 | |
| 148 | /* Reset expansion ROM address decode enable */ |
Adam Kropelin | 27b2f67 | 2005-09-16 19:28:20 -0700 | [diff] [blame] | 149 | pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d); |
| 150 | d &= ~PCI_ROM_ADDRESS_ENABLE; |
| 151 | pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 153 | /* Get PCI bus information. */ |
| 154 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 155 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 156 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 157 | |
| 158 | return QLA_SUCCESS; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 163 | * @ha: HA context |
| 164 | * |
| 165 | * Returns 0 on success. |
| 166 | */ |
| 167 | int |
| 168 | qla2300_pci_config(scsi_qla_host_t *ha) |
| 169 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 170 | uint16_t w; |
Adam Kropelin | 27b2f67 | 2005-09-16 19:28:20 -0700 | [diff] [blame] | 171 | uint32_t d; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 172 | unsigned long flags = 0; |
| 173 | uint32_t cnt; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 174 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 175 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 176 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 177 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 178 | |
| 179 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 180 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 181 | |
| 182 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 183 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 184 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 185 | |
| 186 | /* |
| 187 | * If this is a 2300 card and not 2312, reset the |
| 188 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 189 | * the 2310 also reports itself as a 2300 so we need to get the |
| 190 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 191 | * not a 2310. |
| 192 | */ |
| 193 | if (IS_QLA2300(ha)) { |
| 194 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 195 | |
| 196 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 197 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 198 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 199 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 200 | break; |
| 201 | |
| 202 | udelay(10); |
| 203 | } |
| 204 | |
| 205 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 206 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 207 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 208 | |
| 209 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 210 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 211 | |
| 212 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 213 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 214 | |
| 215 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 216 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 217 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 218 | |
| 219 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 220 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 221 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 222 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 223 | break; |
| 224 | |
| 225 | udelay(10); |
| 226 | } |
| 227 | |
| 228 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 229 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 230 | |
| 231 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 232 | |
| 233 | /* Reset expansion ROM address decode enable */ |
Adam Kropelin | 27b2f67 | 2005-09-16 19:28:20 -0700 | [diff] [blame] | 234 | pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d); |
| 235 | d &= ~PCI_ROM_ADDRESS_ENABLE; |
| 236 | pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 237 | |
| 238 | /* Get PCI bus information. */ |
| 239 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 240 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 241 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 242 | |
| 243 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 247 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 248 | * @ha: HA context |
| 249 | * |
| 250 | * Returns 0 on success. |
| 251 | */ |
| 252 | int |
| 253 | qla24xx_pci_config(scsi_qla_host_t *ha) |
| 254 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 255 | uint16_t w; |
Adam Kropelin | 27b2f67 | 2005-09-16 19:28:20 -0700 | [diff] [blame] | 256 | uint32_t d; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 257 | unsigned long flags = 0; |
| 258 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 259 | |
| 260 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 261 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 262 | |
| 263 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 264 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 265 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 266 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 267 | |
| 268 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 269 | |
| 270 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 271 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 272 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 273 | |
| 274 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 275 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) |
| 276 | pcie_set_readrq(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 277 | |
| 278 | /* Reset expansion ROM address decode enable */ |
Adam Kropelin | 27b2f67 | 2005-09-16 19:28:20 -0700 | [diff] [blame] | 279 | pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d); |
| 280 | d &= ~PCI_ROM_ADDRESS_ENABLE; |
| 281 | pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 282 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 283 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 284 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 285 | /* Get PCI bus information. */ |
| 286 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 287 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 288 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 289 | |
| 290 | return QLA_SUCCESS; |
| 291 | } |
| 292 | |
| 293 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 294 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 295 | * @ha: HA context |
| 296 | * |
| 297 | * Returns 0 on success. |
| 298 | */ |
| 299 | int |
| 300 | qla25xx_pci_config(scsi_qla_host_t *ha) |
| 301 | { |
| 302 | uint16_t w; |
| 303 | uint32_t d; |
| 304 | |
| 305 | pci_set_master(ha->pdev); |
| 306 | pci_try_set_mwi(ha->pdev); |
| 307 | |
| 308 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 309 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 310 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 311 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 312 | |
| 313 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
| 314 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) |
| 315 | pcie_set_readrq(ha->pdev, 2048); |
| 316 | |
| 317 | /* Reset expansion ROM address decode enable */ |
| 318 | pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d); |
| 319 | d &= ~PCI_ROM_ADDRESS_ENABLE; |
| 320 | pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d); |
| 321 | |
| 322 | ha->chip_revision = ha->pdev->revision; |
| 323 | |
| 324 | return QLA_SUCCESS; |
| 325 | } |
| 326 | |
| 327 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | * qla2x00_isp_firmware() - Choose firmware image. |
| 329 | * @ha: HA context |
| 330 | * |
| 331 | * Returns 0 on success. |
| 332 | */ |
| 333 | static int |
| 334 | qla2x00_isp_firmware(scsi_qla_host_t *ha) |
| 335 | { |
| 336 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 337 | uint16_t loop_id, topo, sw_cap; |
| 338 | uint8_t domain, area, al_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
| 340 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 341 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | if (ha->flags.disable_risc_code_load) { |
| 344 | DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n", |
| 345 | ha->host_no)); |
| 346 | qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n"); |
| 347 | |
| 348 | /* Verify checksum of loaded RISC code. */ |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 349 | rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 350 | if (rval == QLA_SUCCESS) { |
| 351 | /* And, verify we are not in ROM code. */ |
| 352 | rval = qla2x00_get_adapter_id(ha, &loop_id, &al_pa, |
| 353 | &area, &domain, &topo, &sw_cap); |
| 354 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | if (rval) { |
| 358 | DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n", |
| 359 | ha->host_no)); |
| 360 | } |
| 361 | |
| 362 | return (rval); |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * qla2x00_reset_chip() - Reset ISP chip. |
| 367 | * @ha: HA context |
| 368 | * |
| 369 | * Returns 0 on success. |
| 370 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 371 | void |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 372 | qla2x00_reset_chip(scsi_qla_host_t *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | { |
| 374 | unsigned long flags = 0; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 375 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | uint16_t cmd; |
| 378 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 379 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
| 381 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 382 | |
| 383 | /* Turn off master enable */ |
| 384 | cmd = 0; |
| 385 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 386 | cmd &= ~PCI_COMMAND_MASTER; |
| 387 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 388 | |
| 389 | if (!IS_QLA2100(ha)) { |
| 390 | /* Pause RISC. */ |
| 391 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 392 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 393 | for (cnt = 0; cnt < 30000; cnt++) { |
| 394 | if ((RD_REG_WORD(®->hccr) & |
| 395 | HCCR_RISC_PAUSE) != 0) |
| 396 | break; |
| 397 | udelay(100); |
| 398 | } |
| 399 | } else { |
| 400 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 401 | udelay(10); |
| 402 | } |
| 403 | |
| 404 | /* Select FPM registers. */ |
| 405 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 406 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 407 | |
| 408 | /* FPM Soft Reset. */ |
| 409 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 410 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 411 | |
| 412 | /* Toggle Fpm Reset. */ |
| 413 | if (!IS_QLA2200(ha)) { |
| 414 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 415 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 416 | } |
| 417 | |
| 418 | /* Select frame buffer registers. */ |
| 419 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 420 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 421 | |
| 422 | /* Reset frame buffer FIFOs. */ |
| 423 | if (IS_QLA2200(ha)) { |
| 424 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 425 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 426 | } else { |
| 427 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 428 | |
| 429 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 430 | for (cnt = 0; cnt < 3000; cnt++) { |
| 431 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 432 | break; |
| 433 | udelay(100); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | /* Select RISC module registers. */ |
| 438 | WRT_REG_WORD(®->ctrl_status, 0); |
| 439 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 440 | |
| 441 | /* Reset RISC processor. */ |
| 442 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 443 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 444 | |
| 445 | /* Release RISC processor. */ |
| 446 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 447 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 448 | } |
| 449 | |
| 450 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 451 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 452 | |
| 453 | /* Reset ISP chip. */ |
| 454 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 455 | |
| 456 | /* Wait for RISC to recover from reset. */ |
| 457 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 458 | /* |
| 459 | * It is necessary to for a delay here since the card doesn't |
| 460 | * respond to PCI reads during a reset. On some architectures |
| 461 | * this will result in an MCA. |
| 462 | */ |
| 463 | udelay(20); |
| 464 | for (cnt = 30000; cnt; cnt--) { |
| 465 | if ((RD_REG_WORD(®->ctrl_status) & |
| 466 | CSR_ISP_SOFT_RESET) == 0) |
| 467 | break; |
| 468 | udelay(100); |
| 469 | } |
| 470 | } else |
| 471 | udelay(10); |
| 472 | |
| 473 | /* Reset RISC processor. */ |
| 474 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 475 | |
| 476 | WRT_REG_WORD(®->semaphore, 0); |
| 477 | |
| 478 | /* Release RISC processor. */ |
| 479 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 480 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 481 | |
| 482 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 483 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 484 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
| 487 | udelay(100); |
| 488 | } |
| 489 | } else |
| 490 | udelay(100); |
| 491 | |
| 492 | /* Turn on master enable */ |
| 493 | cmd |= PCI_COMMAND_MASTER; |
| 494 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 495 | |
| 496 | /* Disable RISC pause on FPM parity error. */ |
| 497 | if (!IS_QLA2100(ha)) { |
| 498 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 499 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 500 | } |
| 501 | |
| 502 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 503 | } |
| 504 | |
| 505 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 506 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 507 | * @ha: HA context |
| 508 | * |
| 509 | * Returns 0 on success. |
| 510 | */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 511 | static inline void |
| 512 | qla24xx_reset_risc(scsi_qla_host_t *ha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 513 | { |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 514 | int hw_evt = 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 515 | unsigned long flags = 0; |
| 516 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 517 | uint32_t cnt, d2; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 518 | uint16_t wd; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 519 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 520 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 521 | |
| 522 | /* Reset RISC. */ |
| 523 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 524 | for (cnt = 0; cnt < 30000; cnt++) { |
| 525 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 526 | break; |
| 527 | |
| 528 | udelay(10); |
| 529 | } |
| 530 | |
| 531 | WRT_REG_DWORD(®->ctrl_status, |
| 532 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 533 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 534 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 535 | udelay(100); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 536 | /* Wait for firmware to complete NVRAM accesses. */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 537 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 538 | for (cnt = 10000 ; cnt && d2; cnt--) { |
| 539 | udelay(5); |
| 540 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 541 | barrier(); |
| 542 | } |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 543 | if (cnt == 0) |
| 544 | hw_evt = 1; |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 545 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 546 | /* Wait for soft-reset to complete. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 547 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 548 | for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) { |
| 549 | udelay(5); |
| 550 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 551 | barrier(); |
| 552 | } |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 553 | if (cnt == 0 || hw_evt) |
| 554 | qla2xxx_hw_event_log(ha, HW_EVENT_RESET_ERR, |
| 555 | RD_REG_WORD(®->mailbox1), RD_REG_WORD(®->mailbox2), |
| 556 | RD_REG_WORD(®->mailbox3)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 557 | |
| 558 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 559 | RD_REG_DWORD(®->hccr); |
| 560 | |
| 561 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 562 | RD_REG_DWORD(®->hccr); |
| 563 | |
| 564 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 565 | RD_REG_DWORD(®->hccr); |
| 566 | |
| 567 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 568 | for (cnt = 6000000 ; cnt && d2; cnt--) { |
| 569 | udelay(5); |
| 570 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 571 | barrier(); |
| 572 | } |
| 573 | |
| 574 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 575 | } |
| 576 | |
| 577 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 578 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 579 | * @ha: HA context |
| 580 | * |
| 581 | * Returns 0 on success. |
| 582 | */ |
| 583 | void |
| 584 | qla24xx_reset_chip(scsi_qla_host_t *ha) |
| 585 | { |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 586 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 587 | |
| 588 | /* Perform RISC reset. */ |
| 589 | qla24xx_reset_risc(ha); |
| 590 | } |
| 591 | |
| 592 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 594 | * @ha: HA context |
| 595 | * |
| 596 | * Returns 0 on success. |
| 597 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 598 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | qla2x00_chip_diag(scsi_qla_host_t *ha) |
| 600 | { |
| 601 | int rval; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 602 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | unsigned long flags = 0; |
| 604 | uint16_t data; |
| 605 | uint32_t cnt; |
| 606 | uint16_t mb[5]; |
| 607 | |
| 608 | /* Assume a failed state */ |
| 609 | rval = QLA_FUNCTION_FAILED; |
| 610 | |
| 611 | DEBUG3(printk("scsi(%ld): Testing device at %lx.\n", |
| 612 | ha->host_no, (u_long)®->flash_address)); |
| 613 | |
| 614 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 615 | |
| 616 | /* Reset ISP chip. */ |
| 617 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 618 | |
| 619 | /* |
| 620 | * We need to have a delay here since the card will not respond while |
| 621 | * in reset causing an MCA on some architectures. |
| 622 | */ |
| 623 | udelay(20); |
| 624 | data = qla2x00_debounce_register(®->ctrl_status); |
| 625 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 626 | udelay(5); |
| 627 | data = RD_REG_WORD(®->ctrl_status); |
| 628 | barrier(); |
| 629 | } |
| 630 | |
| 631 | if (!cnt) |
| 632 | goto chip_diag_failed; |
| 633 | |
| 634 | DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n", |
| 635 | ha->host_no)); |
| 636 | |
| 637 | /* Reset RISC processor. */ |
| 638 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 639 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 640 | |
| 641 | /* Workaround for QLA2312 PCI parity error */ |
| 642 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 643 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 644 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 645 | udelay(5); |
| 646 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 647 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | } |
| 649 | } else |
| 650 | udelay(10); |
| 651 | |
| 652 | if (!cnt) |
| 653 | goto chip_diag_failed; |
| 654 | |
| 655 | /* Check product ID of chip */ |
| 656 | DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no)); |
| 657 | |
| 658 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 659 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 660 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 661 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 662 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 663 | mb[3] != PROD_ID_3) { |
| 664 | qla_printk(KERN_WARNING, ha, |
| 665 | "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]); |
| 666 | |
| 667 | goto chip_diag_failed; |
| 668 | } |
| 669 | ha->product_id[0] = mb[1]; |
| 670 | ha->product_id[1] = mb[2]; |
| 671 | ha->product_id[2] = mb[3]; |
| 672 | ha->product_id[3] = mb[4]; |
| 673 | |
| 674 | /* Adjust fw RISC transfer size */ |
| 675 | if (ha->request_q_length > 1024) |
| 676 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 677 | else |
| 678 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
| 679 | ha->request_q_length; |
| 680 | |
| 681 | if (IS_QLA2200(ha) && |
| 682 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 683 | /* Limit firmware transfer size with a 2200A */ |
| 684 | DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n", |
| 685 | ha->host_no)); |
| 686 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 687 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | ha->fw_transfer_size = 128; |
| 689 | } |
| 690 | |
| 691 | /* Wrap Incoming Mailboxes Test. */ |
| 692 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 693 | |
| 694 | DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no)); |
| 695 | rval = qla2x00_mbx_reg_test(ha); |
| 696 | if (rval) { |
| 697 | DEBUG(printk("scsi(%ld): Failed mailbox send register test\n", |
| 698 | ha->host_no)); |
| 699 | qla_printk(KERN_WARNING, ha, |
| 700 | "Failed mailbox send register test\n"); |
| 701 | } |
| 702 | else { |
| 703 | /* Flag a successful rval */ |
| 704 | rval = QLA_SUCCESS; |
| 705 | } |
| 706 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 707 | |
| 708 | chip_diag_failed: |
| 709 | if (rval) |
| 710 | DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED " |
| 711 | "****\n", ha->host_no)); |
| 712 | |
| 713 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 714 | |
| 715 | return (rval); |
| 716 | } |
| 717 | |
| 718 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 719 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 720 | * @ha: HA context |
| 721 | * |
| 722 | * Returns 0 on success. |
| 723 | */ |
| 724 | int |
| 725 | qla24xx_chip_diag(scsi_qla_host_t *ha) |
| 726 | { |
| 727 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 728 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 729 | /* Perform RISC reset. */ |
| 730 | qla24xx_reset_risc(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 731 | |
Andrew Vasquez | 6d05252 | 2008-07-10 16:56:02 -0700 | [diff] [blame^] | 732 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * ha->request_q_length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 733 | |
| 734 | rval = qla2x00_mbx_reg_test(ha); |
| 735 | if (rval) { |
| 736 | DEBUG(printk("scsi(%ld): Failed mailbox send register test\n", |
| 737 | ha->host_no)); |
| 738 | qla_printk(KERN_WARNING, ha, |
| 739 | "Failed mailbox send register test\n"); |
| 740 | } else { |
| 741 | /* Flag a successful rval */ |
| 742 | rval = QLA_SUCCESS; |
| 743 | } |
| 744 | |
| 745 | return rval; |
| 746 | } |
| 747 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 748 | void |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 749 | qla2x00_alloc_fw_dump(scsi_qla_host_t *ha) |
| 750 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 751 | int rval; |
| 752 | uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 753 | eft_size, fce_size; |
| 754 | dma_addr_t tc_dma; |
| 755 | void *tc; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 756 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 757 | if (ha->fw_dump) { |
| 758 | qla_printk(KERN_WARNING, ha, |
| 759 | "Firmware dump previously allocated.\n"); |
| 760 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 763 | ha->fw_dumped = 0; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 764 | fixed_size = mem_size = eft_size = fce_size = 0; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 765 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 766 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 767 | } else if (IS_QLA23XX(ha)) { |
| 768 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 769 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 770 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 771 | } else if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 772 | fixed_size = IS_QLA25XX(ha) ? |
| 773 | offsetof(struct qla25xx_fw_dump, ext_mem): |
| 774 | offsetof(struct qla24xx_fw_dump, ext_mem); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 775 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 776 | sizeof(uint32_t); |
| 777 | |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 778 | /* Allocate memory for Fibre Channel Event Buffer. */ |
| 779 | if (!IS_QLA25XX(ha)) |
| 780 | goto try_eft; |
| 781 | |
| 782 | tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 783 | GFP_KERNEL); |
| 784 | if (!tc) { |
| 785 | qla_printk(KERN_WARNING, ha, "Unable to allocate " |
| 786 | "(%d KB) for FCE.\n", FCE_SIZE / 1024); |
| 787 | goto try_eft; |
| 788 | } |
| 789 | |
| 790 | memset(tc, 0, FCE_SIZE); |
| 791 | rval = qla2x00_enable_fce_trace(ha, tc_dma, FCE_NUM_BUFFERS, |
| 792 | ha->fce_mb, &ha->fce_bufs); |
| 793 | if (rval) { |
| 794 | qla_printk(KERN_WARNING, ha, "Unable to initialize " |
| 795 | "FCE (%d).\n", rval); |
| 796 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 797 | tc_dma); |
| 798 | ha->flags.fce_enabled = 0; |
| 799 | goto try_eft; |
| 800 | } |
| 801 | |
| 802 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n", |
| 803 | FCE_SIZE / 1024); |
| 804 | |
| 805 | fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE; |
| 806 | ha->flags.fce_enabled = 1; |
| 807 | ha->fce_dma = tc_dma; |
| 808 | ha->fce = tc; |
| 809 | try_eft: |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 810 | /* Allocate memory for Extended Trace Buffer. */ |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 811 | tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 812 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 813 | if (!tc) { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 814 | qla_printk(KERN_WARNING, ha, "Unable to allocate " |
| 815 | "(%d KB) for EFT.\n", EFT_SIZE / 1024); |
| 816 | goto cont_alloc; |
| 817 | } |
| 818 | |
Andrew Vasquez | fc44765 | 2008-01-17 09:02:18 -0800 | [diff] [blame] | 819 | memset(tc, 0, EFT_SIZE); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 820 | rval = qla2x00_enable_eft_trace(ha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 821 | if (rval) { |
| 822 | qla_printk(KERN_WARNING, ha, "Unable to initialize " |
| 823 | "EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 824 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 825 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 826 | goto cont_alloc; |
| 827 | } |
| 828 | |
| 829 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n", |
| 830 | EFT_SIZE / 1024); |
| 831 | |
| 832 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 833 | ha->eft_dma = tc_dma; |
| 834 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 835 | } |
| 836 | cont_alloc: |
| 837 | req_q_size = ha->request_q_length * sizeof(request_t); |
| 838 | rsp_q_size = ha->response_q_length * sizeof(response_t); |
| 839 | |
| 840 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
| 841 | dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 842 | eft_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 843 | |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 844 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 845 | if (!ha->fw_dump) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 846 | qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for " |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 847 | "firmware dump!!!\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 848 | |
| 849 | if (ha->eft) { |
| 850 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 851 | ha->eft_dma); |
| 852 | ha->eft = NULL; |
| 853 | ha->eft_dma = 0; |
| 854 | } |
| 855 | return; |
| 856 | } |
| 857 | |
| 858 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n", |
| 859 | dump_size / 1024); |
| 860 | |
| 861 | ha->fw_dump_len = dump_size; |
| 862 | ha->fw_dump->signature[0] = 'Q'; |
| 863 | ha->fw_dump->signature[1] = 'L'; |
| 864 | ha->fw_dump->signature[2] = 'G'; |
| 865 | ha->fw_dump->signature[3] = 'C'; |
| 866 | ha->fw_dump->version = __constant_htonl(1); |
| 867 | |
| 868 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 869 | ha->fw_dump->mem_size = htonl(mem_size); |
| 870 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 871 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 872 | |
| 873 | ha->fw_dump->eft_size = htonl(eft_size); |
| 874 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 875 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 876 | |
| 877 | ha->fw_dump->header_size = |
| 878 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | * qla2x00_resize_request_q() - Resize request queue given available ISP memory. |
| 883 | * @ha: HA context |
| 884 | * |
| 885 | * Returns 0 on success. |
| 886 | */ |
| 887 | static void |
| 888 | qla2x00_resize_request_q(scsi_qla_host_t *ha) |
| 889 | { |
| 890 | int rval; |
| 891 | uint16_t fw_iocb_cnt = 0; |
| 892 | uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM; |
| 893 | dma_addr_t request_dma; |
| 894 | request_t *request_ring; |
| 895 | |
| 896 | /* Valid only on recent ISPs. */ |
| 897 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 898 | return; |
| 899 | |
| 900 | /* Retrieve IOCB counts available to the firmware. */ |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 901 | rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt, |
| 902 | &ha->max_npiv_vports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | if (rval) |
| 904 | return; |
| 905 | /* No point in continuing if current settings are sufficient. */ |
| 906 | if (fw_iocb_cnt < 1024) |
| 907 | return; |
| 908 | if (ha->request_q_length >= request_q_length) |
| 909 | return; |
| 910 | |
| 911 | /* Attempt to claim larger area for request queue. */ |
| 912 | request_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 913 | (request_q_length + 1) * sizeof(request_t), &request_dma, |
| 914 | GFP_KERNEL); |
| 915 | if (request_ring == NULL) |
| 916 | return; |
| 917 | |
| 918 | /* Resize successful, report extensions. */ |
| 919 | qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n", |
| 920 | (ha->fw_memory_size + 1) / 1024); |
| 921 | qla_printk(KERN_INFO, ha, "Resizing request queue depth " |
| 922 | "(%d -> %d)...\n", ha->request_q_length, request_q_length); |
| 923 | |
| 924 | /* Clear old allocations. */ |
| 925 | dma_free_coherent(&ha->pdev->dev, |
| 926 | (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring, |
| 927 | ha->request_dma); |
| 928 | |
| 929 | /* Begin using larger queue. */ |
| 930 | ha->request_q_length = request_q_length; |
| 931 | ha->request_ring = request_ring; |
| 932 | ha->request_dma = request_dma; |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 937 | * @ha: HA context |
| 938 | * |
| 939 | * Returns 0 on success. |
| 940 | */ |
| 941 | static int |
| 942 | qla2x00_setup_chip(scsi_qla_host_t *ha) |
| 943 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 944 | int rval; |
| 945 | uint32_t srisc_address = 0; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 946 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 947 | unsigned long flags; |
| 948 | |
| 949 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 950 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 951 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 952 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 953 | RD_REG_WORD(®->hccr); |
| 954 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 955 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
| 957 | /* Load firmware sequences */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 958 | rval = ha->isp_ops->load_risc(ha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 959 | if (rval == QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC " |
| 961 | "code.\n", ha->host_no)); |
| 962 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 963 | rval = qla2x00_verify_checksum(ha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | if (rval == QLA_SUCCESS) { |
| 965 | /* Start firmware execution. */ |
| 966 | DEBUG(printk("scsi(%ld): Checksum OK, start " |
| 967 | "firmware.\n", ha->host_no)); |
| 968 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 969 | rval = qla2x00_execute_fw(ha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | /* Retrieve firmware information. */ |
| 971 | if (rval == QLA_SUCCESS && ha->fw_major_version == 0) { |
| 972 | qla2x00_get_fw_version(ha, |
| 973 | &ha->fw_major_version, |
| 974 | &ha->fw_minor_version, |
| 975 | &ha->fw_subminor_version, |
| 976 | &ha->fw_attributes, &ha->fw_memory_size); |
| 977 | qla2x00_resize_request_q(ha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 978 | ha->flags.npiv_supported = 0; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 979 | if ((IS_QLA24XX(ha) || IS_QLA25XX(ha)) && |
| 980 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 981 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 982 | if ((!ha->max_npiv_vports) || |
| 983 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 984 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 985 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 986 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 987 | } |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 988 | |
| 989 | if (ql2xallocfwdump) |
| 990 | qla2x00_alloc_fw_dump(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | } |
| 992 | } else { |
| 993 | DEBUG2(printk(KERN_INFO |
| 994 | "scsi(%ld): ISP Firmware failed checksum.\n", |
| 995 | ha->host_no)); |
| 996 | } |
| 997 | } |
| 998 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 999 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1000 | /* Enable proper parity. */ |
| 1001 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1002 | if (IS_QLA2300(ha)) |
| 1003 | /* SRAM parity */ |
| 1004 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 1005 | else |
| 1006 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 1007 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 1008 | RD_REG_WORD(®->hccr); |
| 1009 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1010 | } |
| 1011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | if (rval) { |
| 1013 | DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n", |
| 1014 | ha->host_no)); |
| 1015 | } |
| 1016 | |
| 1017 | return (rval); |
| 1018 | } |
| 1019 | |
| 1020 | /** |
| 1021 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 1022 | * @ha: HA context |
| 1023 | * |
| 1024 | * Beginning of request ring has initialization control block already built |
| 1025 | * by nvram config routine. |
| 1026 | * |
| 1027 | * Returns 0 on success. |
| 1028 | */ |
| 1029 | static void |
| 1030 | qla2x00_init_response_q_entries(scsi_qla_host_t *ha) |
| 1031 | { |
| 1032 | uint16_t cnt; |
| 1033 | response_t *pkt; |
| 1034 | |
| 1035 | pkt = ha->response_ring_ptr; |
| 1036 | for (cnt = 0; cnt < ha->response_q_length; cnt++) { |
| 1037 | pkt->signature = RESPONSE_PROCESSED; |
| 1038 | pkt++; |
| 1039 | } |
| 1040 | |
| 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 1045 | * @ha: HA context |
| 1046 | * |
| 1047 | * Returns 0 on success. |
| 1048 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1049 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | qla2x00_update_fw_options(scsi_qla_host_t *ha) |
| 1051 | { |
| 1052 | uint16_t swing, emphasis, tx_sens, rx_sens; |
| 1053 | |
| 1054 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 1055 | qla2x00_get_fw_options(ha, ha->fw_options); |
| 1056 | |
| 1057 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 1058 | return; |
| 1059 | |
| 1060 | /* Serial Link options. */ |
| 1061 | DEBUG3(printk("scsi(%ld): Serial link options:\n", |
| 1062 | ha->host_no)); |
| 1063 | DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options, |
| 1064 | sizeof(ha->fw_seriallink_options))); |
| 1065 | |
| 1066 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 1067 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 1068 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 1069 | |
| 1070 | /* 1G settings */ |
| 1071 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 1072 | emphasis = (ha->fw_seriallink_options[2] & |
| 1073 | (BIT_4 | BIT_3)) >> 3; |
| 1074 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1075 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | rx_sens = (ha->fw_seriallink_options[0] & |
| 1077 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1078 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 1079 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1080 | if (rx_sens == 0x0) |
| 1081 | rx_sens = 0x3; |
| 1082 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 1083 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1084 | ha->fw_options[10] |= BIT_5 | |
| 1085 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1086 | (tx_sens & (BIT_1 | BIT_0)); |
| 1087 | |
| 1088 | /* 2G settings */ |
| 1089 | swing = (ha->fw_seriallink_options[2] & |
| 1090 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 1091 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 1092 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1093 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | rx_sens = (ha->fw_seriallink_options[1] & |
| 1095 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1096 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 1097 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1098 | if (rx_sens == 0x0) |
| 1099 | rx_sens = 0x3; |
| 1100 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 1101 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1102 | ha->fw_options[11] |= BIT_5 | |
| 1103 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1104 | (tx_sens & (BIT_1 | BIT_0)); |
| 1105 | } |
| 1106 | |
| 1107 | /* FCP2 options. */ |
| 1108 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 1109 | ha->fw_options[3] |= BIT_13; |
| 1110 | |
| 1111 | /* LED scheme. */ |
| 1112 | if (ha->flags.enable_led_scheme) |
| 1113 | ha->fw_options[2] |= BIT_12; |
| 1114 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 1115 | /* Detect ISP6312. */ |
| 1116 | if (IS_QLA6312(ha)) |
| 1117 | ha->fw_options[2] |= BIT_13; |
| 1118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | /* Update firmware options. */ |
| 1120 | qla2x00_set_fw_options(ha, ha->fw_options); |
| 1121 | } |
| 1122 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1123 | void |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1124 | qla24xx_update_fw_options(scsi_qla_host_t *ha) |
| 1125 | { |
| 1126 | int rval; |
| 1127 | |
| 1128 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1129 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1130 | return; |
| 1131 | |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1132 | rval = qla2x00_set_serdes_params(ha, |
| 1133 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 1134 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 1135 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1136 | if (rval != QLA_SUCCESS) { |
| 1137 | qla_printk(KERN_WARNING, ha, |
| 1138 | "Unable to update Serial Link options (%x).\n", rval); |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | void |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1143 | qla2x00_config_rings(struct scsi_qla_host *ha) |
| 1144 | { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1145 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1146 | |
| 1147 | /* Setup ring parameters in initialization control block. */ |
| 1148 | ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1149 | ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0); |
| 1150 | ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length); |
| 1151 | ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length); |
| 1152 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma)); |
| 1153 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma)); |
| 1154 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma)); |
| 1155 | ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma)); |
| 1156 | |
| 1157 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 1158 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 1159 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 1160 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 1161 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 1162 | } |
| 1163 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1164 | void |
| 1165 | qla24xx_config_rings(struct scsi_qla_host *ha) |
| 1166 | { |
| 1167 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1168 | struct init_cb_24xx *icb; |
| 1169 | |
| 1170 | /* Setup ring parameters in initialization control block. */ |
| 1171 | icb = (struct init_cb_24xx *)ha->init_cb; |
| 1172 | icb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1173 | icb->response_q_inpointer = __constant_cpu_to_le16(0); |
| 1174 | icb->request_q_length = cpu_to_le16(ha->request_q_length); |
| 1175 | icb->response_q_length = cpu_to_le16(ha->response_q_length); |
| 1176 | icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma)); |
| 1177 | icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma)); |
| 1178 | icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma)); |
| 1179 | icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma)); |
| 1180 | |
| 1181 | WRT_REG_DWORD(®->req_q_in, 0); |
| 1182 | WRT_REG_DWORD(®->req_q_out, 0); |
| 1183 | WRT_REG_DWORD(®->rsp_q_in, 0); |
| 1184 | WRT_REG_DWORD(®->rsp_q_out, 0); |
| 1185 | RD_REG_DWORD(®->rsp_q_out); |
| 1186 | } |
| 1187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | /** |
| 1189 | * qla2x00_init_rings() - Initializes firmware. |
| 1190 | * @ha: HA context |
| 1191 | * |
| 1192 | * Beginning of request ring has initialization control block already built |
| 1193 | * by nvram config routine. |
| 1194 | * |
| 1195 | * Returns 0 on success. |
| 1196 | */ |
| 1197 | static int |
| 1198 | qla2x00_init_rings(scsi_qla_host_t *ha) |
| 1199 | { |
| 1200 | int rval; |
| 1201 | unsigned long flags = 0; |
| 1202 | int cnt; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1203 | struct mid_init_cb_24xx *mid_init_cb = |
| 1204 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | |
| 1206 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1207 | |
| 1208 | /* Clear outstanding commands array. */ |
| 1209 | for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) |
| 1210 | ha->outstanding_cmds[cnt] = NULL; |
| 1211 | |
| 1212 | ha->current_outstanding_cmd = 0; |
| 1213 | |
| 1214 | /* Clear RSCN queue. */ |
| 1215 | ha->rscn_in_ptr = 0; |
| 1216 | ha->rscn_out_ptr = 0; |
| 1217 | |
| 1218 | /* Initialize firmware. */ |
| 1219 | ha->request_ring_ptr = ha->request_ring; |
| 1220 | ha->req_ring_index = 0; |
| 1221 | ha->req_q_cnt = ha->request_q_length; |
| 1222 | ha->response_ring_ptr = ha->response_ring; |
| 1223 | ha->rsp_ring_index = 0; |
| 1224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | /* Initialize response queue entries */ |
| 1226 | qla2x00_init_response_q_entries(ha); |
| 1227 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1228 | ha->isp_ops->config_rings(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | |
| 1230 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1231 | |
| 1232 | /* Update any ISP specific firmware options before initialization. */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1233 | ha->isp_ops->update_fw_options(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | |
| 1235 | DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1236 | |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 1237 | if (ha->flags.npiv_supported) |
| 1238 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
| 1239 | |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1240 | mid_init_cb->options = __constant_cpu_to_le16(BIT_1); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1241 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1242 | rval = qla2x00_init_firmware(ha, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | if (rval) { |
| 1244 | DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n", |
| 1245 | ha->host_no)); |
| 1246 | } else { |
| 1247 | DEBUG3(printk("scsi(%ld): Init firmware -- success.\n", |
| 1248 | ha->host_no)); |
| 1249 | } |
| 1250 | |
| 1251 | return (rval); |
| 1252 | } |
| 1253 | |
| 1254 | /** |
| 1255 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 1256 | * @ha: HA context |
| 1257 | * |
| 1258 | * Returns 0 on success. |
| 1259 | */ |
| 1260 | static int |
| 1261 | qla2x00_fw_ready(scsi_qla_host_t *ha) |
| 1262 | { |
| 1263 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1264 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 1266 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1267 | uint16_t state[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
| 1269 | rval = QLA_SUCCESS; |
| 1270 | |
| 1271 | /* 20 seconds for loop down. */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1272 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | |
| 1274 | /* |
| 1275 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 1276 | * our own processing. |
| 1277 | */ |
| 1278 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 1279 | wait_time = min_wait; |
| 1280 | } |
| 1281 | |
| 1282 | /* Min wait time if loop down */ |
| 1283 | mtime = jiffies + (min_wait * HZ); |
| 1284 | |
| 1285 | /* wait time before firmware ready */ |
| 1286 | wtime = jiffies + (wait_time * HZ); |
| 1287 | |
| 1288 | /* Wait for ISP to finish LIP */ |
| 1289 | if (!ha->flags.init_done) |
| 1290 | qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n"); |
| 1291 | |
| 1292 | DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n", |
| 1293 | ha->host_no)); |
| 1294 | |
| 1295 | do { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1296 | rval = qla2x00_get_firmware_state(ha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1298 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | ha->device_flags &= ~DFLG_NO_CABLE; |
| 1300 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1301 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
| 1302 | DEBUG16(printk("scsi(%ld): fw_state=%x " |
| 1303 | "84xx=%x.\n", ha->host_no, state[0], |
| 1304 | state[2])); |
| 1305 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 1306 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
| 1307 | DEBUG16(printk("scsi(%ld): Sending " |
| 1308 | "verify iocb.\n", ha->host_no)); |
| 1309 | |
| 1310 | cs84xx_time = jiffies; |
| 1311 | rval = qla84xx_init_chip(ha); |
| 1312 | if (rval != QLA_SUCCESS) |
| 1313 | break; |
| 1314 | |
| 1315 | /* Add time taken to initialize. */ |
| 1316 | cs84xx_time = jiffies - cs84xx_time; |
| 1317 | wtime += cs84xx_time; |
| 1318 | mtime += cs84xx_time; |
| 1319 | DEBUG16(printk("scsi(%ld): Increasing " |
| 1320 | "wait time by %ld. New time %ld\n", |
| 1321 | ha->host_no, cs84xx_time, wtime)); |
| 1322 | } |
| 1323 | } else if (state[0] == FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | DEBUG(printk("scsi(%ld): F/W Ready - OK \n", |
| 1325 | ha->host_no)); |
| 1326 | |
| 1327 | qla2x00_get_retry_cnt(ha, &ha->retry_count, |
| 1328 | &ha->login_timeout, &ha->r_a_tov); |
| 1329 | |
| 1330 | rval = QLA_SUCCESS; |
| 1331 | break; |
| 1332 | } |
| 1333 | |
| 1334 | rval = QLA_FUNCTION_FAILED; |
| 1335 | |
| 1336 | if (atomic_read(&ha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1337 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1339 | * other than Wait for Login. |
| 1340 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | if (time_after_eq(jiffies, mtime)) { |
| 1342 | qla_printk(KERN_INFO, ha, |
| 1343 | "Cable is unplugged...\n"); |
| 1344 | |
| 1345 | ha->device_flags |= DFLG_NO_CABLE; |
| 1346 | break; |
| 1347 | } |
| 1348 | } |
| 1349 | } else { |
| 1350 | /* Mailbox cmd failed. Timeout on min_wait. */ |
| 1351 | if (time_after_eq(jiffies, mtime)) |
| 1352 | break; |
| 1353 | } |
| 1354 | |
| 1355 | if (time_after_eq(jiffies, wtime)) |
| 1356 | break; |
| 1357 | |
| 1358 | /* Delay for a while */ |
| 1359 | msleep(500); |
| 1360 | |
| 1361 | DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n", |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1362 | ha->host_no, state[0], jiffies)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | } while (1); |
| 1364 | |
| 1365 | DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n", |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1366 | ha->host_no, state[0], jiffies)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | |
| 1368 | if (rval) { |
| 1369 | DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n", |
| 1370 | ha->host_no)); |
| 1371 | } |
| 1372 | |
| 1373 | return (rval); |
| 1374 | } |
| 1375 | |
| 1376 | /* |
| 1377 | * qla2x00_configure_hba |
| 1378 | * Setup adapter context. |
| 1379 | * |
| 1380 | * Input: |
| 1381 | * ha = adapter state pointer. |
| 1382 | * |
| 1383 | * Returns: |
| 1384 | * 0 = success |
| 1385 | * |
| 1386 | * Context: |
| 1387 | * Kernel context. |
| 1388 | */ |
| 1389 | static int |
| 1390 | qla2x00_configure_hba(scsi_qla_host_t *ha) |
| 1391 | { |
| 1392 | int rval; |
| 1393 | uint16_t loop_id; |
| 1394 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1395 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | uint8_t al_pa; |
| 1397 | uint8_t area; |
| 1398 | uint8_t domain; |
| 1399 | char connect_type[22]; |
| 1400 | |
| 1401 | /* Get host addresses. */ |
| 1402 | rval = qla2x00_get_adapter_id(ha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1403 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | 23443b1 | 2005-12-06 10:57:06 -0800 | [diff] [blame] | 1405 | if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 1406 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
| 1407 | DEBUG2(printk("%s(%ld) Loop is in a transition state\n", |
| 1408 | __func__, ha->host_no)); |
| 1409 | } else { |
| 1410 | qla_printk(KERN_WARNING, ha, |
| 1411 | "ERROR -- Unable to get host loop ID.\n"); |
| 1412 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 1413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | return (rval); |
| 1415 | } |
| 1416 | |
| 1417 | if (topo == 4) { |
| 1418 | qla_printk(KERN_INFO, ha, |
| 1419 | "Cannot get topology - retrying.\n"); |
| 1420 | return (QLA_FUNCTION_FAILED); |
| 1421 | } |
| 1422 | |
| 1423 | ha->loop_id = loop_id; |
| 1424 | |
| 1425 | /* initialize */ |
| 1426 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 1427 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1428 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
| 1430 | switch (topo) { |
| 1431 | case 0: |
| 1432 | DEBUG3(printk("scsi(%ld): HBA in NL topology.\n", |
| 1433 | ha->host_no)); |
| 1434 | ha->current_topology = ISP_CFG_NL; |
| 1435 | strcpy(connect_type, "(Loop)"); |
| 1436 | break; |
| 1437 | |
| 1438 | case 1: |
| 1439 | DEBUG3(printk("scsi(%ld): HBA in FL topology.\n", |
| 1440 | ha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1441 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | ha->current_topology = ISP_CFG_FL; |
| 1443 | strcpy(connect_type, "(FL_Port)"); |
| 1444 | break; |
| 1445 | |
| 1446 | case 2: |
| 1447 | DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n", |
| 1448 | ha->host_no)); |
| 1449 | ha->operating_mode = P2P; |
| 1450 | ha->current_topology = ISP_CFG_N; |
| 1451 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 1452 | break; |
| 1453 | |
| 1454 | case 3: |
| 1455 | DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n", |
| 1456 | ha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1457 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | ha->operating_mode = P2P; |
| 1459 | ha->current_topology = ISP_CFG_F; |
| 1460 | strcpy(connect_type, "(F_Port)"); |
| 1461 | break; |
| 1462 | |
| 1463 | default: |
| 1464 | DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. " |
| 1465 | "Using NL.\n", |
| 1466 | ha->host_no, topo)); |
| 1467 | ha->current_topology = ISP_CFG_NL; |
| 1468 | strcpy(connect_type, "(Loop)"); |
| 1469 | break; |
| 1470 | } |
| 1471 | |
| 1472 | /* Save Host port and loop ID. */ |
| 1473 | /* byte order - Big Endian */ |
| 1474 | ha->d_id.b.domain = domain; |
| 1475 | ha->d_id.b.area = area; |
| 1476 | ha->d_id.b.al_pa = al_pa; |
| 1477 | |
| 1478 | if (!ha->flags.init_done) |
| 1479 | qla_printk(KERN_INFO, ha, |
| 1480 | "Topology - %s, Host Loop address 0x%x\n", |
| 1481 | connect_type, ha->loop_id); |
| 1482 | |
| 1483 | if (rval) { |
| 1484 | DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no)); |
| 1485 | } else { |
| 1486 | DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no)); |
| 1487 | } |
| 1488 | |
| 1489 | return(rval); |
| 1490 | } |
| 1491 | |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1492 | static inline void |
| 1493 | qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def) |
| 1494 | { |
| 1495 | char *st, *en; |
| 1496 | uint16_t index; |
| 1497 | |
| 1498 | if (memcmp(model, BINZERO, len) != 0) { |
| 1499 | strncpy(ha->model_number, model, len); |
| 1500 | st = en = ha->model_number; |
| 1501 | en += len - 1; |
| 1502 | while (en > st) { |
| 1503 | if (*en != 0x20 && *en != 0x00) |
| 1504 | break; |
| 1505 | *en-- = '\0'; |
| 1506 | } |
| 1507 | |
| 1508 | index = (ha->pdev->subsystem_device & 0xff); |
| 1509 | if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
| 1510 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 1511 | strncpy(ha->model_desc, |
| 1512 | qla2x00_model_name[index * 2 + 1], |
| 1513 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1514 | } else { |
| 1515 | index = (ha->pdev->subsystem_device & 0xff); |
| 1516 | if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
| 1517 | index < QLA_MODEL_NAMES) { |
| 1518 | strcpy(ha->model_number, |
| 1519 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 1520 | strncpy(ha->model_desc, |
| 1521 | qla2x00_model_name[index * 2 + 1], |
| 1522 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1523 | } else { |
| 1524 | strcpy(ha->model_number, def); |
| 1525 | } |
| 1526 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 1527 | if (IS_FWI2_CAPABLE(ha)) |
| 1528 | qla2xxx_get_vpd_field(ha, "\x82", ha->model_desc, |
| 1529 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1530 | } |
| 1531 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1532 | /* On sparc systems, obtain port and node WWN from firmware |
| 1533 | * properties. |
| 1534 | */ |
| 1535 | static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv) |
| 1536 | { |
| 1537 | #ifdef CONFIG_SPARC |
| 1538 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 1539 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 1540 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1541 | int len; |
| 1542 | |
| 1543 | val = of_get_property(dp, "port-wwn", &len); |
| 1544 | if (val && len >= WWN_SIZE) |
| 1545 | memcpy(nv->port_name, val, WWN_SIZE); |
| 1546 | |
| 1547 | val = of_get_property(dp, "node-wwn", &len); |
| 1548 | if (val && len >= WWN_SIZE) |
| 1549 | memcpy(nv->node_name, val, WWN_SIZE); |
| 1550 | #endif |
| 1551 | } |
| 1552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | /* |
| 1554 | * NVRAM configuration for ISP 2xxx |
| 1555 | * |
| 1556 | * Input: |
| 1557 | * ha = adapter block pointer. |
| 1558 | * |
| 1559 | * Output: |
| 1560 | * initialization control block in response_ring |
| 1561 | * host adapters parameters in host adapter block |
| 1562 | * |
| 1563 | * Returns: |
| 1564 | * 0 = success. |
| 1565 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1566 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | qla2x00_nvram_config(scsi_qla_host_t *ha) |
| 1568 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1569 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1570 | uint8_t chksum = 0; |
| 1571 | uint16_t cnt; |
| 1572 | uint8_t *dptr1, *dptr2; |
| 1573 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 1574 | nvram_t *nv = ha->nvram; |
| 1575 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1576 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1578 | rval = QLA_SUCCESS; |
| 1579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1581 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | ha->nvram_base = 0; |
| 1583 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 1584 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 1585 | ha->nvram_base = 0x80; |
| 1586 | |
| 1587 | /* Get NVRAM data and calculate checksum. */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1588 | ha->isp_ops->read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1589 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 1590 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | |
| 1592 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no)); |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 1593 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | |
| 1595 | /* Bad NVRAM data, set defaults parameters. */ |
| 1596 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 1597 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 1598 | /* Reset NVRAM data. */ |
| 1599 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 1600 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 1601 | nv->nvram_version); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1602 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 1603 | "invalid -- WWPN) defaults.\n"); |
| 1604 | |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1605 | if (chksum) |
| 1606 | qla2xxx_hw_event_log(ha, HW_EVENT_NVRAM_CHKSUM_ERR, 0, |
| 1607 | MSW(chksum), LSW(chksum)); |
| 1608 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1609 | /* |
| 1610 | * Set default initialization control block. |
| 1611 | */ |
| 1612 | memset(nv, 0, ha->nvram_size); |
| 1613 | nv->parameter_block_version = ICB_VERSION; |
| 1614 | |
| 1615 | if (IS_QLA23XX(ha)) { |
| 1616 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 1617 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 1618 | nv->add_firmware_options[0] = BIT_5; |
| 1619 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 1620 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 1621 | nv->special_options[1] = BIT_7; |
| 1622 | } else if (IS_QLA2200(ha)) { |
| 1623 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 1624 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 1625 | nv->add_firmware_options[0] = BIT_5; |
| 1626 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 1627 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 1628 | } else if (IS_QLA2100(ha)) { |
| 1629 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 1630 | nv->firmware_options[1] = BIT_5; |
| 1631 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 1632 | } |
| 1633 | |
| 1634 | nv->max_iocb_allocation = __constant_cpu_to_le16(256); |
| 1635 | nv->execution_throttle = __constant_cpu_to_le16(16); |
| 1636 | nv->retry_count = 8; |
| 1637 | nv->retry_delay = 1; |
| 1638 | |
| 1639 | nv->port_name[0] = 33; |
| 1640 | nv->port_name[3] = 224; |
| 1641 | nv->port_name[4] = 139; |
| 1642 | |
| 1643 | qla2xxx_nvram_wwn_from_ofw(ha, nv); |
| 1644 | |
| 1645 | nv->login_timeout = 4; |
| 1646 | |
| 1647 | /* |
| 1648 | * Set default host adapter parameters |
| 1649 | */ |
| 1650 | nv->host_p[1] = BIT_2; |
| 1651 | nv->reset_delay = 5; |
| 1652 | nv->port_down_retry_count = 8; |
| 1653 | nv->max_luns_per_target = __constant_cpu_to_le16(8); |
| 1654 | nv->link_down_timeout = 60; |
| 1655 | |
| 1656 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 1660 | /* |
| 1661 | * The SN2 does not provide BIOS emulation which means you can't change |
| 1662 | * potentially bogus BIOS settings. Force the use of default settings |
| 1663 | * for link rate and frame size. Hope that the rest of the settings |
| 1664 | * are valid. |
| 1665 | */ |
| 1666 | if (ia64_platform_is("sn2")) { |
| 1667 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 1668 | if (IS_QLA23XX(ha)) |
| 1669 | nv->special_options[1] = BIT_7; |
| 1670 | } |
| 1671 | #endif |
| 1672 | |
| 1673 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1674 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | |
| 1676 | /* |
| 1677 | * Setup driver NVRAM options. |
| 1678 | */ |
| 1679 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 1680 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 1681 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 1682 | nv->firmware_options[1] &= ~BIT_4; |
| 1683 | |
| 1684 | if (IS_QLA23XX(ha)) { |
| 1685 | nv->firmware_options[0] |= BIT_2; |
| 1686 | nv->firmware_options[0] &= ~BIT_3; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1687 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | |
| 1689 | if (IS_QLA2300(ha)) { |
| 1690 | if (ha->fb_rev == FPM_2310) { |
| 1691 | strcpy(ha->model_number, "QLA2310"); |
| 1692 | } else { |
| 1693 | strcpy(ha->model_number, "QLA2300"); |
| 1694 | } |
| 1695 | } else { |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1696 | qla2x00_set_model_info(ha, nv->model_number, |
| 1697 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | } |
| 1699 | } else if (IS_QLA2200(ha)) { |
| 1700 | nv->firmware_options[0] |= BIT_2; |
| 1701 | /* |
| 1702 | * 'Point-to-point preferred, else loop' is not a safe |
| 1703 | * connection mode setting. |
| 1704 | */ |
| 1705 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 1706 | (BIT_5 | BIT_4)) { |
| 1707 | /* Force 'loop preferred, else point-to-point'. */ |
| 1708 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 1709 | nv->add_firmware_options[0] |= BIT_5; |
| 1710 | } |
| 1711 | strcpy(ha->model_number, "QLA22xx"); |
| 1712 | } else /*if (IS_QLA2100(ha))*/ { |
| 1713 | strcpy(ha->model_number, "QLA2100"); |
| 1714 | } |
| 1715 | |
| 1716 | /* |
| 1717 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 1718 | */ |
| 1719 | dptr1 = (uint8_t *)icb; |
| 1720 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 1721 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 1722 | while (cnt--) |
| 1723 | *dptr1++ = *dptr2++; |
| 1724 | |
| 1725 | /* Copy 2nd half. */ |
| 1726 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 1727 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 1728 | while (cnt--) |
| 1729 | *dptr1++ = *dptr2++; |
| 1730 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 1731 | /* Use alternate WWN? */ |
| 1732 | if (nv->host_p[1] & BIT_7) { |
| 1733 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 1734 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 1735 | } |
| 1736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | /* Prepare nodename */ |
| 1738 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 1739 | /* |
| 1740 | * Firmware will apply the following mask if the nodename was |
| 1741 | * not provided. |
| 1742 | */ |
| 1743 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 1744 | icb->node_name[0] &= 0xF0; |
| 1745 | } |
| 1746 | |
| 1747 | /* |
| 1748 | * Set host adapter parameters. |
| 1749 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 1750 | if (nv->host_p[0] & BIT_7) |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 1751 | ql2xextended_error_logging = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 1753 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 1754 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 1755 | ha->flags.disable_risc_code_load = 0; |
| 1756 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 1757 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 1758 | ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0); |
Andrew Vasquez | 06c22bd | 2005-08-26 19:09:00 -0700 | [diff] [blame] | 1759 | ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1760 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | |
| 1762 | ha->operating_mode = |
| 1763 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1764 | |
| 1765 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 1766 | sizeof(ha->fw_seriallink_options)); |
| 1767 | |
| 1768 | /* save HBA serial number */ |
| 1769 | ha->serial0 = icb->port_name[5]; |
| 1770 | ha->serial1 = icb->port_name[6]; |
| 1771 | ha->serial2 = icb->port_name[7]; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1772 | ha->node_name = icb->node_name; |
| 1773 | ha->port_name = icb->port_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | |
| 1775 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 1776 | |
| 1777 | ha->retry_count = nv->retry_count; |
| 1778 | |
| 1779 | /* Set minimum login_timeout to 4 seconds. */ |
| 1780 | if (nv->login_timeout < ql2xlogintimeout) |
| 1781 | nv->login_timeout = ql2xlogintimeout; |
| 1782 | if (nv->login_timeout < 4) |
| 1783 | nv->login_timeout = 4; |
| 1784 | ha->login_timeout = nv->login_timeout; |
| 1785 | icb->login_timeout = nv->login_timeout; |
| 1786 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 1787 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 1788 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | ha->loop_reset_delay = nv->reset_delay; |
| 1791 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | /* Link Down Timeout = 0: |
| 1793 | * |
| 1794 | * When Port Down timer expires we will start returning |
| 1795 | * I/O's to OS with "DID_NO_CONNECT". |
| 1796 | * |
| 1797 | * Link Down Timeout != 0: |
| 1798 | * |
| 1799 | * The driver waits for the link to come up after link down |
| 1800 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1801 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | if (nv->link_down_timeout == 0) { |
| 1803 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 1804 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | } else { |
| 1806 | ha->link_down_timeout = nv->link_down_timeout; |
| 1807 | ha->loop_down_abort_time = |
| 1808 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1809 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | /* |
| 1812 | * Need enough time to try and get the port back. |
| 1813 | */ |
| 1814 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 1815 | if (qlport_down_retry) |
| 1816 | ha->port_down_retry_count = qlport_down_retry; |
| 1817 | /* Set login_retry_count */ |
| 1818 | ha->login_retry_count = nv->retry_count; |
| 1819 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 1820 | ha->port_down_retry_count > 3) |
| 1821 | ha->login_retry_count = ha->port_down_retry_count; |
| 1822 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 1823 | ha->login_retry_count = ha->port_down_retry_count; |
| 1824 | if (ql2xloginretrycount) |
| 1825 | ha->login_retry_count = ql2xloginretrycount; |
| 1826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | icb->lun_enables = __constant_cpu_to_le16(0); |
| 1828 | icb->command_resource_count = 0; |
| 1829 | icb->immediate_notify_resource_count = 0; |
| 1830 | icb->timeout = __constant_cpu_to_le16(0); |
| 1831 | |
| 1832 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 1833 | /* Enable RIO */ |
| 1834 | icb->firmware_options[0] &= ~BIT_3; |
| 1835 | icb->add_firmware_options[0] &= |
| 1836 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 1837 | icb->add_firmware_options[0] |= BIT_2; |
| 1838 | icb->response_accumulation_timer = 3; |
| 1839 | icb->interrupt_delay_timer = 5; |
| 1840 | |
| 1841 | ha->flags.process_response_queue = 1; |
| 1842 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1843 | /* Enable ZIO. */ |
| 1844 | if (!ha->flags.init_done) { |
| 1845 | ha->zio_mode = icb->add_firmware_options[0] & |
| 1846 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 1847 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 1848 | icb->interrupt_delay_timer: 2; |
| 1849 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | icb->add_firmware_options[0] &= |
| 1851 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1852 | ha->flags.process_response_queue = 0; |
| 1853 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1854 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 1855 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1856 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer " |
| 1857 | "delay (%d us).\n", ha->host_no, ha->zio_mode, |
| 1858 | ha->zio_timer * 100)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | qla_printk(KERN_INFO, ha, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1860 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 1861 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1863 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 1864 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | ha->flags.process_response_queue = 1; |
| 1866 | } |
| 1867 | } |
| 1868 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1869 | if (rval) { |
| 1870 | DEBUG2_3(printk(KERN_WARNING |
| 1871 | "scsi(%ld): NVRAM configuration failed!\n", ha->host_no)); |
| 1872 | } |
| 1873 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1876 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1877 | qla2x00_rport_del(void *data) |
| 1878 | { |
| 1879 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1880 | struct fc_rport *rport; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1881 | |
Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 1882 | spin_lock_irq(fcport->ha->host->host_lock); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1883 | rport = fcport->drport; |
| 1884 | fcport->drport = NULL; |
Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 1885 | spin_unlock_irq(fcport->ha->host->host_lock); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1886 | if (rport) |
| 1887 | fc_remote_port_delete(rport); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1888 | } |
| 1889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | /** |
| 1891 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 1892 | * @ha: HA context |
| 1893 | * @flags: allocation flags |
| 1894 | * |
| 1895 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 1896 | */ |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 1897 | static fc_port_t * |
Al Viro | c53033f | 2005-10-21 03:22:08 -0400 | [diff] [blame] | 1898 | qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | { |
| 1900 | fc_port_t *fcport; |
| 1901 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 1902 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 1903 | if (!fcport) |
| 1904 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | |
| 1906 | /* Setup fcport template structure. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | fcport->ha = ha; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1908 | fcport->vp_idx = ha->vp_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | fcport->port_type = FCT_UNKNOWN; |
| 1910 | fcport->loop_id = FC_NO_LOOP_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | atomic_set(&fcport->state, FCS_UNCONFIGURED); |
| 1912 | fcport->flags = FCF_RLC_SUPPORT; |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 1913 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 1915 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | /* |
| 1919 | * qla2x00_configure_loop |
| 1920 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 1921 | * |
| 1922 | * Input: |
| 1923 | * ha = adapter block pointer. |
| 1924 | * |
| 1925 | * Returns: |
| 1926 | * 0 = success. |
| 1927 | * 1 = error. |
| 1928 | * 2 = database was full and device was not configured. |
| 1929 | */ |
| 1930 | static int |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1931 | qla2x00_configure_loop(scsi_qla_host_t *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | { |
| 1933 | int rval; |
| 1934 | unsigned long flags, save_flags; |
| 1935 | |
| 1936 | rval = QLA_SUCCESS; |
| 1937 | |
| 1938 | /* Get Initiator ID */ |
| 1939 | if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) { |
| 1940 | rval = qla2x00_configure_hba(ha); |
| 1941 | if (rval != QLA_SUCCESS) { |
| 1942 | DEBUG(printk("scsi(%ld): Unable to configure HBA.\n", |
| 1943 | ha->host_no)); |
| 1944 | return (rval); |
| 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | save_flags = flags = ha->dpc_flags; |
| 1949 | DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n", |
| 1950 | ha->host_no, flags)); |
| 1951 | |
| 1952 | /* |
| 1953 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 1954 | * both at the same time. |
| 1955 | */ |
| 1956 | clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 1957 | clear_bit(RSCN_UPDATE, &ha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | |
| 1959 | /* Determine what we need to do */ |
| 1960 | if (ha->current_topology == ISP_CFG_FL && |
| 1961 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 1962 | |
| 1963 | ha->flags.rscn_queue_overflow = 1; |
| 1964 | set_bit(RSCN_UPDATE, &flags); |
| 1965 | |
| 1966 | } else if (ha->current_topology == ISP_CFG_F && |
| 1967 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 1968 | |
| 1969 | ha->flags.rscn_queue_overflow = 1; |
| 1970 | set_bit(RSCN_UPDATE, &flags); |
| 1971 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 1972 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 1973 | } else if (ha->current_topology == ISP_CFG_N) { |
| 1974 | clear_bit(RSCN_UPDATE, &flags); |
| 1975 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | } else if (!ha->flags.online || |
| 1977 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
| 1978 | |
| 1979 | ha->flags.rscn_queue_overflow = 1; |
| 1980 | set_bit(RSCN_UPDATE, &flags); |
| 1981 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 1982 | } |
| 1983 | |
| 1984 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
| 1985 | if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) { |
| 1986 | rval = QLA_FUNCTION_FAILED; |
| 1987 | } else { |
| 1988 | rval = qla2x00_configure_local_loop(ha); |
| 1989 | } |
| 1990 | } |
| 1991 | |
| 1992 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Andrew Vasquez | 23443b1 | 2005-12-06 10:57:06 -0800 | [diff] [blame] | 1993 | if (LOOP_TRANSITION(ha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | rval = QLA_FUNCTION_FAILED; |
| 1995 | } else { |
| 1996 | rval = qla2x00_configure_fabric(ha); |
| 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | if (rval == QLA_SUCCESS) { |
| 2001 | if (atomic_read(&ha->loop_down_timer) || |
| 2002 | test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) { |
| 2003 | rval = QLA_FUNCTION_FAILED; |
| 2004 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | atomic_set(&ha->loop_state, LOOP_READY); |
| 2006 | |
| 2007 | DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no)); |
| 2008 | } |
| 2009 | } |
| 2010 | |
| 2011 | if (rval) { |
| 2012 | DEBUG2_3(printk("%s(%ld): *** FAILED ***\n", |
| 2013 | __func__, ha->host_no)); |
| 2014 | } else { |
| 2015 | DEBUG3(printk("%s: exiting normally\n", __func__)); |
| 2016 | } |
| 2017 | |
| 2018 | /* Restore state if a resync event occured during processing */ |
| 2019 | if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) { |
| 2020 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
| 2021 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
Seokmann Ju | 5de1f70 | 2008-07-10 16:55:58 -0700 | [diff] [blame] | 2022 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
| 2023 | ha->flags.rscn_queue_overflow = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | set_bit(RSCN_UPDATE, &ha->dpc_flags); |
Seokmann Ju | 5de1f70 | 2008-07-10 16:55:58 -0700 | [diff] [blame] | 2025 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | return (rval); |
| 2029 | } |
| 2030 | |
| 2031 | |
| 2032 | |
| 2033 | /* |
| 2034 | * qla2x00_configure_local_loop |
| 2035 | * Updates Fibre Channel Device Database with local loop devices. |
| 2036 | * |
| 2037 | * Input: |
| 2038 | * ha = adapter block pointer. |
| 2039 | * |
| 2040 | * Returns: |
| 2041 | * 0 = success. |
| 2042 | */ |
| 2043 | static int |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2044 | qla2x00_configure_local_loop(scsi_qla_host_t *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | { |
| 2046 | int rval, rval2; |
| 2047 | int found_devs; |
| 2048 | int found; |
| 2049 | fc_port_t *fcport, *new_fcport; |
| 2050 | |
| 2051 | uint16_t index; |
| 2052 | uint16_t entries; |
| 2053 | char *id_iter; |
| 2054 | uint16_t loop_id; |
| 2055 | uint8_t domain, area, al_pa; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2056 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | |
| 2058 | found_devs = 0; |
| 2059 | new_fcport = NULL; |
| 2060 | entries = MAX_FIBRE_DEVICES; |
| 2061 | |
| 2062 | DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no)); |
| 2063 | DEBUG3(qla2x00_get_fcal_position_map(ha, NULL)); |
| 2064 | |
| 2065 | /* Get list of logged in devices. */ |
| 2066 | memset(ha->gid_list, 0, GID_LIST_SIZE); |
| 2067 | rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma, |
| 2068 | &entries); |
| 2069 | if (rval != QLA_SUCCESS) |
| 2070 | goto cleanup_allocation; |
| 2071 | |
| 2072 | DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n", |
| 2073 | ha->host_no, entries)); |
| 2074 | DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list, |
| 2075 | entries * sizeof(struct gid_list_info))); |
| 2076 | |
| 2077 | /* Allocate temporary fcport for any new fcports discovered. */ |
| 2078 | new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL); |
| 2079 | if (new_fcport == NULL) { |
| 2080 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2081 | goto cleanup_allocation; |
| 2082 | } |
| 2083 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2084 | |
| 2085 | /* |
| 2086 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 2087 | */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2088 | list_for_each_entry(fcport, &pha->fcports, list) { |
| 2089 | if (fcport->vp_idx != ha->vp_idx) |
| 2090 | continue; |
| 2091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 2093 | fcport->port_type != FCT_BROADCAST && |
| 2094 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 2095 | |
| 2096 | DEBUG(printk("scsi(%ld): Marking port lost, " |
| 2097 | "loop_id=0x%04x\n", |
| 2098 | ha->host_no, fcport->loop_id)); |
| 2099 | |
| 2100 | atomic_set(&fcport->state, FCS_DEVICE_LOST); |
| 2101 | fcport->flags &= ~FCF_FARP_DONE; |
| 2102 | } |
| 2103 | } |
| 2104 | |
| 2105 | /* Add devices to port list. */ |
| 2106 | id_iter = (char *)ha->gid_list; |
| 2107 | for (index = 0; index < entries; index++) { |
| 2108 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 2109 | area = ((struct gid_list_info *)id_iter)->area; |
| 2110 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2111 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | loop_id = (uint16_t) |
| 2113 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2114 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | loop_id = le16_to_cpu( |
| 2116 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2117 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | |
| 2119 | /* Bypass reserved domain fields. */ |
| 2120 | if ((domain & 0xf0) == 0xf0) |
| 2121 | continue; |
| 2122 | |
| 2123 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2124 | if (area && domain && |
| 2125 | (area != ha->d_id.b.area || domain != ha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | continue; |
| 2127 | |
| 2128 | /* Bypass invalid local loop ID. */ |
| 2129 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 2130 | continue; |
| 2131 | |
| 2132 | /* Fill in member data. */ |
| 2133 | new_fcport->d_id.b.domain = domain; |
| 2134 | new_fcport->d_id.b.area = area; |
| 2135 | new_fcport->d_id.b.al_pa = al_pa; |
| 2136 | new_fcport->loop_id = loop_id; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2137 | new_fcport->vp_idx = ha->vp_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | rval2 = qla2x00_get_port_database(ha, new_fcport, 0); |
| 2139 | if (rval2 != QLA_SUCCESS) { |
| 2140 | DEBUG2(printk("scsi(%ld): Failed to retrieve fcport " |
| 2141 | "information -- get_port_database=%x, " |
| 2142 | "loop_id=0x%04x\n", |
| 2143 | ha->host_no, rval2, new_fcport->loop_id)); |
andrew.vasquez@qlogic.com | c9d02ac | 2006-01-13 17:05:26 -0800 | [diff] [blame] | 2144 | DEBUG2(printk("scsi(%ld): Scheduling resync...\n", |
| 2145 | ha->host_no)); |
| 2146 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | continue; |
| 2148 | } |
| 2149 | |
| 2150 | /* Check for matching device in port list. */ |
| 2151 | found = 0; |
| 2152 | fcport = NULL; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2153 | list_for_each_entry(fcport, &pha->fcports, list) { |
| 2154 | if (fcport->vp_idx != ha->vp_idx) |
| 2155 | continue; |
| 2156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 2158 | WWN_SIZE)) |
| 2159 | continue; |
| 2160 | |
| 2161 | fcport->flags &= ~(FCF_FABRIC_DEVICE | |
| 2162 | FCF_PERSISTENT_BOUND); |
| 2163 | fcport->loop_id = new_fcport->loop_id; |
| 2164 | fcport->port_type = new_fcport->port_type; |
| 2165 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2166 | memcpy(fcport->node_name, new_fcport->node_name, |
| 2167 | WWN_SIZE); |
| 2168 | |
| 2169 | found++; |
| 2170 | break; |
| 2171 | } |
| 2172 | |
| 2173 | if (!found) { |
| 2174 | /* New device, add to fcports list. */ |
| 2175 | new_fcport->flags &= ~FCF_PERSISTENT_BOUND; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2176 | if (ha->parent) { |
| 2177 | new_fcport->ha = ha; |
| 2178 | new_fcport->vp_idx = ha->vp_idx; |
| 2179 | list_add_tail(&new_fcport->vp_fcport, |
| 2180 | &ha->vp_fcports); |
| 2181 | } |
| 2182 | list_add_tail(&new_fcport->list, &pha->fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | |
| 2184 | /* Allocate a new replacement fcport. */ |
| 2185 | fcport = new_fcport; |
| 2186 | new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL); |
| 2187 | if (new_fcport == NULL) { |
| 2188 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2189 | goto cleanup_allocation; |
| 2190 | } |
| 2191 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2192 | } |
| 2193 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2194 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2195 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | qla2x00_update_fcport(ha, fcport); |
| 2198 | |
| 2199 | found_devs++; |
| 2200 | } |
| 2201 | |
| 2202 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2203 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | |
| 2205 | if (rval != QLA_SUCCESS) { |
| 2206 | DEBUG2(printk("scsi(%ld): Configure local loop error exit: " |
| 2207 | "rval=%x\n", ha->host_no, rval)); |
| 2208 | } |
| 2209 | |
| 2210 | if (found_devs) { |
| 2211 | ha->device_flags |= DFLG_LOCAL_DEVICES; |
| 2212 | ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES; |
| 2213 | } |
| 2214 | |
| 2215 | return (rval); |
| 2216 | } |
| 2217 | |
| 2218 | static void |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2219 | qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport) |
| 2220 | { |
| 2221 | #define LS_UNKNOWN 2 |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2222 | static char *link_speeds[5] = { "1", "2", "?", "4", "8" }; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2223 | int rval; |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2224 | uint16_t mb[6]; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2225 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 2226 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2227 | return; |
| 2228 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 2229 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 2230 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2231 | return; |
| 2232 | |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2233 | rval = qla2x00_set_idma_speed(ha, fcport->loop_id, fcport->fp_speed, |
| 2234 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2235 | if (rval != QLA_SUCCESS) { |
| 2236 | DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA " |
| 2237 | "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n", |
| 2238 | ha->host_no, fcport->port_name[0], fcport->port_name[1], |
| 2239 | fcport->port_name[2], fcport->port_name[3], |
| 2240 | fcport->port_name[4], fcport->port_name[5], |
| 2241 | fcport->port_name[6], fcport->port_name[7], rval, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2242 | fcport->fp_speed, mb[0], mb[1])); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2243 | } else { |
| 2244 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 2245 | "iIDMA adjusted to %s GB/s on " |
| 2246 | "%02x%02x%02x%02x%02x%02x%02x%02x.\n", |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2247 | link_speeds[fcport->fp_speed], fcport->port_name[0], |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2248 | fcport->port_name[1], fcport->port_name[2], |
| 2249 | fcport->port_name[3], fcport->port_name[4], |
| 2250 | fcport->port_name[5], fcport->port_name[6], |
| 2251 | fcport->port_name[7])); |
| 2252 | } |
| 2253 | } |
| 2254 | |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2255 | static void |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2256 | qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport) |
| 2257 | { |
| 2258 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2259 | struct fc_rport *rport; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2260 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2261 | if (fcport->drport) |
| 2262 | qla2x00_rport_del(fcport); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2263 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 2264 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 2265 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2266 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 2267 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 2268 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 2269 | fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2270 | if (!rport) { |
| 2271 | qla_printk(KERN_WARNING, ha, |
| 2272 | "Unable to allocate fc remote port!\n"); |
| 2273 | return; |
| 2274 | } |
Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 2275 | spin_lock_irq(fcport->ha->host->host_lock); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2276 | *((fc_port_t **)rport->dd_data) = fcport; |
Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 2277 | spin_unlock_irq(fcport->ha->host->host_lock); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2278 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2279 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2280 | |
| 2281 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2282 | if (fcport->port_type == FCT_INITIATOR) |
| 2283 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 2284 | if (fcport->port_type == FCT_TARGET) |
| 2285 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2286 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2287 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | |
| 2289 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2290 | * qla2x00_update_fcport |
| 2291 | * Updates device on list. |
| 2292 | * |
| 2293 | * Input: |
| 2294 | * ha = adapter block pointer. |
| 2295 | * fcport = port structure pointer. |
| 2296 | * |
| 2297 | * Return: |
| 2298 | * 0 - Success |
| 2299 | * BIT_0 - error |
| 2300 | * |
| 2301 | * Context: |
| 2302 | * Kernel context. |
| 2303 | */ |
| 2304 | void |
| 2305 | qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport) |
| 2306 | { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2307 | scsi_qla_host_t *pha = to_qla_parent(ha); |
| 2308 | |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2309 | fcport->ha = ha; |
| 2310 | fcport->login_retry = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2311 | fcport->port_login_retry_count = pha->port_down_retry_count * |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2312 | PORT_RETRY_TIME; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2313 | atomic_set(&fcport->port_down_timer, pha->port_down_retry_count * |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2314 | PORT_RETRY_TIME); |
| 2315 | fcport->flags &= ~FCF_LOGIN_NEEDED; |
| 2316 | |
| 2317 | qla2x00_iidma_fcport(ha, fcport); |
| 2318 | |
| 2319 | atomic_set(&fcport->state, FCS_ONLINE); |
| 2320 | |
| 2321 | qla2x00_reg_remote_port(ha, fcport); |
| 2322 | } |
| 2323 | |
| 2324 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | * qla2x00_configure_fabric |
| 2326 | * Setup SNS devices with loop ID's. |
| 2327 | * |
| 2328 | * Input: |
| 2329 | * ha = adapter block pointer. |
| 2330 | * |
| 2331 | * Returns: |
| 2332 | * 0 = success. |
| 2333 | * BIT_0 = error |
| 2334 | */ |
| 2335 | static int |
| 2336 | qla2x00_configure_fabric(scsi_qla_host_t *ha) |
| 2337 | { |
| 2338 | int rval, rval2; |
| 2339 | fc_port_t *fcport, *fcptemp; |
| 2340 | uint16_t next_loopid; |
| 2341 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2342 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | LIST_HEAD(new_fcports); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2344 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | |
| 2346 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2347 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2348 | loop_id = NPH_F_PORT; |
| 2349 | else |
| 2350 | loop_id = SNS_FL_PORT; |
Andrew Vasquez | 90991c8 | 2006-10-02 12:00:46 -0700 | [diff] [blame] | 2351 | rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | if (rval != QLA_SUCCESS) { |
| 2353 | DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL " |
| 2354 | "Port\n", ha->host_no)); |
| 2355 | |
| 2356 | ha->device_flags &= ~SWITCH_FOUND; |
| 2357 | return (QLA_SUCCESS); |
| 2358 | } |
Andrew Vasquez | 90991c8 | 2006-10-02 12:00:46 -0700 | [diff] [blame] | 2359 | ha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | |
| 2361 | /* Mark devices that need re-synchronization. */ |
| 2362 | rval2 = qla2x00_device_resync(ha); |
| 2363 | if (rval2 == QLA_RSCNS_HANDLED) { |
| 2364 | /* No point doing the scan, just continue. */ |
| 2365 | return (QLA_SUCCESS); |
| 2366 | } |
| 2367 | do { |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 2368 | /* FDMI support. */ |
| 2369 | if (ql2xfdmienable && |
| 2370 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags)) |
| 2371 | qla2x00_fdmi_register(ha); |
| 2372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2374 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2375 | loop_id = NPH_SNS; |
| 2376 | else |
| 2377 | loop_id = SIMPLE_NAME_SERVER; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2378 | ha->isp_ops->fabric_login(ha, loop_id, 0xff, 0xff, |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2379 | 0xfc, mb, BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
| 2381 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 2382 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2383 | "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | mb[0], mb[1], mb[2], mb[6], mb[7])); |
| 2385 | return (QLA_SUCCESS); |
| 2386 | } |
| 2387 | |
| 2388 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) { |
| 2389 | if (qla2x00_rft_id(ha)) { |
| 2390 | /* EMPTY */ |
| 2391 | DEBUG2(printk("scsi(%ld): Register FC-4 " |
| 2392 | "TYPE failed.\n", ha->host_no)); |
| 2393 | } |
| 2394 | if (qla2x00_rff_id(ha)) { |
| 2395 | /* EMPTY */ |
| 2396 | DEBUG2(printk("scsi(%ld): Register FC-4 " |
| 2397 | "Features failed.\n", ha->host_no)); |
| 2398 | } |
| 2399 | if (qla2x00_rnn_id(ha)) { |
| 2400 | /* EMPTY */ |
| 2401 | DEBUG2(printk("scsi(%ld): Register Node Name " |
| 2402 | "failed.\n", ha->host_no)); |
| 2403 | } else if (qla2x00_rsnn_nn(ha)) { |
| 2404 | /* EMPTY */ |
| 2405 | DEBUG2(printk("scsi(%ld): Register Symbolic " |
| 2406 | "Node Name failed.\n", ha->host_no)); |
| 2407 | } |
| 2408 | } |
| 2409 | |
| 2410 | rval = qla2x00_find_all_fabric_devs(ha, &new_fcports); |
| 2411 | if (rval != QLA_SUCCESS) |
| 2412 | break; |
| 2413 | |
| 2414 | /* |
| 2415 | * Logout all previous fabric devices marked lost, except |
| 2416 | * tape devices. |
| 2417 | */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2418 | list_for_each_entry(fcport, &pha->fcports, list) { |
| 2419 | if (fcport->vp_idx !=ha->vp_idx) |
| 2420 | continue; |
| 2421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) |
| 2423 | break; |
| 2424 | |
| 2425 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) |
| 2426 | continue; |
| 2427 | |
| 2428 | if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) { |
| 2429 | qla2x00_mark_device_lost(ha, fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2430 | ql2xplogiabsentdevice, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 2432 | (fcport->flags & FCF_TAPE_PRESENT) == 0 && |
| 2433 | fcport->port_type != FCT_INITIATOR && |
| 2434 | fcport->port_type != FCT_BROADCAST) { |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2435 | ha->isp_ops->fabric_logout(ha, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2436 | fcport->loop_id, |
| 2437 | fcport->d_id.b.domain, |
| 2438 | fcport->d_id.b.area, |
| 2439 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | fcport->loop_id = FC_NO_LOOP_ID; |
| 2441 | } |
| 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | /* Starting free loop ID. */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2446 | next_loopid = pha->min_external_loopid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | |
| 2448 | /* |
| 2449 | * Scan through our port list and login entries that need to be |
| 2450 | * logged in. |
| 2451 | */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2452 | list_for_each_entry(fcport, &pha->fcports, list) { |
| 2453 | if (fcport->vp_idx != ha->vp_idx) |
| 2454 | continue; |
| 2455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | if (atomic_read(&ha->loop_down_timer) || |
| 2457 | test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) |
| 2458 | break; |
| 2459 | |
| 2460 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 2461 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 2462 | continue; |
| 2463 | |
| 2464 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 2465 | fcport->loop_id = next_loopid; |
Seokmann Ju | d4486fd6 | 2008-04-03 13:13:28 -0700 | [diff] [blame] | 2466 | rval = qla2x00_find_new_loop_id( |
| 2467 | to_qla_parent(ha), fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | if (rval != QLA_SUCCESS) { |
| 2469 | /* Ran out of IDs to use */ |
| 2470 | break; |
| 2471 | } |
| 2472 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | /* Login and update database */ |
| 2474 | qla2x00_fabric_dev_login(ha, fcport, &next_loopid); |
| 2475 | } |
| 2476 | |
| 2477 | /* Exit if out of loop IDs. */ |
| 2478 | if (rval != QLA_SUCCESS) { |
| 2479 | break; |
| 2480 | } |
| 2481 | |
| 2482 | /* |
| 2483 | * Login and add the new devices to our port list. |
| 2484 | */ |
| 2485 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
| 2486 | if (atomic_read(&ha->loop_down_timer) || |
| 2487 | test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) |
| 2488 | break; |
| 2489 | |
| 2490 | /* Find a new loop ID to use. */ |
| 2491 | fcport->loop_id = next_loopid; |
Seokmann Ju | d4486fd6 | 2008-04-03 13:13:28 -0700 | [diff] [blame] | 2492 | rval = qla2x00_find_new_loop_id(to_qla_parent(ha), |
| 2493 | fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | if (rval != QLA_SUCCESS) { |
| 2495 | /* Ran out of IDs to use */ |
| 2496 | break; |
| 2497 | } |
| 2498 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2499 | /* Login and update database */ |
| 2500 | qla2x00_fabric_dev_login(ha, fcport, &next_loopid); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2501 | |
| 2502 | if (ha->parent) { |
| 2503 | fcport->ha = ha; |
| 2504 | fcport->vp_idx = ha->vp_idx; |
| 2505 | list_add_tail(&fcport->vp_fcport, |
| 2506 | &ha->vp_fcports); |
| 2507 | list_move_tail(&fcport->list, |
| 2508 | &ha->parent->fcports); |
| 2509 | } else |
| 2510 | list_move_tail(&fcport->list, &ha->fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | } |
| 2512 | } while (0); |
| 2513 | |
| 2514 | /* Free all new device structures not processed. */ |
| 2515 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
| 2516 | list_del(&fcport->list); |
| 2517 | kfree(fcport); |
| 2518 | } |
| 2519 | |
| 2520 | if (rval) { |
| 2521 | DEBUG2(printk("scsi(%ld): Configure fabric error exit: " |
| 2522 | "rval=%d\n", ha->host_no, rval)); |
| 2523 | } |
| 2524 | |
| 2525 | return (rval); |
| 2526 | } |
| 2527 | |
| 2528 | |
| 2529 | /* |
| 2530 | * qla2x00_find_all_fabric_devs |
| 2531 | * |
| 2532 | * Input: |
| 2533 | * ha = adapter block pointer. |
| 2534 | * dev = database device entry pointer. |
| 2535 | * |
| 2536 | * Returns: |
| 2537 | * 0 = success. |
| 2538 | * |
| 2539 | * Context: |
| 2540 | * Kernel context. |
| 2541 | */ |
| 2542 | static int |
| 2543 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports) |
| 2544 | { |
| 2545 | int rval; |
| 2546 | uint16_t loop_id; |
| 2547 | fc_port_t *fcport, *new_fcport, *fcptemp; |
| 2548 | int found; |
| 2549 | |
| 2550 | sw_info_t *swl; |
| 2551 | int swl_idx; |
| 2552 | int first_dev, last_dev; |
| 2553 | port_id_t wrap, nxt_d_id; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2554 | int vp_index; |
| 2555 | int empty_vp_index; |
| 2556 | int found_vp; |
| 2557 | scsi_qla_host_t *vha; |
| 2558 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | |
| 2560 | rval = QLA_SUCCESS; |
| 2561 | |
| 2562 | /* Try GID_PT to get device list, else GAN. */ |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2563 | swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_ATOMIC); |
| 2564 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | /*EMPTY*/ |
| 2566 | DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback " |
| 2567 | "on GA_NXT\n", ha->host_no)); |
| 2568 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) { |
| 2570 | kfree(swl); |
| 2571 | swl = NULL; |
| 2572 | } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) { |
| 2573 | kfree(swl); |
| 2574 | swl = NULL; |
| 2575 | } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) { |
| 2576 | kfree(swl); |
| 2577 | swl = NULL; |
Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 2578 | } else if (ql2xiidmaenable && |
| 2579 | qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2580 | qla2x00_gpsc(ha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | } |
| 2582 | } |
| 2583 | swl_idx = 0; |
| 2584 | |
| 2585 | /* Allocate temporary fcport for any new fcports discovered. */ |
| 2586 | new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL); |
| 2587 | if (new_fcport == NULL) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2588 | kfree(swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | return (QLA_MEMORY_ALLOC_FAILED); |
| 2590 | } |
| 2591 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2592 | new_fcport->vp_idx = ha->vp_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | /* Set start port ID scan at adapter ID. */ |
| 2594 | first_dev = 1; |
| 2595 | last_dev = 0; |
| 2596 | |
| 2597 | /* Starting free loop ID. */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2598 | loop_id = pha->min_external_loopid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | for (; loop_id <= ha->last_loop_id; loop_id++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2600 | if (qla2x00_is_reserved_id(ha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | continue; |
| 2602 | |
Andrew Vasquez | 23443b1 | 2005-12-06 10:57:06 -0800 | [diff] [blame] | 2603 | if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | break; |
| 2605 | |
| 2606 | if (swl != NULL) { |
| 2607 | if (last_dev) { |
| 2608 | wrap.b24 = new_fcport->d_id.b24; |
| 2609 | } else { |
| 2610 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 2611 | memcpy(new_fcport->node_name, |
| 2612 | swl[swl_idx].node_name, WWN_SIZE); |
| 2613 | memcpy(new_fcport->port_name, |
| 2614 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2615 | memcpy(new_fcport->fabric_port_name, |
| 2616 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 2617 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | |
| 2619 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 2620 | last_dev = 1; |
| 2621 | } |
| 2622 | swl_idx++; |
| 2623 | } |
| 2624 | } else { |
| 2625 | /* Send GA_NXT to the switch */ |
| 2626 | rval = qla2x00_ga_nxt(ha, new_fcport); |
| 2627 | if (rval != QLA_SUCCESS) { |
| 2628 | qla_printk(KERN_WARNING, ha, |
| 2629 | "SNS scan failed -- assuming zero-entry " |
| 2630 | "result...\n"); |
| 2631 | list_for_each_entry_safe(fcport, fcptemp, |
| 2632 | new_fcports, list) { |
| 2633 | list_del(&fcport->list); |
| 2634 | kfree(fcport); |
| 2635 | } |
| 2636 | rval = QLA_SUCCESS; |
| 2637 | break; |
| 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | /* If wrap on switch device list, exit. */ |
| 2642 | if (first_dev) { |
| 2643 | wrap.b24 = new_fcport->d_id.b24; |
| 2644 | first_dev = 0; |
| 2645 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
| 2646 | DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n", |
| 2647 | ha->host_no, new_fcport->d_id.b.domain, |
| 2648 | new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa)); |
| 2649 | break; |
| 2650 | } |
| 2651 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2652 | /* Bypass if same physical adapter. */ |
| 2653 | if (new_fcport->d_id.b24 == pha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | continue; |
| 2655 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2656 | /* Bypass virtual ports of the same host. */ |
| 2657 | if (pha->num_vhosts) { |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 2658 | for_each_mapped_vp_idx(pha, vp_index) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2659 | empty_vp_index = 1; |
| 2660 | found_vp = 0; |
| 2661 | list_for_each_entry(vha, &pha->vp_list, |
| 2662 | vp_list) { |
| 2663 | if (vp_index == vha->vp_idx) { |
| 2664 | empty_vp_index = 0; |
| 2665 | found_vp = 1; |
| 2666 | break; |
| 2667 | } |
| 2668 | } |
| 2669 | |
| 2670 | if (empty_vp_index) |
| 2671 | continue; |
| 2672 | |
| 2673 | if (found_vp && |
| 2674 | new_fcport->d_id.b24 == vha->d_id.b24) |
| 2675 | break; |
| 2676 | } |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 2677 | |
| 2678 | if (vp_index <= pha->max_npiv_vports) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2679 | continue; |
| 2680 | } |
| 2681 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2682 | /* Bypass if same domain and area of adapter. */ |
| 2683 | if (((new_fcport->d_id.b24 & 0xffff00) == |
| 2684 | (ha->d_id.b24 & 0xffff00)) && ha->current_topology == |
| 2685 | ISP_CFG_FL) |
| 2686 | continue; |
| 2687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | /* Bypass reserved domain fields. */ |
| 2689 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 2690 | continue; |
| 2691 | |
| 2692 | /* Locate matching device in database. */ |
| 2693 | found = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2694 | list_for_each_entry(fcport, &pha->fcports, list) { |
| 2695 | if (new_fcport->vp_idx != fcport->vp_idx) |
| 2696 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 2698 | WWN_SIZE)) |
| 2699 | continue; |
| 2700 | |
| 2701 | found++; |
| 2702 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2703 | /* Update port state. */ |
| 2704 | memcpy(fcport->fabric_port_name, |
| 2705 | new_fcport->fabric_port_name, WWN_SIZE); |
| 2706 | fcport->fp_speed = new_fcport->fp_speed; |
| 2707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | /* |
| 2709 | * If address the same and state FCS_ONLINE, nothing |
| 2710 | * changed. |
| 2711 | */ |
| 2712 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
| 2713 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 2714 | break; |
| 2715 | } |
| 2716 | |
| 2717 | /* |
| 2718 | * If device was not a fabric device before. |
| 2719 | */ |
| 2720 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 2721 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2722 | fcport->loop_id = FC_NO_LOOP_ID; |
| 2723 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 2724 | FCF_LOGIN_NEEDED); |
| 2725 | fcport->flags &= ~FCF_PERSISTENT_BOUND; |
| 2726 | break; |
| 2727 | } |
| 2728 | |
| 2729 | /* |
| 2730 | * Port ID changed or device was marked to be updated; |
| 2731 | * Log it out if still logged in and mark it for |
| 2732 | * relogin later. |
| 2733 | */ |
| 2734 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2735 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 2736 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 2737 | (fcport->flags & FCF_TAPE_PRESENT) == 0 && |
| 2738 | fcport->port_type != FCT_INITIATOR && |
| 2739 | fcport->port_type != FCT_BROADCAST) { |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2740 | ha->isp_ops->fabric_logout(ha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2741 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 2742 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | fcport->loop_id = FC_NO_LOOP_ID; |
| 2744 | } |
| 2745 | |
| 2746 | break; |
| 2747 | } |
| 2748 | |
| 2749 | if (found) |
| 2750 | continue; |
| 2751 | |
| 2752 | /* If device was not in our fcports list, then add it. */ |
| 2753 | list_add_tail(&new_fcport->list, new_fcports); |
| 2754 | |
| 2755 | /* Allocate a new replacement fcport. */ |
| 2756 | nxt_d_id.b24 = new_fcport->d_id.b24; |
| 2757 | new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL); |
| 2758 | if (new_fcport == NULL) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2759 | kfree(swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | return (QLA_MEMORY_ALLOC_FAILED); |
| 2761 | } |
| 2762 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 2763 | new_fcport->d_id.b24 = nxt_d_id.b24; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2764 | new_fcport->vp_idx = ha->vp_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | } |
| 2766 | |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2767 | kfree(swl); |
| 2768 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | |
| 2770 | if (!list_empty(new_fcports)) |
| 2771 | ha->device_flags |= DFLG_FABRIC_DEVICES; |
| 2772 | |
| 2773 | return (rval); |
| 2774 | } |
| 2775 | |
| 2776 | /* |
| 2777 | * qla2x00_find_new_loop_id |
| 2778 | * Scan through our port list and find a new usable loop ID. |
| 2779 | * |
| 2780 | * Input: |
| 2781 | * ha: adapter state pointer. |
| 2782 | * dev: port structure pointer. |
| 2783 | * |
| 2784 | * Returns: |
| 2785 | * qla2x00 local function return status code. |
| 2786 | * |
| 2787 | * Context: |
| 2788 | * Kernel context. |
| 2789 | */ |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 2790 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev) |
| 2792 | { |
| 2793 | int rval; |
| 2794 | int found; |
| 2795 | fc_port_t *fcport; |
| 2796 | uint16_t first_loop_id; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2797 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | |
| 2799 | rval = QLA_SUCCESS; |
| 2800 | |
| 2801 | /* Save starting loop ID. */ |
| 2802 | first_loop_id = dev->loop_id; |
| 2803 | |
| 2804 | for (;;) { |
| 2805 | /* Skip loop ID if already used by adapter. */ |
| 2806 | if (dev->loop_id == ha->loop_id) { |
| 2807 | dev->loop_id++; |
| 2808 | } |
| 2809 | |
| 2810 | /* Skip reserved loop IDs. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2811 | while (qla2x00_is_reserved_id(ha, dev->loop_id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | dev->loop_id++; |
| 2813 | } |
| 2814 | |
| 2815 | /* Reset loop ID if passed the end. */ |
| 2816 | if (dev->loop_id > ha->last_loop_id) { |
| 2817 | /* first loop ID. */ |
| 2818 | dev->loop_id = ha->min_external_loopid; |
| 2819 | } |
| 2820 | |
| 2821 | /* Check for loop ID being already in use. */ |
| 2822 | found = 0; |
| 2823 | fcport = NULL; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2824 | list_for_each_entry(fcport, &pha->fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | if (fcport->loop_id == dev->loop_id && fcport != dev) { |
| 2826 | /* ID possibly in use */ |
| 2827 | found++; |
| 2828 | break; |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | /* If not in use then it is free to use. */ |
| 2833 | if (!found) { |
| 2834 | break; |
| 2835 | } |
| 2836 | |
| 2837 | /* ID in use. Try next value. */ |
| 2838 | dev->loop_id++; |
| 2839 | |
| 2840 | /* If wrap around. No free ID to use. */ |
| 2841 | if (dev->loop_id == first_loop_id) { |
| 2842 | dev->loop_id = FC_NO_LOOP_ID; |
| 2843 | rval = QLA_FUNCTION_FAILED; |
| 2844 | break; |
| 2845 | } |
| 2846 | } |
| 2847 | |
| 2848 | return (rval); |
| 2849 | } |
| 2850 | |
| 2851 | /* |
| 2852 | * qla2x00_device_resync |
| 2853 | * Marks devices in the database that needs resynchronization. |
| 2854 | * |
| 2855 | * Input: |
| 2856 | * ha = adapter block pointer. |
| 2857 | * |
| 2858 | * Context: |
| 2859 | * Kernel context. |
| 2860 | */ |
| 2861 | static int |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2862 | qla2x00_device_resync(scsi_qla_host_t *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | { |
| 2864 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | uint32_t mask; |
| 2866 | fc_port_t *fcport; |
| 2867 | uint32_t rscn_entry; |
| 2868 | uint8_t rscn_out_iter; |
| 2869 | uint8_t format; |
| 2870 | port_id_t d_id; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2871 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | |
| 2873 | rval = QLA_RSCNS_HANDLED; |
| 2874 | |
| 2875 | while (ha->rscn_out_ptr != ha->rscn_in_ptr || |
| 2876 | ha->flags.rscn_queue_overflow) { |
| 2877 | |
| 2878 | rscn_entry = ha->rscn_queue[ha->rscn_out_ptr]; |
| 2879 | format = MSB(MSW(rscn_entry)); |
| 2880 | d_id.b.domain = LSB(MSW(rscn_entry)); |
| 2881 | d_id.b.area = MSB(LSW(rscn_entry)); |
| 2882 | d_id.b.al_pa = LSB(LSW(rscn_entry)); |
| 2883 | |
| 2884 | DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = " |
| 2885 | "[%02x/%02x%02x%02x].\n", |
| 2886 | ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain, |
| 2887 | d_id.b.area, d_id.b.al_pa)); |
| 2888 | |
| 2889 | ha->rscn_out_ptr++; |
| 2890 | if (ha->rscn_out_ptr == MAX_RSCN_COUNT) |
| 2891 | ha->rscn_out_ptr = 0; |
| 2892 | |
| 2893 | /* Skip duplicate entries. */ |
| 2894 | for (rscn_out_iter = ha->rscn_out_ptr; |
| 2895 | !ha->flags.rscn_queue_overflow && |
| 2896 | rscn_out_iter != ha->rscn_in_ptr; |
| 2897 | rscn_out_iter = (rscn_out_iter == |
| 2898 | (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) { |
| 2899 | |
| 2900 | if (rscn_entry != ha->rscn_queue[rscn_out_iter]) |
| 2901 | break; |
| 2902 | |
| 2903 | DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue " |
| 2904 | "entry found at [%d].\n", ha->host_no, |
| 2905 | rscn_out_iter)); |
| 2906 | |
| 2907 | ha->rscn_out_ptr = rscn_out_iter; |
| 2908 | } |
| 2909 | |
| 2910 | /* Queue overflow, set switch default case. */ |
| 2911 | if (ha->flags.rscn_queue_overflow) { |
| 2912 | DEBUG(printk("scsi(%ld): device_resync: rscn " |
| 2913 | "overflow.\n", ha->host_no)); |
| 2914 | |
| 2915 | format = 3; |
| 2916 | ha->flags.rscn_queue_overflow = 0; |
| 2917 | } |
| 2918 | |
| 2919 | switch (format) { |
| 2920 | case 0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | mask = 0xffffff; |
| 2922 | break; |
| 2923 | case 1: |
| 2924 | mask = 0xffff00; |
| 2925 | break; |
| 2926 | case 2: |
| 2927 | mask = 0xff0000; |
| 2928 | break; |
| 2929 | default: |
| 2930 | mask = 0x0; |
| 2931 | d_id.b24 = 0; |
| 2932 | ha->rscn_out_ptr = ha->rscn_in_ptr; |
| 2933 | break; |
| 2934 | } |
| 2935 | |
| 2936 | rval = QLA_SUCCESS; |
| 2937 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2938 | list_for_each_entry(fcport, &pha->fcports, list) { |
| 2939 | if (fcport->vp_idx != ha->vp_idx) |
| 2940 | continue; |
| 2941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 2943 | (fcport->d_id.b24 & mask) != d_id.b24 || |
| 2944 | fcport->port_type == FCT_BROADCAST) |
| 2945 | continue; |
| 2946 | |
| 2947 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
| 2948 | if (format != 3 || |
| 2949 | fcport->port_type != FCT_INITIATOR) { |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2950 | qla2x00_mark_device_lost(ha, fcport, |
| 2951 | 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | } |
| 2953 | } |
| 2954 | fcport->flags &= ~FCF_FARP_DONE; |
| 2955 | } |
| 2956 | } |
| 2957 | return (rval); |
| 2958 | } |
| 2959 | |
| 2960 | /* |
| 2961 | * qla2x00_fabric_dev_login |
| 2962 | * Login fabric target device and update FC port database. |
| 2963 | * |
| 2964 | * Input: |
| 2965 | * ha: adapter state pointer. |
| 2966 | * fcport: port structure list pointer. |
| 2967 | * next_loopid: contains value of a new loop ID that can be used |
| 2968 | * by the next login attempt. |
| 2969 | * |
| 2970 | * Returns: |
| 2971 | * qla2x00 local function return status code. |
| 2972 | * |
| 2973 | * Context: |
| 2974 | * Kernel context. |
| 2975 | */ |
| 2976 | static int |
| 2977 | qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport, |
| 2978 | uint16_t *next_loopid) |
| 2979 | { |
| 2980 | int rval; |
| 2981 | int retry; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2982 | uint8_t opts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | |
| 2984 | rval = QLA_SUCCESS; |
| 2985 | retry = 0; |
| 2986 | |
| 2987 | rval = qla2x00_fabric_login(ha, fcport, next_loopid); |
| 2988 | if (rval == QLA_SUCCESS) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2989 | /* Send an ADISC to tape devices.*/ |
| 2990 | opts = 0; |
| 2991 | if (fcport->flags & FCF_TAPE_PRESENT) |
| 2992 | opts |= BIT_1; |
| 2993 | rval = qla2x00_get_port_database(ha, fcport, opts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2995 | ha->isp_ops->fabric_logout(ha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2996 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 2997 | fcport->d_id.b.al_pa); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2998 | qla2x00_mark_device_lost(ha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | } else { |
| 3000 | qla2x00_update_fcport(ha, fcport); |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | return (rval); |
| 3005 | } |
| 3006 | |
| 3007 | /* |
| 3008 | * qla2x00_fabric_login |
| 3009 | * Issue fabric login command. |
| 3010 | * |
| 3011 | * Input: |
| 3012 | * ha = adapter block pointer. |
| 3013 | * device = pointer to FC device type structure. |
| 3014 | * |
| 3015 | * Returns: |
| 3016 | * 0 - Login successfully |
| 3017 | * 1 - Login failed |
| 3018 | * 2 - Initiator device |
| 3019 | * 3 - Fatal error |
| 3020 | */ |
| 3021 | int |
| 3022 | qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport, |
| 3023 | uint16_t *next_loopid) |
| 3024 | { |
| 3025 | int rval; |
| 3026 | int retry; |
| 3027 | uint16_t tmp_loopid; |
| 3028 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 3029 | |
| 3030 | retry = 0; |
| 3031 | tmp_loopid = 0; |
| 3032 | |
| 3033 | for (;;) { |
| 3034 | DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x " |
| 3035 | "for port %02x%02x%02x.\n", |
| 3036 | ha->host_no, fcport->loop_id, fcport->d_id.b.domain, |
| 3037 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 3038 | |
| 3039 | /* Login fcport on switch. */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3040 | ha->isp_ops->fabric_login(ha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3042 | fcport->d_id.b.al_pa, mb, BIT_0); |
| 3043 | if (mb[0] == MBS_PORT_ID_USED) { |
| 3044 | /* |
| 3045 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3046 | * recommends the driver perform an implicit login with |
| 3047 | * the specified ID again. The ID we just used is save |
| 3048 | * here so we return with an ID that can be tried by |
| 3049 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | */ |
| 3051 | retry++; |
| 3052 | tmp_loopid = fcport->loop_id; |
| 3053 | fcport->loop_id = mb[1]; |
| 3054 | |
| 3055 | DEBUG(printk("Fabric Login: port in use - next " |
| 3056 | "loop id=0x%04x, port Id=%02x%02x%02x.\n", |
| 3057 | fcport->loop_id, fcport->d_id.b.domain, |
| 3058 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 3059 | |
| 3060 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 3061 | /* |
| 3062 | * Login succeeded. |
| 3063 | */ |
| 3064 | if (retry) { |
| 3065 | /* A retry occurred before. */ |
| 3066 | *next_loopid = tmp_loopid; |
| 3067 | } else { |
| 3068 | /* |
| 3069 | * No retry occurred before. Just increment the |
| 3070 | * ID value for next login. |
| 3071 | */ |
| 3072 | *next_loopid = (fcport->loop_id + 1); |
| 3073 | } |
| 3074 | |
| 3075 | if (mb[1] & BIT_0) { |
| 3076 | fcport->port_type = FCT_INITIATOR; |
| 3077 | } else { |
| 3078 | fcport->port_type = FCT_TARGET; |
| 3079 | if (mb[1] & BIT_1) { |
| 3080 | fcport->flags |= FCF_TAPE_PRESENT; |
| 3081 | } |
| 3082 | } |
| 3083 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3084 | if (mb[10] & BIT_0) |
| 3085 | fcport->supported_classes |= FC_COS_CLASS2; |
| 3086 | if (mb[10] & BIT_1) |
| 3087 | fcport->supported_classes |= FC_COS_CLASS3; |
| 3088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | rval = QLA_SUCCESS; |
| 3090 | break; |
| 3091 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 3092 | /* |
| 3093 | * Loop ID already used, try next loop ID. |
| 3094 | */ |
| 3095 | fcport->loop_id++; |
| 3096 | rval = qla2x00_find_new_loop_id(ha, fcport); |
| 3097 | if (rval != QLA_SUCCESS) { |
| 3098 | /* Ran out of loop IDs to use */ |
| 3099 | break; |
| 3100 | } |
| 3101 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 3102 | /* |
| 3103 | * Firmware possibly timed out during login. If NO |
| 3104 | * retries are left to do then the device is declared |
| 3105 | * dead. |
| 3106 | */ |
| 3107 | *next_loopid = fcport->loop_id; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3108 | ha->isp_ops->fabric_logout(ha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3109 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3110 | fcport->d_id.b.al_pa); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3111 | qla2x00_mark_device_lost(ha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | |
| 3113 | rval = 1; |
| 3114 | break; |
| 3115 | } else { |
| 3116 | /* |
| 3117 | * unrecoverable / not handled error |
| 3118 | */ |
| 3119 | DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x " |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3120 | "loop_id=%x jiffies=%lx.\n", |
| 3121 | __func__, ha->host_no, mb[0], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3123 | fcport->d_id.b.al_pa, fcport->loop_id, jiffies)); |
| 3124 | |
| 3125 | *next_loopid = fcport->loop_id; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3126 | ha->isp_ops->fabric_logout(ha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3127 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3128 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | fcport->loop_id = FC_NO_LOOP_ID; |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 3130 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | |
| 3132 | rval = 3; |
| 3133 | break; |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | return (rval); |
| 3138 | } |
| 3139 | |
| 3140 | /* |
| 3141 | * qla2x00_local_device_login |
| 3142 | * Issue local device login command. |
| 3143 | * |
| 3144 | * Input: |
| 3145 | * ha = adapter block pointer. |
| 3146 | * loop_id = loop id of device to login to. |
| 3147 | * |
| 3148 | * Returns (Where's the #define!!!!): |
| 3149 | * 0 - Login successfully |
| 3150 | * 1 - Login failed |
| 3151 | * 3 - Fatal error |
| 3152 | */ |
| 3153 | int |
andrew.vasquez@qlogic.com | 9a52a57 | 2006-03-09 14:27:44 -0800 | [diff] [blame] | 3154 | qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | { |
| 3156 | int rval; |
| 3157 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 3158 | |
| 3159 | memset(mb, 0, sizeof(mb)); |
andrew.vasquez@qlogic.com | 9a52a57 | 2006-03-09 14:27:44 -0800 | [diff] [blame] | 3160 | rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | if (rval == QLA_SUCCESS) { |
| 3162 | /* Interrogate mailbox registers for any errors */ |
| 3163 | if (mb[0] == MBS_COMMAND_ERROR) |
| 3164 | rval = 1; |
| 3165 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 3166 | /* device not in PCB table */ |
| 3167 | rval = 3; |
| 3168 | } |
| 3169 | |
| 3170 | return (rval); |
| 3171 | } |
| 3172 | |
| 3173 | /* |
| 3174 | * qla2x00_loop_resync |
| 3175 | * Resync with fibre channel devices. |
| 3176 | * |
| 3177 | * Input: |
| 3178 | * ha = adapter block pointer. |
| 3179 | * |
| 3180 | * Returns: |
| 3181 | * 0 = success |
| 3182 | */ |
| 3183 | int |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3184 | qla2x00_loop_resync(scsi_qla_host_t *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | { |
| 3186 | int rval; |
| 3187 | uint32_t wait_time; |
| 3188 | |
| 3189 | rval = QLA_SUCCESS; |
| 3190 | |
| 3191 | atomic_set(&ha->loop_state, LOOP_UPDATE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags); |
| 3193 | if (ha->flags.online) { |
| 3194 | if (!(rval = qla2x00_fw_ready(ha))) { |
| 3195 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 3196 | wait_time = 256; |
| 3197 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | atomic_set(&ha->loop_state, LOOP_UPDATE); |
| 3199 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3200 | /* Issue a marker after FW becomes ready. */ |
| 3201 | qla2x00_marker(ha, 0, 0, MK_SYNC_ALL); |
| 3202 | ha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | |
| 3204 | /* Remap devices on Loop. */ |
| 3205 | clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 3206 | |
| 3207 | qla2x00_configure_loop(ha); |
| 3208 | wait_time--; |
| 3209 | } while (!atomic_read(&ha->loop_down_timer) && |
| 3210 | !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) && |
| 3211 | wait_time && |
| 3212 | (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))); |
| 3213 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) { |
| 3217 | return (QLA_FUNCTION_FAILED); |
| 3218 | } |
| 3219 | |
| 3220 | if (rval) { |
| 3221 | DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__)); |
| 3222 | } |
| 3223 | |
| 3224 | return (rval); |
| 3225 | } |
| 3226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | void |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3228 | qla2x00_update_fcports(scsi_qla_host_t *ha) |
| 3229 | { |
| 3230 | fc_port_t *fcport; |
| 3231 | |
| 3232 | /* Go with deferred removal of rport references. */ |
| 3233 | list_for_each_entry(fcport, &ha->fcports, list) |
| 3234 | if (fcport->drport) |
| 3235 | qla2x00_rport_del(fcport); |
| 3236 | } |
| 3237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | /* |
| 3239 | * qla2x00_abort_isp |
| 3240 | * Resets ISP and aborts all outstanding commands. |
| 3241 | * |
| 3242 | * Input: |
| 3243 | * ha = adapter block pointer. |
| 3244 | * |
| 3245 | * Returns: |
| 3246 | * 0 = success |
| 3247 | */ |
| 3248 | int |
| 3249 | qla2x00_abort_isp(scsi_qla_host_t *ha) |
| 3250 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 3251 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | uint8_t status = 0; |
| 3253 | |
| 3254 | if (ha->flags.online) { |
| 3255 | ha->flags.online = 0; |
| 3256 | clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
Harish Zunjarrao | e5f5f6f | 2008-07-10 16:55:49 -0700 | [diff] [blame] | 3257 | ha->qla_stats.total_isp_aborts++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | |
| 3259 | qla_printk(KERN_INFO, ha, |
| 3260 | "Performing ISP error recovery - ha= %p.\n", ha); |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3261 | ha->isp_ops->reset_chip(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | |
| 3263 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 3264 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { |
| 3265 | atomic_set(&ha->loop_state, LOOP_DOWN); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3266 | qla2x00_mark_all_devices_lost(ha, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | } else { |
| 3268 | if (!atomic_read(&ha->loop_down_timer)) |
| 3269 | atomic_set(&ha->loop_down_timer, |
| 3270 | LOOP_DOWN_TIME); |
| 3271 | } |
| 3272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | /* Requeue all commands in outstanding command list. */ |
Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 3274 | qla2x00_abort_all_cmds(ha, DID_RESET << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3276 | ha->isp_ops->get_flash_version(ha, ha->request_ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 3277 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3278 | ha->isp_ops->nvram_config(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | |
| 3280 | if (!qla2x00_restart_isp(ha)) { |
| 3281 | clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
| 3282 | |
| 3283 | if (!atomic_read(&ha->loop_down_timer)) { |
| 3284 | /* |
| 3285 | * Issue marker command only when we are going |
| 3286 | * to start the I/O . |
| 3287 | */ |
| 3288 | ha->marker_needed = 1; |
| 3289 | } |
| 3290 | |
| 3291 | ha->flags.online = 1; |
| 3292 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3293 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3295 | ha->isp_abort_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 3297 | |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 3298 | if (ha->fce) { |
| 3299 | ha->flags.fce_enabled = 1; |
| 3300 | memset(ha->fce, 0, |
| 3301 | fce_calc_size(ha->fce_bufs)); |
| 3302 | rval = qla2x00_enable_fce_trace(ha, |
| 3303 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 3304 | &ha->fce_bufs); |
| 3305 | if (rval) { |
| 3306 | qla_printk(KERN_WARNING, ha, |
| 3307 | "Unable to reinitialize FCE " |
| 3308 | "(%d).\n", rval); |
| 3309 | ha->flags.fce_enabled = 0; |
| 3310 | } |
| 3311 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 3312 | |
| 3313 | if (ha->eft) { |
| 3314 | memset(ha->eft, 0, EFT_SIZE); |
| 3315 | rval = qla2x00_enable_eft_trace(ha, |
| 3316 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 3317 | if (rval) { |
| 3318 | qla_printk(KERN_WARNING, ha, |
| 3319 | "Unable to reinitialize EFT " |
| 3320 | "(%d).\n", rval); |
| 3321 | } |
| 3322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | } else { /* failed the ISP abort */ |
| 3324 | ha->flags.online = 1; |
| 3325 | if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) { |
| 3326 | if (ha->isp_abort_cnt == 0) { |
| 3327 | qla_printk(KERN_WARNING, ha, |
| 3328 | "ISP error recovery failed - " |
| 3329 | "board disabled\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3330 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | * The next call disables the board |
| 3332 | * completely. |
| 3333 | */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3334 | ha->isp_ops->reset_adapter(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | ha->flags.online = 0; |
| 3336 | clear_bit(ISP_ABORT_RETRY, |
| 3337 | &ha->dpc_flags); |
| 3338 | status = 0; |
| 3339 | } else { /* schedule another ISP abort */ |
| 3340 | ha->isp_abort_cnt--; |
| 3341 | DEBUG(printk("qla%ld: ISP abort - " |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3342 | "retry remaining %d\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 3343 | ha->host_no, ha->isp_abort_cnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | status = 1; |
| 3345 | } |
| 3346 | } else { |
| 3347 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
| 3348 | DEBUG(printk("qla2x00(%ld): ISP error recovery " |
| 3349 | "- retrying (%d) more times\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 3350 | ha->host_no, ha->isp_abort_cnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | set_bit(ISP_ABORT_RETRY, &ha->dpc_flags); |
| 3352 | status = 1; |
| 3353 | } |
| 3354 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | if (status) { |
| 3359 | qla_printk(KERN_INFO, ha, |
| 3360 | "qla2x00_abort_isp: **** FAILED ****\n"); |
| 3361 | } else { |
| 3362 | DEBUG(printk(KERN_INFO |
| 3363 | "qla2x00_abort_isp(%ld): exiting.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 3364 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | return(status); |
| 3368 | } |
| 3369 | |
| 3370 | /* |
| 3371 | * qla2x00_restart_isp |
| 3372 | * restarts the ISP after a reset |
| 3373 | * |
| 3374 | * Input: |
| 3375 | * ha = adapter block pointer. |
| 3376 | * |
| 3377 | * Returns: |
| 3378 | * 0 = success |
| 3379 | */ |
| 3380 | static int |
| 3381 | qla2x00_restart_isp(scsi_qla_host_t *ha) |
| 3382 | { |
| 3383 | uint8_t status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | uint32_t wait_time; |
| 3385 | |
| 3386 | /* If firmware needs to be loaded */ |
| 3387 | if (qla2x00_isp_firmware(ha)) { |
| 3388 | ha->flags.online = 0; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3389 | if (!(status = ha->isp_ops->chip_diag(ha))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | status = qla2x00_setup_chip(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | } |
| 3392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | if (!status && !(status = qla2x00_init_rings(ha))) { |
| 3394 | clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
| 3395 | if (!(status = qla2x00_fw_ready(ha))) { |
| 3396 | DEBUG(printk("%s(): Start configure loop, " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 3397 | "status = %d\n", __func__, status)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3398 | |
| 3399 | /* Issue a marker after FW becomes ready. */ |
| 3400 | qla2x00_marker(ha, 0, 0, MK_SYNC_ALL); |
| 3401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | ha->flags.online = 1; |
| 3403 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 3404 | wait_time = 256; |
| 3405 | do { |
| 3406 | clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 3407 | qla2x00_configure_loop(ha); |
| 3408 | wait_time--; |
| 3409 | } while (!atomic_read(&ha->loop_down_timer) && |
| 3410 | !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) && |
| 3411 | wait_time && |
| 3412 | (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))); |
| 3413 | } |
| 3414 | |
| 3415 | /* if no cable then assume it's good */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3416 | if ((ha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | status = 0; |
| 3418 | |
| 3419 | DEBUG(printk("%s(): Configure loop done, status = 0x%x\n", |
| 3420 | __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 3421 | status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | } |
| 3423 | return (status); |
| 3424 | } |
| 3425 | |
| 3426 | /* |
| 3427 | * qla2x00_reset_adapter |
| 3428 | * Reset adapter. |
| 3429 | * |
| 3430 | * Input: |
| 3431 | * ha = adapter block pointer. |
| 3432 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3433 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | qla2x00_reset_adapter(scsi_qla_host_t *ha) |
| 3435 | { |
| 3436 | unsigned long flags = 0; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3437 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | |
| 3439 | ha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3440 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3443 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 3444 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 3445 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 3446 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 3447 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3448 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3449 | |
| 3450 | void |
| 3451 | qla24xx_reset_adapter(scsi_qla_host_t *ha) |
| 3452 | { |
| 3453 | unsigned long flags = 0; |
| 3454 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 3455 | |
| 3456 | ha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3457 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3458 | |
| 3459 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3460 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 3461 | RD_REG_DWORD(®->hccr); |
| 3462 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 3463 | RD_REG_DWORD(®->hccr); |
| 3464 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3465 | } |
| 3466 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3467 | /* On sparc systems, obtain port and node WWN from firmware |
| 3468 | * properties. |
| 3469 | */ |
| 3470 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv) |
| 3471 | { |
| 3472 | #ifdef CONFIG_SPARC |
| 3473 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 3474 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 3475 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3476 | int len; |
| 3477 | |
| 3478 | val = of_get_property(dp, "port-wwn", &len); |
| 3479 | if (val && len >= WWN_SIZE) |
| 3480 | memcpy(nv->port_name, val, WWN_SIZE); |
| 3481 | |
| 3482 | val = of_get_property(dp, "node-wwn", &len); |
| 3483 | if (val && len >= WWN_SIZE) |
| 3484 | memcpy(nv->node_name, val, WWN_SIZE); |
| 3485 | #endif |
| 3486 | } |
| 3487 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3488 | int |
| 3489 | qla24xx_nvram_config(scsi_qla_host_t *ha) |
| 3490 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3491 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3492 | struct init_cb_24xx *icb; |
| 3493 | struct nvram_24xx *nv; |
| 3494 | uint32_t *dptr; |
| 3495 | uint8_t *dptr1, *dptr2; |
| 3496 | uint32_t chksum; |
| 3497 | uint16_t cnt; |
| 3498 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3499 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3500 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3501 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3502 | |
| 3503 | /* Determine NVRAM starting address. */ |
| 3504 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 3505 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 3506 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
| 3507 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 3508 | if (PCI_FUNC(ha->pdev->devfn)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3509 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 3510 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 3511 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3512 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3513 | /* Get VPD data into cache */ |
| 3514 | ha->vpd = ha->nvram + VPD_OFFSET; |
| 3515 | ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, |
| 3516 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 3517 | |
| 3518 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3519 | dptr = (uint32_t *)nv; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3520 | ha->isp_ops->read_nvram(ha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3521 | ha->nvram_size); |
| 3522 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 3523 | chksum += le32_to_cpu(*dptr++); |
| 3524 | |
| 3525 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no)); |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3526 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3527 | |
| 3528 | /* Bad NVRAM data, set defaults parameters. */ |
| 3529 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 3530 | || nv->id[3] != ' ' || |
| 3531 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 3532 | /* Reset NVRAM data. */ |
| 3533 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 3534 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 3535 | le16_to_cpu(nv->nvram_version)); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3536 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 3537 | "invalid -- WWPN) defaults.\n"); |
| 3538 | |
| 3539 | /* |
| 3540 | * Set default initialization control block. |
| 3541 | */ |
| 3542 | memset(nv, 0, ha->nvram_size); |
| 3543 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 3544 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 3545 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 3546 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 3547 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 3548 | nv->hard_address = __constant_cpu_to_le16(124); |
| 3549 | nv->port_name[0] = 0x21; |
| 3550 | nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn); |
| 3551 | nv->port_name[2] = 0x00; |
| 3552 | nv->port_name[3] = 0xe0; |
| 3553 | nv->port_name[4] = 0x8b; |
| 3554 | nv->port_name[5] = 0x1c; |
| 3555 | nv->port_name[6] = 0x55; |
| 3556 | nv->port_name[7] = 0x86; |
| 3557 | nv->node_name[0] = 0x20; |
| 3558 | nv->node_name[1] = 0x00; |
| 3559 | nv->node_name[2] = 0x00; |
| 3560 | nv->node_name[3] = 0xe0; |
| 3561 | nv->node_name[4] = 0x8b; |
| 3562 | nv->node_name[5] = 0x1c; |
| 3563 | nv->node_name[6] = 0x55; |
| 3564 | nv->node_name[7] = 0x86; |
| 3565 | qla24xx_nvram_wwn_from_ofw(ha, nv); |
| 3566 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 3567 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 3568 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 3569 | nv->firmware_options_1 = |
| 3570 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 3571 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 3572 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 3573 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 3574 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 3575 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 3576 | nv->reset_delay = 5; |
| 3577 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 3578 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
| 3579 | nv->link_down_timeout = __constant_cpu_to_le16(30); |
| 3580 | |
| 3581 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | /* Reset Initialization control block */ |
| 3585 | memset(icb, 0, sizeof(struct init_cb_24xx)); |
| 3586 | |
| 3587 | /* Copy 1st segment. */ |
| 3588 | dptr1 = (uint8_t *)icb; |
| 3589 | dptr2 = (uint8_t *)&nv->version; |
| 3590 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 3591 | while (cnt--) |
| 3592 | *dptr1++ = *dptr2++; |
| 3593 | |
| 3594 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 3595 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3596 | |
| 3597 | /* Copy 2nd segment. */ |
| 3598 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 3599 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 3600 | cnt = (uint8_t *)&icb->reserved_3 - |
| 3601 | (uint8_t *)&icb->interrupt_delay_timer; |
| 3602 | while (cnt--) |
| 3603 | *dptr1++ = *dptr2++; |
| 3604 | |
| 3605 | /* |
| 3606 | * Setup driver NVRAM options. |
| 3607 | */ |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3608 | qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name), |
| 3609 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3610 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 3611 | /* Use alternate WWN? */ |
| 3612 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
| 3613 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 3614 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 3615 | } |
| 3616 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3617 | /* Prepare nodename */ |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 3618 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3619 | /* |
| 3620 | * Firmware will apply the following mask if the nodename was |
| 3621 | * not provided. |
| 3622 | */ |
| 3623 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 3624 | icb->node_name[0] &= 0xF0; |
| 3625 | } |
| 3626 | |
| 3627 | /* Set host adapter parameters. */ |
| 3628 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 3629 | ha->flags.enable_lip_reset = 0; |
| 3630 | ha->flags.enable_lip_full_login = |
| 3631 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 3632 | ha->flags.enable_target_reset = |
| 3633 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3634 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 3635 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3636 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 3637 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 3638 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3639 | |
| 3640 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 3641 | sizeof(ha->fw_seriallink_options24)); |
| 3642 | |
| 3643 | /* save HBA serial number */ |
| 3644 | ha->serial0 = icb->port_name[5]; |
| 3645 | ha->serial1 = icb->port_name[6]; |
| 3646 | ha->serial2 = icb->port_name[7]; |
| 3647 | ha->node_name = icb->node_name; |
| 3648 | ha->port_name = icb->port_name; |
| 3649 | |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 3650 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 3651 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3652 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 3653 | |
| 3654 | /* Set minimum login_timeout to 4 seconds. */ |
| 3655 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 3656 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 3657 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 3658 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 3659 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Seokmann Ju | c6852c4 | 2008-04-24 15:21:29 -0700 | [diff] [blame] | 3660 | icb->login_timeout = nv->login_timeout; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3661 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 3662 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 3663 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3664 | |
| 3665 | ha->loop_reset_delay = nv->reset_delay; |
| 3666 | |
| 3667 | /* Link Down Timeout = 0: |
| 3668 | * |
| 3669 | * When Port Down timer expires we will start returning |
| 3670 | * I/O's to OS with "DID_NO_CONNECT". |
| 3671 | * |
| 3672 | * Link Down Timeout != 0: |
| 3673 | * |
| 3674 | * The driver waits for the link to come up after link down |
| 3675 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 3676 | */ |
| 3677 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 3678 | ha->loop_down_abort_time = |
| 3679 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 3680 | } else { |
| 3681 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 3682 | ha->loop_down_abort_time = |
| 3683 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 3684 | } |
| 3685 | |
| 3686 | /* Need enough time to try and get the port back. */ |
| 3687 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 3688 | if (qlport_down_retry) |
| 3689 | ha->port_down_retry_count = qlport_down_retry; |
| 3690 | |
| 3691 | /* Set login_retry_count */ |
| 3692 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 3693 | if (ha->port_down_retry_count == |
| 3694 | le16_to_cpu(nv->port_down_retry_count) && |
| 3695 | ha->port_down_retry_count > 3) |
| 3696 | ha->login_retry_count = ha->port_down_retry_count; |
| 3697 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 3698 | ha->login_retry_count = ha->port_down_retry_count; |
| 3699 | if (ql2xloginretrycount) |
| 3700 | ha->login_retry_count = ql2xloginretrycount; |
| 3701 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3702 | /* Enable ZIO. */ |
| 3703 | if (!ha->flags.init_done) { |
| 3704 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 3705 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 3706 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 3707 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 3708 | } |
| 3709 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 3710 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 3711 | ha->flags.process_response_queue = 0; |
| 3712 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 3713 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 3714 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3715 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay " |
| 3716 | "(%d us).\n", ha->host_no, ha->zio_mode, |
| 3717 | ha->zio_timer * 100)); |
| 3718 | qla_printk(KERN_INFO, ha, |
| 3719 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 3720 | ha->zio_mode, ha->zio_timer * 100); |
| 3721 | |
| 3722 | icb->firmware_options_2 |= cpu_to_le32( |
| 3723 | (uint32_t)ha->zio_mode); |
| 3724 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 3725 | ha->flags.process_response_queue = 1; |
| 3726 | } |
| 3727 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3728 | if (rval) { |
| 3729 | DEBUG2_3(printk(KERN_WARNING |
| 3730 | "scsi(%ld): NVRAM configuration failed!\n", ha->host_no)); |
| 3731 | } |
| 3732 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3733 | } |
| 3734 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 3735 | static int |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3736 | qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr) |
| 3737 | { |
| 3738 | int rval; |
| 3739 | int segments, fragment; |
| 3740 | uint32_t faddr; |
| 3741 | uint32_t *dcode, dlen; |
| 3742 | uint32_t risc_addr; |
| 3743 | uint32_t risc_size; |
| 3744 | uint32_t i; |
| 3745 | |
| 3746 | rval = QLA_SUCCESS; |
| 3747 | |
| 3748 | segments = FA_RISC_CODE_SEGMENTS; |
| 3749 | faddr = FA_RISC_CODE_ADDR; |
| 3750 | dcode = (uint32_t *)ha->request_ring; |
| 3751 | *srisc_addr = 0; |
| 3752 | |
| 3753 | /* Validate firmware image by checking version. */ |
| 3754 | qla24xx_read_flash_data(ha, dcode, faddr + 4, 4); |
| 3755 | for (i = 0; i < 4; i++) |
| 3756 | dcode[i] = be32_to_cpu(dcode[i]); |
| 3757 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 3758 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 3759 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 3760 | dcode[3] == 0)) { |
| 3761 | qla_printk(KERN_WARNING, ha, |
| 3762 | "Unable to verify integrity of flash firmware image!\n"); |
| 3763 | qla_printk(KERN_WARNING, ha, |
| 3764 | "Firmware data: %08x %08x %08x %08x!\n", dcode[0], |
| 3765 | dcode[1], dcode[2], dcode[3]); |
| 3766 | |
| 3767 | return QLA_FUNCTION_FAILED; |
| 3768 | } |
| 3769 | |
| 3770 | while (segments && rval == QLA_SUCCESS) { |
| 3771 | /* Read segment's load information. */ |
| 3772 | qla24xx_read_flash_data(ha, dcode, faddr, 4); |
| 3773 | |
| 3774 | risc_addr = be32_to_cpu(dcode[2]); |
| 3775 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 3776 | risc_size = be32_to_cpu(dcode[3]); |
| 3777 | |
| 3778 | fragment = 0; |
| 3779 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 3780 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 3781 | if (dlen > risc_size) |
| 3782 | dlen = risc_size; |
| 3783 | |
| 3784 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
| 3785 | "addr %x, number of dwords 0x%x, offset 0x%x.\n", |
| 3786 | ha->host_no, risc_addr, dlen, faddr)); |
| 3787 | |
| 3788 | qla24xx_read_flash_data(ha, dcode, faddr, dlen); |
| 3789 | for (i = 0; i < dlen; i++) |
| 3790 | dcode[i] = swab32(dcode[i]); |
| 3791 | |
| 3792 | rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr, |
| 3793 | dlen); |
| 3794 | if (rval) { |
| 3795 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
| 3796 | "segment %d of firmware\n", ha->host_no, |
| 3797 | fragment)); |
| 3798 | qla_printk(KERN_WARNING, ha, |
| 3799 | "[ERROR] Failed to load segment %d of " |
| 3800 | "firmware\n", fragment); |
| 3801 | break; |
| 3802 | } |
| 3803 | |
| 3804 | faddr += dlen; |
| 3805 | risc_addr += dlen; |
| 3806 | risc_size -= dlen; |
| 3807 | fragment++; |
| 3808 | } |
| 3809 | |
| 3810 | /* Next segment. */ |
| 3811 | segments--; |
| 3812 | } |
| 3813 | |
| 3814 | return rval; |
| 3815 | } |
| 3816 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3817 | #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/" |
| 3818 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3819 | int |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3820 | qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr) |
| 3821 | { |
| 3822 | int rval; |
| 3823 | int i, fragment; |
| 3824 | uint16_t *wcode, *fwcode; |
| 3825 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 3826 | struct fw_blob *blob; |
| 3827 | |
| 3828 | /* Load firmware blob. */ |
| 3829 | blob = qla2x00_request_firmware(ha); |
| 3830 | if (!blob) { |
| 3831 | qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3832 | qla_printk(KERN_ERR, ha, "Firmware images can be retrieved " |
| 3833 | "from: " QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3834 | return QLA_FUNCTION_FAILED; |
| 3835 | } |
| 3836 | |
| 3837 | rval = QLA_SUCCESS; |
| 3838 | |
| 3839 | wcode = (uint16_t *)ha->request_ring; |
| 3840 | *srisc_addr = 0; |
| 3841 | fwcode = (uint16_t *)blob->fw->data; |
| 3842 | fwclen = 0; |
| 3843 | |
| 3844 | /* Validate firmware image by checking version. */ |
| 3845 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
| 3846 | qla_printk(KERN_WARNING, ha, |
| 3847 | "Unable to verify integrity of firmware image (%Zd)!\n", |
| 3848 | blob->fw->size); |
| 3849 | goto fail_fw_integrity; |
| 3850 | } |
| 3851 | for (i = 0; i < 4; i++) |
| 3852 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 3853 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 3854 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 3855 | wcode[2] == 0 && wcode[3] == 0)) { |
| 3856 | qla_printk(KERN_WARNING, ha, |
| 3857 | "Unable to verify integrity of firmware image!\n"); |
| 3858 | qla_printk(KERN_WARNING, ha, |
| 3859 | "Firmware data: %04x %04x %04x %04x!\n", wcode[0], |
| 3860 | wcode[1], wcode[2], wcode[3]); |
| 3861 | goto fail_fw_integrity; |
| 3862 | } |
| 3863 | |
| 3864 | seg = blob->segs; |
| 3865 | while (*seg && rval == QLA_SUCCESS) { |
| 3866 | risc_addr = *seg; |
| 3867 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 3868 | risc_size = be16_to_cpu(fwcode[3]); |
| 3869 | |
| 3870 | /* Validate firmware image size. */ |
| 3871 | fwclen += risc_size * sizeof(uint16_t); |
| 3872 | if (blob->fw->size < fwclen) { |
| 3873 | qla_printk(KERN_WARNING, ha, |
| 3874 | "Unable to verify integrity of firmware image " |
| 3875 | "(%Zd)!\n", blob->fw->size); |
| 3876 | goto fail_fw_integrity; |
| 3877 | } |
| 3878 | |
| 3879 | fragment = 0; |
| 3880 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 3881 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 3882 | if (wlen > risc_size) |
| 3883 | wlen = risc_size; |
| 3884 | |
| 3885 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
| 3886 | "addr %x, number of words 0x%x.\n", ha->host_no, |
| 3887 | risc_addr, wlen)); |
| 3888 | |
| 3889 | for (i = 0; i < wlen; i++) |
| 3890 | wcode[i] = swab16(fwcode[i]); |
| 3891 | |
| 3892 | rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr, |
| 3893 | wlen); |
| 3894 | if (rval) { |
| 3895 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
| 3896 | "segment %d of firmware\n", ha->host_no, |
| 3897 | fragment)); |
| 3898 | qla_printk(KERN_WARNING, ha, |
| 3899 | "[ERROR] Failed to load segment %d of " |
| 3900 | "firmware\n", fragment); |
| 3901 | break; |
| 3902 | } |
| 3903 | |
| 3904 | fwcode += wlen; |
| 3905 | risc_addr += wlen; |
| 3906 | risc_size -= wlen; |
| 3907 | fragment++; |
| 3908 | } |
| 3909 | |
| 3910 | /* Next segment. */ |
| 3911 | seg++; |
| 3912 | } |
| 3913 | return rval; |
| 3914 | |
| 3915 | fail_fw_integrity: |
| 3916 | return QLA_FUNCTION_FAILED; |
| 3917 | } |
| 3918 | |
| 3919 | int |
| 3920 | qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3921 | { |
| 3922 | int rval; |
| 3923 | int segments, fragment; |
| 3924 | uint32_t *dcode, dlen; |
| 3925 | uint32_t risc_addr; |
| 3926 | uint32_t risc_size; |
| 3927 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3928 | struct fw_blob *blob; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3929 | uint32_t *fwcode, fwclen; |
| 3930 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3931 | /* Load firmware blob. */ |
| 3932 | blob = qla2x00_request_firmware(ha); |
| 3933 | if (!blob) { |
| 3934 | qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3935 | qla_printk(KERN_ERR, ha, "Firmware images can be retrieved " |
| 3936 | "from: " QLA_FW_URL ".\n"); |
| 3937 | |
| 3938 | /* Try to load RISC code from flash. */ |
| 3939 | qla_printk(KERN_ERR, ha, "Attempting to load (potentially " |
| 3940 | "outdated) firmware from flash.\n"); |
| 3941 | return qla24xx_load_risc_flash(ha, srisc_addr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | rval = QLA_SUCCESS; |
| 3945 | |
| 3946 | segments = FA_RISC_CODE_SEGMENTS; |
| 3947 | dcode = (uint32_t *)ha->request_ring; |
| 3948 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3949 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3950 | fwclen = 0; |
| 3951 | |
| 3952 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3953 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3954 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3955 | "Unable to verify integrity of firmware image (%Zd)!\n", |
| 3956 | blob->fw->size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3957 | goto fail_fw_integrity; |
| 3958 | } |
| 3959 | for (i = 0; i < 4; i++) |
| 3960 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 3961 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 3962 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 3963 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 3964 | dcode[3] == 0)) { |
| 3965 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3966 | "Unable to verify integrity of firmware image!\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3967 | qla_printk(KERN_WARNING, ha, |
| 3968 | "Firmware data: %08x %08x %08x %08x!\n", dcode[0], |
| 3969 | dcode[1], dcode[2], dcode[3]); |
| 3970 | goto fail_fw_integrity; |
| 3971 | } |
| 3972 | |
| 3973 | while (segments && rval == QLA_SUCCESS) { |
| 3974 | risc_addr = be32_to_cpu(fwcode[2]); |
| 3975 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 3976 | risc_size = be32_to_cpu(fwcode[3]); |
| 3977 | |
| 3978 | /* Validate firmware image size. */ |
| 3979 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3980 | if (blob->fw->size < fwclen) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3981 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3982 | "Unable to verify integrity of firmware image " |
| 3983 | "(%Zd)!\n", blob->fw->size); |
| 3984 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3985 | goto fail_fw_integrity; |
| 3986 | } |
| 3987 | |
| 3988 | fragment = 0; |
| 3989 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 3990 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 3991 | if (dlen > risc_size) |
| 3992 | dlen = risc_size; |
| 3993 | |
| 3994 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
| 3995 | "addr %x, number of dwords 0x%x.\n", ha->host_no, |
| 3996 | risc_addr, dlen)); |
| 3997 | |
| 3998 | for (i = 0; i < dlen; i++) |
| 3999 | dcode[i] = swab32(fwcode[i]); |
| 4000 | |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 4001 | rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr, |
| 4002 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4003 | if (rval) { |
| 4004 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
| 4005 | "segment %d of firmware\n", ha->host_no, |
| 4006 | fragment)); |
| 4007 | qla_printk(KERN_WARNING, ha, |
| 4008 | "[ERROR] Failed to load segment %d of " |
| 4009 | "firmware\n", fragment); |
| 4010 | break; |
| 4011 | } |
| 4012 | |
| 4013 | fwcode += dlen; |
| 4014 | risc_addr += dlen; |
| 4015 | risc_size -= dlen; |
| 4016 | fragment++; |
| 4017 | } |
| 4018 | |
| 4019 | /* Next segment. */ |
| 4020 | segments--; |
| 4021 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4022 | return rval; |
| 4023 | |
| 4024 | fail_fw_integrity: |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4025 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4026 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4027 | |
| 4028 | void |
| 4029 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha) |
| 4030 | { |
| 4031 | int ret, retries; |
| 4032 | |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4033 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4034 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 4035 | if (!ha->fw_major_version) |
| 4036 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4037 | |
| 4038 | ret = qla2x00_stop_firmware(ha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 4039 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
| 4040 | retries ; retries--) { |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4041 | qla2x00_reset_chip(ha); |
| 4042 | if (qla2x00_chip_diag(ha) != QLA_SUCCESS) |
| 4043 | continue; |
| 4044 | if (qla2x00_setup_chip(ha) != QLA_SUCCESS) |
| 4045 | continue; |
| 4046 | qla_printk(KERN_INFO, ha, |
| 4047 | "Attempting retry of stop-firmware command...\n"); |
| 4048 | ret = qla2x00_stop_firmware(ha); |
| 4049 | } |
| 4050 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4051 | |
| 4052 | int |
| 4053 | qla24xx_configure_vhba(scsi_qla_host_t *ha) |
| 4054 | { |
| 4055 | int rval = QLA_SUCCESS; |
| 4056 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 4057 | |
| 4058 | if (!ha->parent) |
| 4059 | return -EINVAL; |
| 4060 | |
Seokmann Ju | d4486fd6 | 2008-04-03 13:13:28 -0700 | [diff] [blame] | 4061 | rval = qla2x00_fw_ready(ha->parent); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4062 | if (rval == QLA_SUCCESS) { |
| 4063 | clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 4064 | qla2x00_marker(ha, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | ha->flags.management_server_logged_in = 0; |
| 4068 | |
| 4069 | /* Login to SNS first */ |
Seokmann Ju | d4486fd6 | 2008-04-03 13:13:28 -0700 | [diff] [blame] | 4070 | qla24xx_login_fabric(ha->parent, NPH_SNS, 0xff, 0xff, 0xfc, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4071 | mb, BIT_1); |
| 4072 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
| 4073 | DEBUG15(qla_printk(KERN_INFO, ha, |
| 4074 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 4075 | "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS, |
| 4076 | mb[0], mb[1], mb[2], mb[6], mb[7])); |
| 4077 | return (QLA_FUNCTION_FAILED); |
| 4078 | } |
| 4079 | |
| 4080 | atomic_set(&ha->loop_down_timer, 0); |
| 4081 | atomic_set(&ha->loop_state, LOOP_UP); |
| 4082 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 4083 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
Seokmann Ju | d4486fd6 | 2008-04-03 13:13:28 -0700 | [diff] [blame] | 4084 | rval = qla2x00_loop_resync(ha->parent); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4085 | |
| 4086 | return rval; |
| 4087 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4088 | |
| 4089 | /* 84XX Support **************************************************************/ |
| 4090 | |
| 4091 | static LIST_HEAD(qla_cs84xx_list); |
| 4092 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 4093 | |
| 4094 | static struct qla_chip_state_84xx * |
| 4095 | qla84xx_get_chip(struct scsi_qla_host *ha) |
| 4096 | { |
| 4097 | struct qla_chip_state_84xx *cs84xx; |
| 4098 | |
| 4099 | mutex_lock(&qla_cs84xx_mutex); |
| 4100 | |
| 4101 | /* Find any shared 84xx chip. */ |
| 4102 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 4103 | if (cs84xx->bus == ha->pdev->bus) { |
| 4104 | kref_get(&cs84xx->kref); |
| 4105 | goto done; |
| 4106 | } |
| 4107 | } |
| 4108 | |
| 4109 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 4110 | if (!cs84xx) |
| 4111 | goto done; |
| 4112 | |
| 4113 | kref_init(&cs84xx->kref); |
| 4114 | spin_lock_init(&cs84xx->access_lock); |
| 4115 | mutex_init(&cs84xx->fw_update_mutex); |
| 4116 | cs84xx->bus = ha->pdev->bus; |
| 4117 | |
| 4118 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 4119 | done: |
| 4120 | mutex_unlock(&qla_cs84xx_mutex); |
| 4121 | return cs84xx; |
| 4122 | } |
| 4123 | |
| 4124 | static void |
| 4125 | __qla84xx_chip_release(struct kref *kref) |
| 4126 | { |
| 4127 | struct qla_chip_state_84xx *cs84xx = |
| 4128 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 4129 | |
| 4130 | mutex_lock(&qla_cs84xx_mutex); |
| 4131 | list_del(&cs84xx->list); |
| 4132 | mutex_unlock(&qla_cs84xx_mutex); |
| 4133 | kfree(cs84xx); |
| 4134 | } |
| 4135 | |
| 4136 | void |
| 4137 | qla84xx_put_chip(struct scsi_qla_host *ha) |
| 4138 | { |
| 4139 | if (ha->cs84xx) |
| 4140 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 4141 | } |
| 4142 | |
| 4143 | static int |
| 4144 | qla84xx_init_chip(scsi_qla_host_t *ha) |
| 4145 | { |
| 4146 | int rval; |
| 4147 | uint16_t status[2]; |
| 4148 | |
| 4149 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 4150 | |
| 4151 | rval = qla84xx_verify_chip(ha, status); |
| 4152 | |
| 4153 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 4154 | |
| 4155 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 4156 | QLA_SUCCESS; |
| 4157 | } |