Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[platform/kernel/linux-rpi.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 struct virtio_pci_modern_device {
16         struct pci_dev *pci_dev;
17
18         struct virtio_pci_common_cfg __iomem *common;
19         /* Device-specific data (non-legacy mode)  */
20         void __iomem *device;
21         /* Base of vq notifications (non-legacy mode). */
22         void __iomem *notify_base;
23         /* Physical base of vq notifications */
24         resource_size_t notify_pa;
25         /* Where to read and clear interrupt */
26         u8 __iomem *isr;
27
28         /* So we can sanity-check accesses. */
29         size_t notify_len;
30         size_t device_len;
31
32         /* Capability for when we need to map notifications per-vq. */
33         int notify_map_cap;
34
35         /* Multiply queue_notify_off by this value. (non-legacy mode). */
36         u32 notify_offset_multiplier;
37
38         int modern_bars;
39
40         struct virtio_device_id id;
41
42         /* optional check for vendor virtio device, returns dev_id or -ERRNO */
43         int (*device_id_check)(struct pci_dev *pdev);
44
45         /* optional mask for devices with limited DMA space */
46         u64 dma_mask;
47 };
48
49 /*
50  * Type-safe wrappers for io accesses.
51  * Use these to enforce at compile time the following spec requirement:
52  *
53  * The driver MUST access each field using the “natural” access
54  * method, i.e. 32-bit accesses for 32-bit fields, 16-bit accesses
55  * for 16-bit fields and 8-bit accesses for 8-bit fields.
56  */
57 static inline u8 vp_ioread8(const u8 __iomem *addr)
58 {
59         return ioread8(addr);
60 }
61 static inline u16 vp_ioread16 (const __le16 __iomem *addr)
62 {
63         return ioread16(addr);
64 }
65
66 static inline u32 vp_ioread32(const __le32 __iomem *addr)
67 {
68         return ioread32(addr);
69 }
70
71 static inline void vp_iowrite8(u8 value, u8 __iomem *addr)
72 {
73         iowrite8(value, addr);
74 }
75
76 static inline void vp_iowrite16(u16 value, __le16 __iomem *addr)
77 {
78         iowrite16(value, addr);
79 }
80
81 static inline void vp_iowrite32(u32 value, __le32 __iomem *addr)
82 {
83         iowrite32(value, addr);
84 }
85
86 static inline void vp_iowrite64_twopart(u64 val,
87                                         __le32 __iomem *lo,
88                                         __le32 __iomem *hi)
89 {
90         vp_iowrite32((u32)val, lo);
91         vp_iowrite32(val >> 32, hi);
92 }
93
94 u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev);
95 u64 vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev);
96 void vp_modern_set_features(struct virtio_pci_modern_device *mdev,
97                      u64 features);
98 u32 vp_modern_generation(struct virtio_pci_modern_device *mdev);
99 u8 vp_modern_get_status(struct virtio_pci_modern_device *mdev);
100 void vp_modern_set_status(struct virtio_pci_modern_device *mdev,
101                    u8 status);
102 u16 vp_modern_queue_vector(struct virtio_pci_modern_device *mdev,
103                            u16 idx, u16 vector);
104 u16 vp_modern_config_vector(struct virtio_pci_modern_device *mdev,
105                      u16 vector);
106 void vp_modern_queue_address(struct virtio_pci_modern_device *mdev,
107                              u16 index, u64 desc_addr, u64 driver_addr,
108                              u64 device_addr);
109 void vp_modern_set_queue_enable(struct virtio_pci_modern_device *mdev,
110                                 u16 idx, bool enable);
111 bool vp_modern_get_queue_enable(struct virtio_pci_modern_device *mdev,
112                                 u16 idx);
113 void vp_modern_set_queue_size(struct virtio_pci_modern_device *mdev,
114                               u16 idx, u16 size);
115 u16 vp_modern_get_queue_size(struct virtio_pci_modern_device *mdev,
116                              u16 idx);
117 u16 vp_modern_get_num_queues(struct virtio_pci_modern_device *mdev);
118 void __iomem * vp_modern_map_vq_notify(struct virtio_pci_modern_device *mdev,
119                                        u16 index, resource_size_t *pa);
120 int vp_modern_probe(struct virtio_pci_modern_device *mdev);
121 void vp_modern_remove(struct virtio_pci_modern_device *mdev);
122 int vp_modern_get_queue_reset(struct virtio_pci_modern_device *mdev, u16 index);
123 void vp_modern_set_queue_reset(struct virtio_pci_modern_device *mdev, u16 index);
124 #endif