ib_isert.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #include <linux/socket.h>
  2. #include <linux/in.h>
  3. #include <linux/in6.h>
  4. #include <rdma/ib_verbs.h>
  5. #include <rdma/rdma_cm.h>
  6. #define ISERT_RDMA_LISTEN_BACKLOG 10
  7. #define ISCSI_ISER_SG_TABLESIZE 256
  8. #define ISER_FASTREG_LI_WRID 0xffffffffffffffffULL
  9. enum isert_desc_type {
  10. ISCSI_TX_CONTROL,
  11. ISCSI_TX_DATAIN
  12. };
  13. enum iser_ib_op_code {
  14. ISER_IB_RECV,
  15. ISER_IB_SEND,
  16. ISER_IB_RDMA_WRITE,
  17. ISER_IB_RDMA_READ,
  18. };
  19. enum iser_conn_state {
  20. ISER_CONN_INIT,
  21. ISER_CONN_UP,
  22. ISER_CONN_FULL_FEATURE,
  23. ISER_CONN_TERMINATING,
  24. ISER_CONN_DOWN,
  25. };
  26. struct iser_rx_desc {
  27. struct iser_hdr iser_header;
  28. struct iscsi_hdr iscsi_header;
  29. char data[ISER_RECV_DATA_SEG_LEN];
  30. u64 dma_addr;
  31. struct ib_sge rx_sg;
  32. char pad[ISER_RX_PAD_SIZE];
  33. } __packed;
  34. struct iser_tx_desc {
  35. struct iser_hdr iser_header;
  36. struct iscsi_hdr iscsi_header;
  37. enum isert_desc_type type;
  38. u64 dma_addr;
  39. struct ib_sge tx_sg[2];
  40. int num_sge;
  41. struct isert_cmd *isert_cmd;
  42. struct llist_node *comp_llnode_batch;
  43. struct llist_node comp_llnode;
  44. bool llnode_active;
  45. struct ib_send_wr send_wr;
  46. } __packed;
  47. enum isert_indicator {
  48. ISERT_PROTECTED = 1 << 0,
  49. ISERT_DATA_KEY_VALID = 1 << 1,
  50. ISERT_PROT_KEY_VALID = 1 << 2,
  51. ISERT_SIG_KEY_VALID = 1 << 3,
  52. };
  53. struct pi_context {
  54. struct ib_mr *prot_mr;
  55. struct ib_fast_reg_page_list *prot_frpl;
  56. struct ib_mr *sig_mr;
  57. };
  58. struct fast_reg_descriptor {
  59. struct list_head list;
  60. struct ib_mr *data_mr;
  61. struct ib_fast_reg_page_list *data_frpl;
  62. u8 ind;
  63. struct pi_context *pi_ctx;
  64. };
  65. struct isert_data_buf {
  66. struct scatterlist *sg;
  67. int nents;
  68. u32 sg_off;
  69. u32 len; /* cur_rdma_length */
  70. u32 offset;
  71. unsigned int dma_nents;
  72. enum dma_data_direction dma_dir;
  73. };
  74. enum {
  75. DATA = 0,
  76. PROT = 1,
  77. SIG = 2,
  78. };
  79. struct isert_rdma_wr {
  80. struct list_head wr_list;
  81. struct isert_cmd *isert_cmd;
  82. enum iser_ib_op_code iser_ib_op;
  83. struct ib_sge *ib_sge;
  84. struct ib_sge s_ib_sge;
  85. int send_wr_num;
  86. struct ib_send_wr *send_wr;
  87. struct ib_send_wr s_send_wr;
  88. struct ib_sge ib_sg[3];
  89. struct isert_data_buf data;
  90. struct isert_data_buf prot;
  91. struct fast_reg_descriptor *fr_desc;
  92. };
  93. struct isert_cmd {
  94. uint32_t read_stag;
  95. uint32_t write_stag;
  96. uint64_t read_va;
  97. uint64_t write_va;
  98. u64 pdu_buf_dma;
  99. u32 pdu_buf_len;
  100. u32 read_va_off;
  101. u32 write_va_off;
  102. u32 rdma_wr_num;
  103. struct isert_conn *conn;
  104. struct iscsi_cmd *iscsi_cmd;
  105. struct iser_tx_desc tx_desc;
  106. struct isert_rdma_wr rdma_wr;
  107. struct work_struct comp_work;
  108. };
  109. struct isert_device;
  110. struct isert_conn {
  111. enum iser_conn_state state;
  112. int post_recv_buf_count;
  113. atomic_t post_send_buf_count;
  114. u32 responder_resources;
  115. u32 initiator_depth;
  116. bool pi_support;
  117. u32 max_sge;
  118. char *login_buf;
  119. char *login_req_buf;
  120. char *login_rsp_buf;
  121. u64 login_req_dma;
  122. int login_req_len;
  123. u64 login_rsp_dma;
  124. unsigned int conn_rx_desc_head;
  125. struct iser_rx_desc *conn_rx_descs;
  126. struct ib_recv_wr conn_rx_wr[ISERT_MIN_POSTED_RX];
  127. struct iscsi_conn *conn;
  128. struct list_head conn_accept_node;
  129. struct completion conn_login_comp;
  130. struct completion login_req_comp;
  131. struct iser_tx_desc conn_login_tx_desc;
  132. struct rdma_cm_id *conn_cm_id;
  133. struct ib_pd *conn_pd;
  134. struct ib_mr *conn_mr;
  135. struct ib_qp *conn_qp;
  136. struct isert_device *conn_device;
  137. struct mutex conn_mutex;
  138. struct completion conn_wait;
  139. struct completion conn_wait_comp_err;
  140. struct kref conn_kref;
  141. struct list_head conn_fr_pool;
  142. int conn_fr_pool_size;
  143. /* lock to protect fastreg pool */
  144. spinlock_t conn_lock;
  145. struct work_struct release_work;
  146. #define ISERT_COMP_BATCH_COUNT 8
  147. int conn_comp_batch;
  148. struct llist_head conn_comp_llist;
  149. };
  150. #define ISERT_MAX_CQ 64
  151. struct isert_cq_desc {
  152. struct isert_device *device;
  153. int cq_index;
  154. struct work_struct cq_rx_work;
  155. struct work_struct cq_tx_work;
  156. };
  157. struct isert_device {
  158. int use_fastreg;
  159. bool pi_capable;
  160. int cqs_used;
  161. int refcount;
  162. int cq_active_qps[ISERT_MAX_CQ];
  163. struct ib_device *ib_device;
  164. struct ib_cq *dev_rx_cq[ISERT_MAX_CQ];
  165. struct ib_cq *dev_tx_cq[ISERT_MAX_CQ];
  166. struct isert_cq_desc *cq_desc;
  167. struct list_head dev_node;
  168. struct ib_device_attr dev_attr;
  169. int (*reg_rdma_mem)(struct iscsi_conn *conn,
  170. struct iscsi_cmd *cmd,
  171. struct isert_rdma_wr *wr);
  172. void (*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
  173. struct isert_conn *isert_conn);
  174. };
  175. struct isert_np {
  176. struct iscsi_np *np;
  177. struct semaphore np_sem;
  178. struct rdma_cm_id *np_cm_id;
  179. struct mutex np_accept_mutex;
  180. struct list_head np_accept_list;
  181. struct completion np_login_comp;
  182. };