Skip to contentSkip to conversation

net: ethernet: mtk_eth_soc: add code for offloading flows from wlan devices

PATCH Superseded Felix Fietkau 2 participants 11 messages Mar 21, 2023 – Mar 22, 2023

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
author maintainer
#1 lore raw

PATCH 2/2 net: ethernet: mediatek: mtk_ppe: prefer newly added l2 flows over existing ones

In reply to 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.

---
 drivers/net/ethernet/mediatek/mtk_ppe.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_ppe.c +12 -2
index 6883eb34cd8b..5e150007bb7d 100644
@@ -580,10 +580,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

Felix Fietkau

author maintainer
#0 lore raw

PATCH 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.

---
 drivers/net/ethernet/mediatek/mtk_eth_soc.h   |   3 +
 .../net/ethernet/mediatek/mtk_ppe_offload.c   |  37 ++++---
 drivers/net/ethernet/mediatek/mtk_wed.c       | 104 ++++++++++++++++++
 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
index 084a6badef6d..f7092b532643 100644
@@ -1322,6 +1322,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
index 81afd5ee3fbf..0c5e049b8141 100644
@@ -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)
@@ -512,25 +514,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);
@@ -547,6 +539,23 @@ mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_pri
 	return 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 = netdev_priv(dev);
+	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 +104 -0

128 lines not on this page · raw message

include/linux/soc/mediatek/mtk_wed.h +6 -0
index fd0b0605cf90..b2b28180dff7 100644
@@ -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
#2 lore raw

Re: [PATCH net-next 2/2] net: ethernet: mediatek: mtk_ppe: prefer newly added l2 flows over existing ones

In reply to Felix Fietkau
Quoted 3 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.

As per patch 1/2. checkpatch complains that the patch description has lines more than 75 characters long.

That aside, this change looks good to me.
But I'm wondering if it is fixing a bug.
Or just improving something suboptimal (form a user experience POV).

Quoted 37 lines
---
 drivers/net/ethernet/mediatek/mtk_ppe.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_ppe.c +12 -2
index 6883eb34cd8b..5e150007bb7d 100644
@@ -580,10 +580,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
#5 lore raw
In reply to Felix Fietkau
Quoted 7 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_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.

Hi Felix,

A few nits from my side.

First, please reformat the patch description to have a maximum of 75 characters per line, as suggested by checkpatch.

...

Quoted 30 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +3 -13
@@ -512,25 +514,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);

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 548

Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +7 -0
@@ -547,6 +539,23 @@ mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_pri
 	return 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 = netdev_priv(dev);
+	struct mtk_eth *eth = mac->hw;

Reverse xmas tree - longest line to shortest -
for local variable declarations please.

Quoted 18 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
index 95d890870984..30fe1281d2d3 100644

...

Quoted 8 lines
drivers/net/ethernet/mediatek/mtk_wed.c +4 -0
@@ -1745,6 +1752,102 @@ void mtk_wed_flow_remove(int index)
 	mutex_unlock(&hw_lock);
 }
 
+static int
+mtk_wed_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
+{
+	struct mtk_wed_flow_block_priv *priv = cb_priv;

drivers/net/ethernet/mediatek/mtk_wed.c void mtk_wed_flow_remove(int index) · line 1768

Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_wed.c +10 -0
+	struct flow_cls_offload *cls = type_data;
+	struct mtk_wed_hw *hw = priv->hw;
+
+	if (!tc_can_offload(priv->dev))
+		return -EOPNOTSUPP;
+
+	if (type != TC_SETUP_CLSFLOWER)
+		return -EOPNOTSUPP;
+
+	return mtk_flow_offload_cmd(hw->eth, cls, hw->index);

This seems very similar to mtk_eth_setup_tc_block_cb(). Can further consolidation be considered?

Quoted 16 lines
drivers/net/ethernet/mediatek/mtk_wed.c +16 -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;
+	flow_setup_cb_t *cb;
+
+	if (!eth->soc->offload_version)
+		return -EOPNOTSUPP;
+

drivers/net/ethernet/mediatek/mtk_wed.c void mtk_wed_flow_remove(int index) · line 1794

Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_wed.c +10 -0
+	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) {

I wonder if this could be written more idiomatically as:

		if (block_cb) {
			flow_block_cb_incref(block_cb);
			return 0;
		}

		priv = kzalloc(sizeof(*priv), GFP_KERNEL);
		...
Quoted 37 lines
drivers/net/ethernet/mediatek/mtk_wed.c +37 -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);
+			}
+
+			register_block = true;
+		}
+
+		flow_block_cb_incref(block_cb);
+
+		if (register_block) {
+			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;
+	}
+}

