xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/lib/hv_vhca.h (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2019 Mellanox Technologies. */
3 
4 #ifndef __LIB_HV_VHCA_H__
5 #define __LIB_HV_VHCA_H__
6 
7 #include "en.h"
8 #include "lib/hv.h"
9 
10 struct mlx5_hv_vhca_agent;
11 struct mlx5_hv_vhca;
12 struct mlx5_hv_vhca_control_block;
13 
14 enum mlx5_hv_vhca_agent_type {
15 	MLX5_HV_VHCA_AGENT_CONTROL = 0,
16 	MLX5_HV_VHCA_AGENT_STATS   = 1,
17 	MLX5_HV_VHCA_AGENT_MAX = 32,
18 };
19 
20 #if IS_ENABLED(CONFIG_PCI_HYPERV_INTERFACE)
21 
22 struct mlx5_hv_vhca_control_block {
23 	u32     capabilities;
24 	u32     control;
25 	u16     command;
26 	u16     command_ack;
27 	u16     version;
28 	u16     rings;
29 	u32     reserved1[28];
30 };
31 
32 struct mlx5_hv_vhca *mlx5_hv_vhca_create(struct mlx5_core_dev *dev);
33 void mlx5_hv_vhca_destroy(struct mlx5_hv_vhca *hv_vhca);
34 void mlx5_hv_vhca_init(struct mlx5_hv_vhca *hv_vhca);
35 void mlx5_hv_vhca_cleanup(struct mlx5_hv_vhca *hv_vhca);
36 void mlx5_hv_vhca_invalidate(void *context, u64 block_mask);
37 
38 struct mlx5_hv_vhca_agent *
39 mlx5_hv_vhca_agent_create(struct mlx5_hv_vhca *hv_vhca,
40 			  enum mlx5_hv_vhca_agent_type type,
41 			  void (*control)(struct mlx5_hv_vhca_agent*,
42 					  struct mlx5_hv_vhca_control_block *block),
43 			  void (*invalidate)(struct mlx5_hv_vhca_agent*,
44 					     u64 block_mask),
45 			  void (*cleanup)(struct mlx5_hv_vhca_agent *agent),
46 			  void *context,
47 			  struct mlx5_hv_vhca_agent **ctx_update);
48 
49 void mlx5_hv_vhca_agent_destroy(struct mlx5_hv_vhca_agent *agent);
50 int mlx5_hv_vhca_agent_write(struct mlx5_hv_vhca_agent *agent,
51 			     void *buf, int len);
52 void *mlx5_hv_vhca_agent_priv(struct mlx5_hv_vhca_agent *agent);
53 
54 #else
55 
56 static inline struct mlx5_hv_vhca *
mlx5_hv_vhca_create(struct mlx5_core_dev * dev)57 mlx5_hv_vhca_create(struct mlx5_core_dev *dev)
58 {
59 	return NULL;
60 }
61 
mlx5_hv_vhca_destroy(struct mlx5_hv_vhca * hv_vhca)62 static inline void mlx5_hv_vhca_destroy(struct mlx5_hv_vhca *hv_vhca)
63 {
64 }
65 
mlx5_hv_vhca_init(struct mlx5_hv_vhca * hv_vhca)66 static inline void mlx5_hv_vhca_init(struct mlx5_hv_vhca *hv_vhca)
67 {
68 }
69 
mlx5_hv_vhca_cleanup(struct mlx5_hv_vhca * hv_vhca)70 static inline void mlx5_hv_vhca_cleanup(struct mlx5_hv_vhca *hv_vhca)
71 {
72 }
73 
mlx5_hv_vhca_invalidate(void * context,u64 block_mask)74 static inline void mlx5_hv_vhca_invalidate(void *context,
75 					   u64 block_mask)
76 {
77 }
78 
79 static inline struct mlx5_hv_vhca_agent *
mlx5_hv_vhca_agent_create(struct mlx5_hv_vhca * hv_vhca,enum mlx5_hv_vhca_agent_type type,void (* control)(struct mlx5_hv_vhca_agent *,struct mlx5_hv_vhca_control_block * block),void (* invalidate)(struct mlx5_hv_vhca_agent *,u64 block_mask),void (* cleanup)(struct mlx5_hv_vhca_agent * agent),void * context,struct mlx5_hv_vhca_agent ** ctx_update)80 mlx5_hv_vhca_agent_create(struct mlx5_hv_vhca *hv_vhca,
81 			  enum mlx5_hv_vhca_agent_type type,
82 			  void (*control)(struct mlx5_hv_vhca_agent*,
83 					  struct mlx5_hv_vhca_control_block *block),
84 			  void (*invalidate)(struct mlx5_hv_vhca_agent*,
85 					     u64 block_mask),
86 			  void (*cleanup)(struct mlx5_hv_vhca_agent *agent),
87 			  void *context,
88 			  struct mlx5_hv_vhca_agent **ctx_update)
89 {
90 	return NULL;
91 }
92 
mlx5_hv_vhca_agent_destroy(struct mlx5_hv_vhca_agent * agent)93 static inline void mlx5_hv_vhca_agent_destroy(struct mlx5_hv_vhca_agent *agent)
94 {
95 }
96 #endif
97 
98 #endif /* __LIB_HV_VHCA_H__ */
99