Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2476841pxb; Tue, 13 Apr 2021 02:55:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJDEPwUWTEsJYG0zpBpaMuCHfT1UDb3S/rk7LRYnWvk+OkYI7qc3K0fs7+jJu5G072Txbb X-Received: by 2002:a17:902:64:b029:eb:1827:de61 with SMTP id 91-20020a1709020064b02900eb1827de61mr5576694pla.32.1618307755623; Tue, 13 Apr 2021 02:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618307755; cv=none; d=google.com; s=arc-20160816; b=TqaxtMAxH3m/JRhEiL29t1ZWJEKG8BJd90KB6wa+FgZJ6NI3isNUjiY/qgBgA3y5fg Yf/slfhky0t+9pjx5Y03f73bL3lcOcN7rajjqpzpxOGJs7irTNHQsWT11gXJP37X0W/a wndyQUTnvkX27wdVJEAx74xhgr7A+EX8d9sMtPcSC50AE/smcf47a61sbwP2h4JdJcEm nMUmlhX/KjKj6V0GE3J8tggJvJ2uhm5ZwFiaRU01WH/eby/dUoGVdb91QUGJHvv0iRFi Ku+9O8Dqm9uvQRRxm6JnQ85IFnQbMi8yuaX7HBHbSEbTIBmp6VKAfG+8z4+tKDh8lPeQ IlEg== 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 :ironport-sdr:ironport-sdr; bh=asT62JkJAidvdD7UWG30F3qINeBSoKs5djMCZj9XWco=; b=pPABdLvq3BdX0vR7MPighAfRSIR2s+fYYN0XvZwlVzl/F4/J1CHxwLO6f2l7za0Ddc 5/ZSHIBcqpvreXGEm4inEVECqrsdp8pRJkeL5DOf5K+dgl8JBRqEsWn6FMxkJw0HW6pV BJf8PnZTG+dfK1V0Z3gpEPXtcgySUWygCkCVzqy4gcOaJLNbEDmULuIhe2BSZprsaKfv 4ggGF6ojoKSWJu31+9CxvxSjGzRDqy4BfBCSz0nYQhn3jfSQ5bHKf6IQ1FNzg6vnglGM iH91RueVeVe1caK/FtwTfEsQnKqgSGHuhQpQPvr+dnolwmtlAPmU5B5xeZS0BsM/OhwC XZ4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v5si16957385pgi.468.2021.04.13.02.55.43; Tue, 13 Apr 2021 02:55:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245731AbhDMJcm (ORCPT + 99 others); Tue, 13 Apr 2021 05:32:42 -0400 Received: from mga12.intel.com ([192.55.52.136]:15985 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230251AbhDMJci (ORCPT ); Tue, 13 Apr 2021 05:32:38 -0400 IronPort-SDR: 2wxMrYFDlNFtPdJ39qASRU/HLxd0qJDAWuoIQsh/4IJxk7ZZRPVrq6sDcTy9C5mBH0gGYUYjdY ObcwCwVGju2g== X-IronPort-AV: E=McAfee;i="6200,9189,9952"; a="173868040" X-IronPort-AV: E=Sophos;i="5.82,219,1613462400"; d="scan'208";a="173868040" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2021 02:32:19 -0700 IronPort-SDR: fqePouQHEYHxvaMPgMveVf7pX/F8esCGV9XWO3d6g0cJ/4AI2Jv4TgtL0ScUmxTEKWr8xiaNxq R080VoOgKxUg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,219,1613462400"; d="scan'208";a="424178074" Received: from glass.png.intel.com ([10.158.65.59]) by orsmga008.jf.intel.com with ESMTP; 13 Apr 2021 02:32:14 -0700 From: Ong Boon Leong To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S . Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend Cc: alexandre.torgue@foss.st.com, Maxime Coquelin , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Ong Boon Leong Subject: [PATCH net-next v2 1/7] net: stmmac: rearrange RX buffer allocation and free functions Date: Tue, 13 Apr 2021 17:36:20 +0800 Message-Id: <20210413093626.3447-2-boon.leong.ong@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210413093626.3447-1-boon.leong.ong@intel.com> References: <20210413093626.3447-1-boon.leong.ong@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch restructures the per RX queue buffer allocation from page_pool to stmmac_alloc_rx_buffers(). We also rearrange dma_free_rx_skbufs() so that it can be used in init_dma_rx_desc_rings() during freeing of RX buffer in the event of page_pool allocation failure to replace the more efficient method earlier. The replacement is needed to make the RX buffer alloc and free method scalable to XDP ZC xsk_pool alloc and free later. Signed-off-by: Ong Boon Leong --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 84 +++++++++++-------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 77285646c5fc..f6d3d26ce45a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -1475,6 +1475,43 @@ static void stmmac_free_tx_buffer(struct stmmac_priv *priv, u32 queue, int i) tx_q->tx_skbuff_dma[i].map_as_page = false; } +/** + * dma_free_rx_skbufs - free RX dma buffers + * @priv: private structure + * @queue: RX queue index + */ +static void dma_free_rx_skbufs(struct stmmac_priv *priv, u32 queue) +{ + int i; + + for (i = 0; i < priv->dma_rx_size; i++) + stmmac_free_rx_buffer(priv, queue, i); +} + +static int stmmac_alloc_rx_buffers(struct stmmac_priv *priv, u32 queue, + gfp_t flags) +{ + struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; + int i; + + for (i = 0; i < priv->dma_rx_size; i++) { + struct dma_desc *p; + int ret; + + if (priv->extend_desc) + p = &((rx_q->dma_erx + i)->basic); + else + p = rx_q->dma_rx + i; + + ret = stmmac_init_rx_buffers(priv, p, i, flags, + queue); + if (ret) + return ret; + } + + return 0; +} + /** * stmmac_reinit_rx_buffers - reinit the RX descriptor buffer. * @priv: driver private structure @@ -1547,15 +1584,14 @@ static void stmmac_reinit_rx_buffers(struct stmmac_priv *priv) return; err_reinit_rx_buffers: - do { - while (--i >= 0) - stmmac_free_rx_buffer(priv, queue, i); + while (queue >= 0) { + dma_free_rx_skbufs(priv, queue); if (queue == 0) break; - i = priv->dma_rx_size; - } while (queue-- > 0); + queue--; + } } /** @@ -1572,7 +1608,6 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags) u32 rx_count = priv->plat->rx_queues_to_use; int ret = -ENOMEM; int queue; - int i; /* RX INITIALIZATION */ netif_dbg(priv, probe, priv->dev, @@ -1580,7 +1615,7 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags) for (queue = 0; queue < rx_count; queue++) { struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; - int ret; + netif_dbg(priv, probe, priv->dev, "(%s) dma_rx_phy=0x%08x\n", __func__, @@ -1596,22 +1631,12 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags) "Register MEM_TYPE_PAGE_POOL RxQ-%d\n", rx_q->queue_index); - for (i = 0; i < priv->dma_rx_size; i++) { - struct dma_desc *p; - - if (priv->extend_desc) - p = &((rx_q->dma_erx + i)->basic); - else - p = rx_q->dma_rx + i; - - ret = stmmac_init_rx_buffers(priv, p, i, flags, - queue); - if (ret) - goto err_init_rx_buffers; - } + ret = stmmac_alloc_rx_buffers(priv, queue, flags); + if (ret < 0) + goto err_init_rx_buffers; rx_q->cur_rx = 0; - rx_q->dirty_rx = (unsigned int)(i - priv->dma_rx_size); + rx_q->dirty_rx = 0; /* Setup the chained descriptor addresses */ if (priv->mode == STMMAC_CHAIN_MODE) { @@ -1630,13 +1655,11 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags) err_init_rx_buffers: while (queue >= 0) { - while (--i >= 0) - stmmac_free_rx_buffer(priv, queue, i); + dma_free_rx_skbufs(priv, queue); if (queue == 0) break; - i = priv->dma_rx_size; queue--; } @@ -1731,19 +1754,6 @@ static int init_dma_desc_rings(struct net_device *dev, gfp_t flags) return ret; } -/** - * dma_free_rx_skbufs - free RX dma buffers - * @priv: private structure - * @queue: RX queue index - */ -static void dma_free_rx_skbufs(struct stmmac_priv *priv, u32 queue) -{ - int i; - - for (i = 0; i < priv->dma_rx_size; i++) - stmmac_free_rx_buffer(priv, queue, i); -} - /** * dma_free_tx_skbufs - free TX dma buffers * @priv: private structure -- 2.25.1