diff options
Diffstat (limited to 'drivers/scsi/qla4xxx/ql4_init.c')
| -rw-r--r-- | drivers/scsi/qla4xxx/ql4_init.c | 243 |
1 files changed, 203 insertions, 40 deletions
diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c index 3075fbaef553..1bdfa8120ac8 100644 --- a/drivers/scsi/qla4xxx/ql4_init.c +++ b/drivers/scsi/qla4xxx/ql4_init.c | |||
| @@ -773,22 +773,24 @@ int qla4xxx_start_firmware(struct scsi_qla_host *ha) | |||
| 773 | * be freed so that when login happens from user space there are free DDB | 773 | * be freed so that when login happens from user space there are free DDB |
| 774 | * indices available. | 774 | * indices available. |
| 775 | **/ | 775 | **/ |
| 776 | static void qla4xxx_free_ddb_index(struct scsi_qla_host *ha) | 776 | void qla4xxx_free_ddb_index(struct scsi_qla_host *ha) |
| 777 | { | 777 | { |
| 778 | int max_ddbs; | 778 | int max_ddbs; |
| 779 | int ret; | 779 | int ret; |
| 780 | uint32_t idx = 0, next_idx = 0; | 780 | uint32_t idx = 0, next_idx = 0; |
| 781 | uint32_t state = 0, conn_err = 0; | 781 | uint32_t state = 0, conn_err = 0; |
| 782 | 782 | ||
| 783 | max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES : | 783 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 784 | MAX_DEV_DB_ENTRIES; | 784 | MAX_DEV_DB_ENTRIES; |
| 785 | 785 | ||
| 786 | for (idx = 0; idx < max_ddbs; idx = next_idx) { | 786 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
| 787 | ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL, | 787 | ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL, |
| 788 | &next_idx, &state, &conn_err, | 788 | &next_idx, &state, &conn_err, |
| 789 | NULL, NULL); | 789 | NULL, NULL); |
| 790 | if (ret == QLA_ERROR) | 790 | if (ret == QLA_ERROR) { |
| 791 | next_idx++; | ||
| 791 | continue; | 792 | continue; |
| 793 | } | ||
| 792 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || | 794 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 793 | state == DDB_DS_SESSION_FAILED) { | 795 | state == DDB_DS_SESSION_FAILED) { |
| 794 | DEBUG2(ql4_printk(KERN_INFO, ha, | 796 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| @@ -804,7 +806,6 @@ static void qla4xxx_free_ddb_index(struct scsi_qla_host *ha) | |||
| 804 | } | 806 | } |
| 805 | } | 807 | } |
| 806 | 808 | ||
| 807 | |||
| 808 | /** | 809 | /** |
| 809 | * qla4xxx_initialize_adapter - initiailizes hba | 810 | * qla4xxx_initialize_adapter - initiailizes hba |
| 810 | * @ha: Pointer to host adapter structure. | 811 | * @ha: Pointer to host adapter structure. |
| @@ -812,7 +813,7 @@ static void qla4xxx_free_ddb_index(struct scsi_qla_host *ha) | |||
| 812 | * This routine parforms all of the steps necessary to initialize the adapter. | 813 | * This routine parforms all of the steps necessary to initialize the adapter. |
| 813 | * | 814 | * |
| 814 | **/ | 815 | **/ |
| 815 | int qla4xxx_initialize_adapter(struct scsi_qla_host *ha) | 816 | int qla4xxx_initialize_adapter(struct scsi_qla_host *ha, int is_reset) |
| 816 | { | 817 | { |
| 817 | int status = QLA_ERROR; | 818 | int status = QLA_ERROR; |
| 818 | 819 | ||
| @@ -840,7 +841,8 @@ int qla4xxx_initialize_adapter(struct scsi_qla_host *ha) | |||
| 840 | if (status == QLA_ERROR) | 841 | if (status == QLA_ERROR) |
| 841 | goto exit_init_hba; | 842 | goto exit_init_hba; |
| 842 | 843 | ||
| 843 | qla4xxx_free_ddb_index(ha); | 844 | if (is_reset == RESET_ADAPTER) |
| 845 | qla4xxx_build_ddb_list(ha, is_reset); | ||
| 844 | 846 | ||
| 845 | set_bit(AF_ONLINE, &ha->flags); | 847 | set_bit(AF_ONLINE, &ha->flags); |
| 846 | exit_init_hba: | 848 | exit_init_hba: |
| @@ -855,38 +857,12 @@ exit_init_hba: | |||
| 855 | return status; | 857 | return status; |
| 856 | } | 858 | } |
| 857 | 859 | ||
| 858 | /** | 860 | int qla4xxx_ddb_change(struct scsi_qla_host *ha, uint32_t fw_ddb_index, |
| 859 | * qla4xxx_process_ddb_changed - process ddb state change | 861 | struct ddb_entry *ddb_entry, uint32_t state) |
| 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 | **/ | ||
| 866 | int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index, | ||
| 867 | uint32_t state, uint32_t conn_err) | ||
| 868 | { | 862 | { |
| 869 | struct ddb_entry * ddb_entry; | ||
| 870 | uint32_t old_fw_ddb_device_state; | 863 | uint32_t old_fw_ddb_device_state; |
| 871 | int status = QLA_ERROR; | 864 | int status = QLA_ERROR; |
| 872 | 865 | ||
| 873 | /* check for out of range index */ | ||
| 874 | if (fw_ddb_index >= MAX_DDB_ENTRIES) | ||
| 875 | goto exit_ddb_event; | ||
| 876 | |||
| 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) { | ||
| 881 | ql4_printk(KERN_ERR, ha, "%s: No ddb_entry at FW index [%d]\n", | ||
| 882 | __func__, fw_ddb_index); | ||
| 883 | |||
| 884 | if (state == DDB_DS_NO_CONNECTION_ACTIVE) | ||
| 885 | clear_bit(fw_ddb_index, ha->ddb_idx_map); | ||
| 886 | |||
| 887 | goto exit_ddb_event; | ||
| 888 | } | ||
| 889 | |||
| 890 | old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state; | 866 | old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state; |
| 891 | DEBUG2(ql4_printk(KERN_INFO, ha, | 867 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 892 | "%s: DDB - old state = 0x%x, new state = 0x%x for " | 868 | "%s: DDB - old state = 0x%x, new state = 0x%x for " |
| @@ -900,9 +876,7 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index, | |||
| 900 | switch (state) { | 876 | switch (state) { |
| 901 | case DDB_DS_SESSION_ACTIVE: | 877 | case DDB_DS_SESSION_ACTIVE: |
| 902 | case DDB_DS_DISCOVERY: | 878 | case DDB_DS_DISCOVERY: |
| 903 | iscsi_conn_start(ddb_entry->conn); | 879 | ddb_entry->unblock_sess(ddb_entry->sess); |
| 904 | iscsi_conn_login_event(ddb_entry->conn, | ||
| 905 | ISCSI_CONN_STATE_LOGGED_IN); | ||
| 906 | qla4xxx_update_session_conn_param(ha, ddb_entry); | 880 | qla4xxx_update_session_conn_param(ha, ddb_entry); |
| 907 | status = QLA_SUCCESS; | 881 | status = QLA_SUCCESS; |
| 908 | break; | 882 | break; |
| @@ -936,9 +910,7 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index, | |||
| 936 | switch (state) { | 910 | switch (state) { |
| 937 | case DDB_DS_SESSION_ACTIVE: | 911 | case DDB_DS_SESSION_ACTIVE: |
| 938 | case DDB_DS_DISCOVERY: | 912 | case DDB_DS_DISCOVERY: |
| 939 | iscsi_conn_start(ddb_entry->conn); | 913 | ddb_entry->unblock_sess(ddb_entry->sess); |
| 940 | iscsi_conn_login_event(ddb_entry->conn, | ||
| 941 | ISCSI_CONN_STATE_LOGGED_IN); | ||
| 942 | qla4xxx_update_session_conn_param(ha, ddb_entry); | 914 | qla4xxx_update_session_conn_param(ha, ddb_entry); |
| 943 | status = QLA_SUCCESS; | 915 | status = QLA_SUCCESS; |
| 944 | break; | 916 | break; |
| @@ -954,7 +926,198 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index, | |||
| 954 | __func__)); | 926 | __func__)); |
| 955 | break; | 927 | break; |
| 956 | } | 928 | } |
| 929 | return status; | ||
| 930 | } | ||
| 931 | |||
| 932 | void qla4xxx_arm_relogin_timer(struct ddb_entry *ddb_entry) | ||
| 933 | { | ||
| 934 | /* | ||
| 935 | * This triggers a relogin. After the relogin_timer | ||
| 936 | * expires, the relogin gets scheduled. We must wait a | ||
| 937 | * minimum amount of time since receiving an 0x8014 AEN | ||
| 938 | * with failed device_state or a logout response before | ||
| 939 | * we can issue another relogin. | ||
| 940 | * | ||
| 941 | * Firmware pads this timeout: (time2wait +1). | ||
| 942 | * Driver retry to login should be longer than F/W. | ||
| 943 | * Otherwise F/W will fail | ||
| 944 | * set_ddb() mbx cmd with 0x4005 since it still | ||
| 945 | * counting down its time2wait. | ||
| 946 | */ | ||
| 947 | atomic_set(&ddb_entry->relogin_timer, 0); | ||
| 948 | atomic_set(&ddb_entry->retry_relogin_timer, | ||
| 949 | ddb_entry->default_time2wait + 4); | ||
| 950 | |||
| 951 | } | ||
| 952 | |||
| 953 | int qla4xxx_flash_ddb_change(struct scsi_qla_host *ha, uint32_t fw_ddb_index, | ||
| 954 | struct ddb_entry *ddb_entry, uint32_t state) | ||
| 955 | { | ||
| 956 | uint32_t old_fw_ddb_device_state; | ||
| 957 | int status = QLA_ERROR; | ||
| 958 | |||
| 959 | old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state; | ||
| 960 | DEBUG2(ql4_printk(KERN_INFO, ha, | ||
| 961 | "%s: DDB - old state = 0x%x, new state = 0x%x for " | ||
| 962 | "index [%d]\n", __func__, | ||
| 963 | ddb_entry->fw_ddb_device_state, state, fw_ddb_index)); | ||
| 964 | |||
| 965 | ddb_entry->fw_ddb_device_state = state; | ||
| 966 | |||
| 967 | switch (old_fw_ddb_device_state) { | ||
| 968 | case DDB_DS_LOGIN_IN_PROCESS: | ||
| 969 | case DDB_DS_NO_CONNECTION_ACTIVE: | ||
| 970 | switch (state) { | ||
| 971 | case DDB_DS_SESSION_ACTIVE: | ||
| 972 | ddb_entry->unblock_sess(ddb_entry->sess); | ||
| 973 | qla4xxx_update_session_conn_fwddb_param(ha, ddb_entry); | ||
| 974 | status = QLA_SUCCESS; | ||
| 975 | break; | ||
| 976 | case DDB_DS_SESSION_FAILED: | ||
| 977 | iscsi_block_session(ddb_entry->sess); | ||
| 978 | if (!test_bit(DF_RELOGIN, &ddb_entry->flags)) | ||
| 979 | qla4xxx_arm_relogin_timer(ddb_entry); | ||
| 980 | status = QLA_SUCCESS; | ||
| 981 | break; | ||
| 982 | } | ||
| 983 | break; | ||
| 984 | case DDB_DS_SESSION_ACTIVE: | ||
| 985 | switch (state) { | ||
| 986 | case DDB_DS_SESSION_FAILED: | ||
| 987 | iscsi_block_session(ddb_entry->sess); | ||
| 988 | if (!test_bit(DF_RELOGIN, &ddb_entry->flags)) | ||
| 989 | qla4xxx_arm_relogin_timer(ddb_entry); | ||
| 990 | status = QLA_SUCCESS; | ||
| 991 | break; | ||
| 992 | } | ||
| 993 | break; | ||
| 994 | case DDB_DS_SESSION_FAILED: | ||
| 995 | switch (state) { | ||
| 996 | case DDB_DS_SESSION_ACTIVE: | ||
| 997 | ddb_entry->unblock_sess(ddb_entry->sess); | ||
| 998 | qla4xxx_update_session_conn_fwddb_param(ha, ddb_entry); | ||
| 999 | status = QLA_SUCCESS; | ||
| 1000 | break; | ||
| 1001 | case DDB_DS_SESSION_FAILED: | ||
| 1002 | if (!test_bit(DF_RELOGIN, &ddb_entry->flags)) | ||
| 1003 | qla4xxx_arm_relogin_timer(ddb_entry); | ||
| 1004 | status = QLA_SUCCESS; | ||
| 1005 | break; | ||
| 1006 | } | ||
| 1007 | break; | ||
| 1008 | default: | ||
| 1009 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unknown Event\n", | ||
| 1010 | __func__)); | ||
| 1011 | break; | ||
| 1012 | } | ||
| 1013 | return status; | ||
| 1014 | } | ||
| 1015 | |||
| 1016 | /** | ||
| 1017 | * qla4xxx_process_ddb_changed - process ddb state change | ||
| 1018 | * @ha - Pointer to host adapter structure. | ||
| 1019 | * @fw_ddb_index - Firmware's device database index | ||
| 1020 | * @state - Device state | ||
| 1021 | * | ||
| 1022 | * This routine processes a Decive Database Changed AEN Event. | ||
| 1023 | **/ | ||
| 1024 | int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, | ||
| 1025 | uint32_t fw_ddb_index, | ||
| 1026 | uint32_t state, uint32_t conn_err) | ||
| 1027 | { | ||
| 1028 | struct ddb_entry *ddb_entry; | ||
| 1029 | int status = QLA_ERROR; | ||
| 1030 | |||
| 1031 | /* check for out of range index */ | ||
| 1032 | if (fw_ddb_index >= MAX_DDB_ENTRIES) | ||
| 1033 | goto exit_ddb_event; | ||
| 1034 | |||
| 1035 | /* Get the corresponging ddb entry */ | ||
| 1036 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index); | ||
| 1037 | /* Device does not currently exist in our database. */ | ||
| 1038 | if (ddb_entry == NULL) { | ||
| 1039 | ql4_printk(KERN_ERR, ha, "%s: No ddb_entry at FW index [%d]\n", | ||
| 1040 | __func__, fw_ddb_index); | ||
| 1041 | |||
| 1042 | if (state == DDB_DS_NO_CONNECTION_ACTIVE) | ||
| 1043 | clear_bit(fw_ddb_index, ha->ddb_idx_map); | ||
| 1044 | |||
| 1045 | goto exit_ddb_event; | ||
| 1046 | } | ||
| 1047 | |||
| 1048 | ddb_entry->ddb_change(ha, fw_ddb_index, ddb_entry, state); | ||
| 957 | 1049 | ||
| 958 | exit_ddb_event: | 1050 | exit_ddb_event: |
| 959 | return status; | 1051 | return status; |
| 960 | } | 1052 | } |
| 1053 | |||
| 1054 | /** | ||
| 1055 | * qla4xxx_login_flash_ddb - Login to target (DDB) | ||
| 1056 | * @cls_session: Pointer to the session to login | ||
| 1057 | * | ||
| 1058 | * This routine logins to the target. | ||
| 1059 | * Issues setddb and conn open mbx | ||
| 1060 | **/ | ||
| 1061 | void qla4xxx_login_flash_ddb(struct iscsi_cls_session *cls_session) | ||
| 1062 | { | ||
| 1063 | struct iscsi_session *sess; | ||
| 1064 | struct ddb_entry *ddb_entry; | ||
| 1065 | struct scsi_qla_host *ha; | ||
| 1066 | struct dev_db_entry *fw_ddb_entry = NULL; | ||
| 1067 | dma_addr_t fw_ddb_dma; | ||
| 1068 | uint32_t mbx_sts = 0; | ||
| 1069 | int ret; | ||
| 1070 | |||
| 1071 | sess = cls_session->dd_data; | ||
| 1072 | ddb_entry = sess->dd_data; | ||
| 1073 | ha = ddb_entry->ha; | ||
| 1074 | |||
| 1075 | if (!test_bit(AF_LINK_UP, &ha->flags)) | ||
| 1076 | return; | ||
| 1077 | |||
| 1078 | if (ddb_entry->ddb_type != FLASH_DDB) { | ||
| 1079 | DEBUG2(ql4_printk(KERN_INFO, ha, | ||
| 1080 | "Skipping login to non FLASH DB")); | ||
| 1081 | goto exit_login; | ||
| 1082 | } | ||
| 1083 | |||
| 1084 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, | ||
| 1085 | &fw_ddb_dma); | ||
| 1086 | if (fw_ddb_entry == NULL) { | ||
| 1087 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); | ||
| 1088 | goto exit_login; | ||
| 1089 | } | ||
| 1090 | |||
| 1091 | if (ddb_entry->fw_ddb_index == INVALID_ENTRY) { | ||
| 1092 | ret = qla4xxx_get_ddb_index(ha, &ddb_entry->fw_ddb_index); | ||
| 1093 | if (ret == QLA_ERROR) | ||
| 1094 | goto exit_login; | ||
| 1095 | |||
| 1096 | ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry; | ||
| 1097 | ha->tot_ddbs++; | ||
| 1098 | } | ||
| 1099 | |||
| 1100 | memcpy(fw_ddb_entry, &ddb_entry->fw_ddb_entry, | ||
| 1101 | sizeof(struct dev_db_entry)); | ||
| 1102 | ddb_entry->sess->target_id = ddb_entry->fw_ddb_index; | ||
| 1103 | |||
| 1104 | ret = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index, | ||
| 1105 | fw_ddb_dma, &mbx_sts); | ||
| 1106 | if (ret == QLA_ERROR) { | ||
| 1107 | DEBUG2(ql4_printk(KERN_ERR, ha, "Set DDB failed\n")); | ||
| 1108 | goto exit_login; | ||
| 1109 | } | ||
| 1110 | |||
| 1111 | ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS; | ||
| 1112 | ret = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index); | ||
| 1113 | if (ret == QLA_ERROR) { | ||
| 1114 | ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__, | ||
| 1115 | sess->targetname); | ||
| 1116 | goto exit_login; | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | exit_login: | ||
| 1120 | if (fw_ddb_entry) | ||
| 1121 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); | ||
| 1122 | } | ||
| 1123 | |||
