pull-request: can-next 2022-07-20
Subsystems (13)
Marc Kleine-Budde
maintainercover pull-request: can-next 2022-07-20
Hello Jakub, hello David,
this is a pull request of 29 patches for net-next/master.
The first 6 patches target the slcan driver. Dan Carpenter contributes a hardening patch, followed by 5 cleanup patches.
Biju Das contributes 5 patches to prepare the sja1000 driver to support the Renesas RZ/N1 SJA1000 CAN controller.
Dario Binacchi's patch for the slcan driver fixes a sleep with held spin lock.
Another patch by Dario Binacchi fixes a wrong comment in the c_can driver.
Pavel Pisa updates the CTU CAN FD IP core registers.
Stephane Grosjean contributes 3 patches to the peak_usb driver for cleanups and support of a new MCU.
The last 12 patches are by Vincent Mailhol, they fix and improve the txerr and rxerr reporting in all CAN drivers.
regards,
Marc
---
The following changes since commit e22c88799f2629088504e1357384f2ec3798da46:
Merge branch '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue (2022-07-18 20:39:54 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git tags/linux-can-next-for-5.20-20220720
for you to fetch changes up to 1dbd8748a147c971747c8460e0cd1828cf2745d7:
Merge branch 'can-error-set-of-fixes-and-improvement-on-txerr-and-rxerr-reporting' (2022-07-20 09:28:43 +0200)
----------------------------------------------------------------
linux-can-next-for-5.20-20220720
----------------------------------------------------------------
Biju Das (5):
dt-bindings: can: sja1000: Convert to json-schema
dt-bindings: can: nxp,sja1000: Document RZ/N1{D,S} support
can: sja1000: Add Quirk for RZ/N1 SJA1000 CAN controller
can: sja1000: Use device_get_match_data to get device data
can: sja1000: Change the return type as void for SoC specific init
Dan Carpenter (1):
can: slcan: use scnprintf() as a hardening measure
Dario Binacchi (2):
can: slcan: do not sleep with a spin lock held
can: c_can: remove wrong comment
Marc Kleine-Budde (9):
can: slcan: convert comments to network style comments
can: slcan: slcan_init() convert printk(LEVEL ...) to pr_level()
can: slcan: fix whitespace issues
can: slcan: convert comparison to NULL into !val
can: slcan: clean up if/else
Merge branch 'can-slcan-checkpatch-cleanups'
Merge branch 'can-add-support-for-rz-n1-sja1000-can-controller' Merge branch 'can-peak_usb-cleanups-and-updates'
Merge branch 'can-error-set-of-fixes-and-improvement-on-txerr-and-rxerr-reporting'
Pavel Pisa (1):
can: ctucanfd: Update CTU CAN FD IP core registers to match version 3.x.
Stephane Grosjean (3):
can: peak_usb: pcan_dump_mem(): mark input prompt and data pointer as const
can: peak_usb: correction of an initially misnamed field name
can: peak_usb: include support for a new MCU
Vincent Mailhol (12):
can: pch_can: do not report txerr and rxerr during bus-off
can: rcar_can: do not report txerr and rxerr during bus-off
can: sja1000: do not report txerr and rxerr during bus-off
can: slcan: do not report txerr and rxerr during bus-off
can: hi311x: do not report txerr and rxerr during bus-off
can: sun4i_can: do not report txerr and rxerr during bus-off
can: kvaser_usb_hydra: do not report txerr and rxerr during bus-off
can: kvaser_usb_leaf: do not report txerr and rxerr during bus-off
can: usb_8dev: do not report txerr and rxerr during bus-off
can: error: specify the values of data[5..7] of CAN error frames
can: add CAN_ERR_CNT flag to notify availability of error counter
can: error: add definitions for the different CAN error thresholds
.../devicetree/bindings/net/can/nxp,sja1000.yaml | 132 +++++++++++++++++++++ .../devicetree/bindings/net/can/sja1000.txt | 58 --------- drivers/net/can/c_can/c_can_main.c | 7 +- drivers/net/can/cc770/cc770.c | 1 + drivers/net/can/ctucanfd/ctucanfd_base.c | 5 +- drivers/net/can/ctucanfd/ctucanfd_kregs.h | 32 ++++- drivers/net/can/grcan.c | 1 + drivers/net/can/ifi_canfd/ifi_canfd.c | 4 +- drivers/net/can/janz-ican3.c | 4 +- drivers/net/can/kvaser_pciefd.c | 2 +- drivers/net/can/m_can/m_can.c | 4 +- drivers/net/can/pch_can.c | 7 +- drivers/net/can/peak_canfd/peak_canfd.c | 6 +- drivers/net/can/rcar/rcar_can.c | 9 +- drivers/net/can/rcar/rcar_canfd.c | 4 +- drivers/net/can/sja1000/sja1000.c | 16 ++- drivers/net/can/sja1000/sja1000.h | 3 +- drivers/net/can/sja1000/sja1000_platform.c | 20 +--- drivers/net/can/slcan/slcan-core.c | 117 +++++++++--------- drivers/net/can/spi/hi311x.c | 6 +- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 1 + drivers/net/can/sun4i_can.c | 10 +- drivers/net/can/ti_hecc.c | 1 + drivers/net/can/usb/esd_usb.c | 3 +- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 14 ++- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 7 +- drivers/net/can/usb/peak_usb/pcan_usb.c | 1 + drivers/net/can/usb/peak_usb/pcan_usb_core.c | 2 +- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 2 +- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 68 +++++++++-- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 2 +- drivers/net/can/usb/peak_usb/pcan_usb_pro.h | 2 +- drivers/net/can/usb/usb_8dev.c | 8 +- drivers/net/can/xilinx_can.c | 1 + include/uapi/linux/can/error.h | 20 +++- 35 files changed, 376 insertions(+), 204 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml delete mode 100644 Documentation/devicetree/bindings/net/can/sja1000.txt
Marc Kleine-Budde
maintainerPATCH 1/29 can: slcan: use scnprintf() as a hardening measure
From: Dan Carpenter <[email protected]>
The snprintf() function returns the number of bytes which *would* have been copied if there were no space. So, since this code does not check the return value, there if the buffer was not large enough then there would be a buffer overflow two lines later when it does:
actual = sl->tty->ops->write(sl->tty, sl->xbuff, n);
Use scnprintf() instead because that returns the number of bytes which were actually copied.
--- drivers/net/can/slcan/slcan-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/slcan/slcan-core.c +1 -1
@@ -647,7 +647,7 @@ static int slcan_transmit_cmd(struct slcan *sl, const unsigned char *cmd)return -ENODEV ; } - n =snprintf (sl->xbuff,sizeof (sl->xbuff),"%s" , cmd); + n =scnprintf (sl->xbuff,sizeof (sl->xbuff),"%s" , cmd);set_bit (TTY_DO_WRITE_WAKEUP , &sl->tty->flags); actual = sl->tty->ops->write (sl->tty, sl->xbuff, n); sl->xleft = n - actual;
base-commit: e22c88799f2629088504e1357384f2ec3798da46
Signature · 1 line
2.35.1
Re: [PATCH net-next 01/29] can: slcan: use scnprintf() as a hardening measure
This series was applied to netdev/net-next.git (master) by Marc Kleine-Budde <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Marc Kleine-Budde <[email protected]>:
Quoted 8 lines · On Wed, 20 Jul 2022 10:10:06 +0200 you wrote:
From: Dan Carpenter <[email protected]>
The
snprintf()function returns the number of bytes which *would* have been copied if there were no space. So, since this code does not check the return value, there if the buffer was not large enough then there would be a buffer overflow two lines later when it does:[...]
Here is the summary with links:
- [net-next,01/29] can: slcan: use scnprintf() as a hardening measure
https://git.kernel.org/netdev/net-next/c/0159a9305d40 - [net-next,02/29] can: slcan: convert comments to network style comments https://git.kernel.org/netdev/net-next/c/71f3a4cc740a - [net-next,03/29] can: slcan: slcan_init() convert printk(LEVEL ...) to pr_level() https://git.kernel.org/netdev/net-next/c/ded5fa885b2d - [net-next,04/29] can: slcan: fix whitespace issues https://git.kernel.org/netdev/net-next/c/f07d9e3c849b - [net-next,05/29] can: slcan: convert comparison to NULL into !val https://git.kernel.org/netdev/net-next/c/69a6539632dd - [net-next,06/29] can: slcan: clean up if/else https://git.kernel.org/netdev/net-next/c/18de712a5802 - [net-next,07/29] dt-bindings: can: sja1000: Convert to json-schema https://git.kernel.org/netdev/net-next/c/f6b8061db9af - [net-next,08/29] dt-bindings: can: nxp,sja1000: Document RZ/N1{D,S} support https://git.kernel.org/netdev/net-next/c/4591c760b797 - [net-next,09/29] can: sja1000: Add Quirk for RZ/N1 SJA1000 CAN controller https://git.kernel.org/netdev/net-next/c/2d99bfbf3386 - [net-next,10/29] can: sja1000: Use device_get_match_data to get device data https://git.kernel.org/netdev/net-next/c/63ab1b63695e - [net-next,11/29] can: sja1000: Change the return type as void for SoC specific init https://git.kernel.org/netdev/net-next/c/6d5fe10796bb - [net-next,12/29] can: slcan: do not sleep with a spin lock held https://git.kernel.org/netdev/net-next/c/c6887023268e - [net-next,13/29] can: c_can: remove wrong comment https://git.kernel.org/netdev/net-next/c/4940eb51fc49 - [net-next,14/29] can: ctucanfd: Update CTU CAN FD IP core registers to match version 3.x. https://git.kernel.org/netdev/net-next/c/9e7c9b8eb719 - [net-next,15/29] can: peak_usb: pcan_dump_mem(): mark input prompt and data pointer as const https://git.kernel.org/netdev/net-next/c/92505df464ff - [net-next,16/29] can: peak_usb: correction of an initially misnamed field name https://git.kernel.org/netdev/net-next/c/a0cf2fe6cf2e - [net-next,17/29] can: peak_usb: include support for a new MCU https://git.kernel.org/netdev/net-next/c/4f232482467a - [net-next,18/29] can: pch_can: do not report txerr and rxerr during bus-off https://git.kernel.org/netdev/net-next/c/3a5c7e4611dd - [net-next,19/29] can: rcar_can: do not report txerr and rxerr during bus-off https://git.kernel.org/netdev/net-next/c/a37b7245e831 - [net-next,20/29] can: sja1000: do not report txerr and rxerr during bus-off https://git.kernel.org/netdev/net-next/c/164d7cb2d5a3 - [net-next,21/29] can: slcan: do not report txerr and rxerr during bus-off https://git.kernel.org/netdev/net-next/c/ce0e7aeb676b - [net-next,22/29] can: hi311x: do not report txerr and rxerr during bus-off https://git.kernel.org/netdev/net-next/c/a22bd630cfff - [net-next,23/29] can: sun4i_can: do not report txerr and rxerr during bus-off https://git.kernel.org/netdev/net-next/c/0ac15a8f661b - [net-next,24/29] can: kvaser_usb_hydra: do not report txerr and rxerr during bus-off https://git.kernel.org/netdev/net-next/c/936e90595376 - [net-next,25/29] can: kvaser_usb_leaf: do not report txerr and rxerr during bus-off https://git.kernel.org/netdev/net-next/c/a57732084e06 - [net-next,26/29] can: usb_8dev: do not report txerr and rxerr during bus-off https://git.kernel.org/netdev/net-next/c/aebe8a2433cd - [net-next,27/29] can: error: specify the values of data[5..7] of CAN error frames https://git.kernel.org/netdev/net-next/c/e70a3263a7ee - [net-next,28/29] can: add CAN_ERR_CNT flag to notify availability of error counter https://git.kernel.org/netdev/net-next/c/3e5c291c7942 - [net-next,29/29] can: error: add definitions for the different CAN error thresholds https://git.kernel.org/netdev/net-next/c/3f9c26210cf8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Marc Kleine-Budde
maintainerPATCH 2/29 can: slcan: convert comments to network style comments
In reply to Marc Kleine-BuddeConvert all comments to network subsystem style comments.
--- drivers/net/can/slcan/slcan-core.c | 55 +++++++++++++----------------- 1 file changed, 24 insertions(+), 31 deletions(-)
drivers/net/can/slcan/slcan-core.c +24 -31
@@ -67,8 +67,9 @@ MODULE_AUTHOR("Oliver Hartkopp <[email protected]>");#define SLCAN_MAGIC 0x53CAstatic int maxdev =10 ;/* MAX number of SLCAN channels; -This can be overridden with -insmod slcan.ko maxdev=nnn */ +* This can be overridden with +* insmod slcan.ko maxdev=nnn +*/ module_param (maxdev, int,0 );MODULE_PARM_DESC (maxdev,"Maximum number of slcan interfaces" );
@@ -139,12 +140,11 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on)return 0 ; } -/************************************************************************ -* SLCAN ENCAPSULATION FORMAT * -************************************************************************/ +/************************************************************************* +* SLCAN ENCAPSULATION FORMAT * +*************************************************************************/ -/* -* A CAN frame has a can_id (11 bit standard frame format OR 29 bit extended +/* A CAN frame has a can_id (11 bit standard frame format OR 29 bit extended * frame format) a data length code (len) which can be from 0 to 8 * and up to <len> data bytes as payload. * Additionally a CAN frame may become a remote transmission frame if the
@@ -174,9 +174,9 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on)* */ -/************************************************************************ -* STANDARD SLCAN DECAPSULATION * -************************************************************************/ +/************************************************************************* +* STANDARD SLCAN DECAPSULATION * +*************************************************************************/ /* Send one completely decapsulated can_frame to the network layer */ static void slc_bump_frame (struct slcan *sl)
@@ -486,9 +486,9 @@ static void slcan_unesc(struct slcan *sl, unsigned char s) } } -/************************************************************************ -* STANDARD SLCAN ENCAPSULATION * -************************************************************************/ +/************************************************************************* +* STANDARD SLCAN ENCAPSULATION * +*************************************************************************/ /* Encapsulate one can_frame and stuff into a TTY queue. */ static void slc_encaps (struct slcan *sl,struct can_frame *cf)
@@ -575,7 +575,8 @@ static void slcan_transmit(struct work_struct *work) }/* Now serial buffer is almost free & we can start -* transmission of another packet */ +* transmission of another packet +*/ sl->dev->stats.tx_packets++;clear_bit (TTY_DO_WRITE_WAKEUP , &sl->tty->flags);spin_unlock_bh (&sl->lock);
@@ -589,8 +590,7 @@ static void slcan_transmit(struct work_struct *work)spin_unlock_bh (&sl->lock); } -/* -* Called by the driver when there's room for more data. +/* Called by the driver when there's room for more data. * Schedule the transmit. */ static void slcan_write_wakeup (struct tty_struct *tty)
@@ -632,7 +632,6 @@ static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } -/****************************************** * Routines looking at netdevice side. ******************************************/
@@ -736,7 +735,6 @@ static int slc_open(struct net_device *dev)/* The CAN framework has already validate the bitrate value, * so we can avoid to check if `s' has been properly set. */ -snprintf (cmd,sizeof (cmd),"C\rS%d\r" , s); err =slcan_transmit_cmd (sl, cmd);if (err) {
@@ -792,18 +790,16 @@ static const struct net_device_ops slc_netdev_ops = { };/****************************************** -Routines looking at TTY side. +* Routines looking at TTY side. ******************************************/ -/* -* Handle the 'receiver data ready' interrupt. +/* Handle the 'receiver data ready' interrupt. * This function is called by the 'tty_io' module in the kernel when * a block of SLCAN data has been received, which can now be decapsulated * and sent on to some IP layer for further processing. This will not * be re-entered while running but other ldisc functions may be called * in parallel */ -static void slcan_receive_buf (struct tty_struct *tty,const unsigned char *cp,const char *fp,int count)
@@ -890,8 +886,7 @@ static struct slcan *slc_alloc(void)return sl; } -/* -* Open the high-level part of the SLCAN channel. +/* Open the high-level part of the SLCAN channel. * This function is called by the TTY module when the * SLCAN line discipline is called for. Because we are * sure the tty line exists, we only have to link it to
@@ -899,7 +894,6 @@ static struct slcan *slc_alloc(void)* * Called in process context serialized from other ldisc calls. */ -static int slcan_open (struct tty_struct *tty) {struct slcan *sl;
@@ -912,8 +906,8 @@ static int slcan_open(struct tty_struct *tty)return -EOPNOTSUPP ;/* RTnetlink lock is misused here to serialize concurrent -opens of slcan channels. There are better ways, but it is -the simplest one. +* opens of slcan channels. There are better ways, but it is +* the simplest one. */ rtnl_lock ();
@@ -974,14 +968,12 @@ static int slcan_open(struct tty_struct *tty)return err; } -/* -* Close down a SLCAN channel. +/* Close down a SLCAN channel. * This means flushing out any pending queues, and then returning. This * call is serialized against other ldisc functions. * * We also use this method for a hangup event. */ -static void slcan_close (struct tty_struct *tty) {struct slcan *sl = (struct slcan *) tty->disc_data;
@@ -1104,7 +1096,8 @@ static void __exit slcan_exit(void) }while (busy &&time_before (jiffies, timeout));/* FIXME: hangup is async so we should wait when doing this second -phase */ +* phase +*/ for (i =0 ; i < maxdev; i++) { dev = slcan_devs[i];
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 3/29 can: slcan: slcan_init() convert printk(LEVEL ...) to pr_level()
In reply to Marc Kleine-BuddeConvert the last printk(LEVEL ...) to pr_level().
--- drivers/net/can/slcan/slcan-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/slcan/slcan-core.c +1 -1
@@ -1057,7 +1057,7 @@ static int __init slcan_init(void)/* Fill in our line protocol discipline, and register it */ status =tty_register_ldisc (&slc_ldisc);if (status) { -printk (KERN_ERR "slcan: can't register line discipline\n" ); +pr_err ("slcan: can't register line discipline\n" );kfree (slcan_devs); }return status;
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 4/29 can: slcan: fix whitespace issues
In reply to Marc Kleine-BuddeAdd and remove whitespace to make checkpatch happy.
--- drivers/net/can/slcan/slcan-core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/can/slcan/slcan-core.c +5 -5
@@ -74,7 +74,7 @@ module_param(maxdev, int, 0);MODULE_PARM_DESC (maxdev,"Maximum number of slcan interfaces" );/* maximum rx buffer len: extended CAN frame with timestamp */ -#define SLC_MTU (sizeof("T1111222281122334455667788EA5F\r")+1) +#define SLC_MTU (sizeof("T1111222281122334455667788EA5F\r") + 1)#define SLC_CMD_LEN 1#define SLC_SFF_ID_LEN 3
@@ -624,7 +624,7 @@ static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev) }netif_stop_queue (sl->dev); -slc_encaps (sl, (struct can_frame *) skb->data);/* encaps & send */ +slc_encaps (sl, (struct can_frame *)skb->data);/* encaps & send */ spin_unlock (&sl->lock); out:
@@ -804,7 +804,7 @@ static void slcan_receive_buf(struct tty_struct *tty, const unsigned char *cp, const char *fp, int count) { - struct slcan *sl = (struct slcan *) tty->disc_data; + struct slcan *sl = (struct slcan *)tty->disc_data;if (!sl || sl->magic !=SLCAN_MAGIC || !netif_running (sl->dev))return ;
@@ -976,7 +976,7 @@ static int slcan_open(struct tty_struct *tty)*/ static void slcan_close (struct tty_struct *tty) { -struct slcan *sl = (struct slcan *) tty->disc_data; +struct slcan *sl = (struct slcan *)tty->disc_data;/* First make sure we're connected. */ if (!sl || sl->magic !=SLCAN_MAGIC || sl->tty != tty)
@@ -1006,7 +1006,7 @@ static void slcan_hangup(struct tty_struct *tty)static int slcan_ioctl (struct tty_struct *tty,unsigned int cmd,unsigned long arg) { -struct slcan *sl = (struct slcan *) tty->disc_data; +struct slcan *sl = (struct slcan *)tty->disc_data;unsigned int tmp;/* First make sure we're connected. */
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 5/29 can: slcan: convert comparison to NULL into !val
In reply to Marc Kleine-BuddeAll comparison to NULL could be written "!val", convert them to make checkpatch happy.
--- drivers/net/can/slcan/slcan-core.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/net/can/slcan/slcan-core.c +7 -8
@@ -618,7 +618,7 @@ static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev)netdev_warn (dev,"xmit: iface is down\n" ); goto out; } -if (sl->tty ==NULL ) { +if (!sl->tty) {spin_unlock (&sl->lock); goto out; }
@@ -707,7 +707,7 @@ static int slc_open(struct net_device *dev)unsigned char cmd[SLC_MTU ];int err, s; -if (sl->tty ==NULL ) +if (!sl->tty)return -ENODEV ;/* The baud rate is not set with the command
@@ -834,7 +834,7 @@ static void slc_sync(void)for (i =0 ; i < maxdev; i++) { dev = slcan_devs[i]; -if (dev ==NULL ) +if (!dev)break ; sl =netdev_priv (dev);
@@ -854,9 +854,8 @@ static struct slcan *slc_alloc(void)for (i =0 ; i < maxdev; i++) { dev = slcan_devs[i]; -if (dev ==NULL ) +if (!dev)break ; - }/* Sorry, too many, all slots in use */
@@ -902,7 +901,7 @@ static int slcan_open(struct tty_struct *tty)if (!capable (CAP_NET_ADMIN ))return -EPERM ; -if (tty->ops->write ==NULL ) +if (!tty->ops->write)return -EOPNOTSUPP ;/* RTnetlink lock is misused here to serialize concurrent
@@ -924,7 +923,7 @@ static int slcan_open(struct tty_struct *tty)/* OK. Find a free SLCAN channel to use. */ err = -ENFILE ; sl =slc_alloc (); -if (sl ==NULL ) +if (!sl) goto err_exit; sl->tty = tty;
@@ -1071,7 +1070,7 @@ static void __exit slcan_exit(void)unsigned long timeout = jiffies +HZ ;int busy =0 ; -if (slcan_devs ==NULL ) +if (!slcan_devs)return ;/* First of all: check for active disciplines and hangup them.
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 6/29 can: slcan: clean up if/else
In reply to Marc Kleine-BuddeRemove braces after if() for single statement blocks, also remove else after return() in if() block.
--- drivers/net/can/slcan/slcan-core.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/can/slcan/slcan-core.c +6 -7
@@ -469,19 +469,19 @@ static void slcan_unesc(struct slcan *sl, unsigned char s) {if ((s =='\r' ) || (s =='\a' )) {/* CR or BEL ends the pdu */ if (!test_and_clear_bit (SLF_ERROR , &sl->flags) && - (sl->rcount >4 )) { + sl->rcount >4 )slc_bump (sl); - } + sl->rcount =0 ; }else {if (!test_bit (SLF_ERROR , &sl->flags)) {if (sl->rcount <SLC_MTU ) { sl->rbuff[sl->rcount++] = s;return ; - }else { - sl->dev->stats.rx_over_errors++; -set_bit (SLF_ERROR , &sl->flags); } + + sl->dev->stats.rx_over_errors++; +set_bit (SLF_ERROR , &sl->flags); } } }
@@ -1104,9 +1104,8 @@ static void __exit slcan_exit(void)continue ; sl =netdev_priv (dev); -if (sl->tty) { +if (sl->tty)netdev_err (dev,"tty discipline still running\n" ); - }slc_close (dev);unregister_candev (dev);
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 7/29 dt-bindings: can: sja1000: Convert to json-schema
In reply to Marc Kleine-BuddeFrom: Biju Das <[email protected]>
Convert the NXP SJA1000 CAN Controller Device Tree binding documentation to json-schema.
Update the example to match reality.
--- .../bindings/net/can/nxp,sja1000.yaml | 101 ++++++++++++++++++ .../devicetree/bindings/net/can/sja1000.txt | 58 ---------- 2 files changed, 101 insertions(+), 58 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml delete mode 100644 Documentation/devicetree/bindings/net/can/sja1000.txt
Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml new file +101 -0
@@ -0,0 +1,101 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/can/nxp,sja1000.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Memory mapped SJA1000 CAN controller from NXP (formerly Philips) + +maintainers: + - Wolfgang Grandegger <[email protected]> + +properties: + compatible: + enum: + - nxp,sja1000 + - technologic,sja1000 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + reg-io-width: + $ref: /schemas/types.yaml#/definitions/uint32 + description: I/O register width (in bytes) implemented by this device + default: 1 + enum: [ 1, 2, 4 ] + + nxp,external-clock-frequency: + $ref: /schemas/types.yaml#/definitions/uint32 + default: 16000000 + description: | + Frequency of the external oscillator clock in Hz. + The internal clock frequency used by the SJA1000 is half of that value. + + nxp,tx-output-mode: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 1, 2, 3 ] + default: 1 + description: | + operation mode of the TX output control logic. Valid values are: + <0> : bi-phase output mode + <1> : normal output mode (default) + <2> : test output mode + <3> : clock output mode + + nxp,tx-output-config: + $ref: /schemas/types.yaml#/definitions/uint32 + default: 0x02 + description: | + TX output pin configuration. Valid values are any one of the below + or combination of TX0 and TX1: + <0x01> : TX0 invert + <0x02> : TX0 pull-down (default) + <0x04> : TX0 pull-up + <0x06> : TX0 push-pull + <0x08> : TX1 invert + <0x10> : TX1 pull-down + <0x20> : TX1 pull-up + <0x30> : TX1 push-pull + + nxp,clock-out-frequency: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + clock frequency in Hz on the CLKOUT pin. + If not specified or if the specified value is 0, the CLKOUT pin + will be disabled. + + nxp,no-comparator-bypass: + type: boolean + description: Allows to disable the CAN input comparator. + +required: + - compatible + - reg + - interrupts + +allOf: + - $ref: can-controller.yaml# + - if: + properties: + compatible: + contains: + const: technologic,sja1000 + then: + required: + - reg-io-width + +unevaluatedProperties: false + +examples: + - | + can@1a000 { + compatible = "technologic,sja1000"; + reg = <0x1a000 0x100>; + interrupts = <1>; + reg-io-width = <2>; + nxp,tx-output-config = <0x06>; + nxp,external-clock-frequency = <24000000>; + };
Documentation/devicetree/bindings/net/can/sja1000.txt deleted +0 -58
58 lines not on this page · raw message
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 8/29 dt-bindings: can: nxp,sja1000: Document RZ/N1{D,S} support
In reply to Marc Kleine-BuddeFrom: Biju Das <[email protected]>
Add CAN binding documentation for Renesas RZ/N1 SoC.
The SJA1000 CAN controller on RZ/N1 SoC has some differences compared to others like it has no clock divider register (CDR) support and it has no HW loopback (HW doesn't see tx messages on rx), so introduced a new compatible 'renesas,rzn1-sja1000' to handle these differences.
--- .../bindings/net/can/nxp,sja1000.yaml | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml +35 -4
@@ -11,9 +11,15 @@ maintainers: properties: compatible: - enum: - - nxp,sja1000 - - technologic,sja1000 + oneOf: + - enum: + - nxp,sja1000 + - technologic,sja1000 + - items: + - enum: + - renesas,r9a06g032-sja1000 # RZ/N1D + - renesas,r9a06g033-sja1000 # RZ/N1S + - const: renesas,rzn1-sja1000 # RZ/N1 reg: maxItems: 1
@@ -21,6 +27,9 @@ properties: interrupts: maxItems: 1 + clocks: + maxItems: 1 + reg-io-width: $ref: /schemas/types.yaml#/definitions/uint32 description: I/O register width (in bytes) implemented by this device
@@ -82,10 +91,20 @@ allOf: properties: compatible: contains: - const: technologic,sja1000 + enum: + - technologic,sja1000 + - renesas,rzn1-sja1000 then: required: - reg-io-width + - if: + properties: + compatible: + contains: + const: renesas,rzn1-sja1000 + then: + required: + - clocks unevaluatedProperties: false
@@ -99,3 +118,15 @@ examples: nxp,tx-output-config = <0x06>; nxp,external-clock-frequency = <24000000>; }; + + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/clock/r9a06g032-sysctrl.h> + + can@52104000 { + compatible = "renesas,r9a06g032-sja1000", "renesas,rzn1-sja1000"; + reg = <0x52104000 0x800>; + reg-io-width = <4>; + interrupts = <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&sysctrl R9A06G032_HCLK_CAN0>; + };
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 9/29 can: sja1000: Add Quirk for RZ/N1 SJA1000 CAN controller
In reply to Marc Kleine-BuddeFrom: Biju Das <[email protected]>
As per Chapter 6.5.16 of the RZ/N1 Peripheral Manual, The SJA1000 CAN controller does not support Clock Divider Register compared to the reference Philips SJA1000 device.
This patch adds a device quirk to handle this difference.
--- drivers/net/can/sja1000/sja1000.c | 8 +++++--- drivers/net/can/sja1000/sja1000.h | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-)
drivers/net/can/sja1000/sja1000.c +5 -3
@@ -183,8 +183,9 @@ static void chipset_init(struct net_device *dev) {struct sja1000_priv *priv =netdev_priv (dev); -/* set clock divider and output control register */ - priv->write_reg (priv,SJA1000_CDR , priv->cdr |CDR_PELICAN ); +if (!(priv->flags &SJA1000_QUIRK_NO_CDR_REG )) +/* set clock divider and output control register */ + priv->write_reg (priv,SJA1000_CDR , priv->cdr |CDR_PELICAN );/* set acceptance filter (accept all) */ priv->write_reg (priv,SJA1000_ACCC0 ,0x00 );
@@ -209,7 +210,8 @@ static void sja1000_start(struct net_device *dev)set_reset_mode (dev);/* Initialize chip if uninitialized at this stage */ -if (!(priv->read_reg (priv,SJA1000_CDR ) &CDR_PELICAN )) +if (!(priv->flags &SJA1000_QUIRK_NO_CDR_REG || + priv->read_reg (priv,SJA1000_CDR ) &CDR_PELICAN ))chipset_init (dev);/* Clear error counters and error code capture */
drivers/net/can/sja1000/sja1000.h +2 -1
@@ -145,7 +145,8 @@/* * Flags for sja1000priv.flags */ -#define SJA1000_CUSTOM_IRQ_HANDLER 0x1 +#define SJA1000_CUSTOM_IRQ_HANDLER BIT(0) +#define SJA1000_QUIRK_NO_CDR_REG BIT(1)/* * SJA1000 private data structure
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 10/29 can: sja1000: Use device_get_match_data to get device data
In reply to Marc Kleine-BuddeFrom: Biju Das <[email protected]>
This patch replaces of_match_device->device_get_match_data to get pointer to device data.
--- drivers/net/can/sja1000/sja1000_platform.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/can/sja1000/sja1000_platform.c +2 -5
@@ -210,7 +210,6 @@ static int sp_probe(struct platform_device *pdev)struct resource *res_mem, *res_irq =NULL ;struct sja1000_platform_data *pdata;struct device_node *of = pdev->dev.of_node; -const struct of_device_id *of_id;const struct sja1000_of_data *of_data =NULL ;size_t priv_sz =0 ;
@@ -243,11 +242,9 @@ static int sp_probe(struct platform_device *pdev)return -ENODEV ; } - of_id =of_match_device (sp_of_table, &pdev->dev); -if (of_id && of_id->data) { - of_data = of_id->data; + of_data =device_get_match_data (&pdev->dev); +if (of_data) priv_sz = of_data->priv_sz; - } dev =alloc_sja1000dev (priv_sz);if (!dev)
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 11/29 can: sja1000: Change the return type as void for SoC specific init
In reply to Marc Kleine-BuddeFrom: Biju Das <[email protected]>
Change the return type as void for SoC specific init function as it always return 0.
--- drivers/net/can/sja1000/sja1000_platform.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/net/can/sja1000/sja1000_platform.c +4 -9
@@ -31,7 +31,7 @@ MODULE_LICENSE("GPL v2");struct sja1000_of_data {size_t priv_sz; -int (*init)(struct sja1000_priv *priv,struct device_node *of); +void (*init)(struct sja1000_priv *priv,struct device_node *of); };struct technologic_priv {
@@ -94,15 +94,13 @@ static void sp_technologic_write_reg16(const struct sja1000_priv *priv,spin_unlock_irqrestore (&tp->io_lock, flags); } -static int sp_technologic_init (struct sja1000_priv *priv,struct device_node *of) +static void sp_technologic_init (struct sja1000_priv *priv,struct device_node *of) {struct technologic_priv *tp = priv->priv; priv->read_reg = sp_technologic_read_reg16; priv->write_reg = sp_technologic_write_reg16;spin_lock_init (&tp->io_lock); - -return 0 ; } static void sp_populate(struct sja1000_priv *priv,
@@ -266,11 +264,8 @@ static int sp_probe(struct platform_device *pdev)if (of) {sp_populate_of (priv, of); -if (of_data && of_data->init) { - err = of_data->init (priv, of); -if (err) - goto exit_free; - } +if (of_data && of_data->init) + of_data->init (priv, of); }else {sp_populate (priv, pdata, res_mem->flags); }
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 12/29 can: slcan: do not sleep with a spin lock held
In reply to Marc Kleine-BuddeFrom: Dario Binacchi <[email protected]>
We can't call close_candev() with a spin lock held, so release the lock before calling it. After calling close_candev(), we can update the fields of the private `struct can_priv' without having to acquire the lock.
--- drivers/net/can/slcan/slcan-core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/can/slcan/slcan-core.c +3 -4
@@ -688,15 +688,14 @@ static int slc_close(struct net_device *dev)clear_bit (TTY_DO_WRITE_WAKEUP , &sl->tty->flags); }netif_stop_queue (dev); + sl->rcount =0 ; + sl->xleft =0 ; +spin_unlock_bh (&sl->lock);close_candev (dev); sl->can.state =CAN_STATE_STOPPED ;if (sl->can.bittiming.bitrate ==CAN_BITRATE_UNKNOWN ) sl->can.bittiming.bitrate =CAN_BITRATE_UNSET ; - sl->rcount =0 ; - sl->xleft =0 ; -spin_unlock_bh (&sl->lock); -return 0 ; }
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 13/29 can: c_can: remove wrong comment
In reply to Marc Kleine-BuddeFrom: Dario Binacchi <[email protected]>
The comment referred to a status (warning) other than the one that was being managed (active error).
--- drivers/net/can/c_can/c_can_main.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/can/c_can/c_can_main.c +0 -1
@@ -952,7 +952,6 @@ static int c_can_handle_state_change(struct net_device *dev,switch (error_type) {case C_CAN_NO_ERROR : -/* error warning state */ cf->can_id |=CAN_ERR_CRTL ; cf->data[1 ] =CAN_ERR_CRTL_ACTIVE ; cf->data[6 ] = bec.txerr;
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 14/29 can: ctucanfd: Update CTU CAN FD IP core registers to match version 3.x.
In reply to Marc Kleine-BuddeFrom: Pavel Pisa <[email protected]>
The update is compatible/pure extension of 2.x IP core version
- new option for 2, 4, or 8 Tx buffers option during synthesis. The 2.x version has fixed 4 Tx buffers. 3.x version default is 4 as well
- new REG_TX_COMMAND_TXT_BUFFER_COUNT provides synthesis choice. When read as 0 assume 2.x core with fixed 4 Tx buffers.
- new REG_ERR_CAPT_TS_BITS field to provide most significant active/implemented timestamp bit. For 2.x read as zero, assume value 63 is such case for 64 bit counter.
- new REG_MODE_RXBAM bit which controls automatic advance to next word after Rx FIFO register read. Bit is set to 1 by default after the core reset (REG_MODE_RST) and value 1 has to be preserved for the normal ctucanfd Linux driver operation. Even preceding driver version resets core and then modifies only known/required MODE register bits so backward and forward compatibility is ensured.
See complete datasheet for time-triggered and other updated capabilities
http://canbus.pages.fel.cvut.cz/ctucanfd_ip_core/doc/Datasheet.pdf
The fields related to ongoing Ondrej Ille's work on fault tolerant version with parity protected buffers and FIFOs are not included for now. Their inclusion will be considered when design is settled and tested.
--- drivers/net/can/ctucanfd/ctucanfd_kregs.h | 32 ++++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-)
drivers/net/can/ctucanfd/ctucanfd_kregs.h +28 -4
@@ -4,9 +4,9 @@* CTU CAN FD IP Core * * Copyright (C) 2015-2018 Ondrej Ille <[email protected]> FEE CTU -* Copyright (C) 2018-2021 Ondrej Ille <[email protected]> self-funded +* Copyright (C) 2018-2022 Ondrej Ille <[email protected]> self-funded * Copyright (C) 2018-2019 Martin Jerabek <[email protected]> FEE CTU -* Copyright (C) 2018-2021 Pavel Pisa <[email protected]> FEE CTU/self-funded +* Copyright (C) 2018-2022 Pavel Pisa <[email protected]> FEE CTU/self-funded * * Project advisors: * Jiri Novak <[email protected]>
@@ -64,9 +64,12 @@ enum ctu_can_fd_can_registers {CTUCANFD_RX_DATA =0x6c ,CTUCANFD_TX_STATUS =0x70 ,CTUCANFD_TX_COMMAND =0x74 , +CTUCANFD_TXTB_INFO =0x76 ,CTUCANFD_TX_PRIORITY =0x78 ,CTUCANFD_ERR_CAPT =0x7c , +CTUCANFD_RETR_CTR =0x7d ,CTUCANFD_ALC =0x7e , +CTUCANFD_TS_INFO =0x7f ,CTUCANFD_TRV_DELAY =0x80 ,CTUCANFD_SSP_CFG =0x82 , CTUCANFD_RX_FR_CTR = 0x84,
@@ -102,8 +105,12 @@ enum ctu_can_fd_can_registers {#define REG_MODE_STM BIT(2)#define REG_MODE_AFM BIT(3)#define REG_MODE_FDE BIT(4) +#define REG_MODE_TTTM BIT(5) +#define REG_MODE_ROM BIT(6)#define REG_MODE_ACF BIT(7)#define REG_MODE_TSTM BIT(8) +#define REG_MODE_RXBAM BIT(9) +#define REG_MODE_SAM BIT(11)#define REG_MODE_RTRLE BIT(16)#define REG_MODE_RTRTH GENMASK(20, 17)#define REG_MODE_ILBP BIT(21)
@@ -123,8 +130,10 @@ enum ctu_can_fd_can_registers {#define REG_STATUS_EWL BIT(6)#define REG_STATUS_IDLE BIT(7)#define REG_STATUS_PEXS BIT(8) +#define REG_STATUS_STCNT BIT(16)/* COMMAND registers */ +#define REG_COMMAND_RXRPMV BIT(1)#define REG_COMMAND_RRB BIT(2)#define REG_COMMAND_CDO BIT(3)#define REG_COMMAND_ERCRST BIT(4)
@@ -263,8 +272,12 @@ enum ctu_can_fd_can_registers {#define REG_TX_STATUS_TX2S GENMASK(7, 4)#define REG_TX_STATUS_TX3S GENMASK(11, 8)#define REG_TX_STATUS_TX4S GENMASK(15, 12) +#define REG_TX_STATUS_TX5S GENMASK(19, 16) +#define REG_TX_STATUS_TX6S GENMASK(23, 20) +#define REG_TX_STATUS_TX7S GENMASK(27, 24) +#define REG_TX_STATUS_TX8S GENMASK(31, 28) -/* TX_COMMAND registers */ +/* TX_COMMAND TXTB_INFO registers */ #define REG_TX_COMMAND_TXCE BIT(0)#define REG_TX_COMMAND_TXCR BIT(1)#define REG_TX_COMMAND_TXCA BIT(2)
@@ -272,18 +285,29 @@ enum ctu_can_fd_can_registers {#define REG_TX_COMMAND_TXB2 BIT(9)#define REG_TX_COMMAND_TXB3 BIT(10)#define REG_TX_COMMAND_TXB4 BIT(11) +#define REG_TX_COMMAND_TXB5 BIT(12) +#define REG_TX_COMMAND_TXB6 BIT(13) +#define REG_TX_COMMAND_TXB7 BIT(14) +#define REG_TX_COMMAND_TXB8 BIT(15) +#define REG_TX_COMMAND_TXT_BUFFER_COUNT GENMASK(19, 16)/* TX_PRIORITY registers */ #define REG_TX_PRIORITY_TXT1P GENMASK(2, 0)#define REG_TX_PRIORITY_TXT2P GENMASK(6, 4)#define REG_TX_PRIORITY_TXT3P GENMASK(10, 8)#define REG_TX_PRIORITY_TXT4P GENMASK(14, 12) +#define REG_TX_PRIORITY_TXT5P GENMASK(18, 16) +#define REG_TX_PRIORITY_TXT6P GENMASK(22, 20) +#define REG_TX_PRIORITY_TXT7P GENMASK(26, 24) +#define REG_TX_PRIORITY_TXT8P GENMASK(30, 28) -/* ERR_CAPT ALC registers */ +/* ERR_CAPT RETR_CTR ALC TS_INFO registers */ #define REG_ERR_CAPT_ERR_POS GENMASK(4, 0)#define REG_ERR_CAPT_ERR_TYPE GENMASK(7, 5) +#define REG_ERR_CAPT_RETR_CTR_VAL GENMASK(11, 8)#define REG_ERR_CAPT_ALC_BIT GENMASK(20, 16)#define REG_ERR_CAPT_ALC_ID_FIELD GENMASK(23, 21) +#define REG_ERR_CAPT_TS_BITS GENMASK(29, 24)/* TRV_DELAY SSP_CFG registers */ #define REG_TRV_DELAY_TRV_DELAY_VALUE GENMASK(6, 0)
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 15/29 can: peak_usb: pcan_dump_mem(): mark input prompt and data pointer as const
In reply to Marc Kleine-BuddeFrom: Stephane Grosjean <[email protected]>
Mark the input prompt and data pointer as const.
--- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 2 +- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/usb/peak_usb/pcan_usb_core.c +1 -1
@@ -57,7 +57,7 @@ MODULE_DEVICE_TABLE(usb, peak_usb_table);* dump memory */ #define DUMP_WIDTH 16 -void pcan_dump_mem (char *prompt,void *p,int l) +void pcan_dump_mem (const char *prompt,const void *p,int l) {pr_info ("%s dumping %s (%d bytes):\n" ,PCAN_USB_DRIVER_NAME , prompt ? prompt :"memory" , l);
drivers/net/can/usb/peak_usb/pcan_usb_core.h +1 -1
@@ -132,7 +132,7 @@ struct peak_usb_device {struct peak_usb_device *next_siblings; }; -void pcan_dump_mem (char *prompt,void *p,int l); +void pcan_dump_mem (const char *prompt,const void *p,int l);/* common timestamp management */ void peak_usb_init_time_ref(struct peak_time_ref *time_ref,
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 16/29 can: peak_usb: correction of an initially misnamed field name
In reply to Marc Kleine-BuddeFrom: Stephane Grosjean <[email protected]>
The data structure returned from the USB device contains a number flashed by the user and not the serial number of the device.
--- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 2 +- drivers/net/can/usb/peak_usb/pcan_usb_pro.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/usb/peak_usb/pcan_usb_pro.c +1 -1
@@ -439,7 +439,7 @@ static int pcan_usb_pro_get_device_id(struct peak_usb_device *dev,return err; pdn = (struct pcan_usb_pro_devid *)pc; - *device_id =le32_to_cpu (pdn->serial_num); + *device_id =le32_to_cpu (pdn->dev_num);return err; }
drivers/net/can/usb/peak_usb/pcan_usb_pro.h +1 -1
@@ -112,7 +112,7 @@ struct __packed pcan_usb_pro_devid {u8 data_type;u8 channel;__le16 dummy; -__le32 serial_num; +__le32 dev_num; };#define PCAN_USBPRO_LED_DEVICE 0x00
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 17/29 can: peak_usb: include support for a new MCU
In reply to Marc Kleine-BuddeFrom: Stephane Grosjean <[email protected]>
The CANFD-USB PCAN-USB FD interface undergoes an internal component change that requires a slight modification of its drivers, which leads them to dynamically use endpoint numbers provided by the interface itself. In addition to a change in the calls to the USB functions exported by the kernel, the detection of the USB interface dedicated to CAN must also be modified, as some PEAK-System devices support other interfaces than CAN.
--- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 68 ++++++++++++++++++---- 1 file changed, 58 insertions(+), 10 deletions(-)
drivers/net/can/usb/peak_usb/pcan_usb_fd.c +58 -10
@@ -33,6 +33,10 @@#define PCAN_UFD_RX_BUFFER_SIZE 2048#define PCAN_UFD_TX_BUFFER_SIZE 512 +/* struct pcan_ufd_fw_info::type */ +#define PCAN_USBFD_TYPE_STD 1 +#define PCAN_USBFD_TYPE_EXT 2/* includes EP numbers */ +/* read some versions info from the hw device */ struct __packed pcan_ufd_fw_info {__le16 size_of;/* sizeof this */
@@ -44,6 +48,13 @@ struct __packed pcan_ufd_fw_info {__le32 dev_id[2 ];/* "device id" per CAN */ __le32 ser_no;/* S/N */ __le32 flags;/* special functions */ + +/* extended data when type == PCAN_USBFD_TYPE_EXT */ +u8 cmd_out_ep;/* ep for cmd */ +u8 cmd_in_ep;/* ep for replies */ +u8 data_out_ep[2 ];/* ep for CANx TX */ +u8 data_in_ep;/* ep for CAN RX */ +u8 dummy[3 ]; };/* handle device specific info used by the netdevices */
@@ -171,6 +182,9 @@ static inline void *pcan_usb_fd_cmd_buffer(struct peak_usb_device *dev)/* send PCAN-USB Pro FD commands synchronously */ static int pcan_usb_fd_send_cmd (struct peak_usb_device *dev,void *cmd_tail) { +struct pcan_usb_fd_device *pdev = + container_of(dev, struct pcan_usb_fd_device, dev); +struct pcan_ufd_fw_info *fw_info = &pdev->usb_if->fw_info;void *cmd_head =pcan_usb_fd_cmd_buffer (dev);int err =0 ;u8 *packet_ptr;
@@ -200,7 +214,7 @@ static int pcan_usb_fd_send_cmd(struct peak_usb_device *dev, void *cmd_tail) do { err = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, - PCAN_USBPRO_EP_CMDOUT), + fw_info->cmd_out_ep), packet_ptr, packet_len, NULL, PCAN_UFD_CMD_TIMEOUT_MS); if (err) {
@@ -426,6 +440,9 @@ static int pcan_usb_fd_set_bittiming_fast(struct peak_usb_device *dev,static int pcan_usb_fd_restart_async (struct peak_usb_device *dev,struct urb *urb,u8 *buf) { +struct pcan_usb_fd_device *pdev = + container_of(dev, struct pcan_usb_fd_device, dev); +struct pcan_ufd_fw_info *fw_info = &pdev->usb_if->fw_info;u8 *pc = buf;/* build the entire cmds list in the provided buffer, to go back into
@@ -439,7 +456,7 @@ static int pcan_usb_fd_restart_async(struct peak_usb_device *dev,/* complete the URB */ usb_fill_bulk_urb (urb, dev->udev, -usb_sndbulkpipe (dev->udev,PCAN_USBPRO_EP_CMDOUT ), +usb_sndbulkpipe (dev->udev, fw_info->cmd_out_ep), buf, pc - buf, pcan_usb_pro_restart_complete, dev);
@@ -839,6 +856,15 @@ static int pcan_usb_fd_get_berr_counter(const struct net_device *netdev,return 0 ; } +/* probe function for all PCAN-USB FD family usb interfaces */ +static int pcan_usb_fd_probe (struct usb_interface *intf) +{ +struct usb_host_interface *iface_desc = &intf->altsetting[0 ]; + +/* CAN interface is always interface #0 */ +return iface_desc->desc.bInterfaceNumber; +} +/* stop interface (last chance before set bus off) */ static int pcan_usb_fd_stop (struct peak_usb_device *dev) {
@@ -860,6 +886,7 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev) {struct pcan_usb_fd_device *pdev = container_of(dev, struct pcan_usb_fd_device, dev); +struct pcan_ufd_fw_info *fw_info;int i, err = -ENOMEM ;/* do this for 1st channel only */
@@ -878,10 +905,12 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)/* number of ts msgs to ignore before taking one into account */ pdev->usb_if->cm_ignore_count =5 ; + fw_info = &pdev->usb_if->fw_info; + err =pcan_usb_pro_send_req (dev,PCAN_USBPRO_REQ_INFO ,PCAN_USBPRO_INFO_FW , - &pdev->usb_if->fw_info, -sizeof (pdev->usb_if->fw_info)); + fw_info, +sizeof (*fw_info));if (err) { dev_err(dev->netdev->dev.parent, "unable to read %s firmware info (err %d)\n",
@@ -895,14 +924,14 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)*/ dev_info (dev->netdev->dev.parent,"PEAK-System %s v%u fw v%u.%u.%u (%u channels)\n" , - dev->adapter->name, pdev->usb_if->fw_info.hw_version, - pdev->usb_if->fw_info.fw_version[0 ], - pdev->usb_if->fw_info.fw_version[1 ], - pdev->usb_if->fw_info.fw_version[2 ], + dev->adapter->name, fw_info->hw_version, + fw_info->fw_version[0 ], + fw_info->fw_version[1 ], + fw_info->fw_version[2 ], dev->adapter->ctrl_count);/* check for ability to switch between ISO/non-ISO modes */ -if (pdev->usb_if->fw_info.fw_version[0 ] >=2 ) { +if (fw_info->fw_version[0 ] >=2 ) {/* firmware >= 2.x supports ISO/non-ISO switching */ dev->can.ctrlmode_supported |=CAN_CTRLMODE_FD_NON_ISO ; }else {
@@ -910,6 +939,14 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev) dev->can.ctrlmode |=CAN_CTRLMODE_FD_NON_ISO ; } +/* if vendor rsp is of type 2, then it contains EP numbers to +* use for cmds pipes. If not, then default EP should be used. +*/ +if (fw_info->type !=cpu_to_le16 (PCAN_USBFD_TYPE_EXT )) { + fw_info->cmd_out_ep =PCAN_USBPRO_EP_CMDOUT ; + fw_info->cmd_in_ep =PCAN_USBPRO_EP_CMDIN ; + } +/* tell the hardware the can driver is running */ err =pcan_usb_fd_drv_loaded (dev,1 );if (err) {
@@ -930,12 +967,23 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)/* do a copy of the ctrlmode[_supported] too */ dev->can.ctrlmode = ppdev->dev.can.ctrlmode; dev->can.ctrlmode_supported = ppdev->dev.can.ctrlmode_supported; + + fw_info = &pdev->usb_if->fw_info; } pdev->usb_if->dev[dev->ctrl_idx] = dev; dev->device_number =le32_to_cpu (pdev->usb_if->fw_info.dev_id[dev->ctrl_idx]); +/* if vendor rsp is of type 2, then it contains EP numbers to +* use for data pipes. If not, then statically defined EP are used +* (see peak_usb_create_dev()). +*/ +if (fw_info->type ==cpu_to_le16 (PCAN_USBFD_TYPE_EXT )) { + dev->ep_msg_in = fw_info->data_in_ep; + dev->ep_msg_out = fw_info->data_out_ep[dev->ctrl_idx]; + } +/* set clock domain */ for (i =0 ; i <ARRAY_SIZE (pcan_usb_fd_clk_freq); i++)if (dev->adapter->clock.freq == pcan_usb_fd_clk_freq[i])
@@ -1091,7 +1139,7 @@ const struct peak_usb_adapter pcan_usb_fd = { .tx_buffer_size = PCAN_UFD_TX_BUFFER_SIZE,/* device callbacks */ - .intf_probe = pcan_usb_pro_probe, /* same as PCAN-USB Pro */ + .intf_probe = pcan_usb_fd_probe, .dev_init = pcan_usb_fd_init, .dev_exit = pcan_usb_fd_exit,
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 18/29 can: pch_can: do not report txerr and rxerr during bus-off
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/pch_can.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/can/pch_can.c +3 -3
@@ -496,6 +496,9 @@ static void pch_can_error(struct net_device *ndev, u32 status) cf->can_id |=CAN_ERR_BUSOFF ; priv->can.can_stats.bus_off++;can_bus_off (ndev); + }else { + cf->data[6 ] = errc &PCH_TEC ; + cf->data[7 ] = (errc &PCH_REC ) >>8 ; } errc =ioread32 (&priv->regs->errc);
@@ -556,9 +559,6 @@ static void pch_can_error(struct net_device *ndev, u32 status)break ; } - cf->data[6 ] = errc &PCH_TEC ; - cf->data[7 ] = (errc &PCH_REC ) >>8 ; - priv->can.state = state;netif_receive_skb (skb); }
Signature · 1 line
2.35.1
Re: [PATCH net-next 18/29] can: pch_can: do not report txerr and rxerr during bus-off
Quoted 42 lines · Marc Kleine-Budde
From: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
Fixes 0c78ab76a05c ("pch_can: Add setting TEC/REC statistics processing")Signed-off-by Vincent Mailhol <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>--- drivers/net/can/pch_can.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/net/can/pch_can.c +3
-3@@ -496,6 +496,9 @@ static void pch_can_error(struct net_device *ndev, u32 status) cf->can_id |=CAN_ERR_BUSOFF ; priv->can.can_stats.bus_off++;can_bus_off (ndev); + }else { + cf->data[6 ] = errc &PCH_TEC ; + cf->data[7 ] = (errc &PCH_REC ) >>8 ; } errc =ioread32 (&priv->regs->errc);@@ -556,9 +559,6 @@ static void pch_can_error(struct net_device *ndev, u32 status)break ; } - cf->data[6 ] = errc &PCH_TEC ; - cf->data[7 ] = (errc &PCH_REC ) >>8 ; - priv->can.state = state;netif_receive_skb (skb); }Signature · 1 line
2.35.1
Apologies if this has been reported already, I didn't see anything on the mailing lists.
This commit is now in -next as commit 3a5c7e4611dd ("can: pch_can: do not report txerr and rxerr during bus-off"), where it causes the following clang warning:
../drivers/net/can/pch_can.c:501:17: error: variable 'errc' is uninitialized when used here [-Werror,-Wuninitialized]
cf->data[6] = errc & PCH_TEC;
^~~~
../drivers/net/can/pch_can.c:484:10: note: initialize the variable 'errc' to silence this warning
u32 errc, lec;
^
= 01 error generated.
errc is initialized underneath this now, should it be hoisted or is there another fix?
Cheers,
Nathan
Marc Kleine-Budde
maintainerRe: [PATCH net-next 18/29] can: pch_can: do not report txerr and rxerr during bus-off
Quoted 58 lines · Nathan Chancellor
Quoted 42 lines · Marc Kleine-Budde
From: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
Fixes 0c78ab76a05c ("pch_can: Add setting TEC/REC statistics processing")Signed-off-by Vincent Mailhol <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>--- drivers/net/can/pch_can.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/net/can/pch_can.c +3
-3@@ -496,6 +496,9 @@ static void pch_can_error(struct net_device *ndev, u32 status) cf->can_id |=CAN_ERR_BUSOFF ; priv->can.can_stats.bus_off++;can_bus_off (ndev); + }else { + cf->data[6 ] = errc &PCH_TEC ; + cf->data[7 ] = (errc &PCH_REC ) >>8 ; } errc =ioread32 (&priv->regs->errc);@@ -556,9 +559,6 @@ static void pch_can_error(struct net_device *ndev, u32 status)break ; } - cf->data[6 ] = errc &PCH_TEC ; - cf->data[7 ] = (errc &PCH_REC ) >>8 ; - priv->can.state = state;netif_receive_skb (skb); }Signature · 1 line
2.35.1Apologies if this has been reported already, I didn't see anything on the mailing lists.
This commit is now in -next as commit
3a5c7e4611dd("can:pch_can: do not report txerr and rxerr during bus-off"), where it causes the following clang warning:
../drivers/net/can/pch_can.c:501:17: error: variable 'errc' is uninitialized when used here [-Werror,-Wuninitialized]cf->data[6] = errc & PCH_TEC; ^~~~ ../drivers/net/can/pch_can.c:484:10: note: initialize the variable 'errc' to silence this warning u32 errc, lec; ^ = 0
Quoted 4 lines
1 error generated.
errc is initialized underneath this now, should it be hoisted or is there another fix?
Doh! I'll send a fix.
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH net-next 18/29] can: pch_can: do not report txerr and rxerr during bus-off
Quoted 61 lines · Marc Kleine-Budde
Quoted 60 lines · Nathan Chancellor
Quoted 38 lines · Marc Kleine-Budde
From: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
Fixes 0c78ab76a05c ("pch_can: Add setting TEC/REC statistics processing")Signed-off-by Vincent Mailhol <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>--- drivers/net/can/pch_can.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/net/can/pch_can.c +3
-4@@ -496,6 +496,9 @@ static void pch_can_error(struct net_device *ndev, u32 status) cf->can_id |=CAN_ERR_BUSOFF ; priv->can.can_stats.bus_off++;can_bus_off (ndev); + }else { + cf->data[6 ] = errc &PCH_TEC ; + cf->data[7 ] = (errc &PCH_REC ) >>8 ; } errc =ioread32 (&priv->regs->errc);@@ -556,9 +559,6 @@ static void pch_can_error(struct net_device *ndev, u32 status)break ; } - cf->data[6 ] = errc &PCH_TEC ; - cf->data[7 ] = (errc &PCH_REC ) >>8 ; - priv->can.state = state;netif_receive_skb (skb); } --Quoted 4 lines
2.35.1
Apologies if this has been reported already, I didn't see anything on the mailing lists.
This commit is now in -next as commit
3a5c7e4611dd("can:pch_can: do not report txerr and rxerr during bus-off"), where it causes the following clang warning:
../drivers/net/can/pch_can.c:501:17: error: variable 'errc' is uninitialized when used here [-Werror,-Wuninitialized]cf->data[6] = errc & PCH_TEC; ^~~~ ../drivers/net/can/pch_can.c:484:10: note: initialize the variable 'errc' to silence this warning u32 errc, lec; ^ = 01 error generated.
Quoted 2 lines
Quoted 2 lines
errc is initialized underneath this now, should it be hoisted or is there another fix?
Thanks for reporting and sorry for the bug.
That said, I have one complaint: this type of warning is reported at W=2 *but* W=2 output is heavily polluted, mostly due to a false positive on linux/bits.h's GENMASK_INPUT_CHECK(). Under the current situation, the relevant warings become invisible with all the flooding.
I tried to send a patch to silence a huge chunk of the W=2 spam in [1] but it got rejected. I am sorry but even with the best intent, I might repeat a similar mistake in the future. The W=2 is just not usable.
[1] https://lore.kernel.org/all/[email protected]/
Quoted 1 line
Doh! I'll send a fix.
Thanks Marc for the patch!
Re: [PATCH net-next 18/29] can: pch_can: do not report txerr and rxerr during bus-off
Quoted 62 lines · Vincent MAILHOL
Quoted 61 lines · Marc Kleine-Budde
Quoted 60 lines · Nathan Chancellor
Quoted 38 lines · Marc Kleine-Budde
From: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
Fixes 0c78ab76a05c ("pch_can: Add setting TEC/REC statistics processing")Signed-off-by Vincent Mailhol <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>--- drivers/net/can/pch_can.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/net/can/pch_can.c +3
-4@@ -496,6 +496,9 @@ static void pch_can_error(struct net_device *ndev, u32 status) cf->can_id |=CAN_ERR_BUSOFF ; priv->can.can_stats.bus_off++;can_bus_off (ndev); + }else { + cf->data[6 ] = errc &PCH_TEC ; + cf->data[7 ] = (errc &PCH_REC ) >>8 ; } errc =ioread32 (&priv->regs->errc);@@ -556,9 +559,6 @@ static void pch_can_error(struct net_device *ndev, u32 status)break ; } - cf->data[6 ] = errc &PCH_TEC ; - cf->data[7 ] = (errc &PCH_REC ) >>8 ; - priv->can.state = state;netif_receive_skb (skb); } --Quoted 4 lines
2.35.1
Apologies if this has been reported already, I didn't see anything on the mailing lists.
This commit is now in -next as commit
3a5c7e4611dd("can:pch_can: do not report txerr and rxerr during bus-off"), where it causes the following clang warning:
../drivers/net/can/pch_can.c:501:17: error: variable 'errc' is uninitialized when used here [-Werror,-Wuninitialized]cf->data[6] = errc & PCH_TEC; ^~~~ ../drivers/net/can/pch_can.c:484:10: note: initialize the variable 'errc' to silence this warning u32 errc, lec; ^ = 01 error generated.
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
errc is initialized underneath this now, should it be hoisted or is there another fix?
Thanks for reporting and sorry for the bug.
No worries, it happens :)
Quoted 10 lines
That said, I have one complaint: this type of warning is reported at W=2 *but* W=2 output is heavily polluted, mostly due to a false positive on linux/bits.h's
GENMASK_INPUT_CHECK(). Under the current situation, the relevant warings become invisible with all the flooding.
I tried to send a patch to silence a huge chunk of the W=2 spam in [1] but it got rejected. I am sorry but even with the best intent, I might repeat a similar mistake in the future. The W=2 is just not usable.
Yes, having -Wmaybe-uninitialized in W=2 is unfortunate because these types of mistakes will continue to happen. I have been fighting this for a while and so has Dan Carpenter, who started a thread about it a couple of months ago but it doesn't seem like it really went anywhere:
https://lore.kernel.org/20220506091338.GE4031@kadam/
Cheers,
Nathan
Jakub Kicinski
maintainerRe: [PATCH net-next 18/29] can: pch_can: do not report txerr and rxerr during bus-off
Quoted 9 lines · On Thu, 21 Jul 2022 09:20:23 -0700 Nathan Chancellor wrote:
Quoted 9 lines
That said, I have one complaint: this type of warning is reported at W=2 *but* W=2 output is heavily polluted, mostly due to a false positive on linux/bits.h's
GENMASK_INPUT_CHECK(). Under the current situation, the relevant warings become invisible with all the flooding.
I tried to send a patch to silence a huge chunk of the W=2 spam in [1] but it got rejected. I am sorry but even with the best intent, I might repeat a similar mistake in the future. The W=2 is just not usable.
Quoted 8 lines
Quoted 1 line
Yes, having -Wmaybe-uninitialized in W=2 is unfortunate because these types of mistakes will continue to happen. I have been fighting this for a while and so has Dan Carpenter, who started a thread about it a couple of months ago but it doesn't seem like it really went anywhere:
FWIW it's reported by clang and was in fact reported in the netdev patchwork:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
DaveM must have not looked before pulling :S
PATCH 1/1 can: pch_can: initialize errc before using it
In reply to Nathan ChancellorAfter commit 3a5c7e4611dd, the variable errc is accessed before being initialized, c.f. below W=2 warning:
| In function 'pch_can_error', | inlined from 'pch_can_poll' at drivers/net/can/pch_can.c:739:4: | drivers/net/can/pch_can.c:501:29: warning: 'errc' may be used uninitialized [-Wmaybe-uninitialized] | 501 | cf->data[6] = errc & PCH_TEC; | | ^ | drivers/net/can/pch_can.c: In function 'pch_can_poll': | drivers/net/can/pch_can.c:484:13: note: 'errc' was declared here | 484 | u32 errc, lec; | | ^~~~
Moving errc initialization up solves this issue.
--- drivers/net/can/pch_can.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/pch_can.c +1 -1
@@ -489,6 +489,7 @@ static void pch_can_error(struct net_device *ndev, u32 status)if (!skb)return ; + errc =ioread32 (&priv->regs->errc);if (status &PCH_BUS_OFF ) {pch_can_set_tx_all (priv,0 );pch_can_set_rx_all (priv,0 );
@@ -502,7 +503,6 @@ static void pch_can_error(struct net_device *ndev, u32 status) cf->data[7 ] = (errc &PCH_REC ) >>8 ; } - errc =ioread32 (&priv->regs->errc);/* Warning interrupt. */ if (status &PCH_EWARN ) { state =CAN_STATE_ERROR_WARNING ;
Signature · 1 line
2.35.1
Re: [PATCH] can: pch_can: initialize errc before using it
Quoted 13 lines · Vincent Mailhol
After commit
3a5c7e4611dd, the variable errc is accessed before being initialized, c.f. below W=2 warning:| In function 'pch_can_error', | inlined from 'pch_can_poll' at drivers/net/can/pch_can.c:739:4: | drivers/net/can/pch_can.c:501:29: warning: 'errc' may be used uninitialized [-Wmaybe-uninitialized] | 501 | cf->data[6] = errc & PCH_TEC; | | ^ | drivers/net/can/pch_can.c: In function 'pch_can_poll': | drivers/net/can/pch_can.c:484:13: note: 'errc' was declared here | 484 | u32 errc, lec; | | ^~~~
Quoted 5 lines
Moving errc initialization up solves this issue.
Fixes 3a5c7e4611dd ("can: pch_can: do not report txerr and rxerr during bus-off")Reported-by Nathan Chancellor <[email protected]>Signed-off-by Vincent Mailhol <[email protected]>
Heh, Marc just sent the same patch. Just in case this one gets picked up instead:
Thanks for the quick response!
Quoted 27 lines
--- drivers/net/can/pch_can.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/can/pch_can.c +1
-1@@ -489,6 +489,7 @@ static void pch_can_error(struct net_device *ndev, u32 status)if (!skb)return ; + errc =ioread32 (&priv->regs->errc);if (status &PCH_BUS_OFF ) {pch_can_set_tx_all (priv,0 );pch_can_set_rx_all (priv,0 );@@ -502,7 +503,6 @@ static void pch_can_error(struct net_device *ndev, u32 status) cf->data[7 ] = (errc &PCH_REC ) >>8 ; } - errc =ioread32 (&priv->regs->errc);/* Warning interrupt. */ if (status &PCH_EWARN ) { state =CAN_STATE_ERROR_WARNING ;Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 19/29 can: rcar_can: do not report txerr and rxerr during bus-off
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/rcar/rcar_can.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/can/rcar/rcar_can.c +4 -4
@@ -232,11 +232,8 @@ static void rcar_can_error(struct net_device *ndev)if (eifr & (RCAR_CAN_EIFR_EWIF |RCAR_CAN_EIFR_EPIF )) { txerr =readb (&priv->regs->tecr); rxerr =readb (&priv->regs->recr); -if (skb) { +if (skb) cf->can_id |=CAN_ERR_CRTL ; - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; - } }if (eifr &RCAR_CAN_EIFR_BEIF ) {int rx_errors =0 , tx_errors =0 ;
@@ -336,6 +333,9 @@ static void rcar_can_error(struct net_device *ndev)can_bus_off (ndev);if (skb) cf->can_id |=CAN_ERR_BUSOFF ; + }else if (skb) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; }if (eifr &RCAR_CAN_EIFR_ORIF ) {netdev_dbg (priv->ndev,"Receive overrun error interrupt\n" );
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 20/29 can: sja1000: do not report txerr and rxerr during bus-off
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/sja1000/sja1000.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/can/sja1000/sja1000.c +4 -3
@@ -404,9 +404,6 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) txerr = priv->read_reg (priv,SJA1000_TXERR ); rxerr = priv->read_reg (priv,SJA1000_RXERR ); - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; -if (isrc &IRQ_DOI ) {/* data overrun interrupt */ netdev_dbg (dev,"data overrun interrupt\n" );
@@ -428,6 +425,10 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)else state =CAN_STATE_ERROR_ACTIVE ; } +if (state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + }if (isrc &IRQ_BEI ) {/* bus error interrupt */ priv->can.can_stats.bus_error++;
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 21/29 can: slcan: do not report txerr and rxerr during bus-off
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
alloc_can_err_skb() already sets cf to NULL if the allocation fails [1], so the redundant cf = NULL assignment gets removed.
[1] https://elixir.bootlin.com/linux/latest/source/drivers/net/can/dev/skb.c#L187
--- drivers/net/can/slcan/slcan-core.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/net/can/slcan/slcan-core.c +5 -7
@@ -306,19 +306,17 @@ static void slc_bump_state(struct slcan *sl)return ; skb =alloc_can_err_skb (dev, &cf); -if (skb) { - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; - }else { - cf =NULL ; - } tx_state = txerr >= rxerr ? state :0 ; rx_state = txerr <= rxerr ? state :0 ;can_change_state (dev, cf, tx_state, rx_state); -if (state ==CAN_STATE_BUS_OFF ) +if (state ==CAN_STATE_BUS_OFF ) {can_bus_off (dev); + }else if (skb) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + }if (skb)netif_rx (skb);
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 22/29 can: hi311x: do not report txerr and rxerr during bus-off
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/spi/hi311x.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/can/spi/hi311x.c +3 -2
@@ -667,8 +667,6 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id) txerr =hi3110_read (spi,HI3110_READ_TEC ); rxerr =hi3110_read (spi,HI3110_READ_REC ); - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; tx_state = txerr >= rxerr ? new_state :0 ; rx_state = txerr <= rxerr ? new_state :0 ;can_change_state (net, cf, tx_state, rx_state);
@@ -681,6 +679,9 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id)hi3110_hw_sleep (spi);break ; } + }else { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; } }
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 23/29 can: sun4i_can: do not report txerr and rxerr during bus-off
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/sun4i_can.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/can/sun4i_can.c +4 -5
@@ -535,11 +535,6 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status) rxerr = (errc >>16 ) &0xFF ; txerr = errc &0xFF ; -if (skb) { - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; - } -if (isrc &SUN4I_INT_DATA_OR ) {/* data overrun interrupt */ netdev_dbg (dev,"data overrun interrupt\n" );
@@ -570,6 +565,10 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)else state =CAN_STATE_ERROR_ACTIVE ; } +if (skb && state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + }if (isrc &SUN4I_INT_BUS_ERR ) {/* bus error interrupt */ netdev_dbg (dev,"bus error interrupt\n" );
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 24/29 can: kvaser_usb_hydra: do not report txerr and rxerr during bus-off
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +8 -4
@@ -917,8 +917,10 @@ static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv, new_state < CAN_STATE_BUS_OFF) priv->can.can_stats.restarts++; - cf->data[6 ] = bec->txerr; - cf->data[7 ] = bec->rxerr; +if (new_state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = bec->txerr; + cf->data[7 ] = bec->rxerr; + }netif_rx (skb); }
@@ -1069,8 +1071,10 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv *priv, shhwtstamps->hwtstamp = hwtstamp; cf->can_id |=CAN_ERR_BUSERROR ; - cf->data[6 ] = bec.txerr; - cf->data[7 ] = bec.rxerr; +if (new_state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = bec.txerr; + cf->data[7 ] = bec.rxerr; + }netif_rx (skb);
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 25/29 can: kvaser_usb_leaf: do not report txerr and rxerr during bus-off
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +4 -2
@@ -853,8 +853,10 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev,break ; } - cf->data[6 ] = es->txerr; - cf->data[7 ] = es->rxerr; +if (new_state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = es->txerr; + cf->data[7 ] = es->rxerr; + }netif_rx (skb); }
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 26/29 can: usb_8dev: do not report txerr and rxerr during bus-off
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
During bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/usb/usb_8dev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/can/usb/usb_8dev.c +4 -3
@@ -438,9 +438,10 @@ static void usb_8dev_rx_err_msg(struct usb_8dev_priv *priv,if (rx_errors) stats->rx_errors++; - - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; +if (priv->can.state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + } priv->bec.txerr = txerr; priv->bec.rxerr = rxerr;
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 27/29 can: error: specify the values of data[5..7] of CAN error frames
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Currently, data[5..7] of struct can_frame, when used as a CAN error frame, are defined as being "controller specific". Device specific behaviours are problematic because it prevents someone from writing code which is portable between devices.
As a matter of fact, data[5] is never used, data[6] is always used to report TX error counter and data[7] is always used to report RX error counter. can-utils also relies on this.
This patch updates the comment in the uapi header to specify that data[5] is reserved (and thus should not be used) and that data[6..7] are used for error counters.
--- include/uapi/linux/can/error.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/uapi/linux/can/error.h +4 -1
@@ -120,6 +120,9 @@#define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70/* 0111 0000 */ #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80/* 1000 0000 */ -/* controller specific additional information / data[5..7] */ +/* data[5] is reserved (do not use) */ + +/* TX error counter / data[6] */ +/* RX error counter / data[7] */ #endif /* _UAPI_CAN_ERROR_H */
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 28/29 can: add CAN_ERR_CNT flag to notify availability of error counter
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Add a dedicated flag in uapi/linux/can/error.h to notify the userland that fields data[6] and data[7] of the CAN error frame were respectively populated with the tx and rx error counters.
For all driver tree-wide, set up this flags whenever needed.
--- drivers/net/can/c_can/c_can_main.c | 6 +++--- drivers/net/can/cc770/cc770.c | 1 + drivers/net/can/ctucanfd/ctucanfd_base.c | 5 +++-- drivers/net/can/grcan.c | 1 + drivers/net/can/ifi_canfd/ifi_canfd.c | 4 ++-- drivers/net/can/janz-ican3.c | 4 ++-- drivers/net/can/kvaser_pciefd.c | 2 +- drivers/net/can/m_can/m_can.c | 4 ++-- drivers/net/can/pch_can.c | 1 + drivers/net/can/peak_canfd/peak_canfd.c | 6 +++--- drivers/net/can/rcar/rcar_can.c | 1 + drivers/net/can/rcar/rcar_canfd.c | 4 ++-- drivers/net/can/sja1000/sja1000.c | 1 + drivers/net/can/slcan/slcan-core.c | 1 + drivers/net/can/spi/hi311x.c | 1 + drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 1 + drivers/net/can/sun4i_can.c | 1 + drivers/net/can/ti_hecc.c | 1 + drivers/net/can/usb/esd_usb.c | 3 ++- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 2 ++ drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 1 + drivers/net/can/usb/peak_usb/pcan_usb.c | 1 + drivers/net/can/usb/usb_8dev.c | 1 + drivers/net/can/xilinx_can.c | 1 + include/uapi/linux/can/error.h | 2 ++ 25 files changed, 38 insertions(+), 18 deletions(-)
drivers/net/can/c_can/c_can_main.c +3 -3
@@ -952,14 +952,14 @@ static int c_can_handle_state_change(struct net_device *dev,switch (error_type) {case C_CAN_NO_ERROR : - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] =CAN_ERR_CRTL_ACTIVE ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr;break ;case C_CAN_ERROR_WARNING :/* error warning state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -969,7 +969,7 @@ static int c_can_handle_state_change(struct net_device *dev,break ;case C_CAN_ERROR_PASSIVE :/* error passive state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ;if (rx_err_passive) cf->data[1 ] |=CAN_ERR_CRTL_RX_PASSIVE ;if (bec.txerr >127 )
drivers/net/can/cc770/cc770.c +1 -0
@@ -512,6 +512,7 @@ static int cc770_err(struct net_device *dev, u8 status)/* Use extended functions of the CC770 */ if (priv->control_normal_mode &CTRL_EAF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] =cc770_read_reg (priv, tx_error_counter); cf->data[7 ] =cc770_read_reg (priv, rx_error_counter); }
drivers/net/can/ctucanfd/ctucanfd_base.c +3 -2
@@ -847,7 +847,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)case CAN_STATE_ERROR_PASSIVE : priv->can.can_stats.error_passive++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.rxerr >127 ) ?CAN_ERR_CRTL_RX_PASSIVE :CAN_ERR_CRTL_TX_PASSIVE ;
@@ -858,7 +858,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)case CAN_STATE_ERROR_WARNING : priv->can.can_stats.error_warning++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] |= (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -867,6 +867,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr) }break ;case CAN_STATE_ERROR_ACTIVE : + cf->can_id |=CAN_ERR_CNT ; cf->data[1 ] =CAN_ERR_CRTL_ACTIVE ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr;
drivers/net/can/grcan.c +1 -0
@@ -671,6 +671,7 @@ static void grcan_err(struct net_device *dev, u32 sources, u32 status)/* There are no others at this point */ break ; } + cf.can_id |=CAN_ERR_CNT ; cf.data[6 ] = txerr; cf.data[7 ] = rxerr; priv->can.state = state;
drivers/net/can/ifi_canfd/ifi_canfd.c +2 -2
@@ -492,7 +492,7 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,switch (new_state) {case CAN_STATE_ERROR_WARNING :/* error warning state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -501,7 +501,7 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,break ;case CAN_STATE_ERROR_PASSIVE :/* error passive state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] |=CAN_ERR_CRTL_RX_PASSIVE ;if (bec.txerr >127 ) cf->data[1 ] |=CAN_ERR_CRTL_TX_PASSIVE ;
drivers/net/can/janz-ican3.c +2 -2
@@ -1127,7 +1127,7 @@ static int ican3_handle_cevtind(struct ican3_dev *mod, struct ican3_msg *msg)/* bus error interrupt */ if (isrc ==CEVTIND_BEI ) { mod->can.can_stats.bus_error++; - cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR ; + cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR |CAN_ERR_CNT ;switch (ecc &ECC_MASK ) {case ECC_BIT :
@@ -1153,7 +1153,7 @@ static int ican3_handle_cevtind(struct ican3_dev *mod, struct ican3_msg *msg)if (state != mod->can.state && (state ==CAN_STATE_ERROR_WARNING || state ==CAN_STATE_ERROR_PASSIVE )) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ;if (state ==CAN_STATE_ERROR_WARNING ) { mod->can.can_stats.error_warning++; cf->data[1] = (txerr > rxerr) ?
drivers/net/can/kvaser_pciefd.c +1 -1
@@ -1306,7 +1306,7 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, shhwtstamps->hwtstamp =ns_to_ktime (div_u64 (p->timestamp *1000 , can->kv_pcie->freq_to_ticks_div)); - cf->can_id |=CAN_ERR_BUSERROR ; + cf->can_id |=CAN_ERR_BUSERROR |CAN_ERR_CNT ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr;
drivers/net/can/m_can/m_can.c +2 -2
@@ -741,7 +741,7 @@ static int m_can_handle_state_change(struct net_device *dev,switch (new_state) {case CAN_STATE_ERROR_WARNING :/* error warning state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -750,7 +750,7 @@ static int m_can_handle_state_change(struct net_device *dev,break ;case CAN_STATE_ERROR_PASSIVE :/* error passive state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; ecr =m_can_read (cdev,M_CAN_ECR );if (ecr &ECR_RP ) cf->data[1 ] |=CAN_ERR_CRTL_RX_PASSIVE ;
drivers/net/can/pch_can.c +1 -0
@@ -497,6 +497,7 @@ static void pch_can_error(struct net_device *ndev, u32 status) priv->can.can_stats.bus_off++;can_bus_off (ndev); }else { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = errc &PCH_TEC ; cf->data[7 ] = (errc &PCH_REC ) >>8 ; }
drivers/net/can/peak_canfd/peak_canfd.c +3 -3
@@ -373,7 +373,7 @@ static int pucan_handle_status(struct peak_canfd_priv *priv, priv->can.state =CAN_STATE_ERROR_PASSIVE ; priv->can.can_stats.error_passive++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (priv->bec.txerr > priv->bec.rxerr) ?CAN_ERR_CRTL_TX_PASSIVE :CAN_ERR_CRTL_RX_PASSIVE ;
@@ -386,7 +386,7 @@ static int pucan_handle_status(struct peak_canfd_priv *priv, priv->can.state =CAN_STATE_ERROR_WARNING ; priv->can.can_stats.error_warning++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (priv->bec.txerr > priv->bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -430,7 +430,7 @@ static int pucan_handle_cache_critical(struct peak_canfd_priv *priv)return -ENOMEM ; } - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] =CAN_ERR_CRTL_RX_OVERFLOW ; cf->data[6 ] = priv->bec.txerr;
drivers/net/can/rcar/rcar_can.c +1 -0
@@ -334,6 +334,7 @@ static void rcar_can_error(struct net_device *ndev)if (skb) cf->can_id |=CAN_ERR_BUSOFF ; }else if (skb) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/rcar/rcar_canfd.c +2 -2
@@ -1052,7 +1052,7 @@ static void rcar_canfd_error(struct net_device *ndev, u32 cerfl,netdev_dbg (ndev,"Error warning interrupt\n" ); priv->can.state =CAN_STATE_ERROR_WARNING ; priv->can.can_stats.error_warning++; - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = txerr > rxerr ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ; cf->data[6 ] = txerr;
@@ -1062,7 +1062,7 @@ static void rcar_canfd_error(struct net_device *ndev, u32 cerfl,netdev_dbg (ndev,"Error passive interrupt\n" ); priv->can.state =CAN_STATE_ERROR_PASSIVE ; priv->can.can_stats.error_passive++; - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = txerr > rxerr ?CAN_ERR_CRTL_TX_PASSIVE :CAN_ERR_CRTL_RX_PASSIVE ; cf->data[6 ] = txerr;
drivers/net/can/sja1000/sja1000.c +1 -0
@@ -426,6 +426,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) state =CAN_STATE_ERROR_ACTIVE ; }if (state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/slcan/slcan-core.c +1 -0
@@ -314,6 +314,7 @@ static void slc_bump_state(struct slcan *sl)if (state ==CAN_STATE_BUS_OFF ) {can_bus_off (dev); }else if (skb) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/spi/hi311x.c +1 -0
@@ -680,6 +680,7 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id)break ; } }else { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -0
@@ -1099,6 +1099,7 @@ static int mcp251xfd_handle_cerrif(struct mcp251xfd_priv *priv) err =mcp251xfd_get_berr_counter (priv->ndev, &bec);if (err)return err; + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; }
drivers/net/can/sun4i_can.c +1 -0
@@ -566,6 +566,7 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status) state =CAN_STATE_ERROR_ACTIVE ; }if (skb && state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/ti_hecc.c +1 -0
@@ -662,6 +662,7 @@ static void ti_hecc_change_state(struct net_device *ndev,can_change_state (priv->ndev, cf, tx_state, rx_state);if (max (tx_state, rx_state) !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] =hecc_read (priv,HECC_CANTEC ); cf->data[7 ] =hecc_read (priv,HECC_CANREC ); }
drivers/net/can/usb/esd_usb.c +2 -1
@@ -265,7 +265,8 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, priv->can.can_stats.bus_error++; stats->rx_errors++; - cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR ; + cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR | +CAN_ERR_CNT ;switch (ecc &SJA1000_ECC_MASK ) {case SJA1000_ECC_BIT :
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +2 -0
@@ -918,6 +918,7 @@ static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv, priv->can.can_stats.restarts++;if (new_state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = bec->txerr; cf->data[7 ] = bec->rxerr; }
@@ -1072,6 +1073,7 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv *priv, cf->can_id |=CAN_ERR_BUSERROR ;if (new_state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; }
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +1 -0
@@ -854,6 +854,7 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev, }if (new_state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = es->txerr; cf->data[7 ] = es->rxerr; }
drivers/net/can/usb/peak_usb/pcan_usb.c +1 -0
@@ -506,6 +506,7 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n,/* Supply TX/RX error counters in case of * controller error. */ + cf->can_id =CAN_ERR_CNT ; cf->data[6 ] = mc->pdev->bec.txerr; cf->data[7 ] = mc->pdev->bec.rxerr; }
drivers/net/can/usb/usb_8dev.c +1 -0
@@ -439,6 +439,7 @@ static void usb_8dev_rx_err_msg(struct usb_8dev_priv *priv,if (rx_errors) stats->rx_errors++;if (priv->can.state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/xilinx_can.c +1 -0
@@ -965,6 +965,7 @@ static void xcan_set_error_state(struct net_device *ndev,can_change_state (ndev, cf, tx_state, rx_state);if (cf) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
include/uapi/linux/can/error.h +2 -0
@@ -57,6 +57,8 @@#define CAN_ERR_BUSOFF 0x00000040U/* bus off */ #define CAN_ERR_BUSERROR 0x00000080U/* bus error (may flood!) */ #define CAN_ERR_RESTARTED 0x00000100U/* controller restarted */ +#define CAN_ERR_CNT 0x00000200U/* TX error counter / data[6] */ +/* RX error counter / data[7] */ /* arbitration lost in bit ... / data[0] */ #define CAN_ERR_LOSTARB_UNSPEC 0x00/* unspecified */
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerPATCH 29/29 can: error: add definitions for the different CAN error thresholds
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Currently, drivers are using magic numbers to derive the CAN error states from the error counter. Add three macro declarations to remediate this.
For reference, the error-active, error-passive and bus-off are defined in ISO 11898, section 12.1.4.2 "Error counting". Although ISO 11898 does not define error-warning state, this extra value is also commonly used and is thus also added.
--- include/uapi/linux/can/error.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/uapi/linux/can/error.h +13 -0
@@ -127,4 +127,17 @@/* TX error counter / data[6] */ /* RX error counter / data[7] */ +/* CAN state thresholds +* +* Error counter Error state +* ----------------------------------- +* 0 - 95 Error-active +* 96 - 127 Error-warning +* 128 - 255 Error-passive +* 256 and greater Bus-off +*/ +#define CAN_ERROR_WARNING_THRESHOLD 96 +#define CAN_ERROR_PASSIVE_THRESHOLD 128 +#define CAN_BUS_OFF_THRESHOLD 256 +#endif /* _UAPI_CAN_ERROR_H */
Signature · 1 line
2.35.1