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_EN_MACSEC
8 
9 #include <linux/mlx5/driver.h>
10 #include <net/macsec.h>
11 #include <net/dst_metadata.h>
12 
13 /* Bit31 - 30: MACsec marker, Bit3-0: MACsec id */
14 #define MLX5_MACSEC_METADATA_MARKER(metadata)  ((((metadata) >> 30) & 0x3)  == 0x1)
15 #define MLX5_MACSEC_METADATA_HANDLE(metadata)  ((metadata) & GENMASK(3, 0))
16 
17 struct mlx5e_priv;
18 struct mlx5e_macsec;
19 
20 struct mlx5e_macsec_stats {
21 	u64 macsec_rx_pkts;
22 	u64 macsec_rx_bytes;
23 	u64 macsec_rx_pkts_drop;
24 	u64 macsec_rx_bytes_drop;
25 	u64 macsec_tx_pkts;
26 	u64 macsec_tx_bytes;
27 	u64 macsec_tx_pkts_drop;
28 	u64 macsec_tx_bytes_drop;
29 };
30 
31 void mlx5e_macsec_build_netdev(struct mlx5e_priv *priv);
32 int mlx5e_macsec_init(struct mlx5e_priv *priv);
33 void mlx5e_macsec_cleanup(struct mlx5e_priv *priv);
34 bool mlx5e_macsec_handle_tx_skb(struct mlx5e_macsec *macsec, struct sk_buff *skb);
35 void mlx5e_macsec_tx_build_eseg(struct mlx5e_macsec *macsec,
36 				struct sk_buff *skb,
37 				struct mlx5_wqe_eth_seg *eseg);
38 
39 static inline bool mlx5e_macsec_skb_is_offload(struct sk_buff *skb)
40 {
41 	struct metadata_dst *md_dst = skb_metadata_dst(skb);
42 
43 	return md_dst && (md_dst->type == METADATA_MACSEC);
44 }
45 
46 static inline bool mlx5e_macsec_is_rx_flow(struct mlx5_cqe64 *cqe)
47 {
48 	return MLX5_MACSEC_METADATA_MARKER(be32_to_cpu(cqe->ft_metadata));
49 }
50 
51 void mlx5e_macsec_offload_handle_rx_skb(struct net_device *netdev, struct sk_buff *skb,
52 					struct mlx5_cqe64 *cqe);
53 bool mlx5e_is_macsec_device(const struct mlx5_core_dev *mdev);
54 void mlx5e_macsec_get_stats_fill(struct mlx5e_macsec *macsec, void *macsec_stats);
55 struct mlx5e_macsec_stats *mlx5e_macsec_get_stats(struct mlx5e_macsec *macsec);
56 
57 #else
58 
59 static inline void mlx5e_macsec_build_netdev(struct mlx5e_priv *priv) {}
60 static inline int mlx5e_macsec_init(struct mlx5e_priv *priv) { return 0; }
61 static inline void mlx5e_macsec_cleanup(struct mlx5e_priv *priv) {}
62 static inline bool mlx5e_macsec_skb_is_offload(struct sk_buff *skb) { return false; }
63 static inline bool mlx5e_macsec_is_rx_flow(struct mlx5_cqe64 *cqe) { return false; }
64 static inline void mlx5e_macsec_offload_handle_rx_skb(struct net_device *netdev,
65 						      struct sk_buff *skb,
66 						      struct mlx5_cqe64 *cqe)
67 {}
68 static inline bool mlx5e_is_macsec_device(const struct mlx5_core_dev *mdev) { return false; }
69 #endif  /* CONFIG_MLX5_EN_MACSEC */
70 
71 #endif	/* __MLX5_ACCEL_EN_MACSEC_H__ */
72