Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3351338pxf; Mon, 22 Mar 2021 04:34:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydHyc6b7fdg+HpIj0J6NMuUUGC8v2pLuVfhfmWvY4dQ0n/WmyI8uYMgAWm6g+zRNvzQRk8 X-Received: by 2002:a05:6402:510b:: with SMTP id m11mr25482892edd.103.1616412860068; Mon, 22 Mar 2021 04:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616412860; cv=none; d=google.com; s=arc-20160816; b=grzzHSTpCQ7XW1++655sbnvAMGbo5sn8zucyKPYS4O+/cG++4zT46zHKIn7KHDUa/i y7LcdqgDUF6infPgT+WwIMK8NBcxfFPnPGxm4W6AVvZCkt9zA/8jyOBh++AgmY0Io/Lm MIo3Wute1Ehr5xgCL53xo1u5dyMdeIP4h19GqZc9yDmLlT2YukiABCjZeRImrO94SnBg WB8pqV+XkSlbQ1877ZAThBghvX796SsI2kqFx5jiNJtf/33xWD8RO2fRGSKss8txX8JV P7L5sxYeME9xjmqwv2uzJCZ3zNfUrBM0wKLh2RaZhfxLLjwqekLF+gcWLow2ZH2EFxD5 9DrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XYeVx8d4LjQCrMjqtdwToyONIZtgo42NmTTPNbi924c=; b=TJMP32kg3pYKeyfU4SYHdziUoOR5B2qc1C55Z6lYsRbPPKwRa285a4vH/0LxK3KQOG qMoUoUc6yy2kgOFaQamYlYh+zpgFVVesTP4pnimn2ugU2b9ue2VDelVFyr0ign+170dr mfQa5NNBaBs5h6Wk4o2w97P+mfZv6gn+HxZwLIMt7J8lC+Q5C5JOlZHQ1BSL+gFMZ7qS jLiDKig4HS0QDTSHMdDjreCw7HYlP6CWh5XY3MaZYmoLdejxK/u/bS9Mh0BYtjCHPJ9Z /Tp5Zra4fvVH56HM7Za+EpbfitUzLOI44/BMyhG1AgWb5mz0KmZ/6da3D/SK8hxiXK37 iq4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mailerdienst.de header.s=20200217 header.b=ug9Ij2wq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j13si11036318edn.369.2021.03.22.04.33.57; Mon, 22 Mar 2021 04:34:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mailerdienst.de header.s=20200217 header.b=ug9Ij2wq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbhCVLbO (ORCPT + 99 others); Mon, 22 Mar 2021 07:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230085AbhCVLar (ORCPT ); Mon, 22 Mar 2021 07:30:47 -0400 Received: from mxwww.masterlogin.de (mxwww.masterlogin.de [IPv6:2a03:2900:1:1::a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FDC9C061574; Mon, 22 Mar 2021 04:30:46 -0700 (PDT) Received: from mxout4.routing.net (unknown [192.168.10.112]) by backup.mxwww.masterlogin.de (Postfix) with ESMTPS id E889C2C51F; Mon, 22 Mar 2021 11:21:46 +0000 (UTC) Received: from mxbox3.masterlogin.de (unknown [192.168.10.78]) by mxout4.routing.net (Postfix) with ESMTP id 692E51007B4; Mon, 22 Mar 2021 11:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailerdienst.de; s=20200217; t=1616412101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XYeVx8d4LjQCrMjqtdwToyONIZtgo42NmTTPNbi924c=; b=ug9Ij2wqVs5oPGAjn8m8HMPznXHwXLmTNqJMlob3uRaB5fQPY/2E12aV+pZc65+yxC+9RN WubOvEBS1NhliP5ZGYApPt/8Jl9tPaMzERFP8zbW/sEE+W6xkM8Fv3SKrKtqSpskAZTkmf aZAiDp/JC2BNK0qNoJQZnAU1d7JKV6c= Received: from localhost.localdomain (unknown [80.245.73.88]) by mxbox3.masterlogin.de (Postfix) with ESMTPSA id B761436010D; Mon, 22 Mar 2021 11:21:40 +0000 (UTC) From: Frank Wunderlich To: linux-mediatek@lists.infradead.org Cc: Frank Wunderlich , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , "David S. Miller" , Jakub Kicinski , Matthias Brugger , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] [RFC] net: ethernet: mtk_eth_soc: add ipv6 flow offload support Date: Mon, 22 Mar 2021 12:21:17 +0100 Message-Id: <20210322112117.16162-3-linux@fw-web.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210322112117.16162-1-linux@fw-web.de> References: <20210322112117.16162-1-linux@fw-web.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mail-ID: ce223c4d-bd77-4263-a479-9b2339e766b7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Frank Wunderlich adding ipv6 hardware offload support patch by user graphine (https://github.com/graphine27/) http://forum.banana-pi.org/u/graphine/summary Signed-off-by: Frank Wunderlich --- .../net/ethernet/mediatek/mtk_ppe_offload.c | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c index d0c46786571f..29cf0eb25a22 100644 --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,11 @@ struct mtk_flow_data { __be32 src_addr; __be32 dst_addr; } v4; + + struct { + struct in6_addr src_addr; + struct in6_addr dst_addr; + } v6; }; __be16 src_port; @@ -64,6 +70,14 @@ mtk_flow_set_ipv4_addr(struct mtk_foe_entry *foe, struct mtk_flow_data *data, data->v4.dst_addr, data->dst_port); } +static int +mtk_flow_set_ipv6_addr(struct mtk_foe_entry *foe, struct mtk_flow_data *data) +{ + return mtk_foe_entry_set_ipv6_tuple(foe, + data->v6.src_addr.s6_addr32, data->src_port, + data->v6.dst_addr.s6_addr32, data->dst_port); +} + static void mtk_flow_offload_mangle_eth(const struct flow_action_entry *act, void *eth) { @@ -127,6 +141,29 @@ mtk_flow_mangle_ipv4(const struct flow_action_entry *act, return 0; } +static int +mtk_flow_mangle_ipv6(const struct flow_action_entry *act, + struct mtk_flow_data *data) +{ + __be32 *dest; + size_t offset_of_ip6_daddr = offsetof(struct ipv6hdr, daddr); + size_t offset_of_ip6_saddr = offsetof(struct ipv6hdr, saddr); + u32 idx; + + if (act->mangle.offset >= offset_of_ip6_daddr && act->mangle.offset < offset_of_ip6_daddr) { + idx = (act->mangle.offset - offset_of_ip6_saddr) / 4; + dest = &data->v6.src_addr.s6_addr32[idx]; + } else if (act->mangle.offset >= offset_of_ip6_daddr && + act->mangle.offset < offset_of_ip6_daddr + 16) { + idx = (act->mangle.offset - offset_of_ip6_daddr) / 4; + dest = &data->v6.dst_addr.s6_addr32[idx]; + } + + memcpy(dest, &act->mangle.val, sizeof(u32)); + + return 0; +} + static int mtk_flow_get_dsa_port(struct net_device **dev) { @@ -249,6 +286,9 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f) case FLOW_DISSECTOR_KEY_IPV4_ADDRS: offload_type = MTK_PPE_PKT_TYPE_IPV4_HNAPT; break; + case FLOW_DISSECTOR_KEY_IPV6_ADDRS: + offload_type = MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T; + break; default: return -EOPNOTSUPP; } @@ -284,6 +324,18 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f) mtk_flow_set_ipv4_addr(&foe, &data, false); } + + if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) { + struct flow_match_ipv6_addrs addrs; + + flow_rule_match_ipv6_addrs(rule, &addrs); + + data.v6.src_addr = addrs.key->src; + data.v6.dst_addr = addrs.key->dst; + + mtk_flow_set_ipv6_addr(&foe, &data); + } + flow_action_for_each(i, act, &rule->action) { if (act->id != FLOW_ACTION_MANGLE) continue; @@ -296,6 +348,9 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f) case FLOW_ACT_MANGLE_HDR_TYPE_IP4: err = mtk_flow_mangle_ipv4(act, &data); break; + case FLOW_ACT_MANGLE_HDR_TYPE_IP6: + err = mtk_flow_mangle_ipv6(act, &data); + break; case FLOW_ACT_MANGLE_HDR_TYPE_ETH: /* handled earlier */ break; -- 2.25.1