net: ethernet: mtk_eth_soc: add code for offloading flows from wlan devices
Subsystems (4)
Felix Fietkau
maintainerPATCH v3 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.
---
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 | 37 ++++--- drivers/net/ethernet/mediatek/mtk_wed.c | 102 ++++++++++++++++++ include/linux/soc/mediatek/mtk_wed.h | 6 ++ 4 files changed, 134 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 +23 -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,23 @@ 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 mtk_mac *mac =netdev_priv (dev); +struct net_device *dev = cb_priv; +struct mtk_eth *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 +102 -0
126 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 v3 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
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]>
...
Quoted 1 line
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +0
-0
...
drivers/net/ethernet/mediatek/mtk_ppe_offload.c mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_pri · line 554
Quoted 5 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +5
-0+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 mtk_mac *mac =netdev_priv (dev);
This does not compile because dev is undefined at this point.
drivers/net/ethernet/mediatek/mtk_ppe_offload.c mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_pri · line 556
Quoted 2 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +2
-0+struct net_device *dev = cb_priv; +struct mtk_eth *eth = mac->hw;
I would suggest something like this:
struct flow_cls_offload *cls = type_data;
struct net_device *dev = cb_priv;
struct mtk_mac *mac;
struct mtk_eth *eth;
mac = netdev_priv(cb_priv);
eth = mac->hw;Quoted 14 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +10
-0+ +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 +0
-0
...
drivers/net/ethernet/mediatek/mtk_wed.c void mtk_wed_flow_remove(int index) · line 1779
Quoted 9 lines
drivers/net/ethernet/mediatek/mtk_wed.c +9
-0+static int +mtk_wed_setup_tc_block (struct mtk_wed_hw *hw,struct net_device *dev, +struct flow_block_offload *f) +{ +struct mtk_wed_flow_block_priv *priv; +static LIST_HEAD (block_cb_list); +struct flow_block_cb *block_cb; +struct mtk_eth *eth = hw->eth; +bool register_block = false;
gcc-12 with W=1 tellsme that register_block is unused. It should be removed.
Quoted 50 lines
drivers/net/ethernet/mediatek/mtk_wed.c +50
-0+flow_setup_cb_t *cb; + +if (!eth->soc->offload_version) +return -EOPNOTSUPP ; + +if (f->binder_type !=FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS ) +return -EOPNOTSUPP ; + + cb = mtk_wed_setup_tc_block_cb; + f->driver_block_list = &block_cb_list; + +switch (f->command) { +case FLOW_BLOCK_BIND : + block_cb =flow_block_cb_lookup (f->block, cb, dev); +if (block_cb) { +flow_block_cb_incref (block_cb); +return 0 ; + } + + priv =kzalloc (sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->hw = hw; + priv->dev = dev; + block_cb =flow_block_cb_alloc (cb, dev, priv,NULL ); +if (IS_ERR (block_cb)) { +kfree (priv); +return PTR_ERR (block_cb); + } + +flow_block_cb_incref (block_cb); +flow_block_cb_add (block_cb, f); +list_add_tail (&block_cb->driver_list, &block_cb_list); +return 0 ; +case FLOW_BLOCK_UNBIND : + block_cb =flow_block_cb_lookup (f->block, cb, dev); +if (!block_cb) +return -ENOENT ; + +if (!flow_block_cb_decref (block_cb)) { +flow_block_cb_remove (block_cb, f); +list_del (&block_cb->driver_list); +kfree (block_cb->cb_priv); + } +return 0 ; +default : +return -EOPNOTSUPP ; + } +}
...
Felix Fietkau
maintainerQuoted 16 lines · Simon Horman
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]>...
Quoted 1 line
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +0
-0...
Quoted 7 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_pri · line 554
Quoted 5 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +5
-0+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 mtk_mac *mac =netdev_priv (dev);This does not compile because dev is undefined at this point.
Yes, I had fixed that, but forgot to amend the commit before sending it out. Sorry about that.
Quoted 14 lines
...
drivers/net/ethernet/mediatek/mtk_ppe_offload.c
Quoted 9 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +9
-0+static int +mtk_wed_setup_tc_block (struct mtk_wed_hw *hw,struct net_device *dev, +struct flow_block_offload *f) +{ +struct mtk_wed_flow_block_priv *priv; +static LIST_HEAD (block_cb_list); +struct flow_block_cb *block_cb; +struct mtk_eth *eth = hw->eth; +bool register_block = false;gcc-12 with W=1 tellsme that
register_blockis unused. It should be removed.
Right. Will send v4 tomorrow.
Thanks,
- Felix
kernel test robot
build botI love your patch! Yet something to improve:
Hi Felix,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Felix-Fietkau/net-ethernet-mtk_eth_soc-mtk_ppe-prefer-newly-added-l2-flows/20230331-204831 patch link: https://lore.kernel.org/r/20230331124707.40296-1-nbd%40nbd.name patch subject: [PATCH v3 net-next 1/2] net: ethernet: mtk_eth_soc: add code for offloading flows from wlan devices config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20230401/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 67409911353323ca5edf2049ef0df54132fa1ca7)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/6b34c03bc2f53e9370621f04e2925d2ccb41ce7b
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Felix-Fietkau/net-ethernet-mtk_eth_soc-mtk_ppe-prefer-newly-added-l2-flows/20230331-204831 git checkout 6b34c03bc2f53e9370621f04e2925d2ccb41ce7b
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/net/ethernet/mediatek/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/net/ethernet/mediatek/mtk_ppe_offload.c:554:36: error: use of undeclared identifier 'dev'
struct mtk_mac *mac = netdev_priv(dev);
^1 error generated.
vim +/dev +554 drivers/net/ethernet/mediatek/mtk_ppe_offload.c
549
550 static int
551 mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
552 {
553 struct flow_cls_offload *cls = type_data;
> 554 struct mtk_mac *mac = netdev_priv(dev);
555 struct net_device *dev = cb_priv;
556 struct mtk_eth *eth = mac->hw;
557
558 if (!tc_can_offload(dev))
559 return -EOPNOTSUPP;
560
561 if (type != TC_SETUP_CLSFLOWER)
562 return -EOPNOTSUPP;
563
564 return mtk_flow_offload_cmd(eth, cls, 0);
565 }
566
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests