iscsi_target_core.h 25 KB

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