Add FDMA support on ocelot switch driver
Subsystems (3)
v8 cover Add FDMA support on ocelot switch driver
This series adds support for the Frame DMA present on the VSC7514 switch. The FDMA is able to extract and inject packets on the various ethernet interfaces present on the switch.
------------------
Changes in V8:
- Rebase on net-next/master
Changes in V7:
- Fix kernel doc for fdma struct
Changes in V6:
- Remove dead code added in ocelot_vsc7514
- Remove useless include added in mscc/ocelot.h
- Remove trailing whitespace
- Move skb_tx_timestamp before sending the skb
- Fix a few long lines
Changes in V5:
- Add skb freeing for TX and fix RX ring skb not being freed
- Fix napi init in case of netdev registration failure
- Reorganize FDMA register definitions
- Used regmap targets from ocelot structure to get fdma pointer
- s/page_count/page_ref_count
- Move napi back in struct ocelot_fdma
Changes in V4:
- Use regmap for register access
- Removed yaml bindings convertion as well as mac address from dt
- Removed pre-computed IFH for the moment
- Fixed timestamp reading for PTP in FDMA
- Fixed wrong exit path for fdma netdev init
- Removed spinlock from TX cleanup
- Add asynchronous RX chan stop before refilling
- Reduce CH_SAFE wait time to 10us
- Reduce waiting time for channel to be safe
- Completely rework rx to use page recycling (code from gianfar)
- Reenable MTU change support since FDMA now supports it transparently
- Split TX and RX ring size
- Larger RX size to lower page allocation rate
- Add static key to check for FDMA to be enabled in fast path
Changes in V3:
- Add timeouts for hardware registers read
- Add cleanup path in fdma_init
- Rework injection and extraction to used ring like structure
- Added PTP support to FDMA
- Use pskb_expand_head instead of skb_copy_expand in xmit
- Drop jumbo support
- Use of_get_ethdev_address
- Add ocelot_fdma_netdev_init/deinit
Changes in V2:
- Read MAC for each port and not as switch base MAC address
- Add missing static for some functions in ocelot_fdma.c
- Split change_mtu from fdma commit
- Add jumbo support for register based xmit
- Move precomputed header into ocelot_port struct
- Remove use of QUIRK_ENDIAN_LITTLE due to misconfiguration for tests
- Remove fragmented packet sending which has not been tested
Clément Léger (4):
net: ocelot: export ocelot_ifh_port_set() to setup IFH
net: ocelot: add and export ocelot_ptp_rx_timestamp()
net: ocelot: add support for ndo_change_mtu
net: ocelot: add FDMA support
drivers/net/ethernet/mscc/Makefile | 1 + drivers/net/ethernet/mscc/ocelot.c | 59 +- drivers/net/ethernet/mscc/ocelot.h | 2 + drivers/net/ethernet/mscc/ocelot_fdma.c | 894 +++++++++++++++++++++ drivers/net/ethernet/mscc/ocelot_fdma.h | 166 ++++ drivers/net/ethernet/mscc/ocelot_net.c | 39 +- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 10 + include/soc/mscc/ocelot.h | 6 + 8 files changed, 1151 insertions(+), 26 deletions(-) create mode 100644 drivers/net/ethernet/mscc/ocelot_fdma.c create mode 100644 drivers/net/ethernet/mscc/ocelot_fdma.h
Signature · 1 line
2.34.1
PATCH v8 1/4 net: ocelot: export ocelot_ifh_port_set() to setup IFH
FDMA will need this code to prepare the injection frame header when sending SKBs. Move this code into ocelot_ifh_port_set() and add conditional IFH setting for vlan and rew op if they are not set.
--- drivers/net/ethernet/mscc/ocelot.c | 18 +++++++++++++----- include/soc/mscc/ocelot.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-)
drivers/net/ethernet/mscc/ocelot.c +13 -5
@@ -1164,6 +1164,18 @@ bool ocelot_can_inject(struct ocelot *ocelot, int grp) }EXPORT_SYMBOL (ocelot_can_inject); +void ocelot_ifh_port_set (void *ifh,int port,u32 rew_op,u32 vlan_tag) +{ +ocelot_ifh_set_bypass (ifh,1 ); +ocelot_ifh_set_dest (ifh,BIT_ULL (port)); +ocelot_ifh_set_tag_type (ifh,IFH_TAG_TYPE_C ); +if (vlan_tag) +ocelot_ifh_set_vlan_tci (ifh, vlan_tag); +if (rew_op) +ocelot_ifh_set_rew_op (ifh, rew_op); +} +EXPORT_SYMBOL (ocelot_ifh_port_set); +void ocelot_port_inject_frame (struct ocelot *ocelot,int port,int grp,u32 rew_op,struct sk_buff *skb) {
@@ -1173,11 +1185,7 @@ void ocelot_port_inject_frame(struct ocelot *ocelot, int port, int grp,ocelot_write_rix (ocelot,QS_INJ_CTRL_GAP_SIZE (1 ) |QS_INJ_CTRL_SOF ,QS_INJ_CTRL , grp); -ocelot_ifh_set_bypass (ifh,1 ); -ocelot_ifh_set_dest (ifh,BIT_ULL (port)); -ocelot_ifh_set_tag_type (ifh,IFH_TAG_TYPE_C ); -ocelot_ifh_set_vlan_tci (ifh,skb_vlan_tag_get (skb)); -ocelot_ifh_set_rew_op (ifh, rew_op); +ocelot_ifh_port_set (ifh, port, rew_op,skb_vlan_tag_get (skb));for (i =0 ; i <OCELOT_TAG_LEN /4 ; i++)ocelot_write_rix (ocelot, ifh[i],QS_INJ_WR , grp);
include/soc/mscc/ocelot.h +1 -0
@@ -794,6 +794,7 @@ void __ocelot_target_write_ix(struct ocelot *ocelot, enum ocelot_target target,bool ocelot_can_inject (struct ocelot *ocelot,int grp);void ocelot_port_inject_frame (struct ocelot *ocelot,int port,int grp,u32 rew_op,struct sk_buff *skb); +void ocelot_ifh_port_set (void *ifh,int port,u32 rew_op,u32 vlan_tag);int ocelot_xtr_poll_frame (struct ocelot *ocelot,int grp,struct sk_buff **skb);void ocelot_drain_cpu_queue (struct ocelot *ocelot,int grp);
Signature · 1 line
2.34.1
PATCH v8 2/4 net: ocelot: add and export ocelot_ptp_rx_timestamp()
In reply to Clément LégerIn order to support PTP in FDMA, PTP handling code is needed. Since this is the same as for register-based extraction, export it with a new ocelot_ptp_rx_timestamp() function.
--- drivers/net/ethernet/mscc/ocelot.c | 41 +++++++++++++++++------------- include/soc/mscc/ocelot.h | 2 ++ 2 files changed, 26 insertions(+), 17 deletions(-)
drivers/net/ethernet/mscc/ocelot.c +24 -17
@@ -1054,14 +1054,34 @@ static int ocelot_xtr_poll_xfh(struct ocelot *ocelot, int grp, u32 *xfh)return 0 ; } -int ocelot_xtr_poll_frame (struct ocelot *ocelot,int grp,struct sk_buff **nskb) +void ocelot_ptp_rx_timestamp (struct ocelot *ocelot,struct sk_buff *skb, +u64 timestamp) {struct skb_shared_hwtstamps *shhwtstamps;u64 tod_in_ns, full_ts_in_ns; +struct timespec64 ts; + +ocelot_ptp_gettime64 (&ocelot->ptp_info, &ts); + + tod_in_ns =ktime_set (ts.tv_sec, ts.tv_nsec); +if ((tod_in_ns &0xffffffff ) < timestamp) + full_ts_in_ns = (((tod_in_ns >>32 ) -1 ) <<32 ) | + timestamp; +else + full_ts_in_ns = (tod_in_ns &GENMASK_ULL (63 ,32 )) | + timestamp; + + shhwtstamps =skb_hwtstamps (skb); +memset (shhwtstamps,0 ,sizeof (struct skb_shared_hwtstamps )); + shhwtstamps->hwtstamp = full_ts_in_ns; +} +EXPORT_SYMBOL (ocelot_ptp_rx_timestamp); + +int ocelot_xtr_poll_frame (struct ocelot *ocelot,int grp,struct sk_buff **nskb) +{u64 timestamp, src_port, len;u32 xfh[OCELOT_TAG_LEN /4 ];struct net_device *dev; -struct timespec64 ts;struct sk_buff *skb;int sz, buf_len;u32 val, *buf;
@@ -1117,21 +1137,8 @@ int ocelot_xtr_poll_frame(struct ocelot *ocelot, int grp, struct sk_buff **nskb) *buf = val; } -if (ocelot->ptp) { -ocelot_ptp_gettime64 (&ocelot->ptp_info, &ts); - - tod_in_ns =ktime_set (ts.tv_sec, ts.tv_nsec); -if ((tod_in_ns &0xffffffff ) < timestamp) - full_ts_in_ns = (((tod_in_ns >>32 ) -1 ) <<32 ) | - timestamp; -else - full_ts_in_ns = (tod_in_ns &GENMASK_ULL (63 ,32 )) | - timestamp; - - shhwtstamps =skb_hwtstamps (skb); -memset (shhwtstamps,0 ,sizeof (struct skb_shared_hwtstamps )); - shhwtstamps->hwtstamp = full_ts_in_ns; - } +if (ocelot->ptp) +ocelot_ptp_rx_timestamp (ocelot, skb, timestamp);/* Everything we see on an interface that is in the HW bridge * has already been forwarded.
include/soc/mscc/ocelot.h +2 -0
@@ -797,6 +797,8 @@ void ocelot_port_inject_frame(struct ocelot *ocelot, int port, int grp,void ocelot_ifh_port_set (void *ifh,int port,u32 rew_op,u32 vlan_tag);int ocelot_xtr_poll_frame (struct ocelot *ocelot,int grp,struct sk_buff **skb);void ocelot_drain_cpu_queue (struct ocelot *ocelot,int grp); +void ocelot_ptp_rx_timestamp (struct ocelot *ocelot,struct sk_buff *skb, +u64 timestamp);/* Hardware initialization */ int ocelot_regfields_init(struct ocelot *ocelot,
Signature · 1 line
2.34.1
PATCH v8 3/4 net: ocelot: add support for ndo_change_mtu
In reply to Clément LégerThis commit adds support for changing MTU for the ocelot register based interface. For ocelot, JUMBO frame size can be set up to 25000 bytes but has been set to 9000 which is a saner value and allows for maximum gain of performance with FDMA.
--- drivers/net/ethernet/mscc/ocelot.h | 2 ++ drivers/net/ethernet/mscc/ocelot_net.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+)
drivers/net/ethernet/mscc/ocelot.h +2 -0
@@ -32,6 +32,8 @@#define OCELOT_PTP_QUEUE_SZ 128 +#define OCELOT_JUMBO_MTU 9000 +struct ocelot_port_tc {bool block_shared;unsigned long offload_cnt;
drivers/net/ethernet/mscc/ocelot_net.c +14 -0
@@ -764,10 +764,23 @@ static int ocelot_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)return phy_mii_ioctl (dev->phydev, ifr, cmd); } +static int ocelot_change_mtu (struct net_device *dev,int new_mtu) +{ +struct ocelot_port_private *priv =netdev_priv (dev); +struct ocelot_port *ocelot_port = &priv->port; +struct ocelot *ocelot = ocelot_port->ocelot; + +ocelot_port_set_maxlen (ocelot, priv->chip_port, new_mtu); +WRITE_ONCE (dev->mtu, new_mtu); + +return 0 ; +} +static const struct net_device_ops ocelot_port_netdev_ops = { .ndo_open = ocelot_port_open, .ndo_stop = ocelot_port_stop, .ndo_start_xmit = ocelot_port_xmit, + .ndo_change_mtu = ocelot_change_mtu, .ndo_set_rx_mode = ocelot_set_rx_mode, .ndo_set_mac_address = ocelot_port_set_mac_address, .ndo_get_stats64 = ocelot_get_stats64,
@@ -1670,6 +1683,7 @@ int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target, dev->netdev_ops = &ocelot_port_netdev_ops; dev->ethtool_ops = &ocelot_ethtool_ops; + dev->max_mtu =OCELOT_JUMBO_MTU ; dev->hw_features |=NETIF_F_HW_VLAN_CTAG_FILTER |NETIF_F_RXFCS |NETIF_F_HW_TC ;
Signature · 1 line
2.34.1
PATCH v8 4/4 net: ocelot: add FDMA support
In reply to Clément LégerEthernet frames can be extracted or injected autonomously to or from the device’s DDR3/DDR3L memory and/or PCIe memory space. Linked list data structures in memory are used for injecting or extracting Ethernet frames. The FDMA generates interrupts when frame extraction or injection is done and when the linked lists need updating.
The FDMA is shared between all the ethernet ports of the switch and uses a linked list of descriptors (DCB) to inject and extract packets. Before adding descriptors, the FDMA channels must be stopped. It would be inefficient to do that each time a descriptor would be added so the channels are restarted only once they stopped.
Both channels uses ring-like structure to feed the DCBs to the FDMA. head and tail are never touched by hardware and are completely handled by the driver. On top of that, page recycling has been added and is mostly taken from gianfar driver.
--- drivers/net/ethernet/mscc/Makefile | 1 + drivers/net/ethernet/mscc/ocelot_fdma.c | 894 +++++++++++++++++++++ drivers/net/ethernet/mscc/ocelot_fdma.h | 166 ++++ drivers/net/ethernet/mscc/ocelot_net.c | 25 +- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 10 + include/soc/mscc/ocelot.h | 3 + 6 files changed, 1095 insertions(+), 4 deletions(-) create mode 100644 drivers/net/ethernet/mscc/ocelot_fdma.c create mode 100644 drivers/net/ethernet/mscc/ocelot_fdma.h
drivers/net/ethernet/mscc/Makefile +1 -0
@@ -12,5 +12,6 @@ mscc_ocelot_switch_lib-y := \ mscc_ocelot_switch_lib-$(CONFIG_BRIDGE_MRP) += ocelot_mrp.o obj-$(CONFIG_MSCC_OCELOT_SWITCH) += mscc_ocelot.o mscc_ocelot-y := \ + ocelot_fdma.o \ ocelot_vsc7514.o \ ocelot_net.o
drivers/net/ethernet/mscc/ocelot_fdma.c new file +894 -0
894 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_fdma.h new file +166 -0
166 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_net.c +21 -4
@@ -15,6 +15,7 @@#include <net/pkt_cls.h> #include "ocelot.h" #include "ocelot_vcap.h" +#include "ocelot_fdma.h" #define OCELOT_MAC_QUIRKS OCELOT_QUIRK_QSGMII_PORTS_MUST_BE_UP
@@ -457,7 +458,8 @@ static netdev_tx_t ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)int port = priv->chip_port;u32 rew_op =0 ; -if (!ocelot_can_inject (ocelot,0 )) +if (!static_branch_unlikely (&ocelot_fdma_enabled) && + !ocelot_can_inject (ocelot,0 ))return NETDEV_TX_BUSY ;/* Check if timestamping is needed */
@@ -475,9 +477,13 @@ static netdev_tx_t ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev) rew_op =ocelot_ptp_rew_op (skb); } -ocelot_port_inject_frame (ocelot, port,0 , rew_op, skb); +if (static_branch_unlikely (&ocelot_fdma_enabled)) { +ocelot_fdma_inject_frame (ocelot, port, rew_op, skb, dev); + }else { +ocelot_port_inject_frame (ocelot, port,0 , rew_op, skb); -kfree_skb (skb); +consume_skb (skb); + }return NETDEV_TX_OK ; }
@@ -1702,14 +1708,20 @@ int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target,if (err) goto out; +if (ocelot->fdma) +ocelot_fdma_netdev_init (ocelot, dev); + err =register_netdev (dev);if (err) {dev_err (ocelot->dev,"register_netdev failed\n" ); - goto out; + goto out_fdma_deinit; }return 0 ; +out_fdma_deinit: +if (ocelot->fdma) +ocelot_fdma_netdev_deinit (ocelot, dev); out: ocelot->ports[port] =NULL ;free_netdev (dev);
@@ -1722,9 +1734,14 @@ void ocelot_release_port(struct ocelot_port *ocelot_port)struct ocelot_port_private *priv =container_of (ocelot_port, struct ocelot_port_private, port); +struct ocelot *ocelot = ocelot_port->ocelot; +struct ocelot_fdma *fdma = ocelot->fdma;unregister_netdev (priv->dev); +if (fdma) +ocelot_fdma_netdev_deinit (ocelot, priv->dev); +if (priv->phylink) {rtnl_lock ();phylink_disconnect_phy (priv->phylink);
drivers/net/ethernet/mscc/ocelot_vsc7514.c +10 -0
@@ -19,6 +19,7 @@#include <soc/mscc/ocelot_vcap.h> #include <soc/mscc/ocelot_hsio.h> #include <soc/mscc/vsc7514_regs.h> +#include "ocelot_fdma.h" #include "ocelot.h" #define VSC7514_VCAP_POLICER_BASE 128
@@ -550,6 +551,7 @@ static int mscc_ocelot_probe(struct platform_device *pdev) { S1, "s1" }, { S2, "s2" }, { PTP, "ptp", 1 }, + { FDMA, "fdma", 1 }, };if (!np && !pdev->dev.platform_data)
@@ -585,6 +587,9 @@ static int mscc_ocelot_probe(struct platform_device *pdev) ocelot->targets[io_target[i].id] = target; } +if (ocelot->targets[FDMA ]) +ocelot_fdma_init (pdev, ocelot); + hsio =syscon_regmap_lookup_by_compatible ("mscc,ocelot-hsio" );if (IS_ERR (hsio)) {dev_err (&pdev->dev,"missing hsio syscon\n" );
@@ -648,6 +653,9 @@ static int mscc_ocelot_probe(struct platform_device *pdev)if (err) goto out_ocelot_devlink_unregister; +if (ocelot->fdma) +ocelot_fdma_start (ocelot); + err =ocelot_devlink_sb_register (ocelot);if (err) goto out_ocelot_release_ports;
@@ -688,6 +696,8 @@ static int mscc_ocelot_remove(struct platform_device *pdev) {struct ocelot *ocelot =platform_get_drvdata (pdev); +if (ocelot->fdma) +ocelot_fdma_deinit (ocelot);devlink_unregister (ocelot->devlink);ocelot_deinit_timestamp (ocelot);ocelot_devlink_sb_unregister (ocelot);
include/soc/mscc/ocelot.h +3 -0
@@ -118,6 +118,7 @@ enum ocelot_target {S2 ,HSIO ,PTP , +FDMA ,GCB ,DEV_GMII , TARGET_MAX,
@@ -732,6 +733,8 @@ struct ocelot {/* Protects the PTP clock */ spinlock_t ptp_clock_lock;struct ptp_pin_desc ptp_pins[OCELOT_PTP_PINS_NUM ]; + +struct ocelot_fdma *fdma; };struct ocelot_policer {
Signature · 1 line
2.34.1
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Thu, 9 Dec 2021 16:49:07 +0100 you wrote:
This series adds support for the Frame DMA present on the VSC7514 switch. The FDMA is able to extract and inject packets on the various ethernet interfaces present on the switch.
------------------
Changes in V8:
- Rebase on net-next/master[...]
Here is the summary with links:
- [net-next,v8,1/4] net: ocelot: export ocelot_ifh_port_set() to setup IFH
https://git.kernel.org/netdev/net-next/c/e5150f00721f - [net-next,v8,2/4] net: ocelot: add and export ocelot_ptp_rx_timestamp() https://git.kernel.org/netdev/net-next/c/b471a71e525c - [net-next,v8,3/4] net: ocelot: add support for ndo_change_mtu https://git.kernel.org/netdev/net-next/c/de5841e1c93f - [net-next,v8,4/4] net: ocelot: add FDMA support https://git.kernel.org/netdev/net-next/c/753a026cfec1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html