1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /******************************************************************************* 3 * This file contains the main functions related to Initiator Node Attributes. 4 * 5 * (c) Copyright 2007-2013 Datera, Inc. 6 * 7 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> 8 * 9 ******************************************************************************/ 10 11 #include <target/target_core_base.h> 12 13 #include <target/iscsi/iscsi_target_core.h> 14 #include "iscsi_target_device.h" 15 #include "iscsi_target_tpg.h" 16 #include "iscsi_target_util.h" 17 #include "iscsi_target_nodeattrib.h" 18 19 static inline char *iscsit_na_get_initiatorname( 20 struct iscsi_node_acl *nacl) 21 { 22 struct se_node_acl *se_nacl = &nacl->se_node_acl; 23 24 return &se_nacl->initiatorname[0]; 25 } 26 27 void iscsit_set_default_node_attribues( 28 struct iscsi_node_acl *acl, 29 struct iscsi_portal_group *tpg) 30 { 31 struct iscsi_node_attrib *a = &acl->node_attrib; 32 33 a->dataout_timeout = NA_DATAOUT_TIMEOUT; 34 a->dataout_timeout_retries = NA_DATAOUT_TIMEOUT_RETRIES; 35 a->nopin_timeout = NA_NOPIN_TIMEOUT; 36 a->nopin_response_timeout = NA_NOPIN_RESPONSE_TIMEOUT; 37 a->random_datain_pdu_offsets = NA_RANDOM_DATAIN_PDU_OFFSETS; 38 a->random_datain_seq_offsets = NA_RANDOM_DATAIN_SEQ_OFFSETS; 39 a->random_r2t_offsets = NA_RANDOM_R2T_OFFSETS; 40 a->default_erl = tpg->tpg_attrib.default_erl; 41 } 42 43 int iscsit_na_dataout_timeout( 44 struct iscsi_node_acl *acl, 45 u32 dataout_timeout) 46 { 47 struct iscsi_node_attrib *a = &acl->node_attrib; 48 49 if (dataout_timeout > NA_DATAOUT_TIMEOUT_MAX) { 50 pr_err("Requested DataOut Timeout %u larger than" 51 " maximum %u\n", dataout_timeout, 52 NA_DATAOUT_TIMEOUT_MAX); 53 return -EINVAL; 54 } else if (dataout_timeout < NA_DATAOUT_TIMEOUT_MIX) { 55 pr_err("Requested DataOut Timeout %u smaller than" 56 " minimum %u\n", dataout_timeout, 57 NA_DATAOUT_TIMEOUT_MIX); 58 return -EINVAL; 59 } 60 61 a->dataout_timeout = dataout_timeout; 62 pr_debug("Set DataOut Timeout to %u for Initiator Node" 63 " %s\n", a->dataout_timeout, iscsit_na_get_initiatorname(acl)); 64 65 return 0; 66 } 67 68 int iscsit_na_dataout_timeout_retries( 69 struct iscsi_node_acl *acl, 70 u32 dataout_timeout_retries) 71 { 72 struct iscsi_node_attrib *a = &acl->node_attrib; 73 74 if (dataout_timeout_retries > NA_DATAOUT_TIMEOUT_RETRIES_MAX) { 75 pr_err("Requested DataOut Timeout Retries %u larger" 76 " than maximum %u", dataout_timeout_retries, 77 NA_DATAOUT_TIMEOUT_RETRIES_MAX); 78 return -EINVAL; 79 } else if (dataout_timeout_retries < NA_DATAOUT_TIMEOUT_RETRIES_MIN) { 80 pr_err("Requested DataOut Timeout Retries %u smaller" 81 " than minimum %u", dataout_timeout_retries, 82 NA_DATAOUT_TIMEOUT_RETRIES_MIN); 83 return -EINVAL; 84 } 85 86 a->dataout_timeout_retries = dataout_timeout_retries; 87 pr_debug("Set DataOut Timeout Retries to %u for" 88 " Initiator Node %s\n", a->dataout_timeout_retries, 89 iscsit_na_get_initiatorname(acl)); 90 91 return 0; 92 } 93 94 int iscsit_na_nopin_timeout( 95 struct iscsi_node_acl *acl, 96 u32 nopin_timeout) 97 { 98 struct iscsi_node_attrib *a = &acl->node_attrib; 99 struct iscsi_session *sess; 100 struct iscsi_conn *conn; 101 struct se_node_acl *se_nacl = &a->nacl->se_node_acl; 102 struct se_session *se_sess; 103 u32 orig_nopin_timeout = a->nopin_timeout; 104 105 if (nopin_timeout > NA_NOPIN_TIMEOUT_MAX) { 106 pr_err("Requested NopIn Timeout %u larger than maximum" 107 " %u\n", nopin_timeout, NA_NOPIN_TIMEOUT_MAX); 108 return -EINVAL; 109 } else if ((nopin_timeout < NA_NOPIN_TIMEOUT_MIN) && 110 (nopin_timeout != 0)) { 111 pr_err("Requested NopIn Timeout %u smaller than" 112 " minimum %u and not 0\n", nopin_timeout, 113 NA_NOPIN_TIMEOUT_MIN); 114 return -EINVAL; 115 } 116 117 a->nopin_timeout = nopin_timeout; 118 pr_debug("Set NopIn Timeout to %u for Initiator" 119 " Node %s\n", a->nopin_timeout, 120 iscsit_na_get_initiatorname(acl)); 121 /* 122 * Reenable disabled nopin_timeout timer for all iSCSI connections. 123 */ 124 if (!orig_nopin_timeout) { 125 spin_lock_bh(&se_nacl->nacl_sess_lock); 126 se_sess = se_nacl->nacl_sess; 127 if (se_sess) { 128 sess = se_sess->fabric_sess_ptr; 129 130 spin_lock(&sess->conn_lock); 131 list_for_each_entry(conn, &sess->sess_conn_list, 132 conn_list) { 133 if (conn->conn_state != 134 TARG_CONN_STATE_LOGGED_IN) 135 continue; 136 137 spin_lock(&conn->nopin_timer_lock); 138 __iscsit_start_nopin_timer(conn); 139 spin_unlock(&conn->nopin_timer_lock); 140 } 141 spin_unlock(&sess->conn_lock); 142 } 143 spin_unlock_bh(&se_nacl->nacl_sess_lock); 144 } 145 146 return 0; 147 } 148 149 int iscsit_na_nopin_response_timeout( 150 struct iscsi_node_acl *acl, 151 u32 nopin_response_timeout) 152 { 153 struct iscsi_node_attrib *a = &acl->node_attrib; 154 155 if (nopin_response_timeout > NA_NOPIN_RESPONSE_TIMEOUT_MAX) { 156 pr_err("Requested NopIn Response Timeout %u larger" 157 " than maximum %u\n", nopin_response_timeout, 158 NA_NOPIN_RESPONSE_TIMEOUT_MAX); 159 return -EINVAL; 160 } else if (nopin_response_timeout < NA_NOPIN_RESPONSE_TIMEOUT_MIN) { 161 pr_err("Requested NopIn Response Timeout %u smaller" 162 " than minimum %u\n", nopin_response_timeout, 163 NA_NOPIN_RESPONSE_TIMEOUT_MIN); 164 return -EINVAL; 165 } 166 167 a->nopin_response_timeout = nopin_response_timeout; 168 pr_debug("Set NopIn Response Timeout to %u for" 169 " Initiator Node %s\n", a->nopin_timeout, 170 iscsit_na_get_initiatorname(acl)); 171 172 return 0; 173 } 174 175 int iscsit_na_random_datain_pdu_offsets( 176 struct iscsi_node_acl *acl, 177 u32 random_datain_pdu_offsets) 178 { 179 struct iscsi_node_attrib *a = &acl->node_attrib; 180 181 if (random_datain_pdu_offsets != 0 && random_datain_pdu_offsets != 1) { 182 pr_err("Requested Random DataIN PDU Offsets: %u not" 183 " 0 or 1\n", random_datain_pdu_offsets); 184 return -EINVAL; 185 } 186 187 a->random_datain_pdu_offsets = random_datain_pdu_offsets; 188 pr_debug("Set Random DataIN PDU Offsets to %u for" 189 " Initiator Node %s\n", a->random_datain_pdu_offsets, 190 iscsit_na_get_initiatorname(acl)); 191 192 return 0; 193 } 194 195 int iscsit_na_random_datain_seq_offsets( 196 struct iscsi_node_acl *acl, 197 u32 random_datain_seq_offsets) 198 { 199 struct iscsi_node_attrib *a = &acl->node_attrib; 200 201 if (random_datain_seq_offsets != 0 && random_datain_seq_offsets != 1) { 202 pr_err("Requested Random DataIN Sequence Offsets: %u" 203 " not 0 or 1\n", random_datain_seq_offsets); 204 return -EINVAL; 205 } 206 207 a->random_datain_seq_offsets = random_datain_seq_offsets; 208 pr_debug("Set Random DataIN Sequence Offsets to %u for" 209 " Initiator Node %s\n", a->random_datain_seq_offsets, 210 iscsit_na_get_initiatorname(acl)); 211 212 return 0; 213 } 214 215 int iscsit_na_random_r2t_offsets( 216 struct iscsi_node_acl *acl, 217 u32 random_r2t_offsets) 218 { 219 struct iscsi_node_attrib *a = &acl->node_attrib; 220 221 if (random_r2t_offsets != 0 && random_r2t_offsets != 1) { 222 pr_err("Requested Random R2T Offsets: %u not" 223 " 0 or 1\n", random_r2t_offsets); 224 return -EINVAL; 225 } 226 227 a->random_r2t_offsets = random_r2t_offsets; 228 pr_debug("Set Random R2T Offsets to %u for" 229 " Initiator Node %s\n", a->random_r2t_offsets, 230 iscsit_na_get_initiatorname(acl)); 231 232 return 0; 233 } 234 235 int iscsit_na_default_erl( 236 struct iscsi_node_acl *acl, 237 u32 default_erl) 238 { 239 struct iscsi_node_attrib *a = &acl->node_attrib; 240 241 if (default_erl != 0 && default_erl != 1 && default_erl != 2) { 242 pr_err("Requested default ERL: %u not 0, 1, or 2\n", 243 default_erl); 244 return -EINVAL; 245 } 246 247 a->default_erl = default_erl; 248 pr_debug("Set use ERL0 flag to %u for Initiator" 249 " Node %s\n", a->default_erl, 250 iscsit_na_get_initiatorname(acl)); 251 252 return 0; 253 } 254