Commit 34dd1710 authored by Vadym Kochan's avatar Vadym Kochan Committed by David S. Miller

net: marvell: prestera: Add basic devlink support

Add very basic support for devlink interface:

    - driver name
    - fw version
    - devlink ports
Signed-off-by: default avatarVadym Kochan <vadym.kochan@plvision.eu>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4c2703df
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
config PRESTERA config PRESTERA
tristate "Marvell Prestera Switch ASICs support" tristate "Marvell Prestera Switch ASICs support"
depends on NET_SWITCHDEV && VLAN_8021Q depends on NET_SWITCHDEV && VLAN_8021Q
select NET_DEVLINK
help help
This driver supports Marvell Prestera Switch ASICs family. This driver supports Marvell Prestera Switch ASICs family.
......
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_PRESTERA) += prestera.o obj-$(CONFIG_PRESTERA) += prestera.o
prestera-objs := prestera_main.o prestera_hw.o prestera_dsa.o \ prestera-objs := prestera_main.o prestera_hw.o prestera_dsa.o \
prestera_rxtx.o prestera_rxtx.o prestera_devlink.o
obj-$(CONFIG_PRESTERA_PCI) += prestera_pci.o obj-$(CONFIG_PRESTERA_PCI) += prestera_pci.o
...@@ -7,8 +7,11 @@ ...@@ -7,8 +7,11 @@
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <net/devlink.h>
#include <uapi/linux/if_ether.h> #include <uapi/linux/if_ether.h>
#define PRESTERA_DRV_NAME "prestera"
struct prestera_fw_rev { struct prestera_fw_rev {
u16 maj; u16 maj;
u16 min; u16 min;
...@@ -58,6 +61,7 @@ struct prestera_port_caps { ...@@ -58,6 +61,7 @@ struct prestera_port_caps {
struct prestera_port { struct prestera_port {
struct net_device *dev; struct net_device *dev;
struct prestera_switch *sw; struct prestera_switch *sw;
struct devlink_port dl_port;
u32 id; u32 id;
u32 hw_id; u32 hw_id;
u32 dev_id; u32 dev_id;
......
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved */
#include <net/devlink.h>
#include "prestera_devlink.h"
static int prestera_dl_info_get(struct devlink *dl,
struct devlink_info_req *req,
struct netlink_ext_ack *extack)
{
struct prestera_switch *sw = devlink_priv(dl);
char buf[16];
int err;
err = devlink_info_driver_name_put(req, PRESTERA_DRV_NAME);
if (err)
return err;
snprintf(buf, sizeof(buf), "%d.%d.%d",
sw->dev->fw_rev.maj,
sw->dev->fw_rev.min,
sw->dev->fw_rev.sub);
return devlink_info_version_running_put(req,
DEVLINK_INFO_VERSION_GENERIC_FW,
buf);
}
static const struct devlink_ops prestera_dl_ops = {
.info_get = prestera_dl_info_get,
};
struct prestera_switch *prestera_devlink_alloc(void)
{
struct devlink *dl;
dl = devlink_alloc(&prestera_dl_ops, sizeof(struct prestera_switch));
return devlink_priv(dl);
}
void prestera_devlink_free(struct prestera_switch *sw)
{
struct devlink *dl = priv_to_devlink(sw);
devlink_free(dl);
}
int prestera_devlink_register(struct prestera_switch *sw)
{
struct devlink *dl = priv_to_devlink(sw);
int err;
err = devlink_register(dl, sw->dev->dev);
if (err)
dev_err(prestera_dev(sw), "devlink_register failed: %d\n", err);
return err;
}
void prestera_devlink_unregister(struct prestera_switch *sw)
{
struct devlink *dl = priv_to_devlink(sw);
devlink_unregister(dl);
}
int prestera_devlink_port_register(struct prestera_port *port)
{
struct prestera_switch *sw = port->sw;
struct devlink *dl = priv_to_devlink(sw);
struct devlink_port_attrs attrs = {};
int err;
attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
attrs.phys.port_number = port->fp_id;
attrs.switch_id.id_len = sizeof(sw->id);
memcpy(attrs.switch_id.id, &sw->id, attrs.switch_id.id_len);
devlink_port_attrs_set(&port->dl_port, &attrs);
err = devlink_port_register(dl, &port->dl_port, port->fp_id);
if (err) {
dev_err(prestera_dev(sw), "devlink_port_register failed: %d\n", err);
return err;
}
return 0;
}
void prestera_devlink_port_unregister(struct prestera_port *port)
{
devlink_port_unregister(&port->dl_port);
}
void prestera_devlink_port_set(struct prestera_port *port)
{
devlink_port_type_eth_set(&port->dl_port, port->dev);
}
void prestera_devlink_port_clear(struct prestera_port *port)
{
devlink_port_type_clear(&port->dl_port);
}
struct devlink_port *prestera_devlink_get_port(struct net_device *dev)
{
struct prestera_port *port = netdev_priv(dev);
return &port->dl_port;
}
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved. */
#ifndef _PRESTERA_DEVLINK_H_
#define _PRESTERA_DEVLINK_H_
#include "prestera.h"
struct prestera_switch *prestera_devlink_alloc(void);
void prestera_devlink_free(struct prestera_switch *sw);
int prestera_devlink_register(struct prestera_switch *sw);
void prestera_devlink_unregister(struct prestera_switch *sw);
int prestera_devlink_port_register(struct prestera_port *port);
void prestera_devlink_port_unregister(struct prestera_port *port);
void prestera_devlink_port_set(struct prestera_port *port);
void prestera_devlink_port_clear(struct prestera_port *port);
struct devlink_port *prestera_devlink_get_port(struct net_device *dev);
#endif /* _PRESTERA_DEVLINK_H_ */
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "prestera.h" #include "prestera.h"
#include "prestera_hw.h" #include "prestera_hw.h"
#include "prestera_rxtx.h" #include "prestera_rxtx.h"
#include "prestera_devlink.h"
#define PRESTERA_MTU_DEFAULT 1536 #define PRESTERA_MTU_DEFAULT 1536
...@@ -186,6 +187,7 @@ static const struct net_device_ops prestera_netdev_ops = { ...@@ -186,6 +187,7 @@ static const struct net_device_ops prestera_netdev_ops = {
.ndo_change_mtu = prestera_port_change_mtu, .ndo_change_mtu = prestera_port_change_mtu,
.ndo_get_stats64 = prestera_port_get_stats64, .ndo_get_stats64 = prestera_port_get_stats64,
.ndo_set_mac_address = prestera_port_set_mac_address, .ndo_set_mac_address = prestera_port_set_mac_address,
.ndo_get_devlink_port = prestera_devlink_get_port,
}; };
static int prestera_port_autoneg_set(struct prestera_port *port, bool enable, static int prestera_port_autoneg_set(struct prestera_port *port, bool enable,
...@@ -250,9 +252,13 @@ static int prestera_port_create(struct prestera_switch *sw, u32 id) ...@@ -250,9 +252,13 @@ static int prestera_port_create(struct prestera_switch *sw, u32 id)
&port->fp_id); &port->fp_id);
if (err) { if (err) {
dev_err(prestera_dev(sw), "Failed to get port(%u) info\n", id); dev_err(prestera_dev(sw), "Failed to get port(%u) info\n", id);
goto err_port_init; goto err_port_info_get;
} }
err = prestera_devlink_port_register(port);
if (err)
goto err_dl_port_register;
dev->features |= NETIF_F_NETNS_LOCAL; dev->features |= NETIF_F_NETNS_LOCAL;
dev->netdev_ops = &prestera_netdev_ops; dev->netdev_ops = &prestera_netdev_ops;
...@@ -313,11 +319,16 @@ static int prestera_port_create(struct prestera_switch *sw, u32 id) ...@@ -313,11 +319,16 @@ static int prestera_port_create(struct prestera_switch *sw, u32 id)
if (err) if (err)
goto err_register_netdev; goto err_register_netdev;
prestera_devlink_port_set(port);
return 0; return 0;
err_register_netdev: err_register_netdev:
prestera_port_list_del(port); prestera_port_list_del(port);
err_port_init: err_port_init:
prestera_devlink_port_unregister(port);
err_dl_port_register:
err_port_info_get:
free_netdev(dev); free_netdev(dev);
return err; return err;
} }
...@@ -327,8 +338,10 @@ static void prestera_port_destroy(struct prestera_port *port) ...@@ -327,8 +338,10 @@ static void prestera_port_destroy(struct prestera_port *port)
struct net_device *dev = port->dev; struct net_device *dev = port->dev;
cancel_delayed_work_sync(&port->cached_hw_stats.caching_dw); cancel_delayed_work_sync(&port->cached_hw_stats.caching_dw);
prestera_devlink_port_clear(port);
unregister_netdev(dev); unregister_netdev(dev);
prestera_port_list_del(port); prestera_port_list_del(port);
prestera_devlink_port_unregister(port);
free_netdev(dev); free_netdev(dev);
} }
...@@ -446,6 +459,10 @@ static int prestera_switch_init(struct prestera_switch *sw) ...@@ -446,6 +459,10 @@ static int prestera_switch_init(struct prestera_switch *sw)
if (err) if (err)
goto err_handlers_register; goto err_handlers_register;
err = prestera_devlink_register(sw);
if (err)
goto err_dl_register;
err = prestera_create_ports(sw); err = prestera_create_ports(sw);
if (err) if (err)
goto err_ports_create; goto err_ports_create;
...@@ -453,6 +470,8 @@ static int prestera_switch_init(struct prestera_switch *sw) ...@@ -453,6 +470,8 @@ static int prestera_switch_init(struct prestera_switch *sw)
return 0; return 0;
err_ports_create: err_ports_create:
prestera_devlink_unregister(sw);
err_dl_register:
prestera_event_handlers_unregister(sw); prestera_event_handlers_unregister(sw);
err_handlers_register: err_handlers_register:
prestera_rxtx_switch_fini(sw); prestera_rxtx_switch_fini(sw);
...@@ -464,6 +483,7 @@ static int prestera_switch_init(struct prestera_switch *sw) ...@@ -464,6 +483,7 @@ static int prestera_switch_init(struct prestera_switch *sw)
static void prestera_switch_fini(struct prestera_switch *sw) static void prestera_switch_fini(struct prestera_switch *sw)
{ {
prestera_destroy_ports(sw); prestera_destroy_ports(sw);
prestera_devlink_unregister(sw);
prestera_event_handlers_unregister(sw); prestera_event_handlers_unregister(sw);
prestera_rxtx_switch_fini(sw); prestera_rxtx_switch_fini(sw);
prestera_hw_switch_fini(sw); prestera_hw_switch_fini(sw);
...@@ -474,7 +494,7 @@ int prestera_device_register(struct prestera_device *dev) ...@@ -474,7 +494,7 @@ int prestera_device_register(struct prestera_device *dev)
struct prestera_switch *sw; struct prestera_switch *sw;
int err; int err;
sw = kzalloc(sizeof(*sw), GFP_KERNEL); sw = prestera_devlink_alloc();
if (!sw) if (!sw)
return -ENOMEM; return -ENOMEM;
...@@ -483,7 +503,7 @@ int prestera_device_register(struct prestera_device *dev) ...@@ -483,7 +503,7 @@ int prestera_device_register(struct prestera_device *dev)
err = prestera_switch_init(sw); err = prestera_switch_init(sw);
if (err) { if (err) {
kfree(sw); prestera_devlink_free(sw);
return err; return err;
} }
...@@ -496,7 +516,7 @@ void prestera_device_unregister(struct prestera_device *dev) ...@@ -496,7 +516,7 @@ void prestera_device_unregister(struct prestera_device *dev)
struct prestera_switch *sw = dev->priv; struct prestera_switch *sw = dev->priv;
prestera_switch_fini(sw); prestera_switch_fini(sw);
kfree(sw); prestera_devlink_free(sw);
} }
EXPORT_SYMBOL(prestera_device_unregister); EXPORT_SYMBOL(prestera_device_unregister);
......
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