xref: /openbmc/linux/drivers/vdpa/mlx5/net/mlx5_vnet.h (revision 2f164822)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
3 
4 #ifndef __MLX5_VNET_H__
5 #define __MLX5_VNET_H__
6 
7 #include "mlx5_vdpa.h"
8 
9 #define to_mlx5_vdpa_ndev(__mvdev)                                             \
10 	container_of(__mvdev, struct mlx5_vdpa_net, mvdev)
11 #define to_mvdev(__vdev) container_of((__vdev), struct mlx5_vdpa_dev, vdev)
12 
13 struct mlx5_vdpa_net_resources {
14 	u32 tisn;
15 	u32 tdn;
16 	u32 tirn;
17 	u32 rqtn;
18 	bool valid;
19 	struct dentry *tirn_dent;
20 };
21 
22 #define MLX5V_MACVLAN_SIZE 256
23 
24 static inline u16 key2vid(u64 key)
25 {
26 	return (u16)(key >> 48) & 0xfff;
27 }
28 
29 struct mlx5_vdpa_net {
30 	struct mlx5_vdpa_dev mvdev;
31 	struct mlx5_vdpa_net_resources res;
32 	struct virtio_net_config config;
33 	struct mlx5_vdpa_virtqueue *vqs;
34 	struct vdpa_callback *event_cbs;
35 
36 	/* Serialize vq resources creation and destruction. This is required
37 	 * since memory map might change and we need to destroy and create
38 	 * resources while driver in operational.
39 	 */
40 	struct rw_semaphore reslock;
41 	struct mlx5_flow_table *rxft;
42 	struct dentry *rx_dent;
43 	struct dentry *rx_table_dent;
44 	bool setup;
45 	u32 cur_num_vqs;
46 	u32 rqt_size;
47 	bool nb_registered;
48 	struct notifier_block nb;
49 	struct vdpa_callback config_cb;
50 	struct mlx5_vdpa_wq_ent cvq_ent;
51 	struct hlist_head macvlan_hash[MLX5V_MACVLAN_SIZE];
52 	struct dentry *debugfs;
53 };
54 
55 struct mlx5_vdpa_counter {
56 	struct mlx5_fc *counter;
57 	struct dentry *dent;
58 	struct mlx5_core_dev *mdev;
59 };
60 
61 struct macvlan_node {
62 	struct hlist_node hlist;
63 	struct mlx5_flow_handle *ucast_rule;
64 	struct mlx5_flow_handle *mcast_rule;
65 	u64 macvlan;
66 	struct mlx5_vdpa_net *ndev;
67 	bool tagged;
68 #if defined(CONFIG_MLX5_VDPA_STEERING_DEBUG)
69 	struct dentry *dent;
70 	struct mlx5_vdpa_counter ucast_counter;
71 	struct mlx5_vdpa_counter mcast_counter;
72 #endif
73 };
74 
75 void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev);
76 void mlx5_vdpa_remove_debugfs(struct dentry *dbg);
77 void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev);
78 void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev);
79 void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev);
80 void mlx5_vdpa_remove_tirn(struct mlx5_vdpa_net *ndev);
81 #if defined(CONFIG_MLX5_VDPA_STEERING_DEBUG)
82 void mlx5_vdpa_add_rx_counters(struct mlx5_vdpa_net *ndev,
83 			       struct macvlan_node *node);
84 void mlx5_vdpa_remove_rx_counters(struct mlx5_vdpa_net *ndev,
85 				  struct macvlan_node *node);
86 #else
87 static inline void mlx5_vdpa_add_rx_counters(struct mlx5_vdpa_net *ndev,
88 					     struct macvlan_node *node) {}
89 static inline void mlx5_vdpa_remove_rx_counters(struct mlx5_vdpa_net *ndev,
90 						struct macvlan_node *node) {}
91 #endif
92 
93 
94 #endif /* __MLX5_VNET_H__ */
95