18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Intel IFC VF NIC driver for virtio dataplane offloading
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2020 Intel Corporation.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: Zhu Lingshan <lingshan.zhu@intel.com>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef _IFCVF_H_
128c2ecf20Sopenharmony_ci#define _IFCVF_H_
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/pci.h>
158c2ecf20Sopenharmony_ci#include <linux/pci_regs.h>
168c2ecf20Sopenharmony_ci#include <linux/vdpa.h>
178c2ecf20Sopenharmony_ci#include <uapi/linux/virtio_net.h>
188c2ecf20Sopenharmony_ci#include <uapi/linux/virtio_config.h>
198c2ecf20Sopenharmony_ci#include <uapi/linux/virtio_pci.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define IFCVF_VENDOR_ID		0x1AF4
228c2ecf20Sopenharmony_ci#define IFCVF_DEVICE_ID		0x1041
238c2ecf20Sopenharmony_ci#define IFCVF_SUBSYS_VENDOR_ID	0x8086
248c2ecf20Sopenharmony_ci#define IFCVF_SUBSYS_DEVICE_ID	0x001A
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define IFCVF_SUPPORTED_FEATURES \
278c2ecf20Sopenharmony_ci		((1ULL << VIRTIO_NET_F_MAC)			| \
288c2ecf20Sopenharmony_ci		 (1ULL << VIRTIO_F_ANY_LAYOUT)			| \
298c2ecf20Sopenharmony_ci		 (1ULL << VIRTIO_F_VERSION_1)			| \
308c2ecf20Sopenharmony_ci		 (1ULL << VIRTIO_NET_F_STATUS)			| \
318c2ecf20Sopenharmony_ci		 (1ULL << VIRTIO_F_ORDER_PLATFORM)		| \
328c2ecf20Sopenharmony_ci		 (1ULL << VIRTIO_F_ACCESS_PLATFORM)		| \
338c2ecf20Sopenharmony_ci		 (1ULL << VIRTIO_NET_F_MRG_RXBUF))
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* Only one queue pair for now. */
368c2ecf20Sopenharmony_ci#define IFCVF_MAX_QUEUE_PAIRS	1
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define IFCVF_QUEUE_ALIGNMENT	PAGE_SIZE
398c2ecf20Sopenharmony_ci#define IFCVF_QUEUE_MAX		32768
408c2ecf20Sopenharmony_ci#define IFCVF_MSI_CONFIG_OFF	0
418c2ecf20Sopenharmony_ci#define IFCVF_MSI_QUEUE_OFF	1
428c2ecf20Sopenharmony_ci#define IFCVF_PCI_MAX_RESOURCE	6
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define IFCVF_LM_CFG_SIZE		0x40
458c2ecf20Sopenharmony_ci#define IFCVF_LM_RING_STATE_OFFSET	0x20
468c2ecf20Sopenharmony_ci#define IFCVF_LM_BAR			4
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define IFCVF_ERR(pdev, fmt, ...)	dev_err(&pdev->dev, fmt, ##__VA_ARGS__)
498c2ecf20Sopenharmony_ci#define IFCVF_DBG(pdev, fmt, ...)	dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)
508c2ecf20Sopenharmony_ci#define IFCVF_INFO(pdev, fmt, ...)	dev_info(&pdev->dev, fmt, ##__VA_ARGS__)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define ifcvf_private_to_vf(adapter) \
538c2ecf20Sopenharmony_ci	(&((struct ifcvf_adapter *)adapter)->vf)
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define IFCVF_MAX_INTR (IFCVF_MAX_QUEUE_PAIRS * 2 + 1)
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistruct vring_info {
588c2ecf20Sopenharmony_ci	u64 desc;
598c2ecf20Sopenharmony_ci	u64 avail;
608c2ecf20Sopenharmony_ci	u64 used;
618c2ecf20Sopenharmony_ci	u16 size;
628c2ecf20Sopenharmony_ci	u16 last_avail_idx;
638c2ecf20Sopenharmony_ci	bool ready;
648c2ecf20Sopenharmony_ci	void __iomem *notify_addr;
658c2ecf20Sopenharmony_ci	u32 irq;
668c2ecf20Sopenharmony_ci	struct vdpa_callback cb;
678c2ecf20Sopenharmony_ci	char msix_name[256];
688c2ecf20Sopenharmony_ci};
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistruct ifcvf_hw {
718c2ecf20Sopenharmony_ci	u8 __iomem *isr;
728c2ecf20Sopenharmony_ci	/* Live migration */
738c2ecf20Sopenharmony_ci	u8 __iomem *lm_cfg;
748c2ecf20Sopenharmony_ci	u16 nr_vring;
758c2ecf20Sopenharmony_ci	/* Notification bar number */
768c2ecf20Sopenharmony_ci	u8 notify_bar;
778c2ecf20Sopenharmony_ci	/* Notificaiton bar address */
788c2ecf20Sopenharmony_ci	void __iomem *notify_base;
798c2ecf20Sopenharmony_ci	u32 notify_off_multiplier;
808c2ecf20Sopenharmony_ci	u64 req_features;
818c2ecf20Sopenharmony_ci	struct virtio_pci_common_cfg __iomem *common_cfg;
828c2ecf20Sopenharmony_ci	void __iomem *net_cfg;
838c2ecf20Sopenharmony_ci	struct vring_info vring[IFCVF_MAX_QUEUE_PAIRS * 2];
848c2ecf20Sopenharmony_ci	void __iomem * const *base;
858c2ecf20Sopenharmony_ci	char config_msix_name[256];
868c2ecf20Sopenharmony_ci	struct vdpa_callback config_cb;
878c2ecf20Sopenharmony_ci	unsigned int config_irq;
888c2ecf20Sopenharmony_ci};
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistruct ifcvf_adapter {
918c2ecf20Sopenharmony_ci	struct vdpa_device vdpa;
928c2ecf20Sopenharmony_ci	struct pci_dev *pdev;
938c2ecf20Sopenharmony_ci	struct ifcvf_hw vf;
948c2ecf20Sopenharmony_ci};
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistruct ifcvf_vring_lm_cfg {
978c2ecf20Sopenharmony_ci	u32 idx_addr[2];
988c2ecf20Sopenharmony_ci	u8 reserved[IFCVF_LM_CFG_SIZE - 8];
998c2ecf20Sopenharmony_ci};
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_cistruct ifcvf_lm_cfg {
1028c2ecf20Sopenharmony_ci	u8 reserved[IFCVF_LM_RING_STATE_OFFSET];
1038c2ecf20Sopenharmony_ci	struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUE_PAIRS];
1048c2ecf20Sopenharmony_ci};
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ciint ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev);
1078c2ecf20Sopenharmony_ciint ifcvf_start_hw(struct ifcvf_hw *hw);
1088c2ecf20Sopenharmony_civoid ifcvf_stop_hw(struct ifcvf_hw *hw);
1098c2ecf20Sopenharmony_civoid ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid);
1108c2ecf20Sopenharmony_civoid ifcvf_read_net_config(struct ifcvf_hw *hw, u64 offset,
1118c2ecf20Sopenharmony_ci			   void *dst, int length);
1128c2ecf20Sopenharmony_civoid ifcvf_write_net_config(struct ifcvf_hw *hw, u64 offset,
1138c2ecf20Sopenharmony_ci			    const void *src, int length);
1148c2ecf20Sopenharmony_ciu8 ifcvf_get_status(struct ifcvf_hw *hw);
1158c2ecf20Sopenharmony_civoid ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
1168c2ecf20Sopenharmony_civoid io_write64_twopart(u64 val, u32 *lo, u32 *hi);
1178c2ecf20Sopenharmony_civoid ifcvf_reset(struct ifcvf_hw *hw);
1188c2ecf20Sopenharmony_ciu64 ifcvf_get_features(struct ifcvf_hw *hw);
1198c2ecf20Sopenharmony_ciu16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
1208c2ecf20Sopenharmony_ciint ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
1218c2ecf20Sopenharmony_cistruct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
1228c2ecf20Sopenharmony_ci#endif /* _IFCVF_H_ */
123