[PATCH RFC net-next 15/19] net: dsa: tag_mtk: add GRO callbacks

From: Alexander Lobakin
Date: Mon Dec 30 2019 - 09:32:39 EST


Make GRO available for frames with MTK tag by adding the corresponding
callbacks to MTK tagger.

Signed-off-by: Alexander Lobakin <alobakin@xxxxxxxx>
---
net/dsa/tag_mtk.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)

diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index b926ffdf5fb5..13d929160283 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -102,12 +102,85 @@ static void mtk_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
*proto = mtk_tag_encap_proto(skb->data);
}

+static struct sk_buff *mtk_tag_gro_receive(struct list_head *head,
+ struct sk_buff *skb)
+{
+ const struct packet_offload *ptype;
+ struct sk_buff *p, *pp = NULL;
+ u32 data_off, data_end;
+ const u8 *data;
+ int flush = 1;
+
+ data_off = skb_gro_offset(skb);
+ data_end = data_off + MTK_HDR_LEN;
+
+ data = skb_gro_header_fast(skb, data_off);
+ if (skb_gro_header_hard(skb, data_end)) {
+ data = skb_gro_header_slow(skb, data_end, data_off);
+ if (unlikely(!data))
+ goto out;
+ }
+
+ rcu_read_lock();
+
+ ptype = gro_find_receive_by_type(mtk_tag_encap_proto(data));
+ if (!ptype)
+ goto out_unlock;
+
+ flush = 0;
+
+ list_for_each_entry(p, head, list) {
+ if (!NAPI_GRO_CB(p)->same_flow)
+ continue;
+
+ /* Data that is to the left to the current position is already
+ * pulled to the head
+ */
+ if (mtk_tag_source_port(skb->data + data_off) ^
+ mtk_tag_source_port(p->data + data_off))
+ NAPI_GRO_CB(p)->same_flow = 0;
+ }
+
+ skb_gro_pull(skb, MTK_HDR_LEN);
+ skb_gro_postpull_rcsum(skb, data, MTK_HDR_LEN);
+
+ pp = call_gro_receive(ptype->callbacks.gro_receive, head, skb);
+
+out_unlock:
+ rcu_read_unlock();
+out:
+ skb_gro_flush_final(skb, pp, flush);
+
+ return pp;
+}
+
+static int mtk_tag_gro_complete(struct sk_buff *skb, int nhoff)
+{
+ const struct packet_offload *ptype;
+ int err = -ENOENT;
+ __be16 proto;
+
+ proto = mtk_tag_encap_proto(skb->data + nhoff);
+
+ rcu_read_lock();
+
+ ptype = gro_find_complete_by_type(proto);
+ if (ptype)
+ err = ptype->callbacks.gro_complete(skb, nhoff + MTK_HDR_LEN);
+
+ rcu_read_unlock();
+
+ return err;
+}
+
static const struct dsa_device_ops mtk_netdev_ops = {
.name = "mtk",
.proto = DSA_TAG_PROTO_MTK,
.xmit = mtk_tag_xmit,
.rcv = mtk_tag_rcv,
.flow_dissect = mtk_tag_flow_dissect,
+ .gro_receive = mtk_tag_gro_receive,
+ .gro_complete = mtk_tag_gro_complete,
.overhead = MTK_HDR_LEN,
};

--
2.24.1