162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Intel IFC VF NIC driver for virtio dataplane offloading 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2020 Intel Corporation. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Author: Zhu Lingshan <lingshan.zhu@intel.com> 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#ifndef _IFCVF_H_ 1262306a36Sopenharmony_ci#define _IFCVF_H_ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <linux/pci.h> 1562306a36Sopenharmony_ci#include <linux/pci_regs.h> 1662306a36Sopenharmony_ci#include <linux/vdpa.h> 1762306a36Sopenharmony_ci#include <linux/virtio_pci_modern.h> 1862306a36Sopenharmony_ci#include <uapi/linux/virtio_net.h> 1962306a36Sopenharmony_ci#include <uapi/linux/virtio_blk.h> 2062306a36Sopenharmony_ci#include <uapi/linux/virtio_config.h> 2162306a36Sopenharmony_ci#include <uapi/linux/virtio_pci.h> 2262306a36Sopenharmony_ci#include <uapi/linux/vdpa.h> 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#define N3000_DEVICE_ID 0x1041 2562306a36Sopenharmony_ci#define N3000_SUBSYS_DEVICE_ID 0x001A 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE 2862306a36Sopenharmony_ci#define IFCVF_PCI_MAX_RESOURCE 6 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci#define IFCVF_LM_BAR 4 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#define IFCVF_ERR(pdev, fmt, ...) dev_err(&pdev->dev, fmt, ##__VA_ARGS__) 3362306a36Sopenharmony_ci#define IFCVF_DBG(pdev, fmt, ...) dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__) 3462306a36Sopenharmony_ci#define IFCVF_INFO(pdev, fmt, ...) dev_info(&pdev->dev, fmt, ##__VA_ARGS__) 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci/* all vqs and config interrupt has its own vector */ 3762306a36Sopenharmony_ci#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1 3862306a36Sopenharmony_ci/* all vqs share a vector, and config interrupt has a separate vector */ 3962306a36Sopenharmony_ci#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2 4062306a36Sopenharmony_ci/* all vqs and config interrupt share a vector */ 4162306a36Sopenharmony_ci#define MSIX_VECTOR_DEV_SHARED 3 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_cistruct vring_info { 4462306a36Sopenharmony_ci u16 last_avail_idx; 4562306a36Sopenharmony_ci void __iomem *notify_addr; 4662306a36Sopenharmony_ci phys_addr_t notify_pa; 4762306a36Sopenharmony_ci u32 irq; 4862306a36Sopenharmony_ci struct vdpa_callback cb; 4962306a36Sopenharmony_ci char msix_name[256]; 5062306a36Sopenharmony_ci}; 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_cistruct ifcvf_lm_cfg { 5362306a36Sopenharmony_ci __le64 control; 5462306a36Sopenharmony_ci __le64 status; 5562306a36Sopenharmony_ci __le64 lm_mem_log_start_addr; 5662306a36Sopenharmony_ci __le64 lm_mem_log_end_addr; 5762306a36Sopenharmony_ci __le16 vq_state_region; 5862306a36Sopenharmony_ci}; 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_cistruct ifcvf_hw { 6162306a36Sopenharmony_ci u8 __iomem *isr; 6262306a36Sopenharmony_ci /* Live migration */ 6362306a36Sopenharmony_ci struct ifcvf_lm_cfg __iomem *lm_cfg; 6462306a36Sopenharmony_ci /* Notification bar number */ 6562306a36Sopenharmony_ci u8 notify_bar; 6662306a36Sopenharmony_ci u8 msix_vector_status; 6762306a36Sopenharmony_ci /* virtio-net or virtio-blk device config size */ 6862306a36Sopenharmony_ci u32 config_size; 6962306a36Sopenharmony_ci /* Notificaiton bar address */ 7062306a36Sopenharmony_ci void __iomem *notify_base; 7162306a36Sopenharmony_ci phys_addr_t notify_base_pa; 7262306a36Sopenharmony_ci u32 notify_off_multiplier; 7362306a36Sopenharmony_ci u32 dev_type; 7462306a36Sopenharmony_ci u64 hw_features; 7562306a36Sopenharmony_ci /* provisioned device features */ 7662306a36Sopenharmony_ci u64 dev_features; 7762306a36Sopenharmony_ci struct virtio_pci_common_cfg __iomem *common_cfg; 7862306a36Sopenharmony_ci void __iomem *dev_cfg; 7962306a36Sopenharmony_ci struct vring_info *vring; 8062306a36Sopenharmony_ci void __iomem * const *base; 8162306a36Sopenharmony_ci char config_msix_name[256]; 8262306a36Sopenharmony_ci struct vdpa_callback config_cb; 8362306a36Sopenharmony_ci int config_irq; 8462306a36Sopenharmony_ci int vqs_reused_irq; 8562306a36Sopenharmony_ci u16 nr_vring; 8662306a36Sopenharmony_ci /* VIRTIO_PCI_CAP_DEVICE_CFG size */ 8762306a36Sopenharmony_ci u32 num_msix_vectors; 8862306a36Sopenharmony_ci u32 cap_dev_config_size; 8962306a36Sopenharmony_ci struct pci_dev *pdev; 9062306a36Sopenharmony_ci}; 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_cistruct ifcvf_adapter { 9362306a36Sopenharmony_ci struct vdpa_device vdpa; 9462306a36Sopenharmony_ci struct pci_dev *pdev; 9562306a36Sopenharmony_ci struct ifcvf_hw *vf; 9662306a36Sopenharmony_ci}; 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_cistruct ifcvf_vdpa_mgmt_dev { 9962306a36Sopenharmony_ci struct vdpa_mgmt_dev mdev; 10062306a36Sopenharmony_ci struct ifcvf_hw vf; 10162306a36Sopenharmony_ci struct ifcvf_adapter *adapter; 10262306a36Sopenharmony_ci struct pci_dev *pdev; 10362306a36Sopenharmony_ci}; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ciint ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev); 10662306a36Sopenharmony_civoid ifcvf_stop(struct ifcvf_hw *hw); 10762306a36Sopenharmony_civoid ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid); 10862306a36Sopenharmony_civoid ifcvf_read_dev_config(struct ifcvf_hw *hw, u64 offset, 10962306a36Sopenharmony_ci void *dst, int length); 11062306a36Sopenharmony_civoid ifcvf_write_dev_config(struct ifcvf_hw *hw, u64 offset, 11162306a36Sopenharmony_ci const void *src, int length); 11262306a36Sopenharmony_ciu8 ifcvf_get_status(struct ifcvf_hw *hw); 11362306a36Sopenharmony_civoid ifcvf_set_status(struct ifcvf_hw *hw, u8 status); 11462306a36Sopenharmony_civoid io_write64_twopart(u64 val, u32 *lo, u32 *hi); 11562306a36Sopenharmony_civoid ifcvf_reset(struct ifcvf_hw *hw); 11662306a36Sopenharmony_ciu64 ifcvf_get_dev_features(struct ifcvf_hw *hw); 11762306a36Sopenharmony_ciu64 ifcvf_get_hw_features(struct ifcvf_hw *hw); 11862306a36Sopenharmony_ciint ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features); 11962306a36Sopenharmony_ciu16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid); 12062306a36Sopenharmony_ciint ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num); 12162306a36Sopenharmony_cistruct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw); 12262306a36Sopenharmony_ciint ifcvf_probed_virtio_net(struct ifcvf_hw *hw); 12362306a36Sopenharmony_ciu32 ifcvf_get_config_size(struct ifcvf_hw *hw); 12462306a36Sopenharmony_ciu16 ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector); 12562306a36Sopenharmony_ciu16 ifcvf_set_config_vector(struct ifcvf_hw *hw, int vector); 12662306a36Sopenharmony_civoid ifcvf_set_vq_num(struct ifcvf_hw *hw, u16 qid, u32 num); 12762306a36Sopenharmony_ciint ifcvf_set_vq_address(struct ifcvf_hw *hw, u16 qid, u64 desc_area, 12862306a36Sopenharmony_ci u64 driver_area, u64 device_area); 12962306a36Sopenharmony_cibool ifcvf_get_vq_ready(struct ifcvf_hw *hw, u16 qid); 13062306a36Sopenharmony_civoid ifcvf_set_vq_ready(struct ifcvf_hw *hw, u16 qid, bool ready); 13162306a36Sopenharmony_civoid ifcvf_set_driver_features(struct ifcvf_hw *hw, u64 features); 13262306a36Sopenharmony_ciu64 ifcvf_get_driver_features(struct ifcvf_hw *hw); 13362306a36Sopenharmony_ciu16 ifcvf_get_max_vq_size(struct ifcvf_hw *hw); 13462306a36Sopenharmony_ci#endif /* _IFCVF_H_ */ 135