xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.h (revision 2ace52718376fdb56aca863da2eebe70d7e2ddb1)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
3 
4 #ifndef __MLX5_MACSEC_STEERING_H__
5 #define __MLX5_MACSEC_STEERING_H__
6 
7 #ifdef CONFIG_MLX5_MACSEC
8 
9 /* Bit31 - 30: MACsec marker, Bit15-0: MACsec id */
10 #define MLX5_MACEC_RX_FS_ID_MAX USHRT_MAX /* Must be power of two */
11 #define MLX5_MACSEC_RX_FS_ID_MASK MLX5_MACEC_RX_FS_ID_MAX
12 #define MLX5_MACSEC_METADATA_MARKER(metadata)  ((((metadata) >> 30) & 0x3)  == 0x1)
13 #define MLX5_MACSEC_RX_METADAT_HANDLE(metadata)  ((metadata) & MLX5_MACSEC_RX_FS_ID_MASK)
14 
15 /* MACsec TX flow steering */
16 #define MLX5_ETH_WQE_FT_META_MACSEC_MASK \
17 	(MLX5_ETH_WQE_FT_META_MACSEC | MLX5_ETH_WQE_FT_META_MACSEC_FS_ID_MASK)
18 #define MLX5_ETH_WQE_FT_META_MACSEC_SHIFT MLX5_ETH_WQE_FT_META_SHIFT
19 
20 /* MACsec fs_id handling for steering */
21 #define mlx5_macsec_fs_set_tx_fs_id(fs_id) \
22 	(((MLX5_ETH_WQE_FT_META_MACSEC) >> MLX5_ETH_WQE_FT_META_MACSEC_SHIFT) \
23 	 | ((fs_id) << 2))
24 
25 #define MLX5_MACSEC_TX_METADATA(fs_id) \
26 	(mlx5_macsec_fs_set_tx_fs_id(fs_id) << \
27 	 MLX5_ETH_WQE_FT_META_MACSEC_SHIFT)
28 
29 /* MACsec fs_id uses 4 bits, supports up to 16 interfaces */
30 #define MLX5_MACSEC_NUM_OF_SUPPORTED_INTERFACES 16
31 
32 struct mlx5_macsec_fs;
33 union mlx5_macsec_rule;
34 
35 struct mlx5_macsec_rule_attrs {
36 	sci_t sci;
37 	u32 macsec_obj_id;
38 	u8 assoc_num;
39 	int action;
40 };
41 
42 struct mlx5_macsec_stats {
43 	u64 macsec_rx_pkts;
44 	u64 macsec_rx_bytes;
45 	u64 macsec_rx_pkts_drop;
46 	u64 macsec_rx_bytes_drop;
47 	u64 macsec_tx_pkts;
48 	u64 macsec_tx_bytes;
49 	u64 macsec_tx_pkts_drop;
50 	u64 macsec_tx_bytes_drop;
51 };
52 
53 enum mlx5_macsec_action {
54 	MLX5_ACCEL_MACSEC_ACTION_ENCRYPT,
55 	MLX5_ACCEL_MACSEC_ACTION_DECRYPT,
56 };
57 
58 void mlx5_macsec_fs_cleanup(struct mlx5_macsec_fs *macsec_fs);
59 
60 struct mlx5_macsec_fs *
61 mlx5_macsec_fs_init(struct mlx5_core_dev *mdev);
62 
63 union mlx5_macsec_rule *
64 mlx5_macsec_fs_add_rule(struct mlx5_macsec_fs *macsec_fs,
65 			const struct macsec_context *ctx,
66 			struct mlx5_macsec_rule_attrs *attrs,
67 			u32 *sa_fs_id);
68 
69 void mlx5_macsec_fs_del_rule(struct mlx5_macsec_fs *macsec_fs,
70 			     union mlx5_macsec_rule *macsec_rule,
71 			     int action, void *macdev, u32 sa_fs_id);
72 
73 void mlx5_macsec_fs_get_stats_fill(struct mlx5_macsec_fs *macsec_fs, void *macsec_stats);
74 struct mlx5_macsec_stats *mlx5_macsec_fs_get_stats(struct mlx5_macsec_fs *macsec_fs);
75 u32 mlx5_macsec_fs_get_fs_id_from_hashtable(struct mlx5_macsec_fs *macsec_fs, sci_t *sci);
76 
77 #endif
78 
79 #endif /* __MLX5_MACSEC_STEERING_H__ */
80