Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLOGIC LINUX SOFTWARE |
| 3 | * |
| 4 | * QLogic ISP2x00 device driver for Linux 2.6.x |
| 5 | * Copyright (C) 2003-2004 QLogic Corporation |
| 6 | * (www.qlogic.com) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2, or (at your option) any |
| 11 | * later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | */ |
| 19 | #include "qla_def.h" |
| 20 | |
| 21 | #include <linux/delay.h> |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 22 | #include <scsi/scsi_transport_fc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include "qla_devtbl.h" |
| 25 | |
| 26 | /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */ |
| 27 | #ifndef EXT_IS_LUN_BIT_SET |
| 28 | #define EXT_IS_LUN_BIT_SET(P,L) \ |
| 29 | (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0) |
| 30 | #define EXT_SET_LUN_BIT(P,L) \ |
| 31 | ((P)->mask[L/8] |= (0x80 >> (L%8))) |
| 32 | #endif |
| 33 | |
| 34 | /* |
| 35 | * QLogic ISP2x00 Hardware Support Function Prototypes. |
| 36 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static int qla2x00_isp_firmware(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static void qla2x00_resize_request_q(scsi_qla_host_t *); |
| 39 | static int qla2x00_setup_chip(scsi_qla_host_t *); |
| 40 | static void qla2x00_init_response_q_entries(scsi_qla_host_t *); |
| 41 | static int qla2x00_init_rings(scsi_qla_host_t *); |
| 42 | static int qla2x00_fw_ready(scsi_qla_host_t *); |
| 43 | static int qla2x00_configure_hba(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | static int qla2x00_configure_loop(scsi_qla_host_t *); |
| 45 | static int qla2x00_configure_local_loop(scsi_qla_host_t *); |
| 46 | static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | static int qla2x00_configure_fabric(scsi_qla_host_t *); |
| 48 | static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *); |
| 49 | static int qla2x00_device_resync(scsi_qla_host_t *); |
| 50 | static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *, |
| 51 | uint16_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | static int qla2x00_restart_isp(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /****************************************************************************/ |
| 56 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 57 | /****************************************************************************/ |
| 58 | |
| 59 | /* |
| 60 | * qla2x00_initialize_adapter |
| 61 | * Initialize board. |
| 62 | * |
| 63 | * Input: |
| 64 | * ha = adapter block pointer. |
| 65 | * |
| 66 | * Returns: |
| 67 | * 0 = success |
| 68 | */ |
| 69 | int |
| 70 | qla2x00_initialize_adapter(scsi_qla_host_t *ha) |
| 71 | { |
| 72 | int rval; |
| 73 | uint8_t restart_risc = 0; |
| 74 | uint8_t retry; |
| 75 | uint32_t wait_time; |
| 76 | |
| 77 | /* Clear adapter flags. */ |
| 78 | ha->flags.online = 0; |
| 79 | ha->flags.reset_active = 0; |
| 80 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 81 | atomic_set(&ha->loop_state, LOOP_DOWN); |
| 82 | ha->device_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | ha->dpc_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | ha->flags.management_server_logged_in = 0; |
| 85 | ha->marker_needed = 0; |
| 86 | ha->mbx_flags = 0; |
| 87 | ha->isp_abort_cnt = 0; |
| 88 | ha->beacon_blink_led = 0; |
| 89 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 90 | rval = ha->isp_ops.pci_config(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | if (rval) { |
| 92 | DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n", |
| 93 | ha->host_no)); |
| 94 | return (rval); |
| 95 | } |
| 96 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 97 | ha->isp_ops.reset_chip(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n"); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 100 | ha->isp_ops.nvram_config(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n"); |
| 103 | |
| 104 | retry = 10; |
| 105 | /* |
| 106 | * Try to configure the loop. |
| 107 | */ |
| 108 | do { |
| 109 | restart_risc = 0; |
| 110 | |
| 111 | /* If firmware needs to be loaded */ |
| 112 | if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) { |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 113 | if ((rval = ha->isp_ops.chip_diag(ha)) == QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | rval = qla2x00_setup_chip(ha); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | if (rval == QLA_SUCCESS && |
| 119 | (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) { |
| 120 | check_fw_ready_again: |
| 121 | /* |
| 122 | * Wait for a successful LIP up to a maximum |
| 123 | * of (in seconds): RISC login timeout value, |
| 124 | * RISC retry count value, and port down retry |
| 125 | * value OR a minimum of 4 seconds OR If no |
| 126 | * cable, only 5 seconds. |
| 127 | */ |
| 128 | rval = qla2x00_fw_ready(ha); |
| 129 | if (rval == QLA_SUCCESS) { |
| 130 | clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
| 131 | |
| 132 | /* |
| 133 | * Wait at most MAX_TARGET RSCNs for a stable |
| 134 | * link. |
| 135 | */ |
| 136 | wait_time = 256; |
| 137 | do { |
| 138 | clear_bit(LOOP_RESYNC_NEEDED, |
| 139 | &ha->dpc_flags); |
| 140 | rval = qla2x00_configure_loop(ha); |
| 141 | |
| 142 | if (test_and_clear_bit(ISP_ABORT_NEEDED, |
| 143 | &ha->dpc_flags)) { |
| 144 | restart_risc = 1; |
| 145 | break; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * If loop state change while we were |
| 150 | * discoverying devices then wait for |
| 151 | * LIP to complete |
| 152 | */ |
| 153 | |
| 154 | if (atomic_read(&ha->loop_state) == |
| 155 | LOOP_DOWN && retry--) { |
| 156 | goto check_fw_ready_again; |
| 157 | } |
| 158 | wait_time--; |
| 159 | } while (!atomic_read(&ha->loop_down_timer) && |
| 160 | retry && |
| 161 | wait_time && |
| 162 | (test_bit(LOOP_RESYNC_NEEDED, |
| 163 | &ha->dpc_flags))); |
| 164 | |
| 165 | if (wait_time == 0) |
| 166 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } else if (ha->device_flags & DFLG_NO_CABLE) |
| 168 | /* If no cable, then all is good. */ |
| 169 | rval = QLA_SUCCESS; |
| 170 | } |
| 171 | } while (restart_risc && retry--); |
| 172 | |
| 173 | if (rval == QLA_SUCCESS) { |
| 174 | clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
| 175 | ha->marker_needed = 1; |
| 176 | qla2x00_marker(ha, 0, 0, MK_SYNC_ALL); |
| 177 | ha->marker_needed = 0; |
| 178 | |
| 179 | ha->flags.online = 1; |
| 180 | } else { |
| 181 | DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__)); |
| 182 | } |
| 183 | |
| 184 | return (rval); |
| 185 | } |
| 186 | |
| 187 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 188 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | * @ha: HA context |
| 190 | * |
| 191 | * Returns 0 on success. |
| 192 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 193 | int |
| 194 | qla2100_pci_config(scsi_qla_host_t *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 196 | uint16_t w, mwi; |
| 197 | unsigned long flags; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 198 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | qla_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
| 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | pci_set_master(ha->pdev); |
| 203 | mwi = 0; |
| 204 | if (pci_set_mwi(ha->pdev)) |
| 205 | mwi = PCI_COMMAND_INVALIDATE; |
| 206 | pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision); |
| 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 209 | w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 211 | |
| 212 | /* Reset expansion ROM address decode enable */ |
| 213 | pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w); |
| 214 | w &= ~PCI_ROM_ADDRESS_ENABLE; |
| 215 | pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w); |
| 216 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 217 | /* Get PCI bus information. */ |
| 218 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 219 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 220 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 221 | |
| 222 | return QLA_SUCCESS; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 227 | * @ha: HA context |
| 228 | * |
| 229 | * Returns 0 on success. |
| 230 | */ |
| 231 | int |
| 232 | qla2300_pci_config(scsi_qla_host_t *ha) |
| 233 | { |
| 234 | uint16_t w, mwi; |
| 235 | unsigned long flags = 0; |
| 236 | uint32_t cnt; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 237 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 238 | |
| 239 | qla_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
| 240 | |
| 241 | pci_set_master(ha->pdev); |
| 242 | mwi = 0; |
| 243 | if (pci_set_mwi(ha->pdev)) |
| 244 | mwi = PCI_COMMAND_INVALIDATE; |
| 245 | pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision); |
| 246 | |
| 247 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 248 | w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 249 | |
| 250 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 251 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 252 | |
| 253 | /* |
| 254 | * If this is a 2300 card and not 2312, reset the |
| 255 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 256 | * the 2310 also reports itself as a 2300 so we need to get the |
| 257 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 258 | * not a 2310. |
| 259 | */ |
| 260 | if (IS_QLA2300(ha)) { |
| 261 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 262 | |
| 263 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 264 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 265 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 266 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 267 | break; |
| 268 | |
| 269 | udelay(10); |
| 270 | } |
| 271 | |
| 272 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 273 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 274 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 275 | |
| 276 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 277 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 278 | |
| 279 | if (ha->fb_rev == FPM_2300) |
| 280 | w &= ~PCI_COMMAND_INVALIDATE; |
| 281 | |
| 282 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 283 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 284 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 285 | |
| 286 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 287 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 288 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 289 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 290 | break; |
| 291 | |
| 292 | udelay(10); |
| 293 | } |
| 294 | |
| 295 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 296 | } |
| 297 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 298 | |
| 299 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 300 | |
| 301 | /* Reset expansion ROM address decode enable */ |
| 302 | pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w); |
| 303 | w &= ~PCI_ROM_ADDRESS_ENABLE; |
| 304 | pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w); |
| 305 | |
| 306 | /* Get PCI bus information. */ |
| 307 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 308 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 309 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 310 | |
| 311 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /** |
| 315 | * qla2x00_isp_firmware() - Choose firmware image. |
| 316 | * @ha: HA context |
| 317 | * |
| 318 | * Returns 0 on success. |
| 319 | */ |
| 320 | static int |
| 321 | qla2x00_isp_firmware(scsi_qla_host_t *ha) |
| 322 | { |
| 323 | int rval; |
| 324 | |
| 325 | /* Assume loading risc code */ |
| 326 | rval = QLA_FUNCTION_FAILED; |
| 327 | |
| 328 | if (ha->flags.disable_risc_code_load) { |
| 329 | DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n", |
| 330 | ha->host_no)); |
| 331 | qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n"); |
| 332 | |
| 333 | /* Verify checksum of loaded RISC code. */ |
| 334 | rval = qla2x00_verify_checksum(ha); |
| 335 | } |
| 336 | |
| 337 | if (rval) { |
| 338 | DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n", |
| 339 | ha->host_no)); |
| 340 | } |
| 341 | |
| 342 | return (rval); |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * qla2x00_reset_chip() - Reset ISP chip. |
| 347 | * @ha: HA context |
| 348 | * |
| 349 | * Returns 0 on success. |
| 350 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 351 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | qla2x00_reset_chip(scsi_qla_host_t *ha) |
| 353 | { |
| 354 | unsigned long flags = 0; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 355 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | uint32_t cnt; |
| 357 | unsigned long mbx_flags = 0; |
| 358 | uint16_t cmd; |
| 359 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 360 | ha->isp_ops.disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 363 | |
| 364 | /* Turn off master enable */ |
| 365 | cmd = 0; |
| 366 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 367 | cmd &= ~PCI_COMMAND_MASTER; |
| 368 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 369 | |
| 370 | if (!IS_QLA2100(ha)) { |
| 371 | /* Pause RISC. */ |
| 372 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 373 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 374 | for (cnt = 0; cnt < 30000; cnt++) { |
| 375 | if ((RD_REG_WORD(®->hccr) & |
| 376 | HCCR_RISC_PAUSE) != 0) |
| 377 | break; |
| 378 | udelay(100); |
| 379 | } |
| 380 | } else { |
| 381 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 382 | udelay(10); |
| 383 | } |
| 384 | |
| 385 | /* Select FPM registers. */ |
| 386 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 387 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 388 | |
| 389 | /* FPM Soft Reset. */ |
| 390 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 391 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 392 | |
| 393 | /* Toggle Fpm Reset. */ |
| 394 | if (!IS_QLA2200(ha)) { |
| 395 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 396 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 397 | } |
| 398 | |
| 399 | /* Select frame buffer registers. */ |
| 400 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 401 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 402 | |
| 403 | /* Reset frame buffer FIFOs. */ |
| 404 | if (IS_QLA2200(ha)) { |
| 405 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 406 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 407 | } else { |
| 408 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 409 | |
| 410 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 411 | for (cnt = 0; cnt < 3000; cnt++) { |
| 412 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 413 | break; |
| 414 | udelay(100); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | /* Select RISC module registers. */ |
| 419 | WRT_REG_WORD(®->ctrl_status, 0); |
| 420 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 421 | |
| 422 | /* Reset RISC processor. */ |
| 423 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 424 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 425 | |
| 426 | /* Release RISC processor. */ |
| 427 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 428 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 429 | } |
| 430 | |
| 431 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 432 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 433 | |
| 434 | /* Reset ISP chip. */ |
| 435 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 436 | |
| 437 | /* Wait for RISC to recover from reset. */ |
| 438 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 439 | /* |
| 440 | * It is necessary to for a delay here since the card doesn't |
| 441 | * respond to PCI reads during a reset. On some architectures |
| 442 | * this will result in an MCA. |
| 443 | */ |
| 444 | udelay(20); |
| 445 | for (cnt = 30000; cnt; cnt--) { |
| 446 | if ((RD_REG_WORD(®->ctrl_status) & |
| 447 | CSR_ISP_SOFT_RESET) == 0) |
| 448 | break; |
| 449 | udelay(100); |
| 450 | } |
| 451 | } else |
| 452 | udelay(10); |
| 453 | |
| 454 | /* Reset RISC processor. */ |
| 455 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 456 | |
| 457 | WRT_REG_WORD(®->semaphore, 0); |
| 458 | |
| 459 | /* Release RISC processor. */ |
| 460 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 461 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 462 | |
| 463 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 464 | for (cnt = 0; cnt < 30000; cnt++) { |
| 465 | if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) |
| 466 | spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags); |
| 467 | |
| 468 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) { |
| 469 | if (!(test_bit(ABORT_ISP_ACTIVE, |
| 470 | &ha->dpc_flags))) |
| 471 | spin_unlock_irqrestore( |
| 472 | &ha->mbx_reg_lock, mbx_flags); |
| 473 | break; |
| 474 | } |
| 475 | |
| 476 | if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) |
| 477 | spin_unlock_irqrestore(&ha->mbx_reg_lock, |
| 478 | mbx_flags); |
| 479 | |
| 480 | udelay(100); |
| 481 | } |
| 482 | } else |
| 483 | udelay(100); |
| 484 | |
| 485 | /* Turn on master enable */ |
| 486 | cmd |= PCI_COMMAND_MASTER; |
| 487 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 488 | |
| 489 | /* Disable RISC pause on FPM parity error. */ |
| 490 | if (!IS_QLA2100(ha)) { |
| 491 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 492 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 493 | } |
| 494 | |
| 495 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 500 | * @ha: HA context |
| 501 | * |
| 502 | * Returns 0 on success. |
| 503 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 504 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | qla2x00_chip_diag(scsi_qla_host_t *ha) |
| 506 | { |
| 507 | int rval; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 508 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | unsigned long flags = 0; |
| 510 | uint16_t data; |
| 511 | uint32_t cnt; |
| 512 | uint16_t mb[5]; |
| 513 | |
| 514 | /* Assume a failed state */ |
| 515 | rval = QLA_FUNCTION_FAILED; |
| 516 | |
| 517 | DEBUG3(printk("scsi(%ld): Testing device at %lx.\n", |
| 518 | ha->host_no, (u_long)®->flash_address)); |
| 519 | |
| 520 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 521 | |
| 522 | /* Reset ISP chip. */ |
| 523 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 524 | |
| 525 | /* |
| 526 | * We need to have a delay here since the card will not respond while |
| 527 | * in reset causing an MCA on some architectures. |
| 528 | */ |
| 529 | udelay(20); |
| 530 | data = qla2x00_debounce_register(®->ctrl_status); |
| 531 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 532 | udelay(5); |
| 533 | data = RD_REG_WORD(®->ctrl_status); |
| 534 | barrier(); |
| 535 | } |
| 536 | |
| 537 | if (!cnt) |
| 538 | goto chip_diag_failed; |
| 539 | |
| 540 | DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n", |
| 541 | ha->host_no)); |
| 542 | |
| 543 | /* Reset RISC processor. */ |
| 544 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 545 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 546 | |
| 547 | /* Workaround for QLA2312 PCI parity error */ |
| 548 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 549 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 550 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 551 | udelay(5); |
| 552 | data = RD_MAILBOX_REG(ha, reg, 0); |
| 553 | barrier(); |
| 554 | } |
| 555 | } else |
| 556 | udelay(10); |
| 557 | |
| 558 | if (!cnt) |
| 559 | goto chip_diag_failed; |
| 560 | |
| 561 | /* Check product ID of chip */ |
| 562 | DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no)); |
| 563 | |
| 564 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 565 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 566 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 567 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 568 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 569 | mb[3] != PROD_ID_3) { |
| 570 | qla_printk(KERN_WARNING, ha, |
| 571 | "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]); |
| 572 | |
| 573 | goto chip_diag_failed; |
| 574 | } |
| 575 | ha->product_id[0] = mb[1]; |
| 576 | ha->product_id[1] = mb[2]; |
| 577 | ha->product_id[2] = mb[3]; |
| 578 | ha->product_id[3] = mb[4]; |
| 579 | |
| 580 | /* Adjust fw RISC transfer size */ |
| 581 | if (ha->request_q_length > 1024) |
| 582 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 583 | else |
| 584 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
| 585 | ha->request_q_length; |
| 586 | |
| 587 | if (IS_QLA2200(ha) && |
| 588 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 589 | /* Limit firmware transfer size with a 2200A */ |
| 590 | DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n", |
| 591 | ha->host_no)); |
| 592 | |
| 593 | ha->fw_transfer_size = 128; |
| 594 | } |
| 595 | |
| 596 | /* Wrap Incoming Mailboxes Test. */ |
| 597 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 598 | |
| 599 | DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no)); |
| 600 | rval = qla2x00_mbx_reg_test(ha); |
| 601 | if (rval) { |
| 602 | DEBUG(printk("scsi(%ld): Failed mailbox send register test\n", |
| 603 | ha->host_no)); |
| 604 | qla_printk(KERN_WARNING, ha, |
| 605 | "Failed mailbox send register test\n"); |
| 606 | } |
| 607 | else { |
| 608 | /* Flag a successful rval */ |
| 609 | rval = QLA_SUCCESS; |
| 610 | } |
| 611 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 612 | |
| 613 | chip_diag_failed: |
| 614 | if (rval) |
| 615 | DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED " |
| 616 | "****\n", ha->host_no)); |
| 617 | |
| 618 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 619 | |
| 620 | return (rval); |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * qla2x00_resize_request_q() - Resize request queue given available ISP memory. |
| 625 | * @ha: HA context |
| 626 | * |
| 627 | * Returns 0 on success. |
| 628 | */ |
| 629 | static void |
| 630 | qla2x00_resize_request_q(scsi_qla_host_t *ha) |
| 631 | { |
| 632 | int rval; |
| 633 | uint16_t fw_iocb_cnt = 0; |
| 634 | uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM; |
| 635 | dma_addr_t request_dma; |
| 636 | request_t *request_ring; |
| 637 | |
| 638 | /* Valid only on recent ISPs. */ |
| 639 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 640 | return; |
| 641 | |
| 642 | /* Retrieve IOCB counts available to the firmware. */ |
| 643 | rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt); |
| 644 | if (rval) |
| 645 | return; |
| 646 | /* No point in continuing if current settings are sufficient. */ |
| 647 | if (fw_iocb_cnt < 1024) |
| 648 | return; |
| 649 | if (ha->request_q_length >= request_q_length) |
| 650 | return; |
| 651 | |
| 652 | /* Attempt to claim larger area for request queue. */ |
| 653 | request_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 654 | (request_q_length + 1) * sizeof(request_t), &request_dma, |
| 655 | GFP_KERNEL); |
| 656 | if (request_ring == NULL) |
| 657 | return; |
| 658 | |
| 659 | /* Resize successful, report extensions. */ |
| 660 | qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n", |
| 661 | (ha->fw_memory_size + 1) / 1024); |
| 662 | qla_printk(KERN_INFO, ha, "Resizing request queue depth " |
| 663 | "(%d -> %d)...\n", ha->request_q_length, request_q_length); |
| 664 | |
| 665 | /* Clear old allocations. */ |
| 666 | dma_free_coherent(&ha->pdev->dev, |
| 667 | (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring, |
| 668 | ha->request_dma); |
| 669 | |
| 670 | /* Begin using larger queue. */ |
| 671 | ha->request_q_length = request_q_length; |
| 672 | ha->request_ring = request_ring; |
| 673 | ha->request_dma = request_dma; |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 678 | * @ha: HA context |
| 679 | * |
| 680 | * Returns 0 on success. |
| 681 | */ |
| 682 | static int |
| 683 | qla2x00_setup_chip(scsi_qla_host_t *ha) |
| 684 | { |
| 685 | int rval; |
| 686 | uint16_t cnt; |
| 687 | uint16_t *risc_code; |
| 688 | unsigned long risc_address; |
| 689 | unsigned long risc_code_size; |
| 690 | int num; |
| 691 | int i; |
| 692 | uint16_t *req_ring; |
| 693 | struct qla_fw_info *fw_iter; |
| 694 | |
| 695 | rval = QLA_SUCCESS; |
| 696 | |
| 697 | /* Load firmware sequences */ |
| 698 | fw_iter = ha->brd_info->fw_info; |
| 699 | while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) { |
| 700 | risc_code = fw_iter->fwcode; |
| 701 | risc_code_size = *fw_iter->fwlen; |
| 702 | |
| 703 | if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) { |
| 704 | risc_address = *fw_iter->fwstart; |
| 705 | } else { |
| 706 | /* Extended address */ |
| 707 | risc_address = *fw_iter->lfwstart; |
| 708 | } |
| 709 | |
| 710 | num = 0; |
| 711 | rval = 0; |
| 712 | while (risc_code_size > 0 && !rval) { |
| 713 | cnt = (uint16_t)(ha->fw_transfer_size >> 1); |
| 714 | if (cnt > risc_code_size) |
| 715 | cnt = risc_code_size; |
| 716 | |
| 717 | DEBUG7(printk("scsi(%ld): Loading risc segment@ " |
| 718 | "addr %p, number of bytes 0x%x, offset 0x%lx.\n", |
| 719 | ha->host_no, risc_code, cnt, risc_address)); |
| 720 | |
| 721 | req_ring = (uint16_t *)ha->request_ring; |
| 722 | for (i = 0; i < cnt; i++) |
| 723 | req_ring[i] = cpu_to_le16(risc_code[i]); |
| 724 | |
| 725 | if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) { |
| 726 | rval = qla2x00_load_ram(ha, |
| 727 | ha->request_dma, risc_address, cnt); |
| 728 | } else { |
| 729 | rval = qla2x00_load_ram_ext(ha, |
| 730 | ha->request_dma, risc_address, cnt); |
| 731 | } |
| 732 | if (rval) { |
| 733 | DEBUG(printk("scsi(%ld): [ERROR] Failed to " |
| 734 | "load segment %d of firmware\n", |
| 735 | ha->host_no, num)); |
| 736 | qla_printk(KERN_WARNING, ha, |
| 737 | "[ERROR] Failed to load " |
| 738 | "segment %d of firmware\n", num); |
| 739 | |
| 740 | qla2x00_dump_regs(ha); |
| 741 | break; |
| 742 | } |
| 743 | |
| 744 | risc_code += cnt; |
| 745 | risc_address += cnt; |
| 746 | risc_code_size -= cnt; |
| 747 | num++; |
| 748 | } |
| 749 | |
| 750 | /* Next firmware sequence */ |
| 751 | fw_iter++; |
| 752 | } |
| 753 | |
| 754 | /* Verify checksum of loaded RISC code. */ |
| 755 | if (!rval) { |
| 756 | DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC " |
| 757 | "code.\n", ha->host_no)); |
| 758 | |
| 759 | rval = qla2x00_verify_checksum(ha); |
| 760 | if (rval == QLA_SUCCESS) { |
| 761 | /* Start firmware execution. */ |
| 762 | DEBUG(printk("scsi(%ld): Checksum OK, start " |
| 763 | "firmware.\n", ha->host_no)); |
| 764 | |
| 765 | rval = qla2x00_execute_fw(ha); |
| 766 | /* Retrieve firmware information. */ |
| 767 | if (rval == QLA_SUCCESS && ha->fw_major_version == 0) { |
| 768 | qla2x00_get_fw_version(ha, |
| 769 | &ha->fw_major_version, |
| 770 | &ha->fw_minor_version, |
| 771 | &ha->fw_subminor_version, |
| 772 | &ha->fw_attributes, &ha->fw_memory_size); |
| 773 | qla2x00_resize_request_q(ha); |
| 774 | } |
| 775 | } else { |
| 776 | DEBUG2(printk(KERN_INFO |
| 777 | "scsi(%ld): ISP Firmware failed checksum.\n", |
| 778 | ha->host_no)); |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | if (rval) { |
| 783 | DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n", |
| 784 | ha->host_no)); |
| 785 | } |
| 786 | |
| 787 | return (rval); |
| 788 | } |
| 789 | |
| 790 | /** |
| 791 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 792 | * @ha: HA context |
| 793 | * |
| 794 | * Beginning of request ring has initialization control block already built |
| 795 | * by nvram config routine. |
| 796 | * |
| 797 | * Returns 0 on success. |
| 798 | */ |
| 799 | static void |
| 800 | qla2x00_init_response_q_entries(scsi_qla_host_t *ha) |
| 801 | { |
| 802 | uint16_t cnt; |
| 803 | response_t *pkt; |
| 804 | |
| 805 | pkt = ha->response_ring_ptr; |
| 806 | for (cnt = 0; cnt < ha->response_q_length; cnt++) { |
| 807 | pkt->signature = RESPONSE_PROCESSED; |
| 808 | pkt++; |
| 809 | } |
| 810 | |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 815 | * @ha: HA context |
| 816 | * |
| 817 | * Returns 0 on success. |
| 818 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 819 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | qla2x00_update_fw_options(scsi_qla_host_t *ha) |
| 821 | { |
| 822 | uint16_t swing, emphasis, tx_sens, rx_sens; |
| 823 | |
| 824 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 825 | qla2x00_get_fw_options(ha, ha->fw_options); |
| 826 | |
| 827 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 828 | return; |
| 829 | |
| 830 | /* Serial Link options. */ |
| 831 | DEBUG3(printk("scsi(%ld): Serial link options:\n", |
| 832 | ha->host_no)); |
| 833 | DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options, |
| 834 | sizeof(ha->fw_seriallink_options))); |
| 835 | |
| 836 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 837 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 838 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 839 | |
| 840 | /* 1G settings */ |
| 841 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 842 | emphasis = (ha->fw_seriallink_options[2] & |
| 843 | (BIT_4 | BIT_3)) >> 3; |
| 844 | tx_sens = ha->fw_seriallink_options[0] & |
| 845 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 846 | rx_sens = (ha->fw_seriallink_options[0] & |
| 847 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 848 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 849 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 850 | if (rx_sens == 0x0) |
| 851 | rx_sens = 0x3; |
| 852 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 853 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 854 | ha->fw_options[10] |= BIT_5 | |
| 855 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 856 | (tx_sens & (BIT_1 | BIT_0)); |
| 857 | |
| 858 | /* 2G settings */ |
| 859 | swing = (ha->fw_seriallink_options[2] & |
| 860 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 861 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 862 | tx_sens = ha->fw_seriallink_options[1] & |
| 863 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 864 | rx_sens = (ha->fw_seriallink_options[1] & |
| 865 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 866 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 867 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 868 | if (rx_sens == 0x0) |
| 869 | rx_sens = 0x3; |
| 870 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 871 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 872 | ha->fw_options[11] |= BIT_5 | |
| 873 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 874 | (tx_sens & (BIT_1 | BIT_0)); |
| 875 | } |
| 876 | |
| 877 | /* FCP2 options. */ |
| 878 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 879 | ha->fw_options[3] |= BIT_13; |
| 880 | |
| 881 | /* LED scheme. */ |
| 882 | if (ha->flags.enable_led_scheme) |
| 883 | ha->fw_options[2] |= BIT_12; |
| 884 | |
| 885 | /* Update firmware options. */ |
| 886 | qla2x00_set_fw_options(ha, ha->fw_options); |
| 887 | } |
| 888 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 889 | void |
| 890 | qla2x00_config_rings(struct scsi_qla_host *ha) |
| 891 | { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 892 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 893 | |
| 894 | /* Setup ring parameters in initialization control block. */ |
| 895 | ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 896 | ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0); |
| 897 | ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length); |
| 898 | ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length); |
| 899 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma)); |
| 900 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma)); |
| 901 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma)); |
| 902 | ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma)); |
| 903 | |
| 904 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 905 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 906 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 907 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 908 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 909 | } |
| 910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | /** |
| 912 | * qla2x00_init_rings() - Initializes firmware. |
| 913 | * @ha: HA context |
| 914 | * |
| 915 | * Beginning of request ring has initialization control block already built |
| 916 | * by nvram config routine. |
| 917 | * |
| 918 | * Returns 0 on success. |
| 919 | */ |
| 920 | static int |
| 921 | qla2x00_init_rings(scsi_qla_host_t *ha) |
| 922 | { |
| 923 | int rval; |
| 924 | unsigned long flags = 0; |
| 925 | int cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
| 927 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 928 | |
| 929 | /* Clear outstanding commands array. */ |
| 930 | for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) |
| 931 | ha->outstanding_cmds[cnt] = NULL; |
| 932 | |
| 933 | ha->current_outstanding_cmd = 0; |
| 934 | |
| 935 | /* Clear RSCN queue. */ |
| 936 | ha->rscn_in_ptr = 0; |
| 937 | ha->rscn_out_ptr = 0; |
| 938 | |
| 939 | /* Initialize firmware. */ |
| 940 | ha->request_ring_ptr = ha->request_ring; |
| 941 | ha->req_ring_index = 0; |
| 942 | ha->req_q_cnt = ha->request_q_length; |
| 943 | ha->response_ring_ptr = ha->response_ring; |
| 944 | ha->rsp_ring_index = 0; |
| 945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | /* Initialize response queue entries */ |
| 947 | qla2x00_init_response_q_entries(ha); |
| 948 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 949 | ha->isp_ops.config_rings(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | |
| 951 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 952 | |
| 953 | /* Update any ISP specific firmware options before initialization. */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 954 | ha->isp_ops.update_fw_options(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | |
| 956 | DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no)); |
| 957 | rval = qla2x00_init_firmware(ha, sizeof(init_cb_t)); |
| 958 | if (rval) { |
| 959 | DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n", |
| 960 | ha->host_no)); |
| 961 | } else { |
| 962 | DEBUG3(printk("scsi(%ld): Init firmware -- success.\n", |
| 963 | ha->host_no)); |
| 964 | } |
| 965 | |
| 966 | return (rval); |
| 967 | } |
| 968 | |
| 969 | /** |
| 970 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 971 | * @ha: HA context |
| 972 | * |
| 973 | * Returns 0 on success. |
| 974 | */ |
| 975 | static int |
| 976 | qla2x00_fw_ready(scsi_qla_host_t *ha) |
| 977 | { |
| 978 | int rval; |
| 979 | unsigned long wtime, mtime; |
| 980 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 981 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
| 982 | uint16_t fw_state; |
| 983 | |
| 984 | rval = QLA_SUCCESS; |
| 985 | |
| 986 | /* 20 seconds for loop down. */ |
| 987 | min_wait = 20; |
| 988 | |
| 989 | /* |
| 990 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 991 | * our own processing. |
| 992 | */ |
| 993 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 994 | wait_time = min_wait; |
| 995 | } |
| 996 | |
| 997 | /* Min wait time if loop down */ |
| 998 | mtime = jiffies + (min_wait * HZ); |
| 999 | |
| 1000 | /* wait time before firmware ready */ |
| 1001 | wtime = jiffies + (wait_time * HZ); |
| 1002 | |
| 1003 | /* Wait for ISP to finish LIP */ |
| 1004 | if (!ha->flags.init_done) |
| 1005 | qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n"); |
| 1006 | |
| 1007 | DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n", |
| 1008 | ha->host_no)); |
| 1009 | |
| 1010 | do { |
| 1011 | rval = qla2x00_get_firmware_state(ha, &fw_state); |
| 1012 | if (rval == QLA_SUCCESS) { |
| 1013 | if (fw_state < FSTATE_LOSS_OF_SYNC) { |
| 1014 | ha->device_flags &= ~DFLG_NO_CABLE; |
| 1015 | } |
| 1016 | if (fw_state == FSTATE_READY) { |
| 1017 | DEBUG(printk("scsi(%ld): F/W Ready - OK \n", |
| 1018 | ha->host_no)); |
| 1019 | |
| 1020 | qla2x00_get_retry_cnt(ha, &ha->retry_count, |
| 1021 | &ha->login_timeout, &ha->r_a_tov); |
| 1022 | |
| 1023 | rval = QLA_SUCCESS; |
| 1024 | break; |
| 1025 | } |
| 1026 | |
| 1027 | rval = QLA_FUNCTION_FAILED; |
| 1028 | |
| 1029 | if (atomic_read(&ha->loop_down_timer) && |
| 1030 | (fw_state >= FSTATE_LOSS_OF_SYNC || |
| 1031 | fw_state == FSTATE_WAIT_AL_PA)) { |
| 1032 | /* Loop down. Timeout on min_wait for states |
| 1033 | * other than Wait for Login. |
| 1034 | */ |
| 1035 | if (time_after_eq(jiffies, mtime)) { |
| 1036 | qla_printk(KERN_INFO, ha, |
| 1037 | "Cable is unplugged...\n"); |
| 1038 | |
| 1039 | ha->device_flags |= DFLG_NO_CABLE; |
| 1040 | break; |
| 1041 | } |
| 1042 | } |
| 1043 | } else { |
| 1044 | /* Mailbox cmd failed. Timeout on min_wait. */ |
| 1045 | if (time_after_eq(jiffies, mtime)) |
| 1046 | break; |
| 1047 | } |
| 1048 | |
| 1049 | if (time_after_eq(jiffies, wtime)) |
| 1050 | break; |
| 1051 | |
| 1052 | /* Delay for a while */ |
| 1053 | msleep(500); |
| 1054 | |
| 1055 | DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n", |
| 1056 | ha->host_no, fw_state, jiffies)); |
| 1057 | } while (1); |
| 1058 | |
| 1059 | DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n", |
| 1060 | ha->host_no, fw_state, jiffies)); |
| 1061 | |
| 1062 | if (rval) { |
| 1063 | DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n", |
| 1064 | ha->host_no)); |
| 1065 | } |
| 1066 | |
| 1067 | return (rval); |
| 1068 | } |
| 1069 | |
| 1070 | /* |
| 1071 | * qla2x00_configure_hba |
| 1072 | * Setup adapter context. |
| 1073 | * |
| 1074 | * Input: |
| 1075 | * ha = adapter state pointer. |
| 1076 | * |
| 1077 | * Returns: |
| 1078 | * 0 = success |
| 1079 | * |
| 1080 | * Context: |
| 1081 | * Kernel context. |
| 1082 | */ |
| 1083 | static int |
| 1084 | qla2x00_configure_hba(scsi_qla_host_t *ha) |
| 1085 | { |
| 1086 | int rval; |
| 1087 | uint16_t loop_id; |
| 1088 | uint16_t topo; |
| 1089 | uint8_t al_pa; |
| 1090 | uint8_t area; |
| 1091 | uint8_t domain; |
| 1092 | char connect_type[22]; |
| 1093 | |
| 1094 | /* Get host addresses. */ |
| 1095 | rval = qla2x00_get_adapter_id(ha, |
| 1096 | &loop_id, &al_pa, &area, &domain, &topo); |
| 1097 | if (rval != QLA_SUCCESS) { |
| 1098 | qla_printk(KERN_WARNING, ha, |
| 1099 | "ERROR -- Unable to get host loop ID.\n"); |
| 1100 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 1101 | return (rval); |
| 1102 | } |
| 1103 | |
| 1104 | if (topo == 4) { |
| 1105 | qla_printk(KERN_INFO, ha, |
| 1106 | "Cannot get topology - retrying.\n"); |
| 1107 | return (QLA_FUNCTION_FAILED); |
| 1108 | } |
| 1109 | |
| 1110 | ha->loop_id = loop_id; |
| 1111 | |
| 1112 | /* initialize */ |
| 1113 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 1114 | ha->operating_mode = LOOP; |
| 1115 | |
| 1116 | switch (topo) { |
| 1117 | case 0: |
| 1118 | DEBUG3(printk("scsi(%ld): HBA in NL topology.\n", |
| 1119 | ha->host_no)); |
| 1120 | ha->current_topology = ISP_CFG_NL; |
| 1121 | strcpy(connect_type, "(Loop)"); |
| 1122 | break; |
| 1123 | |
| 1124 | case 1: |
| 1125 | DEBUG3(printk("scsi(%ld): HBA in FL topology.\n", |
| 1126 | ha->host_no)); |
| 1127 | ha->current_topology = ISP_CFG_FL; |
| 1128 | strcpy(connect_type, "(FL_Port)"); |
| 1129 | break; |
| 1130 | |
| 1131 | case 2: |
| 1132 | DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n", |
| 1133 | ha->host_no)); |
| 1134 | ha->operating_mode = P2P; |
| 1135 | ha->current_topology = ISP_CFG_N; |
| 1136 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 1137 | break; |
| 1138 | |
| 1139 | case 3: |
| 1140 | DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n", |
| 1141 | ha->host_no)); |
| 1142 | ha->operating_mode = P2P; |
| 1143 | ha->current_topology = ISP_CFG_F; |
| 1144 | strcpy(connect_type, "(F_Port)"); |
| 1145 | break; |
| 1146 | |
| 1147 | default: |
| 1148 | DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. " |
| 1149 | "Using NL.\n", |
| 1150 | ha->host_no, topo)); |
| 1151 | ha->current_topology = ISP_CFG_NL; |
| 1152 | strcpy(connect_type, "(Loop)"); |
| 1153 | break; |
| 1154 | } |
| 1155 | |
| 1156 | /* Save Host port and loop ID. */ |
| 1157 | /* byte order - Big Endian */ |
| 1158 | ha->d_id.b.domain = domain; |
| 1159 | ha->d_id.b.area = area; |
| 1160 | ha->d_id.b.al_pa = al_pa; |
| 1161 | |
| 1162 | if (!ha->flags.init_done) |
| 1163 | qla_printk(KERN_INFO, ha, |
| 1164 | "Topology - %s, Host Loop address 0x%x\n", |
| 1165 | connect_type, ha->loop_id); |
| 1166 | |
| 1167 | if (rval) { |
| 1168 | DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no)); |
| 1169 | } else { |
| 1170 | DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no)); |
| 1171 | } |
| 1172 | |
| 1173 | return(rval); |
| 1174 | } |
| 1175 | |
| 1176 | /* |
| 1177 | * NVRAM configuration for ISP 2xxx |
| 1178 | * |
| 1179 | * Input: |
| 1180 | * ha = adapter block pointer. |
| 1181 | * |
| 1182 | * Output: |
| 1183 | * initialization control block in response_ring |
| 1184 | * host adapters parameters in host adapter block |
| 1185 | * |
| 1186 | * Returns: |
| 1187 | * 0 = success. |
| 1188 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1189 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | qla2x00_nvram_config(scsi_qla_host_t *ha) |
| 1191 | { |
| 1192 | int rval; |
| 1193 | uint8_t chksum = 0; |
| 1194 | uint16_t cnt; |
| 1195 | uint8_t *dptr1, *dptr2; |
| 1196 | init_cb_t *icb = ha->init_cb; |
| 1197 | nvram_t *nv = (nvram_t *)ha->request_ring; |
| 1198 | uint16_t *wptr = (uint16_t *)ha->request_ring; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 1199 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | uint8_t timer_mode; |
| 1201 | |
| 1202 | rval = QLA_SUCCESS; |
| 1203 | |
| 1204 | /* Determine NVRAM starting address. */ |
| 1205 | ha->nvram_base = 0; |
| 1206 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 1207 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 1208 | ha->nvram_base = 0x80; |
| 1209 | |
| 1210 | /* Get NVRAM data and calculate checksum. */ |
| 1211 | qla2x00_lock_nvram_access(ha); |
| 1212 | for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++) { |
| 1213 | *wptr = cpu_to_le16(qla2x00_get_nvram_word(ha, |
| 1214 | (cnt+ha->nvram_base))); |
| 1215 | chksum += (uint8_t)*wptr; |
| 1216 | chksum += (uint8_t)(*wptr >> 8); |
| 1217 | wptr++; |
| 1218 | } |
| 1219 | qla2x00_unlock_nvram_access(ha); |
| 1220 | |
| 1221 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no)); |
| 1222 | DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring, |
| 1223 | sizeof(nvram_t))); |
| 1224 | |
| 1225 | /* Bad NVRAM data, set defaults parameters. */ |
| 1226 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 1227 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 1228 | /* Reset NVRAM data. */ |
| 1229 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 1230 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 1231 | nv->nvram_version); |
| 1232 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 1233 | "invalid -- WWPN) defaults.\n"); |
| 1234 | |
| 1235 | /* |
| 1236 | * Set default initialization control block. |
| 1237 | */ |
| 1238 | memset(nv, 0, sizeof(nvram_t)); |
| 1239 | nv->parameter_block_version = ICB_VERSION; |
| 1240 | |
| 1241 | if (IS_QLA23XX(ha)) { |
| 1242 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 1243 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 1244 | nv->add_firmware_options[0] = BIT_5; |
| 1245 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 1246 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 1247 | nv->special_options[1] = BIT_7; |
| 1248 | } else if (IS_QLA2200(ha)) { |
| 1249 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 1250 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 1251 | nv->add_firmware_options[0] = BIT_5; |
| 1252 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 1253 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 1254 | } else if (IS_QLA2100(ha)) { |
| 1255 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 1256 | nv->firmware_options[1] = BIT_5; |
| 1257 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 1258 | } |
| 1259 | |
| 1260 | nv->max_iocb_allocation = __constant_cpu_to_le16(256); |
| 1261 | nv->execution_throttle = __constant_cpu_to_le16(16); |
| 1262 | nv->retry_count = 8; |
| 1263 | nv->retry_delay = 1; |
| 1264 | |
| 1265 | nv->port_name[0] = 33; |
| 1266 | nv->port_name[3] = 224; |
| 1267 | nv->port_name[4] = 139; |
| 1268 | |
| 1269 | nv->login_timeout = 4; |
| 1270 | |
| 1271 | /* |
| 1272 | * Set default host adapter parameters |
| 1273 | */ |
| 1274 | nv->host_p[1] = BIT_2; |
| 1275 | nv->reset_delay = 5; |
| 1276 | nv->port_down_retry_count = 8; |
| 1277 | nv->max_luns_per_target = __constant_cpu_to_le16(8); |
| 1278 | nv->link_down_timeout = 60; |
| 1279 | |
| 1280 | rval = 1; |
| 1281 | } |
| 1282 | |
| 1283 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 1284 | /* |
| 1285 | * The SN2 does not provide BIOS emulation which means you can't change |
| 1286 | * potentially bogus BIOS settings. Force the use of default settings |
| 1287 | * for link rate and frame size. Hope that the rest of the settings |
| 1288 | * are valid. |
| 1289 | */ |
| 1290 | if (ia64_platform_is("sn2")) { |
| 1291 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 1292 | if (IS_QLA23XX(ha)) |
| 1293 | nv->special_options[1] = BIT_7; |
| 1294 | } |
| 1295 | #endif |
| 1296 | |
| 1297 | /* Reset Initialization control block */ |
| 1298 | memset(icb, 0, sizeof(init_cb_t)); |
| 1299 | |
| 1300 | /* |
| 1301 | * Setup driver NVRAM options. |
| 1302 | */ |
| 1303 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 1304 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 1305 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 1306 | nv->firmware_options[1] &= ~BIT_4; |
| 1307 | |
| 1308 | if (IS_QLA23XX(ha)) { |
| 1309 | nv->firmware_options[0] |= BIT_2; |
| 1310 | nv->firmware_options[0] &= ~BIT_3; |
| 1311 | |
| 1312 | if (IS_QLA2300(ha)) { |
| 1313 | if (ha->fb_rev == FPM_2310) { |
| 1314 | strcpy(ha->model_number, "QLA2310"); |
| 1315 | } else { |
| 1316 | strcpy(ha->model_number, "QLA2300"); |
| 1317 | } |
| 1318 | } else { |
| 1319 | if (rval == 0 && |
| 1320 | memcmp(nv->model_number, BINZERO, |
| 1321 | sizeof(nv->model_number)) != 0) { |
| 1322 | char *st, *en; |
| 1323 | |
| 1324 | strncpy(ha->model_number, nv->model_number, |
| 1325 | sizeof(nv->model_number)); |
| 1326 | st = en = ha->model_number; |
| 1327 | en += sizeof(nv->model_number) - 1; |
| 1328 | while (en > st) { |
| 1329 | if (*en != 0x20 && *en != 0x00) |
| 1330 | break; |
| 1331 | *en-- = '\0'; |
| 1332 | } |
| 1333 | } else { |
| 1334 | uint16_t index; |
| 1335 | |
| 1336 | index = (ha->pdev->subsystem_device & 0xff); |
| 1337 | if (index < QLA_MODEL_NAMES) { |
| 1338 | strcpy(ha->model_number, |
| 1339 | qla2x00_model_name[index]); |
| 1340 | ha->model_desc = |
| 1341 | qla2x00_model_desc[index]; |
| 1342 | } else { |
| 1343 | strcpy(ha->model_number, "QLA23xx"); |
| 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | } else if (IS_QLA2200(ha)) { |
| 1348 | nv->firmware_options[0] |= BIT_2; |
| 1349 | /* |
| 1350 | * 'Point-to-point preferred, else loop' is not a safe |
| 1351 | * connection mode setting. |
| 1352 | */ |
| 1353 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 1354 | (BIT_5 | BIT_4)) { |
| 1355 | /* Force 'loop preferred, else point-to-point'. */ |
| 1356 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 1357 | nv->add_firmware_options[0] |= BIT_5; |
| 1358 | } |
| 1359 | strcpy(ha->model_number, "QLA22xx"); |
| 1360 | } else /*if (IS_QLA2100(ha))*/ { |
| 1361 | strcpy(ha->model_number, "QLA2100"); |
| 1362 | } |
| 1363 | |
| 1364 | /* |
| 1365 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 1366 | */ |
| 1367 | dptr1 = (uint8_t *)icb; |
| 1368 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 1369 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 1370 | while (cnt--) |
| 1371 | *dptr1++ = *dptr2++; |
| 1372 | |
| 1373 | /* Copy 2nd half. */ |
| 1374 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 1375 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 1376 | while (cnt--) |
| 1377 | *dptr1++ = *dptr2++; |
| 1378 | |
| 1379 | /* Prepare nodename */ |
| 1380 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 1381 | /* |
| 1382 | * Firmware will apply the following mask if the nodename was |
| 1383 | * not provided. |
| 1384 | */ |
| 1385 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 1386 | icb->node_name[0] &= 0xF0; |
| 1387 | } |
| 1388 | |
| 1389 | /* |
| 1390 | * Set host adapter parameters. |
| 1391 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 1393 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 1394 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 1395 | ha->flags.disable_risc_code_load = 0; |
| 1396 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 1397 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 1398 | ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0); |
| 1399 | ha->flags.enable_led_scheme = ((nv->efi_parameters & BIT_3) ? 1 : 0); |
| 1400 | |
| 1401 | ha->operating_mode = |
| 1402 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1403 | |
| 1404 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 1405 | sizeof(ha->fw_seriallink_options)); |
| 1406 | |
| 1407 | /* save HBA serial number */ |
| 1408 | ha->serial0 = icb->port_name[5]; |
| 1409 | ha->serial1 = icb->port_name[6]; |
| 1410 | ha->serial2 = icb->port_name[7]; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 1411 | ha->node_name = icb->node_name; |
| 1412 | ha->port_name = icb->port_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | |
| 1414 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 1415 | |
| 1416 | ha->retry_count = nv->retry_count; |
| 1417 | |
| 1418 | /* Set minimum login_timeout to 4 seconds. */ |
| 1419 | if (nv->login_timeout < ql2xlogintimeout) |
| 1420 | nv->login_timeout = ql2xlogintimeout; |
| 1421 | if (nv->login_timeout < 4) |
| 1422 | nv->login_timeout = 4; |
| 1423 | ha->login_timeout = nv->login_timeout; |
| 1424 | icb->login_timeout = nv->login_timeout; |
| 1425 | |
| 1426 | /* Set minimum RATOV to 200 tenths of a second. */ |
| 1427 | ha->r_a_tov = 200; |
| 1428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | ha->loop_reset_delay = nv->reset_delay; |
| 1430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | /* Link Down Timeout = 0: |
| 1432 | * |
| 1433 | * When Port Down timer expires we will start returning |
| 1434 | * I/O's to OS with "DID_NO_CONNECT". |
| 1435 | * |
| 1436 | * Link Down Timeout != 0: |
| 1437 | * |
| 1438 | * The driver waits for the link to come up after link down |
| 1439 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 1440 | */ |
| 1441 | if (nv->link_down_timeout == 0) { |
| 1442 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 1443 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | } else { |
| 1445 | ha->link_down_timeout = nv->link_down_timeout; |
| 1446 | ha->loop_down_abort_time = |
| 1447 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 1448 | } |
| 1449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | /* |
| 1451 | * Need enough time to try and get the port back. |
| 1452 | */ |
| 1453 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 1454 | if (qlport_down_retry) |
| 1455 | ha->port_down_retry_count = qlport_down_retry; |
| 1456 | /* Set login_retry_count */ |
| 1457 | ha->login_retry_count = nv->retry_count; |
| 1458 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 1459 | ha->port_down_retry_count > 3) |
| 1460 | ha->login_retry_count = ha->port_down_retry_count; |
| 1461 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 1462 | ha->login_retry_count = ha->port_down_retry_count; |
| 1463 | if (ql2xloginretrycount) |
| 1464 | ha->login_retry_count = ql2xloginretrycount; |
| 1465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | icb->lun_enables = __constant_cpu_to_le16(0); |
| 1467 | icb->command_resource_count = 0; |
| 1468 | icb->immediate_notify_resource_count = 0; |
| 1469 | icb->timeout = __constant_cpu_to_le16(0); |
| 1470 | |
| 1471 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 1472 | /* Enable RIO */ |
| 1473 | icb->firmware_options[0] &= ~BIT_3; |
| 1474 | icb->add_firmware_options[0] &= |
| 1475 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 1476 | icb->add_firmware_options[0] |= BIT_2; |
| 1477 | icb->response_accumulation_timer = 3; |
| 1478 | icb->interrupt_delay_timer = 5; |
| 1479 | |
| 1480 | ha->flags.process_response_queue = 1; |
| 1481 | } else { |
| 1482 | /* Enable ZIO -- Support mode 5 only. */ |
| 1483 | timer_mode = icb->add_firmware_options[0] & |
| 1484 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 1485 | icb->add_firmware_options[0] &= |
| 1486 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 1487 | if (ql2xenablezio) |
| 1488 | timer_mode = BIT_2 | BIT_0; |
| 1489 | if (timer_mode == (BIT_2 | BIT_0)) { |
| 1490 | DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay " |
| 1491 | "(%d).\n", ha->host_no, ql2xintrdelaytimer)); |
| 1492 | qla_printk(KERN_INFO, ha, |
| 1493 | "ZIO enabled; timer delay (%d).\n", |
| 1494 | ql2xintrdelaytimer); |
| 1495 | |
| 1496 | icb->add_firmware_options[0] |= timer_mode; |
| 1497 | icb->interrupt_delay_timer = ql2xintrdelaytimer; |
| 1498 | ha->flags.process_response_queue = 1; |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | if (rval) { |
| 1503 | DEBUG2_3(printk(KERN_WARNING |
| 1504 | "scsi(%ld): NVRAM configuration failed!\n", ha->host_no)); |
| 1505 | } |
| 1506 | return (rval); |
| 1507 | } |
| 1508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | /** |
| 1510 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 1511 | * @ha: HA context |
| 1512 | * @flags: allocation flags |
| 1513 | * |
| 1514 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 1515 | */ |
| 1516 | fc_port_t * |
| 1517 | qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags) |
| 1518 | { |
| 1519 | fc_port_t *fcport; |
| 1520 | |
| 1521 | fcport = kmalloc(sizeof(fc_port_t), flags); |
| 1522 | if (fcport == NULL) |
| 1523 | return (fcport); |
| 1524 | |
| 1525 | /* Setup fcport template structure. */ |
| 1526 | memset(fcport, 0, sizeof (fc_port_t)); |
| 1527 | fcport->ha = ha; |
| 1528 | fcport->port_type = FCT_UNKNOWN; |
| 1529 | fcport->loop_id = FC_NO_LOOP_ID; |
| 1530 | fcport->iodesc_idx_sent = IODESC_INVALID_INDEX; |
| 1531 | atomic_set(&fcport->state, FCS_UNCONFIGURED); |
| 1532 | fcport->flags = FCF_RLC_SUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | |
| 1534 | return (fcport); |
| 1535 | } |
| 1536 | |
| 1537 | /* |
| 1538 | * qla2x00_configure_loop |
| 1539 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 1540 | * |
| 1541 | * Input: |
| 1542 | * ha = adapter block pointer. |
| 1543 | * |
| 1544 | * Returns: |
| 1545 | * 0 = success. |
| 1546 | * 1 = error. |
| 1547 | * 2 = database was full and device was not configured. |
| 1548 | */ |
| 1549 | static int |
| 1550 | qla2x00_configure_loop(scsi_qla_host_t *ha) |
| 1551 | { |
| 1552 | int rval; |
| 1553 | unsigned long flags, save_flags; |
| 1554 | |
| 1555 | rval = QLA_SUCCESS; |
| 1556 | |
| 1557 | /* Get Initiator ID */ |
| 1558 | if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) { |
| 1559 | rval = qla2x00_configure_hba(ha); |
| 1560 | if (rval != QLA_SUCCESS) { |
| 1561 | DEBUG(printk("scsi(%ld): Unable to configure HBA.\n", |
| 1562 | ha->host_no)); |
| 1563 | return (rval); |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | save_flags = flags = ha->dpc_flags; |
| 1568 | DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n", |
| 1569 | ha->host_no, flags)); |
| 1570 | |
| 1571 | /* |
| 1572 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 1573 | * both at the same time. |
| 1574 | */ |
| 1575 | clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 1576 | clear_bit(RSCN_UPDATE, &ha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
| 1578 | /* Determine what we need to do */ |
| 1579 | if (ha->current_topology == ISP_CFG_FL && |
| 1580 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 1581 | |
| 1582 | ha->flags.rscn_queue_overflow = 1; |
| 1583 | set_bit(RSCN_UPDATE, &flags); |
| 1584 | |
| 1585 | } else if (ha->current_topology == ISP_CFG_F && |
| 1586 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 1587 | |
| 1588 | ha->flags.rscn_queue_overflow = 1; |
| 1589 | set_bit(RSCN_UPDATE, &flags); |
| 1590 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 1591 | |
| 1592 | } else if (!ha->flags.online || |
| 1593 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
| 1594 | |
| 1595 | ha->flags.rscn_queue_overflow = 1; |
| 1596 | set_bit(RSCN_UPDATE, &flags); |
| 1597 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 1598 | } |
| 1599 | |
| 1600 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
| 1601 | if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) { |
| 1602 | rval = QLA_FUNCTION_FAILED; |
| 1603 | } else { |
| 1604 | rval = qla2x00_configure_local_loop(ha); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
| 1609 | if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) { |
| 1610 | rval = QLA_FUNCTION_FAILED; |
| 1611 | } else { |
| 1612 | rval = qla2x00_configure_fabric(ha); |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | if (rval == QLA_SUCCESS) { |
| 1617 | if (atomic_read(&ha->loop_down_timer) || |
| 1618 | test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) { |
| 1619 | rval = QLA_FUNCTION_FAILED; |
| 1620 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | atomic_set(&ha->loop_state, LOOP_READY); |
| 1622 | |
| 1623 | DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no)); |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | if (rval) { |
| 1628 | DEBUG2_3(printk("%s(%ld): *** FAILED ***\n", |
| 1629 | __func__, ha->host_no)); |
| 1630 | } else { |
| 1631 | DEBUG3(printk("%s: exiting normally\n", __func__)); |
| 1632 | } |
| 1633 | |
| 1634 | /* Restore state if a resync event occured during processing */ |
| 1635 | if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) { |
| 1636 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
| 1637 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 1638 | if (test_bit(RSCN_UPDATE, &save_flags)) |
| 1639 | set_bit(RSCN_UPDATE, &ha->dpc_flags); |
| 1640 | } |
| 1641 | |
| 1642 | return (rval); |
| 1643 | } |
| 1644 | |
| 1645 | |
| 1646 | |
| 1647 | /* |
| 1648 | * qla2x00_configure_local_loop |
| 1649 | * Updates Fibre Channel Device Database with local loop devices. |
| 1650 | * |
| 1651 | * Input: |
| 1652 | * ha = adapter block pointer. |
| 1653 | * |
| 1654 | * Returns: |
| 1655 | * 0 = success. |
| 1656 | */ |
| 1657 | static int |
| 1658 | qla2x00_configure_local_loop(scsi_qla_host_t *ha) |
| 1659 | { |
| 1660 | int rval, rval2; |
| 1661 | int found_devs; |
| 1662 | int found; |
| 1663 | fc_port_t *fcport, *new_fcport; |
| 1664 | |
| 1665 | uint16_t index; |
| 1666 | uint16_t entries; |
| 1667 | char *id_iter; |
| 1668 | uint16_t loop_id; |
| 1669 | uint8_t domain, area, al_pa; |
| 1670 | |
| 1671 | found_devs = 0; |
| 1672 | new_fcport = NULL; |
| 1673 | entries = MAX_FIBRE_DEVICES; |
| 1674 | |
| 1675 | DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no)); |
| 1676 | DEBUG3(qla2x00_get_fcal_position_map(ha, NULL)); |
| 1677 | |
| 1678 | /* Get list of logged in devices. */ |
| 1679 | memset(ha->gid_list, 0, GID_LIST_SIZE); |
| 1680 | rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma, |
| 1681 | &entries); |
| 1682 | if (rval != QLA_SUCCESS) |
| 1683 | goto cleanup_allocation; |
| 1684 | |
| 1685 | DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n", |
| 1686 | ha->host_no, entries)); |
| 1687 | DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list, |
| 1688 | entries * sizeof(struct gid_list_info))); |
| 1689 | |
| 1690 | /* Allocate temporary fcport for any new fcports discovered. */ |
| 1691 | new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL); |
| 1692 | if (new_fcport == NULL) { |
| 1693 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 1694 | goto cleanup_allocation; |
| 1695 | } |
| 1696 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 1697 | |
| 1698 | /* |
| 1699 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 1700 | */ |
| 1701 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 1702 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 1703 | fcport->port_type != FCT_BROADCAST && |
| 1704 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 1705 | |
| 1706 | DEBUG(printk("scsi(%ld): Marking port lost, " |
| 1707 | "loop_id=0x%04x\n", |
| 1708 | ha->host_no, fcport->loop_id)); |
| 1709 | |
| 1710 | atomic_set(&fcport->state, FCS_DEVICE_LOST); |
| 1711 | fcport->flags &= ~FCF_FARP_DONE; |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | /* Add devices to port list. */ |
| 1716 | id_iter = (char *)ha->gid_list; |
| 1717 | for (index = 0; index < entries; index++) { |
| 1718 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 1719 | area = ((struct gid_list_info *)id_iter)->area; |
| 1720 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1721 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | loop_id = (uint16_t) |
| 1723 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1724 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | loop_id = le16_to_cpu( |
| 1726 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1727 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | |
| 1729 | /* Bypass reserved domain fields. */ |
| 1730 | if ((domain & 0xf0) == 0xf0) |
| 1731 | continue; |
| 1732 | |
| 1733 | /* Bypass if not same domain and area of adapter. */ |
| 1734 | if (area != ha->d_id.b.area || domain != ha->d_id.b.domain) |
| 1735 | continue; |
| 1736 | |
| 1737 | /* Bypass invalid local loop ID. */ |
| 1738 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 1739 | continue; |
| 1740 | |
| 1741 | /* Fill in member data. */ |
| 1742 | new_fcport->d_id.b.domain = domain; |
| 1743 | new_fcport->d_id.b.area = area; |
| 1744 | new_fcport->d_id.b.al_pa = al_pa; |
| 1745 | new_fcport->loop_id = loop_id; |
| 1746 | rval2 = qla2x00_get_port_database(ha, new_fcport, 0); |
| 1747 | if (rval2 != QLA_SUCCESS) { |
| 1748 | DEBUG2(printk("scsi(%ld): Failed to retrieve fcport " |
| 1749 | "information -- get_port_database=%x, " |
| 1750 | "loop_id=0x%04x\n", |
| 1751 | ha->host_no, rval2, new_fcport->loop_id)); |
| 1752 | continue; |
| 1753 | } |
| 1754 | |
| 1755 | /* Check for matching device in port list. */ |
| 1756 | found = 0; |
| 1757 | fcport = NULL; |
| 1758 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 1759 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 1760 | WWN_SIZE)) |
| 1761 | continue; |
| 1762 | |
| 1763 | fcport->flags &= ~(FCF_FABRIC_DEVICE | |
| 1764 | FCF_PERSISTENT_BOUND); |
| 1765 | fcport->loop_id = new_fcport->loop_id; |
| 1766 | fcport->port_type = new_fcport->port_type; |
| 1767 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 1768 | memcpy(fcport->node_name, new_fcport->node_name, |
| 1769 | WWN_SIZE); |
| 1770 | |
| 1771 | found++; |
| 1772 | break; |
| 1773 | } |
| 1774 | |
| 1775 | if (!found) { |
| 1776 | /* New device, add to fcports list. */ |
| 1777 | new_fcport->flags &= ~FCF_PERSISTENT_BOUND; |
| 1778 | list_add_tail(&new_fcport->list, &ha->fcports); |
| 1779 | |
| 1780 | /* Allocate a new replacement fcport. */ |
| 1781 | fcport = new_fcport; |
| 1782 | new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL); |
| 1783 | if (new_fcport == NULL) { |
| 1784 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 1785 | goto cleanup_allocation; |
| 1786 | } |
| 1787 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 1788 | } |
| 1789 | |
| 1790 | qla2x00_update_fcport(ha, fcport); |
| 1791 | |
| 1792 | found_devs++; |
| 1793 | } |
| 1794 | |
| 1795 | cleanup_allocation: |
| 1796 | if (new_fcport) |
| 1797 | kfree(new_fcport); |
| 1798 | |
| 1799 | if (rval != QLA_SUCCESS) { |
| 1800 | DEBUG2(printk("scsi(%ld): Configure local loop error exit: " |
| 1801 | "rval=%x\n", ha->host_no, rval)); |
| 1802 | } |
| 1803 | |
| 1804 | if (found_devs) { |
| 1805 | ha->device_flags |= DFLG_LOCAL_DEVICES; |
| 1806 | ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES; |
| 1807 | } |
| 1808 | |
| 1809 | return (rval); |
| 1810 | } |
| 1811 | |
| 1812 | static void |
| 1813 | qla2x00_probe_for_all_luns(scsi_qla_host_t *ha) |
| 1814 | { |
| 1815 | fc_port_t *fcport; |
| 1816 | |
| 1817 | qla2x00_mark_all_devices_lost(ha); |
| 1818 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 1819 | if (fcport->port_type != FCT_TARGET) |
| 1820 | continue; |
| 1821 | |
| 1822 | qla2x00_update_fcport(ha, fcport); |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | /* |
| 1827 | * qla2x00_update_fcport |
| 1828 | * Updates device on list. |
| 1829 | * |
| 1830 | * Input: |
| 1831 | * ha = adapter block pointer. |
| 1832 | * fcport = port structure pointer. |
| 1833 | * |
| 1834 | * Return: |
| 1835 | * 0 - Success |
| 1836 | * BIT_0 - error |
| 1837 | * |
| 1838 | * Context: |
| 1839 | * Kernel context. |
| 1840 | */ |
| 1841 | static void |
| 1842 | qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport) |
| 1843 | { |
| 1844 | uint16_t index; |
| 1845 | unsigned long flags; |
| 1846 | srb_t *sp; |
| 1847 | |
| 1848 | fcport->ha = ha; |
| 1849 | fcport->login_retry = 0; |
| 1850 | fcport->port_login_retry_count = ha->port_down_retry_count * |
| 1851 | PORT_RETRY_TIME; |
| 1852 | atomic_set(&fcport->port_down_timer, ha->port_down_retry_count * |
| 1853 | PORT_RETRY_TIME); |
| 1854 | fcport->flags &= ~FCF_LOGIN_NEEDED; |
| 1855 | |
| 1856 | /* |
| 1857 | * Check for outstanding cmd on tape Bypass LUN discovery if active |
| 1858 | * command on tape. |
| 1859 | */ |
| 1860 | if (fcport->flags & FCF_TAPE_PRESENT) { |
| 1861 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1862 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1863 | fc_port_t *sfcp; |
| 1864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | if ((sp = ha->outstanding_cmds[index]) != 0) { |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1866 | sfcp = sp->fcport; |
| 1867 | if (sfcp == fcport) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | atomic_set(&fcport->state, FCS_ONLINE); |
| 1869 | spin_unlock_irqrestore( |
| 1870 | &ha->hardware_lock, flags); |
| 1871 | return; |
| 1872 | } |
| 1873 | } |
| 1874 | } |
| 1875 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1876 | } |
| 1877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | if (fcport->port_type == FCT_INITIATOR || |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1879 | fcport->port_type == FCT_BROADCAST) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | fcport->device_type = TYPE_PROCESSOR; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | atomic_set(&fcport->state, FCS_ONLINE); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1883 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1884 | if (ha->flags.init_done) |
| 1885 | qla2x00_reg_remote_port(ha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1888 | void |
| 1889 | qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport) |
| 1890 | { |
| 1891 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1892 | struct fc_rport *rport; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1893 | |
| 1894 | if (fcport->rport) { |
| 1895 | fc_remote_port_unblock(fcport->rport); |
| 1896 | return; |
| 1897 | } |
| 1898 | |
| 1899 | rport_ids.node_name = be64_to_cpu(*(uint64_t *)fcport->node_name); |
| 1900 | rport_ids.port_name = be64_to_cpu(*(uint64_t *)fcport->port_name); |
| 1901 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 1902 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 1903 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 1904 | if (fcport->port_type == FCT_INITIATOR) |
| 1905 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 1906 | if (fcport->port_type == FCT_TARGET) |
| 1907 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 1908 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1909 | fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids); |
| 1910 | if (!rport) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1911 | qla_printk(KERN_WARNING, ha, |
| 1912 | "Unable to allocate fc remote port!\n"); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1913 | |
| 1914 | if (rport->scsi_target_id != -1 && rport->scsi_target_id < MAX_TARGETS) |
| 1915 | fcport->os_target_id = rport->scsi_target_id; |
| 1916 | |
| 1917 | rport->dd_data = fcport; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
| 1920 | /* |
| 1921 | * qla2x00_configure_fabric |
| 1922 | * Setup SNS devices with loop ID's. |
| 1923 | * |
| 1924 | * Input: |
| 1925 | * ha = adapter block pointer. |
| 1926 | * |
| 1927 | * Returns: |
| 1928 | * 0 = success. |
| 1929 | * BIT_0 = error |
| 1930 | */ |
| 1931 | static int |
| 1932 | qla2x00_configure_fabric(scsi_qla_host_t *ha) |
| 1933 | { |
| 1934 | int rval, rval2; |
| 1935 | fc_port_t *fcport, *fcptemp; |
| 1936 | uint16_t next_loopid; |
| 1937 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 1938 | LIST_HEAD(new_fcports); |
| 1939 | |
| 1940 | /* If FL port exists, then SNS is present */ |
| 1941 | rval = qla2x00_get_port_name(ha, SNS_FL_PORT, NULL, 0); |
| 1942 | if (rval != QLA_SUCCESS) { |
| 1943 | DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL " |
| 1944 | "Port\n", ha->host_no)); |
| 1945 | |
| 1946 | ha->device_flags &= ~SWITCH_FOUND; |
| 1947 | return (QLA_SUCCESS); |
| 1948 | } |
| 1949 | |
| 1950 | /* Mark devices that need re-synchronization. */ |
| 1951 | rval2 = qla2x00_device_resync(ha); |
| 1952 | if (rval2 == QLA_RSCNS_HANDLED) { |
| 1953 | /* No point doing the scan, just continue. */ |
| 1954 | return (QLA_SUCCESS); |
| 1955 | } |
| 1956 | do { |
| 1957 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1958 | ha->isp_ops.fabric_login(ha, SIMPLE_NAME_SERVER, 0xff, 0xff, |
| 1959 | 0xfc, mb, BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
| 1961 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 1962 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 1963 | "mb[2]=%x mb[6]=%x mb[7]=%x\n", SIMPLE_NAME_SERVER, |
| 1964 | mb[0], mb[1], mb[2], mb[6], mb[7])); |
| 1965 | return (QLA_SUCCESS); |
| 1966 | } |
| 1967 | |
| 1968 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) { |
| 1969 | if (qla2x00_rft_id(ha)) { |
| 1970 | /* EMPTY */ |
| 1971 | DEBUG2(printk("scsi(%ld): Register FC-4 " |
| 1972 | "TYPE failed.\n", ha->host_no)); |
| 1973 | } |
| 1974 | if (qla2x00_rff_id(ha)) { |
| 1975 | /* EMPTY */ |
| 1976 | DEBUG2(printk("scsi(%ld): Register FC-4 " |
| 1977 | "Features failed.\n", ha->host_no)); |
| 1978 | } |
| 1979 | if (qla2x00_rnn_id(ha)) { |
| 1980 | /* EMPTY */ |
| 1981 | DEBUG2(printk("scsi(%ld): Register Node Name " |
| 1982 | "failed.\n", ha->host_no)); |
| 1983 | } else if (qla2x00_rsnn_nn(ha)) { |
| 1984 | /* EMPTY */ |
| 1985 | DEBUG2(printk("scsi(%ld): Register Symbolic " |
| 1986 | "Node Name failed.\n", ha->host_no)); |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | rval = qla2x00_find_all_fabric_devs(ha, &new_fcports); |
| 1991 | if (rval != QLA_SUCCESS) |
| 1992 | break; |
| 1993 | |
| 1994 | /* |
| 1995 | * Logout all previous fabric devices marked lost, except |
| 1996 | * tape devices. |
| 1997 | */ |
| 1998 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 1999 | if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) |
| 2000 | break; |
| 2001 | |
| 2002 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) |
| 2003 | continue; |
| 2004 | |
| 2005 | if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) { |
| 2006 | qla2x00_mark_device_lost(ha, fcport, |
| 2007 | ql2xplogiabsentdevice); |
| 2008 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 2009 | (fcport->flags & FCF_TAPE_PRESENT) == 0 && |
| 2010 | fcport->port_type != FCT_INITIATOR && |
| 2011 | fcport->port_type != FCT_BROADCAST) { |
| 2012 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2013 | ha->isp_ops.fabric_logout(ha, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | fcport->loop_id); |
| 2015 | fcport->loop_id = FC_NO_LOOP_ID; |
| 2016 | } |
| 2017 | } |
| 2018 | } |
| 2019 | |
| 2020 | /* Starting free loop ID. */ |
| 2021 | next_loopid = ha->min_external_loopid; |
| 2022 | |
| 2023 | /* |
| 2024 | * Scan through our port list and login entries that need to be |
| 2025 | * logged in. |
| 2026 | */ |
| 2027 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 2028 | if (atomic_read(&ha->loop_down_timer) || |
| 2029 | test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) |
| 2030 | break; |
| 2031 | |
| 2032 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 2033 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 2034 | continue; |
| 2035 | |
| 2036 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 2037 | fcport->loop_id = next_loopid; |
| 2038 | rval = qla2x00_find_new_loop_id(ha, fcport); |
| 2039 | if (rval != QLA_SUCCESS) { |
| 2040 | /* Ran out of IDs to use */ |
| 2041 | break; |
| 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | /* Login and update database */ |
| 2046 | qla2x00_fabric_dev_login(ha, fcport, &next_loopid); |
| 2047 | } |
| 2048 | |
| 2049 | /* Exit if out of loop IDs. */ |
| 2050 | if (rval != QLA_SUCCESS) { |
| 2051 | break; |
| 2052 | } |
| 2053 | |
| 2054 | /* |
| 2055 | * Login and add the new devices to our port list. |
| 2056 | */ |
| 2057 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
| 2058 | if (atomic_read(&ha->loop_down_timer) || |
| 2059 | test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) |
| 2060 | break; |
| 2061 | |
| 2062 | /* Find a new loop ID to use. */ |
| 2063 | fcport->loop_id = next_loopid; |
| 2064 | rval = qla2x00_find_new_loop_id(ha, fcport); |
| 2065 | if (rval != QLA_SUCCESS) { |
| 2066 | /* Ran out of IDs to use */ |
| 2067 | break; |
| 2068 | } |
| 2069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | /* Remove device from the new list and add it to DB */ |
| 2071 | list_del(&fcport->list); |
| 2072 | list_add_tail(&fcport->list, &ha->fcports); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2073 | |
| 2074 | /* Login and update database */ |
| 2075 | qla2x00_fabric_dev_login(ha, fcport, &next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | } |
| 2077 | } while (0); |
| 2078 | |
| 2079 | /* Free all new device structures not processed. */ |
| 2080 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
| 2081 | list_del(&fcport->list); |
| 2082 | kfree(fcport); |
| 2083 | } |
| 2084 | |
| 2085 | if (rval) { |
| 2086 | DEBUG2(printk("scsi(%ld): Configure fabric error exit: " |
| 2087 | "rval=%d\n", ha->host_no, rval)); |
| 2088 | } |
| 2089 | |
| 2090 | return (rval); |
| 2091 | } |
| 2092 | |
| 2093 | |
| 2094 | /* |
| 2095 | * qla2x00_find_all_fabric_devs |
| 2096 | * |
| 2097 | * Input: |
| 2098 | * ha = adapter block pointer. |
| 2099 | * dev = database device entry pointer. |
| 2100 | * |
| 2101 | * Returns: |
| 2102 | * 0 = success. |
| 2103 | * |
| 2104 | * Context: |
| 2105 | * Kernel context. |
| 2106 | */ |
| 2107 | static int |
| 2108 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports) |
| 2109 | { |
| 2110 | int rval; |
| 2111 | uint16_t loop_id; |
| 2112 | fc_port_t *fcport, *new_fcport, *fcptemp; |
| 2113 | int found; |
| 2114 | |
| 2115 | sw_info_t *swl; |
| 2116 | int swl_idx; |
| 2117 | int first_dev, last_dev; |
| 2118 | port_id_t wrap, nxt_d_id; |
| 2119 | |
| 2120 | rval = QLA_SUCCESS; |
| 2121 | |
| 2122 | /* Try GID_PT to get device list, else GAN. */ |
| 2123 | swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC); |
| 2124 | if (swl == NULL) { |
| 2125 | /*EMPTY*/ |
| 2126 | DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback " |
| 2127 | "on GA_NXT\n", ha->host_no)); |
| 2128 | } else { |
| 2129 | memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES); |
| 2130 | if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) { |
| 2131 | kfree(swl); |
| 2132 | swl = NULL; |
| 2133 | } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) { |
| 2134 | kfree(swl); |
| 2135 | swl = NULL; |
| 2136 | } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) { |
| 2137 | kfree(swl); |
| 2138 | swl = NULL; |
| 2139 | } |
| 2140 | } |
| 2141 | swl_idx = 0; |
| 2142 | |
| 2143 | /* Allocate temporary fcport for any new fcports discovered. */ |
| 2144 | new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL); |
| 2145 | if (new_fcport == NULL) { |
| 2146 | if (swl) |
| 2147 | kfree(swl); |
| 2148 | return (QLA_MEMORY_ALLOC_FAILED); |
| 2149 | } |
| 2150 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 2151 | |
| 2152 | /* Set start port ID scan at adapter ID. */ |
| 2153 | first_dev = 1; |
| 2154 | last_dev = 0; |
| 2155 | |
| 2156 | /* Starting free loop ID. */ |
| 2157 | loop_id = ha->min_external_loopid; |
| 2158 | |
| 2159 | for (; loop_id <= ha->last_loop_id; loop_id++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 2160 | if (qla2x00_is_reserved_id(ha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | continue; |
| 2162 | |
| 2163 | if (atomic_read(&ha->loop_down_timer) || |
| 2164 | test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) |
| 2165 | break; |
| 2166 | |
| 2167 | if (swl != NULL) { |
| 2168 | if (last_dev) { |
| 2169 | wrap.b24 = new_fcport->d_id.b24; |
| 2170 | } else { |
| 2171 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 2172 | memcpy(new_fcport->node_name, |
| 2173 | swl[swl_idx].node_name, WWN_SIZE); |
| 2174 | memcpy(new_fcport->port_name, |
| 2175 | swl[swl_idx].port_name, WWN_SIZE); |
| 2176 | |
| 2177 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 2178 | last_dev = 1; |
| 2179 | } |
| 2180 | swl_idx++; |
| 2181 | } |
| 2182 | } else { |
| 2183 | /* Send GA_NXT to the switch */ |
| 2184 | rval = qla2x00_ga_nxt(ha, new_fcport); |
| 2185 | if (rval != QLA_SUCCESS) { |
| 2186 | qla_printk(KERN_WARNING, ha, |
| 2187 | "SNS scan failed -- assuming zero-entry " |
| 2188 | "result...\n"); |
| 2189 | list_for_each_entry_safe(fcport, fcptemp, |
| 2190 | new_fcports, list) { |
| 2191 | list_del(&fcport->list); |
| 2192 | kfree(fcport); |
| 2193 | } |
| 2194 | rval = QLA_SUCCESS; |
| 2195 | break; |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | /* If wrap on switch device list, exit. */ |
| 2200 | if (first_dev) { |
| 2201 | wrap.b24 = new_fcport->d_id.b24; |
| 2202 | first_dev = 0; |
| 2203 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
| 2204 | DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n", |
| 2205 | ha->host_no, new_fcport->d_id.b.domain, |
| 2206 | new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa)); |
| 2207 | break; |
| 2208 | } |
| 2209 | |
| 2210 | /* Bypass if host adapter. */ |
| 2211 | if (new_fcport->d_id.b24 == ha->d_id.b24) |
| 2212 | continue; |
| 2213 | |
| 2214 | /* Bypass reserved domain fields. */ |
| 2215 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 2216 | continue; |
| 2217 | |
| 2218 | /* Locate matching device in database. */ |
| 2219 | found = 0; |
| 2220 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 2221 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 2222 | WWN_SIZE)) |
| 2223 | continue; |
| 2224 | |
| 2225 | found++; |
| 2226 | |
| 2227 | /* |
| 2228 | * If address the same and state FCS_ONLINE, nothing |
| 2229 | * changed. |
| 2230 | */ |
| 2231 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
| 2232 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 2233 | break; |
| 2234 | } |
| 2235 | |
| 2236 | /* |
| 2237 | * If device was not a fabric device before. |
| 2238 | */ |
| 2239 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 2240 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2241 | fcport->loop_id = FC_NO_LOOP_ID; |
| 2242 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 2243 | FCF_LOGIN_NEEDED); |
| 2244 | fcport->flags &= ~FCF_PERSISTENT_BOUND; |
| 2245 | break; |
| 2246 | } |
| 2247 | |
| 2248 | /* |
| 2249 | * Port ID changed or device was marked to be updated; |
| 2250 | * Log it out if still logged in and mark it for |
| 2251 | * relogin later. |
| 2252 | */ |
| 2253 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2254 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 2255 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 2256 | (fcport->flags & FCF_TAPE_PRESENT) == 0 && |
| 2257 | fcport->port_type != FCT_INITIATOR && |
| 2258 | fcport->port_type != FCT_BROADCAST) { |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2259 | ha->isp_ops.fabric_logout(ha, fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | fcport->loop_id = FC_NO_LOOP_ID; |
| 2261 | } |
| 2262 | |
| 2263 | break; |
| 2264 | } |
| 2265 | |
| 2266 | if (found) |
| 2267 | continue; |
| 2268 | |
| 2269 | /* If device was not in our fcports list, then add it. */ |
| 2270 | list_add_tail(&new_fcport->list, new_fcports); |
| 2271 | |
| 2272 | /* Allocate a new replacement fcport. */ |
| 2273 | nxt_d_id.b24 = new_fcport->d_id.b24; |
| 2274 | new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL); |
| 2275 | if (new_fcport == NULL) { |
| 2276 | if (swl) |
| 2277 | kfree(swl); |
| 2278 | return (QLA_MEMORY_ALLOC_FAILED); |
| 2279 | } |
| 2280 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 2281 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 2282 | } |
| 2283 | |
| 2284 | if (swl) |
| 2285 | kfree(swl); |
| 2286 | |
| 2287 | if (new_fcport) |
| 2288 | kfree(new_fcport); |
| 2289 | |
| 2290 | if (!list_empty(new_fcports)) |
| 2291 | ha->device_flags |= DFLG_FABRIC_DEVICES; |
| 2292 | |
| 2293 | return (rval); |
| 2294 | } |
| 2295 | |
| 2296 | /* |
| 2297 | * qla2x00_find_new_loop_id |
| 2298 | * Scan through our port list and find a new usable loop ID. |
| 2299 | * |
| 2300 | * Input: |
| 2301 | * ha: adapter state pointer. |
| 2302 | * dev: port structure pointer. |
| 2303 | * |
| 2304 | * Returns: |
| 2305 | * qla2x00 local function return status code. |
| 2306 | * |
| 2307 | * Context: |
| 2308 | * Kernel context. |
| 2309 | */ |
| 2310 | int |
| 2311 | qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev) |
| 2312 | { |
| 2313 | int rval; |
| 2314 | int found; |
| 2315 | fc_port_t *fcport; |
| 2316 | uint16_t first_loop_id; |
| 2317 | |
| 2318 | rval = QLA_SUCCESS; |
| 2319 | |
| 2320 | /* Save starting loop ID. */ |
| 2321 | first_loop_id = dev->loop_id; |
| 2322 | |
| 2323 | for (;;) { |
| 2324 | /* Skip loop ID if already used by adapter. */ |
| 2325 | if (dev->loop_id == ha->loop_id) { |
| 2326 | dev->loop_id++; |
| 2327 | } |
| 2328 | |
| 2329 | /* Skip reserved loop IDs. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 2330 | while (qla2x00_is_reserved_id(ha, dev->loop_id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | dev->loop_id++; |
| 2332 | } |
| 2333 | |
| 2334 | /* Reset loop ID if passed the end. */ |
| 2335 | if (dev->loop_id > ha->last_loop_id) { |
| 2336 | /* first loop ID. */ |
| 2337 | dev->loop_id = ha->min_external_loopid; |
| 2338 | } |
| 2339 | |
| 2340 | /* Check for loop ID being already in use. */ |
| 2341 | found = 0; |
| 2342 | fcport = NULL; |
| 2343 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 2344 | if (fcport->loop_id == dev->loop_id && fcport != dev) { |
| 2345 | /* ID possibly in use */ |
| 2346 | found++; |
| 2347 | break; |
| 2348 | } |
| 2349 | } |
| 2350 | |
| 2351 | /* If not in use then it is free to use. */ |
| 2352 | if (!found) { |
| 2353 | break; |
| 2354 | } |
| 2355 | |
| 2356 | /* ID in use. Try next value. */ |
| 2357 | dev->loop_id++; |
| 2358 | |
| 2359 | /* If wrap around. No free ID to use. */ |
| 2360 | if (dev->loop_id == first_loop_id) { |
| 2361 | dev->loop_id = FC_NO_LOOP_ID; |
| 2362 | rval = QLA_FUNCTION_FAILED; |
| 2363 | break; |
| 2364 | } |
| 2365 | } |
| 2366 | |
| 2367 | return (rval); |
| 2368 | } |
| 2369 | |
| 2370 | /* |
| 2371 | * qla2x00_device_resync |
| 2372 | * Marks devices in the database that needs resynchronization. |
| 2373 | * |
| 2374 | * Input: |
| 2375 | * ha = adapter block pointer. |
| 2376 | * |
| 2377 | * Context: |
| 2378 | * Kernel context. |
| 2379 | */ |
| 2380 | static int |
| 2381 | qla2x00_device_resync(scsi_qla_host_t *ha) |
| 2382 | { |
| 2383 | int rval; |
| 2384 | int rval2; |
| 2385 | uint32_t mask; |
| 2386 | fc_port_t *fcport; |
| 2387 | uint32_t rscn_entry; |
| 2388 | uint8_t rscn_out_iter; |
| 2389 | uint8_t format; |
| 2390 | port_id_t d_id; |
| 2391 | |
| 2392 | rval = QLA_RSCNS_HANDLED; |
| 2393 | |
| 2394 | while (ha->rscn_out_ptr != ha->rscn_in_ptr || |
| 2395 | ha->flags.rscn_queue_overflow) { |
| 2396 | |
| 2397 | rscn_entry = ha->rscn_queue[ha->rscn_out_ptr]; |
| 2398 | format = MSB(MSW(rscn_entry)); |
| 2399 | d_id.b.domain = LSB(MSW(rscn_entry)); |
| 2400 | d_id.b.area = MSB(LSW(rscn_entry)); |
| 2401 | d_id.b.al_pa = LSB(LSW(rscn_entry)); |
| 2402 | |
| 2403 | DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = " |
| 2404 | "[%02x/%02x%02x%02x].\n", |
| 2405 | ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain, |
| 2406 | d_id.b.area, d_id.b.al_pa)); |
| 2407 | |
| 2408 | ha->rscn_out_ptr++; |
| 2409 | if (ha->rscn_out_ptr == MAX_RSCN_COUNT) |
| 2410 | ha->rscn_out_ptr = 0; |
| 2411 | |
| 2412 | /* Skip duplicate entries. */ |
| 2413 | for (rscn_out_iter = ha->rscn_out_ptr; |
| 2414 | !ha->flags.rscn_queue_overflow && |
| 2415 | rscn_out_iter != ha->rscn_in_ptr; |
| 2416 | rscn_out_iter = (rscn_out_iter == |
| 2417 | (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) { |
| 2418 | |
| 2419 | if (rscn_entry != ha->rscn_queue[rscn_out_iter]) |
| 2420 | break; |
| 2421 | |
| 2422 | DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue " |
| 2423 | "entry found at [%d].\n", ha->host_no, |
| 2424 | rscn_out_iter)); |
| 2425 | |
| 2426 | ha->rscn_out_ptr = rscn_out_iter; |
| 2427 | } |
| 2428 | |
| 2429 | /* Queue overflow, set switch default case. */ |
| 2430 | if (ha->flags.rscn_queue_overflow) { |
| 2431 | DEBUG(printk("scsi(%ld): device_resync: rscn " |
| 2432 | "overflow.\n", ha->host_no)); |
| 2433 | |
| 2434 | format = 3; |
| 2435 | ha->flags.rscn_queue_overflow = 0; |
| 2436 | } |
| 2437 | |
| 2438 | switch (format) { |
| 2439 | case 0: |
| 2440 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && |
| 2441 | !IS_QLA6312(ha) && !IS_QLA6322(ha) && |
| 2442 | ha->flags.init_done) { |
| 2443 | /* Handle port RSCN via asyncronous IOCBs */ |
| 2444 | rval2 = qla2x00_handle_port_rscn(ha, rscn_entry, |
| 2445 | NULL, 0); |
| 2446 | if (rval2 == QLA_SUCCESS) |
| 2447 | continue; |
| 2448 | } |
| 2449 | mask = 0xffffff; |
| 2450 | break; |
| 2451 | case 1: |
| 2452 | mask = 0xffff00; |
| 2453 | break; |
| 2454 | case 2: |
| 2455 | mask = 0xff0000; |
| 2456 | break; |
| 2457 | default: |
| 2458 | mask = 0x0; |
| 2459 | d_id.b24 = 0; |
| 2460 | ha->rscn_out_ptr = ha->rscn_in_ptr; |
| 2461 | break; |
| 2462 | } |
| 2463 | |
| 2464 | rval = QLA_SUCCESS; |
| 2465 | |
| 2466 | /* Abort any outstanding IO descriptors. */ |
| 2467 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 2468 | qla2x00_cancel_io_descriptors(ha); |
| 2469 | |
| 2470 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 2471 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 2472 | (fcport->d_id.b24 & mask) != d_id.b24 || |
| 2473 | fcport->port_type == FCT_BROADCAST) |
| 2474 | continue; |
| 2475 | |
| 2476 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
| 2477 | if (format != 3 || |
| 2478 | fcport->port_type != FCT_INITIATOR) { |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2479 | qla2x00_mark_device_lost(ha, fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | } |
| 2481 | } |
| 2482 | fcport->flags &= ~FCF_FARP_DONE; |
| 2483 | } |
| 2484 | } |
| 2485 | return (rval); |
| 2486 | } |
| 2487 | |
| 2488 | /* |
| 2489 | * qla2x00_fabric_dev_login |
| 2490 | * Login fabric target device and update FC port database. |
| 2491 | * |
| 2492 | * Input: |
| 2493 | * ha: adapter state pointer. |
| 2494 | * fcport: port structure list pointer. |
| 2495 | * next_loopid: contains value of a new loop ID that can be used |
| 2496 | * by the next login attempt. |
| 2497 | * |
| 2498 | * Returns: |
| 2499 | * qla2x00 local function return status code. |
| 2500 | * |
| 2501 | * Context: |
| 2502 | * Kernel context. |
| 2503 | */ |
| 2504 | static int |
| 2505 | qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport, |
| 2506 | uint16_t *next_loopid) |
| 2507 | { |
| 2508 | int rval; |
| 2509 | int retry; |
| 2510 | |
| 2511 | rval = QLA_SUCCESS; |
| 2512 | retry = 0; |
| 2513 | |
| 2514 | rval = qla2x00_fabric_login(ha, fcport, next_loopid); |
| 2515 | if (rval == QLA_SUCCESS) { |
| 2516 | rval = qla2x00_get_port_database(ha, fcport, 0); |
| 2517 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2518 | ha->isp_ops.fabric_logout(ha, fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | } else { |
| 2520 | qla2x00_update_fcport(ha, fcport); |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | return (rval); |
| 2525 | } |
| 2526 | |
| 2527 | /* |
| 2528 | * qla2x00_fabric_login |
| 2529 | * Issue fabric login command. |
| 2530 | * |
| 2531 | * Input: |
| 2532 | * ha = adapter block pointer. |
| 2533 | * device = pointer to FC device type structure. |
| 2534 | * |
| 2535 | * Returns: |
| 2536 | * 0 - Login successfully |
| 2537 | * 1 - Login failed |
| 2538 | * 2 - Initiator device |
| 2539 | * 3 - Fatal error |
| 2540 | */ |
| 2541 | int |
| 2542 | qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport, |
| 2543 | uint16_t *next_loopid) |
| 2544 | { |
| 2545 | int rval; |
| 2546 | int retry; |
| 2547 | uint16_t tmp_loopid; |
| 2548 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 2549 | |
| 2550 | retry = 0; |
| 2551 | tmp_loopid = 0; |
| 2552 | |
| 2553 | for (;;) { |
| 2554 | DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x " |
| 2555 | "for port %02x%02x%02x.\n", |
| 2556 | ha->host_no, fcport->loop_id, fcport->d_id.b.domain, |
| 2557 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 2558 | |
| 2559 | /* Login fcport on switch. */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2560 | ha->isp_ops.fabric_login(ha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 2562 | fcport->d_id.b.al_pa, mb, BIT_0); |
| 2563 | if (mb[0] == MBS_PORT_ID_USED) { |
| 2564 | /* |
| 2565 | * Device has another loop ID. The firmware team |
| 2566 | * recommends us to perform an implicit login with the |
| 2567 | * specified ID again. The ID we just used is save here |
| 2568 | * so we return with an ID that can be tried by the |
| 2569 | * next login. |
| 2570 | */ |
| 2571 | retry++; |
| 2572 | tmp_loopid = fcport->loop_id; |
| 2573 | fcport->loop_id = mb[1]; |
| 2574 | |
| 2575 | DEBUG(printk("Fabric Login: port in use - next " |
| 2576 | "loop id=0x%04x, port Id=%02x%02x%02x.\n", |
| 2577 | fcport->loop_id, fcport->d_id.b.domain, |
| 2578 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 2579 | |
| 2580 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 2581 | /* |
| 2582 | * Login succeeded. |
| 2583 | */ |
| 2584 | if (retry) { |
| 2585 | /* A retry occurred before. */ |
| 2586 | *next_loopid = tmp_loopid; |
| 2587 | } else { |
| 2588 | /* |
| 2589 | * No retry occurred before. Just increment the |
| 2590 | * ID value for next login. |
| 2591 | */ |
| 2592 | *next_loopid = (fcport->loop_id + 1); |
| 2593 | } |
| 2594 | |
| 2595 | if (mb[1] & BIT_0) { |
| 2596 | fcport->port_type = FCT_INITIATOR; |
| 2597 | } else { |
| 2598 | fcport->port_type = FCT_TARGET; |
| 2599 | if (mb[1] & BIT_1) { |
| 2600 | fcport->flags |= FCF_TAPE_PRESENT; |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | rval = QLA_SUCCESS; |
| 2605 | break; |
| 2606 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 2607 | /* |
| 2608 | * Loop ID already used, try next loop ID. |
| 2609 | */ |
| 2610 | fcport->loop_id++; |
| 2611 | rval = qla2x00_find_new_loop_id(ha, fcport); |
| 2612 | if (rval != QLA_SUCCESS) { |
| 2613 | /* Ran out of loop IDs to use */ |
| 2614 | break; |
| 2615 | } |
| 2616 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 2617 | /* |
| 2618 | * Firmware possibly timed out during login. If NO |
| 2619 | * retries are left to do then the device is declared |
| 2620 | * dead. |
| 2621 | */ |
| 2622 | *next_loopid = fcport->loop_id; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2623 | ha->isp_ops.fabric_logout(ha, fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | qla2x00_mark_device_lost(ha, fcport, 1); |
| 2625 | |
| 2626 | rval = 1; |
| 2627 | break; |
| 2628 | } else { |
| 2629 | /* |
| 2630 | * unrecoverable / not handled error |
| 2631 | */ |
| 2632 | DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x " |
| 2633 | "loop_id=%x jiffies=%lx.\n", |
| 2634 | __func__, ha->host_no, mb[0], |
| 2635 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 2636 | fcport->d_id.b.al_pa, fcport->loop_id, jiffies)); |
| 2637 | |
| 2638 | *next_loopid = fcport->loop_id; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2639 | ha->isp_ops.fabric_logout(ha, fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | fcport->loop_id = FC_NO_LOOP_ID; |
| 2641 | atomic_set(&fcport->state, FCS_DEVICE_DEAD); |
| 2642 | |
| 2643 | rval = 3; |
| 2644 | break; |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | return (rval); |
| 2649 | } |
| 2650 | |
| 2651 | /* |
| 2652 | * qla2x00_local_device_login |
| 2653 | * Issue local device login command. |
| 2654 | * |
| 2655 | * Input: |
| 2656 | * ha = adapter block pointer. |
| 2657 | * loop_id = loop id of device to login to. |
| 2658 | * |
| 2659 | * Returns (Where's the #define!!!!): |
| 2660 | * 0 - Login successfully |
| 2661 | * 1 - Login failed |
| 2662 | * 3 - Fatal error |
| 2663 | */ |
| 2664 | int |
| 2665 | qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id) |
| 2666 | { |
| 2667 | int rval; |
| 2668 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 2669 | |
| 2670 | memset(mb, 0, sizeof(mb)); |
| 2671 | rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0); |
| 2672 | if (rval == QLA_SUCCESS) { |
| 2673 | /* Interrogate mailbox registers for any errors */ |
| 2674 | if (mb[0] == MBS_COMMAND_ERROR) |
| 2675 | rval = 1; |
| 2676 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 2677 | /* device not in PCB table */ |
| 2678 | rval = 3; |
| 2679 | } |
| 2680 | |
| 2681 | return (rval); |
| 2682 | } |
| 2683 | |
| 2684 | /* |
| 2685 | * qla2x00_loop_resync |
| 2686 | * Resync with fibre channel devices. |
| 2687 | * |
| 2688 | * Input: |
| 2689 | * ha = adapter block pointer. |
| 2690 | * |
| 2691 | * Returns: |
| 2692 | * 0 = success |
| 2693 | */ |
| 2694 | int |
| 2695 | qla2x00_loop_resync(scsi_qla_host_t *ha) |
| 2696 | { |
| 2697 | int rval; |
| 2698 | uint32_t wait_time; |
| 2699 | |
| 2700 | rval = QLA_SUCCESS; |
| 2701 | |
| 2702 | atomic_set(&ha->loop_state, LOOP_UPDATE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags); |
| 2704 | if (ha->flags.online) { |
| 2705 | if (!(rval = qla2x00_fw_ready(ha))) { |
| 2706 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 2707 | wait_time = 256; |
| 2708 | do { |
| 2709 | /* v2.19.05b6 */ |
| 2710 | atomic_set(&ha->loop_state, LOOP_UPDATE); |
| 2711 | |
| 2712 | /* |
| 2713 | * Issue marker command only when we are going |
| 2714 | * to start the I/O . |
| 2715 | */ |
| 2716 | ha->marker_needed = 1; |
| 2717 | |
| 2718 | /* Remap devices on Loop. */ |
| 2719 | clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 2720 | |
| 2721 | qla2x00_configure_loop(ha); |
| 2722 | wait_time--; |
| 2723 | } while (!atomic_read(&ha->loop_down_timer) && |
| 2724 | !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) && |
| 2725 | wait_time && |
| 2726 | (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))); |
| 2727 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) { |
| 2731 | return (QLA_FUNCTION_FAILED); |
| 2732 | } |
| 2733 | |
| 2734 | if (rval) { |
| 2735 | DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__)); |
| 2736 | } |
| 2737 | |
| 2738 | return (rval); |
| 2739 | } |
| 2740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | void |
| 2742 | qla2x00_rescan_fcports(scsi_qla_host_t *ha) |
| 2743 | { |
| 2744 | int rescan_done; |
| 2745 | fc_port_t *fcport; |
| 2746 | |
| 2747 | rescan_done = 0; |
| 2748 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 2749 | if ((fcport->flags & FCF_RESCAN_NEEDED) == 0) |
| 2750 | continue; |
| 2751 | |
| 2752 | qla2x00_update_fcport(ha, fcport); |
| 2753 | fcport->flags &= ~FCF_RESCAN_NEEDED; |
| 2754 | |
| 2755 | rescan_done = 1; |
| 2756 | } |
| 2757 | qla2x00_probe_for_all_luns(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | /* |
| 2761 | * qla2x00_abort_isp |
| 2762 | * Resets ISP and aborts all outstanding commands. |
| 2763 | * |
| 2764 | * Input: |
| 2765 | * ha = adapter block pointer. |
| 2766 | * |
| 2767 | * Returns: |
| 2768 | * 0 = success |
| 2769 | */ |
| 2770 | int |
| 2771 | qla2x00_abort_isp(scsi_qla_host_t *ha) |
| 2772 | { |
| 2773 | unsigned long flags = 0; |
| 2774 | uint16_t cnt; |
| 2775 | srb_t *sp; |
| 2776 | uint8_t status = 0; |
| 2777 | |
| 2778 | if (ha->flags.online) { |
| 2779 | ha->flags.online = 0; |
| 2780 | clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | |
| 2782 | qla_printk(KERN_INFO, ha, |
| 2783 | "Performing ISP error recovery - ha= %p.\n", ha); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2784 | ha->isp_ops.reset_chip(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | |
| 2786 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 2787 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { |
| 2788 | atomic_set(&ha->loop_state, LOOP_DOWN); |
| 2789 | qla2x00_mark_all_devices_lost(ha); |
| 2790 | } else { |
| 2791 | if (!atomic_read(&ha->loop_down_timer)) |
| 2792 | atomic_set(&ha->loop_down_timer, |
| 2793 | LOOP_DOWN_TIME); |
| 2794 | } |
| 2795 | |
| 2796 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2797 | /* Requeue all commands in outstanding command list. */ |
| 2798 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { |
| 2799 | sp = ha->outstanding_cmds[cnt]; |
| 2800 | if (sp) { |
| 2801 | ha->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | sp->flags = 0; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2803 | sp->cmd->result = DID_RESET << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | sp->cmd->host_scribble = (unsigned char *)NULL; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2805 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | } |
| 2807 | } |
| 2808 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2809 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2810 | ha->isp_ops.nvram_config(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | |
| 2812 | if (!qla2x00_restart_isp(ha)) { |
| 2813 | clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
| 2814 | |
| 2815 | if (!atomic_read(&ha->loop_down_timer)) { |
| 2816 | /* |
| 2817 | * Issue marker command only when we are going |
| 2818 | * to start the I/O . |
| 2819 | */ |
| 2820 | ha->marker_needed = 1; |
| 2821 | } |
| 2822 | |
| 2823 | ha->flags.online = 1; |
| 2824 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2825 | ha->isp_ops.enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | ha->isp_abort_cnt = 0; |
| 2828 | clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags); |
| 2829 | } else { /* failed the ISP abort */ |
| 2830 | ha->flags.online = 1; |
| 2831 | if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) { |
| 2832 | if (ha->isp_abort_cnt == 0) { |
| 2833 | qla_printk(KERN_WARNING, ha, |
| 2834 | "ISP error recovery failed - " |
| 2835 | "board disabled\n"); |
| 2836 | /* |
| 2837 | * The next call disables the board |
| 2838 | * completely. |
| 2839 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2840 | ha->isp_ops.reset_adapter(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | ha->flags.online = 0; |
| 2842 | clear_bit(ISP_ABORT_RETRY, |
| 2843 | &ha->dpc_flags); |
| 2844 | status = 0; |
| 2845 | } else { /* schedule another ISP abort */ |
| 2846 | ha->isp_abort_cnt--; |
| 2847 | DEBUG(printk("qla%ld: ISP abort - " |
| 2848 | "retry remainning %d\n", |
| 2849 | ha->host_no, ha->isp_abort_cnt);) |
| 2850 | status = 1; |
| 2851 | } |
| 2852 | } else { |
| 2853 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
| 2854 | DEBUG(printk("qla2x00(%ld): ISP error recovery " |
| 2855 | "- retrying (%d) more times\n", |
| 2856 | ha->host_no, ha->isp_abort_cnt);) |
| 2857 | set_bit(ISP_ABORT_RETRY, &ha->dpc_flags); |
| 2858 | status = 1; |
| 2859 | } |
| 2860 | } |
| 2861 | |
| 2862 | } |
| 2863 | |
| 2864 | if (status) { |
| 2865 | qla_printk(KERN_INFO, ha, |
| 2866 | "qla2x00_abort_isp: **** FAILED ****\n"); |
| 2867 | } else { |
| 2868 | DEBUG(printk(KERN_INFO |
| 2869 | "qla2x00_abort_isp(%ld): exiting.\n", |
| 2870 | ha->host_no);) |
| 2871 | } |
| 2872 | |
| 2873 | return(status); |
| 2874 | } |
| 2875 | |
| 2876 | /* |
| 2877 | * qla2x00_restart_isp |
| 2878 | * restarts the ISP after a reset |
| 2879 | * |
| 2880 | * Input: |
| 2881 | * ha = adapter block pointer. |
| 2882 | * |
| 2883 | * Returns: |
| 2884 | * 0 = success |
| 2885 | */ |
| 2886 | static int |
| 2887 | qla2x00_restart_isp(scsi_qla_host_t *ha) |
| 2888 | { |
| 2889 | uint8_t status = 0; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 2890 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | unsigned long flags = 0; |
| 2892 | uint32_t wait_time; |
| 2893 | |
| 2894 | /* If firmware needs to be loaded */ |
| 2895 | if (qla2x00_isp_firmware(ha)) { |
| 2896 | ha->flags.online = 0; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2897 | if (!(status = ha->isp_ops.chip_diag(ha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2899 | status = qla2x00_setup_chip(ha); |
| 2900 | goto done; |
| 2901 | } |
| 2902 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2904 | |
| 2905 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 2906 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 2907 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2908 | |
| 2909 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2910 | |
| 2911 | status = qla2x00_setup_chip(ha); |
| 2912 | |
| 2913 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2914 | |
| 2915 | /* Enable proper parity */ |
| 2916 | if (IS_QLA2300(ha)) |
| 2917 | /* SRAM parity */ |
| 2918 | WRT_REG_WORD(®->hccr, |
| 2919 | (HCCR_ENABLE_PARITY + 0x1)); |
| 2920 | else |
| 2921 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 2922 | WRT_REG_WORD(®->hccr, |
| 2923 | (HCCR_ENABLE_PARITY + 0x7)); |
| 2924 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2925 | |
| 2926 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2927 | } |
| 2928 | } |
| 2929 | |
| 2930 | done: |
| 2931 | if (!status && !(status = qla2x00_init_rings(ha))) { |
| 2932 | clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
| 2933 | if (!(status = qla2x00_fw_ready(ha))) { |
| 2934 | DEBUG(printk("%s(): Start configure loop, " |
| 2935 | "status = %d\n", |
| 2936 | __func__, |
| 2937 | status);) |
| 2938 | ha->flags.online = 1; |
| 2939 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 2940 | wait_time = 256; |
| 2941 | do { |
| 2942 | clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 2943 | qla2x00_configure_loop(ha); |
| 2944 | wait_time--; |
| 2945 | } while (!atomic_read(&ha->loop_down_timer) && |
| 2946 | !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) && |
| 2947 | wait_time && |
| 2948 | (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))); |
| 2949 | } |
| 2950 | |
| 2951 | /* if no cable then assume it's good */ |
| 2952 | if ((ha->device_flags & DFLG_NO_CABLE)) |
| 2953 | status = 0; |
| 2954 | |
| 2955 | DEBUG(printk("%s(): Configure loop done, status = 0x%x\n", |
| 2956 | __func__, |
| 2957 | status);) |
| 2958 | } |
| 2959 | return (status); |
| 2960 | } |
| 2961 | |
| 2962 | /* |
| 2963 | * qla2x00_reset_adapter |
| 2964 | * Reset adapter. |
| 2965 | * |
| 2966 | * Input: |
| 2967 | * ha = adapter block pointer. |
| 2968 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2969 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | qla2x00_reset_adapter(scsi_qla_host_t *ha) |
| 2971 | { |
| 2972 | unsigned long flags = 0; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame^] | 2973 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | |
| 2975 | ha->flags.online = 0; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2976 | ha->isp_ops.disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | |
| 2978 | /* Reset RISC processor. */ |
| 2979 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2980 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2981 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2982 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2983 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2984 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2985 | } |