mad_priv.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * Copyright (c) 2004, 2005, Voltaire, Inc. All rights reserved.
  3. * Copyright (c) 2005 Intel Corporation. All rights reserved.
  4. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  5. * Copyright (c) 2009 HNR Consulting. All rights reserved.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * OpenIB.org BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  30. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  31. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. */
  35. #ifndef __IB_MAD_PRIV_H__
  36. #define __IB_MAD_PRIV_H__
  37. #include <linux/completion.h>
  38. #include <linux/err.h>
  39. #include <linux/workqueue.h>
  40. #include <rdma/ib_mad.h>
  41. #include <rdma/ib_smi.h>
  42. #include <rdma/opa_smi.h>
  43. #define IB_MAD_QPS_CORE 2 /* Always QP0 and QP1 as a minimum */
  44. /* QP and CQ parameters */
  45. #define IB_MAD_QP_SEND_SIZE 128
  46. #define IB_MAD_QP_RECV_SIZE 512
  47. #define IB_MAD_QP_MIN_SIZE 64
  48. #define IB_MAD_QP_MAX_SIZE 8192
  49. #define IB_MAD_SEND_REQ_MAX_SG 2
  50. #define IB_MAD_RECV_REQ_MAX_SG 1
  51. #define IB_MAD_SEND_Q_PSN 0
  52. /* Registration table sizes */
  53. #define MAX_MGMT_CLASS 80
  54. #define MAX_MGMT_VERSION 0x83
  55. #define MAX_MGMT_OUI 8
  56. #define MAX_MGMT_VENDOR_RANGE2 (IB_MGMT_CLASS_VENDOR_RANGE2_END - \
  57. IB_MGMT_CLASS_VENDOR_RANGE2_START + 1)
  58. struct ib_mad_list_head {
  59. struct list_head list;
  60. struct ib_cqe cqe;
  61. struct ib_mad_queue *mad_queue;
  62. };
  63. struct ib_mad_private_header {
  64. struct ib_mad_list_head mad_list;
  65. struct ib_mad_recv_wc recv_wc;
  66. struct ib_wc wc;
  67. u64 mapping;
  68. } __packed;
  69. struct ib_mad_private {
  70. struct ib_mad_private_header header;
  71. size_t mad_size;
  72. struct ib_grh grh;
  73. u8 mad[];
  74. } __packed;
  75. struct ib_rmpp_segment {
  76. struct list_head list;
  77. u32 num;
  78. u8 data[];
  79. };
  80. struct ib_mad_agent_private {
  81. struct ib_mad_agent agent;
  82. struct ib_mad_reg_req *reg_req;
  83. struct ib_mad_qp_info *qp_info;
  84. spinlock_t lock;
  85. struct list_head send_list;
  86. unsigned int sol_fc_send_count;
  87. struct list_head wait_list;
  88. unsigned int sol_fc_wait_count;
  89. struct delayed_work timed_work;
  90. unsigned long timeout;
  91. struct list_head local_list;
  92. struct work_struct local_work;
  93. struct list_head rmpp_list;
  94. unsigned int sol_fc_max;
  95. struct list_head backlog_list;
  96. refcount_t refcount;
  97. union {
  98. struct completion comp;
  99. struct rcu_head rcu;
  100. };
  101. };
  102. struct ib_mad_snoop_private {
  103. struct ib_mad_agent agent;
  104. struct ib_mad_qp_info *qp_info;
  105. int snoop_index;
  106. int mad_snoop_flags;
  107. struct completion comp;
  108. };
  109. enum ib_mad_state {
  110. /* MAD is in the making and is not yet in any list */
  111. IB_MAD_STATE_INIT,
  112. /* MAD is in backlog list */
  113. IB_MAD_STATE_QUEUED,
  114. /*
  115. * MAD was sent to the QP and is waiting for completion
  116. * notification in send list.
  117. */
  118. IB_MAD_STATE_SEND_START,
  119. /*
  120. * MAD send completed successfully, waiting for a response
  121. * in wait list.
  122. */
  123. IB_MAD_STATE_WAIT_RESP,
  124. /*
  125. * Response came early, before send completion notification,
  126. * in send list.
  127. */
  128. IB_MAD_STATE_EARLY_RESP,
  129. /* MAD was canceled while in wait or send list */
  130. IB_MAD_STATE_CANCELED,
  131. /* MAD processing completed, MAD in no list */
  132. IB_MAD_STATE_DONE
  133. };
  134. struct ib_mad_send_wr_private {
  135. struct ib_mad_list_head mad_list;
  136. struct list_head agent_list;
  137. struct ib_mad_agent_private *mad_agent_priv;
  138. struct ib_mad_send_buf send_buf;
  139. u64 header_mapping;
  140. u64 payload_mapping;
  141. struct ib_ud_wr send_wr;
  142. struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG];
  143. __be64 tid;
  144. unsigned long timeout;
  145. int max_retries;
  146. int retries_left;
  147. int retry;
  148. /* RMPP control */
  149. struct list_head rmpp_list;
  150. struct ib_rmpp_segment *last_ack_seg;
  151. struct ib_rmpp_segment *cur_seg;
  152. int last_ack;
  153. int seg_num;
  154. int newwin;
  155. int pad;
  156. enum ib_mad_state state;
  157. /* Solicited MAD flow control */
  158. bool is_solicited_fc;
  159. };
  160. static inline void expect_mad_state(struct ib_mad_send_wr_private *mad_send_wr,
  161. enum ib_mad_state expected_state)
  162. {
  163. if (IS_ENABLED(CONFIG_LOCKDEP))
  164. WARN_ON(mad_send_wr->state != expected_state);
  165. }
  166. static inline void expect_mad_state2(struct ib_mad_send_wr_private *mad_send_wr,
  167. enum ib_mad_state expected_state1,
  168. enum ib_mad_state expected_state2)
  169. {
  170. if (IS_ENABLED(CONFIG_LOCKDEP))
  171. WARN_ON(mad_send_wr->state != expected_state1 &&
  172. mad_send_wr->state != expected_state2);
  173. }
  174. static inline void expect_mad_state3(struct ib_mad_send_wr_private *mad_send_wr,
  175. enum ib_mad_state expected_state1,
  176. enum ib_mad_state expected_state2,
  177. enum ib_mad_state expected_state3)
  178. {
  179. if (IS_ENABLED(CONFIG_LOCKDEP))
  180. WARN_ON(mad_send_wr->state != expected_state1 &&
  181. mad_send_wr->state != expected_state2 &&
  182. mad_send_wr->state != expected_state3);
  183. }
  184. static inline void
  185. not_expect_mad_state(struct ib_mad_send_wr_private *mad_send_wr,
  186. enum ib_mad_state wrong_state)
  187. {
  188. if (IS_ENABLED(CONFIG_LOCKDEP))
  189. WARN_ON(mad_send_wr->state == wrong_state);
  190. }
  191. struct ib_mad_local_private {
  192. struct list_head completion_list;
  193. struct ib_mad_private *mad_priv;
  194. struct ib_mad_agent_private *recv_mad_agent;
  195. struct ib_mad_send_wr_private *mad_send_wr;
  196. size_t return_wc_byte_len;
  197. };
  198. struct ib_mad_mgmt_method_table {
  199. struct ib_mad_agent_private *agent[IB_MGMT_MAX_METHODS];
  200. };
  201. struct ib_mad_mgmt_class_table {
  202. struct ib_mad_mgmt_method_table *method_table[MAX_MGMT_CLASS];
  203. };
  204. struct ib_mad_mgmt_vendor_class {
  205. u8 oui[MAX_MGMT_OUI][3];
  206. struct ib_mad_mgmt_method_table *method_table[MAX_MGMT_OUI];
  207. };
  208. struct ib_mad_mgmt_vendor_class_table {
  209. struct ib_mad_mgmt_vendor_class *vendor_class[MAX_MGMT_VENDOR_RANGE2];
  210. };
  211. struct ib_mad_mgmt_version_table {
  212. struct ib_mad_mgmt_class_table *class;
  213. struct ib_mad_mgmt_vendor_class_table *vendor;
  214. };
  215. struct ib_mad_queue {
  216. spinlock_t lock;
  217. struct list_head list;
  218. int count;
  219. int max_active;
  220. struct ib_mad_qp_info *qp_info;
  221. };
  222. struct ib_mad_qp_info {
  223. struct ib_mad_port_private *port_priv;
  224. struct ib_qp *qp;
  225. struct ib_mad_queue send_queue;
  226. struct ib_mad_queue recv_queue;
  227. struct list_head overflow_list;
  228. spinlock_t snoop_lock;
  229. struct ib_mad_snoop_private **snoop_table;
  230. int snoop_table_size;
  231. atomic_t snoop_count;
  232. };
  233. struct ib_mad_port_private {
  234. struct list_head port_list;
  235. struct ib_device *device;
  236. int port_num;
  237. struct ib_cq *cq;
  238. struct ib_pd *pd;
  239. spinlock_t reg_lock;
  240. struct ib_mad_mgmt_version_table version[MAX_MGMT_VERSION];
  241. struct workqueue_struct *wq;
  242. struct ib_mad_qp_info qp_info[IB_MAD_QPS_CORE];
  243. };
  244. int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr);
  245. struct ib_mad_send_wr_private *
  246. ib_find_send_mad(const struct ib_mad_agent_private *mad_agent_priv,
  247. const struct ib_mad_recv_wc *mad_recv_wc);
  248. void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
  249. struct ib_mad_send_wc *mad_send_wc);
  250. void ib_mark_mad_done(struct ib_mad_send_wr_private *mad_send_wr);
  251. void ib_reset_mad_timeout(struct ib_mad_send_wr_private *mad_send_wr,
  252. unsigned long timeout_ms);
  253. void change_mad_state(struct ib_mad_send_wr_private *mad_send_wr,
  254. enum ib_mad_state new_state);
  255. #endif /* __IB_MAD_PRIV_H__ */