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>
22 #include <uapi/linux/vdpa.h>
24 #define N3000_DEVICE_ID 0x1041
25 #define N3000_SUBSYS_DEVICE_ID 0x001A
27 #define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE
28 #define IFCVF_PCI_MAX_RESOURCE 6
30 #define IFCVF_LM_BAR 4
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__)
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
45 void __iomem *notify_addr;
46 phys_addr_t notify_pa;
48 struct vdpa_callback cb;
55 __le64 lm_mem_log_start_addr;
56 __le64 lm_mem_log_end_addr;
57 __le16 vq_state_region;
63 struct ifcvf_lm_cfg __iomem *lm_cfg;
64 /* Notification bar number */
66 u8 msix_vector_status;
67 /* virtio-net or virtio-blk device config size */
69 /* Notificaiton bar address */
70 void __iomem *notify_base;
71 phys_addr_t notify_base_pa;
72 u32 notify_off_multiplier;
75 /* provisioned device 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;
86 /* VIRTIO_PCI_CAP_DEVICE_CFG size */
88 u32 cap_dev_config_size;
92 struct ifcvf_adapter {
93 struct vdpa_device vdpa;
98 struct ifcvf_vdpa_mgmt_dev {
99 struct vdpa_mgmt_dev mdev;
101 struct ifcvf_adapter *adapter;
102 struct pci_dev *pdev;
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_ */