Skip to content

Commit c3606d4

Browse files
can: dev: can_changelink: allow to set bitrate on devices not providing {data_,}bittiming_const
Until commit 08da7da 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 <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 12a6075 commit c3606d4

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

drivers/net/can/dev.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,6 @@ static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt,
284284
{
285285
int err;
286286

287-
/* Check if the CAN device has bit-timing parameters */
288-
if (!btc)
289-
return -EOPNOTSUPP;
290-
291287
/*
292288
* Depending on the given can_bittiming parameter structure the CAN
293289
* timing parameters are calculated based on the provided bitrate OR
@@ -872,10 +868,22 @@ static int can_changelink(struct net_device *dev,
872868
/* Do not allow changing bittiming while running */
873869
if (dev->flags & IFF_UP)
874870
return -EBUSY;
871+
872+
/* Calculate bittiming parameters based on
873+
* bittiming_const if set, otherwise pass bitrate
874+
* directly via do_set_bitrate(). Bail out if neither
875+
* is given.
876+
*/
877+
if (!priv->bittiming_const && !priv->do_set_bittiming)
878+
return -EOPNOTSUPP;
879+
875880
memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt));
876-
err = can_get_bittiming(dev, &bt, priv->bittiming_const);
877-
if (err)
878-
return err;
881+
if (priv->bittiming_const) {
882+
err = can_get_bittiming(dev, &bt,
883+
priv->bittiming_const);
884+
if (err)
885+
return err;
886+
}
879887
memcpy(&priv->bittiming, &bt, sizeof(bt));
880888

881889
if (priv->do_set_bittiming) {
@@ -943,11 +951,23 @@ static int can_changelink(struct net_device *dev,
943951
/* Do not allow changing bittiming while running */
944952
if (dev->flags & IFF_UP)
945953
return -EBUSY;
954+
955+
/* Calculate bittiming parameters based on
956+
* data_bittiming_const if set, otherwise pass bitrate
957+
* directly via do_set_bitrate(). Bail out if neither
958+
* is given.
959+
*/
960+
if (!priv->data_bittiming_const && !priv->do_set_data_bittiming)
961+
return -EOPNOTSUPP;
962+
946963
memcpy(&dbt, nla_data(data[IFLA_CAN_DATA_BITTIMING]),
947964
sizeof(dbt));
948-
err = can_get_bittiming(dev, &dbt, priv->data_bittiming_const);
949-
if (err)
950-
return err;
965+
if (priv->data_bittiming_const) {
966+
err = can_get_bittiming(dev, &dbt,
967+
priv->data_bittiming_const);
968+
if (err)
969+
return err;
970+
}
951971
memcpy(&priv->data_bittiming, &dbt, sizeof(dbt));
952972

953973
if (priv->do_set_data_bittiming) {

0 commit comments

Comments
 (0)