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, gfp_t gfp_mask)
  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_mask);
  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. nlmsg_free(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_mask);
  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, gfp_t gfp_mask)
  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. /* Put the request on the list first.*/
  516. spin_lock_irqsave(&ib_nl_request_lock, flags);
  517. delay = msecs_to_jiffies(sa_local_svc_timeout_ms);
  518. query->timeout = delay + jiffies;
  519. list_add_tail(&query->list, &ib_nl_request_list);
  520. /* Start the timeout if this is the only request */
  521. if (ib_nl_request_list.next == &query->list)
  522. queue_delayed_work(ib_nl_wq, &ib_nl_timed_work, delay);
  523. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  524. ret = ib_nl_send_msg(query, gfp_mask);
  525. if (ret <= 0) {
  526. ret = -EIO;
  527. /* Remove the request */
  528. spin_lock_irqsave(&ib_nl_request_lock, flags);
  529. list_del(&query->list);
  530. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  531. } else {
  532. ret = 0;
  533. }
  534. return ret;
  535. }
  536. static int ib_nl_cancel_request(struct ib_sa_query *query)
  537. {
  538. unsigned long flags;
  539. struct ib_sa_query *wait_query;
  540. int found = 0;
  541. spin_lock_irqsave(&ib_nl_request_lock, flags);
  542. list_for_each_entry(wait_query, &ib_nl_request_list, list) {
  543. /* Let the timeout to take care of the callback */
  544. if (query == wait_query) {
  545. query->flags |= IB_SA_CANCEL;
  546. query->timeout = jiffies;
  547. list_move(&query->list, &ib_nl_request_list);
  548. found = 1;
  549. mod_delayed_work(ib_nl_wq, &ib_nl_timed_work, 1);
  550. break;
  551. }
  552. }
  553. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  554. return found;
  555. }
  556. static void send_handler(struct ib_mad_agent *agent,
  557. struct ib_mad_send_wc *mad_send_wc);
  558. static void ib_nl_process_good_resolve_rsp(struct ib_sa_query *query,
  559. const struct nlmsghdr *nlh)
  560. {
  561. struct ib_mad_send_wc mad_send_wc;
  562. struct ib_sa_mad *mad = NULL;
  563. const struct nlattr *head, *curr;
  564. struct ib_path_rec_data *rec;
  565. int len, rem;
  566. u32 mask = 0;
  567. int status = -EIO;
  568. if (query->callback) {
  569. head = (const struct nlattr *) nlmsg_data(nlh);
  570. len = nlmsg_len(nlh);
  571. switch (query->path_use) {
  572. case LS_RESOLVE_PATH_USE_UNIDIRECTIONAL:
  573. mask = IB_PATH_PRIMARY | IB_PATH_OUTBOUND;
  574. break;
  575. case LS_RESOLVE_PATH_USE_ALL:
  576. case LS_RESOLVE_PATH_USE_GMP:
  577. default:
  578. mask = IB_PATH_PRIMARY | IB_PATH_GMP |
  579. IB_PATH_BIDIRECTIONAL;
  580. break;
  581. }
  582. nla_for_each_attr(curr, head, len, rem) {
  583. if (curr->nla_type == LS_NLA_TYPE_PATH_RECORD) {
  584. rec = nla_data(curr);
  585. /*
  586. * Get the first one. In the future, we may
  587. * need to get up to 6 pathrecords.
  588. */
  589. if ((rec->flags & mask) == mask) {
  590. mad = query->mad_buf->mad;
  591. mad->mad_hdr.method |=
  592. IB_MGMT_METHOD_RESP;
  593. memcpy(mad->data, rec->path_rec,
  594. sizeof(rec->path_rec));
  595. status = 0;
  596. break;
  597. }
  598. }
  599. }
  600. query->callback(query, status, mad);
  601. }
  602. mad_send_wc.send_buf = query->mad_buf;
  603. mad_send_wc.status = IB_WC_SUCCESS;
  604. send_handler(query->mad_buf->mad_agent, &mad_send_wc);
  605. }
  606. static void ib_nl_request_timeout(struct work_struct *work)
  607. {
  608. unsigned long flags;
  609. struct ib_sa_query *query;
  610. unsigned long delay;
  611. struct ib_mad_send_wc mad_send_wc;
  612. int ret;
  613. spin_lock_irqsave(&ib_nl_request_lock, flags);
  614. while (!list_empty(&ib_nl_request_list)) {
  615. query = list_entry(ib_nl_request_list.next,
  616. struct ib_sa_query, list);
  617. if (time_after(query->timeout, jiffies)) {
  618. delay = query->timeout - jiffies;
  619. if ((long)delay <= 0)
  620. delay = 1;
  621. queue_delayed_work(ib_nl_wq, &ib_nl_timed_work, delay);
  622. break;
  623. }
  624. list_del(&query->list);
  625. ib_sa_disable_local_svc(query);
  626. /* Hold the lock to protect against query cancellation */
  627. if (ib_sa_query_cancelled(query))
  628. ret = -1;
  629. else
  630. ret = ib_post_send_mad(query->mad_buf, NULL);
  631. if (ret) {
  632. mad_send_wc.send_buf = query->mad_buf;
  633. mad_send_wc.status = IB_WC_WR_FLUSH_ERR;
  634. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  635. send_handler(query->port->agent, &mad_send_wc);
  636. spin_lock_irqsave(&ib_nl_request_lock, flags);
  637. }
  638. }
  639. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  640. }
  641. static int ib_nl_handle_set_timeout(struct sk_buff *skb,
  642. struct netlink_callback *cb)
  643. {
  644. const struct nlmsghdr *nlh = (struct nlmsghdr *)cb->nlh;
  645. int timeout, delta, abs_delta;
  646. const struct nlattr *attr;
  647. unsigned long flags;
  648. struct ib_sa_query *query;
  649. long delay = 0;
  650. struct nlattr *tb[LS_NLA_TYPE_MAX];
  651. int ret;
  652. if (!netlink_capable(skb, CAP_NET_ADMIN))
  653. return -EPERM;
  654. ret = nla_parse(tb, LS_NLA_TYPE_MAX - 1, nlmsg_data(nlh),
  655. nlmsg_len(nlh), ib_nl_policy);
  656. attr = (const struct nlattr *)tb[LS_NLA_TYPE_TIMEOUT];
  657. if (ret || !attr)
  658. goto settimeout_out;
  659. timeout = *(int *) nla_data(attr);
  660. if (timeout < IB_SA_LOCAL_SVC_TIMEOUT_MIN)
  661. timeout = IB_SA_LOCAL_SVC_TIMEOUT_MIN;
  662. if (timeout > IB_SA_LOCAL_SVC_TIMEOUT_MAX)
  663. timeout = IB_SA_LOCAL_SVC_TIMEOUT_MAX;
  664. delta = timeout - sa_local_svc_timeout_ms;
  665. if (delta < 0)
  666. abs_delta = -delta;
  667. else
  668. abs_delta = delta;
  669. if (delta != 0) {
  670. spin_lock_irqsave(&ib_nl_request_lock, flags);
  671. sa_local_svc_timeout_ms = timeout;
  672. list_for_each_entry(query, &ib_nl_request_list, list) {
  673. if (delta < 0 && abs_delta > query->timeout)
  674. query->timeout = 0;
  675. else
  676. query->timeout += delta;
  677. /* Get the new delay from the first entry */
  678. if (!delay) {
  679. delay = query->timeout - jiffies;
  680. if (delay <= 0)
  681. delay = 1;
  682. }
  683. }
  684. if (delay)
  685. mod_delayed_work(ib_nl_wq, &ib_nl_timed_work,
  686. (unsigned long)delay);
  687. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  688. }
  689. settimeout_out:
  690. return skb->len;
  691. }
  692. static inline int ib_nl_is_good_resolve_resp(const struct nlmsghdr *nlh)
  693. {
  694. struct nlattr *tb[LS_NLA_TYPE_MAX];
  695. int ret;
  696. if (nlh->nlmsg_flags & RDMA_NL_LS_F_ERR)
  697. return 0;
  698. ret = nla_parse(tb, LS_NLA_TYPE_MAX - 1, nlmsg_data(nlh),
  699. nlmsg_len(nlh), ib_nl_policy);
  700. if (ret)
  701. return 0;
  702. return 1;
  703. }
  704. static int ib_nl_handle_resolve_resp(struct sk_buff *skb,
  705. struct netlink_callback *cb)
  706. {
  707. const struct nlmsghdr *nlh = (struct nlmsghdr *)cb->nlh;
  708. unsigned long flags;
  709. struct ib_sa_query *query;
  710. struct ib_mad_send_buf *send_buf;
  711. struct ib_mad_send_wc mad_send_wc;
  712. int found = 0;
  713. int ret;
  714. if (!netlink_capable(skb, CAP_NET_ADMIN))
  715. return -EPERM;
  716. spin_lock_irqsave(&ib_nl_request_lock, flags);
  717. list_for_each_entry(query, &ib_nl_request_list, list) {
  718. /*
  719. * If the query is cancelled, let the timeout routine
  720. * take care of it.
  721. */
  722. if (nlh->nlmsg_seq == query->seq) {
  723. found = !ib_sa_query_cancelled(query);
  724. if (found)
  725. list_del(&query->list);
  726. break;
  727. }
  728. }
  729. if (!found) {
  730. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  731. goto resp_out;
  732. }
  733. send_buf = query->mad_buf;
  734. if (!ib_nl_is_good_resolve_resp(nlh)) {
  735. /* if the result is a failure, send out the packet via IB */
  736. ib_sa_disable_local_svc(query);
  737. ret = ib_post_send_mad(query->mad_buf, NULL);
  738. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  739. if (ret) {
  740. mad_send_wc.send_buf = send_buf;
  741. mad_send_wc.status = IB_WC_GENERAL_ERR;
  742. send_handler(query->port->agent, &mad_send_wc);
  743. }
  744. } else {
  745. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  746. ib_nl_process_good_resolve_rsp(query, nlh);
  747. }
  748. resp_out:
  749. return skb->len;
  750. }
  751. static struct ibnl_client_cbs ib_sa_cb_table[] = {
  752. [RDMA_NL_LS_OP_RESOLVE] = {
  753. .dump = ib_nl_handle_resolve_resp,
  754. .module = THIS_MODULE },
  755. [RDMA_NL_LS_OP_SET_TIMEOUT] = {
  756. .dump = ib_nl_handle_set_timeout,
  757. .module = THIS_MODULE },
  758. };
  759. static void free_sm_ah(struct kref *kref)
  760. {
  761. struct ib_sa_sm_ah *sm_ah = container_of(kref, struct ib_sa_sm_ah, ref);
  762. ib_destroy_ah(sm_ah->ah);
  763. kfree(sm_ah);
  764. }
  765. static void update_sm_ah(struct work_struct *work)
  766. {
  767. struct ib_sa_port *port =
  768. container_of(work, struct ib_sa_port, update_task);
  769. struct ib_sa_sm_ah *new_ah;
  770. struct ib_port_attr port_attr;
  771. struct ib_ah_attr ah_attr;
  772. if (ib_query_port(port->agent->device, port->port_num, &port_attr)) {
  773. printk(KERN_WARNING "Couldn't query port\n");
  774. return;
  775. }
  776. new_ah = kmalloc(sizeof *new_ah, GFP_KERNEL);
  777. if (!new_ah) {
  778. printk(KERN_WARNING "Couldn't allocate new SM AH\n");
  779. return;
  780. }
  781. kref_init(&new_ah->ref);
  782. new_ah->src_path_mask = (1 << port_attr.lmc) - 1;
  783. new_ah->pkey_index = 0;
  784. if (ib_find_pkey(port->agent->device, port->port_num,
  785. IB_DEFAULT_PKEY_FULL, &new_ah->pkey_index))
  786. printk(KERN_ERR "Couldn't find index for default PKey\n");
  787. memset(&ah_attr, 0, sizeof ah_attr);
  788. ah_attr.dlid = port_attr.sm_lid;
  789. ah_attr.sl = port_attr.sm_sl;
  790. ah_attr.port_num = port->port_num;
  791. new_ah->ah = ib_create_ah(port->agent->qp->pd, &ah_attr);
  792. if (IS_ERR(new_ah->ah)) {
  793. printk(KERN_WARNING "Couldn't create new SM AH\n");
  794. kfree(new_ah);
  795. return;
  796. }
  797. spin_lock_irq(&port->ah_lock);
  798. if (port->sm_ah)
  799. kref_put(&port->sm_ah->ref, free_sm_ah);
  800. port->sm_ah = new_ah;
  801. spin_unlock_irq(&port->ah_lock);
  802. }
  803. static void ib_sa_event(struct ib_event_handler *handler, struct ib_event *event)
  804. {
  805. if (event->event == IB_EVENT_PORT_ERR ||
  806. event->event == IB_EVENT_PORT_ACTIVE ||
  807. event->event == IB_EVENT_LID_CHANGE ||
  808. event->event == IB_EVENT_PKEY_CHANGE ||
  809. event->event == IB_EVENT_SM_CHANGE ||
  810. event->event == IB_EVENT_CLIENT_REREGISTER) {
  811. unsigned long flags;
  812. struct ib_sa_device *sa_dev =
  813. container_of(handler, typeof(*sa_dev), event_handler);
  814. struct ib_sa_port *port =
  815. &sa_dev->port[event->element.port_num - sa_dev->start_port];
  816. if (!rdma_cap_ib_sa(handler->device, port->port_num))
  817. return;
  818. spin_lock_irqsave(&port->ah_lock, flags);
  819. if (port->sm_ah)
  820. kref_put(&port->sm_ah->ref, free_sm_ah);
  821. port->sm_ah = NULL;
  822. spin_unlock_irqrestore(&port->ah_lock, flags);
  823. queue_work(ib_wq, &sa_dev->port[event->element.port_num -
  824. sa_dev->start_port].update_task);
  825. }
  826. }
  827. void ib_sa_register_client(struct ib_sa_client *client)
  828. {
  829. atomic_set(&client->users, 1);
  830. init_completion(&client->comp);
  831. }
  832. EXPORT_SYMBOL(ib_sa_register_client);
  833. void ib_sa_unregister_client(struct ib_sa_client *client)
  834. {
  835. ib_sa_client_put(client);
  836. wait_for_completion(&client->comp);
  837. }
  838. EXPORT_SYMBOL(ib_sa_unregister_client);
  839. /**
  840. * ib_sa_cancel_query - try to cancel an SA query
  841. * @id:ID of query to cancel
  842. * @query:query pointer to cancel
  843. *
  844. * Try to cancel an SA query. If the id and query don't match up or
  845. * the query has already completed, nothing is done. Otherwise the
  846. * query is canceled and will complete with a status of -EINTR.
  847. */
  848. void ib_sa_cancel_query(int id, struct ib_sa_query *query)
  849. {
  850. unsigned long flags;
  851. struct ib_mad_agent *agent;
  852. struct ib_mad_send_buf *mad_buf;
  853. spin_lock_irqsave(&idr_lock, flags);
  854. if (idr_find(&query_idr, id) != query) {
  855. spin_unlock_irqrestore(&idr_lock, flags);
  856. return;
  857. }
  858. agent = query->port->agent;
  859. mad_buf = query->mad_buf;
  860. spin_unlock_irqrestore(&idr_lock, flags);
  861. /*
  862. * If the query is still on the netlink request list, schedule
  863. * it to be cancelled by the timeout routine. Otherwise, it has been
  864. * sent to the MAD layer and has to be cancelled from there.
  865. */
  866. if (!ib_nl_cancel_request(query))
  867. ib_cancel_mad(agent, mad_buf);
  868. }
  869. EXPORT_SYMBOL(ib_sa_cancel_query);
  870. static u8 get_src_path_mask(struct ib_device *device, u8 port_num)
  871. {
  872. struct ib_sa_device *sa_dev;
  873. struct ib_sa_port *port;
  874. unsigned long flags;
  875. u8 src_path_mask;
  876. sa_dev = ib_get_client_data(device, &sa_client);
  877. if (!sa_dev)
  878. return 0x7f;
  879. port = &sa_dev->port[port_num - sa_dev->start_port];
  880. spin_lock_irqsave(&port->ah_lock, flags);
  881. src_path_mask = port->sm_ah ? port->sm_ah->src_path_mask : 0x7f;
  882. spin_unlock_irqrestore(&port->ah_lock, flags);
  883. return src_path_mask;
  884. }
  885. int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
  886. struct ib_sa_path_rec *rec, struct ib_ah_attr *ah_attr)
  887. {
  888. int ret;
  889. u16 gid_index;
  890. int force_grh;
  891. memset(ah_attr, 0, sizeof *ah_attr);
  892. ah_attr->dlid = be16_to_cpu(rec->dlid);
  893. ah_attr->sl = rec->sl;
  894. ah_attr->src_path_bits = be16_to_cpu(rec->slid) &
  895. get_src_path_mask(device, port_num);
  896. ah_attr->port_num = port_num;
  897. ah_attr->static_rate = rec->rate;
  898. force_grh = rdma_cap_eth_ah(device, port_num);
  899. if (rec->hop_limit > 1 || force_grh) {
  900. struct net_device *ndev = ib_get_ndev_from_path(rec);
  901. ah_attr->ah_flags = IB_AH_GRH;
  902. ah_attr->grh.dgid = rec->dgid;
  903. ret = ib_find_cached_gid(device, &rec->sgid, ndev, &port_num,
  904. &gid_index);
  905. if (ret) {
  906. if (ndev)
  907. dev_put(ndev);
  908. return ret;
  909. }
  910. ah_attr->grh.sgid_index = gid_index;
  911. ah_attr->grh.flow_label = be32_to_cpu(rec->flow_label);
  912. ah_attr->grh.hop_limit = rec->hop_limit;
  913. ah_attr->grh.traffic_class = rec->traffic_class;
  914. if (ndev)
  915. dev_put(ndev);
  916. }
  917. if (force_grh) {
  918. memcpy(ah_attr->dmac, rec->dmac, ETH_ALEN);
  919. }
  920. return 0;
  921. }
  922. EXPORT_SYMBOL(ib_init_ah_from_path);
  923. static int alloc_mad(struct ib_sa_query *query, gfp_t gfp_mask)
  924. {
  925. unsigned long flags;
  926. spin_lock_irqsave(&query->port->ah_lock, flags);
  927. if (!query->port->sm_ah) {
  928. spin_unlock_irqrestore(&query->port->ah_lock, flags);
  929. return -EAGAIN;
  930. }
  931. kref_get(&query->port->sm_ah->ref);
  932. query->sm_ah = query->port->sm_ah;
  933. spin_unlock_irqrestore(&query->port->ah_lock, flags);
  934. query->mad_buf = ib_create_send_mad(query->port->agent, 1,
  935. query->sm_ah->pkey_index,
  936. 0, IB_MGMT_SA_HDR, IB_MGMT_SA_DATA,
  937. gfp_mask,
  938. IB_MGMT_BASE_VERSION);
  939. if (IS_ERR(query->mad_buf)) {
  940. kref_put(&query->sm_ah->ref, free_sm_ah);
  941. return -ENOMEM;
  942. }
  943. query->mad_buf->ah = query->sm_ah->ah;
  944. return 0;
  945. }
  946. static void free_mad(struct ib_sa_query *query)
  947. {
  948. ib_free_send_mad(query->mad_buf);
  949. kref_put(&query->sm_ah->ref, free_sm_ah);
  950. }
  951. static void init_mad(struct ib_sa_mad *mad, struct ib_mad_agent *agent)
  952. {
  953. unsigned long flags;
  954. memset(mad, 0, sizeof *mad);
  955. mad->mad_hdr.base_version = IB_MGMT_BASE_VERSION;
  956. mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
  957. mad->mad_hdr.class_version = IB_SA_CLASS_VERSION;
  958. spin_lock_irqsave(&tid_lock, flags);
  959. mad->mad_hdr.tid =
  960. cpu_to_be64(((u64) agent->hi_tid) << 32 | tid++);
  961. spin_unlock_irqrestore(&tid_lock, flags);
  962. }
  963. static int send_mad(struct ib_sa_query *query, int timeout_ms, gfp_t gfp_mask)
  964. {
  965. bool preload = gfpflags_allow_blocking(gfp_mask);
  966. unsigned long flags;
  967. int ret, id;
  968. if (preload)
  969. idr_preload(gfp_mask);
  970. spin_lock_irqsave(&idr_lock, flags);
  971. id = idr_alloc(&query_idr, query, 0, 0, GFP_NOWAIT);
  972. spin_unlock_irqrestore(&idr_lock, flags);
  973. if (preload)
  974. idr_preload_end();
  975. if (id < 0)
  976. return id;
  977. query->mad_buf->timeout_ms = timeout_ms;
  978. query->mad_buf->context[0] = query;
  979. query->id = id;
  980. if (query->flags & IB_SA_ENABLE_LOCAL_SERVICE) {
  981. if (!ibnl_chk_listeners(RDMA_NL_GROUP_LS)) {
  982. if (!ib_nl_make_request(query, gfp_mask))
  983. return id;
  984. }
  985. ib_sa_disable_local_svc(query);
  986. }
  987. ret = ib_post_send_mad(query->mad_buf, NULL);
  988. if (ret) {
  989. spin_lock_irqsave(&idr_lock, flags);
  990. idr_remove(&query_idr, id);
  991. spin_unlock_irqrestore(&idr_lock, flags);
  992. }
  993. /*
  994. * It's not safe to dereference query any more, because the
  995. * send may already have completed and freed the query in
  996. * another context.
  997. */
  998. return ret ? ret : id;
  999. }
  1000. void ib_sa_unpack_path(void *attribute, struct ib_sa_path_rec *rec)
  1001. {
  1002. ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table), attribute, rec);
  1003. }
  1004. EXPORT_SYMBOL(ib_sa_unpack_path);
  1005. void ib_sa_pack_path(struct ib_sa_path_rec *rec, void *attribute)
  1006. {
  1007. ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, attribute);
  1008. }
  1009. EXPORT_SYMBOL(ib_sa_pack_path);
  1010. static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
  1011. int status,
  1012. struct ib_sa_mad *mad)
  1013. {
  1014. struct ib_sa_path_query *query =
  1015. container_of(sa_query, struct ib_sa_path_query, sa_query);
  1016. if (mad) {
  1017. struct ib_sa_path_rec rec;
  1018. ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table),
  1019. mad->data, &rec);
  1020. rec.net = NULL;
  1021. rec.ifindex = 0;
  1022. memset(rec.dmac, 0, ETH_ALEN);
  1023. query->callback(status, &rec, query->context);
  1024. } else
  1025. query->callback(status, NULL, query->context);
  1026. }
  1027. static void ib_sa_path_rec_release(struct ib_sa_query *sa_query)
  1028. {
  1029. kfree(container_of(sa_query, struct ib_sa_path_query, sa_query));
  1030. }
  1031. /**
  1032. * ib_sa_path_rec_get - Start a Path get query
  1033. * @client:SA client
  1034. * @device:device to send query on
  1035. * @port_num: port number to send query on
  1036. * @rec:Path Record to send in query
  1037. * @comp_mask:component mask to send in query
  1038. * @timeout_ms:time to wait for response
  1039. * @gfp_mask:GFP mask to use for internal allocations
  1040. * @callback:function called when query completes, times out or is
  1041. * canceled
  1042. * @context:opaque user context passed to callback
  1043. * @sa_query:query context, used to cancel query
  1044. *
  1045. * Send a Path Record Get query to the SA to look up a path. The
  1046. * callback function will be called when the query completes (or
  1047. * fails); status is 0 for a successful response, -EINTR if the query
  1048. * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
  1049. * occurred sending the query. The resp parameter of the callback is
  1050. * only valid if status is 0.
  1051. *
  1052. * If the return value of ib_sa_path_rec_get() is negative, it is an
  1053. * error code. Otherwise it is a query ID that can be used to cancel
  1054. * the query.
  1055. */
  1056. int ib_sa_path_rec_get(struct ib_sa_client *client,
  1057. struct ib_device *device, u8 port_num,
  1058. struct ib_sa_path_rec *rec,
  1059. ib_sa_comp_mask comp_mask,
  1060. int timeout_ms, gfp_t gfp_mask,
  1061. void (*callback)(int status,
  1062. struct ib_sa_path_rec *resp,
  1063. void *context),
  1064. void *context,
  1065. struct ib_sa_query **sa_query)
  1066. {
  1067. struct ib_sa_path_query *query;
  1068. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1069. struct ib_sa_port *port;
  1070. struct ib_mad_agent *agent;
  1071. struct ib_sa_mad *mad;
  1072. int ret;
  1073. if (!sa_dev)
  1074. return -ENODEV;
  1075. port = &sa_dev->port[port_num - sa_dev->start_port];
  1076. agent = port->agent;
  1077. query = kzalloc(sizeof(*query), gfp_mask);
  1078. if (!query)
  1079. return -ENOMEM;
  1080. query->sa_query.port = port;
  1081. ret = alloc_mad(&query->sa_query, gfp_mask);
  1082. if (ret)
  1083. goto err1;
  1084. ib_sa_client_get(client);
  1085. query->sa_query.client = client;
  1086. query->callback = callback;
  1087. query->context = context;
  1088. mad = query->sa_query.mad_buf->mad;
  1089. init_mad(mad, agent);
  1090. query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL;
  1091. query->sa_query.release = ib_sa_path_rec_release;
  1092. mad->mad_hdr.method = IB_MGMT_METHOD_GET;
  1093. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_PATH_REC);
  1094. mad->sa_hdr.comp_mask = comp_mask;
  1095. ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, mad->data);
  1096. *sa_query = &query->sa_query;
  1097. query->sa_query.flags |= IB_SA_ENABLE_LOCAL_SERVICE;
  1098. query->sa_query.mad_buf->context[1] = rec;
  1099. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1100. if (ret < 0)
  1101. goto err2;
  1102. return ret;
  1103. err2:
  1104. *sa_query = NULL;
  1105. ib_sa_client_put(query->sa_query.client);
  1106. free_mad(&query->sa_query);
  1107. err1:
  1108. kfree(query);
  1109. return ret;
  1110. }
  1111. EXPORT_SYMBOL(ib_sa_path_rec_get);
  1112. static void ib_sa_service_rec_callback(struct ib_sa_query *sa_query,
  1113. int status,
  1114. struct ib_sa_mad *mad)
  1115. {
  1116. struct ib_sa_service_query *query =
  1117. container_of(sa_query, struct ib_sa_service_query, sa_query);
  1118. if (mad) {
  1119. struct ib_sa_service_rec rec;
  1120. ib_unpack(service_rec_table, ARRAY_SIZE(service_rec_table),
  1121. mad->data, &rec);
  1122. query->callback(status, &rec, query->context);
  1123. } else
  1124. query->callback(status, NULL, query->context);
  1125. }
  1126. static void ib_sa_service_rec_release(struct ib_sa_query *sa_query)
  1127. {
  1128. kfree(container_of(sa_query, struct ib_sa_service_query, sa_query));
  1129. }
  1130. /**
  1131. * ib_sa_service_rec_query - Start Service Record operation
  1132. * @client:SA client
  1133. * @device:device to send request on
  1134. * @port_num: port number to send request on
  1135. * @method:SA method - should be get, set, or delete
  1136. * @rec:Service Record to send in request
  1137. * @comp_mask:component mask to send in request
  1138. * @timeout_ms:time to wait for response
  1139. * @gfp_mask:GFP mask to use for internal allocations
  1140. * @callback:function called when request completes, times out or is
  1141. * canceled
  1142. * @context:opaque user context passed to callback
  1143. * @sa_query:request context, used to cancel request
  1144. *
  1145. * Send a Service Record set/get/delete to the SA to register,
  1146. * unregister or query a service record.
  1147. * The callback function will be called when the request completes (or
  1148. * fails); status is 0 for a successful response, -EINTR if the query
  1149. * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
  1150. * occurred sending the query. The resp parameter of the callback is
  1151. * only valid if status is 0.
  1152. *
  1153. * If the return value of ib_sa_service_rec_query() is negative, it is an
  1154. * error code. Otherwise it is a request ID that can be used to cancel
  1155. * the query.
  1156. */
  1157. int ib_sa_service_rec_query(struct ib_sa_client *client,
  1158. struct ib_device *device, u8 port_num, u8 method,
  1159. struct ib_sa_service_rec *rec,
  1160. ib_sa_comp_mask comp_mask,
  1161. int timeout_ms, gfp_t gfp_mask,
  1162. void (*callback)(int status,
  1163. struct ib_sa_service_rec *resp,
  1164. void *context),
  1165. void *context,
  1166. struct ib_sa_query **sa_query)
  1167. {
  1168. struct ib_sa_service_query *query;
  1169. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1170. struct ib_sa_port *port;
  1171. struct ib_mad_agent *agent;
  1172. struct ib_sa_mad *mad;
  1173. int ret;
  1174. if (!sa_dev)
  1175. return -ENODEV;
  1176. port = &sa_dev->port[port_num - sa_dev->start_port];
  1177. agent = port->agent;
  1178. if (method != IB_MGMT_METHOD_GET &&
  1179. method != IB_MGMT_METHOD_SET &&
  1180. method != IB_SA_METHOD_DELETE)
  1181. return -EINVAL;
  1182. query = kzalloc(sizeof(*query), gfp_mask);
  1183. if (!query)
  1184. return -ENOMEM;
  1185. query->sa_query.port = port;
  1186. ret = alloc_mad(&query->sa_query, gfp_mask);
  1187. if (ret)
  1188. goto err1;
  1189. ib_sa_client_get(client);
  1190. query->sa_query.client = client;
  1191. query->callback = callback;
  1192. query->context = context;
  1193. mad = query->sa_query.mad_buf->mad;
  1194. init_mad(mad, agent);
  1195. query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL;
  1196. query->sa_query.release = ib_sa_service_rec_release;
  1197. mad->mad_hdr.method = method;
  1198. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_SERVICE_REC);
  1199. mad->sa_hdr.comp_mask = comp_mask;
  1200. ib_pack(service_rec_table, ARRAY_SIZE(service_rec_table),
  1201. rec, mad->data);
  1202. *sa_query = &query->sa_query;
  1203. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1204. if (ret < 0)
  1205. goto err2;
  1206. return ret;
  1207. err2:
  1208. *sa_query = NULL;
  1209. ib_sa_client_put(query->sa_query.client);
  1210. free_mad(&query->sa_query);
  1211. err1:
  1212. kfree(query);
  1213. return ret;
  1214. }
  1215. EXPORT_SYMBOL(ib_sa_service_rec_query);
  1216. static void ib_sa_mcmember_rec_callback(struct ib_sa_query *sa_query,
  1217. int status,
  1218. struct ib_sa_mad *mad)
  1219. {
  1220. struct ib_sa_mcmember_query *query =
  1221. container_of(sa_query, struct ib_sa_mcmember_query, sa_query);
  1222. if (mad) {
  1223. struct ib_sa_mcmember_rec rec;
  1224. ib_unpack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
  1225. mad->data, &rec);
  1226. query->callback(status, &rec, query->context);
  1227. } else
  1228. query->callback(status, NULL, query->context);
  1229. }
  1230. static void ib_sa_mcmember_rec_release(struct ib_sa_query *sa_query)
  1231. {
  1232. kfree(container_of(sa_query, struct ib_sa_mcmember_query, sa_query));
  1233. }
  1234. int ib_sa_mcmember_rec_query(struct ib_sa_client *client,
  1235. struct ib_device *device, u8 port_num,
  1236. u8 method,
  1237. struct ib_sa_mcmember_rec *rec,
  1238. ib_sa_comp_mask comp_mask,
  1239. int timeout_ms, gfp_t gfp_mask,
  1240. void (*callback)(int status,
  1241. struct ib_sa_mcmember_rec *resp,
  1242. void *context),
  1243. void *context,
  1244. struct ib_sa_query **sa_query)
  1245. {
  1246. struct ib_sa_mcmember_query *query;
  1247. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1248. struct ib_sa_port *port;
  1249. struct ib_mad_agent *agent;
  1250. struct ib_sa_mad *mad;
  1251. int ret;
  1252. if (!sa_dev)
  1253. return -ENODEV;
  1254. port = &sa_dev->port[port_num - sa_dev->start_port];
  1255. agent = port->agent;
  1256. query = kzalloc(sizeof(*query), gfp_mask);
  1257. if (!query)
  1258. return -ENOMEM;
  1259. query->sa_query.port = port;
  1260. ret = alloc_mad(&query->sa_query, gfp_mask);
  1261. if (ret)
  1262. goto err1;
  1263. ib_sa_client_get(client);
  1264. query->sa_query.client = client;
  1265. query->callback = callback;
  1266. query->context = context;
  1267. mad = query->sa_query.mad_buf->mad;
  1268. init_mad(mad, agent);
  1269. query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL;
  1270. query->sa_query.release = ib_sa_mcmember_rec_release;
  1271. mad->mad_hdr.method = method;
  1272. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
  1273. mad->sa_hdr.comp_mask = comp_mask;
  1274. ib_pack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
  1275. rec, mad->data);
  1276. *sa_query = &query->sa_query;
  1277. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1278. if (ret < 0)
  1279. goto err2;
  1280. return ret;
  1281. err2:
  1282. *sa_query = NULL;
  1283. ib_sa_client_put(query->sa_query.client);
  1284. free_mad(&query->sa_query);
  1285. err1:
  1286. kfree(query);
  1287. return ret;
  1288. }
  1289. /* Support GuidInfoRecord */
  1290. static void ib_sa_guidinfo_rec_callback(struct ib_sa_query *sa_query,
  1291. int status,
  1292. struct ib_sa_mad *mad)
  1293. {
  1294. struct ib_sa_guidinfo_query *query =
  1295. container_of(sa_query, struct ib_sa_guidinfo_query, sa_query);
  1296. if (mad) {
  1297. struct ib_sa_guidinfo_rec rec;
  1298. ib_unpack(guidinfo_rec_table, ARRAY_SIZE(guidinfo_rec_table),
  1299. mad->data, &rec);
  1300. query->callback(status, &rec, query->context);
  1301. } else
  1302. query->callback(status, NULL, query->context);
  1303. }
  1304. static void ib_sa_guidinfo_rec_release(struct ib_sa_query *sa_query)
  1305. {
  1306. kfree(container_of(sa_query, struct ib_sa_guidinfo_query, sa_query));
  1307. }
  1308. int ib_sa_guid_info_rec_query(struct ib_sa_client *client,
  1309. struct ib_device *device, u8 port_num,
  1310. struct ib_sa_guidinfo_rec *rec,
  1311. ib_sa_comp_mask comp_mask, u8 method,
  1312. int timeout_ms, gfp_t gfp_mask,
  1313. void (*callback)(int status,
  1314. struct ib_sa_guidinfo_rec *resp,
  1315. void *context),
  1316. void *context,
  1317. struct ib_sa_query **sa_query)
  1318. {
  1319. struct ib_sa_guidinfo_query *query;
  1320. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1321. struct ib_sa_port *port;
  1322. struct ib_mad_agent *agent;
  1323. struct ib_sa_mad *mad;
  1324. int ret;
  1325. if (!sa_dev)
  1326. return -ENODEV;
  1327. if (method != IB_MGMT_METHOD_GET &&
  1328. method != IB_MGMT_METHOD_SET &&
  1329. method != IB_SA_METHOD_DELETE) {
  1330. return -EINVAL;
  1331. }
  1332. port = &sa_dev->port[port_num - sa_dev->start_port];
  1333. agent = port->agent;
  1334. query = kzalloc(sizeof(*query), gfp_mask);
  1335. if (!query)
  1336. return -ENOMEM;
  1337. query->sa_query.port = port;
  1338. ret = alloc_mad(&query->sa_query, gfp_mask);
  1339. if (ret)
  1340. goto err1;
  1341. ib_sa_client_get(client);
  1342. query->sa_query.client = client;
  1343. query->callback = callback;
  1344. query->context = context;
  1345. mad = query->sa_query.mad_buf->mad;
  1346. init_mad(mad, agent);
  1347. query->sa_query.callback = callback ? ib_sa_guidinfo_rec_callback : NULL;
  1348. query->sa_query.release = ib_sa_guidinfo_rec_release;
  1349. mad->mad_hdr.method = method;
  1350. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_GUID_INFO_REC);
  1351. mad->sa_hdr.comp_mask = comp_mask;
  1352. ib_pack(guidinfo_rec_table, ARRAY_SIZE(guidinfo_rec_table), rec,
  1353. mad->data);
  1354. *sa_query = &query->sa_query;
  1355. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1356. if (ret < 0)
  1357. goto err2;
  1358. return ret;
  1359. err2:
  1360. *sa_query = NULL;
  1361. ib_sa_client_put(query->sa_query.client);
  1362. free_mad(&query->sa_query);
  1363. err1:
  1364. kfree(query);
  1365. return ret;
  1366. }
  1367. EXPORT_SYMBOL(ib_sa_guid_info_rec_query);
  1368. static void send_handler(struct ib_mad_agent *agent,
  1369. struct ib_mad_send_wc *mad_send_wc)
  1370. {
  1371. struct ib_sa_query *query = mad_send_wc->send_buf->context[0];
  1372. unsigned long flags;
  1373. if (query->callback)
  1374. switch (mad_send_wc->status) {
  1375. case IB_WC_SUCCESS:
  1376. /* No callback -- already got recv */
  1377. break;
  1378. case IB_WC_RESP_TIMEOUT_ERR:
  1379. query->callback(query, -ETIMEDOUT, NULL);
  1380. break;
  1381. case IB_WC_WR_FLUSH_ERR:
  1382. query->callback(query, -EINTR, NULL);
  1383. break;
  1384. default:
  1385. query->callback(query, -EIO, NULL);
  1386. break;
  1387. }
  1388. spin_lock_irqsave(&idr_lock, flags);
  1389. idr_remove(&query_idr, query->id);
  1390. spin_unlock_irqrestore(&idr_lock, flags);
  1391. free_mad(query);
  1392. ib_sa_client_put(query->client);
  1393. query->release(query);
  1394. }
  1395. static void recv_handler(struct ib_mad_agent *mad_agent,
  1396. struct ib_mad_recv_wc *mad_recv_wc)
  1397. {
  1398. struct ib_sa_query *query;
  1399. struct ib_mad_send_buf *mad_buf;
  1400. mad_buf = (void *) (unsigned long) mad_recv_wc->wc->wr_id;
  1401. query = mad_buf->context[0];
  1402. if (query->callback) {
  1403. if (mad_recv_wc->wc->status == IB_WC_SUCCESS)
  1404. query->callback(query,
  1405. mad_recv_wc->recv_buf.mad->mad_hdr.status ?
  1406. -EINVAL : 0,
  1407. (struct ib_sa_mad *) mad_recv_wc->recv_buf.mad);
  1408. else
  1409. query->callback(query, -EIO, NULL);
  1410. }
  1411. ib_free_recv_mad(mad_recv_wc);
  1412. }
  1413. static void ib_sa_add_one(struct ib_device *device)
  1414. {
  1415. struct ib_sa_device *sa_dev;
  1416. int s, e, i;
  1417. int count = 0;
  1418. s = rdma_start_port(device);
  1419. e = rdma_end_port(device);
  1420. sa_dev = kzalloc(sizeof *sa_dev +
  1421. (e - s + 1) * sizeof (struct ib_sa_port),
  1422. GFP_KERNEL);
  1423. if (!sa_dev)
  1424. return;
  1425. sa_dev->start_port = s;
  1426. sa_dev->end_port = e;
  1427. for (i = 0; i <= e - s; ++i) {
  1428. spin_lock_init(&sa_dev->port[i].ah_lock);
  1429. if (!rdma_cap_ib_sa(device, i + 1))
  1430. continue;
  1431. sa_dev->port[i].sm_ah = NULL;
  1432. sa_dev->port[i].port_num = i + s;
  1433. sa_dev->port[i].agent =
  1434. ib_register_mad_agent(device, i + s, IB_QPT_GSI,
  1435. NULL, 0, send_handler,
  1436. recv_handler, sa_dev, 0);
  1437. if (IS_ERR(sa_dev->port[i].agent))
  1438. goto err;
  1439. INIT_WORK(&sa_dev->port[i].update_task, update_sm_ah);
  1440. count++;
  1441. }
  1442. if (!count)
  1443. goto free;
  1444. ib_set_client_data(device, &sa_client, sa_dev);
  1445. /*
  1446. * We register our event handler after everything is set up,
  1447. * and then update our cached info after the event handler is
  1448. * registered to avoid any problems if a port changes state
  1449. * during our initialization.
  1450. */
  1451. INIT_IB_EVENT_HANDLER(&sa_dev->event_handler, device, ib_sa_event);
  1452. if (ib_register_event_handler(&sa_dev->event_handler))
  1453. goto err;
  1454. for (i = 0; i <= e - s; ++i) {
  1455. if (rdma_cap_ib_sa(device, i + 1))
  1456. update_sm_ah(&sa_dev->port[i].update_task);
  1457. }
  1458. return;
  1459. err:
  1460. while (--i >= 0) {
  1461. if (rdma_cap_ib_sa(device, i + 1))
  1462. ib_unregister_mad_agent(sa_dev->port[i].agent);
  1463. }
  1464. free:
  1465. kfree(sa_dev);
  1466. return;
  1467. }
  1468. static void ib_sa_remove_one(struct ib_device *device, void *client_data)
  1469. {
  1470. struct ib_sa_device *sa_dev = client_data;
  1471. int i;
  1472. if (!sa_dev)
  1473. return;
  1474. ib_unregister_event_handler(&sa_dev->event_handler);
  1475. flush_workqueue(ib_wq);
  1476. for (i = 0; i <= sa_dev->end_port - sa_dev->start_port; ++i) {
  1477. if (rdma_cap_ib_sa(device, i + 1)) {
  1478. ib_unregister_mad_agent(sa_dev->port[i].agent);
  1479. if (sa_dev->port[i].sm_ah)
  1480. kref_put(&sa_dev->port[i].sm_ah->ref, free_sm_ah);
  1481. }
  1482. }
  1483. kfree(sa_dev);
  1484. }
  1485. static int __init ib_sa_init(void)
  1486. {
  1487. int ret;
  1488. get_random_bytes(&tid, sizeof tid);
  1489. atomic_set(&ib_nl_sa_request_seq, 0);
  1490. ret = ib_register_client(&sa_client);
  1491. if (ret) {
  1492. printk(KERN_ERR "Couldn't register ib_sa client\n");
  1493. goto err1;
  1494. }
  1495. ret = mcast_init();
  1496. if (ret) {
  1497. printk(KERN_ERR "Couldn't initialize multicast handling\n");
  1498. goto err2;
  1499. }
  1500. ib_nl_wq = create_singlethread_workqueue("ib_nl_sa_wq");
  1501. if (!ib_nl_wq) {
  1502. ret = -ENOMEM;
  1503. goto err3;
  1504. }
  1505. if (ibnl_add_client(RDMA_NL_LS, RDMA_NL_LS_NUM_OPS,
  1506. ib_sa_cb_table)) {
  1507. pr_err("Failed to add netlink callback\n");
  1508. ret = -EINVAL;
  1509. goto err4;
  1510. }
  1511. INIT_DELAYED_WORK(&ib_nl_timed_work, ib_nl_request_timeout);
  1512. return 0;
  1513. err4:
  1514. destroy_workqueue(ib_nl_wq);
  1515. err3:
  1516. mcast_cleanup();
  1517. err2:
  1518. ib_unregister_client(&sa_client);
  1519. err1:
  1520. return ret;
  1521. }
  1522. static void __exit ib_sa_cleanup(void)
  1523. {
  1524. ibnl_remove_client(RDMA_NL_LS);
  1525. cancel_delayed_work(&ib_nl_timed_work);
  1526. flush_workqueue(ib_nl_wq);
  1527. destroy_workqueue(ib_nl_wq);
  1528. mcast_cleanup();
  1529. ib_unregister_client(&sa_client);
  1530. idr_destroy(&query_idr);
  1531. }
  1532. module_init(ib_sa_init);
  1533. module_exit(ib_sa_cleanup);