linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Oliver Hartkopp <socketcan@hartkopp.net>, linux-can@vger.kernel.org
Subject: Re: [PATCH v3 5/5] can: allow to change the device mtu for CAN FD capable devices
Date: Sat, 15 Feb 2014 17:59:56 +0100	[thread overview]
Message-ID: <52FF9D0C.30406@pengutronix.de> (raw)
In-Reply-To: <1392481934-12569-5-git-send-email-socketcan@hartkopp.net>

[-- Attachment #1: Type: text/plain, Size: 4078 bytes --]

Hello Oliver,

please add a cover letter (--compose option to git send-email) when
sending a new version of the series, briefly listing your changes (one
line per change).

Please add a patch description to patch 4, as in the kernel it's
considered bad style to have patches without a description.

On 02/15/2014 05:32 PM, Oliver Hartkopp wrote:
> The configuration for CAN FD depends on CAN_CTRLMODE_FD enabled in the driver
> specific ctrlmode_supported capabilities.
> 
> The configuration can be done either with the 'fd { on | off }' option in the
> 'ip' tool from iproute2 or by setting the CAN netdevice MTU to CAN_MTU (16) or
> to CANFD_MTU (72).

Please don't add two possibilities to activate canfd on a CAN network
card. There should only be one.

> 
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
> ---
>  drivers/net/can/dev.c            | 40 ++++++++++++++++++++++++++++++++++++++++
>  include/linux/can/dev.h          |  1 +
>  include/uapi/linux/can/netlink.h |  1 +
>  3 files changed, 42 insertions(+)
> 
> diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
> index a2b9bce..397efa4 100644
> --- a/drivers/net/can/dev.c
> +++ b/drivers/net/can/dev.c
> @@ -598,6 +598,40 @@ void free_candev(struct net_device *dev)
>  EXPORT_SYMBOL_GPL(free_candev);
>  
>  /*
> + * changing MTU and control mode for CAN/CANFD devices
> + */
> +int can_change_mtu(struct net_device *dev, int new_mtu)
> +{
> +	struct can_priv *priv = netdev_priv(dev);
> +
> +	/* Do not allow changing the MTU while running */
> +	if (dev->flags & IFF_UP)
> +		return -EBUSY;
> +
> +	/* allow change of MTU according to the CANFD ability of the device */
> +	switch (new_mtu) {
> +
> +	case CAN_MTU:
> +		priv->ctrlmode &= ~CAN_CTRLMODE_FD;
> +		break;
> +
> +	case CANFD_MTU:
> +		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD))
> +			return -EINVAL;
> +
> +		priv->ctrlmode |= CAN_CTRLMODE_FD;
> +		break;
> +
> +	default:
> +			return -EINVAL;
> +	}
> +
> +	dev->mtu = new_mtu;
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(can_change_mtu);

Who will be the user of this function? The individual network drivers?

> +
> +/*
>   * Common open function when the device gets opened.
>   *
>   * This function should be called in the open function of the device
> @@ -721,6 +755,12 @@ static int can_changelink(struct net_device *dev,
>  			return -EOPNOTSUPP;
>  		priv->ctrlmode &= ~cm->mask;
>  		priv->ctrlmode |= cm->flags;
> +
> +		/* CAN_CTRLMODE_FD can only be set when driver supports FD */
> +		if (priv->ctrlmode & CAN_CTRLMODE_FD)
> +			dev->mtu = CANFD_MTU;
> +		else
> +			dev->mtu = CAN_MTU;
>  	}
>  
>  	if (data[IFLA_CAN_RESTART_MS]) {
> diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
> index 8adaee9..3ce5e52 100644
> --- a/include/linux/can/dev.h
> +++ b/include/linux/can/dev.h
> @@ -113,6 +113,7 @@ struct can_priv *safe_candev_priv(struct net_device *dev);
>  
>  int open_candev(struct net_device *dev);
>  void close_candev(struct net_device *dev);
> +int can_change_mtu(struct net_device *dev, int new_mtu);
>  
>  int register_candev(struct net_device *dev);
>  void unregister_candev(struct net_device *dev);
> diff --git a/include/uapi/linux/can/netlink.h b/include/uapi/linux/can/netlink.h
> index b41933d..7e2e186 100644
> --- a/include/uapi/linux/can/netlink.h
> +++ b/include/uapi/linux/can/netlink.h
> @@ -96,6 +96,7 @@ struct can_ctrlmode {
>  #define CAN_CTRLMODE_3_SAMPLES		0x04	/* Triple sampling mode */
>  #define CAN_CTRLMODE_ONE_SHOT		0x08	/* One-Shot mode */
>  #define CAN_CTRLMODE_BERR_REPORTING	0x10	/* Bus-error reporting */
> +#define CAN_CTRLMODE_FD			0x20	/* CAN FD mode */
>  
>  /*
>   * CAN device statistics
> 

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 242 bytes --]

  reply	other threads:[~2014-02-15 16:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-15 16:32 [PATCH v3 1/5] can: preserve skbuff protocol in can_put_echo_skb Oliver Hartkopp
2014-02-15 16:32 ` [PATCH v3 2/5] can: netlink send bittiming data only when a bitrate is available Oliver Hartkopp
2014-02-15 16:32 ` [PATCH v3 3/5] can: provide a separate bittiming_const parameter to bittiming functions Oliver Hartkopp
2014-02-15 16:32 ` [PATCH v3 4/5] can: introduce the data bitrate configuration for CAN FD Oliver Hartkopp
2014-02-21  8:27   ` Stephane Grosjean
2014-02-15 16:32 ` [PATCH v3 5/5] can: allow to change the device mtu for CAN FD capable devices Oliver Hartkopp
2014-02-15 16:59   ` Marc Kleine-Budde [this message]
2014-02-15 17:00     ` Marc Kleine-Budde
2014-02-15 17:29     ` Oliver Hartkopp
2014-02-18 11:09       ` Marc Kleine-Budde
2014-02-18 13:08         ` Oliver Hartkopp
2014-02-19 18:25           ` Oliver Hartkopp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52FF9D0C.30406@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=socketcan@hartkopp.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).