lkdtm: Use init_uts_ns.name instead of macros
[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_blk.h>
19 #include <uapi/linux/virtio_config.h>
20 #include <uapi/linux/virtio_pci.h>
21
22 #define N3000_DEVICE_ID         0x1041
23 #define N3000_SUBSYS_DEVICE_ID  0x001A
24
25 #define IFCVF_NET_SUPPORTED_FEATURES \
26                 ((1ULL << VIRTIO_NET_F_MAC)                     | \
27                  (1ULL << VIRTIO_F_ANY_LAYOUT)                  | \
28                  (1ULL << VIRTIO_F_VERSION_1)                   | \
29                  (1ULL << VIRTIO_NET_F_STATUS)                  | \
30                  (1ULL << VIRTIO_F_ORDER_PLATFORM)              | \
31                  (1ULL << VIRTIO_F_ACCESS_PLATFORM)             | \
32                  (1ULL << VIRTIO_NET_F_MRG_RXBUF))
33
34 /* Only one queue pair for now. */
35 #define IFCVF_MAX_QUEUE_PAIRS   1
36
37 #define IFCVF_QUEUE_ALIGNMENT   PAGE_SIZE
38 #define IFCVF_QUEUE_MAX         32768
39 #define IFCVF_MSI_CONFIG_OFF    0
40 #define IFCVF_MSI_QUEUE_OFF     1
41 #define IFCVF_PCI_MAX_RESOURCE  6
42
43 #define IFCVF_LM_CFG_SIZE               0x40
44 #define IFCVF_LM_RING_STATE_OFFSET      0x20
45 #define IFCVF_LM_BAR                    4
46
47 #define IFCVF_ERR(pdev, fmt, ...)       dev_err(&pdev->dev, fmt, ##__VA_ARGS__)
48 #define IFCVF_DBG(pdev, fmt, ...)       dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)
49 #define IFCVF_INFO(pdev, fmt, ...)      dev_info(&pdev->dev, fmt, ##__VA_ARGS__)
50
51 #define ifcvf_private_to_vf(adapter) \
52         (&((struct ifcvf_adapter *)adapter)->vf)
53
54 #define IFCVF_MAX_INTR (IFCVF_MAX_QUEUE_PAIRS * 2 + 1)
55
56 struct vring_info {
57         u64 desc;
58         u64 avail;
59         u64 used;
60         u16 size;
61         u16 last_avail_idx;
62         bool ready;
63         void __iomem *notify_addr;
64         phys_addr_t notify_pa;
65         u32 irq;
66         struct vdpa_callback cb;
67         char msix_name[256];
68 };
69
70 struct ifcvf_hw {
71         u8 __iomem *isr;
72         /* Live migration */
73         u8 __iomem *lm_cfg;
74         u16 nr_vring;
75         /* Notification bar number */
76         u8 notify_bar;
77         /* Notificaiton bar address */
78         void __iomem *notify_base;
79         phys_addr_t notify_base_pa;
80         u32 notify_off_multiplier;
81         u64 req_features;
82         u64 hw_features;
83         u32 dev_type;
84         struct virtio_pci_common_cfg __iomem *common_cfg;
85         void __iomem *net_cfg;
86         struct vring_info vring[IFCVF_MAX_QUEUE_PAIRS * 2];
87         void __iomem * const *base;
88         char config_msix_name[256];
89         struct vdpa_callback config_cb;
90         unsigned int config_irq;
91 };
92
93 struct ifcvf_adapter {
94         struct vdpa_device vdpa;
95         struct pci_dev *pdev;
96         struct ifcvf_hw vf;
97 };
98
99 struct ifcvf_vring_lm_cfg {
100         u32 idx_addr[2];
101         u8 reserved[IFCVF_LM_CFG_SIZE - 8];
102 };
103
104 struct ifcvf_lm_cfg {
105         u8 reserved[IFCVF_LM_RING_STATE_OFFSET];
106         struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUE_PAIRS];
107 };
108
109 int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev);
110 int ifcvf_start_hw(struct ifcvf_hw *hw);
111 void ifcvf_stop_hw(struct ifcvf_hw *hw);
112 void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid);
113 void ifcvf_read_net_config(struct ifcvf_hw *hw, u64 offset,
114                            void *dst, int length);
115 void ifcvf_write_net_config(struct ifcvf_hw *hw, u64 offset,
116                             const void *src, int length);
117 u8 ifcvf_get_status(struct ifcvf_hw *hw);
118 void ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
119 void io_write64_twopart(u64 val, u32 *lo, u32 *hi);
120 void ifcvf_reset(struct ifcvf_hw *hw);
121 u64 ifcvf_get_features(struct ifcvf_hw *hw);
122 u64 ifcvf_get_hw_features(struct ifcvf_hw *hw);
123 int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features);
124 u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
125 int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
126 struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
127 int ifcvf_probed_virtio_net(struct ifcvf_hw *hw);
128 #endif /* _IFCVF_H_ */