net: ethernet: mtk_eth_soc: add code for offloading flows from wlan devices
Subsystems (4)
Felix Fietkau
maintainerPATCH v4 1/2 net: ethernet: mtk_eth_soc: add code for offloading flows from wlan devices
WED version 2 (on MT7986 and later) can offload flows originating from wireless devices.
In order to make that work, ndo_setup_tc needs to be implemented on the netdevs. This adds the required code to offload flows coming in from WED, while keeping track of the incoming wed index used for selecting the correct PPE device.
---
v4:
- fix compile error
- properly fix reverse xmas tree issue
- remove unused variable
v3: revert broken last minute reverse xmas tree change v2:
- fix description
- fix reverse xmas tree
- make flow block refcounting more idiomatic
drivers/net/ethernet/mediatek/mtk_eth_soc.h | 3 + .../net/ethernet/mediatek/mtk_ppe_offload.c | 40 ++++--- drivers/net/ethernet/mediatek/mtk_wed.c | 101 ++++++++++++++++++ include/linux/soc/mediatek/mtk_wed.h | 6 ++ 4 files changed, 136 insertions(+), 14 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.h +3 -0
@@ -1276,6 +1276,9 @@ int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);int mtk_eth_offload_init (struct mtk_eth *eth);int mtk_eth_setup_tc (struct net_device *dev,enum tc_setup_type type,void *type_data); +int mtk_flow_offload_cmd (struct mtk_eth *eth,struct flow_cls_offload *cls, +int ppe_index); +void mtk_flow_offload_cleanup (struct mtk_eth *eth,struct list_head *list);void mtk_eth_set_dma_device (struct mtk_eth *eth,struct device *dma_dev);
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +26 -14
@@ -235,7 +235,8 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe, }static int -mtk_flow_offload_replace (struct mtk_eth *eth,struct flow_cls_offload *f) +mtk_flow_offload_replace (struct mtk_eth *eth,struct flow_cls_offload *f, +int ppe_index) {struct flow_rule *rule =flow_cls_offload_flow_rule (f);struct flow_action_entry *act;
@@ -452,6 +453,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f) entry->cookie = f->cookie;memcpy (&entry->data, &foe,sizeof (entry->data)); entry->wed_index = wed_index; + entry->ppe_index = ppe_index; err =mtk_foe_entry_commit (eth->ppe[entry->ppe_index], entry);if (err <0 )
@@ -520,25 +522,15 @@ mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f)static DEFINE_MUTEX (mtk_flow_offload_mutex); -static int -mtk_eth_setup_tc_block_cb (enum tc_setup_type type,void *type_data,void *cb_priv) +int mtk_flow_offload_cmd (struct mtk_eth *eth,struct flow_cls_offload *cls, +int ppe_index) { -struct flow_cls_offload *cls = type_data; -struct net_device *dev = cb_priv; -struct mtk_mac *mac =netdev_priv (dev); -struct mtk_eth *eth = mac->hw;int err; -if (!tc_can_offload (dev)) -return -EOPNOTSUPP ; - -if (type !=TC_SETUP_CLSFLOWER ) -return -EOPNOTSUPP ; -mutex_lock (&mtk_flow_offload_mutex);switch (cls->command) {case FLOW_CLS_REPLACE : - err =mtk_flow_offload_replace (eth, cls); + err =mtk_flow_offload_replace (eth, cls, ppe_index);break ;case FLOW_CLS_DESTROY : err =mtk_flow_offload_destroy (eth, cls);
@@ -555,6 +547,26 @@ mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_prireturn err; } +static int +mtk_eth_setup_tc_block_cb (enum tc_setup_type type,void *type_data,void *cb_priv) +{ +struct flow_cls_offload *cls = type_data; +struct net_device *dev = cb_priv; +struct mtk_mac *mac; +struct mtk_eth *eth; + + mac =netdev_priv (dev); + eth = mac->hw; + +if (!tc_can_offload (dev)) +return -EOPNOTSUPP ; + +if (type !=TC_SETUP_CLSFLOWER ) +return -EOPNOTSUPP ; + +return mtk_flow_offload_cmd (eth, cls,0 ); +} +static int mtk_eth_setup_tc_block (struct net_device *dev,struct flow_block_offload *f) {
drivers/net/ethernet/mediatek/mtk_wed.c +101 -0
125 lines not on this page · raw message
include/linux/soc/mediatek/mtk_wed.h +6 -0
@@ -6,6 +6,7 @@#include <linux/regmap.h> #include <linux/pci.h> #include <linux/skbuff.h> +#include <linux/netdevice.h> #define MTK_WED_TX_QUEUES 2#define MTK_WED_RX_QUEUES 2
@@ -179,6 +180,8 @@ struct mtk_wed_ops {u32 (*irq_get)(struct mtk_wed_device *dev,u32 mask);void (*irq_set_mask)(struct mtk_wed_device *dev,u32 mask); +int (*setup_tc)(struct mtk_wed_device *wed,struct net_device *dev, +enum tc_setup_type type,void *type_data); };extern const struct mtk_wed_ops __rcu *mtk_soc_wed_ops;
@@ -237,6 +240,8 @@ mtk_wed_get_rx_capa(struct mtk_wed_device *dev) (_dev)->ops->msg_update(_dev, _id, _msg, _len)#define mtk_wed_device_stop (_dev) (_dev)->ops->stop(_dev)#define mtk_wed_device_dma_reset (_dev) (_dev)->ops->reset_dma(_dev) +#define mtk_wed_device_setup_tc (_dev, _netdev, _type, _type_data) \ + (_dev)->ops->setup_tc(_dev, _netdev, _type, _type_data)#else static inline bool mtk_wed_device_active (struct mtk_wed_device *dev) {
@@ -255,6 +260,7 @@ static inline bool mtk_wed_device_active(struct mtk_wed_device *dev)#define mtk_wed_device_update_msg (_dev, _id, _msg, _len) -ENODEV#define mtk_wed_device_stop (_dev) do {} while (0)#define mtk_wed_device_dma_reset (_dev) do {} while (0) +#define mtk_wed_device_setup_tc (_dev, _netdev, _type, _type_data) -EOPNOTSUPP#endif #endif
Signature · 1 line
2.39.0
Felix Fietkau
maintainerPATCH v4 2/2 net: ethernet: mtk_eth_soc: mtk_ppe: prefer newly added l2 flows
When a device is roaming between interfaces and a new flow entry is created, we should assume that its output device is more up to date than whatever entry existed already.
---
v2: fix patch description
drivers/net/ethernet/mediatek/mtk_ppe.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_ppe.c +12 -2
@@ -635,10 +635,20 @@ void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)static int mtk_foe_entry_commit_l2 (struct mtk_ppe *ppe,struct mtk_flow_entry *entry) { +struct mtk_flow_entry *prev; + entry->type =MTK_FLOW_TYPE_L2 ; -return rhashtable_insert_fast (&ppe->l2_flows, &entry->l2_node, - mtk_flow_l2_ht_params); + prev =rhashtable_lookup_get_insert_fast (&ppe->l2_flows, &entry->l2_node, + mtk_flow_l2_ht_params); +if (likely (!prev)) +return 0 ; + +if (IS_ERR (prev)) +return PTR_ERR (prev); + +return rhashtable_replace_fast (&ppe->l2_flows, &prev->l2_node, + &entry->l2_node, mtk_flow_l2_ht_params); }int mtk_foe_entry_commit (struct mtk_ppe *ppe,struct mtk_flow_entry *entry)
Signature · 1 line
2.39.0
Re: [PATCH v4 net-next 2/2] net: ethernet: mtk_eth_soc: mtk_ppe: prefer newly added l2 flows
Quoted 5 lines · Felix Fietkau
When a device is roaming between interfaces and a new flow entry is created, we should assume that its output device is more up to date than whatever entry existed already.
Signed-off-by Felix Fietkau <[email protected]>
Quoted 8 lines · Felix Fietkau
WED version 2 (on MT7986 and later) can offload flows originating from wireless devices.
In order to make that work,ndo_setup_tcneeds to be implemented on the netdevs. This adds the required code to offload flows coming in from WED, while keeping track of the incoming wed index used for selecting the correct PPE device.Signed-off-by Felix Fietkau <[email protected]>
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 8 lines · On Wed, 5 Apr 2023 17:10:25 +0200 you wrote:
WED version 2 (on MT7986 and later) can offload flows originating from wireless devices.
In order to make that work,ndo_setup_tcneeds to be implemented on the netdevs. This adds the required code to offload flows coming in from WED, while keeping track of the incoming wed index used for selecting the correct PPE device.[...]
Here is the summary with links:
- [v4,net-next,1/2] net: ethernet: mtk_eth_soc: add code for offloading flows from wlan devices
https://git.kernel.org/netdev/net-next/c/05f3ab7780b3 - [v4,net-next,2/2] net: ethernet: mtk_eth_soc: mtk_ppe: prefer newly added l2 flows https://git.kernel.org/netdev/net-next/c/e28531143b25
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html