Netdev List
 help / color / mirror / Atom feed
From: Saeed Mahameed <saeedm@mellanox.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, Or Gerlitz <ogerlitz@mellanox.com>,
	Hadar Hen-Zion <hadarh@mellanox.com>,
	Saeed Mahameed <saeedm@mellanox.com>
Subject: [PATCH net-next 08/13] net/mlx5: Check max encap header size capability
Date: Mon,  7 Nov 2016 15:14:43 +0200	[thread overview]
Message-ID: <1478524488-1377-9-git-send-email-saeedm@mellanox.com> (raw)
In-Reply-To: <1478524488-1377-1-git-send-email-saeedm@mellanox.com>

From: Hadar Hen Zion <hadarh@mellanox.com>

Instead of comparing to a const value, check the value of max encap
header size capability as reported by the Firmware.

Fixes: 575ddf5888ea ('net/mlx5: Introduce alloc_encap and dealloc_encap commands')
Signed-off-by: Hadar Hen Zion <hadarh@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c | 26 +++++++++++++++---------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
index 6c9d99a..301cec8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
@@ -453,27 +453,32 @@ void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev,
 	*bytes = MLX5_GET64(traffic_counter, stats, octets);
 }
 
-#define MAX_ENCAP_SIZE (128)
-
 int mlx5_encap_alloc(struct mlx5_core_dev *dev,
 		     int header_type,
 		     size_t size,
 		     void *encap_header,
 		     u32 *encap_id)
 {
+	int max_encap_size = MLX5_CAP_ESW(dev, max_encap_header_size);
 	u32 out[MLX5_ST_SZ_DW(alloc_encap_header_out)];
-	u32 in[MLX5_ST_SZ_DW(alloc_encap_header_in) +
-	      (MAX_ENCAP_SIZE / sizeof(u32))];
-	void *encap_header_in = MLX5_ADDR_OF(alloc_encap_header_in, in,
-					     encap_header);
-	void *header = MLX5_ADDR_OF(encap_header_in, encap_header_in,
-				    encap_header);
-	int inlen = header - (void *)in  + size;
+	void *encap_header_in;
+	void *header;
+	int inlen;
 	int err;
+	u32 *in;
 
-	if (size > MAX_ENCAP_SIZE)
+	if (size > MLX5_CAP_ESW(dev, max_encap_header_size))
 		return -EINVAL;
 
+	in = kzalloc(MLX5_ST_SZ_BYTES(alloc_encap_header_in) + max_encap_size,
+		     GFP_KERNEL);
+	if (!in)
+		return -ENOMEM;
+
+	encap_header_in = MLX5_ADDR_OF(alloc_encap_header_in, in, encap_header);
+	header = MLX5_ADDR_OF(encap_header_in, encap_header_in, encap_header);
+	inlen = header - (void *)in  + size;
+
 	memset(in, 0, inlen);
 	MLX5_SET(alloc_encap_header_in, in, opcode,
 		 MLX5_CMD_OP_ALLOC_ENCAP_HEADER);
@@ -485,6 +490,7 @@ int mlx5_encap_alloc(struct mlx5_core_dev *dev,
 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
 
 	*encap_id = MLX5_GET(alloc_encap_header_out, out, encap_id);
+	kfree(in);
 	return err;
 }
 
-- 
2.7.4

  parent reply	other threads:[~2016-11-07 13:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-07 13:14 [PATCH net-next 00/13] Mellanox 100G SRIOV offloads tunnel_key set/release Saeed Mahameed
2016-11-07 13:14 ` [PATCH net-next 01/13] net/sched: act_tunnel_key: add helper inlines to access tcf_tunnel_key Saeed Mahameed
2016-11-07 13:14 ` [PATCH net-next 02/13] flow_dissector: Add enums for encapsulation keys Saeed Mahameed
2016-11-07 13:14 ` [PATCH net-next 03/13] net/sched: cls_flower: Allow setting encapsulation fields as used key Saeed Mahameed
2016-11-07 13:14 ` [PATCH net-next 04/13] net/sched: cls_flower: Add UDP port to tunnel parameters Saeed Mahameed
2016-11-07 13:14 ` [PATCH net-next 05/13] net/dst: Add dst port to dst_metadata utility functions Saeed Mahameed
2016-11-07 13:14 ` [PATCH net-next 06/13] net/sched: act_tunnel_key: Add UDP dst port option Saeed Mahameed
2016-11-07 13:14 ` [PATCH net-next 07/13] net/mlx5: Move alloc/dealloc encap commands declarations to common header file Saeed Mahameed
2016-11-07 13:14 ` Saeed Mahameed [this message]
2016-11-07 13:14 ` [PATCH net-next 09/13] net/mlx5: Add creation flags when adding new flow table Saeed Mahameed
2016-11-07 13:14 ` [PATCH net-next 10/13] net/mlx5: Support encap id when setting new steering entry Saeed Mahameed
2016-11-07 13:14 ` [PATCH net-next 11/13] net/mlx5e: Add TC tunnel release action for SRIOV offloads Saeed Mahameed
2016-11-07 13:14 ` [PATCH net-next 12/13] net/mlx5e: Add ndo_udp_tunnel_add to VF representors Saeed Mahameed
2016-11-07 13:14 ` [PATCH net-next 13/13] net/mlx5e: Add basic TC tunnel set action for SRIOV offloads Saeed Mahameed
2016-11-09 18:42 ` [PATCH net-next 00/13] Mellanox 100G SRIOV offloads tunnel_key set/release David Miller

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=1478524488-1377-9-git-send-email-saeedm@mellanox.com \
    --to=saeedm@mellanox.com \
    --cc=davem@davemloft.net \
    --cc=hadarh@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=ogerlitz@mellanox.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