From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Faiz Abbas <faiz_abbas@ti.com>,
wg@grandegger.com, robh+dt@kernel.org, mark.rutland@arm.com
Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
nsekhar@ti.com, fcooper@ti.com, robh@kernel.org,
Wenyou.Yang@microchip.com, sergei.shtylyov@cogentembedded.com,
linux-omap@vger.kernel.org, b29396@freescale.com
Subject: Re: [PATCH v7 1/8] can: dev: Add support for limiting configured bitrate
Date: Mon, 15 Jan 2018 14:40:59 +0100 [thread overview]
Message-ID: <d82752f1-657f-b07e-5d91-b39ea0b6984d@pengutronix.de> (raw)
In-Reply-To: <1515581725-29242-2-git-send-email-faiz_abbas@ti.com>
[-- Attachment #1.1: Type: text/plain, Size: 6300 bytes --]
On 01/10/2018 11:55 AM, Faiz Abbas wrote:
> From: Franklin S Cooper Jr <fcooper@ti.com>
>
> Various CAN or CAN-FD IP may be able to run at a faster rate than
> what the transceiver the CAN node is connected to. This can lead to
> unexpected errors. However, CAN transceivers typically have fixed
> limitations and provide no means to discover these limitations at
> runtime. Therefore, add support for a can-transceiver node that
> can be reused by other CAN peripheral drivers to determine for both
> CAN and CAN-FD what the max bitrate that can be used. If the user
> tries to configure CAN to pass these maximum bitrates it will throw
> an error.
>
> Also add support for reading bitrate_max via the netlink interface.
added to can-next with some minor changes. See inline.
> Reviewed-by: Suman Anna <s-anna@ti.com>
> Signed-off-by: Franklin S Cooper Jr <fcooper@ti.com>
> [nsekhar@ti.com: fix build error with !CONFIG_OF]
> Signed-off-by: Sekhar Nori <nsekhar@ti.com>
> Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
> ---
> drivers/net/can/dev.c | 45 +++++++++++++++++++++++++++++++++++++++-
> include/linux/can/dev.h | 8 +++++++
> include/uapi/linux/can/netlink.h | 1 +
> 3 files changed, 53 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
> index 365a8cc..c5bc33f 100644
> --- a/drivers/net/can/dev.c
> +++ b/drivers/net/can/dev.c
> @@ -27,6 +27,7 @@
> #include <linux/can/skb.h>
> #include <linux/can/netlink.h>
> #include <linux/can/led.h>
> +#include <linux/of.h>
> #include <net/rtnetlink.h>
>
> #define MOD_DESC "CAN device driver interface"
> @@ -814,6 +815,29 @@ int open_candev(struct net_device *dev)
> }
> EXPORT_SYMBOL_GPL(open_candev);
>
> +#ifdef CONFIG_OF
> +/* Common function that can be used to understand the limitation of
> + * a transceiver when it provides no means to determine these limitations
> + * at runtime.
> + */
> +void of_can_transceiver(struct net_device *dev)
> +{
> + struct device_node *dn;
> + struct can_priv *priv = netdev_priv(dev);
> + struct device_node *np = dev->dev.parent->of_node;
> + int ret;
> +
> + dn = of_get_child_by_name(np, "can-transceiver");
> + if (!dn)
> + return;
> +
> + ret = of_property_read_u32(dn, "max-bitrate", &priv->bitrate_max);
> + if ((ret && ret != -EINVAL) || (!ret && !priv->bitrate_max))
> + netdev_warn(dev, "Invalid value for transceiver max bitrate. Ignoring bitrate limit.\n");
> +}
> +EXPORT_SYMBOL_GPL(of_can_transceiver);
> +#endif
> +
> /*
> * Common close function for cleanup before the device gets closed.
> *
> @@ -913,6 +937,13 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],
> priv->bitrate_const_cnt);
> if (err)
> return err;
> +
> + if (priv->bitrate_max && bt.bitrate > priv->bitrate_max) {
> + netdev_err(dev, "arbitration bitrate surpasses transceiver capabilities of %d bps\n",
> + priv->bitrate_max);
> + return -EINVAL;
> + }
> +
> memcpy(&priv->bittiming, &bt, sizeof(bt));
>
> if (priv->do_set_bittiming) {
> @@ -997,6 +1028,13 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],
> priv->data_bitrate_const_cnt);
> if (err)
> return err;
> +
> + if (priv->bitrate_max && dbt.bitrate > priv->bitrate_max) {
> + netdev_err(dev, "canfd data bitrate surpasses transceiver capabilities of %d bps\n",
> + priv->bitrate_max);
> + return -EINVAL;
> + }
> +
> memcpy(&priv->data_bittiming, &dbt, sizeof(dbt));
>
> if (priv->do_set_data_bittiming) {
> @@ -1064,6 +1102,7 @@ static size_t can_get_size(const struct net_device *dev)
> if (priv->data_bitrate_const) /* IFLA_CAN_DATA_BITRATE_CONST */
> size += nla_total_size(sizeof(*priv->data_bitrate_const) *
> priv->data_bitrate_const_cnt);
> + size += sizeof(priv->bitrate_max);
Added "mising" comment: /* IFLA_CAN_BITRATE_MAX */
>
> return size;
> }
> @@ -1121,7 +1160,11 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)
> nla_put(skb, IFLA_CAN_DATA_BITRATE_CONST,
> sizeof(*priv->data_bitrate_const) *
> priv->data_bitrate_const_cnt,
> - priv->data_bitrate_const))
> + priv->data_bitrate_const)) ||
> +
> + (nla_put(skb, IFLA_CAN_BITRATE_MAX,
> + sizeof(priv->bitrate_max),
> + &priv->bitrate_max))
> )
>
> return -EMSGSIZE;
> diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
> index 61f1cf2..a199423 100644
> --- a/include/linux/can/dev.h
> +++ b/include/linux/can/dev.h
> @@ -46,8 +46,10 @@ struct can_priv {
> unsigned int bitrate_const_cnt;
> const u32 *data_bitrate_const;
> unsigned int data_bitrate_const_cnt;
> + u32 bitrate_max;
> struct can_clock clock;
>
> +
I've removed this.
> enum can_state state;
>
> /* CAN controller features - see include/uapi/linux/can/netlink.h */
> @@ -166,6 +168,12 @@ void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
> unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx);
> void can_free_echo_skb(struct net_device *dev, unsigned int idx);
>
> +#ifdef CONFIG_OF
> +void of_can_transceiver(struct net_device *dev);
> +#else
> +static inline void of_can_transceiver(struct net_device *dev) { }
> +#endif
> +
> struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf);
> struct sk_buff *alloc_canfd_skb(struct net_device *dev,
> struct canfd_frame **cfd);
> diff --git a/include/uapi/linux/can/netlink.h b/include/uapi/linux/can/netlink.h
> index 96710e7..9f56fad4 100644
> --- a/include/uapi/linux/can/netlink.h
> +++ b/include/uapi/linux/can/netlink.h
> @@ -132,6 +132,7 @@ enum {
> IFLA_CAN_TERMINATION_CONST,
> IFLA_CAN_BITRATE_CONST,
> IFLA_CAN_DATA_BITRATE_CONST,
> + IFLA_CAN_BITRATE_MAX,
> __IFLA_CAN_MAX
> };
>
>
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: 488 bytes --]
next prev parent reply other threads:[~2018-01-15 13:41 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-10 10:55 [PATCH v7 0/8] Add MCAN Support for Dra76 platform Faiz Abbas
2018-01-10 10:55 ` [PATCH v7 2/8] can: m_can: Add call to of_can_transceiver Faiz Abbas
2018-01-10 10:55 ` [PATCH v7 3/8] can: m_can: Remove check for version when allocating m_can net device Faiz Abbas
2018-01-10 10:55 ` [PATCH v7 4/8] can: m_can: Move allocation of net device to probe Faiz Abbas
[not found] ` <1515581725-29242-5-git-send-email-faiz_abbas-l0cyMroinI0@public.gmane.org>
2018-01-15 13:52 ` Marc Kleine-Budde
2018-01-16 9:03 ` Faiz Abbas
2018-01-10 10:55 ` [PATCH v7 5/8] can: m_can: Add PM Support Faiz Abbas
2018-01-15 13:55 ` Marc Kleine-Budde
2018-01-16 11:05 ` Faiz Abbas
2018-01-10 10:55 ` [PATCH v7 6/8] can: m_can: Support higher speed CAN-FD bitrates Faiz Abbas
2018-01-10 10:55 ` [PATCH v7 7/8] dt-bindings: can: m_can: Document new can transceiver binding Faiz Abbas
2018-01-11 20:20 ` Rob Herring
2018-01-12 6:24 ` Faiz Abbas
2018-01-10 10:55 ` [PATCH v7 8/8] dt-bindings: can: can-transceiver: Document new binding Faiz Abbas
[not found] ` <1515581725-29242-1-git-send-email-faiz_abbas-l0cyMroinI0@public.gmane.org>
2018-01-10 10:55 ` [PATCH v7 1/8] can: dev: Add support for limiting configured bitrate Faiz Abbas
2018-01-15 13:40 ` Marc Kleine-Budde [this message]
2018-01-15 14:44 ` [PATCH v7 0/8] Add MCAN Support for Dra76 platform Marc Kleine-Budde
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=d82752f1-657f-b07e-5d91-b39ea0b6984d@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=Wenyou.Yang@microchip.com \
--cc=b29396@freescale.com \
--cc=devicetree@vger.kernel.org \
--cc=faiz_abbas@ti.com \
--cc=fcooper@ti.com \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=netdev@vger.kernel.org \
--cc=nsekhar@ti.com \
--cc=robh+dt@kernel.org \
--cc=robh@kernel.org \
--cc=sergei.shtylyov@cogentembedded.com \
--cc=wg@grandegger.com \
/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).