David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic iSCSI HBA Driver |
Vikas Chaudhary | 4a4f51e | 2013-08-16 07:03:04 -0400 | [diff] [blame] | 3 | * Copyright (c) 2003-2013 QLogic Corporation |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4 | * |
| 5 | * See LICENSE.qla4xxx for copyright and licensing details. |
| 6 | */ |
| 7 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 8 | #include <scsi/iscsi_if.h> |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9 | #include "ql4_def.h" |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 10 | #include "ql4_glbl.h" |
| 11 | #include "ql4_dbg.h" |
| 12 | #include "ql4_inline.h" |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 13 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 14 | static void ql4xxx_set_mac_number(struct scsi_qla_host *ha) |
| 15 | { |
| 16 | uint32_t value; |
| 17 | uint8_t func_number; |
| 18 | unsigned long flags; |
| 19 | |
| 20 | /* Get the function number */ |
| 21 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 22 | value = readw(&ha->reg->ctrl_status); |
| 23 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 24 | |
| 25 | func_number = (uint8_t) ((value >> 4) & 0x30); |
| 26 | switch (value & ISP_CONTROL_FN_MASK) { |
| 27 | case ISP_CONTROL_FN0_SCSI: |
| 28 | ha->mac_index = 1; |
| 29 | break; |
| 30 | case ISP_CONTROL_FN1_SCSI: |
| 31 | ha->mac_index = 3; |
| 32 | break; |
| 33 | default: |
| 34 | DEBUG2(printk("scsi%ld: %s: Invalid function number, " |
| 35 | "ispControlStatus = 0x%x\n", ha->host_no, |
| 36 | __func__, value)); |
| 37 | break; |
| 38 | } |
| 39 | DEBUG2(printk("scsi%ld: %s: mac_index %d.\n", ha->host_no, __func__, |
| 40 | ha->mac_index)); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * qla4xxx_free_ddb - deallocate ddb |
| 45 | * @ha: pointer to host adapter structure. |
| 46 | * @ddb_entry: pointer to device database entry |
| 47 | * |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 48 | * This routine marks a DDB entry INVALID |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 49 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 50 | void qla4xxx_free_ddb(struct scsi_qla_host *ha, |
| 51 | struct ddb_entry *ddb_entry) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 52 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 53 | /* Remove device pointer from index mapping arrays */ |
| 54 | ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = |
| 55 | (struct ddb_entry *) INVALID_ENTRY; |
| 56 | ha->tot_ddbs--; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 60 | * qla4xxx_init_response_q_entries() - Initializes response queue entries. |
| 61 | * @ha: HA context |
| 62 | * |
| 63 | * Beginning of request ring has initialization control block already built |
| 64 | * by nvram config routine. |
| 65 | **/ |
| 66 | static void qla4xxx_init_response_q_entries(struct scsi_qla_host *ha) |
| 67 | { |
| 68 | uint16_t cnt; |
| 69 | struct response *pkt; |
| 70 | |
| 71 | pkt = (struct response *)ha->response_ptr; |
| 72 | for (cnt = 0; cnt < RESPONSE_QUEUE_DEPTH; cnt++) { |
| 73 | pkt->signature = RESPONSE_PROCESSED; |
| 74 | pkt++; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 79 | * qla4xxx_init_rings - initialize hw queues |
| 80 | * @ha: pointer to host adapter structure. |
| 81 | * |
| 82 | * This routine initializes the internal queues for the specified adapter. |
| 83 | * The QLA4010 requires us to restart the queues at index 0. |
| 84 | * The QLA4000 doesn't care, so just default to QLA4010's requirement. |
| 85 | **/ |
| 86 | int qla4xxx_init_rings(struct scsi_qla_host *ha) |
| 87 | { |
| 88 | unsigned long flags = 0; |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 89 | int i; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 90 | |
| 91 | /* Initialize request queue. */ |
| 92 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 93 | ha->request_out = 0; |
| 94 | ha->request_in = 0; |
| 95 | ha->request_ptr = &ha->request_ring[ha->request_in]; |
| 96 | ha->req_q_count = REQUEST_QUEUE_DEPTH; |
| 97 | |
| 98 | /* Initialize response queue. */ |
| 99 | ha->response_in = 0; |
| 100 | ha->response_out = 0; |
| 101 | ha->response_ptr = &ha->response_ring[ha->response_out]; |
| 102 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 103 | if (is_qla8022(ha)) { |
| 104 | writel(0, |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 105 | (unsigned long __iomem *)&ha->qla4_82xx_reg->req_q_out); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 106 | writel(0, |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 107 | (unsigned long __iomem *)&ha->qla4_82xx_reg->rsp_q_in); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 108 | writel(0, |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 109 | (unsigned long __iomem *)&ha->qla4_82xx_reg->rsp_q_out); |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 110 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 111 | writel(0, |
| 112 | (unsigned long __iomem *)&ha->qla4_83xx_reg->req_q_in); |
| 113 | writel(0, |
| 114 | (unsigned long __iomem *)&ha->qla4_83xx_reg->rsp_q_in); |
| 115 | writel(0, |
| 116 | (unsigned long __iomem *)&ha->qla4_83xx_reg->rsp_q_out); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 117 | } else { |
| 118 | /* |
| 119 | * Initialize DMA Shadow registers. The firmware is really |
| 120 | * supposed to take care of this, but on some uniprocessor |
| 121 | * systems, the shadow registers aren't cleared-- causing |
| 122 | * the interrupt_handler to think there are responses to be |
| 123 | * processed when there aren't. |
| 124 | */ |
| 125 | ha->shadow_regs->req_q_out = __constant_cpu_to_le32(0); |
| 126 | ha->shadow_regs->rsp_q_in = __constant_cpu_to_le32(0); |
| 127 | wmb(); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 128 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 129 | writel(0, &ha->reg->req_q_in); |
| 130 | writel(0, &ha->reg->rsp_q_out); |
| 131 | readl(&ha->reg->rsp_q_out); |
| 132 | } |
| 133 | |
| 134 | qla4xxx_init_response_q_entries(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 135 | |
Vikas Chaudhary | 18e2df9 | 2012-06-14 10:13:53 -0400 | [diff] [blame] | 136 | /* Initialize mailbox active array */ |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 137 | for (i = 0; i < MAX_MRB; i++) |
| 138 | ha->active_mrb_array[i] = NULL; |
| 139 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 140 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 141 | |
| 142 | return QLA_SUCCESS; |
| 143 | } |
| 144 | |
| 145 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 146 | * qla4xxx_get_sys_info - validate adapter MAC address(es) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 147 | * @ha: pointer to host adapter structure. |
| 148 | * |
| 149 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 150 | int qla4xxx_get_sys_info(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 151 | { |
| 152 | struct flash_sys_info *sys_info; |
| 153 | dma_addr_t sys_info_dma; |
| 154 | int status = QLA_ERROR; |
| 155 | |
| 156 | sys_info = dma_alloc_coherent(&ha->pdev->dev, sizeof(*sys_info), |
| 157 | &sys_info_dma, GFP_KERNEL); |
| 158 | if (sys_info == NULL) { |
| 159 | DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n", |
| 160 | ha->host_no, __func__)); |
| 161 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 162 | goto exit_get_sys_info_no_free; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 163 | } |
| 164 | memset(sys_info, 0, sizeof(*sys_info)); |
| 165 | |
| 166 | /* Get flash sys info */ |
| 167 | if (qla4xxx_get_flash(ha, sys_info_dma, FLASH_OFFSET_SYS_INFO, |
| 168 | sizeof(*sys_info)) != QLA_SUCCESS) { |
| 169 | DEBUG2(printk("scsi%ld: %s: get_flash FLASH_OFFSET_SYS_INFO " |
| 170 | "failed\n", ha->host_no, __func__)); |
| 171 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 172 | goto exit_get_sys_info; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /* Save M.A.C. address & serial_number */ |
| 176 | memcpy(ha->my_mac, &sys_info->physAddr[0].address[0], |
| 177 | min(sizeof(ha->my_mac), |
| 178 | sizeof(sys_info->physAddr[0].address))); |
| 179 | memcpy(ha->serial_number, &sys_info->acSerialNumber, |
| 180 | min(sizeof(ha->serial_number), |
| 181 | sizeof(sys_info->acSerialNumber))); |
| 182 | |
| 183 | status = QLA_SUCCESS; |
| 184 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 185 | exit_get_sys_info: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 186 | dma_free_coherent(&ha->pdev->dev, sizeof(*sys_info), sys_info, |
| 187 | sys_info_dma); |
| 188 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 189 | exit_get_sys_info_no_free: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 190 | return status; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * qla4xxx_init_local_data - initialize adapter specific local data |
| 195 | * @ha: pointer to host adapter structure. |
| 196 | * |
| 197 | **/ |
Karen Higgins | ff4108d | 2013-01-20 23:50:59 -0500 | [diff] [blame] | 198 | static void qla4xxx_init_local_data(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 199 | { |
Uwe Kleine-König | 421f91d | 2010-06-11 12:17:00 +0200 | [diff] [blame] | 200 | /* Initialize aen queue */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 201 | ha->aen_q_count = MAX_AEN_ENTRIES; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 204 | static uint8_t |
| 205 | qla4xxx_wait_for_ip_config(struct scsi_qla_host *ha) |
| 206 | { |
| 207 | uint8_t ipv4_wait = 0; |
| 208 | uint8_t ipv6_wait = 0; |
| 209 | int8_t ip_address[IPv6_ADDR_LEN] = {0} ; |
| 210 | |
| 211 | /* If both IPv4 & IPv6 are enabled, possibly only one |
| 212 | * IP address may be acquired, so check to see if we |
| 213 | * need to wait for another */ |
| 214 | if (is_ipv4_enabled(ha) && is_ipv6_enabled(ha)) { |
| 215 | if (((ha->addl_fw_state & FW_ADDSTATE_DHCPv4_ENABLED) != 0) && |
| 216 | ((ha->addl_fw_state & |
| 217 | FW_ADDSTATE_DHCPv4_LEASE_ACQUIRED) == 0)) { |
| 218 | ipv4_wait = 1; |
| 219 | } |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 220 | if (((ha->ip_config.ipv6_addl_options & |
| 221 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) != 0) && |
| 222 | ((ha->ip_config.ipv6_link_local_state == |
| 223 | IP_ADDRSTATE_ACQUIRING) || |
| 224 | (ha->ip_config.ipv6_addr0_state == |
| 225 | IP_ADDRSTATE_ACQUIRING) || |
| 226 | (ha->ip_config.ipv6_addr1_state == |
| 227 | IP_ADDRSTATE_ACQUIRING))) { |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 228 | |
| 229 | ipv6_wait = 1; |
| 230 | |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 231 | if ((ha->ip_config.ipv6_link_local_state == |
| 232 | IP_ADDRSTATE_PREFERRED) || |
| 233 | (ha->ip_config.ipv6_addr0_state == |
| 234 | IP_ADDRSTATE_PREFERRED) || |
| 235 | (ha->ip_config.ipv6_addr1_state == |
| 236 | IP_ADDRSTATE_PREFERRED)) { |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 237 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: " |
| 238 | "Preferred IP configured." |
| 239 | " Don't wait!\n", ha->host_no, |
| 240 | __func__)); |
| 241 | ipv6_wait = 0; |
| 242 | } |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 243 | if (memcmp(&ha->ip_config.ipv6_default_router_addr, |
| 244 | ip_address, IPv6_ADDR_LEN) == 0) { |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 245 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: " |
| 246 | "No Router configured. " |
| 247 | "Don't wait!\n", ha->host_no, |
| 248 | __func__)); |
| 249 | ipv6_wait = 0; |
| 250 | } |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 251 | if ((ha->ip_config.ipv6_default_router_state == |
| 252 | IPV6_RTRSTATE_MANUAL) && |
| 253 | (ha->ip_config.ipv6_link_local_state == |
| 254 | IP_ADDRSTATE_TENTATIVE) && |
| 255 | (memcmp(&ha->ip_config.ipv6_link_local_addr, |
| 256 | &ha->ip_config.ipv6_default_router_addr, 4) == |
| 257 | 0)) { |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 258 | DEBUG2(printk("scsi%ld: %s: LinkLocal Router & " |
| 259 | "IP configured. Don't wait!\n", |
| 260 | ha->host_no, __func__)); |
| 261 | ipv6_wait = 0; |
| 262 | } |
| 263 | } |
| 264 | if (ipv4_wait || ipv6_wait) { |
| 265 | DEBUG2(printk("scsi%ld: %s: Wait for additional " |
| 266 | "IP(s) \"", ha->host_no, __func__)); |
| 267 | if (ipv4_wait) |
| 268 | DEBUG2(printk("IPv4 ")); |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 269 | if (ha->ip_config.ipv6_link_local_state == |
| 270 | IP_ADDRSTATE_ACQUIRING) |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 271 | DEBUG2(printk("IPv6LinkLocal ")); |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 272 | if (ha->ip_config.ipv6_addr0_state == |
| 273 | IP_ADDRSTATE_ACQUIRING) |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 274 | DEBUG2(printk("IPv6Addr0 ")); |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 275 | if (ha->ip_config.ipv6_addr1_state == |
| 276 | IP_ADDRSTATE_ACQUIRING) |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 277 | DEBUG2(printk("IPv6Addr1 ")); |
| 278 | DEBUG2(printk("\"\n")); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return ipv4_wait|ipv6_wait; |
| 283 | } |
| 284 | |
Tej Parkash | b410982 | 2014-02-24 22:06:58 -0500 | [diff] [blame] | 285 | static int qla4_80xx_is_minidump_dma_capable(struct scsi_qla_host *ha, |
| 286 | struct qla4_8xxx_minidump_template_hdr *md_hdr) |
| 287 | { |
| 288 | int offset = (is_qla8022(ha)) ? QLA8022_TEMPLATE_CAP_OFFSET : |
| 289 | QLA83XX_TEMPLATE_CAP_OFFSET; |
| 290 | int rval = 1; |
| 291 | uint32_t *cap_offset; |
| 292 | |
| 293 | cap_offset = (uint32_t *)((char *)md_hdr + offset); |
| 294 | |
| 295 | if (!(le32_to_cpu(*cap_offset) & BIT_0)) { |
| 296 | ql4_printk(KERN_INFO, ha, "PEX DMA Not supported %d\n", |
| 297 | *cap_offset); |
| 298 | rval = 0; |
| 299 | } |
| 300 | |
| 301 | return rval; |
| 302 | } |
| 303 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 304 | /** |
| 305 | * qla4xxx_alloc_fw_dump - Allocate memory for minidump data. |
| 306 | * @ha: pointer to host adapter structure. |
| 307 | **/ |
| 308 | void qla4xxx_alloc_fw_dump(struct scsi_qla_host *ha) |
| 309 | { |
| 310 | int status; |
| 311 | uint32_t capture_debug_level; |
| 312 | int hdr_entry_bit, k; |
| 313 | void *md_tmp; |
| 314 | dma_addr_t md_tmp_dma; |
| 315 | struct qla4_8xxx_minidump_template_hdr *md_hdr; |
Tej Parkash | b410982 | 2014-02-24 22:06:58 -0500 | [diff] [blame] | 316 | int dma_capable; |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 317 | |
| 318 | if (ha->fw_dump) { |
| 319 | ql4_printk(KERN_WARNING, ha, |
| 320 | "Firmware dump previously allocated.\n"); |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | status = qla4xxx_req_template_size(ha); |
| 325 | if (status != QLA_SUCCESS) { |
| 326 | ql4_printk(KERN_INFO, ha, |
| 327 | "scsi%ld: Failed to get template size\n", |
| 328 | ha->host_no); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | clear_bit(AF_82XX_FW_DUMPED, &ha->flags); |
| 333 | |
| 334 | /* Allocate memory for saving the template */ |
| 335 | md_tmp = dma_alloc_coherent(&ha->pdev->dev, ha->fw_dump_tmplt_size, |
| 336 | &md_tmp_dma, GFP_KERNEL); |
Maurizio Lombardi | a5c277e | 2014-07-28 14:55:27 +0200 | [diff] [blame] | 337 | if (!md_tmp) { |
| 338 | ql4_printk(KERN_INFO, ha, |
| 339 | "scsi%ld: Failed to allocate DMA memory\n", |
| 340 | ha->host_no); |
| 341 | return; |
| 342 | } |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 343 | |
| 344 | /* Request template */ |
| 345 | status = qla4xxx_get_minidump_template(ha, md_tmp_dma); |
| 346 | if (status != QLA_SUCCESS) { |
| 347 | ql4_printk(KERN_INFO, ha, |
| 348 | "scsi%ld: Failed to get minidump template\n", |
| 349 | ha->host_no); |
| 350 | goto alloc_cleanup; |
| 351 | } |
| 352 | |
| 353 | md_hdr = (struct qla4_8xxx_minidump_template_hdr *)md_tmp; |
| 354 | |
Tej Parkash | b410982 | 2014-02-24 22:06:58 -0500 | [diff] [blame] | 355 | dma_capable = qla4_80xx_is_minidump_dma_capable(ha, md_hdr); |
| 356 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 357 | capture_debug_level = md_hdr->capture_debug_level; |
| 358 | |
| 359 | /* Get capture mask based on module loadtime setting. */ |
Tej Parkash | b410982 | 2014-02-24 22:06:58 -0500 | [diff] [blame] | 360 | if ((ql4xmdcapmask >= 0x3 && ql4xmdcapmask <= 0x7F) || |
| 361 | (ql4xmdcapmask == 0xFF && dma_capable)) { |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 362 | ha->fw_dump_capture_mask = ql4xmdcapmask; |
Tej Parkash | b410982 | 2014-02-24 22:06:58 -0500 | [diff] [blame] | 363 | } else { |
| 364 | if (ql4xmdcapmask == 0xFF) |
| 365 | ql4_printk(KERN_INFO, ha, "Falling back to default capture mask, as PEX DMA is not supported\n"); |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 366 | ha->fw_dump_capture_mask = capture_debug_level; |
Tej Parkash | b410982 | 2014-02-24 22:06:58 -0500 | [diff] [blame] | 367 | } |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 368 | |
| 369 | md_hdr->driver_capture_mask = ha->fw_dump_capture_mask; |
| 370 | |
| 371 | DEBUG2(ql4_printk(KERN_INFO, ha, "Minimum num of entries = %d\n", |
| 372 | md_hdr->num_of_entries)); |
| 373 | DEBUG2(ql4_printk(KERN_INFO, ha, "Dump template size = %d\n", |
| 374 | ha->fw_dump_tmplt_size)); |
| 375 | DEBUG2(ql4_printk(KERN_INFO, ha, "Selected Capture mask =0x%x\n", |
| 376 | ha->fw_dump_capture_mask)); |
| 377 | |
| 378 | /* Calculate fw_dump_size */ |
| 379 | for (hdr_entry_bit = 0x2, k = 1; (hdr_entry_bit & 0xFF); |
| 380 | hdr_entry_bit <<= 1, k++) { |
| 381 | if (hdr_entry_bit & ha->fw_dump_capture_mask) |
| 382 | ha->fw_dump_size += md_hdr->capture_size_array[k]; |
| 383 | } |
| 384 | |
| 385 | /* Total firmware dump size including command header */ |
| 386 | ha->fw_dump_size += ha->fw_dump_tmplt_size; |
| 387 | ha->fw_dump = vmalloc(ha->fw_dump_size); |
| 388 | if (!ha->fw_dump) |
| 389 | goto alloc_cleanup; |
| 390 | |
| 391 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 392 | "Minidump Tempalate Size = 0x%x KB\n", |
| 393 | ha->fw_dump_tmplt_size)); |
| 394 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 395 | "Total Minidump size = 0x%x KB\n", ha->fw_dump_size)); |
| 396 | |
| 397 | memcpy(ha->fw_dump, md_tmp, ha->fw_dump_tmplt_size); |
| 398 | ha->fw_dump_tmplt_hdr = ha->fw_dump; |
| 399 | |
| 400 | alloc_cleanup: |
| 401 | dma_free_coherent(&ha->pdev->dev, ha->fw_dump_tmplt_size, |
| 402 | md_tmp, md_tmp_dma); |
| 403 | } |
| 404 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 405 | static int qla4xxx_fw_ready(struct scsi_qla_host *ha) |
| 406 | { |
| 407 | uint32_t timeout_count; |
| 408 | int ready = 0; |
| 409 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 410 | DEBUG2(ql4_printk(KERN_INFO, ha, "Waiting for Firmware Ready..\n")); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 411 | for (timeout_count = ADAPTER_INIT_TOV; timeout_count > 0; |
| 412 | timeout_count--) { |
| 413 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags)) |
| 414 | qla4xxx_get_dhcp_ip_address(ha); |
| 415 | |
| 416 | /* Get firmware state. */ |
| 417 | if (qla4xxx_get_firmware_state(ha) != QLA_SUCCESS) { |
| 418 | DEBUG2(printk("scsi%ld: %s: unable to get firmware " |
| 419 | "state\n", ha->host_no, __func__)); |
| 420 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | if (ha->firmware_state & FW_STATE_ERROR) { |
| 424 | DEBUG2(printk("scsi%ld: %s: an unrecoverable error has" |
| 425 | " occurred\n", ha->host_no, __func__)); |
| 426 | break; |
| 427 | |
| 428 | } |
| 429 | if (ha->firmware_state & FW_STATE_CONFIG_WAIT) { |
| 430 | /* |
| 431 | * The firmware has not yet been issued an Initialize |
| 432 | * Firmware command, so issue it now. |
| 433 | */ |
| 434 | if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR) |
| 435 | break; |
| 436 | |
| 437 | /* Go back and test for ready state - no wait. */ |
| 438 | continue; |
| 439 | } |
| 440 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 441 | if (ha->firmware_state & FW_STATE_WAIT_AUTOCONNECT) { |
| 442 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: fwstate:" |
| 443 | "AUTOCONNECT in progress\n", |
| 444 | ha->host_no, __func__)); |
| 445 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 446 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 447 | if (ha->firmware_state & FW_STATE_CONFIGURING_IP) { |
| 448 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: fwstate:" |
| 449 | " CONFIGURING IP\n", |
| 450 | ha->host_no, __func__)); |
| 451 | /* |
| 452 | * Check for link state after 15 secs and if link is |
| 453 | * still DOWN then, cable is unplugged. Ignore "DHCP |
| 454 | * in Progress/CONFIGURING IP" bit to check if firmware |
| 455 | * is in ready state or not after 15 secs. |
| 456 | * This is applicable for both 2.x & 3.x firmware |
| 457 | */ |
| 458 | if (timeout_count <= (ADAPTER_INIT_TOV - 15)) { |
| 459 | if (ha->addl_fw_state & FW_ADDSTATE_LINK_UP) { |
| 460 | DEBUG2(printk(KERN_INFO "scsi%ld: %s:" |
| 461 | " LINK UP (Cable plugged)\n", |
| 462 | ha->host_no, __func__)); |
| 463 | } else if (ha->firmware_state & |
| 464 | (FW_STATE_CONFIGURING_IP | |
| 465 | FW_STATE_READY)) { |
| 466 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: " |
| 467 | "LINK DOWN (Cable unplugged)\n", |
| 468 | ha->host_no, __func__)); |
| 469 | ha->firmware_state = FW_STATE_READY; |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | if (ha->firmware_state == FW_STATE_READY) { |
| 475 | /* If DHCP IP Addr is available, retrieve it now. */ |
| 476 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, |
| 477 | &ha->dpc_flags)) |
| 478 | qla4xxx_get_dhcp_ip_address(ha); |
| 479 | |
| 480 | if (!qla4xxx_wait_for_ip_config(ha) || |
| 481 | timeout_count == 1) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 482 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 483 | "Firmware Ready..\n")); |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 484 | /* The firmware is ready to process SCSI |
| 485 | commands. */ |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 486 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 487 | "scsi%ld: %s: MEDIA TYPE" |
| 488 | " - %s\n", ha->host_no, |
| 489 | __func__, (ha->addl_fw_state & |
| 490 | FW_ADDSTATE_OPTICAL_MEDIA) |
| 491 | != 0 ? "OPTICAL" : "COPPER")); |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 492 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 493 | "scsi%ld: %s: DHCPv4 STATE" |
| 494 | " Enabled %s\n", ha->host_no, |
| 495 | __func__, (ha->addl_fw_state & |
| 496 | FW_ADDSTATE_DHCPv4_ENABLED) != 0 ? |
| 497 | "YES" : "NO")); |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 498 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 499 | "scsi%ld: %s: LINK %s\n", |
| 500 | ha->host_no, __func__, |
| 501 | (ha->addl_fw_state & |
| 502 | FW_ADDSTATE_LINK_UP) != 0 ? |
| 503 | "UP" : "DOWN")); |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 504 | DEBUG2(ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 505 | "scsi%ld: %s: iSNS Service " |
| 506 | "Started %s\n", |
| 507 | ha->host_no, __func__, |
| 508 | (ha->addl_fw_state & |
| 509 | FW_ADDSTATE_ISNS_SVC_ENABLED) != 0 ? |
| 510 | "YES" : "NO")); |
| 511 | |
| 512 | ready = 1; |
| 513 | break; |
| 514 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 515 | } |
| 516 | DEBUG2(printk("scsi%ld: %s: waiting on fw, state=%x:%x - " |
| 517 | "seconds expired= %d\n", ha->host_no, __func__, |
| 518 | ha->firmware_state, ha->addl_fw_state, |
| 519 | timeout_count)); |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 520 | if (is_qla4032(ha) && |
| 521 | !(ha->addl_fw_state & FW_ADDSTATE_LINK_UP) && |
| 522 | (timeout_count < ADAPTER_INIT_TOV - 5)) { |
| 523 | break; |
| 524 | } |
| 525 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 526 | msleep(1000); |
| 527 | } /* end of for */ |
| 528 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 529 | if (timeout_count <= 0) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 530 | DEBUG2(printk("scsi%ld: %s: FW Initialization timed out!\n", |
| 531 | ha->host_no, __func__)); |
| 532 | |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 533 | if (ha->firmware_state & FW_STATE_CONFIGURING_IP) { |
| 534 | DEBUG2(printk("scsi%ld: %s: FW initialized, but is reporting " |
| 535 | "it's waiting to configure an IP address\n", |
| 536 | ha->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 537 | ready = 1; |
Vikas Chaudhary | 2a49a78 | 2010-04-28 11:37:07 +0530 | [diff] [blame] | 538 | } else if (ha->firmware_state & FW_STATE_WAIT_AUTOCONNECT) { |
| 539 | DEBUG2(printk("scsi%ld: %s: FW initialized, but " |
| 540 | "auto-discovery still in process\n", |
| 541 | ha->host_no, __func__)); |
Vikas Chaudhary | b966346 | 2010-07-10 14:49:19 +0530 | [diff] [blame] | 542 | ready = 1; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | return ready; |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * qla4xxx_init_firmware - initializes the firmware. |
| 550 | * @ha: pointer to host adapter structure. |
| 551 | * |
| 552 | **/ |
| 553 | static int qla4xxx_init_firmware(struct scsi_qla_host *ha) |
| 554 | { |
| 555 | int status = QLA_ERROR; |
| 556 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 557 | if (is_aer_supported(ha) && |
| 558 | test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags)) |
| 559 | return status; |
| 560 | |
Lalit Chandivade | 9d4946f | 2010-07-30 14:26:31 +0530 | [diff] [blame] | 561 | /* For 82xx, stop firmware before initializing because if BIOS |
| 562 | * has previously initialized firmware, then driver's initialize |
| 563 | * firmware will fail. */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 564 | if (is_qla80XX(ha)) |
Lalit Chandivade | 9d4946f | 2010-07-30 14:26:31 +0530 | [diff] [blame] | 565 | qla4_8xxx_stop_firmware(ha); |
| 566 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 567 | ql4_printk(KERN_INFO, ha, "Initializing firmware..\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 568 | if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR) { |
| 569 | DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware " |
| 570 | "control block\n", ha->host_no, __func__)); |
| 571 | return status; |
| 572 | } |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 573 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 574 | if (!qla4xxx_fw_ready(ha)) |
| 575 | return status; |
| 576 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 577 | if (is_qla80XX(ha) && !test_bit(AF_INIT_DONE, &ha->flags)) |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 578 | qla4xxx_alloc_fw_dump(ha); |
| 579 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 580 | return qla4xxx_get_firmware_status(ha); |
| 581 | } |
| 582 | |
Vikas Chaudhary | 91ec7ce | 2011-08-01 03:26:17 -0700 | [diff] [blame] | 583 | static void qla4xxx_set_model_info(struct scsi_qla_host *ha) |
| 584 | { |
| 585 | uint16_t board_id_string[8]; |
| 586 | int i; |
| 587 | int size = sizeof(ha->nvram->isp4022.boardIdStr); |
| 588 | int offset = offsetof(struct eeprom_data, isp4022.boardIdStr) / 2; |
| 589 | |
| 590 | for (i = 0; i < (size / 2) ; i++) { |
| 591 | board_id_string[i] = rd_nvram_word(ha, offset); |
| 592 | offset += 1; |
| 593 | } |
| 594 | |
| 595 | memcpy(ha->model_name, board_id_string, size); |
| 596 | } |
| 597 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 598 | static int qla4xxx_config_nvram(struct scsi_qla_host *ha) |
| 599 | { |
| 600 | unsigned long flags; |
| 601 | union external_hw_config_reg extHwConfig; |
| 602 | |
| 603 | DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha->host_no, |
| 604 | __func__)); |
| 605 | if (ql4xxx_lock_flash(ha) != QLA_SUCCESS) |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 606 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 607 | if (ql4xxx_lock_nvram(ha) != QLA_SUCCESS) { |
| 608 | ql4xxx_unlock_flash(ha); |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 609 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /* Get EEPRom Parameters from NVRAM and validate */ |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 613 | ql4_printk(KERN_INFO, ha, "Configuring NVRAM ...\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 614 | if (qla4xxx_is_nvram_configuration_valid(ha) == QLA_SUCCESS) { |
| 615 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 616 | extHwConfig.Asuint32_t = |
| 617 | rd_nvram_word(ha, eeprom_ext_hw_conf_offset(ha)); |
| 618 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 619 | } else { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 620 | ql4_printk(KERN_WARNING, ha, |
| 621 | "scsi%ld: %s: EEProm checksum invalid. " |
| 622 | "Please update your EEPROM\n", ha->host_no, |
| 623 | __func__); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 624 | |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 625 | /* Attempt to set defaults */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 626 | if (is_qla4010(ha)) |
| 627 | extHwConfig.Asuint32_t = 0x1912; |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 628 | else if (is_qla4022(ha) | is_qla4032(ha)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 629 | extHwConfig.Asuint32_t = 0x0023; |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 630 | else |
| 631 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 632 | } |
Vikas Chaudhary | 91ec7ce | 2011-08-01 03:26:17 -0700 | [diff] [blame] | 633 | |
| 634 | if (is_qla4022(ha) || is_qla4032(ha)) |
| 635 | qla4xxx_set_model_info(ha); |
| 636 | else |
| 637 | strcpy(ha->model_name, "QLA4010"); |
| 638 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 639 | DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n", |
| 640 | ha->host_no, __func__, extHwConfig.Asuint32_t)); |
| 641 | |
| 642 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 643 | writel((0xFFFF << 16) | extHwConfig.Asuint32_t, isp_ext_hw_conf(ha)); |
| 644 | readl(isp_ext_hw_conf(ha)); |
| 645 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 646 | |
| 647 | ql4xxx_unlock_nvram(ha); |
| 648 | ql4xxx_unlock_flash(ha); |
| 649 | |
Mike Christie | b392551 | 2010-02-10 16:51:48 -0600 | [diff] [blame] | 650 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 653 | /** |
| 654 | * qla4_8xxx_pci_config() - Setup ISP82xx PCI configuration registers. |
| 655 | * @ha: HA context |
| 656 | */ |
| 657 | void qla4_8xxx_pci_config(struct scsi_qla_host *ha) |
| 658 | { |
| 659 | pci_set_master(ha->pdev); |
| 660 | } |
| 661 | |
| 662 | void qla4xxx_pci_config(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 663 | { |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 664 | uint16_t w; |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 665 | int status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 666 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 667 | ql4_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 668 | |
| 669 | pci_set_master(ha->pdev); |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 670 | status = pci_set_mwi(ha->pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 671 | /* |
| 672 | * We want to respect framework's setting of PCI configuration space |
| 673 | * command register and also want to make sure that all bits of |
| 674 | * interest to us are properly set in command register. |
| 675 | */ |
| 676 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 677 | w |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 678 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 679 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 680 | } |
| 681 | |
| 682 | static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host *ha) |
| 683 | { |
| 684 | int status = QLA_ERROR; |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 685 | unsigned long max_wait_time; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 686 | unsigned long flags; |
| 687 | uint32_t mbox_status; |
| 688 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 689 | ql4_printk(KERN_INFO, ha, "Starting firmware ...\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 690 | |
| 691 | /* |
| 692 | * Start firmware from flash ROM |
| 693 | * |
| 694 | * WORKAROUND: Stuff a non-constant value that the firmware can |
| 695 | * use as a seed for a random number generator in MB7 prior to |
| 696 | * setting BOOT_ENABLE. Fixes problem where the TCP |
| 697 | * connections use the same TCP ports after each reboot, |
| 698 | * causing some connections to not get re-established. |
| 699 | */ |
| 700 | DEBUG(printk("scsi%d: %s: Start firmware from flash ROM\n", |
| 701 | ha->host_no, __func__)); |
| 702 | |
| 703 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 704 | writel(jiffies, &ha->reg->mailbox[7]); |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 705 | if (is_qla4022(ha) | is_qla4032(ha)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 706 | writel(set_rmask(NVR_WRITE_ENABLE), |
| 707 | &ha->reg->u1.isp4022.nvram); |
| 708 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 709 | writel(2, &ha->reg->mailbox[6]); |
| 710 | readl(&ha->reg->mailbox[6]); |
| 711 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 712 | writel(set_rmask(CSR_BOOT_ENABLE), &ha->reg->ctrl_status); |
| 713 | readl(&ha->reg->ctrl_status); |
| 714 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 715 | |
| 716 | /* Wait for firmware to come UP. */ |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 717 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: Wait up to %d seconds for " |
| 718 | "boot firmware to complete...\n", |
| 719 | ha->host_no, __func__, FIRMWARE_UP_TOV)); |
| 720 | max_wait_time = jiffies + (FIRMWARE_UP_TOV * HZ); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 721 | do { |
| 722 | uint32_t ctrl_status; |
| 723 | |
| 724 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 725 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 726 | mbox_status = readw(&ha->reg->mailbox[0]); |
| 727 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 728 | |
| 729 | if (ctrl_status & set_rmask(CSR_SCSI_PROCESSOR_INTR)) |
| 730 | break; |
| 731 | if (mbox_status == MBOX_STS_COMMAND_COMPLETE) |
| 732 | break; |
| 733 | |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 734 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: Waiting for boot " |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 735 | "firmware to complete... ctrl_sts=0x%x, remaining=%ld\n", |
| 736 | ha->host_no, __func__, ctrl_status, max_wait_time)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 737 | |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 738 | msleep_interruptible(250); |
| 739 | } while (!time_after_eq(jiffies, max_wait_time)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 740 | |
| 741 | if (mbox_status == MBOX_STS_COMMAND_COMPLETE) { |
Vikas Chaudhary | c301b02 | 2010-04-28 11:40:37 +0530 | [diff] [blame] | 742 | DEBUG(printk(KERN_INFO "scsi%ld: %s: Firmware has started\n", |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 743 | ha->host_no, __func__)); |
| 744 | |
| 745 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 746 | writel(set_rmask(CSR_SCSI_PROCESSOR_INTR), |
| 747 | &ha->reg->ctrl_status); |
| 748 | readl(&ha->reg->ctrl_status); |
| 749 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 750 | |
| 751 | status = QLA_SUCCESS; |
| 752 | } else { |
| 753 | printk(KERN_INFO "scsi%ld: %s: Boot firmware failed " |
| 754 | "- mbox status 0x%x\n", ha->host_no, __func__, |
| 755 | mbox_status); |
| 756 | status = QLA_ERROR; |
| 757 | } |
| 758 | return status; |
| 759 | } |
| 760 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 761 | int ql4xxx_lock_drvr_wait(struct scsi_qla_host *a) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 762 | { |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 763 | #define QL4_LOCK_DRVR_WAIT 60 |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 764 | #define QL4_LOCK_DRVR_SLEEP 1 |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 765 | |
| 766 | int drvr_wait = QL4_LOCK_DRVR_WAIT; |
| 767 | while (drvr_wait) { |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 768 | if (ql4xxx_lock_drvr(a) == 0) { |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 769 | ssleep(QL4_LOCK_DRVR_SLEEP); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 770 | if (drvr_wait) { |
| 771 | DEBUG2(printk("scsi%ld: %s: Waiting for " |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 772 | "Global Init Semaphore(%d)...\n", |
| 773 | a->host_no, |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 774 | __func__, drvr_wait)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 775 | } |
| 776 | drvr_wait -= QL4_LOCK_DRVR_SLEEP; |
| 777 | } else { |
| 778 | DEBUG2(printk("scsi%ld: %s: Global Init Semaphore " |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 779 | "acquired\n", a->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 780 | return QLA_SUCCESS; |
| 781 | } |
| 782 | } |
| 783 | return QLA_ERROR; |
| 784 | } |
| 785 | |
| 786 | /** |
| 787 | * qla4xxx_start_firmware - starts qla4xxx firmware |
| 788 | * @ha: Pointer to host adapter structure. |
| 789 | * |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 790 | * This routine performs the necessary steps to start the firmware for |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 791 | * the QLA4010 adapter. |
| 792 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 793 | int qla4xxx_start_firmware(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 794 | { |
| 795 | unsigned long flags = 0; |
| 796 | uint32_t mbox_status; |
| 797 | int status = QLA_ERROR; |
| 798 | int soft_reset = 1; |
| 799 | int config_chip = 0; |
| 800 | |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 801 | if (is_qla4022(ha) | is_qla4032(ha)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 802 | ql4xxx_set_mac_number(ha); |
| 803 | |
| 804 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 805 | return QLA_ERROR; |
| 806 | |
| 807 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 808 | |
| 809 | DEBUG2(printk("scsi%ld: %s: port_ctrl = 0x%08X\n", ha->host_no, |
| 810 | __func__, readw(isp_port_ctrl(ha)))); |
| 811 | DEBUG(printk("scsi%ld: %s: port_status = 0x%08X\n", ha->host_no, |
| 812 | __func__, readw(isp_port_status(ha)))); |
| 813 | |
| 814 | /* Is Hardware already initialized? */ |
| 815 | if ((readw(isp_port_ctrl(ha)) & 0x8000) != 0) { |
| 816 | DEBUG(printk("scsi%ld: %s: Hardware has already been " |
| 817 | "initialized\n", ha->host_no, __func__)); |
| 818 | |
| 819 | /* Receive firmware boot acknowledgement */ |
| 820 | mbox_status = readw(&ha->reg->mailbox[0]); |
| 821 | |
| 822 | DEBUG2(printk("scsi%ld: %s: H/W Config complete - mbox[0]= " |
| 823 | "0x%x\n", ha->host_no, __func__, mbox_status)); |
| 824 | |
| 825 | /* Is firmware already booted? */ |
| 826 | if (mbox_status == 0) { |
| 827 | /* F/W not running, must be config by net driver */ |
| 828 | config_chip = 1; |
| 829 | soft_reset = 0; |
| 830 | } else { |
| 831 | writel(set_rmask(CSR_SCSI_PROCESSOR_INTR), |
| 832 | &ha->reg->ctrl_status); |
| 833 | readl(&ha->reg->ctrl_status); |
Sarang Radke | 7876499 | 2012-01-11 02:44:18 -0800 | [diff] [blame] | 834 | writel(set_rmask(CSR_SCSI_COMPLETION_INTR), |
| 835 | &ha->reg->ctrl_status); |
| 836 | readl(&ha->reg->ctrl_status); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 837 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 838 | if (qla4xxx_get_firmware_state(ha) == QLA_SUCCESS) { |
| 839 | DEBUG2(printk("scsi%ld: %s: Get firmware " |
| 840 | "state -- state = 0x%x\n", |
| 841 | ha->host_no, |
| 842 | __func__, ha->firmware_state)); |
| 843 | /* F/W is running */ |
| 844 | if (ha->firmware_state & |
| 845 | FW_STATE_CONFIG_WAIT) { |
| 846 | DEBUG2(printk("scsi%ld: %s: Firmware " |
| 847 | "in known state -- " |
| 848 | "config and " |
| 849 | "boot, state = 0x%x\n", |
| 850 | ha->host_no, __func__, |
| 851 | ha->firmware_state)); |
| 852 | config_chip = 1; |
| 853 | soft_reset = 0; |
| 854 | } |
| 855 | } else { |
| 856 | DEBUG2(printk("scsi%ld: %s: Firmware in " |
| 857 | "unknown state -- resetting," |
| 858 | " state = " |
| 859 | "0x%x\n", ha->host_no, __func__, |
| 860 | ha->firmware_state)); |
| 861 | } |
| 862 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 863 | } |
| 864 | } else { |
| 865 | DEBUG(printk("scsi%ld: %s: H/W initialization hasn't been " |
| 866 | "started - resetting\n", ha->host_no, __func__)); |
| 867 | } |
| 868 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 869 | |
| 870 | DEBUG(printk("scsi%ld: %s: Flags soft_rest=%d, config= %d\n ", |
| 871 | ha->host_no, __func__, soft_reset, config_chip)); |
| 872 | if (soft_reset) { |
| 873 | DEBUG(printk("scsi%ld: %s: Issue Soft Reset\n", ha->host_no, |
| 874 | __func__)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 875 | status = qla4xxx_soft_reset(ha); /* NOTE: acquires drvr |
| 876 | * lock again, but ok */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 877 | if (status == QLA_ERROR) { |
| 878 | DEBUG(printk("scsi%d: %s: Soft Reset failed!\n", |
| 879 | ha->host_no, __func__)); |
| 880 | ql4xxx_unlock_drvr(ha); |
| 881 | return QLA_ERROR; |
| 882 | } |
| 883 | config_chip = 1; |
| 884 | |
Joe Perches | b1c1181 | 2008-02-03 17:28:22 +0200 | [diff] [blame] | 885 | /* Reset clears the semaphore, so acquire again */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 886 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 887 | return QLA_ERROR; |
| 888 | } |
| 889 | |
| 890 | if (config_chip) { |
| 891 | if ((status = qla4xxx_config_nvram(ha)) == QLA_SUCCESS) |
| 892 | status = qla4xxx_start_firmware_from_flash(ha); |
| 893 | } |
| 894 | |
| 895 | ql4xxx_unlock_drvr(ha); |
| 896 | if (status == QLA_SUCCESS) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 897 | if (test_and_clear_bit(AF_GET_CRASH_RECORD, &ha->flags)) |
| 898 | qla4xxx_get_crash_record(ha); |
Vikas Chaudhary | aa6db9b | 2014-02-24 22:07:03 -0500 | [diff] [blame] | 899 | |
| 900 | qla4xxx_init_rings(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 901 | } else { |
| 902 | DEBUG(printk("scsi%ld: %s: Firmware has NOT started\n", |
| 903 | ha->host_no, __func__)); |
| 904 | } |
| 905 | return status; |
| 906 | } |
Lalit Chandivade | 166dd20 | 2011-10-07 16:55:45 -0700 | [diff] [blame] | 907 | /** |
| 908 | * qla4xxx_free_ddb_index - Free DDBs reserved by firmware |
| 909 | * @ha: pointer to adapter structure |
| 910 | * |
| 911 | * Since firmware is not running in autoconnect mode the DDB indices should |
| 912 | * be freed so that when login happens from user space there are free DDB |
| 913 | * indices available. |
| 914 | **/ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 915 | void qla4xxx_free_ddb_index(struct scsi_qla_host *ha) |
Lalit Chandivade | 166dd20 | 2011-10-07 16:55:45 -0700 | [diff] [blame] | 916 | { |
| 917 | int max_ddbs; |
| 918 | int ret; |
| 919 | uint32_t idx = 0, next_idx = 0; |
| 920 | uint32_t state = 0, conn_err = 0; |
| 921 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 922 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
Lalit Chandivade | 166dd20 | 2011-10-07 16:55:45 -0700 | [diff] [blame] | 923 | MAX_DEV_DB_ENTRIES; |
| 924 | |
| 925 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
| 926 | ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL, |
| 927 | &next_idx, &state, &conn_err, |
| 928 | NULL, NULL); |
Tomas Henzl | e1cd89c | 2011-12-01 21:38:42 -0600 | [diff] [blame] | 929 | if (ret == QLA_ERROR) { |
| 930 | next_idx++; |
Lalit Chandivade | 166dd20 | 2011-10-07 16:55:45 -0700 | [diff] [blame] | 931 | continue; |
Tomas Henzl | e1cd89c | 2011-12-01 21:38:42 -0600 | [diff] [blame] | 932 | } |
Lalit Chandivade | 166dd20 | 2011-10-07 16:55:45 -0700 | [diff] [blame] | 933 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 934 | state == DDB_DS_SESSION_FAILED) { |
| 935 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 936 | "Freeing DDB index = 0x%x\n", idx)); |
| 937 | ret = qla4xxx_clear_ddb_entry(ha, idx); |
| 938 | if (ret == QLA_ERROR) |
| 939 | ql4_printk(KERN_ERR, ha, |
| 940 | "Unable to clear DDB index = " |
| 941 | "0x%x\n", idx); |
| 942 | } |
| 943 | if (next_idx == 0) |
| 944 | break; |
| 945 | } |
| 946 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 947 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 948 | /** |
| 949 | * qla4xxx_initialize_adapter - initiailizes hba |
| 950 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 951 | * |
| 952 | * This routine parforms all of the steps necessary to initialize the adapter. |
| 953 | * |
| 954 | **/ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 955 | int qla4xxx_initialize_adapter(struct scsi_qla_host *ha, int is_reset) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 956 | { |
| 957 | int status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 958 | |
| 959 | ha->eeprom_cmd_data = 0; |
| 960 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 961 | ql4_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
| 962 | ha->isp_ops->pci_config(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 963 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 964 | ha->isp_ops->disable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 965 | |
| 966 | /* Initialize the Host adapter request/response queues and firmware */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 967 | if (ha->isp_ops->start_firmware(ha) == QLA_ERROR) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 968 | goto exit_init_hba; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 969 | |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 970 | /* |
| 971 | * For ISP83XX, mailbox and IOCB interrupts are enabled separately. |
| 972 | * Mailbox interrupts must be enabled prior to issuing any mailbox |
| 973 | * command in order to prevent the possibility of losing interrupts |
| 974 | * while switching from polling to interrupt mode. IOCB interrupts are |
| 975 | * enabled via isp_ops->enable_intrs. |
| 976 | */ |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 977 | if (is_qla8032(ha) || is_qla8042(ha)) |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 978 | qla4_83xx_enable_mbox_intrs(ha); |
| 979 | |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 980 | if (qla4xxx_about_firmware(ha) == QLA_ERROR) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 981 | goto exit_init_hba; |
| 982 | |
| 983 | if (ha->isp_ops->get_sys_info(ha) == QLA_ERROR) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 984 | goto exit_init_hba; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 985 | |
Karen Higgins | ff4108d | 2013-01-20 23:50:59 -0500 | [diff] [blame] | 986 | qla4xxx_init_local_data(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 987 | |
| 988 | status = qla4xxx_init_firmware(ha); |
| 989 | if (status == QLA_ERROR) |
David C Somayajulu | 46235e6 | 2007-06-08 17:37:16 -0700 | [diff] [blame] | 990 | goto exit_init_hba; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 991 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 992 | if (is_reset == RESET_ADAPTER) |
| 993 | qla4xxx_build_ddb_list(ha, is_reset); |
Lalit Chandivade | 166dd20 | 2011-10-07 16:55:45 -0700 | [diff] [blame] | 994 | |
David C Somayajulu | 92b7273 | 2007-05-23 17:55:40 -0700 | [diff] [blame] | 995 | set_bit(AF_ONLINE, &ha->flags); |
Vikas Chaudhary | 3710c60 | 2010-10-06 22:49:08 -0700 | [diff] [blame] | 996 | |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 997 | exit_init_hba: |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 998 | DEBUG2(printk("scsi%ld: initialize adapter: %s\n", ha->host_no, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 999 | status == QLA_ERROR ? "FAILED" : "SUCCEEDED")); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1000 | return status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1003 | int qla4xxx_ddb_change(struct scsi_qla_host *ha, uint32_t fw_ddb_index, |
| 1004 | struct ddb_entry *ddb_entry, uint32_t state) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1005 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1006 | uint32_t old_fw_ddb_device_state; |
| 1007 | int status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1008 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1009 | old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state; |
| 1010 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1011 | "%s: DDB - old state = 0x%x, new state = 0x%x for " |
| 1012 | "index [%d]\n", __func__, |
| 1013 | ddb_entry->fw_ddb_device_state, state, fw_ddb_index)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1014 | |
| 1015 | ddb_entry->fw_ddb_device_state = state; |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 1016 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1017 | switch (old_fw_ddb_device_state) { |
| 1018 | case DDB_DS_LOGIN_IN_PROCESS: |
| 1019 | switch (state) { |
| 1020 | case DDB_DS_SESSION_ACTIVE: |
| 1021 | case DDB_DS_DISCOVERY: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1022 | qla4xxx_update_session_conn_param(ha, ddb_entry); |
Manish Rangankar | 3d948e2 | 2012-04-23 22:32:33 -0700 | [diff] [blame] | 1023 | ddb_entry->unblock_sess(ddb_entry->sess); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1024 | status = QLA_SUCCESS; |
| 1025 | break; |
| 1026 | case DDB_DS_SESSION_FAILED: |
| 1027 | case DDB_DS_NO_CONNECTION_ACTIVE: |
| 1028 | iscsi_conn_login_event(ddb_entry->conn, |
| 1029 | ISCSI_CONN_STATE_FREE); |
| 1030 | status = QLA_SUCCESS; |
| 1031 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1032 | } |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1033 | break; |
| 1034 | case DDB_DS_SESSION_ACTIVE: |
Manish Rangankar | 3d948e2 | 2012-04-23 22:32:33 -0700 | [diff] [blame] | 1035 | case DDB_DS_DISCOVERY: |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 1036 | switch (state) { |
| 1037 | case DDB_DS_SESSION_FAILED: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1038 | /* |
| 1039 | * iscsi_session failure will cause userspace to |
| 1040 | * stop the connection which in turn would block the |
| 1041 | * iscsi_session and start relogin |
| 1042 | */ |
| 1043 | iscsi_session_failure(ddb_entry->sess->dd_data, |
| 1044 | ISCSI_ERR_CONN_FAILED); |
| 1045 | status = QLA_SUCCESS; |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 1046 | break; |
| 1047 | case DDB_DS_NO_CONNECTION_ACTIVE: |
| 1048 | clear_bit(fw_ddb_index, ha->ddb_idx_map); |
| 1049 | status = QLA_SUCCESS; |
| 1050 | break; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1051 | } |
| 1052 | break; |
Manish Rangankar | 98270ab | 2011-10-07 16:55:47 -0700 | [diff] [blame] | 1053 | case DDB_DS_SESSION_FAILED: |
| 1054 | switch (state) { |
| 1055 | case DDB_DS_SESSION_ACTIVE: |
| 1056 | case DDB_DS_DISCOVERY: |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1057 | ddb_entry->unblock_sess(ddb_entry->sess); |
Manish Rangankar | 98270ab | 2011-10-07 16:55:47 -0700 | [diff] [blame] | 1058 | qla4xxx_update_session_conn_param(ha, ddb_entry); |
| 1059 | status = QLA_SUCCESS; |
| 1060 | break; |
| 1061 | case DDB_DS_SESSION_FAILED: |
| 1062 | iscsi_session_failure(ddb_entry->sess->dd_data, |
| 1063 | ISCSI_ERR_CONN_FAILED); |
| 1064 | status = QLA_SUCCESS; |
| 1065 | break; |
| 1066 | } |
| 1067 | break; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1068 | default: |
| 1069 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unknown Event\n", |
| 1070 | __func__)); |
| 1071 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1072 | } |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1073 | return status; |
| 1074 | } |
| 1075 | |
| 1076 | void qla4xxx_arm_relogin_timer(struct ddb_entry *ddb_entry) |
| 1077 | { |
| 1078 | /* |
| 1079 | * This triggers a relogin. After the relogin_timer |
| 1080 | * expires, the relogin gets scheduled. We must wait a |
| 1081 | * minimum amount of time since receiving an 0x8014 AEN |
| 1082 | * with failed device_state or a logout response before |
| 1083 | * we can issue another relogin. |
| 1084 | * |
| 1085 | * Firmware pads this timeout: (time2wait +1). |
| 1086 | * Driver retry to login should be longer than F/W. |
| 1087 | * Otherwise F/W will fail |
| 1088 | * set_ddb() mbx cmd with 0x4005 since it still |
| 1089 | * counting down its time2wait. |
| 1090 | */ |
| 1091 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 1092 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 1093 | ddb_entry->default_time2wait + 4); |
| 1094 | |
| 1095 | } |
| 1096 | |
| 1097 | int qla4xxx_flash_ddb_change(struct scsi_qla_host *ha, uint32_t fw_ddb_index, |
| 1098 | struct ddb_entry *ddb_entry, uint32_t state) |
| 1099 | { |
| 1100 | uint32_t old_fw_ddb_device_state; |
| 1101 | int status = QLA_ERROR; |
| 1102 | |
| 1103 | old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state; |
| 1104 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1105 | "%s: DDB - old state = 0x%x, new state = 0x%x for " |
| 1106 | "index [%d]\n", __func__, |
| 1107 | ddb_entry->fw_ddb_device_state, state, fw_ddb_index)); |
| 1108 | |
| 1109 | ddb_entry->fw_ddb_device_state = state; |
| 1110 | |
| 1111 | switch (old_fw_ddb_device_state) { |
| 1112 | case DDB_DS_LOGIN_IN_PROCESS: |
| 1113 | case DDB_DS_NO_CONNECTION_ACTIVE: |
| 1114 | switch (state) { |
| 1115 | case DDB_DS_SESSION_ACTIVE: |
| 1116 | ddb_entry->unblock_sess(ddb_entry->sess); |
| 1117 | qla4xxx_update_session_conn_fwddb_param(ha, ddb_entry); |
| 1118 | status = QLA_SUCCESS; |
| 1119 | break; |
| 1120 | case DDB_DS_SESSION_FAILED: |
| 1121 | iscsi_block_session(ddb_entry->sess); |
| 1122 | if (!test_bit(DF_RELOGIN, &ddb_entry->flags)) |
| 1123 | qla4xxx_arm_relogin_timer(ddb_entry); |
| 1124 | status = QLA_SUCCESS; |
| 1125 | break; |
| 1126 | } |
| 1127 | break; |
| 1128 | case DDB_DS_SESSION_ACTIVE: |
| 1129 | switch (state) { |
| 1130 | case DDB_DS_SESSION_FAILED: |
| 1131 | iscsi_block_session(ddb_entry->sess); |
| 1132 | if (!test_bit(DF_RELOGIN, &ddb_entry->flags)) |
| 1133 | qla4xxx_arm_relogin_timer(ddb_entry); |
| 1134 | status = QLA_SUCCESS; |
| 1135 | break; |
| 1136 | } |
| 1137 | break; |
| 1138 | case DDB_DS_SESSION_FAILED: |
| 1139 | switch (state) { |
| 1140 | case DDB_DS_SESSION_ACTIVE: |
| 1141 | ddb_entry->unblock_sess(ddb_entry->sess); |
| 1142 | qla4xxx_update_session_conn_fwddb_param(ha, ddb_entry); |
| 1143 | status = QLA_SUCCESS; |
| 1144 | break; |
| 1145 | case DDB_DS_SESSION_FAILED: |
| 1146 | if (!test_bit(DF_RELOGIN, &ddb_entry->flags)) |
| 1147 | qla4xxx_arm_relogin_timer(ddb_entry); |
| 1148 | status = QLA_SUCCESS; |
| 1149 | break; |
| 1150 | } |
| 1151 | break; |
| 1152 | default: |
| 1153 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unknown Event\n", |
| 1154 | __func__)); |
| 1155 | break; |
| 1156 | } |
| 1157 | return status; |
| 1158 | } |
| 1159 | |
| 1160 | /** |
| 1161 | * qla4xxx_process_ddb_changed - process ddb state change |
| 1162 | * @ha - Pointer to host adapter structure. |
| 1163 | * @fw_ddb_index - Firmware's device database index |
| 1164 | * @state - Device state |
| 1165 | * |
| 1166 | * This routine processes a Decive Database Changed AEN Event. |
| 1167 | **/ |
| 1168 | int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, |
| 1169 | uint32_t fw_ddb_index, |
| 1170 | uint32_t state, uint32_t conn_err) |
| 1171 | { |
| 1172 | struct ddb_entry *ddb_entry; |
| 1173 | int status = QLA_ERROR; |
| 1174 | |
| 1175 | /* check for out of range index */ |
| 1176 | if (fw_ddb_index >= MAX_DDB_ENTRIES) |
| 1177 | goto exit_ddb_event; |
| 1178 | |
| 1179 | /* Get the corresponging ddb entry */ |
| 1180 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index); |
| 1181 | /* Device does not currently exist in our database. */ |
| 1182 | if (ddb_entry == NULL) { |
| 1183 | ql4_printk(KERN_ERR, ha, "%s: No ddb_entry at FW index [%d]\n", |
| 1184 | __func__, fw_ddb_index); |
| 1185 | |
| 1186 | if (state == DDB_DS_NO_CONNECTION_ACTIVE) |
| 1187 | clear_bit(fw_ddb_index, ha->ddb_idx_map); |
| 1188 | |
| 1189 | goto exit_ddb_event; |
| 1190 | } |
| 1191 | |
| 1192 | ddb_entry->ddb_change(ha, fw_ddb_index, ddb_entry, state); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1193 | |
| 1194 | exit_ddb_event: |
| 1195 | return status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1196 | } |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1197 | |
| 1198 | /** |
| 1199 | * qla4xxx_login_flash_ddb - Login to target (DDB) |
| 1200 | * @cls_session: Pointer to the session to login |
| 1201 | * |
| 1202 | * This routine logins to the target. |
| 1203 | * Issues setddb and conn open mbx |
| 1204 | **/ |
| 1205 | void qla4xxx_login_flash_ddb(struct iscsi_cls_session *cls_session) |
| 1206 | { |
| 1207 | struct iscsi_session *sess; |
| 1208 | struct ddb_entry *ddb_entry; |
| 1209 | struct scsi_qla_host *ha; |
| 1210 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 1211 | dma_addr_t fw_ddb_dma; |
| 1212 | uint32_t mbx_sts = 0; |
| 1213 | int ret; |
| 1214 | |
| 1215 | sess = cls_session->dd_data; |
| 1216 | ddb_entry = sess->dd_data; |
| 1217 | ha = ddb_entry->ha; |
| 1218 | |
| 1219 | if (!test_bit(AF_LINK_UP, &ha->flags)) |
| 1220 | return; |
| 1221 | |
| 1222 | if (ddb_entry->ddb_type != FLASH_DDB) { |
| 1223 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1224 | "Skipping login to non FLASH DB")); |
| 1225 | goto exit_login; |
| 1226 | } |
| 1227 | |
| 1228 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 1229 | &fw_ddb_dma); |
| 1230 | if (fw_ddb_entry == NULL) { |
| 1231 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
| 1232 | goto exit_login; |
| 1233 | } |
| 1234 | |
| 1235 | if (ddb_entry->fw_ddb_index == INVALID_ENTRY) { |
| 1236 | ret = qla4xxx_get_ddb_index(ha, &ddb_entry->fw_ddb_index); |
| 1237 | if (ret == QLA_ERROR) |
| 1238 | goto exit_login; |
| 1239 | |
| 1240 | ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry; |
| 1241 | ha->tot_ddbs++; |
| 1242 | } |
| 1243 | |
| 1244 | memcpy(fw_ddb_entry, &ddb_entry->fw_ddb_entry, |
| 1245 | sizeof(struct dev_db_entry)); |
| 1246 | ddb_entry->sess->target_id = ddb_entry->fw_ddb_index; |
| 1247 | |
| 1248 | ret = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index, |
| 1249 | fw_ddb_dma, &mbx_sts); |
| 1250 | if (ret == QLA_ERROR) { |
| 1251 | DEBUG2(ql4_printk(KERN_ERR, ha, "Set DDB failed\n")); |
| 1252 | goto exit_login; |
| 1253 | } |
| 1254 | |
| 1255 | ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS; |
| 1256 | ret = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index); |
| 1257 | if (ret == QLA_ERROR) { |
| 1258 | ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__, |
| 1259 | sess->targetname); |
| 1260 | goto exit_login; |
| 1261 | } |
| 1262 | |
| 1263 | exit_login: |
| 1264 | if (fw_ddb_entry) |
| 1265 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 1266 | } |
| 1267 | |