1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
3 
4 #ifndef __MLX5_EN_ACCEL_MACSEC_H__
5 #define __MLX5_EN_ACCEL_MACSEC_H__
6 
7 #ifdef CONFIG_MLX5_MACSEC
8 
9 #include <linux/mlx5/driver.h>
10 #include <net/macsec.h>
11 #include <net/dst_metadata.h>
12 #include "lib/macsec_fs.h"
13 
14 struct mlx5e_priv;
15 struct mlx5e_macsec;
16 
17 void mlx5e_macsec_build_netdev(struct mlx5e_priv *priv);
18 int mlx5e_macsec_init(struct mlx5e_priv *priv);
19 void mlx5e_macsec_cleanup(struct mlx5e_priv *priv);
20 bool mlx5e_macsec_handle_tx_skb(struct mlx5e_macsec *macsec, struct sk_buff *skb);
21 void mlx5e_macsec_tx_build_eseg(struct mlx5e_macsec *macsec,
22 				struct sk_buff *skb,
23 				struct mlx5_wqe_eth_seg *eseg);
24 
mlx5e_macsec_skb_is_offload(struct sk_buff * skb)25 static inline bool mlx5e_macsec_skb_is_offload(struct sk_buff *skb)
26 {
27 	struct metadata_dst *md_dst = skb_metadata_dst(skb);
28 
29 	return md_dst && (md_dst->type == METADATA_MACSEC);
30 }
31 
mlx5e_macsec_is_rx_flow(struct mlx5_cqe64 * cqe)32 static inline bool mlx5e_macsec_is_rx_flow(struct mlx5_cqe64 *cqe)
33 {
34 	return MLX5_MACSEC_METADATA_MARKER(be32_to_cpu(cqe->ft_metadata));
35 }
36 
37 void mlx5e_macsec_offload_handle_rx_skb(struct net_device *netdev, struct sk_buff *skb,
38 					struct mlx5_cqe64 *cqe);
39 
40 #else
41 
mlx5e_macsec_build_netdev(struct mlx5e_priv * priv)42 static inline void mlx5e_macsec_build_netdev(struct mlx5e_priv *priv) {}
mlx5e_macsec_init(struct mlx5e_priv * priv)43 static inline int mlx5e_macsec_init(struct mlx5e_priv *priv) { return 0; }
mlx5e_macsec_cleanup(struct mlx5e_priv * priv)44 static inline void mlx5e_macsec_cleanup(struct mlx5e_priv *priv) {}
mlx5e_macsec_skb_is_offload(struct sk_buff * skb)45 static inline bool mlx5e_macsec_skb_is_offload(struct sk_buff *skb) { return false; }
mlx5e_macsec_is_rx_flow(struct mlx5_cqe64 * cqe)46 static inline bool mlx5e_macsec_is_rx_flow(struct mlx5_cqe64 *cqe) { return false; }
mlx5e_macsec_offload_handle_rx_skb(struct net_device * netdev,struct sk_buff * skb,struct mlx5_cqe64 * cqe)47 static inline void mlx5e_macsec_offload_handle_rx_skb(struct net_device *netdev,
48 						      struct sk_buff *skb,
49 						      struct mlx5_cqe64 *cqe)
50 {}
51 #endif  /* CONFIG_MLX5_MACSEC */
52 
53 #endif	/* __MLX5_ACCEL_EN_MACSEC_H__ */
54