ib_isert.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. #include <scsi/iser.h>
  7. #define DRV_NAME "isert"
  8. #define PFX DRV_NAME ": "
  9. #define isert_dbg(fmt, arg...) \
  10. do { \
  11. if (unlikely(isert_debug_level > 2)) \
  12. printk(KERN_DEBUG PFX "%s: " fmt,\
  13. __func__ , ## arg); \
  14. } while (0)
  15. #define isert_warn(fmt, arg...) \
  16. do { \
  17. if (unlikely(isert_debug_level > 0)) \
  18. pr_warn(PFX "%s: " fmt, \
  19. __func__ , ## arg); \
  20. } while (0)
  21. #define isert_info(fmt, arg...) \
  22. do { \
  23. if (unlikely(isert_debug_level > 1)) \
  24. pr_info(PFX "%s: " fmt, \
  25. __func__ , ## arg); \
  26. } while (0)
  27. #define isert_err(fmt, arg...) \
  28. pr_err(PFX "%s: " fmt, __func__ , ## arg)
  29. /* Constant PDU lengths calculations */
  30. #define ISER_HEADERS_LEN (sizeof(struct iser_ctrl) + \
  31. sizeof(struct iscsi_hdr))
  32. #define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
  33. /* QP settings */
  34. /* Maximal bounds on received asynchronous PDUs */
  35. #define ISERT_MAX_TX_MISC_PDUS 4 /* NOOP_IN(2) , ASYNC_EVENT(2) */
  36. #define ISERT_MAX_RX_MISC_PDUS 6 /*
  37. * NOOP_OUT(2), TEXT(1),
  38. * SCSI_TMFUNC(2), LOGOUT(1)
  39. */
  40. #define ISCSI_DEF_XMIT_CMDS_MAX 128 /* from libiscsi.h, must be power of 2 */
  41. #define ISERT_QP_MAX_RECV_DTOS (ISCSI_DEF_XMIT_CMDS_MAX)
  42. #define ISERT_MIN_POSTED_RX (ISCSI_DEF_XMIT_CMDS_MAX >> 2)
  43. #define ISERT_INFLIGHT_DATAOUTS 8
  44. #define ISERT_QP_MAX_REQ_DTOS (ISCSI_DEF_XMIT_CMDS_MAX * \
  45. (1 + ISERT_INFLIGHT_DATAOUTS) + \
  46. ISERT_MAX_TX_MISC_PDUS + \
  47. ISERT_MAX_RX_MISC_PDUS)
  48. #define ISER_RX_PAD_SIZE (ISCSI_DEF_MAX_RECV_SEG_LEN + 4096 - \
  49. (ISER_RX_PAYLOAD_SIZE + sizeof(u64) + sizeof(struct ib_sge) + \
  50. sizeof(struct ib_cqe)))
  51. #define ISCSI_ISER_SG_TABLESIZE 256
  52. enum isert_desc_type {
  53. ISCSI_TX_CONTROL,
  54. ISCSI_TX_DATAIN
  55. };
  56. enum iser_ib_op_code {
  57. ISER_IB_RECV,
  58. ISER_IB_SEND,
  59. ISER_IB_RDMA_WRITE,
  60. ISER_IB_RDMA_READ,
  61. };
  62. enum iser_conn_state {
  63. ISER_CONN_INIT,
  64. ISER_CONN_UP,
  65. ISER_CONN_BOUND,
  66. ISER_CONN_FULL_FEATURE,
  67. ISER_CONN_TERMINATING,
  68. ISER_CONN_DOWN,
  69. };
  70. struct iser_rx_desc {
  71. struct iser_ctrl iser_header;
  72. struct iscsi_hdr iscsi_header;
  73. char data[ISCSI_DEF_MAX_RECV_SEG_LEN];
  74. u64 dma_addr;
  75. struct ib_sge rx_sg;
  76. struct ib_cqe rx_cqe;
  77. char pad[ISER_RX_PAD_SIZE];
  78. } __packed;
  79. static inline struct iser_rx_desc *cqe_to_rx_desc(struct ib_cqe *cqe)
  80. {
  81. return container_of(cqe, struct iser_rx_desc, rx_cqe);
  82. }
  83. struct iser_tx_desc {
  84. struct iser_ctrl iser_header;
  85. struct iscsi_hdr iscsi_header;
  86. enum isert_desc_type type;
  87. u64 dma_addr;
  88. struct ib_sge tx_sg[2];
  89. struct ib_cqe tx_cqe;
  90. int num_sge;
  91. struct ib_send_wr send_wr;
  92. } __packed;
  93. static inline struct iser_tx_desc *cqe_to_tx_desc(struct ib_cqe *cqe)
  94. {
  95. return container_of(cqe, struct iser_tx_desc, tx_cqe);
  96. }
  97. enum isert_indicator {
  98. ISERT_PROTECTED = 1 << 0,
  99. ISERT_DATA_KEY_VALID = 1 << 1,
  100. ISERT_PROT_KEY_VALID = 1 << 2,
  101. ISERT_SIG_KEY_VALID = 1 << 3,
  102. };
  103. struct pi_context {
  104. struct ib_mr *prot_mr;
  105. struct ib_mr *sig_mr;
  106. };
  107. struct fast_reg_descriptor {
  108. struct list_head list;
  109. struct ib_mr *data_mr;
  110. u8 ind;
  111. struct pi_context *pi_ctx;
  112. };
  113. struct isert_data_buf {
  114. struct scatterlist *sg;
  115. int nents;
  116. u32 sg_off;
  117. u32 len; /* cur_rdma_length */
  118. u32 offset;
  119. unsigned int dma_nents;
  120. enum dma_data_direction dma_dir;
  121. };
  122. enum {
  123. DATA = 0,
  124. PROT = 1,
  125. SIG = 2,
  126. };
  127. struct isert_cmd {
  128. uint32_t read_stag;
  129. uint32_t write_stag;
  130. uint64_t read_va;
  131. uint64_t write_va;
  132. uint32_t inv_rkey;
  133. u64 pdu_buf_dma;
  134. u32 pdu_buf_len;
  135. struct isert_conn *conn;
  136. struct iscsi_cmd *iscsi_cmd;
  137. struct iser_tx_desc tx_desc;
  138. struct iser_rx_desc *rx_desc;
  139. enum iser_ib_op_code iser_ib_op;
  140. struct ib_sge *ib_sge;
  141. struct ib_sge s_ib_sge;
  142. int rdma_wr_num;
  143. struct ib_rdma_wr *rdma_wr;
  144. struct ib_rdma_wr s_rdma_wr;
  145. struct ib_sge ib_sg[3];
  146. struct isert_data_buf data;
  147. struct isert_data_buf prot;
  148. struct fast_reg_descriptor *fr_desc;
  149. struct work_struct comp_work;
  150. struct scatterlist sg;
  151. };
  152. static inline struct isert_cmd *tx_desc_to_cmd(struct iser_tx_desc *desc)
  153. {
  154. return container_of(desc, struct isert_cmd, tx_desc);
  155. }
  156. struct isert_device;
  157. struct isert_conn {
  158. enum iser_conn_state state;
  159. u32 responder_resources;
  160. u32 initiator_depth;
  161. bool pi_support;
  162. u32 max_sge;
  163. struct iser_rx_desc *login_req_buf;
  164. char *login_rsp_buf;
  165. u64 login_req_dma;
  166. int login_req_len;
  167. u64 login_rsp_dma;
  168. struct iser_rx_desc *rx_descs;
  169. struct ib_recv_wr rx_wr[ISERT_QP_MAX_RECV_DTOS];
  170. struct iscsi_conn *conn;
  171. struct list_head node;
  172. struct completion login_comp;
  173. struct completion login_req_comp;
  174. struct iser_tx_desc login_tx_desc;
  175. struct rdma_cm_id *cm_id;
  176. struct ib_qp *qp;
  177. struct isert_device *device;
  178. struct mutex mutex;
  179. struct kref kref;
  180. struct list_head fr_pool;
  181. int fr_pool_size;
  182. /* lock to protect fastreg pool */
  183. spinlock_t pool_lock;
  184. struct work_struct release_work;
  185. bool logout_posted;
  186. bool snd_w_inv;
  187. };
  188. #define ISERT_MAX_CQ 64
  189. /**
  190. * struct isert_comp - iSER completion context
  191. *
  192. * @device: pointer to device handle
  193. * @cq: completion queue
  194. * @active_qps: Number of active QPs attached
  195. * to completion context
  196. */
  197. struct isert_comp {
  198. struct isert_device *device;
  199. struct ib_cq *cq;
  200. int active_qps;
  201. };
  202. struct isert_device {
  203. int use_fastreg;
  204. bool pi_capable;
  205. int refcount;
  206. struct ib_device *ib_device;
  207. struct ib_pd *pd;
  208. struct isert_comp *comps;
  209. int comps_used;
  210. struct list_head dev_node;
  211. int (*reg_rdma_mem)(struct isert_cmd *isert_cmd,
  212. struct iscsi_conn *conn);
  213. void (*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
  214. struct isert_conn *isert_conn);
  215. };
  216. struct isert_np {
  217. struct iscsi_np *np;
  218. struct semaphore sem;
  219. struct rdma_cm_id *cm_id;
  220. struct mutex mutex;
  221. struct list_head accepted;
  222. struct list_head pending;
  223. };