2020-03-26 22:01:25 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/*
|
|
|
|
* Intel IFC VF NIC driver for virtio dataplane offloading
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Intel Corporation.
|
|
|
|
*
|
|
|
|
* Author: Zhu Lingshan <lingshan.zhu@intel.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _IFCVF_H_
|
|
|
|
#define _IFCVF_H_
|
|
|
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/pci_regs.h>
|
|
|
|
#include <linux/vdpa.h>
|
2022-02-22 19:54:24 +08:00
|
|
|
#include <linux/virtio_pci_modern.h>
|
2020-03-26 22:01:25 +08:00
|
|
|
#include <uapi/linux/virtio_net.h>
|
2021-04-19 14:33:25 +08:00
|
|
|
#include <uapi/linux/virtio_blk.h>
|
2020-03-26 22:01:25 +08:00
|
|
|
#include <uapi/linux/virtio_config.h>
|
|
|
|
#include <uapi/linux/virtio_pci.h>
|
2022-11-25 22:57:24 +08:00
|
|
|
#include <uapi/linux/vdpa.h>
|
2020-03-26 22:01:25 +08:00
|
|
|
|
2021-03-17 17:49:29 +08:00
|
|
|
#define N3000_DEVICE_ID 0x1041
|
|
|
|
#define N3000_SUBSYS_DEVICE_ID 0x001A
|
2020-03-26 22:01:25 +08:00
|
|
|
|
|
|
|
#define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE
|
|
|
|
#define IFCVF_PCI_MAX_RESOURCE 6
|
|
|
|
|
|
|
|
#define IFCVF_LM_BAR 4
|
2024-02-03 00:39:05 +08:00
|
|
|
#define IFCVF_MIN_VQ_SIZE 64
|
2020-03-26 22:01:25 +08:00
|
|
|
|
|
|
|
#define IFCVF_ERR(pdev, fmt, ...) dev_err(&pdev->dev, fmt, ##__VA_ARGS__)
|
|
|
|
#define IFCVF_DBG(pdev, fmt, ...) dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)
|
|
|
|
#define IFCVF_INFO(pdev, fmt, ...) dev_info(&pdev->dev, fmt, ##__VA_ARGS__)
|
|
|
|
|
vDPA/ifcvf: implement shared IRQ feature
On some platforms/devices, there may not be enough MSI vectors
allocated for the virtqueues and config changes. In such a case,
the interrupt sources(virtqueues, config changes) must share
an IRQ/vector, to avoid initialization failures, keep
the device functional.
This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1
(config changes), every virtqueue and the config interrupt has
a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but
greater than 1. In this case, all virtqueues share a vector/IRQ,
the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and
the config interrupt share a vector/IRQ. The worst and most
unlikely case.
Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector() and ifcvf_set_config_vector() sets virtqueue
vector and config vector in the device config space, so that
the device can send interrupt DMA.
Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com>
Link: https://lore.kernel.org/r/20220222115428.998334-5-lingshan.zhu@intel.com
Signed-off-by: Tom Rix <trix@redhat.com>
Link: https://lore.kernel.org/r/20220315124130.1710030-1-trix@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2022-02-22 19:54:27 +08:00
|
|
|
/* all vqs and config interrupt has its own vector */
|
|
|
|
#define MSIX_VECTOR_PER_VQ_AND_CONFIG 1
|
|
|
|
/* all vqs share a vector, and config interrupt has a separate vector */
|
|
|
|
#define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2
|
|
|
|
/* all vqs and config interrupt share a vector */
|
|
|
|
#define MSIX_VECTOR_DEV_SHARED 3
|
|
|
|
|
2020-03-26 22:01:25 +08:00
|
|
|
struct vring_info {
|
|
|
|
u16 last_avail_idx;
|
|
|
|
void __iomem *notify_addr;
|
2021-06-02 16:45:49 +08:00
|
|
|
phys_addr_t notify_pa;
|
2020-03-26 22:01:25 +08:00
|
|
|
u32 irq;
|
|
|
|
struct vdpa_callback cb;
|
|
|
|
char msix_name[256];
|
|
|
|
};
|
|
|
|
|
2023-06-12 23:14:20 +08:00
|
|
|
struct ifcvf_lm_cfg {
|
|
|
|
__le64 control;
|
|
|
|
__le64 status;
|
|
|
|
__le64 lm_mem_log_start_addr;
|
|
|
|
__le64 lm_mem_log_end_addr;
|
|
|
|
__le16 vq_state_region;
|
|
|
|
};
|
|
|
|
|
2020-03-26 22:01:25 +08:00
|
|
|
struct ifcvf_hw {
|
|
|
|
u8 __iomem *isr;
|
|
|
|
/* Live migration */
|
2023-06-12 23:14:20 +08:00
|
|
|
struct ifcvf_lm_cfg __iomem *lm_cfg;
|
2020-03-26 22:01:25 +08:00
|
|
|
/* Notification bar number */
|
|
|
|
u8 notify_bar;
|
2022-02-22 19:54:28 +08:00
|
|
|
u8 msix_vector_status;
|
|
|
|
/* virtio-net or virtio-blk device config size */
|
|
|
|
u32 config_size;
|
2020-03-26 22:01:25 +08:00
|
|
|
/* Notificaiton bar address */
|
|
|
|
void __iomem *notify_base;
|
2021-06-02 16:45:49 +08:00
|
|
|
phys_addr_t notify_base_pa;
|
2020-03-26 22:01:25 +08:00
|
|
|
u32 notify_off_multiplier;
|
2022-02-22 19:54:28 +08:00
|
|
|
u32 dev_type;
|
2021-03-17 17:49:31 +08:00
|
|
|
u64 hw_features;
|
2022-11-25 22:57:24 +08:00
|
|
|
/* provisioned device features */
|
|
|
|
u64 dev_features;
|
2020-03-26 22:01:25 +08:00
|
|
|
struct virtio_pci_common_cfg __iomem *common_cfg;
|
2021-12-01 16:12:55 +08:00
|
|
|
void __iomem *dev_cfg;
|
2023-06-12 23:14:18 +08:00
|
|
|
struct vring_info *vring;
|
2020-03-26 22:01:25 +08:00
|
|
|
void __iomem * const *base;
|
2020-06-05 18:27:15 +08:00
|
|
|
char config_msix_name[256];
|
|
|
|
struct vdpa_callback config_cb;
|
vDPA/ifcvf: implement shared IRQ feature
On some platforms/devices, there may not be enough MSI vectors
allocated for the virtqueues and config changes. In such a case,
the interrupt sources(virtqueues, config changes) must share
an IRQ/vector, to avoid initialization failures, keep
the device functional.
This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1
(config changes), every virtqueue and the config interrupt has
a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but
greater than 1. In this case, all virtqueues share a vector/IRQ,
the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and
the config interrupt share a vector/IRQ. The worst and most
unlikely case.
Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector() and ifcvf_set_config_vector() sets virtqueue
vector and config vector in the device config space, so that
the device can send interrupt DMA.
Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com>
Link: https://lore.kernel.org/r/20220222115428.998334-5-lingshan.zhu@intel.com
Signed-off-by: Tom Rix <trix@redhat.com>
Link: https://lore.kernel.org/r/20220315124130.1710030-1-trix@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2022-02-22 19:54:27 +08:00
|
|
|
int config_irq;
|
|
|
|
int vqs_reused_irq;
|
2022-02-22 19:54:28 +08:00
|
|
|
u16 nr_vring;
|
2022-07-22 19:53:04 +08:00
|
|
|
/* VIRTIO_PCI_CAP_DEVICE_CFG size */
|
2023-05-26 22:52:53 +08:00
|
|
|
u32 num_msix_vectors;
|
2022-07-22 19:53:04 +08:00
|
|
|
u32 cap_dev_config_size;
|
2022-11-25 22:57:13 +08:00
|
|
|
struct pci_dev *pdev;
|
2020-03-26 22:01:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ifcvf_adapter {
|
|
|
|
struct vdpa_device vdpa;
|
|
|
|
struct pci_dev *pdev;
|
2022-11-25 22:57:21 +08:00
|
|
|
struct ifcvf_hw *vf;
|
2020-03-26 22:01:25 +08:00
|
|
|
};
|
|
|
|
|
2021-08-12 11:24:54 +08:00
|
|
|
struct ifcvf_vdpa_mgmt_dev {
|
|
|
|
struct vdpa_mgmt_dev mdev;
|
2022-11-25 22:57:21 +08:00
|
|
|
struct ifcvf_hw vf;
|
2021-08-12 11:24:54 +08:00
|
|
|
struct ifcvf_adapter *adapter;
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
};
|
|
|
|
|
2020-03-26 22:01:25 +08:00
|
|
|
int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev);
|
2023-05-26 22:52:53 +08:00
|
|
|
void ifcvf_stop(struct ifcvf_hw *hw);
|
2020-03-26 22:01:25 +08:00
|
|
|
void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid);
|
2021-12-01 16:12:55 +08:00
|
|
|
void ifcvf_read_dev_config(struct ifcvf_hw *hw, u64 offset,
|
2020-03-26 22:01:25 +08:00
|
|
|
void *dst, int length);
|
2021-12-01 16:12:55 +08:00
|
|
|
void ifcvf_write_dev_config(struct ifcvf_hw *hw, u64 offset,
|
2020-03-26 22:01:25 +08:00
|
|
|
const void *src, int length);
|
|
|
|
u8 ifcvf_get_status(struct ifcvf_hw *hw);
|
|
|
|
void ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
|
|
|
|
void ifcvf_reset(struct ifcvf_hw *hw);
|
2023-05-26 22:52:51 +08:00
|
|
|
u64 ifcvf_get_dev_features(struct ifcvf_hw *hw);
|
2021-03-17 17:49:31 +08:00
|
|
|
u64 ifcvf_get_hw_features(struct ifcvf_hw *hw);
|
2021-03-17 17:49:32 +08:00
|
|
|
int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features);
|
2020-08-04 19:20:43 +03:00
|
|
|
u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
|
|
|
|
int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
|
2021-12-01 16:12:55 +08:00
|
|
|
u32 ifcvf_get_config_size(struct ifcvf_hw *hw);
|
vDPA/ifcvf: implement shared IRQ feature
On some platforms/devices, there may not be enough MSI vectors
allocated for the virtqueues and config changes. In such a case,
the interrupt sources(virtqueues, config changes) must share
an IRQ/vector, to avoid initialization failures, keep
the device functional.
This commit handles three cases:
(1) number of the allocated vectors == the number of virtqueues + 1
(config changes), every virtqueue and the config interrupt has
a separated vector/IRQ, the best and the most likely case.
(2) number of the allocated vectors is less than the best case, but
greater than 1. In this case, all virtqueues share a vector/IRQ,
the config interrupt has a separated vector/IRQ
(3) only one vector is allocated, in this case, the virtqueues and
the config interrupt share a vector/IRQ. The worst and most
unlikely case.
Otherwise, it needs to fail.
This commit introduces some helper functions:
ifcvf_set_vq_vector() and ifcvf_set_config_vector() sets virtqueue
vector and config vector in the device config space, so that
the device can send interrupt DMA.
Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com>
Link: https://lore.kernel.org/r/20220222115428.998334-5-lingshan.zhu@intel.com
Signed-off-by: Tom Rix <trix@redhat.com>
Link: https://lore.kernel.org/r/20220315124130.1710030-1-trix@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2022-02-22 19:54:27 +08:00
|
|
|
u16 ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector);
|
|
|
|
u16 ifcvf_set_config_vector(struct ifcvf_hw *hw, int vector);
|
2023-05-26 22:52:50 +08:00
|
|
|
void ifcvf_set_vq_num(struct ifcvf_hw *hw, u16 qid, u32 num);
|
|
|
|
int ifcvf_set_vq_address(struct ifcvf_hw *hw, u16 qid, u64 desc_area,
|
|
|
|
u64 driver_area, u64 device_area);
|
|
|
|
bool ifcvf_get_vq_ready(struct ifcvf_hw *hw, u16 qid);
|
|
|
|
void ifcvf_set_vq_ready(struct ifcvf_hw *hw, u16 qid, bool ready);
|
2023-05-26 22:52:51 +08:00
|
|
|
void ifcvf_set_driver_features(struct ifcvf_hw *hw, u64 features);
|
|
|
|
u64 ifcvf_get_driver_features(struct ifcvf_hw *hw);
|
2023-06-12 23:14:19 +08:00
|
|
|
u16 ifcvf_get_max_vq_size(struct ifcvf_hw *hw);
|
2024-02-03 00:38:58 +08:00
|
|
|
u16 ifcvf_get_vq_size(struct ifcvf_hw *hw, u16 qid);
|
2020-03-26 22:01:25 +08:00
|
|
|
#endif /* _IFCVF_H_ */
|