drivers: add init and fini on octeontx2 NPA object
[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 #include "otx2_mempool.h"
14
15 /* Common HWCAP flags. Use from LSB bits */
16 #define OTX2_HWCAP_F_VF         BIT_ULL(0) /* VF device */
17 #define otx2_dev_is_vf(dev)     (dev->hwcap & OTX2_HWCAP_F_VF)
18 #define otx2_dev_is_pf(dev)     (!(dev->hwcap & OTX2_HWCAP_F_VF))
19 #define otx2_dev_is_lbk(dev)    ((dev->hwcap & OTX2_HWCAP_F_VF) && \
20                                  (dev->tx_chan_base < 0x700))
21
22 #define OTX2_HWCAP_F_A0         BIT_ULL(1) /* A0 device */
23 #define otx2_dev_is_A0(dev)     (dev->hwcap & OTX2_HWCAP_F_A0)
24
25 struct otx2_dev;
26
27 /* Link status callback */
28 typedef void (*otx2_link_status_t)(struct otx2_dev *dev,
29                                    struct cgx_link_user_info *link);
30 /* PTP info callback */
31 typedef int (*otx2_ptp_info_t)(struct otx2_dev *dev, bool ptp_en);
32
33 struct otx2_dev_ops {
34         otx2_link_status_t link_status_update;
35         otx2_ptp_info_t ptp_info_update;
36 };
37
38 #define OTX2_DEV                                        \
39         int node __rte_cache_aligned;                   \
40         uint16_t pf;                                    \
41         int16_t vf;                                     \
42         uint16_t pf_func;                               \
43         uint8_t mbox_active;                            \
44         bool drv_inited;                                \
45         uint64_t active_vfs[MAX_VFPF_DWORD_BITS];       \
46         uintptr_t bar2;                                 \
47         uintptr_t bar4;                                 \
48         struct otx2_mbox mbox_local;                    \
49         struct otx2_mbox mbox_up;                       \
50         struct otx2_mbox mbox_vfpf;                     \
51         struct otx2_mbox mbox_vfpf_up;                  \
52         otx2_intr_t intr;                               \
53         int timer_set;  /* ~0 : no alarm handling */    \
54         uint64_t hwcap;                                 \
55         struct otx2_npa_lf npalf;                       \
56         struct otx2_mbox *mbox;                         \
57         uint16_t maxvf;                                 \
58         const struct otx2_dev_ops *ops
59
60 struct otx2_dev {
61         OTX2_DEV;
62 };
63
64 int otx2_dev_init(struct rte_pci_device *pci_dev, void *otx2_dev);
65 void otx2_dev_fini(struct rte_pci_device *pci_dev, void *otx2_dev);
66 int otx2_dev_active_vfs(void *otx2_dev);
67
68 #define RVU_PFVF_PF_SHIFT       10
69 #define RVU_PFVF_PF_MASK        0x3F
70 #define RVU_PFVF_FUNC_SHIFT     0
71 #define RVU_PFVF_FUNC_MASK      0x3FF
72
73 static inline int
74 otx2_get_vf(uint16_t pf_func)
75 {
76         return (((pf_func >> RVU_PFVF_FUNC_SHIFT) & RVU_PFVF_FUNC_MASK) - 1);
77 }
78
79 static inline int
80 otx2_get_pf(uint16_t pf_func)
81 {
82         return (pf_func >> RVU_PFVF_PF_SHIFT) & RVU_PFVF_PF_MASK;
83 }
84
85 static inline int
86 otx2_pfvf_func(int pf, int vf)
87 {
88         return (pf << RVU_PFVF_PF_SHIFT) | ((vf << RVU_PFVF_FUNC_SHIFT) + 1);
89 }
90
91 static inline int
92 otx2_is_afvf(uint16_t pf_func)
93 {
94         return !(pf_func & ~RVU_PFVF_FUNC_MASK);
95 }
96
97 #endif /* _OTX2_DEV_H */