Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5264941rdb; Wed, 13 Dec 2023 04:06:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiR/Z/9vgKZ6qqaKyJgIrM86KeNtEAxr7uREKBstlsypY9IYefwNfDQJGL/TUWRvNoIjWV X-Received: by 2002:a92:c54f:0:b0:35f:70e3:1041 with SMTP id a15-20020a92c54f000000b0035f70e31041mr1868276ilj.9.1702469168507; Wed, 13 Dec 2023 04:06:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702469168; cv=none; d=google.com; s=arc-20160816; b=CjH0S5rSYrU8Ex2C81bz1A2ThKSRNhZdbfapI5+ZF/j/aU6JkEJJqSMWkPJgd4zzJe JF9/ZvpMnuvpS5bx40wpYFwwYiEzS7BEJ30yxqlNf0q51GJgF3YxvWBm0vOLjNpqWssg YGvSWatQgy4Jx+WthuZ68e2vZAhPfqIFSzFHfkcn/AFLK9rLvB2rSinN239mxU/t2tY3 /6M9+fSUF3+pcdVJNyNEY+Xqw903VP6qoXrcXfySxCCMpj9PjlUzvRdUNr/eyhxjm0Ft /Mq/7L9Xp62/jQqcxW6k0Cc8zkwsAEtYRKB040gw5XI3Y6SJvL0S7BVEflMx0JRdcTlQ 6R8A== 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:subject:cc:to:from:date :dkim-signature; bh=szkmHjiKCu/X/Xq1D6Mn4RzvKiaRJOzU0iSUc6jNhXs=; fh=nuLCINPCvC6k5pERhNDH7JrIYYuaI/geoK8YAMZYgu0=; b=gP9ha3fnvy9TK0GTW5BBnkDJRflKqctW6gvUxbui2Pe6IFicucThDkpyJPRU/R2quX QiYwonBtY3YJgbcBGRs7TGda+XEqkbYW/9eoShAZHBFVp8zvYl0eufBSfkK0aHWA1fc2 dlN3TEBoQEG1eU0h3YOiWDwZrywXHoEFgk+9G1tkhId/FS9QFrbTg7iT/ZbY8G6zgMC7 QpVxJ/SqB6dDJqrgTYGzBKjtUEogsllaodCUdQsekJBFP6ax877UcUc2HdJ+xYKPT8cT 0gQK9F0UxKFDRx8MftHmNSyf2NJAQADpKmhvDI5JsiHW5K9dp93/WeW9UzIl735M1fI/ vddg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fWPgbClH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id ch3-20020a056a0208c300b005c6bd30ec1fsi9544388pgb.455.2023.12.13.04.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 04:06:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fWPgbClH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4CB7D808854E; Wed, 13 Dec 2023 04:05:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378811AbjLMMF0 (ORCPT + 99 others); Wed, 13 Dec 2023 07:05:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378805AbjLMMFY (ORCPT ); Wed, 13 Dec 2023 07:05:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F230010A for ; Wed, 13 Dec 2023 04:05:29 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58E06C433C8; Wed, 13 Dec 2023 12:05:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702469129; bh=x3oRn837VPa7bmsGIuv/KDiEKRYzL03PVgV7p67+CHQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fWPgbClHGcESgcgFfFV+nPKAvUcJrVYgQMbLkRIDX0gfSxTIDFSGWlL8xs4t5oKtA X/3ua3ilSEnI4z88sykJ8WIfvy5Pwe/R4a8bNdOLqDgdyNekuNnN2nAE1F74HC1mx5 sRlUS3AJu/vhcNQmOgVKZ69M4RDN3K4Klr5bSFAUNTpjJrHS8RTmgernGm57gBNAB5 11s9TcnXYquMdLUYnr74m0Fwgo8Qc6icP/3t6rCZu8MPR3FNLkw5CUG4xYlWzGc0Rh DvRqB4Mf81N9VMBM8mKb8LCucLwnOwze1rgp4Sfy3P3FyWGLivKdHWM/NKbiGGwyad 1zZU9O9iA0pWQ== Date: Wed, 13 Dec 2023 13:05:21 +0100 From: Marek =?UTF-8?B?QmVow7pu?= To: Christian Marangi Cc: Pavel Machek , Lee Jones , Andrew Lunn , "David S. Miller" , Jakub Kicinski , Daniel Golle , Li Zetao , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] leds: trigger: netdev: display only supported link speed attribute Message-ID: <20231213130521.11513e0a@dellmb> In-Reply-To: <20231209150724.25565-1-ansuelsmth@gmail.com> References: <20231209150724.25565-1-ansuelsmth@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Wed, 13 Dec 2023 04:05:50 -0800 (PST) On Sat, 9 Dec 2023 16:07:24 +0100 Christian Marangi wrote: > With the addition of more link speed mode to the netdev trigger, it was > pointed out that there may be a problem with bloating the attribute list > with modes that won't ever be supported by the trigger as the attached > device name doesn't support them. > > To clear and address this problem, change the logic where these > additional trigger modes are added. > > Since the netdev trigger REQUIRE a device name to be set, attach to the > device name change function additional logic to parse the supported link > speed modes using ethtool APIs and add only the supported link speed > modes attribute. > > This only apply to the link speed modes and every other mode is still > provided by default. > > Signed-off-by: Christian Marangi > --- > drivers/leds/trigger/ledtrig-netdev.c | 56 +++++++++++++++++++++++---- > 1 file changed, 49 insertions(+), 7 deletions(-) > > diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c > index 09e75fd9f2bc..ce84808e231c 100644 > --- a/drivers/leds/trigger/ledtrig-netdev.c > +++ b/drivers/leds/trigger/ledtrig-netdev.c > @@ -61,6 +61,8 @@ struct led_netdev_data { > bool hw_control; > }; > > +static int add_link_speed_attr(struct led_netdev_data *trigger_data); > + > static void set_baseline_state(struct led_netdev_data *trigger_data) > { > int current_brightness; > @@ -262,8 +264,10 @@ static int set_device_name(struct led_netdev_data *trigger_data, > trigger_data->carrier_link_up = false; > trigger_data->link_speed = SPEED_UNKNOWN; > trigger_data->duplex = DUPLEX_UNKNOWN; > - if (trigger_data->net_dev) > + if (trigger_data->net_dev) { > get_device_state(trigger_data); > + add_link_speed_attr(trigger_data); > + } > > trigger_data->last_activity = 0; > > @@ -396,6 +400,50 @@ DEFINE_NETDEV_TRIGGER(full_duplex, TRIGGER_NETDEV_FULL_DUPLEX); > DEFINE_NETDEV_TRIGGER(tx, TRIGGER_NETDEV_TX); > DEFINE_NETDEV_TRIGGER(rx, TRIGGER_NETDEV_RX); > > +static int add_link_speed_attr(struct led_netdev_data *trigger_data) > +{ > + struct led_classdev *led_cdev = trigger_data->led_cdev; > + struct device *dev = led_cdev->dev; > + struct ethtool_link_ksettings cmd; > + int ret; > + > + /* First remove any entry previously added */ > + device_remove_file(dev, &dev_attr_link_10); > + device_remove_file(dev, &dev_attr_link_100); > + device_remove_file(dev, &dev_attr_link_1000); > + device_remove_file(dev, &dev_attr_link_2500); > + device_remove_file(dev, &dev_attr_link_5000); > + device_remove_file(dev, &dev_attr_link_10000); Noooooo! > + ret = __ethtool_get_link_ksettings(trigger_data->net_dev, &cmd); > + if (ret) > + return ret; > + > + /* Add only supported entry */ > + if (test_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, cmd.link_modes.supported) || > + test_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, cmd.link_modes.supported)) > + device_create_file(dev, &dev_attr_link_10); > + > + if (test_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, cmd.link_modes.supported) || > + test_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, cmd.link_modes.supported)) > + device_create_file(dev, &dev_attr_link_100); > + > + if (test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, cmd.link_modes.supported) || > + test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, cmd.link_modes.supported)) > + device_create_file(dev, &dev_attr_link_1000); > + > + if (test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, cmd.link_modes.supported)) > + device_create_file(dev, &dev_attr_link_2500); > + > + if (test_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT, cmd.link_modes.supported)) > + device_create_file(dev, &dev_attr_link_5000); > + > + if (test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, cmd.link_modes.supported)) > + device_create_file(dev, &dev_attr_link_10000); > + > + return 0; > +} This should be done via the is_visible sysfs attribute_group method. Also documentation for the link_* files should be changed so that it says that the files are present only if those speeds are available. Marek