From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A767FC433FE for ; Sat, 22 Oct 2022 21:36:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229506AbiJVVgd (ORCPT ); Sat, 22 Oct 2022 17:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbiJVVgb (ORCPT ); Sat, 22 Oct 2022 17:36:31 -0400 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 808ABF88DE for ; Sat, 22 Oct 2022 14:36:30 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 34A81240027 for ; Sat, 22 Oct 2022 23:36:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1666474589; bh=/fMWu1oPJfWnhMGu1g2qHWt8lkkBVzPtIQhBhkQctwg=; h=From:To:Cc:Subject:Date:From; b=oq9+cjwKJFZ8N9FWUgS7t/j0jOFR8fdYCgowxLON2+L4mbIS7zU1hgYq9tpg7sIoO XUyvBU0ASjtC78HcuObZ3LN9DmdR/8KVV3UGSefu/lyVpM+/xHzyZK4A7Wsnhrm8NY vNKn4cI1KVqVDolDnRu1QKtMm3IkukiXMXiUCoasjvpeDQ94NXzO0CvnQDw6uhjN/d 91yPBm3j/EiXHcdvS6sFPGmNhp4/Xob+J98NEKgwAdUEhq4AOZnr44sRf2qQEwTeUw bAhiJpaoicfhw2rBuUGnLP2wzYAAT1O0RrNrIYJu/k6kkuVxM7+uF2IfmMBarS+X55 nXkVxINDSICQQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4MvvmD3xfkz9rxH; Sat, 22 Oct 2022 23:36:28 +0200 (CEST) From: Lukas Magel To: linux-can@vger.kernel.org Cc: Lukas Magel , Stephane Grosjean Subject: [PATCH 6/7] can: peak_usb: export PCAN user device ID as sysfs device attribute Date: Sat, 22 Oct 2022 21:35:34 +0000 Message-Id: <20221022213535.8495-7-lukas.magel@posteo.net> In-Reply-To: <20221022213535.8495-1-lukas.magel@posteo.net> References: <20220801080446.36374-1-lukas.magel@posteo.net> <20221022213535.8495-1-lukas.magel@posteo.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-can@vger.kernel.org This patch exports the user device ID as a sysfs attribute. This allows users to easily read the ID and to write udev rules that can match against the ID. Signed-off-by: Lukas Magel Signed-off-by: Stephane Grosjean --- .../ABI/testing/sysfs-class-net-peak_usb | 15 ++++++++++ drivers/net/can/usb/peak_usb/pcan_usb_core.c | 30 +++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-net-peak_usb diff --git a/Documentation/ABI/testing/sysfs-class-net-peak_usb b/Documentation/ABI/testing/sysfs-class-net-peak_usb new file mode 100644 index 000000000000..f7f23f9bdfde --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-net-peak_usb @@ -0,0 +1,15 @@ + +What: /sys/class/net//peak_usb/user_devid +Date: October 2022 +KernelVersion: 6.1 +Contact: Stephane Grosjean +Description: + PEAK PCAN-USB devices support a user-configurable device + identifier. This attribute provides read-only access to the + currently configured value of the device identifier. Depending + on the device type, the identifier has a length of 8 or 32 bit. + The value read from this attribute is always an 8 digit 32 bit + hexadecimal value in big endian format. If the device only + supports an 8 bit identifier, the upper 24 bit of the value are + set to zero. + diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c index 438788732c2c..fbefd4f05e08 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c @@ -8,13 +8,15 @@ * * Many thanks to Klaus Hitschler */ +#include +#include #include -#include -#include #include #include +#include +#include +#include #include -#include #include #include @@ -53,6 +55,25 @@ static const struct usb_device_id peak_usb_table[] = { MODULE_DEVICE_TABLE(usb, peak_usb_table); +static ssize_t user_devid_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct net_device *netdev = to_net_dev(dev); + struct peak_usb_device *peak_dev = netdev_priv(netdev); + + return sysfs_emit(buf, "%08X\n", peak_dev->user_devid); +} +static DEVICE_ATTR_RO(user_devid); + +static const struct attribute *peak_usb_sysfs_attrs[] = { + &dev_attr_user_devid.attr, + NULL, +}; + +static const struct attribute_group peak_usb_sysfs_group = { + .name = "peak_usb", + .attrs = (struct attribute **)peak_usb_sysfs_attrs, +}; + /* * dump memory */ @@ -961,6 +982,9 @@ static int peak_usb_create_dev(const struct peak_usb_adapter *peak_usb_adapter, /* add ethtool support */ netdev->ethtool_ops = peak_usb_adapter->ethtool_ops; + /* register peak_usb sysfs files */ + netdev->sysfs_groups[0] = &peak_usb_sysfs_group; + init_usb_anchor(&dev->rx_submitted); init_usb_anchor(&dev->tx_submitted); -- 2.37.2