+++ /dev/null
-From 47c5e474bc1e1061fb037d13b5000b38967eb070 Mon Sep 17 00:00:00 2001
-From: Angelo Dureghello <angelo@kernel-space.org>
-Date: Tue, 16 Mar 2021 00:15:10 +0100
-Subject: can: flexcan: flexcan_chip_freeze(): fix chip freeze for missing bitrate
-
-From: Angelo Dureghello <angelo@kernel-space.org>
-
-commit 47c5e474bc1e1061fb037d13b5000b38967eb070 upstream.
-
-For cases when flexcan is built-in, bitrate is still not set at
-registering. So flexcan_chip_freeze() generates:
-
-[ 1.860000] *** ZERO DIVIDE *** FORMAT=4
-[ 1.860000] Current process id is 1
-[ 1.860000] BAD KERNEL TRAP: 00000000
-[ 1.860000] PC: [<402e70c8>] flexcan_chip_freeze+0x1a/0xa8
-
-To allow chip freeze, using an hardcoded timeout when bitrate is still
-not set.
-
-Fixes: ec15e27cc890 ("can: flexcan: enable RX FIFO after FRZ/HALT valid")
-Link: https://lore.kernel.org/r/20210315231510.650593-1-angelo@kernel-space.org
-Signed-off-by: Angelo Dureghello <angelo@kernel-space.org>
-[mkl: use if instead of ? operator]
-Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-Cc: Koen Vandeputte <koen.vandeputte@citymesh.com>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- drivers/net/can/flexcan.c | 8 +++++++-
- 1 file changed, 7 insertions(+), 1 deletion(-)
-
---- a/drivers/net/can/flexcan.c
-+++ b/drivers/net/can/flexcan.c
-@@ -413,9 +413,15 @@ static int flexcan_chip_disable(struct f
- static int flexcan_chip_freeze(struct flexcan_priv *priv)
- {
- struct flexcan_regs __iomem *regs = priv->regs;
-- unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate;
-+ unsigned int timeout;
-+ u32 bitrate = priv->can.bittiming.bitrate;
- u32 reg;
-
-+ if (bitrate)
-+ timeout = 1000 * 1000 * 10 / bitrate;
-+ else
-+ timeout = FLEXCAN_TIMEOUT_US / 10;
-+
- reg = flexcan_read(®s->mcr);
- reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT;
- flexcan_write(reg, ®s->mcr);
return -ETIMEDOUT;
return 0;
-@@ -416,14 +432,14 @@ static int flexcan_chip_freeze(struct fl
- unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate;
- u32 reg;
+@@ -422,14 +438,14 @@ static int flexcan_chip_freeze(struct fl
+ else
+ timeout = FLEXCAN_TIMEOUT_US / 10;
- reg = flexcan_read(®s->mcr);
+ reg = priv->read(®s->mcr);
return -ETIMEDOUT;
return 0;
-@@ -435,14 +451,14 @@ static int flexcan_chip_unfreeze(struct
+@@ -441,14 +457,14 @@ static int flexcan_chip_unfreeze(struct
unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
u32 reg;
return -ETIMEDOUT;
return 0;
-@@ -453,11 +469,11 @@ static int flexcan_chip_softreset(struct
+@@ -459,11 +475,11 @@ static int flexcan_chip_softreset(struct
struct flexcan_regs __iomem *regs = priv->regs;
unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
return -ETIMEDOUT;
return 0;
-@@ -468,7 +484,7 @@ static int __flexcan_get_berr_counter(co
+@@ -474,7 +490,7 @@ static int __flexcan_get_berr_counter(co
{
const struct flexcan_priv *priv = netdev_priv(dev);
struct flexcan_regs __iomem *regs = priv->regs;
bec->txerr = (reg >> 0) & 0xff;
bec->rxerr = (reg >> 8) & 0xff;
-@@ -524,24 +540,24 @@ static int flexcan_start_xmit(struct sk_
+@@ -530,24 +546,24 @@ static int flexcan_start_xmit(struct sk_
if (cf->can_dlc > 0) {
data = be32_to_cpup((__be32 *)&cf->data[0]);
&priv->tx_mb_reserved->can_ctrl);
return NETDEV_TX_OK;
-@@ -660,7 +676,7 @@ static unsigned int flexcan_mailbox_read
+@@ -666,7 +682,7 @@ static unsigned int flexcan_mailbox_read
u32 code;
do {
} while (reg_ctrl & FLEXCAN_MB_CODE_RX_BUSY_BIT);
/* is this MB empty? */
-@@ -675,17 +691,17 @@ static unsigned int flexcan_mailbox_read
+@@ -681,17 +697,17 @@ static unsigned int flexcan_mailbox_read
offload->dev->stats.rx_errors++;
}
} else {
if (reg_ctrl & FLEXCAN_MB_CNT_IDE)
cf->can_id = ((reg_id >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG;
else
-@@ -695,19 +711,19 @@ static unsigned int flexcan_mailbox_read
+@@ -701,19 +717,19 @@ static unsigned int flexcan_mailbox_read
cf->can_id |= CAN_RTR_FLAG;
cf->can_dlc = get_can_dlc((reg_ctrl >> 16) & 0xf);
}
return 1;
-@@ -719,8 +735,8 @@ static inline u64 flexcan_read_reg_iflag
+@@ -725,8 +741,8 @@ static inline u64 flexcan_read_reg_iflag
struct flexcan_regs __iomem *regs = priv->regs;
u32 iflag1, iflag2;
~FLEXCAN_IFLAG_MB(priv->tx_mb_idx);
return (u64)iflag2 << 32 | iflag1;
-@@ -736,7 +752,7 @@ static irqreturn_t flexcan_irq(int irq,
+@@ -742,7 +758,7 @@ static irqreturn_t flexcan_irq(int irq,
u32 reg_iflag1, reg_esr;
enum can_state last_state = priv->can.state;
/* reception interrupt */
if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
-@@ -759,7 +775,8 @@ static irqreturn_t flexcan_irq(int irq,
+@@ -765,7 +781,8 @@ static irqreturn_t flexcan_irq(int irq,
/* FIFO overflow interrupt */
if (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_OVERFLOW) {
handled = IRQ_HANDLED;
dev->stats.rx_over_errors++;
dev->stats.rx_errors++;
}
-@@ -773,18 +790,18 @@ static irqreturn_t flexcan_irq(int irq,
+@@ -779,18 +796,18 @@ static irqreturn_t flexcan_irq(int irq,
can_led_event(dev, CAN_LED_EVENT_TX);
/* after sending a RTR frame MB is in RX mode */
}
/* state change interrupt or broken error state quirk fix is enabled */
-@@ -846,7 +863,7 @@ static void flexcan_set_bittiming(struct
+@@ -852,7 +869,7 @@ static void flexcan_set_bittiming(struct
struct flexcan_regs __iomem *regs = priv->regs;
u32 reg;
reg &= ~(FLEXCAN_CTRL_PRESDIV(0xff) |
FLEXCAN_CTRL_RJW(0x3) |
FLEXCAN_CTRL_PSEG1(0x7) |
-@@ -870,11 +887,11 @@ static void flexcan_set_bittiming(struct
+@@ -876,11 +893,11 @@ static void flexcan_set_bittiming(struct
reg |= FLEXCAN_CTRL_SMP;
netdev_dbg(dev, "writing ctrl=0x%08x\n", reg);
}
/* flexcan_chip_start
-@@ -913,7 +930,7 @@ static int flexcan_chip_start(struct net
+@@ -919,7 +936,7 @@ static int flexcan_chip_start(struct net
* choose format C
* set max mailbox number
*/
reg_mcr &= ~FLEXCAN_MCR_MAXMB(0xff);
reg_mcr |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT | FLEXCAN_MCR_SUPV |
FLEXCAN_MCR_WRN_EN | FLEXCAN_MCR_SRX_DIS | FLEXCAN_MCR_IRMQ |
-@@ -927,7 +944,7 @@ static int flexcan_chip_start(struct net
+@@ -933,7 +950,7 @@ static int flexcan_chip_start(struct net
FLEXCAN_MCR_MAXMB(priv->tx_mb_idx);
}
netdev_dbg(dev, "%s: writing mcr=0x%08x", __func__, reg_mcr);
/* CTRL
*
-@@ -940,7 +957,7 @@ static int flexcan_chip_start(struct net
+@@ -946,7 +963,7 @@ static int flexcan_chip_start(struct net
* enable bus off interrupt
* (== FLEXCAN_CTRL_ERR_STATE)
*/
reg_ctrl &= ~FLEXCAN_CTRL_TSYN;
reg_ctrl |= FLEXCAN_CTRL_BOFF_REC | FLEXCAN_CTRL_LBUF |
FLEXCAN_CTRL_ERR_STATE;
-@@ -960,45 +977,45 @@ static int flexcan_chip_start(struct net
+@@ -966,45 +983,45 @@ static int flexcan_chip_start(struct net
/* leave interrupts disabled for now */
reg_ctrl &= ~FLEXCAN_CTRL_ERR_ALL;
netdev_dbg(dev, "%s: writing ctrl=0x%08x", __func__, reg_ctrl);
/* On Vybrid, disable memory error detection interrupts
* and freeze mode.
-@@ -1011,17 +1028,17 @@ static int flexcan_chip_start(struct net
+@@ -1017,17 +1034,17 @@ static int flexcan_chip_start(struct net
* and Correction of Memory Errors" to write to
* MECR register
*/
}
err = flexcan_transceiver_enable(priv);
-@@ -1037,14 +1054,14 @@ static int flexcan_chip_start(struct net
+@@ -1043,14 +1060,14 @@ static int flexcan_chip_start(struct net
/* enable interrupts atomically */
disable_irq(dev->irq);
return 0;
-@@ -1074,10 +1091,10 @@ static int __flexcan_chip_stop(struct ne
+@@ -1080,10 +1097,10 @@ static int __flexcan_chip_stop(struct ne
goto out_chip_unfreeze;
/* Disable all interrupts */
flexcan_transceiver_disable(priv);
priv->can.state = CAN_STATE_STOPPED;
-@@ -1209,9 +1226,9 @@ static int register_flexcandev(struct ne
+@@ -1215,9 +1232,9 @@ static int register_flexcandev(struct ne
err = flexcan_chip_disable(priv);
if (err)
goto out_disable_per;
err = flexcan_chip_enable(priv);
if (err)
-@@ -1223,16 +1240,16 @@ static int register_flexcandev(struct ne
+@@ -1229,16 +1246,16 @@ static int register_flexcandev(struct ne
goto out_chip_disable;
/* activate FIFO, restrict register access */
if (!(reg & FLEXCAN_MCR_FEN)) {
netdev_err(dev, "Could not enable RX FIFO, unsupported core\n");
err = -ENODEV;
-@@ -1260,8 +1277,12 @@ static void unregister_flexcandev(struct
+@@ -1266,8 +1283,12 @@ static void unregister_flexcandev(struct
static const struct of_device_id flexcan_of_match[] = {
{ .compatible = "fsl,imx6q-flexcan", .data = &fsl_imx6q_devtype_data, },
{ .compatible = "fsl,imx28-flexcan", .data = &fsl_imx28_devtype_data, },
{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, flexcan_of_match);
-@@ -1341,6 +1362,21 @@ static int flexcan_probe(struct platform
+@@ -1347,6 +1368,21 @@ static int flexcan_probe(struct platform
dev->flags |= IFF_ECHO;
priv = netdev_priv(dev);