mad_priv.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. #define PFX "ib_mad: "
  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 8
  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_mad_queue *mad_queue;
  61. };
  62. struct ib_mad_private_header {
  63. struct ib_mad_list_head mad_list;
  64. struct ib_mad_recv_wc recv_wc;
  65. struct ib_wc wc;
  66. u64 mapping;
  67. } __attribute__ ((packed));
  68. struct ib_mad_private {
  69. struct ib_mad_private_header header;
  70. struct ib_grh grh;
  71. union {
  72. struct ib_mad mad;
  73. struct ib_rmpp_mad rmpp_mad;
  74. struct ib_smp smp;
  75. } mad;
  76. } __attribute__ ((packed));
  77. struct ib_rmpp_segment {
  78. struct list_head list;
  79. u32 num;
  80. u8 data[0];
  81. };
  82. struct ib_mad_agent_private {
  83. struct list_head agent_list;
  84. struct ib_mad_agent agent;
  85. struct ib_mad_reg_req *reg_req;
  86. struct ib_mad_qp_info *qp_info;
  87. spinlock_t lock;
  88. struct list_head send_list;
  89. struct list_head wait_list;
  90. struct list_head done_list;
  91. struct delayed_work timed_work;
  92. unsigned long timeout;
  93. struct list_head local_list;
  94. struct work_struct local_work;
  95. struct list_head rmpp_list;
  96. atomic_t refcount;
  97. struct completion comp;
  98. };
  99. struct ib_mad_snoop_private {
  100. struct ib_mad_agent agent;
  101. struct ib_mad_qp_info *qp_info;
  102. int snoop_index;
  103. int mad_snoop_flags;
  104. atomic_t refcount;
  105. struct completion comp;
  106. };
  107. struct ib_mad_send_wr_private {
  108. struct ib_mad_list_head mad_list;
  109. struct list_head agent_list;
  110. struct ib_mad_agent_private *mad_agent_priv;
  111. struct ib_mad_send_buf send_buf;
  112. u64 header_mapping;
  113. u64 payload_mapping;
  114. struct ib_send_wr send_wr;
  115. struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG];
  116. __be64 tid;
  117. unsigned long timeout;
  118. int max_retries;
  119. int retries_left;
  120. int retry;
  121. int refcount;
  122. enum ib_wc_status status;
  123. /* RMPP control */
  124. struct list_head rmpp_list;
  125. struct ib_rmpp_segment *last_ack_seg;
  126. struct ib_rmpp_segment *cur_seg;
  127. int last_ack;
  128. int seg_num;
  129. int newwin;
  130. int pad;
  131. };
  132. struct ib_mad_local_private {
  133. struct list_head completion_list;
  134. struct ib_mad_private *mad_priv;
  135. struct ib_mad_agent_private *recv_mad_agent;
  136. struct ib_mad_send_wr_private *mad_send_wr;
  137. };
  138. struct ib_mad_mgmt_method_table {
  139. struct ib_mad_agent_private *agent[IB_MGMT_MAX_METHODS];
  140. };
  141. struct ib_mad_mgmt_class_table {
  142. struct ib_mad_mgmt_method_table *method_table[MAX_MGMT_CLASS];
  143. };
  144. struct ib_mad_mgmt_vendor_class {
  145. u8 oui[MAX_MGMT_OUI][3];
  146. struct ib_mad_mgmt_method_table *method_table[MAX_MGMT_OUI];
  147. };
  148. struct ib_mad_mgmt_vendor_class_table {
  149. struct ib_mad_mgmt_vendor_class *vendor_class[MAX_MGMT_VENDOR_RANGE2];
  150. };
  151. struct ib_mad_mgmt_version_table {
  152. struct ib_mad_mgmt_class_table *class;
  153. struct ib_mad_mgmt_vendor_class_table *vendor;
  154. };
  155. struct ib_mad_queue {
  156. spinlock_t lock;
  157. struct list_head list;
  158. int count;
  159. int max_active;
  160. struct ib_mad_qp_info *qp_info;
  161. };
  162. struct ib_mad_qp_info {
  163. struct ib_mad_port_private *port_priv;
  164. struct ib_qp *qp;
  165. struct ib_mad_queue send_queue;
  166. struct ib_mad_queue recv_queue;
  167. struct list_head overflow_list;
  168. spinlock_t snoop_lock;
  169. struct ib_mad_snoop_private **snoop_table;
  170. int snoop_table_size;
  171. atomic_t snoop_count;
  172. };
  173. struct ib_mad_port_private {
  174. struct list_head port_list;
  175. struct ib_device *device;
  176. int port_num;
  177. struct ib_cq *cq;
  178. struct ib_pd *pd;
  179. struct ib_mr *mr;
  180. spinlock_t reg_lock;
  181. struct ib_mad_mgmt_version_table version[MAX_MGMT_VERSION];
  182. struct list_head agent_list;
  183. struct workqueue_struct *wq;
  184. struct work_struct work;
  185. struct ib_mad_qp_info qp_info[IB_MAD_QPS_CORE];
  186. };
  187. int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr);
  188. struct ib_mad_send_wr_private *
  189. ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv,
  190. struct ib_mad_recv_wc *mad_recv_wc);
  191. void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
  192. struct ib_mad_send_wc *mad_send_wc);
  193. void ib_mark_mad_done(struct ib_mad_send_wr_private *mad_send_wr);
  194. void ib_reset_mad_timeout(struct ib_mad_send_wr_private *mad_send_wr,
  195. int timeout_ms);
  196. #endif /* __IB_MAD_PRIV_H__ */