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