]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
netdevsim: rename devlink.c to dev.c to contain per-dev(asic) items
authorJiri Pirko <jiri@mellanox.com>
Thu, 25 Apr 2019 13:59:43 +0000 (15:59 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 26 Apr 2019 05:52:02 +0000 (01:52 -0400)
The existing devlink.c code is going to be extended to represent asic
device on a bus. As this is about more than just devlink,
rename the file. Do appropriate prefix renaming alongside with that.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/netdevsim/Makefile
drivers/net/netdevsim/dev.c [new file with mode: 0644]
drivers/net/netdevsim/devlink.c [deleted file]
drivers/net/netdevsim/netdev.c
drivers/net/netdevsim/netdevsim.h

index cdf8611d28119ef176522c10add9588b8a0d642e..a72dec8e179c5ab6073abeda3980774ecdc0dc81 100644 (file)
@@ -3,7 +3,7 @@
 obj-$(CONFIG_NETDEVSIM) += netdevsim.o
 
 netdevsim-objs := \
-       netdev.o devlink.o fib.o sdev.o \
+       netdev.o dev.o fib.o sdev.o
 
 ifeq ($(CONFIG_BPF_SYSCALL),y)
 netdevsim-objs += \
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
new file mode 100644 (file)
index 0000000..c87f0ab
--- /dev/null
@@ -0,0 +1,241 @@
+/*
+ * Copyright (c) 2018 Cumulus Networks. All rights reserved.
+ * Copyright (c) 2018 David Ahern <dsa@cumulusnetworks.com>
+ * Copyright (c) 2019 Mellanox Technologies. All rights reserved.
+ *
+ * This software is licensed under the GNU General License Version 2,
+ * June 1991 as shown in the file COPYING in the top-level directory of this
+ * source tree.
+ *
+ * THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS"
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE
+ * OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
+ * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+ */
+
+#include <linux/device.h>
+#include <linux/rtnetlink.h>
+#include <net/devlink.h>
+
+#include "netdevsim.h"
+
+struct nsim_dev {
+       struct nsim_fib_data *fib_data;
+};
+
+static u64 nsim_dev_ipv4_fib_resource_occ_get(void *priv)
+{
+       struct nsim_dev *nsim_dev = priv;
+
+       return nsim_fib_get_val(nsim_dev->fib_data,
+                               NSIM_RESOURCE_IPV4_FIB, false);
+}
+
+static u64 nsim_dev_ipv4_fib_rules_res_occ_get(void *priv)
+{
+       struct nsim_dev *nsim_dev = priv;
+
+       return nsim_fib_get_val(nsim_dev->fib_data,
+                               NSIM_RESOURCE_IPV4_FIB_RULES, false);
+}
+
+static u64 nsim_dev_ipv6_fib_resource_occ_get(void *priv)
+{
+       struct nsim_dev *nsim_dev = priv;
+
+       return nsim_fib_get_val(nsim_dev->fib_data,
+                               NSIM_RESOURCE_IPV6_FIB, false);
+}
+
+static u64 nsim_dev_ipv6_fib_rules_res_occ_get(void *priv)
+{
+       struct nsim_dev *nsim_dev = priv;
+
+       return nsim_fib_get_val(nsim_dev->fib_data,
+                               NSIM_RESOURCE_IPV6_FIB_RULES, false);
+}
+
+static int nsim_dev_resources_register(struct devlink *devlink)
+{
+       struct nsim_dev *nsim_dev = devlink_priv(devlink);
+       struct devlink_resource_size_params params = {
+               .size_max = (u64)-1,
+               .size_granularity = 1,
+               .unit = DEVLINK_RESOURCE_UNIT_ENTRY
+       };
+       int err;
+       u64 n;
+
+       /* Resources for IPv4 */
+       err = devlink_resource_register(devlink, "IPv4", (u64)-1,
+                                       NSIM_RESOURCE_IPV4,
+                                       DEVLINK_RESOURCE_ID_PARENT_TOP,
+                                       &params);
+       if (err) {
+               pr_err("Failed to register IPv4 top resource\n");
+               goto out;
+       }
+
+       n = nsim_fib_get_val(nsim_dev->fib_data,
+                            NSIM_RESOURCE_IPV4_FIB, true);
+       err = devlink_resource_register(devlink, "fib", n,
+                                       NSIM_RESOURCE_IPV4_FIB,
+                                       NSIM_RESOURCE_IPV4, &params);
+       if (err) {
+               pr_err("Failed to register IPv4 FIB resource\n");
+               return err;
+       }
+
+       n = nsim_fib_get_val(nsim_dev->fib_data,
+                            NSIM_RESOURCE_IPV4_FIB_RULES, true);
+       err = devlink_resource_register(devlink, "fib-rules", n,
+                                       NSIM_RESOURCE_IPV4_FIB_RULES,
+                                       NSIM_RESOURCE_IPV4, &params);
+       if (err) {
+               pr_err("Failed to register IPv4 FIB rules resource\n");
+               return err;
+       }
+
+       /* Resources for IPv6 */
+       err = devlink_resource_register(devlink, "IPv6", (u64)-1,
+                                       NSIM_RESOURCE_IPV6,
+                                       DEVLINK_RESOURCE_ID_PARENT_TOP,
+                                       &params);
+       if (err) {
+               pr_err("Failed to register IPv6 top resource\n");
+               goto out;
+       }
+
+       n = nsim_fib_get_val(nsim_dev->fib_data,
+                            NSIM_RESOURCE_IPV6_FIB, true);
+       err = devlink_resource_register(devlink, "fib", n,
+                                       NSIM_RESOURCE_IPV6_FIB,
+                                       NSIM_RESOURCE_IPV6, &params);
+       if (err) {
+               pr_err("Failed to register IPv6 FIB resource\n");
+               return err;
+       }
+
+       n = nsim_fib_get_val(nsim_dev->fib_data,
+                            NSIM_RESOURCE_IPV6_FIB_RULES, true);
+       err = devlink_resource_register(devlink, "fib-rules", n,
+                                       NSIM_RESOURCE_IPV6_FIB_RULES,
+                                       NSIM_RESOURCE_IPV6, &params);
+       if (err) {
+               pr_err("Failed to register IPv6 FIB rules resource\n");
+               return err;
+       }
+
+       devlink_resource_occ_get_register(devlink,
+                                         NSIM_RESOURCE_IPV4_FIB,
+                                         nsim_dev_ipv4_fib_resource_occ_get,
+                                         nsim_dev);
+       devlink_resource_occ_get_register(devlink,
+                                         NSIM_RESOURCE_IPV4_FIB_RULES,
+                                         nsim_dev_ipv4_fib_rules_res_occ_get,
+                                         nsim_dev);
+       devlink_resource_occ_get_register(devlink,
+                                         NSIM_RESOURCE_IPV6_FIB,
+                                         nsim_dev_ipv6_fib_resource_occ_get,
+                                         nsim_dev);
+       devlink_resource_occ_get_register(devlink,
+                                         NSIM_RESOURCE_IPV6_FIB_RULES,
+                                         nsim_dev_ipv6_fib_rules_res_occ_get,
+                                         nsim_dev);
+out:
+       return err;
+}
+
+static int nsim_dev_reload(struct devlink *devlink,
+                          struct netlink_ext_ack *extack)
+{
+       struct nsim_dev *nsim_dev = devlink_priv(devlink);
+       enum nsim_resource_id res_ids[] = {
+               NSIM_RESOURCE_IPV4_FIB, NSIM_RESOURCE_IPV4_FIB_RULES,
+               NSIM_RESOURCE_IPV6_FIB, NSIM_RESOURCE_IPV6_FIB_RULES
+       };
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(res_ids); ++i) {
+               int err;
+               u64 val;
+
+               err = devlink_resource_size_get(devlink, res_ids[i], &val);
+               if (!err) {
+                       err = nsim_fib_set_max(nsim_dev->fib_data,
+                                              res_ids[i], val, extack);
+                       if (err)
+                               return err;
+               }
+       }
+
+       return 0;
+}
+
+static const struct devlink_ops nsim_dev_devlink_ops = {
+       .reload = nsim_dev_reload,
+};
+
+static int __nsim_dev_init(struct netdevsim *ns)
+{
+       struct nsim_dev *nsim_dev;
+       struct devlink *devlink;
+       int err;
+
+       devlink = devlink_alloc(&nsim_dev_devlink_ops, sizeof(*nsim_dev));
+       if (!devlink)
+               return -ENOMEM;
+       nsim_dev = devlink_priv(devlink);
+
+       nsim_dev->fib_data = nsim_fib_create();
+       if (IS_ERR(nsim_dev->fib_data)) {
+               err = PTR_ERR(nsim_dev->fib_data);
+               goto err_devlink_free;
+       }
+
+       err = nsim_dev_resources_register(devlink);
+       if (err)
+               goto err_fib_destroy;
+
+       err = devlink_register(devlink, &ns->dev);
+       if (err)
+               goto err_resources_unregister;
+
+       ns->devlink = devlink;
+
+       return 0;
+
+err_resources_unregister:
+       devlink_resources_unregister(devlink, NULL);
+err_fib_destroy:
+       nsim_fib_destroy(nsim_dev->fib_data);
+err_devlink_free:
+       devlink_free(devlink);
+
+       return err;
+}
+
+int nsim_dev_init(struct netdevsim *ns)
+{
+       int err;
+
+       dev_hold(ns->netdev);
+       rtnl_unlock();
+       err = __nsim_dev_init(ns);
+       rtnl_lock();
+       dev_put(ns->netdev);
+       return err;
+}
+
+void nsim_dev_exit(struct netdevsim *ns)
+{
+       struct devlink *devlink = ns->devlink;
+       struct nsim_dev *nsim_dev = devlink_priv(devlink);
+
+       devlink_unregister(devlink);
+       devlink_resources_unregister(devlink, NULL);
+       nsim_fib_destroy(nsim_dev->fib_data);
+       devlink_free(devlink);
+}
diff --git a/drivers/net/netdevsim/devlink.c b/drivers/net/netdevsim/devlink.c
deleted file mode 100644 (file)
index f718912..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright (c) 2018 Cumulus Networks. All rights reserved.
- * Copyright (c) 2018 David Ahern <dsa@cumulusnetworks.com>
- *
- * This software is licensed under the GNU General License Version 2,
- * June 1991 as shown in the file COPYING in the top-level directory of this
- * source tree.
- *
- * THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS"
- * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
- * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE
- * OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
- * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
- */
-
-#include <linux/device.h>
-#include <linux/rtnetlink.h>
-#include <net/devlink.h>
-
-#include "netdevsim.h"
-
-struct nsim_devlink {
-       struct nsim_fib_data *fib_data;
-};
-
-/* IPv4
- */
-static u64 nsim_ipv4_fib_resource_occ_get(void *priv)
-{
-       struct nsim_devlink *nsim_devlink = priv;
-
-       return nsim_fib_get_val(nsim_devlink->fib_data,
-                               NSIM_RESOURCE_IPV4_FIB, false);
-}
-
-static u64 nsim_ipv4_fib_rules_res_occ_get(void *priv)
-{
-       struct nsim_devlink *nsim_devlink = priv;
-
-       return nsim_fib_get_val(nsim_devlink->fib_data,
-                               NSIM_RESOURCE_IPV4_FIB_RULES, false);
-}
-
-/* IPv6
- */
-static u64 nsim_ipv6_fib_resource_occ_get(void *priv)
-{
-       struct nsim_devlink *nsim_devlink = priv;
-
-       return nsim_fib_get_val(nsim_devlink->fib_data,
-                               NSIM_RESOURCE_IPV6_FIB, false);
-}
-
-static u64 nsim_ipv6_fib_rules_res_occ_get(void *priv)
-{
-       struct nsim_devlink *nsim_devlink = priv;
-
-       return nsim_fib_get_val(nsim_devlink->fib_data,
-                               NSIM_RESOURCE_IPV6_FIB_RULES, false);
-}
-
-static int devlink_resources_register(struct devlink *devlink)
-{
-       struct nsim_devlink *nsim_devlink = devlink_priv(devlink);
-       struct devlink_resource_size_params params = {
-               .size_max = (u64)-1,
-               .size_granularity = 1,
-               .unit = DEVLINK_RESOURCE_UNIT_ENTRY
-       };
-       int err;
-       u64 n;
-
-       /* Resources for IPv4 */
-       err = devlink_resource_register(devlink, "IPv4", (u64)-1,
-                                       NSIM_RESOURCE_IPV4,
-                                       DEVLINK_RESOURCE_ID_PARENT_TOP,
-                                       &params);
-       if (err) {
-               pr_err("Failed to register IPv4 top resource\n");
-               goto out;
-       }
-
-       n = nsim_fib_get_val(nsim_devlink->fib_data,
-                            NSIM_RESOURCE_IPV4_FIB, true);
-       err = devlink_resource_register(devlink, "fib", n,
-                                       NSIM_RESOURCE_IPV4_FIB,
-                                       NSIM_RESOURCE_IPV4, &params);
-       if (err) {
-               pr_err("Failed to register IPv4 FIB resource\n");
-               return err;
-       }
-
-       n = nsim_fib_get_val(nsim_devlink->fib_data,
-                            NSIM_RESOURCE_IPV4_FIB_RULES, true);
-       err = devlink_resource_register(devlink, "fib-rules", n,
-                                       NSIM_RESOURCE_IPV4_FIB_RULES,
-                                       NSIM_RESOURCE_IPV4, &params);
-       if (err) {
-               pr_err("Failed to register IPv4 FIB rules resource\n");
-               return err;
-       }
-
-       /* Resources for IPv6 */
-       err = devlink_resource_register(devlink, "IPv6", (u64)-1,
-                                       NSIM_RESOURCE_IPV6,
-                                       DEVLINK_RESOURCE_ID_PARENT_TOP,
-                                       &params);
-       if (err) {
-               pr_err("Failed to register IPv6 top resource\n");
-               goto out;
-       }
-
-       n = nsim_fib_get_val(nsim_devlink->fib_data,
-                            NSIM_RESOURCE_IPV6_FIB, true);
-       err = devlink_resource_register(devlink, "fib", n,
-                                       NSIM_RESOURCE_IPV6_FIB,
-                                       NSIM_RESOURCE_IPV6, &params);
-       if (err) {
-               pr_err("Failed to register IPv6 FIB resource\n");
-               return err;
-       }
-
-       n = nsim_fib_get_val(nsim_devlink->fib_data,
-                            NSIM_RESOURCE_IPV6_FIB_RULES, true);
-       err = devlink_resource_register(devlink, "fib-rules", n,
-                                       NSIM_RESOURCE_IPV6_FIB_RULES,
-                                       NSIM_RESOURCE_IPV6, &params);
-       if (err) {
-               pr_err("Failed to register IPv6 FIB rules resource\n");
-               return err;
-       }
-
-       devlink_resource_occ_get_register(devlink,
-                                         NSIM_RESOURCE_IPV4_FIB,
-                                         nsim_ipv4_fib_resource_occ_get,
-                                         nsim_devlink);
-       devlink_resource_occ_get_register(devlink,
-                                         NSIM_RESOURCE_IPV4_FIB_RULES,
-                                         nsim_ipv4_fib_rules_res_occ_get,
-                                         nsim_devlink);
-       devlink_resource_occ_get_register(devlink,
-                                         NSIM_RESOURCE_IPV6_FIB,
-                                         nsim_ipv6_fib_resource_occ_get,
-                                         nsim_devlink);
-       devlink_resource_occ_get_register(devlink,
-                                         NSIM_RESOURCE_IPV6_FIB_RULES,
-                                         nsim_ipv6_fib_rules_res_occ_get,
-                                         nsim_devlink);
-out:
-       return err;
-}
-
-static int nsim_devlink_reload(struct devlink *devlink,
-                              struct netlink_ext_ack *extack)
-{
-       struct nsim_devlink *nsim_devlink = devlink_priv(devlink);
-       enum nsim_resource_id res_ids[] = {
-               NSIM_RESOURCE_IPV4_FIB, NSIM_RESOURCE_IPV4_FIB_RULES,
-               NSIM_RESOURCE_IPV6_FIB, NSIM_RESOURCE_IPV6_FIB_RULES
-       };
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(res_ids); ++i) {
-               int err;
-               u64 val;
-
-               err = devlink_resource_size_get(devlink, res_ids[i], &val);
-               if (!err) {
-                       err = nsim_fib_set_max(nsim_devlink->fib_data,
-                                              res_ids[i], val, extack);
-                       if (err)
-                               return err;
-               }
-       }
-
-       return 0;
-}
-
-static const struct devlink_ops nsim_devlink_ops = {
-       .reload = nsim_devlink_reload,
-};
-
-static int __nsim_devlink_init(struct netdevsim *ns)
-{
-       struct nsim_devlink *nsim_devlink;
-       struct devlink *devlink;
-       int err;
-
-       devlink = devlink_alloc(&nsim_devlink_ops, sizeof(*nsim_devlink));
-       if (!devlink)
-               return -ENOMEM;
-       nsim_devlink = devlink_priv(devlink);
-
-       nsim_devlink->fib_data = nsim_fib_create();
-       if (IS_ERR(nsim_devlink->fib_data)) {
-               err = PTR_ERR(nsim_devlink->fib_data);
-               goto err_devlink_free;
-       }
-
-       err = devlink_resources_register(devlink);
-       if (err)
-               goto err_fib_destroy;
-
-       err = devlink_register(devlink, &ns->dev);
-       if (err)
-               goto err_resources_unregister;
-
-       ns->devlink = devlink;
-
-       return 0;
-
-err_resources_unregister:
-       devlink_resources_unregister(devlink, NULL);
-err_fib_destroy:
-       nsim_fib_destroy(nsim_devlink->fib_data);
-err_devlink_free:
-       devlink_free(devlink);
-
-       return err;
-}
-
-int nsim_devlink_init(struct netdevsim *ns)
-{
-       int err;
-
-       dev_hold(ns->netdev);
-       rtnl_unlock();
-       err = __nsim_devlink_init(ns);
-       rtnl_lock();
-       dev_put(ns->netdev);
-       return err;
-}
-
-void nsim_devlink_exit(struct netdevsim *ns)
-{
-       struct devlink *devlink = ns->devlink;
-       struct nsim_devlink *nsim_devlink = devlink_priv(devlink);
-
-       devlink_unregister(devlink);
-       devlink_resources_unregister(devlink, NULL);
-       nsim_fib_destroy(nsim_devlink->fib_data);
-       devlink_free(devlink);
-}
index 04aa084dc34c28c167fb29f99d3e8cf370067be2..31fc6564d18136c4e681a548f5b5b52c03b3865b 100644 (file)
@@ -195,7 +195,7 @@ static void nsim_free(struct net_device *dev)
 {
        struct netdevsim *ns = netdev_priv(dev);
 
-       nsim_devlink_exit(ns);
+       nsim_dev_exit(ns);
        device_unregister(&ns->dev);
        /* netdev and vf state will be freed out of device_release() */
        nsim_sdev_put(ns->sdev);
@@ -506,17 +506,17 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev,
        SET_NETDEV_DEV(dev, &ns->dev);
        ns->netdev = dev;
 
-       err = nsim_devlink_init(ns);
+       err = nsim_dev_init(ns);
        if (err)
                goto err_unreg_dev;
 
        err = register_netdevice(dev);
        if (err)
-               goto err_devlink_exit;
+               goto err_dev_exit;
        return 0;
 
-err_devlink_exit:
-       nsim_devlink_exit(ns);
+err_dev_exit:
+       nsim_dev_exit(ns);
 err_unreg_dev:
        device_unregister(&ns->dev);
 err_sdev_put:
index df50eb19715d127f26eff475c335e5e5b71ad783..23d19b4618733fda60418499b2d72cff410caa29 100644 (file)
@@ -154,8 +154,8 @@ enum nsim_resource_id {
        NSIM_RESOURCE_IPV6_FIB_RULES,
 };
 
-int nsim_devlink_init(struct netdevsim *ns);
-void nsim_devlink_exit(struct netdevsim *ns);
+int nsim_dev_init(struct netdevsim *ns);
+void nsim_dev_exit(struct netdevsim *ns);
 
 struct nsim_fib_data *nsim_fib_create(void);
 void nsim_fib_destroy(struct nsim_fib_data *fib_data);