pull-request: can-next 2022-01-05
Subsystems (12)
Marc Kleine-Budde
maintainercover pull-request: can-next 2022-01-05
Hello Jakub, hello David,
this is a pull request of 15 patches for net-next/master.
The first patch is by me and removed an unused variable from the usb_8dev driver.
Andy Shevchenko contributes a patch for the mcp251x driver, which removes an unneeded assignment.
Jimmy Assarsson's patch for the kvaser_usb makes use of units.h in the assignment of frequencies.
Lad Prabhakar provides 2 patches, converting the ti_hecc and the sja1000 driver to make use of platform_get_irq().
The 10 remaining patches are by Vincent Mailhol. First the etas_es58x driver populates the net_device::dev_port. The next 5 patches cleanup the handling of CAN error and CAN RTR messages of all drivers. The remaining 4 patches enhance the CAN controller mode flag handling and export it via netlink to user space.
regards,
Marc
---
The following changes since commit ffd32ea6b13c97904cae59bdb13a843d52756578:
Revert "net: wwan: iosm: Keep device at D0 for s2idle case" (2022-01-04 18:15:17 -0800)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git tags/linux-can-next-for-5.17-20220105
for you to fetch changes up to 383f0993fc77152b0773c85ed69d6734baf9cb48:
can: netlink: report the CAN controller mode supported flags (2022-01-05 12:09:06 +0100)
----------------------------------------------------------------
linux-can-next-for-5.17-20220105
----------------------------------------------------------------
Andy Shevchenko (1):
can: mcp251x: mcp251x_gpio_setup(): Get rid of duplicate of_node assignment
Jimmy Assarsson (1):
can: kvaser_usb: make use of units.h in assignment of frequency
Lad Prabhakar (2):
can: ti_hecc: ti_hecc_probe(): use platform_get_irq() to get the interrupt
can: sja1000: sp_probe(): use platform_get_irq() to get the interrupt
Marc Kleine-Budde (1):
can: usb_8dev: remove unused member echo_skb from struct usb_8dev_priv
Vincent Mailhol (10):
can: etas_es58x: es58x_init_netdev: populate net_device::dev_port
can: do not increase rx statistics when generating a CAN rx error message frame
can: kvaser_usb: do not increase tx statistics when sending error message frames
can: do not copy the payload of RTR frames
can: do not increase rx_bytes statistics for RTR frames
can: do not increase tx_bytes statistics for RTR frames
can: dev: replace can_priv::ctrlmode_static by can_get_static_ctrlmode()
can: dev: add sanity check in can_set_static_ctrlmode()
can: dev: reorder struct can_priv members for better packing
can: netlink: report the CAN controller mode supported flags
drivers/net/can/at91_can.c | 18 ++---- drivers/net/can/c_can/c_can.h | 1 - drivers/net/can/c_can/c_can_main.c | 16 ++--- drivers/net/can/cc770/cc770.c | 16 ++--- drivers/net/can/dev/dev.c | 9 +-- drivers/net/can/dev/netlink.c | 33 +++++++++- drivers/net/can/dev/rx-offload.c | 7 +- drivers/net/can/grcan.c | 23 ++----- drivers/net/can/ifi_canfd/ifi_canfd.c | 11 +--- drivers/net/can/janz-ican3.c | 6 +- drivers/net/can/kvaser_pciefd.c | 16 ++--- drivers/net/can/m_can/m_can.c | 23 +++---- drivers/net/can/mscan/mscan.c | 14 ++-- drivers/net/can/pch_can.c | 33 ++++------ drivers/net/can/peak_canfd/peak_canfd.c | 14 ++-- drivers/net/can/rcar/rcar_can.c | 22 +++---- drivers/net/can/rcar/rcar_canfd.c | 17 ++--- drivers/net/can/sja1000/sja1000.c | 11 ++-- drivers/net/can/sja1000/sja1000_platform.c | 15 +++-- drivers/net/can/slcan.c | 7 +- drivers/net/can/softing/softing_main.c | 8 +-- drivers/net/can/spi/hi311x.c | 31 +++++---- drivers/net/can/spi/mcp251x.c | 34 +++++----- drivers/net/can/sun4i_can.c | 22 +++---- drivers/net/can/ti_hecc.c | 8 +-- drivers/net/can/usb/ems_usb.c | 14 ++-- drivers/net/can/usb/esd_usb2.c | 13 ++-- drivers/net/can/usb/etas_es58x/es58x_core.c | 8 +-- drivers/net/can/usb/gs_usb.c | 7 +- drivers/net/can/usb/kvaser_usb/kvaser_usb.h | 5 +- drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 4 +- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 78 +++++++++++------------ drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 29 ++++----- drivers/net/can/usb/mcba_usb.c | 23 +++---- drivers/net/can/usb/peak_usb/pcan_usb.c | 9 ++- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 20 +++--- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 1 - drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 11 ++-- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 12 ++-- drivers/net/can/usb/ucan.c | 17 +++-- drivers/net/can/usb/usb_8dev.c | 19 ++---- drivers/net/can/vcan.c | 7 +- drivers/net/can/vxcan.c | 2 +- drivers/net/can/xilinx_can.c | 19 +++--- include/linux/can/dev.h | 24 +++++-- include/linux/can/skb.h | 5 +- include/uapi/linux/can/netlink.h | 13 ++++ 47 files changed, 351 insertions(+), 404 deletions(-)
Marc Kleine-Budde
maintainerPATCH 1/15 can: usb_8dev: remove unused member echo_skb from struct usb_8dev_priv
This patch removes the unused memberecho_skb from the struct usb_8dev_priv.
--- drivers/net/can/usb/usb_8dev.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/can/usb/usb_8dev.c +0 -2
@@ -121,8 +121,6 @@ struct usb_8dev_tx_urb_context {struct usb_8dev_priv {struct can_priv can;/* must be the first member */ -struct sk_buff *echo_skb[MAX_TX_URBS ]; -struct usb_device *udev;struct net_device *netdev;
base-commit: ffd32ea6b13c97904cae59bdb13a843d52756578
Signature · 1 line
2.34.1
Re: [PATCH net-next 01/15] can: usb_8dev: remove unused member echo_skb from struct usb_8dev_priv
This series was applied to netdev/net-next.git (master) by Marc Kleine-Budde <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Marc Kleine-Budde <[email protected]>:
Quoted 8 lines · On Wed, 5 Jan 2022 15:43:48 +0100 you wrote:
This patch removes the unused
memberecho_skbfrom the structusb_8dev_priv.Fixes 0024d8ad1639 ("can: usb_8dev: Add support for USB2CAN interface from 8 devices")Signed-off-by Marc Kleine-Budde <[email protected]>[...]
Here is the summary with links:
- [net-next,01/15] can: usb_8dev: remove unused member echo_skb from struct usb_8dev_priv
https://git.kernel.org/netdev/net-next/c/617dbee5c7ac - [net-next,02/15] can: mcp251x: mcp251x_gpio_setup(): Get rid of duplicate of_node assignment https://git.kernel.org/netdev/net-next/c/68fa39ea9124 - [net-next,03/15] can: kvaser_usb: make use of units.h in assignment of frequency https://git.kernel.org/netdev/net-next/c/b8f91799687e - [net-next,04/15] can: ti_hecc: ti_hecc_probe(): use platform_get_irq() to get the interrupt https://git.kernel.org/netdev/net-next/c/eff104cf3cf3 - [net-next,05/15] can: sja1000: sp_probe(): use platform_get_irq() to get the interrupt https://git.kernel.org/netdev/net-next/c/decdcaeedce4 - [net-next,06/15] can: etas_es58x: es58x_init_netdev: populate net_device::dev_port https://git.kernel.org/netdev/net-next/c/e233640cd303 - [net-next,07/15] can: do not increase rx statistics when generating a CAN rx error message frame https://git.kernel.org/netdev/net-next/c/676068db69b8 - [net-next,08/15] can: kvaser_usb: do not increase tx statistics when sending error message frames https://git.kernel.org/netdev/net-next/c/0b0ce2c67795 - [net-next,09/15] can: do not copy the payload of RTR frames https://git.kernel.org/netdev/net-next/c/f68eafeb9759 - [net-next,10/15] can: do not increase rx_bytes statistics for RTR frames https://git.kernel.org/netdev/net-next/c/8e674ca74244 - [net-next,11/15] can: do not increase tx_bytes statistics for RTR frames https://git.kernel.org/netdev/net-next/c/cc4b08c31b5c - [net-next,12/15] can: dev: replace can_priv::ctrlmode_static by can_get_static_ctrlmode() https://git.kernel.org/netdev/net-next/c/c9e1d8ed304c - [net-next,13/15] can: dev: add sanity check in can_set_static_ctrlmode() https://git.kernel.org/netdev/net-next/c/7d4a101c0bd3 - [net-next,14/15] can: dev: reorder struct can_priv members for better packing https://git.kernel.org/netdev/net-next/c/5fe1be81efd2 - [net-next,15/15] can: netlink: report the CAN controller mode supported flags https://git.kernel.org/netdev/net-next/c/383f0993fc77
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/15 can: mcp251x: mcp251x_gpio_setup(): Get rid of duplicate of_node assignment
In reply to Marc Kleine-BuddeFrom: Andy Shevchenko <[email protected]>
GPIO library does copy the of_node from the parent device of the GPIO chip, there is no need to repeat this in the individual drivers. Remove assignment here.
For the details one may look into the of_gpio_dev_init() implementation.
--- drivers/net/can/spi/mcp251x.c | 3 --- 1 file changed, 3 deletions(-)
drivers/net/can/spi/mcp251x.c +0 -3
@@ -600,9 +600,6 @@ static int mcp251x_gpio_setup(struct mcp251x_priv *priv) gpio->ngpio =ARRAY_SIZE (mcp251x_gpio_names); gpio->names = mcp251x_gpio_names; gpio->can_sleep = true; -#ifdef CONFIG_OF_GPIO - gpio->of_node = priv->spi->dev.of_node; -#endif return devm_gpiochip_add_data (&priv->spi->dev, gpio, priv); }
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 3/15 can: kvaser_usb: make use of units.h in assignment of frequency
In reply to Marc Kleine-BuddeFrom: Jimmy Assarsson <[email protected]>
Use the MEGA define plus the comment /* Hz */ when assigning frequencies.
--- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 7 ++++--- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +4 -3
@@ -22,6 +22,7 @@#include <linux/spinlock.h> #include <linux/string.h> #include <linux/types.h> +#include <linux/units.h> #include <linux/usb.h> #include <linux/can.h>
@@ -2040,7 +2041,7 @@ const struct kvaser_usb_dev_ops kvaser_usb_hydra_dev_ops = {static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_kcan = { .clock = { - .freq =80000000 , + .freq =80 *MEGA /* Hz */ , }, .timestamp_freq =80 , .bittiming_const = &kvaser_usb_hydra_kcan_bittiming_c,
@@ -2049,7 +2050,7 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_kcan = {static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_flexc = { .clock = { - .freq =24000000 , + .freq =24 *MEGA /* Hz */ , }, .timestamp_freq =1 , .bittiming_const = &kvaser_usb_hydra_flexc_bittiming_c,
@@ -2057,7 +2058,7 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_flexc = {static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_rt = { .clock = { - .freq =80000000 , + .freq =80 *MEGA /* Hz */ , }, .timestamp_freq =24 , .bittiming_const = &kvaser_usb_hydra_rt_bittiming_c,
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +5 -4
@@ -19,6 +19,7 @@#include <linux/spinlock.h> #include <linux/string.h> #include <linux/types.h> +#include <linux/units.h> #include <linux/usb.h> #include <linux/can.h>
@@ -356,7 +357,7 @@ static const struct can_bittiming_const kvaser_usb_leaf_bittiming_const = {static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_8mhz = { .clock = { - .freq =8000000 , + .freq =8 *MEGA /* Hz */ , }, .timestamp_freq =1 , .bittiming_const = &kvaser_usb_leaf_bittiming_const,
@@ -364,7 +365,7 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_8mhz = {static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_16mhz = { .clock = { - .freq =16000000 , + .freq =16 *MEGA /* Hz */ , }, .timestamp_freq =1 , .bittiming_const = &kvaser_usb_leaf_bittiming_const,
@@ -372,7 +373,7 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_16mhz = {static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_24mhz = { .clock = { - .freq =24000000 , + .freq =24 *MEGA /* Hz */ , }, .timestamp_freq =1 , .bittiming_const = &kvaser_usb_leaf_bittiming_const,
@@ -380,7 +381,7 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_24mhz = {static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_32mhz = { .clock = { - .freq =32000000 , + .freq =32 *MEGA /* Hz */ , }, .timestamp_freq =1 , .bittiming_const = &kvaser_usb_leaf_bittiming_const,
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 4/15 can: ti_hecc: ti_hecc_probe(): use platform_get_irq() to get the interrupt
In reply to Marc Kleine-BuddeFrom: Lad Prabhakar <[email protected]>
platform_get_resource(pdev, IORESOURCE_IRQ, ..) relies on static allocation of IRQ resources in DT core code, this causes an issue when using hierarchical interrupt domains using "interrupts" property in the node as this bypasses the hierarchical setup and messes up the irq chaining.
In preparation for removal of static setup of IRQ resource from DT core code use platform_get_irq().
--- drivers/net/can/ti_hecc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/can/ti_hecc.c +3 -5
@@ -859,7 +859,6 @@ static int ti_hecc_probe(struct platform_device *pdev)struct net_device *ndev = (struct net_device *)0 ;struct ti_hecc_priv *priv;struct device_node *np = pdev->dev.of_node; -struct resource *irq;struct regulator *reg_xceiver;int err = -ENODEV ;
@@ -904,9 +903,9 @@ static int ti_hecc_probe(struct platform_device *pdev) goto probe_exit_candev; } - irq =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); -if (!irq) { -dev_err (&pdev->dev,"No irq resource\n" ); + ndev->irq =platform_get_irq (pdev,0 ); +if (ndev->irq <0 ) { + err = ndev->irq; goto probe_exit_candev; }
@@ -920,7 +919,6 @@ static int ti_hecc_probe(struct platform_device *pdev) priv->can.ctrlmode_supported =CAN_CTRLMODE_3_SAMPLES ;spin_lock_init (&priv->mbx_lock); - ndev->irq = irq->start; ndev->flags |=IFF_ECHO ;platform_set_drvdata (pdev, ndev);SET_NETDEV_DEV (ndev, &pdev->dev);
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 5/15 can: sja1000: sp_probe(): use platform_get_irq() to get the interrupt
In reply to Marc Kleine-BuddeFrom: Lad Prabhakar <[email protected]>
It is preferred that drivers use platform_get_irq() instead of irq_of_parse_and_map(), so replace.
--- drivers/net/can/sja1000/sja1000_platform.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/net/can/sja1000/sja1000_platform.c +8 -7
@@ -17,7 +17,6 @@#include <linux/io.h> #include <linux/of.h> #include <linux/of_device.h> -#include <linux/of_irq.h> #include "sja1000.h"
@@ -234,13 +233,15 @@ static int sp_probe(struct platform_device *pdev)if (!addr)return -ENOMEM ; -if (of) - irq =irq_of_parse_and_map (of,0 ); -else +if (of) { + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + }else { res_irq =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); - -if (!irq && !res_irq) -return -ENODEV ; +if (!res_irq) +return -ENODEV ; + } of_id =of_match_device (sp_of_table, &pdev->dev);if (of_id && of_id->data) {
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 6/15 can: etas_es58x: es58x_init_netdev: populate net_device::dev_port
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
The field dev_port of struct net_device indicates the port number of a network device [1]. This patch populates this field.
This field can be helpful to distinguish between the two network interfaces of a dual channel device (i.e. ES581.4 or ES582.1). Indeed, at the moment, all the network interfaces of a same device share the same static udev attributes c.f. output of:
| udevadm info --attribute-walk /sys/class/net/canX
The dev_port attribute can then be used to write some udev rules to, for example, assign a permanent name to each network interface based on the serial/dev_port pair (which is convenient when you have a test bench with several CAN devices connected simultaneously and wish to keep consistent interface names upon reboot).
[1] https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net
--- drivers/net/can/usb/etas_es58x/es58x_core.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/can/usb/etas_es58x/es58x_core.c +1 -0
@@ -2094,6 +2094,7 @@ static int es58x_init_netdev(struct es58x_device *es58x_dev, int channel_idx) netdev->netdev_ops = &es58x_netdev_ops; netdev->flags |=IFF_ECHO ;/* We support local echo */ + netdev->dev_port = channel_idx; ret =register_candev (netdev);if (ret)
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 7/15 can: do not increase rx statistics when generating a CAN rx error message frame
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
The CAN error message frames (i.e. error skb) are an interface specific to socket CAN. The payload of the CAN error message frames does not correspond to any actual data sent on the wire. Only an error flag and a delimiter are transmitted when an error occurs (c.f. ISO 11898-1 section 10.4.4.2 "Error flag").
For this reason, it makes no sense to increment the rx_packets and rx_bytes fields of struct net_device_stats because no actual payload were transmitted on the wire.
This patch fixes all the CAN drivers.
--- drivers/net/can/at91_can.c | 6 ------ drivers/net/can/c_can/c_can_main.c | 5 ----- drivers/net/can/cc770/cc770.c | 3 --- drivers/net/can/dev/dev.c | 4 ---- drivers/net/can/dev/rx-offload.c | 6 ++++-- drivers/net/can/ifi_canfd/ifi_canfd.c | 5 ----- drivers/net/can/kvaser_pciefd.c | 5 ----- drivers/net/can/m_can/m_can.c | 7 ------- drivers/net/can/mscan/mscan.c | 9 +++++---- drivers/net/can/pch_can.c | 3 --- drivers/net/can/peak_canfd/peak_canfd.c | 4 ---- drivers/net/can/rcar/rcar_can.c | 6 +----- drivers/net/can/rcar/rcar_canfd.c | 4 ---- drivers/net/can/sja1000/sja1000.c | 2 -- drivers/net/can/sun4i_can.c | 7 ++----- drivers/net/can/usb/ems_usb.c | 2 -- drivers/net/can/usb/esd_usb2.c | 2 -- drivers/net/can/usb/etas_es58x/es58x_core.c | 7 ------- drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 2 -- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 8 -------- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 4 ---- drivers/net/can/usb/peak_usb/pcan_usb.c | 2 -- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 3 --- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 2 -- drivers/net/can/usb/ucan.c | 6 ++++-- drivers/net/can/usb/usb_8dev.c | 2 -- drivers/net/can/xilinx_can.c | 9 +-------- 27 files changed, 17 insertions(+), 108 deletions(-)
drivers/net/can/at91_can.c +0 -6
@@ -553,8 +553,6 @@ static void at91_rx_overflow_err(struct net_device *dev) cf->can_id |=CAN_ERR_CRTL ; cf->data[1 ] =CAN_ERR_CRTL_RX_OVERFLOW ; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_receive_skb (skb); }
@@ -779,8 +777,6 @@ static int at91_poll_err(struct net_device *dev, int quota, u32 reg_sr)at91_poll_err_frame (dev, cf, reg_sr); - dev->stats.rx_packets++; - dev->stats.rx_bytes += cf->len;netif_receive_skb (skb);return 1 ;
@@ -1037,8 +1033,6 @@ static void at91_irq_err(struct net_device *dev)at91_irq_err_state (dev, cf, new_state); - dev->stats.rx_packets++; - dev->stats.rx_bytes += cf->len;netif_rx (skb); priv->can.state = new_state;
drivers/net/can/c_can/c_can_main.c +0 -5
@@ -920,7 +920,6 @@ static int c_can_handle_state_change(struct net_device *dev,unsigned int reg_err_counter;unsigned int rx_err_passive;struct c_can_priv *priv =netdev_priv (dev); -struct net_device_stats *stats = &dev->stats;struct can_frame *cf;struct sk_buff *skb;struct can_berr_counter bec;
@@ -996,8 +995,6 @@ static int c_can_handle_state_change(struct net_device *dev,break ; } - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_receive_skb (skb);return 1 ;
@@ -1064,8 +1061,6 @@ static int c_can_handle_bus_err(struct net_device *dev,break ; } - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_receive_skb (skb);return 1 ; }
drivers/net/can/cc770/cc770.c +0 -3
@@ -499,7 +499,6 @@ static void cc770_rx(struct net_device *dev, unsigned int mo, u8 ctrl1)static int cc770_err (struct net_device *dev,u8 status) {struct cc770_priv *priv =netdev_priv (dev); -struct net_device_stats *stats = &dev->stats;struct can_frame *cf;struct sk_buff *skb;u8 lec;
@@ -571,8 +570,6 @@ static int cc770_err(struct net_device *dev, u8 status) } - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb);return 0 ;
drivers/net/can/dev/dev.c +0 -4
@@ -136,7 +136,6 @@ EXPORT_SYMBOL_GPL(can_change_state);static void can_restart (struct net_device *dev) {struct can_priv *priv =netdev_priv (dev); -struct net_device_stats *stats = &dev->stats;struct sk_buff *skb;struct can_frame *cf;int err;
@@ -155,9 +154,6 @@ static void can_restart(struct net_device *dev) cf->can_id |=CAN_ERR_RESTARTED ; - stats->rx_packets++; - stats->rx_bytes += cf->len; -netif_rx_ni (skb); restart:
drivers/net/can/dev/rx-offload.c +4 -2
@@ -54,8 +54,10 @@ static int can_rx_offload_napi_poll(struct napi_struct *napi, int quota)struct can_frame *cf = (struct can_frame *)skb->data; work_done++; - stats->rx_packets++; - stats->rx_bytes += cf->len; +if (!(cf->can_id &CAN_ERR_FLAG )) { + stats->rx_packets++; + stats->rx_bytes += cf->len; + }netif_receive_skb (skb); }
drivers/net/can/ifi_canfd/ifi_canfd.c +0 -5
@@ -430,8 +430,6 @@ static int ifi_canfd_handle_lec_err(struct net_device *ndev) priv->base + IFI_CANFD_INTERRUPT);writel (IFI_CANFD_ERROR_CTR_ER_ENABLE , priv->base +IFI_CANFD_ERROR_CTR ); - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_receive_skb (skb);return 1 ;
@@ -456,7 +454,6 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev, enum can_state new_state) {struct ifi_canfd_priv *priv =netdev_priv (ndev); -struct net_device_stats *stats = &ndev->stats;struct can_frame *cf;struct sk_buff *skb;struct can_berr_counter bec;
@@ -522,8 +519,6 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,break ; } - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_receive_skb (skb);return 1 ;
drivers/net/can/kvaser_pciefd.c +0 -5
@@ -1310,9 +1310,6 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; - stats->rx_packets++; - stats->rx_bytes += cf->len; -netif_rx (skb);return 0 ; }
@@ -1510,8 +1507,6 @@ static void kvaser_pciefd_handle_nack_packet(struct kvaser_pciefd_can *can,if (skb) { cf->can_id |=CAN_ERR_BUSERROR ; - stats->rx_bytes += cf->len; - stats->rx_packets++;netif_rx (skb); }else { stats->rx_dropped++;
drivers/net/can/m_can/m_can.c +0 -7
@@ -647,9 +647,6 @@ static int m_can_handle_lec_err(struct net_device *dev,break ; } - stats->rx_packets++; - stats->rx_bytes += cf->len; -if (cdev->is_peripheral) timestamp =m_can_get_timestamp (cdev);
@@ -706,7 +703,6 @@ static int m_can_handle_state_change(struct net_device *dev, enum can_state new_state) {struct m_can_classdev *cdev =netdev_priv (dev); -struct net_device_stats *stats = &dev->stats;struct can_frame *cf;struct sk_buff *skb;struct can_berr_counter bec;
@@ -771,9 +767,6 @@ static int m_can_handle_state_change(struct net_device *dev,break ; } - stats->rx_packets++; - stats->rx_bytes += cf->len; -if (cdev->is_peripheral) timestamp =m_can_get_timestamp (cdev);
drivers/net/can/mscan/mscan.c +5 -4
@@ -401,13 +401,14 @@ static int mscan_rx_poll(struct napi_struct *napi, int quota)continue ; } -if (canrflg &MSCAN_RXF ) +if (canrflg &MSCAN_RXF ) {mscan_get_rx_frame (dev, frame); -else if (canrflg &MSCAN_ERR_IF ) + stats->rx_packets++; + stats->rx_bytes += frame->len; + }else if (canrflg &MSCAN_ERR_IF ) {mscan_get_err_frame (dev, frame, canrflg); + } - stats->rx_packets++; - stats->rx_bytes += frame->len; work_done++;netif_receive_skb (skb); }
drivers/net/can/pch_can.c +0 -3
@@ -561,9 +561,6 @@ static void pch_can_error(struct net_device *ndev, u32 status) priv->can.state = state;netif_receive_skb (skb); - - stats->rx_packets++; - stats->rx_bytes += cf->len; }static irqreturn_t pch_can_interrupt (int irq,void *dev_id)
drivers/net/can/peak_canfd/peak_canfd.c +0 -4
@@ -409,8 +409,6 @@ static int pucan_handle_status(struct peak_canfd_priv *priv,return -ENOMEM ; } - stats->rx_packets++; - stats->rx_bytes += cf->len;pucan_netif_rx (skb, msg->ts_low, msg->ts_high);return 0 ;
@@ -438,8 +436,6 @@ static int pucan_handle_cache_critical(struct peak_canfd_priv *priv) cf->data[6 ] = priv->bec.txerr; cf->data[7 ] = priv->bec.rxerr; - stats->rx_bytes += cf->len; - stats->rx_packets++;netif_rx (skb);return 0 ;
drivers/net/can/rcar/rcar_can.c +1 -5
@@ -223,7 +223,6 @@ static void tx_failure_cleanup(struct net_device *ndev)static void rcar_can_error (struct net_device *ndev) {struct rcar_can_priv *priv =netdev_priv (ndev); -struct net_device_stats *stats = &ndev->stats;struct can_frame *cf;struct sk_buff *skb;u8 eifr, txerr =0 , rxerr =0 ;
@@ -362,11 +361,8 @@ static void rcar_can_error(struct net_device *ndev) } } -if (skb) { - stats->rx_packets++; - stats->rx_bytes += cf->len; +if (skb)netif_rx (skb); - } }static void rcar_can_tx_done (struct net_device *ndev)
drivers/net/can/rcar/rcar_canfd.c +0 -4
@@ -1033,8 +1033,6 @@ static void rcar_canfd_error(struct net_device *ndev, u32 cerfl,/* Clear channel error interrupts that are handled */ rcar_canfd_write (priv->base,RCANFD_CERFL (ch),RCANFD_CERFL_ERR (~cerfl)); - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); }
@@ -1174,8 +1172,6 @@ static void rcar_canfd_state_change(struct net_device *ndev, rx_state = txerr <= rxerr ? state :0 ;can_change_state (ndev, cf, tx_state, rx_state); - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); } }
drivers/net/can/sja1000/sja1000.c +0 -2
@@ -487,8 +487,6 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)can_bus_off (dev); } - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb);return 0 ;
drivers/net/can/sun4i_can.c +2 -5
@@ -633,13 +633,10 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)can_bus_off (dev); } -if (likely (skb)) { - stats->rx_packets++; - stats->rx_bytes += cf->len; +if (likely (skb))netif_rx (skb); - }else { +else return -ENOMEM ; - }return 0 ; }
drivers/net/can/usb/ems_usb.c +0 -2
@@ -397,8 +397,6 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg) stats->rx_errors++; } - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); }
drivers/net/can/usb/esd_usb2.c +0 -2
@@ -293,8 +293,6 @@ static void esd_usb2_rx_event(struct esd_usb2_net_priv *priv, priv->bec.txerr = txerr; priv->bec.rxerr = rxerr; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); } }
drivers/net/can/usb/etas_es58x/es58x_core.c +0 -7
@@ -849,13 +849,6 @@ int es58x_rx_err_msg(struct net_device *netdev, enum es58x_err error,break ; } -/* driver/net/can/dev.c:can_restart() takes in account error -* messages in the RX stats. Doing the same here for -* consistency. -*/ - netdev->stats.rx_packets++; - netdev->stats.rx_bytes +=CAN_ERR_DLC ; -if (cf) {if (cf->data[1 ]) cf->can_id |=CAN_ERR_CRTL ;
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +0 -2
@@ -279,8 +279,6 @@ int kvaser_usb_can_rx_over_error(struct net_device *netdev) cf->can_id |=CAN_ERR_CRTL ; cf->data[1 ] =CAN_ERR_CRTL_RX_OVERFLOW ; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb);return 0 ;
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +0 -8
@@ -870,7 +870,6 @@ static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv,struct net_device *netdev = priv->netdev;struct can_frame *cf;struct sk_buff *skb; -struct net_device_stats *stats;enum can_state new_state, old_state; old_state = priv->can.state;
@@ -920,9 +919,6 @@ static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv, cf->data[6 ] = bec->txerr; cf->data[7 ] = bec->rxerr; - stats = &netdev->stats; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); }
@@ -1075,8 +1071,6 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv *priv, cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); priv->bec.txerr = bec.txerr;
@@ -1110,8 +1104,6 @@ static void kvaser_usb_hydra_one_shot_fail(struct kvaser_usb_net_priv *priv, } stats->tx_errors++; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); }
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +0 -4
@@ -642,8 +642,6 @@ static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev,if (skb) { cf->can_id |=CAN_ERR_RESTARTED ; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); }else { netdev_err(priv->netdev,
@@ -844,8 +842,6 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev, cf->data[6 ] = es->txerr; cf->data[7 ] = es->rxerr; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); }
drivers/net/can/usb/peak_usb/pcan_usb.c +0 -2
@@ -521,8 +521,6 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n, &hwts->hwtstamp); } - mc->netdev->stats.rx_packets++; - mc->netdev->stats.rx_bytes += cf->len;netif_rx (skb);return 0 ;
drivers/net/can/usb/peak_usb/pcan_usb_fd.c +0 -3
@@ -577,9 +577,6 @@ static int pcan_usb_fd_decode_status(struct pcan_usb_fd_if *usb_if,if (!skb)return -ENOMEM ; - netdev->stats.rx_packets++; - netdev->stats.rx_bytes += cf->len; -peak_usb_netif_rx_64 (skb,le32_to_cpu (sm->ts_low),le32_to_cpu (sm->ts_high));
drivers/net/can/usb/peak_usb/pcan_usb_pro.c +0 -2
@@ -660,8 +660,6 @@ static int pcan_usb_pro_handle_error(struct pcan_usb_pro_interface *usb_if, hwts =skb_hwtstamps (skb);peak_usb_get_ts_time (&usb_if->time_ref,le32_to_cpu (er->ts32), &hwts->hwtstamp); - netdev->stats.rx_packets++; - netdev->stats.rx_bytes += can_frame->len;netif_rx (skb);return 0 ;
drivers/net/can/usb/ucan.c +4 -2
@@ -621,8 +621,10 @@ static void ucan_rx_can_msg(struct ucan_priv *up, struct ucan_message_in *m)memcpy (cf->data, m->msg.can_msg.data, cf->len);/* don't count error frames as real packets */ - stats->rx_packets++; - stats->rx_bytes += cf->len; +if (!(cf->can_id &CAN_ERR_FLAG )) { + stats->rx_packets++; + stats->rx_bytes += cf->len; + }/* pass it to Linux */ netif_rx (skb);
drivers/net/can/usb/usb_8dev.c +0 -2
@@ -447,8 +447,6 @@ static void usb_8dev_rx_err_msg(struct usb_8dev_priv *priv, priv->bec.txerr = txerr; priv->bec.rxerr = rxerr; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); }
drivers/net/can/xilinx_can.c +1 -8
@@ -965,13 +965,8 @@ static void xcan_update_error_state_after_rxtx(struct net_device *ndev)xcan_set_error_state (ndev, new_state, skb ? cf :NULL ); -if (skb) { -struct net_device_stats *stats = &ndev->stats; - - stats->rx_packets++; - stats->rx_bytes += cf->len; +if (skb)netif_rx (skb); - } } }
@@ -1095,8 +1090,6 @@ static void xcan_err_interrupt(struct net_device *ndev, u32 isr)if (skb) { skb_cf->can_id |= cf.can_id;memcpy (skb_cf->data, cf.data,CAN_ERR_DLC ); - stats->rx_packets++; - stats->rx_bytes +=CAN_ERR_DLC ;netif_rx (skb); } }
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 8/15 can: kvaser_usb: do not increase tx statistics when sending error message frames
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
The CAN error message frames (i.e. error skb) are an interface specific to socket CAN. The payload of the CAN error message frames does not correspond to any actual data sent on the wire. Only an error flag and a delimiter are transmitted when an error occurs (c.f. ISO 11898-1 section 10.4.4.2 "Error flag").
For this reason, it makes no sense to increment the tx_packets and tx_bytes fields of struct net_device_stats when sending an error message frame because no actual payload will be transmitted on the wire.
N.B. Sending error message frames is a very specific feature which, at the moment, is only supported by the Kvaser Hydra hardware. Please refer to [1] for more details on the topic.
--- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +6 -1
@@ -296,6 +296,7 @@ struct kvaser_cmd {#define KVASER_USB_HYDRA_CF_FLAG_OVERRUN BIT(1)#define KVASER_USB_HYDRA_CF_FLAG_REMOTE_FRAME BIT(4)#define KVASER_USB_HYDRA_CF_FLAG_EXTENDED_ID BIT(5) +#define KVASER_USB_HYDRA_CF_FLAG_TX_ACK BIT(6)/* CAN frame flags. Used in ext_rx_can and ext_tx_can */ #define KVASER_USB_HYDRA_CF_FLAG_OSM_NACK BIT(12)#define KVASER_USB_HYDRA_CF_FLAG_ABL BIT(13)
@@ -1114,6 +1115,7 @@ static void kvaser_usb_hydra_tx_acknowledge(const struct kvaser_usb *dev,struct kvaser_usb_net_priv *priv;unsigned long irq_flags;bool one_shot_fail = false; +bool is_err_frame = false;u16 transid =kvaser_usb_hydra_get_cmd_transid (cmd); priv =kvaser_usb_hydra_net_priv_from_cmd (dev, cmd);
@@ -1132,10 +1134,13 @@ static void kvaser_usb_hydra_tx_acknowledge(const struct kvaser_usb *dev,kvaser_usb_hydra_one_shot_fail (priv, cmd_ext); one_shot_fail = true; } + + is_err_frame = flags &KVASER_USB_HYDRA_CF_FLAG_TX_ACK && + flags &KVASER_USB_HYDRA_CF_FLAG_ERROR_FRAME ; } context = &priv->tx_contexts[transid % dev->max_tx_urbs]; -if (!one_shot_fail) { +if (!one_shot_fail && !is_err_frame) {struct net_device_stats *stats = &priv->netdev->stats; stats->tx_packets++;
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 9/15 can: do not copy the payload of RTR frames
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
The actual payload length of the CAN Remote Transmission Request (RTR) frames is always 0, i.e. no payload is transmitted on the wire. However, those RTR frames still use the DLC to indicate the length of the requested frame.
For this reason, it is incorrect to copy the payload of RTR frames (the payload buffer would only contain garbage data). This patch encapsulates the payload copy in a check toward the RTR flag.
--- drivers/net/can/pch_can.c | 15 ++++++++------- drivers/net/can/spi/mcp251x.c | 3 ++- drivers/net/can/usb/mcba_usb.c | 8 ++++---- 3 files changed, 14 insertions(+), 12 deletions(-)
drivers/net/can/pch_can.c +8 -7
@@ -677,16 +677,17 @@ static int pch_can_rx_normal(struct net_device *ndev, u32 obj_num, int quota) cf->can_id = id; } -if (id2 &PCH_ID2_DIR ) - cf->can_id |=CAN_RTR_FLAG ; - cf->len =can_cc_dlc2len ((ioread32 (&priv->regs-> ifregs[0 ].mcont)) &0xF ); -for (i =0 ; i < cf->len; i +=2 ) { - data_reg =ioread16 (&priv->regs->ifregs[0 ].data[i /2 ]); - cf->data[i] = data_reg; - cf->data[i +1 ] = data_reg >>8 ; +if (id2 &PCH_ID2_DIR ) { + cf->can_id |=CAN_RTR_FLAG ; + }else { +for (i =0 ; i < cf->len; i +=2 ) { + data_reg =ioread16 (&priv->regs->ifregs[0 ].data[i /2 ]); + cf->data[i] = data_reg; + cf->data[i +1 ] = data_reg >>8 ; + } } rcv_pkts++;
drivers/net/can/spi/mcp251x.c +2 -1
@@ -730,7 +730,8 @@ static void mcp251x_hw_rx(struct spi_device *spi, int buf_idx) }/* Data length */ frame->len =can_cc_dlc2len (buf[RXBDLC_OFF ] &RXBDLC_LEN_MASK ); -memcpy (frame->data, buf +RXBDAT_OFF , frame->len); +if (!(frame->can_id &CAN_RTR_FLAG )) +memcpy (frame->data, buf +RXBDAT_OFF , frame->len); priv->net->stats.rx_packets++; priv->net->stats.rx_bytes += frame->len;
drivers/net/can/usb/mcba_usb.c +4 -4
@@ -450,12 +450,12 @@ static void mcba_usb_process_can(struct mcba_priv *priv, cf->can_id = (sid &0xffe0 ) >>5 ; } -if (msg->dlc &MCBA_DLC_RTR_MASK ) - cf->can_id |=CAN_RTR_FLAG ; - cf->len =can_cc_dlc2len (msg->dlc &MCBA_DLC_MASK ); -memcpy (cf->data, msg->data, cf->len); +if (msg->dlc &MCBA_DLC_RTR_MASK ) + cf->can_id |=CAN_RTR_FLAG ; +else +memcpy (cf->data, msg->data, cf->len); stats->rx_packets++; stats->rx_bytes += cf->len;
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 10/15 can: do not increase rx_bytes statistics for RTR frames
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
The actual payload length of the CAN Remote Transmission Request (RTR) frames is always 0, i.e. no payload is transmitted on the wire. However, those RTR frames still use the DLC to indicate the length of the requested frame.
As such, net_device_stats::rx_bytes should not be increased for the RTR frames.
This patch fixes all the CAN drivers.
--- drivers/net/can/at91_can.c | 4 +++- drivers/net/can/c_can/c_can_main.c | 4 ++-- drivers/net/can/cc770/cc770.c | 5 +++-- drivers/net/can/dev/rx-offload.c | 3 ++- drivers/net/can/grcan.c | 6 +++--- drivers/net/can/ifi_canfd/ifi_canfd.c | 6 +++--- drivers/net/can/janz-ican3.c | 3 ++- drivers/net/can/kvaser_pciefd.c | 11 ++++++----- drivers/net/can/m_can/m_can.c | 6 +++--- drivers/net/can/mscan/mscan.c | 3 ++- drivers/net/can/pch_can.c | 6 +++--- drivers/net/can/peak_canfd/peak_canfd.c | 7 ++++--- drivers/net/can/rcar/rcar_can.c | 5 +++-- drivers/net/can/rcar/rcar_canfd.c | 3 ++- drivers/net/can/sja1000/sja1000.c | 5 +++-- drivers/net/can/slcan.c | 4 +++- drivers/net/can/spi/hi311x.c | 7 ++++--- drivers/net/can/spi/mcp251x.c | 5 +++-- drivers/net/can/sun4i_can.c | 10 ++++++---- drivers/net/can/usb/ems_usb.c | 5 +++-- drivers/net/can/usb/esd_usb2.c | 5 +++-- .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 16 ++++++++++------ drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 3 ++- drivers/net/can/usb/mcba_usb.c | 7 ++++--- drivers/net/can/usb/peak_usb/pcan_usb.c | 7 ++++--- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 8 ++++---- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 10 ++++++---- drivers/net/can/usb/ucan.c | 3 ++- drivers/net/can/usb/usb_8dev.c | 9 +++++---- drivers/net/can/xilinx_can.c | 10 +++++++--- 30 files changed, 110 insertions(+), 76 deletions(-)
drivers/net/can/at91_can.c +3 -1
@@ -617,7 +617,9 @@ static void at91_read_msg(struct net_device *dev, unsigned int mb)at91_read_mb (dev, mb, cf); stats->rx_packets++; - stats->rx_bytes += cf->len; +if (!(cf->can_id &CAN_RTR_FLAG )) + stats->rx_bytes += cf->len; +netif_receive_skb (skb);can_led_event (dev,CAN_LED_EVENT_RX );
drivers/net/can/c_can/c_can_main.c +2 -2
@@ -403,10 +403,10 @@ static int c_can_read_msg_object(struct net_device *dev, int iface, u32 ctrl) frame->data[i +1 ] = data >>8 ; } } - } + stats->rx_bytes += frame->len; + } stats->rx_packets++; - stats->rx_bytes += frame->len;netif_receive_skb (skb);return 0 ;
drivers/net/can/cc770/cc770.c +3 -2
@@ -489,10 +489,11 @@ static void cc770_rx(struct net_device *dev, unsigned int mo, u8 ctrl1) cf->len =can_cc_dlc2len ((config &0xf0 ) >>4 );for (i =0 ; i < cf->len; i++) cf->data[i] =cc770_read_reg (priv, msgobj[mo].data[i]); - } + stats->rx_bytes += cf->len; + } stats->rx_packets++; - stats->rx_bytes += cf->len; +netif_rx (skb); }
drivers/net/can/dev/rx-offload.c +2 -1
@@ -56,7 +56,8 @@ static int can_rx_offload_napi_poll(struct napi_struct *napi, int quota) work_done++;if (!(cf->can_id &CAN_ERR_FLAG )) { stats->rx_packets++; - stats->rx_bytes += cf->len; +if (!(cf->can_id &CAN_RTR_FLAG )) + stats->rx_bytes += cf->len; }netif_receive_skb (skb); }
drivers/net/can/grcan.c +3 -3
@@ -1211,11 +1211,11 @@ static int grcan_receive(struct net_device *dev, int budget) shift =GRCAN_MSG_DATA_SHIFT (i); cf->data[i] = (u8)(slot[j] >> shift); } - } -/* Update statistics and read pointer */ + stats->rx_bytes += cf->len; + } stats->rx_packets++; - stats->rx_bytes += cf->len; +netif_receive_skb (skb); rd =grcan_ring_add (rd,GRCAN_MSG_SIZE , dma->rx.size);
drivers/net/can/ifi_canfd/ifi_canfd.c +3 -3
@@ -309,15 +309,15 @@ static void ifi_canfd_read_fifo(struct net_device *ndev) *(u32 *)(cf->data + i) =readl (priv->base +IFI_CANFD_RXFIFO_DATA + i); } + + stats->rx_bytes += cf->len; } + stats->rx_packets++;/* Remove the packet from FIFO */ writel (IFI_CANFD_RXSTCMD_REMOVE_MSG , priv->base +IFI_CANFD_RXSTCMD );writel (rx_irq_mask, priv->base +IFI_CANFD_INTERRUPT ); - stats->rx_packets++; - stats->rx_bytes += cf->len; -netif_receive_skb (skb); }
drivers/net/can/janz-ican3.c +2 -1
@@ -1421,7 +1421,8 @@ static int ican3_recv_skb(struct ican3_dev *mod)/* update statistics, receive the skb */ stats->rx_packets++; - stats->rx_bytes += cf->len; +if (!(cf->can_id &CAN_RTR_FLAG )) + stats->rx_bytes += cf->len;netif_receive_skb (skb); err_noalloc:
drivers/net/can/kvaser_pciefd.c +6 -5
@@ -1185,20 +1185,21 @@ static int kvaser_pciefd_handle_data_packet(struct kvaser_pciefd *pcie, cf->len =can_fd_dlc2len (p->header[1 ] >>KVASER_PCIEFD_RPACKET_DLC_SHIFT ); -if (p->header[0 ] &KVASER_PCIEFD_RPACKET_RTR ) +if (p->header[0 ] &KVASER_PCIEFD_RPACKET_RTR ) { cf->can_id |=CAN_RTR_FLAG ; -else + }else {memcpy (cf->data, data, cf->len); + stats->rx_bytes += cf->len; + } + stats->rx_packets++; + shhwtstamps =skb_hwtstamps (skb); shhwtstamps->hwtstamp =ns_to_ktime (div_u64 (p->timestamp *1000 , pcie->freq_to_ticks_div)); - stats->rx_bytes += cf->len; - stats->rx_packets++; -return netif_rx (skb); }
drivers/net/can/m_can/m_can.c +3 -3
@@ -518,14 +518,14 @@ static int m_can_read_fifo(struct net_device *dev, u32 rxfs) cf->data, DIV_ROUND_UP(cf->len, 4));if (err) goto out_free_skb; + + stats->rx_bytes += cf->len; } + stats->rx_packets++;/* acknowledge rx fifo 0 */ m_can_write (cdev,M_CAN_RXF0A , fgi); - stats->rx_packets++; - stats->rx_bytes += cf->len; - timestamp =FIELD_GET (RX_BUF_RXTS_MASK , fifo_header.dlc);m_can_receive_skb (cdev, skb, timestamp);
drivers/net/can/mscan/mscan.c +2 -1
@@ -404,7 +404,8 @@ static int mscan_rx_poll(struct napi_struct *napi, int quota)if (canrflg &MSCAN_RXF ) {mscan_get_rx_frame (dev, frame); stats->rx_packets++; - stats->rx_bytes += frame->len; +if (!(frame->can_id &CAN_RTR_FLAG )) + stats->rx_bytes += frame->len; }else if (canrflg &MSCAN_ERR_IF ) {mscan_get_err_frame (dev, frame, canrflg); }
drivers/net/can/pch_can.c +3 -3
@@ -688,12 +688,12 @@ static int pch_can_rx_normal(struct net_device *ndev, u32 obj_num, int quota) cf->data[i] = data_reg; cf->data[i +1 ] = data_reg >>8 ; } - } - rcv_pkts++; + stats->rx_bytes += cf->len; + } stats->rx_packets++; + rcv_pkts++; quota--; - stats->rx_bytes += cf->len;netif_receive_skb (skb);pch_fifo_thresh (priv, obj_num);
drivers/net/can/peak_canfd/peak_canfd.c +4 -3
@@ -310,12 +310,13 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,if (rx_msg_flags &PUCAN_MSG_EXT_ID ) cf->can_id |=CAN_EFF_FLAG ; -if (rx_msg_flags &PUCAN_MSG_RTR ) +if (rx_msg_flags &PUCAN_MSG_RTR ) { cf->can_id |=CAN_RTR_FLAG ; -else + }else {memcpy (cf->data, msg->d, cf->len); - stats->rx_bytes += cf->len; + stats->rx_bytes += cf->len; + } stats->rx_packets++;pucan_netif_rx (skb, msg->ts_low, msg->ts_high);
drivers/net/can/rcar/rcar_can.c +3 -2
@@ -662,12 +662,13 @@ static void rcar_can_rx_pkt(struct rcar_can_priv *priv)for (dlc =0 ; dlc < cf->len; dlc++) cf->data[dlc] =readb (&priv->regs->mb[RCAR_CAN_RX_FIFO_MBX ].data[dlc]); + + stats->rx_bytes += cf->len; } + stats->rx_packets++;can_led_event (priv->ndev,CAN_LED_EVENT_RX ); - stats->rx_bytes += cf->len; - stats->rx_packets++;netif_receive_skb (skb); }
drivers/net/can/rcar/rcar_canfd.c +2 -1
@@ -1550,7 +1550,8 @@ static void rcar_canfd_rx_pkt(struct rcar_canfd_channel *priv)can_led_event (priv->ndev,CAN_LED_EVENT_RX ); - stats->rx_bytes += cf->len; +if (!(cf->can_id &CAN_RTR_FLAG )) + stats->rx_bytes += cf->len; stats->rx_packets++;netif_receive_skb (skb); }
drivers/net/can/sja1000/sja1000.c +3 -2
@@ -372,15 +372,16 @@ static void sja1000_rx(struct net_device *dev) }else {for (i =0 ; i < cf->len; i++) cf->data[i] = priv->read_reg (priv, dreg++); + + stats->rx_bytes += cf->len; } + stats->rx_packets++; cf->can_id = id;/* release receive buffer */ sja1000_write_cmdreg (priv,CMD_RRB ); - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb);can_led_event (dev,CAN_LED_EVENT_RX );
drivers/net/can/slcan.c +3 -1
@@ -218,7 +218,9 @@ static void slc_bump(struct slcan *sl)skb_put_data (skb, &cf,sizeof (struct can_frame )); sl->dev->stats.rx_packets++; - sl->dev->stats.rx_bytes += cf.len; +if (!(cf.can_id &CAN_RTR_FLAG )) + sl->dev->stats.rx_bytes += cf.len; +netif_rx_ni (skb); }
drivers/net/can/spi/hi311x.c +4 -3
@@ -343,14 +343,15 @@ static void hi3110_hw_rx(struct spi_device *spi)/* Data length */ frame->len =can_cc_dlc2len (buf[HI3110_FIFO_WOTIME_DLC_OFF ] &0x0F ); -if (buf[HI3110_FIFO_WOTIME_ID_OFF +3 ] &HI3110_FIFO_WOTIME_ID_RTR ) +if (buf[HI3110_FIFO_WOTIME_ID_OFF +3 ] &HI3110_FIFO_WOTIME_ID_RTR ) { frame->can_id |=CAN_RTR_FLAG ; -else + }else {memcpy (frame->data, buf +HI3110_FIFO_WOTIME_DAT_OFF , frame->len); + priv->net->stats.rx_bytes += frame->len; + } priv->net->stats.rx_packets++; - priv->net->stats.rx_bytes += frame->len;can_led_event (priv->net,CAN_LED_EVENT_RX );
drivers/net/can/spi/mcp251x.c +3 -2
@@ -730,11 +730,12 @@ static void mcp251x_hw_rx(struct spi_device *spi, int buf_idx) }/* Data length */ frame->len =can_cc_dlc2len (buf[RXBDLC_OFF ] &RXBDLC_LEN_MASK ); -if (!(frame->can_id &CAN_RTR_FLAG )) +if (!(frame->can_id &CAN_RTR_FLAG )) {memcpy (frame->data, buf +RXBDAT_OFF , frame->len); + priv->net->stats.rx_bytes += frame->len; + } priv->net->stats.rx_packets++; - priv->net->stats.rx_bytes += frame->len;can_led_event (priv->net,CAN_LED_EVENT_RX );
drivers/net/can/sun4i_can.c +6 -4
@@ -501,18 +501,20 @@ static void sun4i_can_rx(struct net_device *dev) }/* remote frame ? */ -if (fi &SUN4I_MSG_RTR_FLAG ) +if (fi &SUN4I_MSG_RTR_FLAG ) { id |=CAN_RTR_FLAG ; -else + }else {for (i =0 ; i < cf->len; i++) cf->data[i] =readl (priv->base + dreg + i *4 ); + stats->rx_bytes += cf->len; + } + stats->rx_packets++; + cf->can_id = id;sun4i_can_write_cmdreg (priv,SUN4I_CMD_RELEASE_RBUF ); - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb);can_led_event (dev,CAN_LED_EVENT_RX );
drivers/net/can/usb/ems_usb.c +3 -2
@@ -320,10 +320,11 @@ static void ems_usb_rx_can_msg(struct ems_usb *dev, struct ems_cpc_msg *msg) }else {for (i =0 ; i < cf->len; i++) cf->data[i] = msg->msg.can_msg.msg[i]; - } + stats->rx_bytes += cf->len; + } stats->rx_packets++; - stats->rx_bytes += cf->len; +netif_rx (skb); }
drivers/net/can/usb/esd_usb2.c +3 -2
@@ -332,10 +332,11 @@ static void esd_usb2_rx_can_msg(struct esd_usb2_net_priv *priv, }else {for (i =0 ; i < cf->len; i++) cf->data[i] = msg->msg.rx.data[i]; - } + stats->rx_bytes += cf->len; + } stats->rx_packets++; - stats->rx_bytes += cf->len; +netif_rx (skb); }
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +10 -6
@@ -1206,13 +1206,15 @@ static void kvaser_usb_hydra_rx_msg_std(const struct kvaser_usb *dev, cf->len =can_cc_dlc2len (cmd->rx_can.dlc); -if (flags &KVASER_USB_HYDRA_CF_FLAG_REMOTE_FRAME ) +if (flags &KVASER_USB_HYDRA_CF_FLAG_REMOTE_FRAME ) { cf->can_id |=CAN_RTR_FLAG ; -else + }else {memcpy (cf->data, cmd->rx_can.data, cf->len); + stats->rx_bytes += cf->len; + } stats->rx_packets++; - stats->rx_bytes += cf->len; +netif_rx (skb); }
@@ -1284,13 +1286,15 @@ static void kvaser_usb_hydra_rx_msg_ext(const struct kvaser_usb *dev, cf->len =can_cc_dlc2len (dlc); } -if (flags &KVASER_USB_HYDRA_CF_FLAG_REMOTE_FRAME ) +if (flags &KVASER_USB_HYDRA_CF_FLAG_REMOTE_FRAME ) { cf->can_id |=CAN_RTR_FLAG ; -else + }else {memcpy (cf->data, cmd->rx_can.kcan_payload, cf->len); + stats->rx_bytes += cf->len; + } stats->rx_packets++; - stats->rx_bytes += cf->len; +netif_rx (skb); }
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +2 -1
@@ -1068,7 +1068,8 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev, } stats->rx_packets++; - stats->rx_bytes += cf->len; +if (!(cf->can_id &CAN_RTR_FLAG )) + stats->rx_bytes += cf->len;netif_rx (skb); }
drivers/net/can/usb/mcba_usb.c +4 -3
@@ -452,13 +452,14 @@ static void mcba_usb_process_can(struct mcba_priv *priv, cf->len =can_cc_dlc2len (msg->dlc &MCBA_DLC_MASK ); -if (msg->dlc &MCBA_DLC_RTR_MASK ) +if (msg->dlc &MCBA_DLC_RTR_MASK ) { cf->can_id |=CAN_RTR_FLAG ; -else + }else {memcpy (cf->data, msg->data, cf->len); + stats->rx_bytes += cf->len; + } stats->rx_packets++; - stats->rx_bytes += cf->len;can_led_event (priv->netdev,CAN_LED_EVENT_RX );netif_rx (skb);
drivers/net/can/usb/peak_usb/pcan_usb.c +4 -3
@@ -677,15 +677,16 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len)/* Ignore next byte (client private id) if SRR bit is set */ if (can_id_flags &PCAN_USB_TX_SRR ) mc->ptr++; + +/* update statistics */ + mc->netdev->stats.rx_bytes += cf->len; } + mc->netdev->stats.rx_packets++;/* convert timestamp into kernel time */ hwts =skb_hwtstamps (skb);peak_usb_get_ts_time (&mc->pdev->time_ref, mc->ts16, &hwts->hwtstamp); -/* update statistics */ - mc->netdev->stats.rx_packets++; - mc->netdev->stats.rx_bytes += cf->len;/* push the skb */ netif_rx (skb);
drivers/net/can/usb/peak_usb/pcan_usb_fd.c +4 -4
@@ -507,13 +507,13 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if,if (rx_msg_flags &PUCAN_MSG_EXT_ID ) cfd->can_id |=CAN_EFF_FLAG ; -if (rx_msg_flags &PUCAN_MSG_RTR ) +if (rx_msg_flags &PUCAN_MSG_RTR ) { cfd->can_id |=CAN_RTR_FLAG ; -else + }else {memcpy (cfd->data, rm->d, cfd->len); - + netdev->stats.rx_bytes += cfd->len; + } netdev->stats.rx_packets++; - netdev->stats.rx_bytes += cfd->len;peak_usb_netif_rx_64 (skb,le32_to_cpu (rm->ts_low),le32_to_cpu (rm->ts_high));
drivers/net/can/usb/peak_usb/pcan_usb_pro.c +6 -4
@@ -536,17 +536,19 @@ static int pcan_usb_pro_handle_canmsg(struct pcan_usb_pro_interface *usb_if,if (rx->flags &PCAN_USBPRO_EXT ) can_frame->can_id |=CAN_EFF_FLAG ; -if (rx->flags &PCAN_USBPRO_RTR ) +if (rx->flags &PCAN_USBPRO_RTR ) { can_frame->can_id |=CAN_RTR_FLAG ; -else + }else {memcpy (can_frame->data, rx->data, can_frame->len); + netdev->stats.rx_bytes += can_frame->len; + } + netdev->stats.rx_packets++; + hwts =skb_hwtstamps (skb);peak_usb_get_ts_time (&usb_if->time_ref,le32_to_cpu (rx->ts32), &hwts->hwtstamp); - netdev->stats.rx_packets++; - netdev->stats.rx_bytes += can_frame->len;netif_rx (skb);return 0 ;
drivers/net/can/usb/ucan.c +2 -1
@@ -623,7 +623,8 @@ static void ucan_rx_can_msg(struct ucan_priv *up, struct ucan_message_in *m)/* don't count error frames as real packets */ if (!(cf->can_id &CAN_ERR_FLAG )) { stats->rx_packets++; - stats->rx_bytes += cf->len; +if (!(cf->can_id &CAN_RTR_FLAG )) + stats->rx_bytes += cf->len; }/* pass it to Linux */
drivers/net/can/usb/usb_8dev.c +5 -4
@@ -472,13 +472,14 @@ static void usb_8dev_rx_can_msg(struct usb_8dev_priv *priv,if (msg->flags &USB_8DEV_EXTID ) cf->can_id |=CAN_EFF_FLAG ; -if (msg->flags &USB_8DEV_RTR ) +if (msg->flags &USB_8DEV_RTR ) { cf->can_id |=CAN_RTR_FLAG ; -else + }else {memcpy (cf->data, msg->data, cf->len); - + stats->rx_bytes += cf->len; + } stats->rx_packets++; - stats->rx_bytes += cf->len; +netif_rx (skb);can_led_event (priv->netdev,CAN_LED_EVENT_RX );
drivers/net/can/xilinx_can.c +7 -3
@@ -787,10 +787,11 @@ static int xcan_rx(struct net_device *ndev, int frame_base) *(__be32 *)(cf->data) =cpu_to_be32 (data[0 ]);if (cf->len >4 ) *(__be32 *)(cf->data +4 ) =cpu_to_be32 (data[1 ]); - } - stats->rx_bytes += cf->len; + stats->rx_bytes += cf->len; + } stats->rx_packets++; +netif_receive_skb (skb);return 1 ;
@@ -871,8 +872,11 @@ static int xcanfd_rx(struct net_device *ndev, int frame_base) *(__be32 *)(cf->data + i) =cpu_to_be32 (data[0 ]); } } - stats->rx_bytes += cf->len; + +if (!(cf->can_id &CAN_RTR_FLAG )) + stats->rx_bytes += cf->len; stats->rx_packets++; +netif_receive_skb (skb);return 1 ;
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 11/15 can: do not increase tx_bytes statistics for RTR frames
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
The actual payload length of the CAN Remote Transmission Request (RTR) frames is always 0, i.e. no payload is transmitted on the wire. However, those RTR frames still use the DLC to indicate the length of the requested frame.
As such, net_device_stats::tx_bytes should not be increased when sending RTR frames.
The function can_get_echo_skb() already returns the correct length, even for RTR frames (c.f. [1]). However, for historical reasons, the drivers do not use can_get_echo_skb()'s return value and instead, most of them store a temporary length (or dlc) in some local structure or array. Using the return value of can_get_echo_skb() solves the issue. After doing this, such length/dlc fields become unused and so this patch does the adequate cleaning when needed.
This patch fixes all the CAN drivers.
Finally, can_get_echo_skb() is decorated with the __must_check attribute in order to force future drivers to correctly use its return value (else the compiler would emit a warning).
[1] commit ed3320cec279 ("can: dev: __can_get_echo_skb():
fix real payload length return value for RTR frames")
--- drivers/net/can/at91_can.c | 8 ++-- drivers/net/can/c_can/c_can.h | 1 - drivers/net/can/c_can/c_can_main.c | 7 +--- drivers/net/can/cc770/cc770.c | 8 +--- drivers/net/can/grcan.c | 17 +------- drivers/net/can/janz-ican3.c | 3 +- drivers/net/can/mscan/mscan.c | 4 +- drivers/net/can/pch_can.c | 9 ++-- drivers/net/can/peak_canfd/peak_canfd.c | 3 +- drivers/net/can/rcar/rcar_can.c | 11 +++-- drivers/net/can/rcar/rcar_canfd.c | 6 +-- drivers/net/can/sja1000/sja1000.c | 4 +- drivers/net/can/slcan.c | 3 +- drivers/net/can/softing/softing_main.c | 8 ++-- drivers/net/can/spi/hi311x.c | 24 +++++------ drivers/net/can/spi/mcp251x.c | 25 +++++------ drivers/net/can/sun4i_can.c | 5 +-- drivers/net/can/usb/ems_usb.c | 7 +--- drivers/net/can/usb/esd_usb2.c | 6 +-- drivers/net/can/usb/gs_usb.c | 7 ++-- drivers/net/can/usb/kvaser_usb/kvaser_usb.h | 5 +-- .../net/can/usb/kvaser_usb/kvaser_usb_core.c | 2 +- .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 42 +++++++++---------- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 13 +++--- drivers/net/can/usb/mcba_usb.c | 12 ++---- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 20 ++++----- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 1 - drivers/net/can/usb/ucan.c | 10 ++--- drivers/net/can/usb/usb_8dev.c | 6 +-- drivers/net/can/vcan.c | 7 ++-- drivers/net/can/vxcan.c | 2 +- include/linux/can/skb.h | 5 ++- 32 files changed, 116 insertions(+), 175 deletions(-)
drivers/net/can/at91_can.c +4 -4
@@ -448,7 +448,6 @@ static void at91_chip_stop(struct net_device *dev, enum can_state state)static netdev_tx_t at91_start_xmit (struct sk_buff *skb,struct net_device *dev) {struct at91_priv *priv =netdev_priv (dev); -struct net_device_stats *stats = &dev->stats;struct can_frame *cf = (struct can_frame *)skb->data;unsigned int mb, prio;u32 reg_mid, reg_mcr;
@@ -480,8 +479,6 @@ static netdev_tx_t at91_start_xmit(struct sk_buff *skb, struct net_device *dev)/* This triggers transmission */ at91_write (priv,AT91_MCR (mb), reg_mcr); - stats->tx_bytes += cf->len; -/* _NOTE_: subtract AT91_MB_TX_FIRST offset from mb! */ can_put_echo_skb (skb, dev, mb -get_mb_tx_first (priv),0 );
@@ -852,7 +849,10 @@ static void at91_irq_tx(struct net_device *dev, u32 reg_sr)if (likely (reg_msr &AT91_MSR_MRDY && ~reg_msr &AT91_MSR_MABT )) {/* _NOTE_: subtract AT91_MB_TX_FIRST offset from mb! */ -can_get_echo_skb (dev, mb -get_mb_tx_first (priv),NULL ); + dev->stats.tx_bytes += +can_get_echo_skb (dev, + mb -get_mb_tx_first (priv), +NULL ); dev->stats.tx_packets++;can_led_event (dev,CAN_LED_EVENT_TX ); }
drivers/net/can/c_can/c_can.h +0 -1
@@ -211,7 +211,6 @@ struct c_can_priv {struct c_can_raminit raminit_sys;/* RAMINIT via syscon regmap */ void (*raminit)(const struct c_can_priv *priv,bool enable);u32 comm_rcv_high; -u32 dlc[]; };struct net_device *alloc_c_can_dev (int msg_obj_num);
drivers/net/can/c_can/c_can_main.c +2 -5
@@ -477,7 +477,6 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,* transmit as we might race against do_tx(). */ c_can_setup_tx_object (dev,IF_TX , frame, idx); - priv->dlc[idx] = frame->len;can_put_echo_skb (skb, dev, idx,0 ); obj = idx + priv->msg_obj_tx_first;c_can_object_put (dev,IF_TX , obj, cmd);
@@ -742,8 +741,7 @@ static void c_can_do_tx(struct net_device *dev)* NAPI. We are not transmitting. */ c_can_inval_tx_object (dev,IF_NAPI , obj); -can_get_echo_skb (dev, idx,NULL ); - bytes += priv->dlc[idx]; + bytes +=can_get_echo_skb (dev, idx,NULL ); pkts++; }
@@ -1227,8 +1225,7 @@ struct net_device *alloc_c_can_dev(int msg_obj_num)struct c_can_priv *priv;int msg_obj_tx_num = msg_obj_num /2 ; - dev =alloc_candev (struct_size (priv, dlc, msg_obj_tx_num), - msg_obj_tx_num); + dev =alloc_candev (sizeof (*priv), msg_obj_tx_num);if (!dev)return NULL ;
drivers/net/can/cc770/cc770.c +2 -6
@@ -664,7 +664,6 @@ static void cc770_tx_interrupt(struct net_device *dev, unsigned int o)struct cc770_priv *priv =netdev_priv (dev);struct net_device_stats *stats = &dev->stats;unsigned int mo =obj2msgobj (o); -struct can_frame *cf;u8 ctrl1; ctrl1 =cc770_read_reg (priv, msgobj[mo].ctrl1);
@@ -696,12 +695,9 @@ static void cc770_tx_interrupt(struct net_device *dev, unsigned int o)return ; } - cf = (struct can_frame *)priv->tx_skb->data; - stats->tx_bytes += cf->len; - stats->tx_packets++; -can_put_echo_skb (priv->tx_skb, dev,0 ,0 ); -can_get_echo_skb (dev,0 ,NULL ); + stats->tx_bytes +=can_get_echo_skb (dev,0 ,NULL ); + stats->tx_packets++; priv->tx_skb =NULL ;netif_wake_queue (dev);
drivers/net/can/grcan.c +2 -15
@@ -255,7 +255,6 @@ struct grcan_priv {struct grcan_dma dma;struct sk_buff **echo_skb;/* We allocate this on our own */ -u8 *txdlc;/* Length of queued frames */ /* The echo skb pointer, pointing into echo_skb and indicating which * frames can be echoed back. See the "Notes on the tx cyclic buffer
@@ -515,9 +514,7 @@ static int catch_up_echo_skb(struct net_device *dev, int budget, bool echo)if (echo) {/* Normal echo of messages */ stats->tx_packets++; - stats->tx_bytes += priv->txdlc[i]; - priv->txdlc[i] =0 ; -can_get_echo_skb (dev, i,NULL ); + stats->tx_bytes +=can_get_echo_skb (dev, i,NULL ); }else {/* For cleanup of untransmitted messages */ can_free_echo_skb (dev, i,NULL );
@@ -1062,16 +1059,10 @@ static int grcan_open(struct net_device *dev) priv->can.echo_skb_max = dma->tx.size; priv->can.echo_skb = priv->echo_skb; - priv->txdlc =kcalloc (dma->tx.size,sizeof (*priv->txdlc),GFP_KERNEL ); -if (!priv->txdlc) { - err = -ENOMEM ; - goto exit_free_echo_skb; - } -/* Get can device up */ err =open_candev (dev);if (err) - goto exit_free_txdlc; + goto exit_free_echo_skb; err =request_irq (dev->irq, grcan_interrupt,IRQF_SHARED , dev->name, dev);
@@ -1093,8 +1084,6 @@ static int grcan_open(struct net_device *dev) exit_close_candev:close_candev (dev); -exit_free_txdlc: -kfree (priv->txdlc); exit_free_echo_skb:kfree (priv->echo_skb); exit_free_dma_buffers:
@@ -1129,7 +1118,6 @@ static int grcan_close(struct net_device *dev) priv->can.echo_skb_max =0 ; priv->can.echo_skb =NULL ;kfree (priv->echo_skb); -kfree (priv->txdlc);return 0 ; }
@@ -1447,7 +1435,6 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *skb,* can_put_echo_skb would be an error unless other measures are * taken. */ - priv->txdlc[slotindex] = cf->len;/* Store dlc for statistics */ can_put_echo_skb (skb, dev, slotindex,0 );/* Make sure everything is written before allowing hardware to
drivers/net/can/janz-ican3.c +2 -1
@@ -1294,7 +1294,8 @@ static unsigned int ican3_get_echo_skb(struct ican3_dev *mod) } cf = (struct can_frame *)skb->data; - dlc = cf->len; +if (!(cf->can_id &CAN_RTR_FLAG )) + dlc = cf->len;/* check flag whether this packet has to be looped back */ if (skb->pkt_type !=PACKET_LOOPBACK ) {
drivers/net/can/mscan/mscan.c +2 -2
@@ -448,9 +448,9 @@ static irqreturn_t mscan_isr(int irq, void *dev_id)continue ;out_8 (®s->cantbsel, mask); - stats->tx_bytes +=in_8 (®s->tx.dlr); + stats->tx_bytes +=can_get_echo_skb (dev, entry->id, +NULL ); stats->tx_packets++; -can_get_echo_skb (dev, entry->id,NULL ); priv->tx_active &= ~mask;list_del (pos); }
drivers/net/can/pch_can.c +3 -6
@@ -707,16 +707,13 @@ static void pch_can_tx_complete(struct net_device *ndev, u32 int_stat) {struct pch_can_priv *priv =netdev_priv (ndev);struct net_device_stats *stats = &(priv->ndev->stats); -u32 dlc; -can_get_echo_skb (ndev, int_stat -PCH_RX_OBJ_END -1 ,NULL ); + stats->tx_bytes +=can_get_echo_skb (ndev, int_stat -PCH_RX_OBJ_END -1 , +NULL ); + stats->tx_packets++;iowrite32 (PCH_CMASK_RX_TX_GET |PCH_CMASK_CLRINTPND , &priv->regs->ifregs[1 ].cmask);pch_can_rw_msg_obj (&priv->regs->ifregs[1 ].creq, int_stat); - dlc =can_cc_dlc2len (ioread32 (&priv->regs->ifregs[1 ].mcont) & -PCH_IF_MCONT_DLC ); - stats->tx_bytes += dlc; - stats->tx_packets++;if (int_stat ==PCH_TX_OBJ_END )netif_wake_queue (ndev); }
drivers/net/can/peak_canfd/peak_canfd.c +1 -2
@@ -266,10 +266,9 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,unsigned long flags;spin_lock_irqsave (&priv->echo_lock, flags); -can_get_echo_skb (priv->ndev, msg->client,NULL );/* count bytes of the echo instead of skb */ - stats->tx_bytes += cf_len; + stats->tx_bytes +=can_get_echo_skb (priv->ndev, msg->client,NULL ); stats->tx_packets++;/* restart tx queue (a slot is free) */
drivers/net/can/rcar/rcar_can.c +5 -6
@@ -94,7 +94,6 @@ struct rcar_can_priv {struct rcar_can_regs __iomem *regs;struct clk *clk;struct clk *can_clk; -u8 tx_dlc[RCAR_CAN_FIFO_DEPTH ];u32 tx_head;u32 tx_tail;u8 clock_select;
@@ -379,10 +378,11 @@ static void rcar_can_tx_done(struct net_device *ndev)if (priv->tx_head - priv->tx_tail <= unsent)break ; stats->tx_packets++; - stats->tx_bytes += priv->tx_dlc[priv->tx_tail % -RCAR_CAN_FIFO_DEPTH ]; - priv->tx_dlc[priv->tx_tail %RCAR_CAN_FIFO_DEPTH ] =0 ; -can_get_echo_skb (ndev, priv->tx_tail %RCAR_CAN_FIFO_DEPTH ,NULL ); + stats->tx_bytes += +can_get_echo_skb (ndev, + priv->tx_tail %RCAR_CAN_FIFO_DEPTH , +NULL ); + priv->tx_tail++;netif_wake_queue (ndev); }
@@ -612,7 +612,6 @@ static netdev_tx_t rcar_can_start_xmit(struct sk_buff *skb,writeb (cf->len, &priv->regs->mb[RCAR_CAN_TX_FIFO_MBX ].dlc); - priv->tx_dlc[priv->tx_head %RCAR_CAN_FIFO_DEPTH ] = cf->len;can_put_echo_skb (skb, ndev, priv->tx_head %RCAR_CAN_FIFO_DEPTH ,0 ); priv->tx_head++;/* Start Tx: write 0xff to the TFPCR register to increment
drivers/net/can/rcar/rcar_canfd.c +1 -5
@@ -502,7 +502,6 @@ struct rcar_canfd_channel {struct rcar_canfd_global *gpriv;/* Controller reference */ void __iomem *base;/* Register base address */ struct napi_struct napi; -u8 tx_len[RCANFD_FIFO_DEPTH ];/* For net stats */ u32 tx_head;/* Incremented on xmit */ u32 tx_tail;/* Incremented on xmit done */ u32 channel;/* Channel number */
@@ -1049,9 +1048,7 @@ static void rcar_canfd_tx_done(struct net_device *ndev) sent = priv->tx_tail %RCANFD_FIFO_DEPTH ; stats->tx_packets++; - stats->tx_bytes += priv->tx_len[sent]; - priv->tx_len[sent] =0 ; -can_get_echo_skb (ndev, sent,NULL ); + stats->tx_bytes +=can_get_echo_skb (ndev, sent,NULL );spin_lock_irqsave (&priv->tx_lock, flags); priv->tx_tail++;
@@ -1461,7 +1458,6 @@ static netdev_tx_t rcar_canfd_start_xmit(struct sk_buff *skb, RCANFD_C_CFDF(ch, RCANFD_CFFIFO_IDX, 0)); } - priv->tx_len[priv->tx_head %RCANFD_FIFO_DEPTH ] = cf->len;can_put_echo_skb (skb, ndev, priv->tx_head %RCANFD_FIFO_DEPTH ,0 );spin_lock_irqsave (&priv->tx_lock, flags);
drivers/net/can/sja1000/sja1000.c +1 -3
@@ -527,10 +527,8 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)can_free_echo_skb (dev,0 ,NULL ); }else {/* transmission complete */ - stats->tx_bytes += - priv->read_reg (priv,SJA1000_FI ) &0xf ; + stats->tx_bytes +=can_get_echo_skb (dev,0 ,NULL ); stats->tx_packets++; -can_get_echo_skb (dev,0 ,NULL ); }netif_wake_queue (dev);can_led_event (dev,CAN_LED_EVENT_TX );
drivers/net/can/slcan.c +2 -1
@@ -290,6 +290,8 @@ static void slc_encaps(struct slcan *sl, struct can_frame *cf)if (!(cf->can_id &CAN_RTR_FLAG )) {for (i =0 ; i < cf->len; i++) pos =hex_byte_pack_upper (pos, cf->data[i]); + + sl->dev->stats.tx_bytes += cf->len; } *pos++ ='\r' ;
@@ -306,7 +308,6 @@ static void slc_encaps(struct slcan *sl, struct can_frame *cf) actual = sl->tty->ops->write (sl->tty, sl->xbuff, pos - sl->xbuff); sl->xleft = (pos - sl->xbuff) - actual; sl->xhead = sl->xbuff + actual; - sl->dev->stats.tx_bytes += cf->len; }/* Write out any remaining transmit buffer. Scheduled when tty is writable */
drivers/net/can/softing/softing_main.c +4 -4
@@ -282,7 +282,10 @@ static int softing_handle_1(struct softing *card) skb = priv->can.echo_skb[priv->tx.echo_get];if (skb) skb->tstamp = ktime; -can_get_echo_skb (netdev, priv->tx.echo_get,NULL ); + ++netdev->stats.tx_packets; + netdev->stats.tx_bytes += +can_get_echo_skb (netdev, priv->tx.echo_get, +NULL ); ++priv->tx.echo_get;if (priv->tx.echo_get >=TX_ECHO_SKB_MAX ) priv->tx.echo_get =0 ;
@@ -290,9 +293,6 @@ static int softing_handle_1(struct softing *card) --priv->tx.pending;if (card->tx.pending) --card->tx.pending; - ++netdev->stats.tx_packets; -if (!(msg.can_id &CAN_RTR_FLAG )) - netdev->stats.tx_bytes += msg.len; }else {int ret;
drivers/net/can/spi/hi311x.c +11 -13
@@ -153,7 +153,6 @@ struct hi3110_priv {u8 *spi_rx_buf;struct sk_buff *tx_skb; -int tx_len;struct workqueue_struct *wq;struct work_struct tx_work;
@@ -166,6 +165,8 @@ struct hi3110_priv {#define HI3110_AFTER_SUSPEND_POWER 4#define HI3110_AFTER_SUSPEND_RESTART 8int restart_tx; +bool tx_busy; +struct regulator *power;struct regulator *transceiver;struct clk *clk;
@@ -175,13 +176,13 @@ static void hi3110_clean(struct net_device *net) {struct hi3110_priv *priv =netdev_priv (net); -if (priv->tx_skb || priv->tx_len) +if (priv->tx_skb || priv->tx_busy) net->stats.tx_errors++;dev_kfree_skb (priv->tx_skb); -if (priv->tx_len) +if (priv->tx_busy)can_free_echo_skb (priv->net,0 ,NULL ); priv->tx_skb =NULL ; - priv->tx_len =0 ; + priv->tx_busy = false; }/* Note about handling of error return of hi3110_spi_trans: accessing
@@ -369,7 +370,7 @@ static netdev_tx_t hi3110_hard_start_xmit(struct sk_buff *skb,struct hi3110_priv *priv =netdev_priv (net);struct spi_device *spi = priv->spi; -if (priv->tx_skb || priv->tx_len) { +if (priv->tx_skb || priv->tx_busy) {dev_err (&spi->dev,"hard_xmit called while tx busy\n" );return NETDEV_TX_BUSY ; }
@@ -586,7 +587,7 @@ static void hi3110_tx_work_handler(struct work_struct *ws) }else { frame = (struct can_frame *)priv->tx_skb->data;hi3110_hw_tx (spi, frame); - priv->tx_len =1 + frame->len; + priv->tx_busy = true;can_put_echo_skb (priv->tx_skb, net,0 ,0 ); priv->tx_skb =NULL ; }
@@ -721,14 +722,11 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id) } } -if (priv->tx_len && statf &HI3110_STAT_TXMTY ) { +if (priv->tx_busy && statf &HI3110_STAT_TXMTY ) { net->stats.tx_packets++; - net->stats.tx_bytes += priv->tx_len -1 ; + net->stats.tx_bytes +=can_get_echo_skb (net,0 ,NULL );can_led_event (net,CAN_LED_EVENT_TX ); -if (priv->tx_len) { -can_get_echo_skb (net,0 ,NULL ); - priv->tx_len =0 ; - } + priv->tx_busy = false;netif_wake_queue (net); }
@@ -755,7 +753,7 @@ static int hi3110_open(struct net_device *net) priv->force_quit =0 ; priv->tx_skb =NULL ; - priv->tx_len =0 ; + priv->tx_busy = false; ret =request_threaded_irq (spi->irq,NULL , hi3110_can_ist, flags,DEVICE_NAME , priv);
drivers/net/can/spi/mcp251x.c +13 -12
@@ -237,7 +237,6 @@ struct mcp251x_priv {u8 *spi_rx_buf;struct sk_buff *tx_skb; -int tx_len;struct workqueue_struct *wq;struct work_struct tx_work;
@@ -250,6 +249,8 @@ struct mcp251x_priv {#define AFTER_SUSPEND_POWER 4#define AFTER_SUSPEND_RESTART 8int restart_tx; +bool tx_busy; +struct regulator *power;struct regulator *transceiver;struct clk *clk;
@@ -272,13 +273,13 @@ static void mcp251x_clean(struct net_device *net) {struct mcp251x_priv *priv =netdev_priv (net); -if (priv->tx_skb || priv->tx_len) +if (priv->tx_skb || priv->tx_busy) net->stats.tx_errors++;dev_kfree_skb (priv->tx_skb); -if (priv->tx_len) +if (priv->tx_busy)can_free_echo_skb (priv->net,0 ,NULL ); priv->tx_skb =NULL ; - priv->tx_len =0 ; + priv->tx_busy = false; }/* Note about handling of error return of mcp251x_spi_trans: accessing
@@ -785,7 +786,7 @@ static netdev_tx_t mcp251x_hard_start_xmit(struct sk_buff *skb,struct mcp251x_priv *priv =netdev_priv (net);struct spi_device *spi = priv->spi; -if (priv->tx_skb || priv->tx_len) { +if (priv->tx_skb || priv->tx_busy) {dev_warn (&spi->dev,"hard_xmit called while tx busy\n" );return NETDEV_TX_BUSY ; }
@@ -1010,7 +1011,7 @@ static void mcp251x_tx_work_handler(struct work_struct *ws)if (frame->len >CAN_FRAME_MAX_DATA_LEN ) frame->len =CAN_FRAME_MAX_DATA_LEN ;mcp251x_hw_tx (spi, frame,0 ); - priv->tx_len =1 + frame->len; + priv->tx_busy = true;can_put_echo_skb (priv->tx_skb, net,0 ,0 ); priv->tx_skb =NULL ; }
@@ -1176,12 +1177,12 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)break ;if (intf &CANINTF_TX ) { - net->stats.tx_packets++; - net->stats.tx_bytes += priv->tx_len -1 ;can_led_event (net,CAN_LED_EVENT_TX ); -if (priv->tx_len) { -can_get_echo_skb (net,0 ,NULL ); - priv->tx_len =0 ; +if (priv->tx_busy) { + net->stats.tx_packets++; + net->stats.tx_bytes +=can_get_echo_skb (net,0 , +NULL ); + priv->tx_busy = false; }netif_wake_queue (net); }
@@ -1208,7 +1209,7 @@ static int mcp251x_open(struct net_device *net) priv->force_quit =0 ; priv->tx_skb =NULL ; - priv->tx_len =0 ; + priv->tx_busy = false;if (!dev_fwnode (&spi->dev)) flags =IRQF_TRIGGER_FALLING ;
drivers/net/can/sun4i_can.c +1 -4
@@ -661,11 +661,8 @@ static irqreturn_t sun4i_can_interrupt(int irq, void *dev_id)if (isrc &SUN4I_INT_TBUF_VLD ) {/* transmission complete interrupt */ - stats->tx_bytes += -readl (priv->base + -SUN4I_REG_RBUF_RBACK_START_ADDR ) &0xf ; + stats->tx_bytes +=can_get_echo_skb (dev,0 ,NULL ); stats->tx_packets++; -can_get_echo_skb (dev,0 ,NULL );netif_wake_queue (dev);can_led_event (dev,CAN_LED_EVENT_TX ); }
drivers/net/can/usb/ems_usb.c +2 -5
@@ -230,7 +230,6 @@ struct ems_tx_urb_context {struct ems_usb *dev;u32 echo_index; -u8 dlc; };struct ems_usb {
@@ -517,9 +516,8 @@ static void ems_usb_write_bulk_callback(struct urb *urb)/* transmission complete interrupt */ netdev->stats.tx_packets++; - netdev->stats.tx_bytes += context->dlc; - -can_get_echo_skb (netdev, context->echo_index,NULL ); + netdev->stats.tx_bytes +=can_get_echo_skb (netdev, context->echo_index, +NULL );/* Release context */ context->echo_index =MAX_TX_URBS ;
@@ -805,7 +803,6 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne context->dev = dev; context->echo_index = i; - context->dlc = cf->len;usb_fill_bulk_urb (urb, dev->udev,usb_sndbulkpipe (dev->udev,2 ), buf, size, ems_usb_write_bulk_callback, context);
drivers/net/can/usb/esd_usb2.c +2 -4
@@ -183,7 +183,6 @@ struct esd_usb2_net_priv;struct esd_tx_urb_context {struct esd_usb2_net_priv *priv;u32 echo_index; -int len;/* CAN payload length */ };struct esd_usb2 {
@@ -357,8 +356,8 @@ static void esd_usb2_tx_done_msg(struct esd_usb2_net_priv *priv,if (!msg->msg.txdone.status) { stats->tx_packets++; - stats->tx_bytes += context->len; -can_get_echo_skb (netdev, context->echo_index,NULL ); + stats->tx_bytes +=can_get_echo_skb (netdev, context->echo_index, +NULL ); }else { stats->tx_errors++;can_free_echo_skb (netdev, context->echo_index,NULL );
@@ -783,7 +782,6 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb, context->priv = priv; context->echo_index = i; - context->len = cf->len;/* hnd must not be 0 - MSB is stripped in txdone handling */ msg->msg.tx.hnd =0x80000000 | i;/* returned in TX done message */
drivers/net/can/usb/gs_usb.c +3 -4
@@ -357,9 +357,6 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) goto resubmit_urb; } - netdev->stats.tx_packets++; - netdev->stats.tx_bytes += hf->can_dlc; - txc =gs_get_tx_context (dev, hf->echo_id);/* bad devices send bad echo_ids. */
@@ -370,7 +367,9 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) goto resubmit_urb; } -can_get_echo_skb (netdev, hf->echo_id,NULL ); + netdev->stats.tx_packets++; + netdev->stats.tx_bytes +=can_get_echo_skb (netdev, hf->echo_id, +NULL );gs_free_tx_context (txc);
drivers/net/can/usb/kvaser_usb/kvaser_usb.h +2 -3
@@ -77,7 +77,6 @@ struct kvaser_usb_dev_card_data {struct kvaser_usb_tx_urb_context {struct kvaser_usb_net_priv *priv;u32 echo_index; -int dlc; };struct kvaser_usb {
@@ -162,8 +161,8 @@ struct kvaser_usb_dev_ops {void (*dev_read_bulk_callback)(struct kvaser_usb *dev,void *buf,int len);void *(*dev_frame_to_cmd)(const struct kvaser_usb_net_priv *priv, -const struct sk_buff *skb,int *frame_len, -int *cmd_len,u16 transid); +const struct sk_buff *skb,int *cmd_len, +u16 transid); };struct kvaser_usb_dev_cfg {
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +1 -1
@@ -565,7 +565,7 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb, goto freeurb; } - buf = dev->ops->dev_frame_to_cmd (priv, skb, &context->dlc, &cmd_len, + buf = dev->ops->dev_frame_to_cmd (priv, skb, &cmd_len, context->echo_index);if (!buf) { stats->tx_dropped++;
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +20 -22
103 lines not on this page · raw message
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +5 -8
@@ -389,16 +389,14 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_32mhz = {static void *kvaser_usb_leaf_frame_to_cmd (const struct kvaser_usb_net_priv *priv, -const struct sk_buff *skb,int *frame_len, -int *cmd_len,u16 transid) +const struct sk_buff *skb,int *cmd_len, +u16 transid) {struct kvaser_usb *dev = priv->dev;struct kvaser_cmd *cmd;u8 *cmd_tx_can_flags =NULL ;/* GCC */ struct can_frame *cf = (struct can_frame *)skb->data; - *frame_len = cf->len; - cmd =kmalloc (sizeof (*cmd),GFP_ATOMIC );if (cmd) { cmd->u.tx_can.tid = transid &0xff ;
@@ -654,12 +652,11 @@ static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev, priv->can.state =CAN_STATE_ERROR_ACTIVE ; } - stats->tx_packets++; - stats->tx_bytes += context->dlc; -spin_lock_irqsave (&priv->tx_contexts_lock, flags); -can_get_echo_skb (priv->netdev, context->echo_index,NULL ); + stats->tx_packets++; + stats->tx_bytes +=can_get_echo_skb (priv->netdev, + context->echo_index,NULL ); context->echo_index = dev->max_tx_urbs; --priv->active_tx_contexts;netif_wake_queue (priv->netdev);
drivers/net/can/usb/mcba_usb.c +4 -8
@@ -64,7 +64,6 @@struct mcba_usb_ctx {struct mcba_priv *priv;u32 ndx; -u8 dlc;bool can; };
@@ -184,13 +183,10 @@ static inline struct mcba_usb_ctx *mcba_usb_get_free_ctx(struct mcba_priv *priv, ctx = &priv->tx_context[i]; ctx->ndx = i; -if (cf) { +if (cf) ctx->can = true; - ctx->dlc = cf->len; - }else { +else ctx->can = false; - ctx->dlc =0 ; - }atomic_dec (&priv->free_ctx_cnt);break ;
@@ -236,10 +232,10 @@ static void mcba_usb_write_bulk_callback(struct urb *urb)return ; netdev->stats.tx_packets++; - netdev->stats.tx_bytes += ctx->dlc; + netdev->stats.tx_bytes +=can_get_echo_skb (netdev, ctx->ndx, +NULL );can_led_event (netdev,CAN_LED_EVENT_TX ); -can_get_echo_skb (netdev, ctx->ndx,NULL ); }if (urb->status)
drivers/net/can/usb/peak_usb/pcan_usb_core.c +9 -11
@@ -291,6 +291,7 @@ static void peak_usb_write_bulk_callback(struct urb *urb)struct peak_tx_urb_context *context = urb->context;struct peak_usb_device *dev;struct net_device *netdev; +int tx_bytes;BUG_ON (!context);
@@ -305,10 +306,6 @@ static void peak_usb_write_bulk_callback(struct urb *urb)/* check tx status */ switch (urb->status) {case 0 : -/* transmission complete */ - netdev->stats.tx_packets++; - netdev->stats.tx_bytes += context->data_len; -/* prevent tx timeout */ netif_trans_update (netdev);break ;
@@ -327,12 +324,17 @@ static void peak_usb_write_bulk_callback(struct urb *urb) }/* should always release echo skb and corresponding context */ -can_get_echo_skb (netdev, context->echo_index,NULL ); + tx_bytes =can_get_echo_skb (netdev, context->echo_index,NULL ); context->echo_index =PCAN_USB_MAX_TX_URBS ; -/* do wakeup tx queue in case of success only */ -if (!urb->status) +if (!urb->status) { +/* transmission complete */ + netdev->stats.tx_packets++; + netdev->stats.tx_bytes += tx_bytes; + +/* do wakeup tx queue in case of success only */ netif_wake_queue (netdev); + } }/*
@@ -344,7 +346,6 @@ static netdev_tx_t peak_usb_ndo_start_xmit(struct sk_buff *skb,struct peak_usb_device *dev =netdev_priv (netdev);struct peak_tx_urb_context *context =NULL ;struct net_device_stats *stats = &netdev->stats; -struct canfd_frame *cfd = (struct canfd_frame *)skb->data;struct urb *urb;u8 *obuf;int i, err;
@@ -378,9 +379,6 @@ static netdev_tx_t peak_usb_ndo_start_xmit(struct sk_buff *skb, context->echo_index = i; -/* Note: this works with CANFD frames too */ - context->data_len = cfd->len; -usb_anchor_urb (urb, &dev->tx_submitted);can_put_echo_skb (skb, netdev, context->echo_index,0 );
drivers/net/can/usb/peak_usb/pcan_usb_core.h +0 -1
@@ -99,7 +99,6 @@ struct peak_time_ref {struct peak_tx_urb_context {struct peak_usb_device *dev;u32 echo_index; -u8 data_len;struct urb *urb; };
drivers/net/can/usb/ucan.c +3 -7
@@ -259,7 +259,6 @@ struct ucan_priv;/* Context Information for transmission URBs */ struct ucan_urb_context {struct ucan_priv *up; -u8 dlc;bool allocated; };
@@ -637,7 +636,7 @@ static void ucan_tx_complete_msg(struct ucan_priv *up, {unsigned long flags;u16 count, i; -u8 echo_index, dlc; +u8 echo_index;u16 len =le16_to_cpu (m->len);struct ucan_urb_context *context;
@@ -661,7 +660,6 @@ static void ucan_tx_complete_msg(struct ucan_priv *up,/* gather information from the context */ context = &up->context_array[echo_index]; - dlc =READ_ONCE (context->dlc);/* Release context and restart queue if necessary. * Also check if the context was allocated
@@ -674,8 +672,8 @@ static void ucan_tx_complete_msg(struct ucan_priv *up, UCAN_TX_COMPLETE_SUCCESS) { /* update statistics */ up->netdev->stats.tx_packets++; - up->netdev->stats.tx_bytes += dlc; - can_get_echo_skb(up->netdev, echo_index, NULL); + up->netdev->stats.tx_bytes += + can_get_echo_skb(up->netdev, echo_index, NULL); } else { up->netdev->stats.tx_dropped++;can_free_echo_skb (up->netdev, echo_index,NULL );
@@ -1089,8 +1087,6 @@ static struct urb *ucan_prepare_tx_urb(struct ucan_priv *up, } m->len =cpu_to_le16 (mlen); - context->dlc = cf->len; - m->subtype = echo_index;/* build the urb */
drivers/net/can/usb/usb_8dev.c +1 -5
@@ -114,7 +114,6 @@ struct usb_8dev_tx_urb_context {struct usb_8dev_priv *priv;u32 echo_index; -u8 dlc; };/* Structure to hold all of our device specific stuff */
@@ -581,9 +580,7 @@ static void usb_8dev_write_bulk_callback(struct urb *urb) urb->status); netdev->stats.tx_packets++; - netdev->stats.tx_bytes += context->dlc; - -can_get_echo_skb (netdev, context->echo_index,NULL ); + netdev->stats.tx_bytes +=can_get_echo_skb (netdev, context->echo_index,NULL );can_led_event (netdev,CAN_LED_EVENT_TX );
@@ -654,7 +651,6 @@ static netdev_tx_t usb_8dev_start_xmit(struct sk_buff *skb, context->priv = priv; context->echo_index = i; - context->dlc = cf->len; usb_fill_bulk_urb(urb, priv->udev, usb_sndbulkpipe(priv->udev, USB_8DEV_ENDP_DATA_TX),
drivers/net/can/vcan.c +4 -3
@@ -87,13 +87,14 @@ static netdev_tx_t vcan_tx(struct sk_buff *skb, struct net_device *dev) {struct canfd_frame *cfd = (struct canfd_frame *)skb->data;struct net_device_stats *stats = &dev->stats; -int loop; +int loop, len;if (can_dropped_invalid_skb (dev, skb))return NETDEV_TX_OK ; + len = cfd->can_id &CAN_RTR_FLAG ?0 : cfd->len; stats->tx_packets++; - stats->tx_bytes += cfd->len; + stats->tx_bytes += len;/* set flag whether this packet has to be looped back */ loop = skb->pkt_type ==PACKET_LOOPBACK ;
@@ -105,7 +106,7 @@ static netdev_tx_t vcan_tx(struct sk_buff *skb, struct net_device *dev)* CAN core already did the echo for us */ stats->rx_packets++; - stats->rx_bytes += cfd->len; + stats->rx_bytes += len; }consume_skb (skb);return NETDEV_TX_OK ;
drivers/net/can/vxcan.c +1 -1
@@ -62,7 +62,7 @@ static netdev_tx_t vxcan_xmit(struct sk_buff *skb, struct net_device *dev) skb->dev = peer; skb->ip_summed =CHECKSUM_UNNECESSARY ; - len = cfd->len; + len = cfd->can_id &CAN_RTR_FLAG ?0 : cfd->len;if (netif_rx_ni (skb) ==NET_RX_SUCCESS ) { srcstats->tx_packets++; srcstats->tx_bytes += len;
include/linux/can/skb.h +3 -2
@@ -21,8 +21,9 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, unsigned int idx, unsigned int frame_len);struct sk_buff *__can_get_echo_skb (struct net_device *dev,unsigned int idx,u8 *len_ptr,unsigned int *frame_len_ptr); -unsigned int can_get_echo_skb (struct net_device *dev,unsigned int idx, -unsigned int *frame_len_ptr); +unsigned int __must_check can_get_echo_skb (struct net_device *dev, +unsigned int idx, +unsigned int *frame_len_ptr);void can_free_echo_skb (struct net_device *dev,unsigned int idx,unsigned int *frame_len_ptr);struct sk_buff *alloc_can_skb (struct net_device *dev,struct can_frame **cf);
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 12/15 can: dev: replace can_priv::ctrlmode_static by can_get_static_ctrlmode()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
The statically enabled features of a CAN controller can be retrieved using below formula:
| u32 ctrlmode_static = priv->ctrlmode & ~priv->ctrlmode_supported;
As such, there is no need to store this information. This patch remove the field ctrlmode_static of struct can_priv and provides, in replacement, the inline function can_get_static_ctrlmode() which returns the same value.
--- drivers/net/can/dev/dev.c | 5 +++-- drivers/net/can/dev/netlink.c | 2 +- include/linux/can/dev.h | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-)
drivers/net/can/dev/dev.c +3 -2
@@ -296,6 +296,7 @@ EXPORT_SYMBOL_GPL(free_candev);int can_change_mtu (struct net_device *dev,int new_mtu) {struct can_priv *priv =netdev_priv (dev); +u32 ctrlmode_static =can_get_static_ctrlmode (priv);/* Do not allow changing the MTU while running */ if (dev->flags &IFF_UP )
@@ -305,7 +306,7 @@ int can_change_mtu(struct net_device *dev, int new_mtu)switch (new_mtu) {case CAN_MTU :/* 'CANFD-only' controllers can not switch to CAN_MTU */ -if (priv->ctrlmode_static &CAN_CTRLMODE_FD ) +if (ctrlmode_static &CAN_CTRLMODE_FD )return -EINVAL ; priv->ctrlmode &= ~CAN_CTRLMODE_FD ;
@@ -314,7 +315,7 @@ int can_change_mtu(struct net_device *dev, int new_mtu)case CANFD_MTU :/* check for potential CANFD ability */ if (!(priv->ctrlmode_supported &CAN_CTRLMODE_FD ) && - !(priv->ctrlmode_static &CAN_CTRLMODE_FD )) + !(ctrlmode_static &CAN_CTRLMODE_FD ))return -EINVAL ; priv->ctrlmode |=CAN_CTRLMODE_FD ;
drivers/net/can/dev/netlink.c +1 -1
@@ -211,7 +211,7 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],if (dev->flags &IFF_UP )return -EBUSY ; cm =nla_data (data[IFLA_CAN_CTRLMODE ]); - ctrlstatic = priv->ctrlmode_static; + ctrlstatic =can_get_static_ctrlmode (priv); maskedflags = cm->flags & cm->mask;/* check whether provided bits are allowed to be passed */
include/linux/can/dev.h +5 -2
@@ -69,7 +69,6 @@ struct can_priv {/* CAN controller features - see include/uapi/linux/can/netlink.h */ u32 ctrlmode;/* current options setting */ u32 ctrlmode_supported;/* options that can be modified by netlink */ -u32 ctrlmode_static;/* static enabled options for driver/hardware */ int restart_ms;struct delayed_work restart_work;
@@ -139,13 +138,17 @@ static inline void can_set_static_ctrlmode(struct net_device *dev,/* alloc_candev() succeeded => netdev_priv() is valid at this point */ priv->ctrlmode = static_mode; - priv->ctrlmode_static = static_mode;/* override MTU which was set by default in can_setup()? */ if (static_mode &CAN_CTRLMODE_FD ) dev->mtu =CANFD_MTU ; } +static inline u32 can_get_static_ctrlmode (struct can_priv *priv) +{ +return priv->ctrlmode & ~priv->ctrlmode_supported; +} +void can_setup (struct net_device *dev); struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 13/15 can: dev: add sanity check in can_set_static_ctrlmode()
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Previous patch removed can_priv::ctrlmode_static to replace it with can_get_static_ctrlmode().
A condition sine qua non for this to work is that the controller static modes should never be set in can_priv::ctrlmode_supported (c.f. the comment on can_priv::ctrlmode_supported which states that it is for "options that can be *modified* by netlink"). Also, this condition is already correctly fulfilled by all existing drivers which rely on the ctrlmode_static feature.
Nonetheless, we added an extra safeguard in can_set_static_ctrlmode() to return an error value and to warn the developer who would be adventurous enough to set to static a given feature that is already set to supported.
The drivers which rely on the static controller mode are then updated to check the return value of can_set_static_ctrlmode().
--- drivers/net/can/m_can/m_can.c | 10 +++++++--- drivers/net/can/rcar/rcar_canfd.c | 4 +++- include/linux/can/dev.h | 11 +++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-)
drivers/net/can/m_can/m_can.c +7 -3
@@ -1456,7 +1456,7 @@ static bool m_can_niso_supported(struct m_can_classdev *cdev)static int m_can_dev_setup (struct m_can_classdev *cdev) {struct net_device *dev = cdev->net; -int m_can_version; +int m_can_version, err; m_can_version =m_can_check_core_release (cdev);/* return if unsupported version */
@@ -1486,7 +1486,9 @@ static int m_can_dev_setup(struct m_can_classdev *cdev)switch (cdev->version) {case 30 :/* CAN_CTRLMODE_FD_NON_ISO is fixed with M_CAN IP v3.0.x */ -can_set_static_ctrlmode (dev,CAN_CTRLMODE_FD_NON_ISO ); + err =can_set_static_ctrlmode (dev,CAN_CTRLMODE_FD_NON_ISO ); +if (err) +return err; cdev->can.bittiming_const = cdev->bit_timing ? cdev->bit_timing : &m_can_bittiming_const_30X;
@@ -1496,7 +1498,9 @@ static int m_can_dev_setup(struct m_can_classdev *cdev)break ;case 31 :/* CAN_CTRLMODE_FD_NON_ISO is fixed with M_CAN IP v3.1.x */ -can_set_static_ctrlmode (dev,CAN_CTRLMODE_FD_NON_ISO ); + err =can_set_static_ctrlmode (dev,CAN_CTRLMODE_FD_NON_ISO ); +if (err) +return err; cdev->can.bittiming_const = cdev->bit_timing ? cdev->bit_timing : &m_can_bittiming_const_31X;
drivers/net/can/rcar/rcar_canfd.c +3 -1
@@ -1699,7 +1699,9 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, &rcar_canfd_data_bittiming_const;/* Controller starts in CAN FD only mode */ -can_set_static_ctrlmode (ndev,CAN_CTRLMODE_FD ); + err =can_set_static_ctrlmode (ndev,CAN_CTRLMODE_FD ); +if (err) + goto fail; priv->can.ctrlmode_supported =CAN_CTRLMODE_BERR_REPORTING ; }else {/* Controller starts in Classical CAN only mode */
include/linux/can/dev.h +9 -2
@@ -131,17 +131,24 @@ static inline s32 can_get_relative_tdco(const struct can_priv *priv) }/* helper to define static CAN controller features at device creation time */ -static inline void can_set_static_ctrlmode (struct net_device *dev, -u32 static_mode) +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)
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 14/15 can: dev: reorder struct can_priv members for better packing
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Save eight bytes of holes on x86-64 architectures by reordering the members of struct can_priv.
Before:
| $ pahole -C can_priv drivers/net/can/dev/dev.o
| struct can_priv {
| struct net_device * dev; /* 0 8 */
| struct can_device_stats can_stats; /* 8 24 */
| const struct can_bittiming_const * bittiming_const; /* 32 8 */
| const struct can_bittiming_const * data_bittiming_const; /* 40 8 */
| struct can_bittiming bittiming; /* 48 32 */
| /* --- cacheline 1 boundary (64 bytes) was 16 bytes ago --- */
| struct can_bittiming data_bittiming; /* 80 32 */
| const struct can_tdc_const * tdc_const; /* 112 8 */
| struct can_tdc tdc; /* 120 12 */
| /* --- cacheline 2 boundary (128 bytes) was 4 bytes ago --- */
| unsigned int bitrate_const_cnt; /* 132 4 */
| const u32 * bitrate_const; /* 136 8 */
| const u32 * data_bitrate_const; /* 144 8 */
| unsigned int data_bitrate_const_cnt; /* 152 4 */
| u32 bitrate_max; /* 156 4 */
| struct can_clock clock; /* 160 4 */
| unsigned int termination_const_cnt; /* 164 4 */
| const u16 * termination_const; /* 168 8 */
| u16 termination; /* 176 2 */
|
| /* XXX 6 bytes hole, try to pack */
|
| struct gpio_desc * termination_gpio; /* 184 8 */
| /* --- cacheline 3 boundary (192 bytes) --- */
| u16 termination_gpio_ohms[2]; /* 192 4 */
| enum can_state state; /* 196 4 */
| u32 ctrlmode; /* 200 4 */
| u32 ctrlmode_supported; /* 204 4 */
| int restart_ms; /* 208 4 */
|
| /* XXX 4 bytes hole, try to pack */
|
| struct delayed_work restart_work; /* 216 88 */
|
| /* XXX last struct has 4 bytes of padding */
|
| /* --- cacheline 4 boundary (256 bytes) was 48 bytes ago --- */
| int (*do_set_bittiming)(struct net_device *); /* 304 8 */
| int (*do_set_data_bittiming)(struct net_device *); /* 312 8 */
| /* --- cacheline 5 boundary (320 bytes) --- */
| int (*do_set_mode)(struct net_device *, enum can_mode); /* 320 8 */
| int (*do_set_termination)(struct net_device *, u16); /* 328 8 */
| int (*do_get_state)(const struct net_device *, enum can_state *); /* 336 8 */
| int (*do_get_berr_counter)(const struct net_device *, struct can_berr_counter *); /* 344 8 */
| unsigned int echo_skb_max; /* 352 4 */
|
| /* XXX 4 bytes hole, try to pack */
|
| struct sk_buff * * echo_skb; /* 360 8 */
|
| /* size: 368, cachelines: 6, members: 32 */
| /* sum members: 354, holes: 3, sum holes: 14 */
| /* paddings: 1, sum paddings: 4 */
| /* last cacheline: 48 bytes */
| };After:
| $ pahole -C can_priv drivers/net/can/dev/dev.o
| struct can_priv {
| struct net_device * dev; /* 0 8 */
| struct can_device_stats can_stats; /* 8 24 */
| const struct can_bittiming_const * bittiming_const; /* 32 8 */
| const struct can_bittiming_const * data_bittiming_const; /* 40 8 */
| struct can_bittiming bittiming; /* 48 32 */
| /* --- cacheline 1 boundary (64 bytes) was 16 bytes ago --- */
| struct can_bittiming data_bittiming; /* 80 32 */
| const struct can_tdc_const * tdc_const; /* 112 8 */
| struct can_tdc tdc; /* 120 12 */
| /* --- cacheline 2 boundary (128 bytes) was 4 bytes ago --- */
| unsigned int bitrate_const_cnt; /* 132 4 */
| const u32 * bitrate_const; /* 136 8 */
| const u32 * data_bitrate_const; /* 144 8 */
| unsigned int data_bitrate_const_cnt; /* 152 4 */
| u32 bitrate_max; /* 156 4 */
| struct can_clock clock; /* 160 4 */
| unsigned int termination_const_cnt; /* 164 4 */
| const u16 * termination_const; /* 168 8 */
| u16 termination; /* 176 2 */
|
| /* XXX 6 bytes hole, try to pack */
|
| struct gpio_desc * termination_gpio; /* 184 8 */
| /* --- cacheline 3 boundary (192 bytes) --- */
| u16 termination_gpio_ohms[2]; /* 192 4 */
| unsigned int echo_skb_max; /* 196 4 */
| struct sk_buff * * echo_skb; /* 200 8 */
| enum can_state state; /* 208 4 */
| u32 ctrlmode; /* 212 4 */
| u32 ctrlmode_supported; /* 216 4 */
| int restart_ms; /* 220 4 */
| struct delayed_work restart_work; /* 224 88 */
|
| /* XXX last struct has 4 bytes of padding */
|
| /* --- cacheline 4 boundary (256 bytes) was 56 bytes ago --- */
| int (*do_set_bittiming)(struct net_device *); /* 312 8 */
| /* --- cacheline 5 boundary (320 bytes) --- */
| int (*do_set_data_bittiming)(struct net_device *); /* 320 8 */
| int (*do_set_mode)(struct net_device *, enum can_mode); /* 328 8 */
| int (*do_set_termination)(struct net_device *, u16); /* 336 8 */
| int (*do_get_state)(const struct net_device *, enum can_state *); /* 344 8 */
| int (*do_get_berr_counter)(const struct net_device *, struct can_berr_counter *); /* 352 8 */
|
| /* size: 360, cachelines: 6, members: 32 */
| /* sum members: 354, holes: 1, sum holes: 6 */
| /* paddings: 1, sum paddings: 4 */
| /* last cacheline: 40 bytes */
| };--- include/linux/can/dev.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/can/dev.h +3 -3
@@ -64,6 +64,9 @@ struct can_priv {struct gpio_desc *termination_gpio;u16 termination_gpio_ohms[CAN_TERMINATION_GPIO_MAX ]; +unsigned int echo_skb_max; +struct sk_buff **echo_skb; +enum can_state state;/* CAN controller features - see include/uapi/linux/can/netlink.h */
@@ -83,9 +86,6 @@ struct can_priv { struct can_berr_counter *bec);int (*do_get_auto_tdcv)(const struct net_device *dev,u32 *tdcv); -unsigned int echo_skb_max; -struct sk_buff **echo_skb; -#ifdef CONFIG_CAN_LEDS struct led_trigger *tx_led_trig;char tx_led_trig_name[CAN_LED_NAME_SZ ];
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH 15/15 can: netlink: report the CAN controller mode supported flags
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Currently, the CAN netlink interface provides no easy ways to check the capabilities of a given controller. The only method from the command line is to try each CAN_CTRLMODE_* individually to check whether the netlink interface returns an -EOPNOTSUPP error or not (alternatively, one may find it easier to directly check the source code of the driver instead...)
This patch introduces a method for the user to check both the supported and the static capabilities. The proposed method introduces a new IFLA nest: IFLA_CAN_CTRLMODE_EXT which extends the current IFLA_CAN_CTRLMODE. This is done to guaranty a full forward and backward compatibility between the kernel and the user land applications.
The IFLA_CAN_CTRLMODE_EXT nest contains one single entry:IFLA_CAN_CTRLMODE_SUPPORTED. Because this entry is only used in one
direction: kernel to userland, no new struct nla_policy are introduced.
Below table explains how IFLA_CAN_CTRLMODE_SUPPORTED (hereafter:
"supported") and can_ctrlmode::flags (hereafter: "flags") allow us to identify both the supported and the static capabilities, when masked with any of the CAN_CTRLMODE_* bit flags:
supported & flags & Controller capabilities
CAN_CTRLMODE_* CAN_CTRLMODE_*
-----------------------------------------------------------------------
false false Feature not supported (always disabled)
false true Static feature (always enabled)
true false Feature supported but disabled
true true Feature supported and enabled
--- drivers/net/can/dev/netlink.c | 31 ++++++++++++++++++++++++++++++- include/uapi/linux/can/netlink.h | 13 +++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-)
drivers/net/can/dev/netlink.c +30 -1
@@ -21,6 +21,7 @@ static const struct nla_policy can_policy[IFLA_CAN_MAX + 1] = { [IFLA_CAN_DATA_BITTIMING_CONST] = { .len = sizeof(struct can_bittiming_const) }, [IFLA_CAN_TERMINATION] = { .type = NLA_U16 }, [IFLA_CAN_TDC] = { .type = NLA_NESTED }, + [IFLA_CAN_CTRLMODE_EXT] = { .type = NLA_NESTED }, };static const struct nla_policy can_tdc_policy[IFLA_CAN_TDC_MAX +1 ] = {
@@ -383,6 +384,12 @@ static size_t can_tdc_get_size(const struct net_device *dev)return size; } +static size_t can_ctrlmode_ext_get_size (void ) +{ +return nla_total_size (0 ) +/* nest IFLA_CAN_CTRLMODE_EXT */ +nla_total_size (sizeof (u32));/* IFLA_CAN_CTRLMODE_SUPPORTED */ +} +static size_t can_get_size (const struct net_device *dev) {struct can_priv *priv =netdev_priv (dev);
@@ -415,6 +422,7 @@ static size_t can_get_size(const struct net_device *dev) priv->data_bitrate_const_cnt); size +=sizeof (priv->bitrate_max);/* IFLA_CAN_BITRATE_MAX */ size +=can_tdc_get_size (dev);/* IFLA_CAN_TDC */ + size +=can_ctrlmode_ext_get_size ();/* IFLA_CAN_CTRLMODE_EXT */ return size; }
@@ -472,6 +480,25 @@ static int can_tdc_fill_info(struct sk_buff *skb, const struct net_device *dev)return -EMSGSIZE ; } +static int can_ctrlmode_ext_fill_info (struct sk_buff *skb, +const struct can_priv *priv) +{ +struct nlattr *nest; + + nest =nla_nest_start (skb,IFLA_CAN_CTRLMODE_EXT ); +if (!nest) +return -EMSGSIZE ; + +if (nla_put_u32 (skb,IFLA_CAN_CTRLMODE_SUPPORTED , + priv->ctrlmode_supported)) { +nla_nest_cancel (skb, nest); +return -EMSGSIZE ; + } + +nla_nest_end (skb, nest); +return 0 ; +} +static int can_fill_info (struct sk_buff *skb,const struct net_device *dev) {struct can_priv *priv =netdev_priv (dev);
@@ -531,7 +558,9 @@ 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) || + + can_ctrlmode_ext_fill_info(skb, priv) )return -EMSGSIZE ;
include/uapi/linux/can/netlink.h +13 -0
@@ -137,6 +137,7 @@ enum {IFLA_CAN_DATA_BITRATE_CONST ,IFLA_CAN_BITRATE_MAX ,IFLA_CAN_TDC , +IFLA_CAN_CTRLMODE_EXT ,/* add new constants above here */ __IFLA_CAN_MAX,
@@ -166,6 +167,18 @@ enum { IFLA_CAN_TDC_MAX = __IFLA_CAN_TDC - 1 }; +/* +* IFLA_CAN_CTRLMODE_EXT nest: controller mode extended parameters +*/ +enum { +IFLA_CAN_CTRLMODE_UNSPEC , +IFLA_CAN_CTRLMODE_SUPPORTED ,/* u32 */ + +/* add new constants above here */ + __IFLA_CAN_CTRLMODE, +IFLA_CAN_CTRLMODE_MAX = __IFLA_CAN_CTRLMODE -1 +}; +/* u16 termination range: 1..65535 Ohms */ #define CAN_TERMINATION_DISABLED 0
Signature · 1 line
2.34.1