common/octeontx2: handle intra device operations
[dpdk.git] / drivers / common / octeontx2 / otx2_common.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #ifndef _OTX2_COMMON_H_
6 #define _OTX2_COMMON_H_
7
8 #include <rte_atomic.h>
9 #include <rte_common.h>
10 #include <rte_cycles.h>
11 #include <rte_memory.h>
12 #include <rte_memzone.h>
13 #include <rte_io.h>
14
15 #include "hw/otx2_rvu.h"
16 #include "hw/otx2_nix.h"
17 #include "hw/otx2_npc.h"
18 #include "hw/otx2_npa.h"
19 #include "hw/otx2_sso.h"
20 #include "hw/otx2_ssow.h"
21 #include "hw/otx2_tim.h"
22
23 /* Alignment */
24 #define OTX2_ALIGN  128
25
26 /* Bits manipulation */
27 #ifndef BIT_ULL
28 #define BIT_ULL(nr) (1ULL << (nr))
29 #endif
30 #ifndef BIT
31 #define BIT(nr)     (1UL << (nr))
32 #endif
33
34 /* Compiler attributes */
35 #ifndef __hot
36 #define __hot   __attribute__((hot))
37 #endif
38
39 /* Intra device related functions */
40 struct otx2_npa_lf {
41         struct otx2_mbox *mbox;
42         struct rte_pci_device *pci_dev;
43         struct rte_intr_handle *intr_handle;
44 };
45
46 struct otx2_idev_cfg {
47         uint16_t sso_pf_func;
48         uint16_t npa_pf_func;
49         struct otx2_npa_lf *npa_lf;
50         RTE_STD_C11
51         union {
52                 rte_atomic16_t npa_refcnt;
53                 uint16_t npa_refcnt_u16;
54         };
55 };
56
57 struct otx2_idev_cfg *otx2_intra_dev_get_cfg(void);
58 void otx2_sso_pf_func_set(uint16_t sso_pf_func);
59 uint16_t otx2_sso_pf_func_get(void);
60 uint16_t otx2_npa_pf_func_get(void);
61 struct otx2_npa_lf *otx2_npa_lf_obj_get(void);
62 void otx2_npa_set_defaults(struct otx2_idev_cfg *idev);
63 int otx2_npa_lf_active(void *dev);
64 int otx2_npa_lf_obj_ref(void);
65
66 /* Log */
67 extern int otx2_logtype_base;
68 extern int otx2_logtype_mbox;
69 extern int otx2_logtype_npa;
70 extern int otx2_logtype_nix;
71 extern int otx2_logtype_sso;
72 extern int otx2_logtype_npc;
73 extern int otx2_logtype_tm;
74 extern int otx2_logtype_tim;
75 extern int otx2_logtype_dpi;
76
77 #define OTX2_CLNRM  "\x1b[0m"
78 #define OTX2_CLRED  "\x1b[31m"
79
80 #define otx2_err(fmt, args...)                                          \
81         RTE_LOG(ERR, PMD, ""OTX2_CLRED"%s():%u " fmt OTX2_CLNRM"\n",    \
82                                 __func__, __LINE__, ## args)
83
84 #define otx2_info(fmt, args...)                                         \
85         RTE_LOG(INFO, PMD, fmt"\n", ## args)
86
87 #define otx2_dbg(subsystem, fmt, args...)                               \
88         rte_log(RTE_LOG_DEBUG, otx2_logtype_ ## subsystem,              \
89                 "[%s] %s():%u " fmt "\n",                               \
90                  #subsystem, __func__, __LINE__, ##args)
91
92 #define otx2_base_dbg(fmt, ...) otx2_dbg(base, fmt, ##__VA_ARGS__)
93 #define otx2_mbox_dbg(fmt, ...) otx2_dbg(mbox, fmt, ##__VA_ARGS__)
94 #define otx2_npa_dbg(fmt, ...) otx2_dbg(npa, fmt, ##__VA_ARGS__)
95 #define otx2_nix_dbg(fmt, ...) otx2_dbg(nix, fmt, ##__VA_ARGS__)
96 #define otx2_sso_dbg(fmt, ...) otx2_dbg(sso, fmt, ##__VA_ARGS__)
97 #define otx2_npc_dbg(fmt, ...) otx2_dbg(npc, fmt, ##__VA_ARGS__)
98 #define otx2_tm_dbg(fmt, ...) otx2_dbg(tm, fmt, ##__VA_ARGS__)
99 #define otx2_tim_dbg(fmt, ...) otx2_dbg(tim, fmt, ##__VA_ARGS__)
100 #define otx2_dpi_dbg(fmt, ...) otx2_dbg(dpi, fmt, ##__VA_ARGS__)
101
102 /* PCI IDs */
103 #define PCI_VENDOR_ID_CAVIUM                    0x177D
104 #define PCI_DEVID_OCTEONTX2_RVU_PF              0xA063
105 #define PCI_DEVID_OCTEONTX2_RVU_VF              0xA064
106 #define PCI_DEVID_OCTEONTX2_RVU_AF              0xA065
107 #define PCI_DEVID_OCTEONTX2_RVU_SSO_TIM_PF      0xA0F9
108 #define PCI_DEVID_OCTEONTX2_RVU_SSO_TIM_VF      0xA0FA
109 #define PCI_DEVID_OCTEONTX2_RVU_NPA_PF          0xA0FB
110 #define PCI_DEVID_OCTEONTX2_RVU_NPA_VF          0xA0FC
111 #define PCI_DEVID_OCTEONTX2_RVU_CPT_PF          0xA0FD
112 #define PCI_DEVID_OCTEONTX2_RVU_CPT_VF          0xA0FE
113 #define PCI_DEVID_OCTEONTX2_RVU_AF_VF           0xA0f8
114 #define PCI_DEVID_OCTEONTX2_DPI_VF              0xA081
115
116 /* IO Access */
117 #define otx2_read64(addr) rte_read64_relaxed((void *)(addr))
118 #define otx2_write64(val, addr) rte_write64_relaxed((val), (void *)(addr))
119
120 #if defined(RTE_ARCH_ARM64)
121 #include "otx2_io_arm64.h"
122 #else
123 #include "otx2_io_generic.h"
124 #endif
125
126 #endif /* _OTX2_COMMON_H_ */