David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic iSCSI HBA Driver |
Vikas Chaudhary | 7d01d06 | 2010-12-02 22:12:51 -0800 | [diff] [blame] | 3 | * Copyright (c) 2003-2010 QLogic Corporation |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4 | * |
| 5 | * See LICENSE.qla4xxx for copyright and licensing details. |
| 6 | */ |
| 7 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 8 | #include <scsi/iscsi_if.h> |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9 | #include "ql4_def.h" |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 10 | #include "ql4_glbl.h" |
| 11 | #include "ql4_dbg.h" |
| 12 | #include "ql4_inline.h" |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 13 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 14 | static void ql4xxx_set_mac_number(struct scsi_qla_host *ha) |
| 15 | { |
| 16 | uint32_t value; |
| 17 | uint8_t func_number; |
| 18 | unsigned long flags; |
| 19 | |
| 20 | /* Get the function number */ |
| 21 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 22 | value = readw(&ha->reg->ctrl_status); |
| 23 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 24 | |
| 25 | func_number = (uint8_t) ((value >> 4) & 0x30); |
| 26 | switch (value & ISP_CONTROL_FN_MASK) { |
| 27 | case ISP_CONTROL_FN0_SCSI: |
| 28 | ha->mac_index = 1; |
| 29 | break; |
| 30 | case ISP_CONTROL_FN1_SCSI: |
| 31 | ha->mac_index = 3; |
| 32 | break; |
| 33 | default: |
| 34 | DEBUG2(printk("scsi%ld: %s: Invalid function number, " |
| 35 | "ispControlStatus = 0x%x\n", ha->host_no, |
| 36 | __func__, value)); |
| 37 | break; |
| 38 | } |
| 39 | DEBUG2(printk("scsi%ld: %s: mac_index %d.\n", ha->host_no, __func__, |
| 40 | ha->mac_index)); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * qla4xxx_free_ddb - deallocate ddb |
| 45 | * @ha: pointer to host adapter structure. |
| 46 | * @ddb_entry: pointer to device database entry |
| 47 | * |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 48 | * This routine marks a DDB entry INVALID |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 49 | **/ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 50 | void qla4xxx_free_ddb(struct scsi_qla_host *ha, |
| 51 | struct ddb_entry *ddb_entry) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 52 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 53 | /* Remove device pointer from index mapping arrays */ |
| 54 | ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = |
| 55 | (struct ddb_entry *) INVALID_ENTRY; |
| 56 | ha->tot_ddbs--; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 60 | * qla4xxx_init_response_q_entries() - Initializes response queue entries. |
| 61 | * @ha: HA context |
| 62 | * |
| 63 | * Beginning of request ring has initialization control block already built |
| 64 | * by nvram config routine. |
| 65 | **/ |
| 66 | static void qla4xxx_init_response_q_entries(struct scsi_qla_host *ha) |
| 67 | { |
| 68 | uint16_t cnt; |
| 69 | struct response *pkt; |
| 70 | |
| 71 | pkt = (struct response *)ha->response_ptr; |
| 72 | for (cnt = 0; cnt < RESPONSE_QUEUE_DEPTH; cnt++) { |
| 73 | pkt->signature = RESPONSE_PROCESSED; |
| 74 | pkt++; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 79 | * qla4xxx_init_rings - initialize hw queues |
| 80 | * @ha: pointer to host adapter structure. |
| 81 | * |
| 82 | * This routine initializes the internal queues for the specified adapter. |
| 83 | * The QLA4010 requires us to restart the queues at index 0. |
| 84 | * The QLA4000 doesn't care, so just default to QLA4010's requirement. |
| 85 | **/ |
| 86 | int qla4xxx_init_rings(struct scsi_qla_host *ha) |
| 87 | { |
| 88 | unsigned long flags = 0; |
| 89 | |
| 90 | /* Initialize request queue. */ |
| 91 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 92 | ha->request_out = 0; |
| 93 | ha->request_in = 0; |
| 94 | ha->request_ptr = &ha->request_ring[ha->request_in]; |
| 95 | ha->req_q_count = REQUEST_QUEUE_DEPTH; |
| 96 | |
| 97 | /* Initialize response queue. */ |
| 98 | ha->response_in = 0; |
| 99 | ha->response_out = 0; |
| 100 | ha->response_ptr = &ha->response_ring[ha->response_out]; |
| 101 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 102 | if (is_qla8022(ha)) { |
| 103 | writel(0, |
| 104 | (unsigned long __iomem *)&ha->qla4_8xxx_reg->req_q_out); |
| 105 | writel(0, |
| 106 | (unsigned long __iomem *)&ha->qla4_8xxx_reg->rsp_q_in); |
| 107 | writel(0, |
| 108 | (unsigned long __iomem *)&ha->qla4_8xxx_reg->rsp_q_out); |
| 109 | } else { |
| 110 | /* |
| 111 | * Initialize DMA Shadow registers. The firmware is really |
| 112 | * supposed to take care of this, but on some uniprocessor |
| 113 | * systems, the shadow registers aren't cleared-- causing |
| 114 | * the interrupt_handler to think there are responses to be |
| 115 | * processed when there aren't. |
| 116 | */ |
| 117 | ha->shadow_regs->req_q_out = __constant_cpu_to_le32(0); |
| 118 | ha->shadow_regs->rsp_q_in = __constant_cpu_to_le32(0); |
| 119 | wmb(); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 120 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 121 | writel(0, &ha->reg->req_q_in); |
| 122 | writel(0, &ha->reg->rsp_q_out); |
| 123 | readl(&ha->reg->rsp_q_out); |
| 124 | } |
| 125 | |
| 126 | qla4xxx_init_response_q_entries(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 127 | |
| 128 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 129 | |
| 130 | return QLA_SUCCESS; |
| 131 | } |
| 132 | |
| 133 | /** |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 134 | * qla4xxx_get_sys_info - validate adapter MAC address(es) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 135 | * @ha: pointer to host adapter structure. |
| 136 | * |
| 137 | **/ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 138 | int qla4xxx_get_sys_info(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 139 | { |
| 140 | struct flash_sys_info *sys_info; |
| 141 | dma_addr_t sys_info_dma; |
| 142 | int status = QLA_ERROR; |
| 143 | |
| 144 | sys_info = dma_alloc_coherent(&ha->pdev->dev, sizeof(*sys_info), |
| 145 | &sys_info_dma, GFP_KERNEL); |
| 146 | if (sys_info == NULL) { |
| 147 | DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n", |
| 148 | ha->host_no, __func__)); |
| 149 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 150 | goto exit_get_sys_info_no_free; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 151 | } |
| 152 | memset(sys_info, 0, sizeof(*sys_info)); |
| 153 | |
| 154 | /* Get flash sys info */ |
| 155 | if (qla4xxx_get_flash(ha, sys_info_dma, FLASH_OFFSET_SYS_INFO, |
| 156 | sizeof(*sys_info)) != QLA_SUCCESS) { |
| 157 | DEBUG2(printk("scsi%ld: %s: get_flash FLASH_OFFSET_SYS_INFO " |
| 158 | "failed\n", ha->host_no, __func__)); |
| 159 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 160 | goto exit_get_sys_info; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /* Save M.A.C. address & serial_number */ |
| 164 | memcpy(ha->my_mac, &sys_info->physAddr[0].address[0], |
| 165 | min(sizeof(ha->my_mac), |
| 166 | sizeof(sys_info->physAddr[0].address))); |
| 167 | memcpy(ha->serial_number, &sys_info->acSerialNumber, |
| 168 | min(sizeof(ha->serial_number), |
| 169 | sizeof(sys_info->acSerialNumber))); |
| 170 | |
| 171 | status = QLA_SUCCESS; |
| 172 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 173 | exit_get_sys_info: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 174 | dma_free_coherent(&ha->pdev->dev, sizeof(*sys_info), sys_info, |
| 175 | sys_info_dma); |
| 176 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 177 | exit_get_sys_info_no_free: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 178 | return status; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * qla4xxx_init_local_data - initialize adapter specific local data |
| 183 | * @ha: pointer to host adapter structure. |
| 184 | * |
| 185 | **/ |
| 186 | static int qla4xxx_init_local_data(struct scsi_qla_host *ha) |
| 187 | { |
Uwe Kleine-König | 421f91d | 2010-06-11 12:17:00 +0200 | [diff] [blame] | 188 | /* Initialize aen queue */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 189 | ha->aen_q_count = MAX_AEN_ENTRIES; |
| 190 | |
| 191 | return qla4xxx_get_firmware_status(ha); |
| 192 | } |
| 193 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 194 | static uint8_t |
| 195 | qla4xxx_wait_for_ip_config(struct scsi_qla_host *ha) |
| 196 | { |
| 197 | uint8_t ipv4_wait = 0; |
| 198 | uint8_t ipv6_wait = 0; |
| 199 | int8_t ip_address[IPv6_ADDR_LEN] = {0} ; |
| 200 | |
| 201 | /* If both IPv4 & IPv6 are enabled, possibly only one |
| 202 | * IP address may be acquired, so check to see if we |
| 203 | * need to wait for another */ |
| 204 | if (is_ipv4_enabled(ha) && is_ipv6_enabled(ha)) { |
| 205 | if (((ha->addl_fw_state & FW_ADDSTATE_DHCPv4_ENABLED) != 0) && |
| 206 | ((ha->addl_fw_state & |
| 207 | FW_ADDSTATE_DHCPv4_LEASE_ACQUIRED) == 0)) { |
| 208 | ipv4_wait = 1; |
| 209 | } |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 210 | if (((ha->ip_config.ipv6_addl_options & |
| 211 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) != 0) && |
| 212 | ((ha->ip_config.ipv6_link_local_state == |
| 213 | IP_ADDRSTATE_ACQUIRING) || |
| 214 | (ha->ip_config.ipv6_addr0_state == |
| 215 | IP_ADDRSTATE_ACQUIRING) || |
| 216 | (ha->ip_config.ipv6_addr1_state == |
| 217 | IP_ADDRSTATE_ACQUIRING))) { |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 218 | |
| 219 | ipv6_wait = 1; |
| 220 | |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 221 | if ((ha->ip_config.ipv6_link_local_state == |
| 222 | IP_ADDRSTATE_PREFERRED) || |
| 223 | (ha->ip_config.ipv6_addr0_state == |
| 224 | IP_ADDRSTATE_PREFERRED) || |
| 225 | (ha->ip_config.ipv6_addr1_state == |
| 226 | IP_ADDRSTATE_PREFERRED)) { |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 227 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: " |
| 228 | "Preferred IP configured." |
| 229 | " Don't wait!\n", ha->host_no, |
| 230 | __func__)); |
| 231 | ipv6_wait = 0; |
| 232 | } |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 233 | if (memcmp(&ha->ip_config.ipv6_default_router_addr, |
| 234 | ip_address, IPv6_ADDR_LEN) == 0) { |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 235 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: " |
| 236 | "No Router configured. " |
| 237 | "Don't wait!\n", ha->host_no, |
| 238 | __func__)); |
| 239 | ipv6_wait = 0; |
| 240 | } |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 241 | if ((ha->ip_config.ipv6_default_router_state == |
| 242 | IPV6_RTRSTATE_MANUAL) && |
| 243 | (ha->ip_config.ipv6_link_local_state == |
| 244 | IP_ADDRSTATE_TENTATIVE) && |
| 245 | (memcmp(&ha->ip_config.ipv6_link_local_addr, |
| 246 | &ha->ip_config.ipv6_default_router_addr, 4) == |
| 247 | 0)) { |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 248 | DEBUG2(printk("scsi%ld: %s: LinkLocal Router & " |
| 249 | "IP configured. Don't wait!\n", |
| 250 | ha->host_no, __func__)); |
| 251 | ipv6_wait = 0; |
| 252 | } |
| 253 | } |
| 254 | if (ipv4_wait || ipv6_wait) { |
| 255 | DEBUG2(printk("scsi%ld: %s: Wait for additional " |
| 256 | "IP(s) \"", ha->host_no, __func__)); |
| 257 | if (ipv4_wait) |
| 258 | DEBUG2(printk("IPv4 ")); |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 259 | if (ha->ip_config.ipv6_link_local_state == |
| 260 | IP_ADDRSTATE_ACQUIRING) |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 261 | DEBUG2(printk("IPv6LinkLocal ")); |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 262 | if (ha->ip_config.ipv6_addr0_state == |
| 263 | IP_ADDRSTATE_ACQUIRING) |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 264 | DEBUG2(printk("IPv6Addr0 ")); |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 265 | if (ha->ip_config.ipv6_addr1_state == |
| 266 | IP_ADDRSTATE_ACQUIRING) |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 267 | DEBUG2(printk("IPv6Addr1 ")); |
| 268 | DEBUG2(printk("\"\n")); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | return ipv4_wait|ipv6_wait; |
| 273 | } |
| 274 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 275 | static int qla4xxx_fw_ready(struct scsi_qla_host *ha) |
| 276 | { |
| 277 | uint32_t timeout_count; |
| 278 | int ready = 0; |
| 279 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 280 | DEBUG2(ql4_printk(KERN_INFO, ha, "Waiting for Firmware Ready..\n")); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 281 | for (timeout_count = ADAPTER_INIT_TOV; timeout_count > 0; |
| 282 | timeout_count--) { |
| 283 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags)) |
| 284 | qla4xxx_get_dhcp_ip_address(ha); |
| 285 | |
| 286 | /* Get firmware state. */ |
| 287 | if (qla4xxx_get_firmware_state(ha) != QLA_SUCCESS) { |
| 288 | DEBUG2(printk("scsi%ld: %s: unable to get firmware " |
| 289 | "state\n", ha->host_no, __func__)); |
| 290 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | if (ha->firmware_state & FW_STATE_ERROR) { |
| 294 | DEBUG2(printk("scsi%ld: %s: an unrecoverable error has" |
| 295 | " occurred\n", ha->host_no, __func__)); |
| 296 | break; |
| 297 | |
| 298 | } |
| 299 | if (ha->firmware_state & FW_STATE_CONFIG_WAIT) { |
| 300 | /* |
| 301 | * The firmware has not yet been issued an Initialize |
| 302 | * Firmware command, so issue it now. |
| 303 | */ |
| 304 | if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR) |
| 305 | break; |
| 306 | |
| 307 | /* Go back and test for ready state - no wait. */ |
| 308 | continue; |
| 309 | } |
| 310 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 311 | if (ha->firmware_state & FW_STATE_WAIT_AUTOCONNECT) { |
| 312 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: fwstate:" |
| 313 | "AUTOCONNECT in progress\n", |
| 314 | ha->host_no, __func__)); |
| 315 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 316 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 317 | if (ha->firmware_state & FW_STATE_CONFIGURING_IP) { |
| 318 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: fwstate:" |
| 319 | " CONFIGURING IP\n", |
| 320 | ha->host_no, __func__)); |
| 321 | /* |
| 322 | * Check for link state after 15 secs and if link is |
| 323 | * still DOWN then, cable is unplugged. Ignore "DHCP |
| 324 | * in Progress/CONFIGURING IP" bit to check if firmware |
| 325 | * is in ready state or not after 15 secs. |
| 326 | * This is applicable for both 2.x & 3.x firmware |
| 327 | */ |
| 328 | if (timeout_count <= (ADAPTER_INIT_TOV - 15)) { |
| 329 | if (ha->addl_fw_state & FW_ADDSTATE_LINK_UP) { |
| 330 | DEBUG2(printk(KERN_INFO "scsi%ld: %s:" |
| 331 | " LINK UP (Cable plugged)\n", |
| 332 | ha->host_no, __func__)); |
| 333 | } else if (ha->firmware_state & |
| 334 | (FW_STATE_CONFIGURING_IP | |
| 335 | FW_STATE_READY)) { |
| 336 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: " |
| 337 | "LINK DOWN (Cable unplugged)\n", |
| 338 | ha->host_no, __func__)); |
| 339 | ha->firmware_state = FW_STATE_READY; |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | if (ha->firmware_state == FW_STATE_READY) { |
| 345 | /* If DHCP IP Addr is available, retrieve it now. */ |
| 346 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, |
| 347 | &ha->dpc_flags)) |
| 348 | qla4xxx_get_dhcp_ip_address(ha); |
| 349 | |
| 350 | if (!qla4xxx_wait_for_ip_config(ha) || |
| 351 | timeout_count == 1) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 352 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 353 | "Firmware Ready..\n")); |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 354 | /* The firmware is ready to process SCSI |
| 355 | commands. */ |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 356 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 357 | "scsi%ld: %s: MEDIA TYPE" |
| 358 | " - %s\n", ha->host_no, |
| 359 | __func__, (ha->addl_fw_state & |
| 360 | FW_ADDSTATE_OPTICAL_MEDIA) |
| 361 | != 0 ? "OPTICAL" : "COPPER")); |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 362 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 363 | "scsi%ld: %s: DHCPv4 STATE" |
| 364 | " Enabled %s\n", ha->host_no, |
| 365 | __func__, (ha->addl_fw_state & |
| 366 | FW_ADDSTATE_DHCPv4_ENABLED) != 0 ? |
| 367 | "YES" : "NO")); |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 368 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 369 | "scsi%ld: %s: LINK %s\n", |
| 370 | ha->host_no, __func__, |
| 371 | (ha->addl_fw_state & |
| 372 | FW_ADDSTATE_LINK_UP) != 0 ? |
| 373 | "UP" : "DOWN")); |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 374 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 375 | "scsi%ld: %s: iSNS Service " |
| 376 | "Started %s\n", |
| 377 | ha->host_no, __func__, |
| 378 | (ha->addl_fw_state & |
| 379 | FW_ADDSTATE_ISNS_SVC_ENABLED) != 0 ? |
| 380 | "YES" : "NO")); |
| 381 | |
| 382 | ready = 1; |
| 383 | break; |
| 384 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 385 | } |
| 386 | DEBUG2(printk("scsi%ld: %s: waiting on fw, state=%x:%x - " |
| 387 | "seconds expired= %d\n", ha->host_no, __func__, |
| 388 | ha->firmware_state, ha->addl_fw_state, |
| 389 | timeout_count)); |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 390 | if (is_qla4032(ha) && |
| 391 | !(ha->addl_fw_state & FW_ADDSTATE_LINK_UP) && |
| 392 | (timeout_count < ADAPTER_INIT_TOV - 5)) { |
| 393 | break; |
| 394 | } |
| 395 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 396 | msleep(1000); |
| 397 | } /* end of for */ |
| 398 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 399 | if (timeout_count <= 0) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 400 | DEBUG2(printk("scsi%ld: %s: FW Initialization timed out!\n", |
| 401 | ha->host_no, __func__)); |
| 402 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 403 | if (ha->firmware_state & FW_STATE_CONFIGURING_IP) { |
| 404 | DEBUG2(printk("scsi%ld: %s: FW initialized, but is reporting " |
| 405 | "it's waiting to configure an IP address\n", |
| 406 | ha->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 407 | ready = 1; |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 408 | } else if (ha->firmware_state & FW_STATE_WAIT_AUTOCONNECT) { |
| 409 | DEBUG2(printk("scsi%ld: %s: FW initialized, but " |
| 410 | "auto-discovery still in process\n", |
| 411 | ha->host_no, __func__)); |
Vikas Chaudhary | b966346 | 2010-07-10 14:49:19 +0530 | [diff] [blame] | 412 | ready = 1; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | return ready; |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * qla4xxx_init_firmware - initializes the firmware. |
| 420 | * @ha: pointer to host adapter structure. |
| 421 | * |
| 422 | **/ |
| 423 | static int qla4xxx_init_firmware(struct scsi_qla_host *ha) |
| 424 | { |
| 425 | int status = QLA_ERROR; |
| 426 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 427 | if (is_aer_supported(ha) && |
| 428 | test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags)) |
| 429 | return status; |
| 430 | |
Lalit Chandivade | 9d4946f | 2010-07-30 14:26:31 +0530 | [diff] [blame] | 431 | /* For 82xx, stop firmware before initializing because if BIOS |
| 432 | * has previously initialized firmware, then driver's initialize |
| 433 | * firmware will fail. */ |
| 434 | if (is_qla8022(ha)) |
| 435 | qla4_8xxx_stop_firmware(ha); |
| 436 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 437 | ql4_printk(KERN_INFO, ha, "Initializing firmware..\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 438 | if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR) { |
| 439 | DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware " |
| 440 | "control block\n", ha->host_no, __func__)); |
| 441 | return status; |
| 442 | } |
| 443 | if (!qla4xxx_fw_ready(ha)) |
| 444 | return status; |
| 445 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 446 | return qla4xxx_get_firmware_status(ha); |
| 447 | } |
| 448 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 449 | static int qla4xxx_config_nvram(struct scsi_qla_host *ha) |
| 450 | { |
| 451 | unsigned long flags; |
| 452 | union external_hw_config_reg extHwConfig; |
| 453 | |
| 454 | DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha->host_no, |
| 455 | __func__)); |
| 456 | if (ql4xxx_lock_flash(ha) != QLA_SUCCESS) |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 457 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 458 | if (ql4xxx_lock_nvram(ha) != QLA_SUCCESS) { |
| 459 | ql4xxx_unlock_flash(ha); |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 460 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | /* Get EEPRom Parameters from NVRAM and validate */ |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 464 | ql4_printk(KERN_INFO, ha, "Configuring NVRAM ...\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 465 | if (qla4xxx_is_nvram_configuration_valid(ha) == QLA_SUCCESS) { |
| 466 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 467 | extHwConfig.Asuint32_t = |
| 468 | rd_nvram_word(ha, eeprom_ext_hw_conf_offset(ha)); |
| 469 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 470 | } else { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 471 | ql4_printk(KERN_WARNING, ha, |
| 472 | "scsi%ld: %s: EEProm checksum invalid. " |
| 473 | "Please update your EEPROM\n", ha->host_no, |
| 474 | __func__); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 475 | |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 476 | /* Attempt to set defaults */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 477 | if (is_qla4010(ha)) |
| 478 | extHwConfig.Asuint32_t = 0x1912; |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 479 | else if (is_qla4022(ha) | is_qla4032(ha)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 480 | extHwConfig.Asuint32_t = 0x0023; |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 481 | else |
| 482 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 483 | } |
| 484 | DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n", |
| 485 | ha->host_no, __func__, extHwConfig.Asuint32_t)); |
| 486 | |
| 487 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 488 | writel((0xFFFF << 16) | extHwConfig.Asuint32_t, isp_ext_hw_conf(ha)); |
| 489 | readl(isp_ext_hw_conf(ha)); |
| 490 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 491 | |
| 492 | ql4xxx_unlock_nvram(ha); |
| 493 | ql4xxx_unlock_flash(ha); |
| 494 | |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 495 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 498 | /** |
| 499 | * qla4_8xxx_pci_config() - Setup ISP82xx PCI configuration registers. |
| 500 | * @ha: HA context |
| 501 | */ |
| 502 | void qla4_8xxx_pci_config(struct scsi_qla_host *ha) |
| 503 | { |
| 504 | pci_set_master(ha->pdev); |
| 505 | } |
| 506 | |
| 507 | void qla4xxx_pci_config(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 508 | { |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 509 | uint16_t w; |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 510 | int status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 511 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 512 | ql4_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 513 | |
| 514 | pci_set_master(ha->pdev); |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 515 | status = pci_set_mwi(ha->pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 516 | /* |
| 517 | * We want to respect framework's setting of PCI configuration space |
| 518 | * command register and also want to make sure that all bits of |
| 519 | * interest to us are properly set in command register. |
| 520 | */ |
| 521 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 522 | w |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 523 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 524 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 525 | } |
| 526 | |
| 527 | static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host *ha) |
| 528 | { |
| 529 | int status = QLA_ERROR; |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 530 | unsigned long max_wait_time; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 531 | unsigned long flags; |
| 532 | uint32_t mbox_status; |
| 533 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 534 | ql4_printk(KERN_INFO, ha, "Starting firmware ...\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 535 | |
| 536 | /* |
| 537 | * Start firmware from flash ROM |
| 538 | * |
| 539 | * WORKAROUND: Stuff a non-constant value that the firmware can |
| 540 | * use as a seed for a random number generator in MB7 prior to |
| 541 | * setting BOOT_ENABLE. Fixes problem where the TCP |
| 542 | * connections use the same TCP ports after each reboot, |
| 543 | * causing some connections to not get re-established. |
| 544 | */ |
| 545 | DEBUG(printk("scsi%d: %s: Start firmware from flash ROM\n", |
| 546 | ha->host_no, __func__)); |
| 547 | |
| 548 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 549 | writel(jiffies, &ha->reg->mailbox[7]); |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 550 | if (is_qla4022(ha) | is_qla4032(ha)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 551 | writel(set_rmask(NVR_WRITE_ENABLE), |
| 552 | &ha->reg->u1.isp4022.nvram); |
| 553 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 554 | writel(2, &ha->reg->mailbox[6]); |
| 555 | readl(&ha->reg->mailbox[6]); |
| 556 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 557 | writel(set_rmask(CSR_BOOT_ENABLE), &ha->reg->ctrl_status); |
| 558 | readl(&ha->reg->ctrl_status); |
| 559 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 560 | |
| 561 | /* Wait for firmware to come UP. */ |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 562 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: Wait up to %d seconds for " |
| 563 | "boot firmware to complete...\n", |
| 564 | ha->host_no, __func__, FIRMWARE_UP_TOV)); |
| 565 | max_wait_time = jiffies + (FIRMWARE_UP_TOV * HZ); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 566 | do { |
| 567 | uint32_t ctrl_status; |
| 568 | |
| 569 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 570 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 571 | mbox_status = readw(&ha->reg->mailbox[0]); |
| 572 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 573 | |
| 574 | if (ctrl_status & set_rmask(CSR_SCSI_PROCESSOR_INTR)) |
| 575 | break; |
| 576 | if (mbox_status == MBOX_STS_COMMAND_COMPLETE) |
| 577 | break; |
| 578 | |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 579 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: Waiting for boot " |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 580 | "firmware to complete... ctrl_sts=0x%x, remaining=%ld\n", |
| 581 | ha->host_no, __func__, ctrl_status, max_wait_time)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 582 | |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 583 | msleep_interruptible(250); |
| 584 | } while (!time_after_eq(jiffies, max_wait_time)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 585 | |
| 586 | if (mbox_status == MBOX_STS_COMMAND_COMPLETE) { |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 587 | DEBUG(printk(KERN_INFO "scsi%ld: %s: Firmware has started\n", |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 588 | ha->host_no, __func__)); |
| 589 | |
| 590 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 591 | writel(set_rmask(CSR_SCSI_PROCESSOR_INTR), |
| 592 | &ha->reg->ctrl_status); |
| 593 | readl(&ha->reg->ctrl_status); |
| 594 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 595 | |
| 596 | status = QLA_SUCCESS; |
| 597 | } else { |
| 598 | printk(KERN_INFO "scsi%ld: %s: Boot firmware failed " |
| 599 | "- mbox status 0x%x\n", ha->host_no, __func__, |
| 600 | mbox_status); |
| 601 | status = QLA_ERROR; |
| 602 | } |
| 603 | return status; |
| 604 | } |
| 605 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 606 | int ql4xxx_lock_drvr_wait(struct scsi_qla_host *a) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 607 | { |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 608 | #define QL4_LOCK_DRVR_WAIT 60 |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 609 | #define QL4_LOCK_DRVR_SLEEP 1 |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 610 | |
| 611 | int drvr_wait = QL4_LOCK_DRVR_WAIT; |
| 612 | while (drvr_wait) { |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 613 | if (ql4xxx_lock_drvr(a) == 0) { |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 614 | ssleep(QL4_LOCK_DRVR_SLEEP); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 615 | if (drvr_wait) { |
| 616 | DEBUG2(printk("scsi%ld: %s: Waiting for " |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 617 | "Global Init Semaphore(%d)...\n", |
| 618 | a->host_no, |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 619 | __func__, drvr_wait)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 620 | } |
| 621 | drvr_wait -= QL4_LOCK_DRVR_SLEEP; |
| 622 | } else { |
| 623 | DEBUG2(printk("scsi%ld: %s: Global Init Semaphore " |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 624 | "acquired\n", a->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 625 | return QLA_SUCCESS; |
| 626 | } |
| 627 | } |
| 628 | return QLA_ERROR; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * qla4xxx_start_firmware - starts qla4xxx firmware |
| 633 | * @ha: Pointer to host adapter structure. |
| 634 | * |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 635 | * This routine performs the necessary steps to start the firmware for |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 636 | * the QLA4010 adapter. |
| 637 | **/ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 638 | int qla4xxx_start_firmware(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 639 | { |
| 640 | unsigned long flags = 0; |
| 641 | uint32_t mbox_status; |
| 642 | int status = QLA_ERROR; |
| 643 | int soft_reset = 1; |
| 644 | int config_chip = 0; |
| 645 | |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 646 | if (is_qla4022(ha) | is_qla4032(ha)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 647 | ql4xxx_set_mac_number(ha); |
| 648 | |
| 649 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 650 | return QLA_ERROR; |
| 651 | |
| 652 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 653 | |
| 654 | DEBUG2(printk("scsi%ld: %s: port_ctrl = 0x%08X\n", ha->host_no, |
| 655 | __func__, readw(isp_port_ctrl(ha)))); |
| 656 | DEBUG(printk("scsi%ld: %s: port_status = 0x%08X\n", ha->host_no, |
| 657 | __func__, readw(isp_port_status(ha)))); |
| 658 | |
| 659 | /* Is Hardware already initialized? */ |
| 660 | if ((readw(isp_port_ctrl(ha)) & 0x8000) != 0) { |
| 661 | DEBUG(printk("scsi%ld: %s: Hardware has already been " |
| 662 | "initialized\n", ha->host_no, __func__)); |
| 663 | |
| 664 | /* Receive firmware boot acknowledgement */ |
| 665 | mbox_status = readw(&ha->reg->mailbox[0]); |
| 666 | |
| 667 | DEBUG2(printk("scsi%ld: %s: H/W Config complete - mbox[0]= " |
| 668 | "0x%x\n", ha->host_no, __func__, mbox_status)); |
| 669 | |
| 670 | /* Is firmware already booted? */ |
| 671 | if (mbox_status == 0) { |
| 672 | /* F/W not running, must be config by net driver */ |
| 673 | config_chip = 1; |
| 674 | soft_reset = 0; |
| 675 | } else { |
| 676 | writel(set_rmask(CSR_SCSI_PROCESSOR_INTR), |
| 677 | &ha->reg->ctrl_status); |
| 678 | readl(&ha->reg->ctrl_status); |
| 679 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 680 | if (qla4xxx_get_firmware_state(ha) == QLA_SUCCESS) { |
| 681 | DEBUG2(printk("scsi%ld: %s: Get firmware " |
| 682 | "state -- state = 0x%x\n", |
| 683 | ha->host_no, |
| 684 | __func__, ha->firmware_state)); |
| 685 | /* F/W is running */ |
| 686 | if (ha->firmware_state & |
| 687 | FW_STATE_CONFIG_WAIT) { |
| 688 | DEBUG2(printk("scsi%ld: %s: Firmware " |
| 689 | "in known state -- " |
| 690 | "config and " |
| 691 | "boot, state = 0x%x\n", |
| 692 | ha->host_no, __func__, |
| 693 | ha->firmware_state)); |
| 694 | config_chip = 1; |
| 695 | soft_reset = 0; |
| 696 | } |
| 697 | } else { |
| 698 | DEBUG2(printk("scsi%ld: %s: Firmware in " |
| 699 | "unknown state -- resetting," |
| 700 | " state = " |
| 701 | "0x%x\n", ha->host_no, __func__, |
| 702 | ha->firmware_state)); |
| 703 | } |
| 704 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 705 | } |
| 706 | } else { |
| 707 | DEBUG(printk("scsi%ld: %s: H/W initialization hasn't been " |
| 708 | "started - resetting\n", ha->host_no, __func__)); |
| 709 | } |
| 710 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 711 | |
| 712 | DEBUG(printk("scsi%ld: %s: Flags soft_rest=%d, config= %d\n ", |
| 713 | ha->host_no, __func__, soft_reset, config_chip)); |
| 714 | if (soft_reset) { |
| 715 | DEBUG(printk("scsi%ld: %s: Issue Soft Reset\n", ha->host_no, |
| 716 | __func__)); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 717 | status = qla4xxx_soft_reset(ha); /* NOTE: acquires drvr |
| 718 | * lock again, but ok */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 719 | if (status == QLA_ERROR) { |
| 720 | DEBUG(printk("scsi%d: %s: Soft Reset failed!\n", |
| 721 | ha->host_no, __func__)); |
| 722 | ql4xxx_unlock_drvr(ha); |
| 723 | return QLA_ERROR; |
| 724 | } |
| 725 | config_chip = 1; |
| 726 | |
Joe Perches | b1c1181 | 2008-02-03 17:28:22 +0200 | [diff] [blame] | 727 | /* Reset clears the semaphore, so acquire again */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 728 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 729 | return QLA_ERROR; |
| 730 | } |
| 731 | |
| 732 | if (config_chip) { |
| 733 | if ((status = qla4xxx_config_nvram(ha)) == QLA_SUCCESS) |
| 734 | status = qla4xxx_start_firmware_from_flash(ha); |
| 735 | } |
| 736 | |
| 737 | ql4xxx_unlock_drvr(ha); |
| 738 | if (status == QLA_SUCCESS) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 739 | if (test_and_clear_bit(AF_GET_CRASH_RECORD, &ha->flags)) |
| 740 | qla4xxx_get_crash_record(ha); |
| 741 | } else { |
| 742 | DEBUG(printk("scsi%ld: %s: Firmware has NOT started\n", |
| 743 | ha->host_no, __func__)); |
| 744 | } |
| 745 | return status; |
| 746 | } |
| 747 | |
| 748 | |
| 749 | /** |
| 750 | * qla4xxx_initialize_adapter - initiailizes hba |
| 751 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 752 | * |
| 753 | * This routine parforms all of the steps necessary to initialize the adapter. |
| 754 | * |
| 755 | **/ |
Manish Rangankar | 0e7e850 | 2011-07-25 13:48:54 -0500 | [diff] [blame^] | 756 | int qla4xxx_initialize_adapter(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 757 | { |
| 758 | int status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 759 | |
| 760 | ha->eeprom_cmd_data = 0; |
| 761 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 762 | ql4_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
| 763 | ha->isp_ops->pci_config(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 764 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 765 | ha->isp_ops->disable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 766 | |
| 767 | /* Initialize the Host adapter request/response queues and firmware */ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 768 | if (ha->isp_ops->start_firmware(ha) == QLA_ERROR) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 769 | goto exit_init_hba; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 770 | |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 771 | if (qla4xxx_about_firmware(ha) == QLA_ERROR) |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 772 | goto exit_init_hba; |
| 773 | |
| 774 | if (ha->isp_ops->get_sys_info(ha) == QLA_ERROR) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 775 | goto exit_init_hba; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 776 | |
| 777 | if (qla4xxx_init_local_data(ha) == QLA_ERROR) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 778 | goto exit_init_hba; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 779 | |
| 780 | status = qla4xxx_init_firmware(ha); |
| 781 | if (status == QLA_ERROR) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 782 | goto exit_init_hba; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 783 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 784 | set_bit(AF_ONLINE, &ha->flags); |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 785 | exit_init_hba: |
Vikas Chaudhary | 3710c60 | 2010-10-06 22:49:08 -0700 | [diff] [blame] | 786 | if (is_qla8022(ha) && (status == QLA_ERROR)) { |
| 787 | /* Since interrupts are registered in start_firmware for |
| 788 | * 82xx, release them here if initialize_adapter fails */ |
| 789 | qla4xxx_free_irqs(ha); |
| 790 | } |
| 791 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 792 | DEBUG2(printk("scsi%ld: initialize adapter: %s\n", ha->host_no, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 793 | status == QLA_ERROR ? "FAILED" : "SUCCEEDED")); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 794 | return status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 798 | * qla4xxx_process_ddb_changed - process ddb state change |
| 799 | * @ha - Pointer to host adapter structure. |
| 800 | * @fw_ddb_index - Firmware's device database index |
| 801 | * @state - Device state |
| 802 | * |
| 803 | * This routine processes a Decive Database Changed AEN Event. |
| 804 | **/ |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 805 | int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index, |
| 806 | uint32_t state, uint32_t conn_err) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 807 | { |
| 808 | struct ddb_entry * ddb_entry; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 809 | uint32_t old_fw_ddb_device_state; |
| 810 | int status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 811 | |
| 812 | /* check for out of range index */ |
| 813 | if (fw_ddb_index >= MAX_DDB_ENTRIES) |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 814 | goto exit_ddb_event; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 815 | |
| 816 | /* Get the corresponging ddb entry */ |
| 817 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index); |
| 818 | /* Device does not currently exist in our database. */ |
| 819 | if (ddb_entry == NULL) { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 820 | ql4_printk(KERN_ERR, ha, "%s: No ddb_entry at FW index [%d]\n", |
| 821 | __func__, fw_ddb_index); |
| 822 | goto exit_ddb_event; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 825 | old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state; |
| 826 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 827 | "%s: DDB - old state = 0x%x, new state = 0x%x for " |
| 828 | "index [%d]\n", __func__, |
| 829 | ddb_entry->fw_ddb_device_state, state, fw_ddb_index)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 830 | |
| 831 | ddb_entry->fw_ddb_device_state = state; |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 832 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 833 | switch (old_fw_ddb_device_state) { |
| 834 | case DDB_DS_LOGIN_IN_PROCESS: |
| 835 | switch (state) { |
| 836 | case DDB_DS_SESSION_ACTIVE: |
| 837 | case DDB_DS_DISCOVERY: |
| 838 | iscsi_conn_login_event(ddb_entry->conn, |
| 839 | ISCSI_CONN_STATE_LOGGED_IN); |
| 840 | qla4xxx_update_session_conn_param(ha, ddb_entry); |
| 841 | status = QLA_SUCCESS; |
| 842 | break; |
| 843 | case DDB_DS_SESSION_FAILED: |
| 844 | case DDB_DS_NO_CONNECTION_ACTIVE: |
| 845 | iscsi_conn_login_event(ddb_entry->conn, |
| 846 | ISCSI_CONN_STATE_FREE); |
| 847 | status = QLA_SUCCESS; |
| 848 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 849 | } |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 850 | break; |
| 851 | case DDB_DS_SESSION_ACTIVE: |
| 852 | if (state == DDB_DS_SESSION_FAILED) { |
| 853 | /* |
| 854 | * iscsi_session failure will cause userspace to |
| 855 | * stop the connection which in turn would block the |
| 856 | * iscsi_session and start relogin |
| 857 | */ |
| 858 | iscsi_session_failure(ddb_entry->sess->dd_data, |
| 859 | ISCSI_ERR_CONN_FAILED); |
| 860 | status = QLA_SUCCESS; |
| 861 | } |
| 862 | break; |
| 863 | default: |
| 864 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unknown Event\n", |
| 865 | __func__)); |
| 866 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 867 | } |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 868 | |
| 869 | exit_ddb_event: |
| 870 | return status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 871 | } |