From patchwork Wed Jan 25 19:50:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 48281 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp456336wrn; Wed, 25 Jan 2023 11:52:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXvxb513dmUNuZHlMgfo21wEAWFmvJvph1NX1NNI+2R9OQSBln5WnT346G8ku+DdYFK00eJA X-Received: by 2002:a05:6a20:d394:b0:b8:9922:dd2a with SMTP id iq20-20020a056a20d39400b000b89922dd2amr36353745pzb.57.1674676360101; Wed, 25 Jan 2023 11:52:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674676360; cv=none; d=google.com; s=arc-20160816; b=t0AgICkcO8vXe2/qS4y1W+5F4a0244ZVImoxqaQf2iiQiT93xCFirifBgv+ADi0e29 oNK850enQjVfNOed38N/EbkkFW1V1mBFOJ2kXfzdt2848UYf59iaOgVapofgsPkTn0W/ lsibP53oDeATQsXsfKhZJI5wlHr12iSxXCRv/4JSE7I+dLGhHq4K3sV+GrnYBhCBy0LM +hnipyl8re5HL5rSEqHMbDl1mRc9YBflcjQA/xBzVJv7SiSSeKyBXeZoOQTivHT6RH4K 44cNfDdwwo4Bapeis6Us47LOYfHNVWYg21OEAOkIq7MCA2beedj52Q3ljReHwcKvyNkA VnoA== 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=QfommV9SggPT6ODN0C3xf43Tcngh6JSfHsK3JHWDVGY=; b=ZqqgWcj9NT6AtEEeWldE8Os0eG7Ok5dea9WXkhKYT9mZKRsIKGDEIrDPsO3Ul0XmWs rIjkYUFN7sO+ivrkCPcS5VAw9IEhfYuxtSLp7WTsC/+k5J2Of1zMvdvc3/Zli5UlA00J LpAVaQGNful6oqLX83Tq67Y8lTbn82VSIvaqqV70Lv2ocl6e5CvHi9idIG33VbhOiJ5l ZcyelZmULOOS6Go8yxXxyqHvKSC/iAdL+s/tyk7wTGGNRd7XJIDTisJeaSTMTJQwmPxi fUnh150oyRfm3D2WEgIYgm9ErKfYp7QtfamHWwBE8UFYUOOsXlPFA+dmGTlRPdOTxtcV tylg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=EAVvGTpO; 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 j63-20020a638b42000000b004a227152324si6281005pge.839.2023.01.25.11.52.28; Wed, 25 Jan 2023 11:52:40 -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=EAVvGTpO; 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 S235844AbjAYTwD (ORCPT + 99 others); Wed, 25 Jan 2023 14:52:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235707AbjAYTvj (ORCPT ); Wed, 25 Jan 2023 14:51:39 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B1EE59574 for ; Wed, 25 Jan 2023 11:51:15 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id vw16so50582904ejc.12 for ; Wed, 25 Jan 2023 11:51:15 -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=QfommV9SggPT6ODN0C3xf43Tcngh6JSfHsK3JHWDVGY=; b=EAVvGTpOTDJ6cVDVcMwO07k2FmJrvWy9qroV4RCQs5igp0Ik0sNwLhS8JY69vx4VwT 1DVXvZcphS914vwdO2duYYrcf9NbRNHO9sieMavL4Ezetq648t2vET56QK6YHnABqkD+ 7fA53W2QfBWIvQmTHDf/3EqO4mQR57dKS1rEDiiJKmGwC351bVu6u2iUwTZXjd4ZWbGI 8qDfHOh3tlXkrRCkFLseE4+KDTi0b20ftS3nZt/tF4F790dzrHfq/KK1F2UQobfbZSvj qPEZVoCxVEkwp8ycQQ0xCpRfrUnZ/EpHW2Ak+YWXbSCQyXiNzeGWEZmW8Ux5z8luTRps lnVg== 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=QfommV9SggPT6ODN0C3xf43Tcngh6JSfHsK3JHWDVGY=; b=lse0zKX/2aQ4kGBiUZ0yAVEgaVD99uAZ9aey2BiBrvnIz96wWW0yD2vwHf4eo2elb8 hINwq1Vcl0nNCeEX5cIqWINqxytnzNPVCJOkHw5ZHRvhUZGHI5wEx1Hm3AwrJ/PeakdV eO5BrIk5/zPli2hoMAxJTkXZYRtf+1enoVrm0ywpYaGmmVlgRu55OZ4GxBxOVdCY4taA eW01r+A6+MLTEklssQj0vAY+C1sKU7rlcFud/Hl95o7pURhxg5lDwr2r45TbFET+e1kT I68quKqGDMuZGigwPaz3TaZJWUgTApEj0WHwTJmHrz3XUTR2RzB1h9j8d71QKIa+IB0O mQpA== X-Gm-Message-State: AFqh2krmDb+oQvUoYTzQwnnWBznUnPaNbWWcu/3Wj8EejK4/orMcHEfN ZVWW7y9AM/wYbkUOYd5JI+y2Gw== X-Received: by 2002:a17:906:9c8b:b0:84d:ed5:a406 with SMTP id fj11-20020a1709069c8b00b0084d0ed5a406mr47950330ejc.14.1674676275056; Wed, 25 Jan 2023 11:51:15 -0800 (PST) Received: from blmsp.fritz.box ([2001:4091:a247:815f:ef74:e427:628a:752c]) by smtp.gmail.com with ESMTPSA id s15-20020a170906454f00b00872c0bccab2sm2778830ejq.35.2023.01.25.11.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 11:51:14 -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 v2 12/18] can: m_can: Add tx coalescing ethtool support Date: Wed, 25 Jan 2023 20:50:53 +0100 Message-Id: <20230125195059.630377-13-msp@baylibre.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230125195059.630377-1-msp@baylibre.com> References: <20230125195059.630377-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?1756025438944896707?= X-GMAIL-MSGID: =?utf-8?q?1756025438944896707?= 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 35c38c230a00..9d2345f52ddc 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1944,6 +1944,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; } @@ -1970,16 +1972,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,