All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
	kernel@pengutronix.de, Lukas Magel <lukas.magel@posteo.net>,
	Stephane Grosjean <s.grosjean@peak-system.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH net-next 28/47] can: peak_usb: export PCAN CAN channel ID as sysfs device attribute
Date: Mon,  6 Feb 2023 14:16:01 +0100	[thread overview]
Message-ID: <20230206131620.2758724-29-mkl@pengutronix.de> (raw)
In-Reply-To: <20230206131620.2758724-1-mkl@pengutronix.de>

From: Lukas Magel <lukas.magel@posteo.net>

This patch exports the CAN channel ID as a sysfs attribute. The CAN
channel ID is a user-configurable u8/u32 identifier that can be set
individually for each CAN interface of a PEAK USB device.

Exporting the channel ID as a sysfs attribute allows users to easily read
the ID and to write udev rules that can match against the ID. This is
especially useful for PEAK USB devices that do not export a serial
number at SUB level.

Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Lukas Magel <lukas.magel@posteo.net>
Link: https://lore.kernel.org/all/20230116200932.157769-7-lukas.magel@posteo.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 .../ABI/testing/sysfs-class-net-peak_usb      | 19 ++++++++++++++
 drivers/net/can/usb/peak_usb/pcan_usb_core.c  | 25 +++++++++++++++++++
 2 files changed, 44 insertions(+)
 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..9e3d0bf4d4b2
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-net-peak_usb
@@ -0,0 +1,19 @@
+
+What:		/sys/class/net/<iface>/peak_usb/can_channel_id
+Date:		November 2022
+KernelVersion:	6.2
+Contact:	Stephane Grosjean <s.grosjean@peak-system.com>
+Description:
+		PEAK PCAN-USB devices support user-configurable CAN channel
+		identifiers. Contrary to a USB serial number, these identifiers
+		are writable and can be set per CAN interface. This means that
+		if a USB device exports multiple CAN interfaces, each of them
+		can be assigned a unique channel ID.
+		This attribute provides read-only access to the currently
+		configured value of the channel 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 3bfd27742ae4..676923bd4213 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -15,6 +15,8 @@
 #include <linux/netdevice.h>
 #include <linux/usb.h>
 #include <linux/ethtool.h>
+#include <linux/sysfs.h>
+#include <linux/device.h>
 
 #include <linux/can.h>
 #include <linux/can/dev.h>
@@ -53,6 +55,26 @@ static const struct usb_device_id peak_usb_table[] = {
 
 MODULE_DEVICE_TABLE(usb, peak_usb_table);
 
+static ssize_t can_channel_id_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->can_channel_id);
+}
+static DEVICE_ATTR_RO(can_channel_id);
+
+/* mutable to avoid cast in attribute_group */
+static struct attribute *peak_usb_sysfs_attrs[] = {
+	&dev_attr_can_channel_id.attr,
+	NULL,
+};
+
+static const struct attribute_group peak_usb_sysfs_group = {
+	.name	= "peak_usb",
+	.attrs	= peak_usb_sysfs_attrs,
+};
+
 /*
  * dump memory
  */
@@ -961,6 +983,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.39.1



  parent reply	other threads:[~2023-02-06 13:19 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 13:15 [PATCH net-next 0/47] pull-request: can-next 2023-02-06 Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 01/47] can: gw: give feedback on missing CGW_FLAGS_CAN_IIF_TX_OK flag Marc Kleine-Budde
