From patchwork Wed Mar 15 11:05:39 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: 70126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2261981wrd; Wed, 15 Mar 2023 04:08:28 -0700 (PDT) X-Google-Smtp-Source: AK7set95icEyQZRg3EcoQDz/sesue3uXQQdG4lcug2yap04CVJSl+0ehCgBKVnHNpu4aTkldc7uD X-Received: by 2002:a17:90a:31c:b0:233:f394:d83 with SMTP id 28-20020a17090a031c00b00233f3940d83mr38870510pje.48.1678878508392; Wed, 15 Mar 2023 04:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678878508; cv=none; d=google.com; s=arc-20160816; b=rIiDKDC0IanTrElz7OPZylWq9KcFw8+52zaZl5rCu3s9ejOGUwjB8AfqmoBq8c5NxT 9F2Y+B/YB1RRAhDI0UDTOY5NahYlWBpwE+vmtxxaOPQKBGO/JOmjTPb3Ur74CQs9Au3W S16hnHULZBZb3PDuozs3VvPztYJQj+kqoBZ3WBPCQZX6IUbK/Shq0GnHRM1xCMDA0Yh+ zZvCCXOBYT+pgQ1Zb4Xx1khRdlVyuj/xo990wFpqvgKmqsfc+Uucud/5JdCBZjgx3P9U A5SLsxIeksyArLVs8gXDKsg2kwRJuhyW9qPcSrOQVhsyUVFzH5X8GItEgbM+QtK43qHM fr5A== 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=JK3QCAzV2uxsgFdaubQ9QvC1c5aZ/o2EHMkQeIZH7RA=; b=ZMFSDTCtmlvytyi39ohA1DQRe/iS+4CWxKVVrrtXXrc6wSmk3QT9Vx4yIgqgMilejl ziEEUU1G+zWNCv7g5FUSTwN7yyit5M39ZJBHdWYFPHmovmDSVzThTKQip4FYyLO1oxpD 4IEdq6ufsm36ktsHc9DgLqeQbjv6fEd+WO3vmmWBkmdRn8DbGtX6ZRgJoiO8jg7hxu32 pfdm02noCjbxRhTe1VNcLbOQuDDUpId7LI1KX/GD9LLlGQDl4El0uVab1WTgw9CWcO1R i2DQXj74QpoAM5XNqJ3/7XgbCntxm5LpU4a4ofj3Jv726bVEfJ506qCD/D2xB9ah/mk5 zc7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=lYYgm1cN; 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 z128-20020a636586000000b00502e7406695si4757315pgb.316.2023.03.15.04.08.12; Wed, 15 Mar 2023 04:08:28 -0700 (PDT) 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=lYYgm1cN; 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 S231976AbjCOLHP (ORCPT + 99 others); Wed, 15 Mar 2023 07:07:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231495AbjCOLGn (ORCPT ); Wed, 15 Mar 2023 07:06:43 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5187E85A48 for ; Wed, 15 Mar 2023 04:06:34 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id ay8so7017762wmb.1 for ; Wed, 15 Mar 2023 04:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; t=1678878392; 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=JK3QCAzV2uxsgFdaubQ9QvC1c5aZ/o2EHMkQeIZH7RA=; b=lYYgm1cNWYtBWM9/MP6pOb3usNz4beGBqUXvyznePJP2TBOG5eGAexBzwQFP5OG4Wi TLTAhPPo4TeaNcrcRyhxqkbiqcPUkki0sHYsevJL0a3o1bUzDUD+5kn/hhYjIEYOHbUQ cs1SMmShHlET6PpHWudYdrNXJ4/TerAH8UTd1oPW2GFsaCfZCyfwrF0SYztqD+8Tb0u6 N40pDsV8/jdNalHUmPZPcrlQ2W80zBYzkXri2kC9mxUrrgmjjbLB2/zYlN3i1bxFLPf8 l0m9c0FBmZYfC3VE9Bm7l9BVMsZAh9kMj7rjGHi2J1jMianx5izwJhgSgaqpmVR/YW92 LBPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678878392; 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=JK3QCAzV2uxsgFdaubQ9QvC1c5aZ/o2EHMkQeIZH7RA=; b=B0R4l5mJ02FBOrsOTeUN9qnTr5LhytUOZG2Rq77J6Ktz28/5h4wgzhEFQyo3s48xko IUplV6pIfOnpY/vhm/NFnxsHmTh9gFqxlul4fuqTXbaUgGBBItj5CyMivi2R9IN867dM LV70vNhdBNXrVI2f8nVh1M9I/JpPvtWSUvp58Ah3qiHwTGVzFyRO4YgqLWxezX7yEqSf Z3EZtlFNqrE0Zbmf+vEJarYzQQghjdlM5hreo0MrG6VQMr4d9J3gCG1buxcz8PZYyQuK t9Gmqb7eck6VpUKy5jBRyuE1hT9rtyJR1ROZuC+zs5ejBdi1hfYe04oDypsmqAoUsIty Habw== X-Gm-Message-State: AO0yUKWlIJvM9MPwTNowPoqltVzviS0N8vCLxqd071HCjg6wawoYfQrm FAXTsPcpZNbGxyiJtk1OPWhbOg== X-Received: by 2002:a05:600c:4751:b0:3ea:f0d6:5d36 with SMTP id w17-20020a05600c475100b003eaf0d65d36mr17547733wmo.29.1678878392795; Wed, 15 Mar 2023 04:06:32 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4090:a247:8056:be7d:83e:a6a5:4659]) by smtp.gmail.com with ESMTPSA id l4-20020a7bc444000000b003eafc47eb09sm1460563wmi.43.2023.03.15.04.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 04:06:32 -0700 (PDT) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann Subject: [PATCH v3 09/16] can: m_can: Add rx coalescing ethtool support Date: Wed, 15 Mar 2023 12:05:39 +0100 Message-Id: <20230315110546.2518305-10-msp@baylibre.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230315110546.2518305-1-msp@baylibre.com> References: <20230315110546.2518305-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?1760431710488410178?= X-GMAIL-MSGID: =?utf-8?q?1760431710488410178?= 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. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 94c962ac6992..7f8decfae81e 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1936,8 +1936,54 @@ 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 int register_m_can_dev(struct net_device *dev)