ib_isert.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 DRV_NAME "isert"
  7. #define PFX DRV_NAME ": "
  8. #define isert_dbg(fmt, arg...) \
  9. do { \
  10. if (unlikely(isert_debug_level > 2)) \
  11. printk(KERN_DEBUG PFX "%s: " fmt,\
  12. __func__ , ## arg); \
  13. } while (0)
  14. #define isert_warn(fmt, arg...) \
  15. do { \
  16. if (unlikely(isert_debug_level > 0)) \
  17. pr_warn(PFX "%s: " fmt, \
  18. __func__ , ## arg); \
  19. } while (0)
  20. #define isert_info(fmt, arg...) \
  21. do { \
  22. if (unlikely(isert_debug_level > 1)) \
  23. pr_info(PFX "%s: " fmt, \
  24. __func__ , ## arg); \
  25. } while (0)
  26. #define isert_err(fmt, arg...) \
  27. pr_err(PFX "%s: " fmt, __func__ , ## arg)
  28. #define ISERT_RDMA_LISTEN_BACKLOG 10
  29. #define ISCSI_ISER_SG_TABLESIZE 256
  30. #define ISER_FASTREG_LI_WRID 0xffffffffffffffffULL
  31. #define ISER_BEACON_WRID 0xfffffffffffffffeULL
  32. enum isert_desc_type {
  33. ISCSI_TX_CONTROL,
  34. ISCSI_TX_DATAIN
  35. };
  36. enum iser_ib_op_code {
  37. ISER_IB_RECV,
  38. ISER_IB_SEND,
  39. ISER_IB_RDMA_WRITE,
  40. ISER_IB_RDMA_READ,
  41. };
  42. enum iser_conn_state {
  43. ISER_CONN_INIT,
  44. ISER_CONN_UP,
  45. ISER_CONN_FULL_FEATURE,
  46. ISER_CONN_TERMINATING,
  47. ISER_CONN_DOWN,
  48. };
  49. struct iser_rx_desc {
  50. struct iser_hdr iser_header;
  51. struct iscsi_hdr iscsi_header;
  52. char data[ISER_RECV_DATA_SEG_LEN];
  53. u64 dma_addr;
  54. struct ib_sge rx_sg;
  55. char pad[ISER_RX_PAD_SIZE];
  56. } __packed;
  57. struct iser_tx_desc {
  58. struct iser_hdr iser_header;
  59. struct iscsi_hdr iscsi_header;
  60. enum isert_desc_type type;
  61. u64 dma_addr;
  62. struct ib_sge tx_sg[2];
  63. int num_sge;
  64. struct isert_cmd *isert_cmd;
  65. struct ib_send_wr send_wr;
  66. } __packed;
  67. enum isert_indicator {
  68. ISERT_PROTECTED = 1 << 0,
  69. ISERT_DATA_KEY_VALID = 1 << 1,
  70. ISERT_PROT_KEY_VALID = 1 << 2,
  71. ISERT_SIG_KEY_VALID = 1 << 3,
  72. };
  73. struct pi_context {
  74. struct ib_mr *prot_mr;
  75. struct ib_fast_reg_page_list *prot_frpl;
  76. struct ib_mr *sig_mr;
  77. };
  78. struct fast_reg_descriptor {
  79. struct list_head list;
  80. struct ib_mr *data_mr;
  81. struct ib_fast_reg_page_list *data_frpl;
  82. u8 ind;
  83. struct pi_context *pi_ctx;
  84. };
  85. struct isert_data_buf {
  86. struct scatterlist *sg;
  87. int nents;
  88. u32 sg_off;
  89. u32 len; /* cur_rdma_length */
  90. u32 offset;
  91. unsigned int dma_nents;
  92. enum dma_data_direction dma_dir;
  93. };
  94. enum {
  95. DATA = 0,
  96. PROT = 1,
  97. SIG = 2,
  98. };
  99. struct isert_rdma_wr {
  100. struct list_head wr_list;
  101. struct isert_cmd *isert_cmd;
  102. enum iser_ib_op_code iser_ib_op;
  103. struct ib_sge *ib_sge;
  104. struct ib_sge s_ib_sge;
  105. int send_wr_num;
  106. struct ib_send_wr *send_wr;
  107. struct ib_send_wr s_send_wr;
  108. struct ib_sge ib_sg[3];
  109. struct isert_data_buf data;
  110. struct isert_data_buf prot;
  111. struct fast_reg_descriptor *fr_desc;
  112. };
  113. struct isert_cmd {
  114. uint32_t read_stag;
  115. uint32_t write_stag;
  116. uint64_t read_va;
  117. uint64_t write_va;
  118. u64 pdu_buf_dma;
  119. u32 pdu_buf_len;
  120. u32 read_va_off;
  121. u32 write_va_off;
  122. u32 rdma_wr_num;
  123. struct isert_conn *conn;
  124. struct iscsi_cmd *iscsi_cmd;
  125. struct iser_tx_desc tx_desc;
  126. struct isert_rdma_wr rdma_wr;
  127. struct work_struct comp_work;
  128. };
  129. struct isert_device;
  130. struct isert_conn {
  131. enum iser_conn_state state;
  132. int post_recv_buf_count;
  133. u32 responder_resources;
  134. u32 initiator_depth;
  135. bool pi_support;
  136. u32 max_sge;
  137. char *login_buf;
  138. char *login_req_buf;
  139. char *login_rsp_buf;
  140. u64 login_req_dma;
  141. int login_req_len;
  142. u64 login_rsp_dma;
  143. unsigned int conn_rx_desc_head;
  144. struct iser_rx_desc *conn_rx_descs;
  145. struct ib_recv_wr conn_rx_wr[ISERT_MIN_POSTED_RX];
  146. struct iscsi_conn *conn;
  147. struct list_head conn_accept_node;
  148. struct completion conn_login_comp;
  149. struct completion login_req_comp;
  150. struct iser_tx_desc conn_login_tx_desc;
  151. struct rdma_cm_id *conn_cm_id;
  152. struct ib_pd *conn_pd;
  153. struct ib_mr *conn_mr;
  154. struct ib_qp *conn_qp;
  155. struct isert_device *conn_device;
  156. struct mutex conn_mutex;
  157. struct completion conn_wait;
  158. struct completion conn_wait_comp_err;
  159. struct kref conn_kref;
  160. struct list_head conn_fr_pool;
  161. int conn_fr_pool_size;
  162. /* lock to protect fastreg pool */
  163. spinlock_t conn_lock;
  164. struct work_struct release_work;
  165. struct ib_recv_wr beacon;
  166. bool logout_posted;
  167. };
  168. #define ISERT_MAX_CQ 64
  169. /**
  170. * struct isert_comp - iSER completion context
  171. *
  172. * @device: pointer to device handle
  173. * @cq: completion queue
  174. * @wcs: work completion array
  175. * @active_qps: Number of active QPs attached
  176. * to completion context
  177. * @work: completion work handle
  178. */
  179. struct isert_comp {
  180. struct isert_device *device;
  181. struct ib_cq *cq;
  182. struct ib_wc wcs[16];
  183. int active_qps;
  184. struct work_struct work;
  185. };
  186. struct isert_device {
  187. int use_fastreg;
  188. bool pi_capable;
  189. int refcount;
  190. struct ib_device *ib_device;
  191. struct isert_comp *comps;
  192. int comps_used;
  193. struct list_head dev_node;
  194. struct ib_device_attr dev_attr;
  195. int (*reg_rdma_mem)(struct iscsi_conn *conn,
  196. struct iscsi_cmd *cmd,
  197. struct isert_rdma_wr *wr);
  198. void (*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
  199. struct isert_conn *isert_conn);
  200. };
  201. struct isert_np {
  202. struct iscsi_np *np;
  203. struct semaphore np_sem;
  204. struct rdma_cm_id *np_cm_id;
  205. struct mutex np_accept_mutex;
  206. struct list_head np_accept_list;
  207. struct completion np_login_comp;
  208. };