Skip to content

Commit ecd82df

Browse files
Merge patch series "can: kvaser_usb: Simplify identification of physical CAN interfaces"
Jimmy Assarsson <extja@kvaser.com> says: This patch series simplifies the process of identifying which network interface (can0..canX) corresponds to which physical CAN channel on Kvaser USB based CAN interfaces. Note that this patch series is based on [1] "can: kvaser_pciefd: Simplify identification of physical CAN interfaces" Changes in v3: - Fix GCC compiler array warning (-Warray-bounds) - Fix transient Sparse warning - Add tag Reviewed-by Vincent Mailhol Changes in v2: - New patch with devlink documentation - New patch assigning netdev.dev_port - Formatting and refactoring [1] https://lore.kernel.org/linux-can/20250725123230.8-1-extja@kvaser.com Link: https://patch.msgid.link/20250725123452.41-1-extja@kvaser.com Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2 parents 46647a8 + 6304c4c commit ecd82df

9 files changed

Lines changed: 388 additions & 48 deletions

File tree

Documentation/networking/devlink/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ parameters, info versions, and other features it supports.
8686
ice
8787
ixgbe
8888
kvaser_pciefd
89+
kvaser_usb
8990
mlx4
9091
mlx5
9192
mlxsw
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
==========================
4+
kvaser_usb devlink support
5+
==========================
6+
7+
This document describes the devlink features implemented by the
8+
``kvaser_usb`` device driver.
9+
10+
Info versions
11+
=============
12+
13+
The ``kvaser_usb`` driver reports the following versions
14+
15+
.. list-table:: devlink info versions implemented
16+
:widths: 5 5 90
17+
18+
* - Name
19+
- Type
20+
- Description
21+
* - ``fw``
22+
- running
23+
- Version of the firmware running on the device. Also available
24+
through ``ethtool -i`` as ``firmware-version``.
25+
* - ``board.rev``
26+
- fixed
27+
- The device hardware revision.
28+
* - ``board.id``
29+
- fixed
30+
- The device EAN (product number).
31+
* - ``serial_number``
32+
- fixed
33+
- The device serial number.

drivers/net/can/usb/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ config CAN_GS_USB
6666

6767
config CAN_KVASER_USB
6868
tristate "Kvaser CAN/USB interface"
69+
select NET_DEVLINK
6970
help
7071
This driver adds support for Kvaser CAN/USB devices like Kvaser
7172
Leaf Light, Kvaser USBcan II and Kvaser Memorator Pro 5xHS.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
obj-$(CONFIG_CAN_KVASER_USB) += kvaser_usb.o
3-
kvaser_usb-y = kvaser_usb_core.o kvaser_usb_leaf.o kvaser_usb_hydra.o
3+
kvaser_usb-y = kvaser_usb_core.o kvaser_usb_devlink.o kvaser_usb_leaf.o kvaser_usb_hydra.o

drivers/net/can/usb/kvaser_usb/kvaser_usb.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/spinlock.h>
2828
#include <linux/types.h>
2929
#include <linux/usb.h>
30+
#include <net/devlink.h>
3031

3132
#include <linux/can.h>
3233
#include <linux/can/dev.h>
@@ -47,13 +48,22 @@
4748
#define KVASER_USB_CAP_EXT_CAP 0x02
4849
#define KVASER_USB_HYDRA_CAP_EXT_CMD 0x04
4950

51+
#define KVASER_USB_SW_VERSION_MAJOR_MASK GENMASK(31, 24)
52+
#define KVASER_USB_SW_VERSION_MINOR_MASK GENMASK(23, 16)
53+
#define KVASER_USB_SW_VERSION_BUILD_MASK GENMASK(15, 0)
54+
5055
struct kvaser_usb_dev_cfg;
5156

5257
enum kvaser_usb_leaf_family {
5358
KVASER_LEAF,
5459
KVASER_USBCAN,
5560
};
5661

