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