Skip to contentSkip to conversation

can: rcar_canfd: Add Classical CAN only mode support

PATCH Superseded Ramesh Shanmugasundaram 3 participants 7 messages Jun 20, 2016 – Jun 24, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 can: rcar_canfd: Add Classical CAN only mode support

The controller can operate in one of the two global modes
- CAN FD only mode (default)
- Classical CAN (CAN2.0) only mode

This patch adds support for Classical CAN only mode. It can be enabled by defining the optional device tree property "renesas,can-nofd" of this node.

Note: R-Car Gen3 h/w manual v0.51E shows bit6 of RSCFDnCFDGCFG as reserved, which is incorrect. This bit is same as RSCFDnGCFG.

---
Hi Marc, All,

This patch is based on top of can-next(tag:linux-can-next-for-4.8-20160617).

Thanks,
Ramesh.

---
 .../devicetree/bindings/net/can/rcar_canfd.txt     |   9 +-
 drivers/net/can/rcar/rcar_canfd.c                  | 355 ++++++++++++++-------
 2 files changed, 249 insertions(+), 115 deletions(-)
Documentation/devicetree/bindings/net/can/rcar_canfd.txt +8 -1
index d45182b..a343359 100644
@@ -32,6 +32,12 @@ below properties.
 - assigned-clocks: phandle of canfd clock.
 - assigned-clock-rates: maximum frequency of this clock.
 
+Optional property:
+The controller can operate in either CAN FD only mode (default) or
+Classical CAN only mode. The mode is global to both the channels. In order to
+enable the later, define the following optional property.
+ - renesas,can-nofd: puts the controller in Classical CAN only mode.
+
 Example
 -------
 
@@ -63,11 +69,12 @@ SoC common .dtsi file:
 
 Board specific .dts file:
 
