ib_isert.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <rdma/rw.h>
  7. #include <scsi/iser.h>
  8. #define DRV_NAME "isert"
  9. #define PFX DRV_NAME ": "
  10. #define isert_dbg(fmt, arg...) \
  11. do { \
  12. if (unlikely(isert_debug_level > 2)) \
  13. printk(KERN_DEBUG PFX "%s: " fmt,\
  14. __func__ , ## arg); \
  15. } while (0)
  16. #define isert_warn(fmt, arg...) \
  17. do { \
  18. if (unlikely(isert_debug_level > 0)) \
  19. pr_warn(PFX "%s: " fmt, \
  20. __func__ , ## arg); \
  21. } while (0)
  22. #define isert_info(fmt, arg...) \
  23. do { \
  24. if (unlikely(isert_debug_level > 1)) \
  25. pr_info(PFX "%s: " fmt, \
  26. __func__ , ## arg); \
  27. } while (0)
  28. #define isert_err(fmt, arg...) \
  29. pr_err(PFX "%s: " fmt, __func__ , ## arg)
  30. /* Constant PDU lengths calculations */
  31. #define ISER_HEADERS_LEN (sizeof(struct iser_ctrl) + \
  32. sizeof(struct iscsi_hdr))
  33. #define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
  34. /* QP settings */
  35. /* Maximal bounds on received asynchronous PDUs */
  36. #define ISERT_MAX_TX_MISC_PDUS 4 /* NOOP_IN(2) , ASYNC_EVENT(2) */
  37. #define ISERT_MAX_RX_MISC_PDUS 6 /*
  38. * NOOP_OUT(2), TEXT(1),
  39. * SCSI_TMFUNC(2), LOGOUT(1)
  40. */
  41. #define ISCSI_DEF_XMIT_CMDS_MAX 128 /* from libiscsi.h, must be power of 2 */
  42. #define ISERT_QP_MAX_RECV_DTOS (ISCSI_DEF_XMIT_CMDS_MAX)
  43. #define ISERT_MIN_POSTED_RX (ISCSI_DEF_XMIT_CMDS_MAX >> 2)
  44. #define ISERT_QP_MAX_REQ_DTOS (ISCSI_DEF_XMIT_CMDS_MAX + \
  45. ISERT_MAX_TX_MISC_PDUS + \
  46. ISERT_MAX_RX_MISC_PDUS)
  47. #define ISER_RX_PAD_SIZE (ISCSI_DEF_MAX_RECV_SEG_LEN + 4096 - \
  48. (ISER_RX_PAYLOAD_SIZE + sizeof(u64) + sizeof(struct ib_sge) + \
  49. sizeof(struct ib_cqe)))
  50. #define ISCSI_ISER_SG_TABLESIZE 256
  51. enum isert_desc_type {
  52. ISCSI_TX_CONTROL,
  53. ISCSI_TX_DATAIN
  54. };
  55. enum iser_conn_state {
  56. ISER_CONN_INIT,
  57. ISER_CONN_UP,
  58. ISER_CONN_BOUND,
  59. ISER_CONN_FULL_FEATURE,
  60. ISER_CONN_TERMINATING,
  61. ISER_CONN_DOWN,
  62. };
  63. struct iser_rx_desc {
  64. struct iser_ctrl iser_header;
  65. struct iscsi_hdr iscsi_header;
  66. char data[ISCSI_DEF_MAX_RECV_SEG_LEN];
  67. u64 dma_addr;
  68. struct ib_sge rx_sg;
  69. struct ib_cqe rx_cqe;
  70. char pad[ISER_RX_PAD_SIZE];
  71. } __packed;
  72. static inline struct iser_rx_desc *cqe_to_rx_desc(struct ib_cqe *cqe)
  73. {
  74. return container_of(cqe, struct iser_rx_desc, rx_cqe);
  75. }
  76. struct iser_tx_desc {
  77. struct iser_ctrl iser_header;
  78. struct iscsi_hdr iscsi_header;
  79. enum isert_desc_type type;
  80. u64 dma_addr;
  81. struct ib_sge tx_sg[2];
  82. struct ib_cqe tx_cqe;
  83. int num_sge;
  84. struct ib_send_wr send_wr;
  85. } __packed;
  86. static inline struct iser_tx_desc *cqe_to_tx_desc(struct ib_cqe *cqe)
  87. {
  88. return container_of(cqe, struct iser_tx_desc, tx_cqe);
  89. }
  90. struct isert_cmd {
  91. uint32_t read_stag;
  92. uint32_t write_stag;
  93. uint64_t read_va;
  94. uint64_t write_va;
  95. uint32_t inv_rkey;
  96. u64 pdu_buf_dma;
  97. u32 pdu_buf_len;
  98. struct isert_conn *conn;
  99. struct iscsi_cmd *iscsi_cmd;
  100. struct iser_tx_desc tx_desc;
  101. struct iser_rx_desc *rx_desc;
  102. struct rdma_rw_ctx rw;
  103. struct work_struct comp_work;
  104. struct scatterlist sg;
  105. bool ctx_init_done;
  106. };
  107. static inline struct isert_cmd *tx_desc_to_cmd(struct iser_tx_desc *desc)
  108. {
  109. return container_of(desc, struct isert_cmd, tx_desc);
  110. }
  111. struct isert_device;
  112. struct isert_conn {
  113. enum iser_conn_state state;
  114. u32 responder_resources;
  115. u32 initiator_depth;
  116. bool pi_support;
  117. struct iser_rx_desc *login_req_buf;
  118. char *login_rsp_buf;
  119. u64 login_req_dma;
  120. int login_req_len;
  121. u64 login_rsp_dma;
  122. struct iser_rx_desc *rx_descs;
  123. struct ib_recv_wr rx_wr[ISERT_QP_MAX_RECV_DTOS];
  124. struct iscsi_conn *conn;
  125. struct list_head node;
  126. struct completion login_comp;
  127. struct completion login_req_comp;
  128. struct iser_tx_desc login_tx_desc;
  129. struct rdma_cm_id *cm_id;
  130. struct ib_qp *qp;
  131. struct isert_device *device;
  132. struct mutex mutex;
  133. struct kref kref;
  134. struct work_struct release_work;
  135. bool logout_posted;
  136. bool snd_w_inv;
  137. wait_queue_head_t rem_wait;
  138. bool dev_removed;
  139. };
  140. #define ISERT_MAX_CQ 64
  141. /**
  142. * struct isert_comp - iSER completion context
  143. *
  144. * @device: pointer to device handle
  145. * @cq: completion queue
  146. * @active_qps: Number of active QPs attached
  147. * to completion context
  148. */
  149. struct isert_comp {
  150. struct isert_device *device;
  151. struct ib_cq *cq;
  152. int active_qps;
  153. };
  154. struct isert_device {
  155. bool pi_capable;
  156. int refcount;
  157. struct ib_device *ib_device;
  158. struct ib_pd *pd;
  159. struct isert_comp *comps;
  160. int comps_used;
  161. struct list_head dev_node;
  162. };
  163. struct isert_np {
  164. struct iscsi_np *np;
  165. struct semaphore sem;
  166. struct rdma_cm_id *cm_id;
  167. struct mutex mutex;
  168. struct list_head accepted;
  169. struct list_head pending;
  170. };