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