Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp5839961rwj; Wed, 21 Dec 2022 07:39:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXveNQht72vBZ6a4SMR56ELZEKdSKx1qsDUrWYdD3q2MIal9iHPyPi1CxYLg4rjYgfCkFY2z X-Received: by 2002:a50:ef11:0:b0:46a:d5ee:7664 with SMTP id m17-20020a50ef11000000b0046ad5ee7664mr2026107eds.6.1671637199704; Wed, 21 Dec 2022 07:39:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671637199; cv=none; d=google.com; s=arc-20160816; b=ehwPS5goJf5wjkRQaRQS7V6qlPxEJujLez2TpRHZQY+a6OrZ4LC/JEFfWnoBneexi6 7U7pg/TfRYcRm37L4UDd5XHfTJu8+mPPclmL4BBd8nZeYfZ/TfBwMRoWB7oRLSBahouM m4LQUFEOXIFi3joEj+tMkuzFn8AC5YZ0dRfRNK8fDphtWMuO+2uS0Dq0QAhjQe0y0UDT UujBoqllUGSczYrI9e1wvbzfNGVuaqpH6a2idxe9iAB//6hAzM7v0+vX9naj6P5v3Mnz sVpQh521N8/pkBsWLO4nn3sGtg8W/KvhfQSFhXrvTDHBTsbH86+W62HkM5vNqVviUCqM 4Qkg== 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=vIiue0Eegphd4TqHDxcJLHie9gRriJxojR2XQBDT6w0=; b=Md/iDfZteo3Qy2sr0d+YkXGPC/PqHXSxPVkKaEjgMv2r1N5mdqQdp3yBRMGMW5qFfi w+h5yVi+QHC/eqQd/TMEahNaKF+dMqrwFXKXBXlZ9ov6xZXxh+wTkzrz5FLbrp/kP+QF V3JXeEKQ4bsEcD89E+LeoeJK96wDaS7TMyisEiMUrMTwv6pIF/YrKamBWmZDQKlY89h5 07yqNS7lKFaCOtgOIYqYn8ittRFIFeFCBVRaGthq8Rd7nhw2tX+DLsDRgW8O+Z0Gpz2b LFuNXv0LcLgQ0UXBaQfI4dKM4kZr2+kMM8ziXQxTxpo+Jl4n18Eqt2iKVSU1KYf46Gk5 GzTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=P6uN06IH; 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 h8-20020a056402094800b00461d726439asi2370272edz.538.2022.12.21.07.39.43; Wed, 21 Dec 2022 07:39:59 -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=P6uN06IH; 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 S234777AbiLUP0f (ORCPT + 68 others); Wed, 21 Dec 2022 10:26:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234661AbiLUPZw (ORCPT ); Wed, 21 Dec 2022 10:25:52 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CD52DFB6 for ; Wed, 21 Dec 2022 07:25:50 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id b69so22461530edf.6 for ; Wed, 21 Dec 2022 07:25:50 -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=vIiue0Eegphd4TqHDxcJLHie9gRriJxojR2XQBDT6w0=; b=P6uN06IHWaXNID+/R1r/6/a5P1HuWXlqwa5Yg7oJS5DlP068fKhkZ3SwKOIqp3F/GG pI3dFE8HWJICes1ljhmq3lEHlMNI+RRI/B/nfwhj7pydJ2/gI1ruJvtkFOVGsDR8IR8G Qu9SopBKJJeUHeAyQMuB+fiUkR+60O39luRPwP/arM8BnMGlETYM1HpqwAz8XSUeEEbh mXTRQzYqk3BeZSgujRIqbYrBkNMaewLo9KO2/c1HFnRhNTfaOlfbhtJAyAQSlPC+VkAe qzaFnRiICuWeXycPMtZKcme4Lf6MXDxNggPuHp8bzUnNk0WdtbUB7CRBr/zqT3G0HgzX oVBw== 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=vIiue0Eegphd4TqHDxcJLHie9gRriJxojR2XQBDT6w0=; b=6ZaLBdQc8krnkkb3rmBOC2i85qCkYBl1Ckexau/FRQXQTsp/XDXLvpGlZ1Gp5kNQNC 157yiJ/M+tk6ijoInTXrrfLT6WcxtKc13tAczUzz8nP+LUQhQPUog9DuL8yq7Ik7+jN2 q6nkEA3BkgmUXu6HixQWFdH8yh5AMDlxZmAB/TBKXiQCnXmbiwBJ64mwOvdVPhJM0Bzv bUhM2f4MLpy6WXM5Jk5rsCl2jgyK8fNoaUDoADwYVk3JOKaqn4Jcp3agAxwYn5in54dn TfNPgxHyXt9PjGTogjXnmU2Oe2zrkRQWvLJ+CuAt36IF/DyLIRyonNkErku8OfygkR6K 0hSA== X-Gm-Message-State: AFqh2koP1GpYeT6U/eVlJ2/xWIv3By21wBUIZUXLow1v+wNtzw2pkFpZ HUYxpTf34xuL4VRIllaxl//DFQ== X-Received: by 2002:a05:6402:1055:b0:467:c3cb:49aa with SMTP id e21-20020a056402105500b00467c3cb49aamr1846132edu.4.1671636349931; Wed, 21 Dec 2022 07:25:49 -0800 (PST) Received: from blmsp.fritz.box ([2001:4091:a245:805c:8713:84e4:2a9e:cbe8]) by smtp.gmail.com with ESMTPSA id n19-20020aa7c793000000b0045cf4f72b04sm7105428eds.94.2022.12.21.07.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 07:25:49 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger Cc: Vincent MAILHOL , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann Subject: [PATCH 10/18] can: m_can: Implement transmit coalescing Date: Wed, 21 Dec 2022 16:25:29 +0100 Message-Id: <20221221152537.751564-11-msp@baylibre.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221221152537.751564-1-msp@baylibre.com> References: <20221221152537.751564-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 Extend the coalescing implementation for transmits. In normal mode the chip raises an interrupt for every finished transmit. This implementation switches to coalescing mode as soon as an interrupt handled a transmit. For coalescing the watermark level interrupt is used to interrupt exactly after x frames were sent. It switches back into normal mode once there was an interrupt with no finished transmit and the timer being inactive. The timer is shared with receive coalescing. The time for receive and transmit coalescing timers have to be the same for that to work. The benefit is to have only a single running timer. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 33 ++++++++++++++++++++------------- drivers/net/can/m_can/m_can.h | 3 +++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 2e664313101b..a84a17386c02 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -254,6 +254,7 @@ enum m_can_reg { #define TXESC_TBDS_64B 0x7 /* Tx Event FIFO Configuration (TXEFC) */ +#define TXEFC_EFWM_MASK GENMASK(29, 24) #define TXEFC_EFS_MASK GENMASK(21, 16) /* Tx Event FIFO Status (TXEFS) */ @@ -1070,7 +1071,7 @@ static void m_can_interrupt_enable(struct m_can_classdev *cdev, u32 interrupts) static void m_can_coalescing_disable(struct m_can_classdev *cdev) { - u32 new_interrupts = cdev->active_interrupts | IR_RF0N; + u32 new_interrupts = cdev->active_interrupts | IR_RF0N | IR_TEFN; hrtimer_cancel(&cdev->irq_timer); m_can_interrupt_enable(cdev, new_interrupts); @@ -1079,21 +1080,26 @@ static void m_can_coalescing_disable(struct m_can_classdev *cdev) static void m_can_coalescing_update(struct m_can_classdev *cdev, u32 ir) { u32 new_interrupts = cdev->active_interrupts; - bool enable_timer = false; + bool enable_rx_timer = false; + bool enable_tx_timer = false; if (cdev->rx_coalesce_usecs_irq > 0 && (ir & (IR_RF0N | IR_RF0W))) { - enable_timer = true; + enable_rx_timer = true; new_interrupts &= ~IR_RF0N; - } else if (!hrtimer_active(&cdev->irq_timer)) { - new_interrupts |= IR_RF0N; } + if (cdev->tx_coalesce_usecs_irq > 0 && (ir & (IR_TEFN | IR_TEFW))) { + enable_tx_timer = true; + new_interrupts &= ~IR_TEFN; + } + if (!enable_rx_timer && !hrtimer_active(&cdev->irq_timer)) + new_interrupts |= IR_RF0N; + if (!enable_tx_timer && !hrtimer_active(&cdev->irq_timer)) + new_interrupts |= IR_TEFN; m_can_interrupt_enable(cdev, new_interrupts); - if (enable_timer) { - hrtimer_start(&cdev->irq_timer, - ns_to_ktime(cdev->rx_coalesce_usecs_irq * NSEC_PER_USEC), + if (enable_rx_timer | enable_tx_timer) + hrtimer_start(&cdev->irq_timer, cdev->irq_timer_wait, HRTIMER_MODE_REL); - } } static irqreturn_t m_can_isr(int irq, void *dev_id) @@ -1148,7 +1154,7 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) netif_wake_queue(dev); } } else { - if (ir & IR_TEFN) { + if (ir & (IR_TEFN | IR_TEFW)) { /* New TX FIFO Element arrived */ if (m_can_echo_tx_event(dev) != 0) goto out_fail; @@ -1309,9 +1315,8 @@ static void m_can_chip_config(struct net_device *dev) u32 interrupts = IR_ALL_INT; /* Disable unused interrupts */ - interrupts &= ~(IR_ARA | IR_ELO | IR_DRX | IR_TEFF | IR_TEFW | IR_TFE | - IR_TCF | IR_HPM | IR_RF1F | IR_RF1W | IR_RF1N | - IR_RF0F); + interrupts &= ~(IR_ARA | IR_ELO | IR_DRX | IR_TEFF | IR_TFE | IR_TCF | + IR_HPM | IR_RF1F | IR_RF1W | IR_RF1N | IR_RF0F); m_can_config_endisable(cdev, true); @@ -1348,6 +1353,8 @@ static void m_can_chip_config(struct net_device *dev) } else { /* Full TX Event FIFO is used */ m_can_write(cdev, M_CAN_TXEFC, + FIELD_PREP(TXEFC_EFWM_MASK, + cdev->tx_max_coalesced_frames_irq) | FIELD_PREP(TXEFC_EFS_MASK, cdev->mcfg[MRAM_TXE].num) | cdev->mcfg[MRAM_TXE].off); diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index 4943e1e9aff0..62631a613076 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -85,6 +85,7 @@ struct m_can_classdev { struct phy *transceiver; struct hrtimer irq_timer; + ktime_t irq_timer_wait; struct m_can_ops *ops; @@ -98,6 +99,8 @@ struct m_can_classdev { u32 active_interrupts; u32 rx_max_coalesced_frames_irq; u32 rx_coalesce_usecs_irq; + u32 tx_max_coalesced_frames_irq; + u32 tx_coalesce_usecs_irq; struct mram_cfg mcfg[MRAM_CFG_NUM]; }; -- 2.38.1