net: ti: am65-cpsw-nuss: Add switchdev driver
Subsystems (4)
v2 cover net: ti: am65-cpsw-nuss: Add switchdev driver
This series adds switchdev support for AM65 CPSW NUSS driver to support multi port CPSW present on J721e and AM64 SoCs.
It adds devlink hook to switch b/w switch mode and multi mac mode.
v2:
Rebased on latest net-next
Update patch 1/4 with rationale for using devlink
Vignesh Raghavendra (4):
net: ti: am65-cpsw-nuss: Add devlink support
net: ti: am65-cpsw-nuss: Add netdevice notifiers
net: ti: am65-cpsw-nuss: Add switchdev support
docs: networking: ti: Add driver doc for AM65 NUSS switch driver
.../device_drivers/ethernet/index.rst | 1 + .../ethernet/ti/am65_nuss_cpsw_switchdev.rst | 143 +++++ .../devlink/am65-nuss-cpsw-switch.rst | 26 + Documentation/networking/devlink/index.rst | 1 + drivers/net/ethernet/ti/Kconfig | 10 + drivers/net/ethernet/ti/Makefile | 1 + drivers/net/ethernet/ti/am65-cpsw-nuss.c | 511 ++++++++++++++++- drivers/net/ethernet/ti/am65-cpsw-nuss.h | 26 + drivers/net/ethernet/ti/am65-cpsw-switchdev.c | 533 ++++++++++++++++++ drivers/net/ethernet/ti/am65-cpsw-switchdev.h | 34 ++ 10 files changed, 1267 insertions(+), 19 deletions(-) create mode 100644 Documentation/networking/device_drivers/ethernet/ti/am65_nuss_cpsw_switchdev.rst create mode 100644 Documentation/networking/devlink/am65-nuss-cpsw-switch.rst create mode 100644 drivers/net/ethernet/ti/am65-cpsw-switchdev.c create mode 100644 drivers/net/ethernet/ti/am65-cpsw-switchdev.h
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 1/4 net: ti: am65-cpsw-nuss: Add devlink support
AM65 NUSS ethernet switch on K3 devices can be configured to work either in independent mac mode where each port acts as independent network interface (multi mac) or switch mode.
Add devlink hooks to provide a way to switch b/w these modes.
Rationale to use devlink instead of defaulting to bridge mode is that SoC use cases require to support multiple independent MAC ports with no switching so that users can use software bridges with multi-mac configuration (e.g: to support LAG, HSR/PRP, etc). Also, switching between multi mac and switch mode requires significant Port and ALE reconfiguration, therefore is easier to be made as part of mode change devlink hooks. It also allows to keep user interface similar to what was implemented for the previous generation of TI CPSW IP (on AM33/AM43/AM57 SoCs).
--- .../devlink/am65-nuss-cpsw-switch.rst | 26 ++ Documentation/networking/devlink/index.rst | 1 + drivers/net/ethernet/ti/Kconfig | 10 + drivers/net/ethernet/ti/am65-cpsw-nuss.c | 363 +++++++++++++++++- drivers/net/ethernet/ti/am65-cpsw-nuss.h | 22 ++ 5 files changed, 404 insertions(+), 18 deletions(-) create mode 100644 Documentation/networking/devlink/am65-nuss-cpsw-switch.rst
Documentation/networking/devlink/am65-nuss-cpsw-switch.rst new file +26 -0
@@ -0,0 +1,26 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============================== +am65-cpsw-nuss devlink support +============================== + +This document describes the devlink features implemented by the ``am65-cpsw-nuss`` +device driver. + +Parameters +========== + +The ``am65-cpsw-nuss`` driver implements the following driver-specific +parameters. + +.. list-table:: Driver-specific parameters implemented + :widths: 5 5 5 85 + + * - Name + - Type + - Mode + - Description + * - ``switch_mode`` + - Boolean + - runtime + - Enable switch mode
Documentation/networking/devlink/index.rst +1 -0
@@ -45,3 +45,4 @@ parameters, info versions, and other features it supports. sja1105 qed ti-cpsw-switch + am65-nuss-cpsw-switch
drivers/net/ethernet/ti/Kconfig +10 -0
@@ -92,6 +92,7 @@ config TI_CPTS config TI_K3_AM65_CPSW_NUSS tristate "TI K3 AM654x/J721E CPSW Ethernet driver" depends on ARCH_K3 && OF && TI_K3_UDMA_GLUE_LAYER + select NET_DEVLINK select TI_DAVINCI_MDIO imply PHY_TI_GMII_SEL depends on TI_K3_AM65_CPTS || !TI_K3_AM65_CPTS
@@ -105,6 +106,15 @@ config TI_K3_AM65_CPSW_NUSS To compile this driver as a module, choose M here: the module will be called ti-am65-cpsw-nuss. +config TI_K3_AM65_CPSW_SWITCHDEV + bool "TI K3 AM654x/J721E CPSW Switch mode support" + depends on TI_K3_AM65_CPSW_NUSS + depends on NET_SWITCHDEV + help + This enables switchdev support for TI K3 CPSWxG Ethernet + Switch. Enable this driver to support hardware switch support for AM65 + CPSW NUSS driver. + config TI_K3_AM65_CPTS tristate "TI K3 AM65x CPTS" depends on ARCH_K3 && OF
drivers/net/ethernet/ti/am65-cpsw-nuss.c +345 -18
452 lines not on this page · raw message
drivers/net/ethernet/ti/am65-cpsw-nuss.h +22 -0
@@ -6,12 +6,14 @@#ifndef AM65_CPSW_NUSS_H_ #define AM65_CPSW_NUSS_H_ +#include <linux/if_ether.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/netdevice.h> #include <linux/phy.h> #include <linux/platform_device.h> #include <linux/soc/ti/k3-ringacc.h> +#include <net/devlink.h> #include "am65-cpsw-qos.h" struct am65_cpts ;
@@ -22,6 +24,8 @@ struct am65_cpts;#define AM65_CPSW_MAX_RX_QUEUES 1#define AM65_CPSW_MAX_RX_FLOWS 1 +#define AM65_CPSW_PORT_VLAN_REG_OFFSET 0x014 +struct am65_cpsw_slave_data {bool mac_only;struct cpsw_sl *mac_sl;
@@ -32,6 +36,7 @@ struct am65_cpsw_slave_data {bool rx_pause;bool tx_pause;u8 mac_addr[ETH_ALEN ]; +int port_vlan; };struct am65_cpsw_port {
@@ -47,6 +52,7 @@ struct am65_cpsw_port {bool tx_ts_enabled;bool rx_ts_enabled;struct am65_cpsw_qos qos; +struct devlink_port devlink_port; };struct am65_cpsw_host {
@@ -85,6 +91,15 @@ struct am65_cpsw_pdata {const char *ale_dev_id; }; +enum cpsw_devlink_param_id { +AM65_CPSW_DEVLINK_PARAM_ID_BASE =DEVLINK_PARAM_GENERIC_ID_MAX , +AM65_CPSW_DL_PARAM_SWITCH_MODE , +}; + +struct am65_cpsw_devlink { +struct am65_cpsw_common *common; +}; +struct am65_cpsw_common {struct device *dev;struct device *mdio_dev;
@@ -117,6 +132,12 @@ struct am65_cpsw_common {bool pf_p0_rx_ptype_rrobin;struct am65_cpts *cpts;int est_enabled; + +bool is_emac_mode; +u16 br_members; +int default_vlan; +struct devlink *devlink; +unsigned char switch_id[MAX_PHYS_ITEM_ID_LEN ]; };struct am65_cpsw_ndev_stats {
@@ -131,6 +152,7 @@ struct am65_cpsw_ndev_priv {u32 msg_enable;struct am65_cpsw_port *port;struct am65_cpsw_ndev_stats __percpu *stats; +bool offload_fwd_mark; };#define am65_ndev_to_priv (ndev) \
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 2/4 net: ti: am65-cpsw-nuss: Add netdevice notifiers
In reply to Vignesh RaghavendraRegister netdevice notifiers in order to receive notification when individual MAC ports are added to the HW bridge.
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 130 ++++++++++++++++++++++- drivers/net/ethernet/ti/am65-cpsw-nuss.h | 4 + 2 files changed, 133 insertions(+), 1 deletion(-)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +129 -1
@@ -2036,6 +2036,126 @@ static void am65_cpsw_nuss_cleanup_ndev(struct am65_cpsw_common *common) } } +static void am65_cpsw_port_offload_fwd_mark_update (struct am65_cpsw_common *common) +{ +int set_val =0 ; +int i; + +if (common->br_members == (GENMASK (common->port_num,1 ) & ~common->disabled_ports_mask)) + set_val =1 ; + +dev_dbg (common->dev,"set offload_fwd_mark %d\n" , set_val); + +for (i =1 ; i <= common->port_num; i++) { +struct am65_cpsw_port *port =am65_common_get_port (common, i); +struct am65_cpsw_ndev_priv *priv =am65_ndev_to_priv (port->ndev); + + priv->offload_fwd_mark = set_val; + } +} + +bool am65_cpsw_port_dev_check (const struct net_device *ndev) +{ +if (ndev->netdev_ops == &am65_cpsw_nuss_netdev_ops) { +struct am65_cpsw_common *common =am65_ndev_to_common (ndev); + +return !common->is_emac_mode; + } + +return false; +} + +static int am65_cpsw_netdevice_port_link (struct net_device *ndev,struct net_device *br_ndev) +{ +struct am65_cpsw_common *common =am65_ndev_to_common (ndev); +struct am65_cpsw_ndev_priv *priv =am65_ndev_to_priv (ndev); + +if (!common->br_members) { + common->hw_bridge_dev = br_ndev; + }else { +/* This is adding the port to a second bridge, this is +* unsupported +*/ +if (common->hw_bridge_dev != br_ndev) +return -EOPNOTSUPP ; + } + + common->br_members |=BIT (priv->port->port_id); + +am65_cpsw_port_offload_fwd_mark_update (common); + +return NOTIFY_DONE ; +} + +static void am65_cpsw_netdevice_port_unlink (struct net_device *ndev) +{ +struct am65_cpsw_common *common =am65_ndev_to_common (ndev); +struct am65_cpsw_ndev_priv *priv =am65_ndev_to_priv (ndev); + + common->br_members &= ~BIT (priv->port->port_id); + +am65_cpsw_port_offload_fwd_mark_update (common); + +if (!common->br_members) + common->hw_bridge_dev =NULL ; +} + +/* netdev notifier */ +static int am65_cpsw_netdevice_event (struct notifier_block *unused, +unsigned long event,void *ptr) +{ +struct net_device *ndev =netdev_notifier_info_to_dev (ptr); +struct netdev_notifier_changeupper_info *info; +int ret =NOTIFY_DONE ; + +if (!am65_cpsw_port_dev_check (ndev)) +return NOTIFY_DONE ; + +switch (event) { +case NETDEV_CHANGEUPPER : + info = ptr; + +if (netif_is_bridge_master (info->upper_dev)) { +if (info->linking) + ret =am65_cpsw_netdevice_port_link (ndev, info->upper_dev); +else +am65_cpsw_netdevice_port_unlink (ndev); + } +break ; +default : +return NOTIFY_DONE ; + } + +return notifier_from_errno (ret); +} + +static int am65_cpsw_register_notifiers (struct am65_cpsw_common *cpsw) +{ +int ret =0 ; + +if (AM65_CPSW_IS_CPSW2G (cpsw) || + !IS_REACHABLE (CONFIG_TI_K3_AM65_CPSW_SWITCHDEV )) +return 0 ; + + cpsw->am65_cpsw_netdevice_nb.notifier_call = &am65_cpsw_netdevice_event; + ret =register_netdevice_notifier (&cpsw->am65_cpsw_netdevice_nb); +if (ret) { +dev_err (cpsw->dev,"can't register netdevice notifier\n" ); +return ret; + } + +return ret; +} + +static void am65_cpsw_unregister_notifiers (struct am65_cpsw_common *cpsw) +{ +if (AM65_CPSW_IS_CPSW2G (cpsw) || + !IS_REACHABLE (CONFIG_TI_K3_AM65_CPSW_SWITCHDEV )) +return ; + +unregister_netdevice_notifier (&cpsw->am65_cpsw_netdevice_nb); +} +static const struct devlink_ops am65_cpsw_devlink_ops = {};static void am65_cpsw_init_stp_ale_entry (struct am65_cpsw_common *cpsw)
@@ -2379,17 +2499,24 @@ static int am65_cpsw_nuss_register_ndevs(struct am65_cpsw_common *common) } } - ret =am65_cpsw_nuss_register_devlink (common); + ret =am65_cpsw_register_notifiers (common);if (ret) goto err_cleanup_ndev; + ret =am65_cpsw_nuss_register_devlink (common); +if (ret) + goto clean_unregister_notifiers; +/* can't auto unregister ndev using devm_add_action() due to * devres release sequence in DD core for DMA */ return 0 ; +clean_unregister_notifiers: +am65_cpsw_unregister_notifiers (common); err_cleanup_ndev:am65_cpsw_nuss_cleanup_ndev (common); +return ret; }
@@ -2628,6 +2755,7 @@ static int am65_cpsw_nuss_remove(struct platform_device *pdev) }am65_cpsw_unregister_devlink (common); +am65_cpsw_unregister_notifiers (common);/* must unregister ndevs here because DD release_driver routine calls * dma_deconfigure(dev) before devres_release_all(dev)
drivers/net/ethernet/ti/am65-cpsw-nuss.h +4 -0
@@ -137,6 +137,8 @@ struct am65_cpsw_common {u16 br_members;int default_vlan;struct devlink *devlink; +struct net_device *hw_bridge_dev; +struct notifier_block am65_cpsw_netdevice_nb;unsigned char switch_id[MAX_PHYS_ITEM_ID_LEN ]; };
@@ -180,4 +182,6 @@ void am65_cpsw_nuss_set_p0_ptype(struct am65_cpsw_common *common);void am65_cpsw_nuss_remove_tx_chns (struct am65_cpsw_common *common);int am65_cpsw_nuss_update_tx_chns (struct am65_cpsw_common *common,int num_tx); +bool am65_cpsw_port_dev_check (const struct net_device *dev); +#endif /* AM65_CPSW_NUSS_H_ */
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 3/4 net: ti: am65-cpsw-nuss: Add switchdev support
In reply to Vignesh RaghavendraJ721e, J7200 and AM64 have multi port switches which can work in multi mac mode and in switch mode. Add support for configuring this HW in switch mode using devlink and switchdev notifiers.
Support is similar to existing CPSW switchdev implementation of TI's 32 bit platform like AM33/AM43/AM57.
To enable switch mode:
devlink dev param set platform/8000000.ethernet name switch_mode value true cmode runtime
All configuration is implemented via switchdev API and notifiers. Supported:
- SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS
- SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS
- SWITCHDEV_ATTR_ID_PORT_STP_STATE
- SWITCHDEV_OBJ_ID_PORT_VLAN
- SWITCHDEV_OBJ_ID_PORT_MDB
- SWITCHDEV_OBJ_ID_HOST_MDB
Hence AM65 CPSW switchdev driver supports:
- FDB offloading
- MDB offloading
- VLAN filtering and offloading
- STP
--- drivers/net/ethernet/ti/Makefile | 1 + drivers/net/ethernet/ti/am65-cpsw-nuss.c | 20 +- drivers/net/ethernet/ti/am65-cpsw-switchdev.c | 533 ++++++++++++++++++ drivers/net/ethernet/ti/am65-cpsw-switchdev.h | 34 ++ 4 files changed, 587 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/ti/am65-cpsw-switchdev.c create mode 100644 drivers/net/ethernet/ti/am65-cpsw-switchdev.h
drivers/net/ethernet/ti/Makefile +1 -0
@@ -26,4 +26,5 @@ keystone_netcp_ethss-y := netcp_ethss.o netcp_sgmii.o netcp_xgbepcsr.o cpsw_ale. obj-$(CONFIG_TI_K3_AM65_CPSW_NUSS) += ti-am65-cpsw-nuss.o ti-am65-cpsw-nuss-y := am65-cpsw-nuss.o cpsw_sl.o am65-cpsw-ethtool.o cpsw_ale.o k3-cppi-desc-pool.o am65-cpsw-qos.o +ti-am65-cpsw-nuss-$(CONFIG_TI_K3_AM65_CPSW_SWITCHDEV) += am65-cpsw-switchdev.o obj-$(CONFIG_TI_K3_AM65_CPTS) += am65-cpts.o
drivers/net/ethernet/ti/am65-cpsw-nuss.c +19 -1
@@ -31,6 +31,7 @@#include "cpsw_ale.h" #include "cpsw_sl.h" #include "am65-cpsw-nuss.h" +#include "am65-cpsw-switchdev.h" #include "k3-cppi-desc-pool.h" #include "am65-cpts.h"
@@ -228,6 +229,9 @@ static int am65_cpsw_nuss_ndo_slave_add_vid(struct net_device *ndev,u32 port_mask, unreg_mcast =0 ;int ret; +if (!common->is_emac_mode) +return 0 ; +if (!netif_running (ndev) || !vid)return 0 ;
@@ -255,6 +259,9 @@ static int am65_cpsw_nuss_ndo_slave_kill_vid(struct net_device *ndev,struct am65_cpsw_port *port =am65_ndev_to_port (ndev);int ret; +if (!common->is_emac_mode) +return 0 ; +if (!netif_running (ndev) || !vid)return 0 ;
@@ -277,6 +284,11 @@ static void am65_cpsw_slave_set_promisc(struct am65_cpsw_port *port, {struct am65_cpsw_common *common = port->common; +if (promisc && !common->is_emac_mode) { +dev_dbg (common->dev,"promisc mode requested in switch mode" ); +return ; + } +if (promisc) {/* Enable promiscuous mode */ cpsw_ale_control_set(common->ale, port->port_id,
@@ -800,12 +812,13 @@ static int am65_cpsw_nuss_rx_packets(struct am65_cpsw_common *common, new_skb =netdev_alloc_skb_ip_align (ndev,AM65_CPSW_MAX_PACKET_SIZE );if (new_skb) { + ndev_priv =netdev_priv (ndev); +am65_cpsw_nuss_set_offload_fwd_mark (skb, ndev_priv->offload_fwd_mark);skb_put (skb, pkt_len); skb->protocol =eth_type_trans (skb, ndev);am65_cpsw_nuss_rx_csum (skb, csum_info);napi_gro_receive (&common->napi_rx, skb); - ndev_priv =netdev_priv (ndev); stats =this_cpu_ptr (ndev_priv->stats);u64_stats_update_begin (&stats->syncp);
@@ -2144,6 +2157,10 @@ static int am65_cpsw_register_notifiers(struct am65_cpsw_common *cpsw)return ret; } + ret =am65_cpsw_switchdev_register_notifiers (cpsw); +if (ret) +unregister_netdevice_notifier (&cpsw->am65_cpsw_netdevice_nb); +return ret; }
@@ -2153,6 +2170,7 @@ static void am65_cpsw_unregister_notifiers(struct am65_cpsw_common *cpsw) !IS_REACHABLE(CONFIG_TI_K3_AM65_CPSW_SWITCHDEV)) return; +am65_cpsw_switchdev_unregister_notifiers (cpsw);unregister_netdevice_notifier (&cpsw->am65_cpsw_netdevice_nb); }
drivers/net/ethernet/ti/am65-cpsw-switchdev.c new file +533 -0
533 lines not on this page · raw message
drivers/net/ethernet/ti/am65-cpsw-switchdev.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2020 Texas Instruments Incorporated - https://www.ti.com/ +*/ + +#ifndef DRIVERS_NET_ETHERNET_TI_AM65_CPSW_SWITCHDEV_H_ +#define DRIVERS_NET_ETHERNET_TI_AM65_CPSW_SWITCHDEV_H_ + +#include <linux/skbuff.h> + +#if IS_ENABLED (CONFIG_TI_K3_AM65_CPSW_SWITCHDEV ) +static inline void am65_cpsw_nuss_set_offload_fwd_mark (struct sk_buff *skb,bool val) +{ + skb->offload_fwd_mark = val; +} + +int am65_cpsw_switchdev_register_notifiers (struct am65_cpsw_common *cpsw); +void am65_cpsw_switchdev_unregister_notifiers (struct am65_cpsw_common *cpsw); +#else +static inline int am65_cpsw_switchdev_register_notifiers (struct am65_cpsw_common *cpsw) +{ +return -EOPNOTSUPP ; +} + +static inline void am65_cpsw_switchdev_unregister_notifiers (struct am65_cpsw_common *cpsw) +{ +} + +static inline void am65_cpsw_nuss_set_offload_fwd_mark (struct sk_buff *skb,bool val) +{ +} + +#endif + +#endif /* DRIVERS_NET_ETHERNET_TI_AM65_CPSW_SWITCHDEV_H_ */
Signature · 1 line
2.30.0
PATCH v2 4/4 docs: networking: ti: Add driver doc for AM65 NUSS switch driver
In reply to Vignesh RaghavendraJ721e, J7200 and AM64 have multi port switches which can work in multi mac mode and in switch mode. Add documentation explaining how to use different modes.
Borrowed from:Documentation/networking/device_drivers/ethernet/ti/cpsw_switchdev.rst
--- .../device_drivers/ethernet/index.rst | 1 + .../ethernet/ti/am65_nuss_cpsw_switchdev.rst | 143 ++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/ti/am65_nuss_cpsw_switchdev.rst
Documentation/networking/device_drivers/ethernet/index.rst +1 -0
@@ -49,6 +49,7 @@ Contents: stmicro/stmmac ti/cpsw ti/cpsw_switchdev + ti/am65_nuss_cpsw_switchdev ti/tlan toshiba/spider_net
Documentation/networking/device_drivers/ethernet/ti/am65_nuss_cpsw_switchdev.rst new file +143 -0
143 lines not on this page · raw message
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 9 lines · On Thu, 11 Feb 2021 16:26:40 +0530 you wrote:
This series adds switchdev support for AM65 CPSW NUSS driver to support multi port CPSW present on J721e and AM64 SoCs.
It adds devlink hook to switch b/w switch mode and multi mac mode.v2:
Rebased on latest net-next
Update patch 1/4 with rationale for using devlink[...]
Here is the summary with links:
- [v2,1/4] net: ti: am65-cpsw-nuss: Add devlink support
https://git.kernel.org/netdev/net-next/c/58356eb31d60 - [v2,2/4] net: ti: am65-cpsw-nuss: Add netdevice notifiers https://git.kernel.org/netdev/net-next/c/2934db9bcb30 - [v2,3/4] net: ti: am65-cpsw-nuss: Add switchdev support https://git.kernel.org/netdev/net-next/c/86e8b070b25e - [v2,4/4] docs: networking: ti: Add driver doc for AM65 NUSS switch driver https://git.kernel.org/netdev/net-next/c/e276cfb9cd5b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html