From patchwork Mon Nov 21 21:28:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 24015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1843475wrr; Mon, 21 Nov 2022 13:28:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf5pdllBDfzd4Ncidan5cD+JJ/yKNd1zvsgMLy4X+7+tpS026LRo9YF3tdLHmQjeJjeDXlt1 X-Received: by 2002:a50:fc10:0:b0:464:2afe:ae18 with SMTP id i16-20020a50fc10000000b004642afeae18mr18765809edr.183.1669066109015; Mon, 21 Nov 2022 13:28:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669066109; cv=none; d=google.com; s=arc-20160816; b=U9wBrzieYg3otoBMVNxoIdC/m1qYYDjwwo9DeGdrUeBhQ1tqG+ig162PEnvTJ7UkLN 5av+wmtYm5alZAKaUvfMIyyftAxoE3Kxua1Lqws50Vkp9807EBz0olhlNuWDC5ibNmUI 4e5BB7f6nKADaIYv9lIYaQFFb14Qujk2gJYISh3bUXNgmKnNdsOfeTjJx1b0AnN1xhwQ m04cBU9OcKotWEUOx5sNqmIvuE/PiUcg+UiEao8eBSULppqYfv2uvws47UgJzLlSDju5 hQZYeZK1jCL9FhJeAiYTxZNX3s3jmjkb7m0R9L6dihujs7SyJdTDqzsUM5VYX/5kCvkM +CMg== 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=sbC7PiRZPINxL6kTcqUkLmMBkJDE3KtV3T6vvAK6zKQ=; b=Dho/hiisWqdj9hxbSF0f0yaKnThkSE/CPxAuZe3Sv4mqDEkLCzITAOCwDN3G2niqe0 QE/hfPCfV/ieEl4o0wAdC0a9Kf97VtBlUHzWdmC91fo43X3wqKQnxa8M9iFSeHfQvpuV VPoo0uyXoC8BWBVOF1yc1dLdWlV5t1HY9fuQMpWfcxZ/e0x1eT91tj8P06b7BolD4pvH SAgQLMPpKDWtQS7euSpFxflXtoO19z7S3kX5NCl/M9s6EdE1zWYEglRvvNBFx9fxPJKI pGkDiKF7Es1+Om6L1J7mjQW17rPECaEIki1Ps96JFWbCiqo9DSUhISfI3Z33aFk8Le0/ zqMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=XVf0aCtL; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c13-20020a170906340d00b007adbc807ca8si8302747ejb.137.2022.11.21.13.28.01; Mon, 21 Nov 2022 13:28:28 -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=XVf0aCtL; 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 S230228AbiKUVYr (ORCPT + 99 others); Mon, 21 Nov 2022 16:24:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbiKUVYp (ORCPT ); Mon, 21 Nov 2022 16:24:45 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C4DB14D3A; Mon, 21 Nov 2022 13:24:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669065881; x=1700601881; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WQHtk5rD0UFDH3ezGkF35r6wv2LNLOm3eEkyD65lDDA=; b=XVf0aCtL/681SfdVnHJYCcRLGwk2h6KS2DhLTGV35rVRl61SnuRKQxcD 1miEamsZQ0BdFSwinx677UyR6A/SmfitHH+ubDB5jtKK5vSvUiV98Vvg0 sKSK1QKmiA1TLAhdFBsIdj2VwlrQYhzVzl9URQPfF9WwGAs0MnLYno+Ml aDiIHYUPgVybIxKF17d91junP6h4Ic+TaHFaGTPYBY/ovCt3/dBs9CbDx SsVdmyCkbZi+42nkmxebCQB4lxhmpLBm8YiTN7EI93MxgINKGhE+cAWxQ Qh1kCpUy/rGNNeewpLA/knQdWgjc9ltP76pze88R4FPJXd35G/vnscYe6 w==; X-IronPort-AV: E=Sophos;i="5.96,182,1665471600"; d="scan'208";a="124468619" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Nov 2022 14:24:40 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Mon, 21 Nov 2022 14:24:35 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Mon, 21 Nov 2022 14:24:33 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v3 1/7] net: lan966x: Add XDP_PACKET_HEADROOM Date: Mon, 21 Nov 2022 22:28:44 +0100 Message-ID: <20221121212850.3212649-2-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221121212850.3212649-1-horatiu.vultur@microchip.com> References: <20221121212850.3212649-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 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,T_SPF_TEMPERROR 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750142664713039626?= X-GMAIL-MSGID: =?utf-8?q?1750142664713039626?= Update the page_pool params to allocate XDP_PACKET_HEADROOM space as headroom for all received frames. This is needed for when the XDP_TX and XDP_REDIRECT are implemented. Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 16 +++++++++++----- .../net/ethernet/microchip/lan966x/lan966x_xdp.c | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 5fbbd479cfb06..3055124b4dd79 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ +#include + #include "lan966x_main.h" static int lan966x_fdma_channel_active(struct lan966x *lan966x) @@ -16,7 +18,7 @@ static struct page *lan966x_fdma_rx_alloc_page(struct lan966x_rx *rx, if (unlikely(!page)) return NULL; - db->dataptr = page_pool_get_dma_addr(page); + db->dataptr = page_pool_get_dma_addr(page) + XDP_PACKET_HEADROOM; return page; } @@ -72,7 +74,7 @@ static int lan966x_fdma_rx_alloc_page_pool(struct lan966x_rx *rx) .nid = NUMA_NO_NODE, .dev = lan966x->dev, .dma_dir = DMA_FROM_DEVICE, - .offset = 0, + .offset = XDP_PACKET_HEADROOM, .max_len = rx->max_mtu - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)), }; @@ -432,11 +434,13 @@ static int lan966x_fdma_rx_check_frame(struct lan966x_rx *rx, u64 *src_port) if (unlikely(!page)) return FDMA_ERROR; - dma_sync_single_for_cpu(lan966x->dev, (dma_addr_t)db->dataptr, + dma_sync_single_for_cpu(lan966x->dev, + (dma_addr_t)db->dataptr + XDP_PACKET_HEADROOM, FDMA_DCB_STATUS_BLOCKL(db->status), DMA_FROM_DEVICE); - lan966x_ifh_get_src_port(page_address(page), src_port); + lan966x_ifh_get_src_port(page_address(page) + XDP_PACKET_HEADROOM, + src_port); if (WARN_ON(*src_port >= lan966x->num_phys_ports)) return FDMA_ERROR; @@ -466,6 +470,7 @@ static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx, skb_mark_for_recycle(skb); + skb_reserve(skb, XDP_PACKET_HEADROOM); skb_put(skb, FDMA_DCB_STATUS_BLOCKL(db->status)); lan966x_ifh_get_timestamp(skb->data, ×tamp); @@ -786,7 +791,8 @@ static int lan966x_fdma_get_max_frame(struct lan966x *lan966x) return lan966x_fdma_get_max_mtu(lan966x) + IFH_LEN_BYTES + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + - VLAN_HLEN * 2; + VLAN_HLEN * 2 + + XDP_PACKET_HEADROOM; } int lan966x_fdma_change_mtu(struct lan966x *lan966x) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c index e77d9f2aad2b4..8ebde1eb6a09c 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c @@ -44,7 +44,8 @@ int lan966x_xdp_run(struct lan966x_port *port, struct page *page, u32 data_len) xdp_init_buff(&xdp, PAGE_SIZE << lan966x->rx.page_order, &port->xdp_rxq); - xdp_prepare_buff(&xdp, page_address(page), IFH_LEN_BYTES, + xdp_prepare_buff(&xdp, page_address(page), + IFH_LEN_BYTES + XDP_PACKET_HEADROOM, data_len - IFH_LEN_BYTES, false); act = bpf_prog_run_xdp(xdp_prog, &xdp); switch (act) { From patchwork Mon Nov 21 21:28:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 24014 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1843369wrr; Mon, 21 Nov 2022 13:28:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf6lO9y0uD3pqfYxRczcZUx05g7HQG1imXWYQ62Nd1kaQUqdb5FaOUIqDCxoHwghqUIhudSa X-Received: by 2002:a17:906:2c51:b0:7b2:8c66:9bda with SMTP id f17-20020a1709062c5100b007b28c669bdamr16358117ejh.732.1669066095091; Mon, 21 Nov 2022 13:28:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669066095; cv=none; d=google.com; s=arc-20160816; b=LQEkKLSjBNy05qyhmUL+27PgCdfqIrx+tKjOlCFiONsauod4kRbRgFT61BAhgVklDD UfGdOqS0uPS8TAU8YPDButIRy5mgjl0z35cukVrf1MfjpqTDSqpnQeB+1hAtosw00fMQ fRsQqryXn07Tzo1BS17Z8hTH5yzRT4kpGe5edVDbPDf+sp4SVxYIESaZ3LcbN3LhJ4sJ 1xqBzIE5LMdLKWIoFQkT7zXrO8w/w8dQ2aRJTCuiOULt/I74XpbqSEfE0pRuhoammmjg hqaZUamAf19X6kwY2UwKEzl7djpeDbWjfAQtzSW9RRx1uqPOzaAjzSk+q6nqigP0f9JB K72A== 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=qs1s2ENuS1HxKJUn7dlYW3Oc+jM1IsYuFiyw3J+oEzw=; b=NS1dzYxh6FpfQzpjIBBw5mKsRHVX3qOCWLgyEhLL3UrOajVqlurNqt0GPFnR88exMI 2Z4SkmYWHgRVFDpiR+OV42PWZE6JjLPcWz466mQkfCHzdPTKk7Taa/dmva41gQBkTos7 abAksiLb+p13wqDNcefZhQF4NiQ1iQwkPfzEANDrRQwxeftp9xPzLMf2qKWBpF9SPXMj 9W4M4XcBbkqOPFKsapql98xO8VbUOTisPsPzj0o5K6YS3UoWEf+kuQNqUcUKDJKLGJ++ mEBQhiFugND0dH5L8h8o4A+F8pEm6q2d2URsQMRuUet3DHznr6HPHPs5LKM1boVJ+UTb k5Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=KSpywKXl; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p36-20020a056402502400b004615bea1d62si10059371eda.472.2022.11.21.13.27.51; Mon, 21 Nov 2022 13:28:15 -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=KSpywKXl; 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 S229482AbiKUVY6 (ORCPT + 99 others); Mon, 21 Nov 2022 16:24:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229969AbiKUVYt (ORCPT ); Mon, 21 Nov 2022 16:24:49 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2855CA414A; Mon, 21 Nov 2022 13:24:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669065884; x=1700601884; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=j2O7GMy+IIz1SySbZrYhpOJz3Xy8edTsWmZxxV8XFC4=; b=KSpywKXlNidutTVnX7OJ4cTLCUFXbR2y2yNGEimQsq3mB2VE7QMWNHxK RwW5nALcnTSoVx9iO59xYpvVPETnN46g80t7394hscDtMwDAGnA8WWMNj gWyP/lbgavYFC4Gzz7TcLxNqOjQ+j67zuL9KE+KwXIi05xKaNoV/B40G8 sqxJzBHPE+bCFwSE2Ljf+Z9wifOH9emvkDrIegEKnko8suJhOf6iqTnrx uz18sL5WOT1q1SeaDgRvkIg/kb9CiHlzdZ/59rr6QYRLYjDa+pIKbo17Y p/Px2DPAb3OXR6+6HBCoU8uheZ/QjcSviU+L3PzOb5Q+QoJpzjY3R8602 w==; X-IronPort-AV: E=Sophos;i="5.96,182,1665471600"; d="scan'208";a="124468627" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Nov 2022 14:24:40 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Mon, 21 Nov 2022 14:24:38 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Mon, 21 Nov 2022 14:24:36 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v3 2/7] net: lan966x: Introduce helper functions Date: Mon, 21 Nov 2022 22:28:45 +0100 Message-ID: <20221121212850.3212649-3-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221121212850.3212649-1-horatiu.vultur@microchip.com> References: <20221121212850.3212649-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 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,T_SPF_TEMPERROR 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750142649716936314?= X-GMAIL-MSGID: =?utf-8?q?1750142649716936314?= Introduce lan966x_fdma_tx_setup_dcb and lan966x_fdma_tx_start functions and use of them inside lan966x_fdma_xmit. There is no functional change in here. They are introduced to be used when XDP_TX/REDIRECT actions are introduced. Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 71 ++++++++++++------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 3055124b4dd79..94c720e59caee 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -612,14 +612,53 @@ static int lan966x_fdma_get_next_dcb(struct lan966x_tx *tx) return -1; } +static void lan966x_fdma_tx_setup_dcb(struct lan966x_tx *tx, + int next_to_use, int len, + dma_addr_t dma_addr) +{ + struct lan966x_tx_dcb *next_dcb; + struct lan966x_db *next_db; + + next_dcb = &tx->dcbs[next_to_use]; + next_dcb->nextptr = FDMA_DCB_INVALID_DATA; + + next_db = &next_dcb->db[0]; + next_db->dataptr = dma_addr; + next_db->status = FDMA_DCB_STATUS_SOF | + FDMA_DCB_STATUS_EOF | + FDMA_DCB_STATUS_INTR | + FDMA_DCB_STATUS_BLOCKO(0) | + FDMA_DCB_STATUS_BLOCKL(len); +} + +static void lan966x_fdma_tx_start(struct lan966x_tx *tx, int next_to_use) +{ + struct lan966x *lan966x = tx->lan966x; + struct lan966x_tx_dcb *dcb; + + if (likely(lan966x->tx.activated)) { + /* Connect current dcb to the next db */ + dcb = &tx->dcbs[tx->last_in_use]; + dcb->nextptr = tx->dma + (next_to_use * + sizeof(struct lan966x_tx_dcb)); + + lan966x_fdma_tx_reload(tx); + } else { + /* Because it is first time, then just activate */ + lan966x->tx.activated = true; + lan966x_fdma_tx_activate(tx); + } + + /* Move to next dcb because this last in use */ + tx->last_in_use = next_to_use; +} + int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev) { struct lan966x_port *port = netdev_priv(dev); struct lan966x *lan966x = port->lan966x; struct lan966x_tx_dcb_buf *next_dcb_buf; - struct lan966x_tx_dcb *next_dcb, *dcb; struct lan966x_tx *tx = &lan966x->tx; - struct lan966x_db *next_db; int needed_headroom; int needed_tailroom; dma_addr_t dma_addr; @@ -665,16 +704,7 @@ int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev) } /* Setup next dcb */ - next_dcb = &tx->dcbs[next_to_use]; - next_dcb->nextptr = FDMA_DCB_INVALID_DATA; - - next_db = &next_dcb->db[0]; - next_db->dataptr = dma_addr; - next_db->status = FDMA_DCB_STATUS_SOF | - FDMA_DCB_STATUS_EOF | - FDMA_DCB_STATUS_INTR | - FDMA_DCB_STATUS_BLOCKO(0) | - FDMA_DCB_STATUS_BLOCKL(skb->len); + lan966x_fdma_tx_setup_dcb(tx, next_to_use, skb->len, dma_addr); /* Fill up the buffer */ next_dcb_buf = &tx->dcbs_buf[next_to_use]; @@ -688,21 +718,8 @@ int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev) LAN966X_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP) next_dcb_buf->ptp = true; - if (likely(lan966x->tx.activated)) { - /* Connect current dcb to the next db */ - dcb = &tx->dcbs[tx->last_in_use]; - dcb->nextptr = tx->dma + (next_to_use * - sizeof(struct lan966x_tx_dcb)); - - lan966x_fdma_tx_reload(tx); - } else { - /* Because it is first time, then just activate */ - lan966x->tx.activated = true; - lan966x_fdma_tx_activate(tx); - } - - /* Move to next dcb because this last in use */ - tx->last_in_use = next_to_use; + /* Start the transmission */ + lan966x_fdma_tx_start(tx, next_to_use); return NETDEV_TX_OK; From patchwork Mon Nov 21 21:28:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 24018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1844051wrr; Mon, 21 Nov 2022 13:30:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf7YcMf1+xkbm4jjJ0Bj28Ls2HvhLWwXnxb+bZ7PH0FNIk8icMPqcACsxFw9xMnJ9mK0Sl5E X-Received: by 2002:a05:6402:48e:b0:463:ab06:f338 with SMTP id k14-20020a056402048e00b00463ab06f338mr18083180edv.371.1669066200248; Mon, 21 Nov 2022 13:30:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669066200; cv=none; d=google.com; s=arc-20160816; b=ggm/VQiyX8oJKGcbzJzYPv3t0w1skR9cvXhbUN1NE5rXVE/I0elBAJa5UTZvxJNE0H fMFjFFKkC7k/a/lr2S6gdjl5HHXAM2X9qAt/COZCBJyhBQjDH0yCOLESoE96ApVBxFyI AjySG8+VFu47+BQ/MfIO/HOUi7DNSbBN7F02ca8et7UaGAykOdHgWVyhziQsFAr2Ax07 /TT8oRfesvyQGbRa7gTL++J+wxSwsZazz7U1MLT1y+861IFktFz+1arN8zPVbeH8o8hQ 9P7X2idSFlDtJluTTxYJ3mQN9pL1+i8WS4Ye2KJKk3FEEmmxvVX8Z3WKjY9KlG1IjfVZ j2LQ== 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=2nWItbphGfB17MFeOzSSm4NoACTXpW1xzBzE4FMr+1Q=; b=hrI/BfBnkxxKoj0UO2JvXnTxLoUgKMdveOP/tNAbVV4G/8i1u6wQwIvq6MsXB4GlxP 1poIofaVddrrJi2Q/yMI0jJAawiP77fFuLu4p2sq5zF7bQSoVCMs32CGunSpFfNjHyi/ KhmRsUvn7gPMkJLVo/c4CcMR8VUVjJqidwd5fFowmRlejPbUvXsP9/N36QgbIhiOU6TF Rz/82QWfC2o84PLjYLukvNRPnF3r+2IDyuiorv02ZnKPOFbBWUgTm8Qzdzuq8eKN/irK OfKYCymgkuT+6ZK4fU9f2+gqPynaXOxFOfCJwgjgoR6dcZ8qYYtLAaftNZSEPt0z7C22 iFdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=shzXO2No; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds3-20020a0564021cc300b0045961c7dde9si6554510edb.63.2022.11.21.13.29.35; Mon, 21 Nov 2022 13:30:00 -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=shzXO2No; 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 S231518AbiKUVYu (ORCPT + 99 others); Mon, 21 Nov 2022 16:24:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbiKUVYq (ORCPT ); Mon, 21 Nov 2022 16:24:46 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 786F1657F7; Mon, 21 Nov 2022 13:24:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669065882; x=1700601882; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=06uf81UhcRsqU248Upd8RTcFIMaBlp2xwT4+VIGMlqQ=; b=shzXO2NoETQY78xpH9dbe3jDKTpxEt2n99R4SbxG1XNtkMcflipv6Cpi QiwrvRCiYNHJ9PIFA+i9Y9ttRE2lgZaDVqtC08Nmzwbf+56UWcwzrRmv4 QUgqY5e/xPPYNbIQ7YfarNtfkfLq24BFLPee+F/opt3UZpNDPDLJoi3Jf 8eUj5rGRcn5rwUu2n3y0b4WXp8VUTUJYNWroYhbMLigice4WJ0ngIFE7S Za7DJUwCl9Edn/wR4BzDRcnLw30QZ6/aisCVoL/OeFztrzM2wOGWFNbeD H8QyvhL9dq1by7U6HVC/+yMW+1B9u9EcdeFq/5qQf1RtdS11ZPXKWKrJc w==; X-IronPort-AV: E=Sophos;i="5.96,182,1665471600"; d="scan'208";a="189968355" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Nov 2022 14:24:41 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Mon, 21 Nov 2022 14:24:41 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Mon, 21 Nov 2022 14:24:38 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v3 3/7] net: lan966x: Add len field to lan966x_tx_dcb_buf Date: Mon, 21 Nov 2022 22:28:46 +0100 Message-ID: <20221121212850.3212649-4-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221121212850.3212649-1-horatiu.vultur@microchip.com> References: <20221121212850.3212649-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 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, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_SPF_TEMPERROR 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750142760323298133?= X-GMAIL-MSGID: =?utf-8?q?1750142760323298133?= Currently when a frame was transmitted, it is required to unamp the frame that was transmitted. The length of the frame was taken from the transmitted skb. In the future we might not have an skb, therefore store the length skb directly in the lan966x_tx_dcb_buf and use this one to unamp the frame. Signed-off-by: Horatiu Vultur --- drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c | 5 +++-- drivers/net/ethernet/microchip/lan966x/lan966x_main.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 94c720e59caee..384ed34197d58 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -391,12 +391,12 @@ static void lan966x_fdma_tx_clear_buf(struct lan966x *lan966x, int weight) continue; dcb_buf->dev->stats.tx_packets++; - dcb_buf->dev->stats.tx_bytes += dcb_buf->skb->len; + dcb_buf->dev->stats.tx_bytes += dcb_buf->len; dcb_buf->used = false; dma_unmap_single(lan966x->dev, dcb_buf->dma_addr, - dcb_buf->skb->len, + dcb_buf->len, DMA_TO_DEVICE); if (!dcb_buf->ptp) dev_kfree_skb_any(dcb_buf->skb); @@ -709,6 +709,7 @@ int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev) /* Fill up the buffer */ next_dcb_buf = &tx->dcbs_buf[next_to_use]; next_dcb_buf->skb = skb; + next_dcb_buf->len = skb->len; next_dcb_buf->dma_addr = dma_addr; next_dcb_buf->used = true; next_dcb_buf->ptp = false; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index bc93051aa0798..7bb9098496f60 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -175,6 +175,7 @@ struct lan966x_rx { struct lan966x_tx_dcb_buf { struct net_device *dev; struct sk_buff *skb; + int len; dma_addr_t dma_addr; bool used; bool ptp; From patchwork Mon Nov 21 21:28:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 24019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1844191wrr; Mon, 21 Nov 2022 13:30:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf5PmFYdNwstOGimUnARsOfp9jOTejJ6i6PUjJ4Yy52oMKNyj4OA+9Jvim2JOXHrOsys3x0R X-Received: by 2002:a05:6402:456:b0:461:9955:b54a with SMTP id p22-20020a056402045600b004619955b54amr7099828edw.159.1669066216758; Mon, 21 Nov 2022 13:30:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669066216; cv=none; d=google.com; s=arc-20160816; b=oLQf+v5SX9ZStMi8X7L050oRPz1Y2vlVBkQOP0zljEmitIu045S29E+FgRzD6Stjus kzanG9ogLjZE+Az2i2IezUrx04mWA0PbA7XcG2uij8ZQoRqvsR95nT0eFczu3LXHmTRc Le5ZqJztzBuvB/NkXZoqGyws73lvHxwAvkUy1ZdeXOvuN6UwwC6S8oES9AAQMpeE8HHL 5udg4VeGUhZCeotrK0q5p2tPU9SLbHSXtnGiNMf6VNLP/l0Py1jv0Lxs9vpO/P1sz5wh QvyfxjMbYYFFv0CbyGTFyrh3VTrKkwYRtoDfMMKldkWvoNty9C/XKHaqBtgeRFgnG9k4 Sk/g== 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=pLtyNYbwTS6UwI7s4ntrsfBuNT7TIR6M6ZMzknBdrgI=; b=zI0T+VmRCXiaIDSdydtt31ZUryQEd6qWwdxp/yK/IwnWgvzpkwR/HJViQw9mHIGtvj E7Gstm9aaDTUOntkC3wV2A/4fEC8IpeIxNu5+/W9QBXeb1lJ4dX7ViBQt8KYCxxbeSqC 7ERrYsmJBN2HV5UkwFoSko5fSkgu5MR1IkYzg6XzT7lkkjROjLHpb2Wkam8WwuDRDmVA qFdTryC/o7ZeE6Io/pSYwo4bPlcerSYFmynwinSwS0YCMyXEjVg91XYSutX0CLme9WOS 4RADvtk1ld2kGzv7Z0Yk/y9nciNFkwAOUWttLDW6FnN9RcXy4eVP5Bi+BupxFSA5kykC kijg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=Zoo45D5A; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a05640242ce00b0046751a6076bsi11853548edc.318.2022.11.21.13.29.53; Mon, 21 Nov 2022 13:30:16 -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=Zoo45D5A; 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 S231598AbiKUVZF (ORCPT + 99 others); Mon, 21 Nov 2022 16:25:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231546AbiKUVY4 (ORCPT ); Mon, 21 Nov 2022 16:24:56 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0A5CB9614; Mon, 21 Nov 2022 13:24:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669065889; x=1700601889; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Hp29edLp8a8OEBxkPTP/BqxOmLMA7en3zD0HWlGqapo=; b=Zoo45D5A+MyMUQYePz6R1z0eh/iC4zAt+Tcj59p70gWJpuQPO5dgi7RR wQBAjmi1K+ec9kr+HwHU6uOVRJLkrTjrMzcNNsQq1tctuyvABjrHPmgL0 SrJOq6bKDGS7gXmO5WrcCHjmSjOox9opgVsNNmeDDq7WRcBhg7hACd2vj eZEDIoG8J2r7ToCfPwvwy71VlKXGF5jMJZ69pzgKxfX1Wu6FwIYHWkyiy Oh65mDvabM3wcXmAhrcmLlGJT95+rknHLE0E4D4sViH2QOswZ0+aD2aIQ 7ClX5oRxy4eQxj1ztlyZpCBoQVs7rvOiXk9ZPptb9ClsloeCyIypu5Z26 w==; X-IronPort-AV: E=Sophos;i="5.96,182,1665471600"; d="scan'208";a="124468641" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Nov 2022 14:24:45 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Mon, 21 Nov 2022 14:24:44 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Mon, 21 Nov 2022 14:24:41 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v3 4/7] net: lan966x: Update rxq memory model Date: Mon, 21 Nov 2022 22:28:47 +0100 Message-ID: <20221121212850.3212649-5-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221121212850.3212649-1-horatiu.vultur@microchip.com> References: <20221121212850.3212649-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 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,T_SPF_TEMPERROR 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750142777063032988?= X-GMAIL-MSGID: =?utf-8?q?1750142777063032988?= By default the rxq memory model is MEM_TYPE_PAGE_SHARED but to be able to reuse pages on the TX side, when the XDP action XDP_TX it is required to update the memory model to PAGE_POOL. Signed-off-by: Horatiu Vultur --- .../net/ethernet/microchip/lan966x/lan966x_fdma.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 384ed34197d58..483d1470c8362 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -78,8 +78,22 @@ static int lan966x_fdma_rx_alloc_page_pool(struct lan966x_rx *rx) .max_len = rx->max_mtu - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)), }; + struct lan966x_port *port; + int i; rx->page_pool = page_pool_create(&pp_params); + + for (i = 0; i < lan966x->num_phys_ports; ++i) { + if (!lan966x->ports[i]) + continue; + + port = lan966x->ports[i]; + + xdp_rxq_info_unreg_mem_model(&port->xdp_rxq); + xdp_rxq_info_reg_mem_model(&port->xdp_rxq, MEM_TYPE_PAGE_POOL, + rx->page_pool); + } + return PTR_ERR_OR_ZERO(rx->page_pool); } From patchwork Mon Nov 21 21:28:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 24020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1844476wrr; Mon, 21 Nov 2022 13:30:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf4WbhuizjQuLCfaGU5vi7G/ap9jjyrKs2DboCxv6lTGoFpY8D5xZpe97NqCFpodrwg5GNVN X-Received: by 2002:a17:906:6a0c:b0:7ad:9f03:aa46 with SMTP id qw12-20020a1709066a0c00b007ad9f03aa46mr976318ejc.175.1669066247890; Mon, 21 Nov 2022 13:30:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669066247; cv=none; d=google.com; s=arc-20160816; b=wM+7xzXcAXcujyyS5i2mlyKQ54ipQU5xRIwwEyNifGIZRcjdRQKZ8uW4MKsGBeGFop hYbMQLxVQJYgeM6/SkIV8l9H+TPYy2jIVoKLaj2JkPF9cEKBscmUISIGNeq6o14yPKv9 7reAaP18vGfg56hSUXJ1BJmSA2gg/yDuUDHjpKfKvwxaJrm6HZL33pAb6l4IevYG9hdB If3kTeWALCI8Apm6vlLCUmKu6sfUBysdQwVHvTrDqyRaSTtb7JcLJ8MKGIQnphkixJ/y py1idriD5rnwQv+20UBgklzr8eYRiMERIEvlZiFohF5uPoky2Q8qdZIIGfLw5t2hb+yE tC0A== 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=HjfXTy3kYG0cAb81BnEzpWGGWUbwAo3cL/JdfTnX9J4=; b=jtuydBaMJ6KfCzx+WlwoU06HI5EdqX94LyKpJJHvFImuezOAXVjtWKLxQqr9nME/QQ TBeIJIVKAl3tGzJzNNBb8P7RxCMOtU19n/SylYQnTtr4K0gk30sJ9uwZ3XcjbUEc56vH /bxK+s+VDGikCy/B0P/acwx9GArS81lSTFJmB/cC5qvIEl4GHWklSg2tp4qAkluBDJts JGXZhYZVctQWgekA/EDe48iS9aK6c/mRgmujrwBYNCHKghsXSuEEr0uu87uFTqi8nndV fEBiD0W9Cc6BVAAktwAon54CcXI8pGRqY31wWInDbT0qnPy4a7sZ2e1Em13jnRtWd0AJ Wz2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=gSaSkTg2; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q18-20020a056402519200b0045a1dbedd92si6079366edd.35.2022.11.21.13.30.23; Mon, 21 Nov 2022 13:30:47 -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=gSaSkTg2; 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 S231690AbiKUVZL (ORCPT + 99 others); Mon, 21 Nov 2022 16:25:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbiKUVY4 (ORCPT ); Mon, 21 Nov 2022 16:24:56 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D618714D3A; Mon, 21 Nov 2022 13:24:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669065887; x=1700601887; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/rcqsr80iCt6QVRBNj/0rDBZ/V/EtWipClEWYsYrmkA=; b=gSaSkTg2xImyvTpDGAL+3buXh1cz3u1D4p/FWmEVtGtF/UD7uptYuhoQ YMNvKa5r+YhPWQ0HonZBXEBoYFZDm8MKgwgPRrvg+F2iRINonvT7SBUGG MC7XfARNQp8Dat/Y+VxvFLzXTRlCLypHON9bvHZgdS5WioL5apbtsISoG mRz+kmB/WircErP78+KzRL/873af5LPxVBLSaiGT8NnyRGJ/dZScsL/oX GX8/fRsw7qqV2agXG50cbzH0ZFNxVFjE5gQPlXrxuVxdMGN2VhpXB2mDo rBUHN58kADCPrpXTZI8L3ypWAMhBFg52MwUrG6XKXLpUZz/xYvRNxE3bq A==; X-IronPort-AV: E=Sophos;i="5.96,182,1665471600"; d="scan'208";a="188028981" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Nov 2022 14:24:46 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Mon, 21 Nov 2022 14:24:46 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Mon, 21 Nov 2022 14:24:44 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v3 5/7] net: lan966x: Update dma_dir of page_pool_params Date: Mon, 21 Nov 2022 22:28:48 +0100 Message-ID: <20221121212850.3212649-6-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221121212850.3212649-1-horatiu.vultur@microchip.com> References: <20221121212850.3212649-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 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,T_SPF_TEMPERROR 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750142810158425453?= X-GMAIL-MSGID: =?utf-8?q?1750142810158425453?= To add support for XDP_TX it is required to be able to write to the DMA area therefore it is required that the pages will be mapped using DMA_BIDIRECTIONAL flag. Therefore check if there are any xdp programs on the interfaces and in that case set DMA_BIDRECTIONAL otherwise use DMA_FROM_DEVICE. Therefore when a new XDP program is added it is required to redo the page_pool. Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 29 ++++++++++++++---- .../ethernet/microchip/lan966x/lan966x_main.h | 2 ++ .../ethernet/microchip/lan966x/lan966x_xdp.c | 30 +++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 483d1470c8362..f8287a6a86ed5 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -81,6 +81,9 @@ static int lan966x_fdma_rx_alloc_page_pool(struct lan966x_rx *rx) struct lan966x_port *port; int i; + if (lan966x_xdp_present(lan966x)) + pp_params.dma_dir = DMA_BIDIRECTIONAL; + rx->page_pool = page_pool_create(&pp_params); for (i = 0; i < lan966x->num_phys_ports; ++i) { @@ -827,16 +830,11 @@ static int lan966x_fdma_get_max_frame(struct lan966x *lan966x) XDP_PACKET_HEADROOM; } -int lan966x_fdma_change_mtu(struct lan966x *lan966x) +static int __lan966x_fdma_reload(struct lan966x *lan966x, int max_mtu) { - int max_mtu; int err; u32 val; - max_mtu = lan966x_fdma_get_max_frame(lan966x); - if (max_mtu == lan966x->rx.max_mtu) - return 0; - /* Disable the CPU port */ lan_rmw(QSYS_SW_PORT_MODE_PORT_ENA_SET(0), QSYS_SW_PORT_MODE_PORT_ENA, @@ -862,6 +860,25 @@ int lan966x_fdma_change_mtu(struct lan966x *lan966x) return err; } +int lan966x_fdma_change_mtu(struct lan966x *lan966x) +{ + int max_mtu; + + max_mtu = lan966x_fdma_get_max_frame(lan966x); + if (max_mtu == lan966x->rx.max_mtu) + return 0; + + return __lan966x_fdma_reload(lan966x, max_mtu); +} + +int lan966x_fdma_reload_page_pool(struct lan966x *lan966x) +{ + int max_mtu; + + max_mtu = lan966x_fdma_get_max_frame(lan966x); + return __lan966x_fdma_reload(lan966x, max_mtu); +} + void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev) { if (lan966x->fdma_ndev) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 7bb9098496f60..7f1231b31c924 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -466,6 +466,7 @@ void lan966x_fdma_netdev_deinit(struct lan966x *lan966x, struct net_device *dev) int lan966x_fdma_init(struct lan966x *lan966x); void lan966x_fdma_deinit(struct lan966x *lan966x); irqreturn_t lan966x_fdma_irq_handler(int irq, void *args); +int lan966x_fdma_reload_page_pool(struct lan966x *lan966x); int lan966x_lag_port_join(struct lan966x_port *port, struct net_device *brport_dev, @@ -556,6 +557,7 @@ 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); +bool lan966x_xdp_present(struct lan966x *lan966x); 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 8ebde1eb6a09c..05c5a28206558 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c @@ -11,6 +11,8 @@ static int lan966x_xdp_setup(struct net_device *dev, struct netdev_bpf *xdp) struct lan966x_port *port = netdev_priv(dev); struct lan966x *lan966x = port->lan966x; struct bpf_prog *old_prog; + bool old_xdp, new_xdp; + int err; if (!lan966x->fdma) { NL_SET_ERR_MSG_MOD(xdp->extack, @@ -18,7 +20,20 @@ static int lan966x_xdp_setup(struct net_device *dev, struct netdev_bpf *xdp) return -EOPNOTSUPP; } + old_xdp = lan966x_xdp_present(lan966x); old_prog = xchg(&port->xdp_prog, xdp->prog); + new_xdp = lan966x_xdp_present(lan966x); + + if (old_xdp != new_xdp) + goto out; + + err = lan966x_fdma_reload_page_pool(lan966x); + if (err) { + xchg(&port->xdp_prog, old_prog); + return err; + } + +out: if (old_prog) bpf_prog_put(old_prog); @@ -62,6 +77,21 @@ int lan966x_xdp_run(struct lan966x_port *port, struct page *page, u32 data_len) } } +bool lan966x_xdp_present(struct lan966x *lan966x) +{ + int p; + + for (p = 0; p < lan966x->num_phys_ports; ++p) { + if (!lan966x->ports[p]) + continue; + + if (lan966x_xdp_port_present(lan966x->ports[p])) + return true; + } + + return false; +} + int lan966x_xdp_port_init(struct lan966x_port *port) { struct lan966x *lan966x = port->lan966x; From patchwork Mon Nov 21 21:28:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 24021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1844689wrr; Mon, 21 Nov 2022 13:31:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Gcgw0nHYH1AKuEvP/tcGzxpUotV/QMpt/c7kte+Fx7UGvP7GIKsAQZzho5KQ5sQY8d25x X-Received: by 2002:a17:906:9702:b0:7aa:5e6c:4b59 with SMTP id k2-20020a170906970200b007aa5e6c4b59mr5165996ejx.231.1669066270622; Mon, 21 Nov 2022 13:31:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669066270; cv=none; d=google.com; s=arc-20160816; b=KoZAQLC4ADfJ33sPK/YxrjJRSRCgjFgaVvqwPM4rrNpOHbKmlqLmqC9GggjLl3KrlU p3WBKr30UABfr4j/ypdZsafSLt2ZrwlclHlBO+FLo3omf5HdfzrWcCGhepUP6VZBlim/ Ky6RuDEFkwtGsDzPnG7M5gSH8pfHasVrsYP667c69wX1udq7KEm+pYv4oy4DQpgVRL/o 7NwnGb5lWlmrGrLAb51nqTVgBJNQugavtTgny6vXIDG34PNfUYZvIQmt8JvniCL01YrL Opsw55S6IkqByjtt/i064YTK1E3mfxc875g0CTP5XmBGusWs3AFV3zdDI5wi1ti301xB 8FLA== 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=bkelJ8srzD8G+FNUz9RAx0kpMcDfiIyp79CuUPMATus=; b=qf5HJgfQDtiz9yYzagwBotZuHORAVm+WvUI7GoaQn8xFR7KgwhHIK0KEAeE0nDFHSU z4Vjvh41rCKfAfQU5/sefDkkf1Mgt7PQhncLMeO+1s3GgjjN9R1nnFJkLITCqLjP3RIY Bcbls2pDbNaH5SSxaIdGZ7mKG0pjMypUMN3lhuCW8wQQqKKuo2dYgIArw5SzqT62XR2P +Et9C/S5m8RpQPHTSKHqJB7bV9+o9P6eIw/OcW15BjJpei9C9dZJ6dB+dEVEI2mgTFVB t8iVrsgwjoiyny4g2lix+lxAXHRbRgwqzidyEpFyv5HI4g9pJ7lvhkczHe05etvZhczr 3Hww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=Mj+Mo1v5; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bo26-20020a0564020b3a00b00469abb21f9esi2213543edb.129.2022.11.21.13.30.43; Mon, 21 Nov 2022 13:31:10 -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=Mj+Mo1v5; 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 S231748AbiKUVZj (ORCPT + 99 others); Mon, 21 Nov 2022 16:25:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbiKUVZL (ORCPT ); Mon, 21 Nov 2022 16:25:11 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 334D2CDFFF; Mon, 21 Nov 2022 13:24:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669065899; x=1700601899; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XCrkrFI/7i3Aho/y2VazmTbT/xHvRS0FfXHzK1wGJ30=; b=Mj+Mo1v5uEX+QUuhZmK9d2ODr0d5tjZrgpPlvwMz1pFNf8Y8MtFqegS2 VV7Qj3JL9nfq+Q0sGtdCPGFWXcbcEJMJUVKgsZAspYzpMkLIwEy0Qii0M GHXpgA5WyzXCoczf/dpiOpX98muF9ohIi+5nLrP4kuJykG4Xe6w8racl4 fFi7pX+uuueo9mMHWw75Bvst8TEdizlvtCX+5jPFesIVDI1z0p8AGeMIm FTbw+DWH8wLCjsAzFuII4WG6DFLyGnEdYpe4HMyTOgEaFRp4X0vTQ/BgK Iu6B/0YrLlRbna1xZRyq5DkC7FZA8WOpTQ/vxZXxCSORikiAHojW+gAII A==; X-IronPort-AV: E=Sophos;i="5.96,182,1665471600"; d="scan'208";a="188029019" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Nov 2022 14:24:58 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Mon, 21 Nov 2022 14:24:49 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Mon, 21 Nov 2022 14:24:47 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v3 6/7] net: lan966x: Add support for XDP_TX Date: Mon, 21 Nov 2022 22:28:49 +0100 Message-ID: <20221121212850.3212649-7-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221121212850.3212649-1-horatiu.vultur@microchip.com> References: <20221121212850.3212649-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 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,T_SPF_TEMPERROR 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750142833787125919?= X-GMAIL-MSGID: =?utf-8?q?1750142833787125919?= Extend lan966x XDP support with the action XDP_TX. In this case when the received buffer needs to execute XDP_TX, the buffer will be moved to the TX buffers. So a new RX buffer will be allocated. When the TX finish with the frame, it would give back the buffer to the page pool. Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 78 +++++++++++++++++-- .../ethernet/microchip/lan966x/lan966x_main.c | 4 +- .../ethernet/microchip/lan966x/lan966x_main.h | 8 ++ .../ethernet/microchip/lan966x/lan966x_xdp.c | 8 ++ 4 files changed, 90 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index f8287a6a86ed5..b14fdb8e15e22 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -411,12 +411,18 @@ static void lan966x_fdma_tx_clear_buf(struct lan966x *lan966x, int weight) dcb_buf->dev->stats.tx_bytes += dcb_buf->len; dcb_buf->used = false; - dma_unmap_single(lan966x->dev, - dcb_buf->dma_addr, - dcb_buf->len, - DMA_TO_DEVICE); - if (!dcb_buf->ptp) - dev_kfree_skb_any(dcb_buf->skb); + if (dcb_buf->skb) { + dma_unmap_single(lan966x->dev, + dcb_buf->dma_addr, + dcb_buf->len, + DMA_TO_DEVICE); + + if (!dcb_buf->ptp) + dev_kfree_skb_any(dcb_buf->skb); + } + + if (dcb_buf->xdpf) + xdp_return_frame_rx_napi(dcb_buf->xdpf); clear = true; } @@ -549,6 +555,9 @@ static int lan966x_fdma_napi_poll(struct napi_struct *napi, int weight) lan966x_fdma_rx_free_page(rx); lan966x_fdma_rx_advance_dcb(rx); goto allocate_new; + case FDMA_TX: + lan966x_fdma_rx_advance_dcb(rx); + continue; case FDMA_DROP: lan966x_fdma_rx_free_page(rx); lan966x_fdma_rx_advance_dcb(rx); @@ -670,6 +679,62 @@ static void lan966x_fdma_tx_start(struct lan966x_tx *tx, int next_to_use) tx->last_in_use = next_to_use; } +int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, + struct xdp_frame *xdpf, + struct page *page) +{ + struct lan966x *lan966x = port->lan966x; + struct lan966x_tx_dcb_buf *next_dcb_buf; + struct lan966x_tx *tx = &lan966x->tx; + dma_addr_t dma_addr; + int next_to_use; + __be32 *ifh; + int ret = 0; + + spin_lock(&lan966x->tx_lock); + + /* Get next index */ + next_to_use = lan966x_fdma_get_next_dcb(tx); + if (next_to_use < 0) { + netif_stop_queue(port->dev); + ret = NETDEV_TX_BUSY; + goto out; + } + + /* Generate new IFH */ + ifh = page_address(page) + XDP_PACKET_HEADROOM; + memset(ifh, 0x0, sizeof(__be32) * IFH_LEN); + lan966x_ifh_set_bypass(ifh, 1); + lan966x_ifh_set_port(ifh, BIT_ULL(port->chip_port)); + + dma_addr = page_pool_get_dma_addr(page); + dma_sync_single_for_device(lan966x->dev, dma_addr + XDP_PACKET_HEADROOM, + xdpf->len + IFH_LEN_BYTES, + DMA_TO_DEVICE); + + /* Setup next dcb */ + lan966x_fdma_tx_setup_dcb(tx, next_to_use, xdpf->len + IFH_LEN_BYTES, + dma_addr + XDP_PACKET_HEADROOM); + + /* Fill up the buffer */ + next_dcb_buf = &tx->dcbs_buf[next_to_use]; + next_dcb_buf->skb = NULL; + next_dcb_buf->xdpf = xdpf; + next_dcb_buf->len = xdpf->len + IFH_LEN_BYTES; + next_dcb_buf->dma_addr = dma_addr; + next_dcb_buf->used = true; + next_dcb_buf->ptp = false; + next_dcb_buf->dev = port->dev; + + /* Start the transmission */ + lan966x_fdma_tx_start(tx, next_to_use); + +out: + spin_unlock(&lan966x->tx_lock); + + return ret; +} + int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev) { struct lan966x_port *port = netdev_priv(dev); @@ -726,6 +791,7 @@ int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev) /* Fill up the buffer */ next_dcb_buf = &tx->dcbs_buf[next_to_use]; next_dcb_buf->skb = skb; + next_dcb_buf->xdpf = NULL; next_dcb_buf->len = skb->len; next_dcb_buf->dma_addr = dma_addr; next_dcb_buf->used = true; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 42be5d0f1f015..0b7707306da26 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -302,13 +302,13 @@ static int lan966x_port_ifh_xmit(struct sk_buff *skb, return NETDEV_TX_BUSY; } -static void lan966x_ifh_set_bypass(void *ifh, u64 bypass) +void lan966x_ifh_set_bypass(void *ifh, u64 bypass) { packing(ifh, &bypass, IFH_POS_BYPASS + IFH_WID_BYPASS - 1, IFH_POS_BYPASS, IFH_LEN * 4, PACK, 0); } -static void lan966x_ifh_set_port(void *ifh, u64 bypass) +void lan966x_ifh_set_port(void *ifh, u64 bypass) { packing(ifh, &bypass, IFH_POS_DSTS + IFH_WID_DSTS - 1, IFH_POS_DSTS, IFH_LEN * 4, PACK, 0); diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 7f1231b31c924..e303a12daf88a 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -105,11 +105,13 @@ enum macaccess_entry_type { * FDMA_PASS, frame is valid and can be used * 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 */ enum lan966x_fdma_action { FDMA_PASS = 0, FDMA_ERROR, FDMA_DROP, + FDMA_TX, }; struct lan966x_port; @@ -175,6 +177,7 @@ struct lan966x_rx { struct lan966x_tx_dcb_buf { struct net_device *dev; struct sk_buff *skb; + struct xdp_frame *xdpf; int len; dma_addr_t dma_addr; bool used; @@ -360,6 +363,8 @@ bool lan966x_hw_offload(struct lan966x *lan966x, u32 port, struct sk_buff *skb); void lan966x_ifh_get_src_port(void *ifh, u64 *src_port); void lan966x_ifh_get_timestamp(void *ifh, u64 *timestamp); +void lan966x_ifh_set_bypass(void *ifh, u64 bypass); +void lan966x_ifh_set_port(void *ifh, u64 bypass); void lan966x_stats_get(struct net_device *dev, struct rtnl_link_stats64 *stats); @@ -460,6 +465,9 @@ u32 lan966x_ptp_get_period_ps(void); int lan966x_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts); int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev); +int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, + struct xdp_frame *frame, + struct page *page); int lan966x_fdma_change_mtu(struct lan966x *lan966x); void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev); void lan966x_fdma_netdev_deinit(struct lan966x *lan966x, struct net_device *dev); diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c index 05c5a28206558..5fd2f3b01e179 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c @@ -54,6 +54,7 @@ int lan966x_xdp_run(struct lan966x_port *port, struct page *page, u32 data_len) { struct bpf_prog *xdp_prog = port->xdp_prog; struct lan966x *lan966x = port->lan966x; + struct xdp_frame *xdpf; struct xdp_buff xdp; u32 act; @@ -66,6 +67,13 @@ int lan966x_xdp_run(struct lan966x_port *port, struct page *page, u32 data_len) switch (act) { case XDP_PASS: return FDMA_PASS; + case XDP_TX: + xdpf = xdp_convert_buff_to_frame(&xdp); + if (!xdpf) + return FDMA_DROP; + + return lan966x_fdma_xmit_xdpf(port, xdpf, page) ? + FDMA_DROP : FDMA_TX; default: bpf_warn_invalid_xdp_action(port->dev, xdp_prog, act); fallthrough; From patchwork Mon Nov 21 21:28:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 24022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1844888wrr; Mon, 21 Nov 2022 13:31:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5i4w3Ds08NhUAmrWtHozjmEuc/lRfz2E5OXmHB5ggEyRbqgN8bivqR9h2hAo10f4tqnNDE X-Received: by 2002:a05:6402:3808:b0:468:c911:d843 with SMTP id es8-20020a056402380800b00468c911d843mr18078310edb.422.1669066294886; Mon, 21 Nov 2022 13:31:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669066294; cv=none; d=google.com; s=arc-20160816; b=RIe5n176PKXEq3JUKEky0MPOrV66EPT2DISZxcxGkvi9+AP6HX51kd8Fg3gCM8pQmb i8/JuxMTaW8/nEXoCNg1mza5X2joBb7JZ6qc0h/eAVoeqDCaaQvRdpl8kSEUoTqkhW9S 1dE4p8YPfO0XjXHaXKvkP6h5A+UyRHkbW2fQr7nzDPy5EliEsauniGu0j3v7Lgm5l1Er E3lec48/nLYpzEn3zuFftOnrObYU7LpST79TKLCqfJhij5uS/bbCRRaVeOGofWumwUU/ a7Rxt7i05xIuSOTOMX/kFuITx9RqMvuWDjQwdsNg2edy/zaipQ51wlAsOlcieQwRJlm7 YQoQ== 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=M2zmKhTm3/ltfSrs7kzd1KYGz+lQ5K2NAAEmNsAIPQc=; b=IR+3RttPaqwyMgf9+YQXfD03OmYB9FbUrWX+UfYfW4D0r9/5qSSLlnmngwheKczUHH //Vk3HR/Xq7BIHi1Oqc4h0T9giPKDdZGWuDXpx+Wi/ZaFqBUpuVtRAVZA+UoNhkeSnaw s0Bwa5c7cgx3WqOKdxWqZDxbDuAVDuBdI3vUIKSY0q/0ulY37vJC4WLu2io19XXhTkfU eGqBkm7eqPhVrDs/5KI0oCCcZ2WYGTVns0moOwpuRtS34G0D563JtdXI1XNLC6N6E4EQ 3NpsZJBgqoUYs6xVx6vmC3y81lHnqeHhQirvfNEE4dYKsCDtXTi8vRpmtKjrs/ZU428X BIxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=WDnQkhnS; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a05640234c400b0045cd68a2bc5si11001789edc.17.2022.11.21.13.31.07; Mon, 21 Nov 2022 13:31:34 -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=WDnQkhnS; 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 S231766AbiKUVZm (ORCPT + 99 others); Mon, 21 Nov 2022 16:25:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbiKUVZL (ORCPT ); Mon, 21 Nov 2022 16:25:11 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DA40C72F6; Mon, 21 Nov 2022 13:25:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669065900; x=1700601900; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6X6bJA+LO8mXgNhUxY9CSUIxQwuQkqML7X9qDygf0eE=; b=WDnQkhnSHCMkxApF7HjBpEv56PvXQO1I7uhjLTCRo5f5YGVuQPd7bvrS V/P91nz/yb7OSi/KEMFglQ66h1a3ZTbm+2aRjiAl8bNQvxfCA27RWz9z4 TweAbfr72HTy2NmytFs2joafsvTmqp+L9YeVAYMBlAGNNylFdZ2bZsj74 X2nQJQRMJHVnI/05MuxoId4WXrllMDO4ORS64EQJhWTUhQ0Hja82+elIb 5X2qxO/nZ+zcAxoQtyuhH1xIvzRD/SpwBZ5AJD9/aclNQmG8uUBf7et2e ZtmJT8ZesNaWDB/xrxOC+ZFROj6hIFNar330zu18Ux5la8WzQhFaD9+DC A==; X-IronPort-AV: E=Sophos;i="5.96,182,1665471600"; d="scan'208";a="188029033" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Nov 2022 14:24:59 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Mon, 21 Nov 2022 14:24:52 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Mon, 21 Nov 2022 14:24:49 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v3 7/7] net: lan966x: Add support for XDP_REDIRECT Date: Mon, 21 Nov 2022 22:28:50 +0100 Message-ID: <20221121212850.3212649-8-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221121212850.3212649-1-horatiu.vultur@microchip.com> References: <20221121212850.3212649-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 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,T_SPF_TEMPERROR 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750142859238344550?= X-GMAIL-MSGID: =?utf-8?q?1750142859238344550?= 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 | 83 +++++++++++++++---- .../ethernet/microchip/lan966x/lan966x_main.c | 1 + .../ethernet/microchip/lan966x/lan966x_main.h | 10 ++- .../ethernet/microchip/lan966x/lan966x_xdp.c | 31 ++++++- 4 files changed, 109 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index b14fdb8e15e22..81dc27d8f8963 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" @@ -391,11 +392,14 @@ static void lan966x_fdma_tx_clear_buf(struct lan966x *lan966x, int weight) { struct lan966x_tx *tx = &lan966x->tx; struct lan966x_tx_dcb_buf *dcb_buf; + struct xdp_frame_bulk bq; struct lan966x_db *db; unsigned long flags; bool clear = false; int i; + xdp_frame_bulk_init(&bq); + spin_lock_irqsave(&lan966x->tx_lock, flags); for (i = 0; i < FDMA_DCB_MAX; ++i) { dcb_buf = &tx->dcbs_buf[i]; @@ -421,12 +425,24 @@ static void lan966x_fdma_tx_clear_buf(struct lan966x *lan966x, int weight) dev_kfree_skb_any(dcb_buf->skb); } - if (dcb_buf->xdpf) - xdp_return_frame_rx_napi(dcb_buf->xdpf); + if (dcb_buf->xdpf) { + if (dcb_buf->xdp_ndo) + dma_unmap_single(lan966x->dev, + dcb_buf->dma_addr, + dcb_buf->len, + DMA_TO_DEVICE); + + if (dcb_buf->xdp_ndo) + xdp_return_frame_bulk(dcb_buf->xdpf, &bq); + else + xdp_return_frame_rx_napi(dcb_buf->xdpf); + } clear = true; } + xdp_flush_frame_bulk(&bq); + if (clear) lan966x_fdma_wakeup_netdev(lan966x); @@ -533,6 +549,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; @@ -558,6 +575,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); @@ -594,6 +615,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; } @@ -681,7 +705,8 @@ static void lan966x_fdma_tx_start(struct lan966x_tx *tx, int next_to_use) int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, struct xdp_frame *xdpf, - struct page *page) + struct page *page, + bool dma_map) { struct lan966x *lan966x = port->lan966x; struct lan966x_tx_dcb_buf *next_dcb_buf; @@ -702,24 +727,53 @@ int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, } /* Generate new IFH */ - ifh = page_address(page) + XDP_PACKET_HEADROOM; - memset(ifh, 0x0, sizeof(__be32) * IFH_LEN); - lan966x_ifh_set_bypass(ifh, 1); - lan966x_ifh_set_port(ifh, BIT_ULL(port->chip_port)); + if (dma_map) { + if (xdpf->headroom < IFH_LEN_BYTES) { + ret = NETDEV_TX_OK; + goto out; + } - dma_addr = page_pool_get_dma_addr(page); - dma_sync_single_for_device(lan966x->dev, dma_addr + XDP_PACKET_HEADROOM, - xdpf->len + IFH_LEN_BYTES, - DMA_TO_DEVICE); + ifh = xdpf->data - IFH_LEN_BYTES; + memset(ifh, 0x0, sizeof(__be32) * IFH_LEN); + lan966x_ifh_set_bypass(ifh, 1); + lan966x_ifh_set_port(ifh, BIT_ULL(port->chip_port)); + + dma_addr = dma_map_single(lan966x->dev, + xdpf->data - IFH_LEN_BYTES, + xdpf->len + IFH_LEN_BYTES, + DMA_TO_DEVICE); + if (dma_mapping_error(lan966x->dev, dma_addr)) { + ret = NETDEV_TX_OK; + goto out; + } - /* Setup next dcb */ - lan966x_fdma_tx_setup_dcb(tx, next_to_use, xdpf->len + IFH_LEN_BYTES, - dma_addr + XDP_PACKET_HEADROOM); + /* Setup next dcb */ + lan966x_fdma_tx_setup_dcb(tx, next_to_use, + xdpf->len + IFH_LEN_BYTES, + dma_addr); + } else { + ifh = page_address(page) + XDP_PACKET_HEADROOM; + memset(ifh, 0x0, sizeof(__be32) * IFH_LEN); + lan966x_ifh_set_bypass(ifh, 1); + lan966x_ifh_set_port(ifh, BIT_ULL(port->chip_port)); + + dma_addr = page_pool_get_dma_addr(page); + dma_sync_single_for_device(lan966x->dev, + dma_addr + XDP_PACKET_HEADROOM, + xdpf->len + IFH_LEN_BYTES, + DMA_TO_DEVICE); + + /* Setup next dcb */ + lan966x_fdma_tx_setup_dcb(tx, next_to_use, + xdpf->len + IFH_LEN_BYTES, + dma_addr + XDP_PACKET_HEADROOM); + } /* Fill up the buffer */ next_dcb_buf = &tx->dcbs_buf[next_to_use]; next_dcb_buf->skb = NULL; next_dcb_buf->xdpf = xdpf; + next_dcb_buf->xdp_ndo = dma_map; next_dcb_buf->len = xdpf->len + IFH_LEN_BYTES; next_dcb_buf->dma_addr = dma_addr; next_dcb_buf->used = true; @@ -792,6 +846,7 @@ int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev) next_dcb_buf = &tx->dcbs_buf[next_to_use]; next_dcb_buf->skb = skb; next_dcb_buf->xdpf = NULL; + next_dcb_buf->xdp_ndo = false; next_dcb_buf->len = skb->len; next_dcb_buf->dma_addr = dma_addr; next_dcb_buf->used = true; 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 e303a12daf88a..ed4adeae553d3 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; @@ -178,6 +180,7 @@ struct lan966x_tx_dcb_buf { struct net_device *dev; struct sk_buff *skb; struct xdp_frame *xdpf; + bool xdp_ndo; int len; dma_addr_t dma_addr; bool used; @@ -467,7 +470,8 @@ int lan966x_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts); int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev); int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, struct xdp_frame *frame, - struct page *page); + struct page *page, + bool dma_map); int lan966x_fdma_change_mtu(struct lan966x *lan966x); void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev); void lan966x_fdma_netdev_deinit(struct lan966x *lan966x, struct net_device *dev); @@ -565,6 +569,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); bool lan966x_xdp_present(struct lan966x *lan966x); static inline bool lan966x_xdp_port_present(struct lan966x_port *port) { diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c index 5fd2f3b01e179..9f363316115ae 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c @@ -50,6 +50,30 @@ 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), + true); + 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; @@ -72,8 +96,13 @@ int lan966x_xdp_run(struct lan966x_port *port, struct page *page, u32 data_len) if (!xdpf) return FDMA_DROP; - return lan966x_fdma_xmit_xdpf(port, xdpf, page) ? + return lan966x_fdma_xmit_xdpf(port, xdpf, page, false) ? 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;