Linux-Serial Archive mirror
 help / color / mirror / Atom feed
From: Christoph Fritz <christoph.fritz@hexdev.de>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Jiri Slaby <jirislaby@kernel.org>,
	Oliver Hartkopp <socketcan@hartkopp.net>,
	 Marc Kleine-Budde <mkl@pengutronix.de>,
	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>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.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 v3 08/11] can: bcm: Add LIN answer offloading for responder mode
Date: Thu, 09 May 2024 19:06:58 +0200	[thread overview]
Message-ID: <e3423e336eceaae2365af9583ee368337272868e.camel@hexdev.de> (raw)
In-Reply-To: <48a79803-0fc9-3931-08f1-4b26b4a9ae93@linux.intel.com>

On Mon, 2024-05-06 at 20:08 +0300, Ilpo Järvinen wrote:
> On Thu, 2 May 2024, Christoph Fritz wrote:
> 
> > Enhance CAN broadcast manager with RX_LIN_SETUP and RX_LIN_DELETE
> > operations to setup automatic LIN frame responses in responder mode.
> > 
> > Additionally, the patch introduces the LIN_EVENT_FRAME flag to
> > setup event-triggered LIN frames.
> > 
> > Signed-off-by: Christoph Fritz <christoph.fritz@hexdev.de>
> > ---
> >  include/uapi/linux/can/bcm.h |  5 ++-
> >  net/can/bcm.c                | 74 +++++++++++++++++++++++++++++++++++-
> >  2 files changed, 77 insertions(+), 2 deletions(-)
> > 
> > diff --git a/include/uapi/linux/can/bcm.h b/include/uapi/linux/can/bcm.h
> > index f1e45f533a72c..c46268a114078 100644
> > --- a/include/uapi/linux/can/bcm.h
> > +++ b/include/uapi/linux/can/bcm.h
> > @@ -86,7 +86,9 @@ enum {
> >  	TX_EXPIRED,	/* notification on performed transmissions (count=0) */
> >  	RX_STATUS,	/* reply to RX_READ request */
> >  	RX_TIMEOUT,	/* cyclic message is absent */
> > -	RX_CHANGED	/* updated CAN frame (detected content change) */
> > +	RX_CHANGED,	/* updated CAN frame (detected content change) */
> > +	RX_LIN_SETUP,	/* create auto-response for LIN frame */
> > +	RX_LIN_DELETE,  /* remove auto-response for LIN frame */
> >  };
> >  
> >  #define SETTIMER            0x0001
> > @@ -101,5 +103,6 @@ enum {
> >  #define TX_RESET_MULTI_IDX  0x0200
> >  #define RX_RTR_FRAME        0x0400
> >  #define CAN_FD_FRAME        0x0800
> > +#define LIN_EVENT_FRAME     0x1000
> >  
> >  #endif /* !_UAPI_CAN_BCM_H */
> > diff --git a/net/can/bcm.c b/net/can/bcm.c
> > index 27d5fcf0eac9d..a717e594234d1 100644
> > --- a/net/can/bcm.c
> > +++ b/net/can/bcm.c
> > @@ -59,6 +59,7 @@
> >  #include <linux/can/bcm.h>
> >  #include <linux/slab.h>
> >  #include <net/sock.h>
> > +#include <net/lin.h>
> >  #include <net/net_namespace.h>
> >  
> >  /*
> > @@ -1330,6 +1331,59 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk,
> >  	return cfsiz + MHSIZ;
> >  }
> >  
> > +static int bcm_lin_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
> > +			 int ifindex, struct sock *sk, int cfsiz, int is_active)
> > +{
> > +	struct lin_responder_answer answ;
> > +	struct net_device *dev;
> > +	struct sk_buff *skb;
> > +	struct canfd_frame cf;
> > +	netdevice_tracker tracker;
> > +	size_t sz;
> > +	int ret;
> > +
> > +	if (msg_head->nframes > 1)
> > +		return -EINVAL;
> > +
> > +	if (!(msg_head->flags & CAN_FD_FRAME))
> > +		return -EINVAL;
> > +
> > +	ret = memcpy_from_msg(&cf, msg, cfsiz);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	answ.lf.lin_id = cf.can_id & LIN_ID_MASK;
> > +	answ.is_active = is_active;
> > +	answ.is_event_frame = !!(msg_head->flags & LIN_EVENT_FRAME);
> > +	answ.event_associated_id = msg_head->can_id;
> > +	answ.lf.len = min(cf.len, LIN_MAX_DLEN);
> > +	memcpy(answ.lf.data, cf.data, answ.lf.len);
> > +	sz = min(sizeof(struct lin_responder_answer), sizeof(cf.data));
> > +	cf.can_id |= LIN_RXOFFLOAD_DATA_FLAG;
> > +	memcpy(cf.data, &answ, sz);
> > +
> > +	dev = netdev_get_by_index(sock_net(sk), ifindex, &tracker, GFP_KERNEL);
> > +	if (!dev)
> > +		return -ENODEV;
> > +
> > +	skb = alloc_skb(cfsiz + sizeof(struct can_skb_priv), gfp_any());
> 
> You just called the other function with GFP_KERNEL and you now need 
> gfp_any(). Which is correct??

I guess GFP_KERNEL but I'm not sure so I'll let gfp_any() decide for
netdev_get_by_index() too.

> 
> > +	if (!skb)
> > +		goto lin_out;
> > +
> > +	can_skb_reserve(skb);
> > +	can_skb_prv(skb)->ifindex = dev->ifindex;
> > +	can_skb_prv(skb)->skbcnt = 0;
> > +	skb_put_data(skb, &cf, cfsiz);
> > +
> > +	skb->dev = dev;
> > +	can_skb_set_owner(skb, sk);
> > +	ret = can_send(skb, 1); /* send with loopback */
> > +
> > +lin_out:
> > +	netdev_put(dev, &tracker);
> > +	return ret;
> > +}
> > +
> >  /*
> >   * bcm_sendmsg - process BCM commands (opcodes) from the userspace
> >   */
> > @@ -1429,12 +1483,30 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
> >  
> >  	case TX_SEND:
> >  		/* we need exactly one CAN frame behind the msg head */
> > -		if ((msg_head.nframes != 1) || (size != cfsiz + MHSIZ))
> > +		if (msg_head.nframes != 1 || size != cfsiz + MHSIZ)
> 
> Unrelated style fix, doesn't belong to this patch.

