f77239fc1644c67aac1112df0e80e6aab222920f
[linux-2.6-microblaze.git] / drivers / vdpa / ifcvf / ifcvf_base.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Intel IFC VF NIC driver for virtio dataplane offloading
4  *
5  * Copyright (C) 2020 Intel Corporation.
6  *
7  * Author: Zhu Lingshan <lingshan.zhu@intel.com>
8  *
9  */
10
11 #ifndef _IFCVF_H_
12 #define _IFCVF_H_
13
14 #include <linux/pci.h>
15 #include <linux/pci_regs.h>
16 #include <linux/vdpa.h>
17 #include <uapi/linux/virtio_net.h>
18 #include <uapi/linux/virtio_config.h>
19 #include <uapi/linux/virtio_pci.h>
20
21 #define N3000_VENDOR_ID         0x1AF4
22 #define N3000_DEVICE_ID         0x1041
23 #define N3000_SUBSYS_VENDOR_ID  0x8086
24 #define N3000_SUBSYS_DEVICE_ID  0x001A
25
26 #define C5000X_PL_VENDOR_ID             0x1AF4
27 #define C5000X_PL_DEVICE_ID             0x1000
28 #define C5000X_PL_SUBSYS_VENDOR_ID      0x8086
29 #define C5000X_PL_SUBSYS_DEVICE_ID      0x0001
30
31 #define IFCVF_SUPPORTED_FEATURES \
32                 ((1ULL << VIRTIO_NET_F_MAC)                     | \
33                  (1ULL << VIRTIO_F_ANY_LAYOUT)                  | \
34                  (1ULL << VIRTIO_F_VERSION_1)                   | \
35                  (1ULL << VIRTIO_NET_F_STATUS)                  | \
36                  (1ULL << VIRTIO_F_ORDER_PLATFORM)              | \
37                  (1ULL << VIRTIO_F_ACCESS_PLATFORM)             | \
38                  (1ULL << VIRTIO_NET_F_MRG_RXBUF))
39
40 /* Only one queue pair for now. */
41 #define IFCVF_MAX_QUEUE_PAIRS   1
42
43 #define IFCVF_QUEUE_ALIGNMENT   PAGE_SIZE
44 #define IFCVF_QUEUE_MAX         32768
45 #define IFCVF_MSI_CONFIG_OFF    0
46 #define IFCVF_MSI_QUEUE_OFF     1
47 #define IFCVF_PCI_MAX_RESOURCE  6
48
49 #define IFCVF_LM_CFG_SIZE               0x40
50 #define IFCVF_LM_RING_STATE_OFFSET      0x20
51 #define IFCVF_LM_BAR                    4
52
53 #define IFCVF_ERR(pdev, fmt, ...)       dev_err(&pdev->dev, fmt, ##__VA_ARGS__)
54 #define IFCVF_DBG(pdev, fmt, ...)       dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)
55 #define IFCVF_INFO(pdev, fmt, ...)      dev_info(&pdev->dev, fmt, ##__VA_ARGS__)
56
57 #define ifcvf_private_to_vf(adapter) \
58         (&((struct ifcvf_adapter *)adapter)->vf)
59
60 #define IFCVF_MAX_INTR (IFCVF_MAX_QUEUE_PAIRS * 2 + 1)
61
62 struct vring_info {
63         u64 desc;
64         u64 avail;
65         u64 used;
66         u16 size;
67         u16 last_avail_idx;
68         bool ready;
69         void __iomem *notify_addr;
70         u32 irq;
71         struct vdpa_callback cb;
72         char msix_name[256];
73 };
74
75 struct ifcvf_hw {
76         u8 __iomem *isr;
77         /* Live migration */
78         u8 __iomem *lm_cfg;
79         u16 nr_vring;
80         /* Notification bar number */
81         u8 notify_bar;
82         /* Notificaiton bar address */
83         void __iomem *notify_base;
84         u32 notify_off_multiplier;
85         u64 req_features;
86         u64 hw_features;
87         struct virtio_pci_common_cfg __iomem *common_cfg;
88         void __iomem *net_cfg;
89         struct vring_info vring[IFCVF_MAX_QUEUE_PAIRS * 2];
90         void __iomem * const *base;
91         char config_msix_name[256];
92         struct vdpa_callback config_cb;
93         unsigned int config_irq;
94 };
95
96 struct ifcvf_adapter {
97         struct vdpa_device vdpa;
98         struct pci_dev *pdev;
99         struct ifcvf_hw vf;
100 };
101
102 struct ifcvf_vring_lm_cfg {
103         u32 idx_addr[2];
104         u8 reserved[IFCVF_LM_CFG_SIZE - 8];
105 };
106
107 struct ifcvf_lm_cfg {
108         u8 reserved[IFCVF_LM_RING_STATE_OFFSET];
109         struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUE_PAIRS];
110 };
111
112 int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev);
113 int ifcvf_start_hw(struct ifcvf_hw *hw);
114 void ifcvf_stop_hw(struct ifcvf_hw *hw);
115 void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid);
116 void ifcvf_read_net_config(struct ifcvf_hw *hw, u64 offset,
117                            void *dst, int length);
118 void ifcvf_write_net_config(struct ifcvf_hw *hw, u64 offset,
119                             const void *src, int length);
120 u8 ifcvf_get_status(struct ifcvf_hw *hw);
121 void ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
122 void io_write64_twopart(u64 val, u32 *lo, u32 *hi);
123 void ifcvf_reset(struct ifcvf_hw *hw);
124 u64 ifcvf_get_features(struct ifcvf_hw *hw);
125 u64 ifcvf_get_hw_features(struct ifcvf_hw *hw);
126 int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features);
127 u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
128 int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
129 struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
130 #endif /* _IFCVF_H_ */