1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
26812baabSThomas Richter /*
36812baabSThomas Richter * Shared Memory Communications over RDMA (SMC-R) and RoCE
46812baabSThomas Richter *
56812baabSThomas Richter * PNET table queries
66812baabSThomas Richter *
76812baabSThomas Richter * Copyright IBM Corp. 2016
86812baabSThomas Richter *
96812baabSThomas Richter * Author(s): Thomas Richter <tmricht@linux.vnet.ibm.com>
106812baabSThomas Richter */
116812baabSThomas Richter
126812baabSThomas Richter #ifndef _SMC_PNET_H
136812baabSThomas Richter #define _SMC_PNET_H
146812baabSThomas Richter
15e888a2e8SUrsula Braun #include <net/smc.h>
16e888a2e8SUrsula Braun
170afff91cSUrsula Braun #if IS_ENABLED(CONFIG_HAVE_PNETID)
180afff91cSUrsula Braun #include <asm/pnet.h>
190afff91cSUrsula Braun #endif
200afff91cSUrsula Braun
216812baabSThomas Richter struct smc_ib_device;
221619f770SHans Wippel struct smcd_dev;
23bc36d2fcSKarsten Graul struct smc_init_info;
246c868a3eSKarsten Graul struct smc_link_group;
256812baabSThomas Richter
2664e28b52SHans Wippel /**
2764e28b52SHans Wippel * struct smc_pnettable - SMC PNET table anchor
2864e28b52SHans Wippel * @lock: Lock for list action
2964e28b52SHans Wippel * @pnetlist: List of PNETIDs
3064e28b52SHans Wippel */
3164e28b52SHans Wippel struct smc_pnettable {
32*7ff57e98SFabio M. De Francesco struct mutex lock;
3364e28b52SHans Wippel struct list_head pnetlist;
3464e28b52SHans Wippel };
3564e28b52SHans Wippel
36e888a2e8SUrsula Braun struct smc_pnetids_ndev { /* list of pnetids for net devices in UP state*/
37e888a2e8SUrsula Braun struct list_head list;
38e888a2e8SUrsula Braun rwlock_t lock;
39e888a2e8SUrsula Braun };
40e888a2e8SUrsula Braun
41e888a2e8SUrsula Braun struct smc_pnetids_ndev_entry {
42e888a2e8SUrsula Braun struct list_head list;
43e888a2e8SUrsula Braun u8 pnetid[SMC_MAX_PNETID_LEN];
44e888a2e8SUrsula Braun refcount_t refcnt;
45e888a2e8SUrsula Braun };
46e888a2e8SUrsula Braun
smc_pnetid_by_dev_port(struct device * dev,unsigned short port,u8 * pnetid)470afff91cSUrsula Braun static inline int smc_pnetid_by_dev_port(struct device *dev,
480afff91cSUrsula Braun unsigned short port, u8 *pnetid)
490afff91cSUrsula Braun {
500afff91cSUrsula Braun #if IS_ENABLED(CONFIG_HAVE_PNETID)
510afff91cSUrsula Braun return pnet_id_by_dev_port(dev, port, pnetid);
520afff91cSUrsula Braun #else
530afff91cSUrsula Braun return -ENOENT;
540afff91cSUrsula Braun #endif
550afff91cSUrsula Braun }
560afff91cSUrsula Braun
576812baabSThomas Richter int smc_pnet_init(void) __init;
5864e28b52SHans Wippel int smc_pnet_net_init(struct net *net);
596812baabSThomas Richter void smc_pnet_exit(void);
6064e28b52SHans Wippel void smc_pnet_net_exit(struct net *net);
61bc36d2fcSKarsten Graul void smc_pnet_find_roce_resource(struct sock *sk, struct smc_init_info *ini);
62bc36d2fcSKarsten Graul void smc_pnet_find_ism_resource(struct sock *sk, struct smc_init_info *ini);
63fdff704dSKarsten Graul int smc_pnetid_by_table_ib(struct smc_ib_device *smcibdev, u8 ib_port);
64fdff704dSKarsten Graul int smc_pnetid_by_table_smcd(struct smcd_dev *smcd);
656c868a3eSKarsten Graul void smc_pnet_find_alt_roce(struct smc_link_group *lgr,
666c868a3eSKarsten Graul struct smc_init_info *ini,
676c868a3eSKarsten Graul struct smc_ib_device *known_dev);
68e888a2e8SUrsula Braun bool smc_pnet_is_ndev_pnetid(struct net *net, u8 *pnetid);
69d70bf4f7SUrsula Braun bool smc_pnet_is_pnetid_set(u8 *pnetid);
706812baabSThomas Richter #endif
71