From patchwork Wed Nov 16 20:53:02 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: 21271 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp57727wrr; Wed, 16 Nov 2022 12:58:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf50p43OCAAmSezDHl66klGRzW2Iqd7tld8Gbt23KzPBCwsTvhWZsMY+xCpGT8gyDUUVFvdj X-Received: by 2002:a17:902:7616:b0:188:b943:2e1c with SMTP id k22-20020a170902761600b00188b9432e1cmr10633734pll.43.1668632299372; Wed, 16 Nov 2022 12:58:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668632299; cv=none; d=google.com; s=arc-20160816; b=BrwnWk4YdgupGdOTn7MDmcBFXhRqoLseJpT2WW5gZD+ZJqS2maQeOJIvVm3mp7AVDb aMJIHLpG1PNumdr6ivLD8yexhlVrMiIqNpgDRcE5Z5ljMhqMs6ViShwNsey1Qq1a7CON RDF5Q5DtE8oilQhzPmjkRxT8ZZdIqNoHXmabhVJ1O2mAc6nQNo6crc49faJ5vIby1cCe iaM5rr+tVeVK3VufikVPOrnTOc6OP+TnzoGsFQ64vQPLgNw9Ffd5CYTdDQLI9jMq84q6 AqEcU39PhQEYZZ5y+1qC2CRTJ17ID7aXI5gAmCLyJBgYjTOxBOFIY+uA0k96xQ3Spiea FioA== 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=76EqNlpDreQF4PZmggfgrCfKC4hAP4lphiWDRZe7nMM=; b=fCf5PP54YEIDo8RBsQASJwvA1KRIdxr8/Rsp4wkxRzsFFL7gpGzluOa6v+nty8eWp/ upKO+nqeb+PBZSVztJ4BJeWKCJAmY5kskMKGtw6mKz0J3hVDCzNrxDXD8ewI4MDx5ppN miry/M8fyIHzQA1pQ1AXyXXhUZzx5GcurxpN+KZFIEOXULwm+EYmgBGAbqbEbrZiacgi 0HyAvHTjOiSMEJTNZLwbM2AFjMrD/v8CqfkSf0MxU7zj6x1xaC+L26EwH1YEgFSafIuz h1cStXjFd89i5ni9Wf2m64+S83TuuUV9tl2pLTDNO5mgiNCp/U7IyQnusvYxm/fKuHNB 2cwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b="uqThAUy/"; 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 z3-20020a170903018300b0017f641cac01si18869714plg.27.2022.11.16.12.58.06; Wed, 16 Nov 2022 12:58:19 -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="uqThAUy/"; 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 S239031AbiKPUyu (ORCPT + 99 others); Wed, 16 Nov 2022 15:54:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238294AbiKPUx4 (ORCPT ); Wed, 16 Nov 2022 15:53:56 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D53C26418 for ; Wed, 16 Nov 2022 12:53:32 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id ft34so47068991ejc.12 for ; Wed, 16 Nov 2022 12:53:32 -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=76EqNlpDreQF4PZmggfgrCfKC4hAP4lphiWDRZe7nMM=; b=uqThAUy/RKwtT1RRbAu8P5FOVTNwBorxorshelO+Gn57d4TcNitGks2jHG8VjQaJT5 TEavYIJSpNPGFpNDMMxKMRiDVcrerBSpI03qY1cHLpu4Pp4zoLW6+xH9aWJwIFdnkCAX 0ETvxF2Apny/2uqVTtLgkjN2UIHwXAqRhbGiOYQJD4Eb3rAUT61h0518k/ei4UTZiryA i2YbNLFvgObJVuHDg/QVg4DSJn1XczUQoYspgCNo6+FTr1x0glc82I6g7nZo6e/KVk/A 1qoiG9heuHqcuR4buQqWP6K0bkU2ZNU7Tn+yhL1XqlnQWFTTdgdp0FlqnVi6oiegV22Y tuJw== 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=76EqNlpDreQF4PZmggfgrCfKC4hAP4lphiWDRZe7nMM=; b=xFw7cVZ3OqW29N2pAWLMATtjcG+rjne+MxjX53leGhn2xXOQrIfJhJpRPVIVy24ISa x3U4Z4M67kn2GtBQowFza5XwXwqlE3qD0fXC+LF/HVnY+KhdcC4El5a5vsqTYfHDhTn1 foW4ADjdtO+wakwIn9woFnWwle8dc8euAAVfDLLH5CKxeJS//EEXLlntewZNg9HsDTWF HCJYIb9WDuK/S30XL+/w3wojc/jHJnSC0ZfIw6kLN8T97b2b7D4Uh/qTLQDYeB7elyC3 9Ex1ArYVltDI39x9FrRxzGKCq7yDktl1/CDjbT7thLv9dv6VExaFV043O7ddUEtsSAhn gUuw== X-Gm-Message-State: ANoB5pl/9QLVk5ZfUw6ykDVP6PtjR0xcBhlbPzJOVQhFz/zHKCwoLAXS yW4U6NMulyimLsIYWQLlGFGbXQ== X-Received: by 2002:a17:906:2696:b0:7ae:4ed2:84f4 with SMTP id t22-20020a170906269600b007ae4ed284f4mr18752930ejc.429.1668632011225; Wed, 16 Nov 2022 12:53:31 -0800 (PST) Received: from blmsp.fritz.box ([2001:4090:a244:804b:353b:565:addf:3aa7]) by smtp.gmail.com with ESMTPSA id kv17-20020a17090778d100b007aece68483csm6782828ejc.193.2022.11.16.12.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 12:53:30 -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 09/15] can: m_can: Count read getindex in the driver Date: Wed, 16 Nov 2022 21:53:02 +0100 Message-Id: <20221116205308.2996556-10-msp@baylibre.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116205308.2996556-1-msp@baylibre.com> References: <20221116205308.2996556-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=unavailable 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?1749687782007392344?= X-GMAIL-MSGID: =?utf-8?q?1749687782007392344?= 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 27095a7254dd..02fd7fe4e9f8 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -477,19 +477,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; @@ -554,6 +551,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); @@ -562,14 +562,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;