GNU Linux-libre 4.19.263-gnu1
[releases.git] / drivers / target / iscsi / iscsi_target_parameters.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef ISCSI_PARAMETERS_H
3 #define ISCSI_PARAMETERS_H
4
5 #include <linux/types.h>
6 #include <scsi/iscsi_proto.h>
7
8 struct iscsi_extra_response {
9         char key[KEY_MAXLEN];
10         char value[32];
11         struct list_head er_list;
12 } ____cacheline_aligned;
13
14 struct iscsi_param {
15         char *name;
16         char *value;
17         u8 set_param;
18         u8 phase;
19         u8 scope;
20         u8 sender;
21         u8 type;
22         u8 use;
23         u16 type_range;
24         u32 state;
25         struct list_head p_list;
26 } ____cacheline_aligned;
27
28 struct iscsi_conn;
29 struct iscsi_conn_ops;
30 struct iscsi_param_list;
31 struct iscsi_sess_ops;
32
33 extern int iscsi_login_rx_data(struct iscsi_conn *, char *, int);
34 extern int iscsi_login_tx_data(struct iscsi_conn *, char *, char *, int);
35 extern void iscsi_dump_conn_ops(struct iscsi_conn_ops *);
36 extern void iscsi_dump_sess_ops(struct iscsi_sess_ops *);
37 extern void iscsi_print_params(struct iscsi_param_list *);
38 extern int iscsi_create_default_params(struct iscsi_param_list **);
39 extern int iscsi_set_keys_to_negotiate(struct iscsi_param_list *, bool);
40 extern int iscsi_set_keys_irrelevant_for_discovery(struct iscsi_param_list *);
41 extern int iscsi_copy_param_list(struct iscsi_param_list **,
42                         struct iscsi_param_list *, int);
43 extern int iscsi_change_param_value(char *, struct iscsi_param_list *, int);
44 extern void iscsi_release_param_list(struct iscsi_param_list *);
45 extern struct iscsi_param *iscsi_find_param_from_key(char *, struct iscsi_param_list *);
46 extern int iscsi_extract_key_value(char *, char **, char **);
47 extern int iscsi_update_param_value(struct iscsi_param *, char *);
48 extern int iscsi_decode_text_input(u8, u8, char *, u32, struct iscsi_conn *);
49 extern int iscsi_encode_text_output(u8, u8, char *, u32 *,
50                         struct iscsi_param_list *, bool);
51 extern int iscsi_check_negotiated_keys(struct iscsi_param_list *);
52 extern void iscsi_set_connection_parameters(struct iscsi_conn_ops *,
53                         struct iscsi_param_list *);
54 extern void iscsi_set_session_parameters(struct iscsi_sess_ops *,
55                         struct iscsi_param_list *, int);
56
57 #define YES                             "Yes"
58 #define NO                              "No"
59 #define ALL                             "All"
60 #define IRRELEVANT                      "Irrelevant"
61 #define NONE                            "None"
62 #define NOTUNDERSTOOD                   "NotUnderstood"
63 #define REJECT                          "Reject"
64
65 /*
66  * The Parameter Names.
67  */
68 #define AUTHMETHOD                      "AuthMethod"
69 #define HEADERDIGEST                    "HeaderDigest"
70 #define DATADIGEST                      "DataDigest"
71 #define MAXCONNECTIONS                  "MaxConnections"
72 #define SENDTARGETS                     "SendTargets"
73 #define TARGETNAME                      "TargetName"
74 #define INITIATORNAME                   "InitiatorName"
75 #define TARGETALIAS                     "TargetAlias"
76 #define INITIATORALIAS                  "InitiatorAlias"
77 #define TARGETADDRESS                   "TargetAddress"
78 #define TARGETPORTALGROUPTAG            "TargetPortalGroupTag"
79 #define INITIALR2T                      "InitialR2T"
80 #define IMMEDIATEDATA                   "ImmediateData"
81 #define MAXRECVDATASEGMENTLENGTH        "MaxRecvDataSegmentLength"
82 #define MAXXMITDATASEGMENTLENGTH        "MaxXmitDataSegmentLength"
83 #define MAXBURSTLENGTH                  "MaxBurstLength"
84 #define FIRSTBURSTLENGTH                "FirstBurstLength"
85 #define DEFAULTTIME2WAIT                "DefaultTime2Wait"
86 #define DEFAULTTIME2RETAIN              "DefaultTime2Retain"
87 #define MAXOUTSTANDINGR2T               "MaxOutstandingR2T"
88 #define DATAPDUINORDER                  "DataPDUInOrder"
89 #define DATASEQUENCEINORDER             "DataSequenceInOrder"
90 #define ERRORRECOVERYLEVEL              "ErrorRecoveryLevel"
91 #define SESSIONTYPE                     "SessionType"
92 #define IFMARKER                        "IFMarker"
93 #define OFMARKER                        "OFMarker"
94 #define IFMARKINT                       "IFMarkInt"
95 #define OFMARKINT                       "OFMarkInt"
96 #define X_EXTENSIONKEY                  "X-com.sbei.version"
97 #define X_EXTENSIONKEY_CISCO_NEW        "X-com.cisco.protocol"
98 #define X_EXTENSIONKEY_CISCO_OLD        "X-com.cisco.iscsi.draft"
99
100 /*
101  * Parameter names of iSCSI Extentions for RDMA (iSER).  See RFC-5046
102  */
103 #define RDMAEXTENSIONS                  "RDMAExtensions"
104 #define INITIATORRECVDATASEGMENTLENGTH  "InitiatorRecvDataSegmentLength"
105 #define TARGETRECVDATASEGMENTLENGTH     "TargetRecvDataSegmentLength"
106
107 /*
108  * For AuthMethod.
109  */
110 #define KRB5                            "KRB5"
111 #define SPKM1                           "SPKM1"
112 #define SPKM2                           "SPKM2"
113 #define SRP                             "SRP"
114 #define CHAP                            "CHAP"
115
116 /*
117  * Initial values for Parameter Negotiation.
118  */
119 #define INITIAL_AUTHMETHOD                      CHAP
120 #define INITIAL_HEADERDIGEST                    "CRC32C,None"
121 #define INITIAL_DATADIGEST                      "CRC32C,None"
122 #define INITIAL_MAXCONNECTIONS                  "1"
123 #define INITIAL_SENDTARGETS                     ALL
124 #define INITIAL_TARGETNAME                      "LIO.Target"
125 #define INITIAL_INITIATORNAME                   "LIO.Initiator"
126 #define INITIAL_TARGETALIAS                     "LIO Target"
127 #define INITIAL_INITIATORALIAS                  "LIO Initiator"
128 #define INITIAL_TARGETADDRESS                   "0.0.0.0:0000,0"
129 #define INITIAL_TARGETPORTALGROUPTAG            "1"
130 #define INITIAL_INITIALR2T                      YES
131 #define INITIAL_IMMEDIATEDATA                   YES
132 #define INITIAL_MAXRECVDATASEGMENTLENGTH        "8192"
133 /*
134  * Match outgoing MXDSL default to incoming Open-iSCSI default
135  */
136 #define INITIAL_MAXXMITDATASEGMENTLENGTH        "262144"
137 #define INITIAL_MAXBURSTLENGTH                  "262144"
138 #define INITIAL_FIRSTBURSTLENGTH                "65536"
139 #define INITIAL_DEFAULTTIME2WAIT                "2"
140 #define INITIAL_DEFAULTTIME2RETAIN              "20"
141 #define INITIAL_MAXOUTSTANDINGR2T               "1"
142 #define INITIAL_DATAPDUINORDER                  YES
143 #define INITIAL_DATASEQUENCEINORDER             YES
144 #define INITIAL_ERRORRECOVERYLEVEL              "0"
145 #define INITIAL_SESSIONTYPE                     NORMAL
146 #define INITIAL_IFMARKER                        NO
147 #define INITIAL_OFMARKER                        NO
148 #define INITIAL_IFMARKINT                       REJECT
149 #define INITIAL_OFMARKINT                       REJECT
150
151 /*
152  * Initial values for iSER parameters following RFC-5046 Section 6
153  */
154 #define INITIAL_RDMAEXTENSIONS                  NO
155 #define INITIAL_INITIATORRECVDATASEGMENTLENGTH  "262144"
156 #define INITIAL_TARGETRECVDATASEGMENTLENGTH     "8192"
157
158 /*
159  * For [Header,Data]Digests.
160  */
161 #define CRC32C                          "CRC32C"
162
163 /*
164  * For SessionType.
165  */
166 #define DISCOVERY                       "Discovery"
167 #define NORMAL                          "Normal"
168
169 /*
170  * struct iscsi_param->use
171  */
172 #define USE_LEADING_ONLY                0x01
173 #define USE_INITIAL_ONLY                0x02
174 #define USE_ALL                         0x04
175
176 #define IS_USE_LEADING_ONLY(p)          ((p)->use & USE_LEADING_ONLY)
177 #define IS_USE_INITIAL_ONLY(p)          ((p)->use & USE_INITIAL_ONLY)
178 #define IS_USE_ALL(p)                   ((p)->use & USE_ALL)
179
180 #define SET_USE_INITIAL_ONLY(p)         ((p)->use |= USE_INITIAL_ONLY)
181
182 /*
183  * struct iscsi_param->sender
184  */
185 #define SENDER_INITIATOR                0x01
186 #define SENDER_TARGET                   0x02
187 #define SENDER_BOTH                     0x03
188 /* Used in iscsi_check_key() */
189 #define SENDER_RECEIVER                 0x04
190
191 #define IS_SENDER_INITIATOR(p)          ((p)->sender & SENDER_INITIATOR)
192 #define IS_SENDER_TARGET(p)             ((p)->sender & SENDER_TARGET)
193 #define IS_SENDER_BOTH(p)               ((p)->sender & SENDER_BOTH)
194
195 /*
196  * struct iscsi_param->scope
197  */
198 #define SCOPE_CONNECTION_ONLY           0x01
199 #define SCOPE_SESSION_WIDE              0x02
200
201 #define IS_SCOPE_CONNECTION_ONLY(p)     ((p)->scope & SCOPE_CONNECTION_ONLY)
202 #define IS_SCOPE_SESSION_WIDE(p)        ((p)->scope & SCOPE_SESSION_WIDE)
203
204 /*
205  * struct iscsi_param->phase
206  */
207 #define PHASE_SECURITY                  0x01
208 #define PHASE_OPERATIONAL               0x02
209 #define PHASE_DECLARATIVE               0x04
210 #define PHASE_FFP0                      0x08
211
212 #define IS_PHASE_SECURITY(p)            ((p)->phase & PHASE_SECURITY)
213 #define IS_PHASE_OPERATIONAL(p)         ((p)->phase & PHASE_OPERATIONAL)
214 #define IS_PHASE_DECLARATIVE(p)         ((p)->phase & PHASE_DECLARATIVE)
215 #define IS_PHASE_FFP0(p)                ((p)->phase & PHASE_FFP0)
216
217 /*
218  * struct iscsi_param->type
219  */
220 #define TYPE_BOOL_AND                   0x01
221 #define TYPE_BOOL_OR                    0x02
222 #define TYPE_NUMBER                     0x04
223 #define TYPE_NUMBER_RANGE               0x08
224 #define TYPE_STRING                     0x10
225 #define TYPE_VALUE_LIST                 0x20
226
227 #define IS_TYPE_BOOL_AND(p)             ((p)->type & TYPE_BOOL_AND)
228 #define IS_TYPE_BOOL_OR(p)              ((p)->type & TYPE_BOOL_OR)
229 #define IS_TYPE_NUMBER(p)               ((p)->type & TYPE_NUMBER)
230 #define IS_TYPE_NUMBER_RANGE(p)         ((p)->type & TYPE_NUMBER_RANGE)
231 #define IS_TYPE_STRING(p)               ((p)->type & TYPE_STRING)
232 #define IS_TYPE_VALUE_LIST(p)           ((p)->type & TYPE_VALUE_LIST)
233
234 /*
235  * struct iscsi_param->type_range
236  */
237 #define TYPERANGE_BOOL_AND              0x0001
238 #define TYPERANGE_BOOL_OR               0x0002
239 #define TYPERANGE_0_TO_2                0x0004
240 #define TYPERANGE_0_TO_3600             0x0008
241 #define TYPERANGE_0_TO_32767            0x0010
242 #define TYPERANGE_0_TO_65535            0x0020
243 #define TYPERANGE_1_TO_65535            0x0040
244 #define TYPERANGE_2_TO_3600             0x0080
245 #define TYPERANGE_512_TO_16777215       0x0100
246 #define TYPERANGE_AUTH                  0x0200
247 #define TYPERANGE_DIGEST                0x0400
248 #define TYPERANGE_ISCSINAME             0x0800
249 #define TYPERANGE_SESSIONTYPE           0x1000
250 #define TYPERANGE_TARGETADDRESS         0x2000
251 #define TYPERANGE_UTF8                  0x4000
252
253 #define IS_TYPERANGE_0_TO_2(p)          ((p)->type_range & TYPERANGE_0_TO_2)
254 #define IS_TYPERANGE_0_TO_3600(p)       ((p)->type_range & TYPERANGE_0_TO_3600)
255 #define IS_TYPERANGE_0_TO_32767(p)      ((p)->type_range & TYPERANGE_0_TO_32767)
256 #define IS_TYPERANGE_0_TO_65535(p)      ((p)->type_range & TYPERANGE_0_TO_65535)
257 #define IS_TYPERANGE_1_TO_65535(p)      ((p)->type_range & TYPERANGE_1_TO_65535)
258 #define IS_TYPERANGE_2_TO_3600(p)       ((p)->type_range & TYPERANGE_2_TO_3600)
259 #define IS_TYPERANGE_512_TO_16777215(p) ((p)->type_range & \
260                                                 TYPERANGE_512_TO_16777215)
261 #define IS_TYPERANGE_AUTH_PARAM(p)      ((p)->type_range & TYPERANGE_AUTH)
262 #define IS_TYPERANGE_DIGEST_PARAM(p)    ((p)->type_range & TYPERANGE_DIGEST)
263 #define IS_TYPERANGE_SESSIONTYPE(p)     ((p)->type_range & \
264                                                 TYPERANGE_SESSIONTYPE)
265
266 /*
267  * struct iscsi_param->state
268  */
269 #define PSTATE_ACCEPTOR                 0x01
270 #define PSTATE_NEGOTIATE                0x02
271 #define PSTATE_PROPOSER                 0x04
272 #define PSTATE_IRRELEVANT               0x08
273 #define PSTATE_REJECT                   0x10
274 #define PSTATE_REPLY_OPTIONAL           0x20
275 #define PSTATE_RESPONSE_GOT             0x40
276 #define PSTATE_RESPONSE_SENT            0x80
277
278 #define IS_PSTATE_ACCEPTOR(p)           ((p)->state & PSTATE_ACCEPTOR)
279 #define IS_PSTATE_NEGOTIATE(p)          ((p)->state & PSTATE_NEGOTIATE)
280 #define IS_PSTATE_PROPOSER(p)           ((p)->state & PSTATE_PROPOSER)
281 #define IS_PSTATE_IRRELEVANT(p)         ((p)->state & PSTATE_IRRELEVANT)
282 #define IS_PSTATE_REJECT(p)             ((p)->state & PSTATE_REJECT)
283 #define IS_PSTATE_REPLY_OPTIONAL(p)     ((p)->state & PSTATE_REPLY_OPTIONAL)
284 #define IS_PSTATE_RESPONSE_GOT(p)       ((p)->state & PSTATE_RESPONSE_GOT)
285 #define IS_PSTATE_RESPONSE_SENT(p)      ((p)->state & PSTATE_RESPONSE_SENT)
286
287 #define SET_PSTATE_ACCEPTOR(p)          ((p)->state |= PSTATE_ACCEPTOR)
288 #define SET_PSTATE_NEGOTIATE(p)         ((p)->state |= PSTATE_NEGOTIATE)
289 #define SET_PSTATE_PROPOSER(p)          ((p)->state |= PSTATE_PROPOSER)
290 #define SET_PSTATE_IRRELEVANT(p)        ((p)->state |= PSTATE_IRRELEVANT)
291 #define SET_PSTATE_REJECT(p)            ((p)->state |= PSTATE_REJECT)
292 #define SET_PSTATE_REPLY_OPTIONAL(p)    ((p)->state |= PSTATE_REPLY_OPTIONAL)
293 #define SET_PSTATE_RESPONSE_GOT(p)      ((p)->state |= PSTATE_RESPONSE_GOT)
294 #define SET_PSTATE_RESPONSE_SENT(p)     ((p)->state |= PSTATE_RESPONSE_SENT)
295
296 #endif /* ISCSI_PARAMETERS_H */