netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: Simon Horman <simon.horman@netronome.com>
Cc: David Miller <davem@davemloft.net>,
	netdev@vger.kernel.org, oss-drivers@netronome.com,
	Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com>
Subject: Re: [PATCH net-next v2 7/9] nfp: add metadata to each flow offload
Date: Wed, 28 Jun 2017 19:33:02 -0700	[thread overview]
Message-ID: <20170628193302.555537c1@cakuba.netronome.com> (raw)
In-Reply-To: <1498681802-2897-8-git-send-email-simon.horman@netronome.com>

On Wed, 28 Jun 2017 22:30:00 +0200, Simon Horman wrote:
> From: Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com>
> 
> Adds metadata describing the mask id of each flow and keeps track of
> flows installed in hardware. Previously a flow could not be removed
> from hardware as there was no way of knowing if that a specific flow
> was installed. This is solved by storing the offloaded flows in a
> hash table.
> 
> Signed-off-by: Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com>
> Signed-off-by: Simon Horman <simon.horman@netronome.com>

> diff --git a/drivers/net/ethernet/netronome/nfp/flower/main.c b/drivers/net/ethernet/netronome/nfp/flower/main.c
> index 19f20f819e2f..1103d23a8ec7 100644
> --- a/drivers/net/ethernet/netronome/nfp/flower/main.c
> +++ b/drivers/net/ethernet/netronome/nfp/flower/main.c
> @@ -50,14 +50,6 @@
>  
>  #define NFP_FLOWER_ALLOWED_VER 0x0001000000010000UL
>  
> -/**
> - * struct nfp_flower_priv - Flower APP per-vNIC priv data
> - * @nn:		     Pointer to vNIC
> - */
> -struct nfp_flower_priv {
> -	struct nfp_net *nn;
> -};
> -
>  static const char *nfp_flower_extra_cap(struct nfp_app *app, struct nfp_net *nn)
>  {
>  	return "FLOWER";
> @@ -351,6 +343,12 @@ static int nfp_flower_init(struct nfp_app *app)
>  	if (!app->priv)
>  		return -ENOMEM;
>  
> +	err = nfp_flower_metadata_init(app);
> +	if (nfp_flower_metadata_init(app)) {

You're calling init twice here.  Also please do the error path with
goto, as explained in review of patch 8 having a proper unwind makes
later patches easier to review.

> +		kfree(app->priv);
> +		return err;
> +	}
> +
>  	return 0;
>  }
>  

> +static int nfp_mask_alloc(struct nfp_app *app, u8 *mask_id)
> +{
> +	struct nfp_flower_priv *priv = app->priv;
> +	struct timespec64 delta, now;
> +	struct circ_buf *ring;
> +	u8 temp_id, freed_id;
> +
> +	ring = &priv->mask_ids.mask_id_free_list;
> +	freed_id = NFP_FLOWER_MASK_ENTRY_RS - 1;
> +	/* Checking for unallocated entries first. */
> +	if (priv->mask_ids.init_unallocated > 0) {
> +		*mask_id = priv->mask_ids.init_unallocated;
> +		priv->mask_ids.init_unallocated--;
> +		return 0;
> +	}
> +
> +	/* Checking if buffer is empty. */
> +	if (ring->head == ring->tail) {
> +		*mask_id = freed_id;
> +		return -ENOENT;
> +	}
> +
> +	memcpy(&temp_id, &ring->buf[ring->tail], NFP_FLOWER_MASK_ELEMENT_RS);
> +	*mask_id = temp_id;
> +	memcpy(&ring->buf[ring->tail], &freed_id, NFP_FLOWER_MASK_ELEMENT_RS);
> +	ring->tail = (ring->tail + NFP_FLOWER_MASK_ELEMENT_RS) %
> +		     (NFP_FLOWER_MASK_ENTRY_RS * NFP_FLOWER_MASK_ELEMENT_RS);
> +
> +	getnstimeofday64(&now);
> +	delta = timespec64_sub(now, priv->mask_ids.last_used[*mask_id]);
> +
> +	if (timespec64_to_ns(&delta) < NFP_FL_MASK_REUSE_TIME_NS) {
> +		nfp_release_mask_id(app, *mask_id);

nfp_release_mask_id() will reset the time stamp and put the mask at the
end of the queue.  Is that OK?

> +		return -ENOENT;
> +	}
> +
> +	return 0;
> +}
> +

