net/thunderx/base: add hardware API
[dpdk.git] / drivers / net / thunderx / base / nicvf_hw.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium networks Ltd. 2016.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium networks nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _THUNDERX_NICVF_HW_H
34 #define _THUNDERX_NICVF_HW_H
35
36 #include <stdint.h>
37
38 #include "nicvf_hw_defs.h"
39
40 #define PCI_VENDOR_ID_CAVIUM                    0x177D
41 #define PCI_DEVICE_ID_THUNDERX_PASS1_NICVF      0x0011
42 #define PCI_DEVICE_ID_THUNDERX_PASS2_NICVF      0xA034
43 #define PCI_SUB_DEVICE_ID_THUNDERX_PASS1_NICVF  0xA11E
44 #define PCI_SUB_DEVICE_ID_THUNDERX_PASS2_NICVF  0xA134
45
46 #define NICVF_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
47
48 #define NICVF_PASS1     (PCI_SUB_DEVICE_ID_THUNDERX_PASS1_NICVF)
49 #define NICVF_PASS2     (PCI_SUB_DEVICE_ID_THUNDERX_PASS2_NICVF)
50
51 #define NICVF_CAP_TUNNEL_PARSING          (1ULL << 0)
52
53 enum nicvf_tns_mode {
54         NIC_TNS_BYPASS_MODE,
55         NIC_TNS_MODE,
56 };
57
58 enum nicvf_err_e {
59         NICVF_OK,
60         NICVF_ERR_SET_QS = -8191,/* -8191 */
61         NICVF_ERR_RESET_QS,      /* -8190 */
62         NICVF_ERR_REG_POLL,      /* -8189 */
63         NICVF_ERR_RBDR_RESET,    /* -8188 */
64         NICVF_ERR_RBDR_DISABLE,  /* -8187 */
65         NICVF_ERR_RBDR_PREFETCH, /* -8186 */
66         NICVF_ERR_RBDR_RESET1,   /* -8185 */
67         NICVF_ERR_RBDR_RESET2,   /* -8184 */
68         NICVF_ERR_RQ_CLAIM,      /* -8183 */
69         NICVF_ERR_RQ_PF_CFG,     /* -8182 */
70         NICVF_ERR_RQ_BP_CFG,     /* -8181 */
71         NICVF_ERR_RQ_DROP_CFG,   /* -8180 */
72         NICVF_ERR_CQ_DISABLE,    /* -8179 */
73         NICVF_ERR_CQ_RESET,      /* -8178 */
74         NICVF_ERR_SQ_DISABLE,    /* -8177 */
75         NICVF_ERR_SQ_RESET,      /* -8176 */
76         NICVF_ERR_SQ_PF_CFG,     /* -8175 */
77         NICVF_ERR_LOOPBACK_CFG,  /* -8174 */
78         NICVF_ERR_BASE_INIT,     /* -8173 */
79 };
80
81 typedef nicvf_phys_addr_t (*rbdr_pool_get_handler)(void *opaque);
82
83 /* Common structs used in DPDK and base layer are defined in DPDK layer */
84 #include "../nicvf_struct.h"
85
86 NICVF_STATIC_ASSERT(sizeof(struct nicvf_rbdr) <= 128);
87 NICVF_STATIC_ASSERT(sizeof(struct nicvf_txq) <= 128);
88 NICVF_STATIC_ASSERT(sizeof(struct nicvf_rxq) <= 128);
89
90 static inline void
91 nicvf_reg_write(struct nicvf *nic, uint32_t offset, uint64_t val)
92 {
93         nicvf_addr_write(nic->reg_base + offset, val);
94 }
95
96 static inline uint64_t
97 nicvf_reg_read(struct nicvf *nic, uint32_t offset)
98 {
99         return nicvf_addr_read(nic->reg_base + offset);
100 }
101
102 static inline uintptr_t
103 nicvf_qset_base(struct nicvf *nic, uint32_t qidx)
104 {
105         return nic->reg_base + (qidx << NIC_Q_NUM_SHIFT);
106 }
107
108 static inline void
109 nicvf_queue_reg_write(struct nicvf *nic, uint32_t offset, uint32_t qidx,
110                       uint64_t val)
111 {
112         nicvf_addr_write(nicvf_qset_base(nic, qidx) + offset, val);
113 }
114
115 static inline uint64_t
116 nicvf_queue_reg_read(struct nicvf *nic, uint32_t offset, uint32_t qidx)
117 {
118         return  nicvf_addr_read(nicvf_qset_base(nic, qidx) + offset);
119 }
120
121 static inline void
122 nicvf_disable_all_interrupts(struct nicvf *nic)
123 {
124         nicvf_reg_write(nic, NIC_VF_ENA_W1C, NICVF_INTR_ALL_MASK);
125         nicvf_reg_write(nic, NIC_VF_INT, NICVF_INTR_ALL_MASK);
126 }
127
128 static inline uint32_t
129 nicvf_hw_version(struct nicvf *nic)
130 {
131         return nic->subsystem_device_id;
132 }
133
134 static inline uint64_t
135 nicvf_hw_cap(struct nicvf *nic)
136 {
137         return nic->hwcap;
138 }
139
140 int nicvf_base_init(struct nicvf *nic);
141
142 int nicvf_reg_get_count(void);
143 int nicvf_reg_poll_interrupts(struct nicvf *nic);
144 int nicvf_reg_dump(struct nicvf *nic, uint64_t *data);
145
146 int nicvf_qset_config(struct nicvf *nic);
147 int nicvf_qset_reclaim(struct nicvf *nic);
148
149 int nicvf_qset_rbdr_config(struct nicvf *nic, uint16_t qidx);
150 int nicvf_qset_rbdr_reclaim(struct nicvf *nic, uint16_t qidx);
151 int nicvf_qset_rbdr_precharge(struct nicvf *nic, uint16_t ridx,
152                               rbdr_pool_get_handler handler, void *opaque,
153                               uint32_t max_buffs);
154 int nicvf_qset_rbdr_active(struct nicvf *nic, uint16_t qidx);
155
156 int nicvf_qset_rq_config(struct nicvf *nic, uint16_t qidx,
157                          struct nicvf_rxq *rxq);
158 int nicvf_qset_rq_reclaim(struct nicvf *nic, uint16_t qidx);
159
160 int nicvf_qset_cq_config(struct nicvf *nic, uint16_t qidx,
161                          struct nicvf_rxq *rxq);
162 int nicvf_qset_cq_reclaim(struct nicvf *nic, uint16_t qidx);
163
164 int nicvf_qset_sq_config(struct nicvf *nic, uint16_t qidx,
165                          struct nicvf_txq *txq);
166 int nicvf_qset_sq_reclaim(struct nicvf *nic, uint16_t qidx);
167
168 uint32_t nicvf_qsize_rbdr_roundup(uint32_t val);
169 uint32_t nicvf_qsize_cq_roundup(uint32_t val);
170 uint32_t nicvf_qsize_sq_roundup(uint32_t val);
171
172 void nicvf_vlan_hw_strip(struct nicvf *nic, bool enable);
173
174 int nicvf_loopback_config(struct nicvf *nic, bool enable);
175
176 #endif /* _THUNDERX_NICVF_HW_H */