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>
44 #define MLX5E_IPSEC_SADB_RX_BITS 10
45 #define MLX5E_IPSEC_ESN_SCOPE_MID 0x80000000L
47 struct aes_gcm_keymat {
54 u32 aes_key[256 / 32];
57 struct mlx5_accel_esp_xfrm_attrs {
61 struct aes_gcm_keymat aes_gcm;
82 MLX5_IPSEC_CAP_CRYPTO = 1 << 0,
83 MLX5_IPSEC_CAP_ESN = 1 << 1,
84 MLX5_IPSEC_CAP_PACKET_OFFLOAD = 1 << 2,
89 struct mlx5e_ipsec_sw_stats {
90 atomic64_t ipsec_rx_drop_sp_alloc;
91 atomic64_t ipsec_rx_drop_sadb_miss;
92 atomic64_t ipsec_rx_drop_syndrome;
93 atomic64_t ipsec_tx_drop_bundle;
94 atomic64_t ipsec_tx_drop_no_state;
95 atomic64_t ipsec_tx_drop_not_ip;
96 atomic64_t ipsec_tx_drop_trailer;
99 struct mlx5e_ipsec_rx;
100 struct mlx5e_ipsec_tx;
102 struct mlx5e_ipsec_aso {
103 u8 ctx[MLX5_ST_SZ_BYTES(ipsec_aso)];
105 struct mlx5_aso *aso;
109 struct mlx5_core_dev *mdev;
110 DECLARE_HASHTABLE(sadb_rx, MLX5E_IPSEC_SADB_RX_BITS);
111 spinlock_t sadb_rx_lock; /* Protects sadb_rx */
112 struct mlx5e_ipsec_sw_stats sw_stats;
113 struct workqueue_struct *wq;
114 struct mlx5e_flow_steering *fs;
115 struct mlx5e_ipsec_rx *rx_ipv4;
116 struct mlx5e_ipsec_rx *rx_ipv6;
117 struct mlx5e_ipsec_tx *tx;
118 struct mlx5e_ipsec_aso *aso;
121 struct mlx5e_ipsec_esn_state {
127 struct mlx5e_ipsec_rule {
128 struct mlx5_flow_handle *rule;
129 struct mlx5_modify_hdr *modify_hdr;
132 struct mlx5e_ipsec_modify_state_work {
133 struct work_struct work;
134 struct mlx5_accel_esp_xfrm_attrs attrs;
137 struct mlx5e_ipsec_sa_entry {
138 struct hlist_node hlist; /* Item in SADB_RX hashtable */
139 struct mlx5e_ipsec_esn_state esn_state;
140 unsigned int handle; /* Handle in SADB_RX */
141 struct xfrm_state *x;
142 struct mlx5e_ipsec *ipsec;
143 struct mlx5_accel_esp_xfrm_attrs attrs;
144 void (*set_iv_op)(struct sk_buff *skb, struct xfrm_state *x,
145 struct xfrm_offload *xo);
148 struct mlx5e_ipsec_rule ipsec_rule;
149 struct mlx5e_ipsec_modify_state_work modify_work;
152 void mlx5e_ipsec_init(struct mlx5e_priv *priv);
153 void mlx5e_ipsec_cleanup(struct mlx5e_priv *priv);
154 void mlx5e_ipsec_build_netdev(struct mlx5e_priv *priv);
156 struct xfrm_state *mlx5e_ipsec_sadb_rx_lookup(struct mlx5e_ipsec *dev,
157 unsigned int handle);
159 void mlx5e_accel_ipsec_fs_cleanup(struct mlx5e_ipsec *ipsec);
160 int mlx5e_accel_ipsec_fs_init(struct mlx5e_ipsec *ipsec);
161 int mlx5e_accel_ipsec_fs_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry);
162 void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_ipsec_sa_entry *sa_entry);
164 int mlx5_ipsec_create_sa_ctx(struct mlx5e_ipsec_sa_entry *sa_entry);
165 void mlx5_ipsec_free_sa_ctx(struct mlx5e_ipsec_sa_entry *sa_entry);
167 u32 mlx5_ipsec_device_caps(struct mlx5_core_dev *mdev);
169 void mlx5_accel_esp_modify_xfrm(struct mlx5e_ipsec_sa_entry *sa_entry,
170 const struct mlx5_accel_esp_xfrm_attrs *attrs);
172 int mlx5e_ipsec_aso_init(struct mlx5e_ipsec *ipsec);
173 void mlx5e_ipsec_aso_cleanup(struct mlx5e_ipsec *ipsec);
175 static inline struct mlx5_core_dev *
176 mlx5e_ipsec_sa2dev(struct mlx5e_ipsec_sa_entry *sa_entry)
178 return sa_entry->ipsec->mdev;
181 static inline void mlx5e_ipsec_init(struct mlx5e_priv *priv)
185 static inline void mlx5e_ipsec_cleanup(struct mlx5e_priv *priv)
189 static inline void mlx5e_ipsec_build_netdev(struct mlx5e_priv *priv)
193 static inline u32 mlx5_ipsec_device_caps(struct mlx5_core_dev *mdev)
199 #endif /* __MLX5E_IPSEC_H__ */