Skip to content

Commit 46647a8

Browse files
Merge patch series "can: kvaser_pciefd: 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 PCIe based CAN interfaces. Changes in v4: - Fix transient Sparse warning - Add tag Reviewed-by Vincent Mailhol Changes in v3: - Fixed typo; kvaser_pcied -> kvaser_pciefd in documentation patch Changes in v2: - Replace use of netdev.dev_id with netdev.dev_port - Formatting and refactoring - New patch with devlink documentation Link: https://patch.msgid.link/20250725123230.8-1-extja@kvaser.com Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2 parents 2db7a52 + fed5524 commit 46647a8

8 files changed

Lines changed: 257 additions & 74 deletions

File tree

Documentation/networking/devlink/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ parameters, info versions, and other features it supports.
8585
ionic
8686
ice
8787
ixgbe
88+
kvaser_pciefd
8889
mlx4
8990
mlx5
9091
mlxsw
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=============================
4+
kvaser_pciefd devlink support
5+
=============================
6+
7+
This document describes the devlink features implemented by the
8+
``kvaser_pciefd`` device driver.
9+
10+
Info versions
11+
=============
12+
13+
The ``kvaser_pciefd`` 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``.

drivers/net/can/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ config CAN_JANZ_ICAN3
154154
config CAN_KVASER_PCIEFD
155155
depends on PCI
156156
tristate "Kvaser PCIe FD cards"
157+
select NET_DEVLINK
157158
help
158159
This is a driver for the Kvaser PCI Express CAN FD family.
159160

drivers/net/can/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ obj-$(CONFIG_CAN_FLEXCAN) += flexcan/
2525
obj-$(CONFIG_CAN_GRCAN) += grcan.o
2626
obj-$(CONFIG_CAN_IFI_CANFD) += ifi_canfd/
2727
obj-$(CONFIG_CAN_JANZ_ICAN3) += janz-ican3.o
28-
obj-$(CONFIG_CAN_KVASER_PCIEFD) += kvaser_pciefd.o
28+
obj-$(CONFIG_CAN_KVASER_PCIEFD) += kvaser_pciefd/
2929
obj-$(CONFIG_CAN_MSCAN) += mscan/
3030
obj-$(CONFIG_CAN_M_CAN) += m_can/
3131
obj-$(CONFIG_CAN_PEAK_PCIEFD) += peak_canfd/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
obj-$(CONFIG_CAN_KVASER_PCIEFD) += kvaser_pciefd.o
3+
kvaser_pciefd-y = kvaser_pciefd_core.o kvaser_pciefd_devlink.o
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
2+
/* kvaser_pciefd common definitions and declarations
3+
*
4+
* Copyright (C) 2025 KVASER AB, Sweden. All rights reserved.
5+
*/
6+
7+
#ifndef _KVASER_PCIEFD_H
8+
#define _KVASER_PCIEFD_H
9+
10+
#include <linux/can/dev.h>
11+
#include <linux/completion.h>
12+
#include <linux/pci.h>
13+
#include <linux/spinlock.h>
14+
#include <linux/timer.h>
15+
#include <linux/types.h>
16+
#include <net/devlink.h>
17+
18+
#define KVASER_PCIEFD_MAX_CAN_CHANNELS 8UL
19+
#define KVASER_PCIEFD_DMA_COUNT 2U
20+
#define KVASER_PCIEFD_DMA_SIZE (4U * 1024U)
21+
#define KVASER_PCIEFD_CAN_TX_MAX_COUNT 17U
22+
23+
struct kvaser_pciefd;
24+
25+
struct kvaser_pciefd_address_offset {
26+
u32 serdes;
27+
u32 pci_ien;
28+
u32 pci_irq;
29+
u32 sysid;
30+
u32 loopback;
31+
u32 kcan_srb_fifo;
32+
u32 kcan_srb;
33+
u32 kcan_ch0;
34+
u32 kcan_ch1;
35+
};
36+
37+
struct kvaser_pciefd_irq_mask {
38+
u32 kcan_rx0;
39+
u32 kcan_tx[KVASER_PCIEFD_MAX_CAN_CHANNELS];
40+
u32 all;
41+
};
42+
43+
struct kvaser_pciefd_dev_ops {
44+
void (*kvaser_pciefd_write_dma_map)(struct kvaser_pciefd *pcie,
45+
dma_addr_t addr, int index);
46+
};
47+
48+
struct kvaser_pciefd_driver_data {
49+
const struct kvaser_pciefd_address_offset *address_offset;
50+
const struct kvaser_pciefd_irq_mask *irq_mask;
51+
const struct kvaser_pciefd_dev_ops *ops;
52+
};
53+
54+
struct kvaser_pciefd_fw_version {
55+
u8 major;
56+
u8 minor;
57+
u16 build;
58+
};
59+
60+
struct kvaser_pciefd_can {
61+
struct can_priv can;
62+
struct devlink_port devlink_port;
63+
struct kvaser_pciefd *kv_pcie;
64+
void __iomem *reg_base;
65+
struct can_berr_counter bec;
66+
u32 ioc;
67+
u8 cmd_seq;
68+
u8 tx_max_count;
69+
u8 tx_idx;
70+
u8 ack_idx;
71+
int err_rep_cnt;
72+
unsigned int completed_tx_pkts;
73+
unsigned int completed_tx_bytes;
74+
spinlock_t lock; /* Locks sensitive registers (e.g. MODE) */
75+
struct timer_list bec_poll_timer;
76+
struct completion start_comp, flush_comp;
77+
};
78+
79+
struct kvaser_pciefd {
80+
struct pci_dev *pci;
81+
void __iomem *reg_base;
82+
struct kvaser_pciefd_can *can[KVASER_PCIEFD_MAX_CAN_CHANNELS];
83+
const struct kvaser_pciefd_driver_data *driver_data;
84+
void *dma_data[KVASER_PCIEFD_DMA_COUNT];
85+
u8 nr_channels;
86+
u32 bus_freq;
87+
u32 freq;
88+
u32 freq_to_ticks_div;
89+
struct kvaser_pciefd_fw_version fw_version;
90+
};
91+
92+
extern const struct devlink_ops kvaser_pciefd_devlink_ops;
93+
94+
int kvaser_pciefd_devlink_port_register(struct kvaser_pciefd_can *can);
95+
void kvaser_pciefd_devlink_port_unregister(struct kvaser_pciefd_can *can);
96+
#endif /* _KVASER_PCIEFD_H */

0 commit comments

Comments
 (0)