[RFC,5/5] can: slcan: send the listen-only command to the adapter

Message ID 20220716170007.2020037-6-dario.binacchi@amarulasolutions.com
State New
Headers show
Series
  • can: slcan: extend supported features (step 2)
Related show

Commit Message

Dario Binacchi July 16, 2022, 5 p.m. UTC
In case the bitrate has been set via ip tool, this patch changes the
driver to send the listen-only ("L\r") command to the adapter.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>

---

 drivers/net/can/slcan/slcan-core.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

Comments

Marc Kleine-Budde July 18, 2022, 10:22 a.m. UTC | #1
The subject can be enhanced, as the listen-only command ist not send
unconditionally. What about: "add support for listen-only mode"?

On 16.07.2022 19:00:07, Dario Binacchi wrote:
> In case the bitrate has been set via ip tool, this patch changes the
> driver to send the listen-only ("L\r") command to the adapter.

...but only of CAN_CTRLMODE_LISTENONLY is requested.

What about:

For non-legacy, i.e. ip based configuration, add support for listen-only
mode. If listen-only is requested send a listen-only ("L\r") command
instead of an open ("O\r") command to the adapter..

> 
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> 
> ---
> 
>  drivers/net/can/slcan/slcan-core.c | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c
> index 7a1540507ecd..d97dfeccbf9c 100644
> --- a/drivers/net/can/slcan/slcan-core.c
> +++ b/drivers/net/can/slcan/slcan-core.c
> @@ -711,10 +711,21 @@ static int slcan_netdev_open(struct net_device *dev)
>  			}
>  		}
>  
> -		err = slcan_transmit_cmd(sl, "O\r");
> -		if (err) {
> -			netdev_err(dev, "failed to send open command 'O\\r'\n");
> -			goto cmd_transmit_failed;
> +		/* listen-only command overrides open command */

I think this comment can be removed.

> +		if (sl->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) {
> +			err = slcan_transmit_cmd(sl, "L\r");
> +			if (err) {
> +				netdev_err(dev,
> +					   "failed to send listen-only command 'L\\r'\n");
> +				goto cmd_transmit_failed;
> +			}
> +		} else {
> +			err = slcan_transmit_cmd(sl, "O\r");
> +			if (err) {
> +				netdev_err(dev,
> +					   "failed to send open command 'O\\r'\n");
> +				goto cmd_transmit_failed;
> +			}
>  		}
>  	}
>  
> @@ -801,6 +812,7 @@ static int slcan_open(struct tty_struct *tty)
>  	/* Configure CAN metadata */
>  	sl->can.bitrate_const = slcan_bitrate_const;
>  	sl->can.bitrate_const_cnt = ARRAY_SIZE(slcan_bitrate_const);
> +	sl->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY;
>  
>  	/* Configure netdev interface */
>  	sl->dev	= dev;

Marc
Dario Binacchi July 21, 2022, 8:17 a.m. UTC | #2
Hello Marc,

On Mon, Jul 18, 2022 at 12:22 PM Marc Kleine-Budde <mkl@pengutronix.de> wrote:
>
> The subject can be enhanced, as the listen-only command ist not send
> unconditionally. What about: "add support for listen-only mode"?

I like it.

>
> On 16.07.2022 19:00:07, Dario Binacchi wrote:
> > In case the bitrate has been set via ip tool, this patch changes the
> > driver to send the listen-only ("L\r") command to the adapter.
>
> ...but only of CAN_CTRLMODE_LISTENONLY is requested.
>
> What about:
>
> For non-legacy, i.e. ip based configuration, add support for listen-only
> mode. If listen-only is requested send a listen-only ("L\r") command
> instead of an open ("O\r") command to the adapter..

I agree with you. It's definitely clearer.

Thanks and regards,
Dario
>
> >
> > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> >
> > ---
> >
> >  drivers/net/can/slcan/slcan-core.c | 20 ++++++++++++++++----
> >  1 file changed, 16 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c
> > index 7a1540507ecd..d97dfeccbf9c 100644
> > --- a/drivers/net/can/slcan/slcan-core.c
> > +++ b/drivers/net/can/slcan/slcan-core.c
> > @@ -711,10 +711,21 @@ static int slcan_netdev_open(struct net_device *dev)
> >                       }
> >               }
> >
> > -             err = slcan_transmit_cmd(sl, "O\r");
> > -             if (err) {
> > -                     netdev_err(dev, "failed to send open command 'O\\r'\n");
> > -                     goto cmd_transmit_failed;
> > +             /* listen-only command overrides open command */
>
> I think this comment can be removed.
>
> > +             if (sl->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) {
> > +                     err = slcan_transmit_cmd(sl, "L\r");
> > +                     if (err) {
> > +                             netdev_err(dev,
> > +                                        "failed to send listen-only command 'L\\r'\n");
> > +                             goto cmd_transmit_failed;
> > +                     }
> > +             } else {
> > +                     err = slcan_transmit_cmd(sl, "O\r");
> > +                     if (err) {
> > +                             netdev_err(dev,
> > +                                        "failed to send open command 'O\\r'\n");
> > +                             goto cmd_transmit_failed;
> > +                     }
> >               }
> >       }
> >
> > @@ -801,6 +812,7 @@ static int slcan_open(struct tty_struct *tty)
> >       /* Configure CAN metadata */
> >       sl->can.bitrate_const = slcan_bitrate_const;
> >       sl->can.bitrate_const_cnt = ARRAY_SIZE(slcan_bitrate_const);
> > +     sl->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY;
> >
> >       /* Configure netdev interface */
> >       sl->dev = dev;
>
> Marc
>
> --
> Pengutronix e.K.                 | Marc Kleine-Budde           |
> Embedded Linux                   | https://www.pengutronix.de  |
> Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
> Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

Patch

diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c
index 7a1540507ecd..d97dfeccbf9c 100644
--- a/drivers/net/can/slcan/slcan-core.c
+++ b/drivers/net/can/slcan/slcan-core.c
@@ -711,10 +711,21 @@  static int slcan_netdev_open(struct net_device *dev)
 			}
 		}
 
-		err = slcan_transmit_cmd(sl, "O\r");
-		if (err) {
-			netdev_err(dev, "failed to send open command 'O\\r'\n");
-			goto cmd_transmit_failed;
+		/* listen-only command overrides open command */
+		if (sl->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) {
+			err = slcan_transmit_cmd(sl, "L\r");
+			if (err) {
+				netdev_err(dev,
+					   "failed to send listen-only command 'L\\r'\n");
+				goto cmd_transmit_failed;
+			}
+		} else {
+			err = slcan_transmit_cmd(sl, "O\r");
+			if (err) {
+				netdev_err(dev,
+					   "failed to send open command 'O\\r'\n");
+				goto cmd_transmit_failed;
+			}
 		}
 	}
 
@@ -801,6 +812,7 @@  static int slcan_open(struct tty_struct *tty)
 	/* Configure CAN metadata */
 	sl->can.bitrate_const = slcan_bitrate_const;
 	sl->can.bitrate_const_cnt = ARRAY_SIZE(slcan_bitrate_const);
+	sl->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY;
 
 	/* Configure netdev interface */
 	sl->dev	= dev;