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