Skip to contentSkip to conversation

flexcan: add err_irq handler for flexcan

PATCH Superseded Zhao Qiang 3 participants 7 messages Jun 23, 2014

Subsystems (3)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Zhao Qiang

author
#0 lore raw

PATCH v3 1/2 flexcan: add err_irq handler for flexcan

when flexcan is not physically linked, command 'cantest' will trigger an err_irq, add err_irq handler for it.

---
Changes for v2:
- use a space instead of tab
- use flexcan_poll_state instead of print
Changes for v3:
- return IRQ_HANDLED if err is triggered
- stop transmitted packets when there is an err_interrupt

 drivers/net/can/flexcan.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/net/can/flexcan.c +34 -1
index f425ec2..6802a25 100644
@@ -208,6 +208,7 @@ struct flexcan_priv {
 	void __iomem *base;
 	u32 reg_esr;
 	u32 reg_ctrl_default;
+	unsigned int err_irq;
 
 	struct clk *clk_ipg;
 	struct clk *clk_per;
@@ -744,6 +745,24 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static irqreturn_t flexcan_err_irq(int irq, void *dev_id)
+{
+	struct net_device *dev = dev_id;
+	struct flexcan_priv *priv = netdev_priv(dev);
+	struct flexcan_regs __iomem *regs = priv->base;
+	u32 reg_ctrl, reg_esr;
+
+	reg_esr = flexcan_read(&regs->esr);
+	reg_ctrl = flexcan_read(&regs->ctrl);
+	if (reg_esr & FLEXCAN_ESR_TX_WRN) {
+		flexcan_write(reg_esr & ~FLEXCAN_ESR_TX_WRN, &regs->esr);
+		flexcan_write(reg_ctrl & ~FLEXCAN_CTRL_ERR_MSK, &regs->ctrl);
+		netif_stop_queue(dev);
+		return IRQ_HANDLED;
+	}
+	return IRQ_NONE;
+}
+
 static void flexcan_set_bittiming(struct net_device *dev)
 {
 	const struct flexcan_priv *priv = netdev_priv(dev);
@@ -944,6 +963,15 @@ static int flexcan_open(struct net_device *dev)
 	if (err)
 		goto out_close;
 
+	if (priv->err_irq) {
+		err = request_irq(priv->err_irq, flexcan_err_irq, IRQF_SHARED,
+				  dev->name, dev);
+		if (err) {
+			free_irq(priv->err_irq, dev);
+			goto out_free_irq;
+		}
+	}
+
 	/* start chip and queuing */
 	err = flexcan_chip_start(dev);
 	if (err)
@@ -1099,7 +1127,7 @@ static int flexcan_probe(struct platform_device *pdev)
 	struct resource *mem;
 	struct clk *clk_ipg = NULL, *clk_per = NULL;
 	void __iomem *base;
-	int err, irq;
+	int err, irq, err_irq;
 	u32 clock_freq = 0;
 
 	if (pdev->dev.of_node)
@@ -1126,6 +1154,10 @@ static int flexcan_probe(struct platform_device *pdev)
 	if (irq <= 0)
 		return -ENODEV;
 
+	err_irq = platform_get_irq(pdev, 1);
+	if (err_irq <= 0)
+		err_irq = 0;
+
 	base = devm_ioremap_resource(&pdev->dev, mem);
 	if (IS_ERR(base))
 		return PTR_ERR(base);
@@ -1149,6 +1181,7 @@ static int flexcan_probe(struct platform_device *pdev)
 	dev->flags |= IFF_ECHO;
 
 	priv = netdev_priv(dev);
+	priv->err_irq = err_irq;
 	priv->can.clock.freq = clock_freq;
 	priv->can.bittiming_const = &flexcan_bittiming_const;
 	priv->can.do_set_mode = flexcan_set_mode;
Signature · 1 line
1.8.5
author
#1 lore raw

PATCH v3 2/2 flexcan: add err interrupt for p1010rdb

add err interrupt for p1010rdb into dts.

---
Changes for v2:
- add binding documentation update
Changes for v3:
- update binding documentation

 Documentation/devicetree/bindings/net/can/fsl-flexcan.txt | 15 +++++++++++++--
 arch/powerpc/boot/dts/fsl/p1010si-post.dtsi               |  6 ++++--
 2 files changed, 17 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +13 -2
index 56d6cc3..7bf377c 100644
@@ -10,7 +10,9 @@ Required properties:
   - fsl,p1010-flexcan
 
 - reg : Offset and length of the register set for this device
-- interrupts : Interrupt tuple for this device
+- interrupts : Interrupt tuple for this device.
+	The first interrupt is for FlexCAN(Message Buffer and Wake Up)
+	The second(optional) is for error
 
 Optional properties:
 
@@ -23,7 +25,16 @@ Example:
 	can@1c000 {
 		compatible = "fsl,p1010-flexcan";
 		reg = <0x1c000 0x1000>;
-		interrupts = <48 0x2>;
+		interrupts = <48 0x2 0 0>;
+		interrupt-parent = <&mpic>;
+		clock-frequency = <200000000>; // filled in by bootloader
+	};
+
+	can@1c000 {
+		compatible = "fsl,p1010-flexcan";
+		reg = <0x1c000 0x1000>;
+		interrupts = <48 0x2 0 0
+			      16 0x2 0 0>;
 		interrupt-parent = <&mpic>;
 		clock-frequency = <200000000>; // filled in by bootloader
 	};
arch/powerpc/boot/dts/fsl/p1010si-post.dtsi +4 -2
index af12ead..47125a6 100644
@@ -136,13 +136,15 @@
 	can0: can@1c000 {
 		compatible = "fsl,p1010-flexcan";
 		reg = <0x1c000 0x1000>;
-		interrupts = <48 0x2 0 0>;
+		interrupts = <48 0x2 0 0
+			      16 0x2 0 0>;
 	};
 
 	can1: can@1d000 {
 		compatible = "fsl,p1010-flexcan";
 		reg = <0x1d000 0x1000>;
-		interrupts = <61 0x2 0 0>;
+		interrupts = <61 0x2 0 0
+			      16 0x2 0 0>;
 	};
 
 	L2: l2-cache-controller@20000 {
Signature · 1 line
1.8.5
#2 lore raw
In reply to Zhao Qiang
Quoted 31 lines · Zhao Qiang

when flexcan is not physically linked, command 'cantest' will trigger an err_irq, add err_irq handler for it.

---
Changes for v2:
- use a space instead of tab
- use flexcan_poll_state instead of print
Changes for v3:
- return IRQ_HANDLED if err is triggered
- stop transmitted packets when there is an err_interrupt

 drivers/net/can/flexcan.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/net/can/flexcan.c +1 -0
index f425ec2..6802a25 100644
@@ -208,6 +208,7 @@ struct flexcan_priv {
 	void __iomem *base;
 	u32 reg_esr;
 	u32 reg_ctrl_default;
+	unsigned int err_irq;
 
 	struct clk *clk_ipg;
 	struct clk *clk_per;
@@ -744,6 +745,24 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 757

Quoted 10 lines
drivers/net/can/flexcan.c +10 -0
+static irqreturn_t flexcan_err_irq(int irq, void *dev_id)
+{
+	struct net_device *dev = dev_id;
+	struct flexcan_priv *priv = netdev_priv(dev);
+	struct flexcan_regs __iomem *regs = priv->base;
+	u32 reg_ctrl, reg_esr;
+
+	reg_esr = flexcan_read(&regs->esr);
+	reg_ctrl = flexcan_read(&regs->ctrl);
+	if (reg_esr & FLEXCAN_ESR_TX_WRN) {

When does the hardware trigger the interrupt?

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 760

Quoted 3 lines
drivers/net/can/flexcan.c +3 -0
+		flexcan_write(reg_esr & ~FLEXCAN_ESR_TX_WRN, &regs->esr);
+		flexcan_write(reg_ctrl & ~FLEXCAN_CTRL_ERR_MSK, &regs->ctrl);
+		netif_stop_queue(dev);

Why are you stopping the txqueue?

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 765

Quoted 5 lines
drivers/net/can/flexcan.c +5 -0
+		return IRQ_HANDLED;
+	}
+	return IRQ_NONE;
+}
+

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#3 lore raw
Quoted 33 lines · Marc Kleine-Budde

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void

Quoted 27 lines · Zhao Qiang

when flexcan is not physically linked, command 'cantest' will trigger an err_irq, add err_irq handler for it.

---
Changes for v2:
- use a space instead of tab
- use flexcan_poll_state instead of print Changes for v3:
- return IRQ_HANDLED if err is triggered
- stop transmitted packets when there is an err_interrupt

 drivers/net/can/flexcan.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/net/can/flexcan.c +1 -0
index f425ec2..6802a25 100644
@@ -208,6 +208,7 @@ struct flexcan_priv {
 	void __iomem *base;
 	u32 reg_esr;
 	u32 reg_ctrl_default;
+	unsigned int err_irq;
 
 	struct clk *clk_ipg;
 	struct clk *clk_per;
@@ -744,6 +745,24 @@ static irqreturn_t flexcan_irq(int irq, void

*dev_id)

Quoted 3 lines
drivers/net/can/flexcan.c +0 -0
 	return IRQ_HANDLED;
 }
 
Quoted 11 lines

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 757

Quoted 9 lines
drivers/net/can/flexcan.c +9 -0
+static irqreturn_t flexcan_err_irq(int irq, void *dev_id) {
+	struct net_device *dev = dev_id;
+	struct flexcan_priv *priv = netdev_priv(dev);
+	struct flexcan_regs __iomem *regs = priv->base;
+	u32 reg_ctrl, reg_esr;
+
+	reg_esr = flexcan_read(&regs->esr);
+	reg_ctrl = flexcan_read(&regs->ctrl);
+	if (reg_esr & FLEXCAN_ESR_TX_WRN) {

When does the hardware trigger the interrupt?

When there is no wire link between tx and rx, tx start transfer and doesn’t get the ack.

Quoted 6 lines

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 760

Quoted 4 lines
drivers/net/can/flexcan.c +3 -0
+		flexcan_write(reg_esr & ~FLEXCAN_ESR_TX_WRN, &regs->esr);
+		flexcan_write(reg_ctrl & ~FLEXCAN_CTRL_ERR_MSK, &regs->ctrl);
+		netif_stop_queue(dev);

Why are you stopping the txqueue?

There is no wire link, tx can't transfer successfully.

Quoted 14 lines

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 765

Quoted 6 lines
drivers/net/can/flexcan.c +5 -0
+		return IRQ_HANDLED;
+	}
+	return IRQ_NONE;
+}
+

Marc

--

Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#4 lore raw
Quoted 48 lines · On 06/23/2014 09:26 AM, [email protected] wrote:
Quoted 33 lines · Marc Kleine-Budde

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void

Quoted 27 lines · Zhao Qiang

when flexcan is not physically linked, command 'cantest' will trigger an err_irq, add err_irq handler for it.

---
Changes for v2:
- use a space instead of tab
- use flexcan_poll_state instead of print Changes for v3:
- return IRQ_HANDLED if err is triggered
- stop transmitted packets when there is an err_interrupt

 drivers/net/can/flexcan.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/net/can/flexcan.c +1 -0
index f425ec2..6802a25 100644
@@ -208,6 +208,7 @@ struct flexcan_priv {
 	void __iomem *base;
 	u32 reg_esr;
 	u32 reg_ctrl_default;
+	unsigned int err_irq;
 
 	struct clk *clk_ipg;
 	struct clk *clk_per;
@@ -744,6 +745,24 @@ static irqreturn_t flexcan_irq(int irq, void

*dev_id)

Quoted 3 lines
drivers/net/can/flexcan.c +0 -0
 	return IRQ_HANDLED;
 }
 
Quoted 11 lines

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 757

Quoted 9 lines
drivers/net/can/flexcan.c +9 -0
+static irqreturn_t flexcan_err_irq(int irq, void *dev_id) {
+	struct net_device *dev = dev_id;
+	struct flexcan_priv *priv = netdev_priv(dev);
+	struct flexcan_regs __iomem *regs = priv->base;
+	u32 reg_ctrl, reg_esr;
+
+	reg_esr = flexcan_read(&regs->esr);
+	reg_ctrl = flexcan_read(&regs->ctrl);
+	if (reg_esr & FLEXCAN_ESR_TX_WRN) {

When does the hardware trigger the interrupt?

Quoted 1 line

When there is no wire link between tx and rx, tx start transfer and doesn’t get the ack.

You are testing for the warning interrupt, not for the FLEXCAN_ESR_ACK_ERR (which is triggered there isn't any ACK).

Quoted 7 lines
Quoted 5 lines

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 760

Quoted 3 lines
drivers/net/can/flexcan.c +3 -0
+		flexcan_write(reg_esr & ~FLEXCAN_ESR_TX_WRN, &regs->esr);
+		flexcan_write(reg_ctrl & ~FLEXCAN_CTRL_ERR_MSK, &regs->ctrl);
+		netif_stop_queue(dev);

Why are you stopping the txqueue?

There is no wire link, tx can't transfer successfully.

You are testing for the warning interrupt, which is triggered if the error counter increases from 95 to 96. And the error counter can increase due to several reasons. No link is only one of them. If the CAN core cannot transmit new packages any more the flow control in the driver will take care.

What about calling the normal interrupt if er err_irq occurs, as this function will take care of both normal and error interrupts anyway?

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#5 lore raw
Quoted 68 lines · Marc Kleine-Budde

-----Original Message-----
From: Marc Kleine-Budde [mailto:[email protected]]
Sent: Monday, June 23, 2014 3:37 PM
To: Zhao Qiang-B45475; [email protected]; linux- [email protected]; [email protected]; Wood Scott-B07421
Subject: Re: [PATCH v3 1/2] flexcan: add err_irq handler for flexcan

Quoted 48 lines · On 06/23/2014 09:26 AM, [email protected] wrote:
Quoted 33 lines · Marc Kleine-Budde

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void

Quoted 27 lines · Zhao Qiang

when flexcan is not physically linked, command 'cantest' will trigger an err_irq, add err_irq handler for it.

---
Changes for v2:
- use a space instead of tab
- use flexcan_poll_state instead of print Changes for v3:
- return IRQ_HANDLED if err is triggered
- stop transmitted packets when there is an err_interrupt

 drivers/net/can/flexcan.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/net/can/flexcan.c +1 -0
index f425ec2..6802a25 100644
@@ -208,6 +208,7 @@ struct flexcan_priv {
 	void __iomem *base;
 	u32 reg_esr;
 	u32 reg_ctrl_default;
+	unsigned int err_irq;
 
 	struct clk *clk_ipg;
 	struct clk *clk_per;
@@ -744,6 +745,24 @@ static irqreturn_t flexcan_irq(int irq, void

*dev_id)

Quoted 3 lines
drivers/net/can/flexcan.c +0 -0
 	return IRQ_HANDLED;
 }
 
Quoted 11 lines

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 757

Quoted 9 lines
drivers/net/can/flexcan.c +9 -0
+static irqreturn_t flexcan_err_irq(int irq, void *dev_id) {
+	struct net_device *dev = dev_id;
+	struct flexcan_priv *priv = netdev_priv(dev);
+	struct flexcan_regs __iomem *regs = priv->base;
+	u32 reg_ctrl, reg_esr;
+
+	reg_esr = flexcan_read(&regs->esr);
+	reg_ctrl = flexcan_read(&regs->ctrl);
+	if (reg_esr & FLEXCAN_ESR_TX_WRN) {

When does the hardware trigger the interrupt?

Quoted 1 line

When there is no wire link between tx and rx, tx start transfer and

doesn’t get the ack.

You are testing for the warning interrupt, not for the FLEXCAN_ESR_ACK_ERR (which is triggered there isn't any ACK).

Quoted 6 lines
Quoted 5 lines

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 760

Quoted 3 lines
drivers/net/can/flexcan.c +3 -0
+		flexcan_write(reg_esr & ~FLEXCAN_ESR_TX_WRN, &regs->esr);
+		flexcan_write(reg_ctrl & ~FLEXCAN_CTRL_ERR_MSK, &regs->ctrl);
+		netif_stop_queue(dev);

Why are you stopping the txqueue?

Quoted 7 lines
Quoted 1 line

There is no wire link, tx can't transfer successfully.

You are testing for the warning interrupt, which is triggered if the error counter increases from 95 to 96. And the error counter can increase due to several reasons. No link is only one of them. If the CAN core cannot transmit new packages any more the flow control in the driver will take care.

When Tx error counter increases from 95 to 96, there must be issue for tx, So why can't I stop the txqueue?
You said that there are several reasons, would you like to take some examples?

Quoted 3 lines

What about calling the normal interrupt if er err_irq occurs, as this function will take care of both normal and error interrupts anyway?

Calling the normal interrupt doesn't work.

Quoted 8 lines

Marc

--

Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#6 lore raw

On 06/23/2014 10:15 AM, [email protected] wrote:
[...]

Quoted 20 lines
Quoted 20 lines
Quoted 7 lines
Quoted 5 lines

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 757

Quoted 3 lines
drivers/net/can/flexcan.c +3 -0
+	reg_esr = flexcan_read(&regs->esr);
+	reg_ctrl = flexcan_read(&regs->ctrl);
+	if (reg_esr & FLEXCAN_ESR_TX_WRN) {

When does the hardware trigger the interrupt?

When there is no wire link between tx and rx, tx start transfer and

doesn’t get the ack.

You are testing for the warning interrupt, not for the FLEXCAN_ESR_ACK_ERR (which is triggered there isn't any ACK).

Quoted 7 lines
Quoted 5 lines

drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 760

Quoted 3 lines
drivers/net/can/flexcan.c +3 -0
+		flexcan_write(reg_esr & ~FLEXCAN_ESR_TX_WRN, &regs->esr);
+		flexcan_write(reg_ctrl & ~FLEXCAN_CTRL_ERR_MSK, &regs->ctrl);
+		netif_stop_queue(dev);

Why are you stopping the txqueue?

There is no wire link, tx can't transfer successfully.

Quoted 8 lines
Quoted 5 lines

You are testing for the warning interrupt, which is triggered if the error counter increases from 95 to 96. And the error counter can increase due to several reasons. No link is only one of them. If the CAN core cannot transmit new packages any more the flow control in the driver will take care.

When Tx error counter increases from 95 to 96, there must be issue for tx, So why can't I stop the txqueue?

Why do you want to stop the queue? It's compliant with the CAN spec to keep sending CAN frames if the error counter increases to 96. If there isn't any problem with the CAN bus anymore, the TX error counters will decrease with every successfully transmitted CAN frame.

Quoted 1 line

You said that there are several reasons, would you like to take some examples?

See CAN Error Confinement Rules in
http://www.can-wiki.info/doku.php?id=can_faq_erors

Quoted 4 lines
Quoted 2 lines

What about calling the normal interrupt if er err_irq occurs, as this function will take care of both normal and error interrupts anyway?

Calling the normal interrupt doesn't work.

Why?

flexcan_irq() if FLEXCAN_CTRL_TWRN_MSK is set and will schedule the NAPI routine:

Quoted 3 lines
	if ((reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE) ||
	    (reg_esr & FLEXCAN_ESR_ERR_STATE) ||
	    flexcan_has_and_handle_berr(priv, reg_esr)) {

[...]

Quoted 2 lines
		napi_schedule(&priv->napi);
	}

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |