sa_query.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300
  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/init.h>
  35. #include <linux/err.h>
  36. #include <linux/random.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/slab.h>
  39. #include <linux/dma-mapping.h>
  40. #include <linux/kref.h>
  41. #include <linux/xarray.h>
  42. #include <linux/workqueue.h>
  43. #include <uapi/linux/if_ether.h>
  44. #include <rdma/ib_pack.h>
  45. #include <rdma/ib_cache.h>
  46. #include <rdma/rdma_netlink.h>
  47. #include <net/netlink.h>
  48. #include <uapi/rdma/ib_user_sa.h>
  49. #include <rdma/ib_marshall.h>
  50. #include <rdma/ib_addr.h>
  51. #include <rdma/opa_addr.h>
  52. #include <rdma/rdma_cm.h>
  53. #include "sa.h"
  54. #include "core_priv.h"
  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. #define IB_SA_CPI_MAX_RETRY_CNT 3
  59. #define IB_SA_CPI_RETRY_WAIT 1000 /*msecs */
  60. static int sa_local_svc_timeout_ms = IB_SA_LOCAL_SVC_TIMEOUT_DEFAULT;
  61. struct ib_sa_sm_ah {
  62. struct ib_ah *ah;
  63. struct kref ref;
  64. u16 pkey_index;
  65. u8 src_path_mask;
  66. };
  67. enum rdma_class_port_info_type {
  68. RDMA_CLASS_PORT_INFO_IB,
  69. RDMA_CLASS_PORT_INFO_OPA
  70. };
  71. struct rdma_class_port_info {
  72. enum rdma_class_port_info_type type;
  73. union {
  74. struct ib_class_port_info ib;
  75. struct opa_class_port_info opa;
  76. };
  77. };
  78. struct ib_sa_classport_cache {
  79. bool valid;
  80. int retry_cnt;
  81. struct rdma_class_port_info data;
  82. };
  83. struct ib_sa_port {
  84. struct ib_mad_agent *agent;
  85. struct ib_sa_sm_ah *sm_ah;
  86. struct work_struct update_task;
  87. struct ib_sa_classport_cache classport_info;
  88. struct delayed_work ib_cpi_work;
  89. spinlock_t classport_lock; /* protects class port info set */
  90. spinlock_t ah_lock;
  91. u32 port_num;
  92. };
  93. struct ib_sa_device {
  94. int start_port, end_port;
  95. struct ib_event_handler event_handler;
  96. struct ib_sa_port port[];
  97. };
  98. struct ib_sa_query {
  99. void (*callback)(struct ib_sa_query *sa_query, int status,
  100. struct ib_sa_mad *mad);
  101. void (*release)(struct ib_sa_query *);
  102. struct ib_sa_client *client;
  103. struct ib_sa_port *port;
  104. struct ib_mad_send_buf *mad_buf;
  105. struct ib_sa_sm_ah *sm_ah;
  106. int id;
  107. u32 flags;
  108. struct list_head list; /* Local svc request list */
  109. u32 seq; /* Local svc request sequence number */
  110. unsigned long timeout; /* Local svc timeout */
  111. u8 path_use; /* How will the pathrecord be used */
  112. };
  113. #define IB_SA_ENABLE_LOCAL_SERVICE 0x00000001
  114. #define IB_SA_CANCEL 0x00000002
  115. #define IB_SA_QUERY_OPA 0x00000004
  116. struct ib_sa_path_query {
  117. void (*callback)(int status, struct sa_path_rec *rec,
  118. unsigned int num_paths, void *context);
  119. void *context;
  120. struct ib_sa_query sa_query;
  121. struct sa_path_rec *conv_pr;
  122. };
  123. struct ib_sa_guidinfo_query {
  124. void (*callback)(int, struct ib_sa_guidinfo_rec *, void *);
  125. void *context;
  126. struct ib_sa_query sa_query;
  127. };
  128. struct ib_sa_classport_info_query {
  129. void (*callback)(void *);
  130. void *context;
  131. struct ib_sa_query sa_query;
  132. };
  133. struct ib_sa_mcmember_query {
  134. void (*callback)(int, struct ib_sa_mcmember_rec *, void *);
  135. void *context;
  136. struct ib_sa_query sa_query;
  137. };
  138. static LIST_HEAD(ib_nl_request_list);
  139. static DEFINE_SPINLOCK(ib_nl_request_lock);
  140. static atomic_t ib_nl_sa_request_seq;
  141. static struct workqueue_struct *ib_nl_wq;
  142. static struct delayed_work ib_nl_timed_work;
  143. static const struct nla_policy ib_nl_policy[LS_NLA_TYPE_MAX] = {
  144. [LS_NLA_TYPE_PATH_RECORD] = {.type = NLA_BINARY,
  145. .len = sizeof(struct ib_path_rec_data)},
  146. [LS_NLA_TYPE_TIMEOUT] = {.type = NLA_U32},
  147. [LS_NLA_TYPE_SERVICE_ID] = {.type = NLA_U64},
  148. [LS_NLA_TYPE_DGID] = {.type = NLA_BINARY,
  149. .len = sizeof(struct rdma_nla_ls_gid)},
  150. [LS_NLA_TYPE_SGID] = {.type = NLA_BINARY,
  151. .len = sizeof(struct rdma_nla_ls_gid)},
  152. [LS_NLA_TYPE_TCLASS] = {.type = NLA_U8},
  153. [LS_NLA_TYPE_PKEY] = {.type = NLA_U16},
  154. [LS_NLA_TYPE_QOS_CLASS] = {.type = NLA_U16},
  155. };
  156. static int ib_sa_add_one(struct ib_device *device);
  157. static void ib_sa_remove_one(struct ib_device *device, void *client_data);
  158. static struct ib_client sa_client = {
  159. .name = "sa",
  160. .add = ib_sa_add_one,
  161. .remove = ib_sa_remove_one
  162. };
  163. static DEFINE_XARRAY_FLAGS(queries, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ);
  164. static DEFINE_SPINLOCK(tid_lock);
  165. static u32 tid;
  166. #define PATH_REC_FIELD(field) \
  167. .struct_offset_bytes = offsetof(struct sa_path_rec, field), \
  168. .struct_size_bytes = sizeof_field(struct sa_path_rec, field), \
  169. .field_name = "sa_path_rec:" #field
  170. static const struct ib_field path_rec_table[] = {
  171. { PATH_REC_FIELD(service_id),
  172. .offset_words = 0,
  173. .offset_bits = 0,
  174. .size_bits = 64 },
  175. { PATH_REC_FIELD(dgid),
  176. .offset_words = 2,
  177. .offset_bits = 0,
  178. .size_bits = 128 },
  179. { PATH_REC_FIELD(sgid),
  180. .offset_words = 6,
  181. .offset_bits = 0,
  182. .size_bits = 128 },
  183. { PATH_REC_FIELD(ib.dlid),
  184. .offset_words = 10,
  185. .offset_bits = 0,
  186. .size_bits = 16 },
  187. { PATH_REC_FIELD(ib.slid),
  188. .offset_words = 10,
  189. .offset_bits = 16,
  190. .size_bits = 16 },
  191. { PATH_REC_FIELD(ib.raw_traffic),
  192. .offset_words = 11,
  193. .offset_bits = 0,
  194. .size_bits = 1 },
  195. { RESERVED,
  196. .offset_words = 11,
  197. .offset_bits = 1,
  198. .size_bits = 3 },
  199. { PATH_REC_FIELD(flow_label),
  200. .offset_words = 11,
  201. .offset_bits = 4,
  202. .size_bits = 20 },
  203. { PATH_REC_FIELD(hop_limit),
  204. .offset_words = 11,
  205. .offset_bits = 24,
  206. .size_bits = 8 },
  207. { PATH_REC_FIELD(traffic_class),
  208. .offset_words = 12,
  209. .offset_bits = 0,
  210. .size_bits = 8 },
  211. { PATH_REC_FIELD(reversible),
  212. .offset_words = 12,
  213. .offset_bits = 8,
  214. .size_bits = 1 },
  215. { PATH_REC_FIELD(numb_path),
  216. .offset_words = 12,
  217. .offset_bits = 9,
  218. .size_bits = 7 },
  219. { PATH_REC_FIELD(pkey),
  220. .offset_words = 12,
  221. .offset_bits = 16,
  222. .size_bits = 16 },
  223. { PATH_REC_FIELD(qos_class),
  224. .offset_words = 13,
  225. .offset_bits = 0,
  226. .size_bits = 12 },
  227. { PATH_REC_FIELD(sl),
  228. .offset_words = 13,
  229. .offset_bits = 12,
  230. .size_bits = 4 },
  231. { PATH_REC_FIELD(mtu_selector),
  232. .offset_words = 13,
  233. .offset_bits = 16,
  234. .size_bits = 2 },
  235. { PATH_REC_FIELD(mtu),
  236. .offset_words = 13,
  237. .offset_bits = 18,
  238. .size_bits = 6 },
  239. { PATH_REC_FIELD(rate_selector),
  240. .offset_words = 13,
  241. .offset_bits = 24,
  242. .size_bits = 2 },
  243. { PATH_REC_FIELD(rate),
  244. .offset_words = 13,
  245. .offset_bits = 26,
  246. .size_bits = 6 },
  247. { PATH_REC_FIELD(packet_life_time_selector),
  248. .offset_words = 14,
  249. .offset_bits = 0,
  250. .size_bits = 2 },
  251. { PATH_REC_FIELD(packet_life_time),
  252. .offset_words = 14,
  253. .offset_bits = 2,
  254. .size_bits = 6 },
  255. { PATH_REC_FIELD(preference),
  256. .offset_words = 14,
  257. .offset_bits = 8,
  258. .size_bits = 8 },
  259. { RESERVED,
  260. .offset_words = 14,
  261. .offset_bits = 16,
  262. .size_bits = 48 },
  263. };
  264. #define OPA_PATH_REC_FIELD(field) \
  265. .struct_offset_bytes = \
  266. offsetof(struct sa_path_rec, field), \
  267. .struct_size_bytes = \
  268. sizeof_field(struct sa_path_rec, field), \
  269. .field_name = "sa_path_rec:" #field
  270. static const struct ib_field opa_path_rec_table[] = {
  271. { OPA_PATH_REC_FIELD(service_id),
  272. .offset_words = 0,
  273. .offset_bits = 0,
  274. .size_bits = 64 },
  275. { OPA_PATH_REC_FIELD(dgid),
  276. .offset_words = 2,
  277. .offset_bits = 0,
  278. .size_bits = 128 },
  279. { OPA_PATH_REC_FIELD(sgid),
  280. .offset_words = 6,
  281. .offset_bits = 0,
  282. .size_bits = 128 },
  283. { OPA_PATH_REC_FIELD(opa.dlid),
  284. .offset_words = 10,
  285. .offset_bits = 0,
  286. .size_bits = 32 },
  287. { OPA_PATH_REC_FIELD(opa.slid),
  288. .offset_words = 11,
  289. .offset_bits = 0,
  290. .size_bits = 32 },
  291. { OPA_PATH_REC_FIELD(opa.raw_traffic),
  292. .offset_words = 12,
  293. .offset_bits = 0,
  294. .size_bits = 1 },
  295. { RESERVED,
  296. .offset_words = 12,
  297. .offset_bits = 1,
  298. .size_bits = 3 },
  299. { OPA_PATH_REC_FIELD(flow_label),
  300. .offset_words = 12,
  301. .offset_bits = 4,
  302. .size_bits = 20 },
  303. { OPA_PATH_REC_FIELD(hop_limit),
  304. .offset_words = 12,
  305. .offset_bits = 24,
  306. .size_bits = 8 },
  307. { OPA_PATH_REC_FIELD(traffic_class),
  308. .offset_words = 13,
  309. .offset_bits = 0,
  310. .size_bits = 8 },
  311. { OPA_PATH_REC_FIELD(reversible),
  312. .offset_words = 13,
  313. .offset_bits = 8,
  314. .size_bits = 1 },
  315. { OPA_PATH_REC_FIELD(numb_path),
  316. .offset_words = 13,
  317. .offset_bits = 9,
  318. .size_bits = 7 },
  319. { OPA_PATH_REC_FIELD(pkey),
  320. .offset_words = 13,
  321. .offset_bits = 16,
  322. .size_bits = 16 },
  323. { OPA_PATH_REC_FIELD(opa.l2_8B),
  324. .offset_words = 14,
  325. .offset_bits = 0,
  326. .size_bits = 1 },
  327. { OPA_PATH_REC_FIELD(opa.l2_10B),
  328. .offset_words = 14,
  329. .offset_bits = 1,
  330. .size_bits = 1 },
  331. { OPA_PATH_REC_FIELD(opa.l2_9B),
  332. .offset_words = 14,
  333. .offset_bits = 2,
  334. .size_bits = 1 },
  335. { OPA_PATH_REC_FIELD(opa.l2_16B),
  336. .offset_words = 14,
  337. .offset_bits = 3,
  338. .size_bits = 1 },
  339. { RESERVED,
  340. .offset_words = 14,
  341. .offset_bits = 4,
  342. .size_bits = 2 },
  343. { OPA_PATH_REC_FIELD(opa.qos_type),
  344. .offset_words = 14,
  345. .offset_bits = 6,
  346. .size_bits = 2 },
  347. { OPA_PATH_REC_FIELD(opa.qos_priority),
  348. .offset_words = 14,
  349. .offset_bits = 8,
  350. .size_bits = 8 },
  351. { RESERVED,
  352. .offset_words = 14,
  353. .offset_bits = 16,
  354. .size_bits = 3 },
  355. { OPA_PATH_REC_FIELD(sl),
  356. .offset_words = 14,
  357. .offset_bits = 19,
  358. .size_bits = 5 },
  359. { RESERVED,
  360. .offset_words = 14,
  361. .offset_bits = 24,
  362. .size_bits = 8 },
  363. { OPA_PATH_REC_FIELD(mtu_selector),
  364. .offset_words = 15,
  365. .offset_bits = 0,
  366. .size_bits = 2 },
  367. { OPA_PATH_REC_FIELD(mtu),
  368. .offset_words = 15,
  369. .offset_bits = 2,
  370. .size_bits = 6 },
  371. { OPA_PATH_REC_FIELD(rate_selector),
  372. .offset_words = 15,
  373. .offset_bits = 8,
  374. .size_bits = 2 },
  375. { OPA_PATH_REC_FIELD(rate),
  376. .offset_words = 15,
  377. .offset_bits = 10,
  378. .size_bits = 6 },
  379. { OPA_PATH_REC_FIELD(packet_life_time_selector),
  380. .offset_words = 15,
  381. .offset_bits = 16,
  382. .size_bits = 2 },
  383. { OPA_PATH_REC_FIELD(packet_life_time),
  384. .offset_words = 15,
  385. .offset_bits = 18,
  386. .size_bits = 6 },
  387. { OPA_PATH_REC_FIELD(preference),
  388. .offset_words = 15,
  389. .offset_bits = 24,
  390. .size_bits = 8 },
  391. };
  392. #define MCMEMBER_REC_FIELD(field) \
  393. .struct_offset_bytes = offsetof(struct ib_sa_mcmember_rec, field), \
  394. .struct_size_bytes = sizeof_field(struct ib_sa_mcmember_rec, field), \
  395. .field_name = "sa_mcmember_rec:" #field
  396. static const struct ib_field mcmember_rec_table[] = {
  397. { MCMEMBER_REC_FIELD(mgid),
  398. .offset_words = 0,
  399. .offset_bits = 0,
  400. .size_bits = 128 },
  401. { MCMEMBER_REC_FIELD(port_gid),
  402. .offset_words = 4,
  403. .offset_bits = 0,
  404. .size_bits = 128 },
  405. { MCMEMBER_REC_FIELD(qkey),
  406. .offset_words = 8,
  407. .offset_bits = 0,
  408. .size_bits = 32 },
  409. { MCMEMBER_REC_FIELD(mlid),
  410. .offset_words = 9,
  411. .offset_bits = 0,
  412. .size_bits = 16 },
  413. { MCMEMBER_REC_FIELD(mtu_selector),
  414. .offset_words = 9,
  415. .offset_bits = 16,
  416. .size_bits = 2 },
  417. { MCMEMBER_REC_FIELD(mtu),
  418. .offset_words = 9,
  419. .offset_bits = 18,
  420. .size_bits = 6 },
  421. { MCMEMBER_REC_FIELD(traffic_class),
  422. .offset_words = 9,
  423. .offset_bits = 24,
  424. .size_bits = 8 },
  425. { MCMEMBER_REC_FIELD(pkey),
  426. .offset_words = 10,
  427. .offset_bits = 0,
  428. .size_bits = 16 },
  429. { MCMEMBER_REC_FIELD(rate_selector),
  430. .offset_words = 10,
  431. .offset_bits = 16,
  432. .size_bits = 2 },
  433. { MCMEMBER_REC_FIELD(rate),
  434. .offset_words = 10,
  435. .offset_bits = 18,
  436. .size_bits = 6 },
  437. { MCMEMBER_REC_FIELD(packet_life_time_selector),
  438. .offset_words = 10,
  439. .offset_bits = 24,
  440. .size_bits = 2 },
  441. { MCMEMBER_REC_FIELD(packet_life_time),
  442. .offset_words = 10,
  443. .offset_bits = 26,
  444. .size_bits = 6 },
  445. { MCMEMBER_REC_FIELD(sl),
  446. .offset_words = 11,
  447. .offset_bits = 0,
  448. .size_bits = 4 },
  449. { MCMEMBER_REC_FIELD(flow_label),
  450. .offset_words = 11,
  451. .offset_bits = 4,
  452. .size_bits = 20 },
  453. { MCMEMBER_REC_FIELD(hop_limit),
  454. .offset_words = 11,
  455. .offset_bits = 24,
  456. .size_bits = 8 },
  457. { MCMEMBER_REC_FIELD(scope),
  458. .offset_words = 12,
  459. .offset_bits = 0,
  460. .size_bits = 4 },
  461. { MCMEMBER_REC_FIELD(join_state),
  462. .offset_words = 12,
  463. .offset_bits = 4,
  464. .size_bits = 4 },
  465. { MCMEMBER_REC_FIELD(proxy_join),
  466. .offset_words = 12,
  467. .offset_bits = 8,
  468. .size_bits = 1 },
  469. { RESERVED,
  470. .offset_words = 12,
  471. .offset_bits = 9,
  472. .size_bits = 23 },
  473. };
  474. #define CLASSPORTINFO_REC_FIELD(field) \
  475. .struct_offset_bytes = offsetof(struct ib_class_port_info, field), \
  476. .struct_size_bytes = sizeof_field(struct ib_class_port_info, field), \
  477. .field_name = "ib_class_port_info:" #field
  478. static const struct ib_field ib_classport_info_rec_table[] = {
  479. { CLASSPORTINFO_REC_FIELD(base_version),
  480. .offset_words = 0,
  481. .offset_bits = 0,
  482. .size_bits = 8 },
  483. { CLASSPORTINFO_REC_FIELD(class_version),
  484. .offset_words = 0,
  485. .offset_bits = 8,
  486. .size_bits = 8 },
  487. { CLASSPORTINFO_REC_FIELD(capability_mask),
  488. .offset_words = 0,
  489. .offset_bits = 16,
  490. .size_bits = 16 },
  491. { CLASSPORTINFO_REC_FIELD(cap_mask2_resp_time),
  492. .offset_words = 1,
  493. .offset_bits = 0,
  494. .size_bits = 32 },
  495. { CLASSPORTINFO_REC_FIELD(redirect_gid),
  496. .offset_words = 2,
  497. .offset_bits = 0,
  498. .size_bits = 128 },
  499. { CLASSPORTINFO_REC_FIELD(redirect_tcslfl),
  500. .offset_words = 6,
  501. .offset_bits = 0,
  502. .size_bits = 32 },
  503. { CLASSPORTINFO_REC_FIELD(redirect_lid),
  504. .offset_words = 7,
  505. .offset_bits = 0,
  506. .size_bits = 16 },
  507. { CLASSPORTINFO_REC_FIELD(redirect_pkey),
  508. .offset_words = 7,
  509. .offset_bits = 16,
  510. .size_bits = 16 },
  511. { CLASSPORTINFO_REC_FIELD(redirect_qp),
  512. .offset_words = 8,
  513. .offset_bits = 0,
  514. .size_bits = 32 },
  515. { CLASSPORTINFO_REC_FIELD(redirect_qkey),
  516. .offset_words = 9,
  517. .offset_bits = 0,
  518. .size_bits = 32 },
  519. { CLASSPORTINFO_REC_FIELD(trap_gid),
  520. .offset_words = 10,
  521. .offset_bits = 0,
  522. .size_bits = 128 },
  523. { CLASSPORTINFO_REC_FIELD(trap_tcslfl),
  524. .offset_words = 14,
  525. .offset_bits = 0,
  526. .size_bits = 32 },
  527. { CLASSPORTINFO_REC_FIELD(trap_lid),
  528. .offset_words = 15,
  529. .offset_bits = 0,
  530. .size_bits = 16 },
  531. { CLASSPORTINFO_REC_FIELD(trap_pkey),
  532. .offset_words = 15,
  533. .offset_bits = 16,
  534. .size_bits = 16 },
  535. { CLASSPORTINFO_REC_FIELD(trap_hlqp),
  536. .offset_words = 16,
  537. .offset_bits = 0,
  538. .size_bits = 32 },
  539. { CLASSPORTINFO_REC_FIELD(trap_qkey),
  540. .offset_words = 17,
  541. .offset_bits = 0,
  542. .size_bits = 32 },
  543. };
  544. #define OPA_CLASSPORTINFO_REC_FIELD(field) \
  545. .struct_offset_bytes =\
  546. offsetof(struct opa_class_port_info, field), \
  547. .struct_size_bytes = \
  548. sizeof_field(struct opa_class_port_info, field), \
  549. .field_name = "opa_class_port_info:" #field
  550. static const struct ib_field opa_classport_info_rec_table[] = {
  551. { OPA_CLASSPORTINFO_REC_FIELD(base_version),
  552. .offset_words = 0,
  553. .offset_bits = 0,
  554. .size_bits = 8 },
  555. { OPA_CLASSPORTINFO_REC_FIELD(class_version),
  556. .offset_words = 0,
  557. .offset_bits = 8,
  558. .size_bits = 8 },
  559. { OPA_CLASSPORTINFO_REC_FIELD(cap_mask),
  560. .offset_words = 0,
  561. .offset_bits = 16,
  562. .size_bits = 16 },
  563. { OPA_CLASSPORTINFO_REC_FIELD(cap_mask2_resp_time),
  564. .offset_words = 1,
  565. .offset_bits = 0,
  566. .size_bits = 32 },
  567. { OPA_CLASSPORTINFO_REC_FIELD(redirect_gid),
  568. .offset_words = 2,
  569. .offset_bits = 0,
  570. .size_bits = 128 },
  571. { OPA_CLASSPORTINFO_REC_FIELD(redirect_tc_fl),
  572. .offset_words = 6,
  573. .offset_bits = 0,
  574. .size_bits = 32 },
  575. { OPA_CLASSPORTINFO_REC_FIELD(redirect_lid),
  576. .offset_words = 7,
  577. .offset_bits = 0,
  578. .size_bits = 32 },
  579. { OPA_CLASSPORTINFO_REC_FIELD(redirect_sl_qp),
  580. .offset_words = 8,
  581. .offset_bits = 0,
  582. .size_bits = 32 },
  583. { OPA_CLASSPORTINFO_REC_FIELD(redirect_qkey),
  584. .offset_words = 9,
  585. .offset_bits = 0,
  586. .size_bits = 32 },
  587. { OPA_CLASSPORTINFO_REC_FIELD(trap_gid),
  588. .offset_words = 10,
  589. .offset_bits = 0,
  590. .size_bits = 128 },
  591. { OPA_CLASSPORTINFO_REC_FIELD(trap_tc_fl),
  592. .offset_words = 14,
  593. .offset_bits = 0,
  594. .size_bits = 32 },
  595. { OPA_CLASSPORTINFO_REC_FIELD(trap_lid),
  596. .offset_words = 15,
  597. .offset_bits = 0,
  598. .size_bits = 32 },
  599. { OPA_CLASSPORTINFO_REC_FIELD(trap_hl_qp),
  600. .offset_words = 16,
  601. .offset_bits = 0,
  602. .size_bits = 32 },
  603. { OPA_CLASSPORTINFO_REC_FIELD(trap_qkey),
  604. .offset_words = 17,
  605. .offset_bits = 0,
  606. .size_bits = 32 },
  607. { OPA_CLASSPORTINFO_REC_FIELD(trap_pkey),
  608. .offset_words = 18,
  609. .offset_bits = 0,
  610. .size_bits = 16 },
  611. { OPA_CLASSPORTINFO_REC_FIELD(redirect_pkey),
  612. .offset_words = 18,
  613. .offset_bits = 16,
  614. .size_bits = 16 },
  615. { OPA_CLASSPORTINFO_REC_FIELD(trap_sl_rsvd),
  616. .offset_words = 19,
  617. .offset_bits = 0,
  618. .size_bits = 8 },
  619. { RESERVED,
  620. .offset_words = 19,
  621. .offset_bits = 8,
  622. .size_bits = 24 },
  623. };
  624. #define GUIDINFO_REC_FIELD(field) \
  625. .struct_offset_bytes = offsetof(struct ib_sa_guidinfo_rec, field), \
  626. .struct_size_bytes = sizeof_field(struct ib_sa_guidinfo_rec, field), \
  627. .field_name = "sa_guidinfo_rec:" #field
  628. static const struct ib_field guidinfo_rec_table[] = {
  629. { GUIDINFO_REC_FIELD(lid),
  630. .offset_words = 0,
  631. .offset_bits = 0,
  632. .size_bits = 16 },
  633. { GUIDINFO_REC_FIELD(block_num),
  634. .offset_words = 0,
  635. .offset_bits = 16,
  636. .size_bits = 8 },
  637. { GUIDINFO_REC_FIELD(res1),
  638. .offset_words = 0,
  639. .offset_bits = 24,
  640. .size_bits = 8 },
  641. { GUIDINFO_REC_FIELD(res2),
  642. .offset_words = 1,
  643. .offset_bits = 0,
  644. .size_bits = 32 },
  645. { GUIDINFO_REC_FIELD(guid_info_list),
  646. .offset_words = 2,
  647. .offset_bits = 0,
  648. .size_bits = 512 },
  649. };
  650. #define RDMA_PRIMARY_PATH_MAX_REC_NUM 3
  651. static inline void ib_sa_disable_local_svc(struct ib_sa_query *query)
  652. {
  653. query->flags &= ~IB_SA_ENABLE_LOCAL_SERVICE;
  654. }
  655. static inline int ib_sa_query_cancelled(struct ib_sa_query *query)
  656. {
  657. return (query->flags & IB_SA_CANCEL);
  658. }
  659. static void ib_nl_set_path_rec_attrs(struct sk_buff *skb,
  660. struct ib_sa_query *query)
  661. {
  662. struct sa_path_rec *sa_rec = query->mad_buf->context[1];
  663. struct ib_sa_mad *mad = query->mad_buf->mad;
  664. ib_sa_comp_mask comp_mask = mad->sa_hdr.comp_mask;
  665. u16 val16;
  666. u64 val64;
  667. struct rdma_ls_resolve_header *header;
  668. query->mad_buf->context[1] = NULL;
  669. /* Construct the family header first */
  670. header = skb_put(skb, NLMSG_ALIGN(sizeof(*header)));
  671. strscpy_pad(header->device_name,
  672. dev_name(&query->port->agent->device->dev),
  673. LS_DEVICE_NAME_MAX);
  674. header->port_num = query->port->port_num;
  675. if ((comp_mask & IB_SA_PATH_REC_REVERSIBLE) &&
  676. sa_rec->reversible != 0)
  677. query->path_use = LS_RESOLVE_PATH_USE_ALL;
  678. else
  679. query->path_use = LS_RESOLVE_PATH_USE_UNIDIRECTIONAL;
  680. header->path_use = query->path_use;
  681. /* Now build the attributes */
  682. if (comp_mask & IB_SA_PATH_REC_SERVICE_ID) {
  683. val64 = be64_to_cpu(sa_rec->service_id);
  684. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_SERVICE_ID,
  685. sizeof(val64), &val64);
  686. }
  687. if (comp_mask & IB_SA_PATH_REC_DGID)
  688. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_DGID,
  689. sizeof(sa_rec->dgid), &sa_rec->dgid);
  690. if (comp_mask & IB_SA_PATH_REC_SGID)
  691. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_SGID,
  692. sizeof(sa_rec->sgid), &sa_rec->sgid);
  693. if (comp_mask & IB_SA_PATH_REC_TRAFFIC_CLASS)
  694. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_TCLASS,
  695. sizeof(sa_rec->traffic_class), &sa_rec->traffic_class);
  696. if (comp_mask & IB_SA_PATH_REC_PKEY) {
  697. val16 = be16_to_cpu(sa_rec->pkey);
  698. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_PKEY,
  699. sizeof(val16), &val16);
  700. }
  701. if (comp_mask & IB_SA_PATH_REC_QOS_CLASS) {
  702. val16 = be16_to_cpu(sa_rec->qos_class);
  703. nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_QOS_CLASS,
  704. sizeof(val16), &val16);
  705. }
  706. }
  707. static int ib_nl_get_path_rec_attrs_len(ib_sa_comp_mask comp_mask)
  708. {
  709. int len = 0;
  710. if (comp_mask & IB_SA_PATH_REC_SERVICE_ID)
  711. len += nla_total_size(sizeof(u64));
  712. if (comp_mask & IB_SA_PATH_REC_DGID)
  713. len += nla_total_size(sizeof(struct rdma_nla_ls_gid));
  714. if (comp_mask & IB_SA_PATH_REC_SGID)
  715. len += nla_total_size(sizeof(struct rdma_nla_ls_gid));
  716. if (comp_mask & IB_SA_PATH_REC_TRAFFIC_CLASS)
  717. len += nla_total_size(sizeof(u8));
  718. if (comp_mask & IB_SA_PATH_REC_PKEY)
  719. len += nla_total_size(sizeof(u16));
  720. if (comp_mask & IB_SA_PATH_REC_QOS_CLASS)
  721. len += nla_total_size(sizeof(u16));
  722. /*
  723. * Make sure that at least some of the required comp_mask bits are
  724. * set.
  725. */
  726. if (WARN_ON(len == 0))
  727. return len;
  728. /* Add the family header */
  729. len += NLMSG_ALIGN(sizeof(struct rdma_ls_resolve_header));
  730. return len;
  731. }
  732. static int ib_nl_make_request(struct ib_sa_query *query, gfp_t gfp_mask)
  733. {
  734. struct sk_buff *skb = NULL;
  735. struct nlmsghdr *nlh;
  736. void *data;
  737. struct ib_sa_mad *mad;
  738. int len;
  739. unsigned long flags;
  740. unsigned long delay;
  741. gfp_t gfp_flag;
  742. int ret;
  743. INIT_LIST_HEAD(&query->list);
  744. query->seq = (u32)atomic_inc_return(&ib_nl_sa_request_seq);
  745. mad = query->mad_buf->mad;
  746. len = ib_nl_get_path_rec_attrs_len(mad->sa_hdr.comp_mask);
  747. if (len <= 0)
  748. return -EMSGSIZE;
  749. skb = nlmsg_new(len, gfp_mask);
  750. if (!skb)
  751. return -ENOMEM;
  752. /* Put nlmsg header only for now */
  753. data = ibnl_put_msg(skb, &nlh, query->seq, 0, RDMA_NL_LS,
  754. RDMA_NL_LS_OP_RESOLVE, NLM_F_REQUEST);
  755. if (!data) {
  756. nlmsg_free(skb);
  757. return -EMSGSIZE;
  758. }
  759. /* Add attributes */
  760. ib_nl_set_path_rec_attrs(skb, query);
  761. /* Repair the nlmsg header length */
  762. nlmsg_end(skb, nlh);
  763. gfp_flag = ((gfp_mask & GFP_ATOMIC) == GFP_ATOMIC) ? GFP_ATOMIC :
  764. GFP_NOWAIT;
  765. spin_lock_irqsave(&ib_nl_request_lock, flags);
  766. ret = rdma_nl_multicast(&init_net, skb, RDMA_NL_GROUP_LS, gfp_flag);
  767. if (ret)
  768. goto out;
  769. /* Put the request on the list.*/
  770. delay = msecs_to_jiffies(sa_local_svc_timeout_ms);
  771. query->timeout = delay + jiffies;
  772. list_add_tail(&query->list, &ib_nl_request_list);
  773. /* Start the timeout if this is the only request */
  774. if (ib_nl_request_list.next == &query->list)
  775. queue_delayed_work(ib_nl_wq, &ib_nl_timed_work, delay);
  776. out:
  777. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  778. return ret;
  779. }
  780. static int ib_nl_cancel_request(struct ib_sa_query *query)
  781. {
  782. unsigned long flags;
  783. struct ib_sa_query *wait_query;
  784. int found = 0;
  785. spin_lock_irqsave(&ib_nl_request_lock, flags);
  786. list_for_each_entry(wait_query, &ib_nl_request_list, list) {
  787. /* Let the timeout to take care of the callback */
  788. if (query == wait_query) {
  789. query->flags |= IB_SA_CANCEL;
  790. query->timeout = jiffies;
  791. list_move(&query->list, &ib_nl_request_list);
  792. found = 1;
  793. mod_delayed_work(ib_nl_wq, &ib_nl_timed_work, 1);
  794. break;
  795. }
  796. }
  797. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  798. return found;
  799. }
  800. static void send_handler(struct ib_mad_agent *agent,
  801. struct ib_mad_send_wc *mad_send_wc);
  802. static void ib_nl_process_good_resolve_rsp(struct ib_sa_query *query,
  803. const struct nlmsghdr *nlh)
  804. {
  805. struct sa_path_rec recs[RDMA_PRIMARY_PATH_MAX_REC_NUM];
  806. struct ib_sa_path_query *path_query;
  807. struct ib_path_rec_data *rec_data;
  808. struct ib_mad_send_wc mad_send_wc;
  809. const struct nlattr *head, *curr;
  810. struct ib_sa_mad *mad = NULL;
  811. int len, rem, status = -EIO;
  812. unsigned int num_prs = 0;
  813. u32 mask = 0;
  814. if (!query->callback)
  815. goto out;
  816. path_query = container_of(query, struct ib_sa_path_query, sa_query);
  817. mad = query->mad_buf->mad;
  818. head = (const struct nlattr *) nlmsg_data(nlh);
  819. len = nlmsg_len(nlh);
  820. switch (query->path_use) {
  821. case LS_RESOLVE_PATH_USE_UNIDIRECTIONAL:
  822. mask = IB_PATH_PRIMARY | IB_PATH_OUTBOUND;
  823. break;
  824. case LS_RESOLVE_PATH_USE_ALL:
  825. mask = IB_PATH_PRIMARY;
  826. break;
  827. case LS_RESOLVE_PATH_USE_GMP:
  828. default:
  829. mask = IB_PATH_PRIMARY | IB_PATH_GMP |
  830. IB_PATH_BIDIRECTIONAL;
  831. break;
  832. }
  833. nla_for_each_attr(curr, head, len, rem) {
  834. if (curr->nla_type != LS_NLA_TYPE_PATH_RECORD)
  835. continue;
  836. rec_data = nla_data(curr);
  837. if ((rec_data->flags & mask) != mask)
  838. continue;
  839. if ((query->flags & IB_SA_QUERY_OPA) ||
  840. path_query->conv_pr) {
  841. mad->mad_hdr.method |= IB_MGMT_METHOD_RESP;
  842. memcpy(mad->data, rec_data->path_rec,
  843. sizeof(rec_data->path_rec));
  844. query->callback(query, 0, mad);
  845. goto out;
  846. }
  847. status = 0;
  848. ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table),
  849. rec_data->path_rec, &recs[num_prs]);
  850. recs[num_prs].flags = rec_data->flags;
  851. recs[num_prs].rec_type = SA_PATH_REC_TYPE_IB;
  852. sa_path_set_dmac_zero(&recs[num_prs]);
  853. num_prs++;
  854. if (num_prs >= RDMA_PRIMARY_PATH_MAX_REC_NUM)
  855. break;
  856. }
  857. if (!status) {
  858. mad->mad_hdr.method |= IB_MGMT_METHOD_RESP;
  859. path_query->callback(status, recs, num_prs,
  860. path_query->context);
  861. } else
  862. query->callback(query, status, mad);
  863. out:
  864. mad_send_wc.send_buf = query->mad_buf;
  865. mad_send_wc.status = IB_WC_SUCCESS;
  866. send_handler(query->mad_buf->mad_agent, &mad_send_wc);
  867. }
  868. static void ib_nl_request_timeout(struct work_struct *work)
  869. {
  870. unsigned long flags;
  871. struct ib_sa_query *query;
  872. unsigned long delay;
  873. struct ib_mad_send_wc mad_send_wc;
  874. int ret;
  875. spin_lock_irqsave(&ib_nl_request_lock, flags);
  876. while (!list_empty(&ib_nl_request_list)) {
  877. query = list_entry(ib_nl_request_list.next,
  878. struct ib_sa_query, list);
  879. if (time_after(query->timeout, jiffies)) {
  880. delay = query->timeout - jiffies;
  881. if ((long)delay <= 0)
  882. delay = 1;
  883. queue_delayed_work(ib_nl_wq, &ib_nl_timed_work, delay);
  884. break;
  885. }
  886. list_del(&query->list);
  887. ib_sa_disable_local_svc(query);
  888. /* Hold the lock to protect against query cancellation */
  889. if (ib_sa_query_cancelled(query))
  890. ret = -1;
  891. else
  892. ret = ib_post_send_mad(query->mad_buf, NULL);
  893. if (ret) {
  894. mad_send_wc.send_buf = query->mad_buf;
  895. mad_send_wc.status = IB_WC_WR_FLUSH_ERR;
  896. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  897. send_handler(query->port->agent, &mad_send_wc);
  898. spin_lock_irqsave(&ib_nl_request_lock, flags);
  899. }
  900. }
  901. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  902. }
  903. int ib_nl_handle_set_timeout(struct sk_buff *skb,
  904. struct nlmsghdr *nlh,
  905. struct netlink_ext_ack *extack)
  906. {
  907. int timeout, delta, abs_delta;
  908. const struct nlattr *attr;
  909. unsigned long flags;
  910. struct ib_sa_query *query;
  911. long delay = 0;
  912. struct nlattr *tb[LS_NLA_TYPE_MAX];
  913. int ret;
  914. if (!(nlh->nlmsg_flags & NLM_F_REQUEST) ||
  915. !(NETLINK_CB(skb).sk))
  916. return -EPERM;
  917. ret = nla_parse_deprecated(tb, LS_NLA_TYPE_MAX - 1, nlmsg_data(nlh),
  918. nlmsg_len(nlh), ib_nl_policy, NULL);
  919. attr = (const struct nlattr *)tb[LS_NLA_TYPE_TIMEOUT];
  920. if (ret || !attr)
  921. goto settimeout_out;
  922. timeout = *(int *) nla_data(attr);
  923. if (timeout < IB_SA_LOCAL_SVC_TIMEOUT_MIN)
  924. timeout = IB_SA_LOCAL_SVC_TIMEOUT_MIN;
  925. if (timeout > IB_SA_LOCAL_SVC_TIMEOUT_MAX)
  926. timeout = IB_SA_LOCAL_SVC_TIMEOUT_MAX;
  927. spin_lock_irqsave(&ib_nl_request_lock, flags);
  928. delta = timeout - sa_local_svc_timeout_ms;
  929. if (delta < 0)
  930. abs_delta = -delta;
  931. else
  932. abs_delta = delta;
  933. if (delta != 0) {
  934. sa_local_svc_timeout_ms = timeout;
  935. list_for_each_entry(query, &ib_nl_request_list, list) {
  936. if (delta < 0 && abs_delta > query->timeout)
  937. query->timeout = 0;
  938. else
  939. query->timeout += delta;
  940. /* Get the new delay from the first entry */
  941. if (!delay) {
  942. delay = query->timeout - jiffies;
  943. if (delay <= 0)
  944. delay = 1;
  945. }
  946. }
  947. if (delay)
  948. mod_delayed_work(ib_nl_wq, &ib_nl_timed_work,
  949. (unsigned long)delay);
  950. }
  951. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  952. settimeout_out:
  953. return 0;
  954. }
  955. static inline int ib_nl_is_good_resolve_resp(const struct nlmsghdr *nlh)
  956. {
  957. struct nlattr *tb[LS_NLA_TYPE_MAX];
  958. int ret;
  959. if (nlh->nlmsg_flags & RDMA_NL_LS_F_ERR)
  960. return 0;
  961. ret = nla_parse_deprecated(tb, LS_NLA_TYPE_MAX - 1, nlmsg_data(nlh),
  962. nlmsg_len(nlh), ib_nl_policy, NULL);
  963. if (ret)
  964. return 0;
  965. return 1;
  966. }
  967. int ib_nl_handle_resolve_resp(struct sk_buff *skb,
  968. struct nlmsghdr *nlh,
  969. struct netlink_ext_ack *extack)
  970. {
  971. unsigned long flags;
  972. struct ib_sa_query *query = NULL, *iter;
  973. struct ib_mad_send_buf *send_buf;
  974. struct ib_mad_send_wc mad_send_wc;
  975. int ret;
  976. if ((nlh->nlmsg_flags & NLM_F_REQUEST) ||
  977. !(NETLINK_CB(skb).sk))
  978. return -EPERM;
  979. spin_lock_irqsave(&ib_nl_request_lock, flags);
  980. list_for_each_entry(iter, &ib_nl_request_list, list) {
  981. /*
  982. * If the query is cancelled, let the timeout routine
  983. * take care of it.
  984. */
  985. if (nlh->nlmsg_seq == iter->seq) {
  986. if (!ib_sa_query_cancelled(iter)) {
  987. list_del(&iter->list);
  988. query = iter;
  989. }
  990. break;
  991. }
  992. }
  993. if (!query) {
  994. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  995. goto resp_out;
  996. }
  997. send_buf = query->mad_buf;
  998. if (!ib_nl_is_good_resolve_resp(nlh)) {
  999. /* if the result is a failure, send out the packet via IB */
  1000. ib_sa_disable_local_svc(query);
  1001. ret = ib_post_send_mad(query->mad_buf, NULL);
  1002. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  1003. if (ret) {
  1004. mad_send_wc.send_buf = send_buf;
  1005. mad_send_wc.status = IB_WC_GENERAL_ERR;
  1006. send_handler(query->port->agent, &mad_send_wc);
  1007. }
  1008. } else {
  1009. spin_unlock_irqrestore(&ib_nl_request_lock, flags);
  1010. ib_nl_process_good_resolve_rsp(query, nlh);
  1011. }
  1012. resp_out:
  1013. return 0;
  1014. }
  1015. static void free_sm_ah(struct kref *kref)
  1016. {
  1017. struct ib_sa_sm_ah *sm_ah = container_of(kref, struct ib_sa_sm_ah, ref);
  1018. rdma_destroy_ah(sm_ah->ah, 0);
  1019. kfree(sm_ah);
  1020. }
  1021. void ib_sa_register_client(struct ib_sa_client *client)
  1022. {
  1023. atomic_set(&client->users, 1);
  1024. init_completion(&client->comp);
  1025. }
  1026. EXPORT_SYMBOL(ib_sa_register_client);
  1027. void ib_sa_unregister_client(struct ib_sa_client *client)
  1028. {
  1029. ib_sa_client_put(client);
  1030. wait_for_completion(&client->comp);
  1031. }
  1032. EXPORT_SYMBOL(ib_sa_unregister_client);
  1033. /**
  1034. * ib_sa_cancel_query - try to cancel an SA query
  1035. * @id:ID of query to cancel
  1036. * @query:query pointer to cancel
  1037. *
  1038. * Try to cancel an SA query. If the id and query don't match up or
  1039. * the query has already completed, nothing is done. Otherwise the
  1040. * query is canceled and will complete with a status of -EINTR.
  1041. */
  1042. void ib_sa_cancel_query(int id, struct ib_sa_query *query)
  1043. {
  1044. unsigned long flags;
  1045. struct ib_mad_send_buf *mad_buf;
  1046. xa_lock_irqsave(&queries, flags);
  1047. if (xa_load(&queries, id) != query) {
  1048. xa_unlock_irqrestore(&queries, flags);
  1049. return;
  1050. }
  1051. mad_buf = query->mad_buf;
  1052. xa_unlock_irqrestore(&queries, flags);
  1053. /*
  1054. * If the query is still on the netlink request list, schedule
  1055. * it to be cancelled by the timeout routine. Otherwise, it has been
  1056. * sent to the MAD layer and has to be cancelled from there.
  1057. */
  1058. if (!ib_nl_cancel_request(query))
  1059. ib_cancel_mad(mad_buf);
  1060. }
  1061. EXPORT_SYMBOL(ib_sa_cancel_query);
  1062. static u8 get_src_path_mask(struct ib_device *device, u32 port_num)
  1063. {
  1064. struct ib_sa_device *sa_dev;
  1065. struct ib_sa_port *port;
  1066. unsigned long flags;
  1067. u8 src_path_mask;
  1068. sa_dev = ib_get_client_data(device, &sa_client);
  1069. if (!sa_dev)
  1070. return 0x7f;
  1071. port = &sa_dev->port[port_num - sa_dev->start_port];
  1072. spin_lock_irqsave(&port->ah_lock, flags);
  1073. src_path_mask = port->sm_ah ? port->sm_ah->src_path_mask : 0x7f;
  1074. spin_unlock_irqrestore(&port->ah_lock, flags);
  1075. return src_path_mask;
  1076. }
  1077. static int init_ah_attr_grh_fields(struct ib_device *device, u32 port_num,
  1078. struct sa_path_rec *rec,
  1079. struct rdma_ah_attr *ah_attr,
  1080. const struct ib_gid_attr *gid_attr)
  1081. {
  1082. enum ib_gid_type type = sa_conv_pathrec_to_gid_type(rec);
  1083. if (!gid_attr) {
  1084. gid_attr = rdma_find_gid_by_port(device, &rec->sgid, type,
  1085. port_num, NULL);
  1086. if (IS_ERR(gid_attr))
  1087. return PTR_ERR(gid_attr);
  1088. } else
  1089. rdma_hold_gid_attr(gid_attr);
  1090. rdma_move_grh_sgid_attr(ah_attr, &rec->dgid,
  1091. be32_to_cpu(rec->flow_label),
  1092. rec->hop_limit, rec->traffic_class,
  1093. gid_attr);
  1094. return 0;
  1095. }
  1096. /**
  1097. * ib_init_ah_attr_from_path - Initialize address handle attributes based on
  1098. * an SA path record.
  1099. * @device: Device associated ah attributes initialization.
  1100. * @port_num: Port on the specified device.
  1101. * @rec: path record entry to use for ah attributes initialization.
  1102. * @ah_attr: address handle attributes to initialization from path record.
  1103. * @gid_attr: SGID attribute to consider during initialization.
  1104. *
  1105. * When ib_init_ah_attr_from_path() returns success,
  1106. * (a) for IB link layer it optionally contains a reference to SGID attribute
  1107. * when GRH is present for IB link layer.
  1108. * (b) for RoCE link layer it contains a reference to SGID attribute.
  1109. * User must invoke rdma_destroy_ah_attr() to release reference to SGID
  1110. * attributes which are initialized using ib_init_ah_attr_from_path().
  1111. */
  1112. int ib_init_ah_attr_from_path(struct ib_device *device, u32 port_num,
  1113. struct sa_path_rec *rec,
  1114. struct rdma_ah_attr *ah_attr,
  1115. const struct ib_gid_attr *gid_attr)
  1116. {
  1117. int ret = 0;
  1118. memset(ah_attr, 0, sizeof(*ah_attr));
  1119. ah_attr->type = rdma_ah_find_type(device, port_num);
  1120. rdma_ah_set_sl(ah_attr, rec->sl);
  1121. rdma_ah_set_port_num(ah_attr, port_num);
  1122. rdma_ah_set_static_rate(ah_attr, rec->rate);
  1123. if (sa_path_is_roce(rec)) {
  1124. ret = roce_resolve_route_from_path(rec, gid_attr);
  1125. if (ret)
  1126. return ret;
  1127. memcpy(ah_attr->roce.dmac, sa_path_get_dmac(rec), ETH_ALEN);
  1128. } else {
  1129. rdma_ah_set_dlid(ah_attr, be32_to_cpu(sa_path_get_dlid(rec)));
  1130. if (sa_path_is_opa(rec) &&
  1131. rdma_ah_get_dlid(ah_attr) == be16_to_cpu(IB_LID_PERMISSIVE))
  1132. rdma_ah_set_make_grd(ah_attr, true);
  1133. rdma_ah_set_path_bits(ah_attr,
  1134. be32_to_cpu(sa_path_get_slid(rec)) &
  1135. get_src_path_mask(device, port_num));
  1136. }
  1137. if (rec->hop_limit > 0 || sa_path_is_roce(rec))
  1138. ret = init_ah_attr_grh_fields(device, port_num,
  1139. rec, ah_attr, gid_attr);
  1140. return ret;
  1141. }
  1142. EXPORT_SYMBOL(ib_init_ah_attr_from_path);
  1143. static int alloc_mad(struct ib_sa_query *query, gfp_t gfp_mask)
  1144. {
  1145. struct rdma_ah_attr ah_attr;
  1146. unsigned long flags;
  1147. spin_lock_irqsave(&query->port->ah_lock, flags);
  1148. if (!query->port->sm_ah) {
  1149. spin_unlock_irqrestore(&query->port->ah_lock, flags);
  1150. return -EAGAIN;
  1151. }
  1152. kref_get(&query->port->sm_ah->ref);
  1153. query->sm_ah = query->port->sm_ah;
  1154. spin_unlock_irqrestore(&query->port->ah_lock, flags);
  1155. /*
  1156. * Always check if sm_ah has valid dlid assigned,
  1157. * before querying for class port info
  1158. */
  1159. if ((rdma_query_ah(query->sm_ah->ah, &ah_attr) < 0) ||
  1160. !rdma_is_valid_unicast_lid(&ah_attr)) {
  1161. kref_put(&query->sm_ah->ref, free_sm_ah);
  1162. return -EAGAIN;
  1163. }
  1164. query->mad_buf = ib_create_send_mad(query->port->agent, 1,
  1165. query->sm_ah->pkey_index,
  1166. 0, IB_MGMT_SA_HDR, IB_MGMT_SA_DATA,
  1167. gfp_mask,
  1168. ((query->flags & IB_SA_QUERY_OPA) ?
  1169. OPA_MGMT_BASE_VERSION :
  1170. IB_MGMT_BASE_VERSION));
  1171. if (IS_ERR(query->mad_buf)) {
  1172. kref_put(&query->sm_ah->ref, free_sm_ah);
  1173. return -ENOMEM;
  1174. }
  1175. query->mad_buf->ah = query->sm_ah->ah;
  1176. return 0;
  1177. }
  1178. static void free_mad(struct ib_sa_query *query)
  1179. {
  1180. ib_free_send_mad(query->mad_buf);
  1181. kref_put(&query->sm_ah->ref, free_sm_ah);
  1182. }
  1183. static void init_mad(struct ib_sa_query *query, struct ib_mad_agent *agent)
  1184. {
  1185. struct ib_sa_mad *mad = query->mad_buf->mad;
  1186. unsigned long flags;
  1187. memset(mad, 0, sizeof *mad);
  1188. if (query->flags & IB_SA_QUERY_OPA) {
  1189. mad->mad_hdr.base_version = OPA_MGMT_BASE_VERSION;
  1190. mad->mad_hdr.class_version = OPA_SA_CLASS_VERSION;
  1191. } else {
  1192. mad->mad_hdr.base_version = IB_MGMT_BASE_VERSION;
  1193. mad->mad_hdr.class_version = IB_SA_CLASS_VERSION;
  1194. }
  1195. mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
  1196. spin_lock_irqsave(&tid_lock, flags);
  1197. mad->mad_hdr.tid =
  1198. cpu_to_be64(((u64) agent->hi_tid) << 32 | tid++);
  1199. spin_unlock_irqrestore(&tid_lock, flags);
  1200. }
  1201. static int send_mad(struct ib_sa_query *query, unsigned long timeout_ms,
  1202. gfp_t gfp_mask)
  1203. {
  1204. unsigned long flags;
  1205. int ret, id;
  1206. const int nmbr_sa_query_retries = 10;
  1207. xa_lock_irqsave(&queries, flags);
  1208. ret = __xa_alloc(&queries, &id, query, xa_limit_32b, gfp_mask);
  1209. xa_unlock_irqrestore(&queries, flags);
  1210. if (ret < 0)
  1211. return ret;
  1212. query->mad_buf->timeout_ms = timeout_ms / nmbr_sa_query_retries;
  1213. query->mad_buf->retries = nmbr_sa_query_retries;
  1214. if (!query->mad_buf->timeout_ms) {
  1215. /* Special case, very small timeout_ms */
  1216. query->mad_buf->timeout_ms = 1;
  1217. query->mad_buf->retries = timeout_ms;
  1218. }
  1219. query->mad_buf->context[0] = query;
  1220. query->id = id;
  1221. if ((query->flags & IB_SA_ENABLE_LOCAL_SERVICE) &&
  1222. (!(query->flags & IB_SA_QUERY_OPA))) {
  1223. if (rdma_nl_chk_listeners(RDMA_NL_GROUP_LS)) {
  1224. if (!ib_nl_make_request(query, gfp_mask))
  1225. return id;
  1226. }
  1227. ib_sa_disable_local_svc(query);
  1228. }
  1229. ret = ib_post_send_mad(query->mad_buf, NULL);
  1230. if (ret) {
  1231. xa_lock_irqsave(&queries, flags);
  1232. __xa_erase(&queries, id);
  1233. xa_unlock_irqrestore(&queries, flags);
  1234. }
  1235. /*
  1236. * It's not safe to dereference query any more, because the
  1237. * send may already have completed and freed the query in
  1238. * another context.
  1239. */
  1240. return ret ? ret : id;
  1241. }
  1242. void ib_sa_unpack_path(void *attribute, struct sa_path_rec *rec)
  1243. {
  1244. ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table), attribute, rec);
  1245. }
  1246. EXPORT_SYMBOL(ib_sa_unpack_path);
  1247. void ib_sa_pack_path(struct sa_path_rec *rec, void *attribute)
  1248. {
  1249. ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, attribute);
  1250. }
  1251. EXPORT_SYMBOL(ib_sa_pack_path);
  1252. static bool ib_sa_opa_pathrecord_support(struct ib_sa_client *client,
  1253. struct ib_sa_device *sa_dev,
  1254. u32 port_num)
  1255. {
  1256. struct ib_sa_port *port;
  1257. unsigned long flags;
  1258. bool ret = false;
  1259. port = &sa_dev->port[port_num - sa_dev->start_port];
  1260. spin_lock_irqsave(&port->classport_lock, flags);
  1261. if (!port->classport_info.valid)
  1262. goto ret;
  1263. if (port->classport_info.data.type == RDMA_CLASS_PORT_INFO_OPA)
  1264. ret = opa_get_cpi_capmask2(&port->classport_info.data.opa) &
  1265. OPA_CLASS_PORT_INFO_PR_SUPPORT;
  1266. ret:
  1267. spin_unlock_irqrestore(&port->classport_lock, flags);
  1268. return ret;
  1269. }
  1270. enum opa_pr_supported {
  1271. PR_NOT_SUPPORTED,
  1272. PR_OPA_SUPPORTED,
  1273. PR_IB_SUPPORTED
  1274. };
  1275. /*
  1276. * opa_pr_query_possible - Check if current PR query can be an OPA query.
  1277. *
  1278. * Returns PR_NOT_SUPPORTED if a path record query is not
  1279. * possible, PR_OPA_SUPPORTED if an OPA path record query
  1280. * is possible and PR_IB_SUPPORTED if an IB path record
  1281. * query is possible.
  1282. */
  1283. static int opa_pr_query_possible(struct ib_sa_client *client,
  1284. struct ib_sa_device *sa_dev,
  1285. struct ib_device *device, u32 port_num)
  1286. {
  1287. struct ib_port_attr port_attr;
  1288. if (ib_query_port(device, port_num, &port_attr))
  1289. return PR_NOT_SUPPORTED;
  1290. if (ib_sa_opa_pathrecord_support(client, sa_dev, port_num))
  1291. return PR_OPA_SUPPORTED;
  1292. if (port_attr.lid >= be16_to_cpu(IB_MULTICAST_LID_BASE))
  1293. return PR_NOT_SUPPORTED;
  1294. else
  1295. return PR_IB_SUPPORTED;
  1296. }
  1297. static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
  1298. int status, struct ib_sa_mad *mad)
  1299. {
  1300. struct ib_sa_path_query *query =
  1301. container_of(sa_query, struct ib_sa_path_query, sa_query);
  1302. struct sa_path_rec rec = {};
  1303. if (!mad) {
  1304. query->callback(status, NULL, 0, query->context);
  1305. return;
  1306. }
  1307. if (sa_query->flags & IB_SA_QUERY_OPA) {
  1308. ib_unpack(opa_path_rec_table, ARRAY_SIZE(opa_path_rec_table),
  1309. mad->data, &rec);
  1310. rec.rec_type = SA_PATH_REC_TYPE_OPA;
  1311. query->callback(status, &rec, 1, query->context);
  1312. return;
  1313. }
  1314. ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table),
  1315. mad->data, &rec);
  1316. rec.rec_type = SA_PATH_REC_TYPE_IB;
  1317. sa_path_set_dmac_zero(&rec);
  1318. if (query->conv_pr) {
  1319. struct sa_path_rec opa;
  1320. memset(&opa, 0, sizeof(struct sa_path_rec));
  1321. sa_convert_path_ib_to_opa(&opa, &rec);
  1322. query->callback(status, &opa, 1, query->context);
  1323. } else {
  1324. query->callback(status, &rec, 1, query->context);
  1325. }
  1326. }
  1327. static void ib_sa_path_rec_release(struct ib_sa_query *sa_query)
  1328. {
  1329. struct ib_sa_path_query *query =
  1330. container_of(sa_query, struct ib_sa_path_query, sa_query);
  1331. kfree(query->conv_pr);
  1332. kfree(query);
  1333. }
  1334. /**
  1335. * ib_sa_path_rec_get - Start a Path get query
  1336. * @client:SA client
  1337. * @device:device to send query on
  1338. * @port_num: port number to send query on
  1339. * @rec:Path Record to send in query
  1340. * @comp_mask:component mask to send in query
  1341. * @timeout_ms:time to wait for response
  1342. * @gfp_mask:GFP mask to use for internal allocations
  1343. * @callback:function called when query completes, times out or is
  1344. * canceled
  1345. * @context:opaque user context passed to callback
  1346. * @sa_query:query context, used to cancel query
  1347. *
  1348. * Send a Path Record Get query to the SA to look up a path. The
  1349. * callback function will be called when the query completes (or
  1350. * fails); status is 0 for a successful response, -EINTR if the query
  1351. * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
  1352. * occurred sending the query. The resp parameter of the callback is
  1353. * only valid if status is 0.
  1354. *
  1355. * If the return value of ib_sa_path_rec_get() is negative, it is an
  1356. * error code. Otherwise it is a query ID that can be used to cancel
  1357. * the query.
  1358. */
  1359. int ib_sa_path_rec_get(struct ib_sa_client *client,
  1360. struct ib_device *device, u32 port_num,
  1361. struct sa_path_rec *rec,
  1362. ib_sa_comp_mask comp_mask,
  1363. unsigned long timeout_ms, gfp_t gfp_mask,
  1364. void (*callback)(int status,
  1365. struct sa_path_rec *resp,
  1366. unsigned int num_paths, void *context),
  1367. void *context,
  1368. struct ib_sa_query **sa_query)
  1369. {
  1370. struct ib_sa_path_query *query;
  1371. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1372. struct ib_sa_port *port;
  1373. struct ib_mad_agent *agent;
  1374. struct ib_sa_mad *mad;
  1375. enum opa_pr_supported status;
  1376. int ret;
  1377. if (!sa_dev)
  1378. return -ENODEV;
  1379. if ((rec->rec_type != SA_PATH_REC_TYPE_IB) &&
  1380. (rec->rec_type != SA_PATH_REC_TYPE_OPA))
  1381. return -EINVAL;
  1382. port = &sa_dev->port[port_num - sa_dev->start_port];
  1383. agent = port->agent;
  1384. query = kzalloc(sizeof(*query), gfp_mask);
  1385. if (!query)
  1386. return -ENOMEM;
  1387. query->sa_query.port = port;
  1388. if (rec->rec_type == SA_PATH_REC_TYPE_OPA) {
  1389. status = opa_pr_query_possible(client, sa_dev, device, port_num);
  1390. if (status == PR_NOT_SUPPORTED) {
  1391. ret = -EINVAL;
  1392. goto err1;
  1393. } else if (status == PR_OPA_SUPPORTED) {
  1394. query->sa_query.flags |= IB_SA_QUERY_OPA;
  1395. } else {
  1396. query->conv_pr =
  1397. kmalloc(sizeof(*query->conv_pr), gfp_mask);
  1398. if (!query->conv_pr) {
  1399. ret = -ENOMEM;
  1400. goto err1;
  1401. }
  1402. }
  1403. }
  1404. ret = alloc_mad(&query->sa_query, gfp_mask);
  1405. if (ret)
  1406. goto err2;
  1407. ib_sa_client_get(client);
  1408. query->sa_query.client = client;
  1409. query->callback = callback;
  1410. query->context = context;
  1411. mad = query->sa_query.mad_buf->mad;
  1412. init_mad(&query->sa_query, agent);
  1413. query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL;
  1414. query->sa_query.release = ib_sa_path_rec_release;
  1415. mad->mad_hdr.method = IB_MGMT_METHOD_GET;
  1416. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_PATH_REC);
  1417. mad->sa_hdr.comp_mask = comp_mask;
  1418. if (query->sa_query.flags & IB_SA_QUERY_OPA) {
  1419. ib_pack(opa_path_rec_table, ARRAY_SIZE(opa_path_rec_table),
  1420. rec, mad->data);
  1421. } else if (query->conv_pr) {
  1422. sa_convert_path_opa_to_ib(query->conv_pr, rec);
  1423. ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table),
  1424. query->conv_pr, mad->data);
  1425. } else {
  1426. ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table),
  1427. rec, mad->data);
  1428. }
  1429. *sa_query = &query->sa_query;
  1430. query->sa_query.flags |= IB_SA_ENABLE_LOCAL_SERVICE;
  1431. query->sa_query.mad_buf->context[1] = (query->conv_pr) ?
  1432. query->conv_pr : rec;
  1433. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1434. if (ret < 0)
  1435. goto err3;
  1436. return ret;
  1437. err3:
  1438. *sa_query = NULL;
  1439. ib_sa_client_put(query->sa_query.client);
  1440. free_mad(&query->sa_query);
  1441. err2:
  1442. kfree(query->conv_pr);
  1443. err1:
  1444. kfree(query);
  1445. return ret;
  1446. }
  1447. EXPORT_SYMBOL(ib_sa_path_rec_get);
  1448. static void ib_sa_mcmember_rec_callback(struct ib_sa_query *sa_query,
  1449. int status, struct ib_sa_mad *mad)
  1450. {
  1451. struct ib_sa_mcmember_query *query =
  1452. container_of(sa_query, struct ib_sa_mcmember_query, sa_query);
  1453. if (mad) {
  1454. struct ib_sa_mcmember_rec rec;
  1455. ib_unpack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
  1456. mad->data, &rec);
  1457. query->callback(status, &rec, query->context);
  1458. } else
  1459. query->callback(status, NULL, query->context);
  1460. }
  1461. static void ib_sa_mcmember_rec_release(struct ib_sa_query *sa_query)
  1462. {
  1463. kfree(container_of(sa_query, struct ib_sa_mcmember_query, sa_query));
  1464. }
  1465. int ib_sa_mcmember_rec_query(struct ib_sa_client *client,
  1466. struct ib_device *device, u32 port_num,
  1467. u8 method,
  1468. struct ib_sa_mcmember_rec *rec,
  1469. ib_sa_comp_mask comp_mask,
  1470. unsigned long timeout_ms, gfp_t gfp_mask,
  1471. void (*callback)(int status,
  1472. struct ib_sa_mcmember_rec *resp,
  1473. void *context),
  1474. void *context,
  1475. struct ib_sa_query **sa_query)
  1476. {
  1477. struct ib_sa_mcmember_query *query;
  1478. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1479. struct ib_sa_port *port;
  1480. struct ib_mad_agent *agent;
  1481. struct ib_sa_mad *mad;
  1482. int ret;
  1483. if (!sa_dev)
  1484. return -ENODEV;
  1485. port = &sa_dev->port[port_num - sa_dev->start_port];
  1486. agent = port->agent;
  1487. query = kzalloc(sizeof(*query), gfp_mask);
  1488. if (!query)
  1489. return -ENOMEM;
  1490. query->sa_query.port = port;
  1491. ret = alloc_mad(&query->sa_query, gfp_mask);
  1492. if (ret)
  1493. goto err1;
  1494. ib_sa_client_get(client);
  1495. query->sa_query.client = client;
  1496. query->callback = callback;
  1497. query->context = context;
  1498. mad = query->sa_query.mad_buf->mad;
  1499. init_mad(&query->sa_query, agent);
  1500. query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL;
  1501. query->sa_query.release = ib_sa_mcmember_rec_release;
  1502. mad->mad_hdr.method = method;
  1503. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
  1504. mad->sa_hdr.comp_mask = comp_mask;
  1505. ib_pack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
  1506. rec, mad->data);
  1507. *sa_query = &query->sa_query;
  1508. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1509. if (ret < 0)
  1510. goto err2;
  1511. return ret;
  1512. err2:
  1513. *sa_query = NULL;
  1514. ib_sa_client_put(query->sa_query.client);
  1515. free_mad(&query->sa_query);
  1516. err1:
  1517. kfree(query);
  1518. return ret;
  1519. }
  1520. /* Support GuidInfoRecord */
  1521. static void ib_sa_guidinfo_rec_callback(struct ib_sa_query *sa_query,
  1522. int status, struct ib_sa_mad *mad)
  1523. {
  1524. struct ib_sa_guidinfo_query *query =
  1525. container_of(sa_query, struct ib_sa_guidinfo_query, sa_query);
  1526. if (mad) {
  1527. struct ib_sa_guidinfo_rec rec;
  1528. ib_unpack(guidinfo_rec_table, ARRAY_SIZE(guidinfo_rec_table),
  1529. mad->data, &rec);
  1530. query->callback(status, &rec, query->context);
  1531. } else
  1532. query->callback(status, NULL, query->context);
  1533. }
  1534. static void ib_sa_guidinfo_rec_release(struct ib_sa_query *sa_query)
  1535. {
  1536. kfree(container_of(sa_query, struct ib_sa_guidinfo_query, sa_query));
  1537. }
  1538. int ib_sa_guid_info_rec_query(struct ib_sa_client *client,
  1539. struct ib_device *device, u32 port_num,
  1540. struct ib_sa_guidinfo_rec *rec,
  1541. ib_sa_comp_mask comp_mask, u8 method,
  1542. unsigned long timeout_ms, gfp_t gfp_mask,
  1543. void (*callback)(int status,
  1544. struct ib_sa_guidinfo_rec *resp,
  1545. void *context),
  1546. void *context,
  1547. struct ib_sa_query **sa_query)
  1548. {
  1549. struct ib_sa_guidinfo_query *query;
  1550. struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
  1551. struct ib_sa_port *port;
  1552. struct ib_mad_agent *agent;
  1553. struct ib_sa_mad *mad;
  1554. int ret;
  1555. if (!sa_dev)
  1556. return -ENODEV;
  1557. if (method != IB_MGMT_METHOD_GET &&
  1558. method != IB_MGMT_METHOD_SET &&
  1559. method != IB_SA_METHOD_DELETE) {
  1560. return -EINVAL;
  1561. }
  1562. port = &sa_dev->port[port_num - sa_dev->start_port];
  1563. agent = port->agent;
  1564. query = kzalloc(sizeof(*query), gfp_mask);
  1565. if (!query)
  1566. return -ENOMEM;
  1567. query->sa_query.port = port;
  1568. ret = alloc_mad(&query->sa_query, gfp_mask);
  1569. if (ret)
  1570. goto err1;
  1571. ib_sa_client_get(client);
  1572. query->sa_query.client = client;
  1573. query->callback = callback;
  1574. query->context = context;
  1575. mad = query->sa_query.mad_buf->mad;
  1576. init_mad(&query->sa_query, agent);
  1577. query->sa_query.callback = callback ? ib_sa_guidinfo_rec_callback : NULL;
  1578. query->sa_query.release = ib_sa_guidinfo_rec_release;
  1579. mad->mad_hdr.method = method;
  1580. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_GUID_INFO_REC);
  1581. mad->sa_hdr.comp_mask = comp_mask;
  1582. ib_pack(guidinfo_rec_table, ARRAY_SIZE(guidinfo_rec_table), rec,
  1583. mad->data);
  1584. *sa_query = &query->sa_query;
  1585. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1586. if (ret < 0)
  1587. goto err2;
  1588. return ret;
  1589. err2:
  1590. *sa_query = NULL;
  1591. ib_sa_client_put(query->sa_query.client);
  1592. free_mad(&query->sa_query);
  1593. err1:
  1594. kfree(query);
  1595. return ret;
  1596. }
  1597. EXPORT_SYMBOL(ib_sa_guid_info_rec_query);
  1598. struct ib_classport_info_context {
  1599. struct completion done;
  1600. struct ib_sa_query *sa_query;
  1601. };
  1602. static void ib_classportinfo_cb(void *context)
  1603. {
  1604. struct ib_classport_info_context *cb_ctx = context;
  1605. complete(&cb_ctx->done);
  1606. }
  1607. static void ib_sa_classport_info_rec_callback(struct ib_sa_query *sa_query,
  1608. int status, struct ib_sa_mad *mad)
  1609. {
  1610. unsigned long flags;
  1611. struct ib_sa_classport_info_query *query =
  1612. container_of(sa_query, struct ib_sa_classport_info_query, sa_query);
  1613. struct ib_sa_classport_cache *info = &sa_query->port->classport_info;
  1614. if (mad) {
  1615. if (sa_query->flags & IB_SA_QUERY_OPA) {
  1616. struct opa_class_port_info rec;
  1617. ib_unpack(opa_classport_info_rec_table,
  1618. ARRAY_SIZE(opa_classport_info_rec_table),
  1619. mad->data, &rec);
  1620. spin_lock_irqsave(&sa_query->port->classport_lock,
  1621. flags);
  1622. if (!status && !info->valid) {
  1623. memcpy(&info->data.opa, &rec,
  1624. sizeof(info->data.opa));
  1625. info->valid = true;
  1626. info->data.type = RDMA_CLASS_PORT_INFO_OPA;
  1627. }
  1628. spin_unlock_irqrestore(&sa_query->port->classport_lock,
  1629. flags);
  1630. } else {
  1631. struct ib_class_port_info rec;
  1632. ib_unpack(ib_classport_info_rec_table,
  1633. ARRAY_SIZE(ib_classport_info_rec_table),
  1634. mad->data, &rec);
  1635. spin_lock_irqsave(&sa_query->port->classport_lock,
  1636. flags);
  1637. if (!status && !info->valid) {
  1638. memcpy(&info->data.ib, &rec,
  1639. sizeof(info->data.ib));
  1640. info->valid = true;
  1641. info->data.type = RDMA_CLASS_PORT_INFO_IB;
  1642. }
  1643. spin_unlock_irqrestore(&sa_query->port->classport_lock,
  1644. flags);
  1645. }
  1646. }
  1647. query->callback(query->context);
  1648. }
  1649. static void ib_sa_classport_info_rec_release(struct ib_sa_query *sa_query)
  1650. {
  1651. kfree(container_of(sa_query, struct ib_sa_classport_info_query,
  1652. sa_query));
  1653. }
  1654. static int ib_sa_classport_info_rec_query(struct ib_sa_port *port,
  1655. unsigned long timeout_ms,
  1656. void (*callback)(void *context),
  1657. void *context,
  1658. struct ib_sa_query **sa_query)
  1659. {
  1660. struct ib_mad_agent *agent;
  1661. struct ib_sa_classport_info_query *query;
  1662. struct ib_sa_mad *mad;
  1663. gfp_t gfp_mask = GFP_KERNEL;
  1664. int ret;
  1665. agent = port->agent;
  1666. query = kzalloc(sizeof(*query), gfp_mask);
  1667. if (!query)
  1668. return -ENOMEM;
  1669. query->sa_query.port = port;
  1670. query->sa_query.flags |= rdma_cap_opa_ah(port->agent->device,
  1671. port->port_num) ?
  1672. IB_SA_QUERY_OPA : 0;
  1673. ret = alloc_mad(&query->sa_query, gfp_mask);
  1674. if (ret)
  1675. goto err_free;
  1676. query->callback = callback;
  1677. query->context = context;
  1678. mad = query->sa_query.mad_buf->mad;
  1679. init_mad(&query->sa_query, agent);
  1680. query->sa_query.callback = ib_sa_classport_info_rec_callback;
  1681. query->sa_query.release = ib_sa_classport_info_rec_release;
  1682. mad->mad_hdr.method = IB_MGMT_METHOD_GET;
  1683. mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_CLASS_PORTINFO);
  1684. mad->sa_hdr.comp_mask = 0;
  1685. *sa_query = &query->sa_query;
  1686. ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
  1687. if (ret < 0)
  1688. goto err_free_mad;
  1689. return ret;
  1690. err_free_mad:
  1691. *sa_query = NULL;
  1692. free_mad(&query->sa_query);
  1693. err_free:
  1694. kfree(query);
  1695. return ret;
  1696. }
  1697. static void update_ib_cpi(struct work_struct *work)
  1698. {
  1699. struct ib_sa_port *port =
  1700. container_of(work, struct ib_sa_port, ib_cpi_work.work);
  1701. struct ib_classport_info_context *cb_context;
  1702. unsigned long flags;
  1703. int ret;
  1704. /* If the classport info is valid, nothing
  1705. * to do here.
  1706. */
  1707. spin_lock_irqsave(&port->classport_lock, flags);
  1708. if (port->classport_info.valid) {
  1709. spin_unlock_irqrestore(&port->classport_lock, flags);
  1710. return;
  1711. }
  1712. spin_unlock_irqrestore(&port->classport_lock, flags);
  1713. cb_context = kmalloc(sizeof(*cb_context), GFP_KERNEL);
  1714. if (!cb_context)
  1715. goto err_nomem;
  1716. init_completion(&cb_context->done);
  1717. ret = ib_sa_classport_info_rec_query(port, 3000,
  1718. ib_classportinfo_cb, cb_context,
  1719. &cb_context->sa_query);
  1720. if (ret < 0)
  1721. goto free_cb_err;
  1722. wait_for_completion(&cb_context->done);
  1723. free_cb_err:
  1724. kfree(cb_context);
  1725. spin_lock_irqsave(&port->classport_lock, flags);
  1726. /* If the classport info is still not valid, the query should have
  1727. * failed for some reason. Retry issuing the query
  1728. */
  1729. if (!port->classport_info.valid) {
  1730. port->classport_info.retry_cnt++;
  1731. if (port->classport_info.retry_cnt <=
  1732. IB_SA_CPI_MAX_RETRY_CNT) {
  1733. unsigned long delay =
  1734. msecs_to_jiffies(IB_SA_CPI_RETRY_WAIT);
  1735. queue_delayed_work(ib_wq, &port->ib_cpi_work, delay);
  1736. }
  1737. }
  1738. spin_unlock_irqrestore(&port->classport_lock, flags);
  1739. err_nomem:
  1740. return;
  1741. }
  1742. static void send_handler(struct ib_mad_agent *agent,
  1743. struct ib_mad_send_wc *mad_send_wc)
  1744. {
  1745. struct ib_sa_query *query = mad_send_wc->send_buf->context[0];
  1746. unsigned long flags;
  1747. if (query->callback)
  1748. switch (mad_send_wc->status) {
  1749. case IB_WC_SUCCESS:
  1750. /* No callback -- already got recv */
  1751. break;
  1752. case IB_WC_RESP_TIMEOUT_ERR:
  1753. query->callback(query, -ETIMEDOUT, NULL);
  1754. break;
  1755. case IB_WC_WR_FLUSH_ERR:
  1756. query->callback(query, -EINTR, NULL);
  1757. break;
  1758. default:
  1759. query->callback(query, -EIO, NULL);
  1760. break;
  1761. }
  1762. xa_lock_irqsave(&queries, flags);
  1763. __xa_erase(&queries, query->id);
  1764. xa_unlock_irqrestore(&queries, flags);
  1765. free_mad(query);
  1766. if (query->client)
  1767. ib_sa_client_put(query->client);
  1768. query->release(query);
  1769. }
  1770. static void recv_handler(struct ib_mad_agent *mad_agent,
  1771. struct ib_mad_send_buf *send_buf,
  1772. struct ib_mad_recv_wc *mad_recv_wc)
  1773. {
  1774. struct ib_sa_query *query;
  1775. if (!send_buf)
  1776. return;
  1777. query = send_buf->context[0];
  1778. if (query->callback) {
  1779. if (mad_recv_wc->wc->status == IB_WC_SUCCESS)
  1780. query->callback(query,
  1781. mad_recv_wc->recv_buf.mad->mad_hdr.status ?
  1782. -EINVAL : 0,
  1783. (struct ib_sa_mad *) mad_recv_wc->recv_buf.mad);
  1784. else
  1785. query->callback(query, -EIO, NULL);
  1786. }
  1787. ib_free_recv_mad(mad_recv_wc);
  1788. }
  1789. static void update_sm_ah(struct work_struct *work)
  1790. {
  1791. struct ib_sa_port *port =
  1792. container_of(work, struct ib_sa_port, update_task);
  1793. struct ib_sa_sm_ah *new_ah;
  1794. struct ib_port_attr port_attr;
  1795. struct rdma_ah_attr ah_attr;
  1796. bool grh_required;
  1797. if (ib_query_port(port->agent->device, port->port_num, &port_attr)) {
  1798. pr_warn("Couldn't query port\n");
  1799. return;
  1800. }
  1801. new_ah = kmalloc(sizeof(*new_ah), GFP_KERNEL);
  1802. if (!new_ah)
  1803. return;
  1804. kref_init(&new_ah->ref);
  1805. new_ah->src_path_mask = (1 << port_attr.lmc) - 1;
  1806. new_ah->pkey_index = 0;
  1807. if (ib_find_pkey(port->agent->device, port->port_num,
  1808. IB_DEFAULT_PKEY_FULL, &new_ah->pkey_index))
  1809. pr_err("Couldn't find index for default PKey\n");
  1810. memset(&ah_attr, 0, sizeof(ah_attr));
  1811. ah_attr.type = rdma_ah_find_type(port->agent->device,
  1812. port->port_num);
  1813. rdma_ah_set_dlid(&ah_attr, port_attr.sm_lid);
  1814. rdma_ah_set_sl(&ah_attr, port_attr.sm_sl);
  1815. rdma_ah_set_port_num(&ah_attr, port->port_num);
  1816. grh_required = rdma_is_grh_required(port->agent->device,
  1817. port->port_num);
  1818. /*
  1819. * The OPA sm_lid of 0xFFFF needs special handling so that it can be
  1820. * differentiated from a permissive LID of 0xFFFF. We set the
  1821. * grh_required flag here so the SA can program the DGID in the
  1822. * address handle appropriately
  1823. */
  1824. if (ah_attr.type == RDMA_AH_ATTR_TYPE_OPA &&
  1825. (grh_required ||
  1826. port_attr.sm_lid == be16_to_cpu(IB_LID_PERMISSIVE)))
  1827. rdma_ah_set_make_grd(&ah_attr, true);
  1828. if (ah_attr.type == RDMA_AH_ATTR_TYPE_IB && grh_required) {
  1829. rdma_ah_set_ah_flags(&ah_attr, IB_AH_GRH);
  1830. rdma_ah_set_subnet_prefix(&ah_attr,
  1831. cpu_to_be64(port_attr.subnet_prefix));
  1832. rdma_ah_set_interface_id(&ah_attr,
  1833. cpu_to_be64(IB_SA_WELL_KNOWN_GUID));
  1834. }
  1835. new_ah->ah = rdma_create_ah(port->agent->qp->pd, &ah_attr,
  1836. RDMA_CREATE_AH_SLEEPABLE);
  1837. if (IS_ERR(new_ah->ah)) {
  1838. pr_warn("Couldn't create new SM AH\n");
  1839. kfree(new_ah);
  1840. return;
  1841. }
  1842. spin_lock_irq(&port->ah_lock);
  1843. if (port->sm_ah)
  1844. kref_put(&port->sm_ah->ref, free_sm_ah);
  1845. port->sm_ah = new_ah;
  1846. spin_unlock_irq(&port->ah_lock);
  1847. }
  1848. static void ib_sa_event(struct ib_event_handler *handler,
  1849. struct ib_event *event)
  1850. {
  1851. if (event->event == IB_EVENT_PORT_ERR ||
  1852. event->event == IB_EVENT_PORT_ACTIVE ||
  1853. event->event == IB_EVENT_LID_CHANGE ||
  1854. event->event == IB_EVENT_PKEY_CHANGE ||
  1855. event->event == IB_EVENT_SM_CHANGE ||
  1856. event->event == IB_EVENT_CLIENT_REREGISTER) {
  1857. unsigned long flags;
  1858. struct ib_sa_device *sa_dev =
  1859. container_of(handler, typeof(*sa_dev), event_handler);
  1860. u32 port_num = event->element.port_num - sa_dev->start_port;
  1861. struct ib_sa_port *port = &sa_dev->port[port_num];
  1862. if (!rdma_cap_ib_sa(handler->device, port->port_num))
  1863. return;
  1864. spin_lock_irqsave(&port->ah_lock, flags);
  1865. if (port->sm_ah)
  1866. kref_put(&port->sm_ah->ref, free_sm_ah);
  1867. port->sm_ah = NULL;
  1868. spin_unlock_irqrestore(&port->ah_lock, flags);
  1869. if (event->event == IB_EVENT_SM_CHANGE ||
  1870. event->event == IB_EVENT_CLIENT_REREGISTER ||
  1871. event->event == IB_EVENT_LID_CHANGE ||
  1872. event->event == IB_EVENT_PORT_ACTIVE) {
  1873. unsigned long delay =
  1874. msecs_to_jiffies(IB_SA_CPI_RETRY_WAIT);
  1875. spin_lock_irqsave(&port->classport_lock, flags);
  1876. port->classport_info.valid = false;
  1877. port->classport_info.retry_cnt = 0;
  1878. spin_unlock_irqrestore(&port->classport_lock, flags);
  1879. queue_delayed_work(ib_wq,
  1880. &port->ib_cpi_work, delay);
  1881. }
  1882. queue_work(ib_wq, &sa_dev->port[port_num].update_task);
  1883. }
  1884. }
  1885. static int ib_sa_add_one(struct ib_device *device)
  1886. {
  1887. struct ib_sa_device *sa_dev;
  1888. int s, e, i;
  1889. int count = 0;
  1890. int ret;
  1891. s = rdma_start_port(device);
  1892. e = rdma_end_port(device);
  1893. sa_dev = kzalloc(struct_size(sa_dev, port,
  1894. size_add(size_sub(e, s), 1)),
  1895. GFP_KERNEL);
  1896. if (!sa_dev)
  1897. return -ENOMEM;
  1898. sa_dev->start_port = s;
  1899. sa_dev->end_port = e;
  1900. for (i = 0; i <= e - s; ++i) {
  1901. spin_lock_init(&sa_dev->port[i].ah_lock);
  1902. if (!rdma_cap_ib_sa(device, i + 1))
  1903. continue;
  1904. sa_dev->port[i].sm_ah = NULL;
  1905. sa_dev->port[i].port_num = i + s;
  1906. spin_lock_init(&sa_dev->port[i].classport_lock);
  1907. sa_dev->port[i].classport_info.valid = false;
  1908. sa_dev->port[i].agent =
  1909. ib_register_mad_agent(device, i + s, IB_QPT_GSI,
  1910. NULL, 0, send_handler,
  1911. recv_handler, sa_dev, 0);
  1912. if (IS_ERR(sa_dev->port[i].agent)) {
  1913. ret = PTR_ERR(sa_dev->port[i].agent);
  1914. goto err;
  1915. }
  1916. INIT_WORK(&sa_dev->port[i].update_task, update_sm_ah);
  1917. INIT_DELAYED_WORK(&sa_dev->port[i].ib_cpi_work,
  1918. update_ib_cpi);
  1919. count++;
  1920. }
  1921. if (!count) {
  1922. ret = -EOPNOTSUPP;
  1923. goto free;
  1924. }
  1925. ib_set_client_data(device, &sa_client, sa_dev);
  1926. /*
  1927. * We register our event handler after everything is set up,
  1928. * and then update our cached info after the event handler is
  1929. * registered to avoid any problems if a port changes state
  1930. * during our initialization.
  1931. */
  1932. INIT_IB_EVENT_HANDLER(&sa_dev->event_handler, device, ib_sa_event);
  1933. ib_register_event_handler(&sa_dev->event_handler);
  1934. for (i = 0; i <= e - s; ++i) {
  1935. if (rdma_cap_ib_sa(device, i + 1))
  1936. update_sm_ah(&sa_dev->port[i].update_task);
  1937. }
  1938. return 0;
  1939. err:
  1940. while (--i >= 0) {
  1941. if (rdma_cap_ib_sa(device, i + 1))
  1942. ib_unregister_mad_agent(sa_dev->port[i].agent);
  1943. }
  1944. free:
  1945. kfree(sa_dev);
  1946. return ret;
  1947. }
  1948. static void ib_sa_remove_one(struct ib_device *device, void *client_data)
  1949. {
  1950. struct ib_sa_device *sa_dev = client_data;
  1951. int i;
  1952. ib_unregister_event_handler(&sa_dev->event_handler);
  1953. flush_workqueue(ib_wq);
  1954. for (i = 0; i <= sa_dev->end_port - sa_dev->start_port; ++i) {
  1955. if (rdma_cap_ib_sa(device, i + 1)) {
  1956. cancel_delayed_work_sync(&sa_dev->port[i].ib_cpi_work);
  1957. ib_unregister_mad_agent(sa_dev->port[i].agent);
  1958. if (sa_dev->port[i].sm_ah)
  1959. kref_put(&sa_dev->port[i].sm_ah->ref, free_sm_ah);
  1960. }
  1961. }
  1962. kfree(sa_dev);
  1963. }
  1964. int ib_sa_init(void)
  1965. {
  1966. int ret;
  1967. get_random_bytes(&tid, sizeof tid);
  1968. atomic_set(&ib_nl_sa_request_seq, 0);
  1969. ret = ib_register_client(&sa_client);
  1970. if (ret) {
  1971. pr_err("Couldn't register ib_sa client\n");
  1972. goto err1;
  1973. }
  1974. ret = mcast_init();
  1975. if (ret) {
  1976. pr_err("Couldn't initialize multicast handling\n");
  1977. goto err2;
  1978. }
  1979. ib_nl_wq = alloc_ordered_workqueue("ib_nl_sa_wq", WQ_MEM_RECLAIM);
  1980. if (!ib_nl_wq) {
  1981. ret = -ENOMEM;
  1982. goto err3;
  1983. }
  1984. INIT_DELAYED_WORK(&ib_nl_timed_work, ib_nl_request_timeout);
  1985. return 0;
  1986. err3:
  1987. mcast_cleanup();
  1988. err2:
  1989. ib_unregister_client(&sa_client);
  1990. err1:
  1991. return ret;
  1992. }
  1993. void ib_sa_cleanup(void)
  1994. {
  1995. cancel_delayed_work(&ib_nl_timed_work);
  1996. destroy_workqueue(ib_nl_wq);
  1997. mcast_cleanup();
  1998. ib_unregister_client(&sa_client);
  1999. WARN_ON(!xa_empty(&queries));
  2000. }