ib_isert.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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_TERMINATING,
  23. ISER_CONN_DOWN,
  24. };
  25. struct iser_rx_desc {
  26. struct iser_hdr iser_header;
  27. struct iscsi_hdr iscsi_header;
  28. char data[ISER_RECV_DATA_SEG_LEN];
  29. u64 dma_addr;
  30. struct ib_sge rx_sg;
  31. char pad[ISER_RX_PAD_SIZE];
  32. } __packed;
  33. struct iser_tx_desc {
  34. struct iser_hdr iser_header;
  35. struct iscsi_hdr iscsi_header;
  36. enum isert_desc_type type;
  37. u64 dma_addr;
  38. struct ib_sge tx_sg[2];
  39. int num_sge;
  40. struct isert_cmd *isert_cmd;
  41. struct llist_node *comp_llnode_batch;
  42. struct llist_node comp_llnode;
  43. bool llnode_active;
  44. struct ib_send_wr send_wr;
  45. } __packed;
  46. struct fast_reg_descriptor {
  47. struct list_head list;
  48. struct ib_mr *data_mr;
  49. struct ib_fast_reg_page_list *data_frpl;
  50. bool valid;
  51. };
  52. struct isert_rdma_wr {
  53. struct list_head wr_list;
  54. struct isert_cmd *isert_cmd;
  55. enum iser_ib_op_code iser_ib_op;
  56. struct ib_sge *ib_sge;
  57. struct ib_sge s_ib_sge;
  58. int num_sge;
  59. struct scatterlist *sge;
  60. int send_wr_num;
  61. struct ib_send_wr *send_wr;
  62. struct ib_send_wr s_send_wr;
  63. u32 cur_rdma_length;
  64. struct fast_reg_descriptor *fr_desc;
  65. };
  66. struct isert_cmd {
  67. uint32_t read_stag;
  68. uint32_t write_stag;
  69. uint64_t read_va;
  70. uint64_t write_va;
  71. u64 pdu_buf_dma;
  72. u32 pdu_buf_len;
  73. u32 read_va_off;
  74. u32 write_va_off;
  75. u32 rdma_wr_num;
  76. struct isert_conn *conn;
  77. struct iscsi_cmd *iscsi_cmd;
  78. struct iser_tx_desc tx_desc;
  79. struct isert_rdma_wr rdma_wr;
  80. struct work_struct comp_work;
  81. };
  82. struct isert_device;
  83. struct isert_conn {
  84. enum iser_conn_state state;
  85. bool logout_posted;
  86. int post_recv_buf_count;
  87. atomic_t post_send_buf_count;
  88. u32 responder_resources;
  89. u32 initiator_depth;
  90. u32 max_sge;
  91. char *login_buf;
  92. char *login_req_buf;
  93. char *login_rsp_buf;
  94. u64 login_req_dma;
  95. u64 login_rsp_dma;
  96. unsigned int conn_rx_desc_head;
  97. struct iser_rx_desc *conn_rx_descs;
  98. struct ib_recv_wr conn_rx_wr[ISERT_MIN_POSTED_RX];
  99. struct iscsi_conn *conn;
  100. struct list_head conn_accept_node;
  101. struct completion conn_login_comp;
  102. struct iser_tx_desc conn_login_tx_desc;
  103. struct rdma_cm_id *conn_cm_id;
  104. struct ib_pd *conn_pd;
  105. struct ib_mr *conn_mr;
  106. struct ib_qp *conn_qp;
  107. struct isert_device *conn_device;
  108. struct work_struct conn_logout_work;
  109. struct mutex conn_mutex;
  110. struct completion conn_wait;
  111. struct completion conn_wait_comp_err;
  112. struct kref conn_kref;
  113. struct list_head conn_fr_pool;
  114. int conn_fr_pool_size;
  115. /* lock to protect fastreg pool */
  116. spinlock_t conn_lock;
  117. #define ISERT_COMP_BATCH_COUNT 8
  118. int conn_comp_batch;
  119. struct llist_head conn_comp_llist;
  120. };
  121. #define ISERT_MAX_CQ 64
  122. struct isert_cq_desc {
  123. struct isert_device *device;
  124. int cq_index;
  125. struct work_struct cq_rx_work;
  126. struct work_struct cq_tx_work;
  127. };
  128. struct isert_device {
  129. int use_fastreg;
  130. int cqs_used;
  131. int refcount;
  132. int cq_active_qps[ISERT_MAX_CQ];
  133. struct ib_device *ib_device;
  134. struct ib_cq *dev_rx_cq[ISERT_MAX_CQ];
  135. struct ib_cq *dev_tx_cq[ISERT_MAX_CQ];
  136. struct isert_cq_desc *cq_desc;
  137. struct list_head dev_node;
  138. struct ib_device_attr dev_attr;
  139. int (*reg_rdma_mem)(struct iscsi_conn *conn,
  140. struct iscsi_cmd *cmd,
  141. struct isert_rdma_wr *wr);
  142. void (*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
  143. struct isert_conn *isert_conn);
  144. };
  145. struct isert_np {
  146. wait_queue_head_t np_accept_wq;
  147. struct rdma_cm_id *np_cm_id;
  148. struct mutex np_accept_mutex;
  149. struct list_head np_accept_list;
  150. struct completion np_login_comp;
  151. };