Commit d4be8ebe authored by Vijaya Mohan Guvva's avatar Vijaya Mohan Guvva Committed by David S. Miller

liquidio: Configure switchdev with devlink

Enable and disable switchdev on SRIOV capable LiquidIO NIC with devlink.
Create representor netdev for each SRIOV VF function on SRIOV enable and
and do the cleanup on SRIOV disable.
Signed-off-by: default avatarVijaya Mohan Guvva <vijaya.guvva@cavium.com>
Signed-off-by: default avatarSatanand Burla <satananda.burla@cavium.com>
Signed-off-by: default avatarRaghu Vatsavayi <raghu.vatsavayi@cavium.com>
Signed-off-by: default avatarFelix Manlunas <felix.manlunas@cavium.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1f233f32
...@@ -53,6 +53,7 @@ config THUNDER_NIC_RGX ...@@ -53,6 +53,7 @@ config THUNDER_NIC_RGX
config LIQUIDIO config LIQUIDIO
tristate "Cavium LiquidIO support" tristate "Cavium LiquidIO support"
depends on 64BIT depends on 64BIT
depends on MAY_USE_DEVLINK
imply PTP_1588_CLOCK imply PTP_1588_CLOCK
select FW_LOADER select FW_LOADER
select LIBCRC32C select LIBCRC32C
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "cn68xx_device.h" #include "cn68xx_device.h"
#include "cn23xx_pf_device.h" #include "cn23xx_pf_device.h"
#include "liquidio_image.h" #include "liquidio_image.h"
#include "lio_vf_rep.h"
MODULE_AUTHOR("Cavium Networks, <support@cavium.com>"); MODULE_AUTHOR("Cavium Networks, <support@cavium.com>");
MODULE_DESCRIPTION("Cavium LiquidIO Intelligent Server Adapter Driver"); MODULE_DESCRIPTION("Cavium LiquidIO Intelligent Server Adapter Driver");
...@@ -1603,6 +1604,8 @@ static int liquidio_stop_nic_module(struct octeon_device *oct) ...@@ -1603,6 +1604,8 @@ static int liquidio_stop_nic_module(struct octeon_device *oct)
oct->cmd_resp_state = OCT_DRV_OFFLINE; oct->cmd_resp_state = OCT_DRV_OFFLINE;
spin_unlock_bh(&oct->cmd_resp_wqlock); spin_unlock_bh(&oct->cmd_resp_wqlock);
lio_vf_rep_destroy(oct);
for (i = 0; i < oct->ifcount; i++) { for (i = 0; i < oct->ifcount; i++) {
lio = GET_LIO(oct->props[i].netdev); lio = GET_LIO(oct->props[i].netdev);
for (j = 0; j < oct->num_oqs; j++) for (j = 0; j < oct->num_oqs; j++)
...@@ -1613,6 +1616,12 @@ static int liquidio_stop_nic_module(struct octeon_device *oct) ...@@ -1613,6 +1616,12 @@ static int liquidio_stop_nic_module(struct octeon_device *oct)
for (i = 0; i < oct->ifcount; i++) for (i = 0; i < oct->ifcount; i++)
liquidio_destroy_nic_device(oct, i); liquidio_destroy_nic_device(oct, i);
if (oct->devlink) {
devlink_unregister(oct->devlink);
devlink_free(oct->devlink);
oct->devlink = NULL;
}
dev_dbg(&oct->pci_dev->dev, "Network interfaces stopped\n"); dev_dbg(&oct->pci_dev->dev, "Network interfaces stopped\n");
return 0; return 0;
} }
...@@ -3310,10 +3319,67 @@ static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx, ...@@ -3310,10 +3319,67 @@ static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx,
return 0; return 0;
} }
static int
liquidio_eswitch_mode_get(struct devlink *devlink, u16 *mode)
{
struct lio_devlink_priv *priv;
struct octeon_device *oct;
priv = devlink_priv(devlink);
oct = priv->oct;
*mode = oct->eswitch_mode;
return 0;
}
static int
liquidio_eswitch_mode_set(struct devlink *devlink, u16 mode)
{
struct lio_devlink_priv *priv;
struct octeon_device *oct;
int ret = 0;
priv = devlink_priv(devlink);
oct = priv->oct;
if (!(oct->fw_info.app_cap_flags & LIQUIDIO_SWITCHDEV_CAP))
return -EINVAL;
if (oct->eswitch_mode == mode)
return 0;
switch (mode) {
case DEVLINK_ESWITCH_MODE_SWITCHDEV:
oct->eswitch_mode = mode;
ret = lio_vf_rep_create(oct);
break;
case DEVLINK_ESWITCH_MODE_LEGACY:
lio_vf_rep_destroy(oct);
oct->eswitch_mode = mode;
break;
default:
ret = -EINVAL;
}
return ret;
}
static const struct devlink_ops liquidio_devlink_ops = {
.eswitch_mode_get = liquidio_eswitch_mode_get,
.eswitch_mode_set = liquidio_eswitch_mode_set,
};
static int static int
lio_pf_switchdev_attr_get(struct net_device *dev, struct switchdev_attr *attr) lio_pf_switchdev_attr_get(struct net_device *dev, struct switchdev_attr *attr)
{ {
struct lio *lio = GET_LIO(dev); struct lio *lio = GET_LIO(dev);
struct octeon_device *oct = lio->oct_dev;
if (oct->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
return -EOPNOTSUPP;
switch (attr->id) { switch (attr->id) {
case SWITCHDEV_ATTR_ID_PORT_PARENT_ID: case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
...@@ -3462,6 +3528,8 @@ static int setup_nic_devices(struct octeon_device *octeon_dev) ...@@ -3462,6 +3528,8 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
u32 resp_size, ctx_size, data_size; u32 resp_size, ctx_size, data_size;
u32 ifidx_or_pfnum; u32 ifidx_or_pfnum;
struct lio_version *vdata; struct lio_version *vdata;
struct devlink *devlink;
struct lio_devlink_priv *lio_devlink;
/* This is to handle link status changes */ /* This is to handle link status changes */
octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC, octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
...@@ -3794,6 +3862,26 @@ static int setup_nic_devices(struct octeon_device *octeon_dev) ...@@ -3794,6 +3862,26 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
octeon_free_soft_command(octeon_dev, sc); octeon_free_soft_command(octeon_dev, sc);
} }
devlink = devlink_alloc(&liquidio_devlink_ops,
sizeof(struct lio_devlink_priv));
if (!devlink) {
dev_err(&octeon_dev->pci_dev->dev, "devlink alloc failed\n");
goto setup_nic_wait_intr;
}
lio_devlink = devlink_priv(devlink);
lio_devlink->oct = octeon_dev;
if (devlink_register(devlink, &octeon_dev->pci_dev->dev)) {
devlink_free(devlink);
dev_err(&octeon_dev->pci_dev->dev,
"devlink registration failed\n");
goto setup_nic_wait_intr;
}
octeon_dev->devlink = devlink;
octeon_dev->eswitch_mode = DEVLINK_ESWITCH_MODE_LEGACY;
return 0; return 0;
setup_nic_dev_fail: setup_nic_dev_fail:
...@@ -3888,6 +3976,7 @@ static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs) ...@@ -3888,6 +3976,7 @@ static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs)
} }
if (!num_vfs) { if (!num_vfs) {
lio_vf_rep_destroy(oct);
ret = lio_pci_sriov_disable(oct); ret = lio_pci_sriov_disable(oct);
} else if (num_vfs > oct->sriov_info.max_vfs) { } else if (num_vfs > oct->sriov_info.max_vfs) {
dev_err(&oct->pci_dev->dev, dev_err(&oct->pci_dev->dev,
...@@ -3899,6 +3988,10 @@ static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs) ...@@ -3899,6 +3988,10 @@ static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs)
ret = octeon_enable_sriov(oct); ret = octeon_enable_sriov(oct);
dev_info(&oct->pci_dev->dev, "oct->pf_num:%d num_vfs:%d\n", dev_info(&oct->pci_dev->dev, "oct->pf_num:%d num_vfs:%d\n",
oct->pf_num, num_vfs); oct->pf_num, num_vfs);
ret = lio_vf_rep_create(oct);
if (ret)
dev_info(&oct->pci_dev->dev,
"vf representor create failed");
} }
return ret; return ret;
......
...@@ -515,6 +515,9 @@ lio_vf_rep_create(struct octeon_device *oct) ...@@ -515,6 +515,9 @@ lio_vf_rep_create(struct octeon_device *oct)
struct net_device *ndev; struct net_device *ndev;
int i, num_vfs; int i, num_vfs;
if (oct->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
return 0;
if (!oct->sriov_info.sriov_enabled) if (!oct->sriov_info.sriov_enabled)
return 0; return 0;
...@@ -599,6 +602,9 @@ lio_vf_rep_destroy(struct octeon_device *oct) ...@@ -599,6 +602,9 @@ lio_vf_rep_destroy(struct octeon_device *oct)
struct net_device *ndev; struct net_device *ndev;
int i; int i;
if (oct->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
return;
if (!oct->sriov_info.sriov_enabled) if (!oct->sriov_info.sriov_enabled)
return; return;
......
...@@ -114,6 +114,7 @@ enum octeon_tag_type { ...@@ -114,6 +114,7 @@ enum octeon_tag_type {
/* App specific capabilities from firmware to pf driver */ /* App specific capabilities from firmware to pf driver */
#define LIQUIDIO_TIME_SYNC_CAP 0x1 #define LIQUIDIO_TIME_SYNC_CAP 0x1
#define LIQUIDIO_SWITCHDEV_CAP 0x2
static inline u32 incr_index(u32 index, u32 count, u32 max) static inline u32 incr_index(u32 index, u32 count, u32 max)
{ {
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#define _OCTEON_DEVICE_H_ #define _OCTEON_DEVICE_H_
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <net/devlink.h>
/** PCI VendorId Device Id */ /** PCI VendorId Device Id */
#define OCTEON_CN68XX_PCIID 0x91177d #define OCTEON_CN68XX_PCIID 0x91177d
...@@ -396,6 +397,10 @@ struct lio_vf_rep_list { ...@@ -396,6 +397,10 @@ struct lio_vf_rep_list {
struct net_device *ndev[CN23XX_MAX_VFS_PER_PF]; struct net_device *ndev[CN23XX_MAX_VFS_PER_PF];
}; };
struct lio_devlink_priv {
struct octeon_device *oct;
};
/** The Octeon device. /** The Octeon device.
* Each Octeon device has this structure to represent all its * Each Octeon device has this structure to represent all its
* components. * components.
...@@ -575,6 +580,8 @@ struct octeon_device { ...@@ -575,6 +580,8 @@ struct octeon_device {
bool ptp_enable; bool ptp_enable;
struct lio_vf_rep_list vf_rep_list; struct lio_vf_rep_list vf_rep_list;
struct devlink *devlink;
enum devlink_eswitch_mode eswitch_mode;
}; };
#define OCT_DRV_ONLINE 1 #define OCT_DRV_ONLINE 1
......
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