smc_pnet.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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 <tmricht@linux.vnet.ibm.com>
  10. */
  11. #include <linux/module.h>
  12. #include <linux/list.h>
  13. #include <linux/ctype.h>
  14. #include <net/netlink.h>
  15. #include <net/genetlink.h>
  16. #include <uapi/linux/if.h>
  17. #include <uapi/linux/smc.h>
  18. #include <rdma/ib_verbs.h>
  19. #include "smc_pnet.h"
  20. #include "smc_ib.h"
  21. #include "smc_ism.h"
  22. static struct nla_policy smc_pnet_policy[SMC_PNETID_MAX + 1] = {
  23. [SMC_PNETID_NAME] = {
  24. .type = NLA_NUL_STRING,
  25. .len = SMC_MAX_PNETID_LEN - 1
  26. },
  27. [SMC_PNETID_ETHNAME] = {
  28. .type = NLA_NUL_STRING,
  29. .len = IFNAMSIZ - 1
  30. },
  31. [SMC_PNETID_IBNAME] = {
  32. .type = NLA_NUL_STRING,
  33. .len = IB_DEVICE_NAME_MAX - 1
  34. },
  35. [SMC_PNETID_IBPORT] = { .type = NLA_U8 }
  36. };
  37. static struct genl_family smc_pnet_nl_family;
  38. /**
  39. * struct smc_pnettable - SMC PNET table anchor
  40. * @lock: Lock for list action
  41. * @pnetlist: List of PNETIDs
  42. */
  43. static struct smc_pnettable {
  44. rwlock_t lock;
  45. struct list_head pnetlist;
  46. } smc_pnettable = {
  47. .pnetlist = LIST_HEAD_INIT(smc_pnettable.pnetlist),
  48. .lock = __RW_LOCK_UNLOCKED(smc_pnettable.lock)
  49. };
  50. /**
  51. * struct smc_pnetentry - pnet identifier name entry
  52. * @list: List node.
  53. * @pnet_name: Pnet identifier name
  54. * @ndev: pointer to network device.
  55. * @smcibdev: Pointer to IB device.
  56. */
  57. struct smc_pnetentry {
  58. struct list_head list;
  59. char pnet_name[SMC_MAX_PNETID_LEN + 1];
  60. struct net_device *ndev;
  61. struct smc_ib_device *smcibdev;
  62. u8 ib_port;
  63. };
  64. /* Check if two RDMA device entries are identical. Use device name and port
  65. * number for comparison.
  66. */
  67. static bool smc_pnet_same_ibname(struct smc_pnetentry *pnetelem, char *ibname,
  68. u8 ibport)
  69. {
  70. return pnetelem->ib_port == ibport &&
  71. !strncmp(pnetelem->smcibdev->ibdev->name, ibname,
  72. sizeof(pnetelem->smcibdev->ibdev->name));
  73. }
  74. /* Find a pnetid in the pnet table.
  75. */
  76. static struct smc_pnetentry *smc_pnet_find_pnetid(char *pnet_name)
  77. {
  78. struct smc_pnetentry *pnetelem, *found_pnetelem = NULL;
  79. read_lock(&smc_pnettable.lock);
  80. list_for_each_entry(pnetelem, &smc_pnettable.pnetlist, list) {
  81. if (!strncmp(pnetelem->pnet_name, pnet_name,
  82. sizeof(pnetelem->pnet_name))) {
  83. found_pnetelem = pnetelem;
  84. break;
  85. }
  86. }
  87. read_unlock(&smc_pnettable.lock);
  88. return found_pnetelem;
  89. }
  90. /* Remove a pnetid from the pnet table.
  91. */
  92. static int smc_pnet_remove_by_pnetid(char *pnet_name)
  93. {
  94. struct smc_pnetentry *pnetelem, *tmp_pe;
  95. int rc = -ENOENT;
  96. write_lock(&smc_pnettable.lock);
  97. list_for_each_entry_safe(pnetelem, tmp_pe, &smc_pnettable.pnetlist,
  98. list) {
  99. if (!strncmp(pnetelem->pnet_name, pnet_name,
  100. sizeof(pnetelem->pnet_name))) {
  101. list_del(&pnetelem->list);
  102. dev_put(pnetelem->ndev);
  103. kfree(pnetelem);
  104. rc = 0;
  105. break;
  106. }
  107. }
  108. write_unlock(&smc_pnettable.lock);
  109. return rc;
  110. }
  111. /* Remove a pnet entry mentioning a given network device from the pnet table.
  112. */
  113. static int smc_pnet_remove_by_ndev(struct net_device *ndev)
  114. {
  115. struct smc_pnetentry *pnetelem, *tmp_pe;
  116. int rc = -ENOENT;
  117. write_lock(&smc_pnettable.lock);
  118. list_for_each_entry_safe(pnetelem, tmp_pe, &smc_pnettable.pnetlist,
  119. list) {
  120. if (pnetelem->ndev == ndev) {
  121. list_del(&pnetelem->list);
  122. dev_put(pnetelem->ndev);
  123. kfree(pnetelem);
  124. rc = 0;
  125. break;
  126. }
  127. }
  128. write_unlock(&smc_pnettable.lock);
  129. return rc;
  130. }
  131. /* Remove a pnet entry mentioning a given ib device from the pnet table.
  132. */
  133. int smc_pnet_remove_by_ibdev(struct smc_ib_device *ibdev)
  134. {
  135. struct smc_pnetentry *pnetelem, *tmp_pe;
  136. int rc = -ENOENT;
  137. write_lock(&smc_pnettable.lock);
  138. list_for_each_entry_safe(pnetelem, tmp_pe, &smc_pnettable.pnetlist,
  139. list) {
  140. if (pnetelem->smcibdev == ibdev) {
  141. list_del(&pnetelem->list);
  142. dev_put(pnetelem->ndev);
  143. kfree(pnetelem);
  144. rc = 0;
  145. break;
  146. }
  147. }
  148. write_unlock(&smc_pnettable.lock);
  149. return rc;
  150. }
  151. /* Append a pnetid to the end of the pnet table if not already on this list.
  152. */
  153. static int smc_pnet_enter(struct smc_pnetentry *new_pnetelem)
  154. {
  155. struct smc_pnetentry *pnetelem;
  156. int rc = -EEXIST;
  157. write_lock(&smc_pnettable.lock);
  158. list_for_each_entry(pnetelem, &smc_pnettable.pnetlist, list) {
  159. if (!strncmp(pnetelem->pnet_name, new_pnetelem->pnet_name,
  160. sizeof(new_pnetelem->pnet_name)) ||
  161. !strncmp(pnetelem->ndev->name, new_pnetelem->ndev->name,
  162. sizeof(new_pnetelem->ndev->name)) ||
  163. smc_pnet_same_ibname(pnetelem,
  164. new_pnetelem->smcibdev->ibdev->name,
  165. new_pnetelem->ib_port)) {
  166. dev_put(pnetelem->ndev);
  167. goto found;
  168. }
  169. }
  170. list_add_tail(&new_pnetelem->list, &smc_pnettable.pnetlist);
  171. rc = 0;
  172. found:
  173. write_unlock(&smc_pnettable.lock);
  174. return rc;
  175. }
  176. /* The limit for pnetid is 16 characters.
  177. * Valid characters should be (single-byte character set) a-z, A-Z, 0-9.
  178. * Lower case letters are converted to upper case.
  179. * Interior blanks should not be used.
  180. */
  181. static bool smc_pnetid_valid(const char *pnet_name, char *pnetid)
  182. {
  183. char *bf = skip_spaces(pnet_name);
  184. size_t len = strlen(bf);
  185. char *end = bf + len;
  186. if (!len)
  187. return false;
  188. while (--end >= bf && isspace(*end))
  189. ;
  190. if (end - bf >= SMC_MAX_PNETID_LEN)
  191. return false;
  192. while (bf <= end) {
  193. if (!isalnum(*bf))
  194. return false;
  195. *pnetid++ = islower(*bf) ? toupper(*bf) : *bf;
  196. bf++;
  197. }
  198. *pnetid = '\0';
  199. return true;
  200. }
  201. /* Find an infiniband device by a given name. The device might not exist. */
  202. static struct smc_ib_device *smc_pnet_find_ib(char *ib_name)
  203. {
  204. struct smc_ib_device *ibdev;
  205. spin_lock(&smc_ib_devices.lock);
  206. list_for_each_entry(ibdev, &smc_ib_devices.list, list) {
  207. if (!strncmp(ibdev->ibdev->name, ib_name,
  208. sizeof(ibdev->ibdev->name))) {
  209. goto out;
  210. }
  211. }
  212. ibdev = NULL;
  213. out:
  214. spin_unlock(&smc_ib_devices.lock);
  215. return ibdev;
  216. }
  217. /* Parse the supplied netlink attributes and fill a pnetentry structure.
  218. * For ethernet and infiniband device names verify that the devices exist.
  219. */
  220. static int smc_pnet_fill_entry(struct net *net, struct smc_pnetentry *pnetelem,
  221. struct nlattr *tb[])
  222. {
  223. char *string, *ibname;
  224. int rc;
  225. memset(pnetelem, 0, sizeof(*pnetelem));
  226. INIT_LIST_HEAD(&pnetelem->list);
  227. rc = -EINVAL;
  228. if (!tb[SMC_PNETID_NAME])
  229. goto error;
  230. string = (char *)nla_data(tb[SMC_PNETID_NAME]);
  231. if (!smc_pnetid_valid(string, pnetelem->pnet_name))
  232. goto error;
  233. rc = -EINVAL;
  234. if (!tb[SMC_PNETID_ETHNAME])
  235. goto error;
  236. rc = -ENOENT;
  237. string = (char *)nla_data(tb[SMC_PNETID_ETHNAME]);
  238. pnetelem->ndev = dev_get_by_name(net, string);
  239. if (!pnetelem->ndev)
  240. goto error;
  241. rc = -EINVAL;
  242. if (!tb[SMC_PNETID_IBNAME])
  243. goto error;
  244. rc = -ENOENT;
  245. ibname = (char *)nla_data(tb[SMC_PNETID_IBNAME]);
  246. ibname = strim(ibname);
  247. pnetelem->smcibdev = smc_pnet_find_ib(ibname);
  248. if (!pnetelem->smcibdev)
  249. goto error;
  250. rc = -EINVAL;
  251. if (!tb[SMC_PNETID_IBPORT])
  252. goto error;
  253. pnetelem->ib_port = nla_get_u8(tb[SMC_PNETID_IBPORT]);
  254. if (pnetelem->ib_port < 1 || pnetelem->ib_port > SMC_MAX_PORTS)
  255. goto error;
  256. return 0;
  257. error:
  258. if (pnetelem->ndev)
  259. dev_put(pnetelem->ndev);
  260. return rc;
  261. }
  262. /* Convert an smc_pnetentry to a netlink attribute sequence */
  263. static int smc_pnet_set_nla(struct sk_buff *msg, struct smc_pnetentry *pnetelem)
  264. {
  265. if (nla_put_string(msg, SMC_PNETID_NAME, pnetelem->pnet_name) ||
  266. nla_put_string(msg, SMC_PNETID_ETHNAME, pnetelem->ndev->name) ||
  267. nla_put_string(msg, SMC_PNETID_IBNAME,
  268. pnetelem->smcibdev->ibdev->name) ||
  269. nla_put_u8(msg, SMC_PNETID_IBPORT, pnetelem->ib_port))
  270. return -1;
  271. return 0;
  272. }
  273. /* Retrieve one PNETID entry */
  274. static int smc_pnet_get(struct sk_buff *skb, struct genl_info *info)
  275. {
  276. struct smc_pnetentry *pnetelem;
  277. struct sk_buff *msg;
  278. void *hdr;
  279. int rc;
  280. if (!info->attrs[SMC_PNETID_NAME])
  281. return -EINVAL;
  282. pnetelem = smc_pnet_find_pnetid(
  283. (char *)nla_data(info->attrs[SMC_PNETID_NAME]));
  284. if (!pnetelem)
  285. return -ENOENT;
  286. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  287. if (!msg)
  288. return -ENOMEM;
  289. hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
  290. &smc_pnet_nl_family, 0, SMC_PNETID_GET);
  291. if (!hdr) {
  292. rc = -EMSGSIZE;
  293. goto err_out;
  294. }
  295. if (smc_pnet_set_nla(msg, pnetelem)) {
  296. rc = -ENOBUFS;
  297. goto err_out;
  298. }
  299. genlmsg_end(msg, hdr);
  300. return genlmsg_reply(msg, info);
  301. err_out:
  302. nlmsg_free(msg);
  303. return rc;
  304. }
  305. static int smc_pnet_add(struct sk_buff *skb, struct genl_info *info)
  306. {
  307. struct net *net = genl_info_net(info);
  308. struct smc_pnetentry *pnetelem;
  309. int rc;
  310. pnetelem = kzalloc(sizeof(*pnetelem), GFP_KERNEL);
  311. if (!pnetelem)
  312. return -ENOMEM;
  313. rc = smc_pnet_fill_entry(net, pnetelem, info->attrs);
  314. if (!rc)
  315. rc = smc_pnet_enter(pnetelem);
  316. if (rc) {
  317. kfree(pnetelem);
  318. return rc;
  319. }
  320. return rc;
  321. }
  322. static int smc_pnet_del(struct sk_buff *skb, struct genl_info *info)
  323. {
  324. if (!info->attrs[SMC_PNETID_NAME])
  325. return -EINVAL;
  326. return smc_pnet_remove_by_pnetid(
  327. (char *)nla_data(info->attrs[SMC_PNETID_NAME]));
  328. }
  329. static int smc_pnet_dump_start(struct netlink_callback *cb)
  330. {
  331. cb->args[0] = 0;
  332. return 0;
  333. }
  334. static int smc_pnet_dumpinfo(struct sk_buff *skb,
  335. u32 portid, u32 seq, u32 flags,
  336. struct smc_pnetentry *pnetelem)
  337. {
  338. void *hdr;
  339. hdr = genlmsg_put(skb, portid, seq, &smc_pnet_nl_family,
  340. flags, SMC_PNETID_GET);
  341. if (!hdr)
  342. return -ENOMEM;
  343. if (smc_pnet_set_nla(skb, pnetelem) < 0) {
  344. genlmsg_cancel(skb, hdr);
  345. return -EMSGSIZE;
  346. }
  347. genlmsg_end(skb, hdr);
  348. return 0;
  349. }
  350. static int smc_pnet_dump(struct sk_buff *skb, struct netlink_callback *cb)
  351. {
  352. struct smc_pnetentry *pnetelem;
  353. int idx = 0;
  354. read_lock(&smc_pnettable.lock);
  355. list_for_each_entry(pnetelem, &smc_pnettable.pnetlist, list) {
  356. if (idx++ < cb->args[0])
  357. continue;
  358. if (smc_pnet_dumpinfo(skb, NETLINK_CB(cb->skb).portid,
  359. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  360. pnetelem)) {
  361. --idx;
  362. break;
  363. }
  364. }
  365. cb->args[0] = idx;
  366. read_unlock(&smc_pnettable.lock);
  367. return skb->len;
  368. }
  369. /* Remove and delete all pnetids from pnet table.
  370. */
  371. static int smc_pnet_flush(struct sk_buff *skb, struct genl_info *info)
  372. {
  373. struct smc_pnetentry *pnetelem, *tmp_pe;
  374. write_lock(&smc_pnettable.lock);
  375. list_for_each_entry_safe(pnetelem, tmp_pe, &smc_pnettable.pnetlist,
  376. list) {
  377. list_del(&pnetelem->list);
  378. dev_put(pnetelem->ndev);
  379. kfree(pnetelem);
  380. }
  381. write_unlock(&smc_pnettable.lock);
  382. return 0;
  383. }
  384. /* SMC_PNETID generic netlink operation definition */
  385. static const struct genl_ops smc_pnet_ops[] = {
  386. {
  387. .cmd = SMC_PNETID_GET,
  388. .flags = GENL_ADMIN_PERM,
  389. .policy = smc_pnet_policy,
  390. .doit = smc_pnet_get,
  391. .dumpit = smc_pnet_dump,
  392. .start = smc_pnet_dump_start
  393. },
  394. {
  395. .cmd = SMC_PNETID_ADD,
  396. .flags = GENL_ADMIN_PERM,
  397. .policy = smc_pnet_policy,
  398. .doit = smc_pnet_add
  399. },
  400. {
  401. .cmd = SMC_PNETID_DEL,
  402. .flags = GENL_ADMIN_PERM,
  403. .policy = smc_pnet_policy,
  404. .doit = smc_pnet_del
  405. },
  406. {
  407. .cmd = SMC_PNETID_FLUSH,
  408. .flags = GENL_ADMIN_PERM,
  409. .policy = smc_pnet_policy,
  410. .doit = smc_pnet_flush
  411. }
  412. };
  413. /* SMC_PNETID family definition */
  414. static struct genl_family smc_pnet_nl_family __ro_after_init = {
  415. .hdrsize = 0,
  416. .name = SMCR_GENL_FAMILY_NAME,
  417. .version = SMCR_GENL_FAMILY_VERSION,
  418. .maxattr = SMC_PNETID_MAX,
  419. .netnsok = true,
  420. .module = THIS_MODULE,
  421. .ops = smc_pnet_ops,
  422. .n_ops = ARRAY_SIZE(smc_pnet_ops)
  423. };
  424. static int smc_pnet_netdev_event(struct notifier_block *this,
  425. unsigned long event, void *ptr)
  426. {
  427. struct net_device *event_dev = netdev_notifier_info_to_dev(ptr);
  428. switch (event) {
  429. case NETDEV_REBOOT:
  430. case NETDEV_UNREGISTER:
  431. smc_pnet_remove_by_ndev(event_dev);
  432. return NOTIFY_OK;
  433. default:
  434. return NOTIFY_DONE;
  435. }
  436. }
  437. static struct notifier_block smc_netdev_notifier = {
  438. .notifier_call = smc_pnet_netdev_event
  439. };
  440. int __init smc_pnet_init(void)
  441. {
  442. int rc;
  443. rc = genl_register_family(&smc_pnet_nl_family);
  444. if (rc)
  445. return rc;
  446. rc = register_netdevice_notifier(&smc_netdev_notifier);
  447. if (rc)
  448. genl_unregister_family(&smc_pnet_nl_family);
  449. return rc;
  450. }
  451. void smc_pnet_exit(void)
  452. {
  453. smc_pnet_flush(NULL, NULL);
  454. unregister_netdevice_notifier(&smc_netdev_notifier);
  455. genl_unregister_family(&smc_pnet_nl_family);
  456. }
  457. /* Determine one base device for stacked net devices.
  458. * If the lower device level contains more than one devices
  459. * (for instance with bonding slaves), just the first device
  460. * is used to reach a base device.
  461. */
  462. static struct net_device *pnet_find_base_ndev(struct net_device *ndev)
  463. {
  464. int i, nest_lvl;
  465. rtnl_lock();
  466. nest_lvl = dev_get_nest_level(ndev);
  467. for (i = 0; i < nest_lvl; i++) {
  468. struct list_head *lower = &ndev->adj_list.lower;
  469. if (list_empty(lower))
  470. break;
  471. lower = lower->next;
  472. ndev = netdev_lower_get_next(ndev, &lower);
  473. }
  474. rtnl_unlock();
  475. return ndev;
  476. }
  477. /* Determine the corresponding IB device port based on the hardware PNETID.
  478. * Searching stops at the first matching active IB device port with vlan_id
  479. * configured.
  480. */
  481. static void smc_pnet_find_roce_by_pnetid(struct net_device *ndev,
  482. struct smc_ib_device **smcibdev,
  483. u8 *ibport, unsigned short vlan_id,
  484. u8 gid[])
  485. {
  486. u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
  487. struct smc_ib_device *ibdev;
  488. int i;
  489. ndev = pnet_find_base_ndev(ndev);
  490. if (smc_pnetid_by_dev_port(ndev->dev.parent, ndev->dev_port,
  491. ndev_pnetid))
  492. return; /* pnetid could not be determined */
  493. spin_lock(&smc_ib_devices.lock);
  494. list_for_each_entry(ibdev, &smc_ib_devices.list, list) {
  495. for (i = 1; i <= SMC_MAX_PORTS; i++) {
  496. if (!rdma_is_port_valid(ibdev->ibdev, i))
  497. continue;
  498. if (!memcmp(ibdev->pnetid[i - 1], ndev_pnetid,
  499. SMC_MAX_PNETID_LEN) &&
  500. smc_ib_port_active(ibdev, i) &&
  501. !smc_ib_determine_gid(ibdev, i, vlan_id, gid,
  502. NULL)) {
  503. *smcibdev = ibdev;
  504. *ibport = i;
  505. goto out;
  506. }
  507. }
  508. }
  509. out:
  510. spin_unlock(&smc_ib_devices.lock);
  511. }
  512. static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev,
  513. struct smcd_dev **smcismdev)
  514. {
  515. u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
  516. struct smcd_dev *ismdev;
  517. ndev = pnet_find_base_ndev(ndev);
  518. if (smc_pnetid_by_dev_port(ndev->dev.parent, ndev->dev_port,
  519. ndev_pnetid))
  520. return; /* pnetid could not be determined */
  521. spin_lock(&smcd_dev_list.lock);
  522. list_for_each_entry(ismdev, &smcd_dev_list.list, list) {
  523. if (!memcmp(ismdev->pnetid, ndev_pnetid, SMC_MAX_PNETID_LEN)) {
  524. *smcismdev = ismdev;
  525. break;
  526. }
  527. }
  528. spin_unlock(&smcd_dev_list.lock);
  529. }
  530. /* Lookup of coupled ib_device via SMC pnet table */
  531. static void smc_pnet_find_roce_by_table(struct net_device *netdev,
  532. struct smc_ib_device **smcibdev,
  533. u8 *ibport, unsigned short vlan_id,
  534. u8 gid[])
  535. {
  536. struct smc_pnetentry *pnetelem;
  537. read_lock(&smc_pnettable.lock);
  538. list_for_each_entry(pnetelem, &smc_pnettable.pnetlist, list) {
  539. if (netdev == pnetelem->ndev) {
  540. if (smc_ib_port_active(pnetelem->smcibdev,
  541. pnetelem->ib_port) &&
  542. !smc_ib_determine_gid(pnetelem->smcibdev,
  543. pnetelem->ib_port, vlan_id,
  544. gid, NULL)) {
  545. *smcibdev = pnetelem->smcibdev;
  546. *ibport = pnetelem->ib_port;
  547. }
  548. break;
  549. }
  550. }
  551. read_unlock(&smc_pnettable.lock);
  552. }
  553. /* PNET table analysis for a given sock:
  554. * determine ib_device and port belonging to used internal TCP socket
  555. * ethernet interface.
  556. */
  557. void smc_pnet_find_roce_resource(struct sock *sk,
  558. struct smc_ib_device **smcibdev, u8 *ibport,
  559. unsigned short vlan_id, u8 gid[])
  560. {
  561. struct dst_entry *dst = sk_dst_get(sk);
  562. *smcibdev = NULL;
  563. *ibport = 0;
  564. if (!dst)
  565. goto out;
  566. if (!dst->dev)
  567. goto out_rel;
  568. /* if possible, lookup via hardware-defined pnetid */
  569. smc_pnet_find_roce_by_pnetid(dst->dev, smcibdev, ibport, vlan_id, gid);
  570. if (*smcibdev)
  571. goto out_rel;
  572. /* lookup via SMC PNET table */
  573. smc_pnet_find_roce_by_table(dst->dev, smcibdev, ibport, vlan_id, gid);
  574. out_rel:
  575. dst_release(dst);
  576. out:
  577. return;
  578. }
  579. void smc_pnet_find_ism_resource(struct sock *sk, struct smcd_dev **smcismdev)
  580. {
  581. struct dst_entry *dst = sk_dst_get(sk);
  582. *smcismdev = NULL;
  583. if (!dst)
  584. goto out;
  585. if (!dst->dev)
  586. goto out_rel;
  587. /* if possible, lookup via hardware-defined pnetid */
  588. smc_pnet_find_ism_by_pnetid(dst->dev, smcismdev);
  589. out_rel:
  590. dst_release(dst);
  591. out:
  592. return;
  593. }