CAN: Add Flexcan CAN controller driver
Subsystems (3)
PATCH v3 1/1 CAN: Add Flexcan CAN controller driver
And another go...
Sascha
Quoted 1 line
From
9f6f6fb67d57d082e056dec8121f1423c1b4fa0bMon Sep 17 00:00:00 2001
From: Sascha Hauer <[email protected]>
Date: Tue, 21 Jul 2009 10:47:19 +0200
Subject: [PATCH] CAN: Add Flexcan CAN driver
This core is found on some Freescale SoCs and also some Coldfire SoCs. Support for Coldfire is missing though at the moment as they have an older revision of the core which does not have RX FIFO support.
V3: integrated comments from Oliver Hartkopp
V2: integrated comments from Wolfgang Grandegger
--- drivers/net/can/Kconfig | 6 + drivers/net/can/Makefile | 1 + drivers/net/can/flexcan.c | 719 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 726 insertions(+), 0 deletions(-) create mode 100644 drivers/net/can/flexcan.c
drivers/net/can/Kconfig +6 -0
@@ -74,6 +74,12 @@ config CAN_KVASER_PCI This driver is for the the PCIcanx and PCIcan cards (1, 2 or 4 channel) from Kvaser (http://www.kvaser.com). +config CAN_FLEXCAN + tristate "Support for Freescale FLEXCAN based chips" + depends on CAN_DEV + ---help--- + Say Y here if you want to support for Freescale FlexCAN. + config CAN_DEBUG_DEVICES bool "CAN devices debugging messages" depends on CAN
drivers/net/can/Makefile +1 -0
@@ -8,5 +8,6 @@ obj-$(CONFIG_CAN_DEV) += can-dev.o can-dev-y := dev.o obj-$(CONFIG_CAN_SJA1000) += sja1000/ +obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
drivers/net/can/flexcan.c new file +719 -0
719 lines not on this page · raw message
Signature · 7 lines
1.6.3.3 -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 15 lines · Sascha Hauer
And another go...
Sascha
From
9f6f6fb67d57d082e056dec8121f1423c1b4fa0bMon Sep 17 00:00:00 2001
From: Sascha Hauer <[email protected]>
Date: Tue, 21 Jul 2009 10:47:19 +0200
Subject: [PATCH] CAN: Add Flexcan CAN driverThis core is found on some Freescale SoCs and also some Coldfire SoCs. Support for Coldfire is missing though at the moment as they have an older revision of the core which does not have RX FIFO support.
Quoted 4 lines
V3: integrated comments from Oliver Hartkopp
V2: integrated comments from Wolfgang GrandeggerSigned-off-by Sascha Hauer <[email protected]>
Thanks Sascha!
The register access and the transition between the struct can_frame became much clearer now.
Looks good to me.
Best regards,
Oliver
Quoted 59 lines · Sascha Hauer
And another go...
Sascha
Quoted 1 line
From
9f6f6fb67d57d082e056dec8121f1423c1b4fa0bMon Sep 17 00:00:00 2001From: Sascha Hauer <[email protected]>
Date: Tue, 21 Jul 2009 10:47:19 +0200
Subject: [PATCH] CAN: Add Flexcan CAN driverThis core is found on some Freescale SoCs and also some Coldfire SoCs. Support for Coldfire is missing though at the moment as they have an older revision of the core which does not have RX FIFO support.
V3: integrated comments from Oliver Hartkopp
V2: integrated comments from Wolfgang GrandeggerSigned-off-by Sascha Hauer <[email protected]>--- drivers/net/can/Kconfig | 6 + drivers/net/can/Makefile | 1 + drivers/net/can/flexcan.c | 719 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 726 insertions(+), 0 deletions(-) create mode 100644 drivers/net/can/flexcan.cdrivers/net/can/Kconfig +6
-0@@ -74,6 +74,12 @@ config CAN_KVASER_PCI This driver is for the the PCIcanx and PCIcan cards (1, 2 or 4 channel) from Kvaser (http://www.kvaser.com). +config CAN_FLEXCAN + tristate "Support for Freescale FLEXCAN based chips" + depends on CAN_DEV + ---help--- + Say Y here if you want to support for Freescale FlexCAN. + config CAN_DEBUG_DEVICES bool "CAN devices debugging messages" depends on CANdrivers/net/can/Makefile +1
-0@@ -8,5 +8,6 @@ obj-$(CONFIG_CAN_DEV) += can-dev.o can-dev-y := dev.o obj-$(CONFIG_CAN_SJA1000) += sja1000/ +obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUGdrivers/net/can/flexcan.c new file +0
-0
[...]
Quoted 22 lines
drivers/net/can/flexcan.c new file +22
-0+static void flexcan_error (struct net_device *ndev,u32 stat) +{ +struct can_frame *cf; +struct sk_buff *skb; +struct flexcan_priv *priv =netdev_priv (ndev); +struct net_device_stats *stats = &ndev->stats; +enum can_state state = priv->can.state; +int error_warning =0 , rx_errors =0 , tx_errors =0 ; + + skb =dev_alloc_skb (sizeof (struct can_frame )); +if (!skb) +return ; + + skb->dev = ndev; + skb->protocol =__constant_htons (ETH_P_CAN ); + skb->ip_summed =CHECKSUM_UNNECESSARY ; + + cf = (struct can_frame *)skb_put (skb,sizeof (*cf)); +memset (cf,0 ,sizeof (*cf)); + + cf->can_id =CAN_ERR_FLAG ; + cf->can_dlc =CAN_ERR_DLC ;
drivers/net/can/flexcan.c line 307
Quoted 10 lines
drivers/net/can/flexcan.c new file +10
-0+ +if (stat &ERRSTAT_RWRNINT ) { + error_warning =1 ; + cf->data[1 ] |=CAN_ERR_CRTL_RX_WARNING ; + } + +if (stat &ERRSTAT_TWRNINT ) { + error_warning =1 ; + cf->data[1 ] |=CAN_ERR_CRTL_TX_WARNING ; + }
What is the meaning of this error warning interrupt? It does *not* change the state.
drivers/net/can/flexcan.c line 319
Quoted 11 lines
drivers/net/can/flexcan.c new file +11
-0+switch ((stat >>4 ) &0x3 ) { +case 0 : + state =CAN_STATE_ERROR_ACTIVE ; +break ; +case 1 : + state =CAN_STATE_ERROR_PASSIVE ; +break ; +default : + state =CAN_STATE_BUS_OFF ; +break ; + }
I'm still not happy with the error message generation. If a state change to error passive happens, it should be signaled to the user. Here my ideas:
if (state != priv->can.state) {
if (state == CAN_STATE_ERROR_WARNING) {
cf->data[1] |= CAN_ERR_CRTL_RX_WARNING;
priv->can.can_stats.error_warning++;
} else if (state == CAN_STATE_ERROR_PASSIVE) {
cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
priv->can.can_stats.error_passive++;
}It might have missed something, though.
Wolfgang.
Quoted 88 lines · Wolfgang Grandegger
Quoted 59 lines · Sascha Hauer
And another go...
Sascha
Quoted 1 line
From
9f6f6fb67d57d082e056dec8121f1423c1b4fa0bMon Sep 17 00:00:00 2001From: Sascha Hauer <[email protected]>
Date: Tue, 21 Jul 2009 10:47:19 +0200
Subject: [PATCH] CAN: Add Flexcan CAN driverThis core is found on some Freescale SoCs and also some Coldfire SoCs. Support for Coldfire is missing though at the moment as they have an older revision of the core which does not have RX FIFO support.
V3: integrated comments from Oliver Hartkopp
V2: integrated comments from Wolfgang GrandeggerSigned-off-by Sascha Hauer <[email protected]>--- drivers/net/can/Kconfig | 6 + drivers/net/can/Makefile | 1 + drivers/net/can/flexcan.c | 719 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 726 insertions(+), 0 deletions(-) create mode 100644 drivers/net/can/flexcan.cdrivers/net/can/Kconfig +6
-0@@ -74,6 +74,12 @@ config CAN_KVASER_PCI This driver is for the the PCIcanx and PCIcan cards (1, 2 or 4 channel) from Kvaser (http://www.kvaser.com). +config CAN_FLEXCAN + tristate "Support for Freescale FLEXCAN based chips" + depends on CAN_DEV + ---help--- + Say Y here if you want to support for Freescale FlexCAN. + config CAN_DEBUG_DEVICES bool "CAN devices debugging messages" depends on CANdrivers/net/can/Makefile +1
-0@@ -8,5 +8,6 @@ obj-$(CONFIG_CAN_DEV) += can-dev.o can-dev-y := dev.o obj-$(CONFIG_CAN_SJA1000) += sja1000/ +obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUGdrivers/net/can/flexcan.c new file +0
-0[...]
Quoted 27 lines
drivers/net/can/flexcan.c new file +27
-0+static void flexcan_error (struct net_device *ndev,u32 stat) +{ +struct can_frame *cf; +struct sk_buff *skb; +struct flexcan_priv *priv =netdev_priv (ndev); +struct net_device_stats *stats = &ndev->stats; +enum can_state state = priv->can.state; +int error_warning =0 , rx_errors =0 , tx_errors =0 ; + + skb =dev_alloc_skb (sizeof (struct can_frame )); +if (!skb) +return ; + + skb->dev = ndev; + skb->protocol =__constant_htons (ETH_P_CAN ); + skb->ip_summed =CHECKSUM_UNNECESSARY ; + + cf = (struct can_frame *)skb_put (skb,sizeof (*cf)); +memset (cf,0 ,sizeof (*cf)); + + cf->can_id =CAN_ERR_FLAG ; + cf->can_dlc =CAN_ERR_DLC ; + +if (stat &ERRSTAT_RWRNINT ) { + error_warning =1 ; + cf->data[1 ] |=CAN_ERR_CRTL_RX_WARNING ; + }
Quoted 8 lines
drivers/net/can/flexcan.c line 307
Quoted 5 lines
drivers/net/can/flexcan.c new file +5
-0+ +if (stat &ERRSTAT_TWRNINT ) { + error_warning =1 ; + cf->data[1 ] |=CAN_ERR_CRTL_TX_WARNING ; + }What is the meaning of this error warning interrupt? It does *not* change the state.
This TWRNINT means that the Tx error counter has transitioned from < 96 to >= 96 (analog the RWRNINT for the Rx error counter). Unfortunately the state bits handled below do not reflect this error warning state.
So this interrupt signals us that we have been in error warning state once but we have no possibility to detect if we are still in error warning state. I don't know how to handle this correctly. I could disable this interrupt and ignore it completely.
Quoted 25 lines
drivers/net/can/flexcan.c line 319
Quoted 12 lines
drivers/net/can/flexcan.c new file +11
-0+switch ((stat >>4 ) &0x3 ) { +case 0 : + state =CAN_STATE_ERROR_ACTIVE ; +break ; +case 1 : + state =CAN_STATE_ERROR_PASSIVE ; +break ; +default : + state =CAN_STATE_BUS_OFF ; +break ; + }I'm still not happy with the error message generation. If a state change to error passive happens, it should be signaled to the user. Here my ideas:
if (state != priv->can.state) { if (state == CAN_STATE_ERROR_WARNING) { cf->data[1] |= CAN_ERR_CRTL_RX_WARNING; priv->can.can_stats.error_warning++; } else if (state == CAN_STATE_ERROR_PASSIVE) { cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE; priv->can.can_stats.error_passive++; }
Quoted 1 line
It might have missed something, though.
Sorry, I missed that from your previous mail. As we can't properly detect ERROR_WARNING state this would reduce to:
if (state != priv->can.state && state == CAN_STATE_ERROR_WARNING) {
cf->data[1] |= CAN_ERR_CRTL_RX_WARNING;
priv->can.can_stats.error_warning++;
}Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 131 lines · Sascha Hauer
Quoted 87 lines · Wolfgang Grandegger
Quoted 59 lines · Sascha Hauer
And another go...
Sascha
Quoted 1 line
From
9f6f6fb67d57d082e056dec8121f1423c1b4fa0bMon Sep 17 00:00:00 2001From: Sascha Hauer <[email protected]>
Date: Tue, 21 Jul 2009 10:47:19 +0200
Subject: [PATCH] CAN: Add Flexcan CAN driverThis core is found on some Freescale SoCs and also some Coldfire SoCs. Support for Coldfire is missing though at the moment as they have an older revision of the core which does not have RX FIFO support.
V3: integrated comments from Oliver Hartkopp
V2: integrated comments from Wolfgang GrandeggerSigned-off-by Sascha Hauer <[email protected]>--- drivers/net/can/Kconfig | 6 + drivers/net/can/Makefile | 1 + drivers/net/can/flexcan.c | 719 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 726 insertions(+), 0 deletions(-) create mode 100644 drivers/net/can/flexcan.cdrivers/net/can/Kconfig +6
-0@@ -74,6 +74,12 @@ config CAN_KVASER_PCI This driver is for the the PCIcanx and PCIcan cards (1, 2 or 4 channel) from Kvaser (http://www.kvaser.com). +config CAN_FLEXCAN + tristate "Support for Freescale FLEXCAN based chips" + depends on CAN_DEV + ---help--- + Say Y here if you want to support for Freescale FlexCAN. + config CAN_DEBUG_DEVICES bool "CAN devices debugging messages" depends on CANdrivers/net/can/Makefile +1
-0@@ -8,5 +8,6 @@ obj-$(CONFIG_CAN_DEV) += can-dev.o can-dev-y := dev.o obj-$(CONFIG_CAN_SJA1000) += sja1000/ +obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUGdrivers/net/can/flexcan.c new file +0
-0[...]
Quoted 26 lines
drivers/net/can/flexcan.c new file +26
-0+static void flexcan_error (struct net_device *ndev,u32 stat) +{ +struct can_frame *cf; +struct sk_buff *skb; +struct flexcan_priv *priv =netdev_priv (ndev); +struct net_device_stats *stats = &ndev->stats; +enum can_state state = priv->can.state; +int error_warning =0 , rx_errors =0 , tx_errors =0 ; + + skb =dev_alloc_skb (sizeof (struct can_frame )); +if (!skb) +return ; + + skb->dev = ndev; + skb->protocol =__constant_htons (ETH_P_CAN ); + skb->ip_summed =CHECKSUM_UNNECESSARY ; + + cf = (struct can_frame *)skb_put (skb,sizeof (*cf)); +memset (cf,0 ,sizeof (*cf)); + + cf->can_id =CAN_ERR_FLAG ; + cf->can_dlc =CAN_ERR_DLC ; + +if (stat &ERRSTAT_RWRNINT ) { + error_warning =1 ; + cf->data[1 ] |=CAN_ERR_CRTL_RX_WARNING ;Quoted 8 lines
drivers/net/can/flexcan.c line 307
Quoted 6 lines
drivers/net/can/flexcan.c new file +6
-0+ } + +if (stat &ERRSTAT_TWRNINT ) { + error_warning =1 ; + cf->data[1 ] |=CAN_ERR_CRTL_TX_WARNING ; + }What is the meaning of this error warning interrupt? It does *not* change the state.
This TWRNINT means that the Tx error counter has transitioned from < 96 to >= 96 (analog the RWRNINT for the Rx error counter). Unfortunately the state bits handled below do not reflect this error warning state.
So this interrupt signals us that we have been in error warning state once but we have no possibility to detect if we are still in error warning state. I don't know how to handle this correctly. I could disable this interrupt and ignore it completely.
Quoted 23 lines
drivers/net/can/flexcan.c line 319
Quoted 11 lines
drivers/net/can/flexcan.c new file +11
-0+switch ((stat >>4 ) &0x3 ) { +case 0 : + state =CAN_STATE_ERROR_ACTIVE ; +break ; +case 1 : + state =CAN_STATE_ERROR_PASSIVE ; +break ; +default : + state =CAN_STATE_BUS_OFF ; +break ; + }I'm still not happy with the error message generation. If a state change to error passive happens, it should be signaled to the user. Here my ideas:
if (state != priv->can.state) { if (state == CAN_STATE_ERROR_WARNING) { cf->data[1] |= CAN_ERR_CRTL_RX_WARNING; priv->can.can_stats.error_warning++; } else if (state == CAN_STATE_ERROR_PASSIVE) { cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE; priv->can.can_stats.error_passive++; }Quoted 1 line
It might have missed something, though.
Quoted 7 lines
Sorry, I missed that from your previous mail. As we can't properly detect
ERROR_WARNINGstate this would reduce to:if (state != priv->can.state && state == CAN_STATE_ERROR_WARNING) { cf->data[1] |= CAN_ERR_CRTL_RX_WARNING; priv->can.can_stats.error_warning++; }
Why you can't detect error warning? When the [RT]WRNINT comes, the error waning state has entered. By looking to the manual, the state changes to error warning and bus-off are directly signaled via interrupt. A change to error passive might be visible when bus error ints occurs. You could add some dev_dbg's to the "if (stat & ERRSTAT_[RT]WRNINT)" and "switch" blocks above and check with sending a message with no cable connected.
Wolfgang.
Quoted 140 lines · Wolfgang Grandegger
Quoted 131 lines · Sascha Hauer
Quoted 87 lines · Wolfgang Grandegger
Quoted 59 lines · Sascha Hauer
And another go...
Sascha
Quoted 1 line
From
9f6f6fb67d57d082e056dec8121f1423c1b4fa0bMon Sep 17 00:00:00 2001From: Sascha Hauer <[email protected]>
Date: Tue, 21 Jul 2009 10:47:19 +0200
Subject: [PATCH] CAN: Add Flexcan CAN driverThis core is found on some Freescale SoCs and also some Coldfire SoCs. Support for Coldfire is missing though at the moment as they have an older revision of the core which does not have RX FIFO support.
V3: integrated comments from Oliver Hartkopp
V2: integrated comments from Wolfgang GrandeggerSigned-off-by Sascha Hauer <[email protected]>--- drivers/net/can/Kconfig | 6 + drivers/net/can/Makefile | 1 + drivers/net/can/flexcan.c | 719 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 726 insertions(+), 0 deletions(-) create mode 100644 drivers/net/can/flexcan.cdrivers/net/can/Kconfig +6
-0@@ -74,6 +74,12 @@ config CAN_KVASER_PCI This driver is for the the PCIcanx and PCIcan cards (1, 2 or 4 channel) from Kvaser (http://www.kvaser.com). +config CAN_FLEXCAN + tristate "Support for Freescale FLEXCAN based chips" + depends on CAN_DEV + ---help--- + Say Y here if you want to support for Freescale FlexCAN. + config CAN_DEBUG_DEVICES bool "CAN devices debugging messages" depends on CANdrivers/net/can/Makefile +1
-0@@ -8,5 +8,6 @@ obj-$(CONFIG_CAN_DEV) += can-dev.o can-dev-y := dev.o obj-$(CONFIG_CAN_SJA1000) += sja1000/ +obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUGdrivers/net/can/flexcan.c new file +0
-0[...]
Quoted 26 lines
drivers/net/can/flexcan.c new file +26
-0+static void flexcan_error (struct net_device *ndev,u32 stat) +{ +struct can_frame *cf; +struct sk_buff *skb; +struct flexcan_priv *priv =netdev_priv (ndev); +struct net_device_stats *stats = &ndev->stats; +enum can_state state = priv->can.state; +int error_warning =0 , rx_errors =0 , tx_errors =0 ; + + skb =dev_alloc_skb (sizeof (struct can_frame )); +if (!skb) +return ; + + skb->dev = ndev; + skb->protocol =__constant_htons (ETH_P_CAN ); + skb->ip_summed =CHECKSUM_UNNECESSARY ; + + cf = (struct can_frame *)skb_put (skb,sizeof (*cf)); +memset (cf,0 ,sizeof (*cf)); + + cf->can_id =CAN_ERR_FLAG ; + cf->can_dlc =CAN_ERR_DLC ; + +if (stat &ERRSTAT_RWRNINT ) { + error_warning =1 ; + cf->data[1 ] |=CAN_ERR_CRTL_RX_WARNING ;Quoted 8 lines
drivers/net/can/flexcan.c line 307
Quoted 6 lines
drivers/net/can/flexcan.c new file +6
-0+ } + +if (stat &ERRSTAT_TWRNINT ) { + error_warning =1 ; + cf->data[1 ] |=CAN_ERR_CRTL_TX_WARNING ; + }What is the meaning of this error warning interrupt? It does *not* change the state.
This TWRNINT means that the Tx error counter has transitioned from < 96 to >= 96 (analog the RWRNINT for the Rx error counter). Unfortunately the state bits handled below do not reflect this error warning state.
So this interrupt signals us that we have been in error warning state once but we have no possibility to detect if we are still in error warning state. I don't know how to handle this correctly. I could disable this interrupt and ignore it completely.
Quoted 23 lines
drivers/net/can/flexcan.c line 319
Quoted 11 lines
drivers/net/can/flexcan.c new file +11
-0+switch ((stat >>4 ) &0x3 ) { +case 0 : + state =CAN_STATE_ERROR_ACTIVE ; +break ; +case 1 : + state =CAN_STATE_ERROR_PASSIVE ; +break ; +default : + state =CAN_STATE_BUS_OFF ; +break ; + }I'm still not happy with the error message generation. If a state change to error passive happens, it should be signaled to the user. Here my ideas:
if (state != priv->can.state) { if (state == CAN_STATE_ERROR_WARNING) { cf->data[1] |= CAN_ERR_CRTL_RX_WARNING; priv->can.can_stats.error_warning++; } else if (state == CAN_STATE_ERROR_PASSIVE) { cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE; priv->can.can_stats.error_passive++; }Quoted 1 line
It might have missed something, though.
Quoted 7 lines
Sorry, I missed that from your previous mail. As we can't properly detect
ERROR_WARNINGstate this would reduce to:if (state != priv->can.state && state == CAN_STATE_ERROR_WARNING) { cf->data[1] |= CAN_ERR_CRTL_RX_WARNING; priv->can.can_stats.error_warning++; }
Quoted 6 lines
Why you can't detect error warning? When the [RT]WRNINT comes, the error waning state has entered. By looking to the manual, the state changes to error warning and bus-off are directly signaled via interrupt. A change to error passive might be visible when bus error ints occurs. You could add some dev_dbg's to the "if (stat & ERRSTAT_[RT]WRNINT)" and "switch" blocks above and check with sending a message with no cable connected.
Read what I've written above. We get an interrupt on entering error warning, but the bits reflecting the actual state only give error active, error passive or bus off, but *not* error warning.
We could read the error counter and do something like
switch ((stat >> 4) & 0x3) {
case 0:
state = CAN_STATE_ERROR_ACTIVE;
break;
case 1:
state = CAN_STATE_ERROR_PASSIVE;
break;
default:
state = CAN_STATE_BUS_OFF;
break;
}
errcnt = readl(®s->errcnt);
rxerr = (errcnt >> 8) & 0xff;
txerr = errcnt & 0xff;
if ((rxerr >= 96 || txerr >= 96) && state == CAN_STATE_ERROR_ACTIVE)
state = CAN_STATE_ERROR_WARNING;Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 145 lines · Sascha Hauer
Quoted 137 lines · Wolfgang Grandegger
Quoted 128 lines · Sascha Hauer
Quoted 87 lines · Wolfgang Grandegger
Quoted 59 lines · Sascha Hauer
And another go...
Sascha
Quoted 1 line
From
9f6f6fb67d57d082e056dec8121f1423c1b4fa0bMon Sep 17 00:00:00 2001From: Sascha Hauer <[email protected]>
Date: Tue, 21 Jul 2009 10:47:19 +0200
Subject: [PATCH] CAN: Add Flexcan CAN driverThis core is found on some Freescale SoCs and also some Coldfire SoCs. Support for Coldfire is missing though at the moment as they have an older revision of the core which does not have RX FIFO support.
V3: integrated comments from Oliver Hartkopp
V2: integrated comments from Wolfgang GrandeggerSigned-off-by Sascha Hauer <[email protected]>--- drivers/net/can/Kconfig | 6 + drivers/net/can/Makefile | 1 + drivers/net/can/flexcan.c | 719 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 726 insertions(+), 0 deletions(-) create mode 100644 drivers/net/can/flexcan.cdrivers/net/can/Kconfig +6
-0@@ -74,6 +74,12 @@ config CAN_KVASER_PCI This driver is for the the PCIcanx and PCIcan cards (1, 2 or 4 channel) from Kvaser (http://www.kvaser.com). +config CAN_FLEXCAN + tristate "Support for Freescale FLEXCAN based chips" + depends on CAN_DEV + ---help--- + Say Y here if you want to support for Freescale FlexCAN. + config CAN_DEBUG_DEVICES bool "CAN devices debugging messages" depends on CANdrivers/net/can/Makefile +1
-0@@ -8,5 +8,6 @@ obj-$(CONFIG_CAN_DEV) += can-dev.o can-dev-y := dev.o obj-$(CONFIG_CAN_SJA1000) += sja1000/ +obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUGdrivers/net/can/flexcan.c new file +0
-0[...]
Quoted 26 lines
drivers/net/can/flexcan.c new file +26
-0+static void flexcan_error (struct net_device *ndev,u32 stat) +{ +struct can_frame *cf; +struct sk_buff *skb; +struct flexcan_priv *priv =netdev_priv (ndev); +struct net_device_stats *stats = &ndev->stats; +enum can_state state = priv->can.state; +int error_warning =0 , rx_errors =0 , tx_errors =0 ; + + skb =dev_alloc_skb (sizeof (struct can_frame )); +if (!skb) +return ; + + skb->dev = ndev; + skb->protocol =__constant_htons (ETH_P_CAN ); + skb->ip_summed =CHECKSUM_UNNECESSARY ; + + cf = (struct can_frame *)skb_put (skb,sizeof (*cf)); +memset (cf,0 ,sizeof (*cf)); + + cf->can_id =CAN_ERR_FLAG ; + cf->can_dlc =CAN_ERR_DLC ; + +if (stat &ERRSTAT_RWRNINT ) { + error_warning =1 ; + cf->data[1 ] |=CAN_ERR_CRTL_RX_WARNING ;Quoted 8 lines
drivers/net/can/flexcan.c line 307
Quoted 6 lines
drivers/net/can/flexcan.c new file +6
-0+ } + +if (stat &ERRSTAT_TWRNINT ) { + error_warning =1 ; + cf->data[1 ] |=CAN_ERR_CRTL_TX_WARNING ; + }What is the meaning of this error warning interrupt? It does *not* change the state.
This TWRNINT means that the Tx error counter has transitioned from < 96 to >= 96 (analog the RWRNINT for the Rx error counter). Unfortunately the state bits handled below do not reflect this error warning state.
So this interrupt signals us that we have been in error warning state once but we have no possibility to detect if we are still in error warning state. I don't know how to handle this correctly. I could disable this interrupt and ignore it completely.
Quoted 23 lines
drivers/net/can/flexcan.c line 319
Quoted 11 lines
drivers/net/can/flexcan.c new file +11
-0+switch ((stat >>4 ) &0x3 ) { +case 0 : + state =CAN_STATE_ERROR_ACTIVE ; +break ; +case 1 : + state =CAN_STATE_ERROR_PASSIVE ; +break ; +default : + state =CAN_STATE_BUS_OFF ; +break ; + }I'm still not happy with the error message generation. If a state change to error passive happens, it should be signaled to the user. Here my ideas:
if (state != priv->can.state) { if (state == CAN_STATE_ERROR_WARNING) { cf->data[1] |= CAN_ERR_CRTL_RX_WARNING; priv->can.can_stats.error_warning++; } else if (state == CAN_STATE_ERROR_PASSIVE) { cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE; priv->can.can_stats.error_passive++; }Quoted 8 lines
Quoted 1 line
It might have missed something, though.
Sorry, I missed that from your previous mail. As we can't properly detect
ERROR_WARNINGstate this would reduce to:if (state != priv->can.state && state == CAN_STATE_ERROR_WARNING) { cf->data[1] |= CAN_ERR_CRTL_RX_WARNING; priv->can.can_stats.error_warning++; }Quoted 6 lines
Why you can't detect error warning? When the [RT]WRNINT comes, the error waning state has entered. By looking to the manual, the state changes to error warning and bus-off are directly signaled via interrupt. A change to error passive might be visible when bus error ints occurs. You could add some dev_dbg's to the "if (stat & ERRSTAT_[RT]WRNINT)" and "switch" blocks above and check with sending a message with no cable connected.
Quoted 3 lines
Read what I've written above. We get an interrupt on entering error warning, but the bits reflecting the actual state only give error active, error passive or bus off, but *not* error warning.
You could check the error counters.to verify the real state.
Quoted 11 lines
We could read the error counter and do something like
switch ((stat >> 4) & 0x3) { case 0: state = CAN_STATE_ERROR_ACTIVE; break; case 1: state = CAN_STATE_ERROR_PASSIVE; break; default: state = CAN_STATE_BUS_OFF;
Quoted 8 lines
break; } errcnt = readl(®s->errcnt); rxerr = (errcnt >> 8) & 0xff; txerr = errcnt & 0xff; if ((rxerr >= 96 || txerr >= 96) && state == CAN_STATE_ERROR_ACTIVE) state = CAN_STATE_ERROR_WARNING;
Yes, or do not handle the state in the "case 0" above appropriately. The CAN spec only specifies the bus error states error active, error passive and bus off. The warning is somehow optional but available on most CAN controllers. Nevertheless, we should create a message if the ISR realizes a state changes.
Wolfgang.
Quoted 1 line · Wolfgang Grandegger
Sascha Hauer wrote:
[...]
Quoted 11 lines
Quoted 5 lines
errcnt = readl(®s->errcnt); rxerr = (errcnt >> 8) & 0xff; txerr = errcnt & 0xff; if ((rxerr >= 96 || txerr >= 96) && state == CAN_STATE_ERROR_ACTIVE) state = CAN_STATE_ERROR_WARNING;Yes, or do not handle the state in the "case 0" above appropriately. The CAN spec only specifies the bus error states error active, error passive and bus off. The warning is somehow optional but available on most CAN controllers. Nevertheless, we should create a message if the ISR realizes a state changes.
FYI, I will be on holiday for the next 1.5 weeks.
Wolfgang.
Quoted 9 lines · Wolfgang Grandegger
Quoted 1 line · Wolfgang Grandegger
Sascha Hauer wrote:
[...]
Quoted 6 lines
Quoted 5 lines
errcnt = readl(®s->errcnt); rxerr = (errcnt >> 8) & 0xff; txerr = errcnt & 0xff; if ((rxerr >= 96 || txerr >= 96) && state == CAN_STATE_ERROR_ACTIVE) state = CAN_STATE_ERROR_WARNING;
Quoted 7 lines
Quoted 5 lines
Yes, or do not handle the state in the "case 0" above appropriately. The CAN spec only specifies the bus error states error active, error passive and bus off. The warning is somehow optional but available on most CAN controllers. Nevertheless, we should create a message if the ISR realizes a state changes.
FYI, I will be on holiday for the next 1.5 weeks.
Lucky you ;)
I just did some tests with the CAN cable disconnected. It turns out that I get flooded by interrupts caused by ACK errors. The system is completely unresponsive then. Unfortunately the ACK error interrupt can't be disabled seperately, so we have to disable error interrupts completely once we get an ACK error. I'm thinking about setting up a timer and poll the error status register then.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 9 lines · Sascha Hauer
Quoted 8 lines · Wolfgang Grandegger
Quoted 1 line · Wolfgang Grandegger
Sascha Hauer wrote:
[...]
Quoted 5 lines
Quoted 5 lines
errcnt = readl(®s->errcnt); rxerr = (errcnt >> 8) & 0xff; txerr = errcnt & 0xff; if ((rxerr >= 96 || txerr >= 96) && state == CAN_STATE_ERROR_ACTIVE) state = CAN_STATE_ERROR_WARNING;
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Yes, or do not handle the state in the "case 0" above appropriately. The CAN spec only specifies the bus error states error active, error passive and bus off. The warning is somehow optional but available on most CAN controllers. Nevertheless, we should create a message if the ISR realizes a state changes.
FYI, I will be on holiday for the next 1.5 weeks.
Lucky you ;)
A last answer before I go really offline...
Quoted 6 lines
I just did some tests with the CAN cable disconnected. It turns out that I get flooded by interrupts caused by ACK errors. The system is completely unresponsive then. Unfortunately the ACK error interrupt can't be disabled seperately, so we have to disable error interrupts completely once we get an ACK error. I'm thinking about setting up a timer and poll the error status register then.
I suspect that you are using 1MB/s. That's the infamous bus error flooding we realize with the SJA1000 on low-end systems as well. The right solution is using the NAPI (RX polling) interface.
Wolfgang.