1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Intel IFC VF NIC driver for virtio dataplane offloading
5 * Copyright (C) 2020 Intel Corporation.
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_config.h>
19 #include <uapi/linux/virtio_pci.h>
21 #define IFCVF_VENDOR_ID 0x1AF4
22 #define IFCVF_DEVICE_ID 0x1041
23 #define IFCVF_SUBSYS_VENDOR_ID 0x8086
24 #define IFCVF_SUBSYS_DEVICE_ID 0x001A
26 #define IFCVF_SUPPORTED_FEATURES \
27 ((1ULL << VIRTIO_NET_F_MAC) | \
28 (1ULL << VIRTIO_F_ANY_LAYOUT) | \
29 (1ULL << VIRTIO_F_VERSION_1) | \
30 (1ULL << VIRTIO_NET_F_STATUS) | \
31 (1ULL << VIRTIO_F_ORDER_PLATFORM) | \
32 (1ULL << VIRTIO_F_ACCESS_PLATFORM) | \
33 (1ULL << VIRTIO_NET_F_MRG_RXBUF))
35 /* Only one queue pair for now. */
36 #define IFCVF_MAX_QUEUE_PAIRS 1
38 #define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE
39 #define IFCVF_QUEUE_MAX 32768
40 #define IFCVF_MSI_CONFIG_OFF 0
41 #define IFCVF_MSI_QUEUE_OFF 1
42 #define IFCVF_PCI_MAX_RESOURCE 6
44 #define IFCVF_LM_CFG_SIZE 0x40
45 #define IFCVF_LM_RING_STATE_OFFSET 0x20
46 #define IFCVF_LM_BAR 4
48 #define IFCVF_ERR(pdev, fmt, ...) dev_err(&pdev->dev, fmt, ##__VA_ARGS__)
49 #define IFCVF_DBG(pdev, fmt, ...) dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)
50 #define IFCVF_INFO(pdev, fmt, ...) dev_info(&pdev->dev, fmt, ##__VA_ARGS__)
52 #define ifcvf_private_to_vf(adapter) \
53 (&((struct ifcvf_adapter *)adapter)->vf)
55 #define IFCVF_MAX_INTR (IFCVF_MAX_QUEUE_PAIRS * 2 + 1)
64 void __iomem *notify_addr;
66 struct vdpa_callback cb;
75 /* Notification bar number */
77 /* Notificaiton bar address */
78 void __iomem *notify_base;
79 u32 notify_off_multiplier;
81 struct virtio_pci_common_cfg __iomem *common_cfg;
82 void __iomem *net_cfg;
83 struct vring_info vring[IFCVF_MAX_QUEUE_PAIRS * 2];
84 void __iomem * const *base;
85 char config_msix_name[256];
86 struct vdpa_callback config_cb;
87 unsigned int config_irq;
90 struct ifcvf_adapter {
91 struct vdpa_device vdpa;
96 struct ifcvf_vring_lm_cfg {
98 u8 reserved[IFCVF_LM_CFG_SIZE - 8];
101 struct ifcvf_lm_cfg {
102 u8 reserved[IFCVF_LM_RING_STATE_OFFSET];
103 struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUE_PAIRS];
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_net_config(struct ifcvf_hw *hw, u64 offset,
111 void *dst, int length);
112 void ifcvf_write_net_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 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 #endif /* _IFCVF_H_ */