From patchwork Wed Jan 25 19:50:52 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: 48283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp456407wrn; Wed, 25 Jan 2023 11:52:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXs7co6AslrGJLZ1DwKN6KnJe2JFIuVp3VDTG9epj97G79BbASz+IrCW3my6p4yE/mKmE3Yh X-Received: by 2002:a05:6a20:6f06:b0:ad:5cde:8f05 with SMTP id gt6-20020a056a206f0600b000ad5cde8f05mr30957174pzb.37.1674676367657; Wed, 25 Jan 2023 11:52:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674676367; cv=none; d=google.com; s=arc-20160816; b=qtHINMsZnYIgf+LDxUhwJp7UgwrOBL+FAiRLeOSpP/RHgMnwSbKAortYmGq/AfSrv2 +LooYKJ9dScgubDQZ/RLy0Sd1f78pVMMKVSr4nMcwfO6KfFJJYnZ7IyibwxwvrwL3DMM 9VjSu+bxuPpFQtIjU+b0kiloLSuMT8T8OGZAls3cjV/mABtxgcZBliEmUdD+mefQzeqp BRqReOjGeI/aBbXV65h+OyIpxu/OdzTfP2K9peJM8gHY7X7wjwM/jaj/p5t3S1Vk84/s qn/Odg36mLfWvYA2ry+qqpaTs6wxz7IEVVK1igeM8v+DV18E/2pSzIEkFY/xSfjXOlfx kz9g== 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=MPZRbcn+ayOOx/787tD+d5yfOpNzt8F4/+0TUH3wcFQ=; b=ImXzXAOqNFElzmUhq2KfN1rVkrCcmYCzIoz1oeIWNUNijt/4fJgZ267bJAltPXPezh qz9b+nmDEJv62XspCigx9nT3t7g0Mltg9X+aoSHmNkU/H3H4jGrPUYib9YmFK2CBRqOj HqHeD48vaDFDuw75dxzh2/mR8uxyQxpp3ulfzb/KawsyMvhhM9o8CbzkwcVAdlO2m9qK 9TVmMLX4ACbl0x43Yp+IxTGENo+W5tkswrT7qfD2H/zB8vcev/KkJGW+jQq277b5MeNP LkZrDPY6kveYaGGHukGqQ8y06M6s5NzHlAKSi0QRcm22tiHp8NBoxzcUAHxBiKLw9meD bqXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=xWuzZuT6; 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 o18-20020a656a52000000b004ce20c32635si6888415pgu.844.2023.01.25.11.52.36; Wed, 25 Jan 2023 11:52:47 -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=xWuzZuT6; 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 S236082AbjAYTwH (ORCPT + 99 others); Wed, 25 Jan 2023 14:52:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235913AbjAYTvj (ORCPT ); Wed, 25 Jan 2023 14:51:39 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 885365A801 for ; Wed, 25 Jan 2023 11:51:15 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id tz11so50685462ejc.0 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=MPZRbcn+ayOOx/787tD+d5yfOpNzt8F4/+0TUH3wcFQ=; b=xWuzZuT6B1uM5aAUffyZgQxOrYA9VusXutUVZ5QO9TF9e/Kpe3RBVU6cJlxUC55o6D SBX2+JVmpDG5pOrITnrCYKJna+28SxE1qCr4VOtrrqrfEjPTHk0SCZ/vGYgU0gDW4m3q 6LImlYw7L/6+NC0oFFQSLfDDTnRzKaIQ+IVYI0VbdC5xnaMmV9pllfI2Zy9+Je/2Gjs9 jIj2HJ+fa2SDWgnnDwnEJu3OJ8SO+UGfVMj7iXLIlG5IvL3nVEqUBiyWA+A7fDA4cija cb1cloQSJVBlQAnzyF0QiTEjOsmzwkgZYiqakQmAtEsNjMw3y0IOibU7u5SjKMMWim72 NzWg== 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=MPZRbcn+ayOOx/787tD+d5yfOpNzt8F4/+0TUH3wcFQ=; b=7EDd4wHTbb+tTbSsKuDPc1JPmUVQb1EFpfFLvxjpSwZgzh0mypPZIUEkE0S63qrr+R sspuqQ+fYoeC9MRT+6EGKOkWbt+RDS1YewLMfOnUMZB+1w9YZTU0QyLgrVYOTem71Fdv L46chdd3Qd7ve7kcCXnNe3bCIlm2EBkzhXNtKgdIentXf3HFjofNtrbUNJoCCHvx5frj UvJv7qxu0zYdWn1Zs5oBzBhSn5dOfwd69sv58C1DlefedrCiV1PUiiZe+A3MpmaHXb3E XIqX7BoZwaLKAM6i4hOKf1FDTbMUj+8BQ3FuhEbc7pao8CrR6o09h5E1dR9UqEdZ4IVU vYNA== X-Gm-Message-State: AFqh2kpKC0X+jkKyF+vqdZO8yJoy5b9ol3LubAZyeUdSfMvhXNUym/a2 CFiRxMRrnbY2H08horAgvSyLOw== X-Received: by 2002:a17:906:514:b0:7c1:1ada:5e1e with SMTP id j20-20020a170906051400b007c11ada5e1emr34079325eja.26.1674676274128; Wed, 25 Jan 2023 11:51:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 11:51:13 -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 11/18] can: m_can: Add rx coalescing ethtool support Date: Wed, 25 Jan 2023 20:50:52 +0100 Message-Id: <20230125195059.630377-12-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?1756025446764482422?= X-GMAIL-MSGID: =?utf-8?q?1756025446764482422?= 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 --- 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 31a5e551ebd9..35c38c230a00 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1935,8 +1935,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)