ifcvf_base.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Intel IFC VF NIC driver for virtio dataplane offloading
  4. *
  5. * Copyright (C) 2020 Intel Corporation.
  6. *
  7. * Author: Zhu Lingshan <[email protected]>
  8. *
  9. */
  10. #ifndef _IFCVF_H_
  11. #define _IFCVF_H_
  12. #include <linux/pci.h>
  13. #include <linux/pci_regs.h>
  14. #include <linux/vdpa.h>
  15. #include <linux/virtio_pci_modern.h>
  16. #include <uapi/linux/virtio_net.h>
  17. #include <uapi/linux/virtio_blk.h>
  18. #include <uapi/linux/virtio_config.h>
  19. #include <uapi/linux/virtio_pci.h>
  20. #define N3000_DEVICE_ID 0x1041
  21. #define N3000_SUBSYS_DEVICE_ID 0x001A
  22. /* Max 8 data queue pairs(16 queues) and one control vq for now. */
  23. #define IFCVF_MAX_QUEUES 17
  24. #define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE
  25. #define IFCVF_QUEUE_MAX 32768
  26. #define IFCVF_PCI_MAX_RESOURCE 6
  27. #define IFCVF_LM_CFG_SIZE 0x40
  28. #define IFCVF_LM_RING_STATE_OFFSET 0x20
  29. #define IFCVF_LM_BAR 4
  30. #define IFCVF_ERR(pdev, fmt, ...) dev_err(&pdev->dev, fmt, ##__VA_ARGS__)
  31. #define IFCVF_DBG(pdev, fmt, ...) dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)
  32. #define IFCVF_INFO(pdev, fmt, ...) dev_info(&pdev->dev, fmt, ##__VA_ARGS__)
  33. #define ifcvf_private_to_vf(adapter) \
  34. (((struct ifcvf_adapter *)adapter)->vf)
  35. /* all vqs and config interrupt has its own vector */
  36. #define MSIX_VECTOR_PER_VQ_AND_CONFIG 1
  37. /* all vqs share a vector, and config interrupt has a separate vector */
  38. #define MSIX_VECTOR_SHARED_VQ_AND_CONFIG 2
  39. /* all vqs and config interrupt share a vector */
  40. #define MSIX_VECTOR_DEV_SHARED 3
  41. struct vring_info {
  42. u64 desc;
  43. u64 avail;
  44. u64 used;
  45. u16 size;
  46. u16 last_avail_idx;
  47. bool ready;
  48. void __iomem *notify_addr;
  49. phys_addr_t notify_pa;
  50. u32 irq;
  51. struct vdpa_callback cb;
  52. char msix_name[256];
  53. };
  54. struct ifcvf_hw {
  55. u8 __iomem *isr;
  56. /* Live migration */
  57. u8 __iomem *lm_cfg;
  58. /* Notification bar number */
  59. u8 notify_bar;
  60. u8 msix_vector_status;
  61. /* virtio-net or virtio-blk device config size */
  62. u32 config_size;
  63. /* Notificaiton bar address */
  64. void __iomem *notify_base;
  65. phys_addr_t notify_base_pa;
  66. u32 notify_off_multiplier;
  67. u32 dev_type;
  68. u64 req_features;
  69. u64 hw_features;
  70. struct virtio_pci_common_cfg __iomem *common_cfg;
  71. void __iomem *dev_cfg;
  72. struct vring_info vring[IFCVF_MAX_QUEUES];
  73. void __iomem * const *base;
  74. char config_msix_name[256];
  75. struct vdpa_callback config_cb;
  76. int config_irq;
  77. int vqs_reused_irq;
  78. u16 nr_vring;
  79. /* VIRTIO_PCI_CAP_DEVICE_CFG size */
  80. u32 cap_dev_config_size;
  81. struct pci_dev *pdev;
  82. };
  83. struct ifcvf_adapter {
  84. struct vdpa_device vdpa;
  85. struct pci_dev *pdev;
  86. struct ifcvf_hw *vf;
  87. };
  88. struct ifcvf_vring_lm_cfg {
  89. u32 idx_addr[2];
  90. u8 reserved[IFCVF_LM_CFG_SIZE - 8];
  91. };
  92. struct ifcvf_lm_cfg {
  93. u8 reserved[IFCVF_LM_RING_STATE_OFFSET];
  94. struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUES];
  95. };
  96. struct ifcvf_vdpa_mgmt_dev {
  97. struct vdpa_mgmt_dev mdev;
  98. struct ifcvf_hw vf;
  99. struct ifcvf_adapter *adapter;
  100. struct pci_dev *pdev;
  101. };
  102. int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev);
  103. int ifcvf_start_hw(struct ifcvf_hw *hw);
  104. void ifcvf_stop_hw(struct ifcvf_hw *hw);
  105. void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid);
  106. void ifcvf_read_dev_config(struct ifcvf_hw *hw, u64 offset,
  107. void *dst, int length);
  108. void ifcvf_write_dev_config(struct ifcvf_hw *hw, u64 offset,
  109. const void *src, int length);
  110. u8 ifcvf_get_status(struct ifcvf_hw *hw);
  111. void ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
  112. void io_write64_twopart(u64 val, u32 *lo, u32 *hi);
  113. void ifcvf_reset(struct ifcvf_hw *hw);
  114. u64 ifcvf_get_features(struct ifcvf_hw *hw);
  115. u64 ifcvf_get_hw_features(struct ifcvf_hw *hw);
  116. int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features);
  117. u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
  118. int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
  119. struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
  120. int ifcvf_probed_virtio_net(struct ifcvf_hw *hw);
  121. u32 ifcvf_get_config_size(struct ifcvf_hw *hw);
  122. u16 ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector);
  123. u16 ifcvf_set_config_vector(struct ifcvf_hw *hw, int vector);
  124. #endif /* _IFCVF_H_ */