sa_query.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785
  1. /*
  2. * Copyright (c) 2004 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
  4. * Copyright (c) 2006 Intel Corporation. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/module.h>
  35. #include <linux/init.h>
  36. #include <linux/err.h>
  37. #include <linux/random.h>
  38. #include <linux/spinlock.h>
  39. #include <linux/slab.h>
  40. #include <linux/dma-mapping.h>
  41. #include <linux/kref.h>
  42. #include <linux/idr.h>
  43. #include <linux/workqueue.h>
  44. #include <uapi/linux/if_ether.h>
  45. #include <rdma/ib_pack.h>
  46. #include <rdma/ib_cache.h>
  47. #include <rdma/rdma_netlink.h>
  48. #include <net/netlink.h>
  49. #include <uapi/rdma/ib_user_sa.h>
  50. #include <rdma/ib_marshall.h>
  51. #include "sa.h"
  52. MODULE_AUTHOR("Roland Dreier");
  53. MODULE_DESCRIPTION("InfiniBand subnet administration query support");
  54. MODULE_LICENSE("Dual BSD/GPL");
  55. #define IB_SA_LOCAL_SVC_TIMEOUT_MIN 100
  56. #define IB_SA_LOCAL_SVC_TIMEOUT_DEFAULT 2000
  57. #define IB_SA_LOCAL_SVC_TIMEOUT_MAX 200000
  58. static int sa_local_svc_timeout_ms = IB_SA_LOCAL_SVC_TIMEOUT_DEFAULT;
  59. struct ib_sa_sm_ah {
  60. struct ib_ah *ah;
  61. struct kref ref;
  62. u16 pkey_index;
  63. u8 src_path_mask;
  64. };
  65. struct ib_sa_port {
  66. struct ib_mad_agent *agent;
  67. struct ib_sa_sm_ah *sm_ah;
  68. struct work_struct update_task;
  69. spinlock_t ah_lock;
  70. u8 port_num;
  71. };
  72. struct ib_sa_device {
  73. int start_port, end_port;
  74. struct ib_event_handler event_handler;
  75. struct ib_sa_port port[0];
  76. };
  77. struct ib_sa_query {
  78. void (*callback)(struct ib_sa_query *, int, struct ib_sa_mad *);
  79. void (*release)(struct ib_sa_query *);
  80. struct ib_sa_client *client;
  81. struct ib_sa_port *port;
  82. struct ib_mad_send_buf *mad_buf;
  83. struct ib_sa_sm_ah *sm_ah;
  84. int id;
  85. u32 flags;
  86. struct list_head list; /* Local svc request list */
  87. u32 seq; /* Local svc request sequence number */
  88. unsigned long timeout; /* Local svc timeout */
  89. u8 path_use; /* How will the pathrecord be used */
  90. };
  91. #define IB_SA_ENABLE_LOCAL_SERVICE 0x00000001
  92. #define IB_SA_CANCEL 0x00000002
  93. struct ib_sa_service_query {
  94. void (*callback)(int, struct ib_sa_service_rec *, void *);
  95. void *context;
  96. struct ib_sa_query sa_query;
  97. };
  98. struct ib_sa_path_query {
  99. void (*callback)(int, struct ib_sa_path_rec *, void *);
  100. void *context;
  101. struct ib_sa_query sa_query;
  102. };
  103. struct ib_sa_guidinfo_query {
  104. void (*callback)(int, struct ib_sa_guidinfo_rec *, void *);
  105. void *context;
  106. struct ib_sa_query sa_query;
  107. };
  108. struct ib_sa_mcmember_query {
  109. void (*callback)(int, struct ib_sa_mcmember_rec *, void *);
  110. void *context;
  111. struct ib_sa_query sa_query;
  112. };
  113. static LIST_HEAD(ib_nl_request_list);
  114. static DEFINE_SPINLOCK(ib_nl_request_lock);
  115. static atomic_t ib_nl_sa_request_seq;
  116. static struct workqueue_struct *ib_nl_wq;
  117. static struct delayed_work ib_nl_timed_work;
  118. static const struct nla_policy ib_nl_policy[LS_NLA_TYPE_MAX] = {
  119. [LS_NLA_TYPE_PATH_RECORD] = {.type = NLA_BINARY,
  120. .len = sizeof(struct ib_path_rec_data)},
  121. [LS_NLA_TYPE_TIMEOUT] = {.type = NLA_U32},
  122. [LS_NLA_TYPE_SERVICE_ID] = {.type = NLA_U64},
  123. [LS_NLA_TYPE_DGID] = {.type = NLA_BINARY,
  124. .len = sizeof(struct rdma_nla_ls_gid)},
  125. [LS_NLA_TYPE_SGID] = {.type = NLA_BINARY,
  126. .len = sizeof(struct rdma_nla_ls_gid)},
  127. [LS_NLA_TYPE_TCLASS] = {.type = NLA_U8},
  128. [LS_NLA_TYPE_PKEY] = {.type = NLA_U16},
  129. [LS_NLA_TYPE_QOS_CLASS] = {.type = NLA_U16},
  130. };
  131. static void ib_sa_add_one(struct ib_device *device);
  132. static void ib_sa_remove_one(struct ib_device *device, void *client_data);
  133. static struct ib_client sa_client = {
  134. .name = "sa",
  135. .add = ib_sa_add_one,
  136. .remove = ib_sa_remove_one
  137. };
  138. static DEFINE_SPINLOCK(idr_lock);
  139. static DEFINE_IDR(query_idr);
  140. static DEFINE_SPINLOCK(tid_lock);
  141. static u32 tid;
  142. #define PATH_REC_FIELD(field) \
  143. .struct_offset_bytes = offsetof(struct ib_sa_path_rec, field), \
  144. .struct_size_bytes = sizeof ((struct ib_sa_path_rec *) 0)->field, \
  145. .field_name = "sa_path_rec:" #field
  146. static const struct ib_field path_rec_table[] = {
  147. { PATH_REC_FIELD(service_id),
  148. .offset_words = 0,
  149. .offset_bits = 0,
  150. .size_bits = 64 },
  151. { PATH_REC_FIELD(dgid),
  152. .offset_words = 2,
  153. .offset_bits = 0,
  154. .size_bits = 128 },
  155. { PATH_REC_FIELD(sgid),
  156. .offset_words = 6,
  157. .offset_bits = 0,
  158. .size_bits = 128 },
  159. { PATH_REC_FIELD(dlid),
  160. .offset_words = 10,
  161. .offset_bits = 0,
  162. .size_bits = 16 },
  163. { PATH_REC_FIELD(slid),
  164. .offset_words = 10,
  165. .offset_bits = 16,
  166. .size_bits = 16 },
  167. { PATH_REC_FIELD(raw_traffic),
  168. .offset_words = 11,
  169. .offset_bits = 0,
  170. .size_bits = 1 },
  171. { RESERVED,
  172. .offset_words = 11,
  173. .offset_bits = 1,
  174. .size_bits = 3 },
  175. { PATH_REC_FIELD(flow_label),
  176. .offset_words = 11,
  177. .offset_bits = 4,
  178. .size_bits = 20 },
  179. { PATH_REC_FIELD(hop_limit),
  180. .offset_words = 11,
  181. .offset_bits = 24,
  182. .size_bits = 8 },
  183. { PATH_REC_FIELD(traffic_class),
  184. .offset_words = 12,
  185. .offset_bits = 0,
  186. .size_bits = 8 },
  187. { PATH_REC_FIELD(reversible),
  188. .offset_words = 12,
  189. .offset_bits = 8,
  190. .size_bits = 1 },
  191. { PATH_REC_FIELD(numb_path),
  192. .offset_words = 12,
  193. .offset_bits = 9,
  194. .size_bits = 7 },
  195. { PATH_REC_FIELD(pkey),
  196. .offset_words = 12,
  197. .offset_bits = 16,
  198. .size_bits = 16 },
  199. { PATH_REC_FIELD(qos_class),
  200. .offset_words = 13,
  201. .offset_bits = 0,
  202. .size_bits = 12 },
  203. { PATH_REC_FIELD(sl),
  204. .offset_words = 13,
  205. .offset_bits = 12,
  206. .size_bits = 4 },
  207. { PATH_REC_FIELD(mtu_selector),
  208. .offset_words = 13,
  209. .offset_bits = 16,
  210. .size_bits = 2 },
  211. { PATH_REC_FIELD(mtu),
  212. .offset_words = 13,
  213. .offset_bits = 18,
  214. .size_bits = 6 },
  215. { PATH_REC_FIELD(rate_selector),
  216. .offset_words = 13,
  217. .offset_bits = 24,
  218. .size_bits = 2 },
  219. { PATH_REC_FIELD(rate),
  220. .offset_words = 13,
  221. .offset_bits = 26,
  222. .size_bits = 6 },
  223. { PATH_REC_FIELD(packet_life_time_selector),
  224. .offset_words = 14,
  225. .offset_bits = 0,
  226. .size_bits = 2 },
  227. { PATH_REC_FIELD(packet_life_time),
  228. .offset_words = 14,
  229. .offset_bits = 2,
  230. .size_bits = 6 },
  231. { PATH_REC_FIELD(preference),
  232. .offset_words = 14,
  233. .offset_bits = 8,
  234. .size_bits = 8 },
  235. { RESERVED,
  236. .offset_words = 14,
  237. .offset_bits = 16,
  238. .size_bits = 48 },
  239. };
  240. #define MCMEMBER_REC_FIELD(field) \
  241. .struct_offset_bytes = offsetof(struct ib_sa_mcmember_rec, field), \
  242. .struct_size_bytes = sizeof ((struct ib_sa_mcmember_rec *) 0)->field, \
  243. .field_name = "sa_mcmember_rec:" #field
  244. static const struct ib_field mcmember_rec_table[] = {
  245. { MCMEMBER_REC_FIELD(mgid),
  246. .offset_words = 0,
  247. .offset_bits = 0,
  248. .size_bits = 128 },
  249. { MCMEMBER_REC_FIELD(port_gid),
  250. .offset_words = 4,
  251. .offset_bits = 0,
  252. .size_bits = 128 },
  253. { MCMEMBER_REC_FIELD(qkey),
  254. .offset_words = 8,
  255. .offset_bits = 0,
  256. .size_bits = 32 },
  257. { MCMEMBER_REC_FIELD(mlid),
  258. .offset_words = 9,
  259. .offset_bits = 0,
  260. .size_bits = 16 },
  261. { MCMEMBER_REC_FIELD(mtu_selector),
  262. .offset_words = 9,
  263. .offset_bits = 16,
  264. .size_bits = 2 },
  265. { MCMEMBER_REC_FIELD(mtu),
  266. .offset_words = 9,
  267. .offset_bits = 18,
  268. .size_bits = 6 },
  269. { MCMEMBER_REC_FIELD(traffic_class),
  270. .offset_words = 9,
  271. .offset_bits = 24,
  272. .size_bits = 8 },
  273. { MCMEMBER_REC_FIELD(pkey),
  274. .offset_words = 10,
  275. .offset_bits = 0,
  276. .size_bits = 16 },
  277. { MCMEMBER_REC_FIELD(rate_selector),
  278. .offset_words = 10,
  279. .offset_bits = 16,
  280. .size_bits = 2 },
  281. { MCMEMBER_REC_FIELD(rate),
  282. .offset_words = 10,
  283. .offset_bits = 18,
  284. .size_bits = 6 },
  285. { MCMEMBER_REC_FIELD(packet_life_time_selector),
  286. .offset_words = 10,
  287. .offset_bits = 24,
  288. .size_bits = 2 },
  289. { MCMEMBER_REC_FIELD(packet_life_time),
  290. .offset_words = 10,
  291. .offset_bits = 26,
  292. .size_bits = 6 },
  293. { MCMEMBER_REC_FIELD(sl),
  294. .offset_words = 11,
  295. .offset_bits = 0,
  296. .size_bits = 4 },
  297. { MCMEMBER_REC_FIELD(flow_label),
  298. .offset_words = 11,
  299. .offset_bits = 4,
  300. .size_bits = 20 },
  301. { MCMEMBER_REC_FIELD(hop_limit),
  302. .offset_words = 11,
  303. .offset_bits = 24,
  304. .size_bits = 8 },
  305. { MCMEMBER_REC_FIELD(scope),
  306. .offset_words = 12,
  307. .offset_bits = 0,
  308. .size_bits = 4 },
  309. { MCMEMBER_REC_FIELD(join_state),
  310. .offset_words = 12,
  311. .offset_bits = 4,
  312. .size_bits = 4 },
  313. { MCMEMBER_REC_FIELD(proxy_join),
  314. .offset_words = 12,
  315. .offset_bits = 8,
  316. .size_bits = 1 },
  317. { RESERVED,
  318. .offset_words = 12,
  319. .offset_bits = 9,
  320. .size_bits = 23 },
  321. };
  322. #define SERVICE_REC_FIELD(field) \
  323. .struct_offset_bytes = offsetof(struct ib_sa_service_rec, field), \
  324. .struct_size_bytes = sizeof ((struct ib_sa_service_rec *) 0)->field, \
  325. .field_name = "sa_service_rec:" #field
  326. static const struct ib_field service_rec_table[] = {
  327. { SERVICE_REC_FIELD(id),
  328. .offset_words = 0,
  329. .offset_bits = 0,
  330. .size_bits = 64 },
  331. { SERVICE_REC_FIELD(gid),
  332. .offset_words = 2,
  333. .offset_bits = 0,
  334. .size_bits = 128 },
  335. { SERVICE_REC_FIELD(pkey),
  336. .offset_words = 6,
  337. .offset_bits = 0,
  338. .size_bits = 16 },
  339. { SERVICE_REC_FIELD(lease),
  340. .offset_words = 7,
  341. .offset_bits = 0,
  342. .size_bits = 32 },
  343. { SERVICE_REC_FIELD(key),
  344. .offset_words = 8,
  345. .offset_bits = 0,
  346. .size_bits = 128 },
  347. { SERVICE_REC_FIELD(name),
  348. .offset_words = 12,
  349. .offset_bits = 0,
  350. .size_bits = 64*8 },
  351. { SERVICE_REC_FIELD(data8),
  352. .offset_words = 28,
  353. .offset_bits = 0,
  354. .size_bits = 16*8 },
  355. { SERVICE_REC_FIELD(data16),
  356. .offset_words = 32,
  357. .offset_bits = 0,
  358. .size_bits = 8*16 },
  359. { SERVICE_REC_FIELD(data32),
  360. .offset_words = 36,
  361. .offset_bits = 0,
  362. .size_bits = 4*32 },
  363. { SERVICE_REC_FIELD(data64),
  364. .offset_words = 40,
  365. .offset_bits = 0,
  366. .size_bits = 2*64 },
  367. };
  368. #define GUIDINFO_REC_FIELD(field) \
  369. .struct_offset_bytes = offsetof(struct ib_sa_guidinfo_rec, field), \
  370. .struct_size_bytes = sizeof((struct ib_sa_guidinfo_rec *) 0)->field, \
  371. .field_name = "sa_guidinfo_rec:" #field
  372. static const struct ib_field guidinfo_rec_table[] = {
  373. { GUIDINFO_REC_FIELD(lid),
  374. .offset_words = 0,
  375. .offset_bits = 0,
  376. .size_bits = 16 },
  377. { GUIDINFO_REC_FIELD(block_num),
  378. .offset_words = 0,
  379. .offset_bits = 16,
  380. .size_bits = 8 },
  381. { GUIDINFO_REC_FIELD(res1),
  382. .offset_words = 0,
  383. .offset_bits = 24,
  384. .size_bits = 8 },
  385. { GUIDINFO_REC_FIELD(res2),
  386. .offset_words = 1,
  387. .offset_bits = 0,
  388. .size_bits = 32 },
  389. { GUIDINFO_REC_FIELD(guid_info_list),
  390. .offset_words = 2,
  391. .offset_bits = 0,
  392. .size_bits = 512 },
  393. };
  394. static inline void ib_sa_disable_local_svc(struct ib_sa_query *query)
  395. {
  396. query->flags &= ~IB_SA_ENABLE_LOCAL_SERVICE;
  397. }
  398. static inline int ib_sa_query_cancelled(struct ib_sa_query *query)
  399. {
  400. return (query->flags & IB_SA_CANCEL);
  401. }
  402. static void ib_nl_set_path_rec_attrs(struct sk_buff *skb,
  403. struct ib_sa_query *query)
  404. {
  405. struct ib_sa_path_rec *sa_rec = query->mad_buf->context[1];
  406. struct ib_sa_mad *mad = query->mad_buf->mad;
  407. ib_sa_comp_mask comp_mask = mad->sa_hdr.comp_mask;
  408. u16 val16;
  409. u64 val64;
  410. struct rdma_ls_resolve_header *header;
  411. query->mad_buf->context[1] = NULL;
  412. /* Construct the family header first */
  413. header = (struct rdma_ls_resolve_header *)
  414. skb_put(skb, NLMSG_ALIGN(sizeof(*header)));
  415. memcpy(header->device_name, query->port->agent->device->name,
  416. LS_DEVICE_NAME_MAX);
  417. header->port_num = query->port->port_num;
  418. if ((comp_mask & IB_SA_PATH_REC_REVERSIBLE) &&
  419. sa_rec->reversible != 0)
  420. query->path_use = LS_RESOLVE_PATH_USE_GMP;
  421. else
  422. query->path_use = LS_RESOLVE_PATH_USE_UNIDIRECTIONAL;
  423. header->path_use = query->path_use;
  424. /* Now build the attributes */
  425. if (comp_mask & IB_SA_PATH_REC_SERVICE_ID) {
  426. val64 = be64_to_cpu(sa_rec->service_id);
  427. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_SERVICE_ID,
  428. sizeof(val64), &val64);
  429. }
  430. if (comp_mask & IB_SA_PATH_REC_DGID)
  431. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_DGID,
  432. sizeof(sa_rec->dgid), &sa_rec->dgid);
  433. if (comp_mask & IB_SA_PATH_REC_SGID)
  434. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_SGID,
  435. sizeof(sa_rec->sgid), &sa_rec->sgid);
  436. if (comp_mask & IB_SA_PATH_REC_TRAFFIC_CLASS)
  437. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_TCLASS,
  438. sizeof(sa_rec->traffic_class), &sa_rec->traffic_class);
  439. if (comp_mask & IB_SA_PATH_REC_PKEY) {
  440. val16 = be16_to_cpu(sa_rec->pkey);
  441. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_PKEY,
  442. sizeof(val16), &val16);
  443. }
  444. if (comp_mask & IB_SA_PATH_REC_QOS_CLASS) {
  445. val16 = be16_to_cpu(sa_rec->qos_class);
  446. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_QOS_CLASS,
  447. sizeof(val16), &val16);
  448. }
  449. }
  450. static int ib_nl_get_path_rec_attrs_len(ib_sa_comp_mask comp_mask)
  451. {
  452. int len = 0;
  453. if (comp_mask & IB_SA_PATH_REC_SERVICE_ID)
  454. len += nla_total_size(sizeof(u64));
  455. if (comp_mask & IB_SA_PATH_REC_DGID)
  456. len += nla_total_size(sizeof(struct rdma_nla_ls_gid));
  457. if (comp_mask & IB_SA_PATH_REC_SGID)
  458. len += nla_total_size(sizeof(struct rdma_nla_ls_gid));
  459. if (comp_mask & IB_SA_PATH_REC_TRAFFIC_CLASS)
  460. len += nla_total_size(sizeof(u8));
  461. if (comp_mask & IB_SA_PATH_REC_PKEY)
  462. len += nla_total_size(sizeof(u16));
  463. if (comp_mask & IB_SA_PATH_REC_QOS_CLASS)
  464. len += nla_total_size(sizeof(u16));
  465. /*
  466. * Make sure that at least some of the required comp_mask bits are
  467. * set.
  468. */
  469. if (WARN_ON(len == 0))
  470. return len;
  471. /* Add the family header */
  472. len += NLMSG_ALIGN(sizeof(struct rdma_ls_resolve_header));
  473. return len;
  474. }
  475. static int ib_nl_send_msg(struct ib_sa_query *query)
  476. {
  477. struct sk_buff *skb = NULL;
  478. struct nlmsghdr *nlh;
  479. void *data;
  480. int ret = 0;
  481. struct ib_sa_mad *mad;
  482. int len;
  483. mad = query->mad_buf->mad;
  484. len = ib_nl_get_path_rec_attrs_len(mad->sa_hdr.comp_mask);
  485. if (len <= 0)
  486. return -EMSGSIZE;
  487. skb = nlmsg_new(len, GFP_KERNEL);
  488. if (!skb)
  489. return -ENOMEM;
  490. /* Put nlmsg header only for now */
  491. data = ibnl_put_msg(skb, &nlh, query->seq, 0, RDMA_NL_LS,
  492. RDMA_NL_LS_OP_RESOLVE, NLM_F_REQUEST);
  493. if (!data) {
  494. kfree_skb(skb);
  495. return -EMSGSIZE;
  496. }
  497. /* Add attributes */
  498. ib_nl_set_path_rec_attrs(skb, query);
  499. /* Repair the nlmsg header length */
  500. nlmsg_end(skb, nlh);
  501. ret = ibnl_multicast(skb, nlh, RDMA_NL_GROUP_LS, GFP_KERNEL);
  502. if (!ret)
  503. ret = len;
  504. else
  505. ret = 0;
  506. return ret;
  507. }
  508. static int ib_nl_make_request(struct ib_sa_query *query)
  509. {
  510. unsigned long flags;
  511. unsigned long delay;
  512. int ret;
  513. INIT_LIST_HEAD(&query->list);
  514. query->seq = (u32)atomic_inc_return(&ib_nl_sa_request_seq);
  515. spin_lock_irqsave(&ib_nl_request_lock, flags);
  516. ret = ib_nl_send_msg(query);
  517. if (ret <= 0) {
  518. ret = -EIO;
  519. goto request_out;
  520. } else {
  521. ret = 0;
  522. }
  523. delay = msecs_to_jiffies(sa_local_svc_timeout_ms);
  524. query->timeout = delay + jiffies;
  525. list_add_tail(&query->list, &ib_nl_request_list);
  526. /* Start the timeout if this is the only request */
  527. if (ib_nl_request_list.next == &query->list)
  528. queue_delayed_work(ib_nl_wq, &ib_nl_timed_work, delay);
  529. request_out:
  530. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  531. return ret;
  532. }
  533. static int ib_nl_cancel_request(struct ib_sa_query *query)
  534. {
  535. unsigned long flags;
  536. struct ib_sa_query *wait_query;
  537. int found = 0;
  538. spin_lock_irqsave(&ib_nl_request_lock, flags);
  539. list_for_each_entry(wait_query, &ib_nl_request_list, list) {
  540. /* Let the timeout to take care of the callback */
  541. if (query == wait_query) {
  542. query->flags |= IB_SA_CANCEL;
  543. query->timeout = jiffies;
  544. list_move(&query->list, &ib_nl_request_list);
  545. found = 1;
  546. mod_delayed_work(ib_nl_wq, &ib_nl_timed_work, 1);
  547. break;
  548. }
  549. }
  550. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  551. return found;
  552. }
  553. static void send_handler(struct ib_mad_agent *agent,
  554. struct ib_mad_send_wc *mad_send_wc);
  555. static void ib_nl_process_good_resolve_rsp(struct ib_sa_query *query,
  556. const struct nlmsghdr *nlh)
  557. {
  558. struct ib_mad_send_wc mad_send_wc;
  559. struct ib_sa_mad *mad = NULL;
  560. const struct nlattr *head, *curr;
  561. struct ib_path_rec_data *rec;
  562. int len, rem;
  563. u32 mask = 0;
  564. int status = -EIO;
  565. if (query->callback) {
  566. head = (const struct nlattr *) nlmsg_data(nlh);
  567. len = nlmsg_len(nlh);
  568. switch (query->path_use) {
  569. case LS_RESOLVE_PATH_USE_UNIDIRECTIONAL:
  570. mask = IB_PATH_PRIMARY | IB_PATH_OUTBOUND;
  571. break;
  572. case LS_RESOLVE_PATH_USE_ALL:
  573. case LS_RESOLVE_PATH_USE_GMP:
  574. default:
  575. mask = IB_PATH_PRIMARY | IB_PATH_GMP |
  576. IB_PATH_BIDIRECTIONAL;
  577. break;
  578. }
  579. nla_for_each_attr(curr, head, len, rem) {
  580. if (curr->nla_type == LS_NLA_TYPE_PATH_RECORD) {
  581. rec = nla_data(curr);
  582. /*
  583. * Get the first one. In the future, we may
  584. * need to get up to 6 pathrecords.
  585. */
  586. if ((rec->flags & mask) == mask) {
  587. mad = query->mad_buf->mad;
  588. mad->mad_hdr.method |=
  589. IB_MGMT_METHOD_RESP;
  590. memcpy(mad->data, rec->path_rec,
  591. sizeof(rec->path_rec));
  592. status = 0;
  593. break;
  594. }
  595. }
  596. }
  597. query->callback(query, status, mad);
  598. }
  599. mad_send_wc.send_buf = query->mad_buf;
  600. mad_send_wc.status = IB_WC_SUCCESS;
  601. send_handler(query->mad_buf->mad_agent, &mad_send_wc);
  602. }
  603. static void ib_nl_request_timeout(struct work_struct *work)
  604. {
  605. unsigned long flags;
  606. struct ib_sa_query *query;
  607. unsigned long delay;
  608. struct ib_mad_send_wc mad_send_wc;
  609. int ret;
  610. spin_lock_irqsave(&ib_nl_request_lock, flags);
  611. while (!list_empty(&ib_nl_request_list)) {
  612. query = list_entry(ib_nl_request_list.next,
  613. struct ib_sa_query, list);
  614. if (time_after(query->timeout, jiffies)) {
  615. delay = query->timeout - jiffies;
  616. if ((long)delay <= 0)
  617. delay = 1;
  618. queue_delayed_work(ib_nl_wq, &ib_nl_timed_work, delay);
  619. break;
  620. }
  621. list_del(&query->list);
  622. ib_sa_disable_local_svc(query);
  623. /* Hold the lock to protect against query cancellation */
  624. if (ib_sa_query_cancelled(query))
  625. ret = -1;
  626. else
  627. ret = ib_post_send_mad(query->mad_buf, NULL);
  628. if (ret) {
  629. mad_send_wc.send_buf = query->mad_buf;
  630. mad_send_wc.status = IB_WC_WR_FLUSH_ERR;
  631. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  632. send_handler(query->port->agent, &mad_send_wc);
  633. spin_lock_irqsave(&ib_nl_request_lock, flags);
  634. }
  635. }
  636. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  637. }
  638. static int ib_nl_handle_set_timeout(struct sk_buff *skb,
  639. struct netlink_callback *cb)
  640. {
  641. const struct nlmsghdr *nlh = (struct nlmsghdr *)cb->nlh;
  642. int timeout, delta, abs_delta;
  643. const struct nlattr *attr;
  644. unsigned long flags;
  645. struct ib_sa_query *query;
  646. long delay = 0;
  647. struct nlattr *tb[LS_NLA_TYPE_MAX];
  648. int ret;
  649. if (!netlink_capable(skb, CAP_NET_ADMIN))
  650. return -EPERM;
  651. ret = nla_parse(tb, LS_NLA_TYPE_MAX - 1, nlmsg_data(nlh),
  652. nlmsg_len(nlh), ib_nl_policy);
  653. attr = (const struct nlattr *)tb[LS_NLA_TYPE_TIMEOUT];
  654. if (ret || !attr)
  655. goto settimeout_out;
  656. timeout = *(int *) nla_data(attr);
  657. if (timeout < IB_SA_LOCAL_SVC_TIMEOUT_MIN)
  658. timeout = IB_SA_LOCAL_SVC_TIMEOUT_MIN;
  659. if (timeout > IB_SA_LOCAL_SVC_TIMEOUT_MAX)
  660. timeout = IB_SA_LOCAL_SVC_TIMEOUT_MAX;
  661. delta = timeout - sa_local_svc_timeout_ms;
  662. if (delta < 0)
  663. abs_delta = -delta;
  664. else
  665. abs_delta = delta;
  666. if (delta != 0) {
  667. spin_lock_irqsave(&ib_nl_request_lock, flags);
  668. sa_local_svc_timeout_ms = timeout;
  669. list_for_each_entry(query, &ib_nl_request_list, list) {
  670. if (delta < 0 && abs_delta > query->timeout)
  671. query->timeout = 0;
  672. else
  673. query->timeout += delta;
  674. /* Get the new delay from the first entry */
  675. if (!delay) {
  676. delay = query->timeout - jiffies;
  677. if (delay <= 0)
  678. delay = 1;
  679. }
  680. }
  681. if (delay)
  682. mod_delayed_work(ib_nl_wq, &ib_nl_timed_work,
  683. (unsigned long)delay);
  684. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  685. }
  686. settimeout_out:
  687. return skb->len;
  688. }
  689. static inline int ib_nl_is_good_resolve_resp(const struct nlmsghdr *nlh)
  690. {
  691. struct nlattr *tb[LS_NLA_TYPE_MAX];
  692. int ret;
  693. if (nlh->nlmsg_flags & RDMA_NL_LS_F_ERR)
  694. return 0;
  695. ret = nla_parse(tb, LS_NLA_TYPE_MAX - 1, nlmsg_data(nlh),
  696. nlmsg_len(nlh), ib_nl_policy);
  697. if (ret)
  698. return 0;
  699. return 1;
  700. }
  701. static int ib_nl_handle_resolve_resp(struct sk_buff *skb,
  702. struct netlink_callback *cb)
  703. {
  704. const struct nlmsghdr *nlh = (struct nlmsghdr *)cb->nlh;
  705. unsigned long flags;
  706. struct ib_sa_query *query;
  707. struct ib_mad_send_buf *send_buf;
  708. struct ib_mad_send_wc mad_send_wc;
  709. int found = 0;
  710. int ret;
  711. if (!netlink_capable(skb, CAP_NET_ADMIN))
  712. return -EPERM;
  713. spin_lock_irqsave(&ib_nl_request_lock, flags);
  714. list_for_each_entry(query, &ib_nl_request_list, list) {
  715. /*
  716. * If the query is cancelled, let the timeout routine
  717. * take care of it.
  718. */
  719. if (nlh->nlmsg_seq == query->seq) {
  720. found = !ib_sa_query_cancelled(query);
  721. if (found)
  722. list_del(&query->list);
  723. break;
  724. }
  725. }
  726. if (!found) {
  727. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  728. goto resp_out;
  729. }
  730. send_buf = query->mad_buf;
  731. if (!ib_nl_is_good_resolve_resp(nlh)) {
  732. /* if the result is a failure, send out the packet via IB */
  733. ib_sa_disable_local_svc(query);
  734. ret = ib_post_send_mad(query->mad_buf, NULL);
  735. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  736. if (ret) {
  737. mad_send_wc.send_buf = send_buf;
  738. mad_send_wc.status = IB_WC_GENERAL_ERR;
  739. send_handler(query->port->agent, &mad_send_wc);
  740. }
  741. } else {
  742. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  743. ib_nl_process_good_resolve_rsp(query, nlh);
  744. }
  745. resp_out:
  746. return skb->len;
  747. }
  748. static struct ibnl_client_cbs ib_sa_cb_table[] = {
  749. [RDMA_NL_LS_OP_RESOLVE] = {
  750. .dump = ib_nl_handle_resolve_resp,
  751. .module = THIS_MODULE },
  752. [RDMA_NL_LS_OP_SET_TIMEOUT] = {
  753. .dump = ib_nl_handle_set_timeout,
  754. .module = THIS_MODULE },
  755. };
  756. static void free_sm_ah(struct kref *kref)
  757. {
  758. struct ib_sa_sm_ah *sm_ah = container_of(kref, struct ib_sa_sm_ah, ref);
  759. ib_destroy_ah(sm_ah->ah);
  760. kfree(sm_ah);
  761. }
  762. static void update_sm_ah(struct work_struct *work)
  763. {
  764. struct ib_sa_port *port =
  765. container_of(work, struct ib_sa_port, update_task);
  766. struct ib_sa_sm_ah *new_ah;
  767. struct ib_port_attr port_attr;
  768. struct ib_ah_attr ah_attr;
  769. if (ib_query_port(port->agent->device, port->port_num, &port_attr)) {
  770. printk(KERN_WARNING "Couldn't query port\n");
  771. return;
  772. }
  773. new_ah = kmalloc(sizeof *new_ah, GFP_KERNEL);
  774. if (!new_ah) {
  775. printk(KERN_WARNING "Couldn't allocate new SM AH\n");
  776. return;
  777. }
  778. kref_init(&new_ah->ref);
  779. new_ah->src_path_mask = (1 << port_attr.lmc) - 1;
  780. new_ah->pkey_index = 0;
  781. if (ib_find_pkey(port->agent->device, port->port_num,
  782. IB_DEFAULT_PKEY_FULL, &new_ah->pkey_index))
  783. printk(KERN_ERR "Couldn't find index for default PKey\n");
  784. memset(&ah_attr, 0, sizeof ah_attr);
  785. ah_attr.dlid = port_attr.sm_lid;
  786. ah_attr.sl = port_attr.sm_sl;
  787. ah_attr.port_num = port->port_num;
  788. new_ah->ah = ib_create_ah(port->agent->qp->pd, &ah_attr);
  789. if (IS_ERR(new_ah->ah)) {
  790. printk(KERN_WARNING "Couldn't create new SM AH\n");
  791. kfree(new_ah);
  792. return;
  793. }
  794. spin_lock_irq(&port->ah_lock);
  795. if (port->sm_ah)
  796. kref_put(&port->sm_ah->ref, free_sm_ah);
  797. port->sm_ah = new_ah;
  798. spin_unlock_irq(&port->ah_lock);
  799. }
  800. static void ib_sa_event(struct ib_event_handler *handler, struct ib_event *event)
  801. {
  802. if (event->event == IB_EVENT_PORT_ERR ||
  803. event->event == IB_EVENT_PORT_ACTIVE ||
  804. event->event == IB_EVENT_LID_CHANGE ||
  805. event->event == IB_EVENT_PKEY_CHANGE ||
  806. event->event == IB_EVENT_SM_CHANGE ||
  807. event->event == IB_EVENT_CLIENT_REREGISTER) {
  808. unsigned long flags;
  809. struct ib_sa_device *sa_dev =
  810. container_of(handler, typeof(*sa_dev), event_handler);
  811. struct ib_sa_port *port =
  812. &sa_dev->port[event->element.port_num - sa_dev->start_port];
  813. if (!rdma_cap_ib_sa(handler->device, port->port_num))
  814. return;
  815. spin_lock_irqsave(&port->ah_lock, flags);
  816. if (port->sm_ah)
  817. kref_put(&port->sm_ah->ref, free_sm_ah);
  818. port->sm_ah = NULL;
  819. spin_unlock_irqrestore(&port->ah_lock, flags);
  820. queue_work(ib_wq, &sa_dev->port[event->element.port_num -
  821. sa_dev->start_port].update_task);
  822. }
  823. }
  824. void ib_sa_register_client(struct ib_sa_client *client)
  825. {
  826. atomic_set(&client->users, 1);
  827. init_completion(&client->comp);
  828. }
  829. EXPORT_SYMBOL(ib_sa_register_client);
  830. void ib_sa_unregister_client(struct ib_sa_client *client)
  831. {
  832. ib_sa_client_put(client);
  833. wait_for_completion(&client->comp);
  834. }
  835. EXPORT_SYMBOL(ib_sa_unregister_client);
  836. /**
  837. * ib_sa_cancel_query - try to cancel an SA query
  838. * @id:ID of query to cancel
  839. * @query:query pointer to cancel
  840. *
  841. * Try to cancel an SA query. If the id and query don't match up or
  842. * the query has already completed, nothing is done. Otherwise the
  843. * query is canceled and will complete with a status of -EINTR.
  844. */
  845. void ib_sa_cancel_query(int id, struct ib_sa_query *query)
  846. {
  847. unsigned long flags;
  848. struct ib_mad_agent *agent;
  849. struct ib_mad_send_buf *mad_buf;
  850. spin_lock_irqsave(&idr_lock, flags);
  851. if (idr_find(&query_idr, id) != query) {
  852. spin_unlock_irqrestore(&idr_lock, flags);
  853. return;
  854. }
  855. agent = query->port->agent;
  856. mad_buf = query->mad_buf;
  857. spin_unlock_irqrestore(&idr_lock, flags);
  858. /*
  859. * If the query is still on the netlink request list, schedule
  860. * it to be cancelled by the timeout routine. Otherwise, it has been
  861. * sent to the MAD layer and has to be cancelled from there.
  862. */
  863. if (!ib_nl_cancel_request(query))
  864. ib_cancel_mad(agent, mad_buf);
  865. }
  866. EXPORT_SYMBOL(ib_sa_cancel_query);
  867. static u8 get_src_path_mask(struct ib_device *device, u8 port_num)
  868. {
  869. struct ib_sa_device *sa_dev;
  870. struct ib_sa_port *port;
  871. unsigned long flags;
  872. u8 src_path_mask;
  873. sa_dev = ib_get_client_data(device, &sa_client);
  874. if (!sa_dev)
  875. return 0x7f;
  876. port = &sa_dev->port[port_num - sa_dev->start_port];
  877. spin_lock_irqsave(&port->ah_lock, flags);
  878. src_path_mask = port->sm_ah ? port->sm_ah->src_path_mask : 0x7f;
  879. spin_unlock_irqrestore(&port->ah_lock, flags);
  880. return src_path_mask;
  881. }
  882. int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
  883. struct ib_sa_path_rec *rec, struct ib_ah_attr *ah_attr)
  884. {
  885. int ret;
  886. u16 gid_index;
  887. int force_grh;
  888. memset(ah_attr, 0, sizeof *ah_attr);
  889. ah_attr->dlid = be16_to_cpu(rec->dlid);
  890. ah_attr->sl = rec->sl;
  891. ah_attr->src_path_bits = be16_to_cpu(rec->slid) &
  892. get_src_path_mask(device, port_num);
  893. ah_attr->port_num = port_num;
  894. ah_attr->static_rate = rec->rate;
  895. force_grh = rdma_cap_eth_ah(device, port_num);
  896. if (rec->hop_limit > 1 || force_grh) {
  897. struct net_device *ndev = ib_get_ndev_from_path(rec);
  898. ah_attr->ah_flags = IB_AH_GRH;
  899. ah_attr->grh.dgid = rec->dgid;
  900. ret = ib_find_cached_gid(device, &rec->sgid, ndev, &port_num,
  901. &gid_index);
  902. if (ret) {
  903. if (ndev)
  904. dev_put(ndev);
  905. return ret;
  906. }
  907. ah_attr->grh.sgid_index = gid_index;
  908. ah_attr->grh.flow_label = be32_to_cpu(rec->flow_label);
  909. ah_attr->grh.hop_limit = rec->hop_limit;
  910. ah_attr->grh.traffic_class = rec->traffic_class;
  911. if (ndev)
  912. dev_put(ndev);
  913. }
  914. if (force_grh) {
  915. memcpy(ah_attr->dmac, rec->dmac, ETH_ALEN);
  916. }
  917. return 0;
  918. }
  919. EXPORT_SYMBOL(ib_init_ah_from_path);
  920. static int alloc_mad(struct ib_sa_query *query, gfp_t gfp_mask)
  921. {
  922. unsigned long flags;
  923. spin_lock_irqsave(&query->port->ah_lock, flags);
  924. if (!query->port->sm_ah) {
  925. spin_unlock_irqrestore(&query->port->ah_lock, flags);
  926. return -EAGAIN;
  927. }
  928. kref_get(&query->port->sm_ah->ref);
  929. query->sm_ah = query->port->sm_ah;
  930. spin_unlock_irqrestore(&query->port->ah_lock, flags);
  931. query->mad_buf = ib_create_send_mad(query->port->agent, 1,
  932. query->sm_ah->pkey_index,
  933. 0, IB_MGMT_SA_HDR, IB_MGMT_SA_DATA,
  934. gfp_mask,
  935. IB_MGMT_BASE_VERSION);
  936. if (IS_ERR(query->mad_buf)) {
  937. kref_put(&query->sm_ah->ref, free_sm_ah);
  938. return -ENOMEM;
  939. }
  940. query->mad_buf->ah = query->sm_ah->ah;
  941. return 0;
  942. }
  943. static void free_mad(struct ib_sa_query *query)
  944. {
  945. ib_free_send_mad(query->mad_buf);
  946. kref_put(&query->sm_ah->ref, free_sm_ah);
  947. }
  948. static void init_mad(struct ib_sa_mad *mad, struct ib_mad_agent *agent)
  949. {
  950. unsigned long flags;
  951. memset(mad, 0, sizeof *mad);
  952. mad->mad_hdr.base_version = IB_MGMT_BASE_VERSION;
  953. mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
  954. mad->mad_hdr.class_version = IB_SA_CLASS_VERSION;
  955. spin_lock_irqsave(&tid_lock, flags);
  956. mad->mad_hdr.tid =
  957. cpu_to_be64(((u64) agent->hi_tid) << 32 | tid++);
  958. spin_unlock_irqrestore(&tid_lock, flags);
  959. }
  960. static int send_mad(struct ib_sa_query *query, int timeout_ms, gfp_t gfp_mask)
  961. {
  962. bool preload = !!(gfp_mask & __GFP_WAIT);
  963. unsigned long flags;
  964. int ret, id;
  965. if (preload)
  966. idr_preload(gfp_mask);
  967. spin_lock_irqsave(&idr_lock, flags);
  968. id = idr_alloc(&query_idr, query, 0, 0, GFP_NOWAIT);
  969. spin_unlock_irqrestore(&idr_lock, flags);
  970. if (preload)
  971. idr_preload_end();
  972. if (id < 0)
  973. return id;
  974. query->mad_buf->timeout_ms = timeout_ms;
  975. query->mad_buf->context[0] = query;
  976. query->id = id;
  977. if (query->flags & IB_SA_ENABLE_LOCAL_SERVICE) {
  978. if (!ibnl_chk_listeners(RDMA_NL_GROUP_LS)) {
  979. if (!ib_nl_make_request(query))
  980. return id;
  981. }
  982. ib_sa_disable_local_svc(query);
  983. }
  984. ret = ib_post_send_mad(query->mad_buf, NULL);
  985. if (ret) {
  986. spin_lock_irqsave(&idr_lock, flags);
  987. idr_remove(&query_idr, id);
  988. spin_unlock_irqrestore(&idr_lock, flags);
  989. }
  990. /*
  991. * It's not safe to dereference query any more, because the
  992. * send may already have completed and freed the query in
  993. * another context.
  994. */
  995. return ret ? ret : id;
  996. }
  997. void ib_sa_unpack_path(void *attribute, struct ib_sa_path_rec *rec)
  998. {
  999. ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table), attribute, rec);
  1000. }
  1001. EXPORT_SYMBOL(ib_sa_unpack_path);
  1002. void ib_sa_pack_path(struct ib_sa_path_rec *rec, void *attribute)
  1003. {
  1004. ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, attribute);
  1005. }
  1006. EXPORT_SYMBOL(ib_sa_pack_path);
  1007. static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
  1008. int status,
  1009. struct ib_sa_mad *mad)
  1010. {
  1011. struct ib_sa_path_query *query =
  1012. container_of(sa_query, struct ib_sa_path_query, sa_query);
  1013. if (mad) {
  1014. struct ib_sa_path_rec rec;
  1015. ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table),
  1016. mad->data, &rec);
  1017. rec.vlan_id = 0xffff;
  1018. rec.net = NULL;
  1019. rec.ifindex = 0;
  1020. memset(rec.dmac, 0, ETH_ALEN);
  1021. memset(rec.smac, 0, ETH_ALEN);
  1022. query->callback(status, &rec, query->context);
  1023. } else
  1024. query->callback(status, NULL, query->context);
  1025. }
  1026. static void ib_sa_path_rec_release(struct ib_sa_query *sa_query)
  1027. {
  1028. kfree(container_of(sa_query, struct ib_sa_path_query, sa_query));
  1029. }
  1030. /**
  1031. * ib_sa_path_rec_get - Start a Path get query
  1032. * @client:SA client
  1033. * @device:device to send query on
  1034. * @port_num: port number to send query on
  1035. * @rec:Path Record to send in query
  1036. * @comp_mask:component mask to send in query
  1037. * @timeout_ms:time to wait for response
  1038. * @gfp_mask:GFP mask to use for internal allocations
  1039. * @callback:function called when query completes, times out or is
  1040. * canceled
  1041. * @context:opaque user context passed to callback
  1042. * @sa_query:query context, used to cancel query
  1043. *
  1044. * Send a Path Record Get query to the SA to look up a path. The
  1045. * callback function will be called when the query completes (or
  1046. * fails); status is 0 for a successful response, -EINTR if the query
  1047. * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
  1048. * occurred sending the query. The resp parameter of the callback is
  1049. * only valid if status is 0.
  1050. *
  1051. * If the return value of ib_sa_path_rec_get() is negative, it is an
  1052. * error code. Otherwise it is a query ID that can be used to cancel
  1053. * the query.
  1054. */
  1055. int ib_sa_path_rec_get(struct ib_sa_client *client,
  1056. struct ib_device *device, u8 port_num,
  1057. struct ib_sa_path_rec *rec,
  1058. ib_sa_comp_mask comp_mask,
  1059. int timeout_ms, gfp_t gfp_mask,
  1060. void (*callback)(int status,
  1061. struct ib_sa_path_rec *resp,
  1062. void *context),
  1063. void *context,
  1064. struct ib_sa_query **sa_query)
  1065. {
  1066. struct ib_sa_path_query *query;
  1067. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1068. struct ib_sa_port *port;
  1069. struct ib_mad_agent *agent;
  1070. struct ib_sa_mad *mad;
  1071. int ret;
  1072. if (!sa_dev)
  1073. return -ENODEV;
  1074. port = &sa_dev->port[port_num - sa_dev->start_port];
  1075. agent = port->agent;
  1076. query = kzalloc(sizeof(*query), gfp_mask);
  1077. if (!query)
  1078. return -ENOMEM;
  1079. query->sa_query.port = port;
  1080. ret = alloc_mad(&query->sa_query, gfp_mask);
  1081. if (ret)
  1082. goto err1;
  1083. ib_sa_client_get(client);
  1084. query->sa_query.client = client;
  1085. query->callback = callback;
  1086. query->context = context;
  1087. mad = query->sa_query.mad_buf->mad;
  1088. init_mad(mad, agent);
  1089. query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL;
  1090. query->sa_query.release = ib_sa_path_rec_release;
  1091. mad->mad_hdr.method = IB_MGMT_METHOD_GET;
  1092. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_PATH_REC);
  1093. mad->sa_hdr.comp_mask = comp_mask;
  1094. ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, mad->data);
  1095. *sa_query = &query->sa_query;
  1096. query->sa_query.flags |= IB_SA_ENABLE_LOCAL_SERVICE;
  1097. query->sa_query.mad_buf->context[1] = rec;
  1098. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1099. if (ret < 0)
  1100. goto err2;
  1101. return ret;
  1102. err2:
  1103. *sa_query = NULL;
  1104. ib_sa_client_put(query->sa_query.client);
  1105. free_mad(&query->sa_query);
  1106. err1:
  1107. kfree(query);
  1108. return ret;
  1109. }
  1110. EXPORT_SYMBOL(ib_sa_path_rec_get);
  1111. static void ib_sa_service_rec_callback(struct ib_sa_query *sa_query,
  1112. int status,
  1113. struct ib_sa_mad *mad)
  1114. {
  1115. struct ib_sa_service_query *query =
  1116. container_of(sa_query, struct ib_sa_service_query, sa_query);
  1117. if (mad) {
  1118. struct ib_sa_service_rec rec;
  1119. ib_unpack(service_rec_table, ARRAY_SIZE(service_rec_table),
  1120. mad->data, &rec);
  1121. query->callback(status, &rec, query->context);
  1122. } else
  1123. query->callback(status, NULL, query->context);
  1124. }
  1125. static void ib_sa_service_rec_release(struct ib_sa_query *sa_query)
  1126. {
  1127. kfree(container_of(sa_query, struct ib_sa_service_query, sa_query));
  1128. }
  1129. /**
  1130. * ib_sa_service_rec_query - Start Service Record operation
  1131. * @client:SA client
  1132. * @device:device to send request on
  1133. * @port_num: port number to send request on
  1134. * @method:SA method - should be get, set, or delete
  1135. * @rec:Service Record to send in request
  1136. * @comp_mask:component mask to send in request
  1137. * @timeout_ms:time to wait for response
  1138. * @gfp_mask:GFP mask to use for internal allocations
  1139. * @callback:function called when request completes, times out or is
  1140. * canceled
  1141. * @context:opaque user context passed to callback
  1142. * @sa_query:request context, used to cancel request
  1143. *
  1144. * Send a Service Record set/get/delete to the SA to register,
  1145. * unregister or query a service record.
  1146. * The callback function will be called when the request completes (or
  1147. * fails); status is 0 for a successful response, -EINTR if the query
  1148. * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
  1149. * occurred sending the query. The resp parameter of the callback is
  1150. * only valid if status is 0.
  1151. *
  1152. * If the return value of ib_sa_service_rec_query() is negative, it is an
  1153. * error code. Otherwise it is a request ID that can be used to cancel
  1154. * the query.
  1155. */
  1156. int ib_sa_service_rec_query(struct ib_sa_client *client,
  1157. struct ib_device *device, u8 port_num, u8 method,
  1158. struct ib_sa_service_rec *rec,
  1159. ib_sa_comp_mask comp_mask,
  1160. int timeout_ms, gfp_t gfp_mask,
  1161. void (*callback)(int status,
  1162. struct ib_sa_service_rec *resp,
  1163. void *context),
  1164. void *context,
  1165. struct ib_sa_query **sa_query)
  1166. {
  1167. struct ib_sa_service_query *query;
  1168. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1169. struct ib_sa_port *port;
  1170. struct ib_mad_agent *agent;
  1171. struct ib_sa_mad *mad;
  1172. int ret;
  1173. if (!sa_dev)
  1174. return -ENODEV;
  1175. port = &sa_dev->port[port_num - sa_dev->start_port];
  1176. agent = port->agent;
  1177. if (method != IB_MGMT_METHOD_GET &&
  1178. method != IB_MGMT_METHOD_SET &&
  1179. method != IB_SA_METHOD_DELETE)
  1180. return -EINVAL;
  1181. query = kzalloc(sizeof(*query), gfp_mask);
  1182. if (!query)
  1183. return -ENOMEM;
  1184. query->sa_query.port = port;
  1185. ret = alloc_mad(&query->sa_query, gfp_mask);
  1186. if (ret)
  1187. goto err1;
  1188. ib_sa_client_get(client);
  1189. query->sa_query.client = client;
  1190. query->callback = callback;
  1191. query->context = context;
  1192. mad = query->sa_query.mad_buf->mad;
  1193. init_mad(mad, agent);
  1194. query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL;
  1195. query->sa_query.release = ib_sa_service_rec_release;
  1196. mad->mad_hdr.method = method;
  1197. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_SERVICE_REC);
  1198. mad->sa_hdr.comp_mask = comp_mask;
  1199. ib_pack(service_rec_table, ARRAY_SIZE(service_rec_table),
  1200. rec, mad->data);
  1201. *sa_query = &query->sa_query;
  1202. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1203. if (ret < 0)
  1204. goto err2;
  1205. return ret;
  1206. err2:
  1207. *sa_query = NULL;
  1208. ib_sa_client_put(query->sa_query.client);
  1209. free_mad(&query->sa_query);
  1210. err1:
  1211. kfree(query);
  1212. return ret;
  1213. }
  1214. EXPORT_SYMBOL(ib_sa_service_rec_query);
  1215. static void ib_sa_mcmember_rec_callback(struct ib_sa_query *sa_query,
  1216. int status,
  1217. struct ib_sa_mad *mad)
  1218. {
  1219. struct ib_sa_mcmember_query *query =
  1220. container_of(sa_query, struct ib_sa_mcmember_query, sa_query);
  1221. if (mad) {
  1222. struct ib_sa_mcmember_rec rec;
  1223. ib_unpack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
  1224. mad->data, &rec);
  1225. query->callback(status, &rec, query->context);
  1226. } else
  1227. query->callback(status, NULL, query->context);
  1228. }
  1229. static void ib_sa_mcmember_rec_release(struct ib_sa_query *sa_query)
  1230. {
  1231. kfree(container_of(sa_query, struct ib_sa_mcmember_query, sa_query));
  1232. }
  1233. int ib_sa_mcmember_rec_query(struct ib_sa_client *client,
  1234. struct ib_device *device, u8 port_num,
  1235. u8 method,
  1236. struct ib_sa_mcmember_rec *rec,
  1237. ib_sa_comp_mask comp_mask,
  1238. int timeout_ms, gfp_t gfp_mask,
  1239. void (*callback)(int status,
  1240. struct ib_sa_mcmember_rec *resp,
  1241. void *context),
  1242. void *context,
  1243. struct ib_sa_query **sa_query)
  1244. {
  1245. struct ib_sa_mcmember_query *query;
  1246. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1247. struct ib_sa_port *port;
  1248. struct ib_mad_agent *agent;
  1249. struct ib_sa_mad *mad;
  1250. int ret;
  1251. if (!sa_dev)
  1252. return -ENODEV;
  1253. port = &sa_dev->port[port_num - sa_dev->start_port];
  1254. agent = port->agent;
  1255. query = kzalloc(sizeof(*query), gfp_mask);
  1256. if (!query)
  1257. return -ENOMEM;
  1258. query->sa_query.port = port;
  1259. ret = alloc_mad(&query->sa_query, gfp_mask);
  1260. if (ret)
  1261. goto err1;
  1262. ib_sa_client_get(client);
  1263. query->sa_query.client = client;
  1264. query->callback = callback;
  1265. query->context = context;
  1266. mad = query->sa_query.mad_buf->mad;
  1267. init_mad(mad, agent);
  1268. query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL;
  1269. query->sa_query.release = ib_sa_mcmember_rec_release;
  1270. mad->mad_hdr.method = method;
  1271. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
  1272. mad->sa_hdr.comp_mask = comp_mask;
  1273. ib_pack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
  1274. rec, mad->data);
  1275. *sa_query = &query->sa_query;
  1276. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1277. if (ret < 0)
  1278. goto err2;
  1279. return ret;
  1280. err2:
  1281. *sa_query = NULL;
  1282. ib_sa_client_put(query->sa_query.client);
  1283. free_mad(&query->sa_query);
  1284. err1:
  1285. kfree(query);
  1286. return ret;
  1287. }
  1288. /* Support GuidInfoRecord */
  1289. static void ib_sa_guidinfo_rec_callback(struct ib_sa_query *sa_query,
  1290. int status,
  1291. struct ib_sa_mad *mad)
  1292. {
  1293. struct ib_sa_guidinfo_query *query =
  1294. container_of(sa_query, struct ib_sa_guidinfo_query, sa_query);
  1295. if (mad) {
  1296. struct ib_sa_guidinfo_rec rec;
  1297. ib_unpack(guidinfo_rec_table, ARRAY_SIZE(guidinfo_rec_table),
  1298. mad->data, &rec);
  1299. query->callback(status, &rec, query->context);
  1300. } else
  1301. query->callback(status, NULL, query->context);
  1302. }
  1303. static void ib_sa_guidinfo_rec_release(struct ib_sa_query *sa_query)
  1304. {
  1305. kfree(container_of(sa_query, struct ib_sa_guidinfo_query, sa_query));
  1306. }
  1307. int ib_sa_guid_info_rec_query(struct ib_sa_client *client,
  1308. struct ib_device *device, u8 port_num,
  1309. struct ib_sa_guidinfo_rec *rec,
  1310. ib_sa_comp_mask comp_mask, u8 method,
  1311. int timeout_ms, gfp_t gfp_mask,
  1312. void (*callback)(int status,
  1313. struct ib_sa_guidinfo_rec *resp,
  1314. void *context),
  1315. void *context,
  1316. struct ib_sa_query **sa_query)
  1317. {
  1318. struct ib_sa_guidinfo_query *query;
  1319. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1320. struct ib_sa_port *port;
  1321. struct ib_mad_agent *agent;
  1322. struct ib_sa_mad *mad;
  1323. int ret;
  1324. if (!sa_dev)
  1325. return -ENODEV;
  1326. if (method != IB_MGMT_METHOD_GET &&
  1327. method != IB_MGMT_METHOD_SET &&
  1328. method != IB_SA_METHOD_DELETE) {
  1329. return -EINVAL;
  1330. }
  1331. port = &sa_dev->port[port_num - sa_dev->start_port];
  1332. agent = port->agent;
  1333. query = kzalloc(sizeof(*query), gfp_mask);
  1334. if (!query)
  1335. return -ENOMEM;
  1336. query->sa_query.port = port;
  1337. ret = alloc_mad(&query->sa_query, gfp_mask);
  1338. if (ret)
  1339. goto err1;
  1340. ib_sa_client_get(client);
  1341. query->sa_query.client = client;
  1342. query->callback = callback;
  1343. query->context = context;
  1344. mad = query->sa_query.mad_buf->mad;
  1345. init_mad(mad, agent);
  1346. query->sa_query.callback = callback ? ib_sa_guidinfo_rec_callback : NULL;
  1347. query->sa_query.release = ib_sa_guidinfo_rec_release;
  1348. mad->mad_hdr.method = method;
  1349. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_GUID_INFO_REC);
  1350. mad->sa_hdr.comp_mask = comp_mask;
  1351. ib_pack(guidinfo_rec_table, ARRAY_SIZE(guidinfo_rec_table), rec,
  1352. mad->data);
  1353. *sa_query = &query->sa_query;
  1354. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1355. if (ret < 0)
  1356. goto err2;
  1357. return ret;
  1358. err2:
  1359. *sa_query = NULL;
  1360. ib_sa_client_put(query->sa_query.client);
  1361. free_mad(&query->sa_query);
  1362. err1:
  1363. kfree(query);
  1364. return ret;
  1365. }
  1366. EXPORT_SYMBOL(ib_sa_guid_info_rec_query);
  1367. static void send_handler(struct ib_mad_agent *agent,
  1368. struct ib_mad_send_wc *mad_send_wc)
  1369. {
  1370. struct ib_sa_query *query = mad_send_wc->send_buf->context[0];
  1371. unsigned long flags;
  1372. if (query->callback)
  1373. switch (mad_send_wc->status) {
  1374. case IB_WC_SUCCESS:
  1375. /* No callback -- already got recv */
  1376. break;
  1377. case IB_WC_RESP_TIMEOUT_ERR:
  1378. query->callback(query, -ETIMEDOUT, NULL);
  1379. break;
  1380. case IB_WC_WR_FLUSH_ERR:
  1381. query->callback(query, -EINTR, NULL);
  1382. break;
  1383. default:
  1384. query->callback(query, -EIO, NULL);
  1385. break;
  1386. }
  1387. spin_lock_irqsave(&idr_lock, flags);
  1388. idr_remove(&query_idr, query->id);
  1389. spin_unlock_irqrestore(&idr_lock, flags);
  1390. free_mad(query);
  1391. ib_sa_client_put(query->client);
  1392. query->release(query);
  1393. }
  1394. static void recv_handler(struct ib_mad_agent *mad_agent,
  1395. struct ib_mad_recv_wc *mad_recv_wc)
  1396. {
  1397. struct ib_sa_query *query;
  1398. struct ib_mad_send_buf *mad_buf;
  1399. mad_buf = (void *) (unsigned long) mad_recv_wc->wc->wr_id;
  1400. query = mad_buf->context[0];
  1401. if (query->callback) {
  1402. if (mad_recv_wc->wc->status == IB_WC_SUCCESS)
  1403. query->callback(query,
  1404. mad_recv_wc->recv_buf.mad->mad_hdr.status ?
  1405. -EINVAL : 0,
  1406. (struct ib_sa_mad *) mad_recv_wc->recv_buf.mad);
  1407. else
  1408. query->callback(query, -EIO, NULL);
  1409. }
  1410. ib_free_recv_mad(mad_recv_wc);
  1411. }
  1412. static void ib_sa_add_one(struct ib_device *device)
  1413. {
  1414. struct ib_sa_device *sa_dev;
  1415. int s, e, i;
  1416. int count = 0;
  1417. s = rdma_start_port(device);
  1418. e = rdma_end_port(device);
  1419. sa_dev = kzalloc(sizeof *sa_dev +
  1420. (e - s + 1) * sizeof (struct ib_sa_port),
  1421. GFP_KERNEL);
  1422. if (!sa_dev)
  1423. return;
  1424. sa_dev->start_port = s;
  1425. sa_dev->end_port = e;
  1426. for (i = 0; i <= e - s; ++i) {
  1427. spin_lock_init(&sa_dev->port[i].ah_lock);
  1428. if (!rdma_cap_ib_sa(device, i + 1))
  1429. continue;
  1430. sa_dev->port[i].sm_ah = NULL;
  1431. sa_dev->port[i].port_num = i + s;
  1432. sa_dev->port[i].agent =
  1433. ib_register_mad_agent(device, i + s, IB_QPT_GSI,
  1434. NULL, 0, send_handler,
  1435. recv_handler, sa_dev, 0);
  1436. if (IS_ERR(sa_dev->port[i].agent))
  1437. goto err;
  1438. INIT_WORK(&sa_dev->port[i].update_task, update_sm_ah);
  1439. count++;
  1440. }
  1441. if (!count)
  1442. goto free;
  1443. ib_set_client_data(device, &sa_client, sa_dev);
  1444. /*
  1445. * We register our event handler after everything is set up,
  1446. * and then update our cached info after the event handler is
  1447. * registered to avoid any problems if a port changes state
  1448. * during our initialization.
  1449. */
  1450. INIT_IB_EVENT_HANDLER(&sa_dev->event_handler, device, ib_sa_event);
  1451. if (ib_register_event_handler(&sa_dev->event_handler))
  1452. goto err;
  1453. for (i = 0; i <= e - s; ++i) {
  1454. if (rdma_cap_ib_sa(device, i + 1))
  1455. update_sm_ah(&sa_dev->port[i].update_task);
  1456. }
  1457. return;
  1458. err:
  1459. while (--i >= 0) {
  1460. if (rdma_cap_ib_sa(device, i + 1))
  1461. ib_unregister_mad_agent(sa_dev->port[i].agent);
  1462. }
  1463. free:
  1464. kfree(sa_dev);
  1465. return;
  1466. }
  1467. static void ib_sa_remove_one(struct ib_device *device, void *client_data)
  1468. {
  1469. struct ib_sa_device *sa_dev = client_data;
  1470. int i;
  1471. if (!sa_dev)
  1472. return;
  1473. ib_unregister_event_handler(&sa_dev->event_handler);
  1474. flush_workqueue(ib_wq);
  1475. for (i = 0; i <= sa_dev->end_port - sa_dev->start_port; ++i) {
  1476. if (rdma_cap_ib_sa(device, i + 1)) {
  1477. ib_unregister_mad_agent(sa_dev->port[i].agent);
  1478. if (sa_dev->port[i].sm_ah)
  1479. kref_put(&sa_dev->port[i].sm_ah->ref, free_sm_ah);
  1480. }
  1481. }
  1482. kfree(sa_dev);
  1483. }
  1484. static int __init ib_sa_init(void)
  1485. {
  1486. int ret;
  1487. get_random_bytes(&tid, sizeof tid);
  1488. atomic_set(&ib_nl_sa_request_seq, 0);
  1489. ret = ib_register_client(&sa_client);
  1490. if (ret) {
  1491. printk(KERN_ERR "Couldn't register ib_sa client\n");
  1492. goto err1;
  1493. }
  1494. ret = mcast_init();
  1495. if (ret) {
  1496. printk(KERN_ERR "Couldn't initialize multicast handling\n");
  1497. goto err2;
  1498. }
  1499. ib_nl_wq = create_singlethread_workqueue("ib_nl_sa_wq");
  1500. if (!ib_nl_wq) {
  1501. ret = -ENOMEM;
  1502. goto err3;
  1503. }
  1504. if (ibnl_add_client(RDMA_NL_LS, RDMA_NL_LS_NUM_OPS,
  1505. ib_sa_cb_table)) {
  1506. pr_err("Failed to add netlink callback\n");
  1507. ret = -EINVAL;
  1508. goto err4;
  1509. }
  1510. INIT_DELAYED_WORK(&ib_nl_timed_work, ib_nl_request_timeout);
  1511. return 0;
  1512. err4:
  1513. destroy_workqueue(ib_nl_wq);
  1514. err3:
  1515. mcast_cleanup();
  1516. err2:
  1517. ib_unregister_client(&sa_client);
  1518. err1:
  1519. return ret;
  1520. }
  1521. static void __exit ib_sa_cleanup(void)
  1522. {
  1523. ibnl_remove_client(RDMA_NL_LS);
  1524. cancel_delayed_work(&ib_nl_timed_work);
  1525. flush_workqueue(ib_nl_wq);
  1526. destroy_workqueue(ib_nl_wq);
  1527. mcast_cleanup();
  1528. ib_unregister_client(&sa_client);
  1529. idr_destroy(&query_idr);
  1530. }
  1531. module_init(ib_sa_init);
  1532. module_exit(ib_sa_cleanup);