From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:46:53
Hello 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
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:46:55
So 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.
Link: https://lore.kernel.org/r/20210309211904.3348700-1-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/dev/skb.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
@@ -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;
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:46:55
Dan Murphy's email address at ti.com doesn't work anymore, mails
bounce with:
| 550 Invalid recipient [off-list ref] (#5.1.1)
For now remove all CAN related entries of Dan from the Maintainers
file.
Link: https://lore.kernel.org/r/20210228094218.40015-1-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
MAINTAINERS | 8 --------
1 file changed, 8 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:46:55
From: Pankaj Sharma <redacted>
Update Chandrasekar Ramakrishnan as maintainer for mcan mmio device driver as I
will be moving to a different role.
Signed-off-by: Pankaj Sharma <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
MAINTAINERS | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:46:55
A 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")
Link: https://lore.kernel.org/r/20210319142700.305648-2-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/dev/skb.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:46:55
In 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")
Link: https://lore.kernel.org/r/20210319142700.305648-3-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
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(-)
@@ -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,
@@ -39,22 +39,23 @@ struct can_priv {structnet_device*dev;structcan_device_statscan_stats;-structcan_bittimingbittiming,data_bittiming;conststructcan_bittiming_const*bittiming_const,*data_bittiming_const;-structcan_tdctdc;+structcan_bittimingbittiming,data_bittiming;conststructcan_tdc_const*tdc_const;+structcan_tdctdc;-constu16*termination_const;-unsignedinttermination_const_cnt;-u16termination;-constu32*bitrate_const;unsignedintbitrate_const_cnt;+constu32*bitrate_const;constu32*data_bitrate_const;unsignedintdata_bitrate_const_cnt;u32bitrate_max;structcan_clockclock;+unsignedinttermination_const_cnt;+constu16*termination_const;+u16termination;+enumcan_statestate;/* CAN controller features - see include/uapi/linux/can/netlink.h */
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:46:55
From: Vincent Mailhol <redacted>
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
Link: https://lore.kernel.org/r/20210224002008.4158-2-mailhol.vincent@wanadoo.fr
Signed-off-by: Vincent Mailhol <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
include/linux/can/bittiming.h | 65 +++++++++++++++++++++++++++++++++++
include/linux/can/dev.h | 3 ++
2 files changed, 68 insertions(+)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:46:55
From: Vincent Mailhol <redacted>
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.
Link: https://lore.kernel.org/r/20210224002008.4158-6-mailhol.vincent@wanadoo.fr
Signed-off-by: Vincent Mailhol <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
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(+)
@@ -174,6 +174,30 @@ int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,return0;}++voidcan_calc_tdco(structnet_device*dev)+{+structcan_priv*priv=netdev_priv(dev);+conststructcan_bittiming*dbt=&priv->data_bittiming;+structcan_tdc*tdc=&priv->tdc;+conststructcan_tdc_const*tdc_const=priv->tdc_const;++if(!tdc_const)+return;++/* As specified in ISO 11898-1 section 11.3.3 "Transmitter+*delaycompensation" (TDC) is only applicable if data BRP is+*oneortwo.+*/+if(dbt->brp==1||dbt->brp==2){+/* Reuse "normal" sample point and convert it to time quanta */+u32sample_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,
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:27
From: Vincent Mailhol <redacted>
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) },
Link: https://lore.kernel.org/r/20210224002008.4158-4-mailhol.vincent@wanadoo.fr
Signed-off-by: Vincent Mailhol <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/dev/netlink.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:27
On 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.
Link: https://lore.kernel.org/r/20210309140424.3331010-1-mkl@pengutronix.de
Reported-by: kernel test robot <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:27
From: Arnd Bergmann <arnd@arndb.de>
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.
Link: https://lore.kernel.org/r/20210204162625.3099392-1-arnd@kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/ucan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:27
From: Michal Simek <redacted>
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.
Link: https://lore.kernel.org/r/91af0945ed7397b08f1af0c829450620bd92b804.1612442564.git.michal.simek@xilinx.com
Signed-off-by: Michal Simek <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/xilinx_can.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
@@ -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");gotoerr_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");gotoerr_free;}
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:28
From: Stephane Grosjean <redacted>
This patch replaces the plain integers used for flags in
pcan_usb_pro_encode_msg() by macros which are already defined.
Link: https://lore.kernel.org/r/20210309082128.23125-4-s.grosjean@peak-system.com
Signed-off-by: Stephane Grosjean <redacted>
[mkl: split into two patches]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:28
From: Stephane Grosjean <redacted>
This patch makes it possible to specifically flash the LED of a CAN
port of the CAN-USB interfaces of PEAK-System.
Link: https://lore.kernel.org/r/20210309122141.3276927-1-mkl@pengutronix.de
Signed-off-by: Stephane Grosjean <redacted>
[mkl: use common prefix PCAN_ for defines]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
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(-)
@@ -971,6 +982,40 @@ static int pcan_usb_probe(struct usb_interface *intf)return0;}+staticintpcan_usb_set_phys_id(structnet_device*netdev,+enumethtool_phys_id_statestate)+{+structpeak_usb_device*dev=netdev_priv(netdev);+interr=0;++switch(state){+caseETHTOOL_ID_ACTIVE:+/* call ON/OFF twice a second */+return2;++caseETHTOOL_ID_OFF:+err=pcan_usb_set_led(dev,0);+break;++caseETHTOOL_ID_ON:+fallthrough;++caseETHTOOL_ID_INACTIVE:+/* restore LED default */+err=pcan_usb_set_led(dev,1);+break;++default:+break;+}++returnerr;+}++staticconststructethtool_opspcan_usb_ethtool_ops={+.set_phys_id=pcan_usb_set_phys_id,+};+/**describethePCAN-USBadapter*/
@@ -1001,6 +1046,8 @@ const struct peak_usb_adapter pcan_usb = {/* size of device private data */.sizeof_dev_private=sizeof(structpcan_usb),+.ethtool_ops=&pcan_usb_ethtool_ops,+/* timestamps usage */.ts_used_bits=16,.ts_period=24575,/* calibration period in ts. */
@@ -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);
@@ -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)return0;}+staticintpcan_usb_pro_set_phys_id(structnet_device*netdev,+enumethtool_phys_id_statestate)+{+structpeak_usb_device*dev=netdev_priv(netdev);+interr=0;++switch(state){+caseETHTOOL_ID_ACTIVE:+/* fast blinking forever */+err=pcan_usb_pro_set_led(dev,PCAN_USBPRO_LED_BLINK_FAST,+0xffffffff);+break;++caseETHTOOL_ID_INACTIVE:+/* restore LED default */+err=pcan_usb_pro_set_led(dev,PCAN_USBPRO_LED_DEVICE,1);+break;++default:+break;+}++returnerr;+}++staticconststructethtool_opspcan_usb_pro_ethtool_ops={+.set_phys_id=pcan_usb_pro_set_phys_id,+};+/**describethePCAN-USBProadapter*/
@@ -1018,6 +1048,8 @@ const struct peak_usb_adapter pcan_usb_pro = {/* size of device private data */.sizeof_dev_private=sizeof(structpcan_usb_pro_device),+.ethtool_ops=&pcan_usb_pro_ethtool_ops,+/* timestamps usage */.ts_used_bits=32,.ts_period=1000000,/* calibration period in ts. */
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:28
In 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.
Link: https://lore.kernel.org/r/20210304160328.2752293-3-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
.../net/can/spi/mcp251xfd/mcp251xfd-core.c | 69 ++++++++++---------
1 file changed, 37 insertions(+), 32 deletions(-)
@@ -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+*chipselectafterthecompleteSPImessage.Thiscausesthe+*controllertointerpretthenextregisteraccessas+*data.Set"cs_change"ofthelasttransferto"0"to+*properlydeactivatethechipselectattheendofthe+*message.+*/+xfer->cs_change=0;+/* TX */tx_ring=priv->tx;tx_ring->head=0;
@@ -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+*activechipselectafterthecompleteSPI+*message.Thiscausesthecontrollertointerpret+*thenextregisteraccessasdata.Set"cs_change"+*ofthelasttransferto"0"toproperlydeactivate+*thechipselectattheendofthemessage.+*/+xfer->cs_change=0;}}
@@ -1366,25 +1381,20 @@ static int mcp251xfd_handle_tefif(struct mcp251xfd_priv *priv)if(len){structmcp251xfd_tef_ring*ring=priv->tef;structmcp251xfd_tx_ring*tx_ring=priv->tx;-structspi_transfer*last_xfer;+intoffset;/* Increment the TEF FIFO tail pointer 'len' times in*asingleSPImessage.**Note:-*-*"cs_change == 1"onthelasttransferresultsinan-*activechipselectafterthecompleteSPI-*message.Thiscausesthecontrollertointerpret-*thenextregisteraccessasdata.Temporaryset-*"cs_change"ofthelasttransferto"0"toproperly-*deactivatethechipselectattheendofthe-*message.+*Calculateoffset,sothattheSPItransferendson+*thelastmessageoftheuinc_xferarray,whichhas+*"cs_change == 0",toproperlydeactivatethechip+*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)returnerr;
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:28
From: Xulin Sun <redacted>
If the CAN net device has been successfully allocated, its private
data structure is impossible to be empty, remove this redundant error
return judgment.
Link: https://lore.kernel.org/r/20210205072559.13241-2-xulin.sun@windriver.com
Signed-off-by: Xulin Sun <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/m_can.c | 5 -----
1 file changed, 5 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:28
This is a preparation patch, it moves the mcp251xfd_get_timestamp()
function into the mcp251xfd.h file.
Link: https://lore.kernel.org/r/20210304160328.2752293-5-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 6 ------
drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 6 ++++++
2 files changed, 6 insertions(+), 6 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:28
From: Torin Cooper-Bennun <redacted>
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.
Link: https://lore.kernel.org/r/20210308102427.63916-3-torin@maxiluxsystems.com
Signed-off-by: Torin Cooper-Bennun <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/m_can.c | 5 +++++
1 file changed, 5 insertions(+)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:28
For 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
Link: https://lore.kernel.org/r/20210304160328.2752293-2-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
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
@@ -0,0 +1,285 @@+// SPDX-License-Identifier: GPL-2.0+//+// mcp251xfd - Microchip MCP251xFD Family CAN controller driver+//+// Copyright (c) 2020, 2021 Pengutronix,+// Marc Kleine-Budde <kernel@pengutronix.de>+// Copyright (C) 2015-2018 Etnaviv Project+//++#include<linux/devcoredump.h>++#include"mcp251xfd.h"+#include"mcp251xfd-dump.h"++structmcp251xfd_dump_iter{+void*start;+structmcp251xfd_dump_object_header*hdr;+void*data;+};++structmcp251xfd_dump_reg_space{+u16base;+u16size;+};++structmcp251xfd_dump_ring{+enummcp251xfd_dump_object_ring_keykey;+u32val;+};++staticconststructmcp251xfd_dump_reg_spacemcp251xfd_dump_reg_space[]={+{+.base=MCP251XFD_REG_CON,+.size=MCP251XFD_REG_FLTOBJ(32)-MCP251XFD_REG_CON,+},{+.base=MCP251XFD_RAM_START,+.size=MCP251XFD_RAM_SIZE,+},{+.base=MCP251XFD_REG_OSC,+.size=MCP251XFD_REG_DEVID-MCP251XFD_REG_OSC,+},+};++staticvoidmcp251xfd_dump_header(structmcp251xfd_dump_iter*iter,+enummcp251xfd_dump_object_typeobject_type,+constvoid*data_end)+{+structmcp251xfd_dump_object_header*hdr=iter->hdr;+unsignedintlen;++len=data_end-iter->data;+if(!len)+return;++hdr->magic=cpu_to_le32(MCP251XFD_DUMP_MAGIC);+hdr->type=cpu_to_le32(object_type);+hdr->offset=cpu_to_le32(iter->data-iter->start);+hdr->len=cpu_to_le32(len);++iter->hdr++;+iter->data+=len;+}++staticvoidmcp251xfd_dump_registers(conststructmcp251xfd_priv*priv,+structmcp251xfd_dump_iter*iter)+{+constintval_bytes=regmap_get_val_bytes(priv->map_rx);+structmcp251xfd_dump_object_reg*reg=iter->data;+unsignedinti,j;+interr;++for(i=0;i<ARRAY_SIZE(mcp251xfd_dump_reg_space);i++){+conststructmcp251xfd_dump_reg_space*reg_space;+void*buf;++reg_space=&mcp251xfd_dump_reg_space[i];++buf=kmalloc(reg_space->size,GFP_KERNEL);+if(!buf)+gotoout;++err=regmap_bulk_read(priv->map_reg,reg_space->base,+buf,reg_space->size/val_bytes);+if(err){+kfree(buf);+continue;+}++for(j=0;j<reg_space->size;j+=sizeof(u32),reg++){+reg->reg=cpu_to_le32(reg_space->base+j);+reg->val=cpu_to_le32p(buf+j);+}++kfree(buf);+}++out:+mcp251xfd_dump_header(iter,MCP251XFD_DUMP_OBJECT_TYPE_REG,reg);+}++staticvoidmcp251xfd_dump_ring(structmcp251xfd_dump_iter*iter,+enummcp251xfd_dump_object_typeobject_type,+conststructmcp251xfd_dump_ring*dump_ring,+unsignedintlen)+{+structmcp251xfd_dump_object_reg*reg=iter->data;+unsignedinti;++for(i=0;i<len;i++,reg++){+reg->reg=cpu_to_le32(dump_ring[i].key);+reg->val=cpu_to_le32(dump_ring[i].val);+}++mcp251xfd_dump_header(iter,object_type,reg);+}++staticvoidmcp251xfd_dump_tef_ring(conststructmcp251xfd_priv*priv,+structmcp251xfd_dump_iter*iter)+{+conststructmcp251xfd_tef_ring*tef=priv->tef;+conststructmcp251xfd_tx_ring*tx=priv->tx;+conststructmcp251xfd_dump_ringdump_ring[]={+{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_HEAD,+.val=tef->head,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_TAIL,+.val=tef->tail,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_BASE,+.val=0,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_NR,+.val=0,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_FIFO_NR,+.val=0,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_OBJ_NUM,+.val=tx->obj_num,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_OBJ_SIZE,+.val=sizeof(structmcp251xfd_hw_tef_obj),+},+};++mcp251xfd_dump_ring(iter,MCP251XFD_DUMP_OBJECT_TYPE_TEF,+dump_ring,ARRAY_SIZE(dump_ring));+}++staticvoidmcp251xfd_dump_rx_ring_one(conststructmcp251xfd_priv*priv,+structmcp251xfd_dump_iter*iter,+conststructmcp251xfd_rx_ring*rx)+{+conststructmcp251xfd_dump_ringdump_ring[]={+{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_HEAD,+.val=rx->head,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_TAIL,+.val=rx->tail,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_BASE,+.val=rx->base,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_NR,+.val=rx->nr,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_FIFO_NR,+.val=rx->fifo_nr,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_OBJ_NUM,+.val=rx->obj_num,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_OBJ_SIZE,+.val=rx->obj_size,+},+};++mcp251xfd_dump_ring(iter,MCP251XFD_DUMP_OBJECT_TYPE_RX,+dump_ring,ARRAY_SIZE(dump_ring));+}++staticvoidmcp251xfd_dump_rx_ring(conststructmcp251xfd_priv*priv,+structmcp251xfd_dump_iter*iter)+{+structmcp251xfd_rx_ring*rx_ring;+unsignedinti;++mcp251xfd_for_each_rx_ring(priv,rx_ring,i)+mcp251xfd_dump_rx_ring_one(priv,iter,rx_ring);+}++staticvoidmcp251xfd_dump_tx_ring(conststructmcp251xfd_priv*priv,+structmcp251xfd_dump_iter*iter)+{+conststructmcp251xfd_tx_ring*tx=priv->tx;+conststructmcp251xfd_dump_ringdump_ring[]={+{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_HEAD,+.val=tx->head,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_TAIL,+.val=tx->tail,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_BASE,+.val=tx->base,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_NR,+.val=0,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_FIFO_NR,+.val=MCP251XFD_TX_FIFO,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_OBJ_NUM,+.val=tx->obj_num,+},{+.key=MCP251XFD_DUMP_OBJECT_RING_KEY_OBJ_SIZE,+.val=tx->obj_size,+},+};++mcp251xfd_dump_ring(iter,MCP251XFD_DUMP_OBJECT_TYPE_TX,+dump_ring,ARRAY_SIZE(dump_ring));+}++staticvoidmcp251xfd_dump_end(conststructmcp251xfd_priv*priv,+structmcp251xfd_dump_iter*iter)+{+structmcp251xfd_dump_object_header*hdr=iter->hdr;++hdr->magic=cpu_to_le32(MCP251XFD_DUMP_MAGIC);+hdr->type=cpu_to_le32(MCP251XFD_DUMP_OBJECT_TYPE_END);+hdr->offset=cpu_to_le32(0);+hdr->len=cpu_to_le32(0);++/* provoke NULL pointer access, if used after END object */+iter->hdr=NULL;+}++voidmcp251xfd_dump(conststructmcp251xfd_priv*priv)+{+structmcp251xfd_dump_iteriter;+unsignedintrings_num,obj_num;+unsignedintfile_size=0;+unsignedinti;++/* register space + end marker */+obj_num=2;++/* register space */+for(i=0;i<ARRAY_SIZE(mcp251xfd_dump_reg_space);i++)+file_size+=mcp251xfd_dump_reg_space[i].size/sizeof(u32)*+sizeof(structmcp251xfd_dump_object_reg);++/* TEF ring, RX ring, TX rings */+rings_num=1+priv->rx_ring_num+1;+obj_num+=rings_num;+file_size+=rings_num*__MCP251XFD_DUMP_OBJECT_RING_KEY_MAX*+sizeof(structmcp251xfd_dump_object_reg);++/* size of the headers */+file_size+=sizeof(*iter.hdr)*obj_num;++/* allocate the file in vmalloc memory, it's likely to be big */+iter.start=__vmalloc(file_size,GFP_KERNEL|__GFP_NOWARN|+__GFP_ZERO|__GFP_NORETRY);+if(!iter.start){+netdev_warn(priv->ndev,"Failed to allocate devcoredump file.\n");+return;+}++/* point the data member after the headers */+iter.hdr=iter.start;+iter.data=&iter.hdr[obj_num];++mcp251xfd_dump_registers(priv,&iter);+mcp251xfd_dump_tef_ring(priv,&iter);+mcp251xfd_dump_rx_ring(priv,&iter);+mcp251xfd_dump_tx_ring(priv,&iter);+mcp251xfd_dump_end(priv,&iter);++dev_coredumpv(&priv->spi->dev,iter.start,+iter.data-iter.start,GFP_KERNEL);+}
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:29
From: Wan Jiabing <redacted>
linux/regmap.h has been included at line 13, so remove the duplicate
one at line 14.
Fixes: 67def4ef8bb9 ("can: tcan4x5x: move regmap code into seperate file")
Link: https://lore.kernel.org/r/20210323021026.140460-1-wanjiabing@vivo.com
Signed-off-by: Wan Jiabing <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x.h | 1 -
1 file changed, 1 deletion(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:29
The netdevice.h header is needed in mcp251xfd.h, so that it can be
included without further headers.
Link: https://lore.kernel.org/r/20210304160328.2752293-4-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 1 -
drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:29
From: Torin Cooper-Bennun <redacted>
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.
Link: https://lore.kernel.org/r/20210308102427.63916-4-torin@maxiluxsystems.com
Signed-off-by: Torin Cooper-Bennun <redacted>
[mkl: m_can_class_register(): update error handling]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
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(-)
@@ -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.Fornon-peripherals,RXisdoneinnapialready,sopush+*directly.timestampisusedtoensuregoodskborderingin+*rx-offloadandisignoredfornon-peripherals.+*/+staticvoidm_can_receive_skb(structm_can_classdev*cdev,+structsk_buff*skb,+u32timestamp)+{+if(cdev->is_peripheral)+can_rx_offload_queue_sorted(&cdev->offload,skb,timestamp);+else+netif_receive_skb(skb);+}+staticvoidm_can_read_fifo(structnet_device*dev,u32rxfs){structnet_device_stats*stats=&dev->stats;
@@ -464,6 +479,7 @@ static void m_can_read_fifo(struct net_device *dev, u32 rxfs)structcanfd_frame*cf;structsk_buff*skb;u32id,fgi,dlc;+u32timestamp=0;inti;/* calculate the fifo get index for where to read data */
@@ -543,9 +561,11 @@ static int m_can_do_rx_poll(struct net_device *dev, int quota)staticintm_can_handle_lost_msg(structnet_device*dev){+structm_can_classdev*cdev=netdev_priv(dev);structnet_device_stats*stats=&dev->stats;structsk_buff*skb;structcan_frame*frame;+u32timestamp=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);return1;}
@@ -571,6 +594,7 @@ static int m_can_handle_lec_err(struct net_device *dev,structnet_device_stats*stats=&dev->stats;structcan_frame*cf;structsk_buff*skb;+u32timestamp=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);return1;}
@@ -674,6 +702,7 @@ static int m_can_handle_state_change(struct net_device *dev,structsk_buff*skb;structcan_berr_counterbec;unsignedintecr;+u32timestamp=0;switch(new_state){caseCAN_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);return1;}
@@ -800,6 +833,7 @@ static int m_can_handle_protocol_error(struct net_device *dev, u32 irqstatus)structm_can_classdev*cdev=netdev_priv(dev);structcan_frame*cf;structsk_buff*skb;+u32timestamp=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");return0;}-netif_receive_skb(skb);++if(cdev->is_peripheral)+timestamp=m_can_get_timestamp(cdev);++m_can_receive_skb(cdev,skb,timestamp);return1;}
@@ -922,6 +960,29 @@ static int m_can_poll(struct napi_struct *napi, int quota)returnwork_done;}+/* Echo tx skb and update net stats. Peripherals use rx-offload for+*echo.timestampisusedforperipheralstoensurecorrectordering+*byrx-offload,andisignoredfornon-peripherals.+*/+staticvoidm_can_tx_update_stats(structm_can_classdev*cdev,+unsignedintmsg_mark,+u32timestamp)+{+structnet_device*dev=cdev->net;+structnet_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++;+}+staticvoidm_can_echo_tx_event(structnet_device*dev){u32txe_count=0;
@@ -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++){+u32txe,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);}}
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:29
This 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.
Link: https://lore.kernel.org/r/20210304160328.2752293-6-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
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
@@ -0,0 +1,71 @@+// SPDX-License-Identifier: GPL-2.0+//+// mcp251xfd - Microchip MCP251xFD Family CAN controller driver+//+// Copyright (c) 2021 Pengutronix,+// Marc Kleine-Budde <kernel@pengutronix.de>+//++#include<linux/clocksource.h>+#include<linux/workqueue.h>++#include"mcp251xfd.h"++staticu64mcp251xfd_timestamp_read(conststructcyclecounter*cc)+{+structmcp251xfd_priv*priv;+u32timestamp=0;+interr;++priv=container_of(cc,structmcp251xfd_priv,cc);+err=mcp251xfd_get_timestamp(priv,×tamp);+if(err)+netdev_err(priv->ndev,+"Error %d while reading timestamp. HW timestamps may be inaccurate.",+err);++returntimestamp;+}++staticvoidmcp251xfd_timestamp_work(structwork_struct*work)+{+structdelayed_work*delayed_work=to_delayed_work(work);+structmcp251xfd_priv*priv;++priv=container_of(delayed_work,structmcp251xfd_priv,timestamp);+timecounter_read(&priv->tc);++schedule_delayed_work(&priv->timestamp,+MCP251XFD_TIMESTAMP_WORK_DELAY_SEC*HZ);+}++voidmcp251xfd_skb_set_timestamp(structmcp251xfd_priv*priv,+structsk_buff*skb,u32timestamp)+{+structskb_shared_hwtstamps*hwtstamps=skb_hwtstamps(skb);+u64ns;++ns=timecounter_cyc2time(&priv->tc,timestamp);+hwtstamps->hwtstamp=ns_to_ktime(ns);+}++voidmcp251xfd_timestamp_init(structmcp251xfd_priv*priv)+{+structcyclecounter*cc=&priv->cc;++cc->read=mcp251xfd_timestamp_read;+cc->mask=CYCLECOUNTER_MASK(32);+cc->shift=1;+cc->mult=clocksource_hz2mult(priv->can.clock.freq,cc->shift);++timecounter_init(&priv->tc,&priv->cc,ktime_get_real_ns());++INIT_DELAYED_WORK(&priv->timestamp,mcp251xfd_timestamp_work);+schedule_delayed_work(&priv->timestamp,+MCP251XFD_TIMESTAMP_WORK_DELAY_SEC*HZ);+}++voidmcp251xfd_timestamp_stop(structmcp251xfd_priv*priv)+{+cancel_delayed_work_sync(&priv->timestamp);+}
@@ -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)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:30
This patch replaces the double assignments by two single ones, to make
checkpatch happy.
Link: https://lore.kernel.org/r/20210304154240.2747987-6-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/c_can/c_can.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
@@ -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);
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:30
This patch fixes the print format string in the driver, so that it
stays in a single line.
Link: https://lore.kernel.org/r/20210304154240.2747987-5-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/c_can/c_can_pci.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
@@ -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;gotoout_release_regions;}
@@ -836,7 +836,7 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)*foramaximumnumberof16objects.*/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)}staticintc_can_handle_state_change(structnet_device*dev,-enumc_can_bus_error_typeserror_type)+enumc_can_bus_error_typeserror_type){unsignedintreg_err_counter;unsignedintrx_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");gotoexit_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)){
@@ -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:AccordingtodocumentationclearingTXIEwhileMSGVALisset+/* Note: According to documentation clearing TXIE while MSGVAL is set*isnotallowed,butworksnicelyonC/DCAN.AndthatlowerstheI/O*loadsignificantly.*/
@@ -309,8 +305,7 @@ static void c_can_setup_tx_object(struct net_device *dev, int iface,if(!rtr)arb|=IF_ARB_TRANSMIT;-/*-*IfwechangetheDIRbit,weneedtoinvalidatethebuffer+/* If we change the DIR bit, we need to invalidate the buffer*first,i.e.cleartheMSGVALflaginthearbiter.*/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))returnNETDEV_TX_OK;-/*-*ThisisnotaFIFO.C/D_CANsendsoutthebuffers+/* This is not a FIFO. C/D_CAN sends out the buffers*prioritized.Thelowestbuffernumberwins.*/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);-/*-*Storethemessageintheinterfacesowecancall+/* Store the message in the interface so we can call*can_put_echo_skb().Wemustdothisbeforeweenable*transmitaswemightraceagainstdo_tx().*/
@@ -527,8 +520,7 @@ static int c_can_set_bittiming(struct net_device *dev)returnc_can_wait_for_ctrl_init(dev,priv,0);}-/*-*ConfigureC_CANmessageobjectsforTxandRxpurposes:+/* Configure C_CAN message objects for Tx and Rx purposes:*C_CANprovidesatotalof32messageobjectsthatcanbeconfigured*eitherforTxorRxpurposes.Herethefirst16messageobjectsareusedas*areceptionFIFO.TheendofreceptionFIFOissignifiedbytheEoBbit
@@ -739,8 +730,7 @@ static void c_can_do_tx(struct net_device *dev)}}-/*-*Ifwehaveagapinthependingbits,thatmeansweeither+/* If we have a gap in the pending bits, that means we either*racedwiththehardwareorfailedtoreadoutallupper*objectsinthelastrunduetoquotalimit.*/
@@ -751,8 +741,7 @@ static u32 c_can_adjust_pending(u32 pend)if(pend==RECEIVE_OBJECT_BITS)returnpend;-/*-*Ifthelastsetbitislargerthanthenumberofpending+/* If the last set bit is larger than the number of pending*bitswehaveagap.*/weight=hweight32(pend);
@@ -762,8 +751,7 @@ static u32 c_can_adjust_pending(u32 pend)if(lasts==weight)returnpend;-/*-*Findthefirstsetbitafterthegap.Wewalkbackwards+/* Find the first set bit after the gap. We walk backwards*fromthelastsetbit.*/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;}-/*-*Thisreallyshouldnothappen,butthiscoverssome+/* This really should not happen, but this covers some*oddHWbehaviour.Donotremovethatunlessyou*wanttobrickyourmachine.*/
@@ -830,8 +817,7 @@ static inline u32 c_can_get_pending(struct c_can_priv *priv)returnpend;}-/*-*theoryofoperation:+/* theory of operation:**c_cancoresavesareceivedCANmessageintothefirstfreemessage*objectitfindsfree(startingwiththelowest).BitsNEWDATand
@@ -848,8 +834,7 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)structc_can_priv*priv=netdev_priv(dev);u32pkts=0,pend=0,toread,n;-/*-*Itisfastertoreadonlyone16bitregister.Thisisonlypossible+/* It is faster to read only one 16bit register. This is only possible*foramaximumnumberof16objects.*/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;-/*-*Ifthependingfieldhasagap,handlethe+/* If the pending field has a gap, handle the*bitsabovethegapfirst.*/toread=c_can_adjust_pending(pend);
@@ -979,8 +963,7 @@ static int c_can_handle_bus_err(struct net_device *dev,structcan_frame*cf;structsk_buff*skb;-/*-*earlyexitifnolecupdateornoerror.+/* early exit if no lec update or no error.*nolecupdatemeansthatnoCANbuseventhasbeendetected*sinceCPUwrote0x7valuetostatusreg.*/
@@ -999,8 +982,7 @@ static int c_can_handle_bus_err(struct net_device *dev,if(unlikely(!skb))return0;-/*-*checkfor'lasterrorcode'whichtellsusthe+/* check for 'last error code' which tells us the*typeofthelasterrortooccurontheCANbus*/cf->can_id|=CAN_ERR_PROT|CAN_ERR_BUSERROR;
@@ -41,8 +41,7 @@ struct c_can_pci_data {void(*init)(conststructc_can_priv*priv,boolenable);};-/*-*16-bitc_canregisterscanbearrangeddifferentlyinthememory+/* 16-bit c_can registers can be arranged differently in the memory*architectureofdifferentimplementations.Forexample:16-bit*registerscanbealignedtoa16-bitboundaryor32-bitboundaryetc.*Handlethesamebyprovidingacommonread/writeinterface.
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:30
This 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.
Link: https://lore.kernel.org/r/20210304161209.2754463-1-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
.../net/can/spi/mcp251xfd/mcp251xfd-core.c | 23 +++++++++++++++----
1 file changed, 18 insertions(+), 5 deletions(-)
@@ -753,7 +753,8 @@ static u32 c_can_adjust_pending(u32 pend)/* Find the first set bit after the gap. We walk backwards*fromthelastsetbit.*/-for(lasts--;pend&(1<<(lasts-1));lasts--);+for(lasts--;pend&(1<<(lasts-1));lasts--)+;returnpend&~((1<<lasts)-1);}
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:31
From: Dario Binacchi <redacted>
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.
Reported-by: kernel test robot <redacted>
Link: https://lore.kernel.org/r/20210302215435.18286-6-dariobin@libero.it
Signed-off-by: Dario Binacchi <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
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(-)
@@ -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 */enumc_can_lec_type{LEC_NO_ERROR=0,
@@ -443,10 +440,10 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,*prioritized.Thelowestbuffernumberwins.*/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().Wemustdothisbeforeweenable
@@ -527,17 +524,18 @@ static int c_can_set_bittiming(struct net_device *dev)*/staticvoidc_can_configure_msg_objects(structnet_device*dev){+structc_can_priv*priv=netdev_priv(dev);inti;/* 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*arecalledfromc_can_poll(),whichrunsinside
@@ -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)*racedwiththehardwareorfailedtoreadoutallupper*objectsinthelastrunduetoquotalimit.*/-staticu32c_can_adjust_pending(u32pend)+staticu32c_can_adjust_pending(u32pend,u32rx_mask){u32weight,lasts;-if(pend==RECEIVE_OBJECT_BITS)+if(pend==rx_mask)returnpend;/* 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*foramaximumnumberof16objects.*/-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*bitsabovethegapfirst.*/-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)return0;}-structnet_device*alloc_c_can_dev(void)+structnet_device*alloc_c_can_dev(intmsg_obj_num){structnet_device*dev;structc_can_priv*priv;+intmsg_obj_tx_num=msg_obj_num/2;-dev=alloc_candev(sizeof(structc_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)returnNULL;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;
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:58
From: Dario Binacchi <redacted>
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.
Link: https://lore.kernel.org/r/20210302215435.18286-4-dariobin@libero.it
Signed-off-by: Dario Binacchi <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/c_can/c_can.c | 5 +++++
1 file changed, 5 insertions(+)
@@ -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+*arecalledfromc_can_poll(),whichrunsinside+*NAPI.Wearenottrasmitting.+*/c_can_inval_tx_object(dev,IF_RX,obj);can_get_echo_skb(dev,idx,NULL);bytes+=priv->dlc[idx];
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:58
From: Dario Binacchi <redacted>
The arbitration register is already set up with 32-bit writes in the
other parts of the code except for this point.
Link: https://lore.kernel.org/r/20210302215435.18286-5-dariobin@libero.it
Signed-off-by: Dario Binacchi <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/c_can/c_can.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-03-30 11:47:58
From: Dario Binacchi <redacted>
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.
Link: https://lore.kernel.org/r/20210302215435.18286-7-dariobin@libero.it
Signed-off-by: Dario Binacchi <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
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(-)
@@ -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)structnet_device_stats*stats=&dev->stats;u32idx,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*fromthelastsetbit.*/-for(lasts--;pend&(1<<(lasts-1));lasts--)+for(lasts--;pend&BIT(lasts-1);lasts--);-returnpend&~((1<<lasts)-1);+returnpend&~GENMASK(lasts-1,0);}staticinlinevoidc_can_rx_object_get(structnet_device*dev,
@@ -835,11 +843,6 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)structc_can_priv*priv=netdev_priv(dev);u32pkts=0,pend=0,toread,n;-/* It is faster to read only one 16bit register. This is only possible-*foramaximumnumberof16objects.-*/-WARN_ON(priv->msg_obj_rx_last>16);-while(quota>0){if(!pend){pend=c_can_get_pending(priv);
@@ -31,6 +31,8 @@ enum c_can_pci_reg_align {structc_can_pci_data{/* Specify if is C_CAN or D_CAN */enumc_can_dev_idtype;+/* Number of message objects */+unsignedintmsg_obj_num;/* Set the register alignment in the memory */enumc_can_pci_reg_alignreg_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;gotoout_iounmap;
Hello:
This pull request was applied to netdev/net-next.git (refs/heads/master):
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 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.
[...]
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
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 [off-list ref] (#5.1.1)
For now remove all CAN related entries of Dan from the Maintainers
file.
[...]