...

Quoted 1 line
include/linux/soc/mediatek/mtk_wed.h +0 -0

...

include/linux/soc/mediatek/mtk_wed.h mtk_wed_get_rx_capa(struct mtk_wed_device *dev) · line 244

Quoted 6 lines
include/linux/soc/mediatek/mtk_wed.h +2 -0
@@ -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)

nit: checkpatch says:

include/linux/soc/mediatek/mtk_wed.h:243: ERROR: Macros with complex values should be enclosed in parentheses +#define mtk_wed_device_setup_tc(_dev, _netdev, _type, _type_data) \
+ (_dev)->ops->setup_tc(_dev, _netdev, _type, _type_data)

include/linux/soc/mediatek/mtk_wed.h:243: CHECK: Macro argument reuse '_dev' - possible side-effects? +#define mtk_wed_device_setup_tc(_dev, _netdev, _type, _type_data) \
+ (_dev)->ops->setup_tc(_dev, _netdev, _type, _type_data)

Quoted 3 lines
include/linux/soc/mediatek/mtk_wed.h +0 -0
 #else
 static inline bool mtk_wed_device_active(struct mtk_wed_device *dev)
 {
#6 lore raw
Quoted 9 lines · Simon Horman
Quoted 7 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_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.

Quoted 8 lines

Hi Felix,

A few nits from my side.

First, please reformat the patch description to have a maximum of 75 characters per line, as suggested by checkpatch.

...

One more.

This seems to conflict with:

[PATCH net 1/2] net: ethernet: mtk_eth_soc: fix flow block

So I guess this series needs to be rebased on that one one at some point.

author maintainer
#3 lore raw

Re: [PATCH net-next 2/2] net: ethernet: mediatek: mtk_ppe: prefer newly added l2 flows over existing ones

In reply to Simon Horman
Quoted 7 lines · Simon Horman
Quoted 3 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.

As per patch 1/2. checkpatch complains that the patch description has lines more than 75 characters long.

Will do.

Quoted 3 lines

That aside, this change looks good to me.
But I'm wondering if it is fixing a bug.
Or just improving something suboptimal (form a user experience POV).

In my opinion, this is just an improvement, not a bugfix.

Thanks,

- Felix

author maintainer
#9 lore raw
In reply to Simon Horman
Quoted 7 lines · Simon Horman
Quoted 6 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_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.

Quoted 8 lines
Quoted 1 line

Hi Felix,

A few nits from my side.

First, please reformat the patch description to have a maximum of 75 characters per line, as suggested by checkpatch.

Will do

Quoted 33 lines
Quoted 33 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +3 -13
@@ -512,25 +514,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);
@@ -547,6 +539,23 @@ mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_pri
 	return err;
 }
 
Quoted 10 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 548

Quoted 7 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +7 -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 net_device *dev = cb_priv;
+	struct mtk_mac *mac = netdev_priv(dev);
+	struct mtk_eth *eth = mac->hw;

Reverse xmas tree - longest line to shortest -
for local variable declarations please.

Will do.

Quoted 20 lines
Quoted 4 lines
drivers/net/ethernet/mediatek/mtk_wed.c +0 -0
index 95d890870984..30fe1281d2d3 100644

...

Quoted 13 lines
drivers/net/ethernet/mediatek/mtk_wed.c +9 -0
@@ -1745,6 +1752,102 @@ void mtk_wed_flow_remove(int index)
 	mutex_unlock(&hw_lock);
 }
 
