a89570b622e84378f9f069876f4162091d6e2fab
[dpdk.git] / drivers / common / octeontx2 / otx2_dev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #ifndef _OTX2_DEV_H
6 #define _OTX2_DEV_H
7
8 #include <rte_bus_pci.h>
9
10 #include "otx2_common.h"
11 #include "otx2_irq.h"
12 #include "otx2_mbox.h"
13
14 /* Common HWCAP flags. Use from LSB bits */
15 #define OTX2_HWCAP_F_VF         BIT_ULL(0) /* VF device */
16 #define otx2_dev_is_vf(dev)     (dev->hwcap & OTX2_HWCAP_F_VF)
17 #define otx2_dev_is_pf(dev)     (!(dev->hwcap & OTX2_HWCAP_F_VF))
18 #define otx2_dev_is_lbk(dev)    ((dev->hwcap & OTX2_HWCAP_F_VF) && \
19                                  (dev->tx_chan_base < 0x700))
20
21 #define OTX2_HWCAP_F_A0         BIT_ULL(1) /* A0 device */
22 #define otx2_dev_is_A0(dev)     (dev->hwcap & OTX2_HWCAP_F_A0)
23
24 struct otx2_dev;
25
26 #define OTX2_DEV                                        \
27         int node __rte_cache_aligned;                   \
28         uint16_t pf;                                    \
29         int16_t vf;                                     \
30         uint16_t pf_func;                               \
31         uint8_t mbox_active;                            \
32         bool drv_inited;                                \
33         uint64_t active_vfs[MAX_VFPF_DWORD_BITS];       \
34         uintptr_t bar2;                                 \
35         uintptr_t bar4;                                 \
36         struct otx2_mbox mbox_local;                    \
37         struct otx2_mbox mbox_up;                       \
38         struct otx2_mbox mbox_vfpf;                     \
39         struct otx2_mbox mbox_vfpf_up;                  \
40         otx2_intr_t intr;                               \
41         int timer_set;  /* ~0 : no alarm handling */    \
42         uint64_t hwcap;                                 \
43         struct otx2_mbox *mbox;                         \
44         uint16_t maxvf;                                 \
45         const struct otx2_dev_ops *ops
46
47 struct otx2_dev {
48         OTX2_DEV;
49 };
50
51 int otx2_dev_init(struct rte_pci_device *pci_dev, void *otx2_dev);
52 void otx2_dev_fini(struct rte_pci_device *pci_dev, void *otx2_dev);
53 int otx2_dev_active_vfs(void *otx2_dev);
54
55 #define RVU_PFVF_PF_SHIFT       10
56 #define RVU_PFVF_PF_MASK        0x3F
57 #define RVU_PFVF_FUNC_SHIFT     0
58 #define RVU_PFVF_FUNC_MASK      0x3FF
59
60 static inline int
61 otx2_get_vf(uint16_t pf_func)
62 {
63         return (((pf_func >> RVU_PFVF_FUNC_SHIFT) & RVU_PFVF_FUNC_MASK) - 1);
64 }
65
66 static inline int
67 otx2_get_pf(uint16_t pf_func)
68 {
69         return (pf_func >> RVU_PFVF_PF_SHIFT) & RVU_PFVF_PF_MASK;
70 }
71
72 static inline int
73 otx2_pfvf_func(int pf, int vf)
74 {
75         return (pf << RVU_PFVF_PF_SHIFT) | ((vf << RVU_PFVF_FUNC_SHIFT) + 1);
76 }
77
78 static inline int
79 otx2_is_afvf(uint16_t pf_func)
80 {
81         return !(pf_func & ~RVU_PFVF_FUNC_MASK);
82 }
83
84 #endif /* _OTX2_DEV_H */