mirror_ubuntu-kernels/drivers/net/can
Vincent Mailhol 80a2fbce45 can: length: refactor frame lengths definition to add size in bits
Introduce a method to calculate the exact size in bits of a CAN(-FD)
frame with or without dynamic bitstuffing.

These are all the possible combinations taken into account:

  - Classical CAN or CAN-FD
  - Standard or Extended frame format
  - CAN-FD CRC17 or CRC21
  - Include or not intermission

Instead of doing several individual macro definitions, declare the
can_frame_bits() function-like macro. To this extent, do a full
refactoring of the length definitions.

In addition add the can_frame_bytes(). This function-like macro
replaces the existing macro:

  - CAN_FRAME_OVERHEAD_SFF: can_frame_bytes(false, false, 0)
  - CAN_FRAME_OVERHEAD_EFF: can_frame_bytes(false, true, 0)
  - CANFD_FRAME_OVERHEAD_SFF: can_frame_bytes(true, false, 0)
  - CANFD_FRAME_OVERHEAD_EFF: can_frame_bytes(true, true, 0)

Function-like macros were chosen over inline functions because they
can be used to initialize const struct fields.

The different maximum frame lengths (maximum data length, including
intermission) are as follow:

   Frame type				bits	bytes
  -------------------------------------------------------
   Classic CAN SFF no bitstuffing	111	14
   Classic CAN EFF no bitstuffing	131	17
   Classic CAN SFF bitstuffing		135	17
   Classic CAN EFF bitstuffing		160	20
   CAN-FD SFF no bitstuffing		579	73
   CAN-FD EFF no bitstuffing		598	75
   CAN-FD SFF bitstuffing		712	89
   CAN-FD EFF bitstuffing		736	92

The macro CAN_FRAME_LEN_MAX and CANFD_FRAME_LEN_MAX are kept as an
alias to, respectively, can_frame_bytes(false, true, CAN_MAX_DLEN) and
can_frame_bytes(true, true, CANFD_MAX_DLEN).

In addition to the above:

 - Use ISO 11898-1:2015 definitions for the names of the CAN frame
   fields.
 - Include linux/bits.h for use of BITS_PER_BYTE.
 - Include linux/math.h for use of mult_frac() and
   DIV_ROUND_UP(). N.B: the use of DIV_ROUND_UP() is not new to this
   patch, but the include was previously omitted.
 - Add copyright 2023 for myself.

Suggested-by: Thomas Kopp <Thomas.Kopp@microchip.com>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Reviewed-by: Thomas Kopp <Thomas.Kopp@microchip.com>
Link: https://lore.kernel.org/all/20230611025728.450837-4-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2023-06-22 09:43:40 +02:00
..
c_can can: c_can: Convert to platform remove callback returning void 2023-05-15 22:53:49 +02:00
cc770 can: cc770_platform: Convert to platform remove callback returning void 2023-05-15 22:53:49 +02:00
ctucanfd can: ctucanfd: Convert to platform remove callback returning void 2023-05-15 22:53:50 +02:00
dev can: length: refactor frame lengths definition to add size in bits 2023-06-22 09:43:40 +02:00
flexcan can: flexcan: Convert to platform remove callback returning void 2023-05-15 22:53:50 +02:00
ifi_canfd can: ifi_canfd: Convert to platform remove callback returning void 2023-05-15 22:53:50 +02:00
m_can can: m_can: fix coding style 2023-06-22 09:42:28 +02:00
mscan can: mscan: mpc5xxx_can: Convert to platform remove callback returning void 2023-05-15 22:53:50 +02:00
peak_canfd can: dev: fix skb drop check 2022-11-07 14:00:27 +01:00
rcar can: rcar: Convert to platform remove callback returning void 2023-05-15 22:53:50 +02:00
sja1000 can: sja1000: Prevent overrun stalls with a soft reset on Renesas SoCs 2023-06-22 09:41:32 +02:00
slcan can: slcan: fix freed work crash 2022-12-07 10:32:24 +01:00
softing can: softing: Convert to platform remove callback returning void 2023-05-15 22:53:51 +02:00
spi linux-can-next-for-6.3-20230206 2023-02-07 15:54:09 +01:00
usb can: esd_usb: Use consistent prefix ESD_USB_ for macros 2023-06-22 09:40:34 +02:00
at91_can.c can: at91_can: Convert to platform remove callback returning void 2023-05-15 22:53:49 +02:00
bxcan.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2023-05-18 14:39:34 -07:00
can327.c can: can327: flush TX_work on ldisc .close() 2022-12-07 10:32:36 +01:00
grcan.c can: grcan: Convert to platform remove callback returning void 2023-05-15 22:53:50 +02:00
janz-ican3.c can: janz-ican3: Convert to platform remove callback returning void 2023-05-15 22:53:50 +02:00
Kconfig can: CAN_BXCAN should depend on ARCH_STM32 2023-05-15 22:24:47 +02:00
kvaser_pciefd.c can: kvaser_pciefd: Disable interrupts in probe error path 2023-05-17 09:02:40 +02:00
Makefile can: bxcan: add support for ST bxCAN controller 2023-03-28 11:43:36 +02:00
sun4i_can.c can: sun4i_can: Convert to platform remove callback returning void 2023-05-15 22:53:51 +02:00
ti_hecc.c can: ti_hecc: fix coding style 2023-06-22 09:42:28 +02:00
vcan.c can: dev: add CAN XL support to virtual CAN 2022-09-15 09:08:09 +02:00
vxcan.c rtnetlink: pass netlink message header and portid to rtnl_configure_link() 2022-10-31 18:10:21 -07:00
xilinx_can.c can: dev: add transceiver capabilities to xilinx_can 2023-05-22 20:21:30 +02:00