2 * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #ifndef __MLX5E_IPSEC_H__
35 #define __MLX5E_IPSEC_H__
37 #ifdef CONFIG_MLX5_EN_IPSEC
39 #include <linux/mlx5/device.h>
41 #include <linux/idr.h>
43 #define MLX5E_IPSEC_SADB_RX_BITS 10
44 #define MLX5E_METADATA_ETHER_TYPE (0x8CE4)
45 #define MLX5E_METADATA_ETHER_LEN 8
49 struct mlx5e_ipsec_sw_stats {
50 atomic64_t ipsec_rx_drop_sp_alloc;
51 atomic64_t ipsec_rx_drop_sadb_miss;
52 atomic64_t ipsec_rx_drop_syndrome;
53 atomic64_t ipsec_tx_drop_bundle;
54 atomic64_t ipsec_tx_drop_no_state;
55 atomic64_t ipsec_tx_drop_not_ip;
56 atomic64_t ipsec_tx_drop_trailer;
57 atomic64_t ipsec_tx_drop_metadata;
60 struct mlx5e_ipsec_stats {
61 u64 ipsec_dec_in_packets;
62 u64 ipsec_dec_out_packets;
63 u64 ipsec_dec_bypass_packets;
64 u64 ipsec_enc_in_packets;
65 u64 ipsec_enc_out_packets;
66 u64 ipsec_enc_bypass_packets;
67 u64 ipsec_dec_drop_packets;
68 u64 ipsec_dec_auth_fail_packets;
69 u64 ipsec_enc_drop_packets;
70 u64 ipsec_add_sa_success;
71 u64 ipsec_add_sa_fail;
72 u64 ipsec_del_sa_success;
73 u64 ipsec_del_sa_fail;
78 struct mlx5e_priv *en_priv;
79 DECLARE_HASHTABLE(sadb_rx, MLX5E_IPSEC_SADB_RX_BITS);
80 spinlock_t sadb_rx_lock; /* Protects sadb_rx and halloc */
82 struct mlx5e_ipsec_sw_stats sw_stats;
83 struct mlx5e_ipsec_stats stats;
86 void mlx5e_ipsec_build_inverse_table(void);
87 int mlx5e_ipsec_init(struct mlx5e_priv *priv);
88 void mlx5e_ipsec_cleanup(struct mlx5e_priv *priv);
89 void mlx5e_ipsec_build_netdev(struct mlx5e_priv *priv);
91 int mlx5e_ipsec_get_count(struct mlx5e_priv *priv);
92 int mlx5e_ipsec_get_strings(struct mlx5e_priv *priv, uint8_t *data);
93 void mlx5e_ipsec_update_stats(struct mlx5e_priv *priv);
94 int mlx5e_ipsec_get_stats(struct mlx5e_priv *priv, u64 *data);
96 struct xfrm_state *mlx5e_ipsec_sadb_rx_lookup(struct mlx5e_ipsec *dev,
101 static inline void mlx5e_ipsec_build_inverse_table(void)
105 static inline int mlx5e_ipsec_init(struct mlx5e_priv *priv)
110 static inline void mlx5e_ipsec_cleanup(struct mlx5e_priv *priv)
114 static inline void mlx5e_ipsec_build_netdev(struct mlx5e_priv *priv)
118 static inline int mlx5e_ipsec_get_count(struct mlx5e_priv *priv)
123 static inline int mlx5e_ipsec_get_strings(struct mlx5e_priv *priv,
129 static inline void mlx5e_ipsec_update_stats(struct mlx5e_priv *priv)
133 static inline int mlx5e_ipsec_get_stats(struct mlx5e_priv *priv, u64 *data)
140 #endif /* __MLX5E_IPSEC_H__ */