Commit 5417783e authored by Parav Pandit's avatar Parav Pandit Committed by Jason Gunthorpe

RDMA/core: Support core port attributes in non init_net

Now that sysfs compatibility layer for non init_net exists, add core port
attributes such as pkey and gid table to non init_net ns.
Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 4e0f7b90
...@@ -336,4 +336,8 @@ int roce_resolve_route_from_path(struct sa_path_rec *rec, ...@@ -336,4 +336,8 @@ int roce_resolve_route_from_path(struct sa_path_rec *rec,
const struct ib_gid_attr *attr); const struct ib_gid_attr *attr);
struct net_device *rdma_read_gid_attr_ndev_rcu(const struct ib_gid_attr *attr); struct net_device *rdma_read_gid_attr_ndev_rcu(const struct ib_gid_attr *attr);
void ib_free_port_attrs(struct ib_core_device *coredev);
int ib_setup_port_attrs(struct ib_core_device *coredev,
bool alloc_hw_stats);
#endif /* _CORE_PRIV_H */ #endif /* _CORE_PRIV_H */
...@@ -773,6 +773,9 @@ static int add_one_compat_dev(struct ib_device *device, ...@@ -773,6 +773,9 @@ static int add_one_compat_dev(struct ib_device *device,
ret = device_add(&cdev->dev); ret = device_add(&cdev->dev);
if (ret) if (ret)
goto add_err; goto add_err;
ret = ib_setup_port_attrs(cdev, false);
if (ret)
goto port_err;
ret = xa_err(xa_store(&device->compat_devs, rnet->id, ret = xa_err(xa_store(&device->compat_devs, rnet->id,
cdev, GFP_KERNEL)); cdev, GFP_KERNEL));
...@@ -783,6 +786,8 @@ static int add_one_compat_dev(struct ib_device *device, ...@@ -783,6 +786,8 @@ static int add_one_compat_dev(struct ib_device *device,
return 0; return 0;
insert_err: insert_err:
ib_free_port_attrs(cdev);
port_err:
device_del(&cdev->dev); device_del(&cdev->dev);
add_err: add_err:
put_device(&cdev->dev); put_device(&cdev->dev);
...@@ -801,6 +806,7 @@ static void remove_one_compat_dev(struct ib_device *device, u32 id) ...@@ -801,6 +806,7 @@ static void remove_one_compat_dev(struct ib_device *device, u32 id)
cdev = xa_erase(&device->compat_devs, id); cdev = xa_erase(&device->compat_devs, id);
mutex_unlock(&device->compat_devs_mutex); mutex_unlock(&device->compat_devs_mutex);
if (cdev) { if (cdev) {
ib_free_port_attrs(cdev);
device_del(&cdev->dev); device_del(&cdev->dev);
put_device(&cdev->dev); put_device(&cdev->dev);
} }
......
...@@ -1015,7 +1015,8 @@ static void setup_hw_stats(struct ib_device *device, struct ib_port *port, ...@@ -1015,7 +1015,8 @@ static void setup_hw_stats(struct ib_device *device, struct ib_port *port,
return; return;
} }
static int add_port(struct ib_core_device *coredev, int port_num) static int add_port(struct ib_core_device *coredev,
int port_num, bool alloc_stats)
{ {
struct ib_device *device = rdma_device_to_ibdev(&coredev->dev); struct ib_device *device = rdma_device_to_ibdev(&coredev->dev);
struct ib_port *p; struct ib_port *p;
...@@ -1056,7 +1057,7 @@ static int add_port(struct ib_core_device *coredev, int port_num) ...@@ -1056,7 +1057,7 @@ static int add_port(struct ib_core_device *coredev, int port_num)
goto err_put; goto err_put;
} }
if (device->ops.process_mad) { if (device->ops.process_mad && alloc_stats) {
p->pma_table = get_counter_table(device, port_num); p->pma_table = get_counter_table(device, port_num);
ret = sysfs_create_group(&p->kobj, p->pma_table); ret = sysfs_create_group(&p->kobj, p->pma_table);
if (ret) if (ret)
...@@ -1123,7 +1124,7 @@ static int add_port(struct ib_core_device *coredev, int port_num) ...@@ -1123,7 +1124,7 @@ static int add_port(struct ib_core_device *coredev, int port_num)
* port, so holder should be device. Therefore skip per port conunter * port, so holder should be device. Therefore skip per port conunter
* initialization. * initialization.
*/ */
if (device->ops.alloc_hw_stats && port_num) if (device->ops.alloc_hw_stats && port_num && alloc_stats)
setup_hw_stats(device, p, port_num); setup_hw_stats(device, p, port_num);
list_add_tail(&p->kobj.entry, &coredev->port_list); list_add_tail(&p->kobj.entry, &coredev->port_list);
...@@ -1280,7 +1281,7 @@ const struct attribute_group ib_dev_attr_group = { ...@@ -1280,7 +1281,7 @@ const struct attribute_group ib_dev_attr_group = {
.attrs = ib_dev_attrs, .attrs = ib_dev_attrs,
}; };
static void ib_free_port_attrs(struct ib_core_device *coredev) void ib_free_port_attrs(struct ib_core_device *coredev)
{ {
struct kobject *p, *t; struct kobject *p, *t;
...@@ -1307,7 +1308,7 @@ static void ib_free_port_attrs(struct ib_core_device *coredev) ...@@ -1307,7 +1308,7 @@ static void ib_free_port_attrs(struct ib_core_device *coredev)
kobject_put(coredev->ports_kobj); kobject_put(coredev->ports_kobj);
} }
static int ib_setup_port_attrs(struct ib_core_device *coredev) int ib_setup_port_attrs(struct ib_core_device *coredev, bool alloc_stats)
{ {
struct ib_device *device = rdma_device_to_ibdev(&coredev->dev); struct ib_device *device = rdma_device_to_ibdev(&coredev->dev);
unsigned int port; unsigned int port;
...@@ -1319,7 +1320,7 @@ static int ib_setup_port_attrs(struct ib_core_device *coredev) ...@@ -1319,7 +1320,7 @@ static int ib_setup_port_attrs(struct ib_core_device *coredev)
return -ENOMEM; return -ENOMEM;
rdma_for_each_port (device, port) { rdma_for_each_port (device, port) {
ret = add_port(coredev, port); ret = add_port(coredev, port, alloc_stats);
if (ret) if (ret)
goto err_put; goto err_put;
} }
...@@ -1335,7 +1336,7 @@ int ib_device_register_sysfs(struct ib_device *device) ...@@ -1335,7 +1336,7 @@ int ib_device_register_sysfs(struct ib_device *device)
{ {
int ret; int ret;
ret = ib_setup_port_attrs(&device->coredev); ret = ib_setup_port_attrs(&device->coredev, true);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment