1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Intel IFC VF NIC driver for virtio dataplane offloading
5 * Copyright (C) 2020 Intel Corporation.
7 * Author: Zhu Lingshan <lingshan.zhu@intel.com>
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>
23 #define N3000_DEVICE_ID 0x1041
24 #define N3000_SUBSYS_DEVICE_ID 0x001A
26 /* Max 8 data queue pairs(16 queues) and one control vq for now. */
27 #define IFCVF_MAX_QUEUES 17
29 #define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE
30 #define IFCVF_QUEUE_MAX 32768
31 #define IFCVF_PCI_MAX_RESOURCE 6
33 #define IFCVF_LM_CFG_SIZE 0x40
34 #define IFCVF_LM_RING_STATE_OFFSET 0x20
35 #define IFCVF_LM_BAR 4
37 #define IFCVF_ERR(pdev, fmt, ...) dev_err(&pdev->dev, fmt, ##__VA_ARGS__)
38 #define IFCVF_DBG(pdev, fmt, ...) dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)
39 #define IFCVF_INFO(pdev, fmt, ...) dev_info(&pdev->dev, fmt, ##__VA_ARGS__)
41 #define ifcvf_private_to_vf(adapter) \
42 (&((struct ifcvf_adapter *)adapter)->vf)
44 /* all vqs and config interrupt has its own vector */
45 #define MSIX_VECTOR_PER_VQ_AND_CONFIG 1
46 /* all vqs share a vector, and config interrupt has a separate vector */
47 #define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2
48 /* all vqs and config interrupt share a vector */
49 #define MSIX_VECTOR_DEV_SHARED 3
58 void __iomem *notify_addr;
59 phys_addr_t notify_pa;
61 struct vdpa_callback cb;
69 /* Notification bar number */
71 u8 msix_vector_status;
72 /* virtio-net or virtio-blk device config size */
74 /* Notificaiton bar address */
75 void __iomem *notify_base;
76 phys_addr_t notify_base_pa;
77 u32 notify_off_multiplier;
81 struct virtio_pci_common_cfg __iomem *common_cfg;
82 void __iomem *dev_cfg;
83 struct vring_info vring[IFCVF_MAX_QUEUES];
84 void __iomem * const *base;
85 char config_msix_name[256];
86 struct vdpa_callback config_cb;
92 struct ifcvf_adapter {
93 struct vdpa_device vdpa;
98 struct ifcvf_vring_lm_cfg {
100 u8 reserved[IFCVF_LM_CFG_SIZE - 8];
103 struct ifcvf_lm_cfg {
104 u8 reserved[IFCVF_LM_RING_STATE_OFFSET];
105 struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUES];
108 struct ifcvf_vdpa_mgmt_dev {
109 struct vdpa_mgmt_dev mdev;
110 struct ifcvf_adapter *adapter;
111 struct pci_dev *pdev;
114 int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev);
115 int ifcvf_start_hw(struct ifcvf_hw *hw);
116 void ifcvf_stop_hw(struct ifcvf_hw *hw);
117 void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid);
118 void ifcvf_read_dev_config(struct ifcvf_hw *hw, u64 offset,
119 void *dst, int length);
120 void ifcvf_write_dev_config(struct ifcvf_hw *hw, u64 offset,
121 const void *src, int length);
122 u8 ifcvf_get_status(struct ifcvf_hw *hw);
123 void ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
124 void io_write64_twopart(u64 val, u32 *lo, u32 *hi);
125 void ifcvf_reset(struct ifcvf_hw *hw);
126 u64 ifcvf_get_features(struct ifcvf_hw *hw);
127 u64 ifcvf_get_hw_features(struct ifcvf_hw *hw);
128 int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features);
129 u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
130 int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
131 struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
132 int ifcvf_probed_virtio_net(struct ifcvf_hw *hw);
133 u32 ifcvf_get_config_size(struct ifcvf_hw *hw);
134 u16 ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector);
135 u16 ifcvf_set_config_vector(struct ifcvf_hw *hw, int vector);
136 #endif /* _IFCVF_H_ */