common/octeontx2: support CNF95xx SoC
[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(8) /* 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 #define otx2_dev_revid(dev)     (dev->hwcap & 0xFF)
22
23 #define otx2_dev_is_A0(dev)                                     \
24         ((RVU_PCI_REV_MAJOR(otx2_dev_revid(dev)) == 0x0) &&     \
25          (RVU_PCI_REV_MINOR(otx2_dev_revid(dev)) == 0x0))
26 #define otx2_dev_is_Ax(dev)                                     \
27         ((RVU_PCI_REV_MAJOR(otx2_dev_revid(dev)) == 0x0))
28
29 struct otx2_dev;
30
31 /* Link status callback */
32 typedef void (*otx2_link_status_t)(struct otx2_dev *dev,
33                                    struct cgx_link_user_info *link);
34 /* PTP info callback */
35 typedef int (*otx2_ptp_info_t)(struct otx2_dev *dev, bool ptp_en);
36
37 struct otx2_dev_ops {
38         otx2_link_status_t link_status_update;
39         otx2_ptp_info_t ptp_info_update;
40 };
41
42 #define OTX2_DEV                                        \
43         int node __rte_cache_aligned;                   \
44         uint16_t pf;                                    \
45         int16_t vf;                                     \
46         uint16_t pf_func;                               \
47         uint8_t mbox_active;                            \
48         bool drv_inited;                                \
49         uint64_t active_vfs[MAX_VFPF_DWORD_BITS];       \
50         uintptr_t bar2;                                 \
51         uintptr_t bar4;                                 \
52         struct otx2_mbox mbox_local;                    \
53         struct otx2_mbox mbox_up;                       \
54         struct otx2_mbox mbox_vfpf;                     \
55         struct otx2_mbox mbox_vfpf_up;                  \
56         otx2_intr_t intr;                               \
57         int timer_set;  /* ~0 : no alarm handling */    \
58         uint64_t hwcap;                                 \
59         struct otx2_npa_lf npalf;                       \
60         struct otx2_mbox *mbox;                         \
61         uint16_t maxvf;                                 \
62         const struct otx2_dev_ops *ops
63
64 struct otx2_dev {
65         OTX2_DEV;
66 };
67
68 int otx2_dev_priv_init(struct rte_pci_device *pci_dev, void *otx2_dev);
69
70 /* Common dev init and fini routines */
71
72 static __rte_always_inline int
73 otx2_dev_init(struct rte_pci_device *pci_dev, void *otx2_dev)
74 {
75         struct otx2_dev *dev = otx2_dev;
76         uint8_t rev_id;
77         int rc;
78
79         rc = rte_pci_read_config(pci_dev, &rev_id,
80                                  1, RVU_PCI_REVISION_ID);
81         if (rc != 1) {
82                 otx2_err("Failed to read pci revision id, rc=%d", rc);
83                 return rc;
84         }
85
86         if (pci_dev->id.subsystem_device_id == PCI_SUBSYS_DEVID_96XX_95XX)
87                 dev->hwcap = rev_id;
88         else
89                 dev->hwcap = 0;
90
91         return otx2_dev_priv_init(pci_dev, otx2_dev);
92 }
93
94 void otx2_dev_fini(struct rte_pci_device *pci_dev, void *otx2_dev);
95 int otx2_dev_active_vfs(void *otx2_dev);
96
97 #define RVU_PFVF_PF_SHIFT       10
98 #define RVU_PFVF_PF_MASK        0x3F
99 #define RVU_PFVF_FUNC_SHIFT     0
100 #define RVU_PFVF_FUNC_MASK      0x3FF
101
102 static inline int
103 otx2_get_vf(uint16_t pf_func)
104 {
105         return (((pf_func >> RVU_PFVF_FUNC_SHIFT) & RVU_PFVF_FUNC_MASK) - 1);
106 }
107
108 static inline int
109 otx2_get_pf(uint16_t pf_func)
110 {
111         return (pf_func >> RVU_PFVF_PF_SHIFT) & RVU_PFVF_PF_MASK;
112 }
113
114 static inline int
115 otx2_pfvf_func(int pf, int vf)
116 {
117         return (pf << RVU_PFVF_PF_SHIFT) | ((vf << RVU_PFVF_FUNC_SHIFT) + 1);
118 }
119
120 static inline int
121 otx2_is_afvf(uint16_t pf_func)
122 {
123         return !(pf_func & ~RVU_PFVF_FUNC_MASK);
124 }
125
126 #endif /* _OTX2_DEV_H */