> +int nfp_flower_metadata_init(struct nfp_app *app)
> +{
> +	struct nfp_flower_priv *priv = app->priv;
> +
> +	hash_init(priv->mask_table);
> +	hash_init(priv->flow_table);
> +
> +	/* Init ring buffer and unallocated mask_ids. */
> +	priv->mask_ids.mask_id_free_list.buf =
> +		kmalloc(NFP_FLOWER_MASK_ENTRY_RS * NFP_FLOWER_MASK_ELEMENT_RS,
> +			GFP_KERNEL);

kmalloc_array, perhaps?  

> +	if (!priv->mask_ids.mask_id_free_list.buf)
> +		return -ENOMEM;
> +
> +	priv->mask_ids.init_unallocated = NFP_FLOWER_MASK_ENTRY_RS - 1;
> +
> +	/* Init timestamps for mask id*/
> +	priv->mask_ids.last_used =
> +		kmalloc_array(NFP_FLOWER_MASK_ENTRY_RS,
> +			      sizeof(*priv->mask_ids.last_used), GFP_KERNEL);
> +	if (!priv->mask_ids.last_used) {
> +		kfree(priv->mask_ids.mask_id_free_list.buf);
> +		return -ENOMEM;
> +	}
> +
> +	return 0;
> +}

  reply	other threads:[~2017-06-29  2:33 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-28 20:29 [PATCH net-next v2 0/9] introduce flower offload capabilities Simon Horman
2017-06-28 20:29 ` [PATCH net-next v2 1/9] net: switchdev: add SET_SWITCHDEV_OPS helper Simon Horman
2017-06-28 20:29 ` [PATCH net-next v2 2/9] nfp: add phys_switch_id support Simon Horman
2017-06-28 20:29 ` [PATCH net-next v2 3/9] nfp: provide infrastructure for offloading flower based TC filters Simon Horman
2017-06-29  1:35   ` Jakub Kicinski
2017-06-29  5:41     ` Simon Horman
2017-06-29  1:53   ` Jakub Kicinski
2017-06-29  8:16     ` Simon Horman
2017-06-29 13:56   ` Or Gerlitz
2017-06-29 14:31     ` Simon Horman
2017-06-28 20:29 ` [PATCH net-next v2 4/9] nfp: extend flower add flow offload Simon Horman
2017-06-29  6:18   ` Yunsheng Lin
2017-06-29  6:48     ` Jakub Kicinski
2017-06-29 13:47       ` David Laight
2017-06-28 20:29 ` [PATCH net-next v2 5/9] nfp: extend flower matching capabilities Simon Horman
2017-06-29 14:31   ` Or Gerlitz
2017-06-29 15:01     ` Simon Horman
2017-06-29 14:33   ` Or Gerlitz
2017-06-29 15:00     ` Simon Horman
2017-06-28 20:29 ` [PATCH net-next v2 6/9] nfp: add basic action capabilities to flower offloads Simon Horman
2017-06-28 20:30 ` [PATCH net-next v2 7/9] nfp: add metadata to each flow offload Simon Horman
2017-06-29  2:33   ` Jakub Kicinski [this message]
2017-06-29  8:14     ` [oss-drivers] " Simon Horman
2017-06-29  8:42       ` Jakub Kicinski
2017-06-29 11:22         ` Simon Horman
2017-06-28 20:30 ` [PATCH net-next v2 8/9] nfp: add a stats handler for flower offloads Simon Horman
2017-06-29  1:28   ` Jakub Kicinski
2017-06-29  8:14     ` [oss-drivers] " Simon Horman
2017-06-29  2:55   ` Jakub Kicinski
2017-06-29  8:15     ` [oss-drivers] " Simon Horman
2017-06-29 14:39   ` Or Gerlitz
2017-06-29 14:53     ` Simon Horman
2017-06-29 15:16   ` Or Gerlitz
2017-06-29 15:27     ` Simon Horman
2017-06-28 20:30 ` [PATCH net-next v2 9/9] nfp: add control message passing capabilities to " Simon Horman
2017-06-29 13:46   ` Or Gerlitz
2017-06-29 14:45     ` David Laight
2017-06-29 15:21   ` Or Gerlitz
2017-06-29 15:30     ` Simon Horman
2017-06-29 15:59       ` Or Gerlitz
2017-06-29 17:35         ` Simon Horman

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=20170628193302.555537c1@cakuba.netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    --cc=pieter.jansenvanvuuren@netronome.com \
    --cc=simon.horman@netronome.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).