+static int
+mtk_wed_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
+{
+	struct mtk_wed_flow_block_priv *priv = cb_priv;
+	struct flow_cls_offload *cls = type_data;
+	struct mtk_wed_hw *hw = priv->hw;
+
+	if (!tc_can_offload(priv->dev))
+		return -EOPNOTSUPP;
Quoted 8 lines

drivers/net/ethernet/mediatek/mtk_wed.c void mtk_wed_flow_remove(int index) · line 1768

Quoted 5 lines
drivers/net/ethernet/mediatek/mtk_wed.c +5 -0
+
+	if (type != TC_SETUP_CLSFLOWER)
+		return -EOPNOTSUPP;
+
+	return mtk_flow_offload_cmd(hw->eth, cls, hw->index);

This seems very similar to mtk_eth_setup_tc_block_cb(). Can further consolidation be considered?

It's similar, but using different data structures and pointer chains. Consolidation does not make sense here.

Quoted 29 lines
Quoted 16 lines
drivers/net/ethernet/mediatek/mtk_wed.c +16 -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;
+	flow_setup_cb_t *cb;
+
+	if (!eth->soc->offload_version)
+		return -EOPNOTSUPP;
+

drivers/net/ethernet/mediatek/mtk_wed.c void mtk_wed_flow_remove(int index) · line 1794

Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_wed.c +10 -0
+	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) {

I wonder if this could be written more idiomatically as:

Quoted 6 lines
		if (block_cb) {
			flow_block_cb_incref(block_cb);
			return 0;
		}

		priv = kzalloc(sizeof(*priv), GFP_KERNEL);

flow_block_cb_incref needs to be called for the newly allocated flow block cb as well. I was following the same pattern that several

Quoted 18 lines
Quoted 1 line
include/linux/soc/mediatek/mtk_wed.h +0 -0

...

include/linux/soc/mediatek/mtk_wed.h mtk_wed_get_rx_capa(struct mtk_wed_device *dev) · line 244

Quoted 6 lines
include/linux/soc/mediatek/mtk_wed.h +2 -0
@@ -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)

nit: checkpatch says:

include/linux/soc/mediatek/mtk_wed.h:243: ERROR: Macros with complex values should be enclosed in parentheses

include/linux/soc/mediatek/mtk_wed.h +2 -0
+#define mtk_wed_device_setup_tc(_dev, _netdev, _type, _type_data) \
+	(_dev)->ops->setup_tc(_dev, _netdev, _type, _type_data)

include/linux/soc/mediatek/mtk_wed.h:243: CHECK: Macro argument reuse '_dev' - possible side-effects?

include/linux/soc/mediatek/mtk_wed.h mtk_wed_get_rx_capa(struct mtk_wed_device *dev) · line 244

Quoted 2 lines
include/linux/soc/mediatek/mtk_wed.h +2 -0
+#define mtk_wed_device_setup_tc(_dev, _netdev, _type, _type_data) \
+	(_dev)->ops->setup_tc(_dev, _netdev, _type, _type_data)

In my opinion that's a false positive. The newly added macros follow the same pattern as the existing ones.

Thanks,

- Felix

author maintainer
#7 lore raw
In reply to Simon Horman
Quoted 19 lines · Simon Horman
Quoted 9 lines · Simon Horman
Quoted 7 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_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.

Quoted 8 lines

Hi Felix,

A few nits from my side.

First, please reformat the patch description to have a maximum of 75 characters per line, as suggested by checkpatch.

...

Quoted 7 lines

One more.

This seems to conflict with:

[PATCH net 1/2] net: ethernet: mtk_eth_soc: fix flow block

So I guess this series needs to be rebased on that one one at some point.

I don't think this conflicts. My local rebase tests didn't show any issues either.

- Felix

#4 lore raw

Re: [PATCH net-next 2/2] net: ethernet: mediatek: mtk_ppe: prefer newly added l2 flows over existing ones

In reply to Felix Fietkau
Quoted 6 lines · Felix Fietkau
Quoted 5 lines · Simon Horman
Quoted 3 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.

Quoted 8 lines
Quoted 2 lines

As per patch 1/2. checkpatch complains that the patch description has lines more than 75 characters long.

Will do.

Quoted 3 lines

That aside, this change looks good to me.
But I'm wondering if it is fixing a bug.
Or just improving something suboptimal (form a user experience POV).

In my opinion, this is just an improvement, not a bugfix.

Sure, thanks for the clarification.

#8 lore raw
In reply to Felix Fietkau
Quoted 22 lines · Felix Fietkau
Quoted 21 lines · Simon Horman
Quoted 9 lines · Simon Horman
Quoted 7 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_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.

Quoted 8 lines

Hi Felix,

A few nits from my side.

First, please reformat the patch description to have a maximum of 75 characters per line, as suggested by checkpatch.

...

One more.

Quoted 7 lines
Quoted 5 lines

This seems to conflict with:

[PATCH net 1/2] net: ethernet: mtk_eth_soc: fix flow block

So I guess this series needs to be rebased on that one one at some point.

I don't think this conflicts. My local rebase tests didn't show any issues either.

Ok, sorry for the noise there.
I must have messed something up when I checked earlier.

#10 lore raw
In reply to Felix Fietkau
Quoted 86 lines · Felix Fietkau
Quoted 7 lines · Simon Horman
Quoted 6 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_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.

