raw/cnxk_bphy: add doxygen comments
[dpdk.git] / drivers / vdpa / ifc / base / ifcvf.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _IFCVF_H_
6 #define _IFCVF_H_
7
8 #include <linux/virtio_blk.h>
9 #include "ifcvf_osdep.h"
10
11 #define IFCVF_NET       0
12 #define IFCVF_BLK       1
13
14 #define IFCVF_VENDOR_ID                     0x1AF4
15 #define IFCVF_NET_DEVICE_ID                 0x1041
16 #define IFCVF_BLK_MODERN_DEVICE_ID          0x1042
17 #define IFCVF_BLK_TRANSITIONAL_DEVICE_ID    0x1001
18 #define IFCVF_SUBSYS_VENDOR_ID              0x8086
19 #define IFCVF_SUBSYS_DEVICE_ID              0x001A
20 #define IFCVF_BLK_DEVICE_ID                 0x0002
21
22 #define IFCVF_MAX_QUEUES                1
23
24 #ifndef VIRTIO_F_IOMMU_PLATFORM
25 #define VIRTIO_F_IOMMU_PLATFORM         33
26 #endif
27
28 /* Common configuration */
29 #define IFCVF_PCI_CAP_COMMON_CFG        1
30 /* Notifications */
31 #define IFCVF_PCI_CAP_NOTIFY_CFG        2
32 /* ISR Status */
33 #define IFCVF_PCI_CAP_ISR_CFG           3
34 /* Device specific configuration */
35 #define IFCVF_PCI_CAP_DEVICE_CFG        4
36 /* PCI configuration access */
37 #define IFCVF_PCI_CAP_PCI_CFG           5
38
39 #define IFCVF_CONFIG_STATUS_RESET     0x00
40 #define IFCVF_CONFIG_STATUS_ACK       0x01
41 #define IFCVF_CONFIG_STATUS_DRIVER    0x02
42 #define IFCVF_CONFIG_STATUS_DRIVER_OK 0x04
43 #define IFCVF_CONFIG_STATUS_FEATURES_OK 0x08
44 #define IFCVF_CONFIG_STATUS_FAILED    0x80
45
46 #define IFCVF_MSI_NO_VECTOR     0xffff
47 #define IFCVF_PCI_MAX_RESOURCE  6
48
49 #define IFCVF_LM_CFG_SIZE               0x40
50 #define IFCVF_LM_RING_STATE_OFFSET      0x20
51
52 #define IFCVF_LM_LOGGING_CTRL           0x0
53
54 #define IFCVF_LM_BASE_ADDR_LOW          0x10
55 #define IFCVF_LM_BASE_ADDR_HIGH         0x14
56 #define IFCVF_LM_END_ADDR_LOW           0x18
57 #define IFCVF_LM_END_ADDR_HIGH          0x1c
58
59 #define IFCVF_LM_DISABLE                0x0
60 #define IFCVF_LM_ENABLE_VF              0x1
61 #define IFCVF_LM_ENABLE_PF              0x3
62 #define IFCVF_LOG_BASE                  0x100000000000
63 #define IFCVF_MEDIATED_VRING            0x200000000000
64
65 #define IFCVF_32_BIT_MASK               0xffffffff
66 #define IFCVF_16_BIT_MASK               0xffff
67
68
69 #ifndef VHOST_USER_PROTOCOL_F_CONFIG
70 #define VHOST_USER_PROTOCOL_F_CONFIG    9
71 #endif
72
73 struct ifcvf_pci_cap {
74         u8 cap_vndr;            /* Generic PCI field: PCI_CAP_ID_VNDR */
75         u8 cap_next;            /* Generic PCI field: next ptr. */
76         u8 cap_len;             /* Generic PCI field: capability length */
77         u8 cfg_type;            /* Identifies the structure. */
78         u8 bar;                 /* Where to find it. */
79         u8 padding[3];          /* Pad to full dword. */
80         u32 offset;             /* Offset within bar. */
81         u32 length;             /* Length of the structure, in bytes. */
82 };
83
84 struct ifcvf_pci_notify_cap {
85         struct ifcvf_pci_cap cap;
86         u32 notify_off_multiplier;  /* Multiplier for queue_notify_off. */
87 };
88
89 struct ifcvf_pci_common_cfg {
90         /* About the whole device. */
91         u32 device_feature_select;
92         u32 device_feature;
93         u32 guest_feature_select;
94         u32 guest_feature;
95         u16 msix_config;
96         u16 num_queues;
97         u8 device_status;
98         u8 config_generation;
99
100         /* About a specific virtqueue. */
101         u16 queue_select;
102         u16 queue_size;
103         u16 queue_msix_vector;
104         u16 queue_enable;
105         u16 queue_notify_off;
106         u32 queue_desc_lo;
107         u32 queue_desc_hi;
108         u32 queue_avail_lo;
109         u32 queue_avail_hi;
110         u32 queue_used_lo;
111         u32 queue_used_hi;
112 };
113
114 struct ifcvf_net_config {
115         u8    mac[6];
116         u16   status;
117         u16   max_virtqueue_pairs;
118 } __rte_packed;
119
120 struct ifcvf_pci_mem_resource {
121         u64      phys_addr; /**< Physical address, 0 if not resource. */
122         u64      len;       /**< Length of the resource. */
123         u8       *addr;     /**< Virtual address, NULL when not mapped. */
124 };
125
126 struct vring_info {
127         u64 desc;
128         u64 avail;
129         u64 used;
130         u16 size;
131         u16 last_avail_idx;
132         u16 last_used_idx;
133         bool enable;
134 };
135
136 struct ifcvf_hw {
137         u64    req_features;
138         u8     notify_region;
139         u32    notify_off_multiplier;
140         struct ifcvf_pci_common_cfg *common_cfg;
141         union {
142                 struct ifcvf_net_config *net_cfg;
143                 struct virtio_blk_config *blk_cfg;
144                 void *dev_cfg;
145         };
146         u8     *isr;
147         u16    *notify_base;
148         u16    *notify_addr[IFCVF_MAX_QUEUES * 2];
149         u8     *lm_cfg;
150         struct vring_info vring[IFCVF_MAX_QUEUES * 2];
151         u8 nr_vring;
152         int device_type;
153         struct ifcvf_pci_mem_resource mem_resource[IFCVF_PCI_MAX_RESOURCE];
154 };
155
156 int
157 ifcvf_init_hw(struct ifcvf_hw *hw, PCI_DEV *dev);
158
159 u64
160 ifcvf_get_features(struct ifcvf_hw *hw);
161
162 int
163 ifcvf_start_hw(struct ifcvf_hw *hw);
164
165 void
166 ifcvf_stop_hw(struct ifcvf_hw *hw);
167
168 void
169 ifcvf_enable_logging(struct ifcvf_hw *hw, u64 log_base, u64 log_size);
170
171 void
172 ifcvf_disable_logging(struct ifcvf_hw *hw);
173
174 void
175 ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid);
176
177 u8
178 ifcvf_get_notify_region(struct ifcvf_hw *hw);
179
180 u64
181 ifcvf_get_queue_notify_off(struct ifcvf_hw *hw, int qid);
182
183 #endif /* _IFCVF_H_ */