Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7289460rwb; Tue, 6 Dec 2022 03:59:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Wsi3dhQmCYSrreNpXgGB+fjDr63skmjsQodNDm9EHVoK86ANGPpxzJfeJsb18LCpxtNNQ X-Received: by 2002:a17:903:452:b0:189:65c5:4508 with SMTP id iw18-20020a170903045200b0018965c54508mr56246574plb.66.1670327988858; Tue, 06 Dec 2022 03:59:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670327988; cv=none; d=google.com; s=arc-20160816; b=ULtI1w3dGeb44+6T/JXBckzrzItfRos4Ca7Y2cTK6emRziSCNwD35U/y+lCmOYpHtY EUS8N565GIAFGaHTK7jdr4kdmpTl+J1jpcBDjPGMpl8gy0mc8OaUog1Nojk3c+/NJZLe 4pHChir2LQBw6FKcn+lLidHYneV2WrVwABsh47iEa9U3guylaUTlDuGVEt74o5Zl5Ahv jzL65N1Zi/Lr7PsBuZDXW1t1rcekO56JgdDpv3Bp+8+ALEg/oV4L7HGsBvpWw/FqlCED CIiFcIr7eswjsXX6bLy9YhEt0YhDR7Zskqk63o1Ca1sXhyWR4ObJO7XILRS6jhZwFwwd 83hg== 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=qNZbR/OCEKJKCF9Pyi6+mM/mCQOvMeAEcjhJky1x5bk=; b=rZgdOrzmjlu8H6puPVPSmcQTl8sAWMViCDOxZ1gYXog5sH+MIJQKI189nzCv74/JX7 Je/Nlfi6xjB08z5eUFWFIIxm0/AtSOX8YY8qSAO610qhVnb3zegDNnvdeJR7Da6WVoAT +XDaG+Ym7gTo2cYFTiQOvNBsIJh1hv4tGMIbPgXjf23SWcjTu12hOR6r9H+t91YMcE0q ZR2+VicuotqyKv5hpATj1iopjnXepTq2OczQVDlyMUdQH+y4MHhS1v9N6X0R3y4Bk7z5 bCVADXQXdreIbnMgOMidTe6vcjpgLoPjXQ1MoKkNJ1QluubFgOol47C5/ynM4Yhvit1I 1T8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=NWXWNYnv; 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 v191-20020a6389c8000000b00478e7f82dd3si590268pgd.543.2022.12.06.03.59.37; Tue, 06 Dec 2022 03:59:48 -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=NWXWNYnv; 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 S235204AbiLFL5u (ORCPT + 80 others); Tue, 6 Dec 2022 06:57:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbiLFL5k (ORCPT ); Tue, 6 Dec 2022 06:57:40 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F295642F for ; Tue, 6 Dec 2022 03:57:38 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id c17so11375401edj.13 for ; Tue, 06 Dec 2022 03:57:38 -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=qNZbR/OCEKJKCF9Pyi6+mM/mCQOvMeAEcjhJky1x5bk=; b=NWXWNYnvN1jBg8fh4s6alBCUPRmNaziz7tTuEZ+3lKk9a1vsxZGan2QgpRPFxAXAP7 YsQ4Du++m8bcwKtpsi9WofamV42a9mEu1S/Fnqb6LfL6+40eaW4+0S7fTIkyY2HmDUiK lzWzBTLkGOwR9Sj1OClt/3jtRXnN4xSNEVMwxNfzsLQ6eQg38h/H1KPOUXF23luITTol vtY3VwKBxefY0dbmYHZvWLUFM37oFrl4EWpXOBjH7NRt2d8CfnEuR5gn0tlVq3YmhCyf WLiJ40Idltmo/IBDV+1sqF/ZJnty5NCiWqICdl+orbB0sLqxFoL70R47xDySUoYzufGE RBVQ== 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=qNZbR/OCEKJKCF9Pyi6+mM/mCQOvMeAEcjhJky1x5bk=; b=Fg2s/b16tmhbbI0/vhzV6WHV/HGusea1Fg7BhH3uRGF/wiBLqhR+zeUtcrx8AlGk0B Zjjnsv/bN8KKYPysL3TKrDu5tSSZWGXQurpbXPJqk1D4zb82brAjMU/saVaPnDShj5Ru YrW/kP84BmvufXPfxp94FOgtAa05NCwFKGb8XWPc246Q5C8A5VF53U2ps9ZfFQfOu0zE +/+/zn1BWK0STI3guI6LCUSRa1BmTX5rSmpW6oNVnvXB09QW66tcLmIltRKUI0/wYbdp C/ojw61Q+oXJAjckMBYkw+HKWbcHbaFHOGkE602aWhMxNAXPgO+kJMzM9PfHjY6x6LNR GSKg== X-Gm-Message-State: ANoB5pmCTeqeqwI/mJdkLqgSVX6kuE9mCKDURqeAXytykN1P6ocqTWEg Qr7JebdP1/n2/T7ejbMKGab9lA== X-Received: by 2002:a05:6402:3785:b0:461:e598:e0bb with SMTP id et5-20020a056402378500b00461e598e0bbmr14889196edb.21.1670327856563; Tue, 06 Dec 2022 03:57:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 03:57:36 -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 01/11] can: m_can: Eliminate double read of TXFQS in tx_handler Date: Tue, 6 Dec 2022 12:57:18 +0100 Message-Id: <20221206115728.1056014-2-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=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 The TXFQS register is read first to check if the fifo is full and then immediately again to get the putidx. This is unnecessary and adds significant overhead if read requests are done over a slow bus, for example SPI with tcan4x5x. Add a variable to store the value of the register. Split the m_can_tx_fifo_full function into two to avoid the hidden m_can_read call if not needed. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index e5575d2755e4..0cc0abde9b1d 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -368,9 +368,14 @@ m_can_txe_fifo_read(struct m_can_classdev *cdev, u32 fgi, u32 offset, u32 *val) return cdev->ops->read_fifo(cdev, addr_offset, val, 1); } +static inline bool _m_can_tx_fifo_full(u32 txfqs) +{ + return !!(txfqs & TXFQS_TFQF); +} + static inline bool m_can_tx_fifo_full(struct m_can_classdev *cdev) { - return !!(m_can_read(cdev, M_CAN_TXFQS) & TXFQS_TFQF); + return _m_can_tx_fifo_full(m_can_read(cdev, M_CAN_TXFQS)); } static void m_can_config_endisable(struct m_can_classdev *cdev, bool enable) @@ -1585,6 +1590,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) struct sk_buff *skb = cdev->tx_skb; struct id_and_dlc fifo_header; u32 cccr, fdflags; + u32 txfqs; int err; int putidx; @@ -1641,8 +1647,10 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) } else { /* Transmit routine for version >= v3.1.x */ + txfqs = m_can_read(cdev, M_CAN_TXFQS); + /* Check if FIFO full */ - if (m_can_tx_fifo_full(cdev)) { + if (_m_can_tx_fifo_full(txfqs)) { /* This shouldn't happen */ netif_stop_queue(dev); netdev_warn(dev, @@ -1658,8 +1666,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) } /* get put index for frame */ - putidx = FIELD_GET(TXFQS_TFQPI_MASK, - m_can_read(cdev, M_CAN_TXFQS)); + putidx = FIELD_GET(TXFQS_TFQPI_MASK, txfqs); /* Construct DLC Field, with CAN-FD configuration. * Use the put index of the fifo as the message marker, -- 2.38.1