From patchwork Tue Dec 6 11:57:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 30258 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2775462wrr; Tue, 6 Dec 2022 04:00:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf4eIo39dAoogrzHIDcAEc7lEuRTZ+LRfZfxwp2i6rHlZ3E27DjODC5hdM1We5Fncm0oFfQo X-Received: by 2002:a17:906:5a0c:b0:7c0:faca:4d5e with SMTP id mx12-20020a1709065a0c00b007c0faca4d5emr5529817ejc.140.1670328053903; Tue, 06 Dec 2022 04:00:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670328053; cv=none; d=google.com; s=arc-20160816; b=ZAQ1snxmGNmRVumHpRD2+XHqiLNYd2X9L99osaGNDSv1CUOrvCDe1x384ISxBuvNlI xSX7UR32ZjGgEqrEJwdAZUlRMLXDs6GI8fZgBh1F4GjTASLIZXaHw1GMNLt23tMgJc8X T76veGOncLzoxChOPfSktloFhhuVFXKRv+5k8UUNnfKQgprueZMGx65euPohCTw2MW4d bCZn+IeHB0NvG1S/h+ij+GYgGoAbQLFwVeiK7vt1oy1Dvya//rXTWUDR0f4HzXqMoW3O XfGLt0l5FSe+8cmEEsZUqPx3+elI6gquQntgK3j+aS2keisDntf75UqnxF+SZpxvclQD aJWw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd9-20020a1709076e0900b00781e6ba94ffsi13836880ejc.126.2022.12.06.04.00.28; Tue, 06 Dec 2022 04:00:53 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751465909775859569?= X-GMAIL-MSGID: =?utf-8?q?1751465909775859569?= 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;