pull-request: can-next 2021-03-30
Subsystems (10)
Marc Kleine-Budde
maintainerHello Jakub, hello David,
this is a pull request of 39 patches for net-next/master.
The first two patches update the MAINTAINERS file. One is by me and removes Dan Murphy from the from m_can and tcan4x5x. The other one is by Pankaj Sharma and updates the maintainership of the m-can mmio driver.
The next three patches are by me and update the CAN echo skb handling.
Vincent Mailhol provides 5 patches where Transmitter Delay Compensation is added CAN bittiming calculation is cleaned up.
The next patch is by me and adds a missing HAS_IOMEM to the grcan driver.
Michal Simek's patch for the xilinx driver add dev_err_probe() support.
Arnd Bergmann's patch for the ucan driver fixes a compiler warning.
Stephane Grosjean provides 3 patches for the peak USB drivers, which add ethtool set_phys_id and CAN one-shot mode.
Xulin Sun's patch removes a not needed return check in the m-can driver. Torin Cooper-Bennun provides 3 patches for the m-can driver that add rx-offload support to ensure that skbs are sent from softirq context. Wan Jiabing's patch for the tcan4x5x driver removes a duplicate include.
The next 6 patches are by me and target the mcp251xfd driver. They add devcoredump support, simplify the UINC handling, and add HW timestamp support.
The remaining 12 patches target the c_can driver. The first 6 are by me and do generic checkpatch related cleanup work. Dario Binacchi's patches bring some cleanups and increase the number of usable message objects from 16 to 64.
regards,
Marc
---
The following changes since commit d0922bf7981799fd86e248de330fb4152399d6c2:
hv_netvsc: Add error handling while switching data path (2021-03-29 16:35:59 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git tags/linux-can-next-for-5.13-20210330
for you to fetch changes up to 132f2d45fb2302a582aef617ea766f3fa52a084c:
can: c_can: add support to 64 message objects (2021-03-30 11:14:53 +0200)
----------------------------------------------------------------
linux-can-next-for-5.13-20210330
----------------------------------------------------------------
Arnd Bergmann (1):
can: ucan: fix alignment constraints
Dario Binacchi (6):
can: c_can: remove unused code
can: c_can: fix indentation
can: c_can: add a comment about IF_RX interface's use
can: c_can: use 32-bit write to set arbitration register
can: c_can: prepare to up the message objects number
can: c_can: add support to 64 message objects
Marc Kleine-Budde (17):
MAINTAINERS: remove Dan Murphy from m_can and tcan4x5x
can: dev: always create TX echo skb
can: dev: can_free_echo_skb(): don't crash the kernel if can_priv::echo_skb is accessed out of bounds
can: dev: can_free_echo_skb(): extend to return can frame length
can: grcan: add missing Kconfig dependency to HAS_IOMEM
can: mcp251xfd: add dev coredump support
can: mcp251xfd: simplify UINC handling
can: mcp251xfd: move netdevice.h to mcp251xfd.h
can: mcp251xfd: mcp251xfd_get_timestamp(): move to mcp251xfd.h
can: mcp251xfd: add HW timestamp infrastructure
can: mcp251xfd: add HW timestamp to RX, TX and error CAN frames
can: c_can: convert block comments to network style comments
can: c_can: remove unnecessary blank lines and add suggested ones
can: c_can: fix indention
can: c_can: fix print formating string
can: c_can: replace double assignments by two single ones
can: c_can: fix remaining checkpatch warnings
Michal Simek (1):
can: xilinx_can: Simplify code by using dev_err_probe()
Pankaj Sharma (1):
MAINTAINERS: Update MCAN MMIO device driver maintainer
Stephane Grosjean (3):
can: peak_usb: pcan_usb_pro_encode_msg(): use macros for flags instead of plain integers
can: peak_usb: add support of ethtool set_phys_id()
can: peak_usb: add support of ONE_SHOT mode
Torin Cooper-Bennun (3):
can: m_can: add infrastructure for internal timestamps
can: m_can: m_can_chip_config(): enable and configure internal timestamps
can: m_can: fix periph RX path: use rx-offload to ensure skbs are sent from softirq context
Vincent Mailhol (5):
can: add new CAN FD bittiming parameters: Transmitter Delay Compensation (TDC)
can: dev: reorder struct can_priv members for better packing
can: netlink: move '=' operators back to previous line (checkpatch fix)
can: bittiming: add calculation for CAN FD Transmitter Delay Compensation (TDC)
can: bittiming: add CAN_KBPS, CAN_MBPS and CAN_MHZ macros
Wan Jiabing (1):
can: tcan4x5x: remove duplicate include of regmap.h
Xulin Sun (1):
can: m_can: m_can_class_allocate_dev(): remove impossible error return judgment
MAINTAINERS | 10 +- drivers/net/can/Kconfig | 2 +- drivers/net/can/c_can/c_can.c | 153 +++++------ drivers/net/can/c_can/c_can.h | 42 ++- drivers/net/can/c_can/c_can_pci.c | 31 ++- drivers/net/can/c_can/c_can_platform.c | 6 +- drivers/net/can/dev/bittiming.c | 28 +- drivers/net/can/dev/netlink.c | 27 +- drivers/net/can/dev/skb.c | 27 +- drivers/net/can/grcan.c | 2 +- drivers/net/can/m_can/m_can.c | 160 ++++++++++-- drivers/net/can/m_can/m_can.h | 2 + drivers/net/can/m_can/tcan4x5x.h | 1 - drivers/net/can/rcar/rcar_can.c | 2 +- drivers/net/can/rcar/rcar_canfd.c | 2 +- drivers/net/can/sja1000/sja1000.c | 2 +- drivers/net/can/spi/hi311x.c | 2 +- drivers/net/can/spi/mcp251x.c | 2 +- drivers/net/can/spi/mcp251xfd/Kconfig | 1 + drivers/net/can/spi/mcp251xfd/Makefile | 3 + drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 104 ++++---- drivers/net/can/spi/mcp251xfd/mcp251xfd-dump.c | 285 +++++++++++++++++++++ drivers/net/can/spi/mcp251xfd/mcp251xfd-dump.h | 45 ++++ .../net/can/spi/mcp251xfd/mcp251xfd-timestamp.c | 71 +++++ drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 28 ++ drivers/net/can/usb/ems_usb.c | 2 +- drivers/net/can/usb/esd_usb2.c | 4 +- drivers/net/can/usb/gs_usb.c | 2 +- drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 2 +- drivers/net/can/usb/mcba_usb.c | 2 +- drivers/net/can/usb/peak_usb/pcan_usb.c | 47 ++++ drivers/net/can/usb/peak_usb/pcan_usb_core.c | 6 +- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 2 + drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 46 +++- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 46 +++- drivers/net/can/usb/peak_usb/pcan_usb_pro.h | 6 + drivers/net/can/usb/ucan.c | 8 +- drivers/net/can/usb/usb_8dev.c | 2 +- drivers/net/can/xilinx_can.c | 10 +- include/linux/can/bittiming.h | 79 ++++++ include/linux/can/dev.h | 14 +- include/linux/can/skb.h | 3 +- 42 files changed, 1068 insertions(+), 251 deletions(-) create mode 100644 drivers/net/can/spi/mcp251xfd/mcp251xfd-dump.c create mode 100644 drivers/net/can/spi/mcp251xfd/mcp251xfd-dump.h create mode 100644 drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c
Marc Kleine-Budde
maintainerPATCH 1/39 MAINTAINERS: remove Dan Murphy from m_can and tcan4x5x
Dan Murphy's email address at ti.com doesn't work anymore, mails bounce with:
| 550 Invalid recipient <[email protected]> (#5.1.1)
For now remove all CAN related entries of Dan from the Maintainers file.
--- MAINTAINERS | 8 -------- 1 file changed, 8 deletions(-)
MAINTAINERS +0 -8
@@ -10910,7 +10910,6 @@ T: git git://linuxtv.org/media_tree.git F: drivers/media/radio/radio-maxiradio* MCAN MMIO DEVICE DRIVER -M: Dan Murphy <[email protected]> M: Pankaj Sharma <[email protected]> L: [email protected] S: Maintained
@@ -17983,13 +17982,6 @@ L: [email protected] (moderated for non-subscribers) S: Odd Fixes F: sound/soc/codecs/tas571x* -TI TCAN4X5X DEVICE DRIVER -M: Dan Murphy <[email protected]> -L: [email protected] -S: Maintained -F: Documentation/devicetree/bindings/net/can/tcan4x5x.txt -F: drivers/net/can/m_can/tcan4x5x* - TI TRF7970A NFC DRIVER M: Mark Greer <[email protected]> L: [email protected]
base-commit: d0922bf7981799fd86e248de330fb4152399d6c2
Signature · 1 line
2.30.2
Re: [net-next 01/39] MAINTAINERS: remove Dan Murphy from m_can and tcan4x5x
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 9 lines · On Tue, 30 Mar 2021 13:45:21 +0200 you wrote:
Dan Murphy's email address at ti.com doesn't work anymore, mails bounce with:
| 550 Invalid recipient <[email protected]> (#5.1.1)
For now remove all CAN related entries of Dan from the Maintainers file.
[...]
Here is the summary with links:
- [net-next,01/39] MAINTAINERS: remove Dan Murphy from m_can and tcan4x5x
https://git.kernel.org/netdev/net-next/c/8560b0e7633b - [net-next,02/39] MAINTAINERS: Update MCAN MMIO device driver maintainer https://git.kernel.org/netdev/net-next/c/ba23dc6dcab5 - [net-next,03/39] can: dev: always create TX echo skb https://git.kernel.org/netdev/net-next/c/7119d7864bc5 - [net-next,04/39] can: dev: can_free_echo_skb(): don't crash the kernel if can_priv::echo_skb is accessed out of bounds https://git.kernel.org/netdev/net-next/c/4168d079aa41 - [net-next,05/39] can: dev: can_free_echo_skb(): extend to return can frame length https://git.kernel.org/netdev/net-next/c/f318482a1c57 - [net-next,06/39] can: add new CAN FD bittiming parameters: Transmitter Delay Compensation (TDC) https://git.kernel.org/netdev/net-next/c/289ea9e4ae59 - [net-next,07/39] can: dev: reorder struct can_priv members for better packing https://git.kernel.org/netdev/net-next/c/4c9258dd26fd - [net-next,08/39] can: netlink: move '=' operators back to previous line (checkpatch fix) https://git.kernel.org/netdev/net-next/c/cfd98c838cbe - [net-next,09/39] can: bittiming: add calculation for CAN FD Transmitter Delay Compensation (TDC) https://git.kernel.org/netdev/net-next/c/c25cc7993243 - [net-next,10/39] can: bittiming: add CAN_KBPS, CAN_MBPS and CAN_MHZ macros https://git.kernel.org/netdev/net-next/c/1d7750760b70 - [net-next,11/39] can: grcan: add missing Kconfig dependency to HAS_IOMEM https://git.kernel.org/netdev/net-next/c/51894cbae49e - [net-next,12/39] can: xilinx_can: Simplify code by using dev_err_probe() https://git.kernel.org/netdev/net-next/c/a3497afbe926 - [net-next,13/39] can: ucan: fix alignment constraints https://git.kernel.org/netdev/net-next/c/27868a8fc1d0 - [net-next,14/39] can: peak_usb: pcan_usb_pro_encode_msg(): use macros for flags instead of plain integers https://git.kernel.org/netdev/net-next/c/cfe2a4ca1e06 - [net-next,15/39] can: peak_usb: add support of ethtool set_phys_id() https://git.kernel.org/netdev/net-next/c/a7e8511ffda6 - [net-next,16/39] can: peak_usb: add support of ONE_SHOT mode https://git.kernel.org/netdev/net-next/c/58b29aa9d471 - [net-next,17/39] can: m_can: m_can_class_allocate_dev(): remove impossible error return judgment https://git.kernel.org/netdev/net-next/c/8fa12201b652 - [net-next,18/39] can: m_can: add infrastructure for internal timestamps https://git.kernel.org/netdev/net-next/c/17447f08202d - [net-next,19/39] can: m_can: m_can_chip_config(): enable and configure internal timestamps https://git.kernel.org/netdev/net-next/c/df06fd678260 - [net-next,20/39] can: m_can: fix periph RX path: use rx-offload to ensure skbs are sent from softirq context https://git.kernel.org/netdev/net-next/c/1be37d3b0414 - [net-next,21/39] can: tcan4x5x: remove duplicate include of regmap.h https://git.kernel.org/netdev/net-next/c/6c23fe67e8dc - [net-next,22/39] can: mcp251xfd: add dev coredump support https://git.kernel.org/netdev/net-next/c/e0ab3dd5f98f - [net-next,23/39] can: mcp251xfd: simplify UINC handling https://git.kernel.org/netdev/net-next/c/eb94b74ccda6 - [net-next,24/39] can: mcp251xfd: move netdevice.h to mcp251xfd.h https://git.kernel.org/netdev/net-next/c/ae2e99401120 - [net-next,25/39] can: mcp251xfd: mcp251xfd_get_timestamp(): move to mcp251xfd.h https://git.kernel.org/netdev/net-next/c/dc09e7e37152 - [net-next,26/39] can: mcp251xfd: add HW timestamp infrastructure https://git.kernel.org/netdev/net-next/c/efd8d98dfb90 - [net-next,27/39] can: mcp251xfd: add HW timestamp to RX, TX and error CAN frames https://git.kernel.org/netdev/net-next/c/5f02a49c6605 - [net-next,28/39] can: c_can: convert block comments to network style comments https://git.kernel.org/netdev/net-next/c/172f6d3a031b - [net-next,29/39] can: c_can: remove unnecessary blank lines and add suggested ones https://git.kernel.org/netdev/net-next/c/beb7e88a2650 - [net-next,30/39] can: c_can: fix indention https://git.kernel.org/netdev/net-next/c/2de0ea97ade0 - [net-next,31/39] can: c_can: fix print formating string https://git.kernel.org/netdev/net-next/c/0c1b0138d641 - [net-next,32/39] can: c_can: replace double assignments by two single ones https://git.kernel.org/netdev/net-next/c/995380f3fbfb - [net-next,33/39] can: c_can: fix remaining checkpatch warnings https://git.kernel.org/netdev/net-next/c/dd477500c70b - [net-next,34/39] can: c_can: remove unused code https://git.kernel.org/netdev/net-next/c/f65735c203d5 - [net-next,35/39] can: c_can: fix indentation https://git.kernel.org/netdev/net-next/c/c8a6b44388cb - [net-next,36/39] can: c_can: add a comment about IF_RX interface's use https://git.kernel.org/netdev/net-next/c/eddf67115040 - [net-next,37/39] can: c_can: use 32-bit write to set arbitration register https://git.kernel.org/netdev/net-next/c/fcbded019855 - [net-next,38/39] can: c_can: prepare to up the message objects number https://git.kernel.org/netdev/net-next/c/13831ce69c77 - [net-next,39/39] can: c_can: add support to 64 message objects https://git.kernel.org/netdev/net-next/c/132f2d45fb23
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Marc Kleine-Budde
maintainerPATCH 2/39 MAINTAINERS: Update MCAN MMIO device driver maintainer
In reply to Marc Kleine-BuddeFrom: Pankaj Sharma <[email protected]>
Update Chandrasekar Ramakrishnan as maintainer for mcan mmio device driver as I will be moving to a different role.
--- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
MAINTAINERS +1 -1
@@ -10910,7 +10910,7 @@ T: git git://linuxtv.org/media_tree.git F: drivers/media/radio/radio-maxiradio* MCAN MMIO DEVICE DRIVER -M: Pankaj Sharma <[email protected]> +M: Chandrasekar Ramakrishnan <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/can/bosch,m_can.yaml
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 3/39 can: dev: always create TX echo skb
In reply to Marc Kleine-BuddeSo far the creation of the TX echo skb was optional and can be controlled by the local sender of a CAN frame.
It turns out that the TX echo CAN skb can be piggybacked to carry information in the driver from the TX- to the TX-complete handler.
Several drivers already use the return value of can_get_echo_skb() (which is the length of the data field in the CAN frame) for their number of transferred bytes statistics. The statistics are not working if CAN echo skbs are disabled.
Another use case is to calculate and set the CAN frame length on the wire, which is needed for BQL support in both the TX and TX-completion handler.
For now in can_put_echo_skb(), which is called from the TX handler, the skb carrying the CAN frame is discarded if no TX echo is requested, leading to the above illustrated problems.
This patch changes the can_put_echo_skb() function, so that the echo skb is always generated. If the sender requests no echo, the echo skb is consumed in __can_get_echo_skb() without being passed into the RX handler of the networking stack, but the CAN data length and CAN frame length information is properly returned.
--- drivers/net/can/dev/skb.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/can/dev/skb.c +8 -2
@@ -45,7 +45,7 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,BUG_ON (idx >= priv->echo_skb_max);/* check flag whether this packet has to be looped back */ -if (!(dev->flags &IFF_ECHO ) || skb->pkt_type !=PACKET_LOOPBACK || +if (!(dev->flags &IFF_ECHO ) || (skb->protocol !=htons (ETH_P_CAN ) && skb->protocol !=htons (ETH_P_CANFD ))) {kfree_skb (skb);
@@ -58,7 +58,6 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,return -ENOMEM ;/* make settings for echo to reduce code in irq context */ - skb->pkt_type =PACKET_BROADCAST ; skb->ip_summed =CHECKSUM_UNNECESSARY ; skb->dev = dev;
@@ -111,6 +110,13 @@ __can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr, priv->echo_skb[idx] =NULL ; +if (skb->pkt_type ==PACKET_LOOPBACK ) { + skb->pkt_type =PACKET_BROADCAST ; + }else { +dev_consume_skb_any (skb); +return NULL ; + } +return skb; }
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 4/39 can: dev: can_free_echo_skb(): don't crash the kernel if can_priv::echo_skb is accessed out of bounds
In reply to Marc Kleine-BuddeA out of bounds access to "struct can_priv::echo_skb" leads to a kernel crash. Better print a sensible warning message instead and try to recover.
This patch is similar to:
| e7a6994d043a ("can: dev: __can_get_echo_skb(): Don't crash the kernel
| if can_priv::echo_skb is accessed out of bounds")
--- drivers/net/can/dev/skb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/can/dev/skb.c +5 -1
@@ -157,7 +157,11 @@ void can_free_echo_skb(struct net_device *dev, unsigned int idx) {struct can_priv *priv =netdev_priv (dev); -BUG_ON (idx >= priv->echo_skb_max); +if (idx >= priv->echo_skb_max) { +netdev_err (dev,"%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n" , + __func__, idx, priv->echo_skb_max); +return ; + }if (priv->echo_skb[idx]) {dev_kfree_skb_any (priv->echo_skb[idx]);
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 5/39 can: dev: can_free_echo_skb(): extend to return can frame length
In reply to Marc Kleine-BuddeIn order to implement byte queue limits (bql) in CAN drivers, the length of the CAN frame needs to be passed into the networking stack even if the transmission failed for some reason.
To avoid to calculate this length twice, extend can_free_echo_skb() to return that value. Convert all users of this function, too.
This patch is the natural extension of commit:
| 9420e1d495e2 ("can: dev: can_get_echo_skb(): extend to return can
| frame length")
--- drivers/net/can/dev/skb.c | 11 +++++++++-- drivers/net/can/grcan.c | 2 +- drivers/net/can/m_can/m_can.c | 2 +- drivers/net/can/rcar/rcar_can.c | 2 +- drivers/net/can/rcar/rcar_canfd.c | 2 +- drivers/net/can/sja1000/sja1000.c | 2 +- drivers/net/can/spi/hi311x.c | 2 +- drivers/net/can/spi/mcp251x.c | 2 +- drivers/net/can/usb/ems_usb.c | 2 +- drivers/net/can/usb/esd_usb2.c | 4 ++-- drivers/net/can/usb/gs_usb.c | 2 +- drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 2 +- drivers/net/can/usb/mcba_usb.c | 2 +- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 2 +- drivers/net/can/usb/ucan.c | 6 +++--- drivers/net/can/usb/usb_8dev.c | 2 +- include/linux/can/skb.h | 3 ++- 17 files changed, 29 insertions(+), 21 deletions(-)
drivers/net/can/dev/skb.c +9 -2
@@ -153,7 +153,8 @@ EXPORT_SYMBOL_GPL(can_get_echo_skb);* * The function is typically called when TX failed. */ -void can_free_echo_skb (struct net_device *dev,unsigned int idx) +void can_free_echo_skb (struct net_device *dev,unsigned int idx, +unsigned int *frame_len_ptr) {struct can_priv *priv =netdev_priv (dev);
@@ -164,7 +165,13 @@ void can_free_echo_skb(struct net_device *dev, unsigned int idx) }if (priv->echo_skb[idx]) { -dev_kfree_skb_any (priv->echo_skb[idx]); +struct sk_buff *skb = priv->echo_skb[idx]; +struct can_skb_priv *can_skb_priv =can_skb_prv (skb); + +if (frame_len_ptr) + *frame_len_ptr = can_skb_priv->frame_len; + +dev_kfree_skb_any (skb); priv->echo_skb[idx] =NULL ; } }
drivers/net/can/grcan.c +1 -1
@@ -520,7 +520,7 @@ static int catch_up_echo_skb(struct net_device *dev, int budget, bool echo)can_get_echo_skb (dev, i,NULL ); }else {/* For cleanup of untransmitted messages */ -can_free_echo_skb (dev, i); +can_free_echo_skb (dev, i,NULL ); } priv->eskbp = grcan_ring_add(priv->eskbp, GRCAN_MSG_SIZE,
drivers/net/can/m_can/m_can.c +1 -1
@@ -425,7 +425,7 @@ static void m_can_clean(struct net_device *net) putidx = ((m_can_read (cdev,M_CAN_TXFQS ) &TXFQS_TFQPI_MASK ) >>TXFQS_TFQPI_SHIFT ); -can_free_echo_skb (cdev->net, putidx); +can_free_echo_skb (cdev->net, putidx,NULL ); cdev->tx_skb =NULL ; } }
drivers/net/can/rcar/rcar_can.c +1 -1
@@ -217,7 +217,7 @@ static void tx_failure_cleanup(struct net_device *ndev)int i;for (i =0 ; i <RCAR_CAN_FIFO_DEPTH ; i++) -can_free_echo_skb (ndev, i); +can_free_echo_skb (ndev, i,NULL ); }static void rcar_can_error (struct net_device *ndev)
drivers/net/can/rcar/rcar_canfd.c +1 -1
@@ -617,7 +617,7 @@ static void rcar_canfd_tx_failure_cleanup(struct net_device *ndev)u32 i;for (i =0 ; i <RCANFD_FIFO_DEPTH ; i++) -can_free_echo_skb (ndev, i); +can_free_echo_skb (ndev, i,NULL ); }static int rcar_canfd_reset_controller (struct rcar_canfd_global *gpriv)
drivers/net/can/sja1000/sja1000.c +1 -1
@@ -525,7 +525,7 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)if (priv->can.ctrlmode &CAN_CTRLMODE_ONE_SHOT && !(status &SR_TCS )) { stats->tx_errors++; -can_free_echo_skb (dev,0 ); +can_free_echo_skb (dev,0 ,NULL ); }else {/* transmission complete */ stats->tx_bytes +=
drivers/net/can/spi/hi311x.c +1 -1
@@ -179,7 +179,7 @@ static void hi3110_clean(struct net_device *net) net->stats.tx_errors++;dev_kfree_skb (priv->tx_skb);if (priv->tx_len) -can_free_echo_skb (priv->net,0 ); +can_free_echo_skb (priv->net,0 ,NULL ); priv->tx_skb =NULL ; priv->tx_len =0 ; }
drivers/net/can/spi/mcp251x.c +1 -1
@@ -276,7 +276,7 @@ static void mcp251x_clean(struct net_device *net) net->stats.tx_errors++;dev_kfree_skb (priv->tx_skb);if (priv->tx_len) -can_free_echo_skb (priv->net,0 ); +can_free_echo_skb (priv->net,0 ,NULL ); priv->tx_skb =NULL ; priv->tx_len =0 ; }
drivers/net/can/usb/ems_usb.c +1 -1
@@ -807,7 +807,7 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne err =usb_submit_urb (urb,GFP_ATOMIC );if (unlikely (err)) { -can_free_echo_skb (netdev, context->echo_index); +can_free_echo_skb (netdev, context->echo_index,NULL );usb_unanchor_urb (urb);usb_free_coherent (dev->udev, size, buf, urb->transfer_dma);
drivers/net/can/usb/esd_usb2.c +2 -2
@@ -360,7 +360,7 @@ static void esd_usb2_tx_done_msg(struct esd_usb2_net_priv *priv,can_get_echo_skb (netdev, context->echo_index,NULL ); }else { stats->tx_errors++; -can_free_echo_skb (netdev, context->echo_index); +can_free_echo_skb (netdev, context->echo_index,NULL ); }/* Release context */
@@ -793,7 +793,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb, err =usb_submit_urb (urb,GFP_ATOMIC );if (err) { -can_free_echo_skb (netdev, context->echo_index); +can_free_echo_skb (netdev, context->echo_index,NULL );atomic_dec (&priv->active_tx_jobs);usb_unanchor_urb (urb);
drivers/net/can/usb/gs_usb.c +1 -1
@@ -533,7 +533,7 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,if (unlikely (rc)) {/* usb send failed */ atomic_dec (&dev->active_tx_urbs); -can_free_echo_skb (netdev, idx); +can_free_echo_skb (netdev, idx,NULL );gs_free_tx_context (txc);usb_unanchor_urb (urb);
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +1 -1
@@ -593,7 +593,7 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb,if (unlikely (err)) {spin_lock_irqsave (&priv->tx_contexts_lock, flags); -can_free_echo_skb (netdev, context->echo_index); +can_free_echo_skb (netdev, context->echo_index,NULL ); context->echo_index = dev->max_tx_urbs; --priv->active_tx_contexts;netif_wake_queue (netdev);
drivers/net/can/usb/mcba_usb.c +1 -1
@@ -364,7 +364,7 @@ static netdev_tx_t mcba_usb_start_xmit(struct sk_buff *skb,return NETDEV_TX_OK ; xmit_failed: -can_free_echo_skb (priv->netdev, ctx->ndx); +can_free_echo_skb (priv->netdev, ctx->ndx,NULL );mcba_usb_free_ctx (ctx);dev_kfree_skb (skb); stats->tx_dropped++;
drivers/net/can/usb/peak_usb/pcan_usb_core.c +1 -1
@@ -371,7 +371,7 @@ static netdev_tx_t peak_usb_ndo_start_xmit(struct sk_buff *skb, err =usb_submit_urb (urb,GFP_ATOMIC );if (err) { -can_free_echo_skb (netdev, context->echo_index); +can_free_echo_skb (netdev, context->echo_index,NULL );usb_unanchor_urb (urb);
drivers/net/can/usb/ucan.c +3 -3
@@ -675,7 +675,7 @@ static void ucan_tx_complete_msg(struct ucan_priv *up,can_get_echo_skb (up->netdev, echo_index,NULL ); }else { up->netdev->stats.tx_dropped++; -can_free_echo_skb (up->netdev, echo_index); +can_free_echo_skb (up->netdev, echo_index,NULL ); }spin_unlock_irqrestore (&up->echo_skb_lock, flags); }
@@ -843,7 +843,7 @@ static void ucan_write_bulk_callback(struct urb *urb)/* update counters an cleanup */ spin_lock_irqsave (&up->echo_skb_lock, flags); -can_free_echo_skb (up->netdev, context - up->context_array); +can_free_echo_skb (up->netdev, context - up->context_array,NULL );spin_unlock_irqrestore (&up->echo_skb_lock, flags); up->netdev->stats.tx_dropped++;
@@ -1157,7 +1157,7 @@ static netdev_tx_t ucan_start_xmit(struct sk_buff *skb,* frees the skb */ spin_lock_irqsave (&up->echo_skb_lock, flags); -can_free_echo_skb (up->netdev, echo_index); +can_free_echo_skb (up->netdev, echo_index,NULL );spin_unlock_irqrestore (&up->echo_skb_lock, flags);if (ret == -ENODEV ) {
drivers/net/can/usb/usb_8dev.c +1 -1
@@ -691,7 +691,7 @@ static netdev_tx_t usb_8dev_start_xmit(struct sk_buff *skb,return NETDEV_TX_BUSY ; failed: -can_free_echo_skb (netdev, context->echo_index); +can_free_echo_skb (netdev, context->echo_index,NULL );usb_unanchor_urb (urb);usb_free_coherent (priv->udev, size, buf, urb->transfer_dma);
include/linux/can/skb.h +2 -1
@@ -23,7 +23,8 @@ 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); -void can_free_echo_skb (struct net_device *dev,unsigned int idx); +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);struct sk_buff *alloc_canfd_skb (struct net_device *dev,struct canfd_frame **cfd);
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 6/39 can: add new CAN FD bittiming parameters: Transmitter Delay Compensation (TDC)
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
At high bit rates, the propagation delay from the TX pin to the RX pin of the transceiver causes measurement errors: the sample point on the RX pin might occur on the previous bit.
This issue is addressed in ISO 11898-1 section 11.3.3 "Transmitter delay compensation" (TDC).
This patch adds two new structures: can_tdc and can_tdc_const in order to implement this TDC.
The structures are then added to can_priv.
A controller supports TDC if an only if can_priv::tdc_const is not NULL.
TDC is active if and only if:
- fd flag is on
- can_priv::tdc.tdco is not zero.
It is the driver responsibility to check those two conditions are met.
No new controller modes are introduced (i.e. no CAN_CTRL_MODE_TDC) in order not to be redundant with above logic.
The names of the parameters are chosen to match existing CAN controllers specification. References:
- Bosch C_CAN FD8:
https://www.bosch-semiconductors.com/media/ip_modules/pdf_2/c_can_fd8/users_manual_c_can_fd8_r210_1.pdf
- Microchip CAN FD Controller Module:
http://ww1.microchip.com/downloads/en/DeviceDoc/MCP251XXFD-CAN-FD-Controller-Module-Family-Reference-Manual-20005678B.pdf
- SAM E701/S70/V70/V71 Family:
https://www.mouser.com/datasheet/2/268/60001527A-1284321.pdf
--- include/linux/can/bittiming.h | 65 +++++++++++++++++++++++++++++++++++ include/linux/can/dev.h | 3 ++ 2 files changed, 68 insertions(+)
include/linux/can/bittiming.h +65 -0
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: GPL-2.0-only */ /* Copyright (c) 2020 Pengutronix, Marc Kleine-Budde <[email protected]> +* Copyright (c) 2021 Vincent Mailhol <[email protected]> */ #ifndef _CAN_BITTIMING_H
@@ -10,6 +11,70 @@#define CAN_SYNC_SEG 1 +/* +* struct can_tdc - CAN FD Transmission Delay Compensation parameters +* +* At high bit rates, the propagation delay from the TX pin to the RX +* pin of the transceiver causes measurement errors: the sample point +* on the RX pin might occur on the previous bit. +* +* To solve this issue, ISO 11898-1 introduces in section 11.3.3 +* "Transmitter delay compensation" a SSP (Secondary Sample Point) +* equal to the distance, in time quanta, from the start of the bit +* time on the TX pin to the actual measurement on the RX pin. +* +* This structure contains the parameters to calculate that SSP. +* +* @tdcv: Transmitter Delay Compensation Value. Distance, in time +* quanta, from when the bit is sent on the TX pin to when it is +* received on the RX pin of the transmitter. Possible options: +* +* O: automatic mode. The controller dynamically measure @tdcv +* for each transmitted CAN FD frame. +* +* Other values: manual mode. Use the fixed provided value. +* +* @tdco: Transmitter Delay Compensation Offset. Offset value, in time +* quanta, defining the distance between the start of the bit +* reception on the RX pin of the transceiver and the SSP +* position such as SSP = @tdcv + @tdco. +* +* If @tdco is zero, then TDC is disabled and both @tdcv and +* @tdcf should be ignored. +* +* @tdcf: Transmitter Delay Compensation Filter window. Defines the +* minimum value for the SSP position in time quanta. If SSP is +* less than @tdcf, then no delay compensations occur and the +* normal sampling point is used instead. The feature is enabled +* if and only if @tdcv is set to zero (automatic mode) and @tdcf +* is configured to a value greater than @tdco. +*/ +struct can_tdc { +u32 tdcv; +u32 tdco; +u32 tdcf; +}; + +/* +* struct can_tdc_const - CAN hardware-dependent constant for +* Transmission Delay Compensation +* +* @tdcv_max: Transmitter Delay Compensation Value maximum value. +* Should be set to zero if the controller does not support +* manual mode for tdcv. +* @tdco_max: Transmitter Delay Compensation Offset maximum value. +* Should not be zero. If the controller does not support TDC, +* then the pointer to this structure should be NULL. +* @tdcf_max: Transmitter Delay Compensation Filter window maximum +* value. Should be set to zero if the controller does not +* support this feature. +*/ +struct can_tdc_const { +u32 tdcv_max; +u32 tdco_max; +u32 tdcf_max; +}; +#ifdef CONFIG_CAN_CALC_BITTIMING int can_calc_bittiming (struct net_device *dev,struct can_bittiming *bt,const struct can_bittiming_const *btc);
include/linux/can/dev.h +3 -0
@@ -42,6 +42,9 @@ struct can_priv {struct can_bittiming bittiming, data_bittiming;const struct can_bittiming_const *bittiming_const, *data_bittiming_const; +struct can_tdc tdc; +const struct can_tdc_const *tdc_const; +const u16 *termination_const;unsigned int termination_const_cnt;u16 termination;
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 7/39 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 struct can_priv members.
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 */
struct can_bittiming bittiming; /* 32 32 */
/* --- cacheline 1 boundary (64 bytes) --- */
struct can_bittiming data_bittiming; /* 64 32 */
const struct can_bittiming_const * bittiming_const; /* 96 8 */
const struct can_bittiming_const * data_bittiming_const; /* 104 8 */
struct can_tdc tdc; /* 112 12 *//* XXX 4 bytes hole, try to pack */
/* --- cacheline 2 boundary (128 bytes) --- */
const struct can_tdc_const * tdc_const; /* 128 8 */
const u16 * termination_const; /* 136 8 */
unsigned int termination_const_cnt; /* 144 4 */
u16 termination; /* 148 2 */
/* XXX 2 bytes hole, try to pack */
const u32 * bitrate_const; /* 152 8 */
unsigned int bitrate_const_cnt; /* 160 4 */
/* XXX 4 bytes hole, try to pack */
const u32 * data_bitrate_const; /* 168 8 */
unsigned int data_bitrate_const_cnt; /* 176 4 */
u32 bitrate_max; /* 180 4 */
struct can_clock clock; /* 184 4 */
enum can_state state; /* 188 4 */
/* --- cacheline 3 boundary (192 bytes) --- */
u32 ctrlmode; /* 192 4 */
u32 ctrlmode_supported; /* 196 4 */
u32 ctrlmode_static; /* 200 4 */
int restart_ms; /* 204 4 */
struct delayed_work restart_work; /* 208 168 */
/* XXX last struct has 4 bytes of padding */
/* --- cacheline 5 boundary (320 bytes) was 56 bytes ago --- */
int (*do_set_bittiming)(struct net_device *); /* 376 8 */
/* --- cacheline 6 boundary (384 bytes) --- */
int (*do_set_data_bittiming)(struct net_device *); /* 384 8 */
int (*do_set_mode)(struct net_device *, enum can_mode); /* 392 8 */
int (*do_set_termination)(struct net_device *, u16); /* 400 8 */
int (*do_get_state)(const struct net_device *, enum can_state *); /* 408 8 */
int (*do_get_berr_counter)(const struct net_device *, struct can_berr_counter *); /* 416 8 */
unsigned int echo_skb_max; /* 424 4 */
/* XXX 4 bytes hole, try to pack */
struct sk_buff * * echo_skb; /* 432 8 */
/* size: 440, cachelines: 7, members: 31 */ /* sum members: 426, holes: 4, sum holes: 14 */ /* paddings: 1, sum paddings: 4 */
/* last cacheline: 56 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 2 bytes hole, try to pack */
enum can_state state; /* 180 4 */
u32 ctrlmode; /* 184 4 */
u32 ctrlmode_supported; /* 188 4 */
/* --- cacheline 3 boundary (192 bytes) --- */
u32 ctrlmode_static; /* 192 4 */
int restart_ms; /* 196 4 */
struct delayed_work restart_work; /* 200 168 */
/* XXX last struct has 4 bytes of padding */
/* --- cacheline 5 boundary (320 bytes) was 48 bytes ago --- */
int (*do_set_bittiming)(struct net_device *); /* 368 8 */
int (*do_set_data_bittiming)(struct net_device *); /* 376 8 */
/* --- cacheline 6 boundary (384 bytes) --- */
int (*do_set_mode)(struct net_device *, enum can_mode); /* 384 8 */
int (*do_set_termination)(struct net_device *, u16); /* 392 8 */
int (*do_get_state)(const struct net_device *, enum can_state *); /* 400 8 */
int (*do_get_berr_counter)(const struct net_device *, struct can_berr_counter *); /* 408 8 */
unsigned int echo_skb_max; /* 416 4 */
/* XXX 4 bytes hole, try to pack */
struct sk_buff * * echo_skb; /* 424 8 */
/* size: 432, cachelines: 7, members: 31 */ /* sum members: 426, holes: 2, sum holes: 6 */ /* paddings: 1, sum paddings: 4 */
/* last cacheline: 48 bytes */
};
--- include/linux/can/dev.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
include/linux/can/dev.h +7 -6
@@ -39,22 +39,23 @@ struct can_priv {struct net_device *dev;struct can_device_stats can_stats; -struct can_bittiming bittiming, data_bittiming;const struct can_bittiming_const *bittiming_const, *data_bittiming_const; -struct can_tdc tdc; +struct can_bittiming bittiming, data_bittiming;const struct can_tdc_const *tdc_const; +struct can_tdc tdc; -const u16 *termination_const; -unsigned int termination_const_cnt; -u16 termination; -const u32 *bitrate_const;unsigned int bitrate_const_cnt; +const u32 *bitrate_const;const u32 *data_bitrate_const;unsigned int data_bitrate_const_cnt;u32 bitrate_max;struct can_clock clock; +unsigned int termination_const_cnt; +const u16 *termination_const; +u16 termination; +enum can_state state;/* CAN controller features - see include/uapi/linux/can/netlink.h */
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 8/39 can: netlink: move '=' operators back to previous line (checkpatch fix)
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Fix the warning triggered by having an '=' at the beginning of the line by moving it back to the previous line. Also replace all indentations with a single space so that future entries can be more easily added.
Extract of ./scripts/checkpatch.pl -f drivers/net/can/dev/netlink.c:
CHECK: Assignment operator '=' should be on the previous line
+ [IFLA_CAN_BITTIMING_CONST]
+ = { .len = sizeof(struct can_bittiming_const) },
CHECK: Assignment operator '=' should be on the previous line
+ [IFLA_CAN_DATA_BITTIMING]
+ = { .len = sizeof(struct can_bittiming) },
CHECK: Assignment operator '=' should be on the previous line
+ [IFLA_CAN_DATA_BITTIMING_CONST]
+ = { .len = sizeof(struct can_bittiming_const) },
--- drivers/net/can/dev/netlink.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)
drivers/net/can/dev/netlink.c +11 -14
@@ -8,20 +8,17 @@#include <net/rtnetlink.h> static const struct nla_policy can_policy[IFLA_CAN_MAX +1 ] = { - [IFLA_CAN_STATE ] = { .type =NLA_U32 }, - [IFLA_CAN_CTRLMODE ] = { .len =sizeof (struct can_ctrlmode ) }, - [IFLA_CAN_RESTART_MS ] = { .type =NLA_U32 }, - [IFLA_CAN_RESTART ] = { .type =NLA_U32 }, - [IFLA_CAN_BITTIMING ] = { .len =sizeof (struct can_bittiming ) }, - [IFLA_CAN_BITTIMING_CONST ] - = { .len =sizeof (struct can_bittiming_const ) }, - [IFLA_CAN_CLOCK ] = { .len =sizeof (struct can_clock ) }, - [IFLA_CAN_BERR_COUNTER ] = { .len =sizeof (struct can_berr_counter ) }, - [IFLA_CAN_DATA_BITTIMING ] - = { .len =sizeof (struct can_bittiming ) }, - [IFLA_CAN_DATA_BITTIMING_CONST ] - = { .len =sizeof (struct can_bittiming_const ) }, - [IFLA_CAN_TERMINATION ] = { .type =NLA_U16 }, + [IFLA_CAN_STATE ] = { .type =NLA_U32 }, + [IFLA_CAN_CTRLMODE ] = { .len =sizeof (struct can_ctrlmode ) }, + [IFLA_CAN_RESTART_MS ] = { .type =NLA_U32 }, + [IFLA_CAN_RESTART ] = { .type =NLA_U32 }, + [IFLA_CAN_BITTIMING ] = { .len =sizeof (struct can_bittiming ) }, + [IFLA_CAN_BITTIMING_CONST ] = { .len =sizeof (struct can_bittiming_const ) }, + [IFLA_CAN_CLOCK ] = { .len =sizeof (struct can_clock ) }, + [IFLA_CAN_BERR_COUNTER ] = { .len =sizeof (struct can_berr_counter ) }, + [IFLA_CAN_DATA_BITTIMING ] = { .len =sizeof (struct can_bittiming ) }, + [IFLA_CAN_DATA_BITTIMING_CONST ] = { .len =sizeof (struct can_bittiming_const ) }, + [IFLA_CAN_TERMINATION ] = { .type =NLA_U16 }, }; static int can_validate(struct nlattr *tb[], struct nlattr *data[],
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 9/39 can: bittiming: add calculation for CAN FD Transmitter Delay Compensation (TDC)
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
The logic for the tdco calculation is to just reuse the normal sample
point: tdco = sp. Because the sample point is expressed in tenth of percent and the tdco is expressed in time quanta, a conversion is needed.
At the end,
ssp = tdcv + tdco
= tdcv + sp.
Another popular method is to set tdco to the middle of the bit:
tdc->tdco = can_bit_time(dbt) / 2
During benchmark tests, we could not find a clear advantages for one of the two methods.
The tdco calculation is triggered each time the data_bittiming is changed so that users relying on automated calculation can use the netlink interface the exact same way without need of new parameters. For example, a command such as:
ip link set canX type can bitrate 500000 dbitrate 4000000 fd on
would trigger the calculation.
The user using CONFIG_CAN_CALC_BITTIMING who does not want automated calculation needs to manually set tdco to zero.
For example with:
ip link set canX type can tdco 0 bitrate 500000 dbitrate 4000000 fd on
(if the tdco parameter is provided in a previous command, it will be overwritten).
If tdcv is set to zero (default), it is automatically calculated by the transiver for each frame. As such, there is no code in the kernel to calculate it.
tdcf has no automated calculation functions because we could not figure out a formula for this parameter.
--- drivers/net/can/dev/bittiming.c | 24 ++++++++++++++++++++++++ drivers/net/can/dev/netlink.c | 2 ++ include/linux/can/bittiming.h | 6 ++++++ 3 files changed, 32 insertions(+)
drivers/net/can/dev/bittiming.c +24 -0
@@ -174,6 +174,30 @@ int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, return 0; } + +void can_calc_tdco (struct net_device *dev) +{ +struct can_priv *priv =netdev_priv (dev); +const struct can_bittiming *dbt = &priv->data_bittiming; +struct can_tdc *tdc = &priv->tdc; +const struct can_tdc_const *tdc_const = priv->tdc_const; + +if (!tdc_const) +return ; + +/* As specified in ISO 11898-1 section 11.3.3 "Transmitter +* delay compensation" (TDC) is only applicable if data BRP is +* one or two. +*/ +if (dbt->brp ==1 || dbt->brp ==2 ) { +/* Reuse "normal" sample point and convert it to time quanta */ +u32 sample_point_in_tq =can_bit_time (dbt) * dbt->sample_point /1000 ; + + tdc->tdco =min (sample_point_in_tq, tdc_const->tdco_max); + }else { + tdc->tdco =0 ; + } +}#endif /* CONFIG_CAN_CALC_BITTIMING */ /* Checks the validity of the specified bit-timing parameters prop_seg,
drivers/net/can/dev/netlink.c +2 -0
@@ -186,6 +186,8 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],memcpy (&priv->data_bittiming, &dbt,sizeof (dbt)); +can_calc_tdco (dev); +if (priv->do_set_data_bittiming) {/* Finally, set the bit-timing registers */ err = priv->do_set_data_bittiming (dev);
include/linux/can/bittiming.h +6 -0
@@ -78,6 +78,8 @@ struct can_tdc_const {#ifdef CONFIG_CAN_CALC_BITTIMING int can_calc_bittiming (struct net_device *dev,struct can_bittiming *bt,const struct can_bittiming_const *btc); + +void can_calc_tdco (struct net_device *dev);#else /* !CONFIG_CAN_CALC_BITTIMING */ static inline int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
@@ -86,6 +88,10 @@ can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,netdev_err (dev,"bit-timing calculation not available\n" );return -EINVAL ; } + +static inline void can_calc_tdco (struct net_device *dev) +{ +}#endif /* CONFIG_CAN_CALC_BITTIMING */ int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt,
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 10/39 can: bittiming: add CAN_KBPS, CAN_MBPS and CAN_MHZ macros
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
Add three macro to simplify the readability of big bit timing numbers:
- CAN_KBPS: kilobits per second (one thousand)
- CAN_MBPS: megabits per second (one million)
- CAN_MHZ: megahertz per second (one million)
Example:
u32 bitrate_max = 8 * CAN_MBPS;
struct can_clock clock = {.freq = 80 * CAN_MHZ};
instead of:
u32 bitrate_max = 8000000;
struct can_clock clock = {.freq = 80000000};Apply the new macro to driver/net/can/dev/bittiming.c.
--- drivers/net/can/dev/bittiming.c | 4 ++-- include/linux/can/bittiming.h | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/net/can/dev/bittiming.c +2 -2
@@ -81,9 +81,9 @@ int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,if (bt->sample_point) { sample_point_nominal = bt->sample_point; }else { -if (bt->bitrate >800000 ) +if (bt->bitrate >800 *CAN_KBPS ) sample_point_nominal =750 ; -else if (bt->bitrate >500000 ) +else if (bt->bitrate >500 *CAN_KBPS ) sample_point_nominal =800 ;else sample_point_nominal =875 ;
include/linux/can/bittiming.h +8 -0
@@ -11,6 +11,14 @@#define CAN_SYNC_SEG 1 + +/* Kilobits and Megabits per second */ +#define CAN_KBPS 1000UL +#define CAN_MBPS 1000000UL + +/* Megahertz */ +#define CAN_MHZ 1000000UL +/* * struct can_tdc - CAN FD Transmission Delay Compensation parameters *
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 11/39 can: grcan: add missing Kconfig dependency to HAS_IOMEM
In reply to Marc Kleine-BuddeOn ARCHs without IOMEM support the grcan driver fails to link due to missing iomem functionality. This patch adds the missing Kconfig dependency to HAS_IOMEM.
--- drivers/net/can/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/Kconfig +1 -1
@@ -103,7 +103,7 @@ config CAN_FLEXCAN config CAN_GRCAN tristate "Aeroflex Gaisler GRCAN and GRHCAN CAN devices" - depends on OF && HAS_DMA + depends on OF && HAS_DMA && HAS_IOMEM help Say Y here if you want to use Aeroflex Gaisler GRCAN or GRHCAN. Note that the driver supports little endian, even though little
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 12/39 can: xilinx_can: Simplify code by using dev_err_probe()
In reply to Marc Kleine-BuddeFrom: Michal Simek <[email protected]>
Use already prepared dev_err_probe() introduced by commit a787e5400a1c ("driver core: add device probe log helper").
It simplifies EPROBE_DEFER handling.
Also unify message format for similar error cases.
--- drivers/net/can/xilinx_can.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/can/xilinx_can.c +4 -6
@@ -1772,17 +1772,15 @@ static int xcan_probe(struct platform_device *pdev)/* Getting the CAN can_clk info */ priv->can_clk =devm_clk_get (&pdev->dev,"can_clk" );if (IS_ERR (priv->can_clk)) { -if (PTR_ERR (priv->can_clk) != -EPROBE_DEFER ) -dev_err (&pdev->dev,"Device clock not found.\n" ); - ret =PTR_ERR (priv->can_clk); + ret =dev_err_probe (&pdev->dev,PTR_ERR (priv->can_clk), +"device clock not found\n" ); goto err_free; } priv->bus_clk =devm_clk_get (&pdev->dev, devtype->bus_clk_name);if (IS_ERR (priv->bus_clk)) { -if (PTR_ERR (priv->bus_clk) != -EPROBE_DEFER ) -dev_err (&pdev->dev,"bus clock not found\n" ); - ret =PTR_ERR (priv->bus_clk); + ret =dev_err_probe (&pdev->dev,PTR_ERR (priv->bus_clk), +"bus clock not found\n" ); goto err_free; }
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 13/39 can: ucan: fix alignment constraints
In reply to Marc Kleine-BuddeFrom: Arnd Bergmann <[email protected]>
struct ucan_message_in contains member with 4-byte alignment but is itself marked as unaligned, which triggers a warning:
drivers/net/can/usb/ucan.c:249:1: warning: alignment 1 of 'struct ucan_message_in' is less than 4 [-Wpacked-not-aligned]
Mark the outer structure to have the same alignment as the inner one.
--- drivers/net/can/usb/ucan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/usb/ucan.c +1 -1
@@ -246,7 +246,7 @@ struct ucan_message_in {*/ struct ucan_tx_complete_entry_t can_tx_complete_msg[0 ]; }__aligned(0x4) msg; -} __packed; +} __packed__aligned(0x4) ;/* Macros to calculate message lengths */ #define UCAN_OUT_HDR_SIZE offsetof(struct ucan_message_out, msg)
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 14/39 can: peak_usb: pcan_usb_pro_encode_msg(): use macros for flags instead of plain integers
In reply to Marc Kleine-BuddeFrom: Stephane Grosjean <[email protected]>
This patch replaces the plain integers used for flags in pcan_usb_pro_encode_msg() by macros which are already defined.
--- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/usb/peak_usb/pcan_usb_pro.c +2 -2
@@ -776,9 +776,9 @@ static int pcan_usb_pro_encode_msg(struct peak_usb_device *dev, flags =0 ;if (cf->can_id &CAN_EFF_FLAG ) - flags |=0x02 ; + flags |=PCAN_USBPRO_EXT ;if (cf->can_id &CAN_RTR_FLAG ) - flags |=0x01 ; + flags |=PCAN_USBPRO_RTR ;pcan_msg_add_rec (&usb_msg, data_type,0 , flags, len, cf->can_id, cf->data);
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 15/39 can: peak_usb: add support of ethtool set_phys_id()
In reply to Marc Kleine-BuddeFrom: Stephane Grosjean <[email protected]>
This patch makes it possible to specifically flash the LED of a CAN port of the CAN-USB interfaces of PEAK-System.
--- drivers/net/can/usb/peak_usb/pcan_usb.c | 47 ++++++++++++++++++++ drivers/net/can/usb/peak_usb/pcan_usb_core.c | 4 ++ drivers/net/can/usb/peak_usb/pcan_usb_core.h | 2 + drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 34 ++++++++++++++ drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 34 +++++++++++++- drivers/net/can/usb/peak_usb/pcan_usb_pro.h | 6 +++ 6 files changed, 126 insertions(+), 1 deletion(-)
drivers/net/can/usb/peak_usb/pcan_usb.c +47 -0
@@ -11,6 +11,7 @@#include <linux/netdevice.h> #include <linux/usb.h> #include <linux/module.h> +#include <linux/ethtool.h> #include <linux/can.h> #include <linux/can/dev.h>
@@ -40,6 +41,7 @@#define PCAN_USB_CMD_REGISTER 9#define PCAN_USB_CMD_EXT_VCC 10#define PCAN_USB_CMD_ERR_FR 11 +#define PCAN_USB_CMD_LED 12/* PCAN_USB_CMD_SET_BUS number arg */ #define PCAN_USB_BUS_XCVER 2
@@ -248,6 +250,15 @@ static int pcan_usb_set_ext_vcc(struct peak_usb_device *dev, u8 onoff)return pcan_usb_send_cmd (dev,PCAN_USB_CMD_EXT_VCC ,PCAN_USB_SET , args); } +static int pcan_usb_set_led (struct peak_usb_device *dev,u8 onoff) +{ +u8 args[PCAN_USB_CMD_ARGS_LEN ] = { + [0 ] = !!onoff, + }; + +return pcan_usb_send_cmd (dev,PCAN_USB_CMD_LED ,PCAN_USB_SET , args); +} +/* * set bittiming value to can */
@@ -971,6 +982,40 @@ static int pcan_usb_probe(struct usb_interface *intf)return 0 ; } +static int pcan_usb_set_phys_id (struct net_device *netdev, +enum ethtool_phys_id_state state) +{ +struct peak_usb_device *dev =netdev_priv (netdev); +int err =0 ; + +switch (state) { +case ETHTOOL_ID_ACTIVE : +/* call ON/OFF twice a second */ +return 2 ; + +case ETHTOOL_ID_OFF : + err =pcan_usb_set_led (dev,0 ); +break ; + +case ETHTOOL_ID_ON : + fallthrough; + +case ETHTOOL_ID_INACTIVE : +/* restore LED default */ + err =pcan_usb_set_led (dev,1 ); +break ; + +default : +break ; + } + +return err; +} + +static const struct ethtool_ops pcan_usb_ethtool_ops = { + .set_phys_id = pcan_usb_set_phys_id, +}; +/* * describe the PCAN-USB adapter */
@@ -1001,6 +1046,8 @@ const struct peak_usb_adapter pcan_usb = {/* size of device private data */ .sizeof_dev_private = sizeof(struct pcan_usb), + .ethtool_ops = &pcan_usb_ethtool_ops, +/* timestamps usage */ .ts_used_bits = 16, .ts_period = 24575, /* calibration period in ts. */
drivers/net/can/usb/peak_usb/pcan_usb_core.c +4 -0
@@ -14,6 +14,7 @@#include <linux/module.h> #include <linux/netdevice.h> #include <linux/usb.h> +#include <linux/ethtool.h> #include <linux/can.h> #include <linux/can/dev.h>
@@ -820,6 +821,9 @@ static int peak_usb_create_dev(const struct peak_usb_adapter *peak_usb_adapter, netdev->flags |=IFF_ECHO ;/* we support local echo */ +/* add ethtool support */ + netdev->ethtool_ops = peak_usb_adapter->ethtool_ops; +init_usb_anchor (&dev->rx_submitted);init_usb_anchor (&dev->tx_submitted);
drivers/net/can/usb/peak_usb/pcan_usb_core.h +2 -0
@@ -46,6 +46,8 @@ struct peak_usb_adapter {const struct can_bittiming_const *const data_bittiming_const;unsigned int ctrl_count; +const struct ethtool_ops *ethtool_ops; +int (*intf_probe)(struct usb_interface *intf);int (*dev_init)(struct peak_usb_device *dev);
drivers/net/can/usb/peak_usb/pcan_usb_fd.c +34 -0
@@ -7,6 +7,7 @@#include <linux/netdevice.h> #include <linux/usb.h> #include <linux/module.h> +#include <linux/ethtool.h> #include <linux/can.h> #include <linux/can/dev.h>
@@ -1006,6 +1007,31 @@ static void pcan_usb_fd_free(struct peak_usb_device *dev) } } +/* blink LED's */ +static int pcan_usb_fd_set_phys_id (struct net_device *netdev, +enum ethtool_phys_id_state state) +{ +struct peak_usb_device *dev =netdev_priv (netdev); +int err =0 ; + +switch (state) { +case ETHTOOL_ID_ACTIVE : + err =pcan_usb_fd_set_can_led (dev,PCAN_UFD_LED_FAST ); +break ; +case ETHTOOL_ID_INACTIVE : + err =pcan_usb_fd_set_can_led (dev,PCAN_UFD_LED_DEF ); +break ; +default : +break ; + } + +return err; +} + +static const struct ethtool_ops pcan_usb_fd_ethtool_ops = { + .set_phys_id = pcan_usb_fd_set_phys_id, +}; +/* describes the PCAN-USB FD adapter */ static const struct can_bittiming_const pcan_usb_fd_const = { .name ="pcan_usb_fd" ,
@@ -1047,6 +1073,8 @@ const struct peak_usb_adapter pcan_usb_fd = {/* size of device private data */ .sizeof_dev_private = sizeof(struct pcan_usb_fd_device), + .ethtool_ops = &pcan_usb_fd_ethtool_ops, +/* timestamps usage */ .ts_used_bits = 32, .ts_period = 1000000, /* calibration period in ts. */
@@ -1120,6 +1148,8 @@ const struct peak_usb_adapter pcan_usb_chip = {/* size of device private data */ .sizeof_dev_private = sizeof(struct pcan_usb_fd_device), + .ethtool_ops = &pcan_usb_fd_ethtool_ops, +/* timestamps usage */ .ts_used_bits = 32, .ts_period = 1000000, /* calibration period in ts. */
@@ -1193,6 +1223,8 @@ const struct peak_usb_adapter pcan_usb_pro_fd = {/* size of device private data */ .sizeof_dev_private = sizeof(struct pcan_usb_fd_device), + .ethtool_ops = &pcan_usb_fd_ethtool_ops, +/* timestamps usage */ .ts_used_bits = 32, .ts_period = 1000000, /* calibration period in ts. */
@@ -1266,6 +1298,8 @@ const struct peak_usb_adapter pcan_usb_x6 = {/* size of device private data */ .sizeof_dev_private = sizeof(struct pcan_usb_fd_device), + .ethtool_ops = &pcan_usb_fd_ethtool_ops, +/* timestamps usage */ .ts_used_bits = 32, .ts_period = 1000000, /* calibration period in ts. */
drivers/net/can/usb/peak_usb/pcan_usb_pro.c +33 -1
@@ -9,6 +9,7 @@#include <linux/netdevice.h> #include <linux/usb.h> #include <linux/module.h> +#include <linux/ethtool.h> #include <linux/can.h> #include <linux/can/dev.h>
@@ -906,7 +907,7 @@ static int pcan_usb_pro_init(struct peak_usb_device *dev) usb_if->dev[dev->ctrl_idx] = dev;/* set LED in default state (end of init phase) */ -pcan_usb_pro_set_led (dev,0 ,1 ); +pcan_usb_pro_set_led (dev,PCAN_USBPRO_LED_DEVICE ,1 );kfree (bi);kfree (fi);
@@ -990,6 +991,35 @@ int pcan_usb_pro_probe(struct usb_interface *intf)return 0 ; } +static int pcan_usb_pro_set_phys_id (struct net_device *netdev, +enum ethtool_phys_id_state state) +{ +struct peak_usb_device *dev =netdev_priv (netdev); +int err =0 ; + +switch (state) { +case ETHTOOL_ID_ACTIVE : +/* fast blinking forever */ + err =pcan_usb_pro_set_led (dev,PCAN_USBPRO_LED_BLINK_FAST , +0xffffffff ); +break ; + +case ETHTOOL_ID_INACTIVE : +/* restore LED default */ + err =pcan_usb_pro_set_led (dev,PCAN_USBPRO_LED_DEVICE ,1 ); +break ; + +default : +break ; + } + +return err; +} + +static const struct ethtool_ops pcan_usb_pro_ethtool_ops = { + .set_phys_id = pcan_usb_pro_set_phys_id, +}; +/* * describe the PCAN-USB Pro adapter */
@@ -1018,6 +1048,8 @@ const struct peak_usb_adapter pcan_usb_pro = {/* size of device private data */ .sizeof_dev_private = sizeof(struct pcan_usb_pro_device), + .ethtool_ops = &pcan_usb_pro_ethtool_ops, +/* timestamps usage */ .ts_used_bits = 32, .ts_period = 1000000, /* calibration period in ts. */
drivers/net/can/usb/peak_usb/pcan_usb_pro.h +6 -0
@@ -115,6 +115,12 @@ struct __packed pcan_usb_pro_devid {__le32 serial_num; }; +#define PCAN_USBPRO_LED_DEVICE 0x00 +#define PCAN_USBPRO_LED_BLINK_FAST 0x01 +#define PCAN_USBPRO_LED_BLINK_SLOW 0x02 +#define PCAN_USBPRO_LED_ON 0x03 +#define PCAN_USBPRO_LED_OFF 0x04 +struct __packed pcan_usb_pro_setled {u8 data_type;u8 channel;
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 16/39 can: peak_usb: add support of ONE_SHOT mode
In reply to Marc Kleine-BuddeFrom: Stephane Grosjean <[email protected]>
This patch adds "ONE-SHOT" mode support to the following CAN-USB PEAK-System GmbH interfaces:
- PCAN-USB X6
- PCAN-USB FD
- PCAN-USB Pro FD
- PCAN-Chip USB
- PCAN-USB Pro
--- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 12 ++++++++---- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 8 +++++++- 2 files changed, 15 insertions(+), 5 deletions(-)
drivers/net/can/usb/peak_usb/pcan_usb_fd.c +8 -4
@@ -774,6 +774,10 @@ static int pcan_usb_fd_encode_msg(struct peak_usb_device *dev, tx_msg_flags |=PUCAN_MSG_RTR ; } +/* Single-Shot frame */ +if (dev->can.ctrlmode &CAN_CTRLMODE_ONE_SHOT ) + tx_msg_flags |=PUCAN_MSG_SINGLE_SHOT ; + tx_msg->flags =cpu_to_le16 (tx_msg_flags); tx_msg->channel_dlc =PUCAN_MSG_CHANNEL_DLC (dev->ctrl_idx, dlc);memcpy (tx_msg->d, cfd->data, cfd->len);
@@ -1063,7 +1067,7 @@ const struct peak_usb_adapter pcan_usb_fd = { .ctrl_count = PCAN_USBFD_CHANNEL_COUNT, .ctrlmode_supported =CAN_CTRLMODE_FD |CAN_CTRLMODE_3_SAMPLES |CAN_CTRLMODE_LISTENONLY | - CAN_CTRLMODE_CC_LEN8_DLC, + CAN_CTRLMODE_ONE_SHOT | CAN_CTRLMODE_CC_LEN8_DLC, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, },
@@ -1138,7 +1142,7 @@ const struct peak_usb_adapter pcan_usb_chip = { .ctrl_count = PCAN_USBFD_CHANNEL_COUNT, .ctrlmode_supported =CAN_CTRLMODE_FD |CAN_CTRLMODE_3_SAMPLES |CAN_CTRLMODE_LISTENONLY | - CAN_CTRLMODE_CC_LEN8_DLC, + CAN_CTRLMODE_ONE_SHOT | CAN_CTRLMODE_CC_LEN8_DLC, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, },
@@ -1213,7 +1217,7 @@ const struct peak_usb_adapter pcan_usb_pro_fd = { .ctrl_count = PCAN_USBPROFD_CHANNEL_COUNT, .ctrlmode_supported =CAN_CTRLMODE_FD |CAN_CTRLMODE_3_SAMPLES |CAN_CTRLMODE_LISTENONLY | - CAN_CTRLMODE_CC_LEN8_DLC, + CAN_CTRLMODE_ONE_SHOT | CAN_CTRLMODE_CC_LEN8_DLC, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, },
@@ -1288,7 +1292,7 @@ const struct peak_usb_adapter pcan_usb_x6 = { .ctrl_count = PCAN_USBPROFD_CHANNEL_COUNT, .ctrlmode_supported =CAN_CTRLMODE_FD |CAN_CTRLMODE_3_SAMPLES |CAN_CTRLMODE_LISTENONLY | - CAN_CTRLMODE_CC_LEN8_DLC, + CAN_CTRLMODE_ONE_SHOT | CAN_CTRLMODE_CC_LEN8_DLC, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, },
drivers/net/can/usb/peak_usb/pcan_usb_pro.c +7 -1
@@ -37,6 +37,7 @@#define PCAN_USBPRO_RTR 0x01#define PCAN_USBPRO_EXT 0x02 +#define PCAN_USBPRO_SS 0x08#define PCAN_USBPRO_CMD_BUFFER_SIZE 512
@@ -781,6 +782,10 @@ static int pcan_usb_pro_encode_msg(struct peak_usb_device *dev,if (cf->can_id &CAN_RTR_FLAG ) flags |=PCAN_USBPRO_RTR ; +/* Single-Shot frame */ +if (dev->can.ctrlmode &CAN_CTRLMODE_ONE_SHOT ) + flags |=PCAN_USBPRO_SS ; +pcan_msg_add_rec (&usb_msg, data_type,0 , flags, len, cf->can_id, cf->data);
@@ -1039,7 +1044,8 @@ const struct peak_usb_adapter pcan_usb_pro = { .name = "PCAN-USB Pro", .device_id = PCAN_USBPRO_PRODUCT_ID, .ctrl_count = PCAN_USBPRO_CHANNEL_COUNT, - .ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, + .ctrlmode_supported =CAN_CTRLMODE_3_SAMPLES |CAN_CTRLMODE_LISTENONLY | + CAN_CTRLMODE_ONE_SHOT, .clock = { .freq = PCAN_USBPRO_CRYSTAL_HZ, },
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 17/39 can: m_can: m_can_class_allocate_dev(): remove impossible error return judgment
In reply to Marc Kleine-BuddeFrom: Xulin Sun <[email protected]>
If the CAN net device has been successfully allocated, its private data structure is impossible to be empty, remove this redundant error return judgment.
--- drivers/net/can/m_can/m_can.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/net/can/m_can/m_can.c +0 -5
@@ -1787,11 +1787,6 @@ struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, } class_dev =netdev_priv (net_dev); -if (!class_dev) { -dev_err (dev,"Failed to init netdev cdevate" ); - goto out; - } - class_dev->net = net_dev; class_dev->dev = dev;SET_NETDEV_DEV (net_dev, dev);
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 18/39 can: m_can: add infrastructure for internal timestamps
In reply to Marc Kleine-BuddeFrom: Torin Cooper-Bennun <[email protected]>
Add infrastucture to allow internal timestamps from the M_CAN to be configured and retrieved.
--- drivers/net/can/m_can/m_can.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/net/can/m_can/m_can.c +27 -0
@@ -8,6 +8,7 @@* https://github.com/linux-can/can-doc/tree/master/m_can */ +#include <linux/bitfield.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/kernel.h>
@@ -148,6 +149,16 @@ enum m_can_reg {#define NBTP_NTSEG2_SHIFT 0#define NBTP_NTSEG2_MASK (0x7f << NBTP_NTSEG2_SHIFT) +/* Timestamp Counter Configuration Register (TSCC) */ +#define TSCC_TCP_MASK GENMASK(19, 16) +#define TSCC_TSS_MASK GENMASK(1, 0) +#define TSCC_TSS_DISABLE 0x0 +#define TSCC_TSS_INTERNAL 0x1 +#define TSCC_TSS_EXTERNAL 0x2 + +/* Timestamp Counter Value Register (TSCV) */ +#define TSCV_TSC_MASK GENMASK(15, 0) +/* Error Counter Register(ECR) */ #define ECR_RP BIT(15)#define ECR_REC_SHIFT 8
@@ -302,6 +313,7 @@ enum m_can_reg {#define RX_BUF_ANMF BIT(31)#define RX_BUF_FDF BIT(21)#define RX_BUF_BRS BIT(20) +#define RX_BUF_RXTS_MASK GENMASK(15, 0)/* Tx Buffer Element */ /* T0 */
@@ -319,6 +331,7 @@ enum m_can_reg {/* E1 */ #define TX_EVENT_MM_SHIFT TX_BUF_MM_SHIFT#define TX_EVENT_MM_MASK (0xff << TX_EVENT_MM_SHIFT) +#define TX_EVENT_TXTS_MASK GENMASK(15, 0)static inline u32 m_can_read (struct m_can_classdev *cdev,enum m_can_reg reg) {
@@ -413,6 +426,20 @@ static inline void m_can_disable_all_interrupts(struct m_can_classdev *cdev)m_can_write (cdev,M_CAN_ILE ,0x0 ); } +/* Retrieve internal timestamp counter from TSCV.TSC, and shift it to 32-bit +* width. +*/ +static u32 m_can_get_timestamp (struct m_can_classdev *cdev) +{ +u32 tscv; +u32 tsc; + + tscv =m_can_read (cdev,M_CAN_TSCV ); + tsc =FIELD_GET (TSCV_TSC_MASK , tscv); + +return (tsc <<16 ); +} +static void m_can_clean (struct net_device *net) {struct m_can_classdev *cdev =netdev_priv (net);
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 19/39 can: m_can: m_can_chip_config(): enable and configure internal timestamps
In reply to Marc Kleine-BuddeFrom: Torin Cooper-Bennun <[email protected]>
This is a prerequisite for transitioning the m_can driver to rx-offload, which works best with TX and RX timestamps.
The timestamps provided by M_CAN are 16-bit, timed according to the nominal bit timing, and may be prescaled by a multiplier up to 16. We choose the highest prescalar so that the timestamp wraps every 2^20 bit times, or 209 ms at a bus speed of 5 Mbit/s. Timestamps will have a precision of 16 bit times.
--- drivers/net/can/m_can/m_can.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/can/m_can/m_can.c +5 -0
@@ -1135,6 +1135,7 @@ static int m_can_set_bittiming(struct net_device *dev)* - >= v3.1.x: TX FIFO is used * - configure mode * - setup bittiming +* - configure timestamp generation */ static void m_can_chip_config (struct net_device *dev) {
@@ -1246,6 +1247,10 @@ static void m_can_chip_config(struct net_device *dev)/* set bittiming params */ m_can_set_bittiming (dev); +/* enable internal timestamp generation, with a prescalar of 16. The +* prescalar is applied to the nominal bit timing */ +m_can_write (cdev,M_CAN_TSCC ,FIELD_PREP (TSCC_TCP_MASK ,0xf )); +m_can_config_endisable (cdev, false);if (cdev->ops->init)
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 20/39 can: m_can: fix periph RX path: use rx-offload to ensure skbs are sent from softirq context
In reply to Marc Kleine-BuddeFrom: Torin Cooper-Bennun <[email protected]>
For peripheral devices, m_can sent skbs directly from a threaded irq instead of from a softirq context, breaking the tcan4x5x peripheral driver completely. This patch transitions the driver to use the rx-offload helper for peripherals, ensuring the skbs are sent from the correct context, with h/w timestamping to ensure correct ordering.
--- drivers/net/can/m_can/m_can.c | 121 +++++++++++++++++++++++++++++----- drivers/net/can/m_can/m_can.h | 2 + 2 files changed, 107 insertions(+), 16 deletions(-)
drivers/net/can/m_can/m_can.c +105 -16
@@ -457,6 +457,21 @@ static void m_can_clean(struct net_device *net) } } +/* For peripherals, pass skb to rx-offload, which will push skb from +* napi. For non-peripherals, RX is done in napi already, so push +* directly. timestamp is used to ensure good skb ordering in +* rx-offload and is ignored for non-peripherals. +*/ +static void m_can_receive_skb (struct m_can_classdev *cdev, +struct sk_buff *skb, +u32 timestamp) +{ +if (cdev->is_peripheral) +can_rx_offload_queue_sorted (&cdev->offload, skb, timestamp); +else +netif_receive_skb (skb); +} +static void m_can_read_fifo (struct net_device *dev,u32 rxfs) {struct net_device_stats *stats = &dev->stats;
@@ -464,6 +479,7 @@ static void m_can_read_fifo(struct net_device *dev, u32 rxfs)struct canfd_frame *cf;struct sk_buff *skb;u32 id, fgi, dlc; +u32 timestamp =0 ;int i;/* calculate the fifo get index for where to read data */
@@ -512,7 +528,9 @@ static void m_can_read_fifo(struct net_device *dev, u32 rxfs) stats->rx_packets++; stats->rx_bytes += cf->len; -netif_receive_skb (skb); + timestamp =FIELD_GET (RX_BUF_RXTS_MASK , dlc); + +m_can_receive_skb (cdev, skb, timestamp); }static int m_can_do_rx_poll (struct net_device *dev,int quota)
@@ -543,9 +561,11 @@ static int m_can_do_rx_poll(struct net_device *dev, int quota)static int m_can_handle_lost_msg (struct net_device *dev) { +struct m_can_classdev *cdev =netdev_priv (dev);struct net_device_stats *stats = &dev->stats;struct sk_buff *skb;struct can_frame *frame; +u32 timestamp =0 ;netdev_err (dev,"msg lost in rxf0\n" );
@@ -559,7 +579,10 @@ static int m_can_handle_lost_msg(struct net_device *dev) frame->can_id |=CAN_ERR_CRTL ; frame->data[1 ] =CAN_ERR_CRTL_RX_OVERFLOW ; -netif_receive_skb (skb); +if (cdev->is_peripheral) + timestamp =m_can_get_timestamp (cdev); + +m_can_receive_skb (cdev, skb, timestamp);return 1 ; }
@@ -571,6 +594,7 @@ static int m_can_handle_lec_err(struct net_device *dev,struct net_device_stats *stats = &dev->stats;struct can_frame *cf;struct sk_buff *skb; +u32 timestamp =0 ; cdev->can.can_stats.bus_error++; stats->rx_errors++;
@@ -616,7 +640,11 @@ static int m_can_handle_lec_err(struct net_device *dev, stats->rx_packets++; stats->rx_bytes += cf->len; -netif_receive_skb (skb); + +if (cdev->is_peripheral) + timestamp =m_can_get_timestamp (cdev); + +m_can_receive_skb (cdev, skb, timestamp);return 1 ; }
@@ -674,6 +702,7 @@ static int m_can_handle_state_change(struct net_device *dev,struct sk_buff *skb;struct can_berr_counter bec;unsigned int ecr; +u32 timestamp =0 ;switch (new_state) {case CAN_STATE_ERROR_WARNING :
@@ -735,7 +764,11 @@ static int m_can_handle_state_change(struct net_device *dev, stats->rx_packets++; stats->rx_bytes += cf->len; -netif_receive_skb (skb); + +if (cdev->is_peripheral) + timestamp =m_can_get_timestamp (cdev); + +m_can_receive_skb (cdev, skb, timestamp);return 1 ; }
@@ -800,6 +833,7 @@ static int m_can_handle_protocol_error(struct net_device *dev, u32 irqstatus)struct m_can_classdev *cdev =netdev_priv (dev);struct can_frame *cf;struct sk_buff *skb; +u32 timestamp =0 ;/* propagate the error condition to the CAN stack */ skb =alloc_can_err_skb (dev, &cf);
@@ -821,7 +855,11 @@ static int m_can_handle_protocol_error(struct net_device *dev, u32 irqstatus)netdev_dbg (dev,"allocation of skb failed\n" );return 0 ; } -netif_receive_skb (skb); + +if (cdev->is_peripheral) + timestamp =m_can_get_timestamp (cdev); + +m_can_receive_skb (cdev, skb, timestamp);return 1 ; }
@@ -922,6 +960,29 @@ static int m_can_poll(struct napi_struct *napi, int quota)return work_done; } +/* Echo tx skb and update net stats. Peripherals use rx-offload for +* echo. timestamp is used for peripherals to ensure correct ordering +* by rx-offload, and is ignored for non-peripherals. +*/ +static void m_can_tx_update_stats (struct m_can_classdev *cdev, +unsigned int msg_mark, +u32 timestamp) +{ +struct net_device *dev = cdev->net; +struct net_device_stats *stats = &dev->stats; + +if (cdev->is_peripheral) + stats->tx_bytes += +can_rx_offload_get_echo_skb (&cdev->offload, + msg_mark, + timestamp, +NULL ); +else + stats->tx_bytes +=can_get_echo_skb (dev, msg_mark,NULL ); + + stats->tx_packets++; +} +static void m_can_echo_tx_event (struct net_device *dev) {u32 txe_count =0 ;
@@ -931,7 +992,6 @@ static void m_can_echo_tx_event(struct net_device *dev)unsigned int msg_mark;struct m_can_classdev *cdev =netdev_priv (dev); -struct net_device_stats *stats = &dev->stats;/* read tx event fifo status */ m_can_txefs =m_can_read (cdev,M_CAN_TXEFS );
@@ -941,21 +1001,23 @@ static void m_can_echo_tx_event(struct net_device *dev)/* Get and process all sent elements */ for (i =0 ; i < txe_count; i++) { +u32 txe, timestamp =0 ; +/* retrieve get index */ fgi = (m_can_read (cdev,M_CAN_TXEFS ) &TXEFS_EFGI_MASK ) >>TXEFS_EFGI_SHIFT ; -/* get message marker */ - msg_mark = (m_can_txe_fifo_read (cdev, fgi,4 ) & -TX_EVENT_MM_MASK ) >>TX_EVENT_MM_SHIFT ; +/* get message marker, timestamp */ + txe =m_can_txe_fifo_read (cdev, fgi,4 ); + msg_mark = (txe &TX_EVENT_MM_MASK ) >>TX_EVENT_MM_SHIFT ; + timestamp =FIELD_GET (TX_EVENT_TXTS_MASK , txe);/* ack txe element */ m_can_write (cdev,M_CAN_TXEFA , (TXEFA_EFAI_MASK & (fgi <<TXEFA_EFAI_SHIFT )));/* update stats */ - stats->tx_bytes +=can_get_echo_skb (dev, msg_mark,NULL ); - stats->tx_packets++; +m_can_tx_update_stats (cdev, msg_mark, timestamp); } }
@@ -963,7 +1025,6 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) {struct net_device *dev = (struct net_device *)dev_id;struct m_can_classdev *cdev =netdev_priv (dev); -struct net_device_stats *stats = &dev->stats;u32 ir;if (pm_runtime_suspended (cdev->dev))
@@ -996,8 +1057,12 @@ static irqreturn_t m_can_isr(int irq, void *dev_id)if (cdev->version ==30 ) {if (ir &IR_TC ) {/* Transmission Complete Interrupt*/ - stats->tx_bytes +=can_get_echo_skb (dev,0 ,NULL ); - stats->tx_packets++; +u32 timestamp =0 ; + +if (cdev->is_peripheral) + timestamp =m_can_get_timestamp (cdev); +m_can_tx_update_stats (cdev,0 , timestamp); +can_led_event (dev,CAN_LED_EVENT_TX );netif_wake_queue (dev); }
@@ -1458,6 +1523,9 @@ static int m_can_close(struct net_device *dev) cdev->tx_wq =NULL ; } +if (cdev->is_peripheral) +can_rx_offload_disable (&cdev->offload); +close_candev (dev);can_led_event (dev,CAN_LED_EVENT_STOP );
@@ -1656,6 +1724,9 @@ static int m_can_open(struct net_device *dev) goto exit_disable_clks; } +if (cdev->is_peripheral) +can_rx_offload_enable (&cdev->offload); +/* register interrupt handler */ if (cdev->is_peripheral) { cdev->tx_skb =NULL ;
@@ -1697,6 +1768,8 @@ static int m_can_open(struct net_device *dev)if (cdev->is_peripheral)destroy_workqueue (cdev->tx_wq); out_wq_fail: +if (cdev->is_peripheral) +can_rx_offload_disable (&cdev->offload);close_candev (dev); exit_disable_clks:m_can_clk_stop (cdev);
@@ -1845,15 +1918,22 @@ int m_can_class_register(struct m_can_classdev *cdev)return ret; } +if (cdev->is_peripheral) { + ret =can_rx_offload_add_manual (cdev->net, &cdev->offload, +M_CAN_NAPI_WEIGHT ); +if (ret) + goto clk_disable; + } + ret =m_can_dev_setup (cdev);if (ret) - goto clk_disable; + goto rx_offload_del; ret =register_m_can_dev (cdev->net);if (ret) {dev_err (cdev->dev,"registering %s failed (err=%d)\n" , cdev->net->name, ret); - goto clk_disable; + goto rx_offload_del; }devm_can_led_init (cdev->net);
@@ -1866,6 +1946,13 @@ int m_can_class_register(struct m_can_classdev *cdev)/* Probe finished * Stop clocks. They will be reactivated once the M_CAN device is opened */ +m_can_clk_stop (cdev); + +return 0 ; + +rx_offload_del: +if (cdev->is_peripheral) +can_rx_offload_del (&cdev->offload); clk_disable:m_can_clk_stop (cdev);
@@ -1875,6 +1962,8 @@ EXPORT_SYMBOL_GPL(m_can_class_register);void m_can_class_unregister (struct m_can_classdev *cdev) { +if (cdev->is_peripheral) +can_rx_offload_del (&cdev->offload);unregister_candev (cdev->net); }EXPORT_SYMBOL_GPL (m_can_class_unregister);
drivers/net/can/m_can/m_can.h +2 -0
@@ -8,6 +8,7 @@#include <linux/can/core.h> #include <linux/can/led.h> +#include <linux/can/rx-offload.h> #include <linux/completion.h> #include <linux/device.h> #include <linux/dma-mapping.h>
@@ -71,6 +72,7 @@ struct m_can_ops {struct m_can_classdev {struct can_priv can; +struct can_rx_offload offload;struct napi_struct napi;struct net_device *net;struct device *dev;
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 21/39 can: tcan4x5x: remove duplicate include of regmap.h
In reply to Marc Kleine-BuddeFrom: Wan Jiabing <[email protected]>
linux/regmap.h has been included at line 13, so remove the duplicate one at line 14.
--- drivers/net/can/m_can/tcan4x5x.h | 1 - 1 file changed, 1 deletion(-)
drivers/net/can/m_can/tcan4x5x.h +0 -1
@@ -11,7 +11,6 @@#include <linux/gpio/consumer.h> #include <linux/regmap.h> -#include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/spi/spi.h>
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 22/39 can: mcp251xfd: add dev coredump support
In reply to Marc Kleine-BuddeFor easier debugging this patch adds dev coredump support to the driver. A dev coredump is generated in case the chip fails to start or an error in the interrupt handler is detected.
The dev coredump consists of all chip registers and chip memory, as well as the driver's internal state of the TEF-, RX- and TX-FIFOs, it can be analyzed with the mcp251xfd-dump tool of the can-utils:
https://github.com/linux-can/can-utils/tree/master/mcp251xfd
--- drivers/net/can/spi/mcp251xfd/Kconfig | 1 + drivers/net/can/spi/mcp251xfd/Makefile | 2 + .../net/can/spi/mcp251xfd/mcp251xfd-core.c | 2 + .../net/can/spi/mcp251xfd/mcp251xfd-dump.c | 285 ++++++++++++++++++ .../net/can/spi/mcp251xfd/mcp251xfd-dump.h | 45 +++ drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 8 + 6 files changed, 343 insertions(+) create mode 100644 drivers/net/can/spi/mcp251xfd/mcp251xfd-dump.c create mode 100644 drivers/net/can/spi/mcp251xfd/mcp251xfd-dump.h
drivers/net/can/spi/mcp251xfd/Kconfig +1 -0
@@ -3,6 +3,7 @@ config CAN_MCP251XFD tristate "Microchip MCP251xFD SPI CAN controllers" select REGMAP + select WANT_DEV_COREDUMP help Driver for the Microchip MCP251XFD SPI FD-CAN controller family.
drivers/net/can/spi/mcp251xfd/Makefile +2 -0
@@ -6,3 +6,5 @@ mcp251xfd-objs := mcp251xfd-objs += mcp251xfd-core.o mcp251xfd-objs += mcp251xfd-crc16.o mcp251xfd-objs += mcp251xfd-regmap.o + +mcp251xfd-$(CONFIG_DEV_COREDUMP) += mcp251xfd-dump.o
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2 -0
@@ -1097,6 +1097,7 @@ static int mcp251xfd_chip_start(struct mcp251xfd_priv *priv)return 0 ; out_chip_stop: +mcp251xfd_dump (priv);mcp251xfd_chip_stop (priv,CAN_STATE_STOPPED );return err;
@@ -2277,6 +2278,7 @@ static irqreturn_t mcp251xfd_irq(int irq, void *dev_id) out_fail:netdev_err (priv->ndev,"IRQ handler returned %d (intf=0x%08x).\n" , err, priv->regs_status.intf); +mcp251xfd_dump (priv);mcp251xfd_chip_interrupts_disable (priv);return handled;
drivers/net/can/spi/mcp251xfd/mcp251xfd-dump.c new file +285 -0
285 lines not on this page · raw message
drivers/net/can/spi/mcp251xfd/mcp251xfd-dump.h new file +45 -0
45 lines not on this page · raw message
drivers/net/can/spi/mcp251xfd/mcp251xfd.h +8 -0
@@ -838,4 +838,12 @@ u16 mcp251xfd_crc16_compute2(const void *cmd, size_t cmd_size, const void *data, size_t data_size);u16 mcp251xfd_crc16_compute (const void *data,size_t data_size); +#if IS_ENABLED (CONFIG_DEV_COREDUMP ) +void mcp251xfd_dump (const struct mcp251xfd_priv *priv); +#else +static inline void mcp251xfd_dump (const struct mcp251xfd_priv *priv) +{ +} +#endif +#endif
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 23/39 can: mcp251xfd: simplify UINC handling
In reply to Marc Kleine-BuddeIn the patches:
| 1f652bb6bae7 can: mcp25xxfd: rx-path: reduce number of SPI core requests to set UINC bit | 68c0c1c7f966 can: mcp251xfd: tef-path: reduce number of SPI core requests to set UINC bit
the setting of the UINC bit in the TEF and RX FIFO was batched into a single SPI message consisting of several transfers. All transfers but the last need to have the cs_change set to 1.
In the original patches the array of prepared transfers is send from the beginning with the length depending on the number of read TEF/RX objects. The cs_change of the last transfer is temporarily set to 0 during send.
This patch removes the modification of cs_change by preparing the last transfer with cs_change to 0 and all other to 1. When sending the SPI message the driver now starts with an offset into the array, so that it always ends on the last entry in the array, which has the cs_change set to 0.
--- .../net/can/spi/mcp251xfd/mcp251xfd-core.c | 69 ++++++++++--------- 1 file changed, 37 insertions(+), 32 deletions(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +37 -32
@@ -2,8 +2,8 @@// // mcp251xfd - Microchip MCP251xFD Family CAN controller driver // -// Copyright (c) 2019, 2020 Pengutronix, -// Marc Kleine-Budde <[email protected]> +// Copyright (c) 2019, 2020, 2021 Pengutronix, +// Marc Kleine-Budde <[email protected]> // // Based on: //
@@ -330,6 +330,7 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv)struct mcp251xfd_tx_ring *tx_ring;struct mcp251xfd_rx_ring *rx_ring, *prev_rx_ring =NULL ;struct mcp251xfd_tx_obj *tx_obj; +struct spi_transfer *xfer;u32 val;u16 addr;u8 len;
@@ -347,8 +348,6 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv) addr, val, val);for (j =0 ; j <ARRAY_SIZE (tef_ring->uinc_xfer); j++) { -struct spi_transfer *xfer; - xfer = &tef_ring->uinc_xfer[j]; xfer->tx_buf = &tef_ring->uinc_buf; xfer->len = len;
@@ -357,6 +356,15 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv) xfer->cs_change_delay.unit =SPI_DELAY_UNIT_NSECS ; } +/* "cs_change == 1" on the last transfer results in an active +* chip select after the complete SPI message. This causes the +* controller to interpret the next register access as +* data. Set "cs_change" of the last transfer to "0" to +* properly deactivate the chip select at the end of the +* message. +*/ + xfer->cs_change =0 ; +/* TX */ tx_ring = priv->tx; tx_ring->head =0 ;
@@ -397,8 +405,6 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv) addr, val, val);for (j =0 ; j <ARRAY_SIZE (rx_ring->uinc_xfer); j++) { -struct spi_transfer *xfer; - xfer = &rx_ring->uinc_xfer[j]; xfer->tx_buf = &rx_ring->uinc_buf; xfer->len = len;
@@ -406,6 +412,15 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv) xfer->cs_change_delay.value =0 ; xfer->cs_change_delay.unit =SPI_DELAY_UNIT_NSECS ; } + +/* "cs_change == 1" on the last transfer results in an +* active chip select after the complete SPI +* message. This causes the controller to interpret +* the next register access as data. Set "cs_change" +* of the last transfer to "0" to properly deactivate +* the chip select at the end of the message. +*/ + xfer->cs_change =0 ; } }
@@ -1366,25 +1381,20 @@ static int mcp251xfd_handle_tefif(struct mcp251xfd_priv *priv)if (len) {struct mcp251xfd_tef_ring *ring = priv->tef;struct mcp251xfd_tx_ring *tx_ring = priv->tx; -struct spi_transfer *last_xfer; +int offset;/* Increment the TEF FIFO tail pointer 'len' times in * a single SPI message. * * Note: -* -* "cs_change == 1" on the last transfer results in an -* active chip select after the complete SPI -* message. This causes the controller to interpret -* the next register access as data. Temporary set -* "cs_change" of the last transfer to "0" to properly -* deactivate the chip select at the end of the -* message. +* Calculate offset, so that the SPI transfer ends on +* the last message of the uinc_xfer array, which has +* "cs_change == 0", to properly deactivate the chip +* select. */ - last_xfer = &ring->uinc_xfer[len -1 ]; - last_xfer->cs_change =0 ; - err =spi_sync_transfer (priv->spi, ring->uinc_xfer, len); - last_xfer->cs_change =1 ; + offset =ARRAY_SIZE (ring->uinc_xfer) - len; + err =spi_sync_transfer (priv->spi, + ring->uinc_xfer + offset, len);if (err)return err;
@@ -1536,7 +1546,7 @@ mcp251xfd_handle_rxif_ring(struct mcp251xfd_priv *priv,return err;while ((len =mcp251xfd_get_rx_linear_len (ring))) { -struct spi_transfer *last_xfer; +int offset; rx_tail =mcp251xfd_get_rx_tail (ring);
@@ -1557,19 +1567,14 @@ mcp251xfd_handle_rxif_ring(struct mcp251xfd_priv *priv,* single SPI message. * * Note: -* -* "cs_change == 1" on the last transfer results in an -* active chip select after the complete SPI -* message. This causes the controller to interpret -* the next register access as data. Temporary set -* "cs_change" of the last transfer to "0" to properly -* deactivate the chip select at the end of the -* message. +* Calculate offset, so that the SPI transfer ends on +* the last message of the uinc_xfer array, which has +* "cs_change == 0", to properly deactivate the chip +* select. */ - last_xfer = &ring->uinc_xfer[len -1 ]; - last_xfer->cs_change =0 ; - err =spi_sync_transfer (priv->spi, ring->uinc_xfer, len); - last_xfer->cs_change =1 ; + offset =ARRAY_SIZE (ring->uinc_xfer) - len; + err =spi_sync_transfer (priv->spi, + ring->uinc_xfer + offset, len);if (err)return err;
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 24/39 can: mcp251xfd: move netdevice.h to mcp251xfd.h
In reply to Marc Kleine-BuddeThe netdevice.h header is needed in mcp251xfd.h, so that it can be included without further headers.
--- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 1 - drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +0 -1
@@ -16,7 +16,6 @@#include <linux/clk.h> #include <linux/device.h> #include <linux/module.h> -#include <linux/netdevice.h> #include <linux/of.h> #include <linux/of_device.h> #include <linux/pm_runtime.h>
drivers/net/can/spi/mcp251xfd/mcp251xfd.h +1 -0
@@ -15,6 +15,7 @@#include <linux/can/rx-offload.h> #include <linux/gpio/consumer.h> #include <linux/kernel.h> +#include <linux/netdevice.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/spi/spi.h>
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 25/39 can: mcp251xfd: mcp251xfd_get_timestamp(): move to mcp251xfd.h
In reply to Marc Kleine-BuddeThis is a preparation patch, it moves the mcp251xfd_get_timestamp() function into the mcp251xfd.h file.
--- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 6 ------ drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +0 -6
@@ -1597,12 +1597,6 @@ static int mcp251xfd_handle_rxif(struct mcp251xfd_priv *priv)return 0 ; } -static inline int mcp251xfd_get_timestamp (const struct mcp251xfd_priv *priv, -u32 *timestamp) -{ -return regmap_read (priv->map_reg,MCP251XFD_REG_TBC , timestamp); -} -static struct sk_buff *mcp251xfd_alloc_can_err_skb (const struct mcp251xfd_priv *priv,struct can_frame **cf,u32 *timestamp)
drivers/net/can/spi/mcp251xfd/mcp251xfd.h +6 -0
@@ -728,6 +728,12 @@ mcp251xfd_spi_cmd_write(const struct mcp251xfd_priv *priv,return data; } +static inline int mcp251xfd_get_timestamp (const struct mcp251xfd_priv *priv, +u32 *timestamp) +{ +return regmap_read (priv->map_reg,MCP251XFD_REG_TBC , timestamp); +} +static inline u16 mcp251xfd_get_tef_obj_addr (u8 n) { return MCP251XFD_RAM_START +
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 26/39 can: mcp251xfd: add HW timestamp infrastructure
In reply to Marc Kleine-BuddeThis patch add the HW timestamping infrastructure. The mcp251xfd has a free running timer of 32 bit width, running at max 40MHz, which wraps around every 107 seconds. The current timestamp is latched into RX and TEF objects automatically be the CAN controller.
This patch sets up a cyclecounter, timecounter and delayed worker infrastructure (which runs every 45 seconds) to convert the timer into a proper 64 bit based ns timestamp.
--- drivers/net/can/spi/mcp251xfd/Makefile | 1 + .../net/can/spi/mcp251xfd/mcp251xfd-core.c | 3 + .../can/spi/mcp251xfd/mcp251xfd-timestamp.c | 71 +++++++++++++++++++ drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 13 ++++ 4 files changed, 88 insertions(+) create mode 100644 drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c
drivers/net/can/spi/mcp251xfd/Makefile +1 -0
@@ -6,5 +6,6 @@ mcp251xfd-objs := mcp251xfd-objs += mcp251xfd-core.o mcp251xfd-objs += mcp251xfd-crc16.o mcp251xfd-objs += mcp251xfd-regmap.o +mcp251xfd-objs += mcp251xfd-timestamp.o mcp251xfd-$(CONFIG_DEV_COREDUMP) += mcp251xfd-dump.o
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +3 -0
@@ -2493,6 +2493,7 @@ static int mcp251xfd_open(struct net_device *ndev)if (err) goto out_transceiver_disable; +mcp251xfd_timestamp_init (priv);can_rx_offload_enable (&priv->offload); err = request_threaded_irq(spi->irq, NULL, mcp251xfd_irq,
@@ -2513,6 +2514,7 @@ static int mcp251xfd_open(struct net_device *ndev)free_irq (spi->irq, priv); out_can_rx_offload_disable:can_rx_offload_disable (&priv->offload); +mcp251xfd_timestamp_stop (priv); out_transceiver_disable:mcp251xfd_transceiver_disable (priv); out_mcp251xfd_ring_free:
@@ -2534,6 +2536,7 @@ static int mcp251xfd_stop(struct net_device *ndev)mcp251xfd_chip_interrupts_disable (priv);free_irq (ndev->irq, priv);can_rx_offload_disable (&priv->offload); +mcp251xfd_timestamp_stop (priv);mcp251xfd_chip_stop (priv,CAN_STATE_STOPPED );mcp251xfd_transceiver_disable (priv);mcp251xfd_ring_free (priv);
drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c new file +71 -0
71 lines not on this page · raw message
drivers/net/can/spi/mcp251xfd/mcp251xfd.h +13 -0
@@ -19,6 +19,8 @@#include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/spi/spi.h> +#include <linux/timecounter.h> +#include <linux/workqueue.h> /* MPC251x registers */
@@ -395,6 +397,9 @@#define MCP251XFD_SYSCLOCK_HZ_MAX 40000000#define MCP251XFD_SYSCLOCK_HZ_MIN 1000000#define MCP251XFD_SPICLOCK_HZ_MAX 20000000 +#define MCP251XFD_TIMESTAMP_WORK_DELAY_SEC 45 +static_assert (MCP251XFD_TIMESTAMP_WORK_DELAY_SEC < +CYCLECOUNTER_MASK (32 ) /MCP251XFD_SYSCLOCK_HZ_MAX /2 );#define MCP251XFD_OSC_PLL_MULTIPLIER 10#define MCP251XFD_OSC_STAB_SLEEP_US (3 * USEC_PER_MSEC)#define MCP251XFD_OSC_STAB_TIMEOUT_US (10 * MCP251XFD_OSC_STAB_SLEEP_US)
@@ -596,6 +601,10 @@ struct mcp251xfd_priv {struct mcp251xfd_ecc ecc;struct mcp251xfd_regs_status regs_status; +struct cyclecounter cc; +struct timecounter tc; +struct delayed_work timestamp; +struct gpio_desc *rx_int;struct clk *clk;struct regulator *reg_vdd;
@@ -844,6 +853,10 @@ int mcp251xfd_regmap_init(struct mcp251xfd_priv *priv);u16 mcp251xfd_crc16_compute2 (const void *cmd,size_t cmd_size,const void *data,size_t data_size);u16 mcp251xfd_crc16_compute (const void *data,size_t data_size); +void mcp251xfd_skb_set_timestamp (struct mcp251xfd_priv *priv, +struct sk_buff *skb,u32 timestamp); +void mcp251xfd_timestamp_init (struct mcp251xfd_priv *priv); +void mcp251xfd_timestamp_stop (struct mcp251xfd_priv *priv);#if IS_ENABLED (CONFIG_DEV_COREDUMP )void mcp251xfd_dump (const struct mcp251xfd_priv *priv);
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 27/39 can: mcp251xfd: add HW timestamp to RX, TX and error CAN frames
In reply to Marc Kleine-BuddeThis patch uses the previously added mcp251xfd_skb_set_timestamp() function to convert the timestamp done by the CAN controller into a proper skb hw timestamp.
--- .../net/can/spi/mcp251xfd/mcp251xfd-core.c | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +18 -5
@@ -1265,7 +1265,8 @@ mcp251xfd_handle_tefif_one(struct mcp251xfd_priv *priv, const struct mcp251xfd_hw_tef_obj *hw_tef_obj) {struct net_device_stats *stats = &priv->ndev->stats; -u32 seq, seq_masked, tef_tail_masked; +struct sk_buff *skb; +u32 seq, seq_masked, tef_tail_masked, tef_tail; seq =FIELD_GET (MCP251XFD_OBJ_FLAGS_SEQ_MCP2518FD_MASK , hw_tef_obj->flags);
@@ -1281,9 +1282,13 @@ mcp251xfd_handle_tefif_one(struct mcp251xfd_priv *priv,if (seq_masked != tef_tail_masked)return mcp251xfd_handle_tefif_recover (priv, seq); + tef_tail =mcp251xfd_get_tef_tail (priv); + skb = priv->can.echo_skb[tef_tail]; +if (skb) +mcp251xfd_skb_set_timestamp (priv, skb, hw_tef_obj->ts); stats->tx_bytes +=can_rx_offload_get_echo_skb (&priv->offload, -mcp251xfd_get_tef_tail (priv), + tef_tail, hw_tef_obj->ts,NULL ); stats->tx_packets++; priv->tef->tail++;
@@ -1442,7 +1447,7 @@ mcp251xfd_rx_ring_update(const struct mcp251xfd_priv *priv, }static void -mcp251xfd_hw_rx_obj_to_skb (const struct mcp251xfd_priv *priv, +mcp251xfd_hw_rx_obj_to_skb (struct mcp251xfd_priv *priv,const struct mcp251xfd_hw_rx_obj_canfd *hw_rx_obj,struct sk_buff *skb) {
@@ -1485,6 +1490,8 @@ mcp251xfd_hw_rx_obj_to_skb(const struct mcp251xfd_priv *priv,if (!(hw_rx_obj->flags &MCP251XFD_OBJ_FLAGS_RTR ))memcpy (cfd->data, hw_rx_obj->data, cfd->len); + +mcp251xfd_skb_set_timestamp (priv, skb, hw_rx_obj->ts); } static int
@@ -1598,16 +1605,21 @@ static int mcp251xfd_handle_rxif(struct mcp251xfd_priv *priv) }static struct sk_buff * -mcp251xfd_alloc_can_err_skb (const struct mcp251xfd_priv *priv, +mcp251xfd_alloc_can_err_skb (struct mcp251xfd_priv *priv,struct can_frame **cf,u32 *timestamp) { +struct sk_buff *skb;int err; err =mcp251xfd_get_timestamp (priv, timestamp);if (err)return NULL ; -return alloc_can_err_skb (priv->ndev, cf); + skb =alloc_can_err_skb (priv->ndev, cf); +if (skb) +mcp251xfd_skb_set_timestamp (priv, skb, *timestamp); + +return skb; }static int mcp251xfd_handle_rxovif (struct mcp251xfd_priv *priv)
@@ -1759,6 +1771,7 @@ static int mcp251xfd_handle_ivmif(struct mcp251xfd_priv *priv)if (!cf)return 0 ; +mcp251xfd_skb_set_timestamp (priv, skb, timestamp); err =can_rx_offload_queue_sorted (&priv->offload, skb, timestamp);if (err) stats->rx_fifo_errors++;
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 28/39 can: c_can: convert block comments to network style comments
In reply to Marc Kleine-BuddeThis patch converts all block comments to network subsystem style block comments.
--- drivers/net/can/c_can/c_can.c | 52 ++++++++++--------------------- drivers/net/can/c_can/c_can_pci.c | 3 +- 2 files changed, 18 insertions(+), 37 deletions(-)
drivers/net/can/c_can/c_can.c +17 -35
@@ -161,9 +161,7 @@#define IF_MCONT_TX (IF_MCONT_TXIE | IF_MCONT_EOB) -/* -* Use IF1 for RX and IF2 for TX -*/ +/* Use IF1 for RX and IF2 for TX */ #define IF_RX 0#define IF_TX 1
@@ -189,8 +187,7 @@ enum c_can_lec_type { LEC_MASK = LEC_UNUSED, }; -/* -* c_can error types: +/* c_can error types: * Bus errors (BUS_OFF, ERROR_WARNING, ERROR_PASSIVE) are supported */ enum c_can_bus_error_types {
@@ -268,8 +265,7 @@ static inline void c_can_object_put(struct net_device *dev, int iface,c_can_obj_update (dev, iface, cmd |IF_COMM_WR , obj); } -/* -* Note: According to documentation clearing TXIE while MSGVAL is set +/* Note: According to documentation clearing TXIE while MSGVAL is set * is not allowed, but works nicely on C/DCAN. And that lowers the I/O * load significantly. */
@@ -309,8 +305,7 @@ static void c_can_setup_tx_object(struct net_device *dev, int iface,if (!rtr) arb |=IF_ARB_TRANSMIT ; -/* -* If we change the DIR bit, we need to invalidate the buffer +/* If we change the DIR bit, we need to invalidate the buffer * first, i.e. clear the MSGVAL flag in the arbiter. */ if (rtr != (bool )test_bit (idx, &priv->tx_dir)) {
@@ -447,8 +442,7 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,if (can_dropped_invalid_skb (dev, skb))return NETDEV_TX_OK ; -/* -* This is not a FIFO. C/D_CAN sends out the buffers +/* This is not a FIFO. C/D_CAN sends out the buffers * prioritized. The lowest buffer number wins. */ idx =fls (atomic_read (&priv->tx_active));
@@ -457,8 +451,7 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,/* If this is the last buffer, stop the xmit queue */ if (idx ==C_CAN_MSG_OBJ_TX_NUM -1 )netif_stop_queue (dev); -/* -* Store the message in the interface so we can call +/* Store the message in the interface so we can call * can_put_echo_skb(). We must do this before we enable * transmit as we might race against do_tx(). */
@@ -527,8 +520,7 @@ static int c_can_set_bittiming(struct net_device *dev)return c_can_wait_for_ctrl_init (dev, priv,0 ); } -/* -* Configure C_CAN message objects for Tx and Rx purposes: +/* Configure C_CAN message objects for Tx and Rx purposes: * C_CAN provides a total of 32 message objects that can be configured * either for Tx or Rx purposes. Here the first 16 message objects are used as * a reception FIFO. The end of reception FIFO is signified by the EoB bit
@@ -572,8 +564,7 @@ static int c_can_software_reset(struct net_device *dev)return 0 ; } -/* -* Configure C_CAN chip: +/* Configure C_CAN chip: * - enable/disable auto-retransmission * - set operating mode * - configure message objects
@@ -739,8 +730,7 @@ static void c_can_do_tx(struct net_device *dev) } } -/* -* If we have a gap in the pending bits, that means we either +/* If we have a gap in the pending bits, that means we either * raced with the hardware or failed to readout all upper * objects in the last run due to quota limit. */
@@ -751,8 +741,7 @@ static u32 c_can_adjust_pending(u32 pend)if (pend ==RECEIVE_OBJECT_BITS )return pend; -/* -* If the last set bit is larger than the number of pending +/* If the last set bit is larger than the number of pending * bits we have a gap. */ weight =hweight32 (pend);
@@ -762,8 +751,7 @@ static u32 c_can_adjust_pending(u32 pend)if (lasts == weight)return pend; -/* -* Find the first set bit after the gap. We walk backwards +/* Find the first set bit after the gap. We walk backwards * from the last set bit. */ for (lasts--; pend & (1 << (lasts -1 )); lasts--);
@@ -803,8 +791,7 @@ static int c_can_read_objects(struct net_device *dev, struct c_can_priv *priv,continue ; } -/* -* This really should not happen, but this covers some +/* This really should not happen, but this covers some * odd HW behaviour. Do not remove that unless you * want to brick your machine. */
@@ -830,8 +817,7 @@ static inline u32 c_can_get_pending(struct c_can_priv *priv)return pend; } -/* -* theory of operation: +/* theory of operation: * * c_can core saves a received CAN message into the first free message * object it finds free (starting with the lowest). Bits NEWDAT and
@@ -848,8 +834,7 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)struct c_can_priv *priv =netdev_priv (dev);u32 pkts =0 , pend =0 , toread, n; -/* -* It is faster to read only one 16bit register. This is only possible +/* It is faster to read only one 16bit register. This is only possible * for a maximum number of 16 objects. */ BUILD_BUG_ON_MSG(C_CAN_MSG_OBJ_RX_LAST > 16,
@@ -860,8 +845,7 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota) pend =c_can_get_pending (priv);if (!pend)break ; -/* -* If the pending field has a gap, handle the +/* If the pending field has a gap, handle the * bits above the gap first. */ toread =c_can_adjust_pending (pend);
@@ -979,8 +963,7 @@ static int c_can_handle_bus_err(struct net_device *dev,struct can_frame *cf;struct sk_buff *skb; -/* -* early exit if no lec update or no error. +/* early exit if no lec update or no error. * no lec update means that no CAN bus event has been detected * since CPU wrote 0x7 value to status reg. */
@@ -999,8 +982,7 @@ static int c_can_handle_bus_err(struct net_device *dev,if (unlikely (!skb))return 0 ; -/* -* check for 'last error code' which tells us the +/* check for 'last error code' which tells us the * type of the last error to occur on the CAN bus */ cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR ;
drivers/net/can/c_can/c_can_pci.c +1 -2
@@ -41,8 +41,7 @@ struct c_can_pci_data {void (*init)(const struct c_can_priv *priv,bool enable); }; -/* -* 16-bit c_can registers can be arranged differently in the memory +/* 16-bit c_can registers can be arranged differently in the memory * architecture of different implementations. For example: 16-bit * registers can be aligned to a 16-bit boundary or 32-bit boundary etc. * Handle the same by providing a common read/write interface.
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 29/39 can: c_can: remove unnecessary blank lines and add suggested ones
In reply to Marc Kleine-BuddeThis patch removes unnecessary blank lines and add suggested ones, so that checkpatch doesn't complain anymore.
--- drivers/net/can/c_can/c_can.c | 2 -- drivers/net/can/c_can/c_can_pci.c | 1 + 2 files changed, 1 insertion(+), 2 deletions(-)
drivers/net/can/c_can/c_can.c +0 -2
@@ -132,7 +132,6 @@/* For the high buffers we clear the interrupt bit and newdat */ #define IF_COMM_RCV_HIGH (IF_COMM_RCV_LOW | IF_COMM_CLR_NEWDAT) -/* Receive setup of message objects */ #define IF_COMM_RCV_SETUP (IF_COMM_MASK | IF_COMM_ARB | IF_COMM_CONTROL)
@@ -250,7 +249,6 @@ static void c_can_obj_update(struct net_device *dev, int iface, u32 cmd, u32 objudelay (1 ); }netdev_err (dev,"Updating object timed out\n" ); - } static inline void c_can_object_get(struct net_device *dev, int iface,
drivers/net/can/c_can/c_can_pci.c +1 -0
@@ -278,6 +278,7 @@ static const struct pci_device_id c_can_pci_tbl[] = { c_can_pch), {}, }; +static struct pci_driver c_can_pci_driver = { .name =KBUILD_MODNAME , .id_table = c_can_pci_tbl,
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 30/39 can: c_can: fix indention
In reply to Marc Kleine-BuddeThis patch fixes the indention in the driver.
--- drivers/net/can/c_can/c_can.c | 12 ++++++------ drivers/net/can/c_can/c_can.h | 10 +++++----- drivers/net/can/c_can/c_can_pci.c | 16 ++++++++-------- 3 files changed, 19 insertions(+), 19 deletions(-)
drivers/net/can/c_can/c_can.c +6 -6
@@ -502,7 +502,7 @@ static int c_can_set_bittiming(struct net_device *dev) reg_brpe = brpe &BRP_EXT_BRPE_MASK ;netdev_info (dev, -"setting BTR=%04x BRPE=%04x\n" , reg_btr, reg_brpe); +"setting BTR=%04x BRPE=%04x\n" , reg_btr, reg_brpe); ctrl_save = priv->read_reg (priv,C_CAN_CTRL_REG ); ctrl_save &= ~CONTROL_INIT ;
@@ -836,7 +836,7 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)* for a maximum number of 16 objects. */ BUILD_BUG_ON_MSG (C_CAN_MSG_OBJ_RX_LAST >16 , -"Implementation does not support more message objects than 16" ); +"Implementation does not support more message objects than 16" );while (quota >0 ) {if (!pend) {
@@ -865,7 +865,7 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota) }static int c_can_handle_state_change (struct net_device *dev, -enum c_can_bus_error_types error_type) +enum c_can_bus_error_types error_type) {unsigned int reg_err_counter;unsigned int rx_err_passive;
@@ -1127,7 +1127,7 @@ static int c_can_open(struct net_device *dev)/* register interrupt handler */ err =request_irq (dev->irq, &c_can_isr,IRQF_SHARED , dev->name, - dev); + dev);if (err <0 ) {netdev_err (dev,"failed to request interrupt\n" ); goto exit_irq_fail;
@@ -1219,7 +1219,7 @@ int c_can_power_down(struct net_device *dev)/* Wait for the PDA bit to get set */ time_out = jiffies +msecs_to_jiffies (INIT_WAIT_MS );while (!(priv->read_reg (priv,C_CAN_STS_REG ) &STATUS_PDA ) && -time_after (time_out, jiffies)) +time_after (time_out, jiffies))cpu_relax ();if (time_after (jiffies, time_out))
@@ -1260,7 +1260,7 @@ int c_can_power_up(struct net_device *dev)/* Wait for the PDA bit to get clear */ time_out = jiffies +msecs_to_jiffies (INIT_WAIT_MS );while ((priv->read_reg (priv,C_CAN_STS_REG ) &STATUS_PDA ) && -time_after (time_out, jiffies)) +time_after (time_out, jiffies))cpu_relax ();if (time_after (jiffies, time_out)) {
drivers/net/can/c_can/c_can.h +5 -5
@@ -201,16 +201,16 @@ struct c_can_priv {atomic_t sie_pending;unsigned long tx_dir;int last_status; -u16 (*read_reg) (const struct c_can_priv *priv,enum reg index); -void (*write_reg) (const struct c_can_priv *priv,enum reg index,u16 val); -u32 (*read_reg32) (const struct c_can_priv *priv,enum reg index); -void (*write_reg32) (const struct c_can_priv *priv,enum reg index,u32 val); +u16 (*read_reg)(const struct c_can_priv *priv,enum reg index); +void (*write_reg)(const struct c_can_priv *priv,enum reg index,u16 val); +u32 (*read_reg32)(const struct c_can_priv *priv,enum reg index); +void (*write_reg32)(const struct c_can_priv *priv,enum reg index,u32 val);void __iomem *base;const u16 *regs;void *priv;/* for board-specific data */ enum c_can_dev_id type;struct c_can_raminit raminit_sys;/* RAMINIT via syscon regmap */ -void (*raminit) (const struct c_can_priv *priv,bool enable); +void (*raminit)(const struct c_can_priv *priv,bool enable);u32 comm_rcv_high;u32 rxmasked;u32 dlc[C_CAN_MSG_OBJ_TX_NUM ];
drivers/net/can/c_can/c_can_pci.c +8 -8
@@ -47,25 +47,25 @@ struct c_can_pci_data {* Handle the same by providing a common read/write interface. */ static u16 c_can_pci_read_reg_aligned_to_16bit (const struct c_can_priv *priv, -enum reg index) +enum reg index) {return readw (priv->base + priv->regs[index]); }static void c_can_pci_write_reg_aligned_to_16bit (const struct c_can_priv *priv, -enum reg index,u16 val) +enum reg index,u16 val) {writew (val, priv->base + priv->regs[index]); }static u16 c_can_pci_read_reg_aligned_to_32bit (const struct c_can_priv *priv, -enum reg index) +enum reg index) {return readw (priv->base +2 * priv->regs[index]); }static void c_can_pci_write_reg_aligned_to_32bit (const struct c_can_priv *priv, -enum reg index,u16 val) +enum reg index,u16 val) {writew (val, priv->base +2 * priv->regs[index]); }
@@ -87,13 +87,13 @@ static u32 c_can_pci_read_reg32(const struct c_can_priv *priv, enum reg index)u32 val; val = priv->read_reg (priv, index); - val |= ((u32 ) priv->read_reg (priv, index +1 )) <<16 ; + val |= ((u32 )priv->read_reg (priv, index +1 )) <<16 ;return val; }static void c_can_pci_write_reg32 (const struct c_can_priv *priv,enum reg index, -u32 val) +u32 val) { priv->write_reg (priv, index +1 , val >>16 ); priv->write_reg (priv, index, val);
@@ -216,7 +216,7 @@ static int c_can_pci_probe(struct pci_dev *pdev, }dev_dbg (&pdev->dev,"%s device registered (regs=%p, irq=%d)\n" , -KBUILD_MODNAME , priv->regs, dev->irq); +KBUILD_MODNAME , priv->regs, dev->irq);return 0 ;
@@ -251,7 +251,7 @@ static void c_can_pci_remove(struct pci_dev *pdev)pci_disable_device (pdev); } -static const struct c_can_pci_data c_can_sta2x11= { +static const struct c_can_pci_data c_can_sta2x11 = { .type =BOSCH_C_CAN , .reg_align =C_CAN_REG_ALIGN_32 , .freq =52000000 ,/* 52 Mhz */
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 31/39 can: c_can: fix print formating string
In reply to Marc Kleine-BuddeThis patch fixes the print format string in the driver, so that it stays in a single line.
--- drivers/net/can/c_can/c_can_pci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/can/c_can/c_can_pci.c +1 -2
@@ -141,8 +141,7 @@ static int c_can_pci_probe(struct pci_dev *pdev, pci_resource_len(pdev, c_can_pci_data->bar));if (!addr) {dev_err (&pdev->dev, -"device has no PCI memory resources, " -"failing adapter\n" ); +"device has no PCI memory resources, failing adapter\n" ); ret = -ENOMEM ; goto out_release_regions; }
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 32/39 can: c_can: replace double assignments by two single ones
In reply to Marc Kleine-BuddeThis patch replaces the double assignments by two single ones, to make checkpatch happy.
--- drivers/net/can/c_can/c_can.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/can/c_can/c_can.c +4 -2
@@ -703,7 +703,8 @@ static void c_can_do_tx(struct net_device *dev)struct net_device_stats *stats = &dev->stats;u32 idx, obj, pkts =0 , bytes =0 , pend, clr; - clr = pend = priv->read_reg (priv,C_CAN_INTPND2_REG ); + pend = priv->read_reg (priv,C_CAN_INTPND2_REG ); + clr = pend;while ((idx =ffs (pend))) { idx--;
@@ -1029,7 +1030,8 @@ static int c_can_poll(struct napi_struct *napi, int quota)/* Only read the status register if a status interrupt was pending */ if (atomic_xchg (&priv->sie_pending,0 )) { - priv->last_status = curr = priv->read_reg (priv,C_CAN_STS_REG ); + priv->last_status = priv->read_reg (priv,C_CAN_STS_REG ); + curr = priv->last_status;/* Ack status on C_CAN. D_CAN is self clearing */ if (priv->type !=BOSCH_D_CAN ) priv->write_reg (priv,C_CAN_STS_REG ,LEC_UNUSED );
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 33/39 can: c_can: fix remaining checkpatch warnings
In reply to Marc Kleine-BuddeThis patch fixes the remaining checkpatch warnings in the driver.
--- drivers/net/can/c_can/c_can.c | 3 ++- drivers/net/can/c_can/c_can_pci.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/can/c_can/c_can.c +2 -1
@@ -753,7 +753,8 @@ static u32 c_can_adjust_pending(u32 pend)/* Find the first set bit after the gap. We walk backwards * from the last set bit. */ -for (lasts--; pend & (1 << (lasts -1 )); lasts--); +for (lasts--; pend & (1 << (lasts -1 )); lasts--) + ;return pend & ~((1 << lasts) -1 ); }
drivers/net/can/c_can/c_can_pci.c +1 -1
@@ -267,7 +267,7 @@ static const struct c_can_pci_data c_can_pch = {#define C_CAN_ID (_vend, _dev, _driverdata) { \ PCI_DEVICE(_vend, _dev), \ - .driver_data = (unsigned long)&_driverdata, \ + .driver_data = (unsigned long)&(_driverdata), \ }static const struct pci_device_id c_can_pci_tbl[] = {
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 34/39 can: c_can: remove unused code
In reply to Marc Kleine-BuddeFrom: Dario Binacchi <[email protected]>
Commit 9d23a9818cb1 ("can: c_can: Remove unused inline function") left behind C_CAN_MSG_OBJ_TX_LAST constant.
Commit fa39b54ccf28 ("can: c_can: Get rid of pointless interrupts") left behind C_CAN_MSG_RX_LOW_LAST and C_CAN_MSG_OBJ_RX_SPLIT constants.
The removed code also made a comment useless and misleading.
--- drivers/net/can/c_can/c_can.c | 3 +-- drivers/net/can/c_can/c_can.h | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-)
drivers/net/can/c_can/c_can.c +1 -2
@@ -822,8 +822,7 @@ static inline u32 c_can_get_pending(struct c_can_priv *priv)* c_can core saves a received CAN message into the first free message * object it finds free (starting with the lowest). Bits NEWDAT and * INTPND are set for this message object indicating that a new message -* has arrived. To work-around this issue, we keep two groups of message -* objects whose partitioning is defined by C_CAN_MSG_OBJ_RX_SPLIT. +* has arrived. * * We clear the newdat bit right away. *
drivers/net/can/c_can/c_can.h +0 -4
@@ -32,11 +32,7 @@ C_CAN_MSG_OBJ_RX_NUM - 1)#define C_CAN_MSG_OBJ_TX_FIRST (C_CAN_MSG_OBJ_RX_LAST + 1) -#define C_CAN_MSG_OBJ_TX_LAST (C_CAN_MSG_OBJ_TX_FIRST + \ - C_CAN_MSG_OBJ_TX_NUM - 1) -#define C_CAN_MSG_OBJ_RX_SPLIT 9 -#define C_CAN_MSG_RX_LOW_LAST (C_CAN_MSG_OBJ_RX_SPLIT - 1)#define RECEIVE_OBJECT_BITS 0x0000ffffenum reg {
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 35/39 can: c_can: fix indentation
In reply to Marc Kleine-BuddeFrom: Dario Binacchi <[email protected]>
Commit 524369e2391f ("can: c_can: remove obsolete STRICT_FRAME_ORDERING Kconfig option") left behind wrong indentation, fix it.
--- drivers/net/can/c_can/c_can.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/c_can/c_can.c +1 -1
@@ -762,7 +762,7 @@ static u32 c_can_adjust_pending(u32 pend)static inline void c_can_rx_object_get (struct net_device *dev,struct c_can_priv *priv,u32 obj) { -c_can_object_get (dev,IF_RX , obj, priv->comm_rcv_high); +c_can_object_get (dev,IF_RX , obj, priv->comm_rcv_high); } static inline void c_can_rx_finalize(struct net_device *dev,
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 36/39 can: c_can: add a comment about IF_RX interface's use
In reply to Marc Kleine-BuddeFrom: Dario Binacchi <[email protected]>
After reading the commit 640916db2bf7 ("can: c_can: Make it SMP safe") it may sound strange to see the IF_RX interface used by the can_inval_tx_object function. A comment was added to avoid any misunderstanding.
--- drivers/net/can/c_can/c_can.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/can/c_can/c_can.c +5 -0
@@ -710,6 +710,11 @@ static void c_can_do_tx(struct net_device *dev) idx--; pend &= ~(1 << idx); obj = idx +C_CAN_MSG_OBJ_TX_FIRST ; + +/* We use IF_RX interface instead of IF_TX because we +* are called from c_can_poll(), which runs inside +* NAPI. We are not trasmitting. +*/ c_can_inval_tx_object (dev,IF_RX , obj);can_get_echo_skb (dev, idx,NULL ); bytes += priv->dlc[idx];
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 37/39 can: c_can: use 32-bit write to set arbitration register
In reply to Marc Kleine-BuddeFrom: Dario Binacchi <[email protected]>
The arbitration register is already set up with 32-bit writes in the other parts of the code except for this point.
--- drivers/net/can/c_can/c_can.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/can/c_can/c_can.c +1 -2
@@ -279,8 +279,7 @@ static void c_can_inval_msg_object(struct net_device *dev, int iface, int obj) {struct c_can_priv *priv =netdev_priv (dev); - priv->write_reg (priv,C_CAN_IFACE (ARB1_REG , iface),0 ); - priv->write_reg (priv,C_CAN_IFACE (ARB2_REG , iface),0 ); + priv->write_reg32 (priv,C_CAN_IFACE (ARB1_REG , iface),0 );c_can_inval_tx_object (dev, iface, obj); }
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 38/39 can: c_can: prepare to up the message objects number
In reply to Marc Kleine-BuddeFrom: Dario Binacchi <[email protected]>
As pointed by commit c0a9f4d396c9 ("can: c_can: Reduce register access") the "driver casts the 16 message objects in stone, which is completely braindead as contemporary hardware has up to 128 message objects".
The patch prepares the module to extend the number of message objects beyond the 32 currently managed. This was achieved by transforming the constants used to manage RX/TX messages into variables without changing the driver policy.
--- drivers/net/can/c_can/c_can.c | 50 ++++++++++++++++---------- drivers/net/can/c_can/c_can.h | 23 ++++++------ drivers/net/can/c_can/c_can_pci.c | 2 +- drivers/net/can/c_can/c_can_platform.c | 2 +- 4 files changed, 43 insertions(+), 34 deletions(-)
drivers/net/can/c_can/c_can.c +31 -19
@@ -170,9 +170,6 @@/* Wait for ~1 sec for INIT bit */ #define INIT_WAIT_MS 1000 -/* napi related */ -#define C_CAN_NAPI_WEIGHT C_CAN_MSG_OBJ_RX_NUM -/* c_can lec values */ enum c_can_lec_type {LEC_NO_ERROR =0 ,
@@ -306,7 +303,7 @@ static void c_can_setup_tx_object(struct net_device *dev, int iface,* first, i.e. clear the MSGVAL flag in the arbiter. */ if (rtr != (bool )test_bit (idx, &priv->tx_dir)) { -u32 obj = idx +C_CAN_MSG_OBJ_TX_FIRST ; +u32 obj = idx + priv->msg_obj_tx_first;c_can_inval_msg_object (dev, iface, obj);change_bit (idx, &priv->tx_dir);
@@ -443,10 +440,10 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,* prioritized. The lowest buffer number wins. */ idx =fls (atomic_read (&priv->tx_active)); - obj = idx +C_CAN_MSG_OBJ_TX_FIRST ; + obj = idx + priv->msg_obj_tx_first;/* If this is the last buffer, stop the xmit queue */ -if (idx ==C_CAN_MSG_OBJ_TX_NUM -1 ) +if (idx == priv->msg_obj_tx_num -1 )netif_stop_queue (dev);/* Store the message in the interface so we can call * can_put_echo_skb(). We must do this before we enable
@@ -527,17 +524,18 @@ static int c_can_set_bittiming(struct net_device *dev)*/ static void c_can_configure_msg_objects (struct net_device *dev) { +struct c_can_priv *priv =netdev_priv (dev);int i;/* first invalidate all message objects */ -for (i =C_CAN_MSG_OBJ_RX_FIRST ; i <=C_CAN_NO_OF_OBJECTS ; i++) +for (i = priv->msg_obj_rx_first; i <= priv->msg_obj_num; i++)c_can_inval_msg_object (dev,IF_RX , i);/* setup receive message objects */ -for (i =C_CAN_MSG_OBJ_RX_FIRST ; i <C_CAN_MSG_OBJ_RX_LAST ; i++) +for (i = priv->msg_obj_rx_first; i < priv->msg_obj_rx_last; i++)c_can_setup_receive_object (dev,IF_RX , i,0 ,0 ,IF_MCONT_RCV ); -c_can_setup_receive_object (dev,IF_RX ,C_CAN_MSG_OBJ_RX_LAST ,0 ,0 , +c_can_setup_receive_object (dev,IF_RX , priv->msg_obj_rx_last,0 ,0 ,IF_MCONT_RCV_EOB ); }
@@ -708,7 +706,7 @@ static void c_can_do_tx(struct net_device *dev)while ((idx =ffs (pend))) { idx--; pend &= ~(1 << idx); - obj = idx +C_CAN_MSG_OBJ_TX_FIRST ; + obj = idx + priv->msg_obj_tx_first;/* We use IF_RX interface instead of IF_TX because we * are called from c_can_poll(), which runs inside
@@ -723,7 +721,7 @@ static void c_can_do_tx(struct net_device *dev)/* Clear the bits in the tx_active mask */ atomic_sub (clr, &priv->tx_active); -if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM -1 ))) +if (clr & (1 << (priv->msg_obj_tx_num -1 )))netif_wake_queue (dev);if (pkts) {
@@ -737,11 +735,11 @@ static void c_can_do_tx(struct net_device *dev)* raced with the hardware or failed to readout all upper * objects in the last run due to quota limit. */ -static u32 c_can_adjust_pending (u32 pend) +static u32 c_can_adjust_pending (u32 pend,u32 rx_mask) {u32 weight, lasts; -if (pend ==RECEIVE_OBJECT_BITS ) +if (pend == rx_mask)return pend;/* If the last set bit is larger than the number of pending
@@ -840,8 +838,7 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)/* It is faster to read only one 16bit register. This is only possible * for a maximum number of 16 objects. */ -BUILD_BUG_ON_MSG (C_CAN_MSG_OBJ_RX_LAST >16 , -"Implementation does not support more message objects than 16" ); +WARN_ON (priv->msg_obj_rx_last >16 );while (quota >0 ) {if (!pend) {
@@ -851,7 +848,8 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)/* If the pending field has a gap, handle the * bits above the gap first. */ - toread =c_can_adjust_pending (pend); + toread =c_can_adjust_pending (pend, + priv->msg_obj_rx_mask); }else { toread = pend; }
@@ -1181,17 +1179,31 @@ static int c_can_close(struct net_device *dev)return 0 ; } -struct net_device *alloc_c_can_dev (void ) +struct net_device *alloc_c_can_dev (int msg_obj_num) {struct net_device *dev;struct c_can_priv *priv; +int msg_obj_tx_num = msg_obj_num /2 ; - dev =alloc_candev (sizeof (struct c_can_priv ),C_CAN_MSG_OBJ_TX_NUM ); + dev =alloc_candev (struct_size (priv, dlc, msg_obj_tx_num), + msg_obj_tx_num);if (!dev)return NULL ; priv =netdev_priv (dev); -netif_napi_add (dev, &priv->napi, c_can_poll,C_CAN_NAPI_WEIGHT ); + priv->msg_obj_num = msg_obj_num; + priv->msg_obj_rx_num = msg_obj_num - msg_obj_tx_num; + priv->msg_obj_rx_first =1 ; + priv->msg_obj_rx_last = + priv->msg_obj_rx_first + priv->msg_obj_rx_num -1 ; + priv->msg_obj_rx_mask =GENMASK (priv->msg_obj_rx_num -1 ,0 ); + + priv->msg_obj_tx_num = msg_obj_tx_num; + priv->msg_obj_tx_first = priv->msg_obj_rx_last +1 ; + priv->msg_obj_tx_last = + priv->msg_obj_tx_first + priv->msg_obj_tx_num -1 ; + +netif_napi_add (dev, &priv->napi, c_can_poll, priv->msg_obj_rx_num); priv->dev = dev; priv->can.bittiming_const = &c_can_bittiming_const;
drivers/net/can/c_can/c_can.h +10 -13
@@ -22,18 +22,7 @@#ifndef C_CAN_H #define C_CAN_H -/* message object split */ #define C_CAN_NO_OF_OBJECTS 32 -#define C_CAN_MSG_OBJ_RX_NUM 16 -#define C_CAN_MSG_OBJ_TX_NUM 16 - -#define C_CAN_MSG_OBJ_RX_FIRST 1 -#define C_CAN_MSG_OBJ_RX_LAST (C_CAN_MSG_OBJ_RX_FIRST + \ - C_CAN_MSG_OBJ_RX_NUM - 1) - -#define C_CAN_MSG_OBJ_TX_FIRST (C_CAN_MSG_OBJ_RX_LAST + 1) - -#define RECEIVE_OBJECT_BITS 0x0000ffffenum reg { C_CAN_CTRL_REG = 0,
@@ -193,6 +182,14 @@ struct c_can_priv {struct napi_struct napi;struct net_device *dev;struct device *device; +unsigned int msg_obj_num; +unsigned int msg_obj_rx_num; +unsigned int msg_obj_tx_num; +unsigned int msg_obj_rx_first; +unsigned int msg_obj_rx_last; +unsigned int msg_obj_tx_first; +unsigned int msg_obj_tx_last; +u32 msg_obj_rx_mask;atomic_t tx_active;atomic_t sie_pending;unsigned long tx_dir;
@@ -209,10 +206,10 @@ struct c_can_priv {void (*raminit)(const struct c_can_priv *priv,bool enable);u32 comm_rcv_high;u32 rxmasked; -u32 dlc[C_CAN_MSG_OBJ_TX_NUM ]; +u32 dlc[]; }; -struct net_device *alloc_c_can_dev (void ); +struct net_device *alloc_c_can_dev (int msg_obj_num);void free_c_can_dev (struct net_device *dev);int register_c_can_dev (struct net_device *dev);void unregister_c_can_dev (struct net_device *dev);
drivers/net/can/c_can/c_can_pci.c +1 -1
@@ -147,7 +147,7 @@ static int c_can_pci_probe(struct pci_dev *pdev, }/* allocate the c_can device */ - dev =alloc_c_can_dev (); + dev =alloc_c_can_dev (C_CAN_NO_OF_OBJECTS );if (!dev) { ret = -ENOMEM ; goto out_iounmap;
drivers/net/can/c_can/c_can_platform.c +1 -1
@@ -294,7 +294,7 @@ static int c_can_plat_probe(struct platform_device *pdev) }/* allocate the c_can device */ - dev =alloc_c_can_dev (); + dev =alloc_c_can_dev (C_CAN_NO_OF_OBJECTS );if (!dev) { ret = -ENOMEM ; goto exit;
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 39/39 can: c_can: add support to 64 message objects
In reply to Marc Kleine-BuddeFrom: Dario Binacchi <[email protected]>
D_CAN controller supports 16, 32, 64 or 128 message objects, comparing to 32 on C_CAN. AM335x/AM437x Sitara processors and DRA7 SOC all instantiate a D_CAN controller with 64 message objects, as described in the "DCAN features" subsection of the CAN chapter of their technical reference manuals.
The driver policy has been kept unchanged, and as in the previous version, the first half of the message objects is used for reception and the second for transmission.
The I/O load is increased only in the case of 64 message objects, keeping it unchanged in the case of 32. Two 32-bit read accesses are in fact required, which however remained at 16-bit for configurations with 32 message objects.
--- drivers/net/can/c_can/c_can.c | 27 ++++++++++++++------------ drivers/net/can/c_can/c_can.h | 5 +++-- drivers/net/can/c_can/c_can_pci.c | 6 +++++- drivers/net/can/c_can/c_can_platform.c | 6 +++++- 4 files changed, 28 insertions(+), 16 deletions(-)
drivers/net/can/c_can/c_can.c +15 -12
@@ -454,7 +454,7 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,can_put_echo_skb (skb, dev, idx,0 );/* Update the active bits */ -atomic_add ((1 << idx), &priv->tx_active); +atomic_add (BIT (idx), &priv->tx_active);/* Start transmission */ c_can_object_put (dev,IF_TX , obj,IF_COMM_TX );
@@ -700,12 +700,15 @@ static void c_can_do_tx(struct net_device *dev)struct net_device_stats *stats = &dev->stats;u32 idx, obj, pkts =0 , bytes =0 , pend, clr; - pend = priv->read_reg (priv,C_CAN_INTPND2_REG ); +if (priv->msg_obj_tx_last >32 ) + pend = priv->read_reg32 (priv,C_CAN_INTPND3_REG ); +else + pend = priv->read_reg (priv,C_CAN_INTPND2_REG ); clr = pend;while ((idx =ffs (pend))) { idx--; - pend &= ~(1 << idx); + pend &= ~BIT (idx); obj = idx + priv->msg_obj_tx_first;/* We use IF_RX interface instead of IF_TX because we
@@ -721,7 +724,7 @@ static void c_can_do_tx(struct net_device *dev)/* Clear the bits in the tx_active mask */ atomic_sub (clr, &priv->tx_active); -if (clr & (1 << (priv->msg_obj_tx_num -1 ))) +if (clr &BIT (priv->msg_obj_tx_num -1 ))netif_wake_queue (dev);if (pkts) {
@@ -755,10 +758,10 @@ static u32 c_can_adjust_pending(u32 pend, u32 rx_mask)/* Find the first set bit after the gap. We walk backwards * from the last set bit. */ -for (lasts--; pend & (1 << (lasts -1 )); lasts--) +for (lasts--; pend &BIT (lasts -1 ); lasts--) ; -return pend & ~((1 << lasts) -1 ); +return pend & ~GENMASK (lasts -1 ,0 ); } static inline void c_can_rx_object_get(struct net_device *dev,
@@ -814,7 +817,12 @@ static int c_can_read_objects(struct net_device *dev, struct c_can_priv *priv,static inline u32 c_can_get_pending (struct c_can_priv *priv) { -u32 pend = priv->read_reg (priv,C_CAN_NEWDAT1_REG ); +u32 pend; + +if (priv->msg_obj_rx_last >16 ) + pend = priv->read_reg32 (priv,C_CAN_NEWDAT1_REG ); +else + pend = priv->read_reg (priv,C_CAN_NEWDAT1_REG );return pend; }
@@ -835,11 +843,6 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)struct c_can_priv *priv =netdev_priv (dev);u32 pkts =0 , pend =0 , toread, n; -/* It is faster to read only one 16bit register. This is only possible -* for a maximum number of 16 objects. -*/ -WARN_ON (priv->msg_obj_rx_last >16 ); -while (quota >0 ) {if (!pend) { pend =c_can_get_pending (priv);
drivers/net/can/c_can/c_can.h +3 -2
@@ -22,8 +22,6 @@#ifndef C_CAN_H #define C_CAN_H -#define C_CAN_NO_OF_OBJECTS 32 -enum reg {C_CAN_CTRL_REG =0 , C_CAN_CTRL_EX_REG,
@@ -61,6 +59,7 @@ enum reg {C_CAN_NEWDAT2_REG ,C_CAN_INTPND1_REG ,C_CAN_INTPND2_REG , +C_CAN_INTPND3_REG ,C_CAN_MSGVAL1_REG ,C_CAN_MSGVAL2_REG , C_CAN_FUNCTION_REG,
@@ -122,6 +121,7 @@ static const u16 __maybe_unused reg_map_d_can[] = { [C_CAN_NEWDAT2_REG] = 0x9E, [C_CAN_INTPND1_REG] = 0xB0, [C_CAN_INTPND2_REG] = 0xB2, + [C_CAN_INTPND3_REG] = 0xB4, [C_CAN_MSGVAL1_REG] = 0xC4, [C_CAN_MSGVAL2_REG] = 0xC6, [C_CAN_IF1_COMREQ_REG] = 0x100,
@@ -161,6 +161,7 @@ struct raminit_bits {struct c_can_driver_data {enum c_can_dev_id id; +unsigned int msg_obj_num;/* RAMINIT register description. Optional. */ const struct raminit_bits *raminit_bits;/* Array of START/DONE bit positions */
drivers/net/can/c_can/c_can_pci.c +5 -1
@@ -31,6 +31,8 @@ enum c_can_pci_reg_align {struct c_can_pci_data {/* Specify if is C_CAN or D_CAN */ enum c_can_dev_id type; +/* Number of message objects */ +unsigned int msg_obj_num;/* Set the register alignment in the memory */ enum c_can_pci_reg_align reg_align;/* Set the frequency */
@@ -147,7 +149,7 @@ static int c_can_pci_probe(struct pci_dev *pdev, }/* allocate the c_can device */ - dev =alloc_c_can_dev (C_CAN_NO_OF_OBJECTS ); + dev =alloc_c_can_dev (c_can_pci_data->msg_obj_num);if (!dev) { ret = -ENOMEM ; goto out_iounmap;
@@ -252,6 +254,7 @@ static void c_can_pci_remove(struct pci_dev *pdev)static const struct c_can_pci_data c_can_sta2x11 = { .type =BOSCH_C_CAN , + .msg_obj_num =32 , .reg_align =C_CAN_REG_ALIGN_32 , .freq =52000000 ,/* 52 Mhz */ .bar =0 ,
@@ -259,6 +262,7 @@ static const struct c_can_pci_data c_can_sta2x11 = {static const struct c_can_pci_data c_can_pch = { .type =BOSCH_C_CAN , + .msg_obj_num =32 , .reg_align =C_CAN_REG_32 , .freq =50000000 ,/* 50 MHz */ .init = c_can_pci_reset_pch,
drivers/net/can/c_can/c_can_platform.c +5 -1
@@ -193,10 +193,12 @@ static void c_can_hw_raminit(const struct c_can_priv *priv, bool enable)static const struct c_can_driver_data c_can_drvdata = { .id =BOSCH_C_CAN , + .msg_obj_num =32 , };static const struct c_can_driver_data d_can_drvdata = { .id =BOSCH_D_CAN , + .msg_obj_num =32 , };static const struct raminit_bits dra7_raminit_bits[] = {
@@ -206,6 +208,7 @@ static const struct raminit_bits dra7_raminit_bits[] = {static const struct c_can_driver_data dra7_dcan_drvdata = { .id =BOSCH_D_CAN , + .msg_obj_num =64 , .raminit_num =ARRAY_SIZE (dra7_raminit_bits), .raminit_bits = dra7_raminit_bits, .raminit_pulse = true,
@@ -218,6 +221,7 @@ static const struct raminit_bits am3352_raminit_bits[] = {static const struct c_can_driver_data am3352_dcan_drvdata = { .id =BOSCH_D_CAN , + .msg_obj_num =64 , .raminit_num =ARRAY_SIZE (am3352_raminit_bits), .raminit_bits = am3352_raminit_bits, };
@@ -294,7 +298,7 @@ static int c_can_plat_probe(struct platform_device *pdev) }/* allocate the c_can device */ - dev =alloc_c_can_dev (C_CAN_NO_OF_OBJECTS ); + dev =alloc_c_can_dev (drvdata->msg_obj_num);if (!dev) { ret = -ENOMEM ; goto exit;
Signature · 1 line
2.30.2
This pull request was applied to netdev/net-next.git (refs/heads/master):
Hello:
This pull request was applied to netdev/net-next.git (refs/heads/master):
Quoted 10 lines · On Tue, 30 Mar 2021 13:45:20 +0200 you wrote:
Hello Jakub, hello David,
this is a pull request of 39 patches for net-next/master.
The first two patches update the
MAINTAINERSfile. One is by me and removes Dan Murphy from the fromm_canand tcan4x5x. The other one is by Pankaj Sharma and updates the maintainership of the m-can mmio driver.[...]
Here is the summary with links:
- pull-request: can-next 2021-03-30
https://git.kernel.org/netdev/net-next/c/9c0ee085c49c
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html