• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /* Max 8 data queue pairs(16 queues) and one control vq for now. */
26 #define IFCVF_MAX_QUEUES	17
27 
28 #define IFCVF_QUEUE_ALIGNMENT	PAGE_SIZE
29 #define IFCVF_QUEUE_MAX		32768
30 #define IFCVF_MSI_CONFIG_OFF	0
31 #define IFCVF_MSI_QUEUE_OFF	1
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 #define ifcvf_private_to_vf(adapter) \
43 	(&((struct ifcvf_adapter *)adapter)->vf)
44 
45 struct vring_info {
46 	u64 desc;
47 	u64 avail;
48 	u64 used;
49 	u16 size;
50 	u16 last_avail_idx;
51 	bool ready;
52 	void __iomem *notify_addr;
53 	phys_addr_t notify_pa;
54 	u32 irq;
55 	struct vdpa_callback cb;
56 	char msix_name[256];
57 };
58 
59 struct ifcvf_hw {
60 	u8 __iomem *isr;
61 	/* Live migration */
62 	u8 __iomem *lm_cfg;
63 	u16 nr_vring;
64 	/* Notification bar number */
65 	u8 notify_bar;
66 	/* Notificaiton bar address */
67 	void __iomem *notify_base;
68 	phys_addr_t notify_base_pa;
69 	u32 notify_off_multiplier;
70 	u64 req_features;
71 	u64 hw_features;
72 	u32 dev_type;
73 	struct virtio_pci_common_cfg __iomem *common_cfg;
74 	void __iomem *dev_cfg;
75 	struct vring_info vring[IFCVF_MAX_QUEUES];
76 	void __iomem * const *base;
77 	char config_msix_name[256];
78 	struct vdpa_callback config_cb;
79 	unsigned int config_irq;
80 	/* virtio-net or virtio-blk device config size */
81 	u32 config_size;
82 };
83 
84 struct ifcvf_adapter {
85 	struct vdpa_device vdpa;
86 	struct pci_dev *pdev;
87 	struct ifcvf_hw vf;
88 };
89 
90 struct ifcvf_vring_lm_cfg {
91 	u32 idx_addr[2];
92 	u8 reserved[IFCVF_LM_CFG_SIZE - 8];
93 };
94 
95 struct ifcvf_lm_cfg {
96 	u8 reserved[IFCVF_LM_RING_STATE_OFFSET];
97 	struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUES];
98 };
99 
100 struct ifcvf_vdpa_mgmt_dev {
101 	struct vdpa_mgmt_dev mdev;
102 	struct ifcvf_adapter *adapter;
103 	struct pci_dev *pdev;
104 };
105 
106 int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev);
107 int ifcvf_start_hw(struct ifcvf_hw *hw);
108 void ifcvf_stop_hw(struct ifcvf_hw *hw);
109 void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid);
110 void ifcvf_read_dev_config(struct ifcvf_hw *hw, u64 offset,
111 			   void *dst, int length);
112 void ifcvf_write_dev_config(struct ifcvf_hw *hw, u64 offset,
113 			    const void *src, int length);
114 u8 ifcvf_get_status(struct ifcvf_hw *hw);
115 void ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
116 void io_write64_twopart(u64 val, u32 *lo, u32 *hi);
117 void ifcvf_reset(struct ifcvf_hw *hw);
118 u64 ifcvf_get_features(struct ifcvf_hw *hw);
119 u64 ifcvf_get_hw_features(struct ifcvf_hw *hw);
120 int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features);
121 u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
122 int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
123 struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
124 int ifcvf_probed_virtio_net(struct ifcvf_hw *hw);
125 u32 ifcvf_get_config_size(struct ifcvf_hw *hw);
126 #endif /* _IFCVF_H_ */
127