Skip to content

Commit 20bc87a

Browse files
Jimmy Assarssonmarckleinebudde
authored andcommitted
can: kvaser_pciefd: Split driver into C-file and header-file.
Split driver into C-file and header-file, to simplify future patches. Move common definitions and declarations to a header file. Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Jimmy Assarsson <extja@kvaser.com> Link: https://patch.msgid.link/20250725123230.8-7-extja@kvaser.com Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent d54b16b commit 20bc87a

4 files changed

Lines changed: 96 additions & 71 deletions

File tree

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
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
17+
#define KVASER_PCIEFD_MAX_CAN_CHANNELS 8UL
18+
#define KVASER_PCIEFD_DMA_COUNT 2U
19+
#define KVASER_PCIEFD_DMA_SIZE (4U * 1024U)
20+
#define KVASER_PCIEFD_CAN_TX_MAX_COUNT 17U
21+
22+
struct kvaser_pciefd;
23+
24+
struct kvaser_pciefd_address_offset {
25+
u32 serdes;
26+
u32 pci_ien;
27+
u32 pci_irq;
28+
u32 sysid;
29+
u32 loopback;
30+
u32 kcan_srb_fifo;
31+
u32 kcan_srb;
32+
u32 kcan_ch0;
33+
u32 kcan_ch1;
34+
};
35+
36+
struct kvaser_pciefd_irq_mask {
37+
u32 kcan_rx0;
38+
u32 kcan_tx[KVASER_PCIEFD_MAX_CAN_CHANNELS];
39+
u32 all;
40+
};
41+
42+
struct kvaser_pciefd_dev_ops {
43+
void (*kvaser_pciefd_write_dma_map)(struct kvaser_pciefd *pcie,
44+
dma_addr_t addr, int index);
45+
};
46+
47+
struct kvaser_pciefd_driver_data {
48+
const struct kvaser_pciefd_address_offset *address_offset;
49+
const struct kvaser_pciefd_irq_mask *irq_mask;
50+
const struct kvaser_pciefd_dev_ops *ops;
51+
};
52+
53+
struct kvaser_pciefd_fw_version {
54+
u8 major;
55+
u8 minor;
56+
u16 build;
57+
};
58+
59+
struct kvaser_pciefd_can {
60+
struct can_priv can;
61+
struct kvaser_pciefd *kv_pcie;
62+
void __iomem *reg_base;
63+
struct can_berr_counter bec;
64+
u32 ioc;
65+
u8 cmd_seq;
66+
u8 tx_max_count;
67+
u8 tx_idx;
68+
u8 ack_idx;
69+
int err_rep_cnt;
70+
unsigned int completed_tx_pkts;
71+
unsigned int completed_tx_bytes;
72+
spinlock_t lock; /* Locks sensitive registers (e.g. MODE) */
73+
struct timer_list bec_poll_timer;
74+
struct completion start_comp, flush_comp;
75+
};
76+
77+
struct kvaser_pciefd {
78+
struct pci_dev *pci;
79+
void __iomem *reg_base;
80+
struct kvaser_pciefd_can *can[KVASER_PCIEFD_MAX_CAN_CHANNELS];
81+
const struct kvaser_pciefd_driver_data *driver_data;
82+
void *dma_data[KVASER_PCIEFD_DMA_COUNT];
83+
u8 nr_channels;
84+
u32 bus_freq;
85+
u32 freq;
86+
u32 freq_to_ticks_div;
87+
struct kvaser_pciefd_fw_version fw_version;
88+
};
89+
90+
#endif /* _KVASER_PCIEFD_H */

drivers/net/can/kvaser_pciefd.c renamed to drivers/net/can/kvaser_pciefd/kvaser_pciefd_core.c

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* - PEAK linux canfd driver
66
*/
77

