net/octeontx2: support TSO offload
[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 #ifndef BITS_PER_LONG
35 #define BITS_PER_LONG   (__SIZEOF_LONG__ * 8)
36 #endif
37 #ifndef BITS_PER_LONG_LONG
38 #define BITS_PER_LONG_LONG (__SIZEOF_LONG_LONG__ * 8)
39 #endif
40
41 #ifndef GENMASK
42 #define GENMASK(h, l) \
43                 (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
44 #endif
45 #ifndef GENMASK_ULL
46 #define GENMASK_ULL(h, l) \
47         (((~0ULL) - (1ULL << (l)) + 1) & \
48          (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
49 #endif
50
51 /* Compiler attributes */
52 #ifndef __hot
53 #define __hot   __attribute__((hot))
54 #endif
55
56 /* Intra device related functions */
57 struct otx2_npa_lf;
58 struct otx2_idev_cfg {
59         uint16_t sso_pf_func;
60         uint16_t npa_pf_func;
61         struct otx2_npa_lf *npa_lf;
62         RTE_STD_C11
63         union {
64                 rte_atomic16_t npa_refcnt;
65                 uint16_t npa_refcnt_u16;
66         };
67 };
68
69 struct otx2_idev_cfg *otx2_intra_dev_get_cfg(void);
70 void otx2_sso_pf_func_set(uint16_t sso_pf_func);
71 uint16_t otx2_sso_pf_func_get(void);
72 uint16_t otx2_npa_pf_func_get(void);
73 struct otx2_npa_lf *otx2_npa_lf_obj_get(void);
74 void otx2_npa_set_defaults(struct otx2_idev_cfg *idev);
75 int otx2_npa_lf_active(void *dev);
76 int otx2_npa_lf_obj_ref(void);
77
78 /* Log */
79 extern int otx2_logtype_base;
80 extern int otx2_logtype_mbox;
81 extern int otx2_logtype_npa;
82 extern int otx2_logtype_nix;
83 extern int otx2_logtype_sso;
84 extern int otx2_logtype_npc;
85 extern int otx2_logtype_tm;
86 extern int otx2_logtype_tim;
87 extern int otx2_logtype_dpi;
88
89 #define otx2_err(fmt, args...)                  \
90         RTE_LOG(ERR, PMD, "%s():%u " fmt "\n",  \
91                 __func__, __LINE__, ## args)
92
93 #define otx2_info(fmt, args...)                                         \
94         RTE_LOG(INFO, PMD, fmt"\n", ## args)
95
96 #define otx2_dbg(subsystem, fmt, args...)                               \
97         rte_log(RTE_LOG_DEBUG, otx2_logtype_ ## subsystem,              \
98                 "[%s] %s():%u " fmt "\n",                               \
99                  #subsystem, __func__, __LINE__, ##args)
100
101 #define otx2_base_dbg(fmt, ...) otx2_dbg(base, fmt, ##__VA_ARGS__)
102 #define otx2_mbox_dbg(fmt, ...) otx2_dbg(mbox, fmt, ##__VA_ARGS__)
103 #define otx2_npa_dbg(fmt, ...) otx2_dbg(npa, fmt, ##__VA_ARGS__)
104 #define otx2_nix_dbg(fmt, ...) otx2_dbg(nix, fmt, ##__VA_ARGS__)
105 #define otx2_sso_dbg(fmt, ...) otx2_dbg(sso, fmt, ##__VA_ARGS__)
106 #define otx2_npc_dbg(fmt, ...) otx2_dbg(npc, fmt, ##__VA_ARGS__)
107 #define otx2_tm_dbg(fmt, ...) otx2_dbg(tm, fmt, ##__VA_ARGS__)
108 #define otx2_tim_dbg(fmt, ...) otx2_dbg(tim, fmt, ##__VA_ARGS__)
109 #define otx2_dpi_dbg(fmt, ...) otx2_dbg(dpi, fmt, ##__VA_ARGS__)
110
111 /* PCI IDs */
112 #define PCI_VENDOR_ID_CAVIUM                    0x177D
113 #define PCI_DEVID_OCTEONTX2_RVU_PF              0xA063
114 #define PCI_DEVID_OCTEONTX2_RVU_VF              0xA064
115 #define PCI_DEVID_OCTEONTX2_RVU_AF              0xA065
116 #define PCI_DEVID_OCTEONTX2_RVU_SSO_TIM_PF      0xA0F9
117 #define PCI_DEVID_OCTEONTX2_RVU_SSO_TIM_VF      0xA0FA
118 #define PCI_DEVID_OCTEONTX2_RVU_NPA_PF          0xA0FB
119 #define PCI_DEVID_OCTEONTX2_RVU_NPA_VF          0xA0FC
120 #define PCI_DEVID_OCTEONTX2_RVU_CPT_PF          0xA0FD
121 #define PCI_DEVID_OCTEONTX2_RVU_CPT_VF          0xA0FE
122 #define PCI_DEVID_OCTEONTX2_RVU_AF_VF           0xA0f8
123 #define PCI_DEVID_OCTEONTX2_DPI_VF              0xA081
124
125 /* Subsystem Device ID */
126 #define PCI_SUBSYS_DEVID_96XX_95XX              0xB200
127
128 /*
129  * REVID for RVU PCIe devices.
130  * Bits 0..1: minor pass
131  * Bits 3..2: major pass
132  * Bits 7..4: midr id, 0:96, 1:95, 2:loki, f:unknown
133  */
134
135 #define RVU_PCI_REV_MIDR_ID(rev_id)             (rev_id >> 4)
136 #define RVU_PCI_REV_MAJOR(rev_id)               ((rev_id >> 2) & 0x3)
137 #define RVU_PCI_REV_MINOR(rev_id)               (rev_id & 0x3)
138
139 #define RVU_PCI_CN96XX_MIDR_ID                  0x0
140 #define RVU_PCI_CNF95XX_MIDR_ID                 0x1
141
142 /* PCI Config offsets */
143 #define RVU_PCI_REVISION_ID                     0x08
144
145 /* IO Access */
146 #define otx2_read64(addr) rte_read64_relaxed((void *)(addr))
147 #define otx2_write64(val, addr) rte_write64_relaxed((val), (void *)(addr))
148
149 #if defined(RTE_ARCH_ARM64)
150 #include "otx2_io_arm64.h"
151 #else
152 #include "otx2_io_generic.h"
153 #endif
154
155 #endif /* _OTX2_COMMON_H_ */