can: dev: can_skb_get_dll_len(): introduce function to get data length of frame in data link layer
Marc Kleine-Budde
maintainerRFC PATCH 1/1 can: dev: can_skb_get_dll_len(): introduce function to get data length of frame in data link layer
From: Vincent Mailhol <[email protected]>
This patch adds the function can_skb_get_dll_len() which returns the length of a CAN frame on the data link layer, including Start-of-frame, Identifier, various other bits, the CRC, the End-of-frame, the Inter frame spacing and the actual data.
---
Hello,
while reviewing the etas_es58X driver and hacking on BQL support for the mcp251xfd driver, it turned out the a function to calculate the length of the CAN frame that's send over the wire should go into the generic CAN dev code.
Looking at the CAN and OSI layering I think the first layer where we have all the bits that we see on the wire is the data link layer (DLL).
https://www.can-cia.org/can-knowledge/can/can-data-link-layers
This is why I named the function can_skb_get_dll_len().
I'm planing to add a (better) calculation of the CAN-FD dll_len, depending on the data and including different CRC lengths.
As this code is copied from the etas_es58X driver, I've added the authors as Co-developed-by and I'd like to add their S-o-b to this patch.
Please review and commnt on the naming on the functions.
regards,
Marc
drivers/net/can/dev.c | 103 ++++++++++++++++++++++++++++++++++++++++ include/linux/can/dev.h | 3 ++ 2 files changed, 106 insertions(+)
drivers/net/can/dev.c +103 -0
@@ -58,6 +58,109 @@ u8 can_len2dlc(u8 len) }EXPORT_SYMBOL_GPL (can_len2dlc); +/* Size of a Classical CAN Standard Frame in Bits: +* +* Start-of-frame 1 +* Identifier 11 +* Remote transmission request (RTR) 1 +* Identifier extension bit (IDE) 1 +* Reserved bit (r0) 1 +* Data length code (DLC) 4 +* Data field 0...64 +* CRC 15 +* CRC delimiter 1 +* ACK slot 1 +* ACK delimiter 1 +* End-of-frame (EOF) 7 +* Inter frame spacing 3 +* +* Rounded up and ignoring bitsuffing +*/ +#define CAN_DLL_OVERHEAD_SFF DIV_ROUND_UP(47, 8) + +/* Size of a Classical CAN Extended Frame in Bits: +* +* Start-of-frame 1 +* Identifier A 11 +* Substitute remote request (SRR) 1 +* Identifier extension bit (IDE) 1 +* Identifier B 18 +* Remote transmission request (RTR) 1 +* Reserved bits (r1, r0) 2 +* Data length code (DLC) 4 +* Data field 0...64 +* CRC 15 +* CRC delimiter 1 +* ACK slot 1 +* ACK delimiter 1 +* End-of-frame (EOF) 7 +* Inter frame spacing 3 +* +* Rounded up and ignoring bitsuffing +*/ +#define CAN_DLL_OVERHEAD_EFF DIV_ROUND_UP(67, 8) + +/* Maximum size of a Classical CAN frame +* (rounded up and ignoring bitsuffing) +*/ +#define CAN_DLL_LEN_MAX (CAN_DLL_OVERHEAD_EFF + CAN_MAX_DLEN) + +/* Maximum size of a CAN-FD frame (rough estimation because +* ES58X_SFF_BYTES() and ES58X_EFF_BYTES() macros are using the +* constant values for Classical CAN, not CAN-FD). +*/ +#define CANFD_DLL_LEN_MAX (CAN_DLL_OVERHEAD_EFF + CANFD_MAX_DLEN) + +/** +* can_skb_get_dll_len() - Calculate the CAN Data Link Layer length in +* bytes of a given skb. +* @skb: socket buffer of a CAN message. +* +* Do a rough calculation: bit stuffing is ignored and length in bits +* is rounded up to a length in bytes. +* +* Rationale: this function is to be used for the BQL functions +* (netdev_sent_queue() and netdev_completed_queue()) which expect a +* value in bytes. Just using skb->len is insufficient because it will +* return the constant value of CAN(FD)_MTU. Doing the bit stuffing +* calculation would be too expensive in term of computing resources +* for no noticeable gain. +* +* Remarks: +* a.) The payload of CAN FD frames with BRS flag are sent at a +* different bitrate. Currently, the can-utils canbusload tool does +* not support CAN-FD yet and so we could not run any benchmark to +* measure the impact. There might be possible improvement here. +* b.) The macro CAN_DLL_OVERHEAD_EFF and CAN_DLL_OVERHEAD_SFF are +* for classical CAN. Need to do the addition for CAN-FD (the value +* are expected to be close enough so the impact should be minimal or +* none). +* +* Return: length in bytes. +*/ +unsigned int can_skb_get_dll_len (const struct sk_buff *skb) +{ +const struct canfd_frame *cf = (const struct canfd_frame *)skb->data; +u8 len; + +if (can_is_canfd_skb (skb)) { + len = cf->len +CAN_DLL_OVERHEAD_EFF ; + }else { +if (cf->can_id &CAN_RTR_FLAG ) + len =0 ; +else + len = cf->len; + +if (cf->can_id &CAN_EFF_FLAG ) + len +=CAN_DLL_OVERHEAD_EFF ; +else + len +=CAN_DLL_OVERHEAD_SFF ; + } + +return len; +} +EXPORT_SYMBOL_GPL (can_skb_get_dll_len); +#ifdef CONFIG_CAN_CALC_BITTIMING #define CAN_CALC_MAX_ERROR 50/* in one-tenth of a percent */
include/linux/can/dev.h +3 -0
@@ -192,6 +192,9 @@ u8 can_dlc2len(u8 can_dlc);/* map the sanitized data length to an appropriate data length code */ u8 can_len2dlc (u8 len); +/* get data link layer length of CAN/CAN-FD frame */ +unsigned int can_skb_get_dll_len (const struct sk_buff *skb); +struct net_device *alloc_candev_mqs (int sizeof_priv,unsigned int echo_skb_max,unsigned int txqs,unsigned int rxqs);#define alloc_candev (sizeof_priv, echo_skb_max) \
Signature · 1 line
2.29.2
Quoted 14 lines · Marc Kleine-Budde
From: Vincent Mailhol <[email protected]>
This patch adds the function
can_skb_get_dll_len()which returns the length of a CAN frame on the data link layer, including Start-of-frame, Identifier, various other bits, the CRC, the End-of-frame, the Inter frame spacing and the actual data.Co-developed-by Arunachalam Santhanam <[email protected]>Not-Signed-off-by Arunachalam Santhanam <[email protected]>Co-developed-by Vincent Mailhol <[email protected]>Not-Signed-off-by Vincent Mailhol <[email protected]>Co-developed-by Marc Kleine-Budde <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>
Quoted 6 lines
---
Hello,while reviewing the
etas_es58Xdriver and hacking on BQL support for the mcp251xfd driver, it turned out the a function to calculate the length of the CAN frame that's send over the wire should go into the generic CAN dev code.
It took me a bit of time to figure out how to use the BQL. Contrary to the other features, I couldn't pull inspiration from the other CAN drivers. I am happy to see that you want to extend it to other drivers.
Also, on a side topic, please let me know if you have any comments on the etas_es58x driver ;)
Quoted 6 lines
Looking at the CAN and OSI layering I think the first layer where we have all the bits that we see on the wire is the data link layer (DLL).
https://www.can-cia.org/can-knowledge/can/can-data-link-layers
This is why I named the function
can_skb_get_dll_len().
I would personally prefer to call it can_skb_get_frame_len(). The ISO 11898 standard defines the "frame" as:
Protocol Data Unit of the data link layer specifying the arrangement and meaning of bits or bit fields in the sequence of transfer across the transmission medium.
I imagine that you want to introduce the term "dll" instead of "frame" to clearly differentiate it from the struct can_frame and struct can_fd_frame. But "frame" remains the most relevant term according to the standard. I think that things are clear enough so that other kernel hackers would understand that the len fields of struct can_frame and struct can_fd_frame represent the length of the payload and that can_skb_get_frame_len() is the length of the frame at the data link layer.
Quoted 2 lines
I'm planing to add a (better) calculation of the CAN-FD
dll_len, depending on the data and including different CRC lengths.
Great! For my driver, everything seemed OK as it is currently but if this gets merged to the generic CAN dev code this part should definitely be improved (the comment I added in my code was there to warn whoever wanted to reuse it about the limitations).
Quoted 17 lines
As this code is copied from the
etas_es58Xdriver, I've added the authors as Co-developed-by and I'd like to add their S-o-b to this patch.Please review and commnt on the naming on the functions.
regards,
Marcdrivers/net/can/dev.c | 103 ++++++++++++++++++++++++++++++++++++++++ include/linux/can/dev.h | 3 ++ 2 files changed, 106 insertions(+)drivers/net/can/dev.c +0
-0
drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 61
Quoted 4 lines
drivers/net/can/dev.c +1
-0@@ -58,6 +58,109 @@ u8 can_len2dlc(u8 len) }EXPORT_SYMBOL_GPL (can_len2dlc); +/* Size of a Classical CAN Standard Frame in Bits:
Size of a Classical CAN Standard Frame in Bytes:
The macro divides the grand total by 8. The subtotal is indeed presented in bits but the macro is in bytes.
Quoted 10 lines
drivers/net/can/dev.c +10
-0+* +* Start-of-frame 1 +* Identifier 11 +* Remote transmission request (RTR) 1 +* Identifier extension bit (IDE) 1 +* Reserved bit (r0) 1 +* Data length code (DLC) 4 +* Data field 0...64 +* CRC 15 +* CRC delimiter 1
drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 81
Quoted 10 lines
drivers/net/can/dev.c +10
-0+* ACK slot 1 +* ACK delimiter 1 +* End-of-frame (EOF) 7 +* Inter frame spacing 3 +* +* Rounded up and ignoring bitsuffing +*/ +#define CAN_DLL_OVERHEAD_SFF DIV_ROUND_UP(47, 8) + +/* Size of a Classical CAN Extended Frame in Bits:
Same as above.
Quoted 20 lines
drivers/net/can/dev.c +20
-0+* +* Start-of-frame 1 +* Identifier A 11 +* Substitute remote request (SRR) 1 +* Identifier extension bit (IDE) 1 +* Identifier B 18 +* Remote transmission request (RTR) 1 +* Reserved bits (r1, r0) 2 +* Data length code (DLC) 4 +* Data field 0...64 +* CRC 15 +* CRC delimiter 1 +* ACK slot 1 +* ACK delimiter 1 +* End-of-frame (EOF) 7 +* Inter frame spacing 3 +* +* Rounded up and ignoring bitsuffing +*/ +#define CAN_DLL_OVERHEAD_EFF DIV_ROUND_UP(67, 8)
drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 111
Quoted 10 lines
drivers/net/can/dev.c +10
-0+ +/* Maximum size of a Classical CAN frame +* (rounded up and ignoring bitsuffing) +*/ +#define CAN_DLL_LEN_MAX (CAN_DLL_OVERHEAD_EFF + CAN_MAX_DLEN) + +/* Maximum size of a CAN-FD frame (rough estimation because +* ES58X_SFF_BYTES() and ES58X_EFF_BYTES() macros are using the +* constant values for Classical CAN, not CAN-FD). +*/
/* Maximum size of a CAN-FD frame (rough estimation because
* CAN_DLL_OVERHEAD_SFF and CAN_DLL_OVERHEAD_EFF macros are using the
* constant values for Classical CAN, not CAN-FD).
*/
Some leftovers from the etas_es58x :)
Quoted 13 lines
drivers/net/can/dev.c +13
-0+*/ +#define CANFD_DLL_LEN_MAX (CAN_DLL_OVERHEAD_EFF + CANFD_MAX_DLEN) + +/** +* can_skb_get_dll_len() - Calculate the CAN Data Link Layer length in +* bytes of a given skb. +* @skb: socket buffer of a CAN message. +* +* Do a rough calculation: bit stuffing is ignored and length in bits +* is rounded up to a length in bytes. +* +* Rationale: this function is to be used for the BQL functions +* (netdev_sent_queue() and netdev_completed_queue()) which expect a
drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 133
Quoted 10 lines
drivers/net/can/dev.c +10
-0+* value in bytes. Just using skb->len is insufficient because it will +* return the constant value of CAN(FD)_MTU. Doing the bit stuffing +* calculation would be too expensive in term of computing resources +* for no noticeable gain. +* +* Remarks: +* a.) The payload of CAN FD frames with BRS flag are sent at a +* different bitrate. Currently, the can-utils canbusload tool does +* not support CAN-FD yet and so we could not run any benchmark to +* measure the impact. There might be possible improvement here.
My initial idea was to convert the data transmitted at data bitrate speed to their equivalent duration at nominal rate (example: 8 bytes at 2Mbps are equivalent to 2 bytes at 500 Kbps).
Code would look as below:
unsigned int can_skb_get_frame_len(const struct can_priv *can,
const struct sk_buff *skb)
{
/* ... */
if (cfd->flags & CANFD_BRS)
len = mult_frac(CANFD_FRAME_OVERHEAD, can->bittiming.bitrate,
can->data_bittiming.bitrate);/* ... */
}
This is just an overview, the data bitrate is also applied to some other fields of the frame (e.g. the CRC). So when creating the macro for the CANFD_FRAME_OVERHEAD, it should be split between the nominal and data bitrates.
Quoted 4 lines
drivers/net/can/dev.c +4
-0+* b.) The macro CAN_DLL_OVERHEAD_EFF and CAN_DLL_OVERHEAD_SFF are +* for classical CAN. Need to do the addition for CAN-FD (the value +* are expected to be close enough so the impact should be minimal or +* none).
drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 147
Quoted 10 lines
drivers/net/can/dev.c +10
-0+* +* Return: length in bytes. +*/ +unsigned int can_skb_get_dll_len (const struct sk_buff *skb) +{ +const struct canfd_frame *cf = (const struct canfd_frame *)skb->data; +u8 len; + +if (can_is_canfd_skb (skb)) { + len = cf->len +CAN_DLL_OVERHEAD_EFF ;
The CAN-FD frame can also be sent in SFF. An additional check on the CAN_EFF_FLAG is needed here.
Quoted 24 lines
drivers/net/can/dev.c +16
-0+ }else { +if (cf->can_id &CAN_RTR_FLAG ) + len =0 ; +else + len = cf->len; + +if (cf->can_id &CAN_EFF_FLAG ) + len +=CAN_DLL_OVERHEAD_EFF ; +else + len +=CAN_DLL_OVERHEAD_SFF ; + } + +return len; +} +EXPORT_SYMBOL_GPL (can_skb_get_dll_len); +#ifdef CONFIG_CAN_CALC_BITTIMING #define CAN_CALC_MAX_ERROR 50/* in one-tenth of a percent */ include/linux/can/dev.h +0
-0
include/linux/can/dev.h u8 can_dlc2len(u8 can_dlc); · line 200
Quoted 9 lines
include/linux/can/dev.h +3
-0@@ -192,6 +192,9 @@ u8 can_dlc2len(u8 can_dlc);/* map the sanitized data length to an appropriate data length code */ u8 can_len2dlc (u8 len); +/* get data link layer length of CAN/CAN-FD frame */ +unsigned int can_skb_get_dll_len (const struct sk_buff *skb); +struct net_device *alloc_candev_mqs (int sizeof_priv,unsigned int echo_skb_max,unsigned int txqs,unsigned int rxqs);#define alloc_candev (sizeof_priv, echo_skb_max) \
Yours sincerely,
Vincent
Marc Kleine-Budde
maintainerQuoted 11 lines · Vincent MAILHOL
Quoted 3 lines
while reviewing the
etas_es58Xdriver and hacking on BQL support for the mcp251xfd driver, it turned out the a function to calculate the length of the CAN frame that's send over the wire should go into the generic CAN dev code.It took me a bit of time to figure out how to use the BQL. Contrary to the other features, I couldn't pull inspiration from the other CAN drivers. I am happy to see that you want to extend it to other drivers.
Also, on a side topic, please let me know if you have any comments on the
etas_es58xdriver ;)
I'll look more into the driver later this week.
Quoted 10 lines
Quoted 6 lines
Looking at the CAN and OSI layering I think the first layer where we have all the bits that we see on the wire is the data link layer (DLL).
https://www.can-cia.org/can-knowledge/can/can-data-link-layers
This is why I named the function
can_skb_get_dll_len().I would personally prefer to call it
can_skb_get_frame_len(). The ISO 11898 standard defines the "frame" as:
Quoted 7 lines
Protocol Data Unit of the data link layer specifying the arrangement and meaning of bits or bit fields in the sequence of transfer across the transmission medium.
I imagine that you want to introduce the term "dll" instead of "frame" to clearly differentiate it from the struct
can_frameand structcan_fd_frame.
ACK
Quoted 6 lines
But "frame" remains the most relevant term according to
the standard. I think that things are clear enough so that other kernel hackers would understand that the len fields of structcan_frameand structcan_fd_framerepresent the length of the payload and thatcan_skb_get_frame_len()is the length of the frame at the data link layer.
Ok.
Quoted 7 lines
Quoted 2 lines
I'm planing to add a (better) calculation of the CAN-FD
dll_len, depending on the data and including different CRC lengths.Great! For my driver, everything seemed OK as it is currently but if this gets merged to the generic CAN dev code this part should definitely be improved (the comment I added in my code was there to warn whoever wanted to reuse it about the limitations).
:)
Quoted 20 lines
Quoted 20 lines
As this code is copied from the
etas_es58Xdriver, I've added the authors as Co-developed-by and I'd like to add their S-o-b to this patch.Please review and commnt on the naming on the functions.
regards,
Marcdrivers/net/can/dev.c | 103 ++++++++++++++++++++++++++++++++++++++++ include/linux/can/dev.h | 3 ++ 2 files changed, 106 insertions(+)drivers/net/can/dev.c +0
-0@@ -58,6 +58,109 @@ u8 can_len2dlc(u8 len) }EXPORT_SYMBOL_GPL (can_len2dlc);
Quoted 3 lines
drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 61
Quoted 1 line
drivers/net/can/dev.c +1
-0+/* Size of a Classical CAN Standard Frame in Bits: Size of a Classical CAN Standard Frame in Bytes:
The table is in bits, the overhead makros are in bytes, I'll try to clarift this.
Quoted 62 lines
The macro divides the grand total by 8. The subtotal is indeed presented in bits but the macro is in bytes.
Quoted 10 lines
drivers/net/can/dev.c +10
-0+* +* Start-of-frame 1 +* Identifier 11 +* Remote transmission request (RTR) 1 +* Identifier extension bit (IDE) 1 +* Reserved bit (r0) 1 +* Data length code (DLC) 4 +* Data field 0...64 +* CRC 15 +* CRC delimiter 1 drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 81
Quoted 10 lines
drivers/net/can/dev.c +10
-0+* ACK slot 1 +* ACK delimiter 1 +* End-of-frame (EOF) 7 +* Inter frame spacing 3 +* +* Rounded up and ignoring bitsuffing +*/ +#define CAN_DLL_OVERHEAD_SFF DIV_ROUND_UP(47, 8) + +/* Size of a Classical CAN Extended Frame in Bits: Same as above.
Quoted 20 lines
drivers/net/can/dev.c +20
-0+* +* Start-of-frame 1 +* Identifier A 11 +* Substitute remote request (SRR) 1 +* Identifier extension bit (IDE) 1 +* Identifier B 18 +* Remote transmission request (RTR) 1 +* Reserved bits (r1, r0) 2 +* Data length code (DLC) 4 +* Data field 0...64 +* CRC 15 +* CRC delimiter 1 +* ACK slot 1 +* ACK delimiter 1 +* End-of-frame (EOF) 7 +* Inter frame spacing 3 +* +* Rounded up and ignoring bitsuffing +*/ +#define CAN_DLL_OVERHEAD_EFF DIV_ROUND_UP(67, 8)drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 111
Quoted 10 lines
drivers/net/can/dev.c +10
-0+ +/* Maximum size of a Classical CAN frame +* (rounded up and ignoring bitsuffing) +*/ +#define CAN_DLL_LEN_MAX (CAN_DLL_OVERHEAD_EFF + CAN_MAX_DLEN) + +/* Maximum size of a CAN-FD frame (rough estimation because +* ES58X_SFF_BYTES() and ES58X_EFF_BYTES() macros are using the +* constant values for Classical CAN, not CAN-FD). +*/ /* Maximum size of a CAN-FD frame (rough estimation because
*CAN_DLL_OVERHEAD_SFFandCAN_DLL_OVERHEAD_EFFmacros are using the
* constant values for Classical CAN, not CAN-FD).
*/
Quoted 1 line
Some leftovers from the
etas_es58x:)
ACK, in the mean time I've makros for CAN-FD.
Quoted 39 lines
Quoted 14 lines
drivers/net/can/dev.c +13
-0+*/ +#define CANFD_DLL_LEN_MAX (CAN_DLL_OVERHEAD_EFF + CANFD_MAX_DLEN) + +/** +* can_skb_get_dll_len() - Calculate the CAN Data Link Layer length in +* bytes of a given skb. +* @skb: socket buffer of a CAN message. +* +* Do a rough calculation: bit stuffing is ignored and length in bits +* is rounded up to a length in bytes. +* +* Rationale: this function is to be used for the BQL functions +* (netdev_sent_queue() and netdev_completed_queue()) which expect a drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 133
Quoted 10 lines
drivers/net/can/dev.c +10
-0+* value in bytes. Just using skb->len is insufficient because it will +* return the constant value of CAN(FD)_MTU. Doing the bit stuffing +* calculation would be too expensive in term of computing resources +* for no noticeable gain. +* +* Remarks: +* a.) The payload of CAN FD frames with BRS flag are sent at a +* different bitrate. Currently, the can-utils canbusload tool does +* not support CAN-FD yet and so we could not run any benchmark to +* measure the impact. There might be possible improvement here. My initial idea was to convert the data transmitted at data bitrate speed to their equivalent duration at nominal rate (example: 8 bytes at 2Mbps are equivalent to 2 bytes at 500 Kbps).
Code would look as below:
unsigned int can_skb_get_frame_len(const struct
can_priv*can,
const structsk_buff*skb)
{
/* ... */if (cfd->flags & CANFD_BRS) len = mult_frac(CANFD_FRAME_OVERHEAD, can->bittiming.bitrate, can->data_bittiming.bitrate);
Quoted 7 lines
/* ... */
}This is just an overview, the data bitrate is also applied to some other fields of the frame (e.g. the CRC). So when creating the macro for the
CANFD_FRAME_OVERHEAD, it should be split between the nominal and data bitrates.
I think we shouldn't mess with the number of bytes depending on BRS. When it turns out that for CAN-FD this is not exact enough, we should look into the wifi drivers. As wifi doesn't even have a constant channel speed.
Quoted 9 lines
Quoted 9 lines
drivers/net/can/dev.c +9
-0+* b.) The macro CAN_DLL_OVERHEAD_EFF and CAN_DLL_OVERHEAD_SFF are +* for classical CAN. Need to do the addition for CAN-FD (the value +* are expected to be close enough so the impact should be minimal or +* none). +* +* Return: length in bytes. +*/ +unsigned int can_skb_get_dll_len (const struct sk_buff *skb) +{
Quoted 8 lines
drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 147
Quoted 5 lines
drivers/net/can/dev.c +5
-0+const struct canfd_frame *cf = (const struct canfd_frame *)skb->data; +u8 len; + +if (can_is_canfd_skb (skb)) { + len = cf->len +CAN_DLL_OVERHEAD_EFF ;The CAN-FD frame can also be sent in SFF. An additional check on the
CAN_EFF_FLAGis needed here.
ACK. CAN-FD was work-in-progress in this patch.
Quoted 27 lines
Quoted 27 lines
drivers/net/can/dev.c +16
-0+ }else { +if (cf->can_id &CAN_RTR_FLAG ) + len =0 ; +else + len = cf->len; + +if (cf->can_id &CAN_EFF_FLAG ) + len +=CAN_DLL_OVERHEAD_EFF ; +else + len +=CAN_DLL_OVERHEAD_SFF ; + } + +return len; +} +EXPORT_SYMBOL_GPL (can_skb_get_dll_len); +#ifdef CONFIG_CAN_CALC_BITTIMING #define CAN_CALC_MAX_ERROR 50/* in one-tenth of a percent */ include/linux/can/dev.h +0
-0@@ -192,6 +192,9 @@ u8 can_dlc2len(u8 can_dlc);/* map the sanitized data length to an appropriate data length code */ u8 can_len2dlc (u8 len);
Quoted 6 lines
include/linux/can/dev.h u8 can_dlc2len(u8 can_dlc); · line 200
Quoted 6 lines
include/linux/can/dev.h +3
-0+/* get data link layer length of CAN/CAN-FD frame */ +unsigned int can_skb_get_dll_len (const struct sk_buff *skb); +struct net_device *alloc_candev_mqs (int sizeof_priv,unsigned int echo_skb_max,unsigned int txqs,unsigned int rxqs);#define alloc_candev (sizeof_priv, echo_skb_max) \
This patch was mainly to get the naming discussion started.
Talking about CAN-FD and naming: For the CAN-FD frame/dll length we need the actual length of the data field.
The code looks like this:
Quoted 11 lines
static const u8 len2XXX[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */
12, 12, 12, 12, /* 9 - 12 */
16, 16, 16, 16, /* 13 - 16 */
20, 20, 20, 20, /* 17 - 20 */
24, 24, 24, 24, /* 21 - 24 */
32, 32, 32, 32, 32, 32, 32, 32, /* 25 - 32 */
40, 40, 40, 40, 40, 40, 40, 40, /* 33 - 40 */
48, 48, 48, 48, 48, 48, 48, 48 /* 41 - 48 */
};Quoted 8 lines
/* map the sanitized data length to an appropriate XXX length */ u8
can_len2XXX(u8 len){ if (unlikely(len > ARRAY_SIZE(len2XXX))) return 64; return len2XXX[len]; }
Have you got a good name for this, too?
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 |
Quoted 11 lines · Marc Kleine-Budde
Quoted 9 lines · Vincent MAILHOL
Quoted 3 lines
while reviewing the
etas_es58Xdriver and hacking on BQL support for the mcp251xfd driver, it turned out the a function to calculate the length of the CAN frame that's send over the wire should go into the generic CAN dev code.It took me a bit of time to figure out how to use the BQL. Contrary to the other features, I couldn't pull inspiration from the other CAN drivers. I am happy to see that you want to extend it to other drivers.
Quoted 4 lines
Quoted 2 lines
Also, on a side topic, please let me know if you have any comments on the
etas_es58xdriver ;)I'll look more into the driver later this week.
Thanks :)
Quoted 60 lines
Quoted 11 lines
Quoted 7 lines
Looking at the CAN and OSI layering I think the first layer where we have all the bits that we see on the wire is the data link layer (DLL).
https://www.can-cia.org/can-knowledge/can/can-data-link-layers
This is why I named the function
can_skb_get_dll_len().I would personally prefer to call it
can_skb_get_frame_len(). The ISO 11898 standard defines the "frame" as:Quoted 7 lines
Protocol Data Unit of the data link layer specifying the arrangement and meaning of bits or bit fields in the sequence of transfer across the transmission medium.
I imagine that you want to introduce the term "dll" instead of "frame" to clearly differentiate it from the struct
can_frameand structcan_fd_frame.ACK
Quoted 6 lines
But "frame" remains the most relevant term according to
the standard. I think that things are clear enough so that other kernel hackers would understand that the len fields of structcan_frameand structcan_fd_framerepresent the length of the payload and thatcan_skb_get_frame_len()is the length of the frame at the data link layer.Ok.
Quoted 7 lines
Quoted 2 lines
I'm planing to add a (better) calculation of the CAN-FD
dll_len, depending on the data and including different CRC lengths.Great! For my driver, everything seemed OK as it is currently but if this gets merged to the generic CAN dev code this part should definitely be improved (the comment I added in my code was there to warn whoever wanted to reuse it about the limitations).
:)
Quoted 20 lines
Quoted 20 lines
As this code is copied from the
etas_es58Xdriver, I've added the authors as Co-developed-by and I'd like to add their S-o-b to this patch.Please review and commnt on the naming on the functions.
regards,
Marcdrivers/net/can/dev.c | 103 ++++++++++++++++++++++++++++++++++++++++ include/linux/can/dev.h | 3 ++ 2 files changed, 106 insertions(+)drivers/net/can/dev.c +0
-0@@ -58,6 +58,109 @@ u8 can_len2dlc(u8 len) }EXPORT_SYMBOL_GPL (can_len2dlc);
Quoted 5 lines
Quoted 3 lines
drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 61
Quoted 1 line
drivers/net/can/dev.c +1
-0+/* Size of a Classical CAN Standard Frame in Bits: Size of a Classical CAN Standard Frame in Bytes:
The table is in bits, the overhead makros are in bytes, I'll try to clarift this.
ACK
Quoted 108 lines
Quoted 62 lines
The macro divides the grand total by 8. The subtotal is indeed presented in bits but the macro is in bytes.
Quoted 10 lines
drivers/net/can/dev.c +10
-0+* +* Start-of-frame 1 +* Identifier 11 +* Remote transmission request (RTR) 1 +* Identifier extension bit (IDE) 1 +* Reserved bit (r0) 1 +* Data length code (DLC) 4 +* Data field 0...64 +* CRC 15 +* CRC delimiter 1 drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 81
Quoted 10 lines
drivers/net/can/dev.c +10
-0+* ACK slot 1 +* ACK delimiter 1 +* End-of-frame (EOF) 7 +* Inter frame spacing 3 +* +* Rounded up and ignoring bitsuffing +*/ +#define CAN_DLL_OVERHEAD_SFF DIV_ROUND_UP(47, 8) + +/* Size of a Classical CAN Extended Frame in Bits: Same as above.
Quoted 20 lines
drivers/net/can/dev.c +20
-0+* +* Start-of-frame 1 +* Identifier A 11 +* Substitute remote request (SRR) 1 +* Identifier extension bit (IDE) 1 +* Identifier B 18 +* Remote transmission request (RTR) 1 +* Reserved bits (r1, r0) 2 +* Data length code (DLC) 4 +* Data field 0...64 +* CRC 15 +* CRC delimiter 1 +* ACK slot 1 +* ACK delimiter 1 +* End-of-frame (EOF) 7 +* Inter frame spacing 3 +* +* Rounded up and ignoring bitsuffing +*/ +#define CAN_DLL_OVERHEAD_EFF DIV_ROUND_UP(67, 8)drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 111
Quoted 10 lines
drivers/net/can/dev.c +10
-0+ +/* Maximum size of a Classical CAN frame +* (rounded up and ignoring bitsuffing) +*/ +#define CAN_DLL_LEN_MAX (CAN_DLL_OVERHEAD_EFF + CAN_MAX_DLEN) + +/* Maximum size of a CAN-FD frame (rough estimation because +* ES58X_SFF_BYTES() and ES58X_EFF_BYTES() macros are using the +* constant values for Classical CAN, not CAN-FD). +*/ /* Maximum size of a CAN-FD frame (rough estimation because
*CAN_DLL_OVERHEAD_SFFandCAN_DLL_OVERHEAD_EFFmacros are using the
* constant values for Classical CAN, not CAN-FD).
*/Quoted 1 line
Some leftovers from the
etas_es58x:)ACK, in the mean time I've makros for CAN-FD.
Quoted 42 lines
Quoted 14 lines
drivers/net/can/dev.c +13
-0+*/ +#define CANFD_DLL_LEN_MAX (CAN_DLL_OVERHEAD_EFF + CANFD_MAX_DLEN) + +/** +* can_skb_get_dll_len() - Calculate the CAN Data Link Layer length in +* bytes of a given skb. +* @skb: socket buffer of a CAN message. +* +* Do a rough calculation: bit stuffing is ignored and length in bits +* is rounded up to a length in bytes. +* +* Rationale: this function is to be used for the BQL functions +* (netdev_sent_queue() and netdev_completed_queue()) which expect a drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 133
Quoted 10 lines
drivers/net/can/dev.c +10
-0+* value in bytes. Just using skb->len is insufficient because it will +* return the constant value of CAN(FD)_MTU. Doing the bit stuffing +* calculation would be too expensive in term of computing resources +* for no noticeable gain. +* +* Remarks: +* a.) The payload of CAN FD frames with BRS flag are sent at a +* different bitrate. Currently, the can-utils canbusload tool does +* not support CAN-FD yet and so we could not run any benchmark to +* measure the impact. There might be possible improvement here. My initial idea was to convert the data transmitted at data bitrate speed to their equivalent duration at nominal rate (example: 8 bytes at 2Mbps are equivalent to 2 bytes at 500 Kbps).
Code would look as below:
unsigned int can_skb_get_frame_len(const struct
can_priv*can,
const structsk_buff*skb)
{
/* ... */if (cfd->flags & CANFD_BRS) len = mult_frac(CANFD_FRAME_OVERHEAD, can->bittiming.bitrate, can->data_bittiming.bitrate);/* ... */
}
Quoted 8 lines
Quoted 4 lines
This is just an overview, the data bitrate is also applied to some other fields of the frame (e.g. the CRC). So when creating the macro for the
CANFD_FRAME_OVERHEAD, it should be split between the nominal and data bitrates.I think we shouldn't mess with the number of bytes depending on BRS. When it turns out that for CAN-FD this is not exact enough, we should look into the wifi drivers. As wifi doesn't even have a constant channel speed.
I have to admit that I was also not a fan of that idea, but it was the only thing I could think of.
I am curious to see how this issue could be handled in a smarter way.
Quoted 78 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/can/dev.c +9
-0+* b.) The macro CAN_DLL_OVERHEAD_EFF and CAN_DLL_OVERHEAD_SFF are +* for classical CAN. Need to do the addition for CAN-FD (the value +* are expected to be close enough so the impact should be minimal or +* none). +* +* Return: length in bytes. +*/ +unsigned int can_skb_get_dll_len (const struct sk_buff *skb) +{Quoted 8 lines
drivers/net/can/dev.c u8 can_len2dlc(u8 len) · line 147
Quoted 5 lines
drivers/net/can/dev.c +5
-0+const struct canfd_frame *cf = (const struct canfd_frame *)skb->data; +u8 len; + +if (can_is_canfd_skb (skb)) { + len = cf->len +CAN_DLL_OVERHEAD_EFF ;The CAN-FD frame can also be sent in SFF. An additional check on the
CAN_EFF_FLAGis needed here.ACK. CAN-FD was work-in-progress in this patch.
Quoted 27 lines
Quoted 27 lines
drivers/net/can/dev.c +16
-0+ }else { +if (cf->can_id &CAN_RTR_FLAG ) + len =0 ; +else + len = cf->len; + +if (cf->can_id &CAN_EFF_FLAG ) + len +=CAN_DLL_OVERHEAD_EFF ; +else + len +=CAN_DLL_OVERHEAD_SFF ; + } + +return len; +} +EXPORT_SYMBOL_GPL (can_skb_get_dll_len); +#ifdef CONFIG_CAN_CALC_BITTIMING #define CAN_CALC_MAX_ERROR 50/* in one-tenth of a percent */ include/linux/can/dev.h +0
-0@@ -192,6 +192,9 @@ u8 can_dlc2len(u8 can_dlc);/* map the sanitized data length to an appropriate data length code */ u8 can_len2dlc (u8 len);Quoted 6 lines
include/linux/can/dev.h u8 can_dlc2len(u8 can_dlc); · line 200
Quoted 6 lines
include/linux/can/dev.h +3
-0+/* get data link layer length of CAN/CAN-FD frame */ +unsigned int can_skb_get_dll_len (const struct sk_buff *skb); +struct net_device *alloc_candev_mqs (int sizeof_priv,unsigned int echo_skb_max,unsigned int txqs,unsigned int rxqs);#define alloc_candev (sizeof_priv, echo_skb_max) \This patch was mainly to get the naming discussion started.
Talking about CAN-FD and naming: For the CAN-FD frame/dll length we need the actual length of the data field.
The code looks like this:
Quoted 17 lines
static const u8 len2XXX[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */ 12, 12, 12, 12, /* 9 - 12 */ 16, 16, 16, 16, /* 13 - 16 */ 20, 20, 20, 20, /* 17 - 20 */ 24, 24, 24, 24, /* 21 - 24 */ 32, 32, 32, 32, 32, 32, 32, 32, /* 25 - 32 */ 40, 40, 40, 40, 40, 40, 40, 40, /* 33 - 40 */ 48, 48, 48, 48, 48, 48, 48, 48 /* 41 - 48 */ };/* map the sanitized data length to an appropriate XXX length */ u8
can_len2XXX(u8 len)
{
if (unlikely(len > ARRAY_SIZE(len2XXX)))
return 64;
Quoted 4 lines
Quoted 2 lines
return len2XXX[len]; }Have you got a good name for this, too?
Before speaking of the naming, let me discuss the how to.
For CAN-FD, the overhead length (i.e. all fields of the frame minus the data) might vary depending on:
* Whether the frame is SFF or EFF
* Size of the CRC: either 15, 17 or 21 depending only on the length of the data.
I did not fully check the ISO standard, but I hope I did not forget another field of variable length in the above list.
The CRC field will be handled in the len2XXX[] table, the SFF/EFF will be handled in the can_len2XXX() function.
The other fields (sof, dlc, eof, ...) are constant, and can be squeezed in either the len2XXX[] table or the can_len2XXX() function.
The choice of how to group things is fully arbitrary.
Some candidates would be:
* can_fd_data_len2crc_len[] which would just do return the length on the CRC and leave all other calculation to the can_len2XXX() function.
* can_fd_data_len2ssf_len[] which will return the full frame length as if it was a SFF. The can_len2XXX() function would only do the very last step and add the length difference between the SFF and EFF if relevant.
All in between mix are also possible but would result in more convoluted naming (e.g. can_fd_data_len2data_crc_len[] that would return the data length plus the CRC length).
In all scenarios, the can_len2XXX() function would serve the same
purpose: calculate the full frame length. So I propose to name it can_fd_data_len2frame_len().
All that said, it is hard for me to pick a favorite. Out of all above idea, I propose to keep the second candidate:
* can_fd_data_len2ssf_len[]
But this is with no big conviction.
Marc Kleine-Budde
maintainerOn 12/15/20 1:40 PM, Vincent MAILHOL wrote:
[...]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
This is just an overview, the data bitrate is also applied to some other fields of the frame (e.g. the CRC). So when creating the macro for the
CANFD_FRAME_OVERHEAD, it should be split between the nominal and data bitrates.
Quoted 8 lines
Quoted 3 lines
I think we shouldn't mess with the number of bytes depending on BRS. When it turns out that for CAN-FD this is not exact enough, we should look into the wifi drivers. As wifi doesn't even have a constant channel speed.
I have to admit that I was also not a fan of that idea, but it was the only thing I could think of.
I am curious to see how this issue could be handled in a smarter way.
Let's wait until we have a "problem" with that :)
[...]
Quoted 22 lines
Quoted 22 lines
Talking about CAN-FD and naming: For the CAN-FD frame/dll length we need the actual length of the data field.
The code looks like this:
Quoted 17 lines
static const u8 len2XXX[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */ 12, 12, 12, 12, /* 9 - 12 */ 16, 16, 16, 16, /* 13 - 16 */ 20, 20, 20, 20, /* 17 - 20 */ 24, 24, 24, 24, /* 21 - 24 */ 32, 32, 32, 32, 32, 32, 32, 32, /* 25 - 32 */ 40, 40, 40, 40, 40, 40, 40, 40, /* 33 - 40 */ 48, 48, 48, 48, 48, 48, 48, 48 /* 41 - 48 */ };/* map the sanitized data length to an appropriate XXX length */ u8
can_len2XXX(u8 len)
{
if (unlikely(len > ARRAY_SIZE(len2XXX)))
return 64;
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
return len2XXX[len]; }Have you got a good name for this, too?
I've send a v2...(hmmm, but missed the v2)
Quoted 5 lines
Before speaking of the naming, let me discuss the how to.
For CAN-FD, the overhead length (i.e. all fields of the frame minus the data) might vary depending on:
* Whether the frame is SFF or EFF
ACK, included in the v2
Quoted 2 lines
* Size of the CRC: either 15, 17 or 21 depending only on the length of the data.
I haven't looked into the actual standard, but from what I have found, the CRC for CAN-FD frames is 17 (for data length 0...16 bytes) or 21 (for data length > 16 byes). Also there are 4 or 5 fixed stuff bits (corresponding to 17 or 21 bits of CRC) in the CRC.
I got the impression that even 0...8 byte CAN-FD frames use a CRC of 17.
Quoted 5 lines
I did not fully check the ISO standard, but I hope I did not forget another field of variable length in the above list.
The CRC field will be handled in the len2XXX[] table, the SFF/EFF will be handled in the
can_len2XXX()function.
For now I've selected the 21 bit CRC, for CAN-FD:
Quoted 1 line
#define
CANFD_DLL_OVERHEAD_SFFDIV_ROUND_UP(61, 8)
== 8 bytes
for CRC17 it would be 5 bits less => 56 bit => 7 bytes
Quoted 1 line
#define
CANFD_DLL_OVERHEAD_EFFDIV_ROUND_UP(80, 8)
== 10 bytes
for CRC17 it would be 5 bits less => 75 bits => 8 bytes
I think that 1 bit is not worth the trouble.
Quoted 2 lines
The other fields (sof, dlc, eof, ...) are constant, and can be squeezed in either the len2XXX[] table or the
can_len2XXX()function.
I want to use the can_fd_data_len2frame_data_len() in the mcp251xfd driver, so I'd like to keep that.
Quoted 11 lines
The choice of how to group things is fully arbitrary.
Some candidates would be:
* can_fd_data_len2crc_len[] which would just do return the length on the CRC and leave all other calculation to thecan_len2XXX()function.
* can_fd_data_len2ssf_len[] which will return the full frame length as if it was a SFF. Thecan_len2XXX()function would only do the very last step and add the length difference between the SFF and EFF if relevant.
Quoted 7 lines
All in between mix are also possible but would result in more convoluted naming (e.g. can_fd_data_len2data_crc_len[] that would return the data length plus the CRC length).
In all scenarios, the
can_len2XXX()function would serve the same
purpose: calculate the full frame length. So I propose to name itcan_fd_data_len2frame_len().
What about: can_fd_data_len2frame_data_len()
As it only the frame's data length, not the complete frame len. (I don't mind long function names :))
Quoted 4 lines
All that said, it is hard for me to pick a favorite. Out of all above idea, I propose to keep the second candidate:
* can_fd_data_len2ssf_len[]
But this is with no big conviction.
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
maintainerQuoted 8 lines · Marc Kleine-Budde
For now I've selected the 21 bit CRC, for CAN-FD:
Quoted 1 line
#define
CANFD_DLL_OVERHEAD_SFFDIV_ROUND_UP(61, 8)== 8 bytes
for CRC17 it would be 5 bits less => 56 bit => 7 bytes
Quoted 6 lines
Quoted 1 line
#define
CANFD_DLL_OVERHEAD_EFFDIV_ROUND_UP(80, 8)== 10 bytes
for CRC17 it would be 5 bits less => 75 bits => 8 bytes
I think that 1 bit is not worth the trouble.
s/bit/byte/
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
maintainerQuoted 27 lines · Marc Kleine-Budde
From: Vincent Mailhol <[email protected]>
This patch adds the function
can_skb_get_dll_len()which returns the length of a CAN frame on the data link layer, including Start-of-frame, Identifier, various other bits, the CRC, the End-of-frame, the Inter frame spacing and the actual data.Co-developed-by Arunachalam Santhanam <[email protected]>Not-Signed-off-by Arunachalam Santhanam <[email protected]>Co-developed-by Vincent Mailhol <[email protected]>Not-Signed-off-by Vincent Mailhol <[email protected]>Co-developed-by Marc Kleine-Budde <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>---
Hello,while reviewing the
etas_es58Xdriver and hacking on BQL support for the mcp251xfd driver, it turned out the a function to calculate the length of the CAN frame that's send over the wire should go into the generic CAN dev code.Looking at the CAN and OSI layering I think the first layer where we have all the bits that we see on the wire is the data link layer (DLL).
https://www.can-cia.org/can-knowledge/can/can-data-link-layers
This is why I named the function
can_skb_get_dll_len().
Quoted 7 lines
I'm planing to add a (better) calculation of the CAN-FD
dll_len, depending on the data and including different CRC lengths.As this code is copied from the
etas_es58Xdriver, I've added the authors as Co-developed-by and I'd like to add their S-o-b to this patch.Please review and commnt on the naming on the functions.
When implementing BQL we need the CAN frame's DLL len twice:
1. When sending the package to the hardware
2. After the TX-complete IRQ
We can calculate this information twice, but I thought we might put it into the struct can_skb_priv.
https://elixir.bootlin.com/linux/latest/source/include/linux/can/skb.h#L34
Thoughts?
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 |
Quoted 41 lines · Marc Kleine-Budde
Quoted 27 lines · Marc Kleine-Budde
From: Vincent Mailhol <[email protected]>
This patch adds the function
can_skb_get_dll_len()which returns the length of a CAN frame on the data link layer, including Start-of-frame, Identifier, various other bits, the CRC, the End-of-frame, the Inter frame spacing and the actual data.Co-developed-by Arunachalam Santhanam <[email protected]>Not-Signed-off-by Arunachalam Santhanam <[email protected]>Co-developed-by Vincent Mailhol <[email protected]>Not-Signed-off-by Vincent Mailhol <[email protected]>Co-developed-by Marc Kleine-Budde <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>---
Hello,while reviewing the
etas_es58Xdriver and hacking on BQL support for the mcp251xfd driver, it turned out the a function to calculate the length of the CAN frame that's send over the wire should go into the generic CAN dev code.Looking at the CAN and OSI layering I think the first layer where we have all the bits that we see on the wire is the data link layer (DLL).
https://www.can-cia.org/can-knowledge/can/can-data-link-layers
This is why I named the function
can_skb_get_dll_len().Quoted 7 lines
I'm planing to add a (better) calculation of the CAN-FD
dll_len, depending on the data and including different CRC lengths.As this code is copied from the
etas_es58Xdriver, I've added the authors as Co-developed-by and I'd like to add their S-o-b to this patch.Please review and commnt on the naming on the functions.
When implementing BQL we need the CAN frame's DLL len twice:
1. When sending the package to the hardware
2. After the TX-complete IRQ
Quoted 6 lines
We can calculate this information twice, but I thought we might put it into the struct
can_skb_priv.https://elixir.bootlin.com/linux/latest/source/include/linux/can/skb.h#L34
Thoughts?
I am not knowledgeable enough on this part to guarantee if there will be no side effects but regardless, I like the idea.
Also, an u8 is enough to hold the value. I wonder if it would be fine to change ifindex to, for example, u16, so that we do not lose any memory.
I would look like that:
struct can_skb_priv {
u16 ifindex;
u8 frame_len;
u8 res;
int skbcnt;
struct can_frame cf[];
};And the final result in the driver would look as below:
/* Tx branch */
can_skb_prv(skb)->frame_len = can_skb_get_frame_len(skb); netdev_sent_queue(can_skb_prv(skb)->frame_len);
/* Rx branch */ netdev_completed_queue(can_skb_prv(skb)->frame_len);
This is quite neat.
Quoted 7 lines · Vincent MAILHOL
Quoted 5 lines · Marc Kleine-Budde
We can calculate this information twice, but I thought we might put it into the struct
can_skb_priv.https://elixir.bootlin.com/linux/latest/source/include/linux/can/skb.h#L34
Quoted 8 lines
Quoted 1 line
Thoughts?
I am not knowledgeable enough on this part to guarantee if there will be no side effects but regardless, I like the idea.
Also, an u8 is enough to hold the value. I wonder if it would be fine to change ifindex to, for example, u16, so that we do not lose any memory.
We should not make can_skb_priv.ifindex another type than net_device.ifindex:
https://elixir.bootlin.com/linux/latest/source/include/linux/netdevice.h#L1899
Quoted 11 lines
I would look like that:
struct can_skb_priv { u16 ifindex; u8 frame_len; u8 res; int skbcnt; struct can_frame cf[]; };
Regards,
Oliver
Marc Kleine-Budde
maintainerQuoted 7 lines · Vincent MAILHOL
Quoted 7 lines
When implementing BQL we need the CAN frame's DLL len twice:
1. When sending the package to the hardware
2. After the TX-complete IRQWe can calculate this information twice, but I thought we might put it into the struct
can_skb_priv.
Quoted 8 lines
Quoted 3 lines
https://elixir.bootlin.com/linux/latest/source/include/linux/can/skb.h#L34
Thoughts?
I am not knowledgeable enough on this part to guarantee if there will be no side effects but regardless, I like the idea.
Also, an u8 is enough to hold the value.
ACK
Quoted 3 lines
I wonder if it would be fine
to change ifindex to, for example, u16, so that we do not lose any memory.
ifindex is an int:
https://elixir.bootlin.com/linux/v5.10.1/source/include/linux/netdevice.h#L1899
Quoted 6 lines
I would look like that:
struct can_skb_priv { u16 ifindex; u8 frame_len; u8 res;
No need for any reserved bytes, as this is not packed and not a stable API. The compiler will take care of the packing. If you want to save space in structures take a look at pahole:
https://lwn.net/Articles/206805/
Quoted 4 lines
int skbcnt;
struct can_frame cf[];
};Quoted 8 lines
And the final result in the driver would look as below:
/* Tx branch */
can_skb_prv(skb)->frame_len =can_skb_get_frame_len(skb); netdev_sent_queue(can_skb_prv(skb)->frame_len);/* Rx branch */ netdev_completed_queue(can_skb_prv(skb)->frame_len);
I think, I'll add another variety of the get_echo_skb() function, that returns the frame_len.
Quoted 1 line
This is quite neat.
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 |