mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-27 00:51:35 +00:00
can: dev: can_changelink: allow to set bitrate on devices not providing {data_,}bittiming_const
Until commit
08da7da41e
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>
This commit is contained in:
parent
12a6075cab
commit
c3606d438a
1 changed files with 30 additions and 10 deletions
|
@ -284,10 +284,6 @@ static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt,
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* Check if the CAN device has bit-timing parameters */
|
|
||||||
if (!btc)
|
|
||||||
return -EOPNOTSUPP;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Depending on the given can_bittiming parameter structure the CAN
|
* Depending on the given can_bittiming parameter structure the CAN
|
||||||
* timing parameters are calculated based on the provided bitrate OR
|
* timing parameters are calculated based on the provided bitrate OR
|
||||||
|
@ -872,10 +868,22 @@ static int can_changelink(struct net_device *dev,
|
||||||
/* Do not allow changing bittiming while running */
|
/* Do not allow changing bittiming while running */
|
||||||
if (dev->flags & IFF_UP)
|
if (dev->flags & IFF_UP)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
|
/* Calculate bittiming parameters based on
|
||||||
|
* bittiming_const if set, otherwise pass bitrate
|
||||||
|
* directly via do_set_bitrate(). Bail out if neither
|
||||||
|
* is given.
|
||||||
|
*/
|
||||||
|
if (!priv->bittiming_const && !priv->do_set_bittiming)
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt));
|
memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt));
|
||||||
err = can_get_bittiming(dev, &bt, priv->bittiming_const);
|
if (priv->bittiming_const) {
|
||||||
if (err)
|
err = can_get_bittiming(dev, &bt,
|
||||||
return err;
|
priv->bittiming_const);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
memcpy(&priv->bittiming, &bt, sizeof(bt));
|
memcpy(&priv->bittiming, &bt, sizeof(bt));
|
||||||
|
|
||||||
if (priv->do_set_bittiming) {
|
if (priv->do_set_bittiming) {
|
||||||
|
@ -943,11 +951,23 @@ static int can_changelink(struct net_device *dev,
|
||||||
/* Do not allow changing bittiming while running */
|
/* Do not allow changing bittiming while running */
|
||||||
if (dev->flags & IFF_UP)
|
if (dev->flags & IFF_UP)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
|
/* Calculate bittiming parameters based on
|
||||||
|
* data_bittiming_const if set, otherwise pass bitrate
|
||||||
|
* directly via do_set_bitrate(). Bail out if neither
|
||||||
|
* is given.
|
||||||
|
*/
|
||||||
|
if (!priv->data_bittiming_const && !priv->do_set_data_bittiming)
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
memcpy(&dbt, nla_data(data[IFLA_CAN_DATA_BITTIMING]),
|
memcpy(&dbt, nla_data(data[IFLA_CAN_DATA_BITTIMING]),
|
||||||
sizeof(dbt));
|
sizeof(dbt));
|
||||||
err = can_get_bittiming(dev, &dbt, priv->data_bittiming_const);
|
if (priv->data_bittiming_const) {
|
||||||
if (err)
|
err = can_get_bittiming(dev, &dbt,
|
||||||
return err;
|
priv->data_bittiming_const);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
memcpy(&priv->data_bittiming, &dbt, sizeof(dbt));
|
memcpy(&priv->data_bittiming, &dbt, sizeof(dbt));
|
||||||
|
|
||||||
if (priv->do_set_data_bittiming) {
|
if (priv->do_set_data_bittiming) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue