Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2915380rdb; Tue, 6 Feb 2024 01:19:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfgilcgXK3XctOhmi1dCQ8Y3QlUlG2nUZ9w2sMrOo0PTn8lrLwICImf2VigW8LHW7SFnJl X-Received: by 2002:a05:6808:2226:b0:3bf:e05e:10e6 with SMTP id bd38-20020a056808222600b003bfe05e10e6mr2173731oib.6.1707211198014; Tue, 06 Feb 2024 01:19:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707211197; cv=pass; d=google.com; s=arc-20160816; b=YujjVAPNm8Eg5No5tnSj9RbfTr1QV/2msqOadvaCn9sBibqACUzUXPrdlj9981BE6M +UZvnz54poWVda4z4tMW2P0lnxXiXSQhlL7Ypy98QssO/Qzd9U3KzbeKs2Uj8XQJkLEy /69ttnS2/fsRjEE0mAqhpLdt5oxsd93DNLNPP2L2rnpYthvJmIEAdC9qmiBv2JeHH8fS mLDw9nG24t/NsyLdxI1SQbbqs0wgoq7LKEdU20YkxlbaO4/55jb5OB3e0Tcfw/YyReZt NJgYXOK509RFq91Cr+TLVhTYk+G8BSjn++XFRUgzwGDCj0Gapt5mQwYulgKxnWGjB8WO XCGQ== 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=H82yGo+pFTzvdiWiiAh27ZB+k3TfVwo6mWiq1iOTe5I=; fh=i1zV0UUNii5fyBqXbmCAbYS8ei9tH9RrkwWYe5DYMkI=; b=fb18xn6bRT4HmWvDESrEVC4xv2apgmai0AeEhwDLbq2PNBc9SFHnP/nOv/WkkLOJ8M GlTWqZlVt23BqtvfRbwRcV629WETQvuhWMSBu5ZCA2+3Hgnmo0LqDOahgI+Zl+IX4Wor 3Xo34bW6h3lapK4cKs7s5kCGd1Wu/43TAV1tUUvMzHPUEsieD2GEOGxckMPV2hRNPbBb EHUgHQiFtjXXoQ+RktGjhNi1XbNGzvAzjcKHtR1z/Qayp4QxQ9aWiuija4A3ElnpkWCw PtVlPIYNW5QhhK6O6rZW9Bo515G3ZAwcwlJeYqCNPQaVgvuaQUnZUiWQZTSTn7fPCyOs oLHw==; 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-54570-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54570-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com X-Forwarded-Encrypted: i=1; AJvYcCXUAz+6kmn0ELOTcgz8OtH3X4XX+q8sjO63jCQH+yyOcMgV9RPckM+DVb/LOSBuxPKgA96pAgY2c9CF+p5lqeymH5b15LXYFtpa8SpCYg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o5-20020a655205000000b005d8bc09efb4si1389793pgp.886.2024.02.06.01.19.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:19:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54570-linux.lists.archive=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-54570-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54570-linux.lists.archive=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 A4C9228525F for ; Tue, 6 Feb 2024 09:19:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80BC612D75F; Tue, 6 Feb 2024 09:19:32 +0000 (UTC) Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3CE8512D173; Tue, 6 Feb 2024 09:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707211171; cv=none; b=qtziCZTA3Z9+2pk8YbWNiO2JqmOy37g0s6n8SWp7LiScx1tXP5IRR+tQnFYX9uvH8lgpYcmaa0AR3/L25d6sFv9r1C+jF9GwQ3Y7xQnAzOZoOqgCABDWezBs5seShLJL4v9JN1houzTRUqJz80/cGqGAHkpydlyr5+8v6OJzvJQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707211171; c=relaxed/simple; bh=C1SY0L5Dc5UjHfx9zo6gwJom7EBMAwYl8y/Lr3H2wDs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SZpCxpbsj1rDDKTFMPU11AmDJ/7bOojRsBOE1rNCw7HnPnfLq2/irG9qw2/aC47DOKAcSt+MAiQtsfwv0wJ858HVBTSqTehQafMAOc35fgNHhFj/yz0LbQRh7NmKU05EEgRRrZ3Eb78UkHOu9pWvQpkKqrP2drelrZW37PhbHo8= 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.172 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,246,1701097200"; d="scan'208";a="196934614" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 06 Feb 2024 18:19:22 +0900 Received: from GBR-5CG2373LKG.adwin.renesas.com (unknown [10.226.93.63]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 8206B41B86C7; Tue, 6 Feb 2024 18:19:18 +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: [RFC PATCH net-next v2 1/7] net: ravb: Simplify poll & receive functions Date: Tue, 6 Feb 2024 09:19:03 +0000 Message-Id: <20240206091909.3191-2-paul.barker.ct@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240206091909.3191-1-paul.barker.ct@bp.renesas.com> References: <20240206091909.3191-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 Content-Transfer-Encoding: 8bit We don't need to pass the work budget to ravb_rx() 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() function and use the common `work_done` variable name seen in other network drivers for consistency and ease of understanding. In ravb_rx_gbeth() & ravb_rx_rcar(), 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.h | 2 +- drivers/net/ethernet/renesas/ravb_main.c | 47 +++++++++--------------- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h index 3cf869fb9a68..55a7a08aabef 100644 --- a/drivers/net/ethernet/renesas/ravb.h +++ b/drivers/net/ethernet/renesas/ravb.h @@ -1050,7 +1050,7 @@ struct ravb_hw_info { void (*rx_ring_free)(struct net_device *ndev, int q); void (*rx_ring_format)(struct net_device *ndev, int q); void *(*alloc_rx_desc)(struct net_device *ndev, int q); - bool (*receive)(struct net_device *ndev, int *quota, int q); + int (*receive)(struct net_device *ndev, int budget, int q); void (*set_rate)(struct net_device *ndev); int (*set_feature)(struct net_device *ndev, netdev_features_t features); int (*dmac_init)(struct net_device *ndev); diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index 4976ecc91cde..b18026575a2d 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,19 +945,16 @@ 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 */ -static bool ravb_rx_rcar(struct net_device *ndev, int *quota, int q) +static int ravb_rx_rcar(struct net_device *ndev, int budget, int q) { struct ravb_private *priv = netdev_priv(ndev); const struct ravb_hw_info *info = priv->info; int entry = priv->cur_rx[q] % priv->num_rx_ring[q]; - int boguscnt = (priv->dirty_rx[q] + priv->num_rx_ring[q]) - - priv->cur_rx[q]; + int limit = priv->dirty_rx[q] + priv->num_rx_ring[q] - priv->cur_rx[q]; struct net_device_stats *stats = &priv->stats[q]; struct ravb_ex_rx_desc *desc; struct sk_buff *skb; @@ -970,19 +963,16 @@ static bool ravb_rx_rcar(struct net_device *ndev, int *quota, int q) u8 desc_status; u16 pkt_len; int limit; + int i; - boguscnt = min(boguscnt, *quota); - limit = boguscnt; + limit = min(limit, budget); desc = &priv->rx_ring[q][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; @@ -1064,18 +1054,16 @@ static bool ravb_rx_rcar(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 */ -static bool ravb_rx(struct net_device *ndev, int *quota, int q) +static int ravb_rx(struct net_device *ndev, int budget, int q) { struct ravb_private *priv = netdev_priv(ndev); const struct ravb_hw_info *info = priv->info; - return info->receive(ndev, quota, q); + return info->receive(ndev, budget, q); } static void ravb_rcv_snd_disable(struct net_device *ndev) @@ -1353,12 +1341,13 @@ static int ravb_poll(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(ndev, "a, q)) + work_done = ravb_rx(ndev, budget, q); + if (work_done == budget) goto out; /* Processing TX Descriptor Ring */ @@ -1391,7 +1380,7 @@ static int ravb_poll(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 void ravb_set_duplex_gbeth(struct net_device *ndev) -- 2.39.2