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