ifcvf_base.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <lingshan.zhu@intel.com>
  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 <uapi/linux/virtio_net.h>
  16. #include <uapi/linux/virtio_config.h>
  17. #include <uapi/linux/virtio_pci.h>
  18. #define IFCVF_VENDOR_ID 0x1AF4
  19. #define IFCVF_DEVICE_ID 0x1041
  20. #define IFCVF_SUBSYS_VENDOR_ID 0x8086
  21. #define IFCVF_SUBSYS_DEVICE_ID 0x001A
  22. #define IFCVF_SUPPORTED_FEATURES \
  23. ((1ULL << VIRTIO_NET_F_MAC) | \
  24. (1ULL << VIRTIO_F_ANY_LAYOUT) | \
  25. (1ULL << VIRTIO_F_VERSION_1) | \
  26. (1ULL << VIRTIO_NET_F_STATUS) | \
  27. (1ULL << VIRTIO_F_ORDER_PLATFORM) | \
  28. (1ULL << VIRTIO_F_ACCESS_PLATFORM) | \
  29. (1ULL << VIRTIO_NET_F_MRG_RXBUF))
  30. /* Only one queue pair for now. */
  31. #define IFCVF_MAX_QUEUE_PAIRS 1
  32. #define IFCVF_QUEUE_ALIGNMENT PAGE_SIZE
  33. #define IFCVF_QUEUE_MAX 32768
  34. #define IFCVF_MSI_CONFIG_OFF 0
  35. #define IFCVF_MSI_QUEUE_OFF 1
  36. #define IFCVF_PCI_MAX_RESOURCE 6
  37. #define IFCVF_LM_CFG_SIZE 0x40
  38. #define IFCVF_LM_RING_STATE_OFFSET 0x20
  39. #define IFCVF_LM_BAR 4
  40. #define IFCVF_ERR(pdev, fmt, ...) dev_err(&pdev->dev, fmt, ##__VA_ARGS__)
  41. #define IFCVF_DBG(pdev, fmt, ...) dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)
  42. #define IFCVF_INFO(pdev, fmt, ...) dev_info(&pdev->dev, fmt, ##__VA_ARGS__)
  43. #define ifcvf_private_to_vf(adapter) \
  44. (&((struct ifcvf_adapter *)adapter)->vf)
  45. #define IFCVF_MAX_INTR (IFCVF_MAX_QUEUE_PAIRS * 2 + 1)
  46. struct vring_info {
  47. u64 desc;
  48. u64 avail;
  49. u64 used;
  50. u16 size;
  51. u16 last_avail_idx;
  52. bool ready;
  53. void __iomem *notify_addr;
  54. u32 irq;
  55. struct vdpa_callback cb;
  56. char msix_name[256];
  57. };
  58. struct ifcvf_hw {
  59. u8 __iomem *isr;
  60. /* Live migration */
  61. u8 __iomem *lm_cfg;
  62. u16 nr_vring;
  63. /* Notification bar number */
  64. u8 notify_bar;
  65. /* Notificaiton bar address */
  66. void __iomem *notify_base;
  67. u32 notify_off_multiplier;
  68. u64 req_features;
  69. struct virtio_pci_common_cfg __iomem *common_cfg;
  70. void __iomem *net_cfg;
  71. struct vring_info vring[IFCVF_MAX_QUEUE_PAIRS * 2];
  72. void __iomem * const *base;
  73. char config_msix_name[256];
  74. struct vdpa_callback config_cb;
  75. unsigned int config_irq;
  76. };
  77. struct ifcvf_adapter {
  78. struct vdpa_device vdpa;
  79. struct pci_dev *pdev;
  80. struct ifcvf_hw vf;
  81. };
  82. struct ifcvf_vring_lm_cfg {
  83. u32 idx_addr[2];
  84. u8 reserved[IFCVF_LM_CFG_SIZE - 8];
  85. };
  86. struct ifcvf_lm_cfg {
  87. u8 reserved[IFCVF_LM_RING_STATE_OFFSET];
  88. struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUE_PAIRS];
  89. };
  90. int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev);
  91. int ifcvf_start_hw(struct ifcvf_hw *hw);
  92. void ifcvf_stop_hw(struct ifcvf_hw *hw);
  93. void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid);
  94. void ifcvf_read_net_config(struct ifcvf_hw *hw, u64 offset,
  95. void *dst, int length);
  96. void ifcvf_write_net_config(struct ifcvf_hw *hw, u64 offset,
  97. const void *src, int length);
  98. u8 ifcvf_get_status(struct ifcvf_hw *hw);
  99. void ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
  100. void io_write64_twopart(u64 val, u32 *lo, u32 *hi);
  101. void ifcvf_reset(struct ifcvf_hw *hw);
  102. u64 ifcvf_get_features(struct ifcvf_hw *hw);
  103. u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
  104. int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
  105. struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
  106. #endif /* _IFCVF_H_ */