iscsi_target_core.h 26 KB

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