From patchwork Fri Sep 29 14:12:56 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: 148960 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp458982vqb; Thu, 5 Oct 2023 10:36:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvDx8ys9PM8PXQL2pS/B59aT7jtTb2CWS1THatbP61ysljkAhMbV0hJxljrdGUQBPA5/UP X-Received: by 2002:a05:6358:419d:b0:135:4003:7857 with SMTP id w29-20020a056358419d00b0013540037857mr4042924rwc.31.1696527378782; Thu, 05 Oct 2023 10:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696527378; cv=none; d=google.com; s=arc-20160816; b=buQ1vua1ylpB+EEtkAxilWJaJa2grpTJB6JLDoqnHAn+2PPxwq7Dvz2bBCXDo5Xa5N gYGkJPIfY1ehKE/HRb4RKMRHZU6kkpbsukh90++n9lONGW6rvvcdoXJiT2t/ZVkS9XpK wU966YeSJY8GJKfxfikYVD7VOQap4XrpXueofnnbtgkQb3O2IT4ax6qYIHvjPLYmZc/C 1bcGNH8PHCxN7S3TJwszLMeI9EZH8omJ+9vqdqTw120zCBleS+YeonseewbF2LAJAkSL mU9+GrTjMMPTSITO6+uUYfFsc1eVDvzMHVn93GsA1wi9jAbxS78LrPzWLcrTjlcQri5Z dnOg== 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=tCQIoaJbLKII1l0AGqTW1Bk8v3XX8EQRXCDvUWkrfVU=; fh=EtuWLR14IhIbZM+E+fYn4isj1Y+iLrncbbgmHIVUFEQ=; b=kt11EXfVcy8hYksAqdmZngzuZvEFzNMKieI/JodpYWSpjjkK7RGb6/lIWE/g5OWn3W jm5WbaK8kzt7joCQMvKQUNBsnDKb72dI0WxB2al1mzPT9W7lRaiZ0eRtNVes4vxzQUKz etCepyVyG/8w+tMvAIqL8Eqt1b7v0C25KKC3Mqb6GS0bRh0IC/QJd+FfFX16hylNqext X52ZbQoaL0TSfuRa4JRFAj+JMkAabJm3A6EmoK6uZxqtrANFzkPdItgacVdq4vZAYWdU YfUjZJfL60szi/Q0Z4lSFt59Wx0EYzARtrEOGB1tLlF+k8oFfCEP0Djvv++voNeZBiCY ldMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="kNEfY/mp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id j1-20020a17090ae60100b00279016a2a2asi2007242pjy.135.2023.10.05.10.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 10:36:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="kNEfY/mp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 128CC83393B6; Fri, 29 Sep 2023 07:14:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233192AbjI2ONb (ORCPT + 20 others); Fri, 29 Sep 2023 10:13:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233233AbjI2ONW (ORCPT ); Fri, 29 Sep 2023 10:13:22 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03DF61B5 for ; Fri, 29 Sep 2023 07:13:19 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-323ef9a8b59so4554421f8f.3 for ; Fri, 29 Sep 2023 07:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695996797; x=1696601597; darn=vger.kernel.org; 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=tCQIoaJbLKII1l0AGqTW1Bk8v3XX8EQRXCDvUWkrfVU=; b=kNEfY/mpmmx/3obmfSoRPyK3d64FG/6uJcQXiLahkoFX8I+rCp/5/PBvmNart2NZId Cl/vWIJp+vgATxo94YNdCPeXZzZVTMa9K3Sjy3N72SmgjkfE/MUt2kODFucYWTtnt0Km jmzkiUcjQlFVU01C1QyPdJoZAxSMX/sP5aYa5wn18v2pMNfxfQP58hSBD1jqEhqu/OU5 ZtxvVzClhhUpZ+76T7vUny3w3ihXdTCvrRd4TPP1xJog2msJpdcV4vbWxkVsHCykbl9J s3TreMi3yUJc6LROg4zGChL/miZ4dqxrG+NaCyqcjWEULkVfY37KeGNLkbIq/J95Xagk 1NSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695996797; x=1696601597; 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=tCQIoaJbLKII1l0AGqTW1Bk8v3XX8EQRXCDvUWkrfVU=; b=p4qsVHjpCU31ThSGNMh/KeVKhNkVMggRATOqS0edPaejVKV7SG3cTahKe5NSAQKQkv d4QbwqeU3HZNS79Z+A3XxJ8KWNy912bBZpKIs7y9PCNyZ0nWy8J1sI4hpXOJ6NzlnVLp OGT9jIgrdXqztNLA9wmGgTHfQtXvn5a+HT1zk4lEDJmjOir8jiKGa2FjBzP3nyzOK749 eUcAaRY5sBuV8KemefPI4pApLZh5HINgP3Wn/WYLdsgjroNQ38GngpnJAzzhAXbMvLIm 9t+XBQw6Q3ELhk9iqk116QfK98+3GY5MK8KJDbIaR3UfpizXSAmax0whuDERiTR+Lglg NMTQ== X-Gm-Message-State: AOJu0YxdkNfFjZFeMXHKhei5Bs9+EbmoXfb9xUnOu71A5WP+KcmJG8Y1 Mqd9ukx8R6n3LzBGTfLueqXJCg== X-Received: by 2002:adf:de0a:0:b0:31f:fb5d:96da with SMTP id b10-20020adfde0a000000b0031ffb5d96damr3728023wrm.64.1695996797063; Fri, 29 Sep 2023 07:13:17 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a246:8222:dbda:9cd9:39cc:f174]) by smtp.gmail.com with ESMTPSA id t25-20020a7bc3d9000000b00405391f485fsm1513068wmj.41.2023.09.29.07.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 07:13:16 -0700 (PDT) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger Cc: Vincent MAILHOL , Simon Horman , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Judith Mendez , Markus Schneider-Pargmann Subject: [PATCH v6 06/14] can: m_can: Add rx coalescing ethtool support Date: Fri, 29 Sep 2023 16:12:56 +0200 Message-Id: <20230929141304.3934380-7-msp@baylibre.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230929141304.3934380-1-msp@baylibre.com> References: <20230929141304.3934380-1-msp@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 29 Sep 2023 07:14:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778555869669064550 X-GMAIL-MSGID: 1778937892401403518 Add the possibility to set coalescing parameters with ethtool. rx-frames-irq and rx-usecs-irq can only be set and unset together as the implemented mechanism would not work otherwise. rx-frames-irq can't be greater than the RX FIFO size. Also all values can only be changed if the chip is not active. Polling is excluded from irq coalescing support. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 55 ++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index b20edd64bb7e..546193ab6e0d 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1976,7 +1976,57 @@ static const struct net_device_ops m_can_netdev_ops = { .ndo_change_mtu = can_change_mtu, }; +static int m_can_get_coalesce(struct net_device *dev, + struct ethtool_coalesce *ec, + struct kernel_ethtool_coalesce *kec, + struct netlink_ext_ack *ext_ack) +{ + struct m_can_classdev *cdev = netdev_priv(dev); + + ec->rx_max_coalesced_frames_irq = cdev->rx_max_coalesced_frames_irq; + ec->rx_coalesce_usecs_irq = cdev->rx_coalesce_usecs_irq; + + return 0; +} + +static int m_can_set_coalesce(struct net_device *dev, + struct ethtool_coalesce *ec, + struct kernel_ethtool_coalesce *kec, + struct netlink_ext_ack *ext_ack) +{ + struct m_can_classdev *cdev = netdev_priv(dev); + + if (cdev->can.state != CAN_STATE_STOPPED) { + netdev_err(dev, "Device is in use, please shut it down first\n"); + return -EBUSY; + } + + if (ec->rx_max_coalesced_frames_irq > cdev->mcfg[MRAM_RXF0].num) { + netdev_err(dev, "rx-frames-irq %u greater than the RX FIFO %u\n", + ec->rx_max_coalesced_frames_irq, + cdev->mcfg[MRAM_RXF0].num); + return -EINVAL; + } + if ((ec->rx_max_coalesced_frames_irq == 0) != (ec->rx_coalesce_usecs_irq == 0)) { + netdev_err(dev, "rx-frames-irq and rx-usecs-irq can only be set together\n"); + return -EINVAL; + } + + cdev->rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; + cdev->rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; + + 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, + .get_ts_info = ethtool_op_get_ts_info, + .get_coalesce = m_can_get_coalesce, + .set_coalesce = m_can_set_coalesce, +}; + +static const struct ethtool_ops m_can_ethtool_ops_polling = { .get_ts_info = ethtool_op_get_ts_info, }; @@ -1984,7 +2034,10 @@ static int register_m_can_dev(struct net_device *dev) { dev->flags |= IFF_ECHO; /* we support local echo */ dev->netdev_ops = &m_can_netdev_ops; - dev->ethtool_ops = &m_can_ethtool_ops; + if (dev->irq) + dev->ethtool_ops = &m_can_ethtool_ops; + else + dev->ethtool_ops = &m_can_ethtool_ops_polling; return register_candev(dev); }