Commit da45a1e4 authored by Vincent Mailhol's avatar Vincent Mailhol Committed by Marc Kleine-Budde

can: bittiming: change can_calc_tdco()'s prototype to not directly modify priv

The function can_calc_tdco() directly retrieves can_priv from the
net_device and directly modifies it.

This is annoying for the upcoming patch. In
drivers/net/can/dev/netlink.c:can_changelink(), the data bittiming are
written to a temporary structure and memcpyed to can_priv only after
everything succeeded. In the next patch, where we will introduce the
netlink interface for TDC parameters, we will add a new TDC block
which can potentially fail. For this reason, the data bittiming
temporary structure has to be copied after that to-be-introduced TDC
block. However, TDC also needs to access data bittiming information.

We change the prototype so that the data bittiming structure is passed
to can_calc_tdco() as an argument instead of retrieving it from
priv. This way can_calc_tdco() can access the data bittiming before it
gets memcpyed to priv.

Link: https://lore.kernel.org/all/20210918095637.20108-4-mailhol.vincent@wanadoo.frSigned-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 39f66c9e
...@@ -175,18 +175,15 @@ int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, ...@@ -175,18 +175,15 @@ int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
return 0; return 0;
} }
void can_calc_tdco(struct net_device *dev) void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const,
{ const struct can_bittiming *dbt,
struct can_priv *priv = netdev_priv(dev); u32 *ctrlmode, u32 ctrlmode_supported)
const struct can_bittiming *dbt = &priv->data_bittiming;
struct can_tdc *tdc = &priv->tdc;
const struct can_tdc_const *tdc_const = priv->tdc_const;
if (!tdc_const || {
!(priv->ctrlmode_supported & CAN_CTRLMODE_TDC_AUTO)) if (!tdc_const || !(ctrlmode_supported & CAN_CTRLMODE_TDC_AUTO))
return; return;
priv->ctrlmode &= ~CAN_CTRLMODE_TDC_MASK; *ctrlmode &= ~CAN_CTRLMODE_TDC_MASK;
/* As specified in ISO 11898-1 section 11.3.3 "Transmitter /* As specified in ISO 11898-1 section 11.3.3 "Transmitter
* delay compensation" (TDC) is only applicable if data BRP is * delay compensation" (TDC) is only applicable if data BRP is
...@@ -200,7 +197,7 @@ void can_calc_tdco(struct net_device *dev) ...@@ -200,7 +197,7 @@ void can_calc_tdco(struct net_device *dev)
if (sample_point_in_tc < tdc_const->tdco_min) if (sample_point_in_tc < tdc_const->tdco_min)
return; return;
tdc->tdco = min(sample_point_in_tc, tdc_const->tdco_max); tdc->tdco = min(sample_point_in_tc, tdc_const->tdco_max);
priv->ctrlmode |= CAN_CTRLMODE_TDC_AUTO; *ctrlmode |= CAN_CTRLMODE_TDC_AUTO;
} }
} }
#endif /* CONFIG_CAN_CALC_BITTIMING */ #endif /* CONFIG_CAN_CALC_BITTIMING */
......
...@@ -189,7 +189,8 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[], ...@@ -189,7 +189,8 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],
memcpy(&priv->data_bittiming, &dbt, sizeof(dbt)); memcpy(&priv->data_bittiming, &dbt, sizeof(dbt));
can_calc_tdco(dev); can_calc_tdco(&priv->tdc, priv->tdc_const, &priv->data_bittiming,
&priv->ctrlmode, priv->ctrlmode_supported);
if (priv->do_set_data_bittiming) { if (priv->do_set_data_bittiming) {
/* Finally, set the bit-timing registers */ /* Finally, set the bit-timing registers */
......
...@@ -123,7 +123,9 @@ struct can_tdc_const { ...@@ -123,7 +123,9 @@ struct can_tdc_const {
int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
const struct can_bittiming_const *btc); const struct can_bittiming_const *btc);
void can_calc_tdco(struct net_device *dev); void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const,
const struct can_bittiming *dbt,
u32 *ctrlmode, u32 ctrlmode_supported);
#else /* !CONFIG_CAN_CALC_BITTIMING */ #else /* !CONFIG_CAN_CALC_BITTIMING */
static inline int static inline int
can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
...@@ -133,7 +135,10 @@ can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, ...@@ -133,7 +135,10 @@ can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
return -EINVAL; return -EINVAL;
} }
static inline void can_calc_tdco(struct net_device *dev) static inline void
can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const,
const struct can_bittiming *dbt,
u32 *ctrlmode, u32 ctrlmode_supported)
{ {
} }
#endif /* CONFIG_CAN_CALC_BITTIMING */ #endif /* CONFIG_CAN_CALC_BITTIMING */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment