smc_pnet.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Shared Memory Communications over RDMA (SMC-R) and RoCE
  4. *
  5. * Generic netlink support functions to configure an SMC-R PNET table
  6. *
  7. * Copyright IBM Corp. 2016
  8. *
  9. * Author(s): Thomas Richter <[email protected]>
  10. */
  11. #include <linux/module.h>
  12. #include <linux/list.h>
  13. #include <linux/ctype.h>
  14. #include <linux/mutex.h>
  15. #include <net/netlink.h>
  16. #include <net/genetlink.h>
  17. #include <uapi/linux/if.h>
  18. #include <uapi/linux/smc.h>
  19. #include <rdma/ib_verbs.h>
  20. #include <net/netns/generic.h>
  21. #include "smc_netns.h"
  22. #include "smc_pnet.h"
  23. #include "smc_ib.h"
  24. #include "smc_ism.h"
  25. #include "smc_core.h"
  26. static struct net_device *__pnet_find_base_ndev(struct net_device *ndev);
  27. static struct net_device *pnet_find_base_ndev(struct net_device *ndev);
  28. static const struct nla_policy smc_pnet_policy[SMC_PNETID_MAX + 1] = {
  29. [SMC_PNETID_NAME] = {
  30. .type = NLA_NUL_STRING,
  31. .len = SMC_MAX_PNETID_LEN
  32. },
  33. [SMC_PNETID_ETHNAME] = {
  34. .type = NLA_NUL_STRING,
  35. .len = IFNAMSIZ - 1
  36. },
  37. [SMC_PNETID_IBNAME] = {
  38. .type = NLA_NUL_STRING,
  39. .len = IB_DEVICE_NAME_MAX - 1
  40. },
  41. [SMC_PNETID_IBPORT] = { .type = NLA_U8 }
  42. };
  43. static struct genl_family smc_pnet_nl_family;
  44. enum smc_pnet_nametype {
  45. SMC_PNET_ETH = 1,
  46. SMC_PNET_IB = 2,
  47. };
  48. /* pnet entry stored in pnet table */
  49. struct smc_pnetentry {
  50. struct list_head list;
  51. char pnet_name[SMC_MAX_PNETID_LEN + 1];
  52. enum smc_pnet_nametype type;
  53. union {
  54. struct {
  55. char eth_name[IFNAMSIZ + 1];
  56. struct net_device *ndev;
  57. netdevice_tracker dev_tracker;
  58. };
  59. struct {
  60. char ib_name[IB_DEVICE_NAME_MAX + 1];
  61. u8 ib_port;
  62. };
  63. };
  64. };
  65. /* Check if the pnetid is set */
  66. bool smc_pnet_is_pnetid_set(u8 *pnetid)
  67. {
  68. if (pnetid[0] == 0 || pnetid[0] == _S)
  69. return false;
  70. return true;
  71. }
  72. /* Check if two given pnetids match */
  73. static bool smc_pnet_match(u8 *pnetid1, u8 *pnetid2)
  74. {
  75. int i;
  76. for (i = 0; i < SMC_MAX_PNETID_LEN; i++) {
  77. if ((pnetid1[i] == 0 || pnetid1[i] == _S) &&
  78. (pnetid2[i] == 0 || pnetid2[i] == _S))
  79. break;
  80. if (pnetid1[i] != pnetid2[i])
  81. return false;
  82. }
  83. return true;
  84. }
  85. /* Remove a pnetid from the pnet table.
  86. */
  87. static int smc_pnet_remove_by_pnetid(struct net *net, char *pnet_name)
  88. {
  89. struct smc_pnetentry *pnetelem, *tmp_pe;
  90. struct smc_pnettable *pnettable;
  91. struct smc_ib_device *ibdev;
  92. struct smcd_dev *smcd_dev;
  93. struct smc_net *sn;
  94. int rc = -ENOENT;
  95. int ibport;
  96. /* get pnettable for namespace */
  97. sn = net_generic(net, smc_net_id);
  98. pnettable = &sn->pnettable;
  99. /* remove table entry */
  100. mutex_lock(&pnettable->lock);
  101. list_for_each_entry_safe(pnetelem, tmp_pe, &pnettable->pnetlist,
  102. list) {
  103. if (!pnet_name ||
  104. smc_pnet_match(pnetelem->pnet_name, pnet_name)) {
  105. list_del(&pnetelem->list);
  106. if (pnetelem->type == SMC_PNET_ETH && pnetelem->ndev) {
  107. netdev_put(pnetelem->ndev,
  108. &pnetelem->dev_tracker);
  109. pr_warn_ratelimited("smc: net device %s "
  110. "erased user defined "
  111. "pnetid %.16s\n",
  112. pnetelem->eth_name,
  113. pnetelem->pnet_name);
  114. }
  115. kfree(pnetelem);
  116. rc = 0;
  117. }
  118. }
  119. mutex_unlock(&pnettable->lock);
  120. /* if this is not the initial namespace, stop here */
  121. if (net != &init_net)
  122. return rc;
  123. /* remove ib devices */
  124. mutex_lock(&smc_ib_devices.mutex);
  125. list_for_each_entry(ibdev, &smc_ib_devices.list, list) {
  126. for (ibport = 0; ibport < SMC_MAX_PORTS; ibport++) {
  127. if (ibdev->pnetid_by_user[ibport] &&
  128. (!pnet_name ||
  129. smc_pnet_match(pnet_name,
  130. ibdev->pnetid[ibport]))) {
  131. pr_warn_ratelimited("smc: ib device %s ibport "
  132. "%d erased user defined "
  133. "pnetid %.16s\n",
  134. ibdev->ibdev->name,
  135. ibport + 1,
  136. ibdev->pnetid[ibport]);
  137. memset(ibdev->pnetid[ibport], 0,
  138. SMC_MAX_PNETID_LEN);
  139. ibdev->pnetid_by_user[ibport] = false;
  140. rc = 0;
  141. }
  142. }
  143. }
  144. mutex_unlock(&smc_ib_devices.mutex);
  145. /* remove smcd devices */
  146. mutex_lock(&smcd_dev_list.mutex);
  147. list_for_each_entry(smcd_dev, &smcd_dev_list.list, list) {
  148. if (smcd_dev->pnetid_by_user &&
  149. (!pnet_name ||
  150. smc_pnet_match(pnet_name, smcd_dev->pnetid))) {
  151. pr_warn_ratelimited("smc: smcd device %s "
  152. "erased user defined pnetid "
  153. "%.16s\n", dev_name(&smcd_dev->dev),
  154. smcd_dev->pnetid);
  155. memset(smcd_dev->pnetid, 0, SMC_MAX_PNETID_LEN);
  156. smcd_dev->pnetid_by_user = false;
  157. rc = 0;
  158. }
  159. }
  160. mutex_unlock(&smcd_dev_list.mutex);
  161. return rc;
  162. }
  163. /* Add the reference to a given network device to the pnet table.
  164. */
  165. static int smc_pnet_add_by_ndev(struct net_device *ndev)
  166. {
  167. struct smc_pnetentry *pnetelem, *tmp_pe;
  168. struct smc_pnettable *pnettable;
  169. struct net *net = dev_net(ndev);
  170. struct smc_net *sn;
  171. int rc = -ENOENT;
  172. /* get pnettable for namespace */
  173. sn = net_generic(net, smc_net_id);
  174. pnettable = &sn->pnettable;
  175. mutex_lock(&pnettable->lock);
  176. list_for_each_entry_safe(pnetelem, tmp_pe, &pnettable->pnetlist, list) {
  177. if (pnetelem->type == SMC_PNET_ETH && !pnetelem->ndev &&
  178. !strncmp(pnetelem->eth_name, ndev->name, IFNAMSIZ)) {
  179. netdev_hold(ndev, &pnetelem->dev_tracker, GFP_ATOMIC);
  180. pnetelem->ndev = ndev;
  181. rc = 0;
  182. pr_warn_ratelimited("smc: adding net device %s with "
  183. "user defined pnetid %.16s\n",
  184. pnetelem->eth_name,
  185. pnetelem->pnet_name);
  186. break;
  187. }
  188. }
  189. mutex_unlock(&pnettable->lock);
  190. return rc;
  191. }
  192. /* Remove the reference to a given network device from the pnet table.
  193. */
  194. static int smc_pnet_remove_by_ndev(struct net_device *ndev)
  195. {
  196. struct smc_pnetentry *pnetelem, *tmp_pe;
  197. struct smc_pnettable *pnettable;
  198. struct net *net = dev_net(ndev);
  199. struct smc_net *sn;
  200. int rc = -ENOENT;
  201. /* get pnettable for namespace */
  202. sn = net_generic(net, smc_net_id);
  203. pnettable = &sn->pnettable;
  204. mutex_lock(&pnettable->lock);
  205. list_for_each_entry_safe(pnetelem, tmp_pe, &pnettable->pnetlist, list) {
  206. if (pnetelem->type == SMC_PNET_ETH && pnetelem->ndev == ndev) {
  207. netdev_put(pnetelem->ndev, &pnetelem->dev_tracker);
  208. pnetelem->ndev = NULL;
  209. rc = 0;
  210. pr_warn_ratelimited("smc: removing net device %s with "
  211. "user defined pnetid %.16s\n",
  212. pnetelem->eth_name,
  213. pnetelem->pnet_name);
  214. break;
  215. }
  216. }
  217. mutex_unlock(&pnettable->lock);
  218. return rc;
  219. }
  220. /* Apply pnetid to ib device when no pnetid is set.
  221. */
  222. static bool smc_pnet_apply_ib(struct smc_ib_device *ib_dev, u8 ib_port,
  223. char *pnet_name)
  224. {
  225. bool applied = false;
  226. mutex_lock(&smc_ib_devices.mutex);
  227. if (!smc_pnet_is_pnetid_set(ib_dev->pnetid[ib_port - 1])) {
  228. memcpy(ib_dev->pnetid[ib_port - 1], pnet_name,
  229. SMC_MAX_PNETID_LEN);
  230. ib_dev->pnetid_by_user[ib_port - 1] = true;
  231. applied = true;
  232. }
  233. mutex_unlock(&smc_ib_devices.mutex);
  234. return applied;
  235. }
  236. /* Apply pnetid to smcd device when no pnetid is set.
  237. */
  238. static bool smc_pnet_apply_smcd(struct smcd_dev *smcd_dev, char *pnet_name)
  239. {
  240. bool applied = false;
  241. mutex_lock(&smcd_dev_list.mutex);
  242. if (!smc_pnet_is_pnetid_set(smcd_dev->pnetid)) {
  243. memcpy(smcd_dev->pnetid, pnet_name, SMC_MAX_PNETID_LEN);
  244. smcd_dev->pnetid_by_user = true;
  245. applied = true;
  246. }
  247. mutex_unlock(&smcd_dev_list.mutex);
  248. return applied;
  249. }
  250. /* The limit for pnetid is 16 characters.
  251. * Valid characters should be (single-byte character set) a-z, A-Z, 0-9.
  252. * Lower case letters are converted to upper case.
  253. * Interior blanks should not be used.
  254. */
  255. static bool smc_pnetid_valid(const char *pnet_name, char *pnetid)
  256. {
  257. char *bf = skip_spaces(pnet_name);
  258. size_t len = strlen(bf);
  259. char *end = bf + len;
  260. if (!len)
  261. return false;
  262. while (--end >= bf && isspace(*end))
  263. ;
  264. if (end - bf >= SMC_MAX_PNETID_LEN)
  265. return false;
  266. while (bf <= end) {
  267. if (!isalnum(*bf))
  268. return false;
  269. *pnetid++ = islower(*bf) ? toupper(*bf) : *bf;
  270. bf++;
  271. }
  272. *pnetid = '\0';
  273. return true;
  274. }
  275. /* Find an infiniband device by a given name. The device might not exist. */
  276. static struct smc_ib_device *smc_pnet_find_ib(char *ib_name)
  277. {
  278. struct smc_ib_device *ibdev;
  279. mutex_lock(&smc_ib_devices.mutex);
  280. list_for_each_entry(ibdev, &smc_ib_devices.list, list) {
  281. if (!strncmp(ibdev->ibdev->name, ib_name,
  282. sizeof(ibdev->ibdev->name)) ||
  283. (ibdev->ibdev->dev.parent &&
  284. !strncmp(dev_name(ibdev->ibdev->dev.parent), ib_name,
  285. IB_DEVICE_NAME_MAX - 1))) {
  286. goto out;
  287. }
  288. }
  289. ibdev = NULL;
  290. out:
  291. mutex_unlock(&smc_ib_devices.mutex);
  292. return ibdev;
  293. }
  294. /* Find an smcd device by a given name. The device might not exist. */
  295. static struct smcd_dev *smc_pnet_find_smcd(char *smcd_name)
  296. {
  297. struct smcd_dev *smcd_dev;
  298. mutex_lock(&smcd_dev_list.mutex);
  299. list_for_each_entry(smcd_dev, &smcd_dev_list.list, list) {
  300. if (!strncmp(dev_name(&smcd_dev->dev), smcd_name,
  301. IB_DEVICE_NAME_MAX - 1))
  302. goto out;
  303. }
  304. smcd_dev = NULL;
  305. out:
  306. mutex_unlock(&smcd_dev_list.mutex);
  307. return smcd_dev;
  308. }
  309. static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net,
  310. char *eth_name, char *pnet_name)
  311. {
  312. struct smc_pnetentry *tmp_pe, *new_pe;
  313. struct net_device *ndev, *base_ndev;
  314. u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
  315. bool new_netdev;
  316. int rc;
  317. /* check if (base) netdev already has a pnetid. If there is one, we do
  318. * not want to add a pnet table entry
  319. */
  320. rc = -EEXIST;
  321. ndev = dev_get_by_name(net, eth_name); /* dev_hold() */
  322. if (ndev) {
  323. base_ndev = pnet_find_base_ndev(ndev);
  324. if (!smc_pnetid_by_dev_port(base_ndev->dev.parent,
  325. base_ndev->dev_port, ndev_pnetid))
  326. goto out_put;
  327. }
  328. /* add a new netdev entry to the pnet table if there isn't one */
  329. rc = -ENOMEM;
  330. new_pe = kzalloc(sizeof(*new_pe), GFP_KERNEL);
  331. if (!new_pe)
  332. goto out_put;
  333. new_pe->type = SMC_PNET_ETH;
  334. memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
  335. strncpy(new_pe->eth_name, eth_name, IFNAMSIZ);
  336. rc = -EEXIST;
  337. new_netdev = true;
  338. mutex_lock(&pnettable->lock);
  339. list_for_each_entry(tmp_pe, &pnettable->pnetlist, list) {
  340. if (tmp_pe->type == SMC_PNET_ETH &&
  341. !strncmp(tmp_pe->eth_name, eth_name, IFNAMSIZ)) {
  342. new_netdev = false;
  343. break;
  344. }
  345. }
  346. if (new_netdev) {
  347. if (ndev) {
  348. new_pe->ndev = ndev;
  349. netdev_tracker_alloc(ndev, &new_pe->dev_tracker,
  350. GFP_ATOMIC);
  351. }
  352. list_add_tail(&new_pe->list, &pnettable->pnetlist);
  353. mutex_unlock(&pnettable->lock);
  354. } else {
  355. mutex_unlock(&pnettable->lock);
  356. kfree(new_pe);
  357. goto out_put;
  358. }
  359. if (ndev)
  360. pr_warn_ratelimited("smc: net device %s "
  361. "applied user defined pnetid %.16s\n",
  362. new_pe->eth_name, new_pe->pnet_name);
  363. return 0;
  364. out_put:
  365. dev_put(ndev);
  366. return rc;
  367. }
  368. static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
  369. u8 ib_port, char *pnet_name)
  370. {
  371. struct smc_pnetentry *tmp_pe, *new_pe;
  372. struct smc_ib_device *ib_dev;
  373. bool smcddev_applied = true;
  374. bool ibdev_applied = true;
  375. struct smcd_dev *smcd_dev;
  376. bool new_ibdev;
  377. /* try to apply the pnetid to active devices */
  378. ib_dev = smc_pnet_find_ib(ib_name);
  379. if (ib_dev) {
  380. ibdev_applied = smc_pnet_apply_ib(ib_dev, ib_port, pnet_name);
  381. if (ibdev_applied)
  382. pr_warn_ratelimited("smc: ib device %s ibport %d "
  383. "applied user defined pnetid "
  384. "%.16s\n", ib_dev->ibdev->name,
  385. ib_port,
  386. ib_dev->pnetid[ib_port - 1]);
  387. }
  388. smcd_dev = smc_pnet_find_smcd(ib_name);
  389. if (smcd_dev) {
  390. smcddev_applied = smc_pnet_apply_smcd(smcd_dev, pnet_name);
  391. if (smcddev_applied)
  392. pr_warn_ratelimited("smc: smcd device %s "
  393. "applied user defined pnetid "
  394. "%.16s\n", dev_name(&smcd_dev->dev),
  395. smcd_dev->pnetid);
  396. }
  397. /* Apply fails when a device has a hardware-defined pnetid set, do not
  398. * add a pnet table entry in that case.
  399. */
  400. if (!ibdev_applied || !smcddev_applied)
  401. return -EEXIST;
  402. /* add a new ib entry to the pnet table if there isn't one */
  403. new_pe = kzalloc(sizeof(*new_pe), GFP_KERNEL);
  404. if (!new_pe)
  405. return -ENOMEM;
  406. new_pe->type = SMC_PNET_IB;
  407. memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
  408. strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
  409. new_pe->ib_port = ib_port;
  410. new_ibdev = true;
  411. mutex_lock(&pnettable->lock);
  412. list_for_each_entry(tmp_pe, &pnettable->pnetlist, list) {
  413. if (tmp_pe->type == SMC_PNET_IB &&
  414. !strncmp(tmp_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX)) {
  415. new_ibdev = false;
  416. break;
  417. }
  418. }
  419. if (new_ibdev) {
  420. list_add_tail(&new_pe->list, &pnettable->pnetlist);
  421. mutex_unlock(&pnettable->lock);
  422. } else {
  423. mutex_unlock(&pnettable->lock);
  424. kfree(new_pe);
  425. }
  426. return (new_ibdev) ? 0 : -EEXIST;
  427. }
  428. /* Append a pnetid to the end of the pnet table if not already on this list.
  429. */
  430. static int smc_pnet_enter(struct net *net, struct nlattr *tb[])
  431. {
  432. char pnet_name[SMC_MAX_PNETID_LEN + 1];
  433. struct smc_pnettable *pnettable;
  434. bool new_netdev = false;
  435. bool new_ibdev = false;
  436. struct smc_net *sn;
  437. u8 ibport = 1;
  438. char *string;
  439. int rc;
  440. /* get pnettable for namespace */
  441. sn = net_generic(net, smc_net_id);
  442. pnettable = &sn->pnettable;
  443. rc = -EINVAL;
  444. if (!tb[SMC_PNETID_NAME])
  445. goto error;
  446. string = (char *)nla_data(tb[SMC_PNETID_NAME]);
  447. if (!smc_pnetid_valid(string, pnet_name))
  448. goto error;
  449. if (tb[SMC_PNETID_ETHNAME]) {
  450. string = (char *)nla_data(tb[SMC_PNETID_ETHNAME]);
  451. rc = smc_pnet_add_eth(pnettable, net, string, pnet_name);
  452. if (!rc)
  453. new_netdev = true;
  454. else if (rc != -EEXIST)
  455. goto error;
  456. }
  457. /* if this is not the initial namespace, stop here */
  458. if (net != &init_net)
  459. return new_netdev ? 0 : -EEXIST;
  460. rc = -EINVAL;
  461. if (tb[SMC_PNETID_IBNAME]) {
  462. string = (char *)nla_data(tb[SMC_PNETID_IBNAME]);
  463. string = strim(string);
  464. if (tb[SMC_PNETID_IBPORT]) {
  465. ibport = nla_get_u8(tb[SMC_PNETID_IBPORT]);
  466. if (ibport < 1 || ibport > SMC_MAX_PORTS)
  467. goto error;
  468. }
  469. rc = smc_pnet_add_ib(pnettable, string, ibport, pnet_name);
  470. if (!rc)
  471. new_ibdev = true;
  472. else if (rc != -EEXIST)
  473. goto error;
  474. }
  475. return (new_netdev || new_ibdev) ? 0 : -EEXIST;
  476. error:
  477. return rc;
  478. }
  479. /* Convert an smc_pnetentry to a netlink attribute sequence */
  480. static int smc_pnet_set_nla(struct sk_buff *msg,
  481. struct smc_pnetentry *pnetelem)
  482. {
  483. if (nla_put_string(msg, SMC_PNETID_NAME, pnetelem->pnet_name))
  484. return -1;
  485. if (pnetelem->type == SMC_PNET_ETH) {
  486. if (nla_put_string(msg, SMC_PNETID_ETHNAME,
  487. pnetelem->eth_name))
  488. return -1;
  489. } else {
  490. if (nla_put_string(msg, SMC_PNETID_ETHNAME, "n/a"))
  491. return -1;
  492. }
  493. if (pnetelem->type == SMC_PNET_IB) {
  494. if (nla_put_string(msg, SMC_PNETID_IBNAME, pnetelem->ib_name) ||
  495. nla_put_u8(msg, SMC_PNETID_IBPORT, pnetelem->ib_port))
  496. return -1;
  497. } else {
  498. if (nla_put_string(msg, SMC_PNETID_IBNAME, "n/a") ||
  499. nla_put_u8(msg, SMC_PNETID_IBPORT, 0xff))
  500. return -1;
  501. }
  502. return 0;
  503. }
  504. static int smc_pnet_add(struct sk_buff *skb, struct genl_info *info)
  505. {
  506. struct net *net = genl_info_net(info);
  507. return smc_pnet_enter(net, info->attrs);
  508. }
  509. static int smc_pnet_del(struct sk_buff *skb, struct genl_info *info)
  510. {
  511. struct net *net = genl_info_net(info);
  512. if (!info->attrs[SMC_PNETID_NAME])
  513. return -EINVAL;
  514. return smc_pnet_remove_by_pnetid(net,
  515. (char *)nla_data(info->attrs[SMC_PNETID_NAME]));
  516. }
  517. static int smc_pnet_dump_start(struct netlink_callback *cb)
  518. {
  519. cb->args[0] = 0;
  520. return 0;
  521. }
  522. static int smc_pnet_dumpinfo(struct sk_buff *skb,
  523. u32 portid, u32 seq, u32 flags,
  524. struct smc_pnetentry *pnetelem)
  525. {
  526. void *hdr;
  527. hdr = genlmsg_put(skb, portid, seq, &smc_pnet_nl_family,
  528. flags, SMC_PNETID_GET);
  529. if (!hdr)
  530. return -ENOMEM;
  531. if (smc_pnet_set_nla(skb, pnetelem) < 0) {
  532. genlmsg_cancel(skb, hdr);
  533. return -EMSGSIZE;
  534. }
  535. genlmsg_end(skb, hdr);
  536. return 0;
  537. }
  538. static int _smc_pnet_dump(struct net *net, struct sk_buff *skb, u32 portid,
  539. u32 seq, u8 *pnetid, int start_idx)
  540. {
  541. struct smc_pnettable *pnettable;
  542. struct smc_pnetentry *pnetelem;
  543. struct smc_net *sn;
  544. int idx = 0;
  545. /* get pnettable for namespace */
  546. sn = net_generic(net, smc_net_id);
  547. pnettable = &sn->pnettable;
  548. /* dump pnettable entries */
  549. mutex_lock(&pnettable->lock);
  550. list_for_each_entry(pnetelem, &pnettable->pnetlist, list) {
  551. if (pnetid && !smc_pnet_match(pnetelem->pnet_name, pnetid))
  552. continue;
  553. if (idx++ < start_idx)
  554. continue;
  555. /* if this is not the initial namespace, dump only netdev */
  556. if (net != &init_net && pnetelem->type != SMC_PNET_ETH)
  557. continue;
  558. if (smc_pnet_dumpinfo(skb, portid, seq, NLM_F_MULTI,
  559. pnetelem)) {
  560. --idx;
  561. break;
  562. }
  563. }
  564. mutex_unlock(&pnettable->lock);
  565. return idx;
  566. }
  567. static int smc_pnet_dump(struct sk_buff *skb, struct netlink_callback *cb)
  568. {
  569. struct net *net = sock_net(skb->sk);
  570. int idx;
  571. idx = _smc_pnet_dump(net, skb, NETLINK_CB(cb->skb).portid,
  572. cb->nlh->nlmsg_seq, NULL, cb->args[0]);
  573. cb->args[0] = idx;
  574. return skb->len;
  575. }
  576. /* Retrieve one PNETID entry */
  577. static int smc_pnet_get(struct sk_buff *skb, struct genl_info *info)
  578. {
  579. struct net *net = genl_info_net(info);
  580. struct sk_buff *msg;
  581. void *hdr;
  582. if (!info->attrs[SMC_PNETID_NAME])
  583. return -EINVAL;
  584. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  585. if (!msg)
  586. return -ENOMEM;
  587. _smc_pnet_dump(net, msg, info->snd_portid, info->snd_seq,
  588. nla_data(info->attrs[SMC_PNETID_NAME]), 0);
  589. /* finish multi part message and send it */
  590. hdr = nlmsg_put(msg, info->snd_portid, info->snd_seq, NLMSG_DONE, 0,
  591. NLM_F_MULTI);
  592. if (!hdr) {
  593. nlmsg_free(msg);
  594. return -EMSGSIZE;
  595. }
  596. return genlmsg_reply(msg, info);
  597. }
  598. /* Remove and delete all pnetids from pnet table.
  599. */
  600. static int smc_pnet_flush(struct sk_buff *skb, struct genl_info *info)
  601. {
  602. struct net *net = genl_info_net(info);
  603. smc_pnet_remove_by_pnetid(net, NULL);
  604. return 0;
  605. }
  606. /* SMC_PNETID generic netlink operation definition */
  607. static const struct genl_ops smc_pnet_ops[] = {
  608. {
  609. .cmd = SMC_PNETID_GET,
  610. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  611. /* can be retrieved by unprivileged users */
  612. .doit = smc_pnet_get,
  613. .dumpit = smc_pnet_dump,
  614. .start = smc_pnet_dump_start
  615. },
  616. {
  617. .cmd = SMC_PNETID_ADD,
  618. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  619. .flags = GENL_ADMIN_PERM,
  620. .doit = smc_pnet_add
  621. },
  622. {
  623. .cmd = SMC_PNETID_DEL,
  624. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  625. .flags = GENL_ADMIN_PERM,
  626. .doit = smc_pnet_del
  627. },
  628. {
  629. .cmd = SMC_PNETID_FLUSH,
  630. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  631. .flags = GENL_ADMIN_PERM,
  632. .doit = smc_pnet_flush
  633. }
  634. };
  635. /* SMC_PNETID family definition */
  636. static struct genl_family smc_pnet_nl_family __ro_after_init = {
  637. .hdrsize = 0,
  638. .name = SMCR_GENL_FAMILY_NAME,
  639. .version = SMCR_GENL_FAMILY_VERSION,
  640. .maxattr = SMC_PNETID_MAX,
  641. .policy = smc_pnet_policy,
  642. .netnsok = true,
  643. .module = THIS_MODULE,
  644. .ops = smc_pnet_ops,
  645. .n_ops = ARRAY_SIZE(smc_pnet_ops),
  646. .resv_start_op = SMC_PNETID_FLUSH + 1,
  647. };
  648. bool smc_pnet_is_ndev_pnetid(struct net *net, u8 *pnetid)
  649. {
  650. struct smc_net *sn = net_generic(net, smc_net_id);
  651. struct smc_pnetids_ndev_entry *pe;
  652. bool rc = false;
  653. read_lock(&sn->pnetids_ndev.lock);
  654. list_for_each_entry(pe, &sn->pnetids_ndev.list, list) {
  655. if (smc_pnet_match(pnetid, pe->pnetid)) {
  656. rc = true;
  657. goto unlock;
  658. }
  659. }
  660. unlock:
  661. read_unlock(&sn->pnetids_ndev.lock);
  662. return rc;
  663. }
  664. static int smc_pnet_add_pnetid(struct net *net, u8 *pnetid)
  665. {
  666. struct smc_net *sn = net_generic(net, smc_net_id);
  667. struct smc_pnetids_ndev_entry *pe, *pi;
  668. pe = kzalloc(sizeof(*pe), GFP_KERNEL);
  669. if (!pe)
  670. return -ENOMEM;
  671. write_lock(&sn->pnetids_ndev.lock);
  672. list_for_each_entry(pi, &sn->pnetids_ndev.list, list) {
  673. if (smc_pnet_match(pnetid, pe->pnetid)) {
  674. refcount_inc(&pi->refcnt);
  675. kfree(pe);
  676. goto unlock;
  677. }
  678. }
  679. refcount_set(&pe->refcnt, 1);
  680. memcpy(pe->pnetid, pnetid, SMC_MAX_PNETID_LEN);
  681. list_add_tail(&pe->list, &sn->pnetids_ndev.list);
  682. unlock:
  683. write_unlock(&sn->pnetids_ndev.lock);
  684. return 0;
  685. }
  686. static void smc_pnet_remove_pnetid(struct net *net, u8 *pnetid)
  687. {
  688. struct smc_net *sn = net_generic(net, smc_net_id);
  689. struct smc_pnetids_ndev_entry *pe, *pe2;
  690. write_lock(&sn->pnetids_ndev.lock);
  691. list_for_each_entry_safe(pe, pe2, &sn->pnetids_ndev.list, list) {
  692. if (smc_pnet_match(pnetid, pe->pnetid)) {
  693. if (refcount_dec_and_test(&pe->refcnt)) {
  694. list_del(&pe->list);
  695. kfree(pe);
  696. }
  697. break;
  698. }
  699. }
  700. write_unlock(&sn->pnetids_ndev.lock);
  701. }
  702. static void smc_pnet_add_base_pnetid(struct net *net, struct net_device *dev,
  703. u8 *ndev_pnetid)
  704. {
  705. struct net_device *base_dev;
  706. base_dev = __pnet_find_base_ndev(dev);
  707. if (base_dev->flags & IFF_UP &&
  708. !smc_pnetid_by_dev_port(base_dev->dev.parent, base_dev->dev_port,
  709. ndev_pnetid)) {
  710. /* add to PNETIDs list */
  711. smc_pnet_add_pnetid(net, ndev_pnetid);
  712. }
  713. }
  714. /* create initial list of netdevice pnetids */
  715. static void smc_pnet_create_pnetids_list(struct net *net)
  716. {
  717. u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
  718. struct net_device *dev;
  719. rtnl_lock();
  720. for_each_netdev(net, dev)
  721. smc_pnet_add_base_pnetid(net, dev, ndev_pnetid);
  722. rtnl_unlock();
  723. }
  724. /* clean up list of netdevice pnetids */
  725. static void smc_pnet_destroy_pnetids_list(struct net *net)
  726. {
  727. struct smc_net *sn = net_generic(net, smc_net_id);
  728. struct smc_pnetids_ndev_entry *pe, *temp_pe;
  729. write_lock(&sn->pnetids_ndev.lock);
  730. list_for_each_entry_safe(pe, temp_pe, &sn->pnetids_ndev.list, list) {
  731. list_del(&pe->list);
  732. kfree(pe);
  733. }
  734. write_unlock(&sn->pnetids_ndev.lock);
  735. }
  736. static int smc_pnet_netdev_event(struct notifier_block *this,
  737. unsigned long event, void *ptr)
  738. {
  739. struct net_device *event_dev = netdev_notifier_info_to_dev(ptr);
  740. struct net *net = dev_net(event_dev);
  741. u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
  742. switch (event) {
  743. case NETDEV_REBOOT:
  744. case NETDEV_UNREGISTER:
  745. smc_pnet_remove_by_ndev(event_dev);
  746. smc_ib_ndev_change(event_dev, event);
  747. return NOTIFY_OK;
  748. case NETDEV_REGISTER:
  749. smc_pnet_add_by_ndev(event_dev);
  750. smc_ib_ndev_change(event_dev, event);
  751. return NOTIFY_OK;
  752. case NETDEV_UP:
  753. smc_pnet_add_base_pnetid(net, event_dev, ndev_pnetid);
  754. return NOTIFY_OK;
  755. case NETDEV_DOWN:
  756. event_dev = __pnet_find_base_ndev(event_dev);
  757. if (!smc_pnetid_by_dev_port(event_dev->dev.parent,
  758. event_dev->dev_port, ndev_pnetid)) {
  759. /* remove from PNETIDs list */
  760. smc_pnet_remove_pnetid(net, ndev_pnetid);
  761. }
  762. return NOTIFY_OK;
  763. default:
  764. return NOTIFY_DONE;
  765. }
  766. }
  767. static struct notifier_block smc_netdev_notifier = {
  768. .notifier_call = smc_pnet_netdev_event
  769. };
  770. /* init network namespace */
  771. int smc_pnet_net_init(struct net *net)
  772. {
  773. struct smc_net *sn = net_generic(net, smc_net_id);
  774. struct smc_pnettable *pnettable = &sn->pnettable;
  775. struct smc_pnetids_ndev *pnetids_ndev = &sn->pnetids_ndev;
  776. INIT_LIST_HEAD(&pnettable->pnetlist);
  777. mutex_init(&pnettable->lock);
  778. INIT_LIST_HEAD(&pnetids_ndev->list);
  779. rwlock_init(&pnetids_ndev->lock);
  780. smc_pnet_create_pnetids_list(net);
  781. /* disable handshake limitation by default */
  782. net->smc.limit_smc_hs = 0;
  783. return 0;
  784. }
  785. int __init smc_pnet_init(void)
  786. {
  787. int rc;
  788. rc = genl_register_family(&smc_pnet_nl_family);
  789. if (rc)
  790. return rc;
  791. rc = register_netdevice_notifier(&smc_netdev_notifier);
  792. if (rc)
  793. genl_unregister_family(&smc_pnet_nl_family);
  794. return rc;
  795. }
  796. /* exit network namespace */
  797. void smc_pnet_net_exit(struct net *net)
  798. {
  799. /* flush pnet table */
  800. smc_pnet_remove_by_pnetid(net, NULL);
  801. smc_pnet_destroy_pnetids_list(net);
  802. }
  803. void smc_pnet_exit(void)
  804. {
  805. unregister_netdevice_notifier(&smc_netdev_notifier);
  806. genl_unregister_family(&smc_pnet_nl_family);
  807. }
  808. static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)
  809. {
  810. int i, nest_lvl;
  811. ASSERT_RTNL();
  812. nest_lvl = ndev->lower_level;
  813. for (i = 0; i < nest_lvl; i++) {
  814. struct list_head *lower = &ndev->adj_list.lower;
  815. if (list_empty(lower))
  816. break;
  817. lower = lower->next;
  818. ndev = netdev_lower_get_next(ndev, &lower);
  819. }
  820. return ndev;
  821. }
  822. /* Determine one base device for stacked net devices.
  823. * If the lower device level contains more than one devices
  824. * (for instance with bonding slaves), just the first device
  825. * is used to reach a base device.
  826. */
  827. static struct net_device *pnet_find_base_ndev(struct net_device *ndev)
  828. {
  829. rtnl_lock();
  830. ndev = __pnet_find_base_ndev(ndev);
  831. rtnl_unlock();
  832. return ndev;
  833. }
  834. static int smc_pnet_find_ndev_pnetid_by_table(struct net_device *ndev,
  835. u8 *pnetid)
  836. {
  837. struct smc_pnettable *pnettable;
  838. struct net *net = dev_net(ndev);
  839. struct smc_pnetentry *pnetelem;
  840. struct smc_net *sn;
  841. int rc = -ENOENT;
  842. /* get pnettable for namespace */
  843. sn = net_generic(net, smc_net_id);
  844. pnettable = &sn->pnettable;
  845. mutex_lock(&pnettable->lock);
  846. list_for_each_entry(pnetelem, &pnettable->pnetlist, list) {
  847. if (pnetelem->type == SMC_PNET_ETH && ndev == pnetelem->ndev) {
  848. /* get pnetid of netdev device */
  849. memcpy(pnetid, pnetelem->pnet_name, SMC_MAX_PNETID_LEN);
  850. rc = 0;
  851. break;
  852. }
  853. }
  854. mutex_unlock(&pnettable->lock);
  855. return rc;
  856. }
  857. static int smc_pnet_determine_gid(struct smc_ib_device *ibdev, int i,
  858. struct smc_init_info *ini)
  859. {
  860. if (!ini->check_smcrv2 &&
  861. !smc_ib_determine_gid(ibdev, i, ini->vlan_id, ini->ib_gid, NULL,
  862. NULL)) {
  863. ini->ib_dev = ibdev;
  864. ini->ib_port = i;
  865. return 0;
  866. }
  867. if (ini->check_smcrv2 &&
  868. !smc_ib_determine_gid(ibdev, i, ini->vlan_id, ini->smcrv2.ib_gid_v2,
  869. NULL, &ini->smcrv2)) {
  870. ini->smcrv2.ib_dev_v2 = ibdev;
  871. ini->smcrv2.ib_port_v2 = i;
  872. return 0;
  873. }
  874. return -ENODEV;
  875. }
  876. /* find a roce device for the given pnetid */
  877. static void _smc_pnet_find_roce_by_pnetid(u8 *pnet_id,
  878. struct smc_init_info *ini,
  879. struct smc_ib_device *known_dev,
  880. struct net *net)
  881. {
  882. struct smc_ib_device *ibdev;
  883. int i;
  884. mutex_lock(&smc_ib_devices.mutex);
  885. list_for_each_entry(ibdev, &smc_ib_devices.list, list) {
  886. if (ibdev == known_dev ||
  887. !rdma_dev_access_netns(ibdev->ibdev, net))
  888. continue;
  889. for (i = 1; i <= SMC_MAX_PORTS; i++) {
  890. if (!rdma_is_port_valid(ibdev->ibdev, i))
  891. continue;
  892. if (smc_pnet_match(ibdev->pnetid[i - 1], pnet_id) &&
  893. smc_ib_port_active(ibdev, i) &&
  894. !test_bit(i - 1, ibdev->ports_going_away)) {
  895. if (!smc_pnet_determine_gid(ibdev, i, ini))
  896. goto out;
  897. }
  898. }
  899. }
  900. out:
  901. mutex_unlock(&smc_ib_devices.mutex);
  902. }
  903. /* find alternate roce device with same pnet_id, vlan_id and net namespace */
  904. void smc_pnet_find_alt_roce(struct smc_link_group *lgr,
  905. struct smc_init_info *ini,
  906. struct smc_ib_device *known_dev)
  907. {
  908. struct net *net = lgr->net;
  909. _smc_pnet_find_roce_by_pnetid(lgr->pnet_id, ini, known_dev, net);
  910. }
  911. /* if handshake network device belongs to a roce device, return its
  912. * IB device and port
  913. */
  914. static void smc_pnet_find_rdma_dev(struct net_device *netdev,
  915. struct smc_init_info *ini)
  916. {
  917. struct net *net = dev_net(netdev);
  918. struct smc_ib_device *ibdev;
  919. mutex_lock(&smc_ib_devices.mutex);
  920. list_for_each_entry(ibdev, &smc_ib_devices.list, list) {
  921. struct net_device *ndev;
  922. int i;
  923. /* check rdma net namespace */
  924. if (!rdma_dev_access_netns(ibdev->ibdev, net))
  925. continue;
  926. for (i = 1; i <= SMC_MAX_PORTS; i++) {
  927. if (!rdma_is_port_valid(ibdev->ibdev, i))
  928. continue;
  929. if (!ibdev->ibdev->ops.get_netdev)
  930. continue;
  931. ndev = ibdev->ibdev->ops.get_netdev(ibdev->ibdev, i);
  932. if (!ndev)
  933. continue;
  934. dev_put(ndev);
  935. if (netdev == ndev &&
  936. smc_ib_port_active(ibdev, i) &&
  937. !test_bit(i - 1, ibdev->ports_going_away)) {
  938. if (!smc_pnet_determine_gid(ibdev, i, ini))
  939. break;
  940. }
  941. }
  942. }
  943. mutex_unlock(&smc_ib_devices.mutex);
  944. }
  945. /* Determine the corresponding IB device port based on the hardware PNETID.
  946. * Searching stops at the first matching active IB device port with vlan_id
  947. * configured.
  948. * If nothing found, check pnetid table.
  949. * If nothing found, try to use handshake device
  950. */
  951. static void smc_pnet_find_roce_by_pnetid(struct net_device *ndev,
  952. struct smc_init_info *ini)
  953. {
  954. u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
  955. struct net *net;
  956. ndev = pnet_find_base_ndev(ndev);
  957. net = dev_net(ndev);
  958. if (smc_pnetid_by_dev_port(ndev->dev.parent, ndev->dev_port,
  959. ndev_pnetid) &&
  960. smc_pnet_find_ndev_pnetid_by_table(ndev, ndev_pnetid)) {
  961. smc_pnet_find_rdma_dev(ndev, ini);
  962. return; /* pnetid could not be determined */
  963. }
  964. _smc_pnet_find_roce_by_pnetid(ndev_pnetid, ini, NULL, net);
  965. }
  966. static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev,
  967. struct smc_init_info *ini)
  968. {
  969. u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
  970. struct smcd_dev *ismdev;
  971. ndev = pnet_find_base_ndev(ndev);
  972. if (smc_pnetid_by_dev_port(ndev->dev.parent, ndev->dev_port,
  973. ndev_pnetid) &&
  974. smc_pnet_find_ndev_pnetid_by_table(ndev, ndev_pnetid))
  975. return; /* pnetid could not be determined */
  976. mutex_lock(&smcd_dev_list.mutex);
  977. list_for_each_entry(ismdev, &smcd_dev_list.list, list) {
  978. if (smc_pnet_match(ismdev->pnetid, ndev_pnetid) &&
  979. !ismdev->going_away &&
  980. (!ini->ism_peer_gid[0] ||
  981. !smc_ism_cantalk(ini->ism_peer_gid[0], ini->vlan_id,
  982. ismdev))) {
  983. ini->ism_dev[0] = ismdev;
  984. break;
  985. }
  986. }
  987. mutex_unlock(&smcd_dev_list.mutex);
  988. }
  989. /* PNET table analysis for a given sock:
  990. * determine ib_device and port belonging to used internal TCP socket
  991. * ethernet interface.
  992. */
  993. void smc_pnet_find_roce_resource(struct sock *sk, struct smc_init_info *ini)
  994. {
  995. struct dst_entry *dst = sk_dst_get(sk);
  996. if (!dst)
  997. goto out;
  998. if (!dst->dev)
  999. goto out_rel;
  1000. smc_pnet_find_roce_by_pnetid(dst->dev, ini);
  1001. out_rel:
  1002. dst_release(dst);
  1003. out:
  1004. return;
  1005. }
  1006. void smc_pnet_find_ism_resource(struct sock *sk, struct smc_init_info *ini)
  1007. {
  1008. struct dst_entry *dst = sk_dst_get(sk);
  1009. ini->ism_dev[0] = NULL;
  1010. if (!dst)
  1011. goto out;
  1012. if (!dst->dev)
  1013. goto out_rel;
  1014. smc_pnet_find_ism_by_pnetid(dst->dev, ini);
  1015. out_rel:
  1016. dst_release(dst);
  1017. out:
  1018. return;
  1019. }
  1020. /* Lookup and apply a pnet table entry to the given ib device.
  1021. */
  1022. int smc_pnetid_by_table_ib(struct smc_ib_device *smcibdev, u8 ib_port)
  1023. {
  1024. char *ib_name = smcibdev->ibdev->name;
  1025. struct smc_pnettable *pnettable;
  1026. struct smc_pnetentry *tmp_pe;
  1027. struct smc_net *sn;
  1028. int rc = -ENOENT;
  1029. /* get pnettable for init namespace */
  1030. sn = net_generic(&init_net, smc_net_id);
  1031. pnettable = &sn->pnettable;
  1032. mutex_lock(&pnettable->lock);
  1033. list_for_each_entry(tmp_pe, &pnettable->pnetlist, list) {
  1034. if (tmp_pe->type == SMC_PNET_IB &&
  1035. !strncmp(tmp_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX) &&
  1036. tmp_pe->ib_port == ib_port) {
  1037. smc_pnet_apply_ib(smcibdev, ib_port, tmp_pe->pnet_name);
  1038. rc = 0;
  1039. break;
  1040. }
  1041. }
  1042. mutex_unlock(&pnettable->lock);
  1043. return rc;
  1044. }
  1045. /* Lookup and apply a pnet table entry to the given smcd device.
  1046. */
  1047. int smc_pnetid_by_table_smcd(struct smcd_dev *smcddev)
  1048. {
  1049. const char *ib_name = dev_name(&smcddev->dev);
  1050. struct smc_pnettable *pnettable;
  1051. struct smc_pnetentry *tmp_pe;
  1052. struct smc_net *sn;
  1053. int rc = -ENOENT;
  1054. /* get pnettable for init namespace */
  1055. sn = net_generic(&init_net, smc_net_id);
  1056. pnettable = &sn->pnettable;
  1057. mutex_lock(&pnettable->lock);
  1058. list_for_each_entry(tmp_pe, &pnettable->pnetlist, list) {
  1059. if (tmp_pe->type == SMC_PNET_IB &&
  1060. !strncmp(tmp_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX)) {
  1061. smc_pnet_apply_smcd(smcddev, tmp_pe->pnet_name);
  1062. rc = 0;
  1063. break;
  1064. }
  1065. }
  1066. mutex_unlock(&pnettable->lock);
  1067. return rc;
  1068. }