1. 30 Mar, 2021 10 commits
    • Vincent Mailhol's avatar
      can: bittiming: add CAN_KBPS, CAN_MBPS and CAN_MHZ macros · 1d775076
      Vincent Mailhol authored
      Add three macro to simplify the readability of big bit timing numbers:
        - CAN_KBPS: kilobits per second (one thousand)
        - CAN_MBPS: megabits per second (one million)
        - CAN_MHZ: megahertz per second (one million)
      
      Example:
      	u32 bitrate_max = 8 * CAN_MBPS;
      	struct can_clock clock = {.freq = 80 * CAN_MHZ};
      instead of:
      	u32 bitrate_max = 8000000;
      	struct can_clock clock = {.freq = 80000000};
      
      Apply the new macro to driver/net/can/dev/bittiming.c.
      
      Link: https://lore.kernel.org/r/20210306054040.76483-1-mailhol.vincent@wanadoo.frSigned-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      1d775076
    • Vincent Mailhol's avatar
      can: bittiming: add calculation for CAN FD Transmitter Delay Compensation (TDC) · c25cc799
      Vincent Mailhol authored
      The logic for the tdco calculation is to just reuse the normal sample
      point: tdco = sp. Because the sample point is expressed in tenth of
      percent and the tdco is expressed in time quanta, a conversion is
      needed.
      
      At the end,
           ssp = tdcv + tdco
               = tdcv + sp.
      
      Another popular method is to set tdco to the middle of the bit:
           tdc->tdco = can_bit_time(dbt) / 2
      During benchmark tests, we could not find a clear advantages for one
      of the two methods.
      
      The tdco calculation is triggered each time the data_bittiming is
      changed so that users relying on automated calculation can use the
      netlink interface the exact same way without need of new parameters.
      For example, a command such as:
      	ip link set canX type can bitrate 500000 dbitrate 4000000 fd on
      would trigger the calculation.
      
      The user using CONFIG_CAN_CALC_BITTIMING who does not want automated
      calculation needs to manually set tdco to zero.
      For example with:
      	ip link set canX type can tdco 0 bitrate 500000 dbitrate 4000000 fd on
      (if the tdco parameter is provided in a previous command, it will be
      overwritten).
      
      If tdcv is set to zero (default), it is automatically calculated by
      the transiver for each frame. As such, there is no code in the kernel
      to calculate it.
      
      tdcf has no automated calculation functions because we could not
      figure out a formula for this parameter.
      
      Link: https://lore.kernel.org/r/20210224002008.4158-6-mailhol.vincent@wanadoo.frSigned-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      c25cc799
    • Vincent Mailhol's avatar
      can: netlink: move '=' operators back to previous line (checkpatch fix) · cfd98c83
      Vincent Mailhol authored
      Fix the warning triggered by having an '=' at the beginning of the
      line by moving it back to the previous line. Also replace all
      indentations with a single space so that future entries can be more
      easily added.
      
      Extract of ./scripts/checkpatch.pl -f drivers/net/can/dev/netlink.c:
      
      CHECK: Assignment operator '=' should be on the previous line
      +       [IFLA_CAN_BITTIMING_CONST]
      +                               = { .len = sizeof(struct can_bittiming_const) },
      
      CHECK: Assignment operator '=' should be on the previous line
      +       [IFLA_CAN_DATA_BITTIMING]
      +                               = { .len = sizeof(struct can_bittiming) },
      
      CHECK: Assignment operator '=' should be on the previous line
      +       [IFLA_CAN_DATA_BITTIMING_CONST]
      +                               = { .len = sizeof(struct can_bittiming_const) },
      
      Link: https://lore.kernel.org/r/20210224002008.4158-4-mailhol.vincent@wanadoo.frSigned-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      cfd98c83
    • Vincent Mailhol's avatar
      can: dev: reorder struct can_priv members for better packing · 4c9258dd
      Vincent Mailhol authored
      Save eight bytes of holes on x86-64 architectures by reordering struct
      can_priv members.
      
      Before:
      
      $ pahole -C can_priv drivers/net/can/dev/dev.o
      struct can_priv {
      	struct net_device *        dev;                  /*     0     8 */
      	struct can_device_stats    can_stats;            /*     8    24 */
      	struct can_bittiming       bittiming;            /*    32    32 */
      	/* --- cacheline 1 boundary (64 bytes) --- */
      	struct can_bittiming       data_bittiming;       /*    64    32 */
      	const struct can_bittiming_const  * bittiming_const; /*    96     8 */
      	const struct can_bittiming_const  * data_bittiming_const; /*   104     8 */
      	struct can_tdc             tdc;                  /*   112    12 */
      
      	/* XXX 4 bytes hole, try to pack */
      
      	/* --- cacheline 2 boundary (128 bytes) --- */
      	const struct can_tdc_const  * tdc_const;         /*   128     8 */
      	const u16  *               termination_const;    /*   136     8 */
      	unsigned int               termination_const_cnt; /*   144     4 */
      	u16                        termination;          /*   148     2 */
      
      	/* XXX 2 bytes hole, try to pack */
      
      	const u32  *               bitrate_const;        /*   152     8 */
      	unsigned int               bitrate_const_cnt;    /*   160     4 */
      
      	/* XXX 4 bytes hole, try to pack */
      
      	const u32  *               data_bitrate_const;   /*   168     8 */
      	unsigned int               data_bitrate_const_cnt; /*   176     4 */
      	u32                        bitrate_max;          /*   180     4 */
      	struct can_clock           clock;                /*   184     4 */
      	enum can_state             state;                /*   188     4 */
      	/* --- cacheline 3 boundary (192 bytes) --- */
      	u32                        ctrlmode;             /*   192     4 */
      	u32                        ctrlmode_supported;   /*   196     4 */
      	u32                        ctrlmode_static;      /*   200     4 */
      	int                        restart_ms;           /*   204     4 */
      	struct delayed_work        restart_work;         /*   208   168 */
      
      	/* XXX last struct has 4 bytes of padding */
      
      	/* --- cacheline 5 boundary (320 bytes) was 56 bytes ago --- */
      	int                        (*do_set_bittiming)(struct net_device *); /*   376     8 */
      	/* --- cacheline 6 boundary (384 bytes) --- */
      	int                        (*do_set_data_bittiming)(struct net_device *); /*   384     8 */
      	int                        (*do_set_mode)(struct net_device *, enum can_mode); /*   392     8 */
      	int                        (*do_set_termination)(struct net_device *, u16); /*   400     8 */
      	int                        (*do_get_state)(const struct net_device  *, enum can_state *); /*   408     8 */
      	int                        (*do_get_berr_counter)(const struct net_device  *, struct can_berr_counter *); /*   416     8 */
      	unsigned int               echo_skb_max;         /*   424     4 */
      
      	/* XXX 4 bytes hole, try to pack */
      
      	struct sk_buff * *         echo_skb;             /*   432     8 */
      
      	/* size: 440, cachelines: 7, members: 31 */
      	/* sum members: 426, holes: 4, sum holes: 14 */
      	/* paddings: 1, sum paddings: 4 */
      	/* last cacheline: 56 bytes */
      };
      
      After:
      
      $ pahole -C can_priv drivers/net/can/dev/dev.o
      struct can_priv {
      	struct net_device *        dev;                  /*     0     8 */
      	struct can_device_stats    can_stats;            /*     8    24 */
      	const struct can_bittiming_const  * bittiming_const; /*    32     8 */
      	const struct can_bittiming_const  * data_bittiming_const; /*    40     8 */
      	struct can_bittiming       bittiming;            /*    48    32 */
      	/* --- cacheline 1 boundary (64 bytes) was 16 bytes ago --- */
      	struct can_bittiming       data_bittiming;       /*    80    32 */
      	const struct can_tdc_const  * tdc_const;         /*   112     8 */
      	struct can_tdc             tdc;                  /*   120    12 */
      	/* --- cacheline 2 boundary (128 bytes) was 4 bytes ago --- */
      	unsigned int               bitrate_const_cnt;    /*   132     4 */
      	const u32  *               bitrate_const;        /*   136     8 */
      	const u32  *               data_bitrate_const;   /*   144     8 */
      	unsigned int               data_bitrate_const_cnt; /*   152     4 */
      	u32                        bitrate_max;          /*   156     4 */
      	struct can_clock           clock;                /*   160     4 */
      	unsigned int               termination_const_cnt; /*   164     4 */
      	const u16  *               termination_const;    /*   168     8 */
      	u16                        termination;          /*   176     2 */
      
      	/* XXX 2 bytes hole, try to pack */
      
      	enum can_state             state;                /*   180     4 */
      	u32                        ctrlmode;             /*   184     4 */
      	u32                        ctrlmode_supported;   /*   188     4 */
      	/* --- cacheline 3 boundary (192 bytes) --- */
      	u32                        ctrlmode_static;      /*   192     4 */
      	int                        restart_ms;           /*   196     4 */
      	struct delayed_work        restart_work;         /*   200   168 */
      
      	/* XXX last struct has 4 bytes of padding */
      
      	/* --- cacheline 5 boundary (320 bytes) was 48 bytes ago --- */
      	int                        (*do_set_bittiming)(struct net_device *); /*   368     8 */
      	int                        (*do_set_data_bittiming)(struct net_device *); /*   376     8 */
      	/* --- cacheline 6 boundary (384 bytes) --- */
      	int                        (*do_set_mode)(struct net_device *, enum can_mode); /*   384     8 */
      	int                        (*do_set_termination)(struct net_device *, u16); /*   392     8 */
      	int                        (*do_get_state)(const struct net_device  *, enum can_state *); /*   400     8 */
      	int                        (*do_get_berr_counter)(const struct net_device  *, struct can_berr_counter *); /*   408     8 */
      	unsigned int               echo_skb_max;         /*   416     4 */
      
      	/* XXX 4 bytes hole, try to pack */
      
      	struct sk_buff * *         echo_skb;             /*   424     8 */
      
      	/* size: 432, cachelines: 7, members: 31 */
      	/* sum members: 426, holes: 2, sum holes: 6 */
      	/* paddings: 1, sum paddings: 4 */
      	/* last cacheline: 48 bytes */
      };
      
      Link: https://lore.kernel.org/r/20210224002008.4158-3-mailhol.vincent@wanadoo.frSigned-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      4c9258dd
    • Vincent Mailhol's avatar
      can: add new CAN FD bittiming parameters: Transmitter Delay Compensation (TDC) · 289ea9e4
      Vincent Mailhol authored
      At high bit rates, the propagation delay from the TX pin to the RX pin
      of the transceiver causes measurement errors: the sample point on the
      RX pin might occur on the previous bit.
      
      This issue is addressed in ISO 11898-1 section 11.3.3 "Transmitter
      delay compensation" (TDC).
      
      This patch adds two new structures: can_tdc and can_tdc_const in order
      to implement this TDC.
      
      The structures are then added to can_priv.
      
      A controller supports TDC if an only if can_priv::tdc_const is not
      NULL.
      
      TDC is active if and only if:
        - fd flag is on
        - can_priv::tdc.tdco is not zero.
      It is the driver responsibility to check those two conditions are met.
      
      No new controller modes are introduced (i.e. no CAN_CTRL_MODE_TDC) in
      order not to be redundant with above logic.
      
      The names of the parameters are chosen to match existing CAN
      controllers specification. References:
        - Bosch C_CAN FD8:
      https://www.bosch-semiconductors.com/media/ip_modules/pdf_2/c_can_fd8/users_manual_c_can_fd8_r210_1.pdf
        - Microchip CAN FD Controller Module:
      http://ww1.microchip.com/downloads/en/DeviceDoc/MCP251XXFD-CAN-FD-Controller-Module-Family-Reference-Manual-20005678B.pdf
        - SAM E701/S70/V70/V71 Family:
      https://www.mouser.com/datasheet/2/268/60001527A-1284321.pdf
      
      Link: https://lore.kernel.org/r/20210224002008.4158-2-mailhol.vincent@wanadoo.frSigned-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      289ea9e4
    • Marc Kleine-Budde's avatar
      can: dev: can_free_echo_skb(): extend to return can frame length · f318482a
      Marc Kleine-Budde authored
      In order to implement byte queue limits (bql) in CAN drivers, the
      length of the CAN frame needs to be passed into the networking stack
      even if the transmission failed for some reason.
      
      To avoid to calculate this length twice, extend can_free_echo_skb() to
      return that value. Convert all users of this function, too.
      
      This patch is the natural extension of commit:
      
      | 9420e1d4 ("can: dev: can_get_echo_skb(): extend to return can
      |                frame length")
      
      Link: https://lore.kernel.org/r/20210319142700.305648-3-mkl@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      f318482a
    • Marc Kleine-Budde's avatar
      can: dev: can_free_echo_skb(): don't crash the kernel if can_priv::echo_skb is... · 4168d079
      Marc Kleine-Budde authored
      can: dev: can_free_echo_skb(): don't crash the kernel if can_priv::echo_skb is accessed out of bounds
      
      A out of bounds access to "struct can_priv::echo_skb" leads to a
      kernel crash. Better print a sensible warning message instead and try
      to recover.
      
      This patch is similar to:
      
      | e7a6994d ("can: dev: __can_get_echo_skb(): Don't crash the kernel
      |               if can_priv::echo_skb is accessed out of bounds")
      
      Link: https://lore.kernel.org/r/20210319142700.305648-2-mkl@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      4168d079
    • Marc Kleine-Budde's avatar
      can: dev: always create TX echo skb · 7119d786
      Marc Kleine-Budde authored
      So far the creation of the TX echo skb was optional and can be
      controlled by the local sender of a CAN frame.
      
      It turns out that the TX echo CAN skb can be piggybacked to carry
      information in the driver from the TX- to the TX-complete handler.
      
      Several drivers already use the return value of
      can_get_echo_skb() (which is the length of the data field in the CAN
      frame) for their number of transferred bytes statistics. The
      statistics are not working if CAN echo skbs are disabled.
      
      Another use case is to calculate and set the CAN frame length on the
      wire, which is needed for BQL support in both the TX and TX-completion
      handler.
      
      For now in can_put_echo_skb(), which is called from the TX handler,
      the skb carrying the CAN frame is discarded if no TX echo is
      requested, leading to the above illustrated problems.
      
      This patch changes the can_put_echo_skb() function, so that the echo
      skb is always generated. If the sender requests no echo, the echo skb
      is consumed in __can_get_echo_skb() without being passed into the RX
      handler of the networking stack, but the CAN data length and CAN frame
      length information is properly returned.
      
      Link: https://lore.kernel.org/r/20210309211904.3348700-1-mkl@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      7119d786
    • Pankaj Sharma's avatar
      MAINTAINERS: Update MCAN MMIO device driver maintainer · ba23dc6d
      Pankaj Sharma authored
      Update Chandrasekar Ramakrishnan as maintainer for mcan mmio device driver as I
      will be moving to a different role.
      Signed-off-by: default avatarPankaj Sharma <pankj.sharma@samsung.com>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      ba23dc6d
    • Marc Kleine-Budde's avatar
      MAINTAINERS: remove Dan Murphy from m_can and tcan4x5x · 8560b0e7
      Marc Kleine-Budde authored
      Dan Murphy's email address at ti.com doesn't work anymore, mails
      bounce with:
      
      | 550 Invalid recipient <dmurphy@ti.com> (#5.1.1)
      
      For now remove all CAN related entries of Dan from the Maintainers
      file.
      
      Link: https://lore.kernel.org/r/20210228094218.40015-1-mkl@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      8560b0e7
  2. 29 Mar, 2021 30 commits