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