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
10struct mlx5_hv_vhca_agent;
11struct mlx5_hv_vhca;
12struct mlx5_hv_vhca_control_block;
13
14enum 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
22struct 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
32struct mlx5_hv_vhca *mlx5_hv_vhca_create(struct mlx5_core_dev *dev);
33void mlx5_hv_vhca_destroy(struct mlx5_hv_vhca *hv_vhca);
34int mlx5_hv_vhca_init(struct mlx5_hv_vhca *hv_vhca);
35void mlx5_hv_vhca_cleanup(struct mlx5_hv_vhca *hv_vhca);
36void mlx5_hv_vhca_invalidate(void *context, u64 block_mask);
37
38struct mlx5_hv_vhca_agent *
39mlx5_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
48void mlx5_hv_vhca_agent_destroy(struct mlx5_hv_vhca_agent *agent);
49int mlx5_hv_vhca_agent_write(struct mlx5_hv_vhca_agent *agent,
50			     void *buf, int len);
51void *mlx5_hv_vhca_agent_priv(struct mlx5_hv_vhca_agent *agent);
52
53#else
54
55static inline struct mlx5_hv_vhca *
56mlx5_hv_vhca_create(struct mlx5_core_dev *dev)
57{
58	return NULL;
59}
60
61static inline void mlx5_hv_vhca_destroy(struct mlx5_hv_vhca *hv_vhca)
62{
63}
64
65static inline int mlx5_hv_vhca_init(struct mlx5_hv_vhca *hv_vhca)
66{
67	return 0;
68}
69
70static inline void mlx5_hv_vhca_cleanup(struct mlx5_hv_vhca *hv_vhca)
71{
72}
73
74static inline void mlx5_hv_vhca_invalidate(void *context,
75					   u64 block_mask)
76{
77}
78
79static inline struct mlx5_hv_vhca_agent *
80mlx5_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{
89	return NULL;
90}
91
92static inline void mlx5_hv_vhca_agent_destroy(struct mlx5_hv_vhca_agent *agent)
93{
94}
95#endif
96
97#endif /* __LIB_HV_VHCA_H__ */
98