xref: /linux/drivers/vdpa/ifcvf/ifcvf_base.h (revision 47b60ec7ba22a6359379bce9643bfff7a1ffe9ed)
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 <linux/virtio_pci_modern.h>
18 #include <uapi/linux/virtio_net.h>
19 #include <uapi/linux/virtio_blk.h>
20 #include <uapi/linux/virtio_config.h>
21 #include <uapi/linux/virtio_pci.h>
22 #include <uapi/linux/vdpa.h>
23 
24 #define N3000_DEVICE_ID		0x1041
25 #define N3000_SUBSYS_DEVICE_ID	0x001A
26 
27 /* Max 8 data queue pairs(16 queues) and one control vq for now. */
28 #define IFCVF_MAX_QUEUES	17
29 
30 #define IFCVF_QUEUE_ALIGNMENT	PAGE_SIZE
31 #define IFCVF_QUEUE_MAX		32768
32 #define IFCVF_PCI_MAX_RESOURCE	6
33 
34 #define IFCVF_LM_CFG_SIZE		0x40
35 #define IFCVF_LM_RING_STATE_OFFSET	0x20
36 #define IFCVF_LM_BAR			4
37 
38 #define IFCVF_ERR(pdev, fmt, ...)	dev_err(&pdev->dev, fmt, ##__VA_ARGS__)
39 #define IFCVF_DBG(pdev, fmt, ...)	dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)
40 #define IFCVF_INFO(pdev, fmt, ...)	dev_info(&pdev->dev, fmt, ##__VA_ARGS__)
41 
42 /* all vqs and config interrupt has its own vector */
43 #define MSIX_VECTOR_PER_VQ_AND_CONFIG		1
44 /* all vqs share a vector, and config interrupt has a separate vector */
45 #define MSIX_VECTOR_SHARED_VQ_AND_CONFIG	2
46 /* all vqs and config interrupt share a vector */
47 #define MSIX_VECTOR_DEV_SHARED			3
48 
49 struct vring_info {
50 	u16 last_avail_idx;
51 	void __iomem *notify_addr;
52 	phys_addr_t notify_pa;
53 	u32 irq;
54 	struct vdpa_callback cb;
55 	char msix_name[256];
56 };
57 
58 struct ifcvf_hw {
59 	u8 __iomem *isr;
60 	/* Live migration */
61 	u8 __iomem *lm_cfg;
62 	/* Notification bar number */
63 	u8 notify_bar;
64 	u8 msix_vector_status;
65 	/* virtio-net or virtio-blk device config size */
66 	u32 config_size;
67 	/* Notificaiton bar address */
68 	void __iomem *notify_base;
69 	phys_addr_t notify_base_pa;
70 	u32 notify_off_multiplier;
71 	u32 dev_type;
72 	u64 hw_features;
73 	/* provisioned device features */
74 	u64 dev_features;
75 	struct virtio_pci_common_cfg __iomem *common_cfg;
76 	void __iomem *dev_cfg;
77 	struct vring_info vring[IFCVF_MAX_QUEUES];
78 	void __iomem * const *base;
79 	char config_msix_name[256];
80 	struct vdpa_callback config_cb;
81 	int config_irq;
82 	int vqs_reused_irq;
83 	u16 nr_vring;
84 	/* VIRTIO_PCI_CAP_DEVICE_CFG size */
85 	u32 num_msix_vectors;
86 	u32 cap_dev_config_size;
87 	struct pci_dev *pdev;
88 };
89 
90 struct ifcvf_adapter {
91 	struct vdpa_device vdpa;
92 	struct pci_dev *pdev;
93 	struct ifcvf_hw *vf;
94 };
95 
96 struct ifcvf_vring_lm_cfg {
97 	u32 idx_addr[2];
98 	u8 reserved[IFCVF_LM_CFG_SIZE - 8];
99 };
100 
101 struct ifcvf_lm_cfg {
102 	u8 reserved[IFCVF_LM_RING_STATE_OFFSET];
103 	struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUES];
104 };
105 
106 struct ifcvf_vdpa_mgmt_dev {
107 	struct vdpa_mgmt_dev mdev;
108 	struct ifcvf_hw vf;
109 	struct ifcvf_adapter *adapter;
110 	struct pci_dev *pdev;
111 };
112 
113 int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev);
114 void ifcvf_stop(struct ifcvf_hw *hw);
115 void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid);
116 void ifcvf_read_dev_config(struct ifcvf_hw *hw, u64 offset,
117 			   void *dst, int length);
118 void ifcvf_write_dev_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_dev_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 int ifcvf_probed_virtio_net(struct ifcvf_hw *hw);
131 u32 ifcvf_get_config_size(struct ifcvf_hw *hw);
132 u16 ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector);
133 u16 ifcvf_set_config_vector(struct ifcvf_hw *hw, int vector);
134 void ifcvf_set_vq_num(struct ifcvf_hw *hw, u16 qid, u32 num);
135 int ifcvf_set_vq_address(struct ifcvf_hw *hw, u16 qid, u64 desc_area,
136 			 u64 driver_area, u64 device_area);
137 bool ifcvf_get_vq_ready(struct ifcvf_hw *hw, u16 qid);
138 void ifcvf_set_vq_ready(struct ifcvf_hw *hw, u16 qid, bool ready);
139 void ifcvf_set_driver_features(struct ifcvf_hw *hw, u64 features);
140 u64 ifcvf_get_driver_features(struct ifcvf_hw *hw);
141 #endif /* _IFCVF_H_ */
142