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
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.
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.
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.
18 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
20 drivers/net/can/flexcan.c | 30 +++++++++++++-----------------
21 1 file changed, 13 insertions(+), 17 deletions(-)
23 --- a/drivers/net/can/flexcan.c
24 +++ b/drivers/net/can/flexcan.c
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 {
35 u8 clk_src; /* clock source of CAN Protocol Engine */
44 @@ -873,16 +873,15 @@ static struct sk_buff *flexcan_mailbox_r
49 static inline u64 flexcan_read_reg_iflag_rx(struct flexcan_priv *priv)
51 struct flexcan_regs __iomem *regs = priv->regs;
55 - iflag2 = priv->read(®s->iflag2) & priv->rx_mask2;
56 - iflag1 = priv->read(®s->iflag1) & priv->rx_mask1;
57 + iflag = (u64)priv->read(®s->iflag2) << 32 |
58 + priv->read(®s->iflag1);
60 - return (u64)iflag2 << 32 | iflag1;
61 + return iflag & priv->rx_mask;
64 static irqreturn_t flexcan_irq(int irq, void *dev_id)
65 @@ -1053,6 +1052,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;
71 struct flexcan_mb __iomem *mb;
73 @@ -1227,8 +1227,9 @@ static int flexcan_chip_start(struct net
74 /* enable interrupts atomically */
75 disable_irq(dev->irq);
76 priv->write(priv->reg_ctrl_default, ®s->ctrl);
77 - priv->write(priv->rx_mask1, ®s->imask1);
78 - priv->write(priv->rx_mask2 | FLEXCAN_IFLAG2_MB(priv->tx_mb_idx), ®s->imask2);
79 + reg_imask = priv->rx_mask | FLEXCAN_IFLAG_MB(priv->tx_mb_idx);
80 + priv->write(upper_32_bits(reg_imask), ®s->imask2);
81 + priv->write(lower_32_bits(reg_imask), ®s->imask1);
84 /* print chip status */
85 @@ -1300,19 +1301,14 @@ static int flexcan_open(struct net_devic
86 priv->offload.mailbox_read = flexcan_mailbox_read;
88 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
91 priv->offload.mb_first = FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST;
92 priv->offload.mb_last = priv->mb_count - 2;
94 - imask = GENMASK_ULL(priv->offload.mb_last,
95 - priv->offload.mb_first);
96 - priv->rx_mask1 = imask;
97 - priv->rx_mask2 = imask >> 32;
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);
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);