Skip to content

Commit 0ca64f0

Browse files
can: flexcan: introduce struct flexcan_priv::tx_mask and make use of it
The current driver uses FLEXCAN_IFLAG2_MB() to generate the mask to check for the TX complete interrupt. This works well, as the driver will always use the last mailbox for TX, which falls into the iflag2 register. To support CANFD the payload size has to increase to 64 bytes and the number of mailboxes will decrease so much that the TX mailbox will be handled in the iflag1 register. This patch introduces a tx_mask in the struct flexcan_priv (similar to rx_mask) and makes use of it. The actual support to handle the TX mailbox in iflag1 will be added in the next patches. Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 8ce5139 commit 0ca64f0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/net/can/flexcan.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@
143143
#define FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP 0
144144
#define FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST (FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP + 1)
145145
#define FLEXCAN_IFLAG_MB(x) BIT_ULL(x)
146-
#define FLEXCAN_IFLAG2_MB(x) BIT((x) & 0x1f)
147146
#define FLEXCAN_IFLAG_RX_FIFO_OVERFLOW BIT(7)
148147
#define FLEXCAN_IFLAG_RX_FIFO_WARN BIT(6)
149148
#define FLEXCAN_IFLAG_RX_FIFO_AVAILABLE BIT(5)
@@ -279,6 +278,7 @@ struct flexcan_priv {
279278
u8 clk_src; /* clock source of CAN Protocol Engine */
280279

281280
u64 rx_mask;
281+
u64 tx_mask;
282282
u32 reg_ctrl_default;
283283

284284
struct clk *clk_ipg;
@@ -890,7 +890,8 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
890890
struct flexcan_priv *priv = netdev_priv(dev);
891891
struct flexcan_regs __iomem *regs = priv->regs;
892892
irqreturn_t handled = IRQ_NONE;
893-
u32 reg_iflag2, reg_esr;
893+
u64 reg_iflag_tx;
894+
u32 reg_esr;
894895
enum can_state last_state = priv->can.state;
895896

896897
/* reception interrupt */
@@ -924,10 +925,10 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
924925
}
925926
}
926927

927-
reg_iflag2 = priv->read(&regs->iflag2);
928+
reg_iflag_tx = (u64)priv->read(&regs->iflag2) << 32;
928929

929930
/* transmission complete interrupt */
930-
if (reg_iflag2 & FLEXCAN_IFLAG2_MB(priv->tx_mb_idx)) {
931+
if (reg_iflag_tx & priv->tx_mask) {
931932
u32 reg_ctrl = priv->read(&priv->tx_mb->can_ctrl);
932933

933934
handled = IRQ_HANDLED;
@@ -939,7 +940,7 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
939940
/* after sending a RTR frame MB is in RX mode */
940941
priv->write(FLEXCAN_MB_CODE_TX_INACTIVE,
941942
&priv->tx_mb->can_ctrl);
942-
priv->write(FLEXCAN_IFLAG2_MB(priv->tx_mb_idx), &regs->iflag2);
943+
priv->write(priv->tx_mask >> 32, &regs->iflag2);
943944
netif_wake_queue(dev);
944945
}
945946

@@ -1226,7 +1227,7 @@ static int flexcan_chip_start(struct net_device *dev)
12261227
/* enable interrupts atomically */
12271228
disable_irq(dev->irq);
12281229
priv->write(priv->reg_ctrl_default, &regs->ctrl);
1229-
reg_imask = priv->rx_mask | FLEXCAN_IFLAG_MB(priv->tx_mb_idx);
1230+
reg_imask = priv->rx_mask | priv->tx_mask;
12301231
priv->write(upper_32_bits(reg_imask), &regs->imask2);
12311232
priv->write(lower_32_bits(reg_imask), &regs->imask1);
12321233
enable_irq(dev->irq);
@@ -1296,6 +1297,7 @@ static int flexcan_open(struct net_device *dev)
12961297
flexcan_get_mb(priv, FLEXCAN_TX_MB_RESERVED_OFF_FIFO);
12971298
priv->tx_mb_idx = priv->mb_count - 1;
12981299
priv->tx_mb = flexcan_get_mb(priv, priv->tx_mb_idx);
1300+
priv->tx_mask = FLEXCAN_IFLAG_MB(priv->tx_mb_idx);
12991301

13001302
priv->offload.mailbox_read = flexcan_mailbox_read;
13011303

0 commit comments

Comments
 (0)