Linux-Can Archive mirror
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Christoph Fritz <christoph.fritz@hexdev.de>
Cc: Jiri Slaby <jirislaby@kernel.org>,
	Simon Horman <horms@kernel.org>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Marc Kleine-Budde <mkl@pengutronix.de>,
	 Oliver Hartkopp <socketcan@hartkopp.net>,
	 Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
	 "David S . Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>, Rob Herring <robh@kernel.org>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	Jiri Kosina <jikos@kernel.org>,
	 Benjamin Tissoires <bentiss@kernel.org>,
	 Sebastian Reichel <sre@kernel.org>,
	 Linus Walleij <linus.walleij@linaro.org>,
	 Andreas Lauser <andreas.lauser@mercedes-benz.com>,
	 Jonathan Corbet <corbet@lwn.net>,
	Pavel Pisa <pisa@cmp.felk.cvut.cz>,
	 linux-can@vger.kernel.org, Netdev <netdev@vger.kernel.org>,
	 devicetree@vger.kernel.org, linux-input@vger.kernel.org,
	 linux-serial <linux-serial@vger.kernel.org>
Subject: Re: [PATCH v4 10/11] can: lin: Support setting LIN mode
Date: Fri, 10 May 2024 17:39:14 +0300 (EEST)	[thread overview]
Message-ID: <b796b3ac-df5e-e39a-7ae2-db7b7829abaa@linux.intel.com> (raw)
In-Reply-To: <20240509171736.2048414-11-christoph.fritz@hexdev.de>

On Thu, 9 May 2024, Christoph Fritz wrote:

