ib_sa.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * Copyright (c) 2004 Topspin Communications. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. * $Id: ib_sa.h 1389 2004-12-27 22:56:47Z roland $
  33. */
  34. #ifndef IB_SA_H
  35. #define IB_SA_H
  36. #include <linux/compiler.h>
  37. #include <ib_verbs.h>
  38. #include <ib_mad.h>
  39. enum {
  40. IB_SA_CLASS_VERSION = 2, /* IB spec version 1.1/1.2 */
  41. IB_SA_METHOD_DELETE = 0x15
  42. };
  43. enum ib_sa_selector {
  44. IB_SA_GTE = 0,
  45. IB_SA_LTE = 1,
  46. IB_SA_EQ = 2,
  47. /*
  48. * The meaning of "best" depends on the attribute: for
  49. * example, for MTU best will return the largest available
  50. * MTU, while for packet life time, best will return the
  51. * smallest available life time.
  52. */
  53. IB_SA_BEST = 3
  54. };
  55. enum ib_sa_rate {
  56. IB_SA_RATE_2_5_GBPS = 2,
  57. IB_SA_RATE_5_GBPS = 5,
  58. IB_SA_RATE_10_GBPS = 3,
  59. IB_SA_RATE_20_GBPS = 6,
  60. IB_SA_RATE_30_GBPS = 4,
  61. IB_SA_RATE_40_GBPS = 7,
  62. IB_SA_RATE_60_GBPS = 8,
  63. IB_SA_RATE_80_GBPS = 9,
  64. IB_SA_RATE_120_GBPS = 10
  65. };
  66. static inline int ib_sa_rate_enum_to_int(enum ib_sa_rate rate)
  67. {
  68. switch (rate) {
  69. case IB_SA_RATE_2_5_GBPS: return 1;
  70. case IB_SA_RATE_5_GBPS: return 2;
  71. case IB_SA_RATE_10_GBPS: return 4;
  72. case IB_SA_RATE_20_GBPS: return 8;
  73. case IB_SA_RATE_30_GBPS: return 12;
  74. case IB_SA_RATE_40_GBPS: return 16;
  75. case IB_SA_RATE_60_GBPS: return 24;
  76. case IB_SA_RATE_80_GBPS: return 32;
  77. case IB_SA_RATE_120_GBPS: return 48;
  78. default: return -1;
  79. }
  80. }
  81. /*
  82. * Structures for SA records are named "struct ib_sa_xxx_rec." No
  83. * attempt is made to pack structures to match the physical layout of
  84. * SA records in SA MADs; all packing and unpacking is handled by the
  85. * SA query code.
  86. *
  87. * For a record with structure ib_sa_xxx_rec, the naming convention
  88. * for the component mask value for field yyy is IB_SA_XXX_REC_YYY (we
  89. * never use different abbreviations or otherwise change the spelling
  90. * of xxx/yyy between ib_sa_xxx_rec.yyy and IB_SA_XXX_REC_YYY).
  91. *
  92. * Reserved rows are indicated with comments to help maintainability.
  93. */
  94. /* reserved: 0 */
  95. /* reserved: 1 */
  96. #define IB_SA_PATH_REC_DGID IB_SA_COMP_MASK( 2)
  97. #define IB_SA_PATH_REC_SGID IB_SA_COMP_MASK( 3)
  98. #define IB_SA_PATH_REC_DLID IB_SA_COMP_MASK( 4)
  99. #define IB_SA_PATH_REC_SLID IB_SA_COMP_MASK( 5)
  100. #define IB_SA_PATH_REC_RAW_TRAFFIC IB_SA_COMP_MASK( 6)
  101. /* reserved: 7 */
  102. #define IB_SA_PATH_REC_FLOW_LABEL IB_SA_COMP_MASK( 8)
  103. #define IB_SA_PATH_REC_HOP_LIMIT IB_SA_COMP_MASK( 9)
  104. #define IB_SA_PATH_REC_TRAFFIC_CLASS IB_SA_COMP_MASK(10)
  105. #define IB_SA_PATH_REC_REVERSIBLE IB_SA_COMP_MASK(11)
  106. #define IB_SA_PATH_REC_NUMB_PATH IB_SA_COMP_MASK(12)
  107. #define IB_SA_PATH_REC_PKEY IB_SA_COMP_MASK(13)
  108. /* reserved: 14 */
  109. #define IB_SA_PATH_REC_SL IB_SA_COMP_MASK(15)
  110. #define IB_SA_PATH_REC_MTU_SELECTOR IB_SA_COMP_MASK(16)
  111. #define IB_SA_PATH_REC_MTU IB_SA_COMP_MASK(17)
  112. #define IB_SA_PATH_REC_RATE_SELECTOR IB_SA_COMP_MASK(18)
  113. #define IB_SA_PATH_REC_RATE IB_SA_COMP_MASK(19)
  114. #define IB_SA_PATH_REC_PACKET_LIFE_TIME_SELECTOR IB_SA_COMP_MASK(20)
  115. #define IB_SA_PATH_REC_PACKET_LIFE_TIME IB_SA_COMP_MASK(21)
  116. #define IB_SA_PATH_REC_PREFERENCE IB_SA_COMP_MASK(22)
  117. struct ib_sa_path_rec {
  118. /* reserved */
  119. /* reserved */
  120. union ib_gid dgid;
  121. union ib_gid sgid;
  122. u16 dlid;
  123. u16 slid;
  124. int raw_traffic;
  125. /* reserved */
  126. u32 flow_label;
  127. u8 hop_limit;
  128. u8 traffic_class;
  129. int reversible;
  130. u8 numb_path;
  131. u16 pkey;
  132. /* reserved */
  133. u8 sl;
  134. u8 mtu_selector;
  135. u8 mtu;
  136. u8 rate_selector;
  137. u8 rate;
  138. u8 packet_life_time_selector;
  139. u8 packet_life_time;
  140. u8 preference;
  141. };
  142. #define IB_SA_MCMEMBER_REC_MGID IB_SA_COMP_MASK( 0)
  143. #define IB_SA_MCMEMBER_REC_PORT_GID IB_SA_COMP_MASK( 1)
  144. #define IB_SA_MCMEMBER_REC_QKEY IB_SA_COMP_MASK( 2)
  145. #define IB_SA_MCMEMBER_REC_MLID IB_SA_COMP_MASK( 3)
  146. #define IB_SA_MCMEMBER_REC_MTU_SELECTOR IB_SA_COMP_MASK( 4)
  147. #define IB_SA_MCMEMBER_REC_MTU IB_SA_COMP_MASK( 5)
  148. #define IB_SA_MCMEMBER_REC_TRAFFIC_CLASS IB_SA_COMP_MASK( 6)
  149. #define IB_SA_MCMEMBER_REC_PKEY IB_SA_COMP_MASK( 7)
  150. #define IB_SA_MCMEMBER_REC_RATE_SELECTOR IB_SA_COMP_MASK( 8)
  151. #define IB_SA_MCMEMBER_REC_RATE IB_SA_COMP_MASK( 9)
  152. #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR IB_SA_COMP_MASK(10)
  153. #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME IB_SA_COMP_MASK(11)
  154. #define IB_SA_MCMEMBER_REC_SL IB_SA_COMP_MASK(12)
  155. #define IB_SA_MCMEMBER_REC_FLOW_LABEL IB_SA_COMP_MASK(13)
  156. #define IB_SA_MCMEMBER_REC_HOP_LIMIT IB_SA_COMP_MASK(14)
  157. #define IB_SA_MCMEMBER_REC_SCOPE IB_SA_COMP_MASK(15)
  158. #define IB_SA_MCMEMBER_REC_JOIN_STATE IB_SA_COMP_MASK(16)
  159. #define IB_SA_MCMEMBER_REC_PROXY_JOIN IB_SA_COMP_MASK(17)
  160. struct ib_sa_mcmember_rec {
  161. union ib_gid mgid;
  162. union ib_gid port_gid;
  163. u32 qkey;
  164. u16 mlid;
  165. u8 mtu_selector;
  166. u8 mtu;
  167. u8 traffic_class;
  168. u16 pkey;
  169. u8 rate_selector;
  170. u8 rate;
  171. u8 packet_life_time_selector;
  172. u8 packet_life_time;
  173. u8 sl;
  174. u32 flow_label;
  175. u8 hop_limit;
  176. u8 scope;
  177. u8 join_state;
  178. int proxy_join;
  179. };
  180. struct ib_sa_query;
  181. void ib_sa_cancel_query(int id, struct ib_sa_query *query);
  182. int ib_sa_path_rec_get(struct ib_device *device, u8 port_num,
  183. struct ib_sa_path_rec *rec,
  184. ib_sa_comp_mask comp_mask,
  185. int timeout_ms, int gfp_mask,
  186. void (*callback)(int status,
  187. struct ib_sa_path_rec *resp,
  188. void *context),
  189. void *context,
  190. struct ib_sa_query **query);
  191. int ib_sa_mcmember_rec_query(struct ib_device *device, u8 port_num,
  192. u8 method,
  193. struct ib_sa_mcmember_rec *rec,
  194. ib_sa_comp_mask comp_mask,
  195. int timeout_ms, int gfp_mask,
  196. void (*callback)(int status,
  197. struct ib_sa_mcmember_rec *resp,
  198. void *context),
  199. void *context,
  200. struct ib_sa_query **query);
  201. /**
  202. * ib_sa_mcmember_rec_set - Start an MCMember set query
  203. * @device:device to send query on
  204. * @port_num: port number to send query on
  205. * @rec:MCMember Record to send in query
  206. * @comp_mask:component mask to send in query
  207. * @timeout_ms:time to wait for response
  208. * @gfp_mask:GFP mask to use for internal allocations
  209. * @callback:function called when query completes, times out or is
  210. * canceled
  211. * @context:opaque user context passed to callback
  212. * @sa_query:query context, used to cancel query
  213. *
  214. * Send an MCMember Set query to the SA (eg to join a multicast
  215. * group). The callback function will be called when the query
  216. * completes (or fails); status is 0 for a successful response, -EINTR
  217. * if the query is canceled, -ETIMEDOUT is the query timed out, or
  218. * -EIO if an error occurred sending the query. The resp parameter of
  219. * the callback is only valid if status is 0.
  220. *
  221. * If the return value of ib_sa_mcmember_rec_set() is negative, it is
  222. * an error code. Otherwise it is a query ID that can be used to
  223. * cancel the query.
  224. */
  225. static inline int
  226. ib_sa_mcmember_rec_set(struct ib_device *device, u8 port_num,
  227. struct ib_sa_mcmember_rec *rec,
  228. ib_sa_comp_mask comp_mask,
  229. int timeout_ms, int gfp_mask,
  230. void (*callback)(int status,
  231. struct ib_sa_mcmember_rec *resp,
  232. void *context),
  233. void *context,
  234. struct ib_sa_query **query)
  235. {
  236. return ib_sa_mcmember_rec_query(device, port_num,
  237. IB_MGMT_METHOD_SET,
  238. rec, comp_mask,
  239. timeout_ms, gfp_mask, callback,
  240. context, query);
  241. }
  242. /**
  243. * ib_sa_mcmember_rec_delete - Start an MCMember delete query
  244. * @device:device to send query on
  245. * @port_num: port number to send query on
  246. * @rec:MCMember Record to send in query
  247. * @comp_mask:component mask to send in query
  248. * @timeout_ms:time to wait for response
  249. * @gfp_mask:GFP mask to use for internal allocations
  250. * @callback:function called when query completes, times out or is
  251. * canceled
  252. * @context:opaque user context passed to callback
  253. * @sa_query:query context, used to cancel query
  254. *
  255. * Send an MCMember Delete query to the SA (eg to leave a multicast
  256. * group). The callback function will be called when the query
  257. * completes (or fails); status is 0 for a successful response, -EINTR
  258. * if the query is canceled, -ETIMEDOUT is the query timed out, or
  259. * -EIO if an error occurred sending the query. The resp parameter of
  260. * the callback is only valid if status is 0.
  261. *
  262. * If the return value of ib_sa_mcmember_rec_delete() is negative, it
  263. * is an error code. Otherwise it is a query ID that can be used to
  264. * cancel the query.
  265. */
  266. static inline int
  267. ib_sa_mcmember_rec_delete(struct ib_device *device, u8 port_num,
  268. struct ib_sa_mcmember_rec *rec,
  269. ib_sa_comp_mask comp_mask,
  270. int timeout_ms, int gfp_mask,
  271. void (*callback)(int status,
  272. struct ib_sa_mcmember_rec *resp,
  273. void *context),
  274. void *context,
  275. struct ib_sa_query **query)
  276. {
  277. return ib_sa_mcmember_rec_query(device, port_num,
  278. IB_SA_METHOD_DELETE,
  279. rec, comp_mask,
  280. timeout_ms, gfp_mask, callback,
  281. context, query);
  282. }
  283. #endif /* IB_SA_H */