726
static void qla4xxx_flush_AENS(struct scsi_qla_host *ha)
730
/* Flush the 0x8014 AEN from the firmware as a result of
731
* Auto connect. We are basically doing get_firmware_ddb()
732
* to determine whether we need to log back in or not.
733
* Trying to do a set ddb before we have processed 0x8014
734
* will result in another set_ddb() for the same ddb. In other
735
* words there will be stale entries in the aen_q.
737
wtime = jiffies + (2 * HZ);
739
if (qla4xxx_get_firmware_state(ha) == QLA_SUCCESS)
740
if (ha->firmware_state & (BIT_2 | BIT_0))
743
if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
744
qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
747
} while (!time_after_eq(jiffies, wtime));
727
* qla4xxx_configure_ddbs - builds driver ddb list
751
* qla4xxx_build_ddb_list - builds driver ddb list
728
752
* @ha: Pointer to host adapter structure.
730
754
* This routine searches for all valid firmware ddb entries and builds
731
755
* an internal ddb list. Ddbs that are considered valid are those with
732
756
* a device state of SESSION_ACTIVE.
757
* A relogin (set_ddb) is issued for DDBs that are not online.
734
759
static int qla4xxx_build_ddb_list(struct scsi_qla_host *ha)
850
struct qla4_relog_scan {
853
uint32_t fw_ddb_index;
854
uint32_t next_fw_ddb_index;
855
uint32_t fw_ddb_device_state;
858
static int qla4_test_rdy(struct scsi_qla_host *ha, struct qla4_relog_scan *rs)
860
struct ddb_entry *ddb_entry;
862
if (qla4_is_relogin_allowed(ha, rs->conn_err)) {
863
/* We either have a device that is in
864
* the process of relogging in or a
865
* device that is waiting to be
869
ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
871
if (ddb_entry == NULL)
874
if (ddb_entry->dev_scan_wait_to_start_relogin != 0
875
&& time_after_eq(jiffies,
877
dev_scan_wait_to_start_relogin))
879
ddb_entry->dev_scan_wait_to_start_relogin = 0;
880
qla4xxx_set_ddb_entry(ha, rs->fw_ddb_index, 0);
886
static int qla4_scan_for_relogin(struct scsi_qla_host *ha,
887
struct qla4_relog_scan *rs)
892
* ----------------- */
893
for (rs->fw_ddb_index = 0; rs->fw_ddb_index < MAX_DDB_ENTRIES;
894
rs->fw_ddb_index = rs->next_fw_ddb_index) {
895
if (qla4xxx_get_fwddb_entry(ha, rs->fw_ddb_index, NULL, 0,
896
NULL, &rs->next_fw_ddb_index,
897
&rs->fw_ddb_device_state,
898
&rs->conn_err, NULL, NULL)
902
if (rs->fw_ddb_device_state == DDB_DS_LOGIN_IN_PROCESS)
905
if (rs->fw_ddb_device_state == DDB_DS_SESSION_FAILED ||
906
rs->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE) {
907
error = qla4_test_rdy(ha, rs);
912
/* We know we've reached the last device when
913
* next_fw_ddb_index is 0 */
914
if (rs->next_fw_ddb_index == 0)
921
* qla4xxx_devices_ready - wait for target devices to be logged in
922
* @ha: pointer to adapter structure
924
* This routine waits up to ql4xdiscoverywait seconds
925
* F/W database during driver load time.
927
static int qla4xxx_devices_ready(struct scsi_qla_host *ha)
930
unsigned long discovery_wtime;
931
struct qla4_relog_scan rs;
933
discovery_wtime = jiffies + (ql4xdiscoverywait * HZ);
935
DEBUG(printk("Waiting (%d) for devices ...\n", ql4xdiscoverywait));
938
qla4xxx_get_firmware_state(ha);
939
if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags)) {
940
/* Set time-between-relogin timer */
941
qla4xxx_process_aen(ha, RELOGIN_DDB_CHANGED_AENS);
944
/* if no relogins active or needed, halt discvery wait */
947
error = qla4_scan_for_relogin(ha, &rs);
950
DEBUG2(printk("scsi%ld: %s: Delay halted. Devices "
951
"Ready.\n", ha->host_no, __func__));
956
} while (!time_after_eq(jiffies, discovery_wtime));
958
DEBUG3(qla4xxx_get_conn_event_log(ha));
963
static void qla4xxx_flush_AENS(struct scsi_qla_host *ha)
967
/* Flush the 0x8014 AEN from the firmware as a result of
968
* Auto connect. We are basically doing get_firmware_ddb()
969
* to determine whether we need to log back in or not.
970
* Trying to do a set ddb before we have processed 0x8014
971
* will result in another set_ddb() for the same ddb. In other
972
* words there will be stale entries in the aen_q.
974
wtime = jiffies + (2 * HZ);
976
if (qla4xxx_get_firmware_state(ha) == QLA_SUCCESS)
977
if (ha->firmware_state & (BIT_2 | BIT_0))
980
if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
981
qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
984
} while (!time_after_eq(jiffies, wtime));
988
877
static int qla4xxx_initialize_ddb_list(struct scsi_qla_host *ha)
990
879
uint16_t fw_ddb_index;
997
886
for (fw_ddb_index = 0; fw_ddb_index < MAX_DDB_ENTRIES; fw_ddb_index++)
998
887
ha->fw_ddb_index_map[fw_ddb_index] =
999
(struct ddb_entry *)INVALID_ENTRY;
888
(struct ddb_entry *)INVALID_ENTRY;
1001
890
ha->tot_ddbs = 0;
1003
qla4xxx_flush_AENS(ha);
1005
/* Wait for an AEN */
1006
qla4xxx_devices_ready(ha);
1009
* First perform device discovery for active
1010
* fw ddb indexes and build
1013
if ((status = qla4xxx_build_ddb_list(ha)) == QLA_ERROR)
1017
* Targets can come online after the inital discovery, so processing
1018
* the aens here will catch them.
1020
if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
1021
qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
892
/* Perform device discovery and build ddb list. */
893
status = qla4xxx_build_ddb_list(ha);
1555
1426
/* Device already exists in our database. */
1556
old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state;
1557
1427
DEBUG2(printk("scsi%ld: %s DDB - old state= 0x%x, new state=0x%x for "
1558
1428
"index [%d]\n", ha->host_no, __func__,
1559
1429
ddb_entry->fw_ddb_device_state, state, fw_ddb_index));
1560
if (old_fw_ddb_device_state == state &&
1561
state == DDB_DS_SESSION_ACTIVE) {
1562
if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
1563
atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
1564
iscsi_unblock_session(ddb_entry->sess);
1569
1431
ddb_entry->fw_ddb_device_state = state;
1570
1432
/* Device is back online. */
1571
if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
1433
if ((ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) &&
1434
(atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)) {
1572
1435
atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
1573
1436
atomic_set(&ddb_entry->relogin_retry_count, 0);
1574
1437
atomic_set(&ddb_entry->relogin_timer, 0);
1575
1438
clear_bit(DF_RELOGIN, &ddb_entry->flags);
1576
clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
1577
1439
iscsi_unblock_session(ddb_entry->sess);
1578
1440
iscsi_session_event(ddb_entry->sess,
1579
1441
ISCSI_KEVENT_CREATE_SESSION);