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