iscsi_target_core.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef ISCSI_TARGET_CORE_H
  3. #define ISCSI_TARGET_CORE_H
  4. #include <linux/dma-direction.h> /* enum dma_data_direction */
  5. #include <linux/list.h> /* struct list_head */
  6. #include <linux/sched.h>
  7. #include <linux/socket.h> /* struct sockaddr_storage */
  8. #include <linux/types.h> /* u8 */
  9. #include <scsi/iscsi_proto.h> /* itt_t */
  10. #include <target/target_core_base.h> /* struct se_cmd */
  11. struct sock;
  12. #define ISCSIT_VERSION "v4.1.0"
  13. #define ISCSI_MAX_DATASN_MISSING_COUNT 16
  14. #define ISCSI_TX_THREAD_TCP_TIMEOUT 2
  15. #define ISCSI_RX_THREAD_TCP_TIMEOUT 2
  16. #define SECONDS_FOR_ASYNC_LOGOUT 10
  17. #define SECONDS_FOR_ASYNC_TEXT 10
  18. #define SECONDS_FOR_LOGOUT_COMP 15
  19. #define WHITE_SPACE " \t\v\f\n\r"
  20. #define ISCSIT_MIN_TAGS 16
  21. #define ISCSIT_EXTRA_TAGS 8
  22. #define ISCSIT_TCP_BACKLOG 256
  23. #define ISCSI_RX_THREAD_NAME "iscsi_trx"
  24. #define ISCSI_TX_THREAD_NAME "iscsi_ttx"
  25. /* struct iscsi_node_attrib sanity values */
  26. #define NA_DATAOUT_TIMEOUT 3
  27. #define NA_DATAOUT_TIMEOUT_MAX 60
  28. #define NA_DATAOUT_TIMEOUT_MIX 2
  29. #define NA_DATAOUT_TIMEOUT_RETRIES 5
  30. #define NA_DATAOUT_TIMEOUT_RETRIES_MAX 15
  31. #define NA_DATAOUT_TIMEOUT_RETRIES_MIN 1
  32. #define NA_NOPIN_TIMEOUT 15
  33. #define NA_NOPIN_TIMEOUT_MAX 60
  34. #define NA_NOPIN_TIMEOUT_MIN 3
  35. #define NA_NOPIN_RESPONSE_TIMEOUT 30
  36. #define NA_NOPIN_RESPONSE_TIMEOUT_MAX 60
  37. #define NA_NOPIN_RESPONSE_TIMEOUT_MIN 3
  38. #define NA_RANDOM_DATAIN_PDU_OFFSETS 0
  39. #define NA_RANDOM_DATAIN_SEQ_OFFSETS 0
  40. #define NA_RANDOM_R2T_OFFSETS 0
  41. /* struct iscsi_tpg_attrib sanity values */
  42. #define TA_AUTHENTICATION 1
  43. #define TA_LOGIN_TIMEOUT 15
  44. #define TA_LOGIN_TIMEOUT_MAX 30
  45. #define TA_LOGIN_TIMEOUT_MIN 5
  46. #define TA_NETIF_TIMEOUT 2
  47. #define TA_NETIF_TIMEOUT_MAX 15
  48. #define TA_NETIF_TIMEOUT_MIN 2
  49. #define TA_GENERATE_NODE_ACLS 0
  50. #define TA_DEFAULT_CMDSN_DEPTH 64
  51. #define TA_DEFAULT_CMDSN_DEPTH_MAX 512
  52. #define TA_DEFAULT_CMDSN_DEPTH_MIN 1
  53. #define TA_CACHE_DYNAMIC_ACLS 0
  54. /* Enabled by default in demo mode (generic_node_acls=1) */
  55. #define TA_DEMO_MODE_WRITE_PROTECT 1
  56. /* Disabled by default in production mode w/ explict ACLs */
  57. #define TA_PROD_MODE_WRITE_PROTECT 0
  58. #define TA_DEMO_MODE_DISCOVERY 1
  59. #define TA_DEFAULT_ERL 0
  60. #define TA_CACHE_CORE_NPS 0
  61. /* T10 protection information disabled by default */
  62. #define TA_DEFAULT_T10_PI 0
  63. #define TA_DEFAULT_FABRIC_PROT_TYPE 0
  64. /* TPG status needs to be enabled to return sendtargets discovery endpoint info */
  65. #define TA_DEFAULT_TPG_ENABLED_SENDTARGETS 1
  66. /*
  67. * Used to control the sending of keys with optional to respond state bit,
  68. * as a workaround for non RFC compliant initiators,that do not propose,
  69. * nor respond to specific keys required for login to complete.
  70. *
  71. * See iscsi_check_proposer_for_optional_reply() for more details.
  72. */
  73. #define TA_DEFAULT_LOGIN_KEYS_WORKAROUND 1
  74. #define ISCSI_IOV_DATA_BUFFER 5
  75. enum iscsit_transport_type {
  76. ISCSI_TCP = 0,
  77. ISCSI_SCTP_TCP = 1,
  78. ISCSI_SCTP_UDP = 2,
  79. ISCSI_IWARP_TCP = 3,
  80. ISCSI_IWARP_SCTP = 4,
  81. ISCSI_INFINIBAND = 5,
  82. ISCSI_CXGBIT = 6,
  83. };
  84. /* RFC-3720 7.1.4 Standard Connection State Diagram for a Target */
  85. enum target_conn_state_table {
  86. TARG_CONN_STATE_FREE = 0x1,
  87. TARG_CONN_STATE_XPT_UP = 0x3,
  88. TARG_CONN_STATE_IN_LOGIN = 0x4,
  89. TARG_CONN_STATE_LOGGED_IN = 0x5,
  90. TARG_CONN_STATE_IN_LOGOUT = 0x6,
  91. TARG_CONN_STATE_LOGOUT_REQUESTED = 0x7,
  92. TARG_CONN_STATE_CLEANUP_WAIT = 0x8,
  93. };
  94. /* RFC-3720 7.3.2 Session State Diagram for a Target */
  95. enum target_sess_state_table {
  96. TARG_SESS_STATE_FREE = 0x1,
  97. TARG_SESS_STATE_ACTIVE = 0x2,
  98. TARG_SESS_STATE_LOGGED_IN = 0x3,
  99. TARG_SESS_STATE_FAILED = 0x4,
  100. TARG_SESS_STATE_IN_CONTINUE = 0x5,
  101. };
  102. /* struct iscsi_data_count->type */
  103. enum data_count_type {
  104. ISCSI_RX_DATA = 1,
  105. ISCSI_TX_DATA = 2,
  106. };
  107. /* struct iscsi_datain_req->dr_complete */
  108. enum datain_req_comp_table {
  109. DATAIN_COMPLETE_NORMAL = 1,
  110. DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY = 2,
  111. DATAIN_COMPLETE_CONNECTION_RECOVERY = 3,
  112. };
  113. /* struct iscsi_datain_req->recovery */
  114. enum datain_req_rec_table {
  115. DATAIN_WITHIN_COMMAND_RECOVERY = 1,
  116. DATAIN_CONNECTION_RECOVERY = 2,
  117. };
  118. /* struct iscsi_portal_group->state */
  119. enum tpg_state_table {
  120. TPG_STATE_FREE = 0,
  121. TPG_STATE_ACTIVE = 1,
  122. TPG_STATE_INACTIVE = 2,
  123. TPG_STATE_COLD_RESET = 3,
  124. };
  125. /* struct iscsi_tiqn->tiqn_state */
  126. enum tiqn_state_table {
  127. TIQN_STATE_ACTIVE = 1,
  128. TIQN_STATE_SHUTDOWN = 2,
  129. };
  130. /* struct iscsi_cmd->cmd_flags */
  131. enum cmd_flags_table {
  132. ICF_GOT_LAST_DATAOUT = 0x00000001,
  133. ICF_GOT_DATACK_SNACK = 0x00000002,
  134. ICF_NON_IMMEDIATE_UNSOLICITED_DATA = 0x00000004,
  135. ICF_SENT_LAST_R2T = 0x00000008,
  136. ICF_WITHIN_COMMAND_RECOVERY = 0x00000010,
  137. ICF_CONTIG_MEMORY = 0x00000020,
  138. ICF_ATTACHED_TO_RQUEUE = 0x00000040,
  139. ICF_OOO_CMDSN = 0x00000080,
  140. ICF_SENDTARGETS_ALL = 0x00000100,
  141. ICF_SENDTARGETS_SINGLE = 0x00000200,
  142. };
  143. /* struct iscsi_cmd->i_state */
  144. enum cmd_i_state_table {
  145. ISTATE_NO_STATE = 0,
  146. ISTATE_NEW_CMD = 1,
  147. ISTATE_DEFERRED_CMD = 2,
  148. ISTATE_UNSOLICITED_DATA = 3,
  149. ISTATE_RECEIVE_DATAOUT = 4,
  150. ISTATE_RECEIVE_DATAOUT_RECOVERY = 5,
  151. ISTATE_RECEIVED_LAST_DATAOUT = 6,
  152. ISTATE_WITHIN_DATAOUT_RECOVERY = 7,
  153. ISTATE_IN_CONNECTION_RECOVERY = 8,
  154. ISTATE_RECEIVED_TASKMGT = 9,
  155. ISTATE_SEND_ASYNCMSG = 10,
  156. ISTATE_SENT_ASYNCMSG = 11,
  157. ISTATE_SEND_DATAIN = 12,
  158. ISTATE_SEND_LAST_DATAIN = 13,
  159. ISTATE_SENT_LAST_DATAIN = 14,
  160. ISTATE_SEND_LOGOUTRSP = 15,
  161. ISTATE_SENT_LOGOUTRSP = 16,
  162. ISTATE_SEND_NOPIN = 17,
  163. ISTATE_SENT_NOPIN = 18,
  164. ISTATE_SEND_REJECT = 19,
  165. ISTATE_SENT_REJECT = 20,
  166. ISTATE_SEND_R2T = 21,
  167. ISTATE_SENT_R2T = 22,
  168. ISTATE_SEND_R2T_RECOVERY = 23,
  169. ISTATE_SENT_R2T_RECOVERY = 24,
  170. ISTATE_SEND_LAST_R2T = 25,
  171. ISTATE_SENT_LAST_R2T = 26,
  172. ISTATE_SEND_LAST_R2T_RECOVERY = 27,
  173. ISTATE_SENT_LAST_R2T_RECOVERY = 28,
  174. ISTATE_SEND_STATUS = 29,
  175. ISTATE_SEND_STATUS_BROKEN_PC = 30,
  176. ISTATE_SENT_STATUS = 31,
  177. ISTATE_SEND_STATUS_RECOVERY = 32,
  178. ISTATE_SENT_STATUS_RECOVERY = 33,
  179. ISTATE_SEND_TASKMGTRSP = 34,
  180. ISTATE_SENT_TASKMGTRSP = 35,
  181. ISTATE_SEND_TEXTRSP = 36,
  182. ISTATE_SENT_TEXTRSP = 37,
  183. ISTATE_SEND_NOPIN_WANT_RESPONSE = 38,
  184. ISTATE_SENT_NOPIN_WANT_RESPONSE = 39,
  185. ISTATE_SEND_NOPIN_NO_RESPONSE = 40,
  186. ISTATE_REMOVE = 41,
  187. ISTATE_FREE = 42,
  188. };
  189. /* Used for iscsi_recover_cmdsn() return values */
  190. enum recover_cmdsn_ret_table {
  191. CMDSN_ERROR_CANNOT_RECOVER = -1,
  192. CMDSN_NORMAL_OPERATION = 0,
  193. CMDSN_LOWER_THAN_EXP = 1,
  194. CMDSN_HIGHER_THAN_EXP = 2,
  195. CMDSN_MAXCMDSN_OVERRUN = 3,
  196. };
  197. /* Used for iscsi_handle_immediate_data() return values */
  198. enum immedate_data_ret_table {
  199. IMMEDIATE_DATA_CANNOT_RECOVER = -1,
  200. IMMEDIATE_DATA_NORMAL_OPERATION = 0,
  201. IMMEDIATE_DATA_ERL1_CRC_FAILURE = 1,
  202. };
  203. /* Used for iscsi_decide_dataout_action() return values */
  204. enum dataout_action_ret_table {
  205. DATAOUT_CANNOT_RECOVER = -1,
  206. DATAOUT_NORMAL = 0,
  207. DATAOUT_SEND_R2T = 1,
  208. DATAOUT_SEND_TO_TRANSPORT = 2,
  209. DATAOUT_WITHIN_COMMAND_RECOVERY = 3,
  210. };
  211. /* Used for struct iscsi_node_auth->naf_flags */
  212. enum naf_flags_table {
  213. NAF_USERID_SET = 0x01,
  214. NAF_PASSWORD_SET = 0x02,
  215. NAF_USERID_IN_SET = 0x04,
  216. NAF_PASSWORD_IN_SET = 0x08,
  217. };
  218. /* Used by various struct timer_list to manage iSCSI specific state */
  219. enum iscsi_timer_flags_table {
  220. ISCSI_TF_RUNNING = 0x01,
  221. ISCSI_TF_STOP = 0x02,
  222. ISCSI_TF_EXPIRED = 0x04,
  223. };
  224. /* Used for struct iscsi_np->np_flags */
  225. enum np_flags_table {
  226. NPF_IP_NETWORK = 0x00,
  227. };
  228. /* Used for struct iscsi_np->np_thread_state */
  229. enum np_thread_state_table {
  230. ISCSI_NP_THREAD_ACTIVE = 1,
  231. ISCSI_NP_THREAD_INACTIVE = 2,
  232. ISCSI_NP_THREAD_RESET = 3,
  233. ISCSI_NP_THREAD_SHUTDOWN = 4,
  234. ISCSI_NP_THREAD_EXIT = 5,
  235. };
  236. struct iscsi_conn_ops {
  237. u8 HeaderDigest; /* [0,1] == [None,CRC32C] */
  238. u8 DataDigest; /* [0,1] == [None,CRC32C] */
  239. u32 MaxRecvDataSegmentLength; /* [512..2**24-1] */
  240. u32 MaxXmitDataSegmentLength; /* [512..2**24-1] */
  241. /*
  242. * iSER specific connection parameters
  243. */
  244. u32 InitiatorRecvDataSegmentLength; /* [512..2**24-1] */
  245. u32 TargetRecvDataSegmentLength; /* [512..2**24-1] */
  246. };
  247. struct iscsi_sess_ops {
  248. char InitiatorName[224];
  249. char InitiatorAlias[256];
  250. char TargetName[224];
  251. char TargetAlias[256];
  252. char TargetAddress[256];
  253. u16 TargetPortalGroupTag; /* [0..65535] */
  254. u16 MaxConnections; /* [1..65535] */
  255. u8 InitialR2T; /* [0,1] == [No,Yes] */
  256. u8 ImmediateData; /* [0,1] == [No,Yes] */
  257. u32 MaxBurstLength; /* [512..2**24-1] */
  258. u32 FirstBurstLength; /* [512..2**24-1] */
  259. u16 DefaultTime2Wait; /* [0..3600] */
  260. u16 DefaultTime2Retain; /* [0..3600] */
  261. u16 MaxOutstandingR2T; /* [1..65535] */
  262. u8 DataPDUInOrder; /* [0,1] == [No,Yes] */
  263. u8 DataSequenceInOrder; /* [0,1] == [No,Yes] */
  264. u8 ErrorRecoveryLevel; /* [0..2] */
  265. u8 SessionType; /* [0,1] == [Normal,Discovery]*/
  266. /*
  267. * iSER specific session parameters
  268. */
  269. u8 RDMAExtensions; /* [0,1] == [No,Yes] */
  270. };
  271. struct iscsi_queue_req {
  272. int state;
  273. struct iscsi_cmd *cmd;
  274. struct list_head qr_list;
  275. };
  276. struct iscsi_data_count {
  277. int data_length;
  278. int sync_and_steering;
  279. enum data_count_type type;
  280. u32 iov_count;
  281. u32 ss_iov_count;
  282. u32 ss_marker_count;
  283. struct kvec *iov;
  284. };
  285. struct iscsi_param_list {
  286. bool iser;
  287. struct list_head param_list;
  288. struct list_head extra_response_list;
  289. };
  290. struct iscsi_datain_req {
  291. enum datain_req_comp_table dr_complete;
  292. int generate_recovery_values;
  293. enum datain_req_rec_table recovery;
  294. u32 begrun;
  295. u32 runlength;
  296. u32 data_length;
  297. u32 data_offset;
  298. u32 data_sn;
  299. u32 next_burst_len;
  300. u32 read_data_done;
  301. u32 seq_send_order;
  302. struct list_head cmd_datain_node;
  303. } ____cacheline_aligned;
  304. struct iscsi_ooo_cmdsn {
  305. u16 cid;
  306. u32 batch_count;
  307. u32 cmdsn;
  308. u32 exp_cmdsn;
  309. struct iscsi_cmd *cmd;
  310. struct list_head ooo_list;
  311. } ____cacheline_aligned;
  312. struct iscsi_datain {
  313. u8 flags;
  314. u32 data_sn;
  315. u32 length;
  316. u32 offset;
  317. } ____cacheline_aligned;
  318. struct iscsi_r2t {
  319. int seq_complete;
  320. int recovery_r2t;
  321. int sent_r2t;
  322. u32 r2t_sn;
  323. u32 offset;
  324. u32 targ_xfer_tag;
  325. u32 xfer_len;
  326. struct list_head r2t_list;
  327. } ____cacheline_aligned;
  328. struct iscsi_cmd {
  329. enum iscsi_timer_flags_table dataout_timer_flags;
  330. /* DataOUT timeout retries */
  331. u8 dataout_timeout_retries;
  332. /* Within command recovery count */
  333. u8 error_recovery_count;
  334. /* iSCSI dependent state for out or order CmdSNs */
  335. enum cmd_i_state_table deferred_i_state;
  336. /* iSCSI dependent state */
  337. enum cmd_i_state_table i_state;
  338. /* Command is an immediate command (ISCSI_OP_IMMEDIATE set) */
  339. u8 immediate_cmd;
  340. /* Immediate data present */
  341. u8 immediate_data;
  342. /* iSCSI Opcode */
  343. u8 iscsi_opcode;
  344. /* iSCSI Response Code */
  345. u8 iscsi_response;
  346. /* Logout reason when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
  347. u8 logout_reason;
  348. /* Logout response code when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
  349. u8 logout_response;
  350. /* MaxCmdSN has been incremented */
  351. u8 maxcmdsn_inc;
  352. /* Immediate Unsolicited Dataout */
  353. u8 unsolicited_data;
  354. /* Reject reason code */
  355. u8 reject_reason;
  356. /* CID contained in logout PDU when opcode == ISCSI_INIT_LOGOUT_CMND */
  357. u16 logout_cid;
  358. /* Command flags */
  359. enum cmd_flags_table cmd_flags;
  360. /* Initiator Task Tag assigned from Initiator */
  361. itt_t init_task_tag;
  362. /* Target Transfer Tag assigned from Target */
  363. u32 targ_xfer_tag;
  364. /* CmdSN assigned from Initiator */
  365. u32 cmd_sn;
  366. /* ExpStatSN assigned from Initiator */
  367. u32 exp_stat_sn;
  368. /* StatSN assigned to this ITT */
  369. u32 stat_sn;
  370. /* DataSN Counter */
  371. u32 data_sn;
  372. /* R2TSN Counter */
  373. u32 r2t_sn;
  374. /* Last DataSN acknowledged via DataAck SNACK */
  375. u32 acked_data_sn;
  376. /* Used for echoing NOPOUT ping data */
  377. u32 buf_ptr_size;
  378. /* Used to store DataDigest */
  379. u32 data_crc;
  380. /* Counter for MaxOutstandingR2T */
  381. u32 outstanding_r2ts;
  382. /* Next R2T Offset when DataSequenceInOrder=Yes */
  383. u32 r2t_offset;
  384. /* Iovec current and orig count for iscsi_cmd->iov_data */
  385. u32 iov_data_count;
  386. u32 orig_iov_data_count;
  387. /* Number of miscellaneous iovecs used for IP stack calls */
  388. u32 iov_misc_count;
  389. /* Number of struct iscsi_pdu in struct iscsi_cmd->pdu_list */
  390. u32 pdu_count;
  391. /* Next struct iscsi_pdu to send in struct iscsi_cmd->pdu_list */
  392. u32 pdu_send_order;
  393. /* Current struct iscsi_pdu in struct iscsi_cmd->pdu_list */
  394. u32 pdu_start;
  395. /* Next struct iscsi_seq to send in struct iscsi_cmd->seq_list */
  396. u32 seq_send_order;
  397. /* Number of struct iscsi_seq in struct iscsi_cmd->seq_list */
  398. u32 seq_count;
  399. /* Current struct iscsi_seq in struct iscsi_cmd->seq_list */
  400. u32 seq_no;
  401. /* Lowest offset in current DataOUT sequence */
  402. u32 seq_start_offset;
  403. /* Highest offset in current DataOUT sequence */
  404. u32 seq_end_offset;
  405. /* Total size in bytes received so far of READ data */
  406. u32 read_data_done;
  407. /* Total size in bytes received so far of WRITE data */
  408. u32 write_data_done;
  409. /* Counter for FirstBurstLength key */
  410. u32 first_burst_len;
  411. /* Counter for MaxBurstLength key */
  412. u32 next_burst_len;
  413. /* Transfer size used for IP stack calls */
  414. u32 tx_size;
  415. /* Buffer used for various purposes */
  416. void *buf_ptr;
  417. /* Used by SendTargets=[iqn.,eui.] discovery */
  418. void *text_in_ptr;
  419. /* See include/linux/dma-mapping.h */
  420. enum dma_data_direction data_direction;
  421. /* iSCSI PDU Header + CRC */
  422. unsigned char pdu[ISCSI_HDR_LEN + ISCSI_CRC_LEN];
  423. /* Number of times struct iscsi_cmd is present in immediate queue */
  424. atomic_t immed_queue_count;
  425. atomic_t response_queue_count;
  426. spinlock_t datain_lock;
  427. spinlock_t dataout_timeout_lock;
  428. /* spinlock for protecting struct iscsi_cmd->i_state */
  429. spinlock_t istate_lock;
  430. /* spinlock for adding within command recovery entries */
  431. spinlock_t error_lock;
  432. /* spinlock for adding R2Ts */
  433. spinlock_t r2t_lock;
  434. /* DataIN List */
  435. struct list_head datain_list;
  436. /* R2T List */
  437. struct list_head cmd_r2t_list;
  438. /* Timer for DataOUT */
  439. struct timer_list dataout_timer;
  440. /* Iovecs for SCSI data payload RX/TX w/ kernel level sockets */
  441. struct kvec *iov_data;
  442. /* Iovecs for miscellaneous purposes */
  443. #define ISCSI_MISC_IOVECS 5
  444. struct kvec iov_misc[ISCSI_MISC_IOVECS];
  445. /* Array of struct iscsi_pdu used for DataPDUInOrder=No */
  446. struct iscsi_pdu *pdu_list;
  447. /* Current struct iscsi_pdu used for DataPDUInOrder=No */
  448. struct iscsi_pdu *pdu_ptr;
  449. /* Array of struct iscsi_seq used for DataSequenceInOrder=No */
  450. struct iscsi_seq *seq_list;
  451. /* Current struct iscsi_seq used for DataSequenceInOrder=No */
  452. struct iscsi_seq *seq_ptr;
  453. /* TMR Request when iscsi_opcode == ISCSI_OP_SCSI_TMFUNC */
  454. struct iscsi_tmr_req *tmr_req;
  455. /* Connection this command is alligient to */
  456. struct iscsi_conn *conn;
  457. /* Pointer to connection recovery entry */
  458. struct iscsi_conn_recovery *cr;
  459. /* Session the command is part of, used for connection recovery */
  460. struct iscsi_session *sess;
  461. /* list_head for connection list */
  462. struct list_head i_conn_node;
  463. /* The TCM I/O descriptor that is accessed via container_of() */
  464. struct se_cmd se_cmd;
  465. /* Sense buffer that will be mapped into outgoing status */
  466. #define ISCSI_SENSE_BUFFER_LEN (TRANSPORT_SENSE_BUFFER + 2)
  467. unsigned char sense_buffer[ISCSI_SENSE_BUFFER_LEN];
  468. u32 padding;
  469. u8 pad_bytes[4];
  470. struct scatterlist *first_data_sg;
  471. u32 first_data_sg_off;
  472. u32 kmapped_nents;
  473. sense_reason_t sense_reason;
  474. } ____cacheline_aligned;
  475. struct iscsi_tmr_req {
  476. bool task_reassign:1;
  477. u32 exp_data_sn;
  478. struct iscsi_cmd *ref_cmd;
  479. struct iscsi_conn_recovery *conn_recovery;
  480. struct se_tmr_req *se_tmr_req;
  481. };
  482. struct iscsi_conn {
  483. wait_queue_head_t queues_wq;
  484. /* Authentication Successful for this connection */
  485. u8 auth_complete;
  486. /* State connection is currently in */
  487. u8 conn_state;
  488. u8 conn_logout_reason;
  489. u8 network_transport;
  490. enum iscsi_timer_flags_table nopin_timer_flags;
  491. enum iscsi_timer_flags_table nopin_response_timer_flags;
  492. /* Used to know what thread encountered a transport failure */
  493. u8 which_thread;
  494. /* connection id assigned by the Initiator */
  495. u16 cid;
  496. /* Remote TCP Port */
  497. u16 login_port;
  498. int net_size;
  499. int login_family;
  500. u32 auth_id;
  501. u32 conn_flags;
  502. /* Used for iscsi_tx_login_rsp() */
  503. itt_t login_itt;
  504. u32 exp_statsn;
  505. /* Per connection status sequence number */
  506. u32 stat_sn;
  507. struct sockaddr_storage login_sockaddr;
  508. struct sockaddr_storage local_sockaddr;
  509. int conn_usage_count;
  510. int conn_waiting_on_uc;
  511. atomic_t check_immediate_queue;
  512. atomic_t conn_logout_remove;
  513. atomic_t connection_exit;
  514. atomic_t connection_recovery;
  515. atomic_t connection_reinstatement;
  516. atomic_t connection_wait_rcfr;
  517. atomic_t sleep_on_conn_wait_comp;
  518. atomic_t transport_failed;
  519. struct completion conn_post_wait_comp;
  520. struct completion conn_wait_comp;
  521. struct completion conn_wait_rcfr_comp;
  522. struct completion conn_waiting_on_uc_comp;
  523. struct completion conn_logout_comp;
  524. struct completion tx_half_close_comp;
  525. struct completion rx_half_close_comp;
  526. /* socket used by this connection */
  527. struct socket *sock;
  528. void (*orig_data_ready)(struct sock *);
  529. void (*orig_state_change)(struct sock *);
  530. #define LOGIN_FLAGS_READ_ACTIVE 1
  531. #define LOGIN_FLAGS_CLOSED 2
  532. #define LOGIN_FLAGS_READY 4
  533. #define LOGIN_FLAGS_INITIAL_PDU 8
  534. unsigned long login_flags;
  535. struct delayed_work login_work;
  536. struct iscsi_login *login;
  537. struct timer_list nopin_timer;
  538. struct timer_list nopin_response_timer;
  539. struct timer_list transport_timer;
  540. struct task_struct *login_kworker;
  541. /* Spinlock used for add/deleting cmd's from conn_cmd_list */
  542. spinlock_t cmd_lock;
  543. spinlock_t conn_usage_lock;
  544. spinlock_t immed_queue_lock;
  545. spinlock_t nopin_timer_lock;
  546. spinlock_t response_queue_lock;
  547. spinlock_t state_lock;
  548. /* libcrypto RX and TX contexts for crc32c */
  549. struct ahash_request *conn_rx_hash;
  550. struct ahash_request *conn_tx_hash;
  551. /* Used for scheduling TX and RX connection kthreads */
  552. cpumask_var_t conn_cpumask;
  553. unsigned int conn_rx_reset_cpumask:1;
  554. unsigned int conn_tx_reset_cpumask:1;
  555. /* list_head of struct iscsi_cmd for this connection */
  556. struct list_head conn_cmd_list;
  557. struct list_head immed_queue_list;
  558. struct list_head response_queue_list;
  559. struct iscsi_conn_ops *conn_ops;
  560. struct iscsi_login *conn_login;
  561. struct iscsit_transport *conn_transport;
  562. struct iscsi_param_list *param_list;
  563. /* Used for per connection auth state machine */
  564. void *auth_protocol;
  565. void *context;
  566. struct iscsi_login_thread_s *login_thread;
  567. struct iscsi_portal_group *tpg;
  568. struct iscsi_tpg_np *tpg_np;
  569. /* Pointer to parent session */
  570. struct iscsi_session *sess;
  571. int bitmap_id;
  572. int rx_thread_active;
  573. struct task_struct *rx_thread;
  574. struct completion rx_login_comp;
  575. int tx_thread_active;
  576. struct task_struct *tx_thread;
  577. /* list_head for session connection list */
  578. struct list_head conn_list;
  579. } ____cacheline_aligned;
  580. struct iscsi_conn_recovery {
  581. u16 cid;
  582. u32 cmd_count;
  583. u32 maxrecvdatasegmentlength;
  584. u32 maxxmitdatasegmentlength;
  585. int ready_for_reallegiance;
  586. struct list_head conn_recovery_cmd_list;
  587. spinlock_t conn_recovery_cmd_lock;
  588. struct timer_list time2retain_timer;
  589. struct iscsi_session *sess;
  590. struct list_head cr_list;
  591. } ____cacheline_aligned;
  592. struct iscsi_session {
  593. u8 initiator_vendor;
  594. u8 isid[6];
  595. enum iscsi_timer_flags_table time2retain_timer_flags;
  596. u8 version_active;
  597. u16 cid_called;
  598. u16 conn_recovery_count;
  599. u16 tsih;
  600. /* state session is currently in */
  601. u32 session_state;
  602. /* session wide counter: initiator assigned task tag */
  603. itt_t init_task_tag;
  604. /* session wide counter: target assigned task tag */
  605. u32 targ_xfer_tag;
  606. u32 cmdsn_window;
  607. /* protects cmdsn values */
  608. struct mutex cmdsn_mutex;
  609. /* session wide counter: expected command sequence number */
  610. u32 exp_cmd_sn;
  611. /* session wide counter: maximum allowed command sequence number */
  612. atomic_t max_cmd_sn;
  613. struct list_head sess_ooo_cmdsn_list;
  614. /* LIO specific session ID */
  615. u32 sid;
  616. char auth_type[8];
  617. /* unique within the target */
  618. int session_index;
  619. /* Used for session reference counting */
  620. int session_usage_count;
  621. int session_waiting_on_uc;
  622. atomic_long_t cmd_pdus;
  623. atomic_long_t rsp_pdus;
  624. atomic_long_t tx_data_octets;
  625. atomic_long_t rx_data_octets;
  626. atomic_long_t conn_digest_errors;
  627. atomic_long_t conn_timeout_errors;
  628. u64 creation_time;
  629. /* Number of active connections */
  630. atomic_t nconn;
  631. atomic_t session_continuation;
  632. atomic_t session_fall_back_to_erl0;
  633. atomic_t session_logout;
  634. atomic_t session_reinstatement;
  635. atomic_t session_stop_active;
  636. atomic_t sleep_on_sess_wait_comp;
  637. /* connection list */
  638. struct list_head sess_conn_list;
  639. struct list_head cr_active_list;
  640. struct list_head cr_inactive_list;
  641. spinlock_t conn_lock;
  642. spinlock_t cr_a_lock;
  643. spinlock_t cr_i_lock;
  644. spinlock_t session_usage_lock;
  645. spinlock_t ttt_lock;
  646. struct completion async_msg_comp;
  647. struct completion reinstatement_comp;
  648. struct completion session_wait_comp;
  649. struct completion session_waiting_on_uc_comp;
  650. struct timer_list time2retain_timer;
  651. struct iscsi_sess_ops *sess_ops;
  652. struct se_session *se_sess;
  653. struct iscsi_portal_group *tpg;
  654. } ____cacheline_aligned;
  655. struct iscsi_login {
  656. u8 auth_complete;
  657. u8 checked_for_existing;
  658. u8 current_stage;
  659. u8 leading_connection;
  660. u8 first_request;
  661. u8 version_min;
  662. u8 version_max;
  663. u8 login_complete;
  664. u8 login_failed;
  665. bool zero_tsih;
  666. char isid[6];
  667. u32 cmd_sn;
  668. itt_t init_task_tag;
  669. u32 initial_exp_statsn;
  670. u32 rsp_length;
  671. u16 cid;
  672. u16 tsih;
  673. char req[ISCSI_HDR_LEN];
  674. char rsp[ISCSI_HDR_LEN];
  675. char *req_buf;
  676. char *rsp_buf;
  677. struct iscsi_conn *conn;
  678. struct iscsi_np *np;
  679. } ____cacheline_aligned;
  680. struct iscsi_node_attrib {
  681. u32 dataout_timeout;
  682. u32 dataout_timeout_retries;
  683. u32 default_erl;
  684. u32 nopin_timeout;
  685. u32 nopin_response_timeout;
  686. u32 random_datain_pdu_offsets;
  687. u32 random_datain_seq_offsets;
  688. u32 random_r2t_offsets;
  689. u32 tmr_cold_reset;
  690. u32 tmr_warm_reset;
  691. struct iscsi_node_acl *nacl;
  692. };
  693. struct se_dev_entry_s;
  694. struct iscsi_node_auth {
  695. enum naf_flags_table naf_flags;
  696. int authenticate_target;
  697. /* Used for iscsit_global->discovery_auth,
  698. * set to zero (auth disabled) by default */
  699. int enforce_discovery_auth;
  700. #define MAX_USER_LEN 256
  701. #define MAX_PASS_LEN 256
  702. char userid[MAX_USER_LEN];
  703. char password[MAX_PASS_LEN];
  704. char userid_mutual[MAX_USER_LEN];
  705. char password_mutual[MAX_PASS_LEN];
  706. };
  707. #include "iscsi_target_stat.h"
  708. struct iscsi_node_stat_grps {
  709. struct config_group iscsi_sess_stats_group;
  710. struct config_group iscsi_conn_stats_group;
  711. };
  712. struct iscsi_node_acl {
  713. struct se_node_acl se_node_acl;
  714. struct iscsi_node_attrib node_attrib;
  715. struct iscsi_node_auth node_auth;
  716. struct iscsi_node_stat_grps node_stat_grps;
  717. };
  718. struct iscsi_tpg_attrib {
  719. u32 authentication;
  720. u32 login_timeout;
  721. u32 netif_timeout;
  722. u32 generate_node_acls;
  723. u32 cache_dynamic_acls;
  724. u32 default_cmdsn_depth;
  725. u32 demo_mode_write_protect;
  726. u32 prod_mode_write_protect;
  727. u32 demo_mode_discovery;
  728. u32 default_erl;
  729. u8 t10_pi;
  730. u32 fabric_prot_type;
  731. u32 tpg_enabled_sendtargets;
  732. u32 login_keys_workaround;
  733. struct iscsi_portal_group *tpg;
  734. };
  735. struct iscsi_np {
  736. int np_network_transport;
  737. int np_ip_proto;
  738. int np_sock_type;
  739. enum np_thread_state_table np_thread_state;
  740. bool enabled;
  741. atomic_t np_reset_count;
  742. enum iscsi_timer_flags_table np_login_timer_flags;
  743. u32 np_exports;
  744. enum np_flags_table np_flags;
  745. spinlock_t np_thread_lock;
  746. struct completion np_restart_comp;
  747. struct socket *np_socket;
  748. struct sockaddr_storage np_sockaddr;
  749. struct task_struct *np_thread;
  750. struct timer_list np_login_timer;
  751. void *np_context;
  752. struct iscsit_transport *np_transport;
  753. struct list_head np_list;
  754. } ____cacheline_aligned;
  755. struct iscsi_tpg_np {
  756. struct iscsi_np *tpg_np;
  757. struct iscsi_portal_group *tpg;
  758. struct iscsi_tpg_np *tpg_np_parent;
  759. struct list_head tpg_np_list;
  760. struct list_head tpg_np_child_list;
  761. struct list_head tpg_np_parent_list;
  762. struct se_tpg_np se_tpg_np;
  763. spinlock_t tpg_np_parent_lock;
  764. struct completion tpg_np_comp;
  765. struct kref tpg_np_kref;
  766. };
  767. struct iscsi_portal_group {
  768. unsigned char tpg_chap_id;
  769. /* TPG State */
  770. enum tpg_state_table tpg_state;
  771. /* Target Portal Group Tag */
  772. u16 tpgt;
  773. /* Id assigned to target sessions */
  774. u16 ntsih;
  775. /* Number of active sessions */
  776. u32 nsessions;
  777. /* Number of Network Portals available for this TPG */
  778. u32 num_tpg_nps;
  779. /* Per TPG LIO specific session ID. */
  780. u32 sid;
  781. /* Spinlock for adding/removing Network Portals */
  782. spinlock_t tpg_np_lock;
  783. spinlock_t tpg_state_lock;
  784. struct se_portal_group tpg_se_tpg;
  785. struct mutex tpg_access_lock;
  786. struct semaphore np_login_sem;
  787. struct iscsi_tpg_attrib tpg_attrib;
  788. struct iscsi_node_auth tpg_demo_auth;
  789. /* Pointer to default list of iSCSI parameters for TPG */
  790. struct iscsi_param_list *param_list;
  791. struct iscsi_tiqn *tpg_tiqn;
  792. struct list_head tpg_gnp_list;
  793. struct list_head tpg_list;
  794. } ____cacheline_aligned;
  795. struct iscsi_wwn_stat_grps {
  796. struct config_group iscsi_stat_group;
  797. struct config_group iscsi_instance_group;
  798. struct config_group iscsi_sess_err_group;
  799. struct config_group iscsi_tgt_attr_group;
  800. struct config_group iscsi_login_stats_group;
  801. struct config_group iscsi_logout_stats_group;
  802. };
  803. struct iscsi_tiqn {
  804. #define ISCSI_IQN_LEN 224
  805. unsigned char tiqn[ISCSI_IQN_LEN];
  806. enum tiqn_state_table tiqn_state;
  807. int tiqn_access_count;
  808. u32 tiqn_active_tpgs;
  809. u32 tiqn_ntpgs;
  810. u32 tiqn_num_tpg_nps;
  811. u32 tiqn_nsessions;
  812. struct list_head tiqn_list;
  813. struct list_head tiqn_tpg_list;
  814. spinlock_t tiqn_state_lock;
  815. spinlock_t tiqn_tpg_lock;
  816. struct se_wwn tiqn_wwn;
  817. struct iscsi_wwn_stat_grps tiqn_stat_grps;
  818. int tiqn_index;
  819. struct iscsi_sess_err_stats sess_err_stats;
  820. struct iscsi_login_stats login_stats;
  821. struct iscsi_logout_stats logout_stats;
  822. } ____cacheline_aligned;
  823. struct iscsit_global {
  824. /* In core shutdown */
  825. u32 in_shutdown;
  826. u32 active_ts;
  827. /* Unique identifier used for the authentication daemon */
  828. u32 auth_id;
  829. u32 inactive_ts;
  830. #define ISCSIT_BITMAP_BITS 262144
  831. /* Thread Set bitmap pointer */
  832. unsigned long *ts_bitmap;
  833. spinlock_t ts_bitmap_lock;
  834. /* Used for iSCSI discovery session authentication */
  835. struct iscsi_node_acl discovery_acl;
  836. struct iscsi_portal_group *discovery_tpg;
  837. };
  838. static inline u32 session_get_next_ttt(struct iscsi_session *session)
  839. {
  840. u32 ttt;
  841. spin_lock_bh(&session->ttt_lock);
  842. ttt = session->targ_xfer_tag++;
  843. if (ttt == 0xFFFFFFFF)
  844. ttt = session->targ_xfer_tag++;
  845. spin_unlock_bh(&session->ttt_lock);
  846. return ttt;
  847. }
  848. extern struct iscsi_cmd *iscsit_find_cmd_from_itt(struct iscsi_conn *, itt_t);
  849. static inline void iscsit_thread_check_cpumask(
  850. struct iscsi_conn *conn,
  851. struct task_struct *p,
  852. int mode)
  853. {
  854. /*
  855. * mode == 1 signals iscsi_target_tx_thread() usage.
  856. * mode == 0 signals iscsi_target_rx_thread() usage.
  857. */
  858. if (mode == 1) {
  859. if (!conn->conn_tx_reset_cpumask)
  860. return;
  861. conn->conn_tx_reset_cpumask = 0;
  862. } else {
  863. if (!conn->conn_rx_reset_cpumask)
  864. return;
  865. conn->conn_rx_reset_cpumask = 0;
  866. }
  867. /*
  868. * Update the CPU mask for this single kthread so that
  869. * both TX and RX kthreads are scheduled to run on the
  870. * same CPU.
  871. */
  872. set_cpus_allowed_ptr(p, conn->conn_cpumask);
  873. }
  874. #endif /* ISCSI_TARGET_CORE_H */