Quoted 8 lines
Quoted 1 line

Hi Felix,

A few nits from my side.

First, please reformat the patch description to have a maximum of 75 characters per line, as suggested by checkpatch.

Will do

Quoted 31 lines
Quoted 31 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +5 -13
@@ -512,25 +514,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);
@@ -547,6 +539,23 @@ mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_pri
 	return err;
 }
+static int
+mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
Quoted 8 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 548

Quoted 5 lines
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +5 -0
+{
+	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;

Reverse xmas tree - longest line to shortest -
for local variable declarations please.

Will do.

Quoted 19 lines
Quoted 4 lines
drivers/net/ethernet/mediatek/mtk_wed.c +0 -0
index 95d890870984..30fe1281d2d3 100644

...

Quoted 12 lines
drivers/net/ethernet/mediatek/mtk_wed.c +9 -0
@@ -1745,6 +1752,102 @@ void mtk_wed_flow_remove(int index)
 	mutex_unlock(&hw_lock);
 }
+static int
+mtk_wed_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
+{
+	struct mtk_wed_flow_block_priv *priv = cb_priv;
+	struct flow_cls_offload *cls = type_data;
+	struct mtk_wed_hw *hw = priv->hw;
+
+	if (!tc_can_offload(priv->dev))
+		return -EOPNOTSUPP;
Quoted 8 lines

drivers/net/ethernet/mediatek/mtk_wed.c void mtk_wed_flow_remove(int index) · line 1768

Quoted 5 lines
drivers/net/ethernet/mediatek/mtk_wed.c +5 -0
+
+	if (type != TC_SETUP_CLSFLOWER)
+		return -EOPNOTSUPP;
+
+	return mtk_flow_offload_cmd(hw->eth, cls, hw->index);

This seems very similar to mtk_eth_setup_tc_block_cb(). Can further consolidation be considered?

Quoted 2 lines

It's similar, but using different data structures and pointer chains. Consolidation does not make sense here.

Thanks, I see that now.

Quoted 29 lines
Quoted 29 lines
Quoted 16 lines
drivers/net/ethernet/mediatek/mtk_wed.c +16 -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;
+	flow_setup_cb_t *cb;
+
+	if (!eth->soc->offload_version)
+		return -EOPNOTSUPP;
+

drivers/net/ethernet/mediatek/mtk_wed.c void mtk_wed_flow_remove(int index) · line 1794

Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_wed.c +10 -0
+	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) {

I wonder if this could be written more idiomatically as:

Quoted 8 lines
Quoted 6 lines
		if (block_cb) {
			flow_block_cb_incref(block_cb);
			return 0;
		}

		priv = kzalloc(sizeof(*priv), GFP_KERNEL);

flow_block_cb_incref needs to be called for the newly allocated flow block cb as well. I was following the same pattern that several

I guess that to some extent it is a question of style. It seems to me that having separate calls to flow_block_cb_incref() for the different cases leads to nicer, and less indented, code.

But its just a suggestion from my side.

Quoted 17 lines
Quoted 17 lines
Quoted 1 line
include/linux/soc/mediatek/mtk_wed.h +0 -0

...

include/linux/soc/mediatek/mtk_wed.h mtk_wed_get_rx_capa(struct mtk_wed_device *dev) · line 244

Quoted 6 lines
include/linux/soc/mediatek/mtk_wed.h +2 -0
@@ -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)

nit: checkpatch says:

include/linux/soc/mediatek/mtk_wed.h:243: ERROR: Macros with complex values should be enclosed in parentheses

include/linux/soc/mediatek/mtk_wed.h +2 -0
+#define mtk_wed_device_setup_tc(_dev, _netdev, _type, _type_data) \
+	(_dev)->ops->setup_tc(_dev, _netdev, _type, _type_data)
Quoted 5 lines

include/linux/soc/mediatek/mtk_wed.h mtk_wed_get_rx_capa(struct mtk_wed_device *dev) · line 244

Quoted 3 lines

include/linux/soc/mediatek/mtk_wed.h:243: CHECK: Macro argument reuse '_dev' - possible side-effects?

include/linux/soc/mediatek/mtk_wed.h +2 -0
+#define mtk_wed_device_setup_tc(_dev, _netdev, _type, _type_data) \
+	(_dev)->ops->setup_tc(_dev, _netdev, _type, _type_data)

In my opinion that's a false positive. The newly added macros follow the same pattern as the existing ones.

Ack.