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 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 14 | static struct ddb_entry *qla4xxx_alloc_ddb(struct scsi_qla_host *ha, |
| 15 | uint32_t fw_ddb_index); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 16 | |
| 17 | static void ql4xxx_set_mac_number(struct scsi_qla_host *ha) |
| 18 | { |
| 19 | uint32_t value; |
| 20 | uint8_t func_number; |
| 21 | unsigned long flags; |
| 22 | |
| 23 | /* Get the function number */ |
| 24 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 25 | value = readw(&ha->reg->ctrl_status); |
| 26 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 27 | |
| 28 | func_number = (uint8_t) ((value >> 4) & 0x30); |
| 29 | switch (value & ISP_CONTROL_FN_MASK) { |
| 30 | case ISP_CONTROL_FN0_SCSI: |
| 31 | ha->mac_index = 1; |
| 32 | break; |
| 33 | case ISP_CONTROL_FN1_SCSI: |
| 34 | ha->mac_index = 3; |
| 35 | break; |
| 36 | default: |
| 37 | DEBUG2(printk("scsi%ld: %s: Invalid function number, " |
| 38 | "ispControlStatus = 0x%x\n", ha->host_no, |
| 39 | __func__, value)); |
| 40 | break; |
| 41 | } |
| 42 | DEBUG2(printk("scsi%ld: %s: mac_index %d.\n", ha->host_no, __func__, |
| 43 | ha->mac_index)); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * qla4xxx_free_ddb - deallocate ddb |
| 48 | * @ha: pointer to host adapter structure. |
| 49 | * @ddb_entry: pointer to device database entry |
| 50 | * |
| 51 | * This routine deallocates and unlinks the specified ddb_entry from the |
| 52 | * adapter's |
| 53 | **/ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 54 | void qla4xxx_free_ddb(struct scsi_qla_host *ha, |
| 55 | struct ddb_entry *ddb_entry) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 56 | { |
| 57 | /* Remove device entry from list */ |
| 58 | list_del_init(&ddb_entry->list); |
| 59 | |
| 60 | /* Remove device pointer from index mapping arrays */ |
| 61 | ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = |
| 62 | (struct ddb_entry *) INVALID_ENTRY; |
| 63 | ha->tot_ddbs--; |
| 64 | |
| 65 | /* Free memory and scsi-ml struct for device entry */ |
| 66 | qla4xxx_destroy_sess(ddb_entry); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * qla4xxx_free_ddb_list - deallocate all ddbs |
| 71 | * @ha: pointer to host adapter structure. |
| 72 | * |
| 73 | * This routine deallocates and removes all devices on the sppecified adapter. |
| 74 | **/ |
| 75 | void qla4xxx_free_ddb_list(struct scsi_qla_host *ha) |
| 76 | { |
| 77 | struct list_head *ptr; |
| 78 | struct ddb_entry *ddb_entry; |
| 79 | |
| 80 | while (!list_empty(&ha->ddb_list)) { |
| 81 | ptr = ha->ddb_list.next; |
| 82 | /* Free memory for device entry and remove */ |
| 83 | ddb_entry = list_entry(ptr, struct ddb_entry, list); |
| 84 | qla4xxx_free_ddb(ha, ddb_entry); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /** |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 89 | * qla4xxx_init_response_q_entries() - Initializes response queue entries. |
| 90 | * @ha: HA context |
| 91 | * |
| 92 | * Beginning of request ring has initialization control block already built |
| 93 | * by nvram config routine. |
| 94 | **/ |
| 95 | static void qla4xxx_init_response_q_entries(struct scsi_qla_host *ha) |
| 96 | { |
| 97 | uint16_t cnt; |
| 98 | struct response *pkt; |
| 99 | |
| 100 | pkt = (struct response *)ha->response_ptr; |
| 101 | for (cnt = 0; cnt < RESPONSE_QUEUE_DEPTH; cnt++) { |
| 102 | pkt->signature = RESPONSE_PROCESSED; |
| 103 | pkt++; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 108 | * qla4xxx_init_rings - initialize hw queues |
| 109 | * @ha: pointer to host adapter structure. |
| 110 | * |
| 111 | * This routine initializes the internal queues for the specified adapter. |
| 112 | * The QLA4010 requires us to restart the queues at index 0. |
| 113 | * The QLA4000 doesn't care, so just default to QLA4010's requirement. |
| 114 | **/ |
| 115 | int qla4xxx_init_rings(struct scsi_qla_host *ha) |
| 116 | { |
| 117 | unsigned long flags = 0; |
| 118 | |
| 119 | /* Initialize request queue. */ |
| 120 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 121 | ha->request_out = 0; |
| 122 | ha->request_in = 0; |
| 123 | ha->request_ptr = &ha->request_ring[ha->request_in]; |
| 124 | ha->req_q_count = REQUEST_QUEUE_DEPTH; |
| 125 | |
| 126 | /* Initialize response queue. */ |
| 127 | ha->response_in = 0; |
| 128 | ha->response_out = 0; |
| 129 | ha->response_ptr = &ha->response_ring[ha->response_out]; |
| 130 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 131 | if (is_qla8022(ha)) { |
| 132 | writel(0, |
| 133 | (unsigned long __iomem *)&ha->qla4_8xxx_reg->req_q_out); |
| 134 | writel(0, |
| 135 | (unsigned long __iomem *)&ha->qla4_8xxx_reg->rsp_q_in); |
| 136 | writel(0, |
| 137 | (unsigned long __iomem *)&ha->qla4_8xxx_reg->rsp_q_out); |
| 138 | } else { |
| 139 | /* |
| 140 | * Initialize DMA Shadow registers. The firmware is really |
| 141 | * supposed to take care of this, but on some uniprocessor |
| 142 | * systems, the shadow registers aren't cleared-- causing |
| 143 | * the interrupt_handler to think there are responses to be |
| 144 | * processed when there aren't. |
| 145 | */ |
| 146 | ha->shadow_regs->req_q_out = __constant_cpu_to_le32(0); |
| 147 | ha->shadow_regs->rsp_q_in = __constant_cpu_to_le32(0); |
| 148 | wmb(); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 149 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 150 | writel(0, &ha->reg->req_q_in); |
| 151 | writel(0, &ha->reg->rsp_q_out); |
| 152 | readl(&ha->reg->rsp_q_out); |
| 153 | } |
| 154 | |
| 155 | qla4xxx_init_response_q_entries(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 156 | |
| 157 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 158 | |
| 159 | return QLA_SUCCESS; |
| 160 | } |
| 161 | |
| 162 | /** |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 163 | * qla4xxx_get_sys_info - validate adapter MAC address(es) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 164 | * @ha: pointer to host adapter structure. |
| 165 | * |
| 166 | **/ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 167 | int qla4xxx_get_sys_info(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 168 | { |
| 169 | struct flash_sys_info *sys_info; |
| 170 | dma_addr_t sys_info_dma; |
| 171 | int status = QLA_ERROR; |
| 172 | |
| 173 | sys_info = dma_alloc_coherent(&ha->pdev->dev, sizeof(*sys_info), |
| 174 | &sys_info_dma, GFP_KERNEL); |
| 175 | if (sys_info == NULL) { |
| 176 | DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n", |
| 177 | ha->host_no, __func__)); |
| 178 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 179 | goto exit_get_sys_info_no_free; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 180 | } |
| 181 | memset(sys_info, 0, sizeof(*sys_info)); |
| 182 | |
| 183 | /* Get flash sys info */ |
| 184 | if (qla4xxx_get_flash(ha, sys_info_dma, FLASH_OFFSET_SYS_INFO, |
| 185 | sizeof(*sys_info)) != QLA_SUCCESS) { |
| 186 | DEBUG2(printk("scsi%ld: %s: get_flash FLASH_OFFSET_SYS_INFO " |
| 187 | "failed\n", ha->host_no, __func__)); |
| 188 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 189 | goto exit_get_sys_info; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* Save M.A.C. address & serial_number */ |
| 193 | memcpy(ha->my_mac, &sys_info->physAddr[0].address[0], |
| 194 | min(sizeof(ha->my_mac), |
| 195 | sizeof(sys_info->physAddr[0].address))); |
| 196 | memcpy(ha->serial_number, &sys_info->acSerialNumber, |
| 197 | min(sizeof(ha->serial_number), |
| 198 | sizeof(sys_info->acSerialNumber))); |
| 199 | |
| 200 | status = QLA_SUCCESS; |
| 201 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 202 | exit_get_sys_info: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 203 | dma_free_coherent(&ha->pdev->dev, sizeof(*sys_info), sys_info, |
| 204 | sys_info_dma); |
| 205 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 206 | exit_get_sys_info_no_free: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 207 | return status; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * qla4xxx_init_local_data - initialize adapter specific local data |
| 212 | * @ha: pointer to host adapter structure. |
| 213 | * |
| 214 | **/ |
| 215 | static int qla4xxx_init_local_data(struct scsi_qla_host *ha) |
| 216 | { |
Uwe Kleine-König | 421f91d | 2010-06-11 12:17:00 +0200 | [diff] [blame] | 217 | /* Initialize aen queue */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 218 | ha->aen_q_count = MAX_AEN_ENTRIES; |
| 219 | |
| 220 | return qla4xxx_get_firmware_status(ha); |
| 221 | } |
| 222 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 223 | static uint8_t |
| 224 | qla4xxx_wait_for_ip_config(struct scsi_qla_host *ha) |
| 225 | { |
| 226 | uint8_t ipv4_wait = 0; |
| 227 | uint8_t ipv6_wait = 0; |
| 228 | int8_t ip_address[IPv6_ADDR_LEN] = {0} ; |
| 229 | |
| 230 | /* If both IPv4 & IPv6 are enabled, possibly only one |
| 231 | * IP address may be acquired, so check to see if we |
| 232 | * need to wait for another */ |
| 233 | if (is_ipv4_enabled(ha) && is_ipv6_enabled(ha)) { |
| 234 | if (((ha->addl_fw_state & FW_ADDSTATE_DHCPv4_ENABLED) != 0) && |
| 235 | ((ha->addl_fw_state & |
| 236 | FW_ADDSTATE_DHCPv4_LEASE_ACQUIRED) == 0)) { |
| 237 | ipv4_wait = 1; |
| 238 | } |
| 239 | if (((ha->ipv6_addl_options & |
| 240 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) != 0) && |
| 241 | ((ha->ipv6_link_local_state == IP_ADDRSTATE_ACQUIRING) || |
| 242 | (ha->ipv6_addr0_state == IP_ADDRSTATE_ACQUIRING) || |
| 243 | (ha->ipv6_addr1_state == IP_ADDRSTATE_ACQUIRING))) { |
| 244 | |
| 245 | ipv6_wait = 1; |
| 246 | |
| 247 | if ((ha->ipv6_link_local_state == |
| 248 | IP_ADDRSTATE_PREFERRED) || |
| 249 | (ha->ipv6_addr0_state == IP_ADDRSTATE_PREFERRED) || |
| 250 | (ha->ipv6_addr1_state == IP_ADDRSTATE_PREFERRED)) { |
| 251 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: " |
| 252 | "Preferred IP configured." |
| 253 | " Don't wait!\n", ha->host_no, |
| 254 | __func__)); |
| 255 | ipv6_wait = 0; |
| 256 | } |
| 257 | if (memcmp(&ha->ipv6_default_router_addr, ip_address, |
| 258 | IPv6_ADDR_LEN) == 0) { |
| 259 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: " |
| 260 | "No Router configured. " |
| 261 | "Don't wait!\n", ha->host_no, |
| 262 | __func__)); |
| 263 | ipv6_wait = 0; |
| 264 | } |
| 265 | if ((ha->ipv6_default_router_state == |
| 266 | IPV6_RTRSTATE_MANUAL) && |
| 267 | (ha->ipv6_link_local_state == |
| 268 | IP_ADDRSTATE_TENTATIVE) && |
| 269 | (memcmp(&ha->ipv6_link_local_addr, |
| 270 | &ha->ipv6_default_router_addr, 4) == 0)) { |
| 271 | DEBUG2(printk("scsi%ld: %s: LinkLocal Router & " |
| 272 | "IP configured. Don't wait!\n", |
| 273 | ha->host_no, __func__)); |
| 274 | ipv6_wait = 0; |
| 275 | } |
| 276 | } |
| 277 | if (ipv4_wait || ipv6_wait) { |
| 278 | DEBUG2(printk("scsi%ld: %s: Wait for additional " |
| 279 | "IP(s) \"", ha->host_no, __func__)); |
| 280 | if (ipv4_wait) |
| 281 | DEBUG2(printk("IPv4 ")); |
| 282 | if (ha->ipv6_link_local_state == IP_ADDRSTATE_ACQUIRING) |
| 283 | DEBUG2(printk("IPv6LinkLocal ")); |
| 284 | if (ha->ipv6_addr0_state == IP_ADDRSTATE_ACQUIRING) |
| 285 | DEBUG2(printk("IPv6Addr0 ")); |
| 286 | if (ha->ipv6_addr1_state == IP_ADDRSTATE_ACQUIRING) |
| 287 | DEBUG2(printk("IPv6Addr1 ")); |
| 288 | DEBUG2(printk("\"\n")); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | return ipv4_wait|ipv6_wait; |
| 293 | } |
| 294 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 295 | static int qla4xxx_fw_ready(struct scsi_qla_host *ha) |
| 296 | { |
| 297 | uint32_t timeout_count; |
| 298 | int ready = 0; |
| 299 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 300 | DEBUG2(ql4_printk(KERN_INFO, ha, "Waiting for Firmware Ready..\n")); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 301 | for (timeout_count = ADAPTER_INIT_TOV; timeout_count > 0; |
| 302 | timeout_count--) { |
| 303 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags)) |
| 304 | qla4xxx_get_dhcp_ip_address(ha); |
| 305 | |
| 306 | /* Get firmware state. */ |
| 307 | if (qla4xxx_get_firmware_state(ha) != QLA_SUCCESS) { |
| 308 | DEBUG2(printk("scsi%ld: %s: unable to get firmware " |
| 309 | "state\n", ha->host_no, __func__)); |
| 310 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | if (ha->firmware_state & FW_STATE_ERROR) { |
| 314 | DEBUG2(printk("scsi%ld: %s: an unrecoverable error has" |
| 315 | " occurred\n", ha->host_no, __func__)); |
| 316 | break; |
| 317 | |
| 318 | } |
| 319 | if (ha->firmware_state & FW_STATE_CONFIG_WAIT) { |
| 320 | /* |
| 321 | * The firmware has not yet been issued an Initialize |
| 322 | * Firmware command, so issue it now. |
| 323 | */ |
| 324 | if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR) |
| 325 | break; |
| 326 | |
| 327 | /* Go back and test for ready state - no wait. */ |
| 328 | continue; |
| 329 | } |
| 330 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 331 | if (ha->firmware_state & FW_STATE_WAIT_AUTOCONNECT) { |
| 332 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: fwstate:" |
| 333 | "AUTOCONNECT in progress\n", |
| 334 | ha->host_no, __func__)); |
| 335 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 336 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 337 | if (ha->firmware_state & FW_STATE_CONFIGURING_IP) { |
| 338 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: fwstate:" |
| 339 | " CONFIGURING IP\n", |
| 340 | ha->host_no, __func__)); |
| 341 | /* |
| 342 | * Check for link state after 15 secs and if link is |
| 343 | * still DOWN then, cable is unplugged. Ignore "DHCP |
| 344 | * in Progress/CONFIGURING IP" bit to check if firmware |
| 345 | * is in ready state or not after 15 secs. |
| 346 | * This is applicable for both 2.x & 3.x firmware |
| 347 | */ |
| 348 | if (timeout_count <= (ADAPTER_INIT_TOV - 15)) { |
| 349 | if (ha->addl_fw_state & FW_ADDSTATE_LINK_UP) { |
| 350 | DEBUG2(printk(KERN_INFO "scsi%ld: %s:" |
| 351 | " LINK UP (Cable plugged)\n", |
| 352 | ha->host_no, __func__)); |
| 353 | } else if (ha->firmware_state & |
| 354 | (FW_STATE_CONFIGURING_IP | |
| 355 | FW_STATE_READY)) { |
| 356 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: " |
| 357 | "LINK DOWN (Cable unplugged)\n", |
| 358 | ha->host_no, __func__)); |
| 359 | ha->firmware_state = FW_STATE_READY; |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | if (ha->firmware_state == FW_STATE_READY) { |
| 365 | /* If DHCP IP Addr is available, retrieve it now. */ |
| 366 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, |
| 367 | &ha->dpc_flags)) |
| 368 | qla4xxx_get_dhcp_ip_address(ha); |
| 369 | |
| 370 | if (!qla4xxx_wait_for_ip_config(ha) || |
| 371 | timeout_count == 1) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 372 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 373 | "Firmware Ready..\n")); |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 374 | /* The firmware is ready to process SCSI |
| 375 | commands. */ |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 376 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 377 | "scsi%ld: %s: MEDIA TYPE" |
| 378 | " - %s\n", ha->host_no, |
| 379 | __func__, (ha->addl_fw_state & |
| 380 | FW_ADDSTATE_OPTICAL_MEDIA) |
| 381 | != 0 ? "OPTICAL" : "COPPER")); |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 382 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 383 | "scsi%ld: %s: DHCPv4 STATE" |
| 384 | " Enabled %s\n", ha->host_no, |
| 385 | __func__, (ha->addl_fw_state & |
| 386 | FW_ADDSTATE_DHCPv4_ENABLED) != 0 ? |
| 387 | "YES" : "NO")); |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 388 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 389 | "scsi%ld: %s: LINK %s\n", |
| 390 | ha->host_no, __func__, |
| 391 | (ha->addl_fw_state & |
| 392 | FW_ADDSTATE_LINK_UP) != 0 ? |
| 393 | "UP" : "DOWN")); |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 394 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 395 | "scsi%ld: %s: iSNS Service " |
| 396 | "Started %s\n", |
| 397 | ha->host_no, __func__, |
| 398 | (ha->addl_fw_state & |
| 399 | FW_ADDSTATE_ISNS_SVC_ENABLED) != 0 ? |
| 400 | "YES" : "NO")); |
| 401 | |
| 402 | ready = 1; |
| 403 | break; |
| 404 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 405 | } |
| 406 | DEBUG2(printk("scsi%ld: %s: waiting on fw, state=%x:%x - " |
| 407 | "seconds expired= %d\n", ha->host_no, __func__, |
| 408 | ha->firmware_state, ha->addl_fw_state, |
| 409 | timeout_count)); |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 410 | if (is_qla4032(ha) && |
| 411 | !(ha->addl_fw_state & FW_ADDSTATE_LINK_UP) && |
| 412 | (timeout_count < ADAPTER_INIT_TOV - 5)) { |
| 413 | break; |
| 414 | } |
| 415 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 416 | msleep(1000); |
| 417 | } /* end of for */ |
| 418 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 419 | if (timeout_count <= 0) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 420 | DEBUG2(printk("scsi%ld: %s: FW Initialization timed out!\n", |
| 421 | ha->host_no, __func__)); |
| 422 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 423 | if (ha->firmware_state & FW_STATE_CONFIGURING_IP) { |
| 424 | DEBUG2(printk("scsi%ld: %s: FW initialized, but is reporting " |
| 425 | "it's waiting to configure an IP address\n", |
| 426 | ha->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 427 | ready = 1; |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 428 | } else if (ha->firmware_state & FW_STATE_WAIT_AUTOCONNECT) { |
| 429 | DEBUG2(printk("scsi%ld: %s: FW initialized, but " |
| 430 | "auto-discovery still in process\n", |
| 431 | ha->host_no, __func__)); |
Vikas Chaudhary | b966346 | 2010-07-10 14:49:19 +0530 | [diff] [blame] | 432 | ready = 1; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | return ready; |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * qla4xxx_init_firmware - initializes the firmware. |
| 440 | * @ha: pointer to host adapter structure. |
| 441 | * |
| 442 | **/ |
| 443 | static int qla4xxx_init_firmware(struct scsi_qla_host *ha) |
| 444 | { |
| 445 | int status = QLA_ERROR; |
| 446 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 447 | if (is_aer_supported(ha) && |
| 448 | test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags)) |
| 449 | return status; |
| 450 | |
Lalit Chandivade | 9d4946f | 2010-07-30 14:26:31 +0530 | [diff] [blame] | 451 | /* For 82xx, stop firmware before initializing because if BIOS |
| 452 | * has previously initialized firmware, then driver's initialize |
| 453 | * firmware will fail. */ |
| 454 | if (is_qla8022(ha)) |
| 455 | qla4_8xxx_stop_firmware(ha); |
| 456 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 457 | ql4_printk(KERN_INFO, ha, "Initializing firmware..\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 458 | if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR) { |
| 459 | DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware " |
| 460 | "control block\n", ha->host_no, __func__)); |
| 461 | return status; |
| 462 | } |
| 463 | if (!qla4xxx_fw_ready(ha)) |
| 464 | return status; |
| 465 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 466 | return qla4xxx_get_firmware_status(ha); |
| 467 | } |
| 468 | |
| 469 | static struct ddb_entry* qla4xxx_get_ddb_entry(struct scsi_qla_host *ha, |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 470 | uint32_t fw_ddb_index, |
| 471 | uint32_t *new_tgt) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 472 | { |
| 473 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 474 | dma_addr_t fw_ddb_entry_dma; |
| 475 | struct ddb_entry *ddb_entry = NULL; |
| 476 | int found = 0; |
| 477 | uint32_t device_state; |
| 478 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 479 | *new_tgt = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 480 | /* Make sure the dma buffer is valid */ |
| 481 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, |
| 482 | sizeof(*fw_ddb_entry), |
| 483 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 484 | if (fw_ddb_entry == NULL) { |
| 485 | DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n", |
| 486 | ha->host_no, __func__)); |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 487 | goto exit_get_ddb_entry_no_free; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index, fw_ddb_entry, |
| 491 | fw_ddb_entry_dma, NULL, NULL, |
| 492 | &device_state, NULL, NULL, NULL) == |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 493 | QLA_ERROR) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 494 | DEBUG2(printk("scsi%ld: %s: failed get_ddb_entry for " |
| 495 | "fw_ddb_index %d\n", ha->host_no, __func__, |
| 496 | fw_ddb_index)); |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 497 | goto exit_get_ddb_entry; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /* Allocate DDB if not already allocated. */ |
| 501 | DEBUG2(printk("scsi%ld: %s: Looking for ddb[%d]\n", ha->host_no, |
| 502 | __func__, fw_ddb_index)); |
| 503 | list_for_each_entry(ddb_entry, &ha->ddb_list, list) { |
Mike Christie | 41bbdbe | 2009-01-16 12:36:52 -0600 | [diff] [blame] | 504 | if ((memcmp(ddb_entry->iscsi_name, fw_ddb_entry->iscsi_name, |
| 505 | ISCSI_NAME_SIZE) == 0) && |
| 506 | (ddb_entry->tpgt == |
| 507 | le32_to_cpu(fw_ddb_entry->tgt_portal_grp)) && |
| 508 | (memcmp(ddb_entry->isid, fw_ddb_entry->isid, |
| 509 | sizeof(ddb_entry->isid)) == 0)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 510 | found++; |
| 511 | break; |
| 512 | } |
| 513 | } |
| 514 | |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 515 | /* if not found allocate new ddb */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 516 | if (!found) { |
| 517 | DEBUG2(printk("scsi%ld: %s: ddb[%d] not found - allocating " |
| 518 | "new ddb\n", ha->host_no, __func__, |
| 519 | fw_ddb_index)); |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 520 | *new_tgt = 1; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 521 | ddb_entry = qla4xxx_alloc_ddb(ha, fw_ddb_index); |
| 522 | } |
| 523 | |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 524 | exit_get_ddb_entry: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 525 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry, |
| 526 | fw_ddb_entry_dma); |
| 527 | |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 528 | exit_get_ddb_entry_no_free: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 529 | return ddb_entry; |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * qla4xxx_update_ddb_entry - update driver's internal ddb |
| 534 | * @ha: pointer to host adapter structure. |
| 535 | * @ddb_entry: pointer to device database structure to be filled |
| 536 | * @fw_ddb_index: index of the ddb entry in fw ddb table |
| 537 | * |
| 538 | * This routine updates the driver's internal device database entry |
| 539 | * with information retrieved from the firmware's device database |
| 540 | * entry for the specified device. The ddb_entry->fw_ddb_index field |
| 541 | * must be initialized prior to calling this routine |
| 542 | * |
| 543 | **/ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 544 | static int qla4xxx_update_ddb_entry(struct scsi_qla_host *ha, |
| 545 | struct ddb_entry *ddb_entry, |
| 546 | uint32_t fw_ddb_index) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 547 | { |
| 548 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 549 | dma_addr_t fw_ddb_entry_dma; |
| 550 | int status = QLA_ERROR; |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 551 | uint32_t conn_err; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 552 | |
| 553 | if (ddb_entry == NULL) { |
| 554 | DEBUG2(printk("scsi%ld: %s: ddb_entry is NULL\n", ha->host_no, |
| 555 | __func__)); |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 556 | |
| 557 | goto exit_update_ddb_no_free; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /* Make sure the dma buffer is valid */ |
| 561 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, |
| 562 | sizeof(*fw_ddb_entry), |
| 563 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 564 | if (fw_ddb_entry == NULL) { |
| 565 | DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n", |
| 566 | ha->host_no, __func__)); |
| 567 | |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 568 | goto exit_update_ddb_no_free; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index, fw_ddb_entry, |
| 572 | fw_ddb_entry_dma, NULL, NULL, |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 573 | &ddb_entry->fw_ddb_device_state, &conn_err, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 574 | &ddb_entry->tcp_source_port_num, |
| 575 | &ddb_entry->connection_id) == |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 576 | QLA_ERROR) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 577 | DEBUG2(printk("scsi%ld: %s: failed get_ddb_entry for " |
| 578 | "fw_ddb_index %d\n", ha->host_no, __func__, |
| 579 | fw_ddb_index)); |
| 580 | |
| 581 | goto exit_update_ddb; |
| 582 | } |
| 583 | |
| 584 | status = QLA_SUCCESS; |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 585 | ddb_entry->options = le16_to_cpu(fw_ddb_entry->options); |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 586 | ddb_entry->target_session_id = le16_to_cpu(fw_ddb_entry->tsid); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 587 | ddb_entry->task_mgmt_timeout = |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 588 | le16_to_cpu(fw_ddb_entry->def_timeout); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 589 | ddb_entry->CmdSn = 0; |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 590 | ddb_entry->exe_throttle = le16_to_cpu(fw_ddb_entry->exec_throttle); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 591 | ddb_entry->default_relogin_timeout = |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 592 | le16_to_cpu(fw_ddb_entry->def_timeout); |
| 593 | ddb_entry->default_time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 594 | |
| 595 | /* Update index in case it changed */ |
| 596 | ddb_entry->fw_ddb_index = fw_ddb_index; |
| 597 | ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry; |
| 598 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 599 | ddb_entry->port = le16_to_cpu(fw_ddb_entry->port); |
| 600 | ddb_entry->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
Mike Christie | 41bbdbe | 2009-01-16 12:36:52 -0600 | [diff] [blame] | 601 | memcpy(ddb_entry->isid, fw_ddb_entry->isid, sizeof(ddb_entry->isid)); |
| 602 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 603 | memcpy(&ddb_entry->iscsi_name[0], &fw_ddb_entry->iscsi_name[0], |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 604 | min(sizeof(ddb_entry->iscsi_name), |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 605 | sizeof(fw_ddb_entry->iscsi_name))); |
Vikas Chaudhary | 3b2bef1 | 2010-07-10 14:51:30 +0530 | [diff] [blame] | 606 | memcpy(&ddb_entry->iscsi_alias[0], &fw_ddb_entry->iscsi_alias[0], |
| 607 | min(sizeof(ddb_entry->iscsi_alias), |
| 608 | sizeof(fw_ddb_entry->iscsi_alias))); |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 609 | memcpy(&ddb_entry->ip_addr[0], &fw_ddb_entry->ip_addr[0], |
| 610 | min(sizeof(ddb_entry->ip_addr), sizeof(fw_ddb_entry->ip_addr))); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 611 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 612 | ddb_entry->iscsi_max_burst_len = fw_ddb_entry->iscsi_max_burst_len; |
| 613 | ddb_entry->iscsi_max_outsnd_r2t = fw_ddb_entry->iscsi_max_outsnd_r2t; |
| 614 | ddb_entry->iscsi_first_burst_len = fw_ddb_entry->iscsi_first_burst_len; |
| 615 | ddb_entry->iscsi_max_rcv_data_seg_len = |
| 616 | fw_ddb_entry->iscsi_max_rcv_data_seg_len; |
| 617 | ddb_entry->iscsi_max_snd_data_seg_len = |
| 618 | fw_ddb_entry->iscsi_max_snd_data_seg_len; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 619 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 620 | if (ddb_entry->options & DDB_OPT_IPV6_DEVICE) { |
| 621 | memcpy(&ddb_entry->remote_ipv6_addr, |
| 622 | fw_ddb_entry->ip_addr, |
| 623 | min(sizeof(ddb_entry->remote_ipv6_addr), |
| 624 | sizeof(fw_ddb_entry->ip_addr))); |
| 625 | memcpy(&ddb_entry->link_local_ipv6_addr, |
| 626 | fw_ddb_entry->link_local_ipv6_addr, |
| 627 | min(sizeof(ddb_entry->link_local_ipv6_addr), |
| 628 | sizeof(fw_ddb_entry->link_local_ipv6_addr))); |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 629 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 630 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: DDB[%d] State %04x" |
| 631 | " ConnErr %08x IP %pI6 " |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 632 | ":%04d \"%s\"\n", |
| 633 | __func__, fw_ddb_index, |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 634 | ddb_entry->fw_ddb_device_state, |
| 635 | conn_err, fw_ddb_entry->ip_addr, |
| 636 | le16_to_cpu(fw_ddb_entry->port), |
| 637 | fw_ddb_entry->iscsi_name)); |
| 638 | } else |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 639 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: DDB[%d] State %04x" |
| 640 | " ConnErr %08x IP %pI4 " |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 641 | ":%04d \"%s\"\n", |
| 642 | __func__, fw_ddb_index, |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 643 | ddb_entry->fw_ddb_device_state, |
| 644 | conn_err, fw_ddb_entry->ip_addr, |
| 645 | le16_to_cpu(fw_ddb_entry->port), |
| 646 | fw_ddb_entry->iscsi_name)); |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 647 | exit_update_ddb: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 648 | if (fw_ddb_entry) |
| 649 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 650 | fw_ddb_entry, fw_ddb_entry_dma); |
| 651 | |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 652 | exit_update_ddb_no_free: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 653 | return status; |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * qla4xxx_alloc_ddb - allocate device database entry |
| 658 | * @ha: Pointer to host adapter structure. |
| 659 | * @fw_ddb_index: Firmware's device database index |
| 660 | * |
| 661 | * This routine allocates a ddb_entry, ititializes some values, and |
| 662 | * inserts it into the ddb list. |
| 663 | **/ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 664 | static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha, |
| 665 | uint32_t fw_ddb_index) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 666 | { |
| 667 | struct ddb_entry *ddb_entry; |
| 668 | |
| 669 | DEBUG2(printk("scsi%ld: %s: fw_ddb_index [%d]\n", ha->host_no, |
| 670 | __func__, fw_ddb_index)); |
| 671 | |
| 672 | ddb_entry = qla4xxx_alloc_sess(ha); |
| 673 | if (ddb_entry == NULL) { |
| 674 | DEBUG2(printk("scsi%ld: %s: Unable to allocate memory " |
| 675 | "to add fw_ddb_index [%d]\n", |
| 676 | ha->host_no, __func__, fw_ddb_index)); |
| 677 | return ddb_entry; |
| 678 | } |
| 679 | |
| 680 | ddb_entry->fw_ddb_index = fw_ddb_index; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 681 | atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY); |
| 682 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 683 | atomic_set(&ddb_entry->relogin_retry_count, 0); |
| 684 | atomic_set(&ddb_entry->state, DDB_STATE_ONLINE); |
| 685 | list_add_tail(&ddb_entry->list, &ha->ddb_list); |
| 686 | ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry; |
| 687 | ha->tot_ddbs++; |
| 688 | |
| 689 | return ddb_entry; |
| 690 | } |
| 691 | |
| 692 | /** |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 693 | * qla4_is_relogin_allowed - Are we allowed to login? |
| 694 | * @ha: Pointer to host adapter structure. |
| 695 | * @conn_err: Last connection error associated with the ddb |
| 696 | * |
| 697 | * This routine tests the given connection error to determine if |
| 698 | * we are allowed to login. |
| 699 | **/ |
| 700 | int qla4_is_relogin_allowed(struct scsi_qla_host *ha, uint32_t conn_err) |
| 701 | { |
| 702 | uint32_t err_code, login_rsp_sts_class; |
| 703 | int relogin = 1; |
| 704 | |
| 705 | err_code = ((conn_err & 0x00ff0000) >> 16); |
| 706 | login_rsp_sts_class = ((conn_err & 0x0000ff00) >> 8); |
| 707 | if (err_code == 0x1c || err_code == 0x06) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 708 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 709 | ": conn_err=0x%08x, send target completed" |
| 710 | " or access denied failure\n", conn_err)); |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 711 | relogin = 0; |
| 712 | } |
| 713 | if ((err_code == 0x08) && (login_rsp_sts_class == 0x02)) { |
| 714 | /* Login Response PDU returned an error. |
| 715 | Login Response Status in Error Code Detail |
| 716 | indicates login should not be retried.*/ |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 717 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 718 | ": conn_err=0x%08x, do not retry relogin\n", |
| 719 | conn_err)); |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 720 | relogin = 0; |
| 721 | } |
| 722 | |
| 723 | return relogin; |
| 724 | } |
| 725 | |
Karen Higgins | 7edd9a7 | 2011-03-21 03:34:27 -0700 | [diff] [blame] | 726 | static void qla4xxx_flush_AENS(struct scsi_qla_host *ha) |
| 727 | { |
| 728 | unsigned long wtime; |
| 729 | |
| 730 | /* Flush the 0x8014 AEN from the firmware as a result of |
| 731 | * Auto connect. We are basically doing get_firmware_ddb() |
| 732 | * to determine whether we need to log back in or not. |
| 733 | * Trying to do a set ddb before we have processed 0x8014 |
| 734 | * will result in another set_ddb() for the same ddb. In other |
| 735 | * words there will be stale entries in the aen_q. |
| 736 | */ |
| 737 | wtime = jiffies + (2 * HZ); |
| 738 | do { |
| 739 | if (qla4xxx_get_firmware_state(ha) == QLA_SUCCESS) |
| 740 | if (ha->firmware_state & (BIT_2 | BIT_0)) |
| 741 | return; |
| 742 | |
| 743 | if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags)) |
| 744 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 745 | |
| 746 | msleep(1000); |
| 747 | } while (!time_after_eq(jiffies, wtime)); |
| 748 | } |
| 749 | |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 750 | /** |
Karen Higgins | 7edd9a7 | 2011-03-21 03:34:27 -0700 | [diff] [blame] | 751 | * qla4xxx_build_ddb_list - builds driver ddb list |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 752 | * @ha: Pointer to host adapter structure. |
| 753 | * |
| 754 | * This routine searches for all valid firmware ddb entries and builds |
| 755 | * an internal ddb list. Ddbs that are considered valid are those with |
| 756 | * a device state of SESSION_ACTIVE. |
Karen Higgins | 7edd9a7 | 2011-03-21 03:34:27 -0700 | [diff] [blame] | 757 | * A relogin (set_ddb) is issued for DDBs that are not online. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 758 | **/ |
| 759 | static int qla4xxx_build_ddb_list(struct scsi_qla_host *ha) |
| 760 | { |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 761 | int status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 762 | uint32_t fw_ddb_index = 0; |
| 763 | uint32_t next_fw_ddb_index = 0; |
| 764 | uint32_t ddb_state; |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 765 | uint32_t conn_err; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 766 | struct ddb_entry *ddb_entry; |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 767 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 768 | dma_addr_t fw_ddb_entry_dma; |
| 769 | uint32_t ipv6_device; |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 770 | uint32_t new_tgt; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 771 | |
Karen Higgins | 7edd9a7 | 2011-03-21 03:34:27 -0700 | [diff] [blame] | 772 | qla4xxx_flush_AENS(ha); |
| 773 | |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 774 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 775 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 776 | if (fw_ddb_entry == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 777 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: DMA alloc failed\n", |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 778 | __func__)); |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 779 | |
| 780 | goto exit_build_ddb_list_no_free; |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 781 | } |
| 782 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 783 | ql4_printk(KERN_INFO, ha, "Initializing DDBs ...\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 784 | for (fw_ddb_index = 0; fw_ddb_index < MAX_DDB_ENTRIES; |
| 785 | fw_ddb_index = next_fw_ddb_index) { |
| 786 | /* First, let's see if a device exists here */ |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 787 | if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index, fw_ddb_entry, |
| 788 | 0, NULL, &next_fw_ddb_index, |
| 789 | &ddb_state, &conn_err, |
| 790 | NULL, NULL) == |
| 791 | QLA_ERROR) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 792 | DEBUG2(printk("scsi%ld: %s: get_ddb_entry, " |
| 793 | "fw_ddb_index %d failed", ha->host_no, |
| 794 | __func__, fw_ddb_index)); |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 795 | goto exit_build_ddb_list; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | DEBUG2(printk("scsi%ld: %s: Getting DDB[%d] ddbstate=0x%x, " |
| 799 | "next_fw_ddb_index=%d.\n", ha->host_no, __func__, |
| 800 | fw_ddb_index, ddb_state, next_fw_ddb_index)); |
| 801 | |
| 802 | /* Issue relogin, if necessary. */ |
| 803 | if (ddb_state == DDB_DS_SESSION_FAILED || |
| 804 | ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) { |
| 805 | /* Try and login to device */ |
| 806 | DEBUG2(printk("scsi%ld: %s: Login to DDB[%d]\n", |
| 807 | ha->host_no, __func__, fw_ddb_index)); |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 808 | ipv6_device = le16_to_cpu(fw_ddb_entry->options) & |
| 809 | DDB_OPT_IPV6_DEVICE; |
| 810 | if (qla4_is_relogin_allowed(ha, conn_err) && |
| 811 | ((!ipv6_device && |
| 812 | *((uint32_t *)fw_ddb_entry->ip_addr)) |
| 813 | || ipv6_device)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 814 | qla4xxx_set_ddb_entry(ha, fw_ddb_index, 0); |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 815 | if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index, |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 816 | NULL, 0, NULL, |
| 817 | &next_fw_ddb_index, |
| 818 | &ddb_state, &conn_err, |
| 819 | NULL, NULL) |
| 820 | == QLA_ERROR) { |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 821 | DEBUG2(printk("scsi%ld: %s:" |
| 822 | "get_ddb_entry %d failed\n", |
| 823 | ha->host_no, |
| 824 | __func__, fw_ddb_index)); |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 825 | goto exit_build_ddb_list; |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | if (ddb_state != DDB_DS_SESSION_ACTIVE) |
| 831 | goto next_one; |
| 832 | /* |
| 833 | * if fw_ddb with session active state found, |
| 834 | * add to ddb_list |
| 835 | */ |
| 836 | DEBUG2(printk("scsi%ld: %s: DDB[%d] added to list\n", |
| 837 | ha->host_no, __func__, fw_ddb_index)); |
| 838 | |
| 839 | /* Add DDB to internal our ddb list. */ |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 840 | ddb_entry = qla4xxx_get_ddb_entry(ha, fw_ddb_index, &new_tgt); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 841 | if (ddb_entry == NULL) { |
| 842 | DEBUG2(printk("scsi%ld: %s: Unable to allocate memory " |
| 843 | "for device at fw_ddb_index %d\n", |
| 844 | ha->host_no, __func__, fw_ddb_index)); |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 845 | goto exit_build_ddb_list; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 846 | } |
| 847 | /* Fill in the device structure */ |
| 848 | if (qla4xxx_update_ddb_entry(ha, ddb_entry, fw_ddb_index) == |
| 849 | QLA_ERROR) { |
| 850 | ha->fw_ddb_index_map[fw_ddb_index] = |
| 851 | (struct ddb_entry *)INVALID_ENTRY; |
| 852 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 853 | DEBUG2(printk("scsi%ld: %s: update_ddb_entry failed " |
| 854 | "for fw_ddb_index %d.\n", |
| 855 | ha->host_no, __func__, fw_ddb_index)); |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 856 | goto exit_build_ddb_list; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | next_one: |
| 860 | /* We know we've reached the last device when |
| 861 | * next_fw_ddb_index is 0 */ |
| 862 | if (next_fw_ddb_index == 0) |
| 863 | break; |
| 864 | } |
| 865 | |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 866 | status = QLA_SUCCESS; |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 867 | ql4_printk(KERN_INFO, ha, "DDB list done..\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 868 | |
Prasanna Mumbai | beabe7c | 2010-07-10 14:49:38 +0530 | [diff] [blame] | 869 | exit_build_ddb_list: |
| 870 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry, |
| 871 | fw_ddb_entry_dma); |
| 872 | |
| 873 | exit_build_ddb_list_no_free: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 874 | return status; |
| 875 | } |
| 876 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 877 | static int qla4xxx_initialize_ddb_list(struct scsi_qla_host *ha) |
| 878 | { |
| 879 | uint16_t fw_ddb_index; |
| 880 | int status = QLA_SUCCESS; |
| 881 | |
| 882 | /* free the ddb list if is not empty */ |
| 883 | if (!list_empty(&ha->ddb_list)) |
| 884 | qla4xxx_free_ddb_list(ha); |
| 885 | |
| 886 | for (fw_ddb_index = 0; fw_ddb_index < MAX_DDB_ENTRIES; fw_ddb_index++) |
| 887 | ha->fw_ddb_index_map[fw_ddb_index] = |
Karen Higgins | 7edd9a7 | 2011-03-21 03:34:27 -0700 | [diff] [blame] | 888 | (struct ddb_entry *)INVALID_ENTRY; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 889 | |
| 890 | ha->tot_ddbs = 0; |
| 891 | |
Karen Higgins | 7edd9a7 | 2011-03-21 03:34:27 -0700 | [diff] [blame] | 892 | /* Perform device discovery and build ddb list. */ |
| 893 | status = qla4xxx_build_ddb_list(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 894 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 895 | return status; |
| 896 | } |
| 897 | |
| 898 | /** |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 899 | * qla4xxx_reinitialize_ddb_list - update the driver ddb list |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 900 | * @ha: pointer to host adapter structure. |
| 901 | * |
| 902 | * This routine obtains device information from the F/W database after |
| 903 | * firmware or adapter resets. The device table is preserved. |
| 904 | **/ |
| 905 | int qla4xxx_reinitialize_ddb_list(struct scsi_qla_host *ha) |
| 906 | { |
| 907 | int status = QLA_SUCCESS; |
| 908 | struct ddb_entry *ddb_entry, *detemp; |
| 909 | |
| 910 | /* Update the device information for all devices. */ |
| 911 | list_for_each_entry_safe(ddb_entry, detemp, &ha->ddb_list, list) { |
| 912 | qla4xxx_update_ddb_entry(ha, ddb_entry, |
| 913 | ddb_entry->fw_ddb_index); |
| 914 | if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) { |
| 915 | atomic_set(&ddb_entry->state, DDB_STATE_ONLINE); |
| 916 | DEBUG2(printk ("scsi%ld: %s: ddb index [%d] marked " |
| 917 | "ONLINE\n", ha->host_no, __func__, |
| 918 | ddb_entry->fw_ddb_index)); |
Vikas Chaudhary | 3638632 | 2010-07-10 14:49:01 +0530 | [diff] [blame] | 919 | iscsi_unblock_session(ddb_entry->sess); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 920 | } else if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE) |
| 921 | qla4xxx_mark_device_missing(ha, ddb_entry); |
| 922 | } |
| 923 | return status; |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * qla4xxx_relogin_device - re-establish session |
| 928 | * @ha: Pointer to host adapter structure. |
| 929 | * @ddb_entry: Pointer to device database entry |
| 930 | * |
| 931 | * This routine does a session relogin with the specified device. |
| 932 | * The ddb entry must be assigned prior to making this call. |
| 933 | **/ |
| 934 | int qla4xxx_relogin_device(struct scsi_qla_host *ha, |
| 935 | struct ddb_entry * ddb_entry) |
| 936 | { |
| 937 | uint16_t relogin_timer; |
| 938 | |
| 939 | relogin_timer = max(ddb_entry->default_relogin_timeout, |
| 940 | (uint16_t)RELOGIN_TOV); |
| 941 | atomic_set(&ddb_entry->relogin_timer, relogin_timer); |
| 942 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 943 | DEBUG2(printk("scsi%ld: Relogin ddb [%d]. TOV=%d\n", ha->host_no, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 944 | ddb_entry->fw_ddb_index, relogin_timer)); |
| 945 | |
| 946 | qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index, 0); |
| 947 | |
| 948 | return QLA_SUCCESS; |
| 949 | } |
| 950 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 951 | static int qla4xxx_config_nvram(struct scsi_qla_host *ha) |
| 952 | { |
| 953 | unsigned long flags; |
| 954 | union external_hw_config_reg extHwConfig; |
| 955 | |
| 956 | DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha->host_no, |
| 957 | __func__)); |
| 958 | if (ql4xxx_lock_flash(ha) != QLA_SUCCESS) |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 959 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 960 | if (ql4xxx_lock_nvram(ha) != QLA_SUCCESS) { |
| 961 | ql4xxx_unlock_flash(ha); |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 962 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | /* Get EEPRom Parameters from NVRAM and validate */ |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 966 | ql4_printk(KERN_INFO, ha, "Configuring NVRAM ...\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 967 | if (qla4xxx_is_nvram_configuration_valid(ha) == QLA_SUCCESS) { |
| 968 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 969 | extHwConfig.Asuint32_t = |
| 970 | rd_nvram_word(ha, eeprom_ext_hw_conf_offset(ha)); |
| 971 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 972 | } else { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 973 | ql4_printk(KERN_WARNING, ha, |
| 974 | "scsi%ld: %s: EEProm checksum invalid. " |
| 975 | "Please update your EEPROM\n", ha->host_no, |
| 976 | __func__); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 977 | |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 978 | /* Attempt to set defaults */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 979 | if (is_qla4010(ha)) |
| 980 | extHwConfig.Asuint32_t = 0x1912; |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 981 | else if (is_qla4022(ha) | is_qla4032(ha)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 982 | extHwConfig.Asuint32_t = 0x0023; |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 983 | else |
| 984 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 985 | } |
| 986 | DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n", |
| 987 | ha->host_no, __func__, extHwConfig.Asuint32_t)); |
| 988 | |
| 989 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 990 | writel((0xFFFF << 16) | extHwConfig.Asuint32_t, isp_ext_hw_conf(ha)); |
| 991 | readl(isp_ext_hw_conf(ha)); |
| 992 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 993 | |
| 994 | ql4xxx_unlock_nvram(ha); |
| 995 | ql4xxx_unlock_flash(ha); |
| 996 | |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 997 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 998 | } |
| 999 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1000 | /** |
| 1001 | * qla4_8xxx_pci_config() - Setup ISP82xx PCI configuration registers. |
| 1002 | * @ha: HA context |
| 1003 | */ |
| 1004 | void qla4_8xxx_pci_config(struct scsi_qla_host *ha) |
| 1005 | { |
| 1006 | pci_set_master(ha->pdev); |
| 1007 | } |
| 1008 | |
| 1009 | void qla4xxx_pci_config(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1010 | { |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1011 | uint16_t w; |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 1012 | int status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1013 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1014 | ql4_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1015 | |
| 1016 | pci_set_master(ha->pdev); |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 1017 | status = pci_set_mwi(ha->pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1018 | /* |
| 1019 | * We want to respect framework's setting of PCI configuration space |
| 1020 | * command register and also want to make sure that all bits of |
| 1021 | * interest to us are properly set in command register. |
| 1022 | */ |
| 1023 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1024 | w |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1025 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 1026 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1027 | } |
| 1028 | |
| 1029 | static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host *ha) |
| 1030 | { |
| 1031 | int status = QLA_ERROR; |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 1032 | unsigned long max_wait_time; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1033 | unsigned long flags; |
| 1034 | uint32_t mbox_status; |
| 1035 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1036 | ql4_printk(KERN_INFO, ha, "Starting firmware ...\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1037 | |
| 1038 | /* |
| 1039 | * Start firmware from flash ROM |
| 1040 | * |
| 1041 | * WORKAROUND: Stuff a non-constant value that the firmware can |
| 1042 | * use as a seed for a random number generator in MB7 prior to |
| 1043 | * setting BOOT_ENABLE. Fixes problem where the TCP |
| 1044 | * connections use the same TCP ports after each reboot, |
| 1045 | * causing some connections to not get re-established. |
| 1046 | */ |
| 1047 | DEBUG(printk("scsi%d: %s: Start firmware from flash ROM\n", |
| 1048 | ha->host_no, __func__)); |
| 1049 | |
| 1050 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1051 | writel(jiffies, &ha->reg->mailbox[7]); |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 1052 | if (is_qla4022(ha) | is_qla4032(ha)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1053 | writel(set_rmask(NVR_WRITE_ENABLE), |
| 1054 | &ha->reg->u1.isp4022.nvram); |
| 1055 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1056 | writel(2, &ha->reg->mailbox[6]); |
| 1057 | readl(&ha->reg->mailbox[6]); |
| 1058 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1059 | writel(set_rmask(CSR_BOOT_ENABLE), &ha->reg->ctrl_status); |
| 1060 | readl(&ha->reg->ctrl_status); |
| 1061 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1062 | |
| 1063 | /* Wait for firmware to come UP. */ |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 1064 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: Wait up to %d seconds for " |
| 1065 | "boot firmware to complete...\n", |
| 1066 | ha->host_no, __func__, FIRMWARE_UP_TOV)); |
| 1067 | max_wait_time = jiffies + (FIRMWARE_UP_TOV * HZ); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1068 | do { |
| 1069 | uint32_t ctrl_status; |
| 1070 | |
| 1071 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1072 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 1073 | mbox_status = readw(&ha->reg->mailbox[0]); |
| 1074 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1075 | |
| 1076 | if (ctrl_status & set_rmask(CSR_SCSI_PROCESSOR_INTR)) |
| 1077 | break; |
| 1078 | if (mbox_status == MBOX_STS_COMMAND_COMPLETE) |
| 1079 | break; |
| 1080 | |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 1081 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: Waiting for boot " |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 1082 | "firmware to complete... ctrl_sts=0x%x, remaining=%ld\n", |
| 1083 | ha->host_no, __func__, ctrl_status, max_wait_time)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1084 | |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 1085 | msleep_interruptible(250); |
| 1086 | } while (!time_after_eq(jiffies, max_wait_time)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1087 | |
| 1088 | if (mbox_status == MBOX_STS_COMMAND_COMPLETE) { |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 1089 | DEBUG(printk(KERN_INFO "scsi%ld: %s: Firmware has started\n", |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1090 | ha->host_no, __func__)); |
| 1091 | |
| 1092 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1093 | writel(set_rmask(CSR_SCSI_PROCESSOR_INTR), |
| 1094 | &ha->reg->ctrl_status); |
| 1095 | readl(&ha->reg->ctrl_status); |
| 1096 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1097 | |
| 1098 | status = QLA_SUCCESS; |
| 1099 | } else { |
| 1100 | printk(KERN_INFO "scsi%ld: %s: Boot firmware failed " |
| 1101 | "- mbox status 0x%x\n", ha->host_no, __func__, |
| 1102 | mbox_status); |
| 1103 | status = QLA_ERROR; |
| 1104 | } |
| 1105 | return status; |
| 1106 | } |
| 1107 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1108 | int ql4xxx_lock_drvr_wait(struct scsi_qla_host *a) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1109 | { |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1110 | #define QL4_LOCK_DRVR_WAIT 60 |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 1111 | #define QL4_LOCK_DRVR_SLEEP 1 |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1112 | |
| 1113 | int drvr_wait = QL4_LOCK_DRVR_WAIT; |
| 1114 | while (drvr_wait) { |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1115 | if (ql4xxx_lock_drvr(a) == 0) { |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 1116 | ssleep(QL4_LOCK_DRVR_SLEEP); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1117 | if (drvr_wait) { |
| 1118 | DEBUG2(printk("scsi%ld: %s: Waiting for " |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1119 | "Global Init Semaphore(%d)...\n", |
| 1120 | a->host_no, |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 1121 | __func__, drvr_wait)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1122 | } |
| 1123 | drvr_wait -= QL4_LOCK_DRVR_SLEEP; |
| 1124 | } else { |
| 1125 | DEBUG2(printk("scsi%ld: %s: Global Init Semaphore " |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1126 | "acquired\n", a->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1127 | return QLA_SUCCESS; |
| 1128 | } |
| 1129 | } |
| 1130 | return QLA_ERROR; |
| 1131 | } |
| 1132 | |
| 1133 | /** |
| 1134 | * qla4xxx_start_firmware - starts qla4xxx firmware |
| 1135 | * @ha: Pointer to host adapter structure. |
| 1136 | * |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 1137 | * This routine performs the necessary steps to start the firmware for |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1138 | * the QLA4010 adapter. |
| 1139 | **/ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1140 | int qla4xxx_start_firmware(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1141 | { |
| 1142 | unsigned long flags = 0; |
| 1143 | uint32_t mbox_status; |
| 1144 | int status = QLA_ERROR; |
| 1145 | int soft_reset = 1; |
| 1146 | int config_chip = 0; |
| 1147 | |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 1148 | if (is_qla4022(ha) | is_qla4032(ha)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1149 | ql4xxx_set_mac_number(ha); |
| 1150 | |
| 1151 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 1152 | return QLA_ERROR; |
| 1153 | |
| 1154 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1155 | |
| 1156 | DEBUG2(printk("scsi%ld: %s: port_ctrl = 0x%08X\n", ha->host_no, |
| 1157 | __func__, readw(isp_port_ctrl(ha)))); |
| 1158 | DEBUG(printk("scsi%ld: %s: port_status = 0x%08X\n", ha->host_no, |
| 1159 | __func__, readw(isp_port_status(ha)))); |
| 1160 | |
| 1161 | /* Is Hardware already initialized? */ |
| 1162 | if ((readw(isp_port_ctrl(ha)) & 0x8000) != 0) { |
| 1163 | DEBUG(printk("scsi%ld: %s: Hardware has already been " |
| 1164 | "initialized\n", ha->host_no, __func__)); |
| 1165 | |
| 1166 | /* Receive firmware boot acknowledgement */ |
| 1167 | mbox_status = readw(&ha->reg->mailbox[0]); |
| 1168 | |
| 1169 | DEBUG2(printk("scsi%ld: %s: H/W Config complete - mbox[0]= " |
| 1170 | "0x%x\n", ha->host_no, __func__, mbox_status)); |
| 1171 | |
| 1172 | /* Is firmware already booted? */ |
| 1173 | if (mbox_status == 0) { |
| 1174 | /* F/W not running, must be config by net driver */ |
| 1175 | config_chip = 1; |
| 1176 | soft_reset = 0; |
| 1177 | } else { |
| 1178 | writel(set_rmask(CSR_SCSI_PROCESSOR_INTR), |
| 1179 | &ha->reg->ctrl_status); |
| 1180 | readl(&ha->reg->ctrl_status); |
| 1181 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1182 | if (qla4xxx_get_firmware_state(ha) == QLA_SUCCESS) { |
| 1183 | DEBUG2(printk("scsi%ld: %s: Get firmware " |
| 1184 | "state -- state = 0x%x\n", |
| 1185 | ha->host_no, |
| 1186 | __func__, ha->firmware_state)); |
| 1187 | /* F/W is running */ |
| 1188 | if (ha->firmware_state & |
| 1189 | FW_STATE_CONFIG_WAIT) { |
| 1190 | DEBUG2(printk("scsi%ld: %s: Firmware " |
| 1191 | "in known state -- " |
| 1192 | "config and " |
| 1193 | "boot, state = 0x%x\n", |
| 1194 | ha->host_no, __func__, |
| 1195 | ha->firmware_state)); |
| 1196 | config_chip = 1; |
| 1197 | soft_reset = 0; |
| 1198 | } |
| 1199 | } else { |
| 1200 | DEBUG2(printk("scsi%ld: %s: Firmware in " |
| 1201 | "unknown state -- resetting," |
| 1202 | " state = " |
| 1203 | "0x%x\n", ha->host_no, __func__, |
| 1204 | ha->firmware_state)); |
| 1205 | } |
| 1206 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1207 | } |
| 1208 | } else { |
| 1209 | DEBUG(printk("scsi%ld: %s: H/W initialization hasn't been " |
| 1210 | "started - resetting\n", ha->host_no, __func__)); |
| 1211 | } |
| 1212 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1213 | |
| 1214 | DEBUG(printk("scsi%ld: %s: Flags soft_rest=%d, config= %d\n ", |
| 1215 | ha->host_no, __func__, soft_reset, config_chip)); |
| 1216 | if (soft_reset) { |
| 1217 | DEBUG(printk("scsi%ld: %s: Issue Soft Reset\n", ha->host_no, |
| 1218 | __func__)); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1219 | status = qla4xxx_soft_reset(ha); /* NOTE: acquires drvr |
| 1220 | * lock again, but ok */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1221 | if (status == QLA_ERROR) { |
| 1222 | DEBUG(printk("scsi%d: %s: Soft Reset failed!\n", |
| 1223 | ha->host_no, __func__)); |
| 1224 | ql4xxx_unlock_drvr(ha); |
| 1225 | return QLA_ERROR; |
| 1226 | } |
| 1227 | config_chip = 1; |
| 1228 | |
Joe Perches | b1c1181 | 2008-02-03 17:28:22 +0200 | [diff] [blame] | 1229 | /* Reset clears the semaphore, so acquire again */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1230 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 1231 | return QLA_ERROR; |
| 1232 | } |
| 1233 | |
| 1234 | if (config_chip) { |
| 1235 | if ((status = qla4xxx_config_nvram(ha)) == QLA_SUCCESS) |
| 1236 | status = qla4xxx_start_firmware_from_flash(ha); |
| 1237 | } |
| 1238 | |
| 1239 | ql4xxx_unlock_drvr(ha); |
| 1240 | if (status == QLA_SUCCESS) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1241 | if (test_and_clear_bit(AF_GET_CRASH_RECORD, &ha->flags)) |
| 1242 | qla4xxx_get_crash_record(ha); |
| 1243 | } else { |
| 1244 | DEBUG(printk("scsi%ld: %s: Firmware has NOT started\n", |
| 1245 | ha->host_no, __func__)); |
| 1246 | } |
| 1247 | return status; |
| 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | /** |
| 1252 | * qla4xxx_initialize_adapter - initiailizes hba |
| 1253 | * @ha: Pointer to host adapter structure. |
| 1254 | * @renew_ddb_list: Indicates what to do with the adapter's ddb list |
| 1255 | * after adapter recovery has completed. |
| 1256 | * 0=preserve ddb list, 1=destroy and rebuild ddb list |
| 1257 | * |
| 1258 | * This routine parforms all of the steps necessary to initialize the adapter. |
| 1259 | * |
| 1260 | **/ |
| 1261 | int qla4xxx_initialize_adapter(struct scsi_qla_host *ha, |
| 1262 | uint8_t renew_ddb_list) |
| 1263 | { |
| 1264 | int status = QLA_ERROR; |
| 1265 | int8_t ip_address[IP_ADDR_LEN] = {0} ; |
| 1266 | |
| 1267 | ha->eeprom_cmd_data = 0; |
| 1268 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1269 | ql4_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
| 1270 | ha->isp_ops->pci_config(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1271 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1272 | ha->isp_ops->disable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1273 | |
| 1274 | /* Initialize the Host adapter request/response queues and firmware */ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1275 | if (ha->isp_ops->start_firmware(ha) == QLA_ERROR) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 1276 | goto exit_init_hba; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1277 | |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame^] | 1278 | if (qla4xxx_about_firmware(ha) == QLA_ERROR) |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1279 | goto exit_init_hba; |
| 1280 | |
| 1281 | if (ha->isp_ops->get_sys_info(ha) == QLA_ERROR) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 1282 | goto exit_init_hba; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1283 | |
| 1284 | if (qla4xxx_init_local_data(ha) == QLA_ERROR) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 1285 | goto exit_init_hba; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1286 | |
| 1287 | status = qla4xxx_init_firmware(ha); |
| 1288 | if (status == QLA_ERROR) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 1289 | goto exit_init_hba; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1290 | |
| 1291 | /* |
| 1292 | * FW is waiting to get an IP address from DHCP server: Skip building |
| 1293 | * the ddb_list and wait for DHCP lease acquired aen to come in |
| 1294 | * followed by 0x8014 aen" to trigger the tgt discovery process. |
| 1295 | */ |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 1296 | if (ha->firmware_state & FW_STATE_CONFIGURING_IP) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 1297 | goto exit_init_online; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1298 | |
| 1299 | /* Skip device discovery if ip and subnet is zero */ |
| 1300 | if (memcmp(ha->ip_address, ip_address, IP_ADDR_LEN) == 0 || |
| 1301 | memcmp(ha->subnet_mask, ip_address, IP_ADDR_LEN) == 0) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 1302 | goto exit_init_online; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1303 | |
| 1304 | if (renew_ddb_list == PRESERVE_DDB_LIST) { |
| 1305 | /* |
| 1306 | * We want to preserve lun states (i.e. suspended, etc.) |
| 1307 | * for recovery initiated by the driver. So just update |
| 1308 | * the device states for the existing ddb_list. |
| 1309 | */ |
| 1310 | qla4xxx_reinitialize_ddb_list(ha); |
| 1311 | } else if (renew_ddb_list == REBUILD_DDB_LIST) { |
| 1312 | /* |
| 1313 | * We want to build the ddb_list from scratch during |
| 1314 | * driver initialization and recovery initiated by the |
| 1315 | * INT_HBA_RESET IOCTL. |
| 1316 | */ |
| 1317 | status = qla4xxx_initialize_ddb_list(ha); |
| 1318 | if (status == QLA_ERROR) { |
| 1319 | DEBUG2(printk("%s(%ld) Error occurred during build" |
| 1320 | "ddb list\n", __func__, ha->host_no)); |
| 1321 | goto exit_init_hba; |
| 1322 | } |
| 1323 | |
| 1324 | } |
| 1325 | if (!ha->tot_ddbs) { |
| 1326 | DEBUG2(printk("scsi%ld: Failed to initialize devices or none " |
| 1327 | "present in Firmware device database\n", |
| 1328 | ha->host_no)); |
| 1329 | } |
| 1330 | |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 1331 | exit_init_online: |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1332 | set_bit(AF_ONLINE, &ha->flags); |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 1333 | exit_init_hba: |
Vikas Chaudhary | 3710c60 | 2010-10-06 22:49:08 -0700 | [diff] [blame] | 1334 | if (is_qla8022(ha) && (status == QLA_ERROR)) { |
| 1335 | /* Since interrupts are registered in start_firmware for |
| 1336 | * 82xx, release them here if initialize_adapter fails */ |
| 1337 | qla4xxx_free_irqs(ha); |
| 1338 | } |
| 1339 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1340 | DEBUG2(printk("scsi%ld: initialize adapter: %s\n", ha->host_no, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1341 | status == QLA_ERROR ? "FAILED" : "SUCCEEDED")); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1342 | return status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | /** |
| 1346 | * qla4xxx_add_device_dynamically - ddb addition due to an AEN |
| 1347 | * @ha: Pointer to host adapter structure. |
| 1348 | * @fw_ddb_index: Firmware's device database index |
| 1349 | * |
| 1350 | * This routine processes adds a device as a result of an 8014h AEN. |
| 1351 | **/ |
| 1352 | static void qla4xxx_add_device_dynamically(struct scsi_qla_host *ha, |
| 1353 | uint32_t fw_ddb_index) |
| 1354 | { |
| 1355 | struct ddb_entry * ddb_entry; |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1356 | uint32_t new_tgt; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1357 | |
| 1358 | /* First allocate a device structure */ |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1359 | ddb_entry = qla4xxx_get_ddb_entry(ha, fw_ddb_index, &new_tgt); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1360 | if (ddb_entry == NULL) { |
| 1361 | DEBUG2(printk(KERN_WARNING |
| 1362 | "scsi%ld: Unable to allocate memory to add " |
| 1363 | "fw_ddb_index %d\n", ha->host_no, fw_ddb_index)); |
| 1364 | return; |
| 1365 | } |
| 1366 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 1367 | if (!new_tgt && (ddb_entry->fw_ddb_index != fw_ddb_index)) { |
| 1368 | /* Target has been bound to a new fw_ddb_index */ |
| 1369 | qla4xxx_free_ddb(ha, ddb_entry); |
| 1370 | ddb_entry = qla4xxx_alloc_ddb(ha, fw_ddb_index); |
| 1371 | if (ddb_entry == NULL) { |
| 1372 | DEBUG2(printk(KERN_WARNING |
| 1373 | "scsi%ld: Unable to allocate memory" |
| 1374 | " to add fw_ddb_index %d\n", |
| 1375 | ha->host_no, fw_ddb_index)); |
| 1376 | return; |
| 1377 | } |
| 1378 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1379 | if (qla4xxx_update_ddb_entry(ha, ddb_entry, fw_ddb_index) == |
| 1380 | QLA_ERROR) { |
| 1381 | ha->fw_ddb_index_map[fw_ddb_index] = |
| 1382 | (struct ddb_entry *)INVALID_ENTRY; |
| 1383 | DEBUG2(printk(KERN_WARNING |
| 1384 | "scsi%ld: failed to add new device at index " |
| 1385 | "[%d]\n Unable to retrieve fw ddb entry\n", |
| 1386 | ha->host_no, fw_ddb_index)); |
| 1387 | qla4xxx_free_ddb(ha, ddb_entry); |
| 1388 | return; |
| 1389 | } |
| 1390 | |
| 1391 | if (qla4xxx_add_sess(ddb_entry)) { |
| 1392 | DEBUG2(printk(KERN_WARNING |
| 1393 | "scsi%ld: failed to add new device at index " |
| 1394 | "[%d]\n Unable to add connection and session\n", |
| 1395 | ha->host_no, fw_ddb_index)); |
| 1396 | qla4xxx_free_ddb(ha, ddb_entry); |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | /** |
| 1401 | * qla4xxx_process_ddb_changed - process ddb state change |
| 1402 | * @ha - Pointer to host adapter structure. |
| 1403 | * @fw_ddb_index - Firmware's device database index |
| 1404 | * @state - Device state |
| 1405 | * |
| 1406 | * This routine processes a Decive Database Changed AEN Event. |
| 1407 | **/ |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 1408 | int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index, |
| 1409 | uint32_t state, uint32_t conn_err) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1410 | { |
| 1411 | struct ddb_entry * ddb_entry; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1412 | |
| 1413 | /* check for out of range index */ |
| 1414 | if (fw_ddb_index >= MAX_DDB_ENTRIES) |
| 1415 | return QLA_ERROR; |
| 1416 | |
| 1417 | /* Get the corresponging ddb entry */ |
| 1418 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index); |
| 1419 | /* Device does not currently exist in our database. */ |
| 1420 | if (ddb_entry == NULL) { |
| 1421 | if (state == DDB_DS_SESSION_ACTIVE) |
| 1422 | qla4xxx_add_device_dynamically(ha, fw_ddb_index); |
| 1423 | return QLA_SUCCESS; |
| 1424 | } |
| 1425 | |
| 1426 | /* Device already exists in our database. */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1427 | DEBUG2(printk("scsi%ld: %s DDB - old state= 0x%x, new state=0x%x for " |
| 1428 | "index [%d]\n", ha->host_no, __func__, |
| 1429 | ddb_entry->fw_ddb_device_state, state, fw_ddb_index)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1430 | |
| 1431 | ddb_entry->fw_ddb_device_state = state; |
| 1432 | /* Device is back online. */ |
Vikas Chaudhary | fc7657c | 2011-03-21 03:34:30 -0700 | [diff] [blame] | 1433 | if ((ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) && |
| 1434 | (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)) { |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 1435 | atomic_set(&ddb_entry->state, DDB_STATE_ONLINE); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1436 | atomic_set(&ddb_entry->relogin_retry_count, 0); |
| 1437 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 1438 | clear_bit(DF_RELOGIN, &ddb_entry->flags); |
Mike Christie | b635930 | 2008-01-31 13:36:44 -0600 | [diff] [blame] | 1439 | iscsi_unblock_session(ddb_entry->sess); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1440 | iscsi_session_event(ddb_entry->sess, |
| 1441 | ISCSI_KEVENT_CREATE_SESSION); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1442 | /* |
| 1443 | * Change the lun state to READY in case the lun TIMEOUT before |
| 1444 | * the device came back. |
| 1445 | */ |
Vikas Chaudhary | fc7657c | 2011-03-21 03:34:30 -0700 | [diff] [blame] | 1446 | } else if (ddb_entry->fw_ddb_device_state != DDB_DS_SESSION_ACTIVE) { |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 1447 | /* Device went away, mark device missing */ |
| 1448 | if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1449 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s mark missing " |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 1450 | "ddb_entry 0x%p sess 0x%p conn 0x%p\n", |
| 1451 | __func__, ddb_entry, |
| 1452 | ddb_entry->sess, ddb_entry->conn)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1453 | qla4xxx_mark_device_missing(ha, ddb_entry); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 1454 | } |
| 1455 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1456 | /* |
| 1457 | * Relogin if device state changed to a not active state. |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 1458 | * However, do not relogin if a RELOGIN is in process, or |
| 1459 | * we are not allowed to relogin to this DDB. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1460 | */ |
| 1461 | if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_FAILED && |
| 1462 | !test_bit(DF_RELOGIN, &ddb_entry->flags) && |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 1463 | qla4_is_relogin_allowed(ha, conn_err)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1464 | /* |
| 1465 | * This triggers a relogin. After the relogin_timer |
| 1466 | * expires, the relogin gets scheduled. We must wait a |
| 1467 | * minimum amount of time since receiving an 0x8014 AEN |
| 1468 | * with failed device_state or a logout response before |
| 1469 | * we can issue another relogin. |
| 1470 | */ |
Vikas Chaudhary | 821d6e5 | 2010-04-28 11:41:21 +0530 | [diff] [blame] | 1471 | /* Firmware pads this timeout: (time2wait +1). |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1472 | * Driver retry to login should be longer than F/W. |
| 1473 | * Otherwise F/W will fail |
| 1474 | * set_ddb() mbx cmd with 0x4005 since it still |
| 1475 | * counting down its time2wait. |
| 1476 | */ |
| 1477 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 1478 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 1479 | ddb_entry->default_time2wait + 4); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1480 | DEBUG(printk("scsi%ld: %s: ddb[%d] " |
| 1481 | "initiate relogin after %d seconds\n", |
| 1482 | ha->host_no, __func__, |
| 1483 | ddb_entry->fw_ddb_index, |
| 1484 | ddb_entry->default_time2wait + 4)); |
| 1485 | } else { |
| 1486 | DEBUG(printk("scsi%ld: %s: ddb[%d] " |
| 1487 | "relogin not initiated, state = %d, " |
| 1488 | "ddb_entry->flags = 0x%lx\n", |
| 1489 | ha->host_no, __func__, |
| 1490 | ddb_entry->fw_ddb_index, |
| 1491 | ddb_entry->fw_ddb_device_state, |
| 1492 | ddb_entry->flags)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1493 | } |
| 1494 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1495 | return QLA_SUCCESS; |
| 1496 | } |