2023-02-07 15:30   ` patchwork-bot+netdevbpf
2023-02-06 13:15 ` [PATCH net-next 02/47] can: isotp: check CAN address family in isotp_bind() Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 03/47] can: mcp251xfd: regmap: optimizing transfer size for CRC transfers size 1 Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 04/47] dt-bindings: can: renesas,rcar-canfd: R-Car V3U is R-Car Gen4 Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 05/47] dt-bindings: can: renesas,rcar-canfd: Document R-Car V4H support Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 06/47] dt-bindings: can: renesas,rcar-canfd: Add transceiver support Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 07/47] can: rcar_canfd: Fix R-Car V3U CAN mode selection Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 08/47] can: rcar_canfd: Fix R-Car V3U GAFLCFG field accesses Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 09/47] can: rcar_canfd: Abstract out DCFG address differences Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 10/47] can: rcar_canfd: Add support for R-Car Gen4 Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 11/47] can: rcar_canfd: Fix R-Car Gen4 DCFG.DSJW field width Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 12/47] can: rcar_canfd: Fix R-Car Gen4 CFCC.CFTML " Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 13/47] can: rcar_canfd: Sort included header files Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 14/47] can: rcar_canfd: Add helper variable dev Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 15/47] can: ems_pci: Fix code style, copyright and email address Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 16/47] can: ems_pci: Add Asix AX99100 definitions Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 17/47] can: ems_pci: Initialize BAR registers Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 18/47] can: ems_pci: Add read/write register and post irq functions Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 19/47] can: ems_pci: Initialize CAN controller base addresses Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 20/47] can: ems_pci: Add IRQ enable Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 21/47] can: ems_pci: Deassert hardware reset Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 22/47] can: ems_pci: Add myself as module author Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 23/47] can: peak_usb: rename device_id to CAN channel ID Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 24/47] can: peak_usb: add callback to read CAN channel ID of PEAK CAN-FD devices Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 25/47] can: peak_usb: allow flashing of the CAN channel ID Marc Kleine-Budde
2023-02-06 13:15 ` [PATCH net-next 26/47] can: peak_usb: replace unregister_netdev() with unregister_candev() Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 27/47] can: peak_usb: add ethtool interface to user-configurable CAN channel identifier Marc Kleine-Budde
2023-02-06 13:16 ` Marc Kleine-Budde [this message]
2023-02-06 13:16 ` [PATCH net-next 29/47] can: peak_usb: align CAN channel ID format in log with sysfs attribute Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 30/47] can: peak_usb: Reorder include directives alphabetically Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 31/47] can: bittiming(): replace open coded variants of can_bit_time() Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 32/47] can: bittiming: can_fixup_bittiming(): use CAN_SYNC_SEG instead of 1 Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 33/47] can: bittiming: can_fixup_bittiming(): set effective tq Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 34/47] can: bittiming: can_get_bittiming(): use direct return and remove unneeded else Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 35/47] can: dev: register_candev(): ensure that bittiming const are valid Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 36/47] can: dev: register_candev(): bail out if both fixed bit rates and bit timing constants are provided Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 37/47] can: netlink: can_validate(): validate sample point for CAN and CAN-FD Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 38/47] can: netlink: can_changelink(): convert from netdev_err() to NL_SET_ERR_MSG_FMT() Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 39/47] can: bittiming: can_changelink() pass extack down callstack Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 40/47] can: bittiming: factor out can_sjw_set_default() and can_sjw_check() Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 41/47] can: bittiming: can_fixup_bittiming(): report error via netlink and harmonize error value Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 42/47] can: bittiming: can_sjw_check(): " Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 43/47] can: bittiming: can_sjw_check(): check that SJW is not longer than either Phase Buffer Segment Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 44/47] can: bittiming: can_sjw_set_default(): use Phase Seg2 / 2 as default for SJW Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 45/47] can: bittiming: can_calc_bittiming(): clean up SJW handling Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 46/47] can: bittiming: can_calc_bittiming(): convert from netdev_err() to NL_SET_ERR_MSG_FMT() Marc Kleine-Budde
2023-02-06 13:16 ` [PATCH net-next 47/47] can: bittiming: can_validate_bitrate(): report error via netlink 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=20230206131620.2758724-29-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=lukas.magel@posteo.net \
    --cc=netdev@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.