From patchwork Sun Nov 6 21:11:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 16185 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1675467wru; Sun, 6 Nov 2022 13:08:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf7MH4p8INlL5yaHzIrVqSc/KVqWdKt7F1KjMocNRhGnDhXtrJJELzYnFaq/aM18H+8rFSC1 X-Received: by 2002:a63:610a:0:b0:470:70d6:d297 with SMTP id v10-20020a63610a000000b0047070d6d297mr2726510pgb.166.1667768922067; Sun, 06 Nov 2022 13:08:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667768922; cv=none; d=google.com; s=arc-20160816; b=S6zWMNyBYeaNfmeJGxW5EMLrprREIQ6ZPXqkLhKxqkXto6v2BJB101L6MUEXHDNvY4 1977heR91ZTFOM9HBElac5GsNZhpjtAATLD07e/Il5Yl0k79bDN+OFqsRiBlpOhWmr/k SYq1UivO4TFapPROPmt4cc+SEfWBBnn6w9h5gt9NZd0Nh/bNy9sUpEgiTsT8fA2ZE13H 9ClEYY3FZI/XUL7eBnAYVAmEypQwOS2MdLhpbkbfKYFgQlqeboHOnwg8IJhwLFuMTPI2 g508SXdTnjHLxBJhVX4yEaekJpHYLURtG0c2/OG1B5N4JeRX4WpYVCmbhqENbG15YszP txmg== 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=L1Gssuq1gegNNB944O+x/D6wlKgsz+SfHksedEi8o5s=; b=FMiwrqJOKblq/NOtMi+UUVVc2reiuczU03NstCe3wqL87mzTMJuNx3ivhZZIKmQdKF VMuqb0xVW5Qj1/eBIQgYrY+wz4Kq4Igx9Coi0al0NGDD8MYA77je0QXOTwHxqj0z4WAv fufyFNb0exeDL8uA1w7bF8flESER1GFid0tWrlbRGqyuSzLRXnmyR+Vu6cX12C+JrMf0 ZWzBKsTgaEdYRO4p5uSWumtMCa4293POdhdp1EWWcYuQrtqWZKndnR/cpWmsyrmiSVGY j/zEwulRwOsGqbmTn3zcGSS2xViR8ZEW38DUIRnNdyMgogOH2qNhWi9UbfSlYNzyjlGy 4zJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=v13Rj1Au; 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 p18-20020a170902ebd200b00186b84c723bsi8529814plg.419.2022.11.06.13.08.27; Sun, 06 Nov 2022 13:08:42 -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=v13Rj1Au; 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 S230175AbiKFVHe (ORCPT + 99 others); Sun, 6 Nov 2022 16:07:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230127AbiKFVHa (ORCPT ); Sun, 6 Nov 2022 16:07:30 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6CB6C2E; Sun, 6 Nov 2022 13:07:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1667768849; x=1699304849; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lY6x5gsAX5a41KCZivFjlGaNatdB1vzlaAiGBzdEo9E=; b=v13Rj1Aub3ETNTX2EC1gsIiMDwARymOl5s9YnSz9w+Z78GUiwcEOGlib vZdvGT254QUmWx74mqjt5sJNgH4GAgd85+K+vWJmRAyVYTKK9Em4Ql3Ei kk1q9YTXsW3bHn1x9efqnPHdgQu7kGz/iW7a08/DDNz6EJKrOvtRoRBQE ucKmiEL60oSKnDGXvbRhINPr5n9L7vUxy/ZZZNy29cBbZY4NWs05eqIHl jnslVoa4vqu+BL20oTTW4k7WBKoV6v5aSlMPPtFMXx0c9bW6dyawJRAvO 9EtlFo5Iilbbm37B+7xjSj3y0ozCf+njb9/7cjS2Zctls+Nz/Zcz3YRA0 g==; X-IronPort-AV: E=Sophos;i="5.96,142,1665471600"; d="scan'208";a="187885495" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 06 Nov 2022 14:07:29 -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; Sun, 6 Nov 2022 14:07:28 -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; Sun, 6 Nov 2022 14:07:26 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v2 1/4] net: lan966x: Add define IFH_LEN_BYTES Date: Sun, 6 Nov 2022 22:11:51 +0100 Message-ID: <20221106211154.3225784-2-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221106211154.3225784-1-horatiu.vultur@microchip.com> References: <20221106211154.3225784-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,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748782464793024738?= X-GMAIL-MSGID: =?utf-8?q?1748782464793024738?= The total length of IFH(inter frame header) in bytes is calculated as IFH_LEN * sizeof(u32). Because IFH_LEN describes the length in words and not in bytes. As the length of IFH in bytes is used quite often, add a define for this. This is just to simplify the things. Signed-off-by: Horatiu Vultur --- drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c | 10 +++++----- drivers/net/ethernet/microchip/lan966x/lan966x_ifh.h | 1 + drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index e6948939ccc2b..6c102ee20f1d7 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -436,7 +436,7 @@ static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx) DMA_ATTR_SKIP_CPU_SYNC); skb->dev = lan966x->ports[src_port]->dev; - skb_pull(skb, IFH_LEN * sizeof(u32)); + skb_pull(skb, IFH_LEN_BYTES); if (likely(!(skb->dev->features & NETIF_F_RXFCS))) skb_trim(skb, skb->len - ETH_FCS_LEN); @@ -592,7 +592,7 @@ int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev) } /* skb processing */ - needed_headroom = max_t(int, IFH_LEN * sizeof(u32) - skb_headroom(skb), 0); + needed_headroom = max_t(int, IFH_LEN_BYTES - skb_headroom(skb), 0); needed_tailroom = max_t(int, ETH_FCS_LEN - skb_tailroom(skb), 0); if (needed_headroom || needed_tailroom || skb_header_cloned(skb)) { err = pskb_expand_head(skb, needed_headroom, needed_tailroom, @@ -605,8 +605,8 @@ int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev) } skb_tx_timestamp(skb); - skb_push(skb, IFH_LEN * sizeof(u32)); - memcpy(skb->data, ifh, IFH_LEN * sizeof(u32)); + skb_push(skb, IFH_LEN_BYTES); + memcpy(skb->data, ifh, IFH_LEN_BYTES); skb_put(skb, 4); dma_addr = dma_map_single(lan966x->dev, skb->data, skb->len, @@ -740,7 +740,7 @@ int lan966x_fdma_change_mtu(struct lan966x *lan966x) u32 val; max_mtu = lan966x_fdma_get_max_mtu(lan966x); - max_mtu += IFH_LEN * sizeof(u32); + max_mtu += IFH_LEN_BYTES; max_mtu += SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); max_mtu += VLAN_HLEN * 2; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_ifh.h b/drivers/net/ethernet/microchip/lan966x/lan966x_ifh.h index ca3314789d18d..f3b1e0d318261 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_ifh.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_ifh.h @@ -8,6 +8,7 @@ */ #define IFH_LEN 7 +#define IFH_LEN_BYTES (IFH_LEN * sizeof(u32)) /* Timestamp for frame */ #define IFH_POS_TIMESTAMP 192 diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 20ee5b28f70a5..1a27946ccaf44 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -760,7 +760,7 @@ static int lan966x_probe_port(struct lan966x *lan966x, u32 p, NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_TC; dev->hw_features |= NETIF_F_HW_TC; - dev->needed_headroom = IFH_LEN * sizeof(u32); + dev->needed_headroom = IFH_LEN_BYTES; eth_hw_addr_gen(dev, lan966x->base_mac, p + 1); From patchwork Sun Nov 6 21:11:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 16186 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1675590wru; Sun, 6 Nov 2022 13:08:59 -0800 (PST) X-Google-Smtp-Source: AMsMyM6cYMUn9gYVWMX1Uh3ReiKCgyXnxBFwDuKv12kL7qhUSSIZBrUO2OMkj1evtiswrZq+LBPm X-Received: by 2002:a65:45c9:0:b0:470:2ecc:c96f with SMTP id m9-20020a6545c9000000b004702eccc96fmr14266131pgr.123.1667768939293; Sun, 06 Nov 2022 13:08:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667768939; cv=none; d=google.com; s=arc-20160816; b=E/hdOm5D00KvkXpxOHGWcCauXPfenB7HEsvw0L0Vseu8RJgQAjZQbMd9UcGkk3ZIJf 563AH59bm0UhtHi0ZorS5Be1Jb9xubhNng6vLqnKfFEPtQFwsBlfn9dO8xY1/g082ARO llWLWd93JR5/NOFmi/NA9AVOUimYJ9Hw9v4G5v8MELbCeOiCZpyvAdNBtpJTjgyg0vGW FCI7NQce8HWKJOZ+K1s5F3nPuq13PG4ckpg7Gv2Png/wZfs0bFoCo2KagrcxA5dhbE5o olZ0Qy15rcQhEl70QFqXvlSy33Of/ejNQu/h3MA8OaYCYGOLoN8wWXud7G/STiADq6pv QBqg== 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=xnOx9bd04bgh7Bb1QSSwxtatP3OHYtqLXcv/5Q9z2uk=; b=ZSLJr5LomgY+r4rSz9ksrajnqZyBV13gaKCtsJYr3529Qjw96Sk+C9mXakG02tOM5w XxU9ItMXIBoWk8ZIC2AVOeDZIDg09VkCcejw4Orf8MpW0OUOyCjjEeiqsdJuhr2VRjeY 8WBSHTtdDVnDiccBJlGB5X9jmcguI+Ur7f18znNnP0t++6V3ZMwcTcOQX3bRly2B655p mQspy0vqpjrF9BStLPihfzAGZC9PHen7bknFdzNgz1Zgz0IXr6ZzJMftDKNku0QtrjWX uAlqW+gq3WmtSM8/oycPhvHtOYGFHRuA4YqLhAfPSGA5WOZgYRjYIG5ivw+fyr34AOmM Yk/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=WCOJ1fvD; 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 j62-20020a638041000000b00470693437b8si3834840pgd.550.2022.11.06.13.08.46; Sun, 06 Nov 2022 13:08:59 -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=WCOJ1fvD; 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 S230304AbiKFVHq (ORCPT + 99 others); Sun, 6 Nov 2022 16:07:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230187AbiKFVHe (ORCPT ); Sun, 6 Nov 2022 16:07:34 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 875C91183B; Sun, 6 Nov 2022 13:07:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1667768853; x=1699304853; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9EaKjxyRgL3ce9mWgRq8+a6jtQ3V00iuJxjk1OMiI84=; b=WCOJ1fvD3apjo+Ln6dqRzETiUblSoEOQvT4X6imaGvbiN0JZ5r2li3gL +FPhwjl83wMxDBk3/wYnjEZLd1qaNIEhNOH6LfQkDWKGejva7qCSudOo1 tEQddmSaQdS96utSeM9cR7azTigG5P6DSbB6uKZ0gqsTyv8423GbI5nsZ bfv1GdxThJ+7Z/BDbsQuVEWfVcw3sMimq/aP9tmZvhZJgRbJXRQz+JZIR XgbAJ07dUAWHiWBeKrgE1AGzjm3b8M+sfkE3elZOPXo9spAvUObVpA0L8 Fw3lMrWQcKjp0FcNK9ymvV9/Vpis7FOYctjT1xKxsngoJxQu6FHr3p5hj w==; X-IronPort-AV: E=Sophos;i="5.96,142,1665471600"; d="scan'208";a="122044427" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 06 Nov 2022 14:07:32 -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; Sun, 6 Nov 2022 14:07:31 -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; Sun, 6 Nov 2022 14:07:29 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v2 2/4] net: lan966x: Split function lan966x_fdma_rx_get_frame Date: Sun, 6 Nov 2022 22:11:52 +0100 Message-ID: <20221106211154.3225784-3-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221106211154.3225784-1-horatiu.vultur@microchip.com> References: <20221106211154.3225784-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,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748782483452506675?= X-GMAIL-MSGID: =?utf-8?q?1748782483452506675?= The function lan966x_fdma_rx_get_frame was unmapping the frame from device and check also if the frame was received on a valid port. And only after that it tried to generate the skb. Move this check in a different function, in preparation for xdp support. Such that xdp to be added here and the lan966x_fdma_rx_get_frame to be used only when giving the skb to upper layers. Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 85 +++++++++++++------ .../ethernet/microchip/lan966x/lan966x_main.h | 9 ++ 2 files changed, 69 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 6c102ee20f1d7..d37765ddd53ae 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -54,6 +54,17 @@ static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx) } } +static void lan966x_fdma_rx_free_page(struct lan966x_rx *rx) +{ + struct page *page; + + page = rx->page[rx->dcb_index][rx->db_index]; + if (unlikely(!page)) + return; + + __free_pages(page, rx->page_order); +} + static void lan966x_fdma_rx_add_dcb(struct lan966x_rx *rx, struct lan966x_rx_dcb *dcb, u64 nextptr) @@ -116,6 +127,12 @@ static int lan966x_fdma_rx_alloc(struct lan966x_rx *rx) return 0; } +static void lan966x_fdma_rx_advance_dcb(struct lan966x_rx *rx) +{ + rx->dcb_index++; + rx->dcb_index &= FDMA_DCB_MAX - 1; +} + static void lan966x_fdma_rx_free(struct lan966x_rx *rx) { struct lan966x *lan966x = rx->lan966x; @@ -403,38 +420,53 @@ static bool lan966x_fdma_rx_more_frames(struct lan966x_rx *rx) return true; } -static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx) +static int lan966x_fdma_rx_check_frame(struct lan966x_rx *rx, u64 *src_port) { struct lan966x *lan966x = rx->lan966x; - u64 src_port, timestamp; struct lan966x_db *db; - struct sk_buff *skb; struct page *page; - /* Get the received frame and unmap it */ db = &rx->dcbs[rx->dcb_index].db[rx->db_index]; page = rx->page[rx->dcb_index][rx->db_index]; + if (unlikely(!page)) + return FDMA_ERROR; dma_sync_single_for_cpu(lan966x->dev, (dma_addr_t)db->dataptr, FDMA_DCB_STATUS_BLOCKL(db->status), DMA_FROM_DEVICE); + dma_unmap_single_attrs(lan966x->dev, (dma_addr_t)db->dataptr, + PAGE_SIZE << rx->page_order, DMA_FROM_DEVICE, + DMA_ATTR_SKIP_CPU_SYNC); + + lan966x_ifh_get_src_port(page_address(page), src_port); + if (WARN_ON(*src_port >= lan966x->num_phys_ports)) + return FDMA_ERROR; + + return FDMA_PASS; +} + +static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx, + u64 src_port) +{ + struct lan966x *lan966x = rx->lan966x; + struct lan966x_db *db; + struct sk_buff *skb; + struct page *page; + u64 timestamp; + + /* Get the received frame and unmap it */ + db = &rx->dcbs[rx->dcb_index].db[rx->db_index]; + page = rx->page[rx->dcb_index][rx->db_index]; + skb = build_skb(page_address(page), PAGE_SIZE << rx->page_order); if (unlikely(!skb)) - goto unmap_page; + goto free_page; skb_put(skb, FDMA_DCB_STATUS_BLOCKL(db->status)); - lan966x_ifh_get_src_port(skb->data, &src_port); lan966x_ifh_get_timestamp(skb->data, ×tamp); - if (WARN_ON(src_port >= lan966x->num_phys_ports)) - goto free_skb; - - dma_unmap_single_attrs(lan966x->dev, (dma_addr_t)db->dataptr, - PAGE_SIZE << rx->page_order, DMA_FROM_DEVICE, - DMA_ATTR_SKIP_CPU_SYNC); - skb->dev = lan966x->ports[src_port]->dev; skb_pull(skb, IFH_LEN_BYTES); @@ -457,12 +489,7 @@ static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx) return skb; -free_skb: - kfree_skb(skb); -unmap_page: - dma_unmap_single_attrs(lan966x->dev, (dma_addr_t)db->dataptr, - PAGE_SIZE << rx->page_order, DMA_FROM_DEVICE, - DMA_ATTR_SKIP_CPU_SYNC); +free_page: __free_pages(page, rx->page_order); return NULL; @@ -478,6 +505,7 @@ static int lan966x_fdma_napi_poll(struct napi_struct *napi, int weight) struct sk_buff *skb; struct page *page; int counter = 0; + u64 src_port; u64 nextptr; lan966x_fdma_tx_clear_buf(lan966x, weight); @@ -487,19 +515,26 @@ static int lan966x_fdma_napi_poll(struct napi_struct *napi, int weight) if (!lan966x_fdma_rx_more_frames(rx)) break; - skb = lan966x_fdma_rx_get_frame(rx); + counter++; - rx->page[rx->dcb_index][rx->db_index] = NULL; - rx->dcb_index++; - rx->dcb_index &= FDMA_DCB_MAX - 1; + switch (lan966x_fdma_rx_check_frame(rx, &src_port)) { + case FDMA_PASS: + break; + case FDMA_ERROR: + lan966x_fdma_rx_free_page(rx); + lan966x_fdma_rx_advance_dcb(rx); + goto allocate_new; + } + skb = lan966x_fdma_rx_get_frame(rx, src_port); + lan966x_fdma_rx_advance_dcb(rx); if (!skb) - break; + goto allocate_new; napi_gro_receive(&lan966x->napi, skb); - counter++; } +allocate_new: /* Allocate new pages and map them */ while (dcb_reload != rx->dcb_index) { db = &rx->dcbs[dcb_reload].db[rx->db_index]; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 4ec33999e4df6..464fb5e4a8ff6 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -100,6 +100,15 @@ enum macaccess_entry_type { ENTRYTYPE_MACV6, }; +/* FDMA return action codes for checking if the frame is valid + * FDMA_PASS, frame is valid and can be used + * FDMA_ERROR, something went wrong, stop getting more frames + */ +enum lan966x_fdma_action { + FDMA_PASS = 0, + FDMA_ERROR, +}; + struct lan966x_port; struct lan966x_db { From patchwork Sun Nov 6 21:11:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 16188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1675669wru; Sun, 6 Nov 2022 13:09:09 -0800 (PST) X-Google-Smtp-Source: AMsMyM4cAV++iGlS0wnSoP7IGPaoW27qnrFf5ZWY5k2+8tHDrBdueYPoPVRCWvu15tK/9mLrmjFh X-Received: by 2002:a17:902:8685:b0:186:cb66:d77b with SMTP id g5-20020a170902868500b00186cb66d77bmr48021713plo.39.1667768949229; Sun, 06 Nov 2022 13:09:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667768949; cv=none; d=google.com; s=arc-20160816; b=ftq8Id1S764x4Ya+fE4l6rVqbUcBy+Qn6oS8xEQwfx+TU8YJtOi1vusYIXh1BJ4D2v 6RtnU2gtidPqY+96WpUHVX6BGdbiGUrym35bot+S+OcbmhC1qCEr3RCAxnT8pZbdrLQ5 XJ+/GE2T8xX4Ol1Xej3yHyad5QP8tmwxUA75wpPLZH/mFjk+qJ7aLOWdM+Iu5LOL5qJ0 QnAGkY4Kkfx9a1Ojn94owUVFYBSTZeHrdJEsEM8+JuOIp+LRicwxNT8RRXtOBoTFk1IO yg0/EEe9zcgBsreiQM+a4mCVOYuYb3Vu1TA8vP4XefX0uW6BlQs3oV/PwLsc7hhXY5Ps GmvA== 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=qh4mPc2xo8yO4gT218RkHMa2JyEUDfVhbtRqMqYmXT8=; b=bmfPacE1KbP6Sb/qOQXyh3XOFq7NuydEoT+ve2sChti0EuBXCs2YX3samOsFaj761r lvDErDfnIIEG5gOquFTtSrxqRnRyZA6m9Aj5+SEPMrc3dN1POlrqGssV5ahF/4GwI4BJ yg96l9PpZ5bhFOokdhn9AB/egJkroCsLJDXLz9UHWP+pdNlaezVthD2Bb40Z/rSAGUUi a4IghaqmrbXCMsKt0m0RXyKkPh560IzRqvxdSeVz9pvR453zC7WKExBLe0tyw0Q2roUb XEo7us5H7MH/IWnGTZZKjhahDpIj4psAmZUrosLAi/G4IiWa5pK9I/5g9BZk7Y/32dAM iIKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=vq9048FY; 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 z4-20020aa78884000000b0053837d7cf84si8743761pfe.254.2022.11.06.13.08.57; Sun, 06 Nov 2022 13:09:09 -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=vq9048FY; 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 S230329AbiKFVH4 (ORCPT + 99 others); Sun, 6 Nov 2022 16:07:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230207AbiKFVHh (ORCPT ); Sun, 6 Nov 2022 16:07:37 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ABC011A38; Sun, 6 Nov 2022 13:07:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1667768855; x=1699304855; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AcKbgq8eHUcebSnBNXishcsZ6PGYC2M9sFMuWQxliLM=; b=vq9048FYKtjMkIHLfO+JXNFPB80w778heYRDKITAicDZB+SoC8Ze+9yu Y6btuVKq1qlyMzN3hh/IvVTdG6YZ5EbeKCshgDcVtTHRwIzqqajfEjAB0 QEOW+dqKYe/g2zn1fTTQ3Q0X8O5AwPHg0Kg2Yg5cbEzQDS4uBJlmaoYO+ cSseZ+AeeS6+mdBCjy8Q4NMojh/X1znSIEVoSVVw9ixpxMTREGVaEKDsT HhbqBm61+WWy2aiBeXhQs8mzdrmTSqva4ILSgXqQoh49B1f2Qke9MfaeO s3aRVCw/FUeNL0ojSNWaWY/P3x3+lcH/x0Bb/ZIU7wtntbt7155eGh89s w==; X-IronPort-AV: E=Sophos;i="5.96,142,1665471600"; d="scan'208";a="187885510" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 06 Nov 2022 14:07:35 -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; Sun, 6 Nov 2022 14:07:34 -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; Sun, 6 Nov 2022 14:07:32 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v2 3/4] net: lan966x: Add basic XDP support Date: Sun, 6 Nov 2022 22:11:53 +0100 Message-ID: <20221106211154.3225784-4-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221106211154.3225784-1-horatiu.vultur@microchip.com> References: <20221106211154.3225784-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,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748782493413363402?= X-GMAIL-MSGID: =?utf-8?q?1748782493413363402?= Introduce basic XDP support to lan966x driver. Currently the driver supports only the actions XDP_PASS, XDP_DROP and XDP_ABORTED. Signed-off-by: Horatiu Vultur --- .../net/ethernet/microchip/lan966x/Makefile | 3 +- .../ethernet/microchip/lan966x/lan966x_fdma.c | 11 ++- .../ethernet/microchip/lan966x/lan966x_main.c | 5 ++ .../ethernet/microchip/lan966x/lan966x_main.h | 13 +++ .../ethernet/microchip/lan966x/lan966x_xdp.c | 81 +++++++++++++++++++ 5 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c diff --git a/drivers/net/ethernet/microchip/lan966x/Makefile b/drivers/net/ethernet/microchip/lan966x/Makefile index 962f7c5f9e7dd..251a7d561d633 100644 --- a/drivers/net/ethernet/microchip/lan966x/Makefile +++ b/drivers/net/ethernet/microchip/lan966x/Makefile @@ -11,4 +11,5 @@ lan966x-switch-objs := lan966x_main.o lan966x_phylink.o lan966x_port.o \ lan966x_ptp.o lan966x_fdma.o lan966x_lag.o \ lan966x_tc.o lan966x_mqprio.o lan966x_taprio.o \ lan966x_tbf.o lan966x_cbs.o lan966x_ets.o \ - lan966x_tc_matchall.o lan966x_police.o lan966x_mirror.o + lan966x_tc_matchall.o lan966x_police.o lan966x_mirror.o \ + lan966x_xdp.o diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index d37765ddd53ae..fa4198c617667 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -423,6 +423,7 @@ static bool lan966x_fdma_rx_more_frames(struct lan966x_rx *rx) static int lan966x_fdma_rx_check_frame(struct lan966x_rx *rx, u64 *src_port) { struct lan966x *lan966x = rx->lan966x; + struct lan966x_port *port; struct lan966x_db *db; struct page *page; @@ -443,7 +444,11 @@ static int lan966x_fdma_rx_check_frame(struct lan966x_rx *rx, u64 *src_port) if (WARN_ON(*src_port >= lan966x->num_phys_ports)) return FDMA_ERROR; - return FDMA_PASS; + port = lan966x->ports[*src_port]; + if (!lan966x_xdp_port_present(port)) + return FDMA_PASS; + + return lan966x_xdp_run(port, page, FDMA_DCB_STATUS_BLOCKL(db->status)); } static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx, @@ -524,6 +529,10 @@ 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_DROP: + lan966x_fdma_rx_free_page(rx); + lan966x_fdma_rx_advance_dcb(rx); + continue; } skb = lan966x_fdma_rx_get_frame(rx, src_port); diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 1a27946ccaf44..42be5d0f1f015 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -468,6 +468,7 @@ static const struct net_device_ops lan966x_port_netdev_ops = { .ndo_get_port_parent_id = lan966x_port_get_parent_id, .ndo_eth_ioctl = lan966x_port_ioctl, .ndo_setup_tc = lan966x_tc_setup, + .ndo_bpf = lan966x_xdp, }; bool lan966x_netdevice_check(const struct net_device *dev) @@ -694,6 +695,7 @@ static void lan966x_cleanup_ports(struct lan966x *lan966x) if (port->dev) unregister_netdev(port->dev); + lan966x_xdp_port_deinit(port); if (lan966x->fdma && lan966x->fdma_ndev == port->dev) lan966x_fdma_netdev_deinit(lan966x, port->dev); @@ -1136,6 +1138,9 @@ static int lan966x_probe(struct platform_device *pdev) lan966x->ports[p]->serdes = serdes; lan966x_port_init(lan966x->ports[p]); + err = lan966x_xdp_port_init(lan966x->ports[p]); + if (err) + goto cleanup_ports; } lan966x_mdb_init(lan966x); diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 464fb5e4a8ff6..18f727f397fd6 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -103,10 +103,12 @@ enum macaccess_entry_type { /* FDMA return action codes for checking if the frame is valid * 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 */ enum lan966x_fdma_action { FDMA_PASS = 0, FDMA_ERROR, + FDMA_DROP, }; struct lan966x_port; @@ -329,6 +331,9 @@ struct lan966x_port { enum netdev_lag_hash hash_type; struct lan966x_port_tc tc; + + struct bpf_prog *xdp_prog; + struct xdp_rxq_info xdp_rxq; }; extern const struct phylink_mac_ops lan966x_phylink_mac_ops; @@ -536,6 +541,14 @@ void lan966x_mirror_port_stats(struct lan966x_port *port, struct flow_stats *stats, bool ingress); +int lan966x_xdp_port_init(struct lan966x_port *port); +void lan966x_xdp_port_deinit(struct lan966x_port *port); +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_port_present(struct lan966x_port *port); + static inline void __iomem *lan_addr(void __iomem *base[], int id, int tinst, int tcnt, int gbase, int ginst, diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c new file mode 100644 index 0000000000000..b8f30abf4f795 --- /dev/null +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include + +#include "lan966x_main.h" + +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; + + if (!lan966x->fdma) { + NL_SET_ERR_MSG_MOD(xdp->extack, + "Allow to set xdp only when using fdma"); + return -EOPNOTSUPP; + } + + old_prog = xchg(&port->xdp_prog, xdp->prog); + if (old_prog) + bpf_prog_put(old_prog); + + return 0; +} + +int lan966x_xdp(struct net_device *dev, struct netdev_bpf *xdp) +{ + switch (xdp->command) { + case XDP_SETUP_PROG: + return lan966x_xdp_setup(dev, xdp); + default: + return -EINVAL; + } +} + +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_buff xdp; + u32 act; + + xdp_init_buff(&xdp, PAGE_SIZE << lan966x->rx.page_order, + &port->xdp_rxq); + xdp_prepare_buff(&xdp, page_address(page), IFH_LEN_BYTES, + data_len - IFH_LEN_BYTES, false); + act = bpf_prog_run_xdp(xdp_prog, &xdp); + switch (act) { + case XDP_PASS: + return FDMA_PASS; + default: + bpf_warn_invalid_xdp_action(port->dev, xdp_prog, act); + fallthrough; + case XDP_ABORTED: + trace_xdp_exception(port->dev, xdp_prog, act); + fallthrough; + case XDP_DROP: + return FDMA_DROP; + } +} + +bool lan966x_xdp_port_present(struct lan966x_port *port) +{ + return !!port->xdp_prog; +} + +int lan966x_xdp_port_init(struct lan966x_port *port) +{ + struct lan966x *lan966x = port->lan966x; + + return xdp_rxq_info_reg(&port->xdp_rxq, port->dev, 0, + lan966x->napi.napi_id); +} + +void lan966x_xdp_port_deinit(struct lan966x_port *port) +{ + if (xdp_rxq_info_is_reg(&port->xdp_rxq)) + xdp_rxq_info_unreg(&port->xdp_rxq); +} From patchwork Sun Nov 6 21:11:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 16187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1675641wru; Sun, 6 Nov 2022 13:09:07 -0800 (PST) X-Google-Smtp-Source: AMsMyM44jPZ3ajed+k7sRjYR0Q91ej9bLArmk7LTDhzHhLgJJGUgxTUxI99fm/txg46sbTwSVkLz X-Received: by 2002:a17:902:e54a:b0:186:a3ba:232a with SMTP id n10-20020a170902e54a00b00186a3ba232amr46921714plf.77.1667768947016; Sun, 06 Nov 2022 13:09:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667768947; cv=none; d=google.com; s=arc-20160816; b=wCDkjyuGFY+jQOEhzgFSc2VymcuXQo+74hE+mYMUsBygOjZ3Td9ubyQpl0JUNG+FFL aP9zTQxmnzAO/TalZxU8wEeGGSB198J2rfOpBDQktjMYy0A0CFJgIQ8eo7K58hWIlss2 DiJn7BHYnwXRMQQfD1aQqJabynPvvDPK/sj/ictVWl1ZM75vx+iLJBFlUbOKSivalBSO 2opf1kS36skijSF5KVZBIQFMQY2bmWiqMkBv7Lxln36noXcF0PKr6SZ9/hn8kRybWRmP WUv8ljXWJOmKdWSbeCdit8ZrhjadkdOoz5MWj5zOctdJ+yKb5RaUdniA+Y5qvquvr4bp A14g== 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=1S9MvSpE2MufJ0uSoIBRQ36vN7DRZYTyZWNlPKJv8yM=; b=diOxNtZS7hnbrojWHQJ3N8MOdkEF8lr8jwFTTVQU8LRy/0UVPMbg9OQLdf6rh883fR Fpmk6nBfOPOSXRuxQVieXmVJIF8CiY7e6FC5TE1vG73pRiip78OJ3+8A1UVJRiWZEwGk KTLRFMNU/94YLTQ2DzdZLEYyhTAQpAExpbFaNY7yJO4CQP8JlJEq4CQSe/lKMvQLDfVY xwJyI1yzYUaUWoTD9kN2HMs/83SON6IHOBZP2cqwVUgwuFC+sguiyYTKa7lYG1c0yMWN YjsS0zAAy8jjeDvGWqhXezcHq+3Td7galrCLBAy3Pz5qOKFPrWbP72t/bCEy2TzrF6Zt fRvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=GfjHJyT2; 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 cp8-20020a056a00348800b0056c2a741b03si7276093pfb.81.2022.11.06.13.08.54; Sun, 06 Nov 2022 13:09:06 -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=GfjHJyT2; 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 S230264AbiKFVHv (ORCPT + 99 others); Sun, 6 Nov 2022 16:07:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230254AbiKFVHn (ORCPT ); Sun, 6 Nov 2022 16:07:43 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B5E311A3C; Sun, 6 Nov 2022 13:07:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1667768858; x=1699304858; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Dda4GjcqT3Bkv68MV+0TVCyhYSee8nGRh9xescJp9Ew=; b=GfjHJyT2aFomWqpZKym3W0j1+xXaMUie/xlNR5i84PAg4ozLQiQBo3qS zBvD+JgREqpsBUKY26udulzf7mtSbHT16TWW62lm3f04vvAglth+kOOtp nG398A6vRc4sRpu21S/BqWSeGKGOCtL6z2pgp3PaJ0RWUmZ7gZZqJf/IA g9gQESxylSE4ieQJOAyqs32kPTk5gwffi/7tFXCVR+zJ41hZwrS/3lXIu +AZjso3XFG4zRTkgPzD3ICDnXHO6askYdW4LGq9lz3dHUgYvXIrQ4f8GM NPwKPnDltsuP1jCwC+CSTI5VjF6MLVc4bzLD/zIvPWulQ4pgPRnmCIqaa Q==; X-IronPort-AV: E=Sophos;i="5.96,142,1665471600"; d="scan'208";a="187885516" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 06 Nov 2022 14:07:37 -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; Sun, 6 Nov 2022 14:07:37 -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; Sun, 6 Nov 2022 14:07:34 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v2 4/4] net: lan96x: Use page_pool API Date: Sun, 6 Nov 2022 22:11:54 +0100 Message-ID: <20221106211154.3225784-5-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221106211154.3225784-1-horatiu.vultur@microchip.com> References: <20221106211154.3225784-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,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748782491537820528?= X-GMAIL-MSGID: =?utf-8?q?1748782491537820528?= Use the page_pool API for allocation, freeing and DMA handling instead of dev_alloc_pages, __free_pages and dma_map_page. Signed-off-by: Horatiu Vultur --- .../net/ethernet/microchip/lan966x/Kconfig | 1 + .../ethernet/microchip/lan966x/lan966x_fdma.c | 72 ++++++++++--------- .../ethernet/microchip/lan966x/lan966x_main.h | 3 + 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/Kconfig b/drivers/net/ethernet/microchip/lan966x/Kconfig index 49e1464a43139..b7ae5ce7d3f7a 100644 --- a/drivers/net/ethernet/microchip/lan966x/Kconfig +++ b/drivers/net/ethernet/microchip/lan966x/Kconfig @@ -7,5 +7,6 @@ config LAN966X_SWITCH depends on BRIDGE || BRIDGE=n select PHYLINK select PACKING + select PAGE_POOL help This driver supports the Lan966x network switch device. diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index fa4198c617667..822c1b053e2d0 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -10,47 +10,25 @@ static int lan966x_fdma_channel_active(struct lan966x *lan966x) static struct page *lan966x_fdma_rx_alloc_page(struct lan966x_rx *rx, struct lan966x_db *db) { - struct lan966x *lan966x = rx->lan966x; - dma_addr_t dma_addr; struct page *page; - page = dev_alloc_pages(rx->page_order); + page = page_pool_dev_alloc_pages(rx->page_pool); if (unlikely(!page)) return NULL; - dma_addr = dma_map_page(lan966x->dev, page, 0, - PAGE_SIZE << rx->page_order, - DMA_FROM_DEVICE); - if (unlikely(dma_mapping_error(lan966x->dev, dma_addr))) - goto free_page; - - db->dataptr = dma_addr; + db->dataptr = page_pool_get_dma_addr(page); return page; - -free_page: - __free_pages(page, rx->page_order); - return NULL; } static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx) { - struct lan966x *lan966x = rx->lan966x; - struct lan966x_rx_dcb *dcb; - struct lan966x_db *db; int i, j; for (i = 0; i < FDMA_DCB_MAX; ++i) { - dcb = &rx->dcbs[i]; - - for (j = 0; j < FDMA_RX_DCB_MAX_DBS; ++j) { - db = &dcb->db[j]; - dma_unmap_single(lan966x->dev, - (dma_addr_t)db->dataptr, - PAGE_SIZE << rx->page_order, - DMA_FROM_DEVICE); - __free_pages(rx->page[i][j], rx->page_order); - } + for (j = 0; j < FDMA_RX_DCB_MAX_DBS; ++j) + page_pool_put_full_page(rx->page_pool, + rx->page[i][j], false); } } @@ -62,7 +40,7 @@ static void lan966x_fdma_rx_free_page(struct lan966x_rx *rx) if (unlikely(!page)) return; - __free_pages(page, rx->page_order); + page_pool_recycle_direct(rx->page_pool, page); } static void lan966x_fdma_rx_add_dcb(struct lan966x_rx *rx, @@ -84,6 +62,27 @@ static void lan966x_fdma_rx_add_dcb(struct lan966x_rx *rx, rx->last_entry = dcb; } +static int lan966x_fdma_rx_alloc_page_pool(struct lan966x_rx *rx) +{ + struct lan966x *lan966x = rx->lan966x; + struct page_pool_params pp_params = { + .order = rx->page_order, + .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, + .pool_size = FDMA_DCB_MAX, + .nid = NUMA_NO_NODE, + .dev = lan966x->dev, + .dma_dir = DMA_FROM_DEVICE, + .offset = 0, + .max_len = PAGE_SIZE << rx->page_order, + }; + + rx->page_pool = page_pool_create(&pp_params); + if (IS_ERR(rx->page_pool)) + return PTR_ERR(rx->page_pool); + + return 0; +} + static int lan966x_fdma_rx_alloc(struct lan966x_rx *rx) { struct lan966x *lan966x = rx->lan966x; @@ -93,6 +92,9 @@ static int lan966x_fdma_rx_alloc(struct lan966x_rx *rx) int i, j; int size; + if (lan966x_fdma_rx_alloc_page_pool(rx)) + return PTR_ERR(rx->page_pool); + /* calculate how many pages are needed to allocate the dcbs */ size = sizeof(struct lan966x_rx_dcb) * FDMA_DCB_MAX; size = ALIGN(size, PAGE_SIZE); @@ -436,10 +438,6 @@ static int lan966x_fdma_rx_check_frame(struct lan966x_rx *rx, u64 *src_port) FDMA_DCB_STATUS_BLOCKL(db->status), DMA_FROM_DEVICE); - dma_unmap_single_attrs(lan966x->dev, (dma_addr_t)db->dataptr, - PAGE_SIZE << rx->page_order, DMA_FROM_DEVICE, - DMA_ATTR_SKIP_CPU_SYNC); - lan966x_ifh_get_src_port(page_address(page), src_port); if (WARN_ON(*src_port >= lan966x->num_phys_ports)) return FDMA_ERROR; @@ -468,6 +466,8 @@ static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx, if (unlikely(!skb)) goto free_page; + skb_mark_for_recycle(skb); + skb_put(skb, FDMA_DCB_STATUS_BLOCKL(db->status)); lan966x_ifh_get_timestamp(skb->data, ×tamp); @@ -495,7 +495,7 @@ static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx, return skb; free_page: - __free_pages(page, rx->page_order); + page_pool_recycle_direct(rx->page_pool, page); return NULL; } @@ -740,6 +740,7 @@ static int lan966x_qsys_sw_status(struct lan966x *lan966x) static int lan966x_fdma_reload(struct lan966x *lan966x, int new_mtu) { + struct page_pool *page_pool; dma_addr_t rx_dma; void *rx_dcbs; u32 size; @@ -748,6 +749,7 @@ static int lan966x_fdma_reload(struct lan966x *lan966x, int new_mtu) /* Store these for later to free them */ rx_dma = lan966x->rx.dma; rx_dcbs = lan966x->rx.dcbs; + page_pool = lan966x->rx.page_pool; napi_synchronize(&lan966x->napi); napi_disable(&lan966x->napi); @@ -765,11 +767,14 @@ static int lan966x_fdma_reload(struct lan966x *lan966x, int new_mtu) size = ALIGN(size, PAGE_SIZE); dma_free_coherent(lan966x->dev, size, rx_dcbs, rx_dma); + page_pool_destroy(page_pool); + lan966x_fdma_wakeup_netdev(lan966x); napi_enable(&lan966x->napi); return err; restore: + lan966x->rx.page_pool = page_pool; lan966x->rx.dma = rx_dma; lan966x->rx.dcbs = rx_dcbs; lan966x_fdma_rx_start(&lan966x->rx); @@ -876,5 +881,6 @@ void lan966x_fdma_deinit(struct lan966x *lan966x) lan966x_fdma_rx_free_pages(&lan966x->rx); lan966x_fdma_rx_free(&lan966x->rx); + page_pool_destroy(lan966x->rx.page_pool); lan966x_fdma_tx_free(&lan966x->tx); } diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 18f727f397fd6..97652a73017a2 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -162,6 +163,8 @@ struct lan966x_rx { u8 page_order; u8 channel_id; + + struct page_pool *page_pool; }; struct lan966x_tx_dcb_buf {