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