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