net/txgbe: add HW init and reset operation
[dpdk.git] / drivers / net / txgbe / base / txgbe_type.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020
3  */
4
5 #ifndef _TXGBE_TYPE_H_
6 #define _TXGBE_TYPE_H_
7
8 #define TXGBE_LINK_UP_TIME      90 /* 9.0 Seconds */
9
10 #define TXGBE_ALIGN                             128 /* as intel did */
11
12 #include "txgbe_status.h"
13 #include "txgbe_osdep.h"
14 #include "txgbe_devids.h"
15
16 enum txgbe_eeprom_type {
17         txgbe_eeprom_unknown = 0,
18         txgbe_eeprom_spi,
19         txgbe_eeprom_flash,
20         txgbe_eeprom_none /* No NVM support */
21 };
22
23 enum txgbe_mac_type {
24         txgbe_mac_unknown = 0,
25         txgbe_mac_raptor,
26         txgbe_mac_raptor_vf,
27         txgbe_num_macs
28 };
29
30 enum txgbe_phy_type {
31         txgbe_phy_unknown = 0,
32         txgbe_phy_none,
33         txgbe_phy_tn,
34         txgbe_phy_aq,
35         txgbe_phy_ext_1g_t,
36         txgbe_phy_cu_mtd,
37         txgbe_phy_cu_unknown,
38         txgbe_phy_qt,
39         txgbe_phy_xaui,
40         txgbe_phy_nl,
41         txgbe_phy_sfp_tyco_passive,
42         txgbe_phy_sfp_unknown_passive,
43         txgbe_phy_sfp_unknown_active,
44         txgbe_phy_sfp_avago,
45         txgbe_phy_sfp_ftl,
46         txgbe_phy_sfp_ftl_active,
47         txgbe_phy_sfp_unknown,
48         txgbe_phy_sfp_intel,
49         txgbe_phy_qsfp_unknown_passive,
50         txgbe_phy_qsfp_unknown_active,
51         txgbe_phy_qsfp_intel,
52         txgbe_phy_qsfp_unknown,
53         txgbe_phy_sfp_unsupported, /* Enforce bit set with unsupported module */
54         txgbe_phy_sgmii,
55         txgbe_phy_fw,
56         txgbe_phy_generic
57 };
58
59 /*
60  * SFP+ module type IDs:
61  *
62  * ID   Module Type
63  * =============
64  * 0    SFP_DA_CU
65  * 1    SFP_SR
66  * 2    SFP_LR
67  * 3    SFP_DA_CU_CORE0 - chip-specific
68  * 4    SFP_DA_CU_CORE1 - chip-specific
69  * 5    SFP_SR/LR_CORE0 - chip-specific
70  * 6    SFP_SR/LR_CORE1 - chip-specific
71  */
72 enum txgbe_sfp_type {
73         txgbe_sfp_type_unknown = 0,
74         txgbe_sfp_type_da_cu,
75         txgbe_sfp_type_sr,
76         txgbe_sfp_type_lr,
77         txgbe_sfp_type_da_cu_core0,
78         txgbe_sfp_type_da_cu_core1,
79         txgbe_sfp_type_srlr_core0,
80         txgbe_sfp_type_srlr_core1,
81         txgbe_sfp_type_da_act_lmt_core0,
82         txgbe_sfp_type_da_act_lmt_core1,
83         txgbe_sfp_type_1g_cu_core0,
84         txgbe_sfp_type_1g_cu_core1,
85         txgbe_sfp_type_1g_sx_core0,
86         txgbe_sfp_type_1g_sx_core1,
87         txgbe_sfp_type_1g_lx_core0,
88         txgbe_sfp_type_1g_lx_core1,
89         txgbe_sfp_type_not_present = 0xFFFE,
90         txgbe_sfp_type_not_known = 0xFFFF
91 };
92
93 enum txgbe_media_type {
94         txgbe_media_type_unknown = 0,
95         txgbe_media_type_fiber,
96         txgbe_media_type_fiber_qsfp,
97         txgbe_media_type_copper,
98         txgbe_media_type_backplane,
99         txgbe_media_type_cx4,
100         txgbe_media_type_virtual
101 };
102
103 /* PCI bus types */
104 enum txgbe_bus_type {
105         txgbe_bus_type_unknown = 0,
106         txgbe_bus_type_pci,
107         txgbe_bus_type_pcix,
108         txgbe_bus_type_pci_express,
109         txgbe_bus_type_internal,
110         txgbe_bus_type_reserved
111 };
112
113 /* PCI bus speeds */
114 enum txgbe_bus_speed {
115         txgbe_bus_speed_unknown = 0,
116         txgbe_bus_speed_33      = 33,
117         txgbe_bus_speed_66      = 66,
118         txgbe_bus_speed_100     = 100,
119         txgbe_bus_speed_120     = 120,
120         txgbe_bus_speed_133     = 133,
121         txgbe_bus_speed_2500    = 2500,
122         txgbe_bus_speed_5000    = 5000,
123         txgbe_bus_speed_8000    = 8000,
124         txgbe_bus_speed_reserved
125 };
126
127 /* PCI bus widths */
128 enum txgbe_bus_width {
129         txgbe_bus_width_unknown = 0,
130         txgbe_bus_width_pcie_x1 = 1,
131         txgbe_bus_width_pcie_x2 = 2,
132         txgbe_bus_width_pcie_x4 = 4,
133         txgbe_bus_width_pcie_x8 = 8,
134         txgbe_bus_width_32      = 32,
135         txgbe_bus_width_64      = 64,
136         txgbe_bus_width_reserved
137 };
138
139 struct txgbe_hw;
140
141 /* Bus parameters */
142 struct txgbe_bus_info {
143         s32 (*get_bus_info)(struct txgbe_hw *hw);
144         void (*set_lan_id)(struct txgbe_hw *hw);
145
146         enum txgbe_bus_speed speed;
147         enum txgbe_bus_width width;
148         enum txgbe_bus_type type;
149
150         u16 func;
151         u8 lan_id;
152         u16 instance_id;
153 };
154
155 /* iterator type for walking multicast address lists */
156 typedef u8* (*txgbe_mc_addr_itr) (struct txgbe_hw *hw, u8 **mc_addr_ptr,
157                                   u32 *vmdq);
158
159 struct txgbe_link_info {
160         s32 (*read_link)(struct txgbe_hw *hw, u8 addr, u16 reg, u16 *val);
161         s32 (*read_link_unlocked)(struct txgbe_hw *hw, u8 addr, u16 reg,
162                                   u16 *val);
163         s32 (*write_link)(struct txgbe_hw *hw, u8 addr, u16 reg, u16 val);
164         s32 (*write_link_unlocked)(struct txgbe_hw *hw, u8 addr, u16 reg,
165                                    u16 val);
166
167         u8 addr;
168 };
169
170 struct txgbe_rom_info {
171         s32 (*init_params)(struct txgbe_hw *hw);
172         s32 (*read16)(struct txgbe_hw *hw, u32 offset, u16 *data);
173         s32 (*readw_sw)(struct txgbe_hw *hw, u32 offset, u16 *data);
174         s32 (*readw_buffer)(struct txgbe_hw *hw, u32 offset, u32 words,
175                             void *data);
176         s32 (*read32)(struct txgbe_hw *hw, u32 addr, u32 *data);
177         s32 (*read_buffer)(struct txgbe_hw *hw, u32 addr, u32 len, void *data);
178         s32 (*write16)(struct txgbe_hw *hw, u32 offset, u16 data);
179         s32 (*writew_sw)(struct txgbe_hw *hw, u32 offset, u16 data);
180         s32 (*writew_buffer)(struct txgbe_hw *hw, u32 offset, u32 words,
181                              void *data);
182         s32 (*write32)(struct txgbe_hw *hw, u32 addr, u32 data);
183         s32 (*write_buffer)(struct txgbe_hw *hw, u32 addr, u32 len, void *data);
184         s32 (*validate_checksum)(struct txgbe_hw *hw, u16 *checksum_val);
185         s32 (*update_checksum)(struct txgbe_hw *hw);
186         s32 (*calc_checksum)(struct txgbe_hw *hw);
187
188         enum txgbe_eeprom_type type;
189         u32 semaphore_delay;
190         u16 word_size;
191         u16 address_bits;
192         u16 word_page_size;
193         u16 ctrl_word_3;
194
195         u32 sw_addr;
196 };
197
198 struct txgbe_flash_info {
199         u32 semaphore_delay;
200         u32 dword_size;
201         u16 address_bits;
202 };
203
204 #define TXGBE_FLAGS_DOUBLE_RESET_REQUIRED       0x01
205 struct txgbe_mac_info {
206         s32 (*init_hw)(struct txgbe_hw *hw);
207         s32 (*reset_hw)(struct txgbe_hw *hw);
208         s32 (*start_hw)(struct txgbe_hw *hw);
209         s32 (*stop_hw)(struct txgbe_hw *hw);
210         s32 (*clear_hw_cntrs)(struct txgbe_hw *hw);
211         s32 (*get_mac_addr)(struct txgbe_hw *hw, u8 *mac_addr);
212         s32 (*get_san_mac_addr)(struct txgbe_hw *hw, u8 *san_mac_addr);
213         s32 (*set_san_mac_addr)(struct txgbe_hw *hw, u8 *san_mac_addr);
214         s32 (*get_device_caps)(struct txgbe_hw *hw, u16 *device_caps);
215         s32 (*get_wwn_prefix)(struct txgbe_hw *hw, u16 *wwnn_prefix,
216                                  u16 *wwpn_prefix);
217         s32 (*setup_sfp)(struct txgbe_hw *hw);
218         s32 (*enable_rx_dma)(struct txgbe_hw *hw, u32 regval);
219         s32 (*disable_sec_rx_path)(struct txgbe_hw *hw);
220         s32 (*enable_sec_rx_path)(struct txgbe_hw *hw);
221         s32 (*disable_sec_tx_path)(struct txgbe_hw *hw);
222         s32 (*enable_sec_tx_path)(struct txgbe_hw *hw);
223         s32 (*acquire_swfw_sync)(struct txgbe_hw *hw, u32 mask);
224         void (*release_swfw_sync)(struct txgbe_hw *hw, u32 mask);
225         u64 (*autoc_read)(struct txgbe_hw *hw);
226         void (*autoc_write)(struct txgbe_hw *hw, u64 value);
227         s32 (*prot_autoc_read)(struct txgbe_hw *hw, bool *locked, u64 *value);
228         s32 (*prot_autoc_write)(struct txgbe_hw *hw, bool locked, u64 value);
229         s32 (*negotiate_api_version)(struct txgbe_hw *hw, int api);
230
231         /* Link */
232         void (*disable_tx_laser)(struct txgbe_hw *hw);
233         void (*enable_tx_laser)(struct txgbe_hw *hw);
234         void (*flap_tx_laser)(struct txgbe_hw *hw);
235         s32 (*setup_link)(struct txgbe_hw *hw, u32 speed,
236                                bool autoneg_wait_to_complete);
237         s32 (*setup_mac_link)(struct txgbe_hw *hw, u32 speed,
238                                bool autoneg_wait_to_complete);
239         s32 (*check_link)(struct txgbe_hw *hw, u32 *speed,
240                                bool *link_up, bool link_up_wait_to_complete);
241         s32 (*get_link_capabilities)(struct txgbe_hw *hw,
242                                       u32 *speed, bool *autoneg);
243         void (*set_rate_select_speed)(struct txgbe_hw *hw, u32 speed);
244
245         /* Packet Buffer manipulation */
246         void (*setup_pba)(struct txgbe_hw *hw, int num_pb, u32 headroom,
247                              int strategy);
248
249         /* LED */
250         s32 (*led_on)(struct txgbe_hw *hw, u32 index);
251         s32 (*led_off)(struct txgbe_hw *hw, u32 index);
252
253         /* RAR, Multicast, VLAN */
254         s32 (*set_rar)(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
255                           u32 enable_addr);
256         s32 (*set_uc_addr)(struct txgbe_hw *hw, u32 index, u8 *addr);
257         s32 (*clear_rar)(struct txgbe_hw *hw, u32 index);
258         s32 (*set_vmdq)(struct txgbe_hw *hw, u32 rar, u32 vmdq);
259         s32 (*clear_vmdq)(struct txgbe_hw *hw, u32 rar, u32 vmdq);
260         s32 (*init_rx_addrs)(struct txgbe_hw *hw);
261         s32 (*update_mc_addr_list)(struct txgbe_hw *hw, u8 *mc_addr_list,
262                                       u32 mc_addr_count,
263                                       txgbe_mc_addr_itr func, bool clear);
264         s32 (*clear_vfta)(struct txgbe_hw *hw);
265         s32 (*set_vfta)(struct txgbe_hw *hw, u32 vlan,
266                          u32 vind, bool vlan_on, bool vlvf_bypass);
267         s32 (*set_vlvf)(struct txgbe_hw *hw, u32 vlan, u32 vind,
268                            bool vlan_on, u32 *vfta_delta, u32 vfta,
269                            bool vlvf_bypass);
270         s32 (*init_uta_tables)(struct txgbe_hw *hw);
271         void (*set_mac_anti_spoofing)(struct txgbe_hw *hw, bool enable, int vf);
272         void (*set_vlan_anti_spoofing)(struct txgbe_hw *hw,
273                                         bool enable, int vf);
274         s32 (*update_xcast_mode)(struct txgbe_hw *hw, int xcast_mode);
275         s32 (*set_rlpml)(struct txgbe_hw *hw, u16 max_size);
276
277         /* Flow Control */
278         s32 (*fc_enable)(struct txgbe_hw *hw);
279         s32 (*setup_fc)(struct txgbe_hw *hw);
280         void (*fc_autoneg)(struct txgbe_hw *hw);
281
282         /* Manageability interface */
283         s32 (*set_fw_drv_ver)(struct txgbe_hw *hw, u8 maj, u8 min, u8 build,
284                          u8 ver, u16 len, char *driver_ver);
285         s32 (*get_thermal_sensor_data)(struct txgbe_hw *hw);
286         s32 (*init_thermal_sensor_thresh)(struct txgbe_hw *hw);
287         void (*get_rtrup2tc)(struct txgbe_hw *hw, u8 *map);
288         void (*disable_rx)(struct txgbe_hw *hw);
289         void (*enable_rx)(struct txgbe_hw *hw);
290         void (*set_ethertype_anti_spoofing)(struct txgbe_hw *hw,
291                                                 bool enable, int vf);
292         s32 (*dmac_update_tcs)(struct txgbe_hw *hw);
293         s32 (*dmac_config_tcs)(struct txgbe_hw *hw);
294         s32 (*dmac_config)(struct txgbe_hw *hw);
295         s32 (*setup_eee)(struct txgbe_hw *hw, bool enable_eee);
296
297         enum txgbe_mac_type type;
298         u8 perm_addr[ETH_ADDR_LEN];
299         u8 san_addr[ETH_ADDR_LEN];
300         /* prefix for World Wide Node Name (WWNN) */
301         u16 wwnn_prefix;
302         /* prefix for World Wide Port Name (WWPN) */
303         u16 wwpn_prefix;
304
305         u32 num_rar_entries;
306
307         u8  san_mac_rar_index;
308         u64 orig_autoc;  /* cached value of AUTOC */
309         bool orig_link_settings_stored;
310         bool autotry_restart;
311         u8 flags;
312         u32  max_link_up_time;
313 };
314
315 struct txgbe_phy_info {
316         u32 (*get_media_type)(struct txgbe_hw *hw);
317         s32 (*identify)(struct txgbe_hw *hw);
318         s32 (*identify_sfp)(struct txgbe_hw *hw);
319         s32 (*init)(struct txgbe_hw *hw);
320         s32 (*reset)(struct txgbe_hw *hw);
321         s32 (*read_reg)(struct txgbe_hw *hw, u32 reg_addr,
322                                 u32 device_type, u16 *phy_data);
323         s32 (*write_reg)(struct txgbe_hw *hw, u32 reg_addr,
324                                 u32 device_type, u16 phy_data);
325         s32 (*read_reg_mdi)(struct txgbe_hw *hw, u32 reg_addr,
326                                 u32 device_type, u16 *phy_data);
327         s32 (*write_reg_mdi)(struct txgbe_hw *hw, u32 reg_addr,
328                                 u32 device_type, u16 phy_data);
329         s32 (*setup_link)(struct txgbe_hw *hw);
330         s32 (*setup_internal_link)(struct txgbe_hw *hw);
331         s32 (*setup_link_speed)(struct txgbe_hw *hw, u32 speed,
332                                 bool autoneg_wait_to_complete);
333         s32 (*check_link)(struct txgbe_hw *hw, u32 *speed, bool *link_up);
334         s32 (*read_i2c_byte)(struct txgbe_hw *hw, u8 byte_offset,
335                                 u8 dev_addr, u8 *data);
336         s32 (*write_i2c_byte)(struct txgbe_hw *hw, u8 byte_offset,
337                                 u8 dev_addr, u8 data);
338         s32 (*read_i2c_sff8472)(struct txgbe_hw *hw, u8 byte_offset,
339                                 u8 *sff8472_data);
340         s32 (*read_i2c_eeprom)(struct txgbe_hw *hw, u8 byte_offset,
341                                 u8 *eeprom_data);
342         s32 (*write_i2c_eeprom)(struct txgbe_hw *hw, u8 byte_offset,
343                                 u8 eeprom_data);
344         s32 (*check_overtemp)(struct txgbe_hw *hw);
345         s32 (*set_phy_power)(struct txgbe_hw *hw, bool on);
346         s32 (*handle_lasi)(struct txgbe_hw *hw);
347         s32 (*read_i2c_byte_unlocked)(struct txgbe_hw *hw, u8 offset, u8 addr,
348                                       u8 *value);
349         s32 (*write_i2c_byte_unlocked)(struct txgbe_hw *hw, u8 offset, u8 addr,
350                                        u8 value);
351
352         enum txgbe_phy_type type;
353         enum txgbe_sfp_type sfp_type;
354         bool sfp_setup_needed;
355         bool reset_disable;
356         u32 media_type;
357 };
358
359 struct txgbe_mbx_info {
360         void (*init_params)(struct txgbe_hw *hw);
361         s32  (*read)(struct txgbe_hw *hw, u32 *msg, u16 size, u16 vf_number);
362         s32  (*write)(struct txgbe_hw *hw, u32 *msg, u16 size, u16 vf_number);
363         s32  (*read_posted)(struct txgbe_hw *hw, u32 *msg, u16 size,
364                                 u16 mbx_id);
365         s32  (*write_posted)(struct txgbe_hw *hw, u32 *msg, u16 size,
366                                 u16 mbx_id);
367         s32  (*check_for_msg)(struct txgbe_hw *hw, u16 mbx_id);
368         s32  (*check_for_ack)(struct txgbe_hw *hw, u16 mbx_id);
369         s32  (*check_for_rst)(struct txgbe_hw *hw, u16 mbx_id);
370 };
371
372 struct txgbe_hw {
373         void IOMEM *hw_addr;
374         void *back;
375         struct txgbe_mac_info mac;
376         struct txgbe_phy_info phy;
377         struct txgbe_link_info link;
378         struct txgbe_rom_info rom;
379         struct txgbe_flash_info flash;
380         struct txgbe_bus_info bus;
381         struct txgbe_mbx_info mbx;
382         u16 device_id;
383         u16 vendor_id;
384         u16 subsystem_device_id;
385         u16 subsystem_vendor_id;
386
387         bool allow_unsupported_sfp;
388
389         uint64_t isb_dma;
390         void IOMEM *isb_mem;
391         enum txgbe_reset_type {
392                 TXGBE_LAN_RESET = 0,
393                 TXGBE_SW_RESET,
394                 TXGBE_GLOBAL_RESET
395         } reset_type;
396 };
397
398 #include "txgbe_regs.h"
399 #include "txgbe_dummy.h"
400
401 #endif /* _TXGBE_TYPE_H_ */