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