sa_query.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  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. ah_attr->ah_flags = IB_AH_GRH;
  898. ah_attr->grh.dgid = rec->dgid;
  899. ret = ib_find_cached_gid(device, &rec->sgid, &port_num,
  900. &gid_index);
  901. if (ret)
  902. return ret;
  903. ah_attr->grh.sgid_index = gid_index;
  904. ah_attr->grh.flow_label = be32_to_cpu(rec->flow_label);
  905. ah_attr->grh.hop_limit = rec->hop_limit;
  906. ah_attr->grh.traffic_class = rec->traffic_class;
  907. }
  908. if (force_grh) {
  909. memcpy(ah_attr->dmac, rec->dmac, ETH_ALEN);
  910. ah_attr->vlan_id = rec->vlan_id;
  911. } else {
  912. ah_attr->vlan_id = 0xffff;
  913. }
  914. return 0;
  915. }
  916. EXPORT_SYMBOL(ib_init_ah_from_path);
  917. static int alloc_mad(struct ib_sa_query *query, gfp_t gfp_mask)
  918. {
  919. unsigned long flags;
  920. spin_lock_irqsave(&query->port->ah_lock, flags);
  921. if (!query->port->sm_ah) {
  922. spin_unlock_irqrestore(&query->port->ah_lock, flags);
  923. return -EAGAIN;
  924. }
  925. kref_get(&query->port->sm_ah->ref);
  926. query->sm_ah = query->port->sm_ah;
  927. spin_unlock_irqrestore(&query->port->ah_lock, flags);
  928. query->mad_buf = ib_create_send_mad(query->port->agent, 1,
  929. query->sm_ah->pkey_index,
  930. 0, IB_MGMT_SA_HDR, IB_MGMT_SA_DATA,
  931. gfp_mask,
  932. IB_MGMT_BASE_VERSION);
  933. if (IS_ERR(query->mad_buf)) {
  934. kref_put(&query->sm_ah->ref, free_sm_ah);
  935. return -ENOMEM;
  936. }
  937. query->mad_buf->ah = query->sm_ah->ah;
  938. return 0;
  939. }
  940. static void free_mad(struct ib_sa_query *query)
  941. {
  942. ib_free_send_mad(query->mad_buf);
  943. kref_put(&query->sm_ah->ref, free_sm_ah);
  944. }
  945. static void init_mad(struct ib_sa_mad *mad, struct ib_mad_agent *agent)
  946. {
  947. unsigned long flags;
  948. memset(mad, 0, sizeof *mad);
  949. mad->mad_hdr.base_version = IB_MGMT_BASE_VERSION;
  950. mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
  951. mad->mad_hdr.class_version = IB_SA_CLASS_VERSION;
  952. spin_lock_irqsave(&tid_lock, flags);
  953. mad->mad_hdr.tid =
  954. cpu_to_be64(((u64) agent->hi_tid) << 32 | tid++);
  955. spin_unlock_irqrestore(&tid_lock, flags);
  956. }
  957. static int send_mad(struct ib_sa_query *query, int timeout_ms, gfp_t gfp_mask)
  958. {
  959. bool preload = !!(gfp_mask & __GFP_WAIT);
  960. unsigned long flags;
  961. int ret, id;
  962. if (preload)
  963. idr_preload(gfp_mask);
  964. spin_lock_irqsave(&idr_lock, flags);
  965. id = idr_alloc(&query_idr, query, 0, 0, GFP_NOWAIT);
  966. spin_unlock_irqrestore(&idr_lock, flags);
  967. if (preload)
  968. idr_preload_end();
  969. if (id < 0)
  970. return id;
  971. query->mad_buf->timeout_ms = timeout_ms;
  972. query->mad_buf->context[0] = query;
  973. query->id = id;
  974. if (query->flags & IB_SA_ENABLE_LOCAL_SERVICE) {
  975. if (!ibnl_chk_listeners(RDMA_NL_GROUP_LS)) {
  976. if (!ib_nl_make_request(query))
  977. return id;
  978. }
  979. ib_sa_disable_local_svc(query);
  980. }
  981. ret = ib_post_send_mad(query->mad_buf, NULL);
  982. if (ret) {
  983. spin_lock_irqsave(&idr_lock, flags);
  984. idr_remove(&query_idr, id);
  985. spin_unlock_irqrestore(&idr_lock, flags);
  986. }
  987. /*
  988. * It's not safe to dereference query any more, because the
  989. * send may already have completed and freed the query in
  990. * another context.
  991. */
  992. return ret ? ret : id;
  993. }
  994. void ib_sa_unpack_path(void *attribute, struct ib_sa_path_rec *rec)
  995. {
  996. ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table), attribute, rec);
  997. }
  998. EXPORT_SYMBOL(ib_sa_unpack_path);
  999. void ib_sa_pack_path(struct ib_sa_path_rec *rec, void *attribute)
  1000. {
  1001. ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, attribute);
  1002. }
  1003. EXPORT_SYMBOL(ib_sa_pack_path);
  1004. static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
  1005. int status,
  1006. struct ib_sa_mad *mad)
  1007. {
  1008. struct ib_sa_path_query *query =
  1009. container_of(sa_query, struct ib_sa_path_query, sa_query);
  1010. if (mad) {
  1011. struct ib_sa_path_rec rec;
  1012. ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table),
  1013. mad->data, &rec);
  1014. rec.vlan_id = 0xffff;
  1015. memset(rec.dmac, 0, ETH_ALEN);
  1016. memset(rec.smac, 0, ETH_ALEN);
  1017. query->callback(status, &rec, query->context);
  1018. } else
  1019. query->callback(status, NULL, query->context);
  1020. }
  1021. static void ib_sa_path_rec_release(struct ib_sa_query *sa_query)
  1022. {
  1023. kfree(container_of(sa_query, struct ib_sa_path_query, sa_query));
  1024. }
  1025. /**
  1026. * ib_sa_path_rec_get - Start a Path get query
  1027. * @client:SA client
  1028. * @device:device to send query on
  1029. * @port_num: port number to send query on
  1030. * @rec:Path Record to send in query
  1031. * @comp_mask:component mask to send in query
  1032. * @timeout_ms:time to wait for response
  1033. * @gfp_mask:GFP mask to use for internal allocations
  1034. * @callback:function called when query completes, times out or is
  1035. * canceled
  1036. * @context:opaque user context passed to callback
  1037. * @sa_query:query context, used to cancel query
  1038. *
  1039. * Send a Path Record Get query to the SA to look up a path. The
  1040. * callback function will be called when the query completes (or
  1041. * fails); status is 0 for a successful response, -EINTR if the query
  1042. * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
  1043. * occurred sending the query. The resp parameter of the callback is
  1044. * only valid if status is 0.
  1045. *
  1046. * If the return value of ib_sa_path_rec_get() is negative, it is an
  1047. * error code. Otherwise it is a query ID that can be used to cancel
  1048. * the query.
  1049. */
  1050. int ib_sa_path_rec_get(struct ib_sa_client *client,
  1051. struct ib_device *device, u8 port_num,
  1052. struct ib_sa_path_rec *rec,
  1053. ib_sa_comp_mask comp_mask,
  1054. int timeout_ms, gfp_t gfp_mask,
  1055. void (*callback)(int status,
  1056. struct ib_sa_path_rec *resp,
  1057. void *context),
  1058. void *context,
  1059. struct ib_sa_query **sa_query)
  1060. {
  1061. struct ib_sa_path_query *query;
  1062. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1063. struct ib_sa_port *port;
  1064. struct ib_mad_agent *agent;
  1065. struct ib_sa_mad *mad;
  1066. int ret;
  1067. if (!sa_dev)
  1068. return -ENODEV;
  1069. port = &sa_dev->port[port_num - sa_dev->start_port];
  1070. agent = port->agent;
  1071. query = kzalloc(sizeof(*query), gfp_mask);
  1072. if (!query)
  1073. return -ENOMEM;
  1074. query->sa_query.port = port;
  1075. ret = alloc_mad(&query->sa_query, gfp_mask);
  1076. if (ret)
  1077. goto err1;
  1078. ib_sa_client_get(client);
  1079. query->sa_query.client = client;
  1080. query->callback = callback;
  1081. query->context = context;
  1082. mad = query->sa_query.mad_buf->mad;
  1083. init_mad(mad, agent);
  1084. query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL;
  1085. query->sa_query.release = ib_sa_path_rec_release;
  1086. mad->mad_hdr.method = IB_MGMT_METHOD_GET;
  1087. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_PATH_REC);
  1088. mad->sa_hdr.comp_mask = comp_mask;
  1089. ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, mad->data);
  1090. *sa_query = &query->sa_query;
  1091. query->sa_query.flags |= IB_SA_ENABLE_LOCAL_SERVICE;
  1092. query->sa_query.mad_buf->context[1] = rec;
  1093. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1094. if (ret < 0)
  1095. goto err2;
  1096. return ret;
  1097. err2:
  1098. *sa_query = NULL;
  1099. ib_sa_client_put(query->sa_query.client);
  1100. free_mad(&query->sa_query);
  1101. err1:
  1102. kfree(query);
  1103. return ret;
  1104. }
  1105. EXPORT_SYMBOL(ib_sa_path_rec_get);
  1106. static void ib_sa_service_rec_callback(struct ib_sa_query *sa_query,
  1107. int status,
  1108. struct ib_sa_mad *mad)
  1109. {
  1110. struct ib_sa_service_query *query =
  1111. container_of(sa_query, struct ib_sa_service_query, sa_query);
  1112. if (mad) {
  1113. struct ib_sa_service_rec rec;
  1114. ib_unpack(service_rec_table, ARRAY_SIZE(service_rec_table),
  1115. mad->data, &rec);
  1116. query->callback(status, &rec, query->context);
  1117. } else
  1118. query->callback(status, NULL, query->context);
  1119. }
  1120. static void ib_sa_service_rec_release(struct ib_sa_query *sa_query)
  1121. {
  1122. kfree(container_of(sa_query, struct ib_sa_service_query, sa_query));
  1123. }
  1124. /**
  1125. * ib_sa_service_rec_query - Start Service Record operation
  1126. * @client:SA client
  1127. * @device:device to send request on
  1128. * @port_num: port number to send request on
  1129. * @method:SA method - should be get, set, or delete
  1130. * @rec:Service Record to send in request
  1131. * @comp_mask:component mask to send in request
  1132. * @timeout_ms:time to wait for response
  1133. * @gfp_mask:GFP mask to use for internal allocations
  1134. * @callback:function called when request completes, times out or is
  1135. * canceled
  1136. * @context:opaque user context passed to callback
  1137. * @sa_query:request context, used to cancel request
  1138. *
  1139. * Send a Service Record set/get/delete to the SA to register,
  1140. * unregister or query a service record.
  1141. * The callback function will be called when the request completes (or
  1142. * fails); status is 0 for a successful response, -EINTR if the query
  1143. * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
  1144. * occurred sending the query. The resp parameter of the callback is
  1145. * only valid if status is 0.
  1146. *
  1147. * If the return value of ib_sa_service_rec_query() is negative, it is an
  1148. * error code. Otherwise it is a request ID that can be used to cancel
  1149. * the query.
  1150. */
  1151. int ib_sa_service_rec_query(struct ib_sa_client *client,
  1152. struct ib_device *device, u8 port_num, u8 method,
  1153. struct ib_sa_service_rec *rec,
  1154. ib_sa_comp_mask comp_mask,
  1155. int timeout_ms, gfp_t gfp_mask,
  1156. void (*callback)(int status,
  1157. struct ib_sa_service_rec *resp,
  1158. void *context),
  1159. void *context,
  1160. struct ib_sa_query **sa_query)
  1161. {
  1162. struct ib_sa_service_query *query;
  1163. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1164. struct ib_sa_port *port;
  1165. struct ib_mad_agent *agent;
  1166. struct ib_sa_mad *mad;
  1167. int ret;
  1168. if (!sa_dev)
  1169. return -ENODEV;
  1170. port = &sa_dev->port[port_num - sa_dev->start_port];
  1171. agent = port->agent;
  1172. if (method != IB_MGMT_METHOD_GET &&
  1173. method != IB_MGMT_METHOD_SET &&
  1174. method != IB_SA_METHOD_DELETE)
  1175. return -EINVAL;
  1176. query = kzalloc(sizeof(*query), gfp_mask);
  1177. if (!query)
  1178. return -ENOMEM;
  1179. query->sa_query.port = port;
  1180. ret = alloc_mad(&query->sa_query, gfp_mask);
  1181. if (ret)
  1182. goto err1;
  1183. ib_sa_client_get(client);
  1184. query->sa_query.client = client;
  1185. query->callback = callback;
  1186. query->context = context;
  1187. mad = query->sa_query.mad_buf->mad;
  1188. init_mad(mad, agent);
  1189. query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL;
  1190. query->sa_query.release = ib_sa_service_rec_release;
  1191. mad->mad_hdr.method = method;
  1192. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_SERVICE_REC);
  1193. mad->sa_hdr.comp_mask = comp_mask;
  1194. ib_pack(service_rec_table, ARRAY_SIZE(service_rec_table),
  1195. rec, mad->data);
  1196. *sa_query = &query->sa_query;
  1197. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1198. if (ret < 0)
  1199. goto err2;
  1200. return ret;
  1201. err2:
  1202. *sa_query = NULL;
  1203. ib_sa_client_put(query->sa_query.client);
  1204. free_mad(&query->sa_query);
  1205. err1:
  1206. kfree(query);
  1207. return ret;
  1208. }
  1209. EXPORT_SYMBOL(ib_sa_service_rec_query);
  1210. static void ib_sa_mcmember_rec_callback(struct ib_sa_query *sa_query,
  1211. int status,
  1212. struct ib_sa_mad *mad)
  1213. {
  1214. struct ib_sa_mcmember_query *query =
  1215. container_of(sa_query, struct ib_sa_mcmember_query, sa_query);
  1216. if (mad) {
  1217. struct ib_sa_mcmember_rec rec;
  1218. ib_unpack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
  1219. mad->data, &rec);
  1220. query->callback(status, &rec, query->context);
  1221. } else
  1222. query->callback(status, NULL, query->context);
  1223. }
  1224. static void ib_sa_mcmember_rec_release(struct ib_sa_query *sa_query)
  1225. {
  1226. kfree(container_of(sa_query, struct ib_sa_mcmember_query, sa_query));
  1227. }
  1228. int ib_sa_mcmember_rec_query(struct ib_sa_client *client,
  1229. struct ib_device *device, u8 port_num,
  1230. u8 method,
  1231. struct ib_sa_mcmember_rec *rec,
  1232. ib_sa_comp_mask comp_mask,
  1233. int timeout_ms, gfp_t gfp_mask,
  1234. void (*callback)(int status,
  1235. struct ib_sa_mcmember_rec *resp,
  1236. void *context),
  1237. void *context,
  1238. struct ib_sa_query **sa_query)
  1239. {
  1240. struct ib_sa_mcmember_query *query;
  1241. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1242. struct ib_sa_port *port;
  1243. struct ib_mad_agent *agent;
  1244. struct ib_sa_mad *mad;
  1245. int ret;
  1246. if (!sa_dev)
  1247. return -ENODEV;
  1248. port = &sa_dev->port[port_num - sa_dev->start_port];
  1249. agent = port->agent;
  1250. query = kzalloc(sizeof(*query), gfp_mask);
  1251. if (!query)
  1252. return -ENOMEM;
  1253. query->sa_query.port = port;
  1254. ret = alloc_mad(&query->sa_query, gfp_mask);
  1255. if (ret)
  1256. goto err1;
  1257. ib_sa_client_get(client);
  1258. query->sa_query.client = client;
  1259. query->callback = callback;
  1260. query->context = context;
  1261. mad = query->sa_query.mad_buf->mad;
  1262. init_mad(mad, agent);
  1263. query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL;
  1264. query->sa_query.release = ib_sa_mcmember_rec_release;
  1265. mad->mad_hdr.method = method;
  1266. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
  1267. mad->sa_hdr.comp_mask = comp_mask;
  1268. ib_pack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
  1269. rec, mad->data);
  1270. *sa_query = &query->sa_query;
  1271. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1272. if (ret < 0)
  1273. goto err2;
  1274. return ret;
  1275. err2:
  1276. *sa_query = NULL;
  1277. ib_sa_client_put(query->sa_query.client);
  1278. free_mad(&query->sa_query);
  1279. err1:
  1280. kfree(query);
  1281. return ret;
  1282. }
  1283. /* Support GuidInfoRecord */
  1284. static void ib_sa_guidinfo_rec_callback(struct ib_sa_query *sa_query,
  1285. int status,
  1286. struct ib_sa_mad *mad)
  1287. {
  1288. struct ib_sa_guidinfo_query *query =
  1289. container_of(sa_query, struct ib_sa_guidinfo_query, sa_query);
  1290. if (mad) {
  1291. struct ib_sa_guidinfo_rec rec;
  1292. ib_unpack(guidinfo_rec_table, ARRAY_SIZE(guidinfo_rec_table),
  1293. mad->data, &rec);
  1294. query->callback(status, &rec, query->context);
  1295. } else
  1296. query->callback(status, NULL, query->context);
  1297. }
  1298. static void ib_sa_guidinfo_rec_release(struct ib_sa_query *sa_query)
  1299. {
  1300. kfree(container_of(sa_query, struct ib_sa_guidinfo_query, sa_query));
  1301. }
  1302. int ib_sa_guid_info_rec_query(struct ib_sa_client *client,
  1303. struct ib_device *device, u8 port_num,
  1304. struct ib_sa_guidinfo_rec *rec,
  1305. ib_sa_comp_mask comp_mask, u8 method,
  1306. int timeout_ms, gfp_t gfp_mask,
  1307. void (*callback)(int status,
  1308. struct ib_sa_guidinfo_rec *resp,
  1309. void *context),
  1310. void *context,
  1311. struct ib_sa_query **sa_query)
  1312. {
  1313. struct ib_sa_guidinfo_query *query;
  1314. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1315. struct ib_sa_port *port;
  1316. struct ib_mad_agent *agent;
  1317. struct ib_sa_mad *mad;
  1318. int ret;
  1319. if (!sa_dev)
  1320. return -ENODEV;
  1321. if (method != IB_MGMT_METHOD_GET &&
  1322. method != IB_MGMT_METHOD_SET &&
  1323. method != IB_SA_METHOD_DELETE) {
  1324. return -EINVAL;
  1325. }
  1326. port = &sa_dev->port[port_num - sa_dev->start_port];
  1327. agent = port->agent;
  1328. query = kzalloc(sizeof(*query), gfp_mask);
  1329. if (!query)
  1330. return -ENOMEM;
  1331. query->sa_query.port = port;
  1332. ret = alloc_mad(&query->sa_query, gfp_mask);
  1333. if (ret)
  1334. goto err1;
  1335. ib_sa_client_get(client);
  1336. query->sa_query.client = client;
  1337. query->callback = callback;
  1338. query->context = context;
  1339. mad = query->sa_query.mad_buf->mad;
  1340. init_mad(mad, agent);
  1341. query->sa_query.callback = callback ? ib_sa_guidinfo_rec_callback : NULL;
  1342. query->sa_query.release = ib_sa_guidinfo_rec_release;
  1343. mad->mad_hdr.method = method;
  1344. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_GUID_INFO_REC);
  1345. mad->sa_hdr.comp_mask = comp_mask;
  1346. ib_pack(guidinfo_rec_table, ARRAY_SIZE(guidinfo_rec_table), rec,
  1347. mad->data);
  1348. *sa_query = &query->sa_query;
  1349. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1350. if (ret < 0)
  1351. goto err2;
  1352. return ret;
  1353. err2:
  1354. *sa_query = NULL;
  1355. ib_sa_client_put(query->sa_query.client);
  1356. free_mad(&query->sa_query);
  1357. err1:
  1358. kfree(query);
  1359. return ret;
  1360. }
  1361. EXPORT_SYMBOL(ib_sa_guid_info_rec_query);
  1362. static void send_handler(struct ib_mad_agent *agent,
  1363. struct ib_mad_send_wc *mad_send_wc)
  1364. {
  1365. struct ib_sa_query *query = mad_send_wc->send_buf->context[0];
  1366. unsigned long flags;
  1367. if (query->callback)
  1368. switch (mad_send_wc->status) {
  1369. case IB_WC_SUCCESS:
  1370. /* No callback -- already got recv */
  1371. break;
  1372. case IB_WC_RESP_TIMEOUT_ERR:
  1373. query->callback(query, -ETIMEDOUT, NULL);
  1374. break;
  1375. case IB_WC_WR_FLUSH_ERR:
  1376. query->callback(query, -EINTR, NULL);
  1377. break;
  1378. default:
  1379. query->callback(query, -EIO, NULL);
  1380. break;
  1381. }
  1382. spin_lock_irqsave(&idr_lock, flags);
  1383. idr_remove(&query_idr, query->id);
  1384. spin_unlock_irqrestore(&idr_lock, flags);
  1385. free_mad(query);
  1386. ib_sa_client_put(query->client);
  1387. query->release(query);
  1388. }
  1389. static void recv_handler(struct ib_mad_agent *mad_agent,
  1390. struct ib_mad_recv_wc *mad_recv_wc)
  1391. {
  1392. struct ib_sa_query *query;
  1393. struct ib_mad_send_buf *mad_buf;
  1394. mad_buf = (void *) (unsigned long) mad_recv_wc->wc->wr_id;
  1395. query = mad_buf->context[0];
  1396. if (query->callback) {
  1397. if (mad_recv_wc->wc->status == IB_WC_SUCCESS)
  1398. query->callback(query,
  1399. mad_recv_wc->recv_buf.mad->mad_hdr.status ?
  1400. -EINVAL : 0,
  1401. (struct ib_sa_mad *) mad_recv_wc->recv_buf.mad);
  1402. else
  1403. query->callback(query, -EIO, NULL);
  1404. }
  1405. ib_free_recv_mad(mad_recv_wc);
  1406. }
  1407. static void ib_sa_add_one(struct ib_device *device)
  1408. {
  1409. struct ib_sa_device *sa_dev;
  1410. int s, e, i;
  1411. int count = 0;
  1412. s = rdma_start_port(device);
  1413. e = rdma_end_port(device);
  1414. sa_dev = kzalloc(sizeof *sa_dev +
  1415. (e - s + 1) * sizeof (struct ib_sa_port),
  1416. GFP_KERNEL);
  1417. if (!sa_dev)
  1418. return;
  1419. sa_dev->start_port = s;
  1420. sa_dev->end_port = e;
  1421. for (i = 0; i <= e - s; ++i) {
  1422. spin_lock_init(&sa_dev->port[i].ah_lock);
  1423. if (!rdma_cap_ib_sa(device, i + 1))
  1424. continue;
  1425. sa_dev->port[i].sm_ah = NULL;
  1426. sa_dev->port[i].port_num = i + s;
  1427. sa_dev->port[i].agent =
  1428. ib_register_mad_agent(device, i + s, IB_QPT_GSI,
  1429. NULL, 0, send_handler,
  1430. recv_handler, sa_dev, 0);
  1431. if (IS_ERR(sa_dev->port[i].agent))
  1432. goto err;
  1433. INIT_WORK(&sa_dev->port[i].update_task, update_sm_ah);
  1434. count++;
  1435. }
  1436. if (!count)
  1437. goto free;
  1438. ib_set_client_data(device, &sa_client, sa_dev);
  1439. /*
  1440. * We register our event handler after everything is set up,
  1441. * and then update our cached info after the event handler is
  1442. * registered to avoid any problems if a port changes state
  1443. * during our initialization.
  1444. */
  1445. INIT_IB_EVENT_HANDLER(&sa_dev->event_handler, device, ib_sa_event);
  1446. if (ib_register_event_handler(&sa_dev->event_handler))
  1447. goto err;
  1448. for (i = 0; i <= e - s; ++i) {
  1449. if (rdma_cap_ib_sa(device, i + 1))
  1450. update_sm_ah(&sa_dev->port[i].update_task);
  1451. }
  1452. return;
  1453. err:
  1454. while (--i >= 0) {
  1455. if (rdma_cap_ib_sa(device, i + 1))
  1456. ib_unregister_mad_agent(sa_dev->port[i].agent);
  1457. }
  1458. free:
  1459. kfree(sa_dev);
  1460. return;
  1461. }
  1462. static void ib_sa_remove_one(struct ib_device *device, void *client_data)
  1463. {
  1464. struct ib_sa_device *sa_dev = client_data;
  1465. int i;
  1466. if (!sa_dev)
  1467. return;
  1468. ib_unregister_event_handler(&sa_dev->event_handler);
  1469. flush_workqueue(ib_wq);
  1470. for (i = 0; i <= sa_dev->end_port - sa_dev->start_port; ++i) {
  1471. if (rdma_cap_ib_sa(device, i + 1)) {
  1472. ib_unregister_mad_agent(sa_dev->port[i].agent);
  1473. if (sa_dev->port[i].sm_ah)
  1474. kref_put(&sa_dev->port[i].sm_ah->ref, free_sm_ah);
  1475. }
  1476. }
  1477. kfree(sa_dev);
  1478. }
  1479. static int __init ib_sa_init(void)
  1480. {
  1481. int ret;
  1482. get_random_bytes(&tid, sizeof tid);
  1483. atomic_set(&ib_nl_sa_request_seq, 0);
  1484. ret = ib_register_client(&sa_client);
  1485. if (ret) {
  1486. printk(KERN_ERR "Couldn't register ib_sa client\n");
  1487. goto err1;
  1488. }
  1489. ret = mcast_init();
  1490. if (ret) {
  1491. printk(KERN_ERR "Couldn't initialize multicast handling\n");
  1492. goto err2;
  1493. }
  1494. ib_nl_wq = create_singlethread_workqueue("ib_nl_sa_wq");
  1495. if (!ib_nl_wq) {
  1496. ret = -ENOMEM;
  1497. goto err3;
  1498. }
  1499. if (ibnl_add_client(RDMA_NL_LS, RDMA_NL_LS_NUM_OPS,
  1500. ib_sa_cb_table)) {
  1501. pr_err("Failed to add netlink callback\n");
  1502. ret = -EINVAL;
  1503. goto err4;
  1504. }
  1505. INIT_DELAYED_WORK(&ib_nl_timed_work, ib_nl_request_timeout);
  1506. return 0;
  1507. err4:
  1508. destroy_workqueue(ib_nl_wq);
  1509. err3:
  1510. mcast_cleanup();
  1511. err2:
  1512. ib_unregister_client(&sa_client);
  1513. err1:
  1514. return ret;
  1515. }
  1516. static void __exit ib_sa_cleanup(void)
  1517. {
  1518. ibnl_remove_client(RDMA_NL_LS);
  1519. cancel_delayed_work(&ib_nl_timed_work);
  1520. flush_workqueue(ib_nl_wq);
  1521. destroy_workqueue(ib_nl_wq);
  1522. mcast_cleanup();
  1523. ib_unregister_client(&sa_client);
  1524. idr_destroy(&query_idr);
  1525. }
  1526. module_init(ib_sa_init);
  1527. module_exit(ib_sa_cleanup);