virtio: kdoc for struct virtio_pci_modern_device
[sfrench/cifs-2.6.git] / include / linux / virtio_pci_modern.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_VIRTIO_PCI_MODERN_H
3 #define _LINUX_VIRTIO_PCI_MODERN_H
4
5 #include <linux/pci.h>
6 #include <linux/virtio_pci.h>
7
8 struct virtio_pci_modern_common_cfg {
9         struct virtio_pci_common_cfg cfg;
10
11         __le16 queue_notify_data;       /* read-write */
12         __le16 queue_reset;             /* read-write */
13 };
14
15 /**
16  * struct virtio_pci_modern_device - info for modern PCI virtio
17  * @pci_dev:        Ptr to the PCI device struct
18  * @common:         Position of the common capability in the PCI config
19  * @device:         Device-specific data (non-legacy mode)
20  * @notify_base:    Base of vq notifications (non-legacy mode)
21  * @notify_pa:      Physical base of vq notifications
22  * @isr:            Where to read and clear interrupt
23  * @notify_len:     So we can sanity-check accesses
24  * @device_len:     So we can sanity-check accesses
25  * @notify_map_cap: Capability for when we need to map notifications per-vq
26  * @notify_offset_multiplier: Multiply queue_notify_off by this value
27  *                            (non-legacy mode).
28  * @modern_bars:    Bitmask of BARs
29  * @id:             Device and vendor id
30  * @device_id_check: Callback defined before vp_modern_probe() to be used to
31  *                  verify the PCI device is a vendor's expected device rather
32  *                  than the standard virtio PCI device
33  *                  Returns the found device id or ERRNO
34  * @dma_mask:       Optional mask instead of the traditional DMA_BIT_MASK(64),
35  *                  for vendor devices with DMA space address limitations
36  */
37 struct virtio_pci_modern_device {
38         struct pci_dev *pci_dev;
39
40         struct virtio_pci_common_cfg __iomem *common;
41         void __iomem *device;
42         void __iomem *notify_base;
43         resource_size_t notify_pa;
44         u8 __iomem *isr;
45
46         size_t notify_len;
47         size_t device_len;
48
49         int notify_map_cap;
50
51         u32 notify_offset_multiplier;
52         int modern_bars;
53         struct virtio_device_id id;
54
55         int (*device_id_check)(struct pci_dev *pdev);
56         u64 dma_mask;
57 };
58
59 /*
60  * Type-safe wrappers for io accesses.
61  * Use these to enforce at compile time the following spec requirement:
62  *
63  * The driver MUST access each field using the “natural” access
64  * method, i.e. 32-bit accesses for 32-bit fields, 16-bit accesses
65  * for 16-bit fields and 8-bit accesses for 8-bit fields.
66  */
67 static inline u8 vp_ioread8(const u8 __iomem *addr)
68 {
69         return ioread8(addr);
70 }
71 static inline u16 vp_ioread16 (const __le16 __iomem *addr)
72 {
73         return ioread16(addr);
74 }
75
76 static inline u32 vp_ioread32(const __le32 __iomem *addr)
77 {
78         return ioread32(addr);
79 }
80
81 static inline void vp_iowrite8(u8 value, u8 __iomem *addr)
82 {
83         iowrite8(value, addr);
84 }
85
86 static inline void vp_iowrite16(u16 value, __le16 __iomem *addr)
87 {
88         iowrite16(value, addr);
89 }
90
91 static inline void vp_iowrite32(u32 value, __le32 __iomem *addr)
92 {
93         iowrite32(value, addr);
94 }
95
96 static inline void vp_iowrite64_twopart(u64 val,
97                                         __le32 __iomem *lo,
98                                         __le32 __iomem *hi)
99 {
100         vp_iowrite32((u32)val, lo);
101         vp_iowrite32(val >> 32, hi);
102 }
103
104 u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev);
105 u64 vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev);
106 void vp_modern_set_features(struct virtio_pci_modern_device *mdev,
107                      u64 features);
108 u32 vp_modern_generation(struct virtio_pci_modern_device *mdev);
109 u8 vp_modern_get_status(struct virtio_pci_modern_device *mdev);
110 void vp_modern_set_status(struct virtio_pci_modern_device *mdev,
111                    u8 status);
112 u16 vp_modern_queue_vector(struct virtio_pci_modern_device *mdev,
113                            u16 idx, u16 vector);
114 u16 vp_modern_config_vector(struct virtio_pci_modern_device *mdev,
115                      u16 vector);
116 void vp_modern_queue_address(struct virtio_pci_modern_device *mdev,
117                              u16 index, u64 desc_addr, u64 driver_addr,
118                              u64 device_addr);
119 void vp_modern_set_queue_enable(struct virtio_pci_modern_device *mdev,
120                                 u16 idx, bool enable);
121 bool vp_modern_get_queue_enable(struct virtio_pci_modern_device *mdev,
122                                 u16 idx);
123 void vp_modern_set_queue_size(struct virtio_pci_modern_device *mdev,
124                               u16 idx, u16 size);
125 u16 vp_modern_get_queue_size(struct virtio_pci_modern_device *mdev,
126                              u16 idx);
127 u16 vp_modern_get_num_queues(struct virtio_pci_modern_device *mdev);
128 void __iomem * vp_modern_map_vq_notify(struct virtio_pci_modern_device *mdev,
129                                        u16 index, resource_size_t *pa);
130 int vp_modern_probe(struct virtio_pci_modern_device *mdev);
131 void vp_modern_remove(struct virtio_pci_modern_device *mdev);
132 int vp_modern_get_queue_reset(struct virtio_pci_modern_device *mdev, u16 index);
133 void vp_modern_set_queue_reset(struct virtio_pci_modern_device *mdev, u16 index);
134 #endif