Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7341842rwb; Tue, 6 Dec 2022 04:40:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf7T39IvjkPyNOIVMuqRpaSMSjis444mC5DVJj5aBjgCOaSoxL310E6HaRECkh8NuQyvbTiD X-Received: by 2002:a17:906:78b:b0:7c0:e813:e07e with SMTP id l11-20020a170906078b00b007c0e813e07emr8859958ejc.156.1670330452430; Tue, 06 Dec 2022 04:40:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670330452; cv=none; d=google.com; s=arc-20160816; b=dhAXYvpPXMxJqOSjRiwiRvOjTYUzaqLpoKJ+Kf7cvV28rrcdojHKhrepUlMkrC4qRg CnZEDVg7eoWa4zRXOtEg0kX45DmLhlWh0yyb2XDYtrzzeVNaJ0AQrAoAd9zArhJx5dER 5FA95S01dNKqzSkkFUbUzH/CfeqI795b7wDQxPaGuiYAt9FIwTKlpSdkU+lEw9cz+7r0 Y4VYmyA5buu5oNxNhlbxlCJlt71AFO8vmWdQVak3CXsoY1uhjA+bvvXegecmHrrWr6dZ /VCIs3RQhfiOlo2kT0UCelMN+5ByEdk73sYT7cEYPoOOZxu+tzblimiFalYoZ/DgcxpJ rMpA== 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=LBqwKcCdNszQ4mwUTsccWY77ZqBMhKPDh+uspgjRsrc=; b=KnUDv2l2gsJMPAzFsxQvXDV4pVtaYqtO9eEBs7JheqFvo+fshohloVTDOba9my+pkX 3zzOmHQ1ig6KI2DvS/eBzddDa7u/MB5J26IOFVnidjMCHoqktD4XPRlqBpdpUjoeq+8c ck66ucIWYPijxyzjCfL9ZxunpK5UNv7B4jEhSYVOPwO5DuDrkBiBKYSX5KaGEr5xo3Kq 9aA18S5F8WxlgwPnezXUJKM8nn0j5DuCvhj/Fg6B+9Ovl4Zdsj0QRcUGD0s00WWoJrzB PHmavcvzDZwQq/+YpYuEZbhl03biu0xMsVDwBWg1oACgsiNkq3Q39ynUyfz0RBhfn4lS q31g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=DPqqNGeJ; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt15-20020a1709072d8f00b007bad1338dd3si15672848ejc.851.2022.12.06.04.40.29; Tue, 06 Dec 2022 04:40:52 -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=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=DPqqNGeJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234976AbiLFL6I (ORCPT + 79 others); Tue, 6 Dec 2022 06:58:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235144AbiLFL5n (ORCPT ); Tue, 6 Dec 2022 06:57:43 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F3C2E3D for ; Tue, 6 Dec 2022 03:57:40 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id qk9so5617701ejc.3 for ; Tue, 06 Dec 2022 03:57:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LBqwKcCdNszQ4mwUTsccWY77ZqBMhKPDh+uspgjRsrc=; b=DPqqNGeJB+CLzaOy8DcBdvQ4jz5mShTjsBsQBiKtpJutZ9pt4futlXIv7BoIoLxKe1 ikRhLz4m7cQ7T/l7BPYX0zBg6Cp/hp+OmXJU5HpZpP3uN7z10J7635BmX25nND0MK2Tt ETAsPvi5kdq5jXRVH1OfPi+3HJHP6RfuZU3hqfrKBWZyC4zngg96khNNLz2iKp+fWlPu /DW905aQp3qfroPlS0pWoDMY+fczDnQXUTEJmd18IHZ1e5ByrTF/YqizF7kWto6RKrSo U5Nxdv5WjyxypVZbti2mw4Eofk4Y/wAOxrrqLim6nMpKVEWYndu5AuE4fI/Xrfx7MCrq yhbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LBqwKcCdNszQ4mwUTsccWY77ZqBMhKPDh+uspgjRsrc=; b=0aRK3C6TrD1Euv+7SH2QB4ZHUGSikPYt+w/Tvz+pmhBu8fYAAydk/dk5CXj/tx3Et1 DQvQeeqX6BnNZ6ClsR7vlwJhLLH2HqHJm0LgI/EHpDjG/xaSq2F2niIlu939VejI0E1d coa71xodkhu3mFsXRKsVCTiuTmkql32AHZzig35KN6hrtbUsM0gw/Zygs12UxJhsBMqY b6U+lsaGkdsHj0g780Ytx7+ZKxZGmmyPeVuAMSQe4DDNdtP5GCQPU0RVtyDlN32UHX5F 0JejnrjHULYqvarWd21N32FDIwxFVclQL5AX9Qk8YwfLtV4bPO4I28G0/Xno/h8vm4BC kOnA== X-Gm-Message-State: ANoB5pkLKyQ3TjT65HxO0CRvNcHPkAURetyJkxZTLch0D+yelp47AoI+ Smv9+I36W4IgT/mMD8Xpj/0SDQ== X-Received: by 2002:a17:906:ad86:b0:7c0:7e90:ec98 with SMTP id la6-20020a170906ad8600b007c07e90ec98mr3823617ejb.537.1670327860065; Tue, 06 Dec 2022 03:57:40 -0800 (PST) Received: from blmsp.fritz.box ([2001:4091:a245:805c:8713:84e4:2a9e:cbe8]) by smtp.gmail.com with ESMTPSA id ky20-20020a170907779400b007c0ac4e6b6esm6472076ejc.143.2022.12.06.03.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 03:57:39 -0800 (PST) From: Markus Schneider-Pargmann To: Chandrasekar Ramakrishnan , Marc Kleine-Budde , Wolfgang Grandegger Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann Subject: [PATCH v2 05/11] can: m_can: Count read getindex in the driver Date: Tue, 6 Dec 2022 12:57:22 +0100 Message-Id: <20221206115728.1056014-6-msp@baylibre.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221206115728.1056014-1-msp@baylibre.com> References: <20221206115728.1056014-1-msp@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 The getindex gets increased by one every time. We can calculate the correct getindex in the driver and avoid the additional reads of rxfs. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index a133f15fb90a..a0ae543d418c 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -476,19 +476,16 @@ static void m_can_receive_skb(struct m_can_classdev *cdev, } } -static int m_can_read_fifo(struct net_device *dev, u32 rxfs) +static int m_can_read_fifo(struct net_device *dev, u32 fgi) { struct net_device_stats *stats = &dev->stats; struct m_can_classdev *cdev = netdev_priv(dev); struct canfd_frame *cf; struct sk_buff *skb; struct id_and_dlc fifo_header; - u32 fgi; u32 timestamp = 0; int err; - /* calculate the fifo get index for where to read data */ - fgi = FIELD_GET(RXFS_FGI_MASK, rxfs); err = m_can_fifo_read(cdev, fgi, M_CAN_FIFO_ID, &fifo_header, 2); if (err) goto out_fail; @@ -553,6 +550,9 @@ static int m_can_do_rx_poll(struct net_device *dev, int quota) struct m_can_classdev *cdev = netdev_priv(dev); u32 pkts = 0; u32 rxfs; + u32 rx_count; + u32 fgi; + int i; int err; rxfs = m_can_read(cdev, M_CAN_RXF0S); @@ -561,14 +561,17 @@ static int m_can_do_rx_poll(struct net_device *dev, int quota) return 0; } - while ((rxfs & RXFS_FFL_MASK) && (quota > 0)) { - err = m_can_read_fifo(dev, rxfs); + rx_count = FIELD_GET(RXFS_FFL_MASK, rxfs); + fgi = FIELD_GET(RXFS_FGI_MASK, rxfs); + + for (i = 0; i < rx_count && quota > 0; ++i) { + err = m_can_read_fifo(dev, fgi); if (err) return err; quota--; pkts++; - rxfs = m_can_read(cdev, M_CAN_RXF0S); + fgi = (++fgi >= cdev->mcfg[MRAM_RXF0].num ? 0 : fgi); } return pkts; -- 2.38.1