ib_isert.h 3.8 KB

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