summaryrefslogtreecommitdiff
path: root/drivers/infiniband/core
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@nvidia.com>2021-06-11 19:00:32 +0300
committerJason Gunthorpe <jgg@nvidia.com>2021-06-16 20:58:31 -0300
commitd7407d16699884817f3a93218e77b0801942362b (patch)
tree62354cafcb7d6ae509521eef88a4ab11393d07a4 /drivers/infiniband/core
parent8f1708f19f919135a5d7eddcdccc15b7fd7d524d (diff)
RDMA: Change ops->init_port to ops->port_groups
init_port was only being used to register sysfs attributes against the port kobject. Now that all users are creating static attribute_group's we can simply set the attribute_group list in the ops and the core code can just handle it directly. This makes all the sysfs management quite straightforward and prevents any driver from abusing the naked port kobject in future because no driver code can access it. Link: https://lore.kernel.org/r/114f68f3d921460eafe14cea5a80ca65d81729c3.1623427137.git.leonro@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Diffstat (limited to 'drivers/infiniband/core')
-rw-r--r--drivers/infiniband/core/device.c4
-rw-r--r--drivers/infiniband/core/sysfs.c39
2 files changed, 15 insertions, 28 deletions
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 030a4041b2e0..2cbd77933ea5 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -1703,7 +1703,7 @@ int ib_device_set_netns_put(struct sk_buff *skb,
* port_cleanup infrastructure is implemented, this limitation will be
* removed.
*/
- if (!dev->ops.disassociate_ucontext || dev->ops.init_port ||
+ if (!dev->ops.disassociate_ucontext || dev->ops.port_groups ||
ib_devices_shared_netns) {
ret = -EOPNOTSUPP;
goto ns_err;
@@ -2668,7 +2668,6 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
SET_DEVICE_OP(dev_ops, get_vf_config);
SET_DEVICE_OP(dev_ops, get_vf_guid);
SET_DEVICE_OP(dev_ops, get_vf_stats);
- SET_DEVICE_OP(dev_ops, init_port);
SET_DEVICE_OP(dev_ops, iw_accept);
SET_DEVICE_OP(dev_ops, iw_add_ref);
SET_DEVICE_OP(dev_ops, iw_connect);
@@ -2691,6 +2690,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
SET_DEVICE_OP(dev_ops, modify_wq);
SET_DEVICE_OP(dev_ops, peek_cq);
SET_DEVICE_OP(dev_ops, poll_cq);
+ SET_DEVICE_OP(dev_ops, port_groups);
SET_DEVICE_OP(dev_ops, post_recv);
SET_DEVICE_OP(dev_ops, post_send);
SET_DEVICE_OP(dev_ops, post_srq_recv);
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index e550a7eb37f6..09a2e1066df0 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -128,22 +128,6 @@ static ssize_t port_attr_store(struct kobject *kobj,
return port_attr->store(p->ibdev, p->port_num, port_attr, buf, count);
}
-int ib_port_sysfs_create_groups(struct ib_device *ibdev, u32 port_num,
- const struct attribute_group **groups)
-{
- return sysfs_create_groups(&ibdev->port_data[port_num].sysfs->kobj,
- groups);
-}
-EXPORT_SYMBOL_GPL(ib_port_sysfs_create_groups);
-
-void ib_port_sysfs_remove_groups(struct ib_device *ibdev, u32 port_num,
- const struct attribute_group **groups)
-{
- return sysfs_remove_groups(&ibdev->port_data[port_num].sysfs->kobj,
- groups);
-}
-EXPORT_SYMBOL_GPL(ib_port_sysfs_remove_groups);
-
struct ib_device *ib_port_sysfs_get_ibdev_kobj(struct kobject *kobj,
u32 *port_num)
{
@@ -1252,6 +1236,11 @@ static struct ib_port *setup_port(struct ib_core_device *coredev, int port_num,
ret = sysfs_create_groups(&p->kobj, p->groups_list);
if (ret)
goto err_del;
+ if (is_full_dev) {
+ ret = sysfs_create_groups(&p->kobj, device->ops.port_groups);
+ if (ret)
+ goto err_groups;
+ }
list_add_tail(&p->kobj.entry, &coredev->port_list);
if (device->port_data && is_full_dev)
@@ -1259,6 +1248,8 @@ static struct ib_port *setup_port(struct ib_core_device *coredev, int port_num,
return p;
+err_groups:
+ sysfs_remove_groups(&p->kobj, p->groups_list);
err_del:
kobject_del(&p->kobj);
err_put:
@@ -1266,12 +1257,16 @@ err_put:
return ERR_PTR(ret);
}
-static void destroy_port(struct ib_port *port)
+static void destroy_port(struct ib_core_device *coredev, struct ib_port *port)
{
+ bool is_full_dev = &port->ibdev->coredev == coredev;
+
if (port->ibdev->port_data &&
port->ibdev->port_data[port->port_num].sysfs == port)
port->ibdev->port_data[port->port_num].sysfs = NULL;
list_del(&port->kobj.entry);
+ if (is_full_dev)
+ sysfs_remove_groups(&port->kobj, port->ibdev->ops.port_groups);
sysfs_remove_groups(&port->kobj, port->groups_list);
kobject_del(&port->kobj);
kobject_put(&port->kobj);
@@ -1397,7 +1392,7 @@ void ib_free_port_attrs(struct ib_core_device *coredev)
struct ib_port *port = container_of(p, struct ib_port, kobj);
destroy_gid_attrs(port);
- destroy_port(port);
+ destroy_port(coredev, port);
}
kobject_put(coredev->ports_kobj);
@@ -1406,7 +1401,6 @@ void ib_free_port_attrs(struct ib_core_device *coredev)
int ib_setup_port_attrs(struct ib_core_device *coredev)
{
struct ib_device *device = rdma_device_to_ibdev(&coredev->dev);
- bool is_full_dev = &device->coredev == coredev;
u32 port_num;
int ret;
@@ -1432,13 +1426,6 @@ int ib_setup_port_attrs(struct ib_core_device *coredev)
ret = setup_gid_attrs(port, &attr);
if (ret)
goto err_put;
-
- if (device->ops.init_port && is_full_dev) {
- ret = device->ops.init_port(device, port_num,
- &port->kobj);
- if (ret)
- goto err_put;
- }
}
return 0;