netdevsim: move details of vf config to dev
Since "eswitch" configuration was added bus.c contains a lot of device details which really belong to dev.c. Restructure the code while moving it. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Родитель
5e388f3dc3
Коммит
1c401078bc
|
@ -8,7 +8,6 @@
|
|||
#include <linux/kernel.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/sysfs.h>
|
||||
|
||||
|
@ -24,50 +23,11 @@ static struct nsim_bus_dev *to_nsim_bus_dev(struct device *dev)
|
|||
return container_of(dev, struct nsim_bus_dev, dev);
|
||||
}
|
||||
|
||||
static void
|
||||
nsim_bus_dev_set_vfs(struct nsim_bus_dev *nsim_bus_dev, unsigned int num_vfs)
|
||||
{
|
||||
rtnl_lock();
|
||||
nsim_bus_dev->num_vfs = num_vfs;
|
||||
rtnl_unlock();
|
||||
}
|
||||
|
||||
static int nsim_bus_dev_vfs_enable(struct nsim_bus_dev *nsim_bus_dev,
|
||||
unsigned int num_vfs)
|
||||
{
|
||||
struct nsim_dev *nsim_dev;
|
||||
int err = 0;
|
||||
|
||||
if (nsim_bus_dev->max_vfs < num_vfs)
|
||||
return -ENOMEM;
|
||||
nsim_bus_dev_set_vfs(nsim_bus_dev, num_vfs);
|
||||
|
||||
nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev);
|
||||
if (nsim_esw_mode_is_switchdev(nsim_dev)) {
|
||||
err = nsim_esw_switchdev_enable(nsim_dev, NULL);
|
||||
if (err)
|
||||
nsim_bus_dev_set_vfs(nsim_bus_dev, 0);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void nsim_bus_dev_vfs_disable(struct nsim_bus_dev *nsim_bus_dev)
|
||||
{
|
||||
struct nsim_dev *nsim_dev;
|
||||
|
||||
nsim_bus_dev_set_vfs(nsim_bus_dev, 0);
|
||||
nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev);
|
||||
if (nsim_esw_mode_is_switchdev(nsim_dev))
|
||||
nsim_esw_legacy_enable(nsim_dev, NULL);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
nsim_bus_dev_numvfs_store(struct device *dev, struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct nsim_bus_dev *nsim_bus_dev = to_nsim_bus_dev(dev);
|
||||
struct nsim_dev *nsim_dev = dev_get_drvdata(dev);
|
||||
unsigned int num_vfs;
|
||||
int ret;
|
||||
|
||||
|
@ -76,33 +36,12 @@ nsim_bus_dev_numvfs_store(struct device *dev, struct device_attribute *attr,
|
|||
return ret;
|
||||
|
||||
device_lock(dev);
|
||||
if (!nsim_dev) {
|
||||
ret = -ENOENT;
|
||||
goto exit_unlock;
|
||||
}
|
||||
|
||||
mutex_lock(&nsim_dev->vfs_lock);
|
||||
if (nsim_bus_dev->num_vfs == num_vfs)
|
||||
goto exit_good;
|
||||
if (nsim_bus_dev->num_vfs && num_vfs) {
|
||||
ret = -EBUSY;
|
||||
goto exit_unlock;
|
||||
}
|
||||
|
||||
if (num_vfs) {
|
||||
ret = nsim_bus_dev_vfs_enable(nsim_bus_dev, num_vfs);
|
||||
if (ret)
|
||||
goto exit_unlock;
|
||||
} else {
|
||||
nsim_bus_dev_vfs_disable(nsim_bus_dev);
|
||||
}
|
||||
exit_good:
|
||||
ret = count;
|
||||
exit_unlock:
|
||||
mutex_unlock(&nsim_dev->vfs_lock);
|
||||
ret = -ENOENT;
|
||||
if (dev_get_drvdata(dev))
|
||||
ret = nsim_drv_configure_vfs(nsim_bus_dev, num_vfs);
|
||||
device_unlock(dev);
|
||||
|
||||
return ret;
|
||||
return ret ? ret : count;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
|
|
|
@ -64,6 +64,14 @@ unsigned int nsim_dev_get_vfs(struct nsim_dev *nsim_dev)
|
|||
return nsim_dev->nsim_bus_dev->num_vfs;
|
||||
}
|
||||
|
||||
static void
|
||||
nsim_bus_dev_set_vfs(struct nsim_bus_dev *nsim_bus_dev, unsigned int num_vfs)
|
||||
{
|
||||
rtnl_lock();
|
||||
nsim_bus_dev->num_vfs = num_vfs;
|
||||
rtnl_unlock();
|
||||
}
|
||||
|
||||
#define NSIM_DEV_DUMMY_REGION_SIZE (1024 * 32)
|
||||
|
||||
static int
|
||||
|
@ -496,7 +504,9 @@ static void nsim_dev_dummy_region_exit(struct nsim_dev *nsim_dev)
|
|||
}
|
||||
|
||||
static void __nsim_dev_port_del(struct nsim_dev_port *nsim_dev_port);
|
||||
int nsim_esw_legacy_enable(struct nsim_dev *nsim_dev, struct netlink_ext_ack *extack)
|
||||
|
||||
static int nsim_esw_legacy_enable(struct nsim_dev *nsim_dev,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct devlink *devlink = priv_to_devlink(nsim_dev);
|
||||
struct nsim_dev_port *nsim_dev_port, *tmp;
|
||||
|
@ -511,7 +521,8 @@ int nsim_esw_legacy_enable(struct nsim_dev *nsim_dev, struct netlink_ext_ack *ex
|
|||
return 0;
|
||||
}
|
||||
|
||||
int nsim_esw_switchdev_enable(struct nsim_dev *nsim_dev, struct netlink_ext_ack *extack)
|
||||
static int nsim_esw_switchdev_enable(struct nsim_dev *nsim_dev,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct nsim_bus_dev *nsim_bus_dev = nsim_dev->nsim_bus_dev;
|
||||
int i, err;
|
||||
|
@ -1565,8 +1576,11 @@ static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev)
|
|||
debugfs_remove(nsim_dev->take_snapshot);
|
||||
|
||||
mutex_lock(&nsim_dev->vfs_lock);
|
||||
if (nsim_dev_get_vfs(nsim_dev))
|
||||
nsim_bus_dev_vfs_disable(nsim_dev->nsim_bus_dev);
|
||||
if (nsim_dev_get_vfs(nsim_dev)) {
|
||||
nsim_bus_dev_set_vfs(nsim_dev->nsim_bus_dev, 0);
|
||||
if (nsim_esw_mode_is_switchdev(nsim_dev))
|
||||
nsim_esw_legacy_enable(nsim_dev, NULL);
|
||||
}
|
||||
mutex_unlock(&nsim_dev->vfs_lock);
|
||||
|
||||
nsim_dev_port_del_all(nsim_dev);
|
||||
|
@ -1641,6 +1655,45 @@ int nsim_dev_port_del(struct nsim_bus_dev *nsim_bus_dev, enum nsim_dev_port_type
|
|||
return err;
|
||||
}
|
||||
|
||||
int nsim_drv_configure_vfs(struct nsim_bus_dev *nsim_bus_dev,
|
||||
unsigned int num_vfs)
|
||||
{
|
||||
struct nsim_dev *nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev);
|
||||
int ret;
|
||||
|
||||
mutex_lock(&nsim_dev->vfs_lock);
|
||||
if (nsim_bus_dev->num_vfs == num_vfs) {
|
||||
ret = 0;
|
||||
goto exit_unlock;
|
||||
}
|
||||
if (nsim_bus_dev->num_vfs && num_vfs) {
|
||||
ret = -EBUSY;
|
||||
goto exit_unlock;
|
||||
}
|
||||
if (nsim_bus_dev->max_vfs < num_vfs) {
|
||||
ret = -ENOMEM;
|
||||
goto exit_unlock;
|
||||
}
|
||||
|
||||
nsim_bus_dev_set_vfs(nsim_bus_dev, num_vfs);
|
||||
if (nsim_esw_mode_is_switchdev(nsim_dev)) {
|
||||
if (num_vfs) {
|
||||
ret = nsim_esw_switchdev_enable(nsim_dev, NULL);
|
||||
if (ret) {
|
||||
nsim_bus_dev_set_vfs(nsim_bus_dev, 0);
|
||||
goto exit_unlock;
|
||||
}
|
||||
} else {
|
||||
nsim_esw_legacy_enable(nsim_dev, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
exit_unlock:
|
||||
mutex_unlock(&nsim_dev->vfs_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int nsim_dev_init(void)
|
||||
{
|
||||
nsim_dev_ddir = debugfs_create_dir(DRV_NAME, NULL);
|
||||
|
|
|
@ -281,9 +281,6 @@ struct nsim_dev {
|
|||
u16 esw_mode;
|
||||
};
|
||||
|
||||
int nsim_esw_legacy_enable(struct nsim_dev *nsim_dev, struct netlink_ext_ack *extack);
|
||||
int nsim_esw_switchdev_enable(struct nsim_dev *nsim_dev, struct netlink_ext_ack *extack);
|
||||
|
||||
static inline bool nsim_esw_mode_is_legacy(struct nsim_dev *nsim_dev)
|
||||
{
|
||||
return nsim_dev->esw_mode == DEVLINK_ESWITCH_MODE_LEGACY;
|
||||
|
@ -309,6 +306,8 @@ int nsim_dev_port_add(struct nsim_bus_dev *nsim_bus_dev,
|
|||
int nsim_dev_port_del(struct nsim_bus_dev *nsim_bus_dev,
|
||||
enum nsim_dev_port_type type,
|
||||
unsigned int port_index);
|
||||
int nsim_drv_configure_vfs(struct nsim_bus_dev *nsim_bus_dev,
|
||||
unsigned int num_vfs);
|
||||
|
||||
unsigned int nsim_dev_get_vfs(struct nsim_dev *nsim_dev);
|
||||
|
||||
|
@ -324,7 +323,6 @@ ssize_t nsim_bus_dev_max_vfs_read(struct file *file,
|
|||
ssize_t nsim_bus_dev_max_vfs_write(struct file *file,
|
||||
const char __user *data,
|
||||
size_t count, loff_t *ppos);
|
||||
void nsim_bus_dev_vfs_disable(struct nsim_bus_dev *nsim_bus_dev);
|
||||
|
||||
static inline bool nsim_dev_port_is_pf(struct nsim_dev_port *nsim_dev_port)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче