From patchwork Wed Dec 21 15:25:31 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: 35414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3586967wrn; Wed, 21 Dec 2022 07:28:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXs6fvhIR92RAQCA2TPeQlIToj8XOA3ACWTC6g0Sg6f7jsYqzxS1TXLWEy6d+G7NnPR7aLHq X-Received: by 2002:a05:6a20:8b89:b0:a7:a591:4fca with SMTP id m9-20020a056a208b8900b000a7a5914fcamr2699781pzh.61.1671636518928; Wed, 21 Dec 2022 07:28:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671636518; cv=none; d=google.com; s=arc-20160816; b=F2QCseT0iy2ere4gZSbALx5FrnUyMtS72Y0iTXNl1yG3OK3aD3fDryj/6ZfZBVLlOC vFe8HWOaZb+afT7ORG/SuSIvF0toHSZx7My/QjtZ+kdSjhANexFCHcpINDgyNp7ZgW7x 6HvoCMokRUEhH2A1bD4oPJCsSMlXN7t2wwArTnbXxqJsA2/zxZGRBIfzCbnq00GsdzOc DKCNfayZDIcZNx+spaTAODn3iUPztkD00hGtNNfRgMe1n376hJWtEnnSf47aEwhUYwhb gRjMVQZ0+BScs7iDydFCG3xU6857EwOiHqaBGiK1ttYqOGY5+vYQ8UdRs8qSLlmpRbLb TfiQ== 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=zaFd0UHzSeYEPzZz7K9tbNkv+WSIQz5WkJ+qjHeZoG0=; b=hp8neAmZlpekInCHCD+XCC+grf/GmtoOww6tV8PyQWJ+Z3ED5c62yDqqnsL9CveyMm Yq0b1A1AsW8y+XvYCjJAu3Jr9hZhdn2RDavkVMipKChGAYEBclvKl+6MIkQqHwZEsk/d HzrMIsqfbpNX/tZyGRSNhuiXqkm1qiMZoALFsg7zNOLhxjJPmN4sHD1IkxhbUixOw5fI HCyoYuKt1s6g6NDVppkrkHIdwS3otgrVtxGKILpxalAlQwTK1287hYjheLJ6Ab3olD3v zTqyFhaVeob/Nch4b9tTIlSocrKw2epCslCmrxxcBlNeMvNTPS48+TSKWdj6160FzR7A 6dbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b="76sOPqH/"; 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 a8-20020a631a08000000b0046edc0aba77si16829343pga.345.2022.12.21.07.28.25; Wed, 21 Dec 2022 07:28:38 -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="76sOPqH/"; 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 S234804AbiLUP0u (ORCPT + 99 others); Wed, 21 Dec 2022 10:26:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234626AbiLUP0A (ORCPT ); Wed, 21 Dec 2022 10:26:00 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D61012AB2 for ; Wed, 21 Dec 2022 07:25:52 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id a1so7452251edf.5 for ; Wed, 21 Dec 2022 07:25:52 -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=zaFd0UHzSeYEPzZz7K9tbNkv+WSIQz5WkJ+qjHeZoG0=; b=76sOPqH/fmMgKEbazcH+Us5Ma/WrgGw2WhMh2Oh4SnBnYPN7eFgp0t3UON5GvUybhR P8qW/TgFWtg6lGMwfIN4AGRTwdt7DUNP1rW570xjnTKeP4tkREOpsVbF/QqgR/GZ6Rfm KVraxRJbkv2q54RucMzujZVWEHoaSAxvoK87TIkyA+c6d4QnWsLZrqBxTLrSaVFyArbH 6wXtYD6quzZG/Uw64VkfNJ4eU+3ynyLczd/DWzEzwTtuHsxzCZbYfauaA9oJLkRs9kMd ixsRxmwhvBMcLJYlOZviydhMCc/gwfbUpKWzNpKvyJ2JP02yEgSyBtzLVrikc6Kau+qV GvlQ== 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=zaFd0UHzSeYEPzZz7K9tbNkv+WSIQz5WkJ+qjHeZoG0=; b=k40sPHcZ1mSesmNM336H2VKeX+SI0MA1iVRa2hv41hq5baue6abMuYH8hJOPBGeJBj UMuj4NktmYrY/CoaZ5m3GB7TXbdgTMvi4IyS1Sv/wgqHtiV8C9/HoqSn3MmfCqgxL+3d hPqdlAJh/o/+2uMS93WKSqUNJtMy8h6zIqmS59Pz+FgLpSfD8v1KA3bQX2uOF54hc8Ks jH26p5suhTtYQcO1kjGu/BKkddcRUUxU0TWx3lGywmD11S/G2VsMTRYZpcmlDNX8D0Vb rhS9EFovTHGJfJoVSfU5x4pUHXO+sta+Qr6gh2iG5i9apcnhu5H6EpWYzpAHb/zR6WPD JCDg== X-Gm-Message-State: AFqh2ko+M4W0NY3q+knvM/pJXDmT1LVjdpnSc1EcGrxT1FizWIEOOXaJ LxuZna4qYbwzQmRQYvNwnng8QA== X-Received: by 2002:a05:6402:241d:b0:46b:19ab:68d8 with SMTP id t29-20020a056402241d00b0046b19ab68d8mr1957308eda.40.1671636351804; Wed, 21 Dec 2022 07:25:51 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 07:25:51 -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 12/18] can: m_can: Add tx coalescing ethtool support Date: Wed, 21 Dec 2022 16:25:31 +0100 Message-Id: <20221221152537.751564-13-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 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?1752837934100913510?= X-GMAIL-MSGID: =?utf-8?q?1752837934100913510?= Add get/set functions for ethtool coalescing. tx-frames-irq and tx-usecs-irq can only be set/unset together. tx-frames-irq needs to be less than TXE and TXB. As rx and tx share the same timer, rx-usecs-irq and tx-usecs-irq can be enabled/disabled individually but they need to have the same value if enabled. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 38 ++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 4d6fc8ade4d6..fc5a269f4930 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1918,6 +1918,8 @@ static int m_can_get_coalesce(struct net_device *dev, ec->rx_max_coalesced_frames_irq = cdev->rx_max_coalesced_frames_irq; ec->rx_coalesce_usecs_irq = cdev->rx_coalesce_usecs_irq; + ec->tx_max_coalesced_frames_irq = cdev->tx_max_coalesced_frames_irq; + ec->tx_coalesce_usecs_irq = cdev->tx_coalesce_usecs_irq; return 0; } @@ -1944,16 +1946,50 @@ static int m_can_set_coalesce(struct net_device *dev, netdev_err(dev, "rx-frames-irq and rx-usecs-irq can only be set together\n"); return -EINVAL; } + if (ec->tx_max_coalesced_frames_irq > cdev->mcfg[MRAM_TXE].num) { + netdev_err(dev, "tx-frames-irq (%u) greater than the TX event FIFO (%u)\n", + ec->tx_max_coalesced_frames_irq, + cdev->mcfg[MRAM_TXE].num); + return -EINVAL; + } + if (ec->tx_max_coalesced_frames_irq > cdev->mcfg[MRAM_TXB].num) { + netdev_err(dev, "tx-frames-irq (%u) greater than the TX FIFO (%u)\n", + ec->tx_max_coalesced_frames_irq, + cdev->mcfg[MRAM_TXB].num); + return -EINVAL; + } + if ((ec->tx_max_coalesced_frames_irq == 0) != (ec->tx_coalesce_usecs_irq == 0)) { + netdev_err(dev, "tx-frames-irq and tx-usecs-irq can only be set together\n"); + return -EINVAL; + } + if (ec->rx_coalesce_usecs_irq != 0 && ec->tx_coalesce_usecs_irq != 0 && + ec->rx_coalesce_usecs_irq != ec->tx_coalesce_usecs_irq) { + netdev_err(dev, "rx-usecs-irq (%u) needs to be equal to tx-usecs-irq (%u) if both are enabled\n", + ec->rx_coalesce_usecs_irq, + ec->tx_coalesce_usecs_irq); + return -EINVAL; + } cdev->rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; cdev->rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; + cdev->tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; + cdev->tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; + + if (cdev->rx_coalesce_usecs_irq) + cdev->irq_timer_wait = + ns_to_ktime(cdev->rx_coalesce_usecs_irq * NSEC_PER_USEC); + else + cdev->irq_timer_wait = + ns_to_ktime(cdev->tx_coalesce_usecs_irq * NSEC_PER_USEC); return 0; } static const struct ethtool_ops m_can_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS_IRQ | - ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ, + ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ | + ETHTOOL_COALESCE_TX_USECS_IRQ | + ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ, .get_ts_info = ethtool_op_get_ts_info, .get_coalesce = m_can_get_coalesce, .set_coalesce = m_can_set_coalesce,