pull-request: can-next 2025-09-25
Subsystems (7)
Marc Kleine-Budde
maintainercover pull-request: can-next 2025-09-25
Hello netdev-team,
this is a pull request of 48 patches for net-next/main, which supersedes tags/linux-can-next-for-6.18-20250923.
The 1st patch is by Xichao Zhao and converts ns_to_ktime() to us_to_ktime() in the m_can driver.
Vincent Mailhol contributes 2 patches: Updating the MAINTAINERS and mailmap files to Vincent's new email address and sorting the includes in the CAN helper library alphabeticaly.
Stéphane Grosjean's patch modifies all peak CAN drivers and the mailmap to reflect Stéphane's new email address.
4 patches by Biju Das update the CAN-FD handling in the rcar_canfd driver.
Followed by 11 patches by Geert Uytterhoeven updating and improving the rcar_can driver.
Stefan Mätje contributes 2 patches for the esd_usb driver updating the error messages.
The next 3 patch series are all by Vincent Mailhol: 3 patches to optimize the size of struct raw_sock and struct uniqframe. 4 patches which rework the CAN MTU logic as preparation for CAN-XL interfaces. And finally 20 patches that prepare and refactor the CAN netlink code for the upcoming CAN-XL support.
regards,
Marc
---
The following changes since commit fc006f5478fcf07d79b35e9dcdc51ecd11a6bf82:
net: phy: micrel: Update Kconfig help text (2025-09-12 17:34:27 -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-6.18-20250924
for you to fetch changes up to 896d52af944107c0644c12378741af9a3834c514:
Merge patch series "can: netlink: preparation before introduction of CAN XL step 3/3" (2025-09-24 17:10:01 +0200)
----------------------------------------------------------------
linux-can-next-for-6.18-20250924
----------------------------------------------------------------
Biju Das (4):
can: rcar_canfd: Update bit rate constants for RZ/G3E and R-Car Gen4
can: rcar_canfd: Update RCANFD_CFG_* macros
can: rcar_canfd: Simplify nominal bit rate config
can: rcar_canfd: Simplify data bit rate config
Geert Uytterhoeven (11):
can: rcar_can: Consistently use ndev for net_device pointers
can: rcar_can: Add helper variable dev to rcar_can_probe()
can: rcar_can: Convert to Runtime PM
can: rcar_can: Convert to BIT()
can: rcar_can: Convert to GENMASK()
can: rcar_can: CTLR bitfield conversion
can: rcar_can: TFCR bitfield conversion
can: rcar_can: BCR bitfield conversion
can: rcar_can: Mailbox bitfield conversion
can: rcar_can: Do not print alloc_candev() failures
can: rcar_can: Convert to %pe
Marc Kleine-Budde (6):
Merge patch series "can: rcar_canfd: R-Car CANFD Improvements"
Merge patch series "can: rcar_can: Miscellaneous cleanups and improvements" Merge patch series "can: esd_usb: Fixes and improvements"
Merge patch series "can: raw: optimize the sizes of struct uniqframe and struct raw_sock" Merge patch series "can: rework the CAN MTU logic (CAN XL preparation step 2/3)" Merge patch series "can: netlink: preparation before introduction of CAN XL step 3/3"
Stefan Mätje (2):
can: esd_usb: Rework display of error messages
can: esd_usb: Avoid errors triggered from USB disconnect
Stéphane Grosjean (1):
can: peak: Modification of references to email accounts being deleted
Vincent Mailhol (29):
MAINTAINERS: update Vincent Mailhol's email address
can: dev: sort includes by alphabetical order
can: raw: reorder struct uniqframe's members to optimise packing
can: raw: use bitfields to store flags in struct raw_sock
can: raw: reorder struct raw_sock's members to optimise packing
can: annotate mtu accesses with READ_ONCE()
can: dev: turn can_set_static_ctrlmode() into a non-inline function
can: populate the minimum and maximum MTU values
can: enable CAN XL for virtual CAN devices by default
can: dev: move struct data_bittiming_params to linux/can/bittiming.h
can: dev: make can_get_relative_tdco() FD agnostic and move it to bittiming.h
can: netlink: document which symbols are FD specific
can: netlink: refactor can_validate_bittiming()
can: netlink: add can_validate_tdc()
can: netlink: add can_validate_databittiming()
can: netlink: refactor CAN_CTRLMODE_TDC_{AUTO,MANUAL} flag reset logic
can: netlink: remove useless check in can_tdc_changelink()
can: netlink: make can_tdc_changelink() FD agnostic
can: netlink: add can_dtb_changelink()
can: netlink: add can_ctrlmode_changelink()
can: netlink: make can_tdc_get_size() FD agnostic
can: netlink: add can_data_bittiming_get_size()
can: netlink: add can_bittiming_fill_info()
can: netlink: add can_bittiming_const_fill_info()
can: netlink: add can_bitrate_const_fill_info()
can: netlink: make can_tdc_fill_info() FD agnostic
can: calc_bittiming: make can_calc_tdco() FD agnostic
can: dev: add can_get_ctrlmode_str()
can: netlink: add userland error messages
Xichao Zhao (1):
can: m_can: use us_to_ktime() where appropriate
.mailmap | 3 + MAINTAINERS | 4 +- drivers/net/can/dev/calc_bittiming.c | 10 +- drivers/net/can/dev/dev.c | 80 +++- drivers/net/can/dev/netlink.c | 628 ++++++++++++++++---------- drivers/net/can/m_can/m_can.c | 6 +- drivers/net/can/peak_canfd/peak_canfd.c | 4 +- drivers/net/can/peak_canfd/peak_canfd_user.h | 4 +- drivers/net/can/peak_canfd/peak_pciefd_main.c | 6 +- drivers/net/can/rcar/rcar_can.c | 290 ++++++------ drivers/net/can/rcar/rcar_canfd.c | 84 ++-- drivers/net/can/sja1000/peak_pci.c | 6 +- drivers/net/can/sja1000/peak_pcmcia.c | 8 +- drivers/net/can/usb/esd_usb.c | 64 ++- drivers/net/can/usb/peak_usb/pcan_usb.c | 6 +- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 6 +- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 4 +- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 3 +- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 4 +- drivers/net/can/usb/peak_usb/pcan_usb_pro.h | 4 +- drivers/net/can/vcan.c | 2 +- drivers/net/can/vxcan.c | 2 +- include/linux/can/bittiming.h | 48 +- include/linux/can/dev.h | 66 +-- include/linux/can/dev/peak_canfd.h | 4 +- include/uapi/linux/can/netlink.h | 14 +- net/can/af_can.c | 2 +- net/can/isotp.c | 2 +- net/can/raw.c | 67 +-- 29 files changed, 848 insertions(+), 583 deletions(-)
Marc Kleine-Budde
maintainerPATCH 1/48 can: m_can: use us_to_ktime() where appropriate
From: Xichao Zhao <[email protected]>
The tx_coalesce_usecs_irq are more suitable for using the us_to_ktime(). This can make the code more concise and enhance readability.
--- drivers/net/can/m_can/m_can.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/can/m_can/m_can.c +2 -4
@@ -2213,11 +2213,9 @@ static int m_can_set_coalesce(struct net_device *dev, cdev->tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;if (cdev->rx_coalesce_usecs_irq) - cdev->irq_timer_wait = -ns_to_ktime (cdev->rx_coalesce_usecs_irq *NSEC_PER_USEC ); + cdev->irq_timer_wait =us_to_ktime (cdev->rx_coalesce_usecs_irq);else - cdev->irq_timer_wait = -ns_to_ktime (cdev->tx_coalesce_usecs_irq *NSEC_PER_USEC ); + cdev->irq_timer_wait =us_to_ktime (cdev->tx_coalesce_usecs_irq);return 0 ; }
base-commit: fc006f5478fcf07d79b35e9dcdc51ecd11a6bf82
Signature · 1 line
2.51.0
Re: [PATCH net-next 01/48] can: m_can: use us_to_ktime() where appropriate
This series was applied to netdev/net-next.git (main) by Marc Kleine-Budde <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Marc Kleine-Budde <[email protected]>:
Quoted 6 lines · On Thu, 25 Sep 2025 14:07:38 +0200 you wrote:
From: Xichao Zhao <[email protected]>
The
tx_coalesce_usecs_irqare more suitable for using theus_to_ktime(). This can make the code more concise and enhance readability.
Quoted 7 lines
Signed-off-by Xichao Zhao <[email protected]>Reviewed-by Vincent Mailhol <[email protected]>[mkl: remove not needed line break]Signed-off-by Marc Kleine-Budde <[email protected]>[...]
Here is the summary with links:
- [net-next,01/48] can: m_can: use us_to_ktime() where appropriate
https://git.kernel.org/netdev/net-next/c/646cb48d4477 - [net-next,02/48] MAINTAINERS: update Vincent Mailhol's email address https://git.kernel.org/netdev/net-next/c/39b8e0fef155 - [net-next,03/48] can: dev: sort includes by alphabetical order https://git.kernel.org/netdev/net-next/c/4827dcc19cc7 - [net-next,04/48] can: peak: Modification of references to email accounts being deleted https://git.kernel.org/netdev/net-next/c/f1880f9cc147 - [net-next,05/48] can: rcar_canfd: Update bit rate constants for RZ/G3E and R-Car Gen4 https://git.kernel.org/netdev/net-next/c/100fafc3e461 - [net-next,06/48] can: rcar_canfd: Update RCANFD_CFG_* macros https://git.kernel.org/netdev/net-next/c/726213c8e79a - [net-next,07/48] can: rcar_canfd: Simplify nominal bit rate config https://git.kernel.org/netdev/net-next/c/02d274adf485 - [net-next,08/48] can: rcar_canfd: Simplify data bit rate config https://git.kernel.org/netdev/net-next/c/33815032b0a6 - [net-next,09/48] can: rcar_can: Consistently use ndev for net_device pointers https://git.kernel.org/netdev/net-next/c/7abf70449369 - [net-next,10/48] can: rcar_can: Add helper variable dev to rcar_can_probe() https://git.kernel.org/netdev/net-next/c/f7844496cba4 - [net-next,11/48] can: rcar_can: Convert to Runtime PM https://git.kernel.org/netdev/net-next/c/1bbff1762638 - [net-next,12/48] can: rcar_can: Convert to BIT() https://git.kernel.org/netdev/net-next/c/bcf4dee47fdf - [net-next,13/48] can: rcar_can: Convert to GENMASK() https://git.kernel.org/netdev/net-next/c/28f3617c392a - [net-next,14/48] can: rcar_can: CTLR bitfield conversion https://git.kernel.org/netdev/net-next/c/669abc406812 - [net-next,15/48] can: rcar_can: TFCR bitfield conversion https://git.kernel.org/netdev/net-next/c/75f319455d05 - [net-next,16/48] can: rcar_can: BCR bitfield conversion https://git.kernel.org/netdev/net-next/c/8d930226d3e5 - [net-next,17/48] can: rcar_can: Mailbox bitfield conversion https://git.kernel.org/netdev/net-next/c/729b1c69b8fa - [net-next,18/48] can: rcar_can: Do not print alloc_candev() failures https://git.kernel.org/netdev/net-next/c/5317225e015c - [net-next,19/48] can: rcar_can: Convert to %pe https://git.kernel.org/netdev/net-next/c/7207788031b9 - [net-next,20/48] can: esd_usb: Rework display of error messages https://git.kernel.org/netdev/net-next/c/c6e07521431c - [net-next,21/48] can: esd_usb: Avoid errors triggered from USB disconnect https://git.kernel.org/netdev/net-next/c/37dc3ea4d2a2 - [net-next,22/48] can: raw: reorder struct uniqframe's members to optimise packing https://git.kernel.org/netdev/net-next/c/fc8418eca43d - [net-next,23/48] can: raw: use bitfields to store flags in struct raw_sock https://git.kernel.org/netdev/net-next/c/890e5198a6e5 - [net-next,24/48] can: raw: reorder struct raw_sock's members to optimise packing https://git.kernel.org/netdev/net-next/c/a146cfaaa0dd - [net-next,25/48] can: annotate mtu accesses with READ_ONCE() https://git.kernel.org/netdev/net-next/c/c67732d06786 - [net-next,26/48] can: dev: turn can_set_static_ctrlmode() into a non-inline function https://git.kernel.org/netdev/net-next/c/7c7da8aa3fd6 - [net-next,27/48] can: populate the minimum and maximum MTU values https://git.kernel.org/netdev/net-next/c/23049938605b - [net-next,28/48] can: enable CAN XL for virtual CAN devices by default https://git.kernel.org/netdev/net-next/c/b98aceb65e2c - [net-next,29/48] can: dev: move struct data_bittiming_params to linux/can/bittiming.h https://git.kernel.org/netdev/net-next/c/cc470fcf1d59 - [net-next,30/48] can: dev: make can_get_relative_tdco() FD agnostic and move it to bittiming.h https://git.kernel.org/netdev/net-next/c/7208385df784 - [net-next,31/48] can: netlink: document which symbols are FD specific https://git.kernel.org/netdev/net-next/c/94040a8f4845 - [net-next,32/48] can: netlink: refactor can_validate_bittiming() https://git.kernel.org/netdev/net-next/c/f5ae5a75412d - [net-next,33/48] can: netlink: add can_validate_tdc() https://git.kernel.org/netdev/net-next/c/b23a8425cba5 - [net-next,34/48] can: netlink: add can_validate_databittiming() https://git.kernel.org/netdev/net-next/c/3820a415bece - [net-next,35/48] can: netlink: refactor CAN_CTRLMODE_TDC_{AUTO,MANUAL} flag reset logic https://git.kernel.org/netdev/net-next/c/45be26b7e35a - [net-next,36/48] can: netlink: remove useless check in can_tdc_changelink() https://git.kernel.org/netdev/net-next/c/2b0a6930ae7c - [net-next,37/48] can: netlink: make can_tdc_changelink() FD agnostic https://git.kernel.org/netdev/net-next/c/530c918f8cf6 - [net-next,38/48] can: netlink: add can_dtb_changelink() https://git.kernel.org/netdev/net-next/c/2e543af483a9 - [net-next,39/48] can: netlink: add can_ctrlmode_changelink() https://git.kernel.org/netdev/net-next/c/e1a5cd9d6665 - [net-next,40/48] can: netlink: make can_tdc_get_size() FD agnostic https://git.kernel.org/netdev/net-next/c/63888a578016 - [net-next,41/48] can: netlink: add can_data_bittiming_get_size() https://git.kernel.org/netdev/net-next/c/d5f45ef88ba4 - [net-next,42/48] can: netlink: add can_bittiming_fill_info() https://git.kernel.org/netdev/net-next/c/e1a2be5a6967 - [net-next,43/48] can: netlink: add can_bittiming_const_fill_info() https://git.kernel.org/netdev/net-next/c/aaeebdb7a723 - [net-next,44/48] can: netlink: add can_bitrate_const_fill_info() https://git.kernel.org/netdev/net-next/c/d5ee934ee19b - [net-next,45/48] can: netlink: make can_tdc_fill_info() FD agnostic https://git.kernel.org/netdev/net-next/c/e72f1ba700e3 - [net-next,46/48] can: calc_bittiming: make can_calc_tdco() FD agnostic https://git.kernel.org/netdev/net-next/c/6ffc1230d3a7 - [net-next,47/48] can: dev: add can_get_ctrlmode_str() https://git.kernel.org/netdev/net-next/c/7de54546fff1 - [net-next,48/48] can: netlink: add userland error messages https://git.kernel.org/netdev/net-next/c/6742ca18cb41
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/48 MAINTAINERS: update Vincent Mailhol's email address
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Now that I have received my kernel.org account, I am changing my email address from [email protected] to [email protected]. The wanadoo.fr address was my first email which I created when I was a kid and has a special meaning to me, but it is restricted to a maximum of 50 messages per hour which starts to be problematic on threads where many people are CC-ed.
Update all the MAINTAINERS entries accordingly and map the old address to the new one.
I remain reachable from my old address. The different copyright notices mentioning my old address are kept as-is for the moment. I will update those one at a time only if I need to touch those files.
--- .mailmap | 1 + MAINTAINERS | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
.mailmap +1 -0
@@ -816,6 +816,7 @@ Veera Sundaram Sankaran <[email protected]> <[email protected]> Veerabhadrarao Badiganti <[email protected]> <[email protected]> Venkateswara Naralasetty <[email protected]> <[email protected]> Vikash Garodia <[email protected]> <[email protected]> +Vincent Mailhol <[email protected]> <[email protected]> Vinod Koul <[email protected]> <[email protected]> Vinod Koul <[email protected]> <[email protected]> Vinod Koul <[email protected]> <[email protected]>
MAINTAINERS +2 -2
@@ -5417,7 +5417,7 @@ F: net/sched/sch_cake.c CAN NETWORK DRIVERS M: Marc Kleine-Budde <[email protected]> -M: Vincent Mailhol <[email protected]> +M: Vincent Mailhol <[email protected]> L: [email protected] S: Maintained W: https://github.com/linux-can
@@ -9080,7 +9080,7 @@ S: Odd Fixes F: drivers/net/ethernet/agere/ ETAS ES58X CAN/USB DRIVER -M: Vincent Mailhol <[email protected]> +M: Vincent Mailhol <[email protected]> L: [email protected] S: Maintained F: Documentation/networking/devlink/etas_es58x.rst
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 3/48 can: dev: sort includes by alphabetical order
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Includes are out of order in
drivers/net/can/dev/dev.c
Sort them by alphabetical order.
--- drivers/net/can/dev/dev.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/can/dev/dev.c +5 -5
@@ -4,17 +4,17 @@* Copyright (C) 2008-2009 Wolfgang Grandegger <[email protected]> */ -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/netdevice.h> -#include <linux/if_arp.h> -#include <linux/workqueue.h> #include <linux/can.h> #include <linux/can/can-ml.h> #include <linux/can/dev.h> #include <linux/can/skb.h> #include <linux/gpio/consumer.h> +#include <linux/if_arp.h> +#include <linux/kernel.h> +#include <linux/netdevice.h> #include <linux/of.h> +#include <linux/slab.h> +#include <linux/workqueue.h> static void can_update_state_error_stats (struct net_device *dev,enum can_state new_state)
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 4/48 can: peak: Modification of references to email accounts being deleted
In reply to Marc Kleine-BuddeFrom: Stéphane Grosjean <[email protected]>
With the upcoming deletion of @peak-system.com accounts and following the acquisition of PEAK-System and its brand by HMS-Networks, this fix aims to migrate all address references to @hms-networks.com, as well as to map my personal committer addresses to author addresses, while taking the opportunity to correct the accent on the first ‘e’ of my first name.
--- .mailmap | 2 ++ drivers/net/can/peak_canfd/peak_canfd.c | 4 ++-- drivers/net/can/peak_canfd/peak_canfd_user.h | 4 ++-- drivers/net/can/peak_canfd/peak_pciefd_main.c | 6 +++--- drivers/net/can/sja1000/peak_pci.c | 6 +++--- drivers/net/can/sja1000/peak_pcmcia.c | 8 ++++---- drivers/net/can/usb/peak_usb/pcan_usb.c | 6 +++--- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 6 +++--- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 4 ++-- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 3 ++- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 4 ++-- drivers/net/can/usb/peak_usb/pcan_usb_pro.h | 4 ++-- include/linux/can/dev/peak_canfd.h | 4 ++-- 13 files changed, 32 insertions(+), 29 deletions(-)
.mailmap +2 -0
@@ -740,6 +740,8 @@ Sriram Yagnaraman <[email protected]> <[email protected]> Stanislav Fomichev <[email protected]> <[email protected]> Stanislav Fomichev <[email protected]> <[email protected]> Stefan Wahren <[email protected]> <[email protected]> +Stéphane Grosjean <[email protected]> <[email protected]> +Stéphane Grosjean <[email protected]> <[email protected]> Stéphane Witzmann <[email protected]> Stephen Hemminger <[email protected]> <[email protected]> Stephen Hemminger <[email protected]> <[email protected]>
drivers/net/can/peak_canfd/peak_canfd.c +2 -2
@@ -1,8 +1,8 @@// SPDX-License-Identifier: GPL-2.0-only /* Copyright (C) 2007, 2011 Wolfgang Grandegger <[email protected]> -* Copyright (C) 2012 Stephane Grosjean <[email protected]> * -* Copyright (C) 2016 PEAK System-Technik GmbH +* Copyright (C) 2016-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> */ #include <linux/can.h>
drivers/net/can/peak_canfd/peak_canfd_user.h +2 -2
@@ -1,8 +1,8 @@/* SPDX-License-Identifier: GPL-2.0-only */ /* CAN driver for PEAK System micro-CAN based adapters * -* Copyright (C) 2003-2011 PEAK System-Technik GmbH -* Copyright (C) 2011-2013 Stephane Grosjean <[email protected]> +* Copyright (C) 2003-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> */ #ifndef PEAK_CANFD_USER_H #define PEAK_CANFD_USER_H
drivers/net/can/peak_canfd/peak_pciefd_main.c +3 -3
@@ -1,10 +1,10 @@// SPDX-License-Identifier: GPL-2.0-only /* Copyright (C) 2007, 2011 Wolfgang Grandegger <[email protected]> -* Copyright (C) 2012 Stephane Grosjean <[email protected]> * * Derived from the PCAN project file driver/src/pcan_pci.c: * -* Copyright (C) 2001-2006 PEAK System-Technik GmbH +* Copyright (C) 2001-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> */ #include <linux/kernel.h>
@@ -19,7 +19,7 @@#include "peak_canfd_user.h" -MODULE_AUTHOR ("Stephane Grosjean <[email protected]>" ); +MODULE_AUTHOR ("Stéphane Grosjean <[email protected]>" );MODULE_DESCRIPTION ("Socket-CAN driver for PEAK PCAN PCIe/M.2 FD family cards" );MODULE_LICENSE ("GPL v2" );
drivers/net/can/sja1000/peak_pci.c +3 -3
@@ -1,11 +1,11 @@// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2007, 2011 Wolfgang Grandegger <[email protected]> -* Copyright (C) 2012 Stephane Grosjean <[email protected]> * * Derived from the PCAN project file driver/src/pcan_pci.c: * -* Copyright (C) 2001-2006 PEAK System-Technik GmbH +* Copyright (C) 2001-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> */ #include <linux/kernel.h>
@@ -22,7 +22,7 @@#include "sja1000.h" -MODULE_AUTHOR ("Stephane Grosjean <[email protected]>" ); +MODULE_AUTHOR ("Stéphane Grosjean <[email protected]>" );MODULE_DESCRIPTION ("Socket-CAN driver for PEAK PCAN PCI family cards" );MODULE_LICENSE ("GPL v2" );
drivers/net/can/sja1000/peak_pcmcia.c +4 -4
@@ -1,10 +1,10 @@// SPDX-License-Identifier: GPL-2.0-only /* -* Copyright (C) 2010-2012 Stephane Grosjean <[email protected]> -* * CAN driver for PEAK-System PCAN-PC Card * Derived from the PCAN project file driver/src/pcan_pccard.c -* Copyright (C) 2006-2010 PEAK System-Technik GmbH +* +* Copyright (C) 2006-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> */ #include <linux/kernel.h> #include <linux/module.h>
@@ -19,7 +19,7 @@#include <linux/can/dev.h> #include "sja1000.h" -MODULE_AUTHOR ("Stephane Grosjean <[email protected]>" ); +MODULE_AUTHOR ("Stéphane Grosjean <[email protected]>" );MODULE_DESCRIPTION ("CAN driver for PEAK-System PCAN-PC Cards" );MODULE_LICENSE ("GPL v2" );
drivers/net/can/usb/peak_usb/pcan_usb.c +3 -3
@@ -3,8 +3,8 @@* CAN driver for PEAK System PCAN-USB adapter * Derived from the PCAN project file driver/src/pcan_usb.c * -* Copyright (C) 2003-2010 PEAK System-Technik GmbH -* Copyright (C) 2011-2012 Stephane Grosjean <[email protected]> +* Copyright (C) 2003-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> * * Many thanks to Klaus Hitschler <[email protected]> */
@@ -919,7 +919,7 @@ static int pcan_usb_init(struct peak_usb_device *dev)CAN_CTRLMODE_LOOPBACK ; }else {dev_info (dev->netdev->dev.parent, -"Firmware update available. Please contact [email protected]\n" ); +"Firmware update available. Please contact [email protected]\n" ); }return 0 ;
drivers/net/can/usb/peak_usb/pcan_usb_core.c +3 -3
@@ -3,8 +3,8 @@* CAN driver for PEAK System USB adapters * Derived from the PCAN project file driver/src/pcan_usb_core.c * -* Copyright (C) 2003-2010 PEAK System-Technik GmbH -* Copyright (C) 2010-2012 Stephane Grosjean <[email protected]> +* Copyright (C) 2003-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> * * Many thanks to Klaus Hitschler <[email protected]> */
@@ -24,7 +24,7 @@#include "pcan_usb_core.h" -MODULE_AUTHOR ("Stephane Grosjean <[email protected]>" ); +MODULE_AUTHOR ("Stéphane Grosjean <[email protected]>" );MODULE_DESCRIPTION ("CAN driver for PEAK-System USB adapters" );MODULE_LICENSE ("GPL v2" );
drivers/net/can/usb/peak_usb/pcan_usb_core.h +2 -2
@@ -3,8 +3,8 @@* CAN driver for PEAK System USB adapters * Derived from the PCAN project file driver/src/pcan_usb_core.c * -* Copyright (C) 2003-2010 PEAK System-Technik GmbH -* Copyright (C) 2010-2012 Stephane Grosjean <[email protected]> +* Copyright (C) 2003-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> * * Many thanks to Klaus Hitschler <[email protected]> */
drivers/net/can/usb/peak_usb/pcan_usb_fd.c +2 -1
@@ -2,7 +2,8 @@/* * CAN driver for PEAK System PCAN-USB FD / PCAN-USB Pro FD adapter * -* Copyright (C) 2013-2014 Stephane Grosjean <[email protected]> +* Copyright (C) 2013-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> */ #include <linux/ethtool.h> #include <linux/module.h>
drivers/net/can/usb/peak_usb/pcan_usb_pro.c +2 -2
@@ -3,8 +3,8 @@* CAN driver for PEAK System PCAN-USB Pro adapter * Derived from the PCAN project file driver/src/pcan_usbpro.c * -* Copyright (C) 2003-2011 PEAK System-Technik GmbH -* Copyright (C) 2011-2012 Stephane Grosjean <[email protected]> +* Copyright (C) 2003-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> */ #include <linux/ethtool.h> #include <linux/module.h>
drivers/net/can/usb/peak_usb/pcan_usb_pro.h +2 -2
@@ -3,8 +3,8 @@* CAN driver for PEAK System PCAN-USB Pro adapter * Derived from the PCAN project file driver/src/pcan_usbpro_fw.h * -* Copyright (C) 2003-2011 PEAK System-Technik GmbH -* Copyright (C) 2011-2012 Stephane Grosjean <[email protected]> +* Copyright (C) 2003-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> */ #ifndef PCAN_USB_PRO_H #define PCAN_USB_PRO_H
include/linux/can/dev/peak_canfd.h +2 -2
@@ -2,8 +2,8 @@/* * CAN driver for PEAK System micro-CAN based adapters * -* Copyright (C) 2003-2011 PEAK System-Technik GmbH -* Copyright (C) 2011-2013 Stephane Grosjean <[email protected]> +* Copyright (C) 2003-2025 PEAK System-Technik GmbH +* Author: Stéphane Grosjean <[email protected]> */ #ifndef PUCAN_H #define PUCAN_H
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 5/48 can: rcar_canfd: Update bit rate constants for RZ/G3E and R-Car Gen4
In reply to Marc Kleine-BuddeFrom: Biju Das <[email protected]>
The calculation formula for nominal bit rate of classical CAN is the same as that of nominal bit rate of CANFD on the RZ/G3E and R-Car Gen4 SoCs compared to other SoCs. Update nominal bit rate constants.
--- drivers/net/can/rcar/rcar_canfd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/can/rcar/rcar_canfd.c +4 -1
@@ -1912,7 +1912,10 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, priv->can.fd.do_get_auto_tdcv = rcar_canfd_get_auto_tdcv; }else {/* Controller starts in Classical CAN only mode */ - priv->can.bittiming_const = &rcar_canfd_bittiming_const; +if (gpriv->info->shared_can_regs) + priv->can.bittiming_const = gpriv->info->nom_bittiming; +else + priv->can.bittiming_const = &rcar_canfd_bittiming_const; priv->can.ctrlmode_supported =CAN_CTRLMODE_BERR_REPORTING ; }
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 6/48 can: rcar_canfd: Update RCANFD_CFG_* macros
In reply to Marc Kleine-BuddeFrom: Biju Das <[email protected]>
Update RCANFD_CFG_* macros to give a meaning to the magic number using GENMASK macro and extract the values using FIELD_PREP macro.
--- drivers/net/can/rcar/rcar_canfd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/can/rcar/rcar_canfd.c +6 -6
@@ -103,10 +103,10 @@/* Channel register bits */ /* RSCFDnCmCFG - Classical CAN only */ -#define RCANFD_CFG_SJW (x) (((x) & 0x3) << 24) -#define RCANFD_CFG_TSEG2 (x) (((x) & 0x7) << 20) -#define RCANFD_CFG_TSEG1 (x) (((x) & 0xf) << 16) -#define RCANFD_CFG_BRP (x) (((x) & 0x3ff) << 0) +#define RCANFD_CFG_SJW GENMASK(25, 24) +#define RCANFD_CFG_TSEG2 GENMASK(22, 20) +#define RCANFD_CFG_TSEG1 GENMASK(19, 16) +#define RCANFD_CFG_BRP GENMASK(9, 0)/* RSCFDnCFDCmNCFG - CAN FD only */ #define RCANFD_NCFG_NTSEG2 (gpriv, x) \
@@ -1411,8 +1411,8 @@ static void rcar_canfd_set_bittiming(struct net_device *ndev) cfg = (RCANFD_NCFG_NTSEG1 (gpriv, tseg1) |RCANFD_NCFG_NBRP (brp) |RCANFD_NCFG_NSJW (gpriv, sjw) |RCANFD_NCFG_NTSEG2 (gpriv, tseg2)); }else { - cfg = (RCANFD_CFG_TSEG1 (tseg1) |RCANFD_CFG_BRP (brp) | -RCANFD_CFG_SJW (sjw) |RCANFD_CFG_TSEG2 (tseg2)); + cfg =FIELD_PREP (RCANFD_CFG_TSEG1 , tseg1) |FIELD_PREP (RCANFD_CFG_BRP , brp) | +FIELD_PREP (RCANFD_CFG_SJW , sjw) |FIELD_PREP (RCANFD_CFG_TSEG2 , tseg2); }rcar_canfd_write (priv->base,RCANFD_CCFG (ch), cfg);
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 7/48 can: rcar_canfd: Simplify nominal bit rate config
In reply to Marc Kleine-BuddeFrom: Biju Das <[email protected]>
Introduce rcar_canfd_compute_nominal_bit_rate_cfg() for simplifying nominal bit rate configuration by replacing function-like macros.
--- drivers/net/can/rcar/rcar_canfd.c | 43 +++++++++++++++++-------------- 1 file changed, 24 insertions(+), 19 deletions(-)
drivers/net/can/rcar/rcar_canfd.c +24 -19
@@ -109,16 +109,7 @@#define RCANFD_CFG_BRP GENMASK(9, 0)/* RSCFDnCFDCmNCFG - CAN FD only */ -#define RCANFD_NCFG_NTSEG2 (gpriv, x) \ - (((x) & ((gpriv)->info->nom_bittiming->tseg2_max - 1)) << (gpriv)->info->sh->ntseg2) - -#define RCANFD_NCFG_NTSEG1 (gpriv, x) \ - (((x) & ((gpriv)->info->nom_bittiming->tseg1_max - 1)) << (gpriv)->info->sh->ntseg1) - -#define RCANFD_NCFG_NSJW (gpriv, x) \ - (((x) & ((gpriv)->info->nom_bittiming->sjw_max - 1)) << (gpriv)->info->sh->nsjw) - -#define RCANFD_NCFG_NBRP (x) (((x) & 0x3ff) << 0) +#define RCANFD_NCFG_NBRP GENMASK(9, 0)/* RSCFDnCFDCmCTR / RSCFDnCmCTR */ #define RCANFD_CCTR_CTME BIT(24)
@@ -1388,6 +1379,28 @@ static irqreturn_t rcar_canfd_channel_interrupt(int irq, void *dev_id)return IRQ_HANDLED ; } +static inline u32 rcar_canfd_compute_nominal_bit_rate_cfg (struct rcar_canfd_channel *priv, +u16 tseg1,u16 tseg2,u16 sjw,u16 brp) +{ +struct rcar_canfd_global *gpriv = priv->gpriv; +const struct rcar_canfd_hw_info *info = gpriv->info; +u32 ntseg1, ntseg2, nsjw, nbrp; + +if ((priv->can.ctrlmode &CAN_CTRLMODE_FD ) || gpriv->info->shared_can_regs) { + ntseg1 = (tseg1 & (info->nom_bittiming->tseg1_max -1 )) << info->sh->ntseg1; + ntseg2 = (tseg2 & (info->nom_bittiming->tseg2_max -1 )) << info->sh->ntseg2; + nsjw = (sjw & (info->nom_bittiming->sjw_max -1 )) << info->sh->nsjw; + nbrp =FIELD_PREP (RCANFD_NCFG_NBRP , brp); + }else { + ntseg1 =FIELD_PREP (RCANFD_CFG_TSEG1 , tseg1); + ntseg2 =FIELD_PREP (RCANFD_CFG_TSEG2 , tseg2); + nsjw =FIELD_PREP (RCANFD_CFG_SJW , sjw); + nbrp =FIELD_PREP (RCANFD_CFG_BRP , brp); + } + +return (ntseg1 | ntseg2 | nsjw | nbrp); +} +static void rcar_canfd_set_bittiming (struct net_device *ndev) {u32 mask =RCANFD_FDCFG_TDCO |RCANFD_FDCFG_TDCE |RCANFD_FDCFG_TDCOC ;
@@ -1406,15 +1419,7 @@ static void rcar_canfd_set_bittiming(struct net_device *ndev) sjw = bt->sjw -1 ; tseg1 = bt->prop_seg + bt->phase_seg1 -1 ; tseg2 = bt->phase_seg2 -1 ; - -if ((priv->can.ctrlmode &CAN_CTRLMODE_FD ) || gpriv->info->shared_can_regs) { - cfg = (RCANFD_NCFG_NTSEG1 (gpriv, tseg1) |RCANFD_NCFG_NBRP (brp) | -RCANFD_NCFG_NSJW (gpriv, sjw) |RCANFD_NCFG_NTSEG2 (gpriv, tseg2)); - }else { - cfg =FIELD_PREP (RCANFD_CFG_TSEG1 , tseg1) |FIELD_PREP (RCANFD_CFG_BRP , brp) | -FIELD_PREP (RCANFD_CFG_SJW , sjw) |FIELD_PREP (RCANFD_CFG_TSEG2 , tseg2); - } - + cfg =rcar_canfd_compute_nominal_bit_rate_cfg (priv, tseg1, tseg2, sjw, brp);rcar_canfd_write (priv->base,RCANFD_CCFG (ch), cfg);if (!(priv->can.ctrlmode &CAN_CTRLMODE_FD ))
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 8/48 can: rcar_canfd: Simplify data bit rate config
In reply to Marc Kleine-BuddeFrom: Biju Das <[email protected]>
Introduce rcar_canfd_compute_data_bit_rate_cfg() for simplifying data bit rate configuration by replacing function-like macros.
--- drivers/net/can/rcar/rcar_canfd.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/net/can/rcar/rcar_canfd.c +15 -13
@@ -169,15 +169,7 @@#define RCANFD_CERFL_ERR (x) ((x) & (0x7fff))/* above bits 14:0 */ /* RSCFDnCFDCmDCFG */ -#define RCANFD_DCFG_DSJW (gpriv, x) (((x) & ((gpriv)->info->data_bittiming->sjw_max - 1)) << 24) - -#define RCANFD_DCFG_DTSEG2 (gpriv, x) \ - (((x) & ((gpriv)->info->data_bittiming->tseg2_max - 1)) << (gpriv)->info->sh->dtseg2) - -#define RCANFD_DCFG_DTSEG1 (gpriv, x) \ - (((x) & ((gpriv)->info->data_bittiming->tseg1_max - 1)) << (gpriv)->info->sh->dtseg1) - -#define RCANFD_DCFG_DBRP (x) (((x) & 0xff) << 0) +#define RCANFD_DCFG_DBRP GENMASK(7, 0)/* RSCFDnCFDCmFDCFG */ #define RCANFD_GEN4_FDCFG_CLOE BIT(30)
@@ -1401,6 +1393,19 @@ static inline u32 rcar_canfd_compute_nominal_bit_rate_cfg(struct rcar_canfd_chanreturn (ntseg1 | ntseg2 | nsjw | nbrp); } +static inline u32 rcar_canfd_compute_data_bit_rate_cfg (const struct rcar_canfd_hw_info *info, +u16 tseg1,u16 tseg2,u16 sjw,u16 brp) +{ +u32 dtseg1, dtseg2, dsjw, dbrp; + + dtseg1 = (tseg1 & (info->data_bittiming->tseg1_max -1 )) << info->sh->dtseg1; + dtseg2 = (tseg2 & (info->data_bittiming->tseg2_max -1 )) << info->sh->dtseg2; + dsjw = (sjw & (info->data_bittiming->sjw_max -1 )) <<24 ; + dbrp =FIELD_PREP (RCANFD_DCFG_DBRP , brp); + +return (dtseg1 | dtseg2 | dsjw | dbrp); +} +static void rcar_canfd_set_bittiming (struct net_device *ndev) {u32 mask =RCANFD_FDCFG_TDCO |RCANFD_FDCFG_TDCE |RCANFD_FDCFG_TDCOC ;
@@ -1430,10 +1435,7 @@ static void rcar_canfd_set_bittiming(struct net_device *ndev) sjw = dbt->sjw -1 ; tseg1 = dbt->prop_seg + dbt->phase_seg1 -1 ; tseg2 = dbt->phase_seg2 -1 ; - - cfg = (RCANFD_DCFG_DTSEG1 (gpriv, tseg1) |RCANFD_DCFG_DBRP (brp) | -RCANFD_DCFG_DSJW (gpriv, sjw) |RCANFD_DCFG_DTSEG2 (gpriv, tseg2)); - + cfg =rcar_canfd_compute_data_bit_rate_cfg (gpriv->info, tseg1, tseg2, sjw, brp);writel (cfg, &gpriv->fcbase[ch].dcfg);/* Transceiver Delay Compensation */
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 9/48 can: rcar_can: Consistently use ndev for net_device pointers
In reply to Marc Kleine-BuddeFrom: Geert Uytterhoeven <[email protected]>
Most net_device pointers are named "ndev", but some are called "dev". Increase uniformity by always using "ndev".
--- drivers/net/can/rcar/rcar_can.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/can/rcar/rcar_can.c +4 -4
@@ -420,9 +420,9 @@ static irqreturn_t rcar_can_interrupt(int irq, void *dev_id)return IRQ_HANDLED ; } -static void rcar_can_set_bittiming (struct net_device *dev) +static void rcar_can_set_bittiming (struct net_device *ndev) { -struct rcar_can_priv *priv =netdev_priv (dev); +struct rcar_can_priv *priv =netdev_priv (ndev);struct can_bittiming *bt = &priv->can.bittiming;u32 bcr;
@@ -715,10 +715,10 @@ static int rcar_can_do_set_mode(struct net_device *ndev, enum can_mode mode) } } -static int rcar_can_get_berr_counter (const struct net_device *dev, +static int rcar_can_get_berr_counter (const struct net_device *ndev,struct can_berr_counter *bec) { -struct rcar_can_priv *priv =netdev_priv (dev); +struct rcar_can_priv *priv =netdev_priv (ndev);int err; err =clk_prepare_enable (priv->clk);
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 10/48 can: rcar_can: Add helper variable dev to rcar_can_probe()
In reply to Marc Kleine-BuddeFrom: Geert Uytterhoeven <[email protected]>
rcar_can_probe() has many users of "pdev->dev". Introduce a shorthand to simplify the code.
--- drivers/net/can/rcar/rcar_can.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/net/can/rcar/rcar_can.c +11 -12
@@ -738,6 +738,7 @@ static const char * const clock_names[] = {static int rcar_can_probe (struct platform_device *pdev) { +struct device *dev = &pdev->dev;struct rcar_can_priv *priv;struct net_device *ndev;void __iomem *addr;
@@ -745,7 +746,7 @@ static int rcar_can_probe(struct platform_device *pdev)int err = -ENODEV ;int irq; -of_property_read_u32 (pdev->dev.of_node,"renesas,can-clock-select" , +of_property_read_u32 (dev->of_node,"renesas,can-clock-select" , &clock_select); irq =platform_get_irq (pdev,0 );
@@ -762,30 +763,29 @@ static int rcar_can_probe(struct platform_device *pdev) ndev =alloc_candev (sizeof (struct rcar_can_priv ),RCAR_CAN_FIFO_DEPTH );if (!ndev) { -dev_err (&pdev->dev,"alloc_candev() failed\n" ); +dev_err (dev,"alloc_candev() failed\n" ); err = -ENOMEM ; goto fail; } priv =netdev_priv (ndev); - priv->clk =devm_clk_get (&pdev->dev,"clkp1" ); + priv->clk =devm_clk_get (dev,"clkp1" );if (IS_ERR (priv->clk)) { err =PTR_ERR (priv->clk); -dev_err (&pdev->dev,"cannot get peripheral clock, error %d\n" , - err); +dev_err (dev,"cannot get peripheral clock, error %d\n" , err); goto fail_clk; }if (!(BIT (clock_select) &RCAR_SUPPORTED_CLOCKS )) { err = -EINVAL ; -dev_err (&pdev->dev,"invalid CAN clock selected\n" ); +dev_err (dev,"invalid CAN clock selected\n" ); goto fail_clk; } - priv->can_clk =devm_clk_get (&pdev->dev, clock_names[clock_select]); + priv->can_clk =devm_clk_get (dev, clock_names[clock_select]);if (IS_ERR (priv->can_clk)) { err =PTR_ERR (priv->can_clk); -dev_err (&pdev->dev,"cannot get CAN clock, error %d\n" , err); +dev_err (dev,"cannot get CAN clock, error %d\n" , err); goto fail_clk; }
@@ -802,18 +802,17 @@ static int rcar_can_probe(struct platform_device *pdev) priv->can.do_get_berr_counter = rcar_can_get_berr_counter; priv->can.ctrlmode_supported =CAN_CTRLMODE_BERR_REPORTING ;platform_set_drvdata (pdev, ndev); -SET_NETDEV_DEV (ndev, &pdev->dev); +SET_NETDEV_DEV (ndev, dev);netif_napi_add_weight (ndev, &priv->napi, rcar_can_rx_poll,RCAR_CAN_NAPI_WEIGHT ); err =register_candev (ndev);if (err) { -dev_err (&pdev->dev,"register_candev() failed, error %d\n" , - err); +dev_err (dev,"register_candev() failed, error %d\n" , err); goto fail_candev; } -dev_info (&pdev->dev,"device registered (IRQ%d)\n" , ndev->irq); +dev_info (dev,"device registered (IRQ%d)\n" , ndev->irq);return 0 ; fail_candev:
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 11/48 can: rcar_can: Convert to Runtime PM
In reply to Marc Kleine-BuddeFrom: Geert Uytterhoeven <[email protected]>
The R-Car CAN module is part of a Clock Domain on all supported SoCs. Hence convert its driver from explicit clock management to Runtime PM.
While at it, use %pe to format error codes.
--- drivers/net/can/rcar/rcar_can.c | 48 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-)
drivers/net/can/rcar/rcar_can.c +24 -24
@@ -16,6 +16,7 @@#include <linux/can/dev.h> #include <linux/clk.h> #include <linux/of.h> +#include <linux/pm_runtime.h> #define RCAR_CAN_DRV_NAME "rcar_can"
@@ -92,7 +93,6 @@ struct rcar_can_priv {struct net_device *ndev;struct napi_struct napi;struct rcar_can_regs __iomem *regs; -struct clk *clk;struct clk *can_clk;u32 tx_head;u32 tx_tail;
@@ -506,18 +506,17 @@ static int rcar_can_open(struct net_device *ndev)struct rcar_can_priv *priv =netdev_priv (ndev);int err; - err =clk_prepare_enable (priv->clk); + err =pm_runtime_resume_and_get (ndev->dev.parent);if (err) { -netdev_err (ndev, -"failed to enable peripheral clock, error %d\n" , - err); +netdev_err (ndev,"pm_runtime_resume_and_get() failed %pe\n" , +ERR_PTR (err)); goto out; } err =clk_prepare_enable (priv->can_clk);if (err) {netdev_err (ndev,"failed to enable CAN clock, error %d\n" , err); - goto out_clock; + goto out_rpm; } err =open_candev (ndev);if (err) {
@@ -539,8 +538,8 @@ static int rcar_can_open(struct net_device *ndev)close_candev (ndev); out_can_clock:clk_disable_unprepare (priv->can_clk); -out_clock: -clk_disable_unprepare (priv->clk); +out_rpm: +pm_runtime_put (ndev->dev.parent); out:return err; }
@@ -578,7 +577,7 @@ static int rcar_can_close(struct net_device *ndev)free_irq (ndev->irq, ndev);napi_disable (&priv->napi);clk_disable_unprepare (priv->can_clk); -clk_disable_unprepare (priv->clk); +pm_runtime_put (ndev->dev.parent);close_candev (ndev);return 0 ; }
@@ -721,12 +720,15 @@ static int rcar_can_get_berr_counter(const struct net_device *ndev,struct rcar_can_priv *priv =netdev_priv (ndev);int err; - err =clk_prepare_enable (priv->clk); + err =pm_runtime_resume_and_get (ndev->dev.parent);if (err)return err; + bec->txerr =readb (&priv->regs->tecr); bec->rxerr =readb (&priv->regs->recr); -clk_disable_unprepare (priv->clk); + +pm_runtime_put (ndev->dev.parent); +return 0 ; }
@@ -770,13 +772,6 @@ static int rcar_can_probe(struct platform_device *pdev) priv =netdev_priv (ndev); - priv->clk =devm_clk_get (dev,"clkp1" ); -if (IS_ERR (priv->clk)) { - err =PTR_ERR (priv->clk); -dev_err (dev,"cannot get peripheral clock, error %d\n" , err); - goto fail_clk; - } -if (!(BIT (clock_select) &RCAR_SUPPORTED_CLOCKS )) { err = -EINVAL ;dev_err (dev,"invalid CAN clock selected\n" );
@@ -806,16 +801,20 @@ static int rcar_can_probe(struct platform_device *pdev)netif_napi_add_weight (ndev, &priv->napi, rcar_can_rx_poll,RCAR_CAN_NAPI_WEIGHT ); + +pm_runtime_enable (dev); + err =register_candev (ndev);if (err) {dev_err (dev,"register_candev() failed, error %d\n" , err); - goto fail_candev; + goto fail_rpm; }dev_info (dev,"device registered (IRQ%d)\n" , ndev->irq);return 0 ; -fail_candev: +fail_rpm: +pm_runtime_disable (dev);netif_napi_del (&priv->napi); fail_clk:free_candev (ndev);
@@ -829,6 +828,7 @@ static void rcar_can_remove(struct platform_device *pdev)struct rcar_can_priv *priv =netdev_priv (ndev);unregister_candev (ndev); +pm_runtime_disable (&pdev->dev);netif_napi_del (&priv->napi);free_candev (ndev); }
@@ -852,22 +852,22 @@ static int rcar_can_suspend(struct device *dev)writew (ctlr, &priv->regs->ctlr); priv->can.state =CAN_STATE_SLEEPING ; -clk_disable (priv->clk); +pm_runtime_put (dev);return 0 ; }static int rcar_can_resume (struct device *dev) {struct net_device *ndev =dev_get_drvdata (dev); -struct rcar_can_priv *priv =netdev_priv (ndev);int err;if (!netif_running (ndev))return 0 ; - err =clk_enable (priv->clk); + err =pm_runtime_resume_and_get (dev);if (err) { -netdev_err (ndev,"clk_enable() failed, error %d\n" , err); +netdev_err (ndev,"pm_runtime_resume_and_get() failed %pe\n" , +ERR_PTR (err));return err; }
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 12/48 can: rcar_can: Convert to BIT()
In reply to Marc Kleine-BuddeFrom: Geert Uytterhoeven <[email protected]>
Use the BIT() macro instead of open-coding the same operation. Add a few more comments while at it.
--- drivers/net/can/rcar/rcar_can.c | 137 ++++++++++++++++---------------- 1 file changed, 69 insertions(+), 68 deletions(-)
drivers/net/can/rcar/rcar_can.c +69 -68
@@ -5,6 +5,7 @@* Copyright (C) 2013 Renesas Solutions Corp. */ +#include <linux/bits.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/types.h>
@@ -116,36 +117,36 @@ static const struct can_bittiming_const rcar_can_bittiming_const = {#define RCAR_CAN_CTLR_BOM (3 << 11)/* Bus-Off Recovery Mode Bits */ #define RCAR_CAN_CTLR_BOM_ENT (1 << 11)/* Entry to halt mode */ /* at bus-off entry */ -#define RCAR_CAN_CTLR_SLPM (1 << 10) +#define RCAR_CAN_CTLR_SLPM BIT(10)/* Sleep Mode */ #define RCAR_CAN_CTLR_CANM (3 << 8)/* Operating Mode Select Bit */ #define RCAR_CAN_CTLR_CANM_HALT (1 << 9)#define RCAR_CAN_CTLR_CANM_RESET (1 << 8)#define RCAR_CAN_CTLR_CANM_FORCE_RESET (3 << 8) -#define RCAR_CAN_CTLR_MLM (1 << 3)/* Message Lost Mode Select */ +#define RCAR_CAN_CTLR_MLM BIT(3)/* Message Lost Mode Select */ #define RCAR_CAN_CTLR_IDFM (3 << 1)/* ID Format Mode Select Bits */ #define RCAR_CAN_CTLR_IDFM_MIXED (1 << 2)/* Mixed ID mode */ -#define RCAR_CAN_CTLR_MBM (1 << 0)/* Mailbox Mode select */ +#define RCAR_CAN_CTLR_MBM BIT(0)/* Mailbox Mode select */ /* Status Register bits */ -#define RCAR_CAN_STR_RSTST (1 << 8)/* Reset Status Bit */ +#define RCAR_CAN_STR_RSTST BIT(8)/* Reset Status Bit */ /* FIFO Received ID Compare Registers 0 and 1 bits */ -#define RCAR_CAN_FIDCR_IDE (1 << 31)/* ID Extension Bit */ -#define RCAR_CAN_FIDCR_RTR (1 << 30)/* Remote Transmission Request Bit */ +#define RCAR_CAN_FIDCR_IDE BIT(31)/* ID Extension Bit */ +#define RCAR_CAN_FIDCR_RTR BIT(30)/* Remote Transmission Request Bit */ /* Receive FIFO Control Register bits */ -#define RCAR_CAN_RFCR_RFEST (1 << 7)/* Receive FIFO Empty Status Flag */ -#define RCAR_CAN_RFCR_RFE (1 << 0)/* Receive FIFO Enable */ +#define RCAR_CAN_RFCR_RFEST BIT(7)/* Receive FIFO Empty Status Flag */ +#define RCAR_CAN_RFCR_RFE BIT(0)/* Receive FIFO Enable */ /* Transmit FIFO Control Register bits */ -#define RCAR_CAN_TFCR_TFUST (7 << 1)/* Transmit FIFO Unsent Message */ -/* Number Status Bits */ -#define RCAR_CAN_TFCR_TFUST_SHIFT 1/* Offset of Transmit FIFO Unsent */ -/* Message Number Status Bits */ -#define RCAR_CAN_TFCR_TFE (1 << 0)/* Transmit FIFO Enable */ +#define RCAR_CAN_TFCR_TFUST (7 << 1)/* Transmit FIFO Unsent Message */ +/* Number Status Bits */ +#define RCAR_CAN_TFCR_TFUST_SHIFT 1/* Offset of Transmit FIFO Unsent */ +/* Message Number Status Bits */ +#define RCAR_CAN_TFCR_TFE BIT(0)/* Transmit FIFO Enable */ -#define RCAR_CAN_N_RX_MKREGS1 2/* Number of mask registers */ -/* for Rx mailboxes 0-31 */ +#define RCAR_CAN_N_RX_MKREGS1 2/* Number of mask registers */ +/* for Rx mailboxes 0-31 */ #define RCAR_CAN_N_RX_MKREGS2 8/* Bit Configuration Register settings */
@@ -155,58 +156,58 @@ static const struct can_bittiming_const rcar_can_bittiming_const = {#define RCAR_CAN_BCR_TSEG2 (x) ((x) & 0x07)/* Mailbox and Mask Registers bits */ -#define RCAR_CAN_IDE (1 << 31) -#define RCAR_CAN_RTR (1 << 30) +#define RCAR_CAN_IDE BIT(31)/* ID Extension */ +#define RCAR_CAN_RTR BIT(30)/* Remote Transmission Request */ #define RCAR_CAN_SID_SHIFT 18/* Mailbox Interrupt Enable Register 1 bits */ -#define RCAR_CAN_MIER1_RXFIE (1 << 28)/* Receive FIFO Interrupt Enable */ -#define RCAR_CAN_MIER1_TXFIE (1 << 24)/* Transmit FIFO Interrupt Enable */ +#define RCAR_CAN_MIER1_RXFIE BIT(28)/* Receive FIFO Interrupt Enable */ +#define RCAR_CAN_MIER1_TXFIE BIT(24)/* Transmit FIFO Interrupt Enable */ /* Interrupt Enable Register bits */ -#define RCAR_CAN_IER_ERSIE (1 << 5)/* Error (ERS) Interrupt Enable Bit */ -#define RCAR_CAN_IER_RXFIE (1 << 4)/* Reception FIFO Interrupt */ -/* Enable Bit */ -#define RCAR_CAN_IER_TXFIE (1 << 3)/* Transmission FIFO Interrupt */ -/* Enable Bit */ +#define RCAR_CAN_IER_ERSIE BIT(5)/* Error (ERS) Interrupt Enable Bit */ +#define RCAR_CAN_IER_RXFIE BIT(4)/* Reception FIFO Interrupt */ +/* Enable Bit */ +#define RCAR_CAN_IER_TXFIE BIT(3)/* Transmission FIFO Interrupt */ +/* Enable Bit */ /* Interrupt Status Register bits */ -#define RCAR_CAN_ISR_ERSF (1 << 5)/* Error (ERS) Interrupt Status Bit */ -#define RCAR_CAN_ISR_RXFF (1 << 4)/* Reception FIFO Interrupt */ -/* Status Bit */ -#define RCAR_CAN_ISR_TXFF (1 << 3)/* Transmission FIFO Interrupt */ -/* Status Bit */ +#define RCAR_CAN_ISR_ERSF BIT(5)/* Error (ERS) Interrupt Status Bit */ +#define RCAR_CAN_ISR_RXFF BIT(4)/* Reception FIFO Interrupt */ +/* Status Bit */ +#define RCAR_CAN_ISR_TXFF BIT(3)/* Transmission FIFO Interrupt */ +/* Status Bit */ /* Error Interrupt Enable Register bits */ -#define RCAR_CAN_EIER_BLIE (1 << 7)/* Bus Lock Interrupt Enable */ -#define RCAR_CAN_EIER_OLIE (1 << 6)/* Overload Frame Transmit */ -/* Interrupt Enable */ -#define RCAR_CAN_EIER_ORIE (1 << 5)/* Receive Overrun Interrupt Enable */ -#define RCAR_CAN_EIER_BORIE (1 << 4)/* Bus-Off Recovery Interrupt Enable */ -#define RCAR_CAN_EIER_BOEIE (1 << 3)/* Bus-Off Entry Interrupt Enable */ -#define RCAR_CAN_EIER_EPIE (1 << 2)/* Error Passive Interrupt Enable */ -#define RCAR_CAN_EIER_EWIE (1 << 1)/* Error Warning Interrupt Enable */ -#define RCAR_CAN_EIER_BEIE (1 << 0)/* Bus Error Interrupt Enable */ +#define RCAR_CAN_EIER_BLIE BIT(7)/* Bus Lock Interrupt Enable */ +#define RCAR_CAN_EIER_OLIE BIT(6)/* Overload Frame Transmit */ +/* Interrupt Enable */ +#define RCAR_CAN_EIER_ORIE BIT(5)/* Receive Overrun Interrupt Enable */ +#define RCAR_CAN_EIER_BORIE BIT(4)/* Bus-Off Recovery Interrupt Enable */ +#define RCAR_CAN_EIER_BOEIE BIT(3)/* Bus-Off Entry Interrupt Enable */ +#define RCAR_CAN_EIER_EPIE BIT(2)/* Error Passive Interrupt Enable */ +#define RCAR_CAN_EIER_EWIE BIT(1)/* Error Warning Interrupt Enable */ +#define RCAR_CAN_EIER_BEIE BIT(0)/* Bus Error Interrupt Enable */ /* Error Interrupt Factor Judge Register bits */ -#define RCAR_CAN_EIFR_BLIF (1 << 7)/* Bus Lock Detect Flag */ -#define RCAR_CAN_EIFR_OLIF (1 << 6)/* Overload Frame Transmission */ -/* Detect Flag */ -#define RCAR_CAN_EIFR_ORIF (1 << 5)/* Receive Overrun Detect Flag */ -#define RCAR_CAN_EIFR_BORIF (1 << 4)/* Bus-Off Recovery Detect Flag */ -#define RCAR_CAN_EIFR_BOEIF (1 << 3)/* Bus-Off Entry Detect Flag */ -#define RCAR_CAN_EIFR_EPIF (1 << 2)/* Error Passive Detect Flag */ -#define RCAR_CAN_EIFR_EWIF (1 << 1)/* Error Warning Detect Flag */ -#define RCAR_CAN_EIFR_BEIF (1 << 0)/* Bus Error Detect Flag */ +#define RCAR_CAN_EIFR_BLIF BIT(7)/* Bus Lock Detect Flag */ +#define RCAR_CAN_EIFR_OLIF BIT(6)/* Overload Frame Transmission */ +/* Detect Flag */ +#define RCAR_CAN_EIFR_ORIF BIT(5)/* Receive Overrun Detect Flag */ +#define RCAR_CAN_EIFR_BORIF BIT(4)/* Bus-Off Recovery Detect Flag */ +#define RCAR_CAN_EIFR_BOEIF BIT(3)/* Bus-Off Entry Detect Flag */ +#define RCAR_CAN_EIFR_EPIF BIT(2)/* Error Passive Detect Flag */ +#define RCAR_CAN_EIFR_EWIF BIT(1)/* Error Warning Detect Flag */ +#define RCAR_CAN_EIFR_BEIF BIT(0)/* Bus Error Detect Flag */ /* Error Code Store Register bits */ -#define RCAR_CAN_ECSR_EDPM (1 << 7)/* Error Display Mode Select Bit */ -#define RCAR_CAN_ECSR_ADEF (1 << 6)/* ACK Delimiter Error Flag */ -#define RCAR_CAN_ECSR_BE0F (1 << 5)/* Bit Error (dominant) Flag */ -#define RCAR_CAN_ECSR_BE1F (1 << 4)/* Bit Error (recessive) Flag */ -#define RCAR_CAN_ECSR_CEF (1 << 3)/* CRC Error Flag */ -#define RCAR_CAN_ECSR_AEF (1 << 2)/* ACK Error Flag */ -#define RCAR_CAN_ECSR_FEF (1 << 1)/* Form Error Flag */ -#define RCAR_CAN_ECSR_SEF (1 << 0)/* Stuff Error Flag */ +#define RCAR_CAN_ECSR_EDPM BIT(7)/* Error Display Mode Select Bit */ +#define RCAR_CAN_ECSR_ADEF BIT(6)/* ACK Delimiter Error Flag */ +#define RCAR_CAN_ECSR_BE0F BIT(5)/* Bit Error (dominant) Flag */ +#define RCAR_CAN_ECSR_BE1F BIT(4)/* Bit Error (recessive) Flag */ +#define RCAR_CAN_ECSR_CEF BIT(3)/* CRC Error Flag */ +#define RCAR_CAN_ECSR_AEF BIT(2)/* ACK Error Flag */ +#define RCAR_CAN_ECSR_FEF BIT(1)/* Form Error Flag */ +#define RCAR_CAN_ECSR_SEF BIT(0)/* Stuff Error Flag */ #define RCAR_CAN_NAPI_WEIGHT 4#define MAX_STR_READS 0x100
@@ -248,35 +249,35 @@ static void rcar_can_error(struct net_device *ndev)if (ecsr &RCAR_CAN_ECSR_ADEF ) {netdev_dbg (priv->ndev,"ACK Delimiter Error\n" ); tx_errors++; -writeb (~RCAR_CAN_ECSR_ADEF , &priv->regs->ecsr); +writeb ((u8 )~RCAR_CAN_ECSR_ADEF , &priv->regs->ecsr);if (skb) cf->data[3 ] =CAN_ERR_PROT_LOC_ACK_DEL ; }if (ecsr &RCAR_CAN_ECSR_BE0F ) {netdev_dbg (priv->ndev,"Bit Error (dominant)\n" ); tx_errors++; -writeb (~RCAR_CAN_ECSR_BE0F , &priv->regs->ecsr); +writeb ((u8 )~RCAR_CAN_ECSR_BE0F , &priv->regs->ecsr);if (skb) cf->data[2 ] |=CAN_ERR_PROT_BIT0 ; }if (ecsr &RCAR_CAN_ECSR_BE1F ) {netdev_dbg (priv->ndev,"Bit Error (recessive)\n" ); tx_errors++; -writeb (~RCAR_CAN_ECSR_BE1F , &priv->regs->ecsr); +writeb ((u8 )~RCAR_CAN_ECSR_BE1F , &priv->regs->ecsr);if (skb) cf->data[2 ] |=CAN_ERR_PROT_BIT1 ; }if (ecsr &RCAR_CAN_ECSR_CEF ) {netdev_dbg (priv->ndev,"CRC Error\n" ); rx_errors++; -writeb (~RCAR_CAN_ECSR_CEF , &priv->regs->ecsr); +writeb ((u8 )~RCAR_CAN_ECSR_CEF , &priv->regs->ecsr);if (skb) cf->data[3 ] =CAN_ERR_PROT_LOC_CRC_SEQ ; }if (ecsr &RCAR_CAN_ECSR_AEF ) {netdev_dbg (priv->ndev,"ACK Error\n" ); tx_errors++; -writeb (~RCAR_CAN_ECSR_AEF , &priv->regs->ecsr); +writeb ((u8 )~RCAR_CAN_ECSR_AEF , &priv->regs->ecsr);if (skb) { cf->can_id |=CAN_ERR_ACK ; cf->data[3 ] =CAN_ERR_PROT_LOC_ACK ;
@@ -285,14 +286,14 @@ static void rcar_can_error(struct net_device *ndev)if (ecsr &RCAR_CAN_ECSR_FEF ) {netdev_dbg (priv->ndev,"Form Error\n" ); rx_errors++; -writeb (~RCAR_CAN_ECSR_FEF , &priv->regs->ecsr); +writeb ((u8 )~RCAR_CAN_ECSR_FEF , &priv->regs->ecsr);if (skb) cf->data[2 ] |=CAN_ERR_PROT_FORM ; }if (ecsr &RCAR_CAN_ECSR_SEF ) {netdev_dbg (priv->ndev,"Stuff Error\n" ); rx_errors++; -writeb (~RCAR_CAN_ECSR_SEF , &priv->regs->ecsr); +writeb ((u8 )~RCAR_CAN_ECSR_SEF , &priv->regs->ecsr);if (skb) cf->data[2 ] |=CAN_ERR_PROT_STUFF ; }
@@ -300,14 +301,14 @@ static void rcar_can_error(struct net_device *ndev) priv->can.can_stats.bus_error++; ndev->stats.rx_errors += rx_errors; ndev->stats.tx_errors += tx_errors; -writeb (~RCAR_CAN_EIFR_BEIF , &priv->regs->eifr); +writeb ((u8 )~RCAR_CAN_EIFR_BEIF , &priv->regs->eifr); }if (eifr &RCAR_CAN_EIFR_EWIF ) {netdev_dbg (priv->ndev,"Error warning interrupt\n" ); priv->can.state =CAN_STATE_ERROR_WARNING ; priv->can.can_stats.error_warning++;/* Clear interrupt condition */ -writeb (~RCAR_CAN_EIFR_EWIF , &priv->regs->eifr); +writeb ((u8 )~RCAR_CAN_EIFR_EWIF , &priv->regs->eifr);if (skb) cf->data[1 ] = txerr > rxerr ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -317,7 +318,7 @@ static void rcar_can_error(struct net_device *ndev) priv->can.state =CAN_STATE_ERROR_PASSIVE ; priv->can.can_stats.error_passive++;/* Clear interrupt condition */ -writeb (~RCAR_CAN_EIFR_EPIF , &priv->regs->eifr); +writeb ((u8 )~RCAR_CAN_EIFR_EPIF , &priv->regs->eifr);if (skb) cf->data[1 ] = txerr > rxerr ?CAN_ERR_CRTL_TX_PASSIVE :CAN_ERR_CRTL_RX_PASSIVE ;
@@ -329,7 +330,7 @@ static void rcar_can_error(struct net_device *ndev)writeb (priv->ier, &priv->regs->ier); priv->can.state =CAN_STATE_BUS_OFF ;/* Clear interrupt condition */ -writeb (~RCAR_CAN_EIFR_BOEIF , &priv->regs->eifr); +writeb ((u8 )~RCAR_CAN_EIFR_BOEIF , &priv->regs->eifr); priv->can.can_stats.bus_off++;can_bus_off (ndev);if (skb)
@@ -343,7 +344,7 @@ static void rcar_can_error(struct net_device *ndev)netdev_dbg (priv->ndev,"Receive overrun error interrupt\n" ); ndev->stats.rx_over_errors++; ndev->stats.rx_errors++; -writeb (~RCAR_CAN_EIFR_ORIF , &priv->regs->eifr); +writeb ((u8 )~RCAR_CAN_EIFR_ORIF , &priv->regs->eifr);if (skb) { cf->can_id |=CAN_ERR_CRTL ; cf->data[1 ] =CAN_ERR_CRTL_RX_OVERFLOW ;
@@ -354,7 +355,7 @@ static void rcar_can_error(struct net_device *ndev) "Overload Frame Transmission error interrupt\n"); ndev->stats.rx_over_errors++; ndev->stats.rx_errors++; -writeb (~RCAR_CAN_EIFR_OLIF , &priv->regs->eifr); +writeb ((u8 )~RCAR_CAN_EIFR_OLIF , &priv->regs->eifr);if (skb) { cf->can_id |=CAN_ERR_PROT ; cf->data[2 ] |=CAN_ERR_PROT_OVERLOAD ;
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 13/48 can: rcar_can: Convert to GENMASK()
In reply to Marc Kleine-BuddeFrom: Geert Uytterhoeven <[email protected]>
Use the GENMASK() macro instead of open-coding the same operation.
--- drivers/net/can/rcar/rcar_can.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/can/rcar/rcar_can.c +4 -4
@@ -114,16 +114,16 @@ static const struct can_bittiming_const rcar_can_bittiming_const = { };/* Control Register bits */ -#define RCAR_CAN_CTLR_BOM (3 << 11)/* Bus-Off Recovery Mode Bits */ +#define RCAR_CAN_CTLR_BOM GENMASK(12, 11)/* Bus-Off Recovery Mode Bits */ #define RCAR_CAN_CTLR_BOM_ENT (1 << 11)/* Entry to halt mode */ /* at bus-off entry */ #define RCAR_CAN_CTLR_SLPM BIT(10)/* Sleep Mode */ -#define RCAR_CAN_CTLR_CANM (3 << 8)/* Operating Mode Select Bit */ +#define RCAR_CAN_CTLR_CANM GENMASK(9, 8)/* Operating Mode Select Bit */ #define RCAR_CAN_CTLR_CANM_HALT (1 << 9)#define RCAR_CAN_CTLR_CANM_RESET (1 << 8)#define RCAR_CAN_CTLR_CANM_FORCE_RESET (3 << 8)#define RCAR_CAN_CTLR_MLM BIT(3)/* Message Lost Mode Select */ -#define RCAR_CAN_CTLR_IDFM (3 << 1)/* ID Format Mode Select Bits */ +#define RCAR_CAN_CTLR_IDFM GENMASK(2, 1)/* ID Format Mode Select Bits */ #define RCAR_CAN_CTLR_IDFM_MIXED (1 << 2)/* Mixed ID mode */ #define RCAR_CAN_CTLR_MBM BIT(0)/* Mailbox Mode select */
@@ -139,7 +139,7 @@ static const struct can_bittiming_const rcar_can_bittiming_const = {#define RCAR_CAN_RFCR_RFE BIT(0)/* Receive FIFO Enable */ /* Transmit FIFO Control Register bits */ -#define RCAR_CAN_TFCR_TFUST (7 << 1)/* Transmit FIFO Unsent Message */ +#define RCAR_CAN_TFCR_TFUST GENMASK(3, 1)/* Transmit FIFO Unsent Message */ /* Number Status Bits */ #define RCAR_CAN_TFCR_TFUST_SHIFT 1/* Offset of Transmit FIFO Unsent */ /* Message Number Status Bits */
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 14/48 can: rcar_can: CTLR bitfield conversion
In reply to Marc Kleine-BuddeFrom: Geert Uytterhoeven <[email protected]>
Convert CAN Control Register field accesses to use the FIELD_PREP() bitfield access macro. Add a few more comments and definitions while at it.
This gets rid of explicit (and sometimes confusing) shifts.
--- drivers/net/can/rcar/rcar_can.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
drivers/net/can/rcar/rcar_can.c +20 -13
@@ -5,6 +5,7 @@* Copyright (C) 2013 Renesas Solutions Corp. */ +#include <linux/bitfield.h> #include <linux/bits.h> #include <linux/module.h> #include <linux/kernel.h>
@@ -115,16 +116,19 @@ static const struct can_bittiming_const rcar_can_bittiming_const = {/* Control Register bits */ #define RCAR_CAN_CTLR_BOM GENMASK(12, 11)/* Bus-Off Recovery Mode Bits */ -#define RCAR_CAN_CTLR_BOM_ENT (1 << 11)/* Entry to halt mode */ -/* at bus-off entry */ +#define RCAR_CAN_CTLR_BOM_ENT 1/* Entry to halt mode */ +/* at bus-off entry */ #define RCAR_CAN_CTLR_SLPM BIT(10)/* Sleep Mode */ #define RCAR_CAN_CTLR_CANM GENMASK(9, 8)/* Operating Mode Select Bit */ -#define RCAR_CAN_CTLR_CANM_HALT (1 << 9) -#define RCAR_CAN_CTLR_CANM_RESET (1 << 8) -#define RCAR_CAN_CTLR_CANM_FORCE_RESET (3 << 8) +#define RCAR_CAN_CTLR_CANM_OPER 0/* Operation Mode */ +#define RCAR_CAN_CTLR_CANM_RESET 1/* Reset Mode */ +#define RCAR_CAN_CTLR_CANM_HALT 2/* Halt Mode */ +#define RCAR_CAN_CTLR_CANM_FORCE_RESET 3/* Reset Mode (forcible) */ #define RCAR_CAN_CTLR_MLM BIT(3)/* Message Lost Mode Select */ #define RCAR_CAN_CTLR_IDFM GENMASK(2, 1)/* ID Format Mode Select Bits */ -#define RCAR_CAN_CTLR_IDFM_MIXED (1 << 2)/* Mixed ID mode */ +#define RCAR_CAN_CTLR_IDFM_STD 0/* Standard ID mode */ +#define RCAR_CAN_CTLR_IDFM_EXT 1/* Extended ID mode */ +#define RCAR_CAN_CTLR_IDFM_MIXED 2/* Mixed ID mode */ #define RCAR_CAN_CTLR_MBM BIT(0)/* Mailbox Mode select */ /* Status Register bits */
@@ -453,16 +457,17 @@ static void rcar_can_start(struct net_device *ndev) ctlr &= ~RCAR_CAN_CTLR_SLPM ;writew (ctlr, &priv->regs->ctlr);/* Go to reset mode */ - ctlr |=RCAR_CAN_CTLR_CANM_FORCE_RESET ; + ctlr |=FIELD_PREP (RCAR_CAN_CTLR_CANM ,RCAR_CAN_CTLR_CANM_FORCE_RESET );writew (ctlr, &priv->regs->ctlr);for (i =0 ; i <MAX_STR_READS ; i++) {if (readw (&priv->regs->str) &RCAR_CAN_STR_RSTST )break ; }rcar_can_set_bittiming (ndev); - ctlr |=RCAR_CAN_CTLR_IDFM_MIXED ;/* Select mixed ID mode */ - ctlr |=RCAR_CAN_CTLR_BOM_ENT ;/* Entry to halt mode automatically */ -/* at bus-off */ +/* Select mixed ID mode */ + ctlr |=FIELD_PREP (RCAR_CAN_CTLR_IDFM ,RCAR_CAN_CTLR_IDFM_MIXED ); +/* Entry to halt mode automatically at bus-off */ + ctlr |=FIELD_PREP (RCAR_CAN_CTLR_BOM ,RCAR_CAN_CTLR_BOM_ENT ); ctlr |=RCAR_CAN_CTLR_MBM ;/* Select FIFO mailbox mode */ ctlr |=RCAR_CAN_CTLR_MLM ;/* Overrun mode */ writew (ctlr, &priv->regs->ctlr);
@@ -492,7 +497,9 @@ static void rcar_can_start(struct net_device *ndev) priv->can.state =CAN_STATE_ERROR_ACTIVE ;/* Go to operation mode */ -writew (ctlr & ~RCAR_CAN_CTLR_CANM , &priv->regs->ctlr); + ctlr &= ~RCAR_CAN_CTLR_CANM ; + ctlr |=FIELD_PREP (RCAR_CAN_CTLR_CANM ,RCAR_CAN_CTLR_CANM_OPER ); +writew (ctlr, &priv->regs->ctlr);for (i =0 ; i <MAX_STR_READS ; i++) {if (!(readw (&priv->regs->str) &RCAR_CAN_STR_RSTST ))break ;
@@ -553,7 +560,7 @@ static void rcar_can_stop(struct net_device *ndev)/* Go to (force) reset mode */ ctlr =readw (&priv->regs->ctlr); - ctlr |=RCAR_CAN_CTLR_CANM_FORCE_RESET ; + ctlr |=FIELD_PREP (RCAR_CAN_CTLR_CANM ,RCAR_CAN_CTLR_CANM_FORCE_RESET );writew (ctlr, &priv->regs->ctlr);for (i =0 ; i <MAX_STR_READS ; i++) {if (readw (&priv->regs->str) &RCAR_CAN_STR_RSTST )
@@ -847,7 +854,7 @@ static int rcar_can_suspend(struct device *dev)netif_device_detach (ndev); ctlr =readw (&priv->regs->ctlr); - ctlr |=RCAR_CAN_CTLR_CANM_HALT ; + ctlr |=FIELD_PREP (RCAR_CAN_CTLR_CANM ,RCAR_CAN_CTLR_CANM_HALT );writew (ctlr, &priv->regs->ctlr); ctlr |=RCAR_CAN_CTLR_SLPM ;writew (ctlr, &priv->regs->ctlr);
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 15/48 can: rcar_can: TFCR bitfield conversion
In reply to Marc Kleine-BuddeFrom: Geert Uytterhoeven <[email protected]>
Convert CAN Transmit FIFO Control Register field accesses to use the FIELD_GET() bitfield access macro.
This gets rid of an explicit shift.
--- drivers/net/can/rcar/rcar_can.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/can/rcar/rcar_can.c +2 -5
@@ -145,8 +145,6 @@ static const struct can_bittiming_const rcar_can_bittiming_const = {/* Transmit FIFO Control Register bits */ #define RCAR_CAN_TFCR_TFUST GENMASK(3, 1)/* Transmit FIFO Unsent Message */ /* Number Status Bits */ -#define RCAR_CAN_TFCR_TFUST_SHIFT 1/* Offset of Transmit FIFO Unsent */ -/* Message Number Status Bits */ #define RCAR_CAN_TFCR_TFE BIT(0)/* Transmit FIFO Enable */ #define RCAR_CAN_N_RX_MKREGS1 2/* Number of mask registers */
@@ -377,10 +375,9 @@ static void rcar_can_tx_done(struct net_device *ndev)u8 isr;while (1 ) { -u8 unsent =readb (&priv->regs->tfcr); +u8 unsent =FIELD_GET (RCAR_CAN_TFCR_TFUST , +readb (&priv->regs->tfcr)); - unsent = (unsent &RCAR_CAN_TFCR_TFUST ) >> -RCAR_CAN_TFCR_TFUST_SHIFT ;if (priv->tx_head - priv->tx_tail <= unsent)break ; stats->tx_packets++;
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 16/48 can: rcar_can: BCR bitfield conversion
In reply to Marc Kleine-BuddeFrom: Geert Uytterhoeven <[email protected]>
Convert CAN Bit Configuration Register field accesses to use the FIELD_PREP() bitfield access macro. While at it, fix the misspelling of BRP.
This gets rid of custom function-like field preparation macros.
--- drivers/net/can/rcar/rcar_can.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/net/can/rcar/rcar_can.c +8 -7
@@ -152,10 +152,10 @@ static const struct can_bittiming_const rcar_can_bittiming_const = {#define RCAR_CAN_N_RX_MKREGS2 8/* Bit Configuration Register settings */ -#define RCAR_CAN_BCR_TSEG1 (x) (((x) & 0x0f) << 20) -#define RCAR_CAN_BCR_BPR (x) (((x) & 0x3ff) << 8) -#define RCAR_CAN_BCR_SJW (x) (((x) & 0x3) << 4) -#define RCAR_CAN_BCR_TSEG2 (x) ((x) & 0x07) +#define RCAR_CAN_BCR_TSEG1 GENMASK(23, 20) +#define RCAR_CAN_BCR_BRP GENMASK(17, 8) +#define RCAR_CAN_BCR_SJW GENMASK(5, 4) +#define RCAR_CAN_BCR_TSEG2 GENMASK(2, 0)/* Mailbox and Mask Registers bits */ #define RCAR_CAN_IDE BIT(31)/* ID Extension */
@@ -428,9 +428,10 @@ static void rcar_can_set_bittiming(struct net_device *ndev)struct can_bittiming *bt = &priv->can.bittiming;u32 bcr; - bcr =RCAR_CAN_BCR_TSEG1 (bt->phase_seg1 + bt->prop_seg -1 ) | -RCAR_CAN_BCR_BPR (bt->brp -1 ) |RCAR_CAN_BCR_SJW (bt->sjw -1 ) | -RCAR_CAN_BCR_TSEG2 (bt->phase_seg2 -1 ); + bcr =FIELD_PREP (RCAR_CAN_BCR_TSEG1 , bt->phase_seg1 + bt->prop_seg -1 ) | +FIELD_PREP (RCAR_CAN_BCR_BRP , bt->brp -1 ) | +FIELD_PREP (RCAR_CAN_BCR_SJW , bt->sjw -1 ) | +FIELD_PREP (RCAR_CAN_BCR_TSEG2 , bt->phase_seg2 -1 );/* Don't overwrite CLKR with 32-bit BCR access; CLKR has 8-bit access. * All the registers are big-endian but they get byte-swapped on 32-bit * read/write (but not on 8-bit, contrary to the manuals)...
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 17/48 can: rcar_can: Mailbox bitfield conversion
In reply to Marc Kleine-BuddeFrom: Geert Uytterhoeven <[email protected]>
Convert CAN Mailbox Register field accesses to use the FIELD_PREP() and FIELD_GET() bitfield access macro.
This gets rid of explicit shifts, and keeps a clear separation between hardware register layouts and offical CAN definitions.
--- drivers/net/can/rcar/rcar_can.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/can/rcar/rcar_can.c +7 -5
@@ -160,7 +160,8 @@ static const struct can_bittiming_const rcar_can_bittiming_const = {/* Mailbox and Mask Registers bits */ #define RCAR_CAN_IDE BIT(31)/* ID Extension */ #define RCAR_CAN_RTR BIT(30)/* Remote Transmission Request */ -#define RCAR_CAN_SID_SHIFT 18 +#define RCAR_CAN_SID GENMASK(28, 18)/* Standard ID */ +#define RCAR_CAN_EID GENMASK(28, 0)/* Extended ID */ /* Mailbox Interrupt Enable Register 1 bits */ #define RCAR_CAN_MIER1_RXFIE BIT(28)/* Receive FIFO Interrupt Enable */
@@ -599,9 +600,10 @@ static netdev_tx_t rcar_can_start_xmit(struct sk_buff *skb,return NETDEV_TX_OK ;if (cf->can_id &CAN_EFF_FLAG )/* Extended frame format */ - data = (cf->can_id &CAN_EFF_MASK ) |RCAR_CAN_IDE ; + data =FIELD_PREP (RCAR_CAN_EID , cf->can_id &CAN_EFF_MASK ) | +RCAR_CAN_IDE ;else /* Standard frame format */ - data = (cf->can_id &CAN_SFF_MASK ) <<RCAR_CAN_SID_SHIFT ; + data =FIELD_PREP (RCAR_CAN_SID , cf->can_id &CAN_SFF_MASK );if (cf->can_id &CAN_RTR_FLAG ) {/* Remote transmission request */ data |=RCAR_CAN_RTR ;
@@ -656,9 +658,9 @@ static void rcar_can_rx_pkt(struct rcar_can_priv *priv) data =readl (&priv->regs->mb[RCAR_CAN_RX_FIFO_MBX ].id);if (data &RCAR_CAN_IDE ) - cf->can_id = (data &CAN_EFF_MASK ) |CAN_EFF_FLAG ; + cf->can_id =FIELD_GET (RCAR_CAN_EID , data) |CAN_EFF_FLAG ;else - cf->can_id = (data >>RCAR_CAN_SID_SHIFT ) &CAN_SFF_MASK ; + cf->can_id =FIELD_GET (RCAR_CAN_SID , data); dlc =readb (&priv->regs->mb[RCAR_CAN_RX_FIFO_MBX ].dlc); cf->len =can_cc_dlc2len (dlc);
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 18/48 can: rcar_can: Do not print alloc_candev() failures
In reply to Marc Kleine-BuddeFrom: Geert Uytterhoeven <[email protected]>
If alloc_candev() failed due to out-of-memory, the core memory allocation code has already printed an error message.
If alloc_candev() failed for a different reason, alloc_netdev_mqs() has already printed an error message.
--- drivers/net/can/rcar/rcar_can.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/can/rcar/rcar_can.c +0 -1
@@ -773,7 +773,6 @@ static int rcar_can_probe(struct platform_device *pdev) ndev =alloc_candev (sizeof (struct rcar_can_priv ),RCAR_CAN_FIFO_DEPTH );if (!ndev) { -dev_err (dev,"alloc_candev() failed\n" ); err = -ENOMEM ; goto fail; }
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 19/48 can: rcar_can: Convert to %pe
In reply to Marc Kleine-BuddeFrom: Geert Uytterhoeven <[email protected]>
Replace numerical error codes by mnemotechnic error codes, to improve the user experience in case of errors.
--- drivers/net/can/rcar/rcar_can.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/net/can/rcar/rcar_can.c +7 -7
@@ -521,20 +521,20 @@ static int rcar_can_open(struct net_device *ndev) } err =clk_prepare_enable (priv->can_clk);if (err) { -netdev_err (ndev,"failed to enable CAN clock, error %d\n" , - err); +netdev_err (ndev,"failed to enable CAN clock: %pe\n" , +ERR_PTR (err)); goto out_rpm; } err =open_candev (ndev);if (err) { -netdev_err (ndev,"open_candev() failed, error %d\n" , err); +netdev_err (ndev,"open_candev() failed %pe\n" ,ERR_PTR (err)); goto out_can_clock; }napi_enable (&priv->napi); err =request_irq (ndev->irq, rcar_can_interrupt,0 , ndev->name, ndev);if (err) { -netdev_err (ndev,"request_irq(%d) failed, error %d\n" , - ndev->irq, err); +netdev_err (ndev,"request_irq(%d) failed %pe\n" , ndev->irq, +ERR_PTR (err)); goto out_close; }rcar_can_start (ndev);
@@ -786,8 +786,8 @@ static int rcar_can_probe(struct platform_device *pdev) } priv->can_clk =devm_clk_get (dev, clock_names[clock_select]);if (IS_ERR (priv->can_clk)) { +dev_err (dev,"cannot get CAN clock: %pe\n" , priv->can_clk); err =PTR_ERR (priv->can_clk); -dev_err (dev,"cannot get CAN clock, error %d\n" , err); goto fail_clk; }
@@ -813,7 +813,7 @@ static int rcar_can_probe(struct platform_device *pdev) err =register_candev (ndev);if (err) { -dev_err (dev,"register_candev() failed, error %d\n" , err); +dev_err (dev,"register_candev() failed %pe\n" ,ERR_PTR (err)); goto fail_rpm; }
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 20/48 can: esd_usb: Rework display of error messages
In reply to Marc Kleine-BuddeFrom: Stefan Mätje <[email protected]>
- esd_usb_open(): Get rid of duplicate "couldn't start device: %d\n" message already printed from esd_usb_start().
- Fix duplicate printout of network device name when network device is registered. Add an unregister message for the network device as counterpart to the register message.
- Add the printout of error codes together with the error messages in esd_usb_close() and some in esd_usb_probe(). The additional error codes should lead to a better understanding what is really going wrong.
- Convert all occurrences of error status prints to use "ERR_PTR(err)" instead of printing the decimal value of "err".
- Rename retval to err in esd_usb_read_bulk_callback() to make the naming of error status variables consistent with all other functions.
--- drivers/net/can/usb/esd_usb.c | 36 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
drivers/net/can/usb/esd_usb.c +20 -16
@@ -9,6 +9,7 @@#include <linux/can.h> #include <linux/can/dev.h> #include <linux/can/error.h> +#include <linux/err.h> #include <linux/ethtool.h> #include <linux/module.h> #include <linux/netdevice.h>
@@ -480,7 +481,7 @@ static void esd_usb_tx_done_msg(struct esd_usb_net_priv *priv,static void esd_usb_read_bulk_callback (struct urb *urb) {struct esd_usb *dev = urb->context; -int retval; +int err;int pos =0 ;int i;
@@ -496,7 +497,7 @@ static void esd_usb_read_bulk_callback(struct urb *urb)default :dev_info (dev->udev->dev.parent, -"Rx URB aborted (%d)\n" , urb->status); +"Rx URB aborted (%pe)\n" ,ERR_PTR (urb->status)); goto resubmit_urb; }
@@ -539,15 +540,15 @@ static void esd_usb_read_bulk_callback(struct urb *urb) urb->transfer_buffer,ESD_USB_RX_BUFFER_SIZE , esd_usb_read_bulk_callback, dev); - retval =usb_submit_urb (urb,GFP_ATOMIC ); -if (retval == -ENODEV ) { + err =usb_submit_urb (urb,GFP_ATOMIC ); +if (err == -ENODEV ) {for (i =0 ; i < dev->net_count; i++) {if (dev->nets[i])netif_device_detach (dev->nets[i]->netdev); } - }else if (retval) { + }else if (err) {dev_err (dev->udev->dev.parent, -"failed resubmitting read bulk urb: %d\n" , retval); +"failed resubmitting read bulk urb: %pe\n" ,ERR_PTR (err)); } }
@@ -572,7 +573,7 @@ static void esd_usb_write_bulk_callback(struct urb *urb)return ;if (urb->status) -netdev_info (netdev,"Tx URB aborted (%d)\n" , urb->status); +netdev_info (netdev,"Tx URB aborted (%pe)\n" ,ERR_PTR (urb->status));netif_trans_update (netdev); }
@@ -758,7 +759,7 @@ static int esd_usb_start(struct esd_usb_net_priv *priv)if (err == -ENODEV )netif_device_detach (netdev);if (err) -netdev_err (netdev,"couldn't start device: %d\n" , err); +netdev_err (netdev,"couldn't start device: %pe\n" ,ERR_PTR (err));kfree (msg);return err;
@@ -800,7 +801,6 @@ static int esd_usb_open(struct net_device *netdev)/* finally start device */ err =esd_usb_start (priv);if (err) { -netdev_warn (netdev,"couldn't start device: %d\n" , err);close_candev (netdev);return err; }
@@ -923,7 +923,7 @@ static netdev_tx_t esd_usb_start_xmit(struct sk_buff *skb,if (err == -ENODEV )netif_device_detach (netdev);else -netdev_warn (netdev,"failed tx_urb %d\n" , err); +netdev_warn (netdev,"failed tx_urb %pe\n" ,ERR_PTR (err)); goto releasebuf; }
@@ -951,6 +951,7 @@ static int esd_usb_close(struct net_device *netdev) {struct esd_usb_net_priv *priv =netdev_priv (netdev);union esd_usb_msg *msg; +int err;int i; msg =kmalloc (sizeof (*msg),GFP_KERNEL );
@@ -964,8 +965,9 @@ static int esd_usb_close(struct net_device *netdev) msg->filter.option =ESD_USB_ID_ENABLE ;/* start with segment 0 */ for (i =0 ; i <=ESD_USB_MAX_ID_SEGMENT ; i++) msg->filter.mask[i] =0 ; -if (esd_usb_send_msg (priv->usb, msg) <0 ) -netdev_err (netdev,"sending idadd message failed\n" ); + err =esd_usb_send_msg (priv->usb, msg); +if (err <0 ) +netdev_err (netdev,"sending idadd message failed: %pe\n" ,ERR_PTR (err));/* set CAN controller to reset mode */ msg->hdr.len =sizeof (struct esd_usb_set_baudrate_msg ) /sizeof (u32);/* # of 32bit words */
@@ -973,8 +975,9 @@ static int esd_usb_close(struct net_device *netdev) msg->setbaud.net = priv->index; msg->setbaud.rsvd =0 ; msg->setbaud.baud =cpu_to_le32 (ESD_USB_NO_BAUDRATE ); -if (esd_usb_send_msg (priv->usb, msg) <0 ) -netdev_err (netdev,"sending setbaud message failed\n" ); + err =esd_usb_send_msg (priv->usb, msg); +if (err <0 ) +netdev_err (netdev,"sending setbaud message failed: %pe\n" ,ERR_PTR (err)); priv->can.state =CAN_STATE_STOPPED ;
@@ -1251,14 +1254,14 @@ static int esd_usb_probe_one_net(struct usb_interface *intf, int index) err =register_candev (netdev);if (err) { -dev_err (&intf->dev,"couldn't register CAN device: %d\n" , err); +dev_err (&intf->dev,"couldn't register CAN device: %pe\n" ,ERR_PTR (err));free_candev (netdev); err = -ENOMEM ; goto done; } dev->nets[index] = priv; -netdev_info (netdev,"device %s registered\n" , netdev->name); +netdev_info (netdev,"registered\n" ); done:return err;
@@ -1357,6 +1360,7 @@ static void esd_usb_disconnect(struct usb_interface *intf)for (i =0 ; i < dev->net_count; i++) {if (dev->nets[i]) { netdev = dev->nets[i]->netdev; +netdev_info (netdev,"unregister\n" );unregister_netdev (netdev);free_candev (netdev); }
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 21/48 can: esd_usb: Avoid errors triggered from USB disconnect
In reply to Marc Kleine-BuddeFrom: Stefan Mätje <[email protected]>
The USB stack calls during disconnect the esd_usb_disconnect() callback. esd_usb_disconnect() calls netdev_unregister() for each network which in turn calls the net_device_ops::ndo_stop callback esd_usb_close() if the net device is up.
The esd_usb_close() callback tries to disable all CAN Ids and to reset the CAN controller of the device sending appropriate control messages.
Sending these messages in .disconnect() is moot and always fails because either the device is gone or the USB communication is already torn down by the USB stack in the course of a rmmod operation.
Move the code that sends these control messages to a new function esd_usb_stop() which is approximately the counterpart of esd_usb_start() to make code structure less convoluted.
Then change esd_usb_close() not to send the control messages at all if the ndo_stop() callback is executed from the USB .disconnect() callback. Add a new flag in_usb_disconnect to the struct esd_usb device structure to mark this condition which is checked by esd_usb_close() whether to skip the send operations in esd_usb_start().
--- drivers/net/can/usb/esd_usb.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
drivers/net/can/usb/esd_usb.c +26 -8
@@ -275,6 +275,7 @@ struct esd_usb {int net_count;u32 version;int rxinitdone; +int in_usb_disconnect;void *rxbuf[ESD_USB_MAX_RX_URBS ];dma_addr_t rxbuf_dma[ESD_USB_MAX_RX_URBS ]; };
@@ -947,9 +948,9 @@ static netdev_tx_t esd_usb_start_xmit(struct sk_buff *skb,return ret; } -static int esd_usb_close (struct net_device *netdev) +/* Stop interface */ +static int esd_usb_stop (struct esd_usb_net_priv *priv) { -struct esd_usb_net_priv *priv =netdev_priv (netdev);union esd_usb_msg *msg;int err;int i;
@@ -966,8 +967,10 @@ static int esd_usb_close(struct net_device *netdev)for (i =0 ; i <=ESD_USB_MAX_ID_SEGMENT ; i++) msg->filter.mask[i] =0 ; err =esd_usb_send_msg (priv->usb, msg); -if (err <0 ) -netdev_err (netdev,"sending idadd message failed: %pe\n" ,ERR_PTR (err)); +if (err <0 ) { +netdev_err (priv->netdev,"sending idadd message failed: %pe\n" ,ERR_PTR (err)); + goto bail; + }/* set CAN controller to reset mode */ msg->hdr.len =sizeof (struct esd_usb_set_baudrate_msg ) /sizeof (u32);/* # of 32bit words */
@@ -977,7 +980,23 @@ static int esd_usb_close(struct net_device *netdev) msg->setbaud.baud =cpu_to_le32 (ESD_USB_NO_BAUDRATE ); err =esd_usb_send_msg (priv->usb, msg);if (err <0 ) -netdev_err (netdev,"sending setbaud message failed: %pe\n" ,ERR_PTR (err)); +netdev_err (priv->netdev,"sending setbaud message failed: %pe\n" ,ERR_PTR (err)); + +bail: +kfree (msg); + +return err; +} + +static int esd_usb_close (struct net_device *netdev) +{ +struct esd_usb_net_priv *priv =netdev_priv (netdev); +int err =0 ; + +if (!priv->usb->in_usb_disconnect) { +/* It's moot to try this in usb_disconnect()! */ + err =esd_usb_stop (priv); + } priv->can.state =CAN_STATE_STOPPED ;
@@ -985,9 +1004,7 @@ static int esd_usb_close(struct net_device *netdev)close_candev (netdev); -kfree (msg); - -return 0 ; +return err; }static const struct net_device_ops esd_usb_netdev_ops = {
@@ -1357,6 +1374,7 @@ static void esd_usb_disconnect(struct usb_interface *intf)usb_set_intfdata (intf,NULL );if (dev) { + dev->in_usb_disconnect =1 ;for (i =0 ; i < dev->net_count; i++) {if (dev->nets[i]) { netdev = dev->nets[i]->netdev;
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 22/48 can: raw: reorder struct uniqframe's members to optimise packing
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
struct uniqframe has one hole. Reorder the fields to save 8 bytes.
Statistics before:
$ pahole --class_name=uniqframe net/can/raw.o
struct uniqframe {
int skbcnt; /* 0 4 *//* XXX 4 bytes hole, try to pack */
const struct sk_buff * skb; /* 8 8 */ unsigned int join_rx_count; /* 16 4 */
/* size: 24, cachelines: 1, members: 3 */ /* sum members: 16, holes: 1, sum holes: 4 */ /* padding: 4 */ /* last cacheline: 24 bytes */ };
...and after:
$ pahole --class_name=uniqframe net/can/raw.o
struct uniqframe {
const struct sk_buff * skb; /* 0 8 */
int skbcnt; /* 8 4 */
unsigned int join_rx_count; /* 12 4 *//* size: 16, cachelines: 1, members: 3 */ /* last cacheline: 16 bytes */ };
--- net/can/raw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/can/raw.c +1 -1
@@ -75,8 +75,8 @@ MODULE_ALIAS("can-proto-1");*/ struct uniqframe { -int skbcnt;const struct sk_buff *skb; +int skbcnt;unsigned int join_rx_count; };
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 23/48 can: raw: use bitfields to store flags in struct raw_sock
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
The bound, loopback, recv_own_msgs, fd_frames, xl_frames and join_filters fields of struct raw_sock just need to store one bit of information.
Declare all those members as a bitfields of type unsigned int and width one bit.
Add a temporary variable to raw_setsockopt() and raw_getsockopt() to make the conversion between the stored bits and the socket interface.
This reduces the size of struct raw_sock by sixteen bytes.
Statistics before:
$ pahole --class_name=raw_sock net/can/raw.o
struct raw_sock {
struct sock sk __attribute__((__aligned__(8))); /* 0 776 *//* XXX last struct has 1 bit hole */
/* --- cacheline 12 boundary (768 bytes) was 8 bytes ago --- */
int bound; /* 776 4 */ int ifindex; /* 780 4 */ struct net_device * dev; /* 784 8 */ netdevice_tracker dev_tracker; /* 792 0 */ struct list_head notifier; /* 792 16 */ int loopback; /* 808 4 */ int recv_own_msgs; /* 812 4 */ int fd_frames; /* 816 4 */ int xl_frames; /* 820 4 */ struct can_raw_vcid_options raw_vcid_opts; /* 824 4 */ canid_t tx_vcid_shifted; /* 828 4 */ /* --- cacheline 13 boundary (832 bytes) --- */ canid_t rx_vcid_shifted; /* 832 4 */ canid_t rx_vcid_mask_shifted; /* 836 4 */ int join_filters; /* 840 4 */ int count; /* 844 4 */ struct can_filter dfilter; /* 848 8 */ struct can_filter * filter; /* 856 8 */ can_err_mask_t err_mask; /* 864 4 */
/* XXX 4 bytes hole, try to pack */
struct uniqframe * uniq; /* 872 8 */
/* size: 880, cachelines: 14, members: 20 */ /* sum members: 876, holes: 1, sum holes: 4 */ /* member types with bit holes: 1, total: 1 */ /* forced alignments: 1 */
/* last cacheline: 48 bytes */
} __attribute__((__aligned__(8)));
...and after:
$ pahole --class_name=raw_sock net/can/raw.o
struct raw_sock {
struct sock sk __attribute__((__aligned__(8))); /* 0 776 *//* XXX last struct has 1 bit hole */
/* --- cacheline 12 boundary (768 bytes) was 8 bytes ago --- */
int ifindex; /* 776 4 */
/* XXX 4 bytes hole, try to pack */
struct net_device * dev; /* 784 8 */ netdevice_tracker dev_tracker; /* 792 0 */ struct list_head notifier; /* 792 16 */ unsigned int bound:1; /* 808: 0 4 */ unsigned int loopback:1; /* 808: 1 4 */ unsigned int recv_own_msgs:1; /* 808: 2 4 */ unsigned int fd_frames:1; /* 808: 3 4 */ unsigned int xl_frames:1; /* 808: 4 4 */ unsigned int join_filters:1; /* 808: 5 4 */
/* XXX 2 bits hole, try to pack */
/* Bitfield combined with next fields */
struct can_raw_vcid_options raw_vcid_opts; /* 809 4 */
/* XXX 3 bytes hole, try to pack */
canid_t tx_vcid_shifted; /* 816 4 */ canid_t rx_vcid_shifted; /* 820 4 */ canid_t rx_vcid_mask_shifted; /* 824 4 */ int count; /* 828 4 */ /* --- cacheline 13 boundary (832 bytes) --- */ struct can_filter dfilter; /* 832 8 */ struct can_filter * filter; /* 840 8 */ can_err_mask_t err_mask; /* 848 4 */
/* XXX 4 bytes hole, try to pack */
struct uniqframe * uniq; /* 856 8 */
/* size: 864, cachelines: 14, members: 20 */
/* sum members: 852, holes: 3, sum holes: 11 */
/* sum bitfield members: 6 bits, bit holes: 1, sum bit holes: 2 bits */ /* member types with bit holes: 1, total: 1 */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
--- net/can/raw.c | 59 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 24 deletions(-)
net/can/raw.c +35 -24
@@ -82,20 +82,20 @@ struct uniqframe {struct raw_sock {struct sock sk; -int bound;int ifindex;struct net_device *dev;netdevice_tracker dev_tracker;struct list_head notifier; -int loopback; -int recv_own_msgs; -int fd_frames; -int xl_frames; +unsigned int bound:1 ; +unsigned int loopback:1 ; +unsigned int recv_own_msgs:1 ; +unsigned int fd_frames:1 ; +unsigned int xl_frames:1 ; +unsigned int join_filters:1 ;struct can_raw_vcid_options raw_vcid_opts;canid_t tx_vcid_shifted;canid_t rx_vcid_shifted;canid_t rx_vcid_mask_shifted; -int join_filters;int count;/* number of active filters */ struct can_filter dfilter;/* default/single filter */ struct can_filter *filter;/* pointer to filter(s) */
@@ -560,8 +560,8 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,struct can_filter sfilter;/* single filter */ struct net_device *dev =NULL ;can_err_mask_t err_mask =0 ; -int fd_frames;int count =0 ; +int flag;int err =0 ;if (level !=SOL_CAN_RAW )
@@ -682,44 +682,48 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,break ;case CAN_RAW_LOOPBACK : -if (optlen !=sizeof (ro->loopback)) +if (optlen !=sizeof (flag))return -EINVAL ; -if (copy_from_sockptr (&ro->loopback, optval, optlen)) +if (copy_from_sockptr (&flag, optval, optlen))return -EFAULT ; + ro->loopback = !!flag;break ;case CAN_RAW_RECV_OWN_MSGS : -if (optlen !=sizeof (ro->recv_own_msgs)) +if (optlen !=sizeof (flag))return -EINVAL ; -if (copy_from_sockptr (&ro->recv_own_msgs, optval, optlen)) +if (copy_from_sockptr (&flag, optval, optlen))return -EFAULT ; + ro->recv_own_msgs = !!flag;break ;case CAN_RAW_FD_FRAMES : -if (optlen !=sizeof (fd_frames)) +if (optlen !=sizeof (flag))return -EINVAL ; -if (copy_from_sockptr (&fd_frames, optval, optlen)) +if (copy_from_sockptr (&flag, optval, optlen))return -EFAULT ;/* Enabling CAN XL includes CAN FD */ -if (ro->xl_frames && !fd_frames) +if (ro->xl_frames && !flag)return -EINVAL ; - ro->fd_frames = fd_frames; + ro->fd_frames = !!flag;break ;case CAN_RAW_XL_FRAMES : -if (optlen !=sizeof (ro->xl_frames)) +if (optlen !=sizeof (flag))return -EINVAL ; -if (copy_from_sockptr (&ro->xl_frames, optval, optlen)) +if (copy_from_sockptr (&flag, optval, optlen))return -EFAULT ; + ro->xl_frames = !!flag; +/* Enabling CAN XL includes CAN FD */ if (ro->xl_frames) ro->fd_frames = ro->xl_frames;
@@ -739,12 +743,13 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,break ;case CAN_RAW_JOIN_FILTERS : -if (optlen !=sizeof (ro->join_filters)) +if (optlen !=sizeof (flag))return -EINVAL ; -if (copy_from_sockptr (&ro->join_filters, optval, optlen)) +if (copy_from_sockptr (&flag, optval, optlen))return -EFAULT ; + ro->join_filters = !!flag;break ;default :
@@ -758,6 +763,7 @@ static int raw_getsockopt(struct socket *sock, int level, int optname, {struct sock *sk = sock->sk;struct raw_sock *ro =raw_sk (sk); +int flag;int len;void *val;
@@ -806,25 +812,29 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,case CAN_RAW_LOOPBACK :if (len >sizeof (int )) len =sizeof (int ); - val = &ro->loopback; + flag = ro->loopback; + val = &flag;break ;case CAN_RAW_RECV_OWN_MSGS :if (len >sizeof (int )) len =sizeof (int ); - val = &ro->recv_own_msgs; + flag = ro->recv_own_msgs; + val = &flag;break ;case CAN_RAW_FD_FRAMES :if (len >sizeof (int )) len =sizeof (int ); - val = &ro->fd_frames; + flag = ro->fd_frames; + val = &flag;break ;case CAN_RAW_XL_FRAMES :if (len >sizeof (int )) len =sizeof (int ); - val = &ro->xl_frames; + flag = ro->xl_frames; + val = &flag;break ;case CAN_RAW_XL_VCID_OPTS : {
@@ -849,7 +859,8 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,case CAN_RAW_JOIN_FILTERS :if (len >sizeof (int )) len =sizeof (int ); - val = &ro->join_filters; + flag = ro->join_filters; + val = &flag;break ;default :
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 24/48 can: raw: reorder struct raw_sock's members to optimise packing
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
struct raw_sock has several holes. Reorder the fields to save 8 bytes.
Statistics before:
$ pahole --class_name=raw_sock net/can/raw.o
struct raw_sock {
struct sock sk __attribute__((__aligned__(8))); /* 0 776 *//* XXX last struct has 1 bit hole */
/* --- cacheline 12 boundary (768 bytes) was 8 bytes ago --- */
int ifindex; /* 776 4 */
/* XXX 4 bytes hole, try to pack */
struct net_device * dev; /* 784 8 */ netdevice_tracker dev_tracker; /* 792 0 */ struct list_head notifier; /* 792 16 */ unsigned int bound:1; /* 808: 0 4 */ unsigned int loopback:1; /* 808: 1 4 */ unsigned int recv_own_msgs:1; /* 808: 2 4 */ unsigned int fd_frames:1; /* 808: 3 4 */ unsigned int xl_frames:1; /* 808: 4 4 */ unsigned int join_filters:1; /* 808: 5 4 */
/* XXX 2 bits hole, try to pack */
/* Bitfield combined with next fields */
struct can_raw_vcid_options raw_vcid_opts; /* 809 4 */
/* XXX 3 bytes hole, try to pack */
canid_t tx_vcid_shifted; /* 816 4 */ canid_t rx_vcid_shifted; /* 820 4 */ canid_t rx_vcid_mask_shifted; /* 824 4 */ int count; /* 828 4 */ /* --- cacheline 13 boundary (832 bytes) --- */ struct can_filter dfilter; /* 832 8 */ struct can_filter * filter; /* 840 8 */ can_err_mask_t err_mask; /* 848 4 */
/* XXX 4 bytes hole, try to pack */
struct uniqframe * uniq; /* 856 8 */
/* size: 864, cachelines: 14, members: 20 */
/* sum members: 852, holes: 3, sum holes: 11 */
/* sum bitfield members: 6 bits, bit holes: 1, sum bit holes: 2 bits */ /* member types with bit holes: 1, total: 1 */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
...and after:
$ pahole --class_name=raw_sock net/can/raw.o
struct raw_sock {
struct sock sk __attribute__((__aligned__(8))); /* 0 776 *//* XXX last struct has 1 bit hole */
/* --- cacheline 12 boundary (768 bytes) was 8 bytes ago --- */
struct net_device * dev; /* 776 8 */ netdevice_tracker dev_tracker; /* 784 0 */ struct list_head notifier; /* 784 16 */ int ifindex; /* 800 4 */ unsigned int bound:1; /* 804: 0 4 */ unsigned int loopback:1; /* 804: 1 4 */ unsigned int recv_own_msgs:1; /* 804: 2 4 */ unsigned int fd_frames:1; /* 804: 3 4 */ unsigned int xl_frames:1; /* 804: 4 4 */ unsigned int join_filters:1; /* 804: 5 4 */
/* XXX 2 bits hole, try to pack */
/* Bitfield combined with next fields */
struct can_raw_vcid_options raw_vcid_opts; /* 805 4 */
/* XXX 3 bytes hole, try to pack */
canid_t tx_vcid_shifted; /* 812 4 */ canid_t rx_vcid_shifted; /* 816 4 */ canid_t rx_vcid_mask_shifted; /* 820 4 */ can_err_mask_t err_mask; /* 824 4 */ int count; /* 828 4 */ /* --- cacheline 13 boundary (832 bytes) --- */ struct can_filter dfilter; /* 832 8 */ struct can_filter * filter; /* 840 8 */ struct uniqframe * uniq; /* 848 8 */
/* size: 856, cachelines: 14, members: 20 */
/* sum members: 852, holes: 1, sum holes: 3 */
/* sum bitfield members: 6 bits, bit holes: 1, sum bit holes: 2 bits */ /* member types with bit holes: 1, total: 1 */
/* forced alignments: 1 */
/* last cacheline: 24 bytes */
} __attribute__((__aligned__(8)));
--- net/can/raw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/can/raw.c +2 -2
@@ -82,10 +82,10 @@ struct uniqframe {struct raw_sock {struct sock sk; -int ifindex;struct net_device *dev;netdevice_tracker dev_tracker;struct list_head notifier; +int ifindex;unsigned int bound:1 ;unsigned int loopback:1 ;unsigned int recv_own_msgs:1 ;
@@ -96,10 +96,10 @@ struct raw_sock {canid_t tx_vcid_shifted;canid_t rx_vcid_shifted;canid_t rx_vcid_mask_shifted; +can_err_mask_t err_mask;int count;/* number of active filters */ struct can_filter dfilter;/* default/single filter */ struct can_filter *filter;/* pointer to filter(s) */ -can_err_mask_t err_mask;struct uniqframe __percpu *uniq; };
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 25/48 can: annotate mtu accesses with READ_ONCE()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
As hinted in commit 501a90c94510 ("inet: protect against too small mtu values."), net_device->mtu is vulnerable to race conditions if it is written and read without holding the RTNL.
At the moment, all the writes are done while the interface is down, either in the devices' probe() function or in can_changelink(). So there are no such issues yet. But upcoming changes will allow to modify the MTU while the CAN XL devices are up.
In preparation to the introduction of CAN XL, annotate all the net_device->mtu accesses which are not yet guarded by the RTNL with a READ_ONCE().
Note that all the write accesses are already either guarded by the RTNL or are already annotated and thus need no changes.
--- net/can/af_can.c | 2 +- net/can/isotp.c | 2 +- net/can/raw.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
net/can/af_can.c +1 -1
@@ -221,7 +221,7 @@ int can_send(struct sk_buff *skb, int loop) }/* Make sure the CAN frame can pass the selected CAN netdevice. */ -if (unlikely (skb->len > skb->dev->mtu)) { +if (unlikely (skb->len >READ_ONCE (skb->dev->mtu))) { err = -EMSGSIZE ; goto inval_skb; }
net/can/isotp.c +1 -1
@@ -1313,7 +1313,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len) err = -ENODEV ; goto out; } -if (dev->mtu < so->ll.mtu) { +if (READ_ONCE (dev->mtu) < so->ll.mtu) {dev_put (dev); err = -EINVAL ; goto out;
net/can/raw.c +1 -1
@@ -961,7 +961,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) err = -EINVAL ;/* check for valid CAN (CC/FD/XL) frame content */ - txmtu =raw_check_txframe (ro, skb, dev->mtu); + txmtu =raw_check_txframe (ro, skb,READ_ONCE (dev->mtu));if (!txmtu) goto free_skb;
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 26/48 can: dev: turn can_set_static_ctrlmode() into a non-inline function
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
can_set_static_ctrlmode() is declared as a static inline. But it is only called in the probe function of the devices and so does not really benefit from any kind of optimization.
Transform it into a "normal" function by moving it to
drivers/net/can/dev/dev.c
--- drivers/net/can/dev/dev.c | 21 +++++++++++++++++++++ include/linux/can/dev.h | 23 ++--------------------- 2 files changed, 23 insertions(+), 21 deletions(-)
drivers/net/can/dev/dev.c +21 -0
@@ -347,6 +347,27 @@ int can_change_mtu(struct net_device *dev, int new_mtu) }EXPORT_SYMBOL_GPL (can_change_mtu); +/* helper to define static CAN controller features at device creation time */ +int can_set_static_ctrlmode (struct net_device *dev,u32 static_mode) +{ +struct can_priv *priv =netdev_priv (dev); + +/* alloc_candev() succeeded => netdev_priv() is valid at this point */ +if (priv->ctrlmode_supported & static_mode) { +netdev_warn (dev, +"Controller features can not be supported and static at the same time\n" ); +return -EINVAL ; + } + priv->ctrlmode = static_mode; + +/* override MTU which was set by default in can_setup()? */ +if (static_mode &CAN_CTRLMODE_FD ) + dev->mtu =CANFD_MTU ; + +return 0 ; +} +EXPORT_SYMBOL_GPL (can_set_static_ctrlmode); +/* generic implementation of netdev_ops::ndo_eth_ioctl for CAN devices * supporting hardware timestamps */
include/linux/can/dev.h +2 -21
@@ -125,27 +125,6 @@ static inline s32 can_get_relative_tdco(const struct can_priv *priv)return (s32 )priv->fd.tdc.tdco - sample_point_in_tc; } -/* helper to define static CAN controller features at device creation time */ -static inline int __must_check can_set_static_ctrlmode (struct net_device *dev, -u32 static_mode) -{ -struct can_priv *priv =netdev_priv (dev); - -/* alloc_candev() succeeded => netdev_priv() is valid at this point */ -if (priv->ctrlmode_supported & static_mode) { -netdev_warn (dev, -"Controller features can not be supported and static at the same time\n" ); -return -EINVAL ; - } - priv->ctrlmode = static_mode; - -/* override MTU which was set by default in can_setup()? */ -if (static_mode &CAN_CTRLMODE_FD ) - dev->mtu =CANFD_MTU ; - -return 0 ; -} -static inline u32 can_get_static_ctrlmode (struct can_priv *priv) {return priv->ctrlmode & ~priv->ctrlmode_supported;
@@ -188,6 +167,8 @@ struct can_priv *safe_candev_priv(struct net_device *dev);int open_candev (struct net_device *dev);void close_candev (struct net_device *dev);int can_change_mtu (struct net_device *dev,int new_mtu); +int __must_check can_set_static_ctrlmode (struct net_device *dev, +u32 static_mode);int can_eth_ioctl_hwts (struct net_device *netdev,struct ifreq *ifr,int cmd);int can_ethtool_op_get_ts_info_hwts (struct net_device *dev,struct kernel_ethtool_ts_info *info);
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 27/48 can: populate the minimum and maximum MTU values
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
By populating:
net_device->min_mtu
and
net_device->max_mtu
the net core infrastructure will automatically:
1. validate that the user's inputs are in range.
2. report those min and max MTU values through the netlink interface.
Add can_set_default_mtu() which sets the default mtu value as well as the minimum and maximum values. The logic for the default mtu value remains unchanged:
- CANFD_MTU if the device has a static CAN_CTRLMODE_FD.
- CAN_MTU otherwise.
Call can_set_default_mtu() each time the CAN_CTRLMODE_FD is modified. This will guarantee that the MTU value is always consistent with the control mode flags.
With this, the checks done in can_change_mtu() become fully redundant and will be removed in an upcoming change and it is now possible to confirm the minimum and maximum MTU values on a physical CAN interface by doing:
$ ip --details link show can0
The virtual interfaces (vcan and vxcan) are not impacted by this change.
--- drivers/net/can/dev/dev.c | 20 ++++++++++++++++++-- drivers/net/can/dev/netlink.c | 9 ++++----- include/linux/can/dev.h | 1 + 3 files changed, 23 insertions(+), 7 deletions(-)
drivers/net/can/dev/dev.c +18 -2
@@ -240,6 +240,8 @@ void can_setup(struct net_device *dev) { dev->type =ARPHRD_CAN ; dev->mtu =CAN_MTU ; + dev->min_mtu =CAN_MTU ; + dev->max_mtu =CAN_MTU ; dev->hard_header_len =0 ; dev->addr_len =0 ; dev->tx_queue_len =10 ;
@@ -309,6 +311,21 @@ void free_candev(struct net_device *dev) }EXPORT_SYMBOL_GPL (free_candev); +void can_set_default_mtu (struct net_device *dev) +{ +struct can_priv *priv =netdev_priv (dev); + +if (priv->ctrlmode &CAN_CTRLMODE_FD ) { + dev->mtu =CANFD_MTU ; + dev->min_mtu =CANFD_MTU ; + dev->max_mtu =CANFD_MTU ; + }else { + dev->mtu =CAN_MTU ; + dev->min_mtu =CAN_MTU ; + dev->max_mtu =CAN_MTU ; + } +} +/* changing MTU and control mode for CAN/CANFD devices */ int can_change_mtu (struct net_device *dev,int new_mtu) {
@@ -361,8 +378,7 @@ int can_set_static_ctrlmode(struct net_device *dev, u32 static_mode) priv->ctrlmode = static_mode;/* override MTU which was set by default in can_setup()? */ -if (static_mode &CAN_CTRLMODE_FD ) - dev->mtu =CANFD_MTU ; +can_set_default_mtu (dev);return 0 ; }
drivers/net/can/dev/netlink.c +4 -5
@@ -223,17 +223,16 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[], priv->ctrlmode &= ~cm->mask; priv->ctrlmode |= maskedflags; -/* CAN_CTRLMODE_FD can only be set when driver supports FD */ -if (priv->ctrlmode &CAN_CTRLMODE_FD ) { - dev->mtu =CANFD_MTU ; - }else { - dev->mtu =CAN_MTU ; +/* Wipe potential leftovers from previous CAN FD config */ +if (!(priv->ctrlmode &CAN_CTRLMODE_FD )) {memset (&priv->fd.data_bittiming,0 ,sizeof (priv->fd.data_bittiming)); priv->ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK ;memset (&priv->fd.tdc,0 ,sizeof (priv->fd.tdc)); } +can_set_default_mtu (dev); + fd_tdc_flag_provided = cm->mask &CAN_CTRLMODE_FD_TDC_MASK ;/* CAN_CTRLMODE_TDC_{AUTO,MANUAL} are mutually * exclusive: make sure to turn the other one off
include/linux/can/dev.h +1 -0
@@ -166,6 +166,7 @@ struct can_priv *safe_candev_priv(struct net_device *dev);int open_candev (struct net_device *dev);void close_candev (struct net_device *dev); +void can_set_default_mtu (struct net_device *dev);int can_change_mtu (struct net_device *dev,int new_mtu);int __must_check can_set_static_ctrlmode (struct net_device *dev,u32 static_mode);
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 28/48 can: enable CAN XL for virtual CAN devices by default
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
In commit 97edec3a11cf ("can: enable CAN FD for virtual CAN devices by default"), vcan and vxcan default MTU was set to CANFD_MTU by default. The reason was that users were confused on how to activate CAN FD on virtual interfaces.
Following the introduction of CAN XL, the same logic should be applied. Set the MTU to CANXL_MTU by default.
The users who really wish to use a Classical CAN only or a CAN FD virtual device can do respectively:
$ ip link set vcan0 mtu 16
or
$ ip link set vcan0 mtu 72
to force the old behaviour.
--- drivers/net/can/vcan.c | 2 +- drivers/net/can/vxcan.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/vcan.c +1 -1
@@ -156,7 +156,7 @@ static const struct ethtool_ops vcan_ethtool_ops = {static void vcan_setup (struct net_device *dev) { dev->type =ARPHRD_CAN ; - dev->mtu =CANFD_MTU ; + dev->mtu =CANXL_MTU ; dev->hard_header_len =0 ; dev->addr_len =0 ; dev->tx_queue_len =0 ;
drivers/net/can/vxcan.c +1 -1
@@ -156,7 +156,7 @@ static void vxcan_setup(struct net_device *dev)struct can_ml_priv *can_ml; dev->type =ARPHRD_CAN ; - dev->mtu =CANFD_MTU ; + dev->mtu =CANXL_MTU ; dev->hard_header_len =0 ; dev->addr_len =0 ; dev->tx_queue_len =0 ;
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 29/48 can: dev: move struct data_bittiming_params to linux/can/bittiming.h
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
In commit b803c4a4f788 ("can: dev: add struct data_bittiming_params to group FD parameters"), struct data_bittiming_params was put into linux/can/dev.h.
This structure being a collection of bittiming parameters, on second thought, bittiming.h is actually a better location. This way, users of struct data_bittiming_params will not have to forcefully include linux/can/dev.h thus removing some complexity and reducing the risk of circular dependencies in headers.
Move struct data_bittiming_params from linux/can/dev.h to linux/can/bittiming.h.
--- include/linux/can/bittiming.h | 11 +++++++++++ include/linux/can/dev.h | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-)
include/linux/can/bittiming.h +11 -0
@@ -114,6 +114,17 @@ struct can_tdc_const {u32 tdcf_max; }; +struct data_bittiming_params { +const struct can_bittiming_const *data_bittiming_const; +struct can_bittiming data_bittiming; +const struct can_tdc_const *tdc_const; +struct can_tdc tdc; +const u32 *data_bitrate_const; +unsigned int data_bitrate_const_cnt; +int (*do_set_data_bittiming)(struct net_device *dev); +int (*do_get_auto_tdcv)(const struct net_device *dev,u32 *tdcv); +}; +#ifdef CONFIG_CAN_CALC_BITTIMING int can_calc_bittiming (const struct net_device *dev,struct can_bittiming *bt,const struct can_bittiming_const *btc,struct netlink_ext_ack *extack);
include/linux/can/dev.h +0 -11
@@ -38,17 +38,6 @@ enum can_termination_gpio { CAN_TERMINATION_GPIO_MAX, }; -struct data_bittiming_params { -const struct can_bittiming_const *data_bittiming_const; -struct can_bittiming data_bittiming; -const struct can_tdc_const *tdc_const; -struct can_tdc tdc; -const u32 *data_bitrate_const; -unsigned int data_bitrate_const_cnt; -int (*do_set_data_bittiming)(struct net_device *dev); -int (*do_get_auto_tdcv)(const struct net_device *dev,u32 *tdcv); -}; -/* * CAN common private data */
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 30/48 can: dev: make can_get_relative_tdco() FD agnostic and move it to bittiming.h
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
can_get_relative_tdco() needs to access can_priv->fd making it specific to CAN FD. Change the function parameter from struct can_priv to struct data_bittiming_params. This way, the function becomes CAN FD agnostic and can be reused later on for the CAN XL TDC.
Now that we dropped the dependency on struct can_priv, also move can_get_relative_tdco() back to bittiming.h where it was meant to belong to.
--- include/linux/can/bittiming.h | 29 +++++++++++++++++++++++++++++ include/linux/can/dev.h | 29 ----------------------------- 2 files changed, 29 insertions(+), 29 deletions(-)
include/linux/can/bittiming.h +29 -0
@@ -160,6 +160,35 @@ int can_get_bittiming(const struct net_device *dev, struct can_bittiming *bt,const unsigned int bitrate_const_cnt, struct netlink_ext_ack *extack); +/* +* can_get_relative_tdco() - TDCO relative to the sample point +* +* struct can_tdc::tdco represents the absolute offset from TDCV. Some +* controllers use instead an offset relative to the Sample Point (SP) +* such that: +* +* SSP = TDCV + absolute TDCO +* = TDCV + SP + relative TDCO +* +* -+----------- one bit ----------+-- TX pin +* |<--- Sample Point --->| +* +* --+----------- one bit ----------+-- RX pin +* |<-------- TDCV -------->| +* |<------------------------>| absolute TDCO +* |<--- Sample Point --->| +* | |<->| relative TDCO +* |<------------- Secondary Sample Point ------------>| +*/ +static inline s32 can_get_relative_tdco (const struct data_bittiming_params *dbt_params) +{ +const struct can_bittiming *dbt = &dbt_params->data_bittiming; +s32 sample_point_in_tc = (CAN_SYNC_SEG + dbt->prop_seg + + dbt->phase_seg1) * dbt->brp; + +return (s32 )dbt_params->tdc.tdco - sample_point_in_tc; +} +/* * can_bit_time() - Duration of one bit *
include/linux/can/dev.h +0 -29
@@ -85,35 +85,6 @@ static inline bool can_fd_tdc_is_enabled(const struct can_priv *priv)return !!(priv->ctrlmode &CAN_CTRLMODE_FD_TDC_MASK ); } -/* -* can_get_relative_tdco() - TDCO relative to the sample point -* -* struct can_tdc::tdco represents the absolute offset from TDCV. Some -* controllers use instead an offset relative to the Sample Point (SP) -* such that: -* -* SSP = TDCV + absolute TDCO -* = TDCV + SP + relative TDCO -* -* -+----------- one bit ----------+-- TX pin -* |<--- Sample Point --->| -* -* --+----------- one bit ----------+-- RX pin -* |<-------- TDCV -------->| -* |<------------------------>| absolute TDCO -* |<--- Sample Point --->| -* | |<->| relative TDCO -* |<------------- Secondary Sample Point ------------>| -*/ -static inline s32 can_get_relative_tdco (const struct can_priv *priv) -{ -const struct can_bittiming *dbt = &priv->fd.data_bittiming; -s32 sample_point_in_tc = (CAN_SYNC_SEG + dbt->prop_seg + - dbt->phase_seg1) * dbt->brp; - -return (s32 )priv->fd.tdc.tdco - sample_point_in_tc; -} -static inline u32 can_get_static_ctrlmode (struct can_priv *priv) {return priv->ctrlmode & ~priv->ctrlmode_supported;
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 31/48 can: netlink: document which symbols are FD specific
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
The CAN XL netlink interface will also have data bitrate and TDC parameters. The current FD parameters do not have a prefix in their names to differentiate them.
Because the netlink interface is part of the UAPI, it is unfortunately not feasible to rename the existing symbols to add an FD_ prefix. The best alternative is to add a comment for each of the symbols to notify the reader of which parts are CAN FD specific.
While at it, fix a typo: transiver -> transceiver.
--- include/uapi/linux/can/netlink.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
include/uapi/linux/can/netlink.h +7 -7
@@ -101,8 +101,8 @@ struct can_ctrlmode {#define CAN_CTRLMODE_PRESUME_ACK 0x40/* Ignore missing CAN ACKs */ #define CAN_CTRLMODE_FD_NON_ISO 0x80/* CAN FD in non-ISO mode */ #define CAN_CTRLMODE_CC_LEN8_DLC 0x100/* Classic CAN DLC option */ -#define CAN_CTRLMODE_TDC_AUTO 0x200/* CAN transiver automatically calculates TDCV */ -#define CAN_CTRLMODE_TDC_MANUAL 0x400/* TDCV is manually set up by user */ +#define CAN_CTRLMODE_TDC_AUTO 0x200/* FD transceiver automatically calculates TDCV */ +#define CAN_CTRLMODE_TDC_MANUAL 0x400/* FD TDCV is manually set up by user */ /* * CAN device statistics
@@ -129,14 +129,14 @@ enum {IFLA_CAN_RESTART_MS ,IFLA_CAN_RESTART ,IFLA_CAN_BERR_COUNTER , -IFLA_CAN_DATA_BITTIMING , -IFLA_CAN_DATA_BITTIMING_CONST , +IFLA_CAN_DATA_BITTIMING ,/* FD */ +IFLA_CAN_DATA_BITTIMING_CONST ,/* FD */ IFLA_CAN_TERMINATION ,IFLA_CAN_TERMINATION_CONST ,IFLA_CAN_BITRATE_CONST , -IFLA_CAN_DATA_BITRATE_CONST , +IFLA_CAN_DATA_BITRATE_CONST ,/* FD */ IFLA_CAN_BITRATE_MAX , -IFLA_CAN_TDC , +IFLA_CAN_TDC ,/* FD */ IFLA_CAN_CTRLMODE_EXT , /* add new constants above here */
@@ -145,7 +145,7 @@ enum { };/* -* CAN FD Transmitter Delay Compensation (TDC) +* CAN FD/XL Transmitter Delay Compensation (TDC) * * Please refer to struct can_tdc_const and can_tdc in * include/linux/can/bittiming.h for further details.
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 32/48 can: netlink: refactor can_validate_bittiming()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Whenever can_validate_bittiming() is called, it is always preceded by some boilerplate code which was copy pasted all over the place. Move that repeated code directly inside can_validate_bittiming().
Finally, the mempcy() is not needed: the nla attributes are four bytes aligned which is just enough for struct can_bittiming. Add a static_assert() to document that the alignment is correct and just use the pointer returned by nla_data() as-is.
--- drivers/net/can/dev/netlink.c | 36 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-)
drivers/net/can/dev/netlink.c +17 -19
@@ -36,13 +36,21 @@ static const struct nla_policy can_tdc_policy[IFLA_CAN_TDC_MAX + 1] = { [IFLA_CAN_TDC_TDCF] = { .type = NLA_U32 }, }; -static int can_validate_bittiming (const struct can_bittiming *bt, -struct netlink_ext_ack *extack) +static int can_validate_bittiming (struct nlattr *data[], +struct netlink_ext_ack *extack, +int ifla_can_bittiming) { +struct can_bittiming *bt; + +if (!data[ifla_can_bittiming]) +return 0 ; + + static_assert(__alignof__(*bt) <= NLA_ALIGNTO); + bt =nla_data (data[ifla_can_bittiming]); +/* sample point is in one-tenth of a percent */ if (bt->sample_point >=1000 ) {NL_SET_ERR_MSG (extack,"sample point must be between 0 and 100%" ); -return -EINVAL ; }
@@ -105,14 +113,9 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[], } } -if (data[IFLA_CAN_BITTIMING ]) { -struct can_bittiming bt; - -memcpy (&bt,nla_data (data[IFLA_CAN_BITTIMING ]),sizeof (bt)); - err =can_validate_bittiming (&bt, extack); -if (err) -return err; - } + err =can_validate_bittiming (data, extack,IFLA_CAN_BITTIMING ); +if (err) +return err;if (is_can_fd) {if (!data[IFLA_CAN_BITTIMING ] || !data[IFLA_CAN_DATA_BITTIMING ])
@@ -124,14 +127,9 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[],return -EOPNOTSUPP ; } -if (data[IFLA_CAN_DATA_BITTIMING ]) { -struct can_bittiming bt; - -memcpy (&bt,nla_data (data[IFLA_CAN_DATA_BITTIMING ]),sizeof (bt)); - err =can_validate_bittiming (&bt, extack); -if (err) -return err; - } + err =can_validate_bittiming (data, extack,IFLA_CAN_DATA_BITTIMING ); +if (err) +return err;return 0 ; }
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 33/48 can: netlink: add can_validate_tdc()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Factorise the TDC validation out of can_validate() and move it in the new can_validate_tdc() function. This is a preparation patch for the introduction of CAN XL because this TDC validation will be reused later on.
--- drivers/net/can/dev/netlink.c | 82 ++++++++++++++++++++--------------- include/linux/can/bittiming.h | 4 ++ 2 files changed, 52 insertions(+), 34 deletions(-)
drivers/net/can/dev/netlink.c +48 -34
@@ -57,6 +57,49 @@ static int can_validate_bittiming(struct nlattr *data[],return 0 ; } +static int can_validate_tdc (struct nlattr *data_tdc, +struct netlink_ext_ack *extack,u32 tdc_flags) +{ +bool tdc_manual = tdc_flags &CAN_CTRLMODE_TDC_MANUAL_MASK ; +bool tdc_auto = tdc_flags &CAN_CTRLMODE_TDC_AUTO_MASK ; +int err; + +/* CAN_CTRLMODE_TDC_{AUTO,MANUAL} are mutually exclusive */ +if (tdc_auto && tdc_manual) +return -EOPNOTSUPP ; + +/* If one of the CAN_CTRLMODE_TDC_* flag is set then TDC +* must be set and vice-versa +*/ +if ((tdc_auto || tdc_manual) != !!data_tdc) +return -EOPNOTSUPP ; + +/* If providing TDC parameters, at least TDCO is needed. TDCV +* is needed if and only if CAN_CTRLMODE_TDC_MANUAL is set +*/ +if (data_tdc) { +struct nlattr *tb_tdc[IFLA_CAN_TDC_MAX +1 ]; + + err =nla_parse_nested (tb_tdc,IFLA_CAN_TDC_MAX , + data_tdc, can_tdc_policy, extack); +if (err) +return err; + +if (tb_tdc[IFLA_CAN_TDC_TDCV ]) { +if (tdc_auto) +return -EOPNOTSUPP ; + }else { +if (tdc_manual) +return -EOPNOTSUPP ; + } + +if (!tb_tdc[IFLA_CAN_TDC_TDCO ]) +return -EOPNOTSUPP ; + } + +return 0 ; +} +static int can_validate (struct nlattr *tb[],struct nlattr *data[],struct netlink_ext_ack *extack) {
@@ -67,7 +110,7 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[],* - nominal/arbitration bittiming * - data bittiming * - control mode with CAN_CTRLMODE_FD set -* - TDC parameters are coherent (details below) +* - TDC parameters are coherent (details in can_validate_tdc()) */ if (!data)
@@ -75,42 +118,13 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[],if (data[IFLA_CAN_CTRLMODE ]) {struct can_ctrlmode *cm =nla_data (data[IFLA_CAN_CTRLMODE ]); -u32 tdc_flags = cm->flags &CAN_CTRLMODE_FD_TDC_MASK ; is_can_fd = cm->flags & cm->mask &CAN_CTRLMODE_FD ; -/* CAN_CTRLMODE_TDC_{AUTO,MANUAL} are mutually exclusive */ -if (tdc_flags ==CAN_CTRLMODE_FD_TDC_MASK ) -return -EOPNOTSUPP ; -/* If one of the CAN_CTRLMODE_TDC_* flag is set then -* TDC must be set and vice-versa -*/ -if (!!tdc_flags != !!data[IFLA_CAN_TDC ]) -return -EOPNOTSUPP ; -/* If providing TDC parameters, at least TDCO is -* needed. TDCV is needed if and only if -* CAN_CTRLMODE_TDC_MANUAL is set -*/ -if (data[IFLA_CAN_TDC ]) { -struct nlattr *tb_tdc[IFLA_CAN_TDC_MAX +1 ]; - - err =nla_parse_nested (tb_tdc,IFLA_CAN_TDC_MAX , - data[IFLA_CAN_TDC ], - can_tdc_policy, extack); -if (err) -return err; - -if (tb_tdc[IFLA_CAN_TDC_TDCV ]) { -if (tdc_flags &CAN_CTRLMODE_TDC_AUTO ) -return -EOPNOTSUPP ; - }else { -if (tdc_flags &CAN_CTRLMODE_TDC_MANUAL ) -return -EOPNOTSUPP ; - } - -if (!tb_tdc[IFLA_CAN_TDC_TDCO ]) -return -EOPNOTSUPP ; - } + err =can_validate_tdc (data[IFLA_CAN_TDC ], extack, + cm->flags &CAN_CTRLMODE_FD_TDC_MASK ); +if (err) +return err; } err =can_validate_bittiming (data, extack,IFLA_CAN_BITTIMING );
include/linux/can/bittiming.h +4 -0
@@ -16,6 +16,10 @@#define CAN_CTRLMODE_FD_TDC_MASK \ (CAN_CTRLMODE_TDC_AUTO | CAN_CTRLMODE_TDC_MANUAL) +#define CAN_CTRLMODE_TDC_AUTO_MASK \ + (CAN_CTRLMODE_TDC_AUTO) +#define CAN_CTRLMODE_TDC_MANUAL_MASK \ + (CAN_CTRLMODE_TDC_MANUAL)/* * struct can_tdc - CAN FD Transmission Delay Compensation parameters
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 34/48 can: netlink: add can_validate_databittiming()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Factorise the databittiming validation out of can_validate() and move it in the new add can_validate_databittiming() function. Also move can_validate()'s comment because it is specific to CAN FD. This is a preparation patch for the introduction of CAN XL as this databittiming validation will be reused later on.
--- drivers/net/can/dev/netlink.c | 64 ++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 20 deletions(-)
drivers/net/can/dev/netlink.c +44 -20
@@ -100,10 +100,13 @@ static int can_validate_tdc(struct nlattr *data_tdc,return 0 ; } -static int can_validate (struct nlattr *tb[],struct nlattr *data[], -struct netlink_ext_ack *extack) +static int can_validate_databittiming (struct nlattr *data[], +struct netlink_ext_ack *extack, +int ifla_can_data_bittiming,u32 flags) { -bool is_can_fd = false; +struct nlattr *data_tdc; +u32 tdc_flags; +bool is_on;int err;/* Make sure that valid CAN FD configurations always consist of
@@ -113,35 +116,56 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[],* - TDC parameters are coherent (details in can_validate_tdc()) */ +if (ifla_can_data_bittiming ==IFLA_CAN_DATA_BITTIMING ) { + data_tdc = data[IFLA_CAN_TDC ]; + tdc_flags = flags &CAN_CTRLMODE_FD_TDC_MASK ; + is_on = flags &CAN_CTRLMODE_FD ; + }else { +return -EOPNOTSUPP ;/* Place holder for CAN XL */ + } + +if (is_on) { +if (!data[IFLA_CAN_BITTIMING ] || !data[ifla_can_data_bittiming]) +return -EOPNOTSUPP ; + } + +if (data[ifla_can_data_bittiming] || data_tdc) { +if (!is_on) +return -EOPNOTSUPP ; + } + + err =can_validate_bittiming (data, extack, ifla_can_data_bittiming); +if (err) +return err; + + err =can_validate_tdc (data_tdc, extack, tdc_flags); +if (err) +return err; + +return 0 ; +} + +static int can_validate (struct nlattr *tb[],struct nlattr *data[], +struct netlink_ext_ack *extack) +{ +u32 flags =0 ; +int err; +if (!data)return 0 ;if (data[IFLA_CAN_CTRLMODE ]) {struct can_ctrlmode *cm =nla_data (data[IFLA_CAN_CTRLMODE ]); - is_can_fd = cm->flags & cm->mask &CAN_CTRLMODE_FD ; - - err =can_validate_tdc (data[IFLA_CAN_TDC ], extack, - cm->flags &CAN_CTRLMODE_FD_TDC_MASK ); -if (err) -return err; + flags = cm->flags & cm->mask; } err =can_validate_bittiming (data, extack,IFLA_CAN_BITTIMING );if (err)return err; -if (is_can_fd) { -if (!data[IFLA_CAN_BITTIMING ] || !data[IFLA_CAN_DATA_BITTIMING ]) -return -EOPNOTSUPP ; - } - -if (data[IFLA_CAN_DATA_BITTIMING ] || data[IFLA_CAN_TDC ]) { -if (!is_can_fd) -return -EOPNOTSUPP ; - } - - err =can_validate_bittiming (data, extack,IFLA_CAN_DATA_BITTIMING ); + err =can_validate_databittiming (data, extack, +IFLA_CAN_DATA_BITTIMING , flags);if (err)return err;
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 35/48 can: netlink: refactor CAN_CTRLMODE_TDC_{AUTO,MANUAL} flag reset logic
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
CAN_CTRLMODE_TDC_AUTO and CAN_CTRLMODE_TDC_MANUAL are mutually exclusive. This means that whenever the user switches from auto to manual mode (or vice versa), the other flag which was set previously needs to be cleared.
Currently, this is handled with a masking operation. It can be done in a simpler manner by clearing any of the previous TDC flags before copying netlink attributes. The code becomes easier to understand and will make it easier to add the new upcoming CAN XL flags which will have a similar reset logic as the current TDC flags.
--- drivers/net/can/dev/netlink.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/can/dev/netlink.c +4 -5
@@ -255,6 +255,10 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],if ((maskedflags & ctrlstatic) != ctrlstatic)return -EOPNOTSUPP ; +/* If a top dependency flag is provided, reset all its dependencies */ +if (cm->mask &CAN_CTRLMODE_FD ) + priv->ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK ; +/* clear bits to be modified and copy the flag values */ priv->ctrlmode &= ~cm->mask; priv->ctrlmode |= maskedflags;
@@ -270,11 +274,6 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],can_set_default_mtu (dev); fd_tdc_flag_provided = cm->mask &CAN_CTRLMODE_FD_TDC_MASK ; -/* CAN_CTRLMODE_TDC_{AUTO,MANUAL} are mutually -* exclusive: make sure to turn the other one off -*/ -if (fd_tdc_flag_provided) - priv->ctrlmode &= cm->flags | ~CAN_CTRLMODE_FD_TDC_MASK ; }if (data[IFLA_CAN_BITTIMING ]) {
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 36/48 can: netlink: remove useless check in can_tdc_changelink()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
can_tdc_changelink() return -EOPNOTSUPP under this condition:
!tdc_const || !can_fd_tdc_is_enabled(priv)
But this function is only called if the data[IFLA_CAN_TDC] parameters are provided. At this point, can_validate_tdc() already checked that either of the tdc auto or tdc manual control modes were provided, that is to say, can_fd_tdc_is_enabled(priv) must be true.
Because the right hand operand of this condition is always true, remove it.
--- drivers/net/can/dev/netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/dev/netlink.c +1 -1
@@ -180,7 +180,7 @@ static int can_tdc_changelink(struct can_priv *priv, const struct nlattr *nla,const struct can_tdc_const *tdc_const = priv->fd.tdc_const;int err; -if (!tdc_const || !can_fd_tdc_is_enabled (priv)) +if (!tdc_const)return -EOPNOTSUPP ; err = nla_parse_nested(tb_tdc, IFLA_CAN_TDC_MAX, nla,
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 37/48 can: netlink: make can_tdc_changelink() FD agnostic
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
can_tdc_changelink() needs to access can_priv->fd making it specific to CAN FD. Change the function parameter from struct can_priv to struct data_bittiming_params. This way, the function becomes CAN FD agnostic and can be reused later on for the CAN XL TDC.
--- drivers/net/can/dev/netlink.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/can/dev/netlink.c +6 -5
@@ -172,12 +172,13 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[],return 0 ; } -static int can_tdc_changelink (struct can_priv *priv,const struct nlattr *nla, +static int can_tdc_changelink (struct data_bittiming_params *dbt_params, +const struct nlattr *nla,struct netlink_ext_ack *extack) {struct nlattr *tb_tdc[IFLA_CAN_TDC_MAX +1 ];struct can_tdc tdc = {0 }; -const struct can_tdc_const *tdc_const = priv->fd.tdc_const; +const struct can_tdc_const *tdc_const = dbt_params->tdc_const;int err;if (!tdc_const)
@@ -215,7 +216,7 @@ static int can_tdc_changelink(struct can_priv *priv, const struct nlattr *nla, tdc.tdcf = tdcf; } - priv->fd.tdc = tdc; + dbt_params->tdc = tdc;return 0 ; }
@@ -382,8 +383,8 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],memset (&priv->fd.tdc,0 ,sizeof (priv->fd.tdc));if (data[IFLA_CAN_TDC ]) {/* TDC parameters are provided: use them */ - err =can_tdc_changelink (priv, data[IFLA_CAN_TDC ], - extack); + err =can_tdc_changelink (&priv->fd, + data[IFLA_CAN_TDC ], extack);if (err) { priv->ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK ;return err;
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 38/48 can: netlink: add can_dtb_changelink()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Factorise the databittiming parsing out of can_changelink() and move it in the new can_dtb_changelink() function. This is a preparation patch for the introduction of CAN XL because the databittiming changelink logic will be reused later on.
--- drivers/net/can/dev/netlink.c | 152 ++++++++++++++++++++-------------- 1 file changed, 88 insertions(+), 64 deletions(-)
drivers/net/can/dev/netlink.c +88 -64
@@ -221,12 +221,95 @@ static int can_tdc_changelink(struct data_bittiming_params *dbt_params,return 0 ; } +static int can_dbt_changelink (struct net_device *dev,struct nlattr *data[], +bool fd,struct netlink_ext_ack *extack) +{ +struct nlattr *data_bittiming, *data_tdc; +struct can_priv *priv =netdev_priv (dev); +struct data_bittiming_params *dbt_params; +struct can_bittiming dbt; +bool need_tdc_calc = false; +u32 tdc_mask; +int err; + +if (fd) { + data_bittiming = data[IFLA_CAN_DATA_BITTIMING ]; + data_tdc = data[IFLA_CAN_TDC ]; + dbt_params = &priv->fd; + tdc_mask =CAN_CTRLMODE_FD_TDC_MASK ; + }else { +return -EOPNOTSUPP ;/* Place holder for CAN XL */ + } + +if (!data_bittiming) +return 0 ; + +/* Do not allow changing bittiming while running */ +if (dev->flags &IFF_UP ) +return -EBUSY ; + +/* Calculate bittiming parameters based on data_bittiming_const +* if set, otherwise pass bitrate directly via do_set_bitrate(). +* Bail out if neither is given. +*/ +if (!dbt_params->data_bittiming_const && !dbt_params->do_set_data_bittiming && + !dbt_params->data_bitrate_const) +return -EOPNOTSUPP ; + +memcpy (&dbt,nla_data (data_bittiming),sizeof (dbt)); + err =can_get_bittiming (dev, &dbt, dbt_params->data_bittiming_const, + dbt_params->data_bitrate_const, + dbt_params->data_bitrate_const_cnt, extack); +if (err) +return err; + +if (priv->bitrate_max && dbt.bitrate > priv->bitrate_max) { +NL_SET_ERR_MSG_FMT (extack, +"CAN data bitrate %u bps surpasses transceiver capabilities of %u bps" , + dbt.bitrate, priv->bitrate_max); +return -EINVAL ; + } + +memset (&dbt_params->tdc,0 ,sizeof (dbt_params->tdc)); +if (data[IFLA_CAN_CTRLMODE ]) { +struct can_ctrlmode *cm =nla_data (data[IFLA_CAN_CTRLMODE ]); + + need_tdc_calc = !(cm->mask & tdc_mask); + } +if (data_tdc) { +/* TDC parameters are provided: use them */ + err =can_tdc_changelink (dbt_params, data_tdc, extack); +if (err) { + priv->ctrlmode &= ~tdc_mask; +return err; + } + }else if (need_tdc_calc) { +/* Neither of TDC parameters nor TDC flags are provided: +* do calculation +*/ +can_calc_tdco (&dbt_params->tdc, dbt_params->tdc_const, &dbt, + &priv->ctrlmode, priv->ctrlmode_supported); + }/* else: both CAN_CTRLMODE_TDC_{AUTO,MANUAL} are explicitly +* turned off. TDC is disabled: do nothing +*/ + +memcpy (&dbt_params->data_bittiming, &dbt,sizeof (dbt)); + +if (dbt_params->do_set_data_bittiming) { +/* Finally, set the bit-timing registers */ + err = dbt_params->do_set_data_bittiming (dev); +if (err) +return err; + } + +return 0 ; +} +static int can_changelink (struct net_device *dev,struct nlattr *tb[],struct nlattr *data[],struct netlink_ext_ack *extack) {struct can_priv *priv =netdev_priv (dev); -bool fd_tdc_flag_provided = false;int err;/* We need synchronization with dev->stop() */
@@ -273,8 +356,6 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[], }can_set_default_mtu (dev); - - fd_tdc_flag_provided = cm->mask &CAN_CTRLMODE_FD_TDC_MASK ; }if (data[IFLA_CAN_BITTIMING ]) {
@@ -347,67 +428,10 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],return err; } -if (data[IFLA_CAN_DATA_BITTIMING ]) { -struct can_bittiming dbt; - -/* Do not allow changing bittiming while running */ -if (dev->flags &IFF_UP ) -return -EBUSY ; - -/* Calculate bittiming parameters based on -* data_bittiming_const if set, otherwise pass bitrate -* directly via do_set_bitrate(). Bail out if neither -* is given. -*/ -if (!priv->fd.data_bittiming_const && !priv->fd.do_set_data_bittiming && - !priv->fd.data_bitrate_const) -return -EOPNOTSUPP ; - -memcpy (&dbt,nla_data (data[IFLA_CAN_DATA_BITTIMING ]), -sizeof (dbt)); - err =can_get_bittiming (dev, &dbt, - priv->fd.data_bittiming_const, - priv->fd.data_bitrate_const, - priv->fd.data_bitrate_const_cnt, - extack); -if (err) -return err; - -if (priv->bitrate_max && dbt.bitrate > priv->bitrate_max) { -NL_SET_ERR_MSG_FMT (extack, -"CANFD data bitrate %u bps surpasses transceiver capabilities of %u bps" , - dbt.bitrate, priv->bitrate_max); -return -EINVAL ; - } - -memset (&priv->fd.tdc,0 ,sizeof (priv->fd.tdc)); -if (data[IFLA_CAN_TDC ]) { -/* TDC parameters are provided: use them */ - err =can_tdc_changelink (&priv->fd, - data[IFLA_CAN_TDC ], extack); -if (err) { - priv->ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK ; -return err; - } - }else if (!fd_tdc_flag_provided) { -/* Neither of TDC parameters nor TDC flags are -* provided: do calculation -*/ -can_calc_tdco (&priv->fd.tdc, priv->fd.tdc_const, &dbt, - &priv->ctrlmode, priv->ctrlmode_supported); - }/* else: both CAN_CTRLMODE_TDC_{AUTO,MANUAL} are explicitly -* turned off. TDC is disabled: do nothing -*/ - -memcpy (&priv->fd.data_bittiming, &dbt,sizeof (dbt)); - -if (priv->fd.do_set_data_bittiming) { -/* Finally, set the bit-timing registers */ - err = priv->fd.do_set_data_bittiming (dev); -if (err) -return err; - } - } +/* CAN FD */ + err =can_dbt_changelink (dev, data, true, extack); +if (err) +return err;if (data[IFLA_CAN_TERMINATION ]) {const u16 termval =nla_get_u16 (data[IFLA_CAN_TERMINATION ]);
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 39/48 can: netlink: add can_ctrlmode_changelink()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Split the control mode change link logic into a new function:can_ctrlmode_changelink(). The purpose is to increase code readability by preventing can_changelink() from becoming too big.
--- drivers/net/can/dev/netlink.c | 96 ++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 42 deletions(-)
drivers/net/can/dev/netlink.c +54 -42
@@ -172,6 +172,59 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[],return 0 ; } +static int can_ctrlmode_changelink (struct net_device *dev, +struct nlattr *data[], +struct netlink_ext_ack *extack) +{ +struct can_priv *priv =netdev_priv (dev); +struct can_ctrlmode *cm; +u32 maskedflags; +u32 ctrlstatic; + +if (!data[IFLA_CAN_CTRLMODE ]) +return 0 ; + +/* Do not allow changing controller mode while running */ +if (dev->flags &IFF_UP ) +return -EBUSY ; + + cm =nla_data (data[IFLA_CAN_CTRLMODE ]); + maskedflags = cm->flags & cm->mask; + ctrlstatic =can_get_static_ctrlmode (priv); + +/* check whether provided bits are allowed to be passed */ +if (maskedflags & ~(priv->ctrlmode_supported | ctrlstatic)) +return -EOPNOTSUPP ; + +/* do not check for static fd-non-iso if 'fd' is disabled */ +if (!(maskedflags &CAN_CTRLMODE_FD )) + ctrlstatic &= ~CAN_CTRLMODE_FD_NON_ISO ; + +/* make sure static options are provided by configuration */ +if ((maskedflags & ctrlstatic) != ctrlstatic) +return -EOPNOTSUPP ; + +/* If a top dependency flag is provided, reset all its dependencies */ +if (cm->mask &CAN_CTRLMODE_FD ) + priv->ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK ; + +/* clear bits to be modified and copy the flag values */ + priv->ctrlmode &= ~cm->mask; + priv->ctrlmode |= maskedflags; + +/* Wipe potential leftovers from previous CAN FD config */ +if (!(priv->ctrlmode &CAN_CTRLMODE_FD )) { +memset (&priv->fd.data_bittiming,0 , +sizeof (priv->fd.data_bittiming)); + priv->ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK ; +memset (&priv->fd.tdc,0 ,sizeof (priv->fd.tdc)); + } + +can_set_default_mtu (dev); + +return 0 ; +} +static int can_tdc_changelink (struct data_bittiming_params *dbt_params,const struct nlattr *nla,struct netlink_ext_ack *extack)
@@ -315,48 +368,7 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],/* We need synchronization with dev->stop() */ ASSERT_RTNL (); -if (data[IFLA_CAN_CTRLMODE ]) { -struct can_ctrlmode *cm; -u32 ctrlstatic; -u32 maskedflags; - -/* Do not allow changing controller mode while running */ -if (dev->flags &IFF_UP ) -return -EBUSY ; - cm =nla_data (data[IFLA_CAN_CTRLMODE ]); - ctrlstatic =can_get_static_ctrlmode (priv); - maskedflags = cm->flags & cm->mask; - -/* check whether provided bits are allowed to be passed */ -if (maskedflags & ~(priv->ctrlmode_supported | ctrlstatic)) -return -EOPNOTSUPP ; - -/* do not check for static fd-non-iso if 'fd' is disabled */ -if (!(maskedflags &CAN_CTRLMODE_FD )) - ctrlstatic &= ~CAN_CTRLMODE_FD_NON_ISO ; - -/* make sure static options are provided by configuration */ -if ((maskedflags & ctrlstatic) != ctrlstatic) -return -EOPNOTSUPP ; - -/* If a top dependency flag is provided, reset all its dependencies */ -if (cm->mask &CAN_CTRLMODE_FD ) - priv->ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK ; - -/* clear bits to be modified and copy the flag values */ - priv->ctrlmode &= ~cm->mask; - priv->ctrlmode |= maskedflags; - -/* Wipe potential leftovers from previous CAN FD config */ -if (!(priv->ctrlmode &CAN_CTRLMODE_FD )) { -memset (&priv->fd.data_bittiming,0 , -sizeof (priv->fd.data_bittiming)); - priv->ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK ; -memset (&priv->fd.tdc,0 ,sizeof (priv->fd.tdc)); - } - -can_set_default_mtu (dev); - } +can_ctrlmode_changelink (dev, data, extack);if (data[IFLA_CAN_BITTIMING ]) {struct can_bittiming bt;
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 40/48 can: netlink: make can_tdc_get_size() FD agnostic
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
can_tdc_get_size() needs to access can_priv->fd making it specific to CAN FD. Change the function parameter from struct can_priv to struct data_bittiming_params.
can_tdc_get_size() also uses the CAN_CTRLMODE_TDC_MANUAL macro making it specific to CAN FD. Add the tdc mask to the function parameter list. The value of the tdc manual flag can then be derived from that mask and stored in a local variable.
This way, the function becomes CAN FD agnostic and can be reused later on for the CAN XL TDC.
--- drivers/net/can/dev/netlink.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/net/can/dev/netlink.c +11 -10
@@ -472,32 +472,32 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],return 0 ; } -static size_t can_tdc_get_size (const struct net_device *dev) +static size_t can_tdc_get_size (struct data_bittiming_params *dbt_params, +u32 tdc_flags) { -struct can_priv *priv =netdev_priv (dev); +bool tdc_manual = tdc_flags &CAN_CTRLMODE_TDC_MANUAL_MASK ;size_t size; -if (!priv->fd.tdc_const) +if (!dbt_params->tdc_const)return 0 ; size =nla_total_size (0 );/* nest IFLA_CAN_TDC */ -if (priv->ctrlmode_supported &CAN_CTRLMODE_TDC_MANUAL ) { +if (tdc_manual) { size +=nla_total_size (sizeof (u32));/* IFLA_CAN_TDCV_MIN */ size +=nla_total_size (sizeof (u32));/* IFLA_CAN_TDCV_MAX */ } size +=nla_total_size (sizeof (u32));/* IFLA_CAN_TDCO_MIN */ size +=nla_total_size (sizeof (u32));/* IFLA_CAN_TDCO_MAX */ -if (priv->fd.tdc_const->tdcf_max) { +if (dbt_params->tdc_const->tdcf_max) { size +=nla_total_size (sizeof (u32));/* IFLA_CAN_TDCF_MIN */ size +=nla_total_size (sizeof (u32));/* IFLA_CAN_TDCF_MAX */ } -if (can_fd_tdc_is_enabled (priv)) { -if (priv->ctrlmode &CAN_CTRLMODE_TDC_MANUAL || - priv->fd.do_get_auto_tdcv) +if (tdc_flags) { +if (tdc_manual || dbt_params->do_get_auto_tdcv) size +=nla_total_size (sizeof (u32));/* IFLA_CAN_TDCV */ size +=nla_total_size (sizeof (u32));/* IFLA_CAN_TDCO */ -if (priv->fd.tdc_const->tdcf_max) +if (dbt_params->tdc_const->tdcf_max) size +=nla_total_size (sizeof (u32));/* IFLA_CAN_TDCF */ }
@@ -541,7 +541,8 @@ static size_t can_get_size(const struct net_device *dev) size +=nla_total_size (sizeof (*priv->fd.data_bitrate_const) * priv->fd.data_bitrate_const_cnt); size +=sizeof (priv->bitrate_max);/* IFLA_CAN_BITRATE_MAX */ - size +=can_tdc_get_size (dev);/* IFLA_CAN_TDC */ + size +=can_tdc_get_size (&priv->fd,/* IFLA_CAN_TDC */ + priv->ctrlmode &CAN_CTRLMODE_FD_TDC_MASK ); size +=can_ctrlmode_ext_get_size ();/* IFLA_CAN_CTRLMODE_EXT */ return size;
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 41/48 can: netlink: add can_data_bittiming_get_size()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Add the can_data_bittiming_get_size() function to factorise the logic to retrieve the size of below data bittiming parameters:
- data_bittiming
- data_bittiming_const
- data_bitrate_const
- tdc parameters
This function will be reused later on for CAN XL.
--- drivers/net/can/dev/netlink.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
drivers/net/can/dev/netlink.c +20 -9
@@ -504,6 +504,23 @@ static size_t can_tdc_get_size(struct data_bittiming_params *dbt_params,return size; } +static size_t can_data_bittiming_get_size (struct data_bittiming_params *dbt_params, +u32 tdc_flags) +{ +size_t size =0 ; + +if (dbt_params->data_bittiming.bitrate)/* IFLA_CAN_DATA_BITTIMING */ + size +=nla_total_size (sizeof (dbt_params->data_bittiming)); +if (dbt_params->data_bittiming_const)/* IFLA_CAN_DATA_BITTIMING_CONST */ + size +=nla_total_size (sizeof (*dbt_params->data_bittiming_const)); +if (dbt_params->data_bitrate_const)/* IFLA_CAN_DATA_BITRATE_CONST */ + size +=nla_total_size (sizeof (*dbt_params->data_bitrate_const) * + dbt_params->data_bitrate_const_cnt); + size +=can_tdc_get_size (dbt_params, tdc_flags);/* IFLA_CAN_TDC */ + +return size; +} +static size_t can_ctrlmode_ext_get_size (void ) { return nla_total_size(0) + /* nest IFLA_CAN_CTRLMODE_EXT */
@@ -525,10 +542,6 @@ static size_t can_get_size(const struct net_device *dev) size +=nla_total_size (sizeof (u32));/* IFLA_CAN_RESTART_MS */ if (priv->do_get_berr_counter)/* IFLA_CAN_BERR_COUNTER */ size +=nla_total_size (sizeof (struct can_berr_counter )); -if (priv->fd.data_bittiming.bitrate)/* IFLA_CAN_DATA_BITTIMING */ - size +=nla_total_size (sizeof (struct can_bittiming )); -if (priv->fd.data_bittiming_const)/* IFLA_CAN_DATA_BITTIMING_CONST */ - size +=nla_total_size (sizeof (struct can_bittiming_const ));if (priv->termination_const) { size +=nla_total_size (sizeof (priv->termination));/* IFLA_CAN_TERMINATION */ size += nla_total_size(sizeof(*priv->termination_const) * /* IFLA_CAN_TERMINATION_CONST */
@@ -537,14 +550,12 @@ static size_t can_get_size(const struct net_device *dev)if (priv->bitrate_const)/* IFLA_CAN_BITRATE_CONST */ size +=nla_total_size (sizeof (*priv->bitrate_const) * priv->bitrate_const_cnt); -if (priv->fd.data_bitrate_const)/* IFLA_CAN_DATA_BITRATE_CONST */ - size +=nla_total_size (sizeof (*priv->fd.data_bitrate_const) * - priv->fd.data_bitrate_const_cnt); size +=sizeof (priv->bitrate_max);/* IFLA_CAN_BITRATE_MAX */ - size +=can_tdc_get_size (&priv->fd,/* IFLA_CAN_TDC */ - priv->ctrlmode &CAN_CTRLMODE_FD_TDC_MASK ); size +=can_ctrlmode_ext_get_size ();/* IFLA_CAN_CTRLMODE_EXT */ + size +=can_data_bittiming_get_size (&priv->fd, + priv->ctrlmode &CAN_CTRLMODE_FD_TDC_MASK ); +return size; }
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 42/48 can: netlink: add can_bittiming_fill_info()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Add can_bittiming_fill_info() to factorise the logic when filling the bittiming information for Classical CAN and CAN FD. This function will be reused later on for CAN XL.
--- drivers/net/can/dev/netlink.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/net/can/dev/netlink.c +12 -7
@@ -559,6 +559,14 @@ static size_t can_get_size(const struct net_device *dev)return size; } +static int can_bittiming_fill_info (struct sk_buff *skb,int ifla_can_bittiming, +struct can_bittiming *bittiming) +{ +return bittiming->bitrate !=CAN_BITRATE_UNSET && + bittiming->bitrate !=CAN_BITRATE_UNKNOWN && +nla_put (skb, ifla_can_bittiming,sizeof (*bittiming), bittiming); +} +static int can_tdc_fill_info (struct sk_buff *skb,const struct net_device *dev) {struct nlattr *nest;
@@ -641,10 +649,8 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)if (priv->do_get_state) priv->do_get_state (dev, &state); - if ((priv->bittiming.bitrate != CAN_BITRATE_UNSET && - priv->bittiming.bitrate != CAN_BITRATE_UNKNOWN && - nla_put(skb, IFLA_CAN_BITTIMING, - sizeof(priv->bittiming), &priv->bittiming)) || + if (can_bittiming_fill_info(skb, IFLA_CAN_BITTIMING, + &priv->bittiming) || (priv->bittiming_const && nla_put(skb, IFLA_CAN_BITTIMING_CONST,
@@ -659,9 +665,8 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) !priv->do_get_berr_counter(dev, &bec) && nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)) || - (priv->fd.data_bittiming.bitrate && - nla_put(skb, IFLA_CAN_DATA_BITTIMING, - sizeof(priv->fd.data_bittiming), &priv->fd.data_bittiming)) || + can_bittiming_fill_info(skb, IFLA_CAN_DATA_BITTIMING, + &priv->fd.data_bittiming) || (priv->fd.data_bittiming_const && nla_put(skb, IFLA_CAN_DATA_BITTIMING_CONST,
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 43/48 can: netlink: add can_bittiming_const_fill_info()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Add function can_bittiming_const_fill_info() to factorise the logic when filling the bittiming constant information for Classical CAN and CAN FD. This function will be reused later on for CAN XL.
--- drivers/net/can/dev/netlink.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/net/can/dev/netlink.c +13 -7
@@ -567,6 +567,15 @@ static int can_bittiming_fill_info(struct sk_buff *skb, int ifla_can_bittiming,nla_put (skb, ifla_can_bittiming,sizeof (*bittiming), bittiming); } +static int can_bittiming_const_fill_info (struct sk_buff *skb, +int ifla_can_bittiming_const, +const struct can_bittiming_const *bittiming_const) +{ +return bittiming_const && +nla_put (skb, ifla_can_bittiming_const, +sizeof (*bittiming_const), bittiming_const); +} +static int can_tdc_fill_info (struct sk_buff *skb,const struct net_device *dev) {struct nlattr *nest;
@@ -652,9 +661,8 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) if (can_bittiming_fill_info(skb, IFLA_CAN_BITTIMING, &priv->bittiming) || - (priv->bittiming_const && - nla_put(skb, IFLA_CAN_BITTIMING_CONST, - sizeof(*priv->bittiming_const), priv->bittiming_const)) || + can_bittiming_const_fill_info(skb, IFLA_CAN_BITTIMING_CONST, + priv->bittiming_const) || nla_put(skb, IFLA_CAN_CLOCK, sizeof(priv->clock), &priv->clock) || nla_put_u32(skb, IFLA_CAN_STATE, state) ||
@@ -668,10 +676,8 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)can_bittiming_fill_info (skb,IFLA_CAN_DATA_BITTIMING , &priv->fd.data_bittiming) || - (priv->fd.data_bittiming_const && -nla_put (skb,IFLA_CAN_DATA_BITTIMING_CONST , -sizeof (*priv->fd.data_bittiming_const), - priv->fd.data_bittiming_const)) || +can_bittiming_const_fill_info (skb,IFLA_CAN_DATA_BITTIMING_CONST , + priv->fd.data_bittiming_const) || (priv->termination_const && (nla_put_u16(skb, IFLA_CAN_TERMINATION, priv->termination) ||
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 44/48 can: netlink: add can_bitrate_const_fill_info()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Add can_bitrate_const_fill_info() to factorise the logic when filling the bitrate constant information for Classical CAN and CAN FD. This function will be reused later on for CAN XL.
--- drivers/net/can/dev/netlink.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
drivers/net/can/dev/netlink.c +15 -10
@@ -576,6 +576,15 @@ static int can_bittiming_const_fill_info(struct sk_buff *skb, sizeof(*bittiming_const), bittiming_const); } +static int can_bitrate_const_fill_info (struct sk_buff *skb, +int ifla_can_bitrate_const, +const u32 *bitrate_const,unsigned int cnt) +{ +return bitrate_const && +nla_put (skb, ifla_can_bitrate_const, +sizeof (*bitrate_const) * cnt, bitrate_const); +} +static int can_tdc_fill_info (struct sk_buff *skb,const struct net_device *dev) {struct nlattr *nest;
@@ -686,17 +695,13 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) priv->termination_const_cnt, priv->termination_const))) || - (priv->bitrate_const && -nla_put (skb,IFLA_CAN_BITRATE_CONST , -sizeof (*priv->bitrate_const) * - priv->bitrate_const_cnt, - priv->bitrate_const)) || +can_bitrate_const_fill_info (skb,IFLA_CAN_BITRATE_CONST , + priv->bitrate_const, + priv->bitrate_const_cnt) || - (priv->fd.data_bitrate_const && -nla_put (skb,IFLA_CAN_DATA_BITRATE_CONST , -sizeof (*priv->fd.data_bitrate_const) * - priv->fd.data_bitrate_const_cnt, - priv->fd.data_bitrate_const)) || +can_bitrate_const_fill_info (skb,IFLA_CAN_DATA_BITRATE_CONST , + priv->fd.data_bitrate_const, + priv->fd.data_bitrate_const_cnt) || (nla_put(skb, IFLA_CAN_BITRATE_MAX, sizeof(priv->bitrate_max),
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 45/48 can: netlink: make can_tdc_fill_info() FD agnostic
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
can_tdc_fill_info() depends on some variables which are specific to CAN FD. Move these to the function parameters list so that, later on, this function can be reused for the CAN XL TDC.
--- drivers/net/can/dev/netlink.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)
drivers/net/can/dev/netlink.c +24 -11
@@ -585,21 +585,34 @@ static int can_bitrate_const_fill_info(struct sk_buff *skb, sizeof(*bitrate_const) * cnt, bitrate_const); } -static int can_tdc_fill_info (struct sk_buff *skb,const struct net_device *dev) +static int can_tdc_fill_info (struct sk_buff *skb,const struct net_device *dev, +int ifla_can_tdc) { -struct nlattr *nest;struct can_priv *priv =netdev_priv (dev); -struct can_tdc *tdc = &priv->fd.tdc; -const struct can_tdc_const *tdc_const = priv->fd.tdc_const; +struct data_bittiming_params *dbt_params; +const struct can_tdc_const *tdc_const; +struct can_tdc *tdc; +struct nlattr *nest; +bool tdc_is_enabled, tdc_manual; + +if (ifla_can_tdc ==IFLA_CAN_TDC ) { + dbt_params = &priv->fd; + tdc_is_enabled =can_fd_tdc_is_enabled (priv); + tdc_manual = priv->ctrlmode &CAN_CTRLMODE_TDC_MANUAL ; + }else { +return -EOPNOTSUPP ;/* Place holder for CAN XL */ + } + tdc_const = dbt_params->tdc_const; + tdc = &dbt_params->tdc;if (!tdc_const)return 0 ; - nest =nla_nest_start (skb,IFLA_CAN_TDC ); + nest =nla_nest_start (skb, ifla_can_tdc);if (!nest)return -EMSGSIZE ; -if (priv->ctrlmode_supported &CAN_CTRLMODE_TDC_MANUAL && +if (tdc_manual && (nla_put_u32 (skb,IFLA_CAN_TDC_TDCV_MIN , tdc_const->tdcv_min) ||nla_put_u32 (skb,IFLA_CAN_TDC_TDCV_MAX , tdc_const->tdcv_max))) goto err_cancel;
@@ -611,15 +624,15 @@ static int can_tdc_fill_info(struct sk_buff *skb, const struct net_device *dev) nla_put_u32(skb, IFLA_CAN_TDC_TDCF_MAX, tdc_const->tdcf_max))) goto err_cancel; -if (can_fd_tdc_is_enabled (priv)) { +if (tdc_is_enabled) {u32 tdcv;int err = -EINVAL ; -if (priv->ctrlmode &CAN_CTRLMODE_TDC_MANUAL ) { +if (tdc_manual) { tdcv = tdc->tdcv; err =0 ; - }else if (priv->fd.do_get_auto_tdcv) { - err = priv->fd.do_get_auto_tdcv (dev, &tdcv); + }else if (dbt_params->do_get_auto_tdcv) { + err = dbt_params->do_get_auto_tdcv (dev, &tdcv); }if (!err &&nla_put_u32 (skb,IFLA_CAN_TDC_TDCV , tdcv)) goto err_cancel;
@@ -707,7 +720,7 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) sizeof(priv->bitrate_max), &priv->bitrate_max)) || -can_tdc_fill_info (skb, dev) || +can_tdc_fill_info (skb, dev,IFLA_CAN_TDC ) ||can_ctrlmode_ext_fill_info (skb, priv) )
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 46/48 can: calc_bittiming: make can_calc_tdco() FD agnostic
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
can_calc_tdco() uses the CAN_CTRLMODE_FD_TDC_MASK and CAN_CTRLMODE_TDC_AUTO macros making it specific to CAN FD. Add the tdc mask to the function parameter list. The value of the tdc auto flag can then be derived from that mask and stored in a local variable. This way, the function becomes CAN FD agnostic and can be reused later on for the CAN XL TDC.
--- drivers/net/can/dev/calc_bittiming.c | 10 ++++++---- drivers/net/can/dev/netlink.c | 2 +- include/linux/can/bittiming.h | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-)
drivers/net/can/dev/calc_bittiming.c +6 -4
@@ -173,13 +173,15 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,void can_calc_tdco (struct can_tdc *tdc,const struct can_tdc_const *tdc_const,const struct can_bittiming *dbt, -u32 *ctrlmode,u32 ctrlmode_supported) +u32 tdc_mask,u32 *ctrlmode,u32 ctrlmode_supported) { -if (!tdc_const || !(ctrlmode_supported &CAN_CTRLMODE_TDC_AUTO )) +u32 tdc_auto = tdc_mask &CAN_CTRLMODE_TDC_AUTO_MASK ; + +if (!tdc_const || !(ctrlmode_supported & tdc_auto))return ; - *ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK ; + *ctrlmode &= ~tdc_mask;/* As specified in ISO 11898-1 section 11.3.3 "Transmitter * delay compensation" (TDC) is only applicable if data BRP is
@@ -193,6 +195,6 @@ void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const,if (sample_point_in_tc < tdc_const->tdco_min)return ; tdc->tdco =min (sample_point_in_tc, tdc_const->tdco_max); - *ctrlmode |=CAN_CTRLMODE_TDC_AUTO ; + *ctrlmode |= tdc_auto; } }
drivers/net/can/dev/netlink.c +1 -1
@@ -341,7 +341,7 @@ static int can_dbt_changelink(struct net_device *dev, struct nlattr *data[],* do calculation */ can_calc_tdco (&dbt_params->tdc, dbt_params->tdc_const, &dbt, - &priv->ctrlmode, priv->ctrlmode_supported); + tdc_mask, &priv->ctrlmode, priv->ctrlmode_supported); }/* else: both CAN_CTRLMODE_TDC_{AUTO,MANUAL} are explicitly * turned off. TDC is disabled: do nothing */
include/linux/can/bittiming.h +2 -2
@@ -135,7 +135,7 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,void can_calc_tdco (struct can_tdc *tdc,const struct can_tdc_const *tdc_const,const struct can_bittiming *dbt, -u32 *ctrlmode,u32 ctrlmode_supported); +u32 tdc_mask,u32 *ctrlmode,u32 ctrlmode_supported);#else /* !CONFIG_CAN_CALC_BITTIMING */ static inline int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,
@@ -148,7 +148,7 @@ can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,static inline void can_calc_tdco (struct can_tdc *tdc,const struct can_tdc_const *tdc_const,const struct can_bittiming *dbt, -u32 *ctrlmode,u32 ctrlmode_supported) +u32 tdc_mask,u32 *ctrlmode,u32 ctrlmode_supported) { }#endif /* CONFIG_CAN_CALC_BITTIMING */
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 47/48 can: dev: add can_get_ctrlmode_str()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
In an effort to give more human readable messages when errors occur because of conflicting options, it can be useful to convert the CAN control mode flags into text.
Add a function which converts the first set CAN control mode into a human readable string. The reason to only convert the first one is to simplify edge cases: imagine that there are several invalid control modes, we would just return the first invalid one to the user, thus not having to handle complex string concatenation. The user can then solve the first problem, call the netlink interface again and see the next issue.
People who wish to enumerate all the control modes can still do so by, for example, using this new function in a for_each_set_bit() loop.
--- drivers/net/can/dev/dev.c | 33 +++++++++++++++++++++++++++++++++ include/linux/can/dev.h | 2 ++ 2 files changed, 35 insertions(+)
drivers/net/can/dev/dev.c +33 -0
@@ -88,6 +88,39 @@ const char *can_get_state_str(const enum can_state state) }EXPORT_SYMBOL_GPL (can_get_state_str); +const char *can_get_ctrlmode_str (u32 ctrlmode) +{ +switch (ctrlmode & ~(ctrlmode -1 )) { +case 0 : +return "none" ; +case CAN_CTRLMODE_LOOPBACK : +return "loopback" ; +case CAN_CTRLMODE_LISTENONLY : +return "listen-only" ; +case CAN_CTRLMODE_3_SAMPLES : +return "triple-sampling" ; +case CAN_CTRLMODE_ONE_SHOT : +return "one-shot" ; +case CAN_CTRLMODE_BERR_REPORTING : +return "berr-reporting" ; +case CAN_CTRLMODE_FD : +return "fd" ; +case CAN_CTRLMODE_PRESUME_ACK : +return "presume-ack" ; +case CAN_CTRLMODE_FD_NON_ISO : +return "fd-non-iso" ; +case CAN_CTRLMODE_CC_LEN8_DLC : +return "cc-len8-dlc" ; +case CAN_CTRLMODE_TDC_AUTO : +return "fd-tdc-auto" ; +case CAN_CTRLMODE_TDC_MANUAL : +return "fd-tdc-manual" ; +default : +return "<unknown>" ; + } +} +EXPORT_SYMBOL_GPL (can_get_ctrlmode_str); +static enum can_state can_state_err_to_state (u16 err) {if (err <CAN_ERROR_WARNING_THRESHOLD )
include/linux/can/dev.h +2 -0
@@ -141,6 +141,8 @@ int can_restart_now(struct net_device *dev);void can_bus_off (struct net_device *dev);const char *can_get_state_str (const enum can_state state); +const char *can_get_ctrlmode_str (u32 ctrlmode); + void can_state_get_by_berr_counter(const struct net_device *dev, const struct can_berr_counter *bec, enum can_state *tx_state,
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 48/48 can: netlink: add userland error messages
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Use NL_SET_ERR_MSG() and NL_SET_ERR_MSG_FMT() to return meaningful error messages to the userland whenever a -EOPNOTSUPP error is returned due to a failed validation of the CAN netlink arguments.
--- drivers/net/can/dev/netlink.c | 82 ++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 20 deletions(-)
drivers/net/can/dev/netlink.c +62 -20
@@ -64,15 +64,23 @@ static int can_validate_tdc(struct nlattr *data_tdc,bool tdc_auto = tdc_flags &CAN_CTRLMODE_TDC_AUTO_MASK ;int err; -/* CAN_CTRLMODE_TDC_{AUTO,MANUAL} are mutually exclusive */ -if (tdc_auto && tdc_manual) +if (tdc_auto && tdc_manual) { +NL_SET_ERR_MSG (extack, +"TDC manual and auto modes are mutually exclusive" );return -EOPNOTSUPP ; + }/* If one of the CAN_CTRLMODE_TDC_* flag is set then TDC * must be set and vice-versa */ -if ((tdc_auto || tdc_manual) != !!data_tdc) +if ((tdc_auto || tdc_manual) && !data_tdc) { +NL_SET_ERR_MSG (extack,"TDC parameters are missing" );return -EOPNOTSUPP ; + } +if (!(tdc_auto || tdc_manual) && data_tdc) { +NL_SET_ERR_MSG (extack,"TDC mode (auto or manual) is missing" ); +return -EOPNOTSUPP ; + }/* If providing TDC parameters, at least TDCO is needed. TDCV * is needed if and only if CAN_CTRLMODE_TDC_MANUAL is set
@@ -86,15 +94,23 @@ static int can_validate_tdc(struct nlattr *data_tdc,return err;if (tb_tdc[IFLA_CAN_TDC_TDCV ]) { -if (tdc_auto) +if (tdc_auto) { +NL_SET_ERR_MSG (extack, +"TDCV is incompatible with TDC auto mode" );return -EOPNOTSUPP ; + } }else { -if (tdc_manual) +if (tdc_manual) { +NL_SET_ERR_MSG (extack, +"TDC manual mode requires TDCV" );return -EOPNOTSUPP ; + } } -if (!tb_tdc[IFLA_CAN_TDC_TDCO ]) +if (!tb_tdc[IFLA_CAN_TDC_TDCO ]) { +NL_SET_ERR_MSG (extack,"TDCO is missing" );return -EOPNOTSUPP ; + } }return 0 ;
@@ -105,6 +121,7 @@ static int can_validate_databittiming(struct nlattr *data[], int ifla_can_data_bittiming, u32 flags) {struct nlattr *data_tdc; +const char *type;u32 tdc_flags;bool is_on;int err;
@@ -120,18 +137,31 @@ static int can_validate_databittiming(struct nlattr *data[], data_tdc = data[IFLA_CAN_TDC ]; tdc_flags = flags &CAN_CTRLMODE_FD_TDC_MASK ; is_on = flags &CAN_CTRLMODE_FD ; + type ="FD" ; }else {return -EOPNOTSUPP ;/* Place holder for CAN XL */ }if (is_on) { -if (!data[IFLA_CAN_BITTIMING ] || !data[ifla_can_data_bittiming]) +if (!data[IFLA_CAN_BITTIMING ] || !data[ifla_can_data_bittiming]) { +NL_SET_ERR_MSG_FMT (extack, +"Provide both nominal and %s data bittiming" , + type);return -EOPNOTSUPP ; - } - -if (data[ifla_can_data_bittiming] || data_tdc) { -if (!is_on) + } + }else { +if (data[ifla_can_data_bittiming]) { +NL_SET_ERR_MSG_FMT (extack, +"%s data bittiming requires CAN %s" , + type, type);return -EOPNOTSUPP ; + } +if (data_tdc) { +NL_SET_ERR_MSG_FMT (extack, +"%s TDC requires CAN %s" , + type, type); +return -EOPNOTSUPP ; + } } err =can_validate_bittiming (data, extack, ifla_can_data_bittiming);
@@ -178,8 +208,7 @@ static int can_ctrlmode_changelink(struct net_device *dev, {struct can_priv *priv =netdev_priv (dev);struct can_ctrlmode *cm; -u32 maskedflags; -u32 ctrlstatic; +u32 ctrlstatic, maskedflags, notsupp, ctrlstatic_missing;if (!data[IFLA_CAN_CTRLMODE ])return 0 ;
@@ -189,20 +218,28 @@ static int can_ctrlmode_changelink(struct net_device *dev,return -EBUSY ; cm =nla_data (data[IFLA_CAN_CTRLMODE ]); - maskedflags = cm->flags & cm->mask; ctrlstatic =can_get_static_ctrlmode (priv); + maskedflags = cm->flags & cm->mask; + notsupp = maskedflags & ~(priv->ctrlmode_supported | ctrlstatic); + ctrlstatic_missing = (maskedflags & ctrlstatic) ^ ctrlstatic; -/* check whether provided bits are allowed to be passed */ -if (maskedflags & ~(priv->ctrlmode_supported | ctrlstatic)) +if (notsupp) { +NL_SET_ERR_MSG_FMT (extack, +"requested control mode %s not supported" , +can_get_ctrlmode_str (notsupp));return -EOPNOTSUPP ; + }/* do not check for static fd-non-iso if 'fd' is disabled */ if (!(maskedflags &CAN_CTRLMODE_FD )) ctrlstatic &= ~CAN_CTRLMODE_FD_NON_ISO ; -/* make sure static options are provided by configuration */ -if ((maskedflags & ctrlstatic) != ctrlstatic) +if (ctrlstatic_missing) { +NL_SET_ERR_MSG_FMT (extack, +"missing required %s static control mode" , +can_get_ctrlmode_str (ctrlstatic_missing));return -EOPNOTSUPP ; + }/* If a top dependency flag is provided, reset all its dependencies */ if (cm->mask &CAN_CTRLMODE_FD )
@@ -234,8 +271,10 @@ static int can_tdc_changelink(struct data_bittiming_params *dbt_params,const struct can_tdc_const *tdc_const = dbt_params->tdc_const;int err; -if (!tdc_const) +if (!tdc_const) { +NL_SET_ERR_MSG (extack,"The device does not support TDC" );return -EOPNOTSUPP ; + } err =nla_parse_nested (tb_tdc,IFLA_CAN_TDC_MAX , nla, can_tdc_policy, extack);
@@ -450,8 +489,11 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],const unsigned int num_term = priv->termination_const_cnt;unsigned int i; -if (!priv->do_set_termination) +if (!priv->do_set_termination) { +NL_SET_ERR_MSG (extack, +"Termination is not configurable on this device" );return -EOPNOTSUPP ; + }/* check whether given value is supported by the interface */ for (i =0 ; i < num_term; i++) {
Signature · 1 line
2.51.0