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