xref: /openbmc/linux/drivers/vdpa/ifcvf/ifcvf_base.h (revision 078b39c9)
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 #define IFCVF_QUEUE_ALIGNMENT	PAGE_SIZE
28 #define IFCVF_PCI_MAX_RESOURCE	6
29 
30 #define IFCVF_LM_BAR			4
31 
32 #define IFCVF_ERR(pdev, fmt, ...)	dev_err(&pdev->dev, fmt, ##__VA_ARGS__)
33 #define IFCVF_DBG(pdev, fmt, ...)	dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)
34 #define IFCVF_INFO(pdev, fmt, ...)	dev_info(&pdev->dev, fmt, ##__VA_ARGS__)
35 
36 /* all vqs and config interrupt has its own vector */
37 #define MSIX_VECTOR_PER_VQ_AND_CONFIG		1
38 /* all vqs share a vector, and config interrupt has a separate vector */
39 #define MSIX_VECTOR_SHARED_VQ_AND_CONFIG	2
40 /* all vqs and config interrupt share a vector */
41 #define MSIX_VECTOR_DEV_SHARED			3
42 
43 struct vring_info {
44 	u16 last_avail_idx;
45 	void __iomem *notify_addr;
46 	phys_addr_t notify_pa;
47 	u32 irq;
48 	struct vdpa_callback cb;
49 	char msix_name[256];
50 };
51 
52 struct ifcvf_lm_cfg {
53 	__le64 control;
54 	__le64 status;
55 	__le64 lm_mem_log_start_addr;
56 	__le64 lm_mem_log_end_addr;
57 	__le16 vq_state_region;
58 };
59 
60 struct ifcvf_hw {
61 	u8 __iomem *isr;
62 	/* Live migration */
63 	struct ifcvf_lm_cfg  __iomem *lm_cfg;
64 	/* Notification bar number */
65 	u8 notify_bar;
66 	u8 msix_vector_status;
67 	/* virtio-net or virtio-blk device config size */
68 	u32 config_size;
69 	/* Notificaiton bar address */
70 	void __iomem *notify_base;
71 	phys_addr_t notify_base_pa;
72 	u32 notify_off_multiplier;
73 	u32 dev_type;
74 	u64 hw_features;
75 	/* provisioned device features */
76 	u64 dev_features;
77 	struct virtio_pci_common_cfg __iomem *common_cfg;
78 	void __iomem *dev_cfg;
79 	struct vring_info *vring;
80 	void __iomem * const *base;
81 	char config_msix_name[256];
82 	struct vdpa_callback config_cb;
83 	int config_irq;
84 	int vqs_reused_irq;
85 	u16 nr_vring;
86 	/* VIRTIO_PCI_CAP_DEVICE_CFG size */
87 	u32 num_msix_vectors;
88 	u32 cap_dev_config_size;
89 	struct pci_dev *pdev;
90 };
91 
92 struct ifcvf_adapter {
93 	struct vdpa_device vdpa;
94 	struct pci_dev *pdev;
95 	struct ifcvf_hw *vf;
96 };
97 
98 struct ifcvf_vdpa_mgmt_dev {
99 	struct vdpa_mgmt_dev mdev;
100 	struct ifcvf_hw vf;
101 	struct ifcvf_adapter *adapter;
102 	struct pci_dev *pdev;
103 };
104 
105 int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev);
106 void ifcvf_stop(struct ifcvf_hw *hw);
107 void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid);
108 void ifcvf_read_dev_config(struct ifcvf_hw *hw, u64 offset,
109 			   void *dst, int length);
110 void ifcvf_write_dev_config(struct ifcvf_hw *hw, u64 offset,
111 			    const void *src, int length);
112 u8 ifcvf_get_status(struct ifcvf_hw *hw);
113 void ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
114 void io_write64_twopart(u64 val, u32 *lo, u32 *hi);
115 void ifcvf_reset(struct ifcvf_hw *hw);
116 u64 ifcvf_get_dev_features(struct ifcvf_hw *hw);
117 u64 ifcvf_get_hw_features(struct ifcvf_hw *hw);
118 int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features);
119 u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
120 int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
121 struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
122 int ifcvf_probed_virtio_net(struct ifcvf_hw *hw);
123 u32 ifcvf_get_config_size(struct ifcvf_hw *hw);
124 u16 ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector);
125 u16 ifcvf_set_config_vector(struct ifcvf_hw *hw, int vector);
126 void ifcvf_set_vq_num(struct ifcvf_hw *hw, u16 qid, u32 num);
127 int ifcvf_set_vq_address(struct ifcvf_hw *hw, u16 qid, u64 desc_area,
128 			 u64 driver_area, u64 device_area);
129 bool ifcvf_get_vq_ready(struct ifcvf_hw *hw, u16 qid);
130 void ifcvf_set_vq_ready(struct ifcvf_hw *hw, u16 qid, bool ready);
131 void ifcvf_set_driver_features(struct ifcvf_hw *hw, u64 features);
132 u64 ifcvf_get_driver_features(struct ifcvf_hw *hw);
133 u16 ifcvf_get_max_vq_size(struct ifcvf_hw *hw);
134 #endif /* _IFCVF_H_ */
135