c7e5e4ec4f0b23717404f6e9e32f481bcb94e5be
[openwrt/openwrt.git] /
1 From 74920ba156136a58dd3411c02d429d4f31497dc0 Mon Sep 17 00:00:00 2001
2 From: Marc Kleine-Budde <mkl@pengutronix.de>
3 Date: Fri, 1 Mar 2019 15:38:05 +0100
4 Subject: [PATCH] can: flexcan: flexcan_read_reg_iflag_rx(): optimize reading
5
6 The flexcan IP core has up to 64 mailboxes, each one has a corresponding
7 interrupt bit in the iflag1 or iflag2 registers and a mask bit in the
8 imask1 or imask2 registers.
9
10 In the timestamp (i.e. non FIFO) mode the driver needs to mask all non RX
11 interrupt sources, it uses the precomputed value rx_mask of struct flexcan_priv
12 for this.
13
14 In certain use cases, for example the CANFD mode, the contents of the iflag2
15 register is completely masked.
16
17 This patch optimizes the flexcan_read_reg_iflag_rx() function by not reading
18 the iflag1 or iflag2 register if the contents is masked.
19
20 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
21 ---
22 drivers/net/can/flexcan.c | 28 +++++++++++++++++-----------
23 1 file changed, 17 insertions(+), 11 deletions(-)
24
25 --- a/drivers/net/can/flexcan.c
26 +++ b/drivers/net/can/flexcan.c
27 @@ -786,6 +786,23 @@ static void flexcan_irq_state(struct net
28 dev->stats.rx_fifo_errors++;
29 }
30
31 +static inline u64 flexcan_read64_mask(struct flexcan_priv *priv, void __iomem *addr, u64 mask)
32 +{
33 + u64 reg = 0;
34 +
35 + if (upper_32_bits(mask))
36 + reg = (u64)priv->read(addr - 4) << 32;
37 + if (lower_32_bits(mask))
38 + reg |= priv->read(addr);
39 +
40 + return reg & mask;
41 +}
42 +
43 +static inline u64 flexcan_read_reg_iflag_rx(struct flexcan_priv *priv)
44 +{
45 + return flexcan_read64_mask(priv, &priv->regs->iflag1, priv->rx_mask);
46 +}
47 +
48 static inline struct flexcan_priv *rx_offload_to_priv(struct can_rx_offload *offload)
49 {
50 return container_of(offload, struct flexcan_priv, offload);
51 @@ -880,17 +897,6 @@ static struct sk_buff *flexcan_mailbox_r
52 return skb;
53 }
54
55 -static inline u64 flexcan_read_reg_iflag_rx(struct flexcan_priv *priv)
56 -{
57 - struct flexcan_regs __iomem *regs = priv->regs;
58 - u64 iflag;
59 -
60 - iflag = (u64)priv->read(&regs->iflag2) << 32 |
61 - priv->read(&regs->iflag1);
62 -
63 - return iflag & priv->rx_mask;
64 -}
65 -
66 static irqreturn_t flexcan_irq(int irq, void *dev_id)
67 {
68 struct net_device *dev = dev_id;