Commit ecd82dfb authored by Marc Kleine-Budde's avatar Marc Kleine-Budde
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: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parents 46647a84 6304c4c8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ parameters, info versions, and other features it supports.
   ice
   ixgbe
   kvaser_pciefd
   kvaser_usb
   mlx4
   mlx5
   mlxsw
+33 −0
Original line number Diff line number Diff line
.. SPDX-License-Identifier: GPL-2.0

==========================
kvaser_usb devlink support
==========================

This document describes the devlink features implemented by the
``kvaser_usb`` device driver.

Info versions
=============

The ``kvaser_usb`` driver reports the following versions

.. list-table:: devlink info versions implemented
   :widths: 5 5 90

   * - Name
     - Type
     - Description
   * - ``fw``
     - running
     - Version of the firmware running on the device. Also available
       through ``ethtool -i`` as ``firmware-version``.
   * - ``board.rev``
     - fixed
     - The device hardware revision.
   * - ``board.id``
     - fixed
     - The device EAN (product number).
   * - ``serial_number``
     - fixed
     - The device serial number.
+1 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ config CAN_GS_USB

config CAN_KVASER_USB
	tristate "Kvaser CAN/USB interface"
	select NET_DEVLINK
	help
	  This driver adds support for Kvaser CAN/USB devices like Kvaser
	  Leaf Light, Kvaser USBcan II and Kvaser Memorator Pro 5xHS.
+1 −1
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_CAN_KVASER_USB) += kvaser_usb.o
kvaser_usb-y = kvaser_usb_core.o kvaser_usb_leaf.o kvaser_usb_hydra.o
kvaser_usb-y = kvaser_usb_core.o kvaser_usb_devlink.o kvaser_usb_leaf.o kvaser_usb_hydra.o
+31 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <linux/spinlock.h>
#include <linux/types.h>
#include <linux/usb.h>
#include <net/devlink.h>

#include <linux/can.h>
#include <linux/can/dev.h>
@@ -47,6 +48,10 @@
#define KVASER_USB_CAP_EXT_CAP			0x02
#define KVASER_USB_HYDRA_CAP_EXT_CMD		0x04

#define KVASER_USB_SW_VERSION_MAJOR_MASK GENMASK(31, 24)
#define KVASER_USB_SW_VERSION_MINOR_MASK GENMASK(23, 16)
#define KVASER_USB_SW_VERSION_BUILD_MASK GENMASK(15, 0)

struct kvaser_usb_dev_cfg;

enum kvaser_usb_leaf_family {
@@ -54,6 +59,11 @@ enum kvaser_usb_leaf_family {
	KVASER_USBCAN,
};

enum kvaser_usb_led_state {
	KVASER_USB_LED_ON = 0,
	KVASER_USB_LED_OFF = 1,
};

#define KVASER_USB_HYDRA_MAX_CMD_LEN		128
struct kvaser_usb_dev_card_data_hydra {
	u8 channel_to_he[KVASER_USB_MAX_NET_DEVICES];
@@ -78,6 +88,12 @@ struct kvaser_usb_tx_urb_context {
	u32 echo_index;
};

struct kvaser_usb_fw_version {
	u8 major;
	u8 minor;
	u16 build;
};

struct kvaser_usb_busparams {
	__le32 bitrate;
	u8 tseg1;
@@ -96,12 +112,15 @@ struct kvaser_usb {
	struct usb_endpoint_descriptor *bulk_in, *bulk_out;
	struct usb_anchor rx_submitted;

	u32 ean[2];
	u32 serial_number;
	struct kvaser_usb_fw_version fw_version;
	u8 hw_revision;
	unsigned int nchannels;
	/* @max_tx_urbs: Firmware-reported maximum number of outstanding,
	 * not yet ACKed, transmissions on this device. This value is
	 * also used as a sentinel for marking free tx contexts.
	 */
	u32 fw_version;
	unsigned int nchannels;
	unsigned int max_tx_urbs;
	struct kvaser_usb_dev_card_data card_data;

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

struct kvaser_usb_net_priv {
	struct can_priv can;
	struct devlink_port devlink_port;
	struct can_berr_counter bec;

	/* subdriver-specific data */
@@ -149,6 +169,7 @@ struct kvaser_usb_net_priv {
 * @dev_get_software_details:	get software details
 * @dev_get_card_info:		get card info
 * @dev_get_capabilities:	discover device capabilities
 * @dev_set_led:		turn on/off device LED
 *
 * @dev_set_opt_mode:		set ctrlmod
 * @dev_start_chip:		start the CAN controller
@@ -176,6 +197,9 @@ struct kvaser_usb_dev_ops {
	int (*dev_get_software_details)(struct kvaser_usb *dev);
	int (*dev_get_card_info)(struct kvaser_usb *dev);
	int (*dev_get_capabilities)(struct kvaser_usb *dev);
	int (*dev_set_led)(struct kvaser_usb_net_priv *priv,
			   enum kvaser_usb_led_state state,
			   u16 duration_ms);
	int (*dev_set_opt_mode)(const struct kvaser_usb_net_priv *priv);
	int (*dev_start_chip)(struct kvaser_usb_net_priv *priv);
	int (*dev_stop_chip)(struct kvaser_usb_net_priv *priv);
@@ -204,6 +228,11 @@ struct kvaser_usb_dev_cfg {
extern const struct kvaser_usb_dev_ops kvaser_usb_hydra_dev_ops;
extern const struct kvaser_usb_dev_ops kvaser_usb_leaf_dev_ops;

extern const struct devlink_ops kvaser_usb_devlink_ops;

int kvaser_usb_devlink_port_register(struct kvaser_usb_net_priv *priv);
void kvaser_usb_devlink_port_unregister(struct kvaser_usb_net_priv *priv);

void kvaser_usb_unlink_tx_urbs(struct kvaser_usb_net_priv *priv);

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