• Vincent Mailhol's avatar
    can: netlink: add interface for CAN-FD Transmitter Delay Compensation (TDC) · d99755f7
    Vincent Mailhol authored
    Add the netlink interface for TDC parameters of struct can_tdc_const
    and can_tdc.
    
    Contrary to the can_bittiming(_const) structures for which there is
    just a single IFLA_CAN(_DATA)_BITTMING(_CONST) entry per structure,
    here, we create a nested entry IFLA_CAN_TDC. Within this nested entry,
    additional IFLA_CAN_TDC_TDC* entries are added for each of the TDC
    parameters of the newly introduced struct can_tdc_const and struct
    can_tdc.
    
    For struct can_tdc_const, these are:
            IFLA_CAN_TDC_TDCV_MIN
            IFLA_CAN_TDC_TDCV_MAX
            IFLA_CAN_TDC_TDCO_MIN
            IFLA_CAN_TDC_TDCO_MAX
            IFLA_CAN_TDC_TDCF_MIN
            IFLA_CAN_TDC_TDCF_MAX
    
    For struct can_tdc, these are:
            IFLA_CAN_TDC_TDCV
            IFLA_CAN_TDC_TDCO
            IFLA_CAN_TDC_TDCF
    
    This is done so that changes can be applied in the future to the
    structures without breaking the netlink interface.
    
    The TDC netlink logic works as follow:
    
     * CAN_CTRLMODE_FD is not provided:
        - if any TDC parameters are provided: error.
    
        - TDC parameters not provided: TDC parameters unchanged.
    
     * CAN_CTRLMODE_FD is provided and is false:
         - TDC is deactivated: both the structure and the
           CAN_CTRLMODE_TDC_{AUTO,MANUAL} flags are flushed.
    
     * CAN_CTRLMODE_FD provided and is true:
        - CAN_CTRLMODE_TDC_{AUTO,MANUAL} and tdc{v,o,f} not provided: call
          can_calc_tdco() to automatically decide whether TDC should be
          activated and, if so, set CAN_CTRLMODE_TDC_AUTO and uses the
          calculated tdco value.
    
        - CAN_CTRLMODE_TDC_AUTO and tdco provided: set
          CAN_CTRLMODE_TDC_AUTO and use the provided tdco value. Here,
          tdcv is illegal and tdcf is optional.
    
        - CAN_CTRLMODE_TDC_MANUAL and both of tdcv and tdco provided: set
          CAN_CTRLMODE_TDC_MANUAL and use the provided tdcv and tdco
          value. Here, tdcf is optional.
    
        - CAN_CTRLMODE_TDC_{AUTO,MANUAL} are mutually exclusive. Whenever
          one flag is turned on, the other will automatically be turned
          off. Providing both returns an error.
    
        - Combination other than the one listed above are illegal and will
          return an error.
    
    N.B. above rules mean that whenever CAN_CTRLMODE_FD is provided, the
    previous TDC values will be overwritten. The only option to reuse
    previous TDC value is to not provide CAN_CTRLMODE_FD.
    
    All the new parameters are defined as u32. This arbitrary choice is
    done to mimic the other bittiming values with are also all of type
    u32. An u16 would have been sufficient to hold the TDC values.
    
    This patch completes below series (c.f. [1]):
      - commit 289ea9e4 ("can: add new CAN FD bittiming parameters:
        Transmitter Delay Compensation (TDC)")
      - commit c25cc799 ("can: bittiming: add calculation for CAN FD
        Transmitter Delay Compensation (TDC)")
    
    [1] https://lore.kernel.org/linux-can/20210224002008.4158-1-mailhol.vincent@wanadoo.fr/T/#t
    
    Link: https://lore.kernel.org/all/20210918095637.20108-5-mailhol.vincent@wanadoo.frSigned-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
    Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
    d99755f7
netlink.c 16.9 KB