> A LIN node can work as commander or responder, so introduce a new
> control mode (CAN_CTRLMODE_LIN_COMMANDER) for configuration.
> 
> This enables e.g. the userland tool ip from iproute2 to turn on
> commander mode when the device is being brought up.
> 
> Signed-off-by: Christoph Fritz <christoph.fritz@hexdev.de>
> ---
>  drivers/net/can/lin.c            | 40 +++++++++++++++++++++++++++++++-
>  include/net/lin.h                |  7 ++++++
>  include/uapi/linux/can/netlink.h |  1 +
>  3 files changed, 47 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/can/lin.c b/drivers/net/can/lin.c
> index f77abd7d7d21c..03ddf5d5a31b8 100644
> --- a/drivers/net/can/lin.c
> +++ b/drivers/net/can/lin.c
> @@ -262,11 +262,40 @@ static netdev_tx_t lin_start_xmit(struct sk_buff *skb,
>  	return NETDEV_TX_OK;
>  }
>  
> +static int lin_update_mode(struct net_device *ndev)
> +{
> +	struct lin_device *ldev = netdev_priv(ndev);
> +	u32 ctrlmode = ldev->can.ctrlmode;
> +	enum lin_mode lm;
> +	int ret = 0;
> +
> +	lm = (ctrlmode & CAN_CTRLMODE_LIN_COMMANDER) ? LINBUS_COMMANDER :
> +						       LINBUS_RESPONDER;
> +	if (ldev->lmode != lm) {
> +		if (!ldev->ldev_ops->update_lin_mode) {
> +			netdev_err(ndev, "setting lin mode unsupported\n");

In user visible messages, it would be best to use the expected 
capitalization, which I suppose is LIN given you use capitals in the 
commit message yourself?

> +			return -EINVAL;
> +		}
> +		ret = ldev->ldev_ops->update_lin_mode(ldev, lm);
> +		if (ret) {
> +			netdev_err(ndev, "Failed to set lin mode: %d\n", ret);

Ditto.

There might be other cases in any of the patches, please check.

> +			return ret;
> +		}
> +		ldev->lmode = lm;
> +	}
> +
> +	return ret;
> +}
> +
>  static int lin_open(struct net_device *ndev)
>  {
>  	struct lin_device *ldev = netdev_priv(ndev);
>  	int ret;
>  
> +	ret = lin_update_mode(ndev);
> +	if (ret)
> +		return ret;
> +
>  	ldev->tx_busy = false;
>  
>  	ret = open_candev(ndev);
> @@ -443,7 +472,7 @@ struct lin_device *register_lin(struct device *dev,
>  	ndev->sysfs_groups[0] = &lin_sysfs_group;
>  	ldev->can.bittiming.bitrate = LIN_DEFAULT_BAUDRATE;
>  	ldev->can.ctrlmode = CAN_CTRLMODE_LIN;
> -	ldev->can.ctrlmode_supported = 0;
> +	ldev->can.ctrlmode_supported = CAN_CTRLMODE_LIN_COMMANDER;
>  	ldev->can.bitrate_const = lin_bitrate;
>  	ldev->can.bitrate_const_cnt = ARRAY_SIZE(lin_bitrate);
>  	ldev->can.do_set_bittiming = lin_set_bittiming;
> @@ -458,6 +487,15 @@ struct lin_device *register_lin(struct device *dev,
>  		goto exit_candev;
>  	}
>  
> +	ldev->lmode = LINBUS_RESPONDER;
> +	if (ldev->ldev_ops->update_lin_mode) {
> +		ret = ldev->ldev_ops->update_lin_mode(ldev, ldev->lmode);
> +		if (ret) {
> +			netdev_err(ndev, "updating lin mode failed\n");

Ditto.

> +			goto exit_candev;
> +		}
> +	}
> +
>  	ret = register_candev(ndev);
>  	if (ret)
>  		goto exit_candev;
> diff --git a/include/net/lin.h b/include/net/lin.h
> index 31bb0feefd188..63ac870a0ab6f 100644
> --- a/include/net/lin.h
> +++ b/include/net/lin.h
> @@ -36,6 +36,11 @@ struct lin_attr {
>  	struct lin_device *ldev;
>  };
>  
> +enum lin_mode {
> +	LINBUS_RESPONDER = 0,
> +	LINBUS_COMMANDER,
> +};
> +
>  struct lin_device {
>  	struct can_priv can;  /* must be the first member */
>  	struct net_device *ndev;
> @@ -45,6 +50,7 @@ struct lin_device {
>  	struct work_struct tx_work;
>  	bool tx_busy;
>  	struct sk_buff *tx_skb;
> +	enum lin_mode lmode;
>  };
>  
>  enum lin_checksum_mode {
> @@ -71,6 +77,7 @@ struct lin_device_ops {
>  	int (*ldo_open)(struct lin_device *ldev);
>  	int (*ldo_stop)(struct lin_device *ldev);
>  	int (*ldo_tx)(struct lin_device *ldev, const struct lin_frame *frame);
> +	int (*update_lin_mode)(struct lin_device *ldev, enum lin_mode lm);
>  	int (*update_bitrate)(struct lin_device *ldev, u16 bitrate);
>  	int (*update_responder_answer)(struct lin_device *ldev,
>  				       const struct lin_responder_answer *answ);
> diff --git a/include/uapi/linux/can/netlink.h b/include/uapi/linux/can/netlink.h
> index a37f56d86c5f2..cc390f6444d59 100644
> --- a/include/uapi/linux/can/netlink.h
> +++ b/include/uapi/linux/can/netlink.h
> @@ -104,6 +104,7 @@ struct can_ctrlmode {
>  #define CAN_CTRLMODE_TDC_AUTO		0x200	/* CAN transiver automatically calculates TDCV */
>  #define CAN_CTRLMODE_TDC_MANUAL		0x400	/* TDCV is manually set up by user */
>  #define CAN_CTRLMODE_LIN		BIT(11)	/* LIN bus mode */
> +#define CAN_CTRLMODE_LIN_COMMANDER	BIT(12)	/* LIN bus specific commander mode */
>  
>  /*
>   * CAN device statistics
> 

-- 
 i.


  reply	other threads:[~2024-05-10 14:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-09 17:17 [PATCH v4 00/11] LIN Bus support for Linux Christoph Fritz
2024-05-09 17:17 ` [PATCH v4 01/11] can: Add LIN bus as CAN abstraction Christoph Fritz
2024-05-10 13:23   ` Ilpo Järvinen
2024-05-13  9:52   ` Simon Horman
2024-05-09 17:17 ` [PATCH v4 02/11] HID: hexLIN: Add support for USB LIN adapter Christoph Fritz
2024-05-10 13:46   ` Ilpo Järvinen
2024-05-11  8:14     ` Christoph Fritz
2024-05-13 12:27       ` Ilpo Järvinen
2024-05-13  5:26     ` Jiri Slaby
2024-05-09 17:17 ` [PATCH v4 03/11] treewide, serdev: add flags argument to receive_buf() Christoph Fritz
2024-05-10 14:11   ` Ilpo Järvinen
2024-05-09 17:17 ` [PATCH v4 04/11] tty: serdev: Add method to enable break flags Christoph Fritz
2024-05-10 14:21   ` Ilpo Järvinen
2024-05-12 13:08     ` Christoph Fritz
2024-05-13 12:30       ` Ilpo Järvinen
2024-05-09 17:17 ` [PATCH v4 05/11] dt-bindings: vendor-prefixes: Add hexDEV Christoph Fritz
2024-05-09 17:17 ` [PATCH v4 06/11] dt-bindings: net/can: Add serial LIN adapter hexLINSER Christoph Fritz
2024-05-09 18:09   ` Conor Dooley
2024-05-09 17:17 ` [PATCH v4 07/11] can: Add support for hexDEV " Christoph Fritz
2024-05-10 14:32   ` Ilpo Järvinen
2024-05-09 17:17 ` [PATCH v4 08/11] can: bcm: Add LIN answer offloading for responder mode Christoph Fritz
2024-05-09 17:17 ` [PATCH v4 09/11] can: lin: Handle rx offload config frames Christoph Fritz
2024-05-10 14:36   ` Ilpo Järvinen
2024-05-09 17:17 ` [PATCH v4 10/11] can: lin: Support setting LIN mode Christoph Fritz
2024-05-10 14:39   ` Ilpo Järvinen [this message]
2024-05-09 17:17 ` [PATCH v4 11/11] HID: hexLIN: Implement ability to update lin mode Christoph Fritz
2024-05-18 18:29 ` [PATCH v4 00/11] LIN Bus support for Linux Christoph Fritz

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=b796b3ac-df5e-e39a-7ae2-db7b7829abaa@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=andreas.lauser@mercedes-benz.com \
    --cc=bentiss@kernel.org \
    --cc=christoph.fritz@hexdev.de \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=horms@kernel.org \
    --cc=jikos@kernel.org \
    --cc=jirislaby@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pisa@cmp.felk.cvut.cz \
    --cc=robh@kernel.org \
    --cc=socketcan@hartkopp.net \
    --cc=sre@kernel.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).