Skip to content

Commit c589557

Browse files
Jimmy Assarssonmarckleinebudde
authored andcommitted
can: kvaser_pciefd: Empty SRB buffer in probe
Empty the "Shared receive buffer" (SRB) in probe, to assure we start in a known state, and don't process any irrelevant packets. Fixes: 26ad340 ("can: kvaser_pciefd: Add driver for Kvaser PCIEcan devices") Cc: [email protected] Signed-off-by: Jimmy Assarsson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 84762d8 commit c589557

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

drivers/net/can/kvaser_pciefd.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices");
7171
#define KVASER_PCIEFD_SYSID_BUILD_REG (KVASER_PCIEFD_SYSID_BASE + 0x14)
7272
/* Shared receive buffer registers */
7373
#define KVASER_PCIEFD_SRB_BASE 0x1f200
74+
#define KVASER_PCIEFD_SRB_FIFO_LAST_REG (KVASER_PCIEFD_SRB_BASE + 0x1f4)
7475
#define KVASER_PCIEFD_SRB_CMD_REG (KVASER_PCIEFD_SRB_BASE + 0x200)
7576
#define KVASER_PCIEFD_SRB_IEN_REG (KVASER_PCIEFD_SRB_BASE + 0x204)
7677
#define KVASER_PCIEFD_SRB_IRQ_REG (KVASER_PCIEFD_SRB_BASE + 0x20c)
7778
#define KVASER_PCIEFD_SRB_STAT_REG (KVASER_PCIEFD_SRB_BASE + 0x210)
79+
#define KVASER_PCIEFD_SRB_RX_NR_PACKETS_REG (KVASER_PCIEFD_SRB_BASE + 0x214)
7880
#define KVASER_PCIEFD_SRB_CTRL_REG (KVASER_PCIEFD_SRB_BASE + 0x218)
7981
/* EPCS flash controller registers */
8082
#define KVASER_PCIEFD_SPI_BASE 0x1fc00
@@ -111,6 +113,9 @@ MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices");
111113
/* DMA support */
112114
#define KVASER_PCIEFD_SRB_STAT_DMA BIT(24)
113115

116+
/* SRB current packet level */
117+
#define KVASER_PCIEFD_SRB_RX_NR_PACKETS_MASK 0xff
118+
114119
/* DMA Enable */
115120
#define KVASER_PCIEFD_SRB_CTRL_DMA_ENABLE BIT(0)
116121

@@ -1061,6 +1066,7 @@ static int kvaser_pciefd_setup_dma(struct kvaser_pciefd *pcie)
10611066
{
10621067
int i;
10631068
u32 srb_status;
1069+
u32 srb_packet_count;
10641070
dma_addr_t dma_addr[KVASER_PCIEFD_DMA_COUNT];
10651071

10661072
/* Disable the DMA */
@@ -1088,6 +1094,15 @@ static int kvaser_pciefd_setup_dma(struct kvaser_pciefd *pcie)
10881094
KVASER_PCIEFD_SRB_CMD_RDB1,
10891095
pcie->reg_base + KVASER_PCIEFD_SRB_CMD_REG);
10901096

1097+
/* Empty Rx FIFO */
1098+
srb_packet_count = ioread32(pcie->reg_base + KVASER_PCIEFD_SRB_RX_NR_PACKETS_REG) &
1099+
KVASER_PCIEFD_SRB_RX_NR_PACKETS_MASK;
1100+
while (srb_packet_count) {
1101+
/* Drop current packet in FIFO */
1102+
ioread32(pcie->reg_base + KVASER_PCIEFD_SRB_FIFO_LAST_REG);
1103+
srb_packet_count--;
1104+
}
1105+
10911106
srb_status = ioread32(pcie->reg_base + KVASER_PCIEFD_SRB_STAT_REG);
10921107
if (!(srb_status & KVASER_PCIEFD_SRB_STAT_DI)) {
10931108
dev_err(&pcie->pci->dev, "DMA not idle before enabling\n");

0 commit comments

Comments
 (0)