Skip to content

Commit 63888a5

Browse files
vincent-mailholmarckleinebudde
authored andcommitted
can: netlink: make can_tdc_get_size() FD agnostic
can_tdc_get_size() needs to access can_priv->fd making it specific to CAN FD. Change the function parameter from struct can_priv to struct data_bittiming_params. can_tdc_get_size() also uses the CAN_CTRLMODE_TDC_MANUAL macro making it specific to CAN FD. Add the tdc mask to the function parameter list. The value of the tdc manual flag can then be derived from that mask and stored in a local variable. This way, the function becomes CAN FD agnostic and can be reused later on for the CAN XL TDC. Signed-off-by: Vincent Mailhol <mailhol@kernel.org> Link: https://patch.msgid.link/20250923-canxl-netlink-prep-v4-12-e720d28f66fe@kernel.org Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent e1a5cd9 commit 63888a5

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

drivers/net/can/dev/netlink.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -472,32 +472,32 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],
472472
return 0;
473473
}
474474

475-
static size_t can_tdc_get_size(const struct net_device *dev)
475+
static size_t can_tdc_get_size(struct data_bittiming_params *dbt_params,
476+
u32 tdc_flags)
476477
{
477-
struct can_priv *priv = netdev_priv(dev);
478+
bool tdc_manual = tdc_flags & CAN_CTRLMODE_TDC_MANUAL_MASK;
478479
size_t size;
479480

480-
if (!priv->fd.tdc_const)
481+
if (!dbt_params->tdc_const)
481482
return 0;
482483

483484
size = nla_total_size(0); /* nest IFLA_CAN_TDC */
484-
if (priv->ctrlmode_supported & CAN_CTRLMODE_TDC_MANUAL) {
485+
if (tdc_manual) {
485486
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCV_MIN */
486487
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCV_MAX */
487488
}
488489
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCO_MIN */
489490
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCO_MAX */
490-
if (priv->fd.tdc_const->tdcf_max) {
491+
if (dbt_params->tdc_const->tdcf_max) {
491492
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCF_MIN */
492493
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCF_MAX */
493494
}
494495

495-
if (can_fd_tdc_is_enabled(priv)) {
496-
if (priv->ctrlmode & CAN_CTRLMODE_TDC_MANUAL ||
497-
priv->fd.do_get_auto_tdcv)
496+
if (tdc_flags) {
497+
if (tdc_manual || dbt_params->do_get_auto_tdcv)
498498
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCV */
499499
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCO */
500-
if (priv->fd.tdc_const->tdcf_max)
500+
if (dbt_params->tdc_const->tdcf_max)
501501
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCF */
502502
}
503503

@@ -541,7 +541,8 @@ static size_t can_get_size(const struct net_device *dev)
541541
size += nla_total_size(sizeof(*priv->fd.data_bitrate_const) *
542542
priv->fd.data_bitrate_const_cnt);
543543
size += sizeof(priv->bitrate_max); /* IFLA_CAN_BITRATE_MAX */
544-
size += can_tdc_get_size(dev); /* IFLA_CAN_TDC */
544+
size += can_tdc_get_size(&priv->fd, /* IFLA_CAN_TDC */
545+
priv->ctrlmode & CAN_CTRLMODE_FD_TDC_MASK);
545546
size += can_ctrlmode_ext_get_size(); /* IFLA_CAN_CTRLMODE_EXT */
546547

547548
return size;

0 commit comments

Comments
 (0)