Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2018, Mellanox Technologies. All rights reserved.
0003  *
0004  * This software is available to you under a choice of one of two
0005  * licenses.  You may choose to be licensed under the terms of the GNU
0006  * General Public License (GPL) Version 2, available from the file
0007  * COPYING in the main directory of this source tree, or the
0008  * OpenIB.org BSD license below:
0009  *
0010  *     Redistribution and use in source and binary forms, with or
0011  *     without modification, are permitted provided that the following
0012  *     conditions are met:
0013  *
0014  *      - Redistributions of source code must retain the above
0015  *        copyright notice, this list of conditions and the following
0016  *        disclaimer.
0017  *
0018  *      - Redistributions in binary form must reproduce the above
0019  *        copyright notice, this list of conditions and the following
0020  *        disclaimer in the documentation and/or other materials
0021  *        provided with the distribution.
0022  *
0023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0024  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0025  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0026  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0027  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0028  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0029  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0030  * SOFTWARE.
0031  */
0032 
0033 #ifndef _MLX5_FS_HELPERS_
0034 #define _MLX5_FS_HELPERS_
0035 
0036 #include <linux/mlx5/mlx5_ifc.h>
0037 
0038 #define MLX5_FS_IPV4_VERSION 4
0039 #define MLX5_FS_IPV6_VERSION 6
0040 
0041 static inline bool mlx5_fs_is_ipsec_flow(const u32 *match_c)
0042 {
0043     void *misc_params_c = MLX5_ADDR_OF(fte_match_param, match_c,
0044                        misc_parameters);
0045 
0046     return MLX5_GET(fte_match_set_misc, misc_params_c, outer_esp_spi);
0047 }
0048 
0049 static inline bool _mlx5_fs_is_outer_ipproto_flow(const u32 *match_c,
0050                           const u32 *match_v, u8 match)
0051 {
0052     const void *headers_c = MLX5_ADDR_OF(fte_match_param, match_c,
0053                          outer_headers);
0054     const void *headers_v = MLX5_ADDR_OF(fte_match_param, match_v,
0055                          outer_headers);
0056 
0057     return MLX5_GET(fte_match_set_lyr_2_4, headers_c, ip_protocol) == 0xff &&
0058         MLX5_GET(fte_match_set_lyr_2_4, headers_v, ip_protocol) == match;
0059 }
0060 
0061 static inline bool mlx5_fs_is_outer_tcp_flow(const u32 *match_c,
0062                          const u32 *match_v)
0063 {
0064     return _mlx5_fs_is_outer_ipproto_flow(match_c, match_v, IPPROTO_TCP);
0065 }
0066 
0067 static inline bool mlx5_fs_is_outer_udp_flow(const u32 *match_c,
0068                          const u32 *match_v)
0069 {
0070     return _mlx5_fs_is_outer_ipproto_flow(match_c, match_v, IPPROTO_UDP);
0071 }
0072 
0073 static inline bool mlx5_fs_is_vxlan_flow(const u32 *match_c)
0074 {
0075     void *misc_params_c = MLX5_ADDR_OF(fte_match_param, match_c,
0076                        misc_parameters);
0077 
0078     return MLX5_GET(fte_match_set_misc, misc_params_c, vxlan_vni);
0079 }
0080 
0081 static inline bool _mlx5_fs_is_outer_ipv_flow(struct mlx5_core_dev *mdev,
0082                           const u32 *match_c,
0083                           const u32 *match_v, int version)
0084 {
0085     int match_ipv = MLX5_CAP_FLOWTABLE_NIC_RX(mdev,
0086                           ft_field_support.outer_ip_version);
0087     const void *headers_c = MLX5_ADDR_OF(fte_match_param, match_c,
0088                          outer_headers);
0089     const void *headers_v = MLX5_ADDR_OF(fte_match_param, match_v,
0090                          outer_headers);
0091 
0092     if (!match_ipv) {
0093         u16 ethertype;
0094 
0095         switch (version) {
0096         case MLX5_FS_IPV4_VERSION:
0097             ethertype = ETH_P_IP;
0098             break;
0099         case MLX5_FS_IPV6_VERSION:
0100             ethertype = ETH_P_IPV6;
0101             break;
0102         default:
0103             return false;
0104         }
0105 
0106         return MLX5_GET(fte_match_set_lyr_2_4, headers_c,
0107                 ethertype) == 0xffff &&
0108             MLX5_GET(fte_match_set_lyr_2_4, headers_v,
0109                  ethertype) == ethertype;
0110     }
0111 
0112     return MLX5_GET(fte_match_set_lyr_2_4, headers_c,
0113             ip_version) == 0xf &&
0114         MLX5_GET(fte_match_set_lyr_2_4, headers_v,
0115              ip_version) == version;
0116 }
0117 
0118 static inline bool
0119 mlx5_fs_is_outer_ipv4_flow(struct mlx5_core_dev *mdev, const u32 *match_c,
0120                const u32 *match_v)
0121 {
0122     return _mlx5_fs_is_outer_ipv_flow(mdev, match_c, match_v,
0123                       MLX5_FS_IPV4_VERSION);
0124 }
0125 
0126 static inline bool
0127 mlx5_fs_is_outer_ipv6_flow(struct mlx5_core_dev *mdev, const u32 *match_c,
0128                const u32 *match_v)
0129 {
0130     return _mlx5_fs_is_outer_ipv_flow(mdev, match_c, match_v,
0131                       MLX5_FS_IPV6_VERSION);
0132 }
0133 
0134 static inline bool mlx5_fs_is_outer_ipsec_flow(const u32 *match_c)
0135 {
0136     void *misc_params_c =
0137             MLX5_ADDR_OF(fte_match_param, match_c, misc_parameters);
0138 
0139     return MLX5_GET(fte_match_set_misc, misc_params_c, outer_esp_spi);
0140 }
0141 
0142 #endif