net/mlx5: Introduce alloc_encap and dealloc_encap commands
authorIlya Lesokhin <ilyal@mellanox.com>
Tue, 23 Feb 2016 11:25:22 +0000 (13:25 +0200)
committerLeon Romanovsky <leon@kernel.org>
Wed, 17 Aug 2016 14:46:01 +0000 (17:46 +0300)
Implement low-level commands to support vxlan encapsulation.

Signed-off-by: Ilya Lesokhin <ilyal@mellanox.com>
Signed-off-by: Hadar Hen Zion <hadarh@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/cmd.c
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.h

index 23b95daa9533c3572b75563366af4ed0d6655594..00bec609aae2aef589c16d3f39ebe20634fbc567 100644 (file)
@@ -301,6 +301,7 @@ static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op,
        case MLX5_CMD_OP_MODIFY_FLOW_TABLE:
        case MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY:
        case MLX5_CMD_OP_SET_FLOW_TABLE_ROOT:
+       case MLX5_CMD_OP_DEALLOC_ENCAP_HEADER:
                return MLX5_CMD_STAT_OK;
 
        case MLX5_CMD_OP_QUERY_HCA_CAP:
@@ -402,6 +403,7 @@ static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op,
        case MLX5_CMD_OP_QUERY_FLOW_TABLE_ENTRY:
        case MLX5_CMD_OP_ALLOC_FLOW_COUNTER:
        case MLX5_CMD_OP_QUERY_FLOW_COUNTER:
+       case MLX5_CMD_OP_ALLOC_ENCAP_HEADER:
                *status = MLX5_DRIVER_STATUS_ABORTED;
                *synd = MLX5_DRIVER_SYND;
                return -EIO;
@@ -550,6 +552,8 @@ const char *mlx5_command_str(int command)
        MLX5_COMMAND_STR_CASE(DEALLOC_FLOW_COUNTER);
        MLX5_COMMAND_STR_CASE(QUERY_FLOW_COUNTER);
        MLX5_COMMAND_STR_CASE(MODIFY_FLOW_TABLE);
+       MLX5_COMMAND_STR_CASE(ALLOC_ENCAP_HEADER);
+       MLX5_COMMAND_STR_CASE(DEALLOC_ENCAP_HEADER);
        default: return "unknown command opcode";
        }
 }
index e64499ebf2b5c5b2f5c7f7297effed121bbd40bf..7aaefa9aaf1cff0d450f5efebe0507cc305e6bdf 100644 (file)
@@ -424,3 +424,51 @@ void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev,
        *packets = MLX5_GET64(traffic_counter, stats, packets);
        *bytes = MLX5_GET64(traffic_counter, stats, octets);
 }
+
+#define MAX_ENCAP_SIZE (128)
+
+int mlx5_cmd_alloc_encap(struct mlx5_core_dev *dev,
+                        int header_type,
+                        size_t size,
+                        void *encap_header,
+                        u32 *encap_id)
+{
+       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;
+       int err;
+
+       if (size > MAX_ENCAP_SIZE)
+               return -EINVAL;
+
+       memset(in, 0, inlen);
+       MLX5_SET(alloc_encap_header_in, in, opcode,
+                MLX5_CMD_OP_ALLOC_ENCAP_HEADER);
+       MLX5_SET(encap_header_in, encap_header_in, encap_header_size, size);
+       MLX5_SET(encap_header_in, encap_header_in, header_type, header_type);
+       memcpy(header, encap_header, size);
+
+       memset(out, 0, sizeof(out));
+       err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
+
+       *encap_id = MLX5_GET(alloc_encap_header_out, out, encap_id);
+       return err;
+}
+
+void mlx5_cmd_dealloc_encap(struct mlx5_core_dev *dev, u32 encap_id)
+{
+       u32 in[MLX5_ST_SZ_DW(dealloc_encap_header_in)];
+       u32 out[MLX5_ST_SZ_DW(dealloc_encap_header_out)];
+
+       memset(in, 0, sizeof(in));
+       MLX5_SET(dealloc_encap_header_in, in, opcode,
+                MLX5_CMD_OP_DEALLOC_ENCAP_HEADER);
+       MLX5_SET(dealloc_encap_header_in, in, encap_id, encap_id);
+
+       mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
+}
index 158844cef82b0eee9112442c5611cd94f235e278..ac52fdfb5096f06c6448657fe218b3416cd2fec7 100644 (file)
@@ -88,4 +88,11 @@ void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev,
                          struct mlx5_cmd_fc_bulk *b, u16 id,
                          u64 *packets, u64 *bytes);
 
+int mlx5_cmd_alloc_encap(struct mlx5_core_dev *dev,
+                        int header_type,
+                        size_t size,
+                        void *encap_header,
+                        u32 *encap_id);
+void mlx5_cmd_dealloc_encap(struct mlx5_core_dev *dev, u32 encap_id);
+
 #endif