netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Mattias Forsblad <mattias.forsblad@gmail.com>
Cc: netdev@vger.kernel.org, Vivien Didelot <vivien.didelot@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Vladimir Oltean <olteanv@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: Re: [PATCH net-next v4 2/6] net: dsa: Add convenience functions for frame handling
Date: Tue, 6 Sep 2022 14:43:48 +0200	[thread overview]
Message-ID: <YxdAhDHy1V22HFw+@lunn.ch> (raw)
In-Reply-To: <20220906063450.3698671-3-mattias.forsblad@gmail.com>

On Tue, Sep 06, 2022 at 08:34:46AM +0200, Mattias Forsblad wrote:
> Add common control functions for drivers that need
> to send and wait for control frames.

It would be nice to explain why a custom complete is needed. Ideally,
it should not be needed at all.

> Signed-off-by: Mattias Forsblad <mattias.forsblad@gmail.com>
> ---
>  include/net/dsa.h | 13 +++++++++++++
>  net/dsa/dsa.c     | 28 ++++++++++++++++++++++++++++
>  net/dsa/dsa2.c    |  2 ++
>  3 files changed, 43 insertions(+)
> 
> diff --git a/include/net/dsa.h b/include/net/dsa.h
> index f2ce12860546..70a358641235 100644
> --- a/include/net/dsa.h
> +++ b/include/net/dsa.h
> @@ -495,6 +495,8 @@ struct dsa_switch {
>  	unsigned int		max_num_bridges;
>  
>  	unsigned int		num_ports;
> +
> +	struct completion	inband_done;
>  };
>  
>  static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
> @@ -1390,6 +1392,17 @@ void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
>  void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
>  				unsigned int count);
>  
> +int dsa_switch_inband_tx(struct dsa_switch *ds, struct sk_buff *skb,
> +			 struct completion *completion, unsigned long timeout);

Blank line please.

> +static inline void dsa_switch_inband_complete(struct dsa_switch *ds, struct completion *completion)
> +{
> +	/* Custom completion? */
> +	if (completion)
> +		complete(completion);
> +	else
> +		complete(&ds->inband_done);
> +}
> +
>  #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count)	\
>  static int __init dsa_tag_driver_module_init(void)			\
>  {									\
> diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
> index be7b320cda76..2d7add779b6f 100644
> --- a/net/dsa/dsa.c
> +++ b/net/dsa/dsa.c
> @@ -324,6 +324,34 @@ int dsa_switch_resume(struct dsa_switch *ds)
>  EXPORT_SYMBOL_GPL(dsa_switch_resume);
>  #endif
>  
> +int dsa_switch_inband_tx(struct dsa_switch *ds, struct sk_buff *skb,
> +			 struct completion *completion, unsigned long timeout)
> +{
> +	int ret;
> +	struct completion *com;

Reverse christmas tree. Longest lines first.

> +
> +	/* Custom completion? */
> +	if (completion)
> +		com = completion;
> +	else
> +		com = &ds->inband_done;
> +
> +	reinit_completion(com);
> +
> +	if (skb)
> +		dev_queue_xmit(skb);
> +
> +	ret = wait_for_completion_timeout(com, msecs_to_jiffies(timeout));
> +	if (ret <= 0) {
> +		dev_dbg(ds->dev, "DSA inband: timeout waiting for answer\n");
> +
> +		return -ETIMEDOUT;
> +	}

It looks like wait_for_completion_timeout() can return a negative
error code. You should return that error code, not replace it with
-ETIMEDOUT. If it returns 0, then it has timed out, and returning
-ETIMEDOUT does make sense. If the completion is indicated before the
timeout, the return value is the remaining time. So you can return a
positive number here. It is worth documenting that, since a common
patterns is:

	err = dsa_switch_inband_tx()
	if (err)
		return err;

does not work in this case.

     Andrew

  reply	other threads:[~2022-09-06 12:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-06  6:34 [PATCH net-next v4 0/6] net: dsa: mv88e6xxx: qca8k: rmon: Add RMU support Mattias Forsblad
2022-09-06  6:34 ` [PATCH net-next v4 1/6] net: dsa: mv88e6xxx: Add RMU enable for select switches Mattias Forsblad
2022-09-06 12:29   ` Andrew Lunn
2022-09-07  5:55     ` Mattias Forsblad
2022-09-06 21:46   ` Florian Fainelli
2022-09-07  6:29     ` Mattias Forsblad
2022-09-06  6:34 ` [PATCH net-next v4 2/6] net: dsa: Add convenience functions for frame handling Mattias Forsblad
2022-09-06 12:43   ` Andrew Lunn [this message]
2022-09-07  6:19     ` Mattias Forsblad
2022-09-06 21:44   ` Florian Fainelli
2022-09-08 11:32   ` Paolo Abeni
2022-09-06  6:34 ` [PATCH net-next v4 3/6] net: dsa: Introduce dsa tagger data operation Mattias Forsblad
2022-09-06 13:08   ` Andrew Lunn
2022-09-06 13:51     ` Vladimir Oltean
2022-09-06  6:34 ` [PATCH net-next v4 4/6] net: dsa: mv88e6xxxx: Add RMU functionality Mattias Forsblad
2022-09-06  6:34 ` [PATCH net-next v4 5/6] net: dsa: mv88e6xxx: rmon: Use RMU for reading RMON data Mattias Forsblad
2022-09-06  6:34 ` [PATCH net-next v4 6/6] net: dsa: qca8k: Use new convenience functions Mattias Forsblad
2022-09-06  8:07 ` [PATCH net-next v4 0/6] net: dsa: mv88e6xxx: qca8k: rmon: Add RMU support Marek Behún
2022-09-06  9:45   ` Mattias Forsblad

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=YxdAhDHy1V22HFw+@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=mattias.forsblad@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=vivien.didelot@gmail.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).