1aaf4363eSJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause
2aaf4363eSJerin Jacob * Copyright(c) 2016 Cavium, Inc
3c747e72bSJerin Jacob */
4c747e72bSJerin Jacob
5c747e72bSJerin Jacob #ifndef _THUNDERX_NICVF_HW_H
6c747e72bSJerin Jacob #define _THUNDERX_NICVF_HW_H
7c747e72bSJerin Jacob
8c747e72bSJerin Jacob #include <stdint.h>
9c747e72bSJerin Jacob
10c747e72bSJerin Jacob #include "nicvf_hw_defs.h"
11c747e72bSJerin Jacob
12c747e72bSJerin Jacob #define PCI_VENDOR_ID_CAVIUM 0x177D
13398a1be1SJerin Jacob #define PCI_DEVICE_ID_THUNDERX_CN88XX_PASS1_NICVF 0x0011
14398a1be1SJerin Jacob #define PCI_DEVICE_ID_THUNDERX_NICVF 0xA034
15398a1be1SJerin Jacob #define PCI_SUB_DEVICE_ID_CN88XX_PASS1_NICVF 0xA11E
16398a1be1SJerin Jacob #define PCI_SUB_DEVICE_ID_CN88XX_PASS2_NICVF 0xA134
17b72a7768SJerin Jacob #define PCI_SUB_DEVICE_ID_CN81XX_NICVF 0xA234
18174dd78eSJerin Jacob #define PCI_SUB_DEVICE_ID_CN83XX_NICVF 0xA334
19c747e72bSJerin Jacob
20*a3c9a11aSAndrew Boyer #define NICVF_ARRAY_SIZE(arr) RTE_DIM(arr)
21c747e72bSJerin Jacob
22263a688cSJerin Jacob #define NICVF_GET_RX_STATS(reg) \
23263a688cSJerin Jacob nicvf_reg_read(nic, NIC_VNIC_RX_STAT_0_13 | (reg << 3))
24263a688cSJerin Jacob #define NICVF_GET_TX_STATS(reg) \
25263a688cSJerin Jacob nicvf_reg_read(nic, NIC_VNIC_TX_STAT_0_4 | (reg << 3))
26263a688cSJerin Jacob
27c747e72bSJerin Jacob #define NICVF_CAP_TUNNEL_PARSING (1ULL << 0)
28e2c519b3SJerin Jacob /* Additional word in Rx descriptor to hold optional tunneling extension info */
29e2c519b3SJerin Jacob #define NICVF_CAP_CQE_RX2 (1ULL << 1)
308a946db3SJerin Jacob /* The device capable of setting NIC_CQE_RX_S[APAD] == 0 */
318a946db3SJerin Jacob #define NICVF_CAP_DISABLE_APAD (1ULL << 2)
32c747e72bSJerin Jacob
33c747e72bSJerin Jacob enum nicvf_tns_mode {
34c747e72bSJerin Jacob NIC_TNS_BYPASS_MODE,
35c747e72bSJerin Jacob NIC_TNS_MODE,
36c747e72bSJerin Jacob };
37c747e72bSJerin Jacob
38c747e72bSJerin Jacob enum nicvf_err_e {
39c747e72bSJerin Jacob NICVF_OK,
40c747e72bSJerin Jacob NICVF_ERR_SET_QS = -8191,/* -8191 */
41c747e72bSJerin Jacob NICVF_ERR_RESET_QS, /* -8190 */
42c747e72bSJerin Jacob NICVF_ERR_REG_POLL, /* -8189 */
43c747e72bSJerin Jacob NICVF_ERR_RBDR_RESET, /* -8188 */
44c747e72bSJerin Jacob NICVF_ERR_RBDR_DISABLE, /* -8187 */
45c747e72bSJerin Jacob NICVF_ERR_RBDR_PREFETCH, /* -8186 */
46c747e72bSJerin Jacob NICVF_ERR_RBDR_RESET1, /* -8185 */
47c747e72bSJerin Jacob NICVF_ERR_RBDR_RESET2, /* -8184 */
48c747e72bSJerin Jacob NICVF_ERR_RQ_CLAIM, /* -8183 */
49c747e72bSJerin Jacob NICVF_ERR_RQ_PF_CFG, /* -8182 */
50c747e72bSJerin Jacob NICVF_ERR_RQ_BP_CFG, /* -8181 */
51c747e72bSJerin Jacob NICVF_ERR_RQ_DROP_CFG, /* -8180 */
52c747e72bSJerin Jacob NICVF_ERR_CQ_DISABLE, /* -8179 */
53c747e72bSJerin Jacob NICVF_ERR_CQ_RESET, /* -8178 */
54c747e72bSJerin Jacob NICVF_ERR_SQ_DISABLE, /* -8177 */
55c747e72bSJerin Jacob NICVF_ERR_SQ_RESET, /* -8176 */
56c747e72bSJerin Jacob NICVF_ERR_SQ_PF_CFG, /* -8175 */
57c747e72bSJerin Jacob NICVF_ERR_LOOPBACK_CFG, /* -8174 */
58c747e72bSJerin Jacob NICVF_ERR_BASE_INIT, /* -8173 */
597694fab2SJerin Jacob NICVF_ERR_RSS_TBL_UPDATE,/* -8172 */
607694fab2SJerin Jacob NICVF_ERR_RSS_GET_SZ, /* -8171 */
61c747e72bSJerin Jacob };
62c747e72bSJerin Jacob
63df6e0a06SSantosh Shukla typedef nicvf_iova_addr_t (*rbdr_pool_get_handler)(void *dev, void *opaque);
64c747e72bSJerin Jacob
65263a688cSJerin Jacob struct nicvf_hw_rx_qstats {
66263a688cSJerin Jacob uint64_t q_rx_bytes;
67263a688cSJerin Jacob uint64_t q_rx_packets;
68263a688cSJerin Jacob };
69263a688cSJerin Jacob
70263a688cSJerin Jacob struct nicvf_hw_tx_qstats {
71263a688cSJerin Jacob uint64_t q_tx_bytes;
72263a688cSJerin Jacob uint64_t q_tx_packets;
73263a688cSJerin Jacob };
74263a688cSJerin Jacob
75263a688cSJerin Jacob struct nicvf_hw_stats {
76263a688cSJerin Jacob uint64_t rx_bytes;
77263a688cSJerin Jacob uint64_t rx_ucast_frames;
78263a688cSJerin Jacob uint64_t rx_bcast_frames;
79263a688cSJerin Jacob uint64_t rx_mcast_frames;
80263a688cSJerin Jacob uint64_t rx_fcs_errors;
81263a688cSJerin Jacob uint64_t rx_l2_errors;
82263a688cSJerin Jacob uint64_t rx_drop_red;
83263a688cSJerin Jacob uint64_t rx_drop_red_bytes;
84263a688cSJerin Jacob uint64_t rx_drop_overrun;
85263a688cSJerin Jacob uint64_t rx_drop_overrun_bytes;
86263a688cSJerin Jacob uint64_t rx_drop_bcast;
87263a688cSJerin Jacob uint64_t rx_drop_mcast;
88263a688cSJerin Jacob uint64_t rx_drop_l3_bcast;
89263a688cSJerin Jacob uint64_t rx_drop_l3_mcast;
90263a688cSJerin Jacob
91263a688cSJerin Jacob uint64_t tx_bytes_ok;
92263a688cSJerin Jacob uint64_t tx_ucast_frames_ok;
93263a688cSJerin Jacob uint64_t tx_bcast_frames_ok;
94263a688cSJerin Jacob uint64_t tx_mcast_frames_ok;
95263a688cSJerin Jacob uint64_t tx_drops;
96263a688cSJerin Jacob };
97263a688cSJerin Jacob
987694fab2SJerin Jacob struct nicvf_rss_reta_info {
997694fab2SJerin Jacob uint8_t hash_bits;
1007694fab2SJerin Jacob uint16_t rss_size;
1017694fab2SJerin Jacob uint8_t ind_tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
1027694fab2SJerin Jacob };
1037694fab2SJerin Jacob
104c747e72bSJerin Jacob /* Common structs used in DPDK and base layer are defined in DPDK layer */
105c747e72bSJerin Jacob #include "../nicvf_struct.h"
106c747e72bSJerin Jacob
107c747e72bSJerin Jacob NICVF_STATIC_ASSERT(sizeof(struct nicvf_rbdr) <= 128);
108c747e72bSJerin Jacob NICVF_STATIC_ASSERT(sizeof(struct nicvf_txq) <= 128);
109c747e72bSJerin Jacob NICVF_STATIC_ASSERT(sizeof(struct nicvf_rxq) <= 128);
110c747e72bSJerin Jacob
111c747e72bSJerin Jacob static inline void
nicvf_reg_write(struct nicvf * nic,uint32_t offset,uint64_t val)112c747e72bSJerin Jacob nicvf_reg_write(struct nicvf *nic, uint32_t offset, uint64_t val)
113c747e72bSJerin Jacob {
114c747e72bSJerin Jacob nicvf_addr_write(nic->reg_base + offset, val);
115c747e72bSJerin Jacob }
116c747e72bSJerin Jacob
117c747e72bSJerin Jacob static inline uint64_t
nicvf_reg_read(struct nicvf * nic,uint32_t offset)118c747e72bSJerin Jacob nicvf_reg_read(struct nicvf *nic, uint32_t offset)
119c747e72bSJerin Jacob {
120c747e72bSJerin Jacob return nicvf_addr_read(nic->reg_base + offset);
121c747e72bSJerin Jacob }
122c747e72bSJerin Jacob
123c747e72bSJerin Jacob static inline uintptr_t
nicvf_qset_base(struct nicvf * nic,uint32_t qidx)124c747e72bSJerin Jacob nicvf_qset_base(struct nicvf *nic, uint32_t qidx)
125c747e72bSJerin Jacob {
126c747e72bSJerin Jacob return nic->reg_base + (qidx << NIC_Q_NUM_SHIFT);
127c747e72bSJerin Jacob }
128c747e72bSJerin Jacob
129c747e72bSJerin Jacob static inline void
nicvf_queue_reg_write(struct nicvf * nic,uint32_t offset,uint32_t qidx,uint64_t val)130c747e72bSJerin Jacob nicvf_queue_reg_write(struct nicvf *nic, uint32_t offset, uint32_t qidx,
131c747e72bSJerin Jacob uint64_t val)
132c747e72bSJerin Jacob {
133c747e72bSJerin Jacob nicvf_addr_write(nicvf_qset_base(nic, qidx) + offset, val);
134c747e72bSJerin Jacob }
135c747e72bSJerin Jacob
136c747e72bSJerin Jacob static inline uint64_t
nicvf_queue_reg_read(struct nicvf * nic,uint32_t offset,uint32_t qidx)137c747e72bSJerin Jacob nicvf_queue_reg_read(struct nicvf *nic, uint32_t offset, uint32_t qidx)
138c747e72bSJerin Jacob {
139c747e72bSJerin Jacob return nicvf_addr_read(nicvf_qset_base(nic, qidx) + offset);
140c747e72bSJerin Jacob }
141c747e72bSJerin Jacob
142c747e72bSJerin Jacob static inline void
nicvf_disable_all_interrupts(struct nicvf * nic)143c747e72bSJerin Jacob nicvf_disable_all_interrupts(struct nicvf *nic)
144c747e72bSJerin Jacob {
145c747e72bSJerin Jacob nicvf_reg_write(nic, NIC_VF_ENA_W1C, NICVF_INTR_ALL_MASK);
146c747e72bSJerin Jacob nicvf_reg_write(nic, NIC_VF_INT, NICVF_INTR_ALL_MASK);
147c747e72bSJerin Jacob }
148c747e72bSJerin Jacob
149c747e72bSJerin Jacob static inline uint32_t
nicvf_hw_version(struct nicvf * nic)150c747e72bSJerin Jacob nicvf_hw_version(struct nicvf *nic)
151c747e72bSJerin Jacob {
152c747e72bSJerin Jacob return nic->subsystem_device_id;
153c747e72bSJerin Jacob }
154c747e72bSJerin Jacob
155c747e72bSJerin Jacob static inline uint64_t
nicvf_hw_cap(struct nicvf * nic)156c747e72bSJerin Jacob nicvf_hw_cap(struct nicvf *nic)
157c747e72bSJerin Jacob {
158c747e72bSJerin Jacob return nic->hwcap;
159c747e72bSJerin Jacob }
160c747e72bSJerin Jacob
161c747e72bSJerin Jacob int nicvf_base_init(struct nicvf *nic);
162c747e72bSJerin Jacob
163c747e72bSJerin Jacob int nicvf_reg_get_count(void);
164c747e72bSJerin Jacob int nicvf_reg_poll_interrupts(struct nicvf *nic);
165c747e72bSJerin Jacob int nicvf_reg_dump(struct nicvf *nic, uint64_t *data);
166c747e72bSJerin Jacob
167c747e72bSJerin Jacob int nicvf_qset_config(struct nicvf *nic);
168c747e72bSJerin Jacob int nicvf_qset_reclaim(struct nicvf *nic);
169c747e72bSJerin Jacob
170c747e72bSJerin Jacob int nicvf_qset_rbdr_config(struct nicvf *nic, uint16_t qidx);
171c747e72bSJerin Jacob int nicvf_qset_rbdr_reclaim(struct nicvf *nic, uint16_t qidx);
172394014bcSKamil Rytarowski int nicvf_qset_rbdr_precharge(void *dev, struct nicvf *nic,
173394014bcSKamil Rytarowski uint16_t ridx, rbdr_pool_get_handler handler,
174c747e72bSJerin Jacob uint32_t max_buffs);
175c747e72bSJerin Jacob int nicvf_qset_rbdr_active(struct nicvf *nic, uint16_t qidx);
176c747e72bSJerin Jacob
177c747e72bSJerin Jacob int nicvf_qset_rq_config(struct nicvf *nic, uint16_t qidx,
178c747e72bSJerin Jacob struct nicvf_rxq *rxq);
179c747e72bSJerin Jacob int nicvf_qset_rq_reclaim(struct nicvf *nic, uint16_t qidx);
180c747e72bSJerin Jacob
181c747e72bSJerin Jacob int nicvf_qset_cq_config(struct nicvf *nic, uint16_t qidx,
182c747e72bSJerin Jacob struct nicvf_rxq *rxq);
183c747e72bSJerin Jacob int nicvf_qset_cq_reclaim(struct nicvf *nic, uint16_t qidx);
184c747e72bSJerin Jacob
185c747e72bSJerin Jacob int nicvf_qset_sq_config(struct nicvf *nic, uint16_t qidx,
186c747e72bSJerin Jacob struct nicvf_txq *txq);
187c747e72bSJerin Jacob int nicvf_qset_sq_reclaim(struct nicvf *nic, uint16_t qidx);
188c747e72bSJerin Jacob
189c747e72bSJerin Jacob uint32_t nicvf_qsize_rbdr_roundup(uint32_t val);
190c747e72bSJerin Jacob uint32_t nicvf_qsize_cq_roundup(uint32_t val);
191c747e72bSJerin Jacob uint32_t nicvf_qsize_sq_roundup(uint32_t val);
192c747e72bSJerin Jacob
193c747e72bSJerin Jacob void nicvf_vlan_hw_strip(struct nicvf *nic, bool enable);
194c747e72bSJerin Jacob
1958a946db3SJerin Jacob void nicvf_apad_config(struct nicvf *nic, bool enable);
196279d3319SRakesh Kudurumalla void nicvf_first_skip_config(struct nicvf *nic, uint8_t dwords);
1978a946db3SJerin Jacob
1987694fab2SJerin Jacob int nicvf_rss_config(struct nicvf *nic, uint32_t qcnt, uint64_t cfg);
1997694fab2SJerin Jacob int nicvf_rss_term(struct nicvf *nic);
2007694fab2SJerin Jacob
2017694fab2SJerin Jacob int nicvf_rss_reta_update(struct nicvf *nic, uint8_t *tbl, uint32_t max_count);
2027694fab2SJerin Jacob int nicvf_rss_reta_query(struct nicvf *nic, uint8_t *tbl, uint32_t max_count);
2037694fab2SJerin Jacob
2047694fab2SJerin Jacob void nicvf_rss_set_key(struct nicvf *nic, uint8_t *key);
2057694fab2SJerin Jacob void nicvf_rss_get_key(struct nicvf *nic, uint8_t *key);
2067694fab2SJerin Jacob
2077694fab2SJerin Jacob void nicvf_rss_set_cfg(struct nicvf *nic, uint64_t val);
2087694fab2SJerin Jacob uint64_t nicvf_rss_get_cfg(struct nicvf *nic);
2097694fab2SJerin Jacob
210c747e72bSJerin Jacob int nicvf_loopback_config(struct nicvf *nic, bool enable);
211c747e72bSJerin Jacob
212263a688cSJerin Jacob void nicvf_hw_get_stats(struct nicvf *nic, struct nicvf_hw_stats *stats);
213263a688cSJerin Jacob void nicvf_hw_get_rx_qstats(struct nicvf *nic,
214263a688cSJerin Jacob struct nicvf_hw_rx_qstats *qstats, uint16_t qidx);
215263a688cSJerin Jacob void nicvf_hw_get_tx_qstats(struct nicvf *nic,
216263a688cSJerin Jacob struct nicvf_hw_tx_qstats *qstats, uint16_t qidx);
217263a688cSJerin Jacob
218c747e72bSJerin Jacob #endif /* _THUNDERX_NICVF_HW_H */
219