-E.g. below enables Channel 1 alone in the board.
+E.g. below enables Channel 1 alone in the board in Classical CAN only mode.
 
 &canfd {
         pinctrl-0 = <&canfd1_pins>;
         pinctrl-names = "default";
+	renesas,can-nofd;
         status = "okay";
 
 	channel1 {
drivers/net/can/rcar/rcar_canfd.c +241 -114

592 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#1 lore raw

PATCH 1/1 can: rcar_canfd: Add Classical CAN only mode support

Quoted 29 lines · Ramesh Shanmugasundaram

The controller can operate in one of the two global modes
- CAN FD only mode (default)
- Classical CAN (CAN2.0) only mode

This patch adds support for Classical CAN only mode. It can be enabled by defining the optional device tree property "renesas,can-nofd" of this node.

Note: R-Car Gen3 h/w manual v0.51E shows bit6 of RSCFDnCFDGCFG as reserved, which is incorrect. This bit is same as RSCFDnGCFG.

---
Hi Marc, All,

This patch is based on top of can-next(tag:linux-can-next-for-4.8-20160617).

Thanks,
Ramesh.

---
 .../devicetree/bindings/net/can/rcar_canfd.txt     |   9 +-
 drivers/net/can/rcar/rcar_canfd.c                  | 355 ++++++++++++++-------
 2 files changed, 249 insertions(+), 115 deletions(-)
Documentation/devicetree/bindings/net/can/rcar_canfd.txt +0 -0
index d45182b..a343359 100644

Documentation/devicetree/bindings/net/can/rcar_canfd.txt below properties. · line 39

Quoted 8 lines
Documentation/devicetree/bindings/net/can/rcar_canfd.txt +5 -0
@@ -32,6 +32,12 @@ below properties.
 - assigned-clocks: phandle of canfd clock.
 - assigned-clock-rates: maximum frequency of this clock.
 
+Optional property:
+The controller can operate in either CAN FD only mode (default) or
+Classical CAN only mode. The mode is global to both the channels. In order to
+enable the later, define the following optional property.
+ - renesas,can-nofd: puts the controller in Classical CAN only mode.

renesas,no-can-fd would be a bit more readable.

Quoted 5 lines
Documentation/devicetree/bindings/net/can/rcar_canfd.txt +1 -0
+
 Example
 -------
 

Documentation/devicetree/bindings/net/can/rcar_canfd.txt SoC common .dtsi file: · line 77

Quoted 10 lines
Documentation/devicetree/bindings/net/can/rcar_canfd.txt +2 -1
@@ -63,11 +69,12 @@ SoC common .dtsi file:
 
 Board specific .dts file:
 
-E.g. below enables Channel 1 alone in the board.
+E.g. below enables Channel 1 alone in the board in Classical CAN only mode.
 
 &canfd {
         pinctrl-0 = <&canfd1_pins>;
         pinctrl-names = "default";
+	renesas,can-nofd;

Now we have a mixture of tabs and spaces.

Quoted 3 lines
Documentation/devicetree/bindings/net/can/rcar_canfd.txt +0 -0
         status = "okay";
 
 	channel1 {
#2 lore raw

v2 cover can: rcar_canfd: Add Classical CAN & lower state transition support

In reply to Ramesh Shanmugasundaram

This patch is based on latest can-next(tag:linux-can-next-for-4.8-20160617).

Changes since v1:
- property named changed from "can-nofd" to "no-can-fd" (Rob H)
- added new patch(0002) that support lower state transitions (Wolfgang G)
(http://marc.info/?l=linux-can&m=146650325116971&w=2)

Ramesh Shanmugasundaram (2):
can: rcar_canfd: Add Classical CAN only mode support
can: rcar_canfd: Add back-to-error-active support

 .../devicetree/bindings/net/can/rcar_canfd.txt     |  21 +-
 drivers/net/can/rcar/rcar_canfd.c                  | 429 ++++++++++++++-------
 2 files changed, 310 insertions(+), 140 deletions(-)
Signature · 1 line
1.9.1
#3 lore raw

PATCH v2 1/2 can: rcar_canfd: Add Classical CAN only mode support

The controller can operate in one of the two global modes
- CAN FD only mode (default)
- Classical CAN (CAN2.0) only mode

This patch adds support for Classical CAN only mode. It can be enabled by defining the optional device tree property "renesas,no-can-fd" of this node.

Note: R-Car Gen3 h/w manual v0.51E shows bit6 of RSCFDnCFDGCFG as reserved, which is incorrect. This bit is same as RSCFDnGCFG.

---
 .../devicetree/bindings/net/can/rcar_canfd.txt     |  21 +-
 drivers/net/can/rcar/rcar_canfd.c                  | 355 ++++++++++++++-------
 2 files changed, 255 insertions(+), 121 deletions(-)
Documentation/devicetree/bindings/net/can/rcar_canfd.txt +14 -7
index d45182b..22a6f10 100644
@@ -32,6 +32,12 @@ below properties.
 - assigned-clocks: phandle of canfd clock.
 - assigned-clock-rates: maximum frequency of this clock.
 
+Optional property:
+The controller can operate in either CAN FD only mode (default) or
+Classical CAN only mode. The mode is global to both the channels. In order to
+enable the later, define the following optional property.
+ - renesas,no-can-fd: puts the controller in Classical CAN only mode.
+
 Example
 -------
 
@@ -63,12 +69,13 @@ SoC common .dtsi file:
 
 Board specific .dts file:
 
-E.g. below enables Channel 1 alone in the board.
+E.g. below enables Channel 1 alone in the board in Classical CAN only mode.
 
 &canfd {
-        pinctrl-0 = <&canfd1_pins>;
-        pinctrl-names = "default";
-        status = "okay";
+	pinctrl-0 = <&canfd1_pins>;
+	pinctrl-names = "default";
+	renesas,no-can-fd;
+	status = "okay";
 
 	channel1 {
 		status = "okay";
@@ -79,9 +86,9 @@ E.g. below enables Channel 0 alone in the board using External clock
 as fCAN clock.
 
 &canfd {
-        pinctrl-0 = <&canfd0_pins &can_clk_pins>;
-        pinctrl-names = "default";
-        status = "okay";
+	pinctrl-0 = <&canfd0_pins &can_clk_pins>;
+	pinctrl-names = "default";
+	status = "okay";
 
 	channel0 {
 		status = "okay";
drivers/net/can/rcar/rcar_canfd.c +241 -114

592 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#4 lore raw

PATCH v2 1/2 can: rcar_canfd: Add Classical CAN only mode support

Quoted 8 lines · Ramesh Shanmugasundaram

The controller can operate in one of the two global modes
- CAN FD only mode (default)
- Classical CAN (CAN2.0) only mode

This patch adds support for Classical CAN only mode. It can be enabled by defining the optional device tree property "renesas,no-can-fd" of this node.

Quoted 6 lines

Note: R-Car Gen3 h/w manual v0.51E shows bit6 of RSCFDnCFDGCFG as reserved, which is incorrect. This bit is same as RSCFDnGCFG.

---
 .../devicetree/bindings/net/can/rcar_canfd.txt     |  21 +-
Quoted 2 lines
 drivers/net/can/rcar/rcar_canfd.c                  | 355 ++++++++++++++-------
 2 files changed, 255 insertions(+), 121 deletions(-)
#5 lore raw

PATCH v2 2/2 can: rcar_canfd: Add back-to-error-active support

In reply to Ramesh Shanmugasundaram

As per Wolfgang G, all new drivers should support decreasing state transition(back-to-error-active). This patch adds this support.

This driver configures the controller to halt on bus-off entry. Hence, when in error states less than bus off state, the TEC/REC counters are checked for lower state transition eligibility and action.

---
 drivers/net/can/rcar/rcar_canfd.c | 76 ++++++++++++++++++++++++++++-----------
 1 file changed, 56 insertions(+), 20 deletions(-)
drivers/net/can/rcar/rcar_canfd.c +56 -20
index 6bcc474..43cdd55 100644
@@ -917,16 +917,17 @@ static void rcar_canfd_global_error(struct net_device *ndev)
 	rcar_canfd_write(priv->base, RCANFD_GERFL, 0);
 }
 
-static void rcar_canfd_error(struct net_device *ndev)
+static void rcar_canfd_error(struct net_device *ndev, u32 cerfl,
+			     u16 txerr, u16 rxerr)
 {
 	struct rcar_canfd_channel *priv = netdev_priv(ndev);
 	struct net_device_stats *stats = &ndev->stats;
 	struct can_frame *cf;
 	struct sk_buff *skb;
-	u32 cerfl, csts;
-	u32 txerr = 0, rxerr = 0;
 	u32 ch = priv->channel;
 
+	netdev_dbg(ndev, "ch erfl %x txerr %u rxerr %u\n", cerfl, txerr, rxerr);
+
 	/* Propagate the error condition to the CAN stack */
 	skb = alloc_can_err_skb(ndev, &cf);
 	if (!skb) {
@@ -934,15 +935,7 @@ static void rcar_canfd_error(struct net_device *ndev)
 		return;
 	}
 
-	/* Channel error interrupt */
-	cerfl = rcar_canfd_read(priv->base, RCANFD_CERFL(ch));
-	csts = rcar_canfd_read(priv->base, RCANFD_CSTS(ch));
-	txerr = RCANFD_CSTS_TECCNT(csts);
-	rxerr = RCANFD_CSTS_RECCNT(csts);
-
-	netdev_dbg(ndev, "ch erfl %x sts %x txerr %u rxerr %u\n",
-		   cerfl, csts, txerr, rxerr);
-
+	/* Channel error interrupts */
 	if (cerfl & RCANFD_CERFL_BEF) {
 		netdev_dbg(ndev, "Bus error\n");
 		cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_PROT;
@@ -1032,8 +1025,9 @@ static void rcar_canfd_error(struct net_device *ndev)
 		cf->data[2] |= CAN_ERR_PROT_OVERLOAD;
 	}
 
-	/* Clear all channel error interrupts */
-	rcar_canfd_write(priv->base, RCANFD_CERFL(ch), 0);
+	/* Clear channel error interrupts that are handled */
+	rcar_canfd_write(priv->base, RCANFD_CERFL(ch),
+			 RCANFD_CERFL_ERR(~cerfl));
 	stats->rx_packets++;
 	stats->rx_bytes += cf->can_dlc;
 	netif_rx(skb);
@@ -1098,12 +1092,12 @@ static irqreturn_t rcar_canfd_global_interrupt(int irq, void *dev_id)
 
 		/* Global error interrupts */
 		gerfl = rcar_canfd_read(priv->base, RCANFD_GERFL);
-		if (RCANFD_GERFL_ERR(gpriv, gerfl))
+		if (unlikely(RCANFD_GERFL_ERR(gpriv, gerfl)))
 			rcar_canfd_global_error(ndev);
 
 		/* Handle Rx interrupts */
 		sts = rcar_canfd_read(priv->base, RCANFD_RFSTS(ridx));
-		if (sts & RCANFD_RFSTS_RFIF) {
+		if (likely(sts & RCANFD_RFSTS_RFIF)) {
 			if (napi_schedule_prep(&priv->napi)) {
 				/* Disable Rx FIFO interrupts */
 				rcar_canfd_clear_bit(priv->base,
@@ -1116,12 +1110,46 @@ static irqreturn_t rcar_canfd_global_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static void rcar_canfd_state_change(struct net_device *ndev,
+				    u16 txerr, u16 rxerr)
+{
+	struct rcar_canfd_channel *priv = netdev_priv(ndev);
+	struct net_device_stats *stats = &ndev->stats;
+	enum can_state rx_state, tx_state, state = priv->can.state;
+	struct can_frame *cf;
+	struct sk_buff *skb;
+
+	/* Handle transition from error to normal states */
+	if (txerr < 96 && rxerr < 96)
+		state = CAN_STATE_ERROR_ACTIVE;
+	else if (txerr < 128 && rxerr < 128)
+		state = CAN_STATE_ERROR_WARNING;
+
+	if (state != priv->can.state) {
+		netdev_dbg(ndev, "state: new %d, old %d: txerr %u, rxerr %u\n",
+			   state, priv->can.state, txerr, rxerr);
+		skb = alloc_can_err_skb(ndev, &cf);
+		if (!skb) {
+			stats->rx_dropped++;
+			return;
+		}
+		tx_state = txerr >= rxerr ? state : 0;
+		rx_state = txerr <= rxerr ? state : 0;
+
+		can_change_state(ndev, cf, tx_state, rx_state);
+		stats->rx_packets++;
+		stats->rx_bytes += cf->can_dlc;
+		netif_rx(skb);
+	}
+}
+
 static irqreturn_t rcar_canfd_channel_interrupt(int irq, void *dev_id)
 {
 	struct rcar_canfd_global *gpriv = dev_id;
 	struct net_device *ndev;
 	struct rcar_canfd_channel *priv;
-	u32 sts, cerfl, ch;
+	u32 sts, ch, cerfl;
+	u16 txerr, rxerr;
 
 	/* Common FIFO is a per channel resource */
 	for_each_set_bit(ch, &gpriv->channels_mask, RCANFD_NUM_CHANNELS) {
@@ -1130,13 +1158,21 @@ static irqreturn_t rcar_canfd_channel_interrupt(int irq, void *dev_id)
 
 		/* Channel error interrupts */
 		cerfl = rcar_canfd_read(priv->base, RCANFD_CERFL(ch));
-		if (RCANFD_CERFL_ERR(cerfl))
-			rcar_canfd_error(ndev);
+		sts = rcar_canfd_read(priv->base, RCANFD_CSTS(ch));
+		txerr = RCANFD_CSTS_TECCNT(sts);
+		rxerr = RCANFD_CSTS_RECCNT(sts);
+		if (unlikely(RCANFD_CERFL_ERR(cerfl)))
+			rcar_canfd_error(ndev, cerfl, txerr, rxerr);
+
+		/* Handle state change to lower states */
+		if (unlikely((priv->can.state != CAN_STATE_ERROR_ACTIVE) &&
+			     (priv->can.state != CAN_STATE_BUS_OFF)))
+			rcar_canfd_state_change(ndev, txerr, rxerr);
 
 		/* Handle Tx interrupts */
 		sts = rcar_canfd_read(priv->base,
 				      RCANFD_CFSTS(ch, RCANFD_CFFIFO_IDX));
-		if (sts & RCANFD_CFSTS_CFTXIF)
+		if (likely(sts & RCANFD_CFSTS_CFTXIF))
 			rcar_canfd_tx_done(ndev);
 	}
 	return IRQ_HANDLED;
Signature · 1 line
1.9.1
maintainer Applied
#6 lore raw

v2 cover can: rcar_canfd: Add Classical CAN & lower state transition support

In reply to Ramesh Shanmugasundaram
Quoted 7 lines · Ramesh Shanmugasundaram

This patch is based on latest can-next(tag:linux-can-next-for-4.8-20160617).

Changes since v1:
- property named changed from "can-nofd" to "no-can-fd" (Rob H)
- added new patch(0002) that support lower state transitions (Wolfgang G)
(http://marc.info/?l=linux-can&m=146650325116971&w=2)

Quoted 7 lines

Ramesh Shanmugasundaram (2):
can: rcar_canfd: Add Classical CAN only mode support
can: rcar_canfd: Add back-to-error-active support

 .../devicetree/bindings/net/can/rcar_canfd.txt     |  21 +-
 drivers/net/can/rcar/rcar_canfd.c                  | 429 ++++++++++++++-------
 2 files changed, 310 insertions(+), 140 deletions(-)

Applied to can-next.

Tnx,
Marc

Signature · 12 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   |

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160622/1f4270e1/attachment.sig>