8+
#include "kvaser_pciefd.h"
9+
810
#include <linux/bitfield.h>
911
#include <linux/can/dev.h>
1012
#include <linux/device.h>
@@ -27,10 +29,6 @@ MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices");
2729
#define KVASER_PCIEFD_WAIT_TIMEOUT msecs_to_jiffies(1000)
2830
#define KVASER_PCIEFD_BEC_POLL_FREQ (jiffies + msecs_to_jiffies(200))
2931
#define KVASER_PCIEFD_MAX_ERR_REP 256U
30-
#define KVASER_PCIEFD_CAN_TX_MAX_COUNT 17U
31-
#define KVASER_PCIEFD_MAX_CAN_CHANNELS 8UL
32-
#define KVASER_PCIEFD_DMA_COUNT 2U
33-
#define KVASER_PCIEFD_DMA_SIZE (4U * 1024U)
3432

3533
#define KVASER_PCIEFD_VENDOR 0x1a07
3634

@@ -296,41 +294,6 @@ static void kvaser_pciefd_write_dma_map_sf2(struct kvaser_pciefd *pcie,
296294
static void kvaser_pciefd_write_dma_map_xilinx(struct kvaser_pciefd *pcie,
297295
dma_addr_t addr, int index);
298296

299-
struct kvaser_pciefd_address_offset {
300-
u32 serdes;
301-
u32 pci_ien;
302-
u32 pci_irq;
303-
u32 sysid;
304-
u32 loopback;
305-
u32 kcan_srb_fifo;
306-
u32 kcan_srb;
307-
u32 kcan_ch0;
308-
u32 kcan_ch1;
309-
};
310-
311-
struct kvaser_pciefd_dev_ops {
312-
void (*kvaser_pciefd_write_dma_map)(struct kvaser_pciefd *pcie,
313-
dma_addr_t addr, int index);
314-
};
315-
316-
struct kvaser_pciefd_irq_mask {
317-
u32 kcan_rx0;
318-
u32 kcan_tx[KVASER_PCIEFD_MAX_CAN_CHANNELS];
319-
u32 all;
320-
};
321-
322-
struct kvaser_pciefd_driver_data {
323-
const struct kvaser_pciefd_address_offset *address_offset;
324-
const struct kvaser_pciefd_irq_mask *irq_mask;
325-
const struct kvaser_pciefd_dev_ops *ops;
326-
};
327-
328-
struct kvaser_pciefd_fw_version {
329-
u8 major;
330-
u8 minor;
331-
u16 build;
332-
};
333-
334297
static const struct kvaser_pciefd_address_offset kvaser_pciefd_altera_address_offset = {
335298
.serdes = 0x1000,
336299
.pci_ien = 0x50,
@@ -415,37 +378,6 @@ static const struct kvaser_pciefd_driver_data kvaser_pciefd_xilinx_driver_data =
415378
.ops = &kvaser_pciefd_xilinx_dev_ops,
416379
};
417380

418-
struct kvaser_pciefd_can {
419-
struct can_priv can;
420-
struct kvaser_pciefd *kv_pcie;
421-
void __iomem *reg_base;
422-
struct can_berr_counter bec;
423-
u32 ioc;
424-
u8 cmd_seq;
425-
u8 tx_max_count;
426-
u8 tx_idx;
427-
u8 ack_idx;
428-
int err_rep_cnt;
429-
unsigned int completed_tx_pkts;
430-
unsigned int completed_tx_bytes;
431-
spinlock_t lock; /* Locks sensitive registers (e.g. MODE) */
432-
struct timer_list bec_poll_timer;
433-
struct completion start_comp, flush_comp;
434-
};
435-
436-
struct kvaser_pciefd {
437-
struct pci_dev *pci;
438-
void __iomem *reg_base;
439-
struct kvaser_pciefd_can *can[KVASER_PCIEFD_MAX_CAN_CHANNELS];
440-
const struct kvaser_pciefd_driver_data *driver_data;
441-
void *dma_data[KVASER_PCIEFD_DMA_COUNT];
442-
u8 nr_channels;
443-
u32 bus_freq;
444-
u32 freq;
445-
u32 freq_to_ticks_div;
446-
struct kvaser_pciefd_fw_version fw_version;
447-
};
448-
449381
struct kvaser_pciefd_rx_packet {
450382
u32 header[2];
451383
u64 timestamp;

0 commit comments

Comments
 (0)