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

can: netlink: make can_tdc_fill_info() FD agnostic

can_tdc_fill_info() depends on some variables which are specific to CAN
FD. Move these to the function parameters list so that, later on, this
function can be reused for the CAN XL TDC.

Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20250923-canxl-netlink-prep-v4-17-e720d28f66fe@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Vincent Mailhol and committed by
Marc Kleine-Budde
e72f1ba7 d5ee934e

+24 -11
+24 -11
drivers/net/can/dev/netlink.c
··· 585 585 sizeof(*bitrate_const) * cnt, bitrate_const); 586 586 } 587 587 588 - static int can_tdc_fill_info(struct sk_buff *skb, const struct net_device *dev) 588 + static int can_tdc_fill_info(struct sk_buff *skb, const struct net_device *dev, 589 + int ifla_can_tdc) 589 590 { 590 - struct nlattr *nest; 591 591 struct can_priv *priv = netdev_priv(dev); 592 - struct can_tdc *tdc = &priv->fd.tdc; 593 - const struct can_tdc_const *tdc_const = priv->fd.tdc_const; 592 + struct data_bittiming_params *dbt_params; 593 + const struct can_tdc_const *tdc_const; 594 + struct can_tdc *tdc; 595 + struct nlattr *nest; 596 + bool tdc_is_enabled, tdc_manual; 597 + 598 + if (ifla_can_tdc == IFLA_CAN_TDC) { 599 + dbt_params = &priv->fd; 600 + tdc_is_enabled = can_fd_tdc_is_enabled(priv); 601 + tdc_manual = priv->ctrlmode & CAN_CTRLMODE_TDC_MANUAL; 602 + } else { 603 + return -EOPNOTSUPP; /* Place holder for CAN XL */ 604 + } 605 + tdc_const = dbt_params->tdc_const; 606 + tdc = &dbt_params->tdc; 594 607 595 608 if (!tdc_const) 596 609 return 0; 597 610 598 - nest = nla_nest_start(skb, IFLA_CAN_TDC); 611 + nest = nla_nest_start(skb, ifla_can_tdc); 599 612 if (!nest) 600 613 return -EMSGSIZE; 601 614 602 - if (priv->ctrlmode_supported & CAN_CTRLMODE_TDC_MANUAL && 615 + if (tdc_manual && 603 616 (nla_put_u32(skb, IFLA_CAN_TDC_TDCV_MIN, tdc_const->tdcv_min) || 604 617 nla_put_u32(skb, IFLA_CAN_TDC_TDCV_MAX, tdc_const->tdcv_max))) 605 618 goto err_cancel; ··· 624 611 nla_put_u32(skb, IFLA_CAN_TDC_TDCF_MAX, tdc_const->tdcf_max))) 625 612 goto err_cancel; 626 613 627 - if (can_fd_tdc_is_enabled(priv)) { 614 + if (tdc_is_enabled) { 628 615 u32 tdcv; 629 616 int err = -EINVAL; 630 617 631 - if (priv->ctrlmode & CAN_CTRLMODE_TDC_MANUAL) { 618 + if (tdc_manual) { 632 619 tdcv = tdc->tdcv; 633 620 err = 0; 634 - } else if (priv->fd.do_get_auto_tdcv) { 635 - err = priv->fd.do_get_auto_tdcv(dev, &tdcv); 621 + } else if (dbt_params->do_get_auto_tdcv) { 622 + err = dbt_params->do_get_auto_tdcv(dev, &tdcv); 636 623 } 637 624 if (!err && nla_put_u32(skb, IFLA_CAN_TDC_TDCV, tdcv)) 638 625 goto err_cancel; ··· 720 707 sizeof(priv->bitrate_max), 721 708 &priv->bitrate_max)) || 722 709 723 - can_tdc_fill_info(skb, dev) || 710 + can_tdc_fill_info(skb, dev, IFLA_CAN_TDC) || 724 711 725 712 can_ctrlmode_ext_fill_info(skb, priv) 726 713 )