xref: /linux/drivers/vdpa/octeon_ep/octep_vdpa.h (revision a3a02a52bcfcbcc4a637d4b68bf1bc391c9fad02)
1 /* SPDX-License-Identifier: GPL-2.0-only
2  * Copyright (C) 2024 Marvell.
3  */
4 #ifndef __OCTEP_VDPA_H__
5 #define __OCTEP_VDPA_H__
6 
7 #include <linux/pci.h>
8 #include <linux/pci_regs.h>
9 #include <linux/vdpa.h>
10 #include <linux/virtio_pci_modern.h>
11 #include <uapi/linux/virtio_net.h>
12 #include <uapi/linux/virtio_blk.h>
13 #include <uapi/linux/virtio_config.h>
14 #include <uapi/linux/virtio_pci.h>
15 #include <uapi/linux/vdpa.h>
16 
17 #define OCTEP_VDPA_DEVID_CN106K_PF 0xb900
18 #define OCTEP_VDPA_DEVID_CN106K_VF 0xb903
19 #define OCTEP_VDPA_DEVID_CN105K_PF 0xba00
20 #define OCTEP_VDPA_DEVID_CN105K_VF 0xba03
21 #define OCTEP_VDPA_DEVID_CN103K_PF 0xbd00
22 #define OCTEP_VDPA_DEVID_CN103K_VF 0xbd03
23 
24 #define OCTEP_HW_MBOX_BAR 0
25 #define OCTEP_HW_CAPS_BAR 4
26 
27 #define OCTEP_DEV_READY_SIGNATURE 0xBABABABA
28 
29 #define OCTEP_EPF_RINFO(x) (0x000209f0 | ((x) << 25))
30 #define OCTEP_VF_MBOX_DATA(x) (0x00010210 | ((x) << 17))
31 #define OCTEP_PF_MBOX_DATA(x) (0x00022000 | ((x) << 4))
32 
33 #define OCTEP_EPF_RINFO_RPVF(val) (((val) >> 32) & 0xF)
34 #define OCTEP_EPF_RINFO_NVFS(val) (((val) >> 48) & 0x7F)
35 
36 #define OCTEP_FW_READY_SIGNATURE0  0xFEEDFEED
37 #define OCTEP_FW_READY_SIGNATURE1  0x3355ffaa
38 
39 enum octep_vdpa_dev_status {
40 	OCTEP_VDPA_DEV_STATUS_INVALID,
41 	OCTEP_VDPA_DEV_STATUS_ALLOC,
42 	OCTEP_VDPA_DEV_STATUS_WAIT_FOR_BAR_INIT,
43 	OCTEP_VDPA_DEV_STATUS_INIT,
44 	OCTEP_VDPA_DEV_STATUS_READY,
45 	OCTEP_VDPA_DEV_STATUS_UNINIT
46 };
47 
48 struct octep_vring_info {
49 	struct vdpa_callback cb;
50 	void __iomem *notify_addr;
51 	u32 __iomem *cb_notify_addr;
52 	phys_addr_t notify_pa;
53 	char msix_name[256];
54 };
55 
56 struct octep_hw {
57 	struct pci_dev *pdev;
58 	u8 __iomem *base[PCI_STD_NUM_BARS];
59 	struct virtio_pci_common_cfg __iomem *common_cfg;
60 	u8 __iomem *dev_cfg;
61 	u8 __iomem *isr;
62 	void __iomem *notify_base;
63 	phys_addr_t notify_base_pa;
64 	u32 notify_off_multiplier;
65 	u8 notify_bar;
66 	struct octep_vring_info *vqs;
67 	struct vdpa_callback config_cb;
68 	u64 features;
69 	u16 nr_vring;
70 	u32 config_size;
71 	int irq;
72 };
73 
74 u8 octep_hw_get_status(struct octep_hw *oct_hw);
75 void octep_hw_set_status(struct octep_hw *dev, uint8_t status);
76 void octep_hw_reset(struct octep_hw *oct_hw);
77 void octep_write_queue_select(struct octep_hw *oct_hw, u16 queue_id);
78 void octep_notify_queue(struct octep_hw *oct_hw, u16 qid);
79 void octep_read_dev_config(struct octep_hw *oct_hw, u64 offset, void *dst, int length);
80 int octep_set_vq_address(struct octep_hw *oct_hw, u16 qid, u64 desc_area, u64 driver_area,
81 			 u64 device_area);
82 void octep_set_vq_num(struct octep_hw *oct_hw, u16 qid, u32 num);
83 void octep_set_vq_ready(struct octep_hw *oct_hw, u16 qid, bool ready);
84 bool octep_get_vq_ready(struct octep_hw *oct_hw, u16 qid);
85 int octep_set_vq_state(struct octep_hw *oct_hw, u16 qid, const struct vdpa_vq_state *state);
86 int octep_get_vq_state(struct octep_hw *oct_hw, u16 qid, struct vdpa_vq_state *state);
87 u16 octep_get_vq_size(struct octep_hw *oct_hw);
88 int octep_hw_caps_read(struct octep_hw *oct_hw, struct pci_dev *pdev);
89 u64 octep_hw_get_dev_features(struct octep_hw *oct_hw);
90 void octep_hw_set_drv_features(struct octep_hw *oct_hw, u64 features);
91 u64 octep_hw_get_drv_features(struct octep_hw *oct_hw);
92 int octep_verify_features(u64 features);
93 
94 #endif /* __OCTEP_VDPA_H__ */
95