* [PATCH v3 1/2] can: kvaser_usb: Simplify struct kvaser_msg_cardinfo
@ 2018-02-16 13:21 Jimmy Assarsson
2018-02-16 13:21 ` [PATCH v3 2/2] can: kvaser_usb: Expose EAN and serial number via sysfs Jimmy Assarsson
2018-02-16 13:26 ` [PATCH v3 1/2] can: kvaser_usb: Simplify struct kvaser_msg_cardinfo Marc Kleine-Budde
0 siblings, 2 replies; 3+ messages in thread
From: Jimmy Assarsson @ 2018-02-16 13:21 UTC (permalink / raw)
To: linux-can; +Cc: Jimmy Assarsson
serial_number_high can be removed from the struct since it is never used in
the USBcan II firmware.
Signed-off-by: Jimmy Assarsson <jimmyassarsson@gmail.com>
---
Changes in v3:
- Change data type of ean, from u32 to __le32.
Changes in v2:
- Made this a separate patch.
| 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
--git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index 63587b8e6825..3c17bb3b1588 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -196,19 +196,11 @@ struct kvaser_msg_simple {
struct kvaser_msg_cardinfo {
u8 tid;
u8 nchannels;
- union {
- struct {
- __le32 serial_number;
- __le32 padding;
- } __packed leaf0;
- struct {
- __le32 serial_number_low;
- __le32 serial_number_high;
- } __packed usbcan0;
- } __packed;
+ __le32 serial_number;
+ __le32 padding0;
__le32 clock_resolution;
__le32 mfgdate;
- u8 ean[8];
+ __le32 ean[2];
u8 hw_revision;
union {
struct {
@@ -218,7 +210,7 @@ struct kvaser_msg_cardinfo {
u8 padding;
} __packed usbcan1;
} __packed;
- __le16 padding;
+ __le16 padding1;
} __packed;
struct kvaser_msg_cardinfo2 {
--
2.16.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3 2/2] can: kvaser_usb: Expose EAN and serial number via sysfs
2018-02-16 13:21 [PATCH v3 1/2] can: kvaser_usb: Simplify struct kvaser_msg_cardinfo Jimmy Assarsson
@ 2018-02-16 13:21 ` Jimmy Assarsson
2018-02-16 13:26 ` [PATCH v3 1/2] can: kvaser_usb: Simplify struct kvaser_msg_cardinfo Marc Kleine-Budde
1 sibling, 0 replies; 3+ messages in thread
From: Jimmy Assarsson @ 2018-02-16 13:21 UTC (permalink / raw)
To: linux-can; +Cc: Jimmy Assarsson
The EAN (article number) combined with serial number form a unique
identifier for any Kvaser device. This makes it possible to map netdevice
with physical Kvaser device.
Example output for USBcan Light 2xHS:
$ cat /sys/class/net/can0/ean
7330130007147
$ cat /sys/class/net/can0/serial
10659
Tested with the following Kvaser devices:
Leaf Light HS, Leaf Light HS v2, USBcan Light 2xHS, USBcan II,
Memorator Professional HS/HS and Memorator HS/HS.
Signed-off-by: Jimmy Assarsson <jimmyassarsson@gmail.com>
---
Changes in v3:
- Add sysfs documentation.
Changes in v2:
- Use u64 for ean, instead of u32 ean[2].
- Use the existing sysfs_groups[0], from the net_device.
| 15 +++++++++
| 38 ++++++++++++++++++++++
2 files changed, 53 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-class-net_kvaser_usb
--git a/Documentation/ABI/testing/sysfs-class-net_kvaser_usb b/Documentation/ABI/testing/sysfs-class-net_kvaser_usb
new file mode 100644
index 000000000000..922a8cc41e60
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-net_kvaser_usb
@@ -0,0 +1,15 @@
+What: /sys/class/net/<ifname>/ean
+Date: February 2018
+Contact: Jimmy Assarsson <jimmyassarsson@gmail.com>
+KernelVersion: 4.16
+Description:
+ Read-only value representing the article number (EAN) for the
+ Kvaser CAN product.
+
+What: /sys/class/net/<ifname>/serial
+Date: February 2018
+Contact: Jimmy Assarsson <jimmyassarsson@gmail.com>
+KernelVersion: 4.16
+Description:
+ Read-only value representing the serial number for the Kvaser
+ CAN product.
--git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index 3c17bb3b1588..d3d19a7ff16f 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -457,6 +457,8 @@ struct kvaser_usb {
* also used as a sentinel for marking free tx contexts.
*/
u32 fw_version;
+ u32 serial;
+ u64 ean;
unsigned int nchannels;
unsigned int max_tx_urbs;
enum kvaser_usb_family family;
@@ -692,6 +694,10 @@ static int kvaser_usb_get_card_info(struct kvaser_usb *dev)
dev->nchannels > MAX_USBCAN_NET_DEVICES))
return -EINVAL;
+ dev->serial = le32_to_cpu(msg.u.cardinfo.serial_number);
+ dev->ean = (u64)(le32_to_cpu(msg.u.cardinfo.ean[1])) << 32 |
+ le32_to_cpu(msg.u.cardinfo.ean[0]);
+
return 0;
}
@@ -1802,6 +1808,37 @@ static const struct can_bittiming_const kvaser_usb_bittiming_const = {
.brp_inc = KVASER_USB_BRP_INC,
};
+static ssize_t serial_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct kvaser_usb_net_priv *priv = netdev_priv(to_net_dev(dev));
+ struct kvaser_usb *kvaser_dev = priv->dev;
+
+ return sprintf(buf, "%u\n", kvaser_dev->serial);
+}
+
+static ssize_t ean_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct kvaser_usb_net_priv *priv = netdev_priv(to_net_dev(dev));
+ struct kvaser_usb *kvaser_dev = priv->dev;
+
+ return sprintf(buf, "%llx\n", kvaser_dev->ean);
+}
+
+static DEVICE_ATTR_RO(serial);
+static DEVICE_ATTR_RO(ean);
+
+static struct attribute *kvaser_usb_dev_attrs[] = {
+ &dev_attr_serial.attr,
+ &dev_attr_ean.attr,
+ NULL,
+};
+
+static const struct attribute_group kvaser_usb_dev_group = {
+ .attrs = kvaser_usb_dev_attrs,
+};
+
static int kvaser_usb_set_bittiming(struct net_device *netdev)
{
struct kvaser_usb_net_priv *priv = netdev_priv(netdev);
@@ -1931,6 +1968,7 @@ static int kvaser_usb_init_one(struct usb_interface *intf,
netdev->flags |= IFF_ECHO;
netdev->netdev_ops = &kvaser_usb_netdev_ops;
+ netdev->sysfs_groups[0] = &kvaser_usb_dev_group;
SET_NETDEV_DEV(netdev, &intf->dev);
netdev->dev_id = channel;
--
2.16.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3 1/2] can: kvaser_usb: Simplify struct kvaser_msg_cardinfo
2018-02-16 13:21 [PATCH v3 1/2] can: kvaser_usb: Simplify struct kvaser_msg_cardinfo Jimmy Assarsson
2018-02-16 13:21 ` [PATCH v3 2/2] can: kvaser_usb: Expose EAN and serial number via sysfs Jimmy Assarsson
@ 2018-02-16 13:26 ` Marc Kleine-Budde
1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2018-02-16 13:26 UTC (permalink / raw)
To: Jimmy Assarsson, linux-can
[-- Attachment #1.1: Type: text/plain, Size: 1777 bytes --]
On 02/16/2018 02:21 PM, Jimmy Assarsson wrote:
> serial_number_high can be removed from the struct since it is never used in
> the USBcan II firmware.
>
> Signed-off-by: Jimmy Assarsson <jimmyassarsson@gmail.com>
> ---
> Changes in v3:
> - Change data type of ean, from u32 to __le32.
>
> Changes in v2:
> - Made this a separate patch.
>
> drivers/net/can/usb/kvaser_usb.c | 16 ++++------------
> 1 file changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
> index 63587b8e6825..3c17bb3b1588 100644
> --- a/drivers/net/can/usb/kvaser_usb.c
> +++ b/drivers/net/can/usb/kvaser_usb.c
> @@ -196,19 +196,11 @@ struct kvaser_msg_simple {
> struct kvaser_msg_cardinfo {
> u8 tid;
> u8 nchannels;
> - union {
> - struct {
> - __le32 serial_number;
> - __le32 padding;
> - } __packed leaf0;
> - struct {
> - __le32 serial_number_low;
> - __le32 serial_number_high;
> - } __packed usbcan0;
> - } __packed;
> + __le32 serial_number;
> + __le32 padding0;
> __le32 clock_resolution;
> __le32 mfgdate;
> - u8 ean[8];
> + __le32 ean[2];
Don't do that change in this patch - it belongs to 2/2.
> u8 hw_revision;
> union {
> struct {
> @@ -218,7 +210,7 @@ struct kvaser_msg_cardinfo {
> u8 padding;
> } __packed usbcan1;
> } __packed;
> - __le16 padding;
> + __le16 padding1;
> } __packed;
>
> struct kvaser_msg_cardinfo2 {
>
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-02-16 13:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-16 13:21 [PATCH v3 1/2] can: kvaser_usb: Simplify struct kvaser_msg_cardinfo Jimmy Assarsson
2018-02-16 13:21 ` [PATCH v3 2/2] can: kvaser_usb: Expose EAN and serial number via sysfs Jimmy Assarsson
2018-02-16 13:26 ` [PATCH v3 1/2] can: kvaser_usb: Simplify struct kvaser_msg_cardinfo Marc Kleine-Budde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox