348d564de576eadf07824c8f431314213976b42c
[openwrt/openwrt.git] /
1 From 6adf87956ee1043e6bf0ef83fa0eec1e755c0d48 Mon Sep 17 00:00:00 2001
2 From: Marc Kleine-Budde <mkl@pengutronix.de>
3 Date: Fri, 1 Mar 2019 12:17:30 +0100
4 Subject: [PATCH] can: flexcan: convert struct flexcan_priv::rx_mask{1,2} to
5 rx_mask
6
7 The flexcan IP core has up to 64 mailboxes, each one has a corresponding
8 interrupt bit in the iflag1 or iflag2 registers and a mask bit in the
9 imask1 or imask2 registers.
10
11 In the timestamp (i.e. non FIFO) mode the driver needs to mask out all non RX
12 interrupt sources and uses the precomputed values rx_mask1 and rx_mask2 of
13 struct flexcan_priv for this.
14
15 This patch merges the two u32 rx_mask1 and rx_mask2 to a single u64 rx_mask
16 variable, which simplifies the code a bit.
17
18 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
19 ---
20 drivers/net/can/flexcan.c | 30 +++++++++++++-----------------
21 1 file changed, 13 insertions(+), 17 deletions(-)
22
23 --- a/drivers/net/can/flexcan.c
24 +++ b/drivers/net/can/flexcan.c
25 @@ -142,6 +142,7 @@
26 #define FLEXCAN_TX_MB_RESERVED_OFF_FIFO 8
27 #define FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP 0
28 #define FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST (FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP + 1)
29 +#define FLEXCAN_IFLAG_MB(x) BIT_ULL(x)
30 #define FLEXCAN_IFLAG2_MB(x) BIT((x) & 0x1f)
31 #define FLEXCAN_IFLAG_RX_FIFO_OVERFLOW BIT(7)
32 #define FLEXCAN_IFLAG_RX_FIFO_WARN BIT(6)
33 @@ -277,9 +278,8 @@ struct flexcan_priv {
34 u8 mb_size;
35 u8 clk_src; /* clock source of CAN Protocol Engine */
36
37 + u64 rx_mask;
38 u32 reg_ctrl_default;
39 - u32 rx_mask1;
40 - u32 rx_mask2;
41
42 struct clk *clk_ipg;
43 struct clk *clk_per;
44 @@ -874,16 +874,15 @@ static struct sk_buff *flexcan_mailbox_r
45 return skb;
46 }
47
48 -
49 static inline u64 flexcan_read_reg_iflag_rx(struct flexcan_priv *priv)
50 {
51 struct flexcan_regs __iomem *regs = priv->regs;
52 - u32 iflag1, iflag2;
53 + u64 iflag;
54
55 - iflag2 = priv->read(&regs->iflag2) & priv->rx_mask2;
56 - iflag1 = priv->read(&regs->iflag1) & priv->rx_mask1;
57 + iflag = (u64)priv->read(&regs->iflag2) << 32 |
58 + priv->read(&regs->iflag1);
59
60 - return (u64)iflag2 << 32 | iflag1;
61 + return iflag & priv->rx_mask;
62 }
63
64 static irqreturn_t flexcan_irq(int irq, void *dev_id)
65 @@ -1054,6 +1053,7 @@ static int flexcan_chip_start(struct net
66 struct flexcan_priv *priv = netdev_priv(dev);
67 struct flexcan_regs __iomem *regs = priv->regs;
68 u32 reg_mcr, reg_ctrl, reg_ctrl2, reg_mecr;
69 + u64 reg_imask;
70 int err, i;
71 struct flexcan_mb __iomem *mb;
72
73 @@ -1224,8 +1224,9 @@ static int flexcan_chip_start(struct net
74 /* enable interrupts atomically */
75 disable_irq(dev->irq);
76 priv->write(priv->reg_ctrl_default, &regs->ctrl);
77 - priv->write(priv->rx_mask1, &regs->imask1);
78 - priv->write(priv->rx_mask2 | FLEXCAN_IFLAG2_MB(priv->tx_mb_idx), &regs->imask2);
79 + reg_imask = priv->rx_mask | FLEXCAN_IFLAG_MB(priv->tx_mb_idx);
80 + priv->write(upper_32_bits(reg_imask), &regs->imask2);
81 + priv->write(lower_32_bits(reg_imask), &regs->imask1);
82 enable_irq(dev->irq);
83
84 /* print chip status */
85 @@ -1322,19 +1323,14 @@ static int flexcan_open(struct net_devic
86 priv->offload.mailbox_read = flexcan_mailbox_read;
87
88 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
89 - u64 imask;
90 -
91 priv->offload.mb_first = FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST;
92 priv->offload.mb_last = priv->mb_count - 2;
93
94 - imask = GENMASK_ULL(priv->offload.mb_last,
95 - priv->offload.mb_first);
96 - priv->rx_mask1 = imask;
97 - priv->rx_mask2 = imask >> 32;
98 -
99 + priv->rx_mask = GENMASK_ULL(priv->offload.mb_last,
100 + priv->offload.mb_first);
101 err = can_rx_offload_add_timestamp(dev, &priv->offload);
102 } else {
103 - priv->rx_mask1 = FLEXCAN_IFLAG_RX_FIFO_OVERFLOW |
104 + priv->rx_mask = FLEXCAN_IFLAG_RX_FIFO_OVERFLOW |
105 FLEXCAN_IFLAG_RX_FIFO_AVAILABLE;
106 err = can_rx_offload_add_fifo(dev, &priv->offload,
107 FLEXCAN_NAPI_WEIGHT);