ib_isert.h 4.7 KB

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