62+
enum kvaser_usb_led_state {
63+
KVASER_USB_LED_ON = 0,
64+
KVASER_USB_LED_OFF = 1,
65+
};
66+
5767
#define KVASER_USB_HYDRA_MAX_CMD_LEN 128
5868
struct kvaser_usb_dev_card_data_hydra {
5969
u8 channel_to_he[KVASER_USB_MAX_NET_DEVICES];
@@ -78,6 +88,12 @@ struct kvaser_usb_tx_urb_context {
7888
u32 echo_index;
7989
};
8090

91+
struct kvaser_usb_fw_version {
92+
u8 major;
93+
u8 minor;
94+
u16 build;
95+
};
96+
8197
struct kvaser_usb_busparams {
8298
__le32 bitrate;
8399
u8 tseg1;
@@ -96,12 +112,15 @@ struct kvaser_usb {
96112
struct usb_endpoint_descriptor *bulk_in, *bulk_out;
97113
struct usb_anchor rx_submitted;
98114

115+
u32 ean[2];
116+
u32 serial_number;
117+
struct kvaser_usb_fw_version fw_version;
118+
u8 hw_revision;
119+
unsigned int nchannels;
99120
/* @max_tx_urbs: Firmware-reported maximum number of outstanding,
100121
* not yet ACKed, transmissions on this device. This value is
101122
* also used as a sentinel for marking free tx contexts.
102123
*/
103-
u32 fw_version;
104-
unsigned int nchannels;
105124
unsigned int max_tx_urbs;
106125
struct kvaser_usb_dev_card_data card_data;
107126

@@ -112,6 +131,7 @@ struct kvaser_usb {
112131

113132
struct kvaser_usb_net_priv {
114133
struct can_priv can;
134+
struct devlink_port devlink_port;
115135
struct can_berr_counter bec;
116136

117137
/* subdriver-specific data */
@@ -149,6 +169,7 @@ struct kvaser_usb_net_priv {
149169
* @dev_get_software_details: get software details
150170
* @dev_get_card_info: get card info
151171
* @dev_get_capabilities: discover device capabilities
172+
* @dev_set_led: turn on/off device LED
152173
*
153174
* @dev_set_opt_mode: set ctrlmod
154175
* @dev_start_chip: start the CAN controller
@@ -176,6 +197,9 @@ struct kvaser_usb_dev_ops {
176197
int (*dev_get_software_details)(struct kvaser_usb *dev);
177198
int (*dev_get_card_info)(struct kvaser_usb *dev);
178199
int (*dev_get_capabilities)(struct kvaser_usb *dev);
200+
int (*dev_set_led)(struct kvaser_usb_net_priv *priv,
201+
enum kvaser_usb_led_state state,
202+
u16 duration_ms);
179203
int (*dev_set_opt_mode)(const struct kvaser_usb_net_priv *priv);
180204
int (*dev_start_chip)(struct kvaser_usb_net_priv *priv);
181205
int (*dev_stop_chip)(struct kvaser_usb_net_priv *priv);
@@ -204,6 +228,11 @@ struct kvaser_usb_dev_cfg {
204228
extern const struct kvaser_usb_dev_ops kvaser_usb_hydra_dev_ops;
205229
extern const struct kvaser_usb_dev_ops kvaser_usb_leaf_dev_ops;
206230

231+
extern const struct devlink_ops kvaser_usb_devlink_ops;
232+
233+
int kvaser_usb_devlink_port_register(struct kvaser_usb_net_priv *priv);
234+
void kvaser_usb_devlink_port_unregister(struct kvaser_usb_net_priv *priv);
235+
207236
void kvaser_usb_unlink_tx_urbs(struct kvaser_usb_net_priv *priv);
208237

209238
int kvaser_usb_recv_cmd(const struct kvaser_usb *dev, void *cmd, int len,

0 commit comments

Comments
 (0)