blob: 064a3a311e77823888331f36522d55caf4476b78 [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
Vikas Chaudhary7d01d062010-12-02 22:12:51 -08003 * Copyright (c) 2003-2010 QLogic Corporation
David Somayajuluafaf5a22006-09-19 10:28:00 -07004 *
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7
Mike Christie26974782007-12-13 12:43:29 -06008#include <scsi/iscsi_if.h>
David Somayajuluafaf5a22006-09-19 10:28:00 -07009#include "ql4_def.h"
David C Somayajulu92b72732007-05-23 17:55:40 -070010#include "ql4_glbl.h"
11#include "ql4_dbg.h"
12#include "ql4_inline.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070013
David Somayajuluafaf5a22006-09-19 10:28:00 -070014static 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 Rangankarb3a271a2011-07-25 13:48:53 -050048 * This routine marks a DDB entry INVALID
David Somayajuluafaf5a22006-09-19 10:28:00 -070049 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053050void qla4xxx_free_ddb(struct scsi_qla_host *ha,
51 struct ddb_entry *ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -070052{
David Somayajuluafaf5a22006-09-19 10:28:00 -070053 /* 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 Somayajuluafaf5a22006-09-19 10:28:00 -070057}
58
59/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053060 * 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 **/
66static 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 Somayajuluafaf5a22006-09-19 10:28:00 -070079 * 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 **/
86int qla4xxx_init_rings(struct scsi_qla_host *ha)
87{
88 unsigned long flags = 0;
89
90 /* Initialize request queue. */
91 spin_lock_irqsave(&ha->hardware_lock, flags);
92 ha->request_out = 0;
93 ha->request_in = 0;
94 ha->request_ptr = &ha->request_ring[ha->request_in];
95 ha->req_q_count = REQUEST_QUEUE_DEPTH;
96
97 /* Initialize response queue. */
98 ha->response_in = 0;
99 ha->response_out = 0;
100 ha->response_ptr = &ha->response_ring[ha->response_out];
101
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530102 if (is_qla8022(ha)) {
103 writel(0,
104 (unsigned long __iomem *)&ha->qla4_8xxx_reg->req_q_out);
105 writel(0,
106 (unsigned long __iomem *)&ha->qla4_8xxx_reg->rsp_q_in);
107 writel(0,
108 (unsigned long __iomem *)&ha->qla4_8xxx_reg->rsp_q_out);
109 } else {
110 /*
111 * Initialize DMA Shadow registers. The firmware is really
112 * supposed to take care of this, but on some uniprocessor
113 * systems, the shadow registers aren't cleared-- causing
114 * the interrupt_handler to think there are responses to be
115 * processed when there aren't.
116 */
117 ha->shadow_regs->req_q_out = __constant_cpu_to_le32(0);
118 ha->shadow_regs->rsp_q_in = __constant_cpu_to_le32(0);
119 wmb();
David Somayajuluafaf5a22006-09-19 10:28:00 -0700120
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530121 writel(0, &ha->reg->req_q_in);
122 writel(0, &ha->reg->rsp_q_out);
123 readl(&ha->reg->rsp_q_out);
124 }
125
126 qla4xxx_init_response_q_entries(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700127
128 spin_unlock_irqrestore(&ha->hardware_lock, flags);
129
130 return QLA_SUCCESS;
131}
132
133/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530134 * qla4xxx_get_sys_info - validate adapter MAC address(es)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700135 * @ha: pointer to host adapter structure.
136 *
137 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530138int qla4xxx_get_sys_info(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700139{
140 struct flash_sys_info *sys_info;
141 dma_addr_t sys_info_dma;
142 int status = QLA_ERROR;
143
144 sys_info = dma_alloc_coherent(&ha->pdev->dev, sizeof(*sys_info),
145 &sys_info_dma, GFP_KERNEL);
146 if (sys_info == NULL) {
147 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
148 ha->host_no, __func__));
149
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530150 goto exit_get_sys_info_no_free;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700151 }
152 memset(sys_info, 0, sizeof(*sys_info));
153
154 /* Get flash sys info */
155 if (qla4xxx_get_flash(ha, sys_info_dma, FLASH_OFFSET_SYS_INFO,
156 sizeof(*sys_info)) != QLA_SUCCESS) {
157 DEBUG2(printk("scsi%ld: %s: get_flash FLASH_OFFSET_SYS_INFO "
158 "failed\n", ha->host_no, __func__));
159
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530160 goto exit_get_sys_info;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700161 }
162
163 /* Save M.A.C. address & serial_number */
164 memcpy(ha->my_mac, &sys_info->physAddr[0].address[0],
165 min(sizeof(ha->my_mac),
166 sizeof(sys_info->physAddr[0].address)));
167 memcpy(ha->serial_number, &sys_info->acSerialNumber,
168 min(sizeof(ha->serial_number),
169 sizeof(sys_info->acSerialNumber)));
170
171 status = QLA_SUCCESS;
172
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530173exit_get_sys_info:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700174 dma_free_coherent(&ha->pdev->dev, sizeof(*sys_info), sys_info,
175 sys_info_dma);
176
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530177exit_get_sys_info_no_free:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700178 return status;
179}
180
181/**
182 * qla4xxx_init_local_data - initialize adapter specific local data
183 * @ha: pointer to host adapter structure.
184 *
185 **/
186static int qla4xxx_init_local_data(struct scsi_qla_host *ha)
187{
Uwe Kleine-König421f91d2010-06-11 12:17:00 +0200188 /* Initialize aen queue */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700189 ha->aen_q_count = MAX_AEN_ENTRIES;
190
191 return qla4xxx_get_firmware_status(ha);
192}
193
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530194static uint8_t
195qla4xxx_wait_for_ip_config(struct scsi_qla_host *ha)
196{
197 uint8_t ipv4_wait = 0;
198 uint8_t ipv6_wait = 0;
199 int8_t ip_address[IPv6_ADDR_LEN] = {0} ;
200
201 /* If both IPv4 & IPv6 are enabled, possibly only one
202 * IP address may be acquired, so check to see if we
203 * need to wait for another */
204 if (is_ipv4_enabled(ha) && is_ipv6_enabled(ha)) {
205 if (((ha->addl_fw_state & FW_ADDSTATE_DHCPv4_ENABLED) != 0) &&
206 ((ha->addl_fw_state &
207 FW_ADDSTATE_DHCPv4_LEASE_ACQUIRED) == 0)) {
208 ipv4_wait = 1;
209 }
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500210 if (((ha->ip_config.ipv6_addl_options &
211 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) != 0) &&
212 ((ha->ip_config.ipv6_link_local_state ==
213 IP_ADDRSTATE_ACQUIRING) ||
214 (ha->ip_config.ipv6_addr0_state ==
215 IP_ADDRSTATE_ACQUIRING) ||
216 (ha->ip_config.ipv6_addr1_state ==
217 IP_ADDRSTATE_ACQUIRING))) {
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530218
219 ipv6_wait = 1;
220
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500221 if ((ha->ip_config.ipv6_link_local_state ==
222 IP_ADDRSTATE_PREFERRED) ||
223 (ha->ip_config.ipv6_addr0_state ==
224 IP_ADDRSTATE_PREFERRED) ||
225 (ha->ip_config.ipv6_addr1_state ==
226 IP_ADDRSTATE_PREFERRED)) {
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530227 DEBUG2(printk(KERN_INFO "scsi%ld: %s: "
228 "Preferred IP configured."
229 " Don't wait!\n", ha->host_no,
230 __func__));
231 ipv6_wait = 0;
232 }
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500233 if (memcmp(&ha->ip_config.ipv6_default_router_addr,
234 ip_address, IPv6_ADDR_LEN) == 0) {
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530235 DEBUG2(printk(KERN_INFO "scsi%ld: %s: "
236 "No Router configured. "
237 "Don't wait!\n", ha->host_no,
238 __func__));
239 ipv6_wait = 0;
240 }
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500241 if ((ha->ip_config.ipv6_default_router_state ==
242 IPV6_RTRSTATE_MANUAL) &&
243 (ha->ip_config.ipv6_link_local_state ==
244 IP_ADDRSTATE_TENTATIVE) &&
245 (memcmp(&ha->ip_config.ipv6_link_local_addr,
246 &ha->ip_config.ipv6_default_router_addr, 4) ==
247 0)) {
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530248 DEBUG2(printk("scsi%ld: %s: LinkLocal Router & "
249 "IP configured. Don't wait!\n",
250 ha->host_no, __func__));
251 ipv6_wait = 0;
252 }
253 }
254 if (ipv4_wait || ipv6_wait) {
255 DEBUG2(printk("scsi%ld: %s: Wait for additional "
256 "IP(s) \"", ha->host_no, __func__));
257 if (ipv4_wait)
258 DEBUG2(printk("IPv4 "));
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500259 if (ha->ip_config.ipv6_link_local_state ==
260 IP_ADDRSTATE_ACQUIRING)
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530261 DEBUG2(printk("IPv6LinkLocal "));
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500262 if (ha->ip_config.ipv6_addr0_state ==
263 IP_ADDRSTATE_ACQUIRING)
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530264 DEBUG2(printk("IPv6Addr0 "));
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500265 if (ha->ip_config.ipv6_addr1_state ==
266 IP_ADDRSTATE_ACQUIRING)
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530267 DEBUG2(printk("IPv6Addr1 "));
268 DEBUG2(printk("\"\n"));
269 }
270 }
271
272 return ipv4_wait|ipv6_wait;
273}
274
David Somayajuluafaf5a22006-09-19 10:28:00 -0700275static int qla4xxx_fw_ready(struct scsi_qla_host *ha)
276{
277 uint32_t timeout_count;
278 int ready = 0;
279
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530280 DEBUG2(ql4_printk(KERN_INFO, ha, "Waiting for Firmware Ready..\n"));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700281 for (timeout_count = ADAPTER_INIT_TOV; timeout_count > 0;
282 timeout_count--) {
283 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
284 qla4xxx_get_dhcp_ip_address(ha);
285
286 /* Get firmware state. */
287 if (qla4xxx_get_firmware_state(ha) != QLA_SUCCESS) {
288 DEBUG2(printk("scsi%ld: %s: unable to get firmware "
289 "state\n", ha->host_no, __func__));
290 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700291 }
292
293 if (ha->firmware_state & FW_STATE_ERROR) {
294 DEBUG2(printk("scsi%ld: %s: an unrecoverable error has"
295 " occurred\n", ha->host_no, __func__));
296 break;
297
298 }
299 if (ha->firmware_state & FW_STATE_CONFIG_WAIT) {
300 /*
301 * The firmware has not yet been issued an Initialize
302 * Firmware command, so issue it now.
303 */
304 if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR)
305 break;
306
307 /* Go back and test for ready state - no wait. */
308 continue;
309 }
310
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530311 if (ha->firmware_state & FW_STATE_WAIT_AUTOCONNECT) {
312 DEBUG2(printk(KERN_INFO "scsi%ld: %s: fwstate:"
313 "AUTOCONNECT in progress\n",
314 ha->host_no, __func__));
315 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700316
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530317 if (ha->firmware_state & FW_STATE_CONFIGURING_IP) {
318 DEBUG2(printk(KERN_INFO "scsi%ld: %s: fwstate:"
319 " CONFIGURING IP\n",
320 ha->host_no, __func__));
321 /*
322 * Check for link state after 15 secs and if link is
323 * still DOWN then, cable is unplugged. Ignore "DHCP
324 * in Progress/CONFIGURING IP" bit to check if firmware
325 * is in ready state or not after 15 secs.
326 * This is applicable for both 2.x & 3.x firmware
327 */
328 if (timeout_count <= (ADAPTER_INIT_TOV - 15)) {
329 if (ha->addl_fw_state & FW_ADDSTATE_LINK_UP) {
330 DEBUG2(printk(KERN_INFO "scsi%ld: %s:"
331 " LINK UP (Cable plugged)\n",
332 ha->host_no, __func__));
333 } else if (ha->firmware_state &
334 (FW_STATE_CONFIGURING_IP |
335 FW_STATE_READY)) {
336 DEBUG2(printk(KERN_INFO "scsi%ld: %s: "
337 "LINK DOWN (Cable unplugged)\n",
338 ha->host_no, __func__));
339 ha->firmware_state = FW_STATE_READY;
340 }
341 }
342 }
343
344 if (ha->firmware_state == FW_STATE_READY) {
345 /* If DHCP IP Addr is available, retrieve it now. */
346 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR,
347 &ha->dpc_flags))
348 qla4xxx_get_dhcp_ip_address(ha);
349
350 if (!qla4xxx_wait_for_ip_config(ha) ||
351 timeout_count == 1) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530352 DEBUG2(ql4_printk(KERN_INFO, ha,
353 "Firmware Ready..\n"));
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530354 /* The firmware is ready to process SCSI
355 commands. */
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530356 DEBUG2(ql4_printk(KERN_INFO, ha,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530357 "scsi%ld: %s: MEDIA TYPE"
358 " - %s\n", ha->host_no,
359 __func__, (ha->addl_fw_state &
360 FW_ADDSTATE_OPTICAL_MEDIA)
361 != 0 ? "OPTICAL" : "COPPER"));
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530362 DEBUG2(ql4_printk(KERN_INFO, ha,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530363 "scsi%ld: %s: DHCPv4 STATE"
364 " Enabled %s\n", ha->host_no,
365 __func__, (ha->addl_fw_state &
366 FW_ADDSTATE_DHCPv4_ENABLED) != 0 ?
367 "YES" : "NO"));
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530368 DEBUG2(ql4_printk(KERN_INFO, ha,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530369 "scsi%ld: %s: LINK %s\n",
370 ha->host_no, __func__,
371 (ha->addl_fw_state &
372 FW_ADDSTATE_LINK_UP) != 0 ?
373 "UP" : "DOWN"));
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530374 DEBUG2(ql4_printk(KERN_INFO, ha,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530375 "scsi%ld: %s: iSNS Service "
376 "Started %s\n",
377 ha->host_no, __func__,
378 (ha->addl_fw_state &
379 FW_ADDSTATE_ISNS_SVC_ENABLED) != 0 ?
380 "YES" : "NO"));
381
382 ready = 1;
383 break;
384 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700385 }
386 DEBUG2(printk("scsi%ld: %s: waiting on fw, state=%x:%x - "
387 "seconds expired= %d\n", ha->host_no, __func__,
388 ha->firmware_state, ha->addl_fw_state,
389 timeout_count));
David C Somayajulud9150582006-11-15 17:38:40 -0800390 if (is_qla4032(ha) &&
391 !(ha->addl_fw_state & FW_ADDSTATE_LINK_UP) &&
392 (timeout_count < ADAPTER_INIT_TOV - 5)) {
393 break;
394 }
395
David Somayajuluafaf5a22006-09-19 10:28:00 -0700396 msleep(1000);
397 } /* end of for */
398
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530399 if (timeout_count <= 0)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700400 DEBUG2(printk("scsi%ld: %s: FW Initialization timed out!\n",
401 ha->host_no, __func__));
402
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530403 if (ha->firmware_state & FW_STATE_CONFIGURING_IP) {
404 DEBUG2(printk("scsi%ld: %s: FW initialized, but is reporting "
405 "it's waiting to configure an IP address\n",
406 ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700407 ready = 1;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530408 } else if (ha->firmware_state & FW_STATE_WAIT_AUTOCONNECT) {
409 DEBUG2(printk("scsi%ld: %s: FW initialized, but "
410 "auto-discovery still in process\n",
411 ha->host_no, __func__));
Vikas Chaudharyb9663462010-07-10 14:49:19 +0530412 ready = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700413 }
414
415 return ready;
416}
417
418/**
419 * qla4xxx_init_firmware - initializes the firmware.
420 * @ha: pointer to host adapter structure.
421 *
422 **/
423static int qla4xxx_init_firmware(struct scsi_qla_host *ha)
424{
425 int status = QLA_ERROR;
426
Lalit Chandivade2232be02010-07-30 14:38:47 +0530427 if (is_aer_supported(ha) &&
428 test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
429 return status;
430
Lalit Chandivade9d4946f2010-07-30 14:26:31 +0530431 /* For 82xx, stop firmware before initializing because if BIOS
432 * has previously initialized firmware, then driver's initialize
433 * firmware will fail. */
434 if (is_qla8022(ha))
435 qla4_8xxx_stop_firmware(ha);
436
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530437 ql4_printk(KERN_INFO, ha, "Initializing firmware..\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -0700438 if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR) {
439 DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware "
440 "control block\n", ha->host_no, __func__));
441 return status;
442 }
443 if (!qla4xxx_fw_ready(ha))
444 return status;
445
David Somayajuluafaf5a22006-09-19 10:28:00 -0700446 return qla4xxx_get_firmware_status(ha);
447}
448
Vikas Chaudhary91ec7ce2011-08-01 03:26:17 -0700449static void qla4xxx_set_model_info(struct scsi_qla_host *ha)
450{
451 uint16_t board_id_string[8];
452 int i;
453 int size = sizeof(ha->nvram->isp4022.boardIdStr);
454 int offset = offsetof(struct eeprom_data, isp4022.boardIdStr) / 2;
455
456 for (i = 0; i < (size / 2) ; i++) {
457 board_id_string[i] = rd_nvram_word(ha, offset);
458 offset += 1;
459 }
460
461 memcpy(ha->model_name, board_id_string, size);
462}
463
David Somayajuluafaf5a22006-09-19 10:28:00 -0700464static int qla4xxx_config_nvram(struct scsi_qla_host *ha)
465{
466 unsigned long flags;
467 union external_hw_config_reg extHwConfig;
468
469 DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha->host_no,
470 __func__));
471 if (ql4xxx_lock_flash(ha) != QLA_SUCCESS)
Mike Christieb3925512010-02-10 16:51:48 -0600472 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700473 if (ql4xxx_lock_nvram(ha) != QLA_SUCCESS) {
474 ql4xxx_unlock_flash(ha);
Mike Christieb3925512010-02-10 16:51:48 -0600475 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700476 }
477
478 /* Get EEPRom Parameters from NVRAM and validate */
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530479 ql4_printk(KERN_INFO, ha, "Configuring NVRAM ...\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -0700480 if (qla4xxx_is_nvram_configuration_valid(ha) == QLA_SUCCESS) {
481 spin_lock_irqsave(&ha->hardware_lock, flags);
482 extHwConfig.Asuint32_t =
483 rd_nvram_word(ha, eeprom_ext_hw_conf_offset(ha));
484 spin_unlock_irqrestore(&ha->hardware_lock, flags);
485 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530486 ql4_printk(KERN_WARNING, ha,
487 "scsi%ld: %s: EEProm checksum invalid. "
488 "Please update your EEPROM\n", ha->host_no,
489 __func__);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700490
Mike Christieb3925512010-02-10 16:51:48 -0600491 /* Attempt to set defaults */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700492 if (is_qla4010(ha))
493 extHwConfig.Asuint32_t = 0x1912;
David C Somayajulud9150582006-11-15 17:38:40 -0800494 else if (is_qla4022(ha) | is_qla4032(ha))
David Somayajuluafaf5a22006-09-19 10:28:00 -0700495 extHwConfig.Asuint32_t = 0x0023;
Mike Christieb3925512010-02-10 16:51:48 -0600496 else
497 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700498 }
Vikas Chaudhary91ec7ce2011-08-01 03:26:17 -0700499
500 if (is_qla4022(ha) || is_qla4032(ha))
501 qla4xxx_set_model_info(ha);
502 else
503 strcpy(ha->model_name, "QLA4010");
504
David Somayajuluafaf5a22006-09-19 10:28:00 -0700505 DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n",
506 ha->host_no, __func__, extHwConfig.Asuint32_t));
507
508 spin_lock_irqsave(&ha->hardware_lock, flags);
509 writel((0xFFFF << 16) | extHwConfig.Asuint32_t, isp_ext_hw_conf(ha));
510 readl(isp_ext_hw_conf(ha));
511 spin_unlock_irqrestore(&ha->hardware_lock, flags);
512
513 ql4xxx_unlock_nvram(ha);
514 ql4xxx_unlock_flash(ha);
515
Mike Christieb3925512010-02-10 16:51:48 -0600516 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700517}
518
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530519/**
520 * qla4_8xxx_pci_config() - Setup ISP82xx PCI configuration registers.
521 * @ha: HA context
522 */
523void qla4_8xxx_pci_config(struct scsi_qla_host *ha)
524{
525 pci_set_master(ha->pdev);
526}
527
528void qla4xxx_pci_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700529{
David C Somayajulu92b72732007-05-23 17:55:40 -0700530 uint16_t w;
David C Somayajulu46235e62007-06-08 17:37:16 -0700531 int status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700532
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530533 ql4_printk(KERN_INFO, ha, "Configuring PCI space...\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -0700534
535 pci_set_master(ha->pdev);
David C Somayajulu46235e62007-06-08 17:37:16 -0700536 status = pci_set_mwi(ha->pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700537 /*
538 * We want to respect framework's setting of PCI configuration space
539 * command register and also want to make sure that all bits of
540 * interest to us are properly set in command register.
541 */
542 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
David C Somayajulu92b72732007-05-23 17:55:40 -0700543 w |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700544 w &= ~PCI_COMMAND_INTX_DISABLE;
545 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
546}
547
548static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host *ha)
549{
550 int status = QLA_ERROR;
Vikas Chaudharyc301b022010-04-28 11:40:37 +0530551 unsigned long max_wait_time;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700552 unsigned long flags;
553 uint32_t mbox_status;
554
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530555 ql4_printk(KERN_INFO, ha, "Starting firmware ...\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -0700556
557 /*
558 * Start firmware from flash ROM
559 *
560 * WORKAROUND: Stuff a non-constant value that the firmware can
561 * use as a seed for a random number generator in MB7 prior to
562 * setting BOOT_ENABLE. Fixes problem where the TCP
563 * connections use the same TCP ports after each reboot,
564 * causing some connections to not get re-established.
565 */
566 DEBUG(printk("scsi%d: %s: Start firmware from flash ROM\n",
567 ha->host_no, __func__));
568
569 spin_lock_irqsave(&ha->hardware_lock, flags);
570 writel(jiffies, &ha->reg->mailbox[7]);
David C Somayajulud9150582006-11-15 17:38:40 -0800571 if (is_qla4022(ha) | is_qla4032(ha))
David Somayajuluafaf5a22006-09-19 10:28:00 -0700572 writel(set_rmask(NVR_WRITE_ENABLE),
573 &ha->reg->u1.isp4022.nvram);
574
David C Somayajulu92b72732007-05-23 17:55:40 -0700575 writel(2, &ha->reg->mailbox[6]);
576 readl(&ha->reg->mailbox[6]);
577
David Somayajuluafaf5a22006-09-19 10:28:00 -0700578 writel(set_rmask(CSR_BOOT_ENABLE), &ha->reg->ctrl_status);
579 readl(&ha->reg->ctrl_status);
580 spin_unlock_irqrestore(&ha->hardware_lock, flags);
581
582 /* Wait for firmware to come UP. */
Vikas Chaudharyc301b022010-04-28 11:40:37 +0530583 DEBUG2(printk(KERN_INFO "scsi%ld: %s: Wait up to %d seconds for "
584 "boot firmware to complete...\n",
585 ha->host_no, __func__, FIRMWARE_UP_TOV));
586 max_wait_time = jiffies + (FIRMWARE_UP_TOV * HZ);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700587 do {
588 uint32_t ctrl_status;
589
590 spin_lock_irqsave(&ha->hardware_lock, flags);
591 ctrl_status = readw(&ha->reg->ctrl_status);
592 mbox_status = readw(&ha->reg->mailbox[0]);
593 spin_unlock_irqrestore(&ha->hardware_lock, flags);
594
595 if (ctrl_status & set_rmask(CSR_SCSI_PROCESSOR_INTR))
596 break;
597 if (mbox_status == MBOX_STS_COMMAND_COMPLETE)
598 break;
599
Vikas Chaudharyc301b022010-04-28 11:40:37 +0530600 DEBUG2(printk(KERN_INFO "scsi%ld: %s: Waiting for boot "
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -0700601 "firmware to complete... ctrl_sts=0x%x, remaining=%ld\n",
602 ha->host_no, __func__, ctrl_status, max_wait_time));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700603
Vikas Chaudharyc301b022010-04-28 11:40:37 +0530604 msleep_interruptible(250);
605 } while (!time_after_eq(jiffies, max_wait_time));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700606
607 if (mbox_status == MBOX_STS_COMMAND_COMPLETE) {
Vikas Chaudharyc301b022010-04-28 11:40:37 +0530608 DEBUG(printk(KERN_INFO "scsi%ld: %s: Firmware has started\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700609 ha->host_no, __func__));
610
611 spin_lock_irqsave(&ha->hardware_lock, flags);
612 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
613 &ha->reg->ctrl_status);
614 readl(&ha->reg->ctrl_status);
615 spin_unlock_irqrestore(&ha->hardware_lock, flags);
616
617 status = QLA_SUCCESS;
618 } else {
619 printk(KERN_INFO "scsi%ld: %s: Boot firmware failed "
620 "- mbox status 0x%x\n", ha->host_no, __func__,
621 mbox_status);
622 status = QLA_ERROR;
623 }
624 return status;
625}
626
David C Somayajulu92b72732007-05-23 17:55:40 -0700627int ql4xxx_lock_drvr_wait(struct scsi_qla_host *a)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700628{
David C Somayajulu92b72732007-05-23 17:55:40 -0700629#define QL4_LOCK_DRVR_WAIT 60
David C Somayajulu477ffb92007-01-22 12:26:11 -0800630#define QL4_LOCK_DRVR_SLEEP 1
David Somayajuluafaf5a22006-09-19 10:28:00 -0700631
632 int drvr_wait = QL4_LOCK_DRVR_WAIT;
633 while (drvr_wait) {
David C Somayajulu92b72732007-05-23 17:55:40 -0700634 if (ql4xxx_lock_drvr(a) == 0) {
David C Somayajulu477ffb92007-01-22 12:26:11 -0800635 ssleep(QL4_LOCK_DRVR_SLEEP);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700636 if (drvr_wait) {
637 DEBUG2(printk("scsi%ld: %s: Waiting for "
David C Somayajulu92b72732007-05-23 17:55:40 -0700638 "Global Init Semaphore(%d)...\n",
639 a->host_no,
David C Somayajulu477ffb92007-01-22 12:26:11 -0800640 __func__, drvr_wait));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700641 }
642 drvr_wait -= QL4_LOCK_DRVR_SLEEP;
643 } else {
644 DEBUG2(printk("scsi%ld: %s: Global Init Semaphore "
David C Somayajulu92b72732007-05-23 17:55:40 -0700645 "acquired\n", a->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700646 return QLA_SUCCESS;
647 }
648 }
649 return QLA_ERROR;
650}
651
652/**
653 * qla4xxx_start_firmware - starts qla4xxx firmware
654 * @ha: Pointer to host adapter structure.
655 *
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200656 * This routine performs the necessary steps to start the firmware for
David Somayajuluafaf5a22006-09-19 10:28:00 -0700657 * the QLA4010 adapter.
658 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530659int qla4xxx_start_firmware(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700660{
661 unsigned long flags = 0;
662 uint32_t mbox_status;
663 int status = QLA_ERROR;
664 int soft_reset = 1;
665 int config_chip = 0;
666
David C Somayajulud9150582006-11-15 17:38:40 -0800667 if (is_qla4022(ha) | is_qla4032(ha))
David Somayajuluafaf5a22006-09-19 10:28:00 -0700668 ql4xxx_set_mac_number(ha);
669
670 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
671 return QLA_ERROR;
672
673 spin_lock_irqsave(&ha->hardware_lock, flags);
674
675 DEBUG2(printk("scsi%ld: %s: port_ctrl = 0x%08X\n", ha->host_no,
676 __func__, readw(isp_port_ctrl(ha))));
677 DEBUG(printk("scsi%ld: %s: port_status = 0x%08X\n", ha->host_no,
678 __func__, readw(isp_port_status(ha))));
679
680 /* Is Hardware already initialized? */
681 if ((readw(isp_port_ctrl(ha)) & 0x8000) != 0) {
682 DEBUG(printk("scsi%ld: %s: Hardware has already been "
683 "initialized\n", ha->host_no, __func__));
684
685 /* Receive firmware boot acknowledgement */
686 mbox_status = readw(&ha->reg->mailbox[0]);
687
688 DEBUG2(printk("scsi%ld: %s: H/W Config complete - mbox[0]= "
689 "0x%x\n", ha->host_no, __func__, mbox_status));
690
691 /* Is firmware already booted? */
692 if (mbox_status == 0) {
693 /* F/W not running, must be config by net driver */
694 config_chip = 1;
695 soft_reset = 0;
696 } else {
697 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
698 &ha->reg->ctrl_status);
699 readl(&ha->reg->ctrl_status);
700 spin_unlock_irqrestore(&ha->hardware_lock, flags);
701 if (qla4xxx_get_firmware_state(ha) == QLA_SUCCESS) {
702 DEBUG2(printk("scsi%ld: %s: Get firmware "
703 "state -- state = 0x%x\n",
704 ha->host_no,
705 __func__, ha->firmware_state));
706 /* F/W is running */
707 if (ha->firmware_state &
708 FW_STATE_CONFIG_WAIT) {
709 DEBUG2(printk("scsi%ld: %s: Firmware "
710 "in known state -- "
711 "config and "
712 "boot, state = 0x%x\n",
713 ha->host_no, __func__,
714 ha->firmware_state));
715 config_chip = 1;
716 soft_reset = 0;
717 }
718 } else {
719 DEBUG2(printk("scsi%ld: %s: Firmware in "
720 "unknown state -- resetting,"
721 " state = "
722 "0x%x\n", ha->host_no, __func__,
723 ha->firmware_state));
724 }
725 spin_lock_irqsave(&ha->hardware_lock, flags);
726 }
727 } else {
728 DEBUG(printk("scsi%ld: %s: H/W initialization hasn't been "
729 "started - resetting\n", ha->host_no, __func__));
730 }
731 spin_unlock_irqrestore(&ha->hardware_lock, flags);
732
733 DEBUG(printk("scsi%ld: %s: Flags soft_rest=%d, config= %d\n ",
734 ha->host_no, __func__, soft_reset, config_chip));
735 if (soft_reset) {
736 DEBUG(printk("scsi%ld: %s: Issue Soft Reset\n", ha->host_no,
737 __func__));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530738 status = qla4xxx_soft_reset(ha); /* NOTE: acquires drvr
739 * lock again, but ok */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700740 if (status == QLA_ERROR) {
741 DEBUG(printk("scsi%d: %s: Soft Reset failed!\n",
742 ha->host_no, __func__));
743 ql4xxx_unlock_drvr(ha);
744 return QLA_ERROR;
745 }
746 config_chip = 1;
747
Joe Perchesb1c11812008-02-03 17:28:22 +0200748 /* Reset clears the semaphore, so acquire again */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700749 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
750 return QLA_ERROR;
751 }
752
753 if (config_chip) {
754 if ((status = qla4xxx_config_nvram(ha)) == QLA_SUCCESS)
755 status = qla4xxx_start_firmware_from_flash(ha);
756 }
757
758 ql4xxx_unlock_drvr(ha);
759 if (status == QLA_SUCCESS) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700760 if (test_and_clear_bit(AF_GET_CRASH_RECORD, &ha->flags))
761 qla4xxx_get_crash_record(ha);
762 } else {
763 DEBUG(printk("scsi%ld: %s: Firmware has NOT started\n",
764 ha->host_no, __func__));
765 }
766 return status;
767}
Lalit Chandivade166dd202011-10-07 16:55:45 -0700768/**
769 * qla4xxx_free_ddb_index - Free DDBs reserved by firmware
770 * @ha: pointer to adapter structure
771 *
772 * Since firmware is not running in autoconnect mode the DDB indices should
773 * be freed so that when login happens from user space there are free DDB
774 * indices available.
775 **/
776static void qla4xxx_free_ddb_index(struct scsi_qla_host *ha)
777{
778 int max_ddbs;
779 int ret;
780 uint32_t idx = 0, next_idx = 0;
781 uint32_t state = 0, conn_err = 0;
782
783 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
784 MAX_DEV_DB_ENTRIES;
785
786 for (idx = 0; idx < max_ddbs; idx = next_idx) {
787 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
788 &next_idx, &state, &conn_err,
789 NULL, NULL);
790 if (ret == QLA_ERROR)
791 continue;
792 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
793 state == DDB_DS_SESSION_FAILED) {
794 DEBUG2(ql4_printk(KERN_INFO, ha,
795 "Freeing DDB index = 0x%x\n", idx));
796 ret = qla4xxx_clear_ddb_entry(ha, idx);
797 if (ret == QLA_ERROR)
798 ql4_printk(KERN_ERR, ha,
799 "Unable to clear DDB index = "
800 "0x%x\n", idx);
801 }
802 if (next_idx == 0)
803 break;
804 }
805}
David Somayajuluafaf5a22006-09-19 10:28:00 -0700806
807
808/**
809 * qla4xxx_initialize_adapter - initiailizes hba
810 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700811 *
812 * This routine parforms all of the steps necessary to initialize the adapter.
813 *
814 **/
Manish Rangankar0e7e8502011-07-25 13:48:54 -0500815int qla4xxx_initialize_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700816{
817 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700818
819 ha->eeprom_cmd_data = 0;
820
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530821 ql4_printk(KERN_INFO, ha, "Configuring PCI space...\n");
822 ha->isp_ops->pci_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700823
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530824 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700825
826 /* Initialize the Host adapter request/response queues and firmware */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530827 if (ha->isp_ops->start_firmware(ha) == QLA_ERROR)
David C Somayajulu46235e62007-06-08 17:37:16 -0700828 goto exit_init_hba;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700829
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700830 if (qla4xxx_about_firmware(ha) == QLA_ERROR)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530831 goto exit_init_hba;
832
833 if (ha->isp_ops->get_sys_info(ha) == QLA_ERROR)
David C Somayajulu46235e62007-06-08 17:37:16 -0700834 goto exit_init_hba;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700835
836 if (qla4xxx_init_local_data(ha) == QLA_ERROR)
David C Somayajulu46235e62007-06-08 17:37:16 -0700837 goto exit_init_hba;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700838
839 status = qla4xxx_init_firmware(ha);
840 if (status == QLA_ERROR)
David C Somayajulu46235e62007-06-08 17:37:16 -0700841 goto exit_init_hba;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700842
Lalit Chandivade166dd202011-10-07 16:55:45 -0700843 qla4xxx_free_ddb_index(ha);
844
David C Somayajulu92b72732007-05-23 17:55:40 -0700845 set_bit(AF_ONLINE, &ha->flags);
David C Somayajulu46235e62007-06-08 17:37:16 -0700846exit_init_hba:
Vikas Chaudhary3710c602010-10-06 22:49:08 -0700847 if (is_qla8022(ha) && (status == QLA_ERROR)) {
848 /* Since interrupts are registered in start_firmware for
849 * 82xx, release them here if initialize_adapter fails */
850 qla4xxx_free_irqs(ha);
851 }
852
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530853 DEBUG2(printk("scsi%ld: initialize adapter: %s\n", ha->host_no,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300854 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700855 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700856}
857
858/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700859 * qla4xxx_process_ddb_changed - process ddb state change
860 * @ha - Pointer to host adapter structure.
861 * @fw_ddb_index - Firmware's device database index
862 * @state - Device state
863 *
864 * This routine processes a Decive Database Changed AEN Event.
865 **/
Vikas Chaudhary821d6e52010-04-28 11:41:21 +0530866int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index,
867 uint32_t state, uint32_t conn_err)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700868{
869 struct ddb_entry * ddb_entry;
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500870 uint32_t old_fw_ddb_device_state;
871 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700872
873 /* check for out of range index */
874 if (fw_ddb_index >= MAX_DDB_ENTRIES)
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500875 goto exit_ddb_event;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700876
877 /* Get the corresponging ddb entry */
878 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index);
879 /* Device does not currently exist in our database. */
880 if (ddb_entry == NULL) {
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500881 ql4_printk(KERN_ERR, ha, "%s: No ddb_entry at FW index [%d]\n",
882 __func__, fw_ddb_index);
883 goto exit_ddb_event;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700884 }
885
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500886 old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state;
887 DEBUG2(ql4_printk(KERN_INFO, ha,
888 "%s: DDB - old state = 0x%x, new state = 0x%x for "
889 "index [%d]\n", __func__,
890 ddb_entry->fw_ddb_device_state, state, fw_ddb_index));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700891
892 ddb_entry->fw_ddb_device_state = state;
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +0530893
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500894 switch (old_fw_ddb_device_state) {
895 case DDB_DS_LOGIN_IN_PROCESS:
896 switch (state) {
897 case DDB_DS_SESSION_ACTIVE:
898 case DDB_DS_DISCOVERY:
899 iscsi_conn_login_event(ddb_entry->conn,
900 ISCSI_CONN_STATE_LOGGED_IN);
901 qla4xxx_update_session_conn_param(ha, ddb_entry);
902 status = QLA_SUCCESS;
903 break;
904 case DDB_DS_SESSION_FAILED:
905 case DDB_DS_NO_CONNECTION_ACTIVE:
906 iscsi_conn_login_event(ddb_entry->conn,
907 ISCSI_CONN_STATE_FREE);
908 status = QLA_SUCCESS;
909 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700910 }
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500911 break;
912 case DDB_DS_SESSION_ACTIVE:
913 if (state == DDB_DS_SESSION_FAILED) {
914 /*
915 * iscsi_session failure will cause userspace to
916 * stop the connection which in turn would block the
917 * iscsi_session and start relogin
918 */
919 iscsi_session_failure(ddb_entry->sess->dd_data,
920 ISCSI_ERR_CONN_FAILED);
921 status = QLA_SUCCESS;
922 }
923 break;
924 default:
925 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unknown Event\n",
926 __func__));
927 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700928 }
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500929
930exit_ddb_event:
931 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700932}