2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
8 #include <scsi/iscsi_if.h>
12 #include "ql4_inline.h"
14 static struct ddb_entry
* qla4xxx_alloc_ddb(struct scsi_qla_host
*ha
,
15 uint32_t fw_ddb_index
);
17 static void ql4xxx_set_mac_number(struct scsi_qla_host
*ha
)
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
);
28 func_number
= (uint8_t) ((value
>> 4) & 0x30);
29 switch (value
& ISP_CONTROL_FN_MASK
) {
30 case ISP_CONTROL_FN0_SCSI
:
33 case ISP_CONTROL_FN1_SCSI
:
37 DEBUG2(printk("scsi%ld: %s: Invalid function number, "
38 "ispControlStatus = 0x%x\n", ha
->host_no
,
42 DEBUG2(printk("scsi%ld: %s: mac_index %d.\n", ha
->host_no
, __func__
,
47 * qla4xxx_free_ddb - deallocate ddb
48 * @ha: pointer to host adapter structure.
49 * @ddb_entry: pointer to device database entry
51 * This routine deallocates and unlinks the specified ddb_entry from the
54 static void qla4xxx_free_ddb(struct scsi_qla_host
*ha
,
55 struct ddb_entry
*ddb_entry
)
57 /* Remove device entry from list */
58 list_del_init(&ddb_entry
->list
);
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
;
65 /* Free memory and scsi-ml struct for device entry */
66 qla4xxx_destroy_sess(ddb_entry
);
70 * qla4xxx_free_ddb_list - deallocate all ddbs
71 * @ha: pointer to host adapter structure.
73 * This routine deallocates and removes all devices on the sppecified adapter.
75 void qla4xxx_free_ddb_list(struct scsi_qla_host
*ha
)
77 struct list_head
*ptr
;
78 struct ddb_entry
*ddb_entry
;
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
);
89 * qla4xxx_init_rings - initialize hw queues
90 * @ha: pointer to host adapter structure.
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.
96 int qla4xxx_init_rings(struct scsi_qla_host
*ha
)
98 unsigned long flags
= 0;
100 /* Initialize request queue. */
101 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
104 ha
->request_ptr
= &ha
->request_ring
[ha
->request_in
];
105 ha
->req_q_count
= REQUEST_QUEUE_DEPTH
;
107 /* Initialize response queue. */
109 ha
->response_out
= 0;
110 ha
->response_ptr
= &ha
->response_ring
[ha
->response_out
];
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.
118 ha
->shadow_regs
->req_q_out
= __constant_cpu_to_le32(0);
119 ha
->shadow_regs
->rsp_q_in
= __constant_cpu_to_le32(0);
122 writel(0, &ha
->reg
->req_q_in
);
123 writel(0, &ha
->reg
->rsp_q_out
);
124 readl(&ha
->reg
->rsp_q_out
);
126 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
132 * qla4xxx_validate_mac_address - validate adapter MAC address(es)
133 * @ha: pointer to host adapter structure.
136 static int qla4xxx_validate_mac_address(struct scsi_qla_host
*ha
)
138 struct flash_sys_info
*sys_info
;
139 dma_addr_t sys_info_dma
;
140 int status
= QLA_ERROR
;
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__
));
148 goto exit_validate_mac_no_free
;
150 memset(sys_info
, 0, sizeof(*sys_info
));
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__
));
158 goto exit_validate_mac
;
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
)));
169 status
= QLA_SUCCESS
;
172 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*sys_info
), sys_info
,
175 exit_validate_mac_no_free
:
180 * qla4xxx_init_local_data - initialize adapter specific local data
181 * @ha: pointer to host adapter structure.
184 static int qla4xxx_init_local_data(struct scsi_qla_host
*ha
)
186 /* Initilize aen queue */
187 ha
->aen_q_count
= MAX_AEN_ENTRIES
;
189 return qla4xxx_get_firmware_status(ha
);
192 static int qla4xxx_fw_ready(struct scsi_qla_host
*ha
)
194 uint32_t timeout_count
;
197 DEBUG2(dev_info(&ha
->pdev
->dev
, "Waiting for Firmware Ready..\n"));
198 for (timeout_count
= ADAPTER_INIT_TOV
; timeout_count
> 0;
200 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
))
201 qla4xxx_get_dhcp_ip_address(ha
);
203 /* Get firmware state. */
204 if (qla4xxx_get_firmware_state(ha
) != QLA_SUCCESS
) {
205 DEBUG2(printk("scsi%ld: %s: unable to get firmware "
206 "state\n", ha
->host_no
, __func__
));
211 if (ha
->firmware_state
& FW_STATE_ERROR
) {
212 DEBUG2(printk("scsi%ld: %s: an unrecoverable error has"
213 " occurred\n", ha
->host_no
, __func__
));
217 if (ha
->firmware_state
& FW_STATE_CONFIG_WAIT
) {
219 * The firmware has not yet been issued an Initialize
220 * Firmware command, so issue it now.
222 if (qla4xxx_initialize_fw_cb(ha
) == QLA_ERROR
)
225 /* Go back and test for ready state - no wait. */
229 if (ha
->firmware_state
== FW_STATE_READY
) {
230 DEBUG2(dev_info(&ha
->pdev
->dev
, "Firmware Ready..\n"));
231 /* The firmware is ready to process SCSI commands. */
232 DEBUG2(dev_info(&ha
->pdev
->dev
,
233 "scsi%ld: %s: MEDIA TYPE - %s\n",
235 __func__
, (ha
->addl_fw_state
&
236 FW_ADDSTATE_OPTICAL_MEDIA
)
237 != 0 ? "OPTICAL" : "COPPER"));
238 DEBUG2(dev_info(&ha
->pdev
->dev
,
239 "scsi%ld: %s: DHCP STATE Enabled "
241 ha
->host_no
, __func__
,
243 FW_ADDSTATE_DHCP_ENABLED
) != 0 ?
245 DEBUG2(dev_info(&ha
->pdev
->dev
,
246 "scsi%ld: %s: LINK %s\n",
247 ha
->host_no
, __func__
,
249 FW_ADDSTATE_LINK_UP
) != 0 ?
251 DEBUG2(dev_info(&ha
->pdev
->dev
,
252 "scsi%ld: %s: iSNS Service "
254 ha
->host_no
, __func__
,
256 FW_ADDSTATE_ISNS_SVC_ENABLED
) != 0 ?
262 DEBUG2(printk("scsi%ld: %s: waiting on fw, state=%x:%x - "
263 "seconds expired= %d\n", ha
->host_no
, __func__
,
264 ha
->firmware_state
, ha
->addl_fw_state
,
266 if (is_qla4032(ha
) &&
267 !(ha
->addl_fw_state
& FW_ADDSTATE_LINK_UP
) &&
268 (timeout_count
< ADAPTER_INIT_TOV
- 5)) {
275 if (timeout_count
== 0)
276 DEBUG2(printk("scsi%ld: %s: FW Initialization timed out!\n",
277 ha
->host_no
, __func__
));
279 if (ha
->firmware_state
& FW_STATE_DHCP_IN_PROGRESS
) {
280 DEBUG2(printk("scsi%ld: %s: FW is reporting its waiting to"
281 " grab an IP address from DHCP server\n",
282 ha
->host_no
, __func__
));
290 * qla4xxx_init_firmware - initializes the firmware.
291 * @ha: pointer to host adapter structure.
294 static int qla4xxx_init_firmware(struct scsi_qla_host
*ha
)
296 int status
= QLA_ERROR
;
298 dev_info(&ha
->pdev
->dev
, "Initializing firmware..\n");
299 if (qla4xxx_initialize_fw_cb(ha
) == QLA_ERROR
) {
300 DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware "
301 "control block\n", ha
->host_no
, __func__
));
304 if (!qla4xxx_fw_ready(ha
))
307 return qla4xxx_get_firmware_status(ha
);
310 static struct ddb_entry
* qla4xxx_get_ddb_entry(struct scsi_qla_host
*ha
,
311 uint32_t fw_ddb_index
,
314 struct dev_db_entry
*fw_ddb_entry
= NULL
;
315 dma_addr_t fw_ddb_entry_dma
;
316 struct ddb_entry
*ddb_entry
= NULL
;
318 uint32_t device_state
;
321 /* Make sure the dma buffer is valid */
322 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
,
323 sizeof(*fw_ddb_entry
),
324 &fw_ddb_entry_dma
, GFP_KERNEL
);
325 if (fw_ddb_entry
== NULL
) {
326 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
327 ha
->host_no
, __func__
));
331 if (qla4xxx_get_fwddb_entry(ha
, fw_ddb_index
, fw_ddb_entry
,
332 fw_ddb_entry_dma
, NULL
, NULL
,
333 &device_state
, NULL
, NULL
, NULL
) ==
335 DEBUG2(printk("scsi%ld: %s: failed get_ddb_entry for "
336 "fw_ddb_index %d\n", ha
->host_no
, __func__
,
341 /* Allocate DDB if not already allocated. */
342 DEBUG2(printk("scsi%ld: %s: Looking for ddb[%d]\n", ha
->host_no
,
343 __func__
, fw_ddb_index
));
344 list_for_each_entry(ddb_entry
, &ha
->ddb_list
, list
) {
345 if ((memcmp(ddb_entry
->iscsi_name
, fw_ddb_entry
->iscsi_name
,
346 ISCSI_NAME_SIZE
) == 0) &&
348 le32_to_cpu(fw_ddb_entry
->tgt_portal_grp
)) &&
349 (memcmp(ddb_entry
->isid
, fw_ddb_entry
->isid
,
350 sizeof(ddb_entry
->isid
)) == 0)) {
357 DEBUG2(printk("scsi%ld: %s: ddb[%d] not found - allocating "
358 "new ddb\n", ha
->host_no
, __func__
,
361 ddb_entry
= qla4xxx_alloc_ddb(ha
, fw_ddb_index
);
364 /* if not found allocate new ddb */
365 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
), fw_ddb_entry
,
372 * qla4xxx_update_ddb_entry - update driver's internal ddb
373 * @ha: pointer to host adapter structure.
374 * @ddb_entry: pointer to device database structure to be filled
375 * @fw_ddb_index: index of the ddb entry in fw ddb table
377 * This routine updates the driver's internal device database entry
378 * with information retrieved from the firmware's device database
379 * entry for the specified device. The ddb_entry->fw_ddb_index field
380 * must be initialized prior to calling this routine
383 static int qla4xxx_update_ddb_entry(struct scsi_qla_host
*ha
,
384 struct ddb_entry
*ddb_entry
,
385 uint32_t fw_ddb_index
)
387 struct dev_db_entry
*fw_ddb_entry
= NULL
;
388 dma_addr_t fw_ddb_entry_dma
;
389 int status
= QLA_ERROR
;
391 if (ddb_entry
== NULL
) {
392 DEBUG2(printk("scsi%ld: %s: ddb_entry is NULL\n", ha
->host_no
,
394 goto exit_update_ddb
;
397 /* Make sure the dma buffer is valid */
398 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
,
399 sizeof(*fw_ddb_entry
),
400 &fw_ddb_entry_dma
, GFP_KERNEL
);
401 if (fw_ddb_entry
== NULL
) {
402 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
403 ha
->host_no
, __func__
));
405 goto exit_update_ddb
;
408 if (qla4xxx_get_fwddb_entry(ha
, fw_ddb_index
, fw_ddb_entry
,
409 fw_ddb_entry_dma
, NULL
, NULL
,
410 &ddb_entry
->fw_ddb_device_state
, NULL
,
411 &ddb_entry
->tcp_source_port_num
,
412 &ddb_entry
->connection_id
) ==
414 DEBUG2(printk("scsi%ld: %s: failed get_ddb_entry for "
415 "fw_ddb_index %d\n", ha
->host_no
, __func__
,
418 goto exit_update_ddb
;
421 status
= QLA_SUCCESS
;
422 ddb_entry
->target_session_id
= le16_to_cpu(fw_ddb_entry
->tsid
);
423 ddb_entry
->task_mgmt_timeout
=
424 le16_to_cpu(fw_ddb_entry
->def_timeout
);
425 ddb_entry
->CmdSn
= 0;
426 ddb_entry
->exe_throttle
= le16_to_cpu(fw_ddb_entry
->exec_throttle
);
427 ddb_entry
->default_relogin_timeout
=
428 le16_to_cpu(fw_ddb_entry
->def_timeout
);
429 ddb_entry
->default_time2wait
= le16_to_cpu(fw_ddb_entry
->iscsi_def_time2wait
);
431 /* Update index in case it changed */
432 ddb_entry
->fw_ddb_index
= fw_ddb_index
;
433 ha
->fw_ddb_index_map
[fw_ddb_index
] = ddb_entry
;
435 ddb_entry
->port
= le16_to_cpu(fw_ddb_entry
->port
);
436 ddb_entry
->tpgt
= le32_to_cpu(fw_ddb_entry
->tgt_portal_grp
);
437 memcpy(ddb_entry
->isid
, fw_ddb_entry
->isid
, sizeof(ddb_entry
->isid
));
439 memcpy(&ddb_entry
->iscsi_name
[0], &fw_ddb_entry
->iscsi_name
[0],
440 min(sizeof(ddb_entry
->iscsi_name
),
441 sizeof(fw_ddb_entry
->iscsi_name
)));
442 memcpy(&ddb_entry
->ip_addr
[0], &fw_ddb_entry
->ip_addr
[0],
443 min(sizeof(ddb_entry
->ip_addr
), sizeof(fw_ddb_entry
->ip_addr
)));
445 DEBUG2(printk("scsi%ld: %s: ddb[%d] - State= %x status= %d.\n",
446 ha
->host_no
, __func__
, fw_ddb_index
,
447 ddb_entry
->fw_ddb_device_state
, status
));
451 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
452 fw_ddb_entry
, fw_ddb_entry_dma
);
458 * qla4xxx_alloc_ddb - allocate device database entry
459 * @ha: Pointer to host adapter structure.
460 * @fw_ddb_index: Firmware's device database index
462 * This routine allocates a ddb_entry, ititializes some values, and
463 * inserts it into the ddb list.
465 static struct ddb_entry
* qla4xxx_alloc_ddb(struct scsi_qla_host
*ha
,
466 uint32_t fw_ddb_index
)
468 struct ddb_entry
*ddb_entry
;
470 DEBUG2(printk("scsi%ld: %s: fw_ddb_index [%d]\n", ha
->host_no
,
471 __func__
, fw_ddb_index
));
473 ddb_entry
= qla4xxx_alloc_sess(ha
);
474 if (ddb_entry
== NULL
) {
475 DEBUG2(printk("scsi%ld: %s: Unable to allocate memory "
476 "to add fw_ddb_index [%d]\n",
477 ha
->host_no
, __func__
, fw_ddb_index
));
481 ddb_entry
->fw_ddb_index
= fw_ddb_index
;
482 atomic_set(&ddb_entry
->port_down_timer
, ha
->port_down_retry_count
);
483 atomic_set(&ddb_entry
->retry_relogin_timer
, INVALID_ENTRY
);
484 atomic_set(&ddb_entry
->relogin_timer
, 0);
485 atomic_set(&ddb_entry
->relogin_retry_count
, 0);
486 atomic_set(&ddb_entry
->state
, DDB_STATE_ONLINE
);
487 list_add_tail(&ddb_entry
->list
, &ha
->ddb_list
);
488 ha
->fw_ddb_index_map
[fw_ddb_index
] = ddb_entry
;
495 * qla4xxx_configure_ddbs - builds driver ddb list
496 * @ha: Pointer to host adapter structure.
498 * This routine searches for all valid firmware ddb entries and builds
499 * an internal ddb list. Ddbs that are considered valid are those with
500 * a device state of SESSION_ACTIVE.
502 static int qla4xxx_build_ddb_list(struct scsi_qla_host
*ha
)
504 int status
= QLA_SUCCESS
;
505 uint32_t fw_ddb_index
= 0;
506 uint32_t next_fw_ddb_index
= 0;
508 uint32_t conn_err
, err_code
;
509 struct ddb_entry
*ddb_entry
;
512 dev_info(&ha
->pdev
->dev
, "Initializing DDBs ...\n");
513 for (fw_ddb_index
= 0; fw_ddb_index
< MAX_DDB_ENTRIES
;
514 fw_ddb_index
= next_fw_ddb_index
) {
515 /* First, let's see if a device exists here */
516 if (qla4xxx_get_fwddb_entry(ha
, fw_ddb_index
, NULL
, 0, NULL
,
517 &next_fw_ddb_index
, &ddb_state
,
518 &conn_err
, NULL
, NULL
) ==
520 DEBUG2(printk("scsi%ld: %s: get_ddb_entry, "
521 "fw_ddb_index %d failed", ha
->host_no
,
522 __func__
, fw_ddb_index
));
526 DEBUG2(printk("scsi%ld: %s: Getting DDB[%d] ddbstate=0x%x, "
527 "next_fw_ddb_index=%d.\n", ha
->host_no
, __func__
,
528 fw_ddb_index
, ddb_state
, next_fw_ddb_index
));
530 /* Issue relogin, if necessary. */
531 if (ddb_state
== DDB_DS_SESSION_FAILED
||
532 ddb_state
== DDB_DS_NO_CONNECTION_ACTIVE
) {
533 /* Try and login to device */
534 DEBUG2(printk("scsi%ld: %s: Login to DDB[%d]\n",
535 ha
->host_no
, __func__
, fw_ddb_index
));
536 err_code
= ((conn_err
& 0x00ff0000) >> 16);
537 if (err_code
== 0x1c || err_code
== 0x06) {
538 DEBUG2(printk("scsi%ld: %s send target "
540 "or access denied failure\n",
541 ha
->host_no
, __func__
));
543 qla4xxx_set_ddb_entry(ha
, fw_ddb_index
, 0);
544 if (qla4xxx_get_fwddb_entry(ha
, fw_ddb_index
,
545 NULL
, 0, NULL
, &next_fw_ddb_index
,
546 &ddb_state
, &conn_err
, NULL
, NULL
)
548 DEBUG2(printk("scsi%ld: %s:"
549 "get_ddb_entry %d failed\n",
551 __func__
, fw_ddb_index
));
557 if (ddb_state
!= DDB_DS_SESSION_ACTIVE
)
560 * if fw_ddb with session active state found,
563 DEBUG2(printk("scsi%ld: %s: DDB[%d] added to list\n",
564 ha
->host_no
, __func__
, fw_ddb_index
));
566 /* Add DDB to internal our ddb list. */
567 ddb_entry
= qla4xxx_get_ddb_entry(ha
, fw_ddb_index
, &new_tgt
);
568 if (ddb_entry
== NULL
) {
569 DEBUG2(printk("scsi%ld: %s: Unable to allocate memory "
570 "for device at fw_ddb_index %d\n",
571 ha
->host_no
, __func__
, fw_ddb_index
));
574 /* Fill in the device structure */
575 if (qla4xxx_update_ddb_entry(ha
, ddb_entry
, fw_ddb_index
) ==
577 ha
->fw_ddb_index_map
[fw_ddb_index
] =
578 (struct ddb_entry
*)INVALID_ENTRY
;
581 DEBUG2(printk("scsi%ld: %s: update_ddb_entry failed "
582 "for fw_ddb_index %d.\n",
583 ha
->host_no
, __func__
, fw_ddb_index
));
588 /* We know we've reached the last device when
589 * next_fw_ddb_index is 0 */
590 if (next_fw_ddb_index
== 0)
594 dev_info(&ha
->pdev
->dev
, "DDB list done..\n");
599 struct qla4_relog_scan
{
603 uint32_t fw_ddb_index
;
604 uint32_t next_fw_ddb_index
;
605 uint32_t fw_ddb_device_state
;
608 static int qla4_test_rdy(struct scsi_qla_host
*ha
, struct qla4_relog_scan
*rs
)
610 struct ddb_entry
*ddb_entry
;
613 * Don't want to do a relogin if connection
616 rs
->err_code
= ((rs
->conn_err
& 0x00ff0000) >> 16);
617 if (rs
->err_code
== 0x1c || rs
->err_code
== 0x06) {
619 "scsi%ld: %s send target"
621 "access denied failure\n",
622 ha
->host_no
, __func__
));
624 /* We either have a device that is in
625 * the process of relogging in or a
626 * device that is waiting to be
630 ddb_entry
= qla4xxx_lookup_ddb_by_fw_index(ha
,
632 if (ddb_entry
== NULL
)
635 if (ddb_entry
->dev_scan_wait_to_start_relogin
!= 0
636 && time_after_eq(jiffies
,
638 dev_scan_wait_to_start_relogin
))
640 ddb_entry
->dev_scan_wait_to_start_relogin
= 0;
641 qla4xxx_set_ddb_entry(ha
, rs
->fw_ddb_index
, 0);
647 static int qla4_scan_for_relogin(struct scsi_qla_host
*ha
,
648 struct qla4_relog_scan
*rs
)
653 * ----------------- */
654 for (rs
->fw_ddb_index
= 0; rs
->fw_ddb_index
< MAX_DDB_ENTRIES
;
655 rs
->fw_ddb_index
= rs
->next_fw_ddb_index
) {
656 if (qla4xxx_get_fwddb_entry(ha
, rs
->fw_ddb_index
, NULL
, 0,
657 NULL
, &rs
->next_fw_ddb_index
,
658 &rs
->fw_ddb_device_state
,
659 &rs
->conn_err
, NULL
, NULL
)
663 if (rs
->fw_ddb_device_state
== DDB_DS_LOGIN_IN_PROCESS
)
666 if (rs
->fw_ddb_device_state
== DDB_DS_SESSION_FAILED
||
667 rs
->fw_ddb_device_state
== DDB_DS_NO_CONNECTION_ACTIVE
) {
668 error
= qla4_test_rdy(ha
, rs
);
673 /* We know we've reached the last device when
674 * next_fw_ddb_index is 0 */
675 if (rs
->next_fw_ddb_index
== 0)
682 * qla4xxx_devices_ready - wait for target devices to be logged in
683 * @ha: pointer to adapter structure
685 * This routine waits up to ql4xdiscoverywait seconds
686 * F/W database during driver load time.
688 static int qla4xxx_devices_ready(struct scsi_qla_host
*ha
)
691 unsigned long discovery_wtime
;
692 struct qla4_relog_scan rs
;
694 discovery_wtime
= jiffies
+ (ql4xdiscoverywait
* HZ
);
696 DEBUG(printk("Waiting (%d) for devices ...\n", ql4xdiscoverywait
));
699 qla4xxx_get_firmware_state(ha
);
700 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
)) {
701 /* Set time-between-relogin timer */
702 qla4xxx_process_aen(ha
, RELOGIN_DDB_CHANGED_AENS
);
705 /* if no relogins active or needed, halt discvery wait */
708 error
= qla4_scan_for_relogin(ha
, &rs
);
711 DEBUG2(printk("scsi%ld: %s: Delay halted. Devices "
712 "Ready.\n", ha
->host_no
, __func__
));
717 } while (!time_after_eq(jiffies
, discovery_wtime
));
719 DEBUG3(qla4xxx_get_conn_event_log(ha
));
724 static void qla4xxx_flush_AENS(struct scsi_qla_host
*ha
)
728 /* Flush the 0x8014 AEN from the firmware as a result of
729 * Auto connect. We are basically doing get_firmware_ddb()
730 * to determine whether we need to log back in or not.
731 * Trying to do a set ddb before we have processed 0x8014
732 * will result in another set_ddb() for the same ddb. In other
733 * words there will be stale entries in the aen_q.
735 wtime
= jiffies
+ (2 * HZ
);
737 if (qla4xxx_get_firmware_state(ha
) == QLA_SUCCESS
)
738 if (ha
->firmware_state
& (BIT_2
| BIT_0
))
741 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
))
742 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
745 } while (!time_after_eq(jiffies
, wtime
));
749 static int qla4xxx_initialize_ddb_list(struct scsi_qla_host
*ha
)
751 uint16_t fw_ddb_index
;
752 int status
= QLA_SUCCESS
;
754 /* free the ddb list if is not empty */
755 if (!list_empty(&ha
->ddb_list
))
756 qla4xxx_free_ddb_list(ha
);
758 for (fw_ddb_index
= 0; fw_ddb_index
< MAX_DDB_ENTRIES
; fw_ddb_index
++)
759 ha
->fw_ddb_index_map
[fw_ddb_index
] =
760 (struct ddb_entry
*)INVALID_ENTRY
;
764 qla4xxx_flush_AENS(ha
);
767 * First perform device discovery for active
768 * fw ddb indexes and build
771 if ((status
= qla4xxx_build_ddb_list(ha
)) == QLA_ERROR
)
774 /* Wait for an AEN */
775 qla4xxx_devices_ready(ha
);
778 * Targets can come online after the inital discovery, so processing
779 * the aens here will catch them.
781 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
))
782 qla4xxx_process_aen(ha
, PROCESS_ALL_AENS
);
788 * qla4xxx_update_ddb_list - update the driver ddb list
789 * @ha: pointer to host adapter structure.
791 * This routine obtains device information from the F/W database after
792 * firmware or adapter resets. The device table is preserved.
794 int qla4xxx_reinitialize_ddb_list(struct scsi_qla_host
*ha
)
796 int status
= QLA_SUCCESS
;
797 struct ddb_entry
*ddb_entry
, *detemp
;
799 /* Update the device information for all devices. */
800 list_for_each_entry_safe(ddb_entry
, detemp
, &ha
->ddb_list
, list
) {
801 qla4xxx_update_ddb_entry(ha
, ddb_entry
,
802 ddb_entry
->fw_ddb_index
);
803 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_ACTIVE
) {
804 atomic_set(&ddb_entry
->state
, DDB_STATE_ONLINE
);
805 DEBUG2(printk ("scsi%ld: %s: ddb index [%d] marked "
806 "ONLINE\n", ha
->host_no
, __func__
,
807 ddb_entry
->fw_ddb_index
));
808 } else if (atomic_read(&ddb_entry
->state
) == DDB_STATE_ONLINE
)
809 qla4xxx_mark_device_missing(ha
, ddb_entry
);
815 * qla4xxx_relogin_device - re-establish session
816 * @ha: Pointer to host adapter structure.
817 * @ddb_entry: Pointer to device database entry
819 * This routine does a session relogin with the specified device.
820 * The ddb entry must be assigned prior to making this call.
822 int qla4xxx_relogin_device(struct scsi_qla_host
*ha
,
823 struct ddb_entry
* ddb_entry
)
825 uint16_t relogin_timer
;
827 relogin_timer
= max(ddb_entry
->default_relogin_timeout
,
828 (uint16_t)RELOGIN_TOV
);
829 atomic_set(&ddb_entry
->relogin_timer
, relogin_timer
);
831 DEBUG2(printk("scsi%ld: Relogin index [%d]. TOV=%d\n", ha
->host_no
,
832 ddb_entry
->fw_ddb_index
, relogin_timer
));
834 qla4xxx_set_ddb_entry(ha
, ddb_entry
->fw_ddb_index
, 0);
839 static int qla4xxx_config_nvram(struct scsi_qla_host
*ha
)
842 union external_hw_config_reg extHwConfig
;
844 DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha
->host_no
,
846 if (ql4xxx_lock_flash(ha
) != QLA_SUCCESS
)
848 if (ql4xxx_lock_nvram(ha
) != QLA_SUCCESS
) {
849 ql4xxx_unlock_flash(ha
);
853 /* Get EEPRom Parameters from NVRAM and validate */
854 dev_info(&ha
->pdev
->dev
, "Configuring NVRAM ...\n");
855 if (qla4xxx_is_nvram_configuration_valid(ha
) == QLA_SUCCESS
) {
856 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
857 extHwConfig
.Asuint32_t
=
858 rd_nvram_word(ha
, eeprom_ext_hw_conf_offset(ha
));
859 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
861 dev_warn(&ha
->pdev
->dev
,
862 "scsi%ld: %s: EEProm checksum invalid. "
863 "Please update your EEPROM\n", ha
->host_no
,
866 /* Attempt to set defaults */
868 extHwConfig
.Asuint32_t
= 0x1912;
869 else if (is_qla4022(ha
) | is_qla4032(ha
))
870 extHwConfig
.Asuint32_t
= 0x0023;
874 DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n",
875 ha
->host_no
, __func__
, extHwConfig
.Asuint32_t
));
877 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
878 writel((0xFFFF << 16) | extHwConfig
.Asuint32_t
, isp_ext_hw_conf(ha
));
879 readl(isp_ext_hw_conf(ha
));
880 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
882 ql4xxx_unlock_nvram(ha
);
883 ql4xxx_unlock_flash(ha
);
888 static void qla4x00_pci_config(struct scsi_qla_host
*ha
)
893 dev_info(&ha
->pdev
->dev
, "Configuring PCI space...\n");
895 pci_set_master(ha
->pdev
);
896 status
= pci_set_mwi(ha
->pdev
);
898 * We want to respect framework's setting of PCI configuration space
899 * command register and also want to make sure that all bits of
900 * interest to us are properly set in command register.
902 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
903 w
|= PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
;
904 w
&= ~PCI_COMMAND_INTX_DISABLE
;
905 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
908 static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host
*ha
)
910 int status
= QLA_ERROR
;
911 uint32_t max_wait_time
;
913 uint32_t mbox_status
;
915 dev_info(&ha
->pdev
->dev
, "Starting firmware ...\n");
918 * Start firmware from flash ROM
920 * WORKAROUND: Stuff a non-constant value that the firmware can
921 * use as a seed for a random number generator in MB7 prior to
922 * setting BOOT_ENABLE. Fixes problem where the TCP
923 * connections use the same TCP ports after each reboot,
924 * causing some connections to not get re-established.
926 DEBUG(printk("scsi%d: %s: Start firmware from flash ROM\n",
927 ha
->host_no
, __func__
));
929 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
930 writel(jiffies
, &ha
->reg
->mailbox
[7]);
931 if (is_qla4022(ha
) | is_qla4032(ha
))
932 writel(set_rmask(NVR_WRITE_ENABLE
),
933 &ha
->reg
->u1
.isp4022
.nvram
);
935 writel(2, &ha
->reg
->mailbox
[6]);
936 readl(&ha
->reg
->mailbox
[6]);
938 writel(set_rmask(CSR_BOOT_ENABLE
), &ha
->reg
->ctrl_status
);
939 readl(&ha
->reg
->ctrl_status
);
940 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
942 /* Wait for firmware to come UP. */
943 max_wait_time
= FIRMWARE_UP_TOV
* 4;
945 uint32_t ctrl_status
;
947 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
948 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
949 mbox_status
= readw(&ha
->reg
->mailbox
[0]);
950 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
952 if (ctrl_status
& set_rmask(CSR_SCSI_PROCESSOR_INTR
))
954 if (mbox_status
== MBOX_STS_COMMAND_COMPLETE
)
957 DEBUG2(printk("scsi%ld: %s: Waiting for boot firmware to "
958 "complete... ctrl_sts=0x%x, remaining=%d\n",
959 ha
->host_no
, __func__
, ctrl_status
,
963 } while ((max_wait_time
--));
965 if (mbox_status
== MBOX_STS_COMMAND_COMPLETE
) {
966 DEBUG(printk("scsi%ld: %s: Firmware has started\n",
967 ha
->host_no
, __func__
));
969 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
970 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR
),
971 &ha
->reg
->ctrl_status
);
972 readl(&ha
->reg
->ctrl_status
);
973 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
975 status
= QLA_SUCCESS
;
977 printk(KERN_INFO
"scsi%ld: %s: Boot firmware failed "
978 "- mbox status 0x%x\n", ha
->host_no
, __func__
,
985 int ql4xxx_lock_drvr_wait(struct scsi_qla_host
*a
)
987 #define QL4_LOCK_DRVR_WAIT 60
988 #define QL4_LOCK_DRVR_SLEEP 1
990 int drvr_wait
= QL4_LOCK_DRVR_WAIT
;
992 if (ql4xxx_lock_drvr(a
) == 0) {
993 ssleep(QL4_LOCK_DRVR_SLEEP
);
995 DEBUG2(printk("scsi%ld: %s: Waiting for "
996 "Global Init Semaphore(%d)...\n",
998 __func__
, drvr_wait
));
1000 drvr_wait
-= QL4_LOCK_DRVR_SLEEP
;
1002 DEBUG2(printk("scsi%ld: %s: Global Init Semaphore "
1003 "acquired\n", a
->host_no
, __func__
));
1011 * qla4xxx_start_firmware - starts qla4xxx firmware
1012 * @ha: Pointer to host adapter structure.
1014 * This routine performs the necessary steps to start the firmware for
1015 * the QLA4010 adapter.
1017 static int qla4xxx_start_firmware(struct scsi_qla_host
*ha
)
1019 unsigned long flags
= 0;
1020 uint32_t mbox_status
;
1021 int status
= QLA_ERROR
;
1023 int config_chip
= 0;
1025 if (is_qla4022(ha
) | is_qla4032(ha
))
1026 ql4xxx_set_mac_number(ha
);
1028 if (ql4xxx_lock_drvr_wait(ha
) != QLA_SUCCESS
)
1031 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1033 DEBUG2(printk("scsi%ld: %s: port_ctrl = 0x%08X\n", ha
->host_no
,
1034 __func__
, readw(isp_port_ctrl(ha
))));
1035 DEBUG(printk("scsi%ld: %s: port_status = 0x%08X\n", ha
->host_no
,
1036 __func__
, readw(isp_port_status(ha
))));
1038 /* Is Hardware already initialized? */
1039 if ((readw(isp_port_ctrl(ha
)) & 0x8000) != 0) {
1040 DEBUG(printk("scsi%ld: %s: Hardware has already been "
1041 "initialized\n", ha
->host_no
, __func__
));
1043 /* Receive firmware boot acknowledgement */
1044 mbox_status
= readw(&ha
->reg
->mailbox
[0]);
1046 DEBUG2(printk("scsi%ld: %s: H/W Config complete - mbox[0]= "
1047 "0x%x\n", ha
->host_no
, __func__
, mbox_status
));
1049 /* Is firmware already booted? */
1050 if (mbox_status
== 0) {
1051 /* F/W not running, must be config by net driver */
1055 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR
),
1056 &ha
->reg
->ctrl_status
);
1057 readl(&ha
->reg
->ctrl_status
);
1058 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1059 if (qla4xxx_get_firmware_state(ha
) == QLA_SUCCESS
) {
1060 DEBUG2(printk("scsi%ld: %s: Get firmware "
1061 "state -- state = 0x%x\n",
1063 __func__
, ha
->firmware_state
));
1064 /* F/W is running */
1065 if (ha
->firmware_state
&
1066 FW_STATE_CONFIG_WAIT
) {
1067 DEBUG2(printk("scsi%ld: %s: Firmware "
1068 "in known state -- "
1070 "boot, state = 0x%x\n",
1071 ha
->host_no
, __func__
,
1072 ha
->firmware_state
));
1077 DEBUG2(printk("scsi%ld: %s: Firmware in "
1078 "unknown state -- resetting,"
1080 "0x%x\n", ha
->host_no
, __func__
,
1081 ha
->firmware_state
));
1083 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1086 DEBUG(printk("scsi%ld: %s: H/W initialization hasn't been "
1087 "started - resetting\n", ha
->host_no
, __func__
));
1089 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1091 DEBUG(printk("scsi%ld: %s: Flags soft_rest=%d, config= %d\n ",
1092 ha
->host_no
, __func__
, soft_reset
, config_chip
));
1094 DEBUG(printk("scsi%ld: %s: Issue Soft Reset\n", ha
->host_no
,
1096 status
= qla4xxx_soft_reset(ha
);
1097 if (status
== QLA_ERROR
) {
1098 DEBUG(printk("scsi%d: %s: Soft Reset failed!\n",
1099 ha
->host_no
, __func__
));
1100 ql4xxx_unlock_drvr(ha
);
1105 /* Reset clears the semaphore, so acquire again */
1106 if (ql4xxx_lock_drvr_wait(ha
) != QLA_SUCCESS
)
1111 if ((status
= qla4xxx_config_nvram(ha
)) == QLA_SUCCESS
)
1112 status
= qla4xxx_start_firmware_from_flash(ha
);
1115 ql4xxx_unlock_drvr(ha
);
1116 if (status
== QLA_SUCCESS
) {
1117 qla4xxx_get_fw_version(ha
);
1118 if (test_and_clear_bit(AF_GET_CRASH_RECORD
, &ha
->flags
))
1119 qla4xxx_get_crash_record(ha
);
1121 DEBUG(printk("scsi%ld: %s: Firmware has NOT started\n",
1122 ha
->host_no
, __func__
));
1129 * qla4xxx_initialize_adapter - initiailizes hba
1130 * @ha: Pointer to host adapter structure.
1131 * @renew_ddb_list: Indicates what to do with the adapter's ddb list
1132 * after adapter recovery has completed.
1133 * 0=preserve ddb list, 1=destroy and rebuild ddb list
1135 * This routine parforms all of the steps necessary to initialize the adapter.
1138 int qla4xxx_initialize_adapter(struct scsi_qla_host
*ha
,
1139 uint8_t renew_ddb_list
)
1141 int status
= QLA_ERROR
;
1142 int8_t ip_address
[IP_ADDR_LEN
] = {0} ;
1144 ha
->eeprom_cmd_data
= 0;
1146 qla4x00_pci_config(ha
);
1148 qla4xxx_disable_intrs(ha
);
1150 /* Initialize the Host adapter request/response queues and firmware */
1151 if (qla4xxx_start_firmware(ha
) == QLA_ERROR
)
1154 if (qla4xxx_validate_mac_address(ha
) == QLA_ERROR
)
1157 if (qla4xxx_init_local_data(ha
) == QLA_ERROR
)
1160 status
= qla4xxx_init_firmware(ha
);
1161 if (status
== QLA_ERROR
)
1165 * FW is waiting to get an IP address from DHCP server: Skip building
1166 * the ddb_list and wait for DHCP lease acquired aen to come in
1167 * followed by 0x8014 aen" to trigger the tgt discovery process.
1169 if (ha
->firmware_state
& FW_STATE_DHCP_IN_PROGRESS
)
1170 goto exit_init_online
;
1172 /* Skip device discovery if ip and subnet is zero */
1173 if (memcmp(ha
->ip_address
, ip_address
, IP_ADDR_LEN
) == 0 ||
1174 memcmp(ha
->subnet_mask
, ip_address
, IP_ADDR_LEN
) == 0)
1175 goto exit_init_online
;
1177 if (renew_ddb_list
== PRESERVE_DDB_LIST
) {
1179 * We want to preserve lun states (i.e. suspended, etc.)
1180 * for recovery initiated by the driver. So just update
1181 * the device states for the existing ddb_list.
1183 qla4xxx_reinitialize_ddb_list(ha
);
1184 } else if (renew_ddb_list
== REBUILD_DDB_LIST
) {
1186 * We want to build the ddb_list from scratch during
1187 * driver initialization and recovery initiated by the
1188 * INT_HBA_RESET IOCTL.
1190 status
= qla4xxx_initialize_ddb_list(ha
);
1191 if (status
== QLA_ERROR
) {
1192 DEBUG2(printk("%s(%ld) Error occurred during build"
1193 "ddb list\n", __func__
, ha
->host_no
));
1198 if (!ha
->tot_ddbs
) {
1199 DEBUG2(printk("scsi%ld: Failed to initialize devices or none "
1200 "present in Firmware device database\n",
1205 set_bit(AF_ONLINE
, &ha
->flags
);
1211 * qla4xxx_add_device_dynamically - ddb addition due to an AEN
1212 * @ha: Pointer to host adapter structure.
1213 * @fw_ddb_index: Firmware's device database index
1215 * This routine processes adds a device as a result of an 8014h AEN.
1217 static void qla4xxx_add_device_dynamically(struct scsi_qla_host
*ha
,
1218 uint32_t fw_ddb_index
)
1220 struct ddb_entry
* ddb_entry
;
1223 /* First allocate a device structure */
1224 ddb_entry
= qla4xxx_get_ddb_entry(ha
, fw_ddb_index
, &new_tgt
);
1225 if (ddb_entry
== NULL
) {
1226 DEBUG2(printk(KERN_WARNING
1227 "scsi%ld: Unable to allocate memory to add "
1228 "fw_ddb_index %d\n", ha
->host_no
, fw_ddb_index
));
1232 if (!new_tgt
&& (ddb_entry
->fw_ddb_index
!= fw_ddb_index
)) {
1233 /* Target has been bound to a new fw_ddb_index */
1234 qla4xxx_free_ddb(ha
, ddb_entry
);
1235 ddb_entry
= qla4xxx_alloc_ddb(ha
, fw_ddb_index
);
1236 if (ddb_entry
== NULL
) {
1237 DEBUG2(printk(KERN_WARNING
1238 "scsi%ld: Unable to allocate memory"
1239 " to add fw_ddb_index %d\n",
1240 ha
->host_no
, fw_ddb_index
));
1244 if (qla4xxx_update_ddb_entry(ha
, ddb_entry
, fw_ddb_index
) ==
1246 ha
->fw_ddb_index_map
[fw_ddb_index
] =
1247 (struct ddb_entry
*)INVALID_ENTRY
;
1248 DEBUG2(printk(KERN_WARNING
1249 "scsi%ld: failed to add new device at index "
1250 "[%d]\n Unable to retrieve fw ddb entry\n",
1251 ha
->host_no
, fw_ddb_index
));
1252 qla4xxx_free_ddb(ha
, ddb_entry
);
1256 if (qla4xxx_add_sess(ddb_entry
)) {
1257 DEBUG2(printk(KERN_WARNING
1258 "scsi%ld: failed to add new device at index "
1259 "[%d]\n Unable to add connection and session\n",
1260 ha
->host_no
, fw_ddb_index
));
1261 qla4xxx_free_ddb(ha
, ddb_entry
);
1266 * qla4xxx_process_ddb_changed - process ddb state change
1267 * @ha - Pointer to host adapter structure.
1268 * @fw_ddb_index - Firmware's device database index
1269 * @state - Device state
1271 * This routine processes a Decive Database Changed AEN Event.
1273 int qla4xxx_process_ddb_changed(struct scsi_qla_host
*ha
,
1274 uint32_t fw_ddb_index
, uint32_t state
)
1276 struct ddb_entry
* ddb_entry
;
1277 uint32_t old_fw_ddb_device_state
;
1279 /* check for out of range index */
1280 if (fw_ddb_index
>= MAX_DDB_ENTRIES
)
1283 /* Get the corresponging ddb entry */
1284 ddb_entry
= qla4xxx_lookup_ddb_by_fw_index(ha
, fw_ddb_index
);
1285 /* Device does not currently exist in our database. */
1286 if (ddb_entry
== NULL
) {
1287 if (state
== DDB_DS_SESSION_ACTIVE
)
1288 qla4xxx_add_device_dynamically(ha
, fw_ddb_index
);
1292 /* Device already exists in our database. */
1293 old_fw_ddb_device_state
= ddb_entry
->fw_ddb_device_state
;
1294 DEBUG2(printk("scsi%ld: %s DDB - old state= 0x%x, new state=0x%x for "
1295 "index [%d]\n", ha
->host_no
, __func__
,
1296 ddb_entry
->fw_ddb_device_state
, state
, fw_ddb_index
));
1297 if (old_fw_ddb_device_state
== state
&&
1298 state
== DDB_DS_SESSION_ACTIVE
) {
1299 /* Do nothing, state not changed. */
1303 ddb_entry
->fw_ddb_device_state
= state
;
1304 /* Device is back online. */
1305 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_ACTIVE
) {
1306 atomic_set(&ddb_entry
->state
, DDB_STATE_ONLINE
);
1307 atomic_set(&ddb_entry
->port_down_timer
,
1308 ha
->port_down_retry_count
);
1309 atomic_set(&ddb_entry
->relogin_retry_count
, 0);
1310 atomic_set(&ddb_entry
->relogin_timer
, 0);
1311 clear_bit(DF_RELOGIN
, &ddb_entry
->flags
);
1312 clear_bit(DF_NO_RELOGIN
, &ddb_entry
->flags
);
1313 iscsi_unblock_session(ddb_entry
->sess
);
1314 iscsi_session_event(ddb_entry
->sess
,
1315 ISCSI_KEVENT_CREATE_SESSION
);
1317 * Change the lun state to READY in case the lun TIMEOUT before
1318 * the device came back.
1321 /* Device went away, try to relogin. */
1322 /* Mark device missing */
1323 if (atomic_read(&ddb_entry
->state
) == DDB_STATE_ONLINE
)
1324 qla4xxx_mark_device_missing(ha
, ddb_entry
);
1326 * Relogin if device state changed to a not active state.
1327 * However, do not relogin if this aen is a result of an IOCTL
1328 * logout (DF_NO_RELOGIN) or if this is a discovered device.
1330 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_FAILED
&&
1331 !test_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
1332 !test_bit(DF_NO_RELOGIN
, &ddb_entry
->flags
) &&
1333 !test_bit(DF_ISNS_DISCOVERED
, &ddb_entry
->flags
)) {
1335 * This triggers a relogin. After the relogin_timer
1336 * expires, the relogin gets scheduled. We must wait a
1337 * minimum amount of time since receiving an 0x8014 AEN
1338 * with failed device_state or a logout response before
1339 * we can issue another relogin.
1341 /* Firmware padds this timeout: (time2wait +1).
1342 * Driver retry to login should be longer than F/W.
1343 * Otherwise F/W will fail
1344 * set_ddb() mbx cmd with 0x4005 since it still
1345 * counting down its time2wait.
1347 atomic_set(&ddb_entry
->relogin_timer
, 0);
1348 atomic_set(&ddb_entry
->retry_relogin_timer
,
1349 ddb_entry
->default_time2wait
+ 4);