Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4364416rwb; Sun, 13 Nov 2022 04:51:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf6j9Bjr02Up2iUGjhO2pN1fxs6kgNttc+LbN9X65t5LZ+pCVoYNdY5cyL010sU+GSRkqHSr X-Received: by 2002:a05:6a00:2190:b0:562:45f0:df50 with SMTP id h16-20020a056a00219000b0056245f0df50mr10380401pfi.16.1668343871128; Sun, 13 Nov 2022 04:51:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668343871; cv=none; d=google.com; s=arc-20160816; b=UMuNOSjtUC5x6NSAmo6vIwCaIMfNUBcZVwrt2Kj53Xi7XXQKtdWF9vlt+6f7asjI9o 3q+uP1kNy8PuyjPJKnjI5OaEl69VVoZWzyH80+zYpMGybf3UpTuhMVkYs4jJvYXpHw6C msQeAPKacgIHFeQFzt1y+HjptGS0dGXeFW00+lBphb9RyzeSNwDaj/JP+hNfHdOsP192 4kr+hPPDheaBQp41sPhpQWDcVyJOTIscIFl+NYTGsg2npURG/XfCoAmAmcTNZF4ndXIQ Qr6H8c0J16R0lH5LRXFz9981Ve8+0e9DbxRIaY4dN5aKrogt+LVXsqLctpRiiXvNOaRC 5daw== 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=4+gp0RgXS5n4IYmjj7OoZhp1+2rBCD3gvw1LFsaYq0A=; b=BR1VhVY3NObGZeHPCN+XgsigTUeME/7DCeJbAqbGCr3YNRKggC+OPL74RuLU0++c/a ZFwh1GiCKJE3Zngm1xD1OqTBRIN7x0KCjnmf7SZROSh3YJ3CpbTQn34ULwwlcTMrs0zG J9KpgvkvYnM8J/n9S4wcv40MOZyrKnWdxhCXHp1rRD1SZ98XGeaFFR46fbS3MbUvnvat RQK/OpWhjBbLeU9OEJDLz6TMLJI5MsstnDCzWVqiKnL3D/Pj9z3zF/h3P9uaKG5CdUVL mDAVQ1eK/pZB/pNOAJcUryqpQjB2lb0e6gIsOQ0HhggQNn80XZcD5FpMQ7TW12XMZgV7 FaNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=zCIoDD4t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cp8-20020a056a00348800b0054252c63d75si6581665pfb.98.2022.11.13.04.50.59; Sun, 13 Nov 2022 04:51:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=zCIoDD4t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232676AbiKMLNA (ORCPT + 89 others); Sun, 13 Nov 2022 06:13:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235326AbiKMLMo (ORCPT ); Sun, 13 Nov 2022 06:12:44 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA62113DD8; Sun, 13 Nov 2022 03:12:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1668337952; x=1699873952; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y3OtMKzhRZ8Kbbh523DkZkeqZ1JmNxHeI5Ulg2C2sds=; b=zCIoDD4t7P01MX3nD1k7nTHp8+a7vVmbgE5s1zWjgAwfe2EnffAjTobA RC9UI7kVCUui3ryFF5XB/4V0fv/YEqTP52zrY0aomoF9/QAfOlNOzFnqn MgPrkImGgyI4vHzORDSCAFaroPGKliZPiUVC60wOCccBBEhbMV1nWq7B2 NRGV/TnHLG9H84Gxwqo+ptvSo3cP42MxbD7H67FpttMW6+vLZ5GoUuf90 dX9zMe97iPOQcKjw7Za5mplhaJnTSL5A/Ng8F4S3/mENQ/9jahczH7Qtw bhQYyL4UTBwRvyeQEk9IaO5NLhTuX5HHlYtu2EOufNicZFBO4lTBf3vnl w==; X-IronPort-AV: E=Sophos;i="5.96,161,1665471600"; d="scan'208";a="183271868" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Nov 2022 04:12:31 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Sun, 13 Nov 2022 04:12:31 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Sun, 13 Nov 2022 04:12:28 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next 5/5] net: lan966x: Add support for XDP_REDIRECT Date: Sun, 13 Nov 2022 12:15:59 +0100 Message-ID: <20221113111559.1028030-6-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221113111559.1028030-1-horatiu.vultur@microchip.com> References: <20221113111559.1028030-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Extend lan966x XDP support with the action XDP_REDIRECT. This is similar with the XDP_TX, so a lot of functionality can be reused. Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 9 ++++++ .../ethernet/microchip/lan966x/lan966x_main.c | 1 + .../ethernet/microchip/lan966x/lan966x_main.h | 6 ++++ .../ethernet/microchip/lan966x/lan966x_xdp.c | 28 +++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index a177ca499db4e..18de2880e202c 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ #include +#include #include "lan966x_main.h" @@ -520,6 +521,7 @@ static int lan966x_fdma_napi_poll(struct napi_struct *napi, int weight) int dcb_reload = rx->dcb_index; struct lan966x_rx_dcb *old_dcb; struct lan966x_db *db; + bool redirect = false; struct sk_buff *skb; struct page *page; int counter = 0; @@ -545,6 +547,10 @@ static int lan966x_fdma_napi_poll(struct napi_struct *napi, int weight) case FDMA_TX: lan966x_fdma_rx_advance_dcb(rx); continue; + case FDMA_REDIRECT: + lan966x_fdma_rx_advance_dcb(rx); + redirect = true; + continue; case FDMA_DROP: lan966x_fdma_rx_free_page(rx); lan966x_fdma_rx_advance_dcb(rx); @@ -581,6 +587,9 @@ static int lan966x_fdma_napi_poll(struct napi_struct *napi, int weight) if (counter < weight && napi_complete_done(napi, counter)) lan_wr(0xff, lan966x, FDMA_INTR_DB_ENA); + if (redirect) + xdp_do_flush(); + return counter; } diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 0b7707306da26..0aed244826d39 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -469,6 +469,7 @@ static const struct net_device_ops lan966x_port_netdev_ops = { .ndo_eth_ioctl = lan966x_port_ioctl, .ndo_setup_tc = lan966x_tc_setup, .ndo_bpf = lan966x_xdp, + .ndo_xdp_xmit = lan966x_xdp_xmit, }; bool lan966x_netdevice_check(const struct net_device *dev) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index df7fec361962b..b73c5a6cc0beb 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -106,12 +106,14 @@ enum macaccess_entry_type { * FDMA_ERROR, something went wrong, stop getting more frames * FDMA_DROP, frame is dropped, but continue to get more frames * FDMA_TX, frame is given to TX, but continue to get more frames + * FDMA_REDIRECT, frame is given to TX, but continue to get more frames */ enum lan966x_fdma_action { FDMA_PASS = 0, FDMA_ERROR, FDMA_DROP, FDMA_TX, + FDMA_REDIRECT, }; struct lan966x_port; @@ -564,6 +566,10 @@ int lan966x_xdp(struct net_device *dev, struct netdev_bpf *xdp); int lan966x_xdp_run(struct lan966x_port *port, struct page *page, u32 data_len); +int lan966x_xdp_xmit(struct net_device *dev, + int n, + struct xdp_frame **frames, + u32 flags); static inline bool lan966x_xdp_port_present(struct lan966x_port *port) { return !!port->xdp_prog; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c index c7dcb9d443ffa..fbf04a82ef994 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c @@ -35,6 +35,29 @@ int lan966x_xdp(struct net_device *dev, struct netdev_bpf *xdp) } } +int lan966x_xdp_xmit(struct net_device *dev, + int n, + struct xdp_frame **frames, + u32 flags) +{ + struct lan966x_port *port = netdev_priv(dev); + int i, nxmit = 0; + + for (i = 0; i < n; ++i) { + struct xdp_frame *xdpf = frames[i]; + int err; + + err = lan966x_fdma_xmit_xdpf(port, xdpf, + virt_to_head_page(xdpf->data)); + if (err) + break; + + nxmit++; + } + + return nxmit; +} + int lan966x_xdp_run(struct lan966x_port *port, struct page *page, u32 data_len) { struct bpf_prog *xdp_prog = port->xdp_prog; @@ -59,6 +82,11 @@ int lan966x_xdp_run(struct lan966x_port *port, struct page *page, u32 data_len) return lan966x_fdma_xmit_xdpf(port, xdpf, page) ? FDMA_DROP : FDMA_TX; + case XDP_REDIRECT: + if (xdp_do_redirect(port->dev, &xdp, xdp_prog)) + return FDMA_DROP; + + return FDMA_REDIRECT; default: bpf_warn_invalid_xdp_action(port->dev, xdp_prog, act); fallthrough; -- 2.38.0