OK

...

thanks
  -- Christoph


  reply	other threads:[~2024-05-09 17:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02 18:27 [PATCH v3 00/11] LIN Bus support for Linux Christoph Fritz
2024-05-02 18:27 ` [PATCH v3 01/11] can: Add LIN bus as CAN abstraction Christoph Fritz
2024-05-06 16:24   ` Ilpo Järvinen
2024-05-08 12:47     ` Christoph Fritz
2024-05-08 13:08       ` Ilpo Järvinen
2024-05-08 18:20         ` Christoph Fritz
2024-05-08 18:48           ` Greg Kroah-Hartman
2024-05-09 17:06             ` Christoph Fritz
2024-05-02 18:27 ` [PATCH v3 02/11] HID: hexLIN: Add support for USB LIN bus adapter Christoph Fritz
2024-05-06 16:53   ` Ilpo Järvinen
2024-05-09 17:06     ` Christoph Fritz
2024-05-10  9:31       ` Ilpo Järvinen
2024-05-02 18:27 ` [PATCH v3 03/11] tty: serdev: Add flag buffer aware receive_buf_fp() Christoph Fritz
2024-05-04 16:00   ` Greg Kroah-Hartman
2024-05-08  8:48     ` Christoph Fritz
2024-05-02 18:27 ` [PATCH v3 04/11] tty: serdev: Add method to enable break flags Christoph Fritz
2024-05-02 18:27 ` [PATCH v3 05/11] dt-bindings: vendor-prefixes: Add hexDEV Christoph Fritz
2024-05-02 18:27 ` [PATCH v3 06/11] dt-bindings: net/can: Add serial (serdev) LIN adapter Christoph Fritz
2024-05-03 17:12   ` Conor Dooley
2024-05-03 18:29     ` Christoph Fritz
2024-05-06 16:16       ` Conor Dooley
2024-05-06 18:50         ` Krzysztof Kozlowski
2024-05-08 11:34           ` Christoph Fritz
2024-05-08 16:16             ` Conor Dooley
2024-05-02 18:28 ` [PATCH v3 07/11] can: Add support for serdev LIN adapters Christoph Fritz
2024-05-06 17:03   ` Ilpo Järvinen
2024-05-09 17:06     ` Christoph Fritz
2024-05-02 18:28 ` [PATCH v3 08/11] can: bcm: Add LIN answer offloading for responder mode Christoph Fritz
2024-05-06 17:08   ` Ilpo Järvinen
2024-05-09 17:06     ` Christoph Fritz [this message]
2024-05-02 18:28 ` [PATCH v3 09/11] can: lin: Handle rx offload config frames Christoph Fritz
2024-05-06 17:11   ` Ilpo Järvinen
2024-05-09 17:07     ` Christoph Fritz
2024-05-02 18:28 ` [PATCH v3 10/11] can: lin: Support setting LIN mode Christoph Fritz
2024-05-02 18:28 ` [PATCH v3 11/11] HID: hexLIN: Implement ability to update lin mode 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=e3423e336eceaae2365af9583ee368337272868e.camel@hexdev.de \
    --to=christoph.fritz@hexdev.de \
    --cc=andreas.lauser@mercedes-benz.com \
    --cc=bentiss@kernel.org \
    --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=ilpo.jarvinen@linux.intel.com \
    --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).