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