net/ngbe: support basic statistics
[dpdk.git] / drivers / net / ngbe / base / ngbe_type.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3  * Copyright(c) 2010-2017 Intel Corporation
4  */
5
6 #ifndef _NGBE_TYPE_H_
7 #define _NGBE_TYPE_H_
8
9 #define NGBE_LINK_UP_TIME       90 /* 9.0 Seconds */
10
11 #define NGBE_FRAME_SIZE_DFT       (1522) /* Default frame size, +FCS */
12 #define NGBE_NUM_POOL             (32)
13 #define NGBE_MAX_QP               (8)
14
15 #define NGBE_ALIGN              128 /* as intel did */
16 #define NGBE_ISB_SIZE           16
17
18 #include "ngbe_status.h"
19 #include "ngbe_osdep.h"
20 #include "ngbe_devids.h"
21
22 struct ngbe_thermal_diode_data {
23         s16 temp;
24         s16 alarm_thresh;
25         s16 dalarm_thresh;
26 };
27
28 struct ngbe_thermal_sensor_data {
29         struct ngbe_thermal_diode_data sensor[1];
30 };
31
32 enum ngbe_eeprom_type {
33         ngbe_eeprom_unknown = 0,
34         ngbe_eeprom_spi,
35         ngbe_eeprom_flash,
36         ngbe_eeprom_none /* No NVM support */
37 };
38
39 enum ngbe_mac_type {
40         ngbe_mac_unknown = 0,
41         ngbe_mac_em,
42         ngbe_mac_em_vf,
43         ngbe_num_macs
44 };
45
46 enum ngbe_phy_type {
47         ngbe_phy_unknown = 0,
48         ngbe_phy_none,
49         ngbe_phy_rtl,
50         ngbe_phy_mvl,
51         ngbe_phy_mvl_sfi,
52         ngbe_phy_yt8521s,
53         ngbe_phy_yt8521s_sfi,
54         ngbe_phy_zte,
55         ngbe_phy_cu_mtd,
56 };
57
58 enum ngbe_media_type {
59         ngbe_media_type_unknown = 0,
60         ngbe_media_type_fiber,
61         ngbe_media_type_fiber_qsfp,
62         ngbe_media_type_copper,
63         ngbe_media_type_backplane,
64         ngbe_media_type_cx4,
65         ngbe_media_type_virtual
66 };
67
68 struct ngbe_hw;
69
70 struct ngbe_addr_filter_info {
71         u32 mta_in_use;
72 };
73
74 /* Bus parameters */
75 struct ngbe_bus_info {
76         void (*set_lan_id)(struct ngbe_hw *hw);
77
78         u16 func;
79         u8 lan_id;
80 };
81
82 /* Statistics counters collected by the MAC */
83 /* PB[] RxTx */
84 struct ngbe_pb_stats {
85         u64 tx_pb_xon_packets;
86         u64 rx_pb_xon_packets;
87         u64 tx_pb_xoff_packets;
88         u64 rx_pb_xoff_packets;
89         u64 rx_pb_dropped;
90         u64 rx_pb_mbuf_alloc_errors;
91         u64 tx_pb_xon2off_packets;
92 };
93
94 /* QP[] RxTx */
95 struct ngbe_qp_stats {
96         u64 rx_qp_packets;
97         u64 tx_qp_packets;
98         u64 rx_qp_bytes;
99         u64 tx_qp_bytes;
100         u64 rx_qp_mc_packets;
101 };
102
103 struct ngbe_hw_stats {
104         /* MNG RxTx */
105         u64 mng_bmc2host_packets;
106         u64 mng_host2bmc_packets;
107         /* Basix RxTx */
108         u64 rx_drop_packets;
109         u64 tx_drop_packets;
110         u64 rx_dma_drop;
111         u64 tx_secdrp_packets;
112         u64 rx_packets;
113         u64 tx_packets;
114         u64 rx_bytes;
115         u64 tx_bytes;
116         u64 rx_total_bytes;
117         u64 rx_total_packets;
118         u64 tx_total_packets;
119         u64 rx_total_missed_packets;
120         u64 rx_broadcast_packets;
121         u64 tx_broadcast_packets;
122         u64 rx_multicast_packets;
123         u64 tx_multicast_packets;
124         u64 rx_management_packets;
125         u64 tx_management_packets;
126         u64 rx_management_dropped;
127
128         /* Basic Error */
129         u64 rx_crc_errors;
130         u64 rx_illegal_byte_errors;
131         u64 rx_error_bytes;
132         u64 rx_mac_short_packet_dropped;
133         u64 rx_length_errors;
134         u64 rx_undersize_errors;
135         u64 rx_fragment_errors;
136         u64 rx_oversize_errors;
137         u64 rx_jabber_errors;
138         u64 rx_l3_l4_xsum_error;
139         u64 mac_local_errors;
140         u64 mac_remote_errors;
141
142         /* MACSEC */
143         u64 tx_macsec_pkts_untagged;
144         u64 tx_macsec_pkts_encrypted;
145         u64 tx_macsec_pkts_protected;
146         u64 tx_macsec_octets_encrypted;
147         u64 tx_macsec_octets_protected;
148         u64 rx_macsec_pkts_untagged;
149         u64 rx_macsec_pkts_badtag;
150         u64 rx_macsec_pkts_nosci;
151         u64 rx_macsec_pkts_unknownsci;
152         u64 rx_macsec_octets_decrypted;
153         u64 rx_macsec_octets_validated;
154         u64 rx_macsec_sc_pkts_unchecked;
155         u64 rx_macsec_sc_pkts_delayed;
156         u64 rx_macsec_sc_pkts_late;
157         u64 rx_macsec_sa_pkts_ok;
158         u64 rx_macsec_sa_pkts_invalid;
159         u64 rx_macsec_sa_pkts_notvalid;
160         u64 rx_macsec_sa_pkts_unusedsa;
161         u64 rx_macsec_sa_pkts_notusingsa;
162
163         /* MAC RxTx */
164         u64 rx_size_64_packets;
165         u64 rx_size_65_to_127_packets;
166         u64 rx_size_128_to_255_packets;
167         u64 rx_size_256_to_511_packets;
168         u64 rx_size_512_to_1023_packets;
169         u64 rx_size_1024_to_max_packets;
170         u64 tx_size_64_packets;
171         u64 tx_size_65_to_127_packets;
172         u64 tx_size_128_to_255_packets;
173         u64 tx_size_256_to_511_packets;
174         u64 tx_size_512_to_1023_packets;
175         u64 tx_size_1024_to_max_packets;
176
177         /* Flow Control */
178         u64 tx_xon_packets;
179         u64 rx_xon_packets;
180         u64 tx_xoff_packets;
181         u64 rx_xoff_packets;
182
183         u64 rx_up_dropped;
184
185         u64 rdb_pkt_cnt;
186         u64 rdb_repli_cnt;
187         u64 rdb_drp_cnt;
188
189         /* QP[] RxTx */
190         struct {
191                 u64 rx_qp_packets;
192                 u64 tx_qp_packets;
193                 u64 rx_qp_bytes;
194                 u64 tx_qp_bytes;
195                 u64 rx_qp_mc_packets;
196                 u64 tx_qp_mc_packets;
197                 u64 rx_qp_bc_packets;
198                 u64 tx_qp_bc_packets;
199         } qp[NGBE_MAX_QP];
200
201 };
202
203 struct ngbe_rom_info {
204         s32 (*init_params)(struct ngbe_hw *hw);
205         s32 (*validate_checksum)(struct ngbe_hw *hw, u16 *checksum_val);
206
207         enum ngbe_eeprom_type type;
208         u32 semaphore_delay;
209         u16 word_size;
210         u16 address_bits;
211         u16 word_page_size;
212         u32 sw_addr;
213         u32 saved_version;
214         u16 cksum_devcap;
215 };
216
217 struct ngbe_mac_info {
218         s32 (*init_hw)(struct ngbe_hw *hw);
219         s32 (*reset_hw)(struct ngbe_hw *hw);
220         s32 (*start_hw)(struct ngbe_hw *hw);
221         s32 (*stop_hw)(struct ngbe_hw *hw);
222         s32 (*clear_hw_cntrs)(struct ngbe_hw *hw);
223         s32 (*get_mac_addr)(struct ngbe_hw *hw, u8 *mac_addr);
224         s32 (*enable_rx_dma)(struct ngbe_hw *hw, u32 regval);
225         s32 (*disable_sec_rx_path)(struct ngbe_hw *hw);
226         s32 (*enable_sec_rx_path)(struct ngbe_hw *hw);
227         s32 (*acquire_swfw_sync)(struct ngbe_hw *hw, u32 mask);
228         void (*release_swfw_sync)(struct ngbe_hw *hw, u32 mask);
229
230         /* Link */
231         s32 (*setup_link)(struct ngbe_hw *hw, u32 speed,
232                                bool autoneg_wait_to_complete);
233         s32 (*check_link)(struct ngbe_hw *hw, u32 *speed,
234                                bool *link_up, bool link_up_wait_to_complete);
235         s32 (*get_link_capabilities)(struct ngbe_hw *hw,
236                                       u32 *speed, bool *autoneg);
237
238         /* RAR */
239         s32 (*set_rar)(struct ngbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
240                           u32 enable_addr);
241         s32 (*clear_rar)(struct ngbe_hw *hw, u32 index);
242         s32 (*set_vmdq)(struct ngbe_hw *hw, u32 rar, u32 vmdq);
243         s32 (*clear_vmdq)(struct ngbe_hw *hw, u32 rar, u32 vmdq);
244         s32 (*init_rx_addrs)(struct ngbe_hw *hw);
245         s32 (*clear_vfta)(struct ngbe_hw *hw);
246
247         /* Manageability interface */
248         s32 (*init_thermal_sensor_thresh)(struct ngbe_hw *hw);
249         s32 (*check_overtemp)(struct ngbe_hw *hw);
250
251         enum ngbe_mac_type type;
252         u8 addr[ETH_ADDR_LEN];
253         u8 perm_addr[ETH_ADDR_LEN];
254         s32 mc_filter_type;
255         u32 mcft_size;
256         u32 vft_size;
257         u32 num_rar_entries;
258         u32 max_tx_queues;
259         u32 max_rx_queues;
260         bool get_link_status;
261         struct ngbe_thermal_sensor_data  thermal_sensor_data;
262         bool set_lben;
263         u32  max_link_up_time;
264
265         u32 default_speeds;
266         bool autoneg;
267 };
268
269 struct ngbe_phy_info {
270         s32 (*identify)(struct ngbe_hw *hw);
271         s32 (*init_hw)(struct ngbe_hw *hw);
272         s32 (*reset_hw)(struct ngbe_hw *hw);
273         s32 (*read_reg)(struct ngbe_hw *hw, u32 reg_addr,
274                                 u32 device_type, u16 *phy_data);
275         s32 (*write_reg)(struct ngbe_hw *hw, u32 reg_addr,
276                                 u32 device_type, u16 phy_data);
277         s32 (*read_reg_unlocked)(struct ngbe_hw *hw, u32 reg_addr,
278                                 u32 device_type, u16 *phy_data);
279         s32 (*write_reg_unlocked)(struct ngbe_hw *hw, u32 reg_addr,
280                                 u32 device_type, u16 phy_data);
281         s32 (*setup_link)(struct ngbe_hw *hw, u32 speed,
282                                 bool autoneg_wait_to_complete);
283         s32 (*check_link)(struct ngbe_hw *hw, u32 *speed, bool *link_up);
284
285         enum ngbe_media_type media_type;
286         enum ngbe_phy_type type;
287         u32 addr;
288         u32 id;
289         u32 revision;
290         u32 phy_semaphore_mask;
291         bool reset_disable;
292         u32 autoneg_advertised;
293 };
294
295 enum ngbe_isb_idx {
296         NGBE_ISB_HEADER,
297         NGBE_ISB_MISC,
298         NGBE_ISB_VEC0,
299         NGBE_ISB_VEC1,
300         NGBE_ISB_MAX
301 };
302
303 struct ngbe_hw {
304         void IOMEM *hw_addr;
305         void *back;
306         struct ngbe_mac_info mac;
307         struct ngbe_addr_filter_info addr_ctrl;
308         struct ngbe_phy_info phy;
309         struct ngbe_rom_info rom;
310         struct ngbe_bus_info bus;
311         u16 device_id;
312         u16 vendor_id;
313         u16 sub_device_id;
314         u16 sub_system_id;
315         bool adapter_stopped;
316
317         uint64_t isb_dma;
318         void IOMEM *isb_mem;
319         u16 nb_rx_queues;
320         u16 nb_tx_queues;
321
322         u32 q_rx_regs[8 * 4];
323         u32 q_tx_regs[8 * 4];
324         bool offset_loaded;
325         bool is_pf;
326         struct {
327                 u64 rx_qp_packets;
328                 u64 tx_qp_packets;
329                 u64 rx_qp_bytes;
330                 u64 tx_qp_bytes;
331                 u64 rx_qp_mc_packets;
332                 u64 tx_qp_mc_packets;
333                 u64 rx_qp_bc_packets;
334                 u64 tx_qp_bc_packets;
335         } qp_last[NGBE_MAX_QP];
336 };
337
338 #include "ngbe_regs.h"
339 #include "ngbe_dummy.h"
340
341 #endif /* _NGBE_TYPE_H_ */