Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Vincent Mailhol and committed by
Marc Kleine-Budde
63888a57 e1a5cd9d

+11 -10
+11 -10
drivers/net/can/dev/netlink.c
··· 472 472 return 0; 473 473 } 474 474 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) 476 477 { 477 - struct can_priv *priv = netdev_priv(dev); 478 + bool tdc_manual = tdc_flags & CAN_CTRLMODE_TDC_MANUAL_MASK; 478 479 size_t size; 479 480 480 - if (!priv->fd.tdc_const) 481 + if (!dbt_params->tdc_const) 481 482 return 0; 482 483 483 484 size = nla_total_size(0); /* nest IFLA_CAN_TDC */ 484 - if (priv->ctrlmode_supported & CAN_CTRLMODE_TDC_MANUAL) { 485 + if (tdc_manual) { 485 486 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCV_MIN */ 486 487 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCV_MAX */ 487 488 } 488 489 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCO_MIN */ 489 490 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) { 491 492 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCF_MIN */ 492 493 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCF_MAX */ 493 494 } 494 495 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) 498 498 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCV */ 499 499 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) 501 501 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCF */ 502 502 } 503 503 ··· 541 541 size += nla_total_size(sizeof(*priv->fd.data_bitrate_const) * 542 542 priv->fd.data_bitrate_const_cnt); 543 543 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); 545 546 size += can_ctrlmode_ext_get_size(); /* IFLA_CAN_CTRLMODE_EXT */ 546 547 547 548 return size;