ib_sa.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. typedef u64 __bitwise ib_sa_comp_mask;
  82. #define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << n))
  83. /*
  84. * Structures for SA records are named "struct ib_sa_xxx_rec." No
  85. * attempt is made to pack structures to match the physical layout of
  86. * SA records in SA MADs; all packing and unpacking is handled by the
  87. * SA query code.
  88. *
  89. * For a record with structure ib_sa_xxx_rec, the naming convention
  90. * for the component mask value for field yyy is IB_SA_XXX_REC_YYY (we
  91. * never use different abbreviations or otherwise change the spelling
  92. * of xxx/yyy between ib_sa_xxx_rec.yyy and IB_SA_XXX_REC_YYY).
  93. *
  94. * Reserved rows are indicated with comments to help maintainability.
  95. */
  96. /* reserved: 0 */
  97. /* reserved: 1 */
  98. #define IB_SA_PATH_REC_DGID IB_SA_COMP_MASK( 2)
  99. #define IB_SA_PATH_REC_SGID IB_SA_COMP_MASK( 3)
  100. #define IB_SA_PATH_REC_DLID IB_SA_COMP_MASK( 4)
  101. #define IB_SA_PATH_REC_SLID IB_SA_COMP_MASK( 5)
  102. #define IB_SA_PATH_REC_RAW_TRAFFIC IB_SA_COMP_MASK( 6)
  103. /* reserved: 7 */
  104. #define IB_SA_PATH_REC_FLOW_LABEL IB_SA_COMP_MASK( 8)
  105. #define IB_SA_PATH_REC_HOP_LIMIT IB_SA_COMP_MASK( 9)
  106. #define IB_SA_PATH_REC_TRAFFIC_CLASS IB_SA_COMP_MASK(10)
  107. #define IB_SA_PATH_REC_REVERSIBLE IB_SA_COMP_MASK(11)
  108. #define IB_SA_PATH_REC_NUMB_PATH IB_SA_COMP_MASK(12)
  109. #define IB_SA_PATH_REC_PKEY IB_SA_COMP_MASK(13)
  110. /* reserved: 14 */
  111. #define IB_SA_PATH_REC_SL IB_SA_COMP_MASK(15)
  112. #define IB_SA_PATH_REC_MTU_SELECTOR IB_SA_COMP_MASK(16)
  113. #define IB_SA_PATH_REC_MTU IB_SA_COMP_MASK(17)
  114. #define IB_SA_PATH_REC_RATE_SELECTOR IB_SA_COMP_MASK(18)
  115. #define IB_SA_PATH_REC_RATE IB_SA_COMP_MASK(19)
  116. #define IB_SA_PATH_REC_PACKET_LIFE_TIME_SELECTOR IB_SA_COMP_MASK(20)
  117. #define IB_SA_PATH_REC_PACKET_LIFE_TIME IB_SA_COMP_MASK(21)
  118. #define IB_SA_PATH_REC_PREFERENCE IB_SA_COMP_MASK(22)
  119. struct ib_sa_path_rec {
  120. /* reserved */
  121. /* reserved */
  122. union ib_gid dgid;
  123. union ib_gid sgid;
  124. u16 dlid;
  125. u16 slid;
  126. int raw_traffic;
  127. /* reserved */
  128. u32 flow_label;
  129. u8 hop_limit;
  130. u8 traffic_class;
  131. int reversible;
  132. u8 numb_path;
  133. u16 pkey;
  134. /* reserved */
  135. u8 sl;
  136. u8 mtu_selector;
  137. u8 mtu;
  138. u8 rate_selector;
  139. u8 rate;
  140. u8 packet_life_time_selector;
  141. u8 packet_life_time;
  142. u8 preference;
  143. };
  144. #define IB_SA_MCMEMBER_REC_MGID IB_SA_COMP_MASK( 0)
  145. #define IB_SA_MCMEMBER_REC_PORT_GID IB_SA_COMP_MASK( 1)
  146. #define IB_SA_MCMEMBER_REC_QKEY IB_SA_COMP_MASK( 2)
  147. #define IB_SA_MCMEMBER_REC_MLID IB_SA_COMP_MASK( 3)
  148. #define IB_SA_MCMEMBER_REC_MTU_SELECTOR IB_SA_COMP_MASK( 4)
  149. #define IB_SA_MCMEMBER_REC_MTU IB_SA_COMP_MASK( 5)
  150. #define IB_SA_MCMEMBER_REC_TRAFFIC_CLASS IB_SA_COMP_MASK( 6)
  151. #define IB_SA_MCMEMBER_REC_PKEY IB_SA_COMP_MASK( 7)
  152. #define IB_SA_MCMEMBER_REC_RATE_SELECTOR IB_SA_COMP_MASK( 8)
  153. #define IB_SA_MCMEMBER_REC_RATE IB_SA_COMP_MASK( 9)
  154. #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR IB_SA_COMP_MASK(10)
  155. #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME IB_SA_COMP_MASK(11)
  156. #define IB_SA_MCMEMBER_REC_SL IB_SA_COMP_MASK(12)
  157. #define IB_SA_MCMEMBER_REC_FLOW_LABEL IB_SA_COMP_MASK(13)
  158. #define IB_SA_MCMEMBER_REC_HOP_LIMIT IB_SA_COMP_MASK(14)
  159. #define IB_SA_MCMEMBER_REC_SCOPE IB_SA_COMP_MASK(15)
  160. #define IB_SA_MCMEMBER_REC_JOIN_STATE IB_SA_COMP_MASK(16)
  161. #define IB_SA_MCMEMBER_REC_PROXY_JOIN IB_SA_COMP_MASK(17)
  162. struct ib_sa_mcmember_rec {
  163. union ib_gid mgid;
  164. union ib_gid port_gid;
  165. u32 qkey;
  166. u16 mlid;
  167. u8 mtu_selector;
  168. u8 mtu;
  169. u8 traffic_class;
  170. u16 pkey;
  171. u8 rate_selector;
  172. u8 rate;
  173. u8 packet_life_time_selector;
  174. u8 packet_life_time;
  175. u8 sl;
  176. u32 flow_label;
  177. u8 hop_limit;
  178. u8 scope;
  179. u8 join_state;
  180. int proxy_join;
  181. };
  182. struct ib_sa_query;
  183. void ib_sa_cancel_query(int id, struct ib_sa_query *query);
  184. int ib_sa_path_rec_get(struct ib_device *device, u8 port_num,
  185. struct ib_sa_path_rec *rec,
  186. ib_sa_comp_mask comp_mask,
  187. int timeout_ms, int gfp_mask,
  188. void (*callback)(int status,
  189. struct ib_sa_path_rec *resp,
  190. void *context),
  191. void *context,
  192. struct ib_sa_query **query);
  193. int ib_sa_mcmember_rec_query(struct ib_device *device, u8 port_num,
  194. u8 method,
  195. struct ib_sa_mcmember_rec *rec,
  196. ib_sa_comp_mask comp_mask,
  197. int timeout_ms, int gfp_mask,
  198. void (*callback)(int status,
  199. struct ib_sa_mcmember_rec *resp,
  200. void *context),
  201. void *context,
  202. struct ib_sa_query **query);
  203. /**
  204. * ib_sa_mcmember_rec_set - Start an MCMember set query
  205. * @device:device to send query on
  206. * @port_num: port number to send query on
  207. * @rec:MCMember Record to send in query
  208. * @comp_mask:component mask to send in query
  209. * @timeout_ms:time to wait for response
  210. * @gfp_mask:GFP mask to use for internal allocations
  211. * @callback:function called when query completes, times out or is
  212. * canceled
  213. * @context:opaque user context passed to callback
  214. * @sa_query:query context, used to cancel query
  215. *
  216. * Send an MCMember Set query to the SA (eg to join a multicast
  217. * group). The callback function will be called when the query
  218. * completes (or fails); status is 0 for a successful response, -EINTR
  219. * if the query is canceled, -ETIMEDOUT is the query timed out, or
  220. * -EIO if an error occurred sending the query. The resp parameter of
  221. * the callback is only valid if status is 0.
  222. *
  223. * If the return value of ib_sa_mcmember_rec_set() is negative, it is
  224. * an error code. Otherwise it is a query ID that can be used to
  225. * cancel the query.
  226. */
  227. static inline int
  228. ib_sa_mcmember_rec_set(struct ib_device *device, u8 port_num,
  229. struct ib_sa_mcmember_rec *rec,
  230. ib_sa_comp_mask comp_mask,
  231. int timeout_ms, int gfp_mask,
  232. void (*callback)(int status,
  233. struct ib_sa_mcmember_rec *resp,
  234. void *context),
  235. void *context,
  236. struct ib_sa_query **query)
  237. {
  238. return ib_sa_mcmember_rec_query(device, port_num,
  239. IB_MGMT_METHOD_SET,
  240. rec, comp_mask,
  241. timeout_ms, gfp_mask, callback,
  242. context, query);
  243. }
  244. /**
  245. * ib_sa_mcmember_rec_delete - Start an MCMember delete query
  246. * @device:device to send query on
  247. * @port_num: port number to send query on
  248. * @rec:MCMember Record to send in query
  249. * @comp_mask:component mask to send in query
  250. * @timeout_ms:time to wait for response
  251. * @gfp_mask:GFP mask to use for internal allocations
  252. * @callback:function called when query completes, times out or is
  253. * canceled
  254. * @context:opaque user context passed to callback
  255. * @sa_query:query context, used to cancel query
  256. *
  257. * Send an MCMember Delete query to the SA (eg to leave a multicast
  258. * group). The callback function will be called when the query
  259. * completes (or fails); status is 0 for a successful response, -EINTR
  260. * if the query is canceled, -ETIMEDOUT is the query timed out, or
  261. * -EIO if an error occurred sending the query. The resp parameter of
  262. * the callback is only valid if status is 0.
  263. *
  264. * If the return value of ib_sa_mcmember_rec_delete() is negative, it
  265. * is an error code. Otherwise it is a query ID that can be used to
  266. * cancel the query.
  267. */
  268. static inline int
  269. ib_sa_mcmember_rec_delete(struct ib_device *device, u8 port_num,
  270. struct ib_sa_mcmember_rec *rec,
  271. ib_sa_comp_mask comp_mask,
  272. int timeout_ms, int gfp_mask,
  273. void (*callback)(int status,
  274. struct ib_sa_mcmember_rec *resp,
  275. void *context),
  276. void *context,
  277. struct ib_sa_query **query)
  278. {
  279. return ib_sa_mcmember_rec_query(device, port_num,
  280. IB_SA_METHOD_DELETE,
  281. rec, comp_mask,
  282. timeout_ms, gfp_mask, callback,
  283. context, query);
  284. }
  285. #endif /* IB_SA_H */