From patchwork Wed Jan 31 17:05:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Barker X-Patchwork-Id: 194867 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp2032092dyb; Wed, 31 Jan 2024 09:10:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/jNAY5I/HWzlnY3DIiitv9V1EgvorYN4YvVgVNZLgcwYglVQfsYaa+SbyRxYuXMjYM6In X-Received: by 2002:a17:903:41cd:b0:1d9:3e29:88ab with SMTP id u13-20020a17090341cd00b001d93e2988abmr1146443ple.65.1706721025422; Wed, 31 Jan 2024 09:10:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706721025; cv=pass; d=google.com; s=arc-20160816; b=pxcrFrk15yGN0gg7CI/xGmWjL45ShXCQrQTe+q9XY+AyXAgAKxevCWkB9qbW2gEhuT beGv+qAC2y17qKMk4rVFk0ktF2jc0YnBLozJ/rNCKAMzyMG/6CJJoGzJT8GvnrpPMR8s Y22VAOUnLtsCdejvunxmcdA8rt5y92UmX+gC7aAWcf6ql5JUgSid0j6Nnm5wspwvPnFz 0M4F7WEBGckGr+uGdQTy20rq/ikHw6eGkNsh2jZX69xvGRm8oc1Ejb1mTv6X1if0Guhy 5Z9vArqgww8atR3luB/Ww/y6A3biDoDshBpa0qoetVlCpNrgfB8p9eEVlMAda/gna/Gc zvqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=/iqI9wL6i9DIQFLXtAcQwNLXGMipzpGUwqLijhchvCo=; fh=UzOyRbaVRBu/HNDsl4Bnx+Fh2RjENVr7fXCgtmMw3YI=; b=QU2QG7G/zOTED528gjPy2ruBUYxAnyimjd6+UYscnNASsY9+bbwMC8N1oPe7SEtyxC DXsnd77K7TFDcI6T99HgZKFxg65RbMKvq20IKzI7Ub4LRe6sQpaF/b2rNTNjj2T2jmLH CADmqRRUemF5daVF3duRhZprbmJDunsdfLe/Rw/Eq/Q6wMP0KaA5gC3ljke9a2jPEv6b oXnV8pNWHD3/lK1IlhnO1t3PBqQGPItn31VHe7mhpJ9Odt6aZhsvGXz6g7fXmlqmaxVB toHdMZZtFv+YHeieRqU7qyzD1bFiTxrHDZnrAFBZTsEfhL3kWFTgTRXNgY/k/HeCzdff ZLJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=bp.renesas.com dmarc=pass fromdomain=bp.renesas.com); spf=pass (google.com: domain of linux-kernel+bounces-46865-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46865-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com X-Forwarded-Encrypted: i=1; AJvYcCV19HFY2SbqVIxrqQ8Zvxo2qlqG/QvmIrCqGiKmZ14By6u0DtI3Uv3mLSXkhG6hwOtVaMl/ZSaF7OzxCFZlzwTI92119w== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 1-20020a170902ee4100b001d8a93ed93esi9021762plo.55.2024.01.31.09.10.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 09:10:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46865-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=bp.renesas.com dmarc=pass fromdomain=bp.renesas.com); spf=pass (google.com: domain of linux-kernel+bounces-46865-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46865-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 249D728787B for ; Wed, 31 Jan 2024 17:07:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1286712FF6E; Wed, 31 Jan 2024 17:06:05 +0000 (UTC) Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45F2212C54B; Wed, 31 Jan 2024 17:06:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706720763; cv=none; b=AtufSdndp6l9i5r5gQavEKklXszUJ7oidqFxo/CtlnOMWk3y/0QWZZhDH/CJ0TKsPr/jFV3DSjp5UO4GQo7cWbt0xaZNr/cHq8Kup0nfktEPChFJj9yiW7EwA/wlskcrTcFkw9ryv6eUHAIJG2LcHwNuXaaPuiBoBobzGrA11rc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706720763; c=relaxed/simple; bh=Xm80ToVUWKO7Ssi3UnhJlGbnKtKdlIZTdxjYk0JSBdo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ktrq3fxNTzsJ2/lH4HXCc6PUNP0XH4v4bh5z2VxPmaFsbtj8rPBhKQPQ4K79wsyms6JbDgA0vCZAEipS1MWEH7gFn2DV+WnwFl+cR0fD3dyLUFBMWXK5fNpDFhIXI0JuqrtUmR/2UrThLlkgnkk/4ckKhDmEVWuay6AmwmW9Zcs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com; spf=pass smtp.mailfrom=bp.renesas.com; arc=none smtp.client-ip=210.160.252.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bp.renesas.com X-IronPort-AV: E=Sophos;i="6.05,231,1701097200"; d="scan'208";a="192404880" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 01 Feb 2024 02:05:54 +0900 Received: from GBR-5CG2373LKG.adwin.renesas.com (unknown [10.226.92.158]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 1F16940344F5; Thu, 1 Feb 2024 02:05:50 +0900 (JST) From: Paul Barker To: Sergey Shtylyov , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Paul Barker , Yoshihiro Shimoda , Wolfram Sang , netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/8] net: ravb: Simplify GbEth poll & receive functions Date: Wed, 31 Jan 2024 17:05:16 +0000 Message-Id: <20240131170523.30048-3-paul.barker.ct@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240131170523.30048-1-paul.barker.ct@bp.renesas.com> References: <20240131170523.30048-1-paul.barker.ct@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789626705721633353 X-GMAIL-MSGID: 1789626705721633353 We don't need to pass the work budget to ravb_rx_gbeth() by reference, it's cleaner to pass this by value and return the amount of work done. This allows us to simplify the ravb_poll_gbeth() function and use the common `work_done` variable name seen in other network drivers for consistency and ease of understanding. In ravb_rx_gbeth(), we can also drop the confusingly named `boguscnt` variable and use a for loop to iterate through descriptors. This is a pure refactor and should not affect behaviour. Signed-off-by: Paul Barker --- drivers/net/ethernet/renesas/ravb_main.c | 25 ++++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index c9464c1731b4..5a6a2a7a9e7a 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -822,7 +822,7 @@ static struct sk_buff *ravb_get_skb_gbeth(struct net_device *ndev, int entry, } /* Packet receive function for Gigabit Ethernet */ -static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q) +static int ravb_rx_gbeth(struct net_device *ndev, int budget, int q) { struct ravb_private *priv = netdev_priv(ndev); const struct ravb_hw_info *info = priv->info; @@ -831,28 +831,24 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q) struct sk_buff *skb; dma_addr_t dma_addr; u8 desc_status; - int boguscnt; u16 pkt_len; u8 die_dt; int entry; int limit; + int i; entry = priv->cur_rx[q] % priv->num_rx_ring[q]; - boguscnt = priv->dirty_rx[q] + priv->num_rx_ring[q] - priv->cur_rx[q]; + limit = priv->dirty_rx[q] + priv->num_rx_ring[q] - priv->cur_rx[q]; stats = &priv->stats[q]; - boguscnt = min(boguscnt, *quota); - limit = boguscnt; + limit = min(limit, budget); desc = &priv->gbeth_rx_ring[entry]; - while (desc->die_dt != DT_FEMPTY) { + for (i = 0; i < limit && desc->die_dt != DT_FEMPTY; i++) { /* Descriptor type must be checked before all other reads */ dma_rmb(); desc_status = desc->msc; pkt_len = le16_to_cpu(desc->ds_cc) & RX_DS; - if (--boguscnt < 0) - break; - /* We use 0-byte descriptors to mark the DMA mapping errors */ if (!pkt_len) continue; @@ -949,9 +945,7 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q) desc->die_dt = DT_FEMPTY; } - *quota -= limit - (++boguscnt); - - return boguscnt <= 0; + return i; } /* Packet receive function for Ethernet AVB */ @@ -1344,12 +1338,13 @@ static int ravb_poll_gbeth(struct napi_struct *napi, int budget) unsigned long flags; int q = napi - priv->napi; int mask = BIT(q); - int quota = budget; + int work_done; /* Processing RX Descriptor Ring */ /* Clear RX interrupt */ ravb_write(ndev, ~(mask | RIS0_RESERVED), RIS0); - if (ravb_rx_gbeth(ndev, "a, q)) + work_done = ravb_rx_gbeth(ndev, budget, q); + if (work_done == budget) goto out; /* Processing TX Descriptor Ring */ @@ -1382,7 +1377,7 @@ static int ravb_poll_gbeth(struct napi_struct *napi, int budget) if (priv->rx_fifo_errors != ndev->stats.rx_fifo_errors) ndev->stats.rx_fifo_errors = priv->rx_fifo_errors; out: - return budget - quota; + return work_done; } static int ravb_poll_rcar(struct napi_struct *napi, int budget)