1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*******************************************************************************
3 * This file contains the main functions related to Initiator Node Attributes.
5 * (c) Copyright 2007-2013 Datera, Inc.
7 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
9 ******************************************************************************/
11 #include <target/target_core_base.h>
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"
19 static inline char *iscsit_na_get_initiatorname(
20 struct iscsi_node_acl
*nacl
)
22 struct se_node_acl
*se_nacl
= &nacl
->se_node_acl
;
24 return &se_nacl
->initiatorname
[0];
27 void iscsit_set_default_node_attribues(
28 struct iscsi_node_acl
*acl
,
29 struct iscsi_portal_group
*tpg
)
31 struct iscsi_node_attrib
*a
= &acl
->node_attrib
;
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
;
43 int iscsit_na_dataout_timeout(
44 struct iscsi_node_acl
*acl
,
47 struct iscsi_node_attrib
*a
= &acl
->node_attrib
;
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
);
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
);
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
));
68 int iscsit_na_dataout_timeout_retries(
69 struct iscsi_node_acl
*acl
,
70 u32 dataout_timeout_retries
)
72 struct iscsi_node_attrib
*a
= &acl
->node_attrib
;
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
);
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
);
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
));
94 int iscsit_na_nopin_timeout(
95 struct iscsi_node_acl
*acl
,
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
;
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
);
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
);
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
));
122 * Reenable disabled nopin_timeout timer for all iSCSI connections.
124 if (!orig_nopin_timeout
) {
125 spin_lock_bh(&se_nacl
->nacl_sess_lock
);
126 se_sess
= se_nacl
->nacl_sess
;
128 sess
= se_sess
->fabric_sess_ptr
;
130 spin_lock(&sess
->conn_lock
);
131 list_for_each_entry(conn
, &sess
->sess_conn_list
,
133 if (conn
->conn_state
!=
134 TARG_CONN_STATE_LOGGED_IN
)
137 spin_lock(&conn
->nopin_timer_lock
);
138 __iscsit_start_nopin_timer(conn
);
139 spin_unlock(&conn
->nopin_timer_lock
);
141 spin_unlock(&sess
->conn_lock
);
143 spin_unlock_bh(&se_nacl
->nacl_sess_lock
);
149 int iscsit_na_nopin_response_timeout(
150 struct iscsi_node_acl
*acl
,
151 u32 nopin_response_timeout
)
153 struct iscsi_node_attrib
*a
= &acl
->node_attrib
;
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
);
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
);
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
));
175 int iscsit_na_random_datain_pdu_offsets(
176 struct iscsi_node_acl
*acl
,
177 u32 random_datain_pdu_offsets
)
179 struct iscsi_node_attrib
*a
= &acl
->node_attrib
;
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
);
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
));
195 int iscsit_na_random_datain_seq_offsets(
196 struct iscsi_node_acl
*acl
,
197 u32 random_datain_seq_offsets
)
199 struct iscsi_node_attrib
*a
= &acl
->node_attrib
;
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
);
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
));
215 int iscsit_na_random_r2t_offsets(
216 struct iscsi_node_acl
*acl
,
217 u32 random_r2t_offsets
)
219 struct iscsi_node_attrib
*a
= &acl
->node_attrib
;
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
);
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
));
235 int iscsit_na_default_erl(
236 struct iscsi_node_acl
*acl
,
239 struct iscsi_node_attrib
*a
= &acl
->node_attrib
;
241 if (default_erl
!= 0 && default_erl
!= 1 && default_erl
!= 2) {
242 pr_err("Requested default ERL: %u not 0, 1, or 2\n",
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
));