From: Lukas Magel <lukas.magel@posteo.net>
To: linux-can@vger.kernel.org
Cc: Lukas Magel <lukas.magel@posteo.net>,
Stephane Grosjean <s.grosjean@peak-system.com>
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 [thread overview]
Message-ID: <20221022213535.8495-7-lukas.magel@posteo.net> (raw)
In-Reply-To: <20221022213535.8495-1-lukas.magel@posteo.net>
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 <lukas.magel@posteo.net>
Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
---
.../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/<iface>/peak_usb/user_devid
+Date: October 2022
+KernelVersion: 6.1
+Contact: Stephane Grosjean <s.grosjean@peak-system.com>
+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 <klaus.hitschler@gmx.de>
*/
+#include <linux/device.h>
+#include <linux/ethtool.h>
#include <linux/init.h>
-#include <linux/signal.h>
-#include <linux/slab.h>
#include <linux/module.h>
#include <linux/netdevice.h>
+#include <linux/signal.h>
+#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <linux/usb.h>
-#include <linux/ethtool.h>
#include <linux/can.h>
#include <linux/can/dev.h>
@@ -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
next prev parent reply other threads:[~2022-10-22 21:36 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-01 8:04 [PATCH v1] can: peak_usb: export PCAN device ID as sysfs device attribute Lukas Magel
2022-08-01 14:36 ` Vincent MAILHOL
2022-08-02 19:26 ` [PATCH v2] " Lukas Magel
2022-09-15 9:54 ` [RESEND PATCH " Lukas Magel
2022-09-28 20:43 ` Lukas Magel
2022-09-30 12:06 ` Marc Kleine-Budde
2022-09-30 14:20 ` Marc Kleine-Budde
2022-10-22 21:57 ` Lukas Magel
2022-10-22 21:35 ` [PATCH 0/7] can: peak_usb: Introduce configurable user dev id Lukas Magel
2022-10-22 21:35 ` [PATCH 1/7] can: peak_usb: rename device_id to a more explicit name Lukas Magel
2022-10-22 21:35 ` [PATCH 2/7] can: peak_usb: add callback to read user value of CANFD devices Lukas Magel
2022-10-22 21:35 ` [PATCH 3/7] can: peak_usb: allow flashing of the user device id Lukas Magel
2022-10-22 21:35 ` [PATCH 4/7] can: peak_usb: replace unregister_netdev() with unregister_candev() Lukas Magel
2022-10-25 13:30 ` Marc Kleine-Budde
2022-10-22 21:35 ` [PATCH 5/7] can: peak_usb: add ethtool interface to user defined flashed device number Lukas Magel
2022-10-25 14:54 ` Marc Kleine-Budde
2022-10-22 21:35 ` Lukas Magel [this message]
2022-10-25 13:30 ` [PATCH 6/7] can: peak_usb: export PCAN user device ID as sysfs device attribute Marc Kleine-Budde
2022-10-22 21:35 ` [PATCH 7/7] can: peak_usb: align user device id format in log with sysfs attribute Lukas Magel
2022-10-25 11:28 ` Marc Kleine-Budde
2022-10-25 11:44 ` Marc Kleine-Budde
2022-10-30 10:59 ` [PATCH v2 0/7] can: peak_usb: Introduce configurable user dev id Lukas Magel
2022-10-30 10:59 ` [PATCH v2 1/7] can: peak_usb: rename device_id to a more explicit name Lukas Magel
2022-10-30 10:59 ` [PATCH v2 2/7] can: peak_usb: add callback to read user value of CANFD devices Lukas Magel
2022-10-30 10:59 ` [PATCH v2 3/7] can: peak_usb: allow flashing of the user device id Lukas Magel
2022-10-30 10:59 ` [PATCH v2 4/7] can: peak_usb: replace unregister_netdev() with unregister_candev() Lukas Magel
2022-10-30 10:59 ` [PATCH v2 5/7] can: peak_usb: add ethtool interface to user defined flashed device number Lukas Magel
2022-10-30 10:59 ` [PATCH v2 6/7] can: peak_usb: export PCAN user device ID as sysfs device attribute Lukas Magel
2022-10-30 10:59 ` [PATCH v2 7/7] can: peak_usb: align user device id format in log with sysfs attribute Lukas Magel
2022-12-13 8:03 ` [PATCH v3 0/7] can: peak_usb: Introduce configurable CAN channel ID Lukas Magel
2022-12-13 8:03 ` [PATCH v3 1/8] can: peak_usb: rename device_id to " Lukas Magel
2022-12-13 8:03 ` [PATCH v3 2/8] can: peak_usb: add callback to read CAN channel ID of PEAK CAN-FD devices Lukas Magel
2022-12-13 8:03 ` [PATCH v3 3/8] can: peak_usb: allow flashing of the CAN channel ID Lukas Magel
2022-12-13 8:03 ` [PATCH v3 4/8] can: peak_usb: replace unregister_netdev() with unregister_candev() Lukas Magel
2022-12-13 8:03 ` [PATCH v3 5/8] can: peak_usb: add ethtool interface to user-configurable CAN channel identifier Lukas Magel
2022-12-13 8:03 ` [PATCH v3 6/8] can: peak_usb: export PCAN CAN channel ID as sysfs device attribute Lukas Magel
2022-12-13 8:03 ` [PATCH v3 7/8] can: peak_usb: align CAN channel ID format in log with sysfs attribute Lukas Magel
2022-12-13 8:03 ` [PATCH v3 8/8] can: peak_usb: Reorder include directives alphabetically Lukas Magel
2023-01-16 20:09 ` [RESEND PATCH v3 0/8] can: peak_usb: Introduce configurable CAN channel ID Lukas Magel
2023-01-16 20:09 ` [PATCH v3 1/8] can: peak_usb: rename device_id to " Lukas Magel
2023-01-16 20:09 ` [PATCH v3 2/8] can: peak_usb: add callback to read CAN channel ID of PEAK CAN-FD devices Lukas Magel
2023-01-16 20:09 ` [PATCH v3 3/8] can: peak_usb: allow flashing of the CAN channel ID Lukas Magel
2023-01-16 20:09 ` [PATCH v3 4/8] can: peak_usb: replace unregister_netdev() with unregister_candev() Lukas Magel
2023-01-16 20:09 ` [PATCH v3 5/8] can: peak_usb: add ethtool interface to user-configurable CAN channel identifier Lukas Magel
2023-01-16 20:09 ` [PATCH v3 6/8] can: peak_usb: export PCAN CAN channel ID as sysfs device attribute Lukas Magel
2023-01-16 20:09 ` [PATCH v3 7/8] can: peak_usb: align CAN channel ID format in log with sysfs attribute Lukas Magel
2023-01-16 20:09 ` [PATCH v3 8/8] can: peak_usb: Reorder include directives alphabetically Lukas Magel
2023-02-02 16:45 ` [RESEND PATCH v3 0/8] can: peak_usb: Introduce configurable CAN channel ID Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221022213535.8495-7-lukas.magel@posteo.net \
--to=lukas.magel@posteo.net \
--cc=linux-can@vger.kernel.org \
--cc=s.grosjean@peak-system.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).