add support for ETAS ES58X CAN USB interfaces
v10 cover add support for ETAS ES58X CAN USB interfaces
Here is the v10 of the patch.
Hope that we are now close to a release. Thanks for your comments!
Yours sincerely,
Vincent
---
Changes in v10 (2021-01-12):
- Rebased on linux-can-next/testing and modified according to latest
BQL patches.
Reference: https://lore.kernel.org/linux-can/[email protected]/T/#m5f99d4da8e8934a75f9481ecc3137b59f3762413
- Replaced __netdev_sent_queue() by netdev_sent_queue().
Changes in v9 (2021-01-09):
- es58x_start_xmit(): do not use skb anymore after the call of can_put_echo_skb(). Rationale: can_put_echo_skb() calls skb_clone() and thus the original skb gets consumed (i.e. use after free issue).
- es58x_start_xmit(): Add a "drop_skb" label to free the skb when errors occur.
Changes in v8 (2021-01-04):
- The driver requires CRC16. Modified Kconfig accordingly.
Changes in v7 (2020-11-17):
- Fix compilation issue if CONFIG_BQL is not set.
Reference: https://lkml.org/lkml/2020/11/15/163
Changes in v6 (2020-11-15):
- Rebase the patch on the testing branch of linux-can-next.
- Rename the helper functions according latest changes
(e.g. can_cc_get_len() -> can_cc_dlc2len())
- Fix comments of enum es58x_physical_layer and enum
es58x_sync_edge.Changes in v5 (2020-11-07):
- Add support for DLC greater than 8.
- All other patches from the previous series were either accepted or dismissed. As such, this is not a series any more but a single patch.
Changes in v4 (2020-10-17):
- Remove struct es58x_abstracted_can_frame.
- Fix formatting (spaces, comment style).
- Transform macros into static inline functions when possible.
- Fix the ctrlmode_supported flags in es581_4.c and removed misleading comments in enum es58x_samples_per_bit.
- Rename enums according to the type.
- Remove function es58x_can_put_echo_skb().
Reference: https://lkml.org/lkml/2020/10/10/53
Changes in v3 (2020-10-03):
- Remove all the calls to likely() and unlikely().
Reference: https://lkml.org/lkml/2020/9/30/995
Changes in v2 (2020-09-30):
- Fixed -W1 warnings (v1 was tested with GCC -WExtra but not with
-W1).
v1 (2020-09-27):
- First release
Vincent Mailhol (1):
can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
drivers/net/can/usb/Kconfig | 10 + drivers/net/can/usb/Makefile | 1 + drivers/net/can/usb/etas_es58x/Makefile | 3 + drivers/net/can/usb/etas_es58x/es581_4.c | 552 ++++ drivers/net/can/usb/etas_es58x/es581_4.h | 206 ++ drivers/net/can/usb/etas_es58x/es58x_core.c | 2589 +++++++++++++++++++ drivers/net/can/usb/etas_es58x/es58x_core.h | 707 +++++ drivers/net/can/usb/etas_es58x/es58x_fd.c | 662 +++++ drivers/net/can/usb/etas_es58x/es58x_fd.h | 242 ++ 9 files changed, 4972 insertions(+) create mode 100644 drivers/net/can/usb/etas_es58x/Makefile create mode 100644 drivers/net/can/usb/etas_es58x/es581_4.c create mode 100644 drivers/net/can/usb/etas_es58x/es581_4.h create mode 100644 drivers/net/can/usb/etas_es58x/es58x_core.c create mode 100644 drivers/net/can/usb/etas_es58x/es58x_core.h create mode 100644 drivers/net/can/usb/etas_es58x/es58x_fd.c create mode 100644 drivers/net/can/usb/etas_es58x/es58x_fd.h
Signature · 1 line
2.26.2
PATCH v10 1/1 can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
--- drivers/net/can/usb/Kconfig | 10 + drivers/net/can/usb/Makefile | 1 + drivers/net/can/usb/etas_es58x/Makefile | 3 + drivers/net/can/usb/etas_es58x/es581_4.c | 552 ++++ drivers/net/can/usb/etas_es58x/es581_4.h | 206 ++ drivers/net/can/usb/etas_es58x/es58x_core.c | 2589 +++++++++++++++++++ drivers/net/can/usb/etas_es58x/es58x_core.h | 707 +++++ drivers/net/can/usb/etas_es58x/es58x_fd.c | 662 +++++ drivers/net/can/usb/etas_es58x/es58x_fd.h | 242 ++ 9 files changed, 4972 insertions(+) create mode 100644 drivers/net/can/usb/etas_es58x/Makefile create mode 100644 drivers/net/can/usb/etas_es58x/es581_4.c create mode 100644 drivers/net/can/usb/etas_es58x/es581_4.h create mode 100644 drivers/net/can/usb/etas_es58x/es58x_core.c create mode 100644 drivers/net/can/usb/etas_es58x/es58x_core.h create mode 100644 drivers/net/can/usb/etas_es58x/es58x_fd.c create mode 100644 drivers/net/can/usb/etas_es58x/es58x_fd.h
drivers/net/can/usb/Kconfig +10 -0
@@ -20,6 +20,16 @@ config CAN_ESD_USB2 This driver supports the CAN-USB/2 interface from esd electronic system design gmbh (http://www.esd.eu). +config CAN_ETAS_ES58X + tristate "ETAS ES58X CAN/USB interfaces" + select CRC16 + help + This driver supports the ES581.4, ES582.1 and ES584.1 interfaces + from ETAS GmbH (https://www.etas.com/en/products/es58x.php). + + To compile this driver as a module, choose M here: the module + will be called etas_es58x. + config CAN_GS_USB tristate "Geschwister Schneider UG interfaces" help
drivers/net/can/usb/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_CAN_8DEV_USB) += usb_8dev.o obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o obj-$(CONFIG_CAN_ESD_USB2) += esd_usb2.o +obj-$(CONFIG_CAN_ETAS_ES58X) += etas_es58x/ obj-$(CONFIG_CAN_GS_USB) += gs_usb.o obj-$(CONFIG_CAN_KVASER_USB) += kvaser_usb/ obj-$(CONFIG_CAN_MCBA_USB) += mcba_usb.o
drivers/net/can/usb/etas_es58x/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_CAN_ETAS_ES58X) += etas_es58x.o +etas_es58x-y = es58x_core.o es581_4.o es58x_fd.o
drivers/net/can/usb/etas_es58x/es581_4.c new file +552 -0
552 lines not on this page · raw message
drivers/net/can/usb/etas_es58x/es581_4.h new file +206 -0
206 lines not on this page · raw message
drivers/net/can/usb/etas_es58x/es58x_core.c new file +2589 -0
2,216 lines not on this page · raw message
drivers/net/can/usb/etas_es58x/es58x_core.h new file +707 -0
707 lines not on this page · raw message
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +662 -0
662 lines not on this page · raw message
drivers/net/can/usb/etas_es58x/es58x_fd.h new file +242 -0
242 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.26.2
Part of the diff is not shown here. View the raw message.
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 9 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
Co-developed-by Arunachalam Santhanam <[email protected]>Signed-off-by Arunachalam Santhanam <[email protected]>Signed-off-by Vincent Mailhol <[email protected]>---
Something strange is going on with the mailing list. I can not see the second patch (1/1) in the *linux-can* mailing archive (only the cover letter is present):
https://lore.kernel.org/linux-can/[email protected]/T/#
However, the full patch series is present on the *netdev* mailing
archives: https://lore.kernel.org/netdev/[email protected]/
Are there any restrictions in regard to the patch size on the linux-can mailing list? Or did I did anything wrong which triggered some kind of spam filter?
Yours sincerely,
Vincent
Marc Kleine-Budde
maintainerRe: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 17 lines · Vincent MAILHOL
Quoted 9 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
Co-developed-by Arunachalam Santhanam <[email protected]>Signed-off-by Arunachalam Santhanam <[email protected]>Signed-off-by Vincent Mailhol <[email protected]>---
Something strange is going on with the mailing list. I can not see the second patch (1/1) in the *linux-can* mailing archive (only the cover letter is present):
https://lore.kernel.org/linux-can/[email protected]/T/#
Quoted 5 lines
However, the full patch series is present on the *netdev* mailing
archives: https://lore.kernel.org/netdev/[email protected]/Are there any restrictions in regard to the patch size on the linux-can mailing list?
Not to my knowledge.
Quoted 1 line
Or did I did anything wrong which triggered some kind of spam filter?
Both lists are hosted on vger.kernel.org. You might ask on [email protected]
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 18 lines · Marc Kleine-Budde
Quoted 17 lines · Vincent MAILHOL
Quoted 9 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
Co-developed-by Arunachalam Santhanam <[email protected]>Signed-off-by Arunachalam Santhanam <[email protected]>Signed-off-by Vincent Mailhol <[email protected]>---
Something strange is going on with the mailing list. I can not see the second patch (1/1) in the *linux-can* mailing archive (only the cover letter is present):
https://lore.kernel.org/linux-can/[email protected]/T/#
Quoted 7 lines
Quoted 5 lines
However, the full patch series is present on the *netdev* mailing
archives: https://lore.kernel.org/netdev/[email protected]/Are there any restrictions in regard to the patch size on the linux-can mailing list?
Not to my knowledge.
I remember having issues posting a large patch.
You probably hit this limit:
"Message size exceeding 100 000 characters causes blocking."
http://vger.kernel.org/majordomo-info.html
Regards,
jimmy
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 25 lines · Jimmy Assarsson
Quoted 24 lines · Marc Kleine-Budde
Quoted 22 lines · Vincent MAILHOL
Quoted 9 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
Co-developed-by Arunachalam Santhanam <[email protected]>Signed-off-by Arunachalam Santhanam <[email protected]>Signed-off-by Vincent Mailhol <[email protected]>---
Something strange is going on with the mailing list. I can not see the second patch (1/1) in the *linux-can* mailing archive (only the cover letter is present):
https://lore.kernel.org/linux-can/[email protected]/T/#However, the full patch series is present on the *netdev* mailing
archives: https://lore.kernel.org/netdev/[email protected]/Are there any restrictions in regard to the patch size on the linux-can mailing list?
Quoted 7 lines
Quoted 1 line
Not to my knowledge.
I remember having issues posting a large patch.
You probably hit this limit:
"Message size exceeding 100 000 characters causes blocking."
http://vger.kernel.org/majordomo-info.html
Thanks!
So, that's the issue. The patch has 161486 characters, way above the limit...
Marc, is this an issue for the patch review? I have no idea how to split it in a pretty way.
Yours sincerely,
Vincent Mailhol
Marc Kleine-Budde
maintainerRe: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 34 lines · Vincent MAILHOL
Quoted 25 lines · Jimmy Assarsson
Quoted 24 lines · Marc Kleine-Budde
Quoted 22 lines · Vincent MAILHOL
Quoted 9 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
Co-developed-by Arunachalam Santhanam <[email protected]>Signed-off-by Arunachalam Santhanam <[email protected]>Signed-off-by Vincent Mailhol <[email protected]>---
Something strange is going on with the mailing list. I can not see the second patch (1/1) in the *linux-can* mailing archive (only the cover letter is present):
https://lore.kernel.org/linux-can/[email protected]/T/#However, the full patch series is present on the *netdev* mailing
archives: https://lore.kernel.org/netdev/[email protected]/Are there any restrictions in regard to the patch size on the linux-can mailing list?
Quoted 7 lines
Quoted 1 line
Not to my knowledge.
I remember having issues posting a large patch.
You probably hit this limit:
"Message size exceeding 100 000 characters causes blocking."
http://vger.kernel.org/majordomo-info.html
Quoted 6 lines
Thanks!
So, that's the issue. The patch has 161486 characters, way above the limit...Marc, is this an issue for the patch review? I have no idea how to split it in a pretty way.
Time, or rather the lack of, is the biggest problem when reviewing a patch. Larger patches take more time, but that's the way it is with complex drivers....
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
kernel test robot
build botRe: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
In reply to Vincent MailholThank you for the patch! Yet something to improve:
Hi Vincent,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.11-rc3 next-20210111]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Vincent-Mailhol/add-support-for-ETAS-ES58X-CAN-USB-interfaces/20210112-211624 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git a0d54b4f5b219fb31f0776e9f53aa137e78ae431 config: m68k-allmodconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/5f55487bd139c33d619a9c8cd8dbd5cb8b558526
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Vincent-Mailhol/add-support-for-ETAS-ES58X-CAN-USB-interfaces/20210112-211624 git checkout 5f55487bd139c33d619a9c8cd8dbd5cb8b558526
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from include/linux/kernel.h:10,
from drivers/net/can/usb/etas_es58x/es58x_core.c:13:
include/linux/scatterlist.h: In function 'sg_set_buf':
arch/m68k/include/asm/page_mm.h:174:49: warning: ordered comparison of pointer with null pointer [-Wextra]
174 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:137:2: note: in expansion of macro 'BUG_ON'
137 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:137:10: note: in expansion of macro 'virt_addr_valid'
137 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
drivers/net/can/usb/etas_es58x/es58x_core.c: In function 'es58x_can_free_echo_skb_tail':
>> drivers/net/can/usb/etas_es58x/es58x_core.c:393:52: error: 'struct can_skb_priv' has no member named 'frame_len'
393 | netdev_completed_queue(netdev, 1, can_skb_prv(skb)->frame_len);
| ^~
drivers/net/can/usb/etas_es58x/es58x_core.c: In function 'es58x_can_get_echo_skb':
>> drivers/net/can/usb/etas_es58x/es58x_core.c:561:29: error: too many arguments to function 'can_get_echo_skb'
561 | netdev->stats.tx_bytes += can_get_echo_skb(netdev, tail_idx,
| ^~~~~~~~~~~~~~~~
In file included from drivers/net/can/usb/etas_es58x/es58x_core.h:19,
from drivers/net/can/usb/etas_es58x/es58x_core.c:21:
include/linux/can/dev.h:247:14: note: declared here
247 | unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx);
| ^~~~~~~~~~~~~~~~
drivers/net/can/usb/etas_es58x/es58x_core.c: In function 'es58x_start_xmit':
>> drivers/net/can/usb/etas_es58x/es58x_core.c:2104:14: error: implicit declaration of function 'can_skb_get_frame_len' [-Werror=implicit-function-declaration]
2104 | frame_len = can_skb_get_frame_len(skb);
| ^~~~~~~~~~~~~~~~~~~~~
>> drivers/net/can/usb/etas_es58x/es58x_core.c:2106:8: error: too many arguments to function 'can_put_echo_skb'
2106 | ret = can_put_echo_skb(skb, netdev, skb_idx, frame_len);
| ^~~~~~~~~~~~~~~~
In file included from drivers/net/can/usb/etas_es58x/es58x_core.h:19,
from drivers/net/can/usb/etas_es58x/es58x_core.c:21: include/linux/can/dev.h:243:5: note: declared here
243 | int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
--
In file included from include/linux/kernel.h:10,
from drivers/net/can/usb/etas_es58x/es581_4.c:12:
include/linux/scatterlist.h: In function 'sg_set_buf':
arch/m68k/include/asm/page_mm.h:174:49: warning: ordered comparison of pointer with null pointer [-Wextra]
174 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:137:2: note: in expansion of macro 'BUG_ON'
137 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:137:10: note: in expansion of macro 'virt_addr_valid'
137 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
drivers/net/can/usb/etas_es58x/es581_4.c: At top level:
>> drivers/net/can/usb/etas_es58x/es581_4.c:532:19: error: 'CAN_FRAME_LEN_MAX' undeclared here (not in a function)
532 | .dql_limit_min = CAN_FRAME_LEN_MAX * 50,
| ^~~~~~~~~~~~~~~~~
--
In file included from include/linux/kernel.h:10,
from drivers/net/can/usb/etas_es58x/es58x_fd.c:14:
include/linux/scatterlist.h: In function 'sg_set_buf':
arch/m68k/include/asm/page_mm.h:174:49: warning: ordered comparison of pointer with null pointer [-Wextra]
174 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:137:2: note: in expansion of macro 'BUG_ON'
137 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:137:10: note: in expansion of macro 'virt_addr_valid'
137 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
drivers/net/can/usb/etas_es58x/es58x_fd.c: In function 'es58x_fd_rx_can_msg':
>> drivers/net/can/usb/etas_es58x/es58x_fd.c:37:15: error: implicit declaration of function 'canfd_sanitize_len' [-Werror=implicit-function-declaration]
37 | __msg_len = canfd_sanitize_len(__msg.len); \
| ^~~~~~~~~~~~~~~~~~
drivers/net/can/usb/etas_es58x/es58x_fd.c:123:24: note: in expansion of macro 'es58x_fd_sizeof_rx_tx_msg'
123 | u16 rx_can_msg_len = es58x_fd_sizeof_rx_tx_msg(*rx_can_msg);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/can/usb/etas_es58x/es58x_fd.c: At top level:
>> drivers/net/can/usb/etas_es58x/es58x_fd.c:642:19: error: 'CAN_FRAME_LEN_MAX' undeclared here (not in a function)
642 | .dql_limit_min = CAN_FRAME_LEN_MAX * 15,
| ^~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +393 drivers/net/can/usb/etas_es58x/es58x_core.c
377
378 /**
379 * es58x_can_free_echo_skb_tail() - Remove the oldest echo skb of the
380 * loopback FIFO.
381 * @netdev: CAN network device.
382 *
383 * Naming convention: the tail is the beginning of the FIFO, i.e. the
384 * first skb to have entered the FIFO.
385 */
386 static void es58x_can_free_echo_skb_tail(struct net_device *netdev)
387 {
388 struct es58x_priv *priv = es58x_priv(netdev);
389 u16 tail_idx = priv->echo_skb_tail_idx;
390 struct sk_buff *skb = priv->can.echo_skb[tail_idx];
391 unsigned long flags;
392
> 393 netdev_completed_queue(netdev, 1, can_skb_prv(skb)->frame_len);
394 can_free_echo_skb(netdev, tail_idx);
395
396 spin_lock_irqsave(&priv->echo_skb_spinlock, flags);
397 es58x_add_skb_idx(priv, &priv->echo_skb_tail_idx, 1);
398 priv->num_echo_skb--;
399 spin_unlock_irqrestore(&priv->echo_skb_spinlock, flags);
400
401 netdev->stats.tx_dropped++;
402 }
403
404 /**
405 * es58x_can_get_echo_skb_recovery() - Try to re-sync the loopback FIFO.
406 * @netdev: CAN network device.
407 * @packet_idx: Index
408 *
409 * This function should not be called under normal circumstances. In
410 * the unlikely case that one or several URB packages get dropped by
411 * the device, the index will get out of sync. Try to recover by
412 * dropping the echo skb packets with older indexes.
413 *
414 * Return: zero if recovery was successful, -EINVAL otherwise.
415 */
416 static int es58x_can_get_echo_skb_recovery(struct net_device *netdev,
417 u32 packet_idx)
418 {
419 struct es58x_priv *priv = es58x_priv(netdev);
420 u32 current_packet_idx, first_packet_idx, num_echo_skb;
421 unsigned long flags;
422 int ret = 0;
423
424 netdev->stats.tx_errors++;
425
426 spin_lock_irqsave(&priv->echo_skb_spinlock, flags);
427 current_packet_idx = priv->current_packet_idx;
428 num_echo_skb = priv->num_echo_skb;
429 spin_unlock_irqrestore(&priv->echo_skb_spinlock, flags);
430 first_packet_idx = current_packet_idx - num_echo_skb;
431
432 if (net_ratelimit())
433 netdev_warn(netdev,
434 "Bad loopback packet index: %u. First index: %u, end index %u, num_echo_skb: %02u/%02u\n",
435 packet_idx, first_packet_idx,
436 current_packet_idx - 1, num_echo_skb,
437 priv->can.echo_skb_max);
438
439 if (packet_idx < first_packet_idx) {
440 if (net_ratelimit())
441 netdev_warn(netdev,
442 "Received loopback is from the past. Ignoring it\n");
443 ret = -EINVAL;
444 } else if ((s32)(packet_idx - current_packet_idx) >= 0LL) {
445 if (net_ratelimit())
446 netdev_err(netdev,
447 "Received loopback is from the future. Ignoring it\n");
448 ret = -EINVAL;
449 } else {
450 if (net_ratelimit())
451 netdev_warn(netdev,
452 "Loopback recovery: dropping %u echo skb from index %u to %u\n",
453 packet_idx - first_packet_idx,
454 first_packet_idx, packet_idx - 1);
455 while (first_packet_idx != packet_idx) {
456 if (num_echo_skb == 0)
457 return -EINVAL;
458 es58x_can_free_echo_skb_tail(netdev);
459 first_packet_idx++;
460 num_echo_skb--;
461 }
462 }
463 return ret;
464 }
465
466 /**
467 * es58x_can_get_echo_skb() - Get the skb from the loopback FIFO and
468 * loop it back locally.
469 * @netdev: CAN network device.
470 * @packet_idx: Index of the first packet.
471 * @tstamps: Array of hardware timestamps received from a ES58X device.
472 * @pkts: Number of packets (and so, length of @tstamps).
473 *
474 * Callback function for when we receive a self reception acknowledgment.
475 * Retrieves the skb from the loopback FIFO, sets its hardware timestamp
476 * (the actual time it was sent) and loops it back locally.
477 *
478 * The device has to be active (i.e. network interface UP and not in
479 * bus off state or restarting).
480 *
481 * Packet indexes must be consecutive (i.e. index of first packet is
482 * @packet_idx, index of second packet is @packet_idx + 1 and index of
483 * last packet is @packet_idx + @pkts - 1).
484 *
485 * Return: zero on success.
486 */
487 int es58x_can_get_echo_skb(struct net_device *netdev, u32 packet_idx,
488 u64 *tstamps, unsigned int pkts)
489 {
490 struct es58x_priv *priv = es58x_priv(netdev);
491 u16 tail_idx;
492 u32 first_packet_idx;
493 unsigned long flags;
494 unsigned int rx_total_frame_len = 0;
495 int i;
496 int ret = 0;
497
498 if (!netif_running(netdev)) {
499 if (net_ratelimit())
500 netdev_info(netdev,
501 "%s: %s is down, dropping %d loopback packets\n",
502 __func__, netdev->name, pkts);
503 netdev->stats.tx_dropped++;
504 return 0;
505 } else if (!es58x_is_can_state_active(netdev)) {
506 if (net_ratelimit())
507 netdev_dbg(netdev,
508 "Bus is off or device is restarting. Ignoring %u loopback packets from index %u\n",
509 pkts, packet_idx);
510 /* stats.tx_dropped will be (or was already)
511 * incremented by
512 * drivers/net/can/net/dev.c:can_flush_echo_skb().
513 */
514 return 0;
515 } else if (priv->num_echo_skb == 0) {
516 if (net_ratelimit())
517 netdev_warn(netdev,
518 "Received %u loopback packets from index: %u but echo skb queue is empty.\n",
519 pkts, packet_idx);
520 netdev->stats.tx_dropped += pkts;
521 return 0;
522 }
523
524 spin_lock_irqsave(&priv->echo_skb_spinlock, flags);
525 first_packet_idx = priv->current_packet_idx - priv->num_echo_skb;
526 if (first_packet_idx != packet_idx) {
527 spin_unlock_irqrestore(&priv->echo_skb_spinlock, flags);
528 ret = es58x_can_get_echo_skb_recovery(netdev, packet_idx);
529 if (ret < 0) {
530 if (net_ratelimit())
531 netdev_warn(netdev,
532 "Could not find echo skb for loopback packet index: %u\n",
533 packet_idx);
534 return 0;
535 }
536 spin_lock_irqsave(&priv->echo_skb_spinlock, flags);
537 first_packet_idx =
538 priv->current_packet_idx - priv->num_echo_skb;
539 WARN_ON(first_packet_idx != packet_idx);
540 }
541 tail_idx = priv->echo_skb_tail_idx;
542 if (priv->num_echo_skb < pkts) {
543 int pkts_drop = pkts - priv->num_echo_skb;
544
545 if (net_ratelimit())
546 netdev_err(netdev,
547 "Received %u loopback packets but have only %d echo skb. Dropping %d echo skb\n",
548 pkts, priv->num_echo_skb, pkts_drop);
549 netdev->stats.tx_dropped += pkts_drop;
550 pkts -= pkts_drop;
551 }
552 spin_unlock_irqrestore(&priv->echo_skb_spinlock, flags);
553
554 for (i = 0; i < pkts; i++) {
555 struct sk_buff *skb = priv->can.echo_skb[tail_idx];
556 unsigned int frame_len = 0;
557
558 if (skb)
559 es58x_set_skb_timestamp(netdev, skb, tstamps[i]);
560
> 561 netdev->stats.tx_bytes += can_get_echo_skb(netdev, tail_idx, 562 &frame_len);
563 rx_total_frame_len += frame_len;
564
565 es58x_add_skb_idx(priv, &tail_idx, 1);
566 }
567
568 spin_lock_irqsave(&priv->echo_skb_spinlock, flags);
569 es58x_add_skb_idx(priv, &priv->echo_skb_tail_idx, pkts);
570 priv->num_echo_skb -= pkts;
571 spin_unlock_irqrestore(&priv->echo_skb_spinlock, flags);
572
573 netdev_completed_queue(netdev, pkts, rx_total_frame_len);
574 netdev->stats.tx_packets += pkts;
575
576 priv->err_passive_before_rtx_success = 0;
577 es58x_netif_wake_queue(netdev);
578
579 return ret;
580 }
581
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 10 lines · kernel test robot
Hi Vincent,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.11-rc3 next-20210111]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
The patch is applied on linux-can-next/testing. All the warnings are related to the latest drivers/net/can/dev API changes.
I thought that the test robot only checked the linux-kernel(a)vger.kernel.org open list and I didn't bother adding the "--base". So this is my bad, sorry for that.
Because this is a false positive, I will not send a new version (unless if requested).
Yours sincerely,
Vincent
Re: [kbuild-all] Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 5 lines · Vincent MAILHOL
Quoted 4 lines · kernel test robot
Hi Vincent,
Thank you for the patch! Yet something to improve:
Quoted 7 lines
Quoted 5 lines
[auto build test ERROR on linus/master]
[also build test ERROR on v5.11-rc3 next-20210111]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]The patch is applied on linux-can-next/testing. All the warnings are related to the latest
drivers/net/can/devAPI changes.
Hi Vincent,
Thanks for the feedback, we'll try linux-can-next/testing next time.
Best Regards,
Rong Chen
Quoted 14 lines
I thought that the test robot only checked the linux-kernel(a)vger.kernel.org open list and I didn't bother adding the "--base". So this is my bad, sorry for that.
Because this is a false positive, I will not send a new version (unless if requested).
Yours sincerely,
Vincent
_______________________________________________
kbuild-all mailing list -- kbuild-all(a)lists.01.org To unsubscribe send an email to kbuild-all-leave(a)lists.01.org
Marc Kleine-Budde
maintainerRe: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
In reply to Vincent MailholQuoted 6 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
Co-developed-by Arunachalam Santhanam <[email protected]>Signed-off-by Arunachalam Santhanam <[email protected]>Signed-off-by Vincent Mailhol <[email protected]>
[...]
Quoted 71 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +65
-0@@ -0,0 +1,2589 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Driver for ETAS GmbH ES58X USB CAN(-FD) Bus Interfaces. +* +* File es58x_core.c: Core logic to manage the network devices and the +* USB interface. +* +* Copyright (C) 2019 Robert Bosch Engineering and Business +* Solutions. All rights reserved. +* Copyright (C) 2020 ETAS K.K.. All rights reserved. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/usb.h> +#include <linux/crc16.h> +#include <linux/spinlock.h> +#include <asm/unaligned.h> + +#include "es58x_core.h" + +#define DRV_VERSION "1.00" +MODULE_AUTHOR ("Mailhol Vincent <[email protected]>" ); +MODULE_AUTHOR ("Arunachalam Santhanam <[email protected]>" ); +MODULE_DESCRIPTION ("Socket CAN driver for ETAS ES58X USB adapters" ); +MODULE_VERSION (DRV_VERSION ); +MODULE_LICENSE ("GPL v2" ); + +/* Vendor and product id */ +#define ES58X_MODULE_NAME "etas_es58x" +#define ES58X_VENDOR_ID 0x108C +#define ES581_4_PRODUCT_ID 0x0159 +#define ES582_1_PRODUCT_ID 0x0168 +#define ES584_1_PRODUCT_ID 0x0169 + +/* Table of devices which work with this driver */ +static const struct usb_device_id es58x_id_table[] = { + {USB_DEVICE (ES58X_VENDOR_ID ,ES581_4_PRODUCT_ID )}, + {USB_DEVICE (ES58X_VENDOR_ID ,ES582_1_PRODUCT_ID )}, + {USB_DEVICE (ES58X_VENDOR_ID ,ES584_1_PRODUCT_ID )}, + {}/* Terminating entry */ +}; + +MODULE_DEVICE_TABLE (usb, es58x_id_table); + +#define es58x_print_hex_dump (buf, len) \ + print_hex_dump(KERN_DEBUG, \ + ES58X_MODULE_NAME " " __stringify(buf) ": ", \ + DUMP_PREFIX_NONE, 16, 1, buf, len, false) + +#define es58x_print_hex_dump_debug (buf, len) \ + print_hex_dump_debug(ES58X_MODULE_NAME " " __stringify(buf) ": ",\ + DUMP_PREFIX_NONE, 16, 1, buf, len, false) + +/* The last two bytes of an ES58X command is a CRC16. The first two +* bytes (the start of frame) are skipped and the CRC calculation +* starts on the third byte. +*/ +#define ES58X_CRC_CALC_OFFSET 2 + +/** +* es58x_calculate_crc() - Compute the crc16 of a given URB. +* @urb_cmd: The URB command for which we want to calculate the CRC. +* @urb_len: Length of @urb_cmd. Must be at least bigger than 4
drivers/net/can/usb/etas_es58x/es58x_core.c line 75
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +10
-0+* (ES58X_CRC_CALC_OFFSET + sizeof(crc)) +* +* Return: crc16 value. +*/ +static u16 es58x_calculate_crc (const union es58x_urb_cmd *urb_cmd,u16 urb_len) +{ +u16 crc; +ssize_t len = urb_len -ES58X_CRC_CALC_OFFSET -sizeof (crc); + +WARN_ON (len <0 );
Is it possible to ensure earlier, that the urbs are of correct length?
Quoted 3 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +3
-0+ crc =crc16 (0 , &urb_cmd->raw_cmd[ES58X_CRC_CALC_OFFSET ], len); +return crc; +}
[...]
Quoted 35 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +35
-0+/** +* struct es58x_priv - All information specific to a CAN channel. +* @can: struct can_priv must be the first member (Socket CAN relies +* on the fact that function netdev_priv() returns a pointer to +* a struct can_priv). +* @es58x_dev: pointer to the corresponding ES58X device. +* @tx_urb: Used as a buffer to concatenate the TX messages and to do +* a bulk send. Please refer to es58x_start_xmit() for more +* details. +* @echo_skb_spinlock: Spinlock to protect the access to the echo skb +* FIFO. +* @current_packet_idx: Keeps track of the packet indexes. +* @echo_skb_tail_idx: beginning of the echo skb FIFO, i.e. index of +* the first element. +* @echo_skb_head_idx: end of the echo skb FIFO plus one, i.e. first +* free index. +* @num_echo_skb: actual number of elements in the FIFO. Thus, the end +* of the FIFO is echo_skb_head = (echo_skb_tail_idx + +* num_echo_skb) % can.echo_skb_max. +* @tx_total_frame_len: sum, in bytes, of the length of each of the +* CAN messages contained in @tx_urb. To be used as an input of +* netdev_sent_queue() for BQL. +* @tx_can_msg_cnt: Number of messages in @tx_urb. +* @tx_can_msg_is_fd: false: all messages in @tx_urb are Classical +* CAN, true: all messages in @tx_urb are CAN FD. Rationale: +* ES58X FD devices do not allow to mix Classical CAN and FD CAN +* frames in one single bulk transmission. +* @err_passive_before_rtx_success: The ES58X device might enter in a +* state in which it keeps alternating between error passive +* and active state. This counter keeps track of the number of +* error passive and if it gets bigger than +* ES58X_CONSECUTIVE_ERR_PASSIVE_MAX, es58x_rx_err_msg() will +* force the status to bus-off. +* @channel_idx: Channel index, starts at zero. +*/
drivers/net/can/usb/etas_es58x/es58x_core.c
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +10
-0+struct es58x_priv { +struct can_priv can; +struct es58x_device *es58x_dev; +struct urb *tx_urb; + +spinlock_t echo_skb_spinlock;/* Comments: c.f. supra */ +u32 current_packet_idx; +u16 echo_skb_tail_idx; +u16 echo_skb_head_idx; +u16 num_echo_skb;
Can you explain me how the tx-path works, especially why you need the current_packet_idx.
In the mcp251xfd driver, the number of TX buffers is a power of two, that makes things easier. tx_heads % len points to the next buffer to be filled, tx_tail % len points to the next buffer to be completed. tx_head - tx_tail is the fill level of the FIFO. This works without spinlocks.
drivers/net/can/usb/etas_es58x/es58x_core.c
Quoted 9 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +9
-0+ +u16 tx_total_frame_len; +u8 tx_can_msg_cnt; +bool tx_can_msg_is_fd; + +u8 err_passive_before_rtx_success; + +u8 channel_idx; +};
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Hi Marc,
Thanks for the comments!
Quoted 86 lines · Marc Kleine-Budde
Quoted 6 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
Co-developed-by Arunachalam Santhanam <[email protected]>Signed-off-by Arunachalam Santhanam <[email protected]>Signed-off-by Vincent Mailhol <[email protected]>[...]
Quoted 75 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +69
-0@@ -0,0 +1,2589 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Driver for ETAS GmbH ES58X USB CAN(-FD) Bus Interfaces. +* +* File es58x_core.c: Core logic to manage the network devices and the +* USB interface. +* +* Copyright (C) 2019 Robert Bosch Engineering and Business +* Solutions. All rights reserved. +* Copyright (C) 2020 ETAS K.K.. All rights reserved. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/usb.h> +#include <linux/crc16.h> +#include <linux/spinlock.h> +#include <asm/unaligned.h> + +#include "es58x_core.h" + +#define DRV_VERSION "1.00" +MODULE_AUTHOR ("Mailhol Vincent <[email protected]>" ); +MODULE_AUTHOR ("Arunachalam Santhanam <[email protected]>" ); +MODULE_DESCRIPTION ("Socket CAN driver for ETAS ES58X USB adapters" ); +MODULE_VERSION (DRV_VERSION ); +MODULE_LICENSE ("GPL v2" ); + +/* Vendor and product id */ +#define ES58X_MODULE_NAME "etas_es58x" +#define ES58X_VENDOR_ID 0x108C +#define ES581_4_PRODUCT_ID 0x0159 +#define ES582_1_PRODUCT_ID 0x0168 +#define ES584_1_PRODUCT_ID 0x0169 + +/* Table of devices which work with this driver */ +static const struct usb_device_id es58x_id_table[] = { + {USB_DEVICE (ES58X_VENDOR_ID ,ES581_4_PRODUCT_ID )}, + {USB_DEVICE (ES58X_VENDOR_ID ,ES582_1_PRODUCT_ID )}, + {USB_DEVICE (ES58X_VENDOR_ID ,ES584_1_PRODUCT_ID )}, + {}/* Terminating entry */ +}; + +MODULE_DEVICE_TABLE (usb, es58x_id_table); + +#define es58x_print_hex_dump (buf, len) \ + print_hex_dump(KERN_DEBUG, \ + ES58X_MODULE_NAME " " __stringify(buf) ": ", \ + DUMP_PREFIX_NONE, 16, 1, buf, len, false) + +#define es58x_print_hex_dump_debug (buf, len) \ + print_hex_dump_debug(ES58X_MODULE_NAME " " __stringify(buf) ": ",\ + DUMP_PREFIX_NONE, 16, 1, buf, len, false) + +/* The last two bytes of an ES58X command is a CRC16. The first two +* bytes (the start of frame) are skipped and the CRC calculation +* starts on the third byte. +*/ +#define ES58X_CRC_CALC_OFFSET 2 + +/** +* es58x_calculate_crc() - Compute the crc16 of a given URB. +* @urb_cmd: The URB command for which we want to calculate the CRC. +* @urb_len: Length of @urb_cmd. Must be at least bigger than 4 +* (ES58X_CRC_CALC_OFFSET + sizeof(crc)) +* +* Return: crc16 value. +*/
Quoted 8 lines
drivers/net/can/usb/etas_es58x/es58x_core.c line 75
Quoted 6 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +6
-0+static u16 es58x_calculate_crc (const union es58x_urb_cmd *urb_cmd,u16 urb_len) +{ +u16 crc; +ssize_t len = urb_len -ES58X_CRC_CALC_OFFSET -sizeof (crc); + +WARN_ON (len <0 );Is it possible to ensure earlier, that the urbs are of correct length?
Easy answer: it is ensured. On the Tx branch, I create the urbs so I know for sure that the length is correct. On the Rx branch, I have a dedicated function: es58x_check_rx_urb() for this purpose. I will remove that WARN_ON() and the one in es58x_get_crc().
I will also check the other WARN_ON() in my code to see if they can be removed (none on my test throughout the last ten months or so could trigger any of these WARN_ON() so should be fine to remove but I will double check).
Quoted 55 lines
Quoted 3 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +3
-0+ crc =crc16 (0 , &urb_cmd->raw_cmd[ES58X_CRC_CALC_OFFSET ], len); +return crc; +}[...]
Quoted 35 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +35
-0+/** +* struct es58x_priv - All information specific to a CAN channel. +* @can: struct can_priv must be the first member (Socket CAN relies +* on the fact that function netdev_priv() returns a pointer to +* a struct can_priv). +* @es58x_dev: pointer to the corresponding ES58X device. +* @tx_urb: Used as a buffer to concatenate the TX messages and to do +* a bulk send. Please refer to es58x_start_xmit() for more +* details. +* @echo_skb_spinlock: Spinlock to protect the access to the echo skb +* FIFO. +* @current_packet_idx: Keeps track of the packet indexes. +* @echo_skb_tail_idx: beginning of the echo skb FIFO, i.e. index of +* the first element. +* @echo_skb_head_idx: end of the echo skb FIFO plus one, i.e. first +* free index. +* @num_echo_skb: actual number of elements in the FIFO. Thus, the end +* of the FIFO is echo_skb_head = (echo_skb_tail_idx + +* num_echo_skb) % can.echo_skb_max. +* @tx_total_frame_len: sum, in bytes, of the length of each of the +* CAN messages contained in @tx_urb. To be used as an input of +* netdev_sent_queue() for BQL. +* @tx_can_msg_cnt: Number of messages in @tx_urb. +* @tx_can_msg_is_fd: false: all messages in @tx_urb are Classical +* CAN, true: all messages in @tx_urb are CAN FD. Rationale: +* ES58X FD devices do not allow to mix Classical CAN and FD CAN +* frames in one single bulk transmission. +* @err_passive_before_rtx_success: The ES58X device might enter in a +* state in which it keeps alternating between error passive +* and active state. This counter keeps track of the number of +* error passive and if it gets bigger than +* ES58X_CONSECUTIVE_ERR_PASSIVE_MAX, es58x_rx_err_msg() will +* force the status to bus-off. +* @channel_idx: Channel index, starts at zero. +*/ drivers/net/can/usb/etas_es58x/es58x_core.c
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +10
-0+struct es58x_priv { +struct can_priv can; +struct es58x_device *es58x_dev; +struct urb *tx_urb; + +spinlock_t echo_skb_spinlock;/* Comments: c.f. supra */ +u32 current_packet_idx; +u16 echo_skb_tail_idx; +u16 echo_skb_head_idx; +u16 num_echo_skb;Can you explain me how the tx-path works, especially why you need the
current_packet_idx.
Quoted 4 lines
In the mcp251xfd driver, the number of TX buffers is a power of two, that makes things easier.
tx_heads% len points to the next buffer to be filled,tx_tail% len points to the next buffer to be completed.tx_head-tx_tailis the fill level of the FIFO. This works without spinlocks.
For what I understand of your explanations here are the equivalences between the etas_es58x and the mcp251xfd drivers:
+--------------------+-------------------+ | etas_es58x | mcp251xfd | +--------------------+-------------------+ | current_packet_idx | tx_head | | echo_skb_tail_idx | tx_tail % len | | echo_skb_head_idx | tx_head % len | | num_echo_skb | tx_head - tx_tail | +--------------------+-------------------+
Especially, the current_packet_idx is sent to the device and returned to the driver upon completion.
I wish the TX buffers were a power of two which is unfortunately not the case. The theoretical TX buffer sizes are 330 and 500 for the two devices so I wrote the code to work with those values. The exact size of the TX buffer is actually even more of a mystery because during testing both devices were unstable when using the theoretical values and I had to lower these. There is a comment at the bottom of es581_4.c and es58x_fd.c to reflect those issues. Because I do not have access to the source code of the firmware, I could not identify the root cause.
My understanding is that having a queue size being a power of two is required in order not to use spinlocks (else, modulo operations would break when the index wraparound back to zero). I tried to minimize the number of spinlock: only one per bulk send or bulk receive.
Yours sincerely,
Vincent
Quoted 18 lines
drivers/net/can/usb/etas_es58x/es58x_core.c
Quoted 9 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +9
-0+ +u16 tx_total_frame_len; +u8 tx_can_msg_cnt; +bool tx_can_msg_is_fd; + +u8 err_passive_before_rtx_success; + +u8 channel_idx; +};Marc
--
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 196 lines · Vincent MAILHOL
Hi Marc,
Thanks for the comments!
Quoted 86 lines · Marc Kleine-Budde
Quoted 6 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
Co-developed-by Arunachalam Santhanam <[email protected]>Signed-off-by Arunachalam Santhanam <[email protected]>Signed-off-by Vincent Mailhol <[email protected]>[...]
Quoted 75 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +69
-0@@ -0,0 +1,2589 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Driver for ETAS GmbH ES58X USB CAN(-FD) Bus Interfaces. +* +* File es58x_core.c: Core logic to manage the network devices and the +* USB interface. +* +* Copyright (C) 2019 Robert Bosch Engineering and Business +* Solutions. All rights reserved. +* Copyright (C) 2020 ETAS K.K.. All rights reserved. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/usb.h> +#include <linux/crc16.h> +#include <linux/spinlock.h> +#include <asm/unaligned.h> + +#include "es58x_core.h" + +#define DRV_VERSION "1.00" +MODULE_AUTHOR ("Mailhol Vincent <[email protected]>" ); +MODULE_AUTHOR ("Arunachalam Santhanam <[email protected]>" ); +MODULE_DESCRIPTION ("Socket CAN driver for ETAS ES58X USB adapters" ); +MODULE_VERSION (DRV_VERSION ); +MODULE_LICENSE ("GPL v2" ); + +/* Vendor and product id */ +#define ES58X_MODULE_NAME "etas_es58x" +#define ES58X_VENDOR_ID 0x108C +#define ES581_4_PRODUCT_ID 0x0159 +#define ES582_1_PRODUCT_ID 0x0168 +#define ES584_1_PRODUCT_ID 0x0169 + +/* Table of devices which work with this driver */ +static const struct usb_device_id es58x_id_table[] = { + {USB_DEVICE (ES58X_VENDOR_ID ,ES581_4_PRODUCT_ID )}, + {USB_DEVICE (ES58X_VENDOR_ID ,ES582_1_PRODUCT_ID )}, + {USB_DEVICE (ES58X_VENDOR_ID ,ES584_1_PRODUCT_ID )}, + {}/* Terminating entry */ +}; + +MODULE_DEVICE_TABLE (usb, es58x_id_table); + +#define es58x_print_hex_dump (buf, len) \ + print_hex_dump(KERN_DEBUG, \ + ES58X_MODULE_NAME " " __stringify(buf) ": ", \ + DUMP_PREFIX_NONE, 16, 1, buf, len, false) + +#define es58x_print_hex_dump_debug (buf, len) \ + print_hex_dump_debug(ES58X_MODULE_NAME " " __stringify(buf) ": ",\ + DUMP_PREFIX_NONE, 16, 1, buf, len, false) + +/* The last two bytes of an ES58X command is a CRC16. The first two +* bytes (the start of frame) are skipped and the CRC calculation +* starts on the third byte. +*/ +#define ES58X_CRC_CALC_OFFSET 2 + +/** +* es58x_calculate_crc() - Compute the crc16 of a given URB. +* @urb_cmd: The URB command for which we want to calculate the CRC. +* @urb_len: Length of @urb_cmd. Must be at least bigger than 4 +* (ES58X_CRC_CALC_OFFSET + sizeof(crc)) +* +* Return: crc16 value. +*/ Quoted 8 lines
drivers/net/can/usb/etas_es58x/es58x_core.c line 75
Quoted 6 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +6
-0+static u16 es58x_calculate_crc (const union es58x_urb_cmd *urb_cmd,u16 urb_len) +{ +u16 crc; +ssize_t len = urb_len -ES58X_CRC_CALC_OFFSET -sizeof (crc); + +WARN_ON (len <0 );Is it possible to ensure earlier, that the urbs are of correct length?
Easy answer: it is ensured. On the Tx branch, I create the urbs so I know for sure that the length is correct. On the Rx branch, I have a dedicated function:
es58x_check_rx_urb()for this purpose. I will remove thatWARN_ON()and the one ines58x_get_crc().I will also check the other
WARN_ON()in my code to see if they can be removed (none on my test throughout the last ten months or so could trigger any of theseWARN_ON()so should be fine to remove but I will double check).Quoted 55 lines
Quoted 3 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +3
-0+ crc =crc16 (0 , &urb_cmd->raw_cmd[ES58X_CRC_CALC_OFFSET ], len); +return crc; +}[...]
Quoted 35 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +35
-0+/** +* struct es58x_priv - All information specific to a CAN channel. +* @can: struct can_priv must be the first member (Socket CAN relies +* on the fact that function netdev_priv() returns a pointer to +* a struct can_priv). +* @es58x_dev: pointer to the corresponding ES58X device. +* @tx_urb: Used as a buffer to concatenate the TX messages and to do +* a bulk send. Please refer to es58x_start_xmit() for more +* details. +* @echo_skb_spinlock: Spinlock to protect the access to the echo skb +* FIFO. +* @current_packet_idx: Keeps track of the packet indexes. +* @echo_skb_tail_idx: beginning of the echo skb FIFO, i.e. index of +* the first element. +* @echo_skb_head_idx: end of the echo skb FIFO plus one, i.e. first +* free index. +* @num_echo_skb: actual number of elements in the FIFO. Thus, the end +* of the FIFO is echo_skb_head = (echo_skb_tail_idx + +* num_echo_skb) % can.echo_skb_max. +* @tx_total_frame_len: sum, in bytes, of the length of each of the +* CAN messages contained in @tx_urb. To be used as an input of +* netdev_sent_queue() for BQL. +* @tx_can_msg_cnt: Number of messages in @tx_urb. +* @tx_can_msg_is_fd: false: all messages in @tx_urb are Classical +* CAN, true: all messages in @tx_urb are CAN FD. Rationale: +* ES58X FD devices do not allow to mix Classical CAN and FD CAN +* frames in one single bulk transmission. +* @err_passive_before_rtx_success: The ES58X device might enter in a +* state in which it keeps alternating between error passive +* and active state. This counter keeps track of the number of +* error passive and if it gets bigger than +* ES58X_CONSECUTIVE_ERR_PASSIVE_MAX, es58x_rx_err_msg() will +* force the status to bus-off. +* @channel_idx: Channel index, starts at zero. +*/ drivers/net/can/usb/etas_es58x/es58x_core.c
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +10
-0+struct es58x_priv { +struct can_priv can; +struct es58x_device *es58x_dev; +struct urb *tx_urb; + +spinlock_t echo_skb_spinlock;/* Comments: c.f. supra */ +u32 current_packet_idx; +u16 echo_skb_tail_idx; +u16 echo_skb_head_idx; +u16 num_echo_skb;Can you explain me how the tx-path works, especially why you need the
current_packet_idx.Quoted 4 lines
In the mcp251xfd driver, the number of TX buffers is a power of two, that makes things easier.
tx_heads% len points to the next buffer to be filled,tx_tail% len points to the next buffer to be completed.tx_head-tx_tailis the fill level of the FIFO. This works without spinlocks.For what I understand of your explanations here are the equivalences between the
etas_es58xand the mcp251xfd drivers:+--------------------+-------------------+ | etas_es58x | mcp251xfd | +--------------------+-------------------+ | current_packet_idx | tx_head | | echo_skb_tail_idx | tx_tail % len | | echo_skb_head_idx | tx_head % len | | num_echo_skb | tx_head - tx_tail | +--------------------+-------------------+Especially, the
current_packet_idxis sent to the device and returned to the driver upon completion.I wish the TX buffers were a power of two which is unfortunately not the case. The theoretical TX buffer sizes are 330 and 500 for the two devices so I wrote the code to work with those values. The exact size of the TX buffer is actually even more of a mystery because during testing both devices were unstable when using the theoretical values and I had to lower these. There is a comment at the bottom of
es581_4.candes58x_fd.cto reflect those issues. Because I do not have access to the source code of the firmware, I could not identify the root cause.
Quoted 4 lines
My understanding is that having a queue size being a power of two is required in order not to use spinlocks (else, modulo operations would break when the index wraparound back to zero). I tried to minimize the number of spinlock: only one per bulk send or bulk receive.
Or do you mean to round up the skb_echo array length to the next power of two in the driver despite the actual size of the device FIFO? Did not think about that in the past but that should work.
I am going to think a bit more of how to improve that.
Yours sincerely,
Vincent
Marc Kleine-Budde
maintainerRe: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 10 lines · Vincent MAILHOL
Quoted 4 lines
My understanding is that having a queue size being a power of two is required in order not to use spinlocks (else, modulo operations would break when the index wraparound back to zero). I tried to minimize the number of spinlock: only one per bulk send or bulk receive.
Or do you mean to round up the
skb_echoarray length to the next power of two in the driver despite the actual size of the device FIFO? Did not think about that in the past but that should work.I am going to think a bit more of how to improve that.
For the echo_skb rounding up might work, but you should round down, so that your can directly use the masked value.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Marc Kleine-Budde
maintainerRe: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
In reply to Vincent MAILHOLQuoted 17 lines · Vincent MAILHOL
Quoted 8 lines
Quoted 8 lines
+/**
+ *es58x_calculate_crc()- Compute the crc16 of a given URB.
+ * @urb_cmd: The URB command for which we want to calculate the CRC.
+ * @urb_len: Length of @urb_cmd. Must be at least bigger than 4
+ * (ES58X_CRC_CALC_OFFSET+ sizeof(crc))
+ *
+ * Return: crc16 value.
+ */Quoted 8 lines
drivers/net/can/usb/etas_es58x/es58x_core.c line 75
Quoted 6 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +6
-0+static u16 es58x_calculate_crc (const union es58x_urb_cmd *urb_cmd,u16 urb_len) +{ +u16 crc; +ssize_t len = urb_len -ES58X_CRC_CALC_OFFSET -sizeof (crc); + +WARN_ON (len <0 );Is it possible to ensure earlier, that the urbs are of correct length?
Quoted 1 line
Easy answer: it is ensured.
Okay, then get rid of those checks :)
Quoted 9 lines
On the Tx branch, I create the urbs so I
know for sure that the length is correct. On the Rx branch, I have a dedicated function:es58x_check_rx_urb()for this purpose. I will remove thatWARN_ON()and the one ines58x_get_crc().I will also check the other
WARN_ON()in my code to see if they can be removed (none on my test throughout the last ten months or so could trigger any of theseWARN_ON()so should be fine to remove but I will double check).
[..]
Quoted 31 lines
Quoted 14 lines
drivers/net/can/usb/etas_es58x/es58x_core.h line 260
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_core.h new file +10
-0+struct es58x_priv { +struct can_priv can; +struct es58x_device *es58x_dev; +struct urb *tx_urb; + +spinlock_t echo_skb_spinlock;/* Comments: c.f. supra */ +u32 current_packet_idx; +u16 echo_skb_tail_idx; +u16 echo_skb_head_idx; +u16 num_echo_skb;Can you explain me how the tx-path works, especially why you need the
current_packet_idx.Quoted 4 lines
In the mcp251xfd driver, the number of TX buffers is a power of two, that makes things easier.
tx_heads% len points to the next buffer to be filled,tx_tail% len points to the next buffer to be completed.tx_head-tx_tailis the fill level of the FIFO. This works without spinlocks.For what I understand of your explanations here are the equivalences between the
etas_es58xand the mcp251xfd drivers:+--------------------+-------------------+ | etas_es58x | mcp251xfd | +--------------------+-------------------+ | current_packet_idx | tx_head | | echo_skb_tail_idx | tx_tail % len | | echo_skb_head_idx | tx_head % len | | num_echo_skb | tx_head - tx_tail | +--------------------+-------------------+
Quoted 2 lines
Especially, the
current_packet_idxis sent to the device and returned to the driver upon completion.
Is current_packet_idx used only for the TX-PATH?
Quoted 7 lines
I wish the TX buffers were a power of two which is unfortunately not the case. The theoretical TX buffer sizes are 330 and 500 for the two devices so I wrote the code to work with those values. The exact size of the TX buffer is actually even more of a mystery because during testing both devices were unstable when using the theoretical values and I had to lower these. There is a comment at the bottom of
es581_4.candes58x_fd.cto reflect those issues.
What are the performance penalties for using 256 for the fd and 64 ofr the other?
Quoted 3 lines
Because I do not
have access to the source code of the firmware, I could not identify the root cause.
ok
Quoted 4 lines
My understanding is that having a queue size being a power of two is required in order not to use spinlocks (else, modulo operations would break when the index wraparound back to zero). I tried to minimize the number of spinlock: only one per bulk send or bulk receive.
With queue size being power of two the modulo can be written as a mask operation, so it's reasonable fast. So you only need to care about tx_head and tx_tail, and there is only one writer for each variable. With a little dance and barriers when stopping and starting the queue it's race-free without spinlocks.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 19 lines · Marc Kleine-Budde
Quoted 17 lines · Vincent MAILHOL
Quoted 16 lines
Quoted 4 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +4
-0+/** +* es58x_calculate_crc() - Compute the crc16 of a given URB. +* @urb_cmd: The URB command for which we want to calculate the CRC. +* @urb_len: Length of @urb_cmd. Must be at least bigger than 4 drivers/net/can/usb/etas_es58x/es58x_core.c line 75
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +10
-0+* (ES58X_CRC_CALC_OFFSET + sizeof(crc)) +* +* Return: crc16 value. +*/ +static u16 es58x_calculate_crc (const union es58x_urb_cmd *urb_cmd,u16 urb_len) +{ +u16 crc; +ssize_t len = urb_len -ES58X_CRC_CALC_OFFSET -sizeof (crc); + +WARN_ON (len <0 );Is it possible to ensure earlier, that the urbs are of correct length?
Quoted 13 lines
Quoted 1 line
Easy answer: it is ensured.
Okay, then get rid of those checks :)
Quoted 9 lines
On the Tx branch, I create the urbs so I
know for sure that the length is correct. On the Rx branch, I have a dedicated function:es58x_check_rx_urb()for this purpose. I will remove thatWARN_ON()and the one ines58x_get_crc().I will also check the other
WARN_ON()in my code to see if they can be removed (none on my test throughout the last ten months or so could trigger any of theseWARN_ON()so should be fine to remove but I will double check).
Checked, all WARN_ON() will be removed in v11.
Quoted 31 lines
Quoted 31 lines
Quoted 14 lines
drivers/net/can/usb/etas_es58x/es58x_core.h line 260
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_core.h new file +10
-0+struct es58x_priv { +struct can_priv can; +struct es58x_device *es58x_dev; +struct urb *tx_urb; + +spinlock_t echo_skb_spinlock;/* Comments: c.f. supra */ +u32 current_packet_idx; +u16 echo_skb_tail_idx; +u16 echo_skb_head_idx; +u16 num_echo_skb;Can you explain me how the tx-path works, especially why you need the
current_packet_idx.Quoted 4 lines
In the mcp251xfd driver, the number of TX buffers is a power of two, that makes things easier.
tx_heads% len points to the next buffer to be filled,tx_tail% len points to the next buffer to be completed.tx_head-tx_tailis the fill level of the FIFO. This works without spinlocks.For what I understand of your explanations here are the equivalences between the
etas_es58xand the mcp251xfd drivers:+--------------------+-------------------+ | etas_es58x | mcp251xfd | +--------------------+-------------------+ | current_packet_idx | tx_head | | echo_skb_tail_idx | tx_tail % len | | echo_skb_head_idx | tx_head % len | | num_echo_skb | tx_head - tx_tail | +--------------------+-------------------+
Quoted 4 lines
Quoted 2 lines
Especially, the
current_packet_idxis sent to the device and returned to the driver upon completion.Is
current_packet_idxused only for the TX-PATH?
It is used in the RX path of loopback packet. When a packet comes back, its index should be equal to current_packet_idx - num_echo_skb. I use this in es58x_can_get_echo_skb() to check that there are no packet drops.
Of course, if the FIFO size is a power of two, the current_packet_idx would become useless.
Quoted 9 lines
Quoted 7 lines
I wish the TX buffers were a power of two which is unfortunately not the case. The theoretical TX buffer sizes are 330 and 500 for the two devices so I wrote the code to work with those values. The exact size of the TX buffer is actually even more of a mystery because during testing both devices were unstable when using the theoretical values and I had to lower these. There is a comment at the bottom of
es581_4.candes58x_fd.cto reflect those issues.What are the performance penalties for using 256 for the fd and 64 ofr the other?
I checked my passed log, actually, I had good results with 256 on the FD. I lowered it to 255 with no strong reasons.
For the classical CAN changing from 75 to 64 should still be enough to reach full busload.
Quoted 11 lines
Quoted 3 lines
Because I do not
have access to the source code of the firmware, I could not identify the root cause.ok
Quoted 4 lines
My understanding is that having a queue size being a power of two is required in order not to use spinlocks (else, modulo operations would break when the index wraparound back to zero). I tried to minimize the number of spinlock: only one per bulk send or bulk receive.
Quoted 4 lines
With queue size being power of two the modulo can be written as a mask operation, so it's reasonable fast. So you only need to care about
tx_headandtx_tail, and there is only one writer for each variable. With a little dance and barriers when stopping and starting the queue it's race-free without spinlocks.
Yep, I checked linux/kfifo.h in the past. I think I understand the theory, now I need to practice.
I will try to do the change. Will get back to you later when it is done and tested.
Yours sincerely,
Vincent
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
In reply to Vincent MailholHi Vincent,
Quoted 2 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +0
-0
(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +5
-0+static void es58x_fd_print_bittiming (struct net_device *netdev, +struct es58x_fd_bittiming + *es58x_fd_bittiming,char *type) +{ + netdev_vdbg(netdev, "bitrate %s = %d\n", type,
drivers/net/can/usb/etas_es58x/es58x_fd.c line 412
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+ le32_to_cpu(es58x_fd_bittiming->bitrate)); +netdev_vdbg (netdev,"tseg1 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg1)); +netdev_vdbg (netdev,"tseg2 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg2)); +netdev_vdbg (netdev,"brp %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->brp)); +netdev_vdbg (netdev,"sjw %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->sjw)); +}
What is the reason for this code?
These values can be retrieved with the 'ip' tool and are probably interesting for development - but not in the final code.
Quoted 21 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +21
-0+ +static void es58x_fd_print_conf (struct net_device *netdev, +struct es58x_fd_tx_conf_msg *tx_conf_msg) +{ +es58x_fd_print_bittiming (netdev, &tx_conf_msg->nominal_bittiming, +"nominal" ); +netdev_vdbg (netdev,"samples_per_bit = %d\n" , + tx_conf_msg->samples_per_bit); +netdev_vdbg (netdev,"sync_edge = %d\n" , + tx_conf_msg->sync_edge); +netdev_vdbg (netdev,"physical_layer = %d\n" , + tx_conf_msg->physical_layer); +netdev_vdbg (netdev,"self_reception = %d\n" , + tx_conf_msg->self_reception_mode); +netdev_vdbg (netdev,"ctrlmode = %d\n" , tx_conf_msg->ctrlmode); +netdev_vdbg (netdev,"canfd_enabled = %d\n" , + tx_conf_msg->canfd_enabled); +if (tx_conf_msg->canfd_enabled) { +es58x_fd_print_bittiming (netdev, + &tx_conf_msg->data_bittiming,"data" ); + netdev_vdbg(netdev,
drivers/net/can/usb/etas_es58x/es58x_fd.c line 443
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+"Transmitter Delay Compensation = %d\n" , + tx_conf_msg->tdc); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Offset = %d\n" , +le16_to_cpu (tx_conf_msg->tdco)); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Filter = %d\n" , +le16_to_cpu (tx_conf_msg->tdcf)); + } +}
Same here.
Either the information can be retrieved with the 'ip' tool OR the are not necessary as set to some reasonable default anyway OR we should implement the functionality in the general CAN driver infrastructure.
Regards,
Oliver
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 35 lines · Oliver Hartkopp
Hi Vincent,
Quoted 2 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +0
-0(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +5
-0+static void es58x_fd_print_bittiming (struct net_device *netdev, +struct es58x_fd_bittiming + *es58x_fd_bittiming,char *type) +{ + netdev_vdbg(netdev, "bitrate %s = %d\n", type,drivers/net/can/usb/etas_es58x/es58x_fd.c line 412
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+ le32_to_cpu(es58x_fd_bittiming->bitrate)); +netdev_vdbg (netdev,"tseg1 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg1)); +netdev_vdbg (netdev,"tseg2 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg2)); +netdev_vdbg (netdev,"brp %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->brp)); +netdev_vdbg (netdev,"sjw %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->sjw)); +}What is the reason for this code?
Quoted 2 lines
These values can be retrieved with the 'ip' tool and are probably interesting for development - but not in the final code.
First thing, I used netdev_vdbg() (verbose debug). That macro will only produce code if VERBOSE_DEBUG is defined. Normal users will not see those. So yes, this is mostly for development.
Also, just realised that netdev_vdbg() is barely used anywhere (only three files use it:
https://elixir.bootlin.com/linux/v5.11-rc3/C/ident/netdev_vdbg).
I guess that I will remove it :)
Quoted 34 lines
Quoted 21 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +21
-0+ +static void es58x_fd_print_conf (struct net_device *netdev, +struct es58x_fd_tx_conf_msg *tx_conf_msg) +{ +es58x_fd_print_bittiming (netdev, &tx_conf_msg->nominal_bittiming, +"nominal" ); +netdev_vdbg (netdev,"samples_per_bit = %d\n" , + tx_conf_msg->samples_per_bit); +netdev_vdbg (netdev,"sync_edge = %d\n" , + tx_conf_msg->sync_edge); +netdev_vdbg (netdev,"physical_layer = %d\n" , + tx_conf_msg->physical_layer); +netdev_vdbg (netdev,"self_reception = %d\n" , + tx_conf_msg->self_reception_mode); +netdev_vdbg (netdev,"ctrlmode = %d\n" , tx_conf_msg->ctrlmode); +netdev_vdbg (netdev,"canfd_enabled = %d\n" , + tx_conf_msg->canfd_enabled); +if (tx_conf_msg->canfd_enabled) { +es58x_fd_print_bittiming (netdev, + &tx_conf_msg->data_bittiming,"data" ); + netdev_vdbg(netdev,drivers/net/can/usb/etas_es58x/es58x_fd.c line 443
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+"Transmitter Delay Compensation = %d\n" , + tx_conf_msg->tdc); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Offset = %d\n" , +le16_to_cpu (tx_conf_msg->tdco)); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Filter = %d\n" , +le16_to_cpu (tx_conf_msg->tdcf)); + } +}Same here.
Quoted 2 lines
Either the information can be retrieved with the 'ip' tool OR the are not necessary as set to some reasonable default anyway
Ack, will remove.
Quoted 2 lines
OR we should
implement the functionality in the general CAN driver infrastructure.
Would make sense to me to add the tdco (Transmitter Delay Compensation Offset). Ref: ISO 11898-1 section 11.3.3 "Transmitter delay compensation"
I would just like your opinion on one topic: the tdco is specific to CAN FD. If we add it, we have two choices:
1. put it in struct can_bittiming: that will mean that we will have an unused field for classical CAN (field bittiming of struct can_priv).
2. put it in struct can_priv (but outside of struct can_bittiming): no unused field but less pretty.
I think that 1/ is best.
Yours sincerely,
Vincent
Marc Kleine-Budde
maintainerRe: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 95 lines · Vincent MAILHOL
Quoted 35 lines · Oliver Hartkopp
Hi Vincent,
Quoted 2 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +0
-0(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +5
-0+static void es58x_fd_print_bittiming (struct net_device *netdev, +struct es58x_fd_bittiming + *es58x_fd_bittiming,char *type) +{ + netdev_vdbg(netdev, "bitrate %s = %d\n", type,drivers/net/can/usb/etas_es58x/es58x_fd.c line 412
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+ le32_to_cpu(es58x_fd_bittiming->bitrate)); +netdev_vdbg (netdev,"tseg1 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg1)); +netdev_vdbg (netdev,"tseg2 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg2)); +netdev_vdbg (netdev,"brp %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->brp)); +netdev_vdbg (netdev,"sjw %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->sjw)); +}What is the reason for this code?
Quoted 2 lines
These values can be retrieved with the 'ip' tool and are probably interesting for development - but not in the final code.
First thing, I used
netdev_vdbg()(verbose debug). That macro will only produce code ifVERBOSE_DEBUGis defined. Normal users will not see those. So yes, this is mostly for development.Also, just realised that
netdev_vdbg()is barely used anywhere (only three files use it:
https://elixir.bootlin.com/linux/v5.11-rc3/C/ident/netdev_vdbg).I guess that I will remove it :)
Quoted 34 lines
Quoted 21 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +21
-0+ +static void es58x_fd_print_conf (struct net_device *netdev, +struct es58x_fd_tx_conf_msg *tx_conf_msg) +{ +es58x_fd_print_bittiming (netdev, &tx_conf_msg->nominal_bittiming, +"nominal" ); +netdev_vdbg (netdev,"samples_per_bit = %d\n" , + tx_conf_msg->samples_per_bit); +netdev_vdbg (netdev,"sync_edge = %d\n" , + tx_conf_msg->sync_edge); +netdev_vdbg (netdev,"physical_layer = %d\n" , + tx_conf_msg->physical_layer); +netdev_vdbg (netdev,"self_reception = %d\n" , + tx_conf_msg->self_reception_mode); +netdev_vdbg (netdev,"ctrlmode = %d\n" , tx_conf_msg->ctrlmode); +netdev_vdbg (netdev,"canfd_enabled = %d\n" , + tx_conf_msg->canfd_enabled); +if (tx_conf_msg->canfd_enabled) { +es58x_fd_print_bittiming (netdev, + &tx_conf_msg->data_bittiming,"data" ); + netdev_vdbg(netdev,drivers/net/can/usb/etas_es58x/es58x_fd.c line 443
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+"Transmitter Delay Compensation = %d\n" , + tx_conf_msg->tdc); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Offset = %d\n" , +le16_to_cpu (tx_conf_msg->tdco)); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Filter = %d\n" , +le16_to_cpu (tx_conf_msg->tdcf)); + } +}Same here.
Quoted 2 lines
Either the information can be retrieved with the 'ip' tool OR the are not necessary as set to some reasonable default anyway
Ack, will remove.
Quoted 2 lines
OR we should
implement the functionality in the general CAN driver infrastructure.Would make sense to me to add the tdco (Transmitter Delay Compensation Offset). Ref: ISO 11898-1 section 11.3.3 "Transmitter delay compensation"
Quoted 7 lines
I would just like your opinion on one topic: the tdco is specific to CAN FD. If we add it, we have two choices:
1. put it in structcan_bittiming: that will mean that we will have an unused field for classical CAN (field bittiming of structcan_priv).
2. put it in structcan_priv(but outside of structcan_bittiming): no unused field but less pretty.
3. Deprecate struct can_bittiming as the user space interface and transfer each member individually via netlink. Extend the kernel-only can_bittiming by the tdc related parameters, and add these to the new netlink interface.
I prefer this, as I want to extend the bittiming_const in this way, too. There are CAN controllers, where the bit timing calculation:
Quoted 2 lines
bt->prop_seg = tseg1 / 2; bt->phase_seg1 = tseg1 - bt->prop_seg;
doesn't work anymore, as they have asymmetric prog_seg and phase_seg1, so that splitting tseg1 in half doesn't work anymore.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
-DaveM
-JacubK
-netdev
@Vincent: No need for cross posting and putting the networking maintainers in CC for these really deep CAN driver specific topics IHMO
Quoted 44 lines · Marc Kleine-Budde
Quoted 43 lines · Vincent MAILHOL
Quoted 35 lines · Oliver Hartkopp
Hi Vincent,
Quoted 2 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +0
-0(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +5
-0+static void es58x_fd_print_bittiming (struct net_device *netdev, +struct es58x_fd_bittiming + *es58x_fd_bittiming,char *type) +{ + netdev_vdbg(netdev, "bitrate %s = %d\n", type,drivers/net/can/usb/etas_es58x/es58x_fd.c line 412
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+ le32_to_cpu(es58x_fd_bittiming->bitrate)); +netdev_vdbg (netdev,"tseg1 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg1)); +netdev_vdbg (netdev,"tseg2 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg2)); +netdev_vdbg (netdev,"brp %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->brp)); +netdev_vdbg (netdev,"sjw %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->sjw)); +}What is the reason for this code?
Quoted 2 lines
These values can be retrieved with the 'ip' tool and are probably interesting for development - but not in the final code.
First thing, I used
netdev_vdbg()(verbose debug). That macro will only produce code ifVERBOSE_DEBUGis defined. Normal users will not see those. So yes, this is mostly for development.
Quoted 6 lines
Quoted 6 lines
Also, just realised that
netdev_vdbg()is barely used anywhere (only three files use it:
https://elixir.bootlin.com/linux/v5.11-rc3/C/ident/netdev_vdbg).I guess that I will remove it :)
Thanks! That will remove some more code in the background too.
Quoted 54 lines
Quoted 46 lines
Quoted 34 lines
Quoted 21 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +21
-0+ +static void es58x_fd_print_conf (struct net_device *netdev, +struct es58x_fd_tx_conf_msg *tx_conf_msg) +{ +es58x_fd_print_bittiming (netdev, &tx_conf_msg->nominal_bittiming, +"nominal" ); +netdev_vdbg (netdev,"samples_per_bit = %d\n" , + tx_conf_msg->samples_per_bit); +netdev_vdbg (netdev,"sync_edge = %d\n" , + tx_conf_msg->sync_edge); +netdev_vdbg (netdev,"physical_layer = %d\n" , + tx_conf_msg->physical_layer); +netdev_vdbg (netdev,"self_reception = %d\n" , + tx_conf_msg->self_reception_mode); +netdev_vdbg (netdev,"ctrlmode = %d\n" , tx_conf_msg->ctrlmode); +netdev_vdbg (netdev,"canfd_enabled = %d\n" , + tx_conf_msg->canfd_enabled); +if (tx_conf_msg->canfd_enabled) { +es58x_fd_print_bittiming (netdev, + &tx_conf_msg->data_bittiming,"data" ); + netdev_vdbg(netdev,drivers/net/can/usb/etas_es58x/es58x_fd.c line 443
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+"Transmitter Delay Compensation = %d\n" , + tx_conf_msg->tdc); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Offset = %d\n" , +le16_to_cpu (tx_conf_msg->tdco)); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Filter = %d\n" , +le16_to_cpu (tx_conf_msg->tdcf)); + } +}Same here.
Quoted 2 lines
Either the information can be retrieved with the 'ip' tool OR the are not necessary as set to some reasonable default anyway
Ack, will remove.
Quoted 2 lines
OR we should
implement the functionality in the general CAN driver infrastructure.Would make sense to me to add the tdco (Transmitter Delay Compensation Offset). Ref: ISO 11898-1 section 11.3.3 "Transmitter delay compensation"
Quoted 7 lines
I would just like your opinion on one topic: the tdco is specific to CAN FD. If we add it, we have two choices:
1. put it in structcan_bittiming: that will mean that we will have an unused field for classical CAN (field bittiming of structcan_priv).
2. put it in structcan_priv(but outside of structcan_bittiming): no unused field but less pretty.
Quoted 4 lines
3. Deprecate struct
can_bittimingas the user space interface and transfer each member individually via netlink. Extend the kernel-onlycan_bittimingby the tdc related parameters, and add these to the new netlink interface.
I also saw the current netlink interface as the problem here.
But even when 'deprecating' the old interface we still need to provide the API, right?
Would therefore the new parameters overwrite the content which is transferred by can_bittiming or how would you like to make sure the mixed content remains consistent?
Quoted 8 lines
I prefer this, as I want to extend the
bittiming_constin this way, too. There are CAN controllers, where the bit timing calculation:Quoted 2 lines
bt->prop_seg = tseg1 / 2; bt->phase_seg1 = tseg1 - bt->prop_seg;doesn't work anymore, as they have asymmetric
prog_segandphase_seg1, so that splitting tseg1 in half doesn't work anymore.
Interesting.
Regards,
Oliver
Marc Kleine-Budde
maintainerRe: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 120 lines · Oliver Hartkopp
(quoted diff) +0
-3-DaveM -JacubK -netdev@Vincent: No need for cross posting and putting the networking maintainers in CC for these really deep CAN driver specific topics IHMO
Quoted 44 lines · Marc Kleine-Budde
Quoted 43 lines · Vincent MAILHOL
Quoted 35 lines · Oliver Hartkopp
Hi Vincent,
Quoted 2 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +0
-0(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +5
-0+static void es58x_fd_print_bittiming (struct net_device *netdev, +struct es58x_fd_bittiming + *es58x_fd_bittiming,char *type) +{ + netdev_vdbg(netdev, "bitrate %s = %d\n", type,drivers/net/can/usb/etas_es58x/es58x_fd.c line 412
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+ le32_to_cpu(es58x_fd_bittiming->bitrate)); +netdev_vdbg (netdev,"tseg1 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg1)); +netdev_vdbg (netdev,"tseg2 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg2)); +netdev_vdbg (netdev,"brp %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->brp)); +netdev_vdbg (netdev,"sjw %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->sjw)); +}What is the reason for this code?
Quoted 2 lines
These values can be retrieved with the 'ip' tool and are probably interesting for development - but not in the final code.
First thing, I used
netdev_vdbg()(verbose debug). That macro will only produce code ifVERBOSE_DEBUGis defined. Normal users will not see those. So yes, this is mostly for development.Quoted 6 lines
Quoted 6 lines
Also, just realised that
netdev_vdbg()is barely used anywhere (only three files use it:
https://elixir.bootlin.com/linux/v5.11-rc3/C/ident/netdev_vdbg).I guess that I will remove it :)
Thanks! That will remove some more code in the background too.
Quoted 54 lines
Quoted 46 lines
Quoted 34 lines
Quoted 21 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +21
-0+ +static void es58x_fd_print_conf (struct net_device *netdev, +struct es58x_fd_tx_conf_msg *tx_conf_msg) +{ +es58x_fd_print_bittiming (netdev, &tx_conf_msg->nominal_bittiming, +"nominal" ); +netdev_vdbg (netdev,"samples_per_bit = %d\n" , + tx_conf_msg->samples_per_bit); +netdev_vdbg (netdev,"sync_edge = %d\n" , + tx_conf_msg->sync_edge); +netdev_vdbg (netdev,"physical_layer = %d\n" , + tx_conf_msg->physical_layer); +netdev_vdbg (netdev,"self_reception = %d\n" , + tx_conf_msg->self_reception_mode); +netdev_vdbg (netdev,"ctrlmode = %d\n" , tx_conf_msg->ctrlmode); +netdev_vdbg (netdev,"canfd_enabled = %d\n" , + tx_conf_msg->canfd_enabled); +if (tx_conf_msg->canfd_enabled) { +es58x_fd_print_bittiming (netdev, + &tx_conf_msg->data_bittiming,"data" ); + netdev_vdbg(netdev,drivers/net/can/usb/etas_es58x/es58x_fd.c line 443
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+"Transmitter Delay Compensation = %d\n" , + tx_conf_msg->tdc); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Offset = %d\n" , +le16_to_cpu (tx_conf_msg->tdco)); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Filter = %d\n" , +le16_to_cpu (tx_conf_msg->tdcf)); + } +}Same here.
Quoted 2 lines
Either the information can be retrieved with the 'ip' tool OR the are not necessary as set to some reasonable default anyway
Ack, will remove.
Quoted 2 lines
OR we should
implement the functionality in the general CAN driver infrastructure.Would make sense to me to add the tdco (Transmitter Delay Compensation Offset). Ref: ISO 11898-1 section 11.3.3 "Transmitter delay compensation"
Quoted 7 lines
I would just like your opinion on one topic: the tdco is specific to CAN FD. If we add it, we have two choices:
1. put it in structcan_bittiming: that will mean that we will have an unused field for classical CAN (field bittiming of structcan_priv).
2. put it in structcan_priv(but outside of structcan_bittiming): no unused field but less pretty.Quoted 4 lines
3. Deprecate struct
can_bittimingas the user space interface and transfer each member individually via netlink. Extend the kernel-onlycan_bittimingby the tdc related parameters, and add these to the new netlink interface.
Quoted 4 lines
I also saw the current netlink interface as the problem here.
But even when 'deprecating' the old interface we still need to provide the API, right?
ACK
Quoted 3 lines
Would therefore the new parameters overwrite the content which is transferred by
can_bittimingor how would you like to make sure the mixed content remains consistent?
For my use case the API is extended and should not contain conflicting data. I think it's 3 steps to convert the kernel (where the 2.* and the 3.* have to be done atomically):
1.
Introduce a new struct can_bittiming_kernel_const, with tseg1_{min,max} replaced by prop_seg_{min,max} and phase_seg1_{min,max}.
2.1.
Convert drivers to use new struct can_bittiming_kernel_const.
2.2.
Convert existing CAN-netlink interface to translate between old usersapce struct can_bittiming_const and new struct can_bittiming_kernel_const:
new -> old:
Quoted 1 line
old->phase_seg1_{min,max} = new->prop_seg_{min,max} + phase_seg1_{min,max}
old -> new:
Quoted 2 lines
new->prop_seg_{min,max} = old->tseg1_{min,max} / 2; new->phase_seg1_{min,max} = old->tseg1_{min,max} -
new->prop_seg;
3.1.
Add new netlink parsing that works with struct can_bittiming_kernel_const
3.2.
Add netlink validity check, so that either old or new API is used in a single netlink call.
Quoted 10 lines
Quoted 8 lines
I prefer this, as I want to extend the
bittiming_constin this way, too. There are CAN controllers, where the bit timing calculation:Quoted 2 lines
bt->prop_seg = tseg1 / 2; bt->phase_seg1 = tseg1 - bt->prop_seg;doesn't work anymore, as they have asymmetric
prog_segandphase_seg1, so that splitting tseg1 in half doesn't work anymore.Interesting.
The flexcan driver works around the problem this way:
Quoted 10 lines
/* CBT[EPSEG1] is 5 bit long and CBT[EPROPSEG] is 6 bit
* long. The can_calc_bittiming() tries to divide the tseg1
* equally between phase_seg1 and prop_seg, which may not fit
* in CBT register. Therefore, if phase_seg1 is more than
* possible value, increase prop_seg and decrease phase_seg1.
*/
if (bt->phase_seg1 > 0x20) {
bt->prop_seg += (bt->phase_seg1 - 0x20);
bt->phase_seg1 = 0x20;
}Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
On Fri. 15 Jan 2021 at 22:44, Marc Kleine-Budde <[email protected]> wrote
Quoted 7 lines · Oliver Hartkopp
Quoted 6 lines
(quoted diff) +0
-3-DaveM -JacubK -netdev@Vincent: No need for cross posting and putting the networking maintainers in CC for these really deep CAN driver specific topics IHMO
I just used to include whatever was listed byscripts/get_maintainer.pl
Noted and thanks for the hint, I will be more careful in the future on who I include.
Quoted 108 lines
Quoted 108 lines · Marc Kleine-Budde
Quoted 44 lines · Vincent MAILHOL
Quoted 43 lines · Oliver Hartkopp
Quoted 35 lines
Hi Vincent,
Quoted 2 lines · Vincent Mailhol
This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +0
-0(..)
Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +5
-0+static void es58x_fd_print_bittiming (struct net_device *netdev, +struct es58x_fd_bittiming + *es58x_fd_bittiming,char *type) +{ + netdev_vdbg(netdev, "bitrate %s = %d\n", type,drivers/net/can/usb/etas_es58x/es58x_fd.c line 412
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+ le32_to_cpu(es58x_fd_bittiming->bitrate)); +netdev_vdbg (netdev,"tseg1 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg1)); +netdev_vdbg (netdev,"tseg2 %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->tseg2)); +netdev_vdbg (netdev,"brp %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->brp)); +netdev_vdbg (netdev,"sjw %s = %d\n" , type, +le16_to_cpu (es58x_fd_bittiming->sjw)); +}What is the reason for this code?
Quoted 2 lines
These values can be retrieved with the 'ip' tool and are probably interesting for development - but not in the final code.
First thing, I used
netdev_vdbg()(verbose debug). That macro will only produce code ifVERBOSE_DEBUGis defined. Normal users will not see those. So yes, this is mostly for development.Quoted 6 lines
Quoted 6 lines
Also, just realised that
netdev_vdbg()is barely used anywhere (only three files use it:
https://elixir.bootlin.com/linux/v5.11-rc3/C/ident/netdev_vdbg).I guess that I will remove it :)
Thanks! That will remove some more code in the background too.
Quoted 54 lines
Quoted 53 lines
Quoted 34 lines
Quoted 21 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +21
-0+ +static void es58x_fd_print_conf (struct net_device *netdev, +struct es58x_fd_tx_conf_msg *tx_conf_msg) +{ +es58x_fd_print_bittiming (netdev, &tx_conf_msg->nominal_bittiming, +"nominal" ); +netdev_vdbg (netdev,"samples_per_bit = %d\n" , + tx_conf_msg->samples_per_bit); +netdev_vdbg (netdev,"sync_edge = %d\n" , + tx_conf_msg->sync_edge); +netdev_vdbg (netdev,"physical_layer = %d\n" , + tx_conf_msg->physical_layer); +netdev_vdbg (netdev,"self_reception = %d\n" , + tx_conf_msg->self_reception_mode); +netdev_vdbg (netdev,"ctrlmode = %d\n" , tx_conf_msg->ctrlmode); +netdev_vdbg (netdev,"canfd_enabled = %d\n" , + tx_conf_msg->canfd_enabled); +if (tx_conf_msg->canfd_enabled) { +es58x_fd_print_bittiming (netdev, + &tx_conf_msg->data_bittiming,"data" ); + netdev_vdbg(netdev,drivers/net/can/usb/etas_es58x/es58x_fd.c line 443
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +10
-0+"Transmitter Delay Compensation = %d\n" , + tx_conf_msg->tdc); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Offset = %d\n" , +le16_to_cpu (tx_conf_msg->tdco)); +netdev_vdbg (netdev, +"Transmitter Delay Compensation Filter = %d\n" , +le16_to_cpu (tx_conf_msg->tdcf)); + } +}Same here.
Quoted 2 lines
Either the information can be retrieved with the 'ip' tool OR the are not necessary as set to some reasonable default anyway
Ack, will remove.
Quoted 2 lines
OR we should
implement the functionality in the general CAN driver infrastructure.Would make sense to me to add the tdco (Transmitter Delay Compensation Offset). Ref: ISO 11898-1 section 11.3.3 "Transmitter delay compensation"
I would just like your opinion on one topic: the tdco is specific to CAN FD. If we add it, we have two choices:
1. put it in structcan_bittiming: that will mean that we will have an unused field for classical CAN (field bittiming of structcan_priv).
2. put it in structcan_priv(but outside of structcan_bittiming): no unused field but less pretty.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
3. Deprecate struct
can_bittimingas the user space interface and transfer each member individually via netlink. Extend the kernel-onlycan_bittimingby the tdc related parameters, and add these to the new netlink interface.
Wow, didn't see that third option coming!
By "extend the kernel-only can_bittiming by the tdc related parameters" do you mean to still use a single struct can_bittiming for classical CAN and CAN FD with the tdc parameters in both (a bit like what I suggested in 1.)?
Yours sincerely,
Vincent
Quoted 72 lines
Quoted 4 lines
I also saw the current netlink interface as the problem here.
But even when 'deprecating' the old interface we still need to provide the API, right?
ACK
Quoted 3 lines
Would therefore the new parameters overwrite the content which is transferred by
can_bittimingor how would you like to make sure the mixed content remains consistent?For my use case the API is extended and should not contain conflicting data. I think it's 3 steps to convert the kernel (where the 2.* and the 3.* have to be done atomically):
1.
Introduce a new structcan_bittiming_kernel_const, with tseg1_{min,max} replaced by prop_seg_{min,max} and phase_seg1_{min,max}.2.1.
Convert drivers to use new structcan_bittiming_kernel_const.2.2.
Convert existing CAN-netlink interface to translate between old usersapce structcan_bittiming_constand new structcan_bittiming_kernel_const:new -> old:
Quoted 1 line
old->phase_seg1_{min,max} = new->prop_seg_{min,max} + phase_seg1_{min,max}
old -> new:
Quoted 2 lines
new->prop_seg_{min,max} = old->tseg1_{min,max} / 2; new->phase_seg1_{min,max} = old->tseg1_{min,max} -
new->prop_seg;3.1.
Add new netlink parsing that works with structcan_bittiming_kernel_const3.2.
Add netlink validity check, so that either old or new API is used in a single netlink call.Quoted 10 lines
Quoted 8 lines
I prefer this, as I want to extend the
bittiming_constin this way, too. There are CAN controllers, where the bit timing calculation:Quoted 2 lines
bt->prop_seg = tseg1 / 2; bt->phase_seg1 = tseg1 - bt->prop_seg;doesn't work anymore, as they have asymmetric
prog_segandphase_seg1, so that splitting tseg1 in half doesn't work anymore.Interesting.
The flexcan driver works around the problem this way:
Quoted 10 lines
/* CBT[EPSEG1] is 5 bit long and CBT[EPROPSEG] is 6 bit * long. The can_calc_bittiming() tries to divide the tseg1 * equally between phase_seg1 and prop_seg, which may not fit * in CBT register. Therefore, if phase_seg1 is more than * possible value, increase prop_seg and decrease phase_seg1. */ if (bt->phase_seg1 > 0x20) { bt->prop_seg += (bt->phase_seg1 - 0x20); bt->phase_seg1 = 0x20; }Marc
--
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Marc Kleine-Budde
maintainerRe: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 13 lines · Vincent MAILHOL
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
I would just like your opinion on one topic: the tdco is specific to CAN FD. If we add it, we have two choices:
1. put it in structcan_bittiming: that will mean that we will have an unused field for classical CAN (field bittiming of structcan_priv).
2. put it in structcan_priv(but outside of structcan_bittiming): no unused field but less pretty.Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
3. Deprecate struct
can_bittimingas the user space interface and transfer each member individually via netlink. Extend the kernel-onlycan_bittimingby the tdc related parameters, and add these to the new netlink interface.
Quoted 6 lines
Wow, didn't see that third option coming!
By "extend the kernel-only
can_bittimingby the tdc related parameters" do you mean to still use a single structcan_bittimingfor classical CAN and CAN FD with the tdc parameters in both (a bit like what I suggested in 1.)?
Let's put it this way, we need 3. in order to implement 1. As we need a stable userspace ABI.
Option 4:
We can introduce a struct can_bitiming_fd with the first member being the struct can_bitiming and add tdc related variables after that. This way we can use the same function to calculate the bit timing on both CAN and CAN-FD.
What about future developments?
Does anyone have a clue about CAN-XL? Will we ever see real HW? Or will 10Base-T1 and 100Base-T1 take the market?
There are also these new transceivers in development that should be better suited for "special" bus setups.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 16 lines · Marc Kleine-Budde
Quoted 15 lines · Vincent MAILHOL
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
I would just like your opinion on one topic: the tdco is specific to CAN FD. If we add it, we have two choices:
1. put it in structcan_bittiming: that will mean that we will have an unused field for classical CAN (field bittiming of structcan_priv).
2. put it in structcan_priv(but outside of structcan_bittiming): no unused field but less pretty.Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
3. Deprecate struct
can_bittimingas the user space interface and transfer each member individually via netlink. Extend the kernel-onlycan_bittimingby the tdc related parameters, and add these to the new netlink interface.Wow, didn't see that third option coming!
Quoted 7 lines
Quoted 4 lines
By "extend the kernel-only
can_bittimingby the tdc related parameters" do you mean to still use a single structcan_bittimingfor classical CAN and CAN FD with the tdc parameters in both (a bit like what I suggested in 1.)?Let's put it this way, we need 3. in order to implement 1. As we need a stable userspace ABI.
I was not familiar enough with the netlink interface to foresee all those dependencies but thanks to your explanations, now everything starts to make sense.
Quoted 4 lines
Option 4:
We can introduce a structcan_bitiming_fdwith the first member being the structcan_bitimingand add tdc related variables after that. This way we can use the same function to calculate the bit timing on both CAN and CAN-FD.
While option 3 is slightly easier, my preference will go to option 4.
Quoted 3 lines
What about future developments?
Does anyone have a clue about CAN-XL? Will we ever see real HW?
Recent news would suggest that CiA will release the CAN XL specification this year:
https://www.can-cia.org/news/cia-in-action/view/a-bright-future-for-can/2021/1/2/
Quoted 2 lines
Or will
10Base-T1 and 100Base-T1 take the market?
My guts tell me that 100Base-T1 will take the market for autonomous driving (camera, Lidar...) and that CAN(-FD) has still a bright future for safety critical domains, at least in the next decade. Will CAN XL find its place or will it meet the same destiny as flexray? I do not know. But once the specification and the first hardware are out, we would probably start to implement it in Socket CAN before knowing if it will win the market :)
Nonetheless, if we follow your idea of transferring each member individually via netlink, then we will have enough flexibility to adjust the new kernel only can_bitiming structures to our liking.
Quoted 2 lines
There are also these new transceivers in development that should be better suited for "special" bus setups.
Do these require additional bittiming parameters?
Yours sincerely,
Vincent
Quoted 8 lines
Marc
--
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Marc Kleine-Budde
maintainerRe: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 27 lines · Vincent MAILHOL
Quoted 15 lines
Quoted 15 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
I would just like your opinion on one topic: the tdco is specific to CAN FD. If we add it, we have two choices:
1. put it in structcan_bittiming: that will mean that we will have an unused field for classical CAN (field bittiming of structcan_priv).
2. put it in structcan_priv(but outside of structcan_bittiming): no unused field but less pretty.Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
3. Deprecate struct
can_bittimingas the user space interface and transfer each member individually via netlink. Extend the kernel-onlycan_bittimingby the tdc related parameters, and add these to the new netlink interface.Wow, didn't see that third option coming!
Quoted 7 lines
Quoted 4 lines
By "extend the kernel-only
can_bittimingby the tdc related parameters" do you mean to still use a single structcan_bittimingfor classical CAN and CAN FD with the tdc parameters in both (a bit like what I suggested in 1.)?Let's put it this way, we need 3. in order to implement 1. As we need a stable userspace ABI.
I was not familiar enough with the netlink interface to foresee all those dependencies but thanks to your explanations, now everything starts to make sense.
Quoted 6 lines
Quoted 4 lines
Option 4:
We can introduce a structcan_bitiming_fdwith the first member being the structcan_bitimingand add tdc related variables after that. This way we can use the same function to calculate the bit timing on both CAN and CAN-FD.While option 3 is slightly easier, my preference will go to option 4.
We still need the netlink enhancement from option 3.
Quoted 7 lines
Quoted 3 lines
What about future developments?
Does anyone have a clue about CAN-XL? Will we ever see real HW?
Recent news would suggest that CiA will release the CAN XL specification this year:
https://www.can-cia.org/news/cia-in-action/view/a-bright-future-for-can/2021/1/2/
Thanks, I've missed this.
Quoted 7 lines
Quoted 2 lines
Or will
10Base-T1 and 100Base-T1 take the market?My guts tell me that 100Base-T1 will take the market for autonomous driving (camera, Lidar...) and that CAN(-FD) has still a bright future for safety critical domains, at least in the next decade.
There are already automotive equipment out there, that uses CAN-FD and 100Base-T1. Wakeup via CAN-FD, once alive do other stuff via 100Base-T1.
Quoted 8 lines
Will CAN XL find its place or will it meet the same destiny as flexray? I do not know. But once the specification and the first hardware are out, we would probably start to implement it in Socket CAN before knowing if it will win the market :)
Nonetheless, if we follow your idea of transferring each member individually via netlink, then we will have enough flexibility to adjust the new kernel only
can_bitimingstructures to our liking.
ACK
Quoted 4 lines
Quoted 2 lines
There are also these new transceivers in development that should be better suited for "special" bus setups.
Do these require additional bittiming parameters?
Don't know - haven't had one of those in my hands, yet. They are called "CAN SIC Transceivers" the slides promise Signal Improvement and former "Ringing Suppression".
Back to TDC, which values do you want to provide to user space?
Quoted 9 lines
Review
Quoted 9 lines
(quoted diff) +9
-0+ netdev_vdbg(netdev, + "Transmitter Delay Compensation = %d\n", + tx_conf_msg->tdc); + netdev_vdbg(netdev, + "Transmitter Delay Compensation Offset = %d\n", + le16_to_cpu(tx_conf_msg->tdco)); + netdev_vdbg(netdev, + "Transmitter Delay Compensation Filter = %d\n", + le16_to_cpu(tx_conf_msg->tdcf));
Can we describe them in a HW independent way?
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Marc Kleine-Budde
maintainerRe: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 8 lines · Marc Kleine-Budde
Quoted 6 lines
Quoted 4 lines
Option 4:
We can introduce a structcan_bitiming_fdwith the first member being the structcan_bitimingand add tdc related variables after that. This way we can use the same function to calculate the bit timing on both CAN and CAN-FD.While option 3 is slightly easier, my preference will go to option 4.
We still need the netlink enhancement from option 3.
Just tried option 4.
include/linux/can/dev.h enum can_mode { · line 36
Quoted 10 lines
include/linux/can/dev.h +2
-0@@ -32,6 +32,10 @@ enum can_mode {CAN_MODE_SLEEP }; +struct canfd_bittiming { +struct can_bittiming dbt;
tdc to be added here....
Quoted 6 lines
include/linux/can/dev.h +2
-0+}; +/* * CAN common private data */
include/linux/can/dev.h struct can_priv { · line 50
Quoted 9 lines
include/linux/can/dev.h +2
-1@@ -39,7 +43,8 @@ struct can_priv {struct net_device *dev;struct can_device_stats can_stats; -struct can_bittiming bittiming, data_bittiming; +struct can_bittiming bittiming; +struct canfd_bittiming data_bittiming;const struct can_bittiming_const *bittiming_const, *data_bittiming_const;const u16 *termination_const;
But I had to add that ".dbt" everywhere....
Quoted 27 lines
drivers/net/can/dev/dev.c +2
-2@@ -345,8 +345,8 @@ int open_candev(struct net_device *dev)/* For CAN FD the data bitrate has to be >= the arbitration bitrate */ if ((priv->ctrlmode &CAN_CTRLMODE_FD ) && - (!priv->data_bittiming.bitrate || - priv->data_bittiming.bitrate < priv->bittiming.bitrate)) { + (!priv->data_bittiming.dbt.bitrate || + priv->data_bittiming.dbt.bitrate < priv->bittiming.bitrate)) {netdev_err (dev,"incorrect/missing data bit-timing\n" );return -EINVAL ; }drivers/net/can/dev/netlink.c +1
-1@@ -239,7 +239,7 @@ static size_t can_get_size(const struct net_device *dev) size +=nla_total_size (sizeof (u32));/* IFLA_CAN_RESTART_MS */ if (priv->do_get_berr_counter)/* IFLA_CAN_BERR_COUNTER */ size +=nla_total_size (sizeof (struct can_berr_counter )); -if (priv->data_bittiming.bitrate)/* IFLA_CAN_DATA_BITTIMING */ +if (priv->data_bittiming.dbt.bitrate)/* IFLA_CAN_DATA_BITTIMING */ size +=nla_total_size (sizeof (struct can_bittiming ));if (priv->data_bittiming_const)/* IFLA_CAN_DATA_BITTIMING_CONST */ size +=nla_total_size (sizeof (struct can_bittiming_const ));
drivers/net/can/dev/netlink.c static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) · line 292
Quoted 8 lines
drivers/net/can/dev/netlink.c +1
-1@@ -286,7 +286,7 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) !priv->do_get_berr_counter (dev, &bec) && nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)) || - (priv->data_bittiming.bitrate && + (priv->data_bittiming.dbt.bitrate &&nla_put (skb,IFLA_CAN_DATA_BITTIMING , sizeof(priv->data_bittiming), &priv->data_bittiming)) ||
And that's not even everything.
I think best it to add a "struct can_tdc" directly to the struct can_priv. Then add a netlink interface that returns the existing can_bittiming and the can_tdc, not as a struct, but each member with a separate tag (or whatever it's called).
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v10 1/1] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces
Quoted 73 lines · Marc Kleine-Budde
Quoted 8 lines · Marc Kleine-Budde
Quoted 6 lines
Quoted 4 lines
Option 4:
We can introduce a structcan_bitiming_fdwith the first member being the structcan_bitimingand add tdc related variables after that. This way we can use the same function to calculate the bit timing on both CAN and CAN-FD.While option 3 is slightly easier, my preference will go to option 4.
We still need the netlink enhancement from option 3.
Just tried option 4.
include/linux/can/dev.h enum can_mode { · line 36
Quoted 10 lines
include/linux/can/dev.h +2
-0@@ -32,6 +32,10 @@ enum can_mode {CAN_MODE_SLEEP }; +struct canfd_bittiming { +struct can_bittiming dbt;tdc to be added here....
Quoted 6 lines
include/linux/can/dev.h +2
-0+}; +/* * CAN common private data */ include/linux/can/dev.h struct can_priv { · line 50
Quoted 9 lines
include/linux/can/dev.h +2
-1@@ -39,7 +43,8 @@ struct can_priv {struct net_device *dev;struct can_device_stats can_stats; -struct can_bittiming bittiming, data_bittiming; +struct can_bittiming bittiming; +struct canfd_bittiming data_bittiming;const struct can_bittiming_const *bittiming_const, *data_bittiming_const;const u16 *termination_const;But I had to add that ".dbt" everywhere....
Quoted 30 lines
drivers/net/can/dev/dev.c +2
-2@@ -345,8 +345,8 @@ int open_candev(struct net_device *dev)/* For CAN FD the data bitrate has to be >= the arbitration bitrate */ if ((priv->ctrlmode &CAN_CTRLMODE_FD ) && - (!priv->data_bittiming.bitrate || - priv->data_bittiming.bitrate < priv->bittiming.bitrate)) { + (!priv->data_bittiming.dbt.bitrate || + priv->data_bittiming.dbt.bitrate < priv->bittiming.bitrate)) {netdev_err (dev,"incorrect/missing data bit-timing\n" );return -EINVAL ; }drivers/net/can/dev/netlink.c +1
-1@@ -239,7 +239,7 @@ static size_t can_get_size(const struct net_device *dev) size +=nla_total_size (sizeof (u32));/* IFLA_CAN_RESTART_MS */ if (priv->do_get_berr_counter)/* IFLA_CAN_BERR_COUNTER */ size +=nla_total_size (sizeof (struct can_berr_counter )); -if (priv->data_bittiming.bitrate)/* IFLA_CAN_DATA_BITTIMING */ +if (priv->data_bittiming.dbt.bitrate)/* IFLA_CAN_DATA_BITTIMING */ size +=nla_total_size (sizeof (struct can_bittiming ));if (priv->data_bittiming_const)/* IFLA_CAN_DATA_BITTIMING_CONST */ size +=nla_total_size (sizeof (struct can_bittiming_const ));@@ -286,7 +286,7 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) !priv->do_get_berr_counter (dev, &bec) && nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)) ||
Quoted 7 lines
drivers/net/can/dev/netlink.c static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) · line 292
Quoted 5 lines
drivers/net/can/dev/netlink.c +1
-1- (priv->data_bittiming.bitrate && + (priv->data_bittiming.dbt.bitrate &&nla_put (skb,IFLA_CAN_DATA_BITTIMING , sizeof(priv->data_bittiming), &priv->data_bittiming)) ||And that's not even everything.
I also expected that many lines would have to be changed:
$ grep -R data_bittiming drivers/net/can/dev | wc -l 15 And (full kernel tree): $ grep -R data_bittiming | wc -l 126
But those changes are all trivial, that's why I liked the idea.
Quoted 3 lines
I think best it to add a "struct
can_tdc" directly to the structcan_priv. Then add a netlink interface that returns the existingcan_bittimingand thecan_tdc, not as a struct, but each member with a separate tag (or whatever it's called).
Not a bad idea, still need to think about the pros and cons.
For now, I will use the "struct can_tdc" in my RFC. Right now, I will not be working on the netlink interface immediately. I will first focus on modifying the ES58X driver's FIFO and go back to the netlink interface later.
Yours sincerely,
Vincent
Quoted 8 lines
Marc
--
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |