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

can: dev: can_changelink: allow to set bitrate on devices not providing {data_,}bittiming_const

Until commit

08da7da41ea4 can: provide a separate bittiming_const parameter to
bittiming functions

it was possible to have devices not providing bittiming_const. This can
be used for hardware that only support pre-defined fixed bitrates.
Although no mainline driver is using this feature so far.

This patch re-introduces this feature for the bitrate and the data
bitrate (of CANFD controllers). The driver can specify the
{data_,}bittiming_const (if the bittiming parameters should be
calculated from the bittiming_const) as before or no
{data_,}bittiming_const but implement the do_set_{data,}bittiming
callback.

Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

+30 -10
+30 -10
drivers/net/can/dev.c
··· 284 284 { 285 285 int err; 286 286 287 - /* Check if the CAN device has bit-timing parameters */ 288 - if (!btc) 289 - return -EOPNOTSUPP; 290 - 291 287 /* 292 288 * Depending on the given can_bittiming parameter structure the CAN 293 289 * timing parameters are calculated based on the provided bitrate OR ··· 868 872 /* Do not allow changing bittiming while running */ 869 873 if (dev->flags & IFF_UP) 870 874 return -EBUSY; 875 + 876 + /* Calculate bittiming parameters based on 877 + * bittiming_const if set, otherwise pass bitrate 878 + * directly via do_set_bitrate(). Bail out if neither 879 + * is given. 880 + */ 881 + if (!priv->bittiming_const && !priv->do_set_bittiming) 882 + return -EOPNOTSUPP; 883 + 871 884 memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt)); 872 - err = can_get_bittiming(dev, &bt, priv->bittiming_const); 873 - if (err) 874 - return err; 885 + if (priv->bittiming_const) { 886 + err = can_get_bittiming(dev, &bt, 887 + priv->bittiming_const); 888 + if (err) 889 + return err; 890 + } 875 891 memcpy(&priv->bittiming, &bt, sizeof(bt)); 876 892 877 893 if (priv->do_set_bittiming) { ··· 951 943 /* Do not allow changing bittiming while running */ 952 944 if (dev->flags & IFF_UP) 953 945 return -EBUSY; 946 + 947 + /* Calculate bittiming parameters based on 948 + * data_bittiming_const if set, otherwise pass bitrate 949 + * directly via do_set_bitrate(). Bail out if neither 950 + * is given. 951 + */ 952 + if (!priv->data_bittiming_const && !priv->do_set_data_bittiming) 953 + return -EOPNOTSUPP; 954 + 954 955 memcpy(&dbt, nla_data(data[IFLA_CAN_DATA_BITTIMING]), 955 956 sizeof(dbt)); 956 - err = can_get_bittiming(dev, &dbt, priv->data_bittiming_const); 957 - if (err) 958 - return err; 957 + if (priv->data_bittiming_const) { 958 + err = can_get_bittiming(dev, &dbt, 959 + priv->data_bittiming_const); 960 + if (err) 961 + return err; 962 + } 959 963 memcpy(&priv->data_bittiming, &dbt, sizeof(dbt)); 960 964 961 965 if (priv->do_set_data_bittiming) {