ib_isert.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. };
  106. static inline struct isert_cmd *tx_desc_to_cmd(struct iser_tx_desc *desc)
  107. {
  108. return container_of(desc, struct isert_cmd, tx_desc);
  109. }
  110. struct isert_device;
  111. struct isert_conn {
  112. enum iser_conn_state state;
  113. u32 responder_resources;
  114. u32 initiator_depth;
  115. bool pi_support;
  116. struct iser_rx_desc *login_req_buf;
  117. char *login_rsp_buf;
  118. u64 login_req_dma;
  119. int login_req_len;
  120. u64 login_rsp_dma;
  121. struct iser_rx_desc *rx_descs;
  122. struct ib_recv_wr rx_wr[ISERT_QP_MAX_RECV_DTOS];
  123. struct iscsi_conn *conn;
  124. struct list_head node;
  125. struct completion login_comp;
  126. struct completion login_req_comp;
  127. struct iser_tx_desc login_tx_desc;
  128. struct rdma_cm_id *cm_id;
  129. struct ib_qp *qp;
  130. struct isert_device *device;
  131. struct mutex mutex;
  132. struct kref kref;
  133. struct work_struct release_work;
  134. bool logout_posted;
  135. bool snd_w_inv;
  136. wait_queue_head_t rem_wait;
  137. bool dev_removed;
  138. };
  139. #define ISERT_MAX_CQ 64
  140. /**
  141. * struct isert_comp - iSER completion context
  142. *
  143. * @device: pointer to device handle
  144. * @cq: completion queue
  145. * @active_qps: Number of active QPs attached
  146. * to completion context
  147. */
  148. struct isert_comp {
  149. struct isert_device *device;
  150. struct ib_cq *cq;
  151. int active_qps;
  152. };
  153. struct isert_device {
  154. bool pi_capable;
  155. int refcount;
  156. struct ib_device *ib_device;
  157. struct ib_pd *pd;
  158. struct isert_comp *comps;
  159. int comps_used;
  160. struct list_head dev_node;
  161. };
  162. struct isert_np {
  163. struct iscsi_np *np;
  164. struct semaphore sem;
  165. struct rdma_cm_id *cm_id;
  166. struct mutex mutex;
  167. struct list_head accepted;
  168. struct list_head pending;
  169. };