xref: /openbsd/sys/dev/pci/ixgbe.h (revision 3b70601b)
1 /*	$OpenBSD: ixgbe.h,v 1.36 2024/06/09 05:18:12 jsg Exp $	*/
2 
3 /******************************************************************************
4 
5   Copyright (c) 2001-2008, Intel Corporation
6   All rights reserved.
7 
8   Redistribution and use in source and binary forms, with or without
9   modification, are permitted provided that the following conditions are met:
10 
11    1. Redistributions of source code must retain the above copyright notice,
12       this list of conditions and the following disclaimer.
13 
14    2. Redistributions in binary form must reproduce the above copyright
15       notice, this list of conditions and the following disclaimer in the
16       documentation and/or other materials provided with the distribution.
17 
18    3. Neither the name of the Intel Corporation nor the names of its
19       contributors may be used to endorse or promote products derived from
20       this software without specific prior written permission.
21 
22   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32   POSSIBILITY OF SUCH DAMAGE.
33 
34 ******************************************************************************/
35 /* FreeBSD: src/sys/dev/ixgbe/ixgbe_osdep.h 326022 2017-11-20 19:36:21Z pfg $*/
36 /* FreeBSD: src/sys/dev/ixgbe/ixgbe_common.h 326022 2017-11-20 19:36:21Z pfg $*/
37 
38 
39 #ifndef _IXGBE_H_
40 #define _IXGBE_H_
41 
42 #include "bpfilter.h"
43 #include "vlan.h"
44 #include "kstat.h"
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/sockio.h>
49 #include <sys/mbuf.h>
50 #include <sys/malloc.h>
51 #include <sys/kernel.h>
52 #include <sys/device.h>
53 #include <sys/socket.h>
54 #include <sys/timeout.h>
55 #include <sys/pool.h>
56 #include <sys/rwlock.h>
57 #include <sys/intrmap.h>
58 #include <sys/atomic.h>
59 #include <sys/kstat.h>
60 
61 #include <net/if.h>
62 #include <net/if_media.h>
63 #include <net/route.h>
64 #include <net/toeplitz.h>
65 
66 #include <netinet/in.h>
67 #include <netinet/if_ether.h>
68 #include <netinet/tcp.h>
69 #include <netinet/tcp_timer.h>
70 #include <netinet/tcp_var.h>
71 
72 #if NBPFILTER > 0
73 #include <net/bpf.h>
74 #endif
75 
76 typedef int	boolean_t;
77 #define TRUE	1
78 #define FALSE	0
79 
80 #include <dev/pci/pcireg.h>
81 #include <dev/pci/pcivar.h>
82 #include <dev/pci/pcidevs.h>
83 #include <dev/pci/ixgbe_type.h>
84 
85 #define DBG 0
86 #define MSGOUT(S, A, B)     printf(S "\n", A, B)
87 #define DEBUGFUNC(F)        DEBUGOUT(F);
88 #if DBG
89 	#define DEBUGOUT(S)         printf(S "\n")
90 	#define DEBUGOUT1(S,A)      printf(S "\n",A)
91 	#define DEBUGOUT2(S,A,B)    printf(S "\n",A,B)
92 	#define DEBUGOUT3(S,A,B,C)  printf(S "\n",A,B,C)
93 	#define DEBUGOUT4(S,A,B,C,D)  printf(S "\n",A,B,C,D)
94 	#define DEBUGOUT5(S,A,B,C,D,E)  printf(S "\n",A,B,C,D,E)
95 	#define DEBUGOUT6(S,A,B,C,D,E,F)  printf(S "\n",A,B,C,D,E,F)
96 	#define DEBUGOUT7(S,A,B,C,D,E,F,G)  printf(S "\n",A,B,C,D,E,F,G)
97 	#define ERROR_REPORT1(S,A)      printf(S "\n",A)
98 	#define ERROR_REPORT2(S,A,B)    printf(S "\n",A,B)
99 	#define ERROR_REPORT3(S,A,B,C)  printf(S "\n",A,B,C)
100 #else
101 	#define DEBUGOUT(S)
102 	#define DEBUGOUT1(S,A)
103 	#define DEBUGOUT2(S,A,B)
104 	#define DEBUGOUT3(S,A,B,C)
105 	#define DEBUGOUT4(S,A,B,C,D)
106 	#define DEBUGOUT5(S,A,B,C,D,E)
107 	#define DEBUGOUT6(S,A,B,C,D,E,F)
108 	#define DEBUGOUT7(S,A,B,C,D,E,F,G)
109 
110 	#define ERROR_REPORT1(S,A)
111 	#define ERROR_REPORT2(S,A,B)
112 	#define ERROR_REPORT3(S,A,B,C)
113 #endif
114 
115 #define FALSE		    		0
116 #define TRUE		    		1
117 #define CMD_MEM_WRT_INVALIDATE          0x0010  /* BIT_4 */
118 #define PCI_COMMAND_REGISTER            PCIR_COMMAND
119 
120 /* Compat glue */
121 #define PCIR_BAR(_x)	(0x10 + (_x) * 4)
122 #define roundup2(size, unit) (((size) + (unit) - 1) & ~((unit) - 1))
123 #define usec_delay(x) delay(x)
124 #define msec_delay(x) delay(1000 * (x))
125 
126 /* This is needed by the shared code */
127 struct ixgbe_hw;
128 
129 struct ixgbe_osdep {
130 	bus_dma_tag_t		 os_dmat;
131 	bus_space_tag_t		 os_memt;
132 	bus_space_handle_t	 os_memh;
133 
134 	bus_size_t		 os_memsize;
135 	bus_addr_t		 os_membase;
136 
137 	void			*os_sc;
138 	struct pci_attach_args	 os_pa;
139 };
140 
141 extern uint16_t ixgbe_read_pci_cfg(struct ixgbe_hw *, uint32_t);
142 #define IXGBE_READ_PCIE_WORD ixgbe_read_pci_cfg
143 
144 extern void ixgbe_write_pci_cfg(struct ixgbe_hw *, uint32_t, uint16_t);
145 #define IXGBE_WRITE_PCIE_WORD ixgbe_write_pci_cfg
146 
147 #define IXGBE_WRITE_FLUSH(a)						\
148 	IXGBE_READ_REG(a, IXGBE_STATUS)
149 #define IXGBE_READ_REG(a, reg)						\
150 	bus_space_read_4(((struct ixgbe_osdep *)(a)->back)->os_memt,	\
151 	((struct ixgbe_osdep *)(a)->back)->os_memh, reg)
152 #define IXGBE_WRITE_REG(a, reg, value)					\
153 	bus_space_write_4(((struct ixgbe_osdep *)(a)->back)->os_memt,	\
154 	((struct ixgbe_osdep *)(a)->back)->os_memh, reg, value)
155 #define IXGBE_READ_REG_ARRAY(a, reg, offset)				\
156 	bus_space_read_4(((struct ixgbe_osdep *)(a)->back)->os_memt,	\
157 	((struct ixgbe_osdep *)(a)->back)->os_memh, (reg + ((offset) << 2)))
158 #define IXGBE_WRITE_REG_ARRAY(a, reg, offset, value)			\
159 	bus_space_write_4(((struct ixgbe_osdep *)(a)->back)->os_memt,	\
160 	((struct ixgbe_osdep *)(a)->back)->os_memh, (reg + ((offset) << 2)), value)
161 
162 #define IXGBE_REMOVED(a) (0)
163 
164 /* MAC Operations */
165 uint16_t ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw);
166 int32_t ixgbe_init_ops_generic(struct ixgbe_hw *hw);
167 int32_t ixgbe_init_hw_generic(struct ixgbe_hw *hw);
168 int32_t ixgbe_start_hw_generic(struct ixgbe_hw *hw);
169 int32_t ixgbe_start_hw_gen2(struct ixgbe_hw *hw);
170 int32_t ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw);
171 int32_t ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, uint8_t *mac_addr);
172 int32_t ixgbe_get_bus_info_generic(struct ixgbe_hw *hw);
173 void    ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw);
174 int32_t ixgbe_stop_adapter_generic(struct ixgbe_hw *hw);
175 
176 int32_t ixgbe_led_on_generic(struct ixgbe_hw *hw, uint32_t index);
177 int32_t ixgbe_led_off_generic(struct ixgbe_hw *hw, uint32_t index);
178 
179 int32_t ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw);
180 int32_t ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, uint16_t offset, uint16_t data);
181 int32_t ixgbe_read_eerd_generic(struct ixgbe_hw *hw, uint16_t offset, uint16_t *data);
182 int32_t ixgbe_write_eewr_generic(struct ixgbe_hw *hw, uint16_t offset, uint16_t data);
183 int32_t ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, uint16_t offset,
184 					   uint16_t *data);
185 int32_t ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw);
186 int32_t ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
187 					       uint16_t *checksum_val);
188 int32_t ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw);
189 int32_t ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, uint32_t ee_reg);
190 
191 int32_t ixgbe_set_rar_generic(struct ixgbe_hw *hw, uint32_t index, uint8_t *addr, uint32_t vmdq,
192 			      uint32_t enable_addr);
193 int32_t ixgbe_clear_rar_generic(struct ixgbe_hw *hw, uint32_t index);
194 int32_t ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw);
195 int32_t ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, uint8_t *mc_addr_list,
196 					  uint32_t mc_addr_count,
197 					  ixgbe_mc_addr_itr func, bool clear);
198 int32_t ixgbe_enable_mc_generic(struct ixgbe_hw *hw);
199 int32_t ixgbe_disable_mc_generic(struct ixgbe_hw *hw);
200 int32_t ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, uint32_t regval);
201 int32_t ixgbe_disable_sec_rx_path_generic(struct ixgbe_hw *hw);
202 int32_t ixgbe_enable_sec_rx_path_generic(struct ixgbe_hw *hw);
203 
204 int32_t ixgbe_fc_enable_generic(struct ixgbe_hw *hw);
205 void ixgbe_fc_autoneg(struct ixgbe_hw *hw);
206 int32_t ixgbe_setup_fc_generic(struct ixgbe_hw *hw);
207 
208 int32_t ixgbe_validate_mac_addr(uint8_t *mac_addr);
209 int32_t ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, uint32_t mask);
210 void    ixgbe_release_swfw_sync(struct ixgbe_hw *hw, uint32_t mask);
211 int32_t ixgbe_disable_pcie_master(struct ixgbe_hw *hw);
212 
213 int32_t prot_autoc_read_generic(struct ixgbe_hw *hw, bool *, uint32_t *reg_val);
214 int32_t prot_autoc_write_generic(struct ixgbe_hw *hw, uint32_t reg_val, bool locked);
215 
216 int32_t ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, uint32_t index);
217 int32_t ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, uint32_t index);
218 
219 int32_t ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, uint32_t rar, uint32_t vmdq);
220 int32_t ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, uint32_t rar, uint32_t vmdq);
221 int32_t ixgbe_insert_mac_addr_generic(struct ixgbe_hw *hw, uint8_t *addr, uint32_t vmdq);
222 int32_t ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw);
223 int32_t ixgbe_set_vfta_generic(struct ixgbe_hw *hw, uint32_t vlan,
224 			       uint32_t vind, bool vlan_on, bool);
225 int32_t ixgbe_set_vlvf_generic(struct ixgbe_hw *hw, uint32_t vlan, uint32_t vind,
226 			       bool vlan_on, uint32_t*, uint32_t, bool);
227 int32_t ixgbe_clear_vfta_generic(struct ixgbe_hw *hw);
228 
229 int32_t ixgbe_check_mac_link_generic(struct ixgbe_hw *hw,
230 				     ixgbe_link_speed *speed,
231 				     bool *link_up,
232 				     bool link_up_wait_to_complete);
233 
234 int32_t ixgbe_get_device_caps_generic(struct ixgbe_hw *hw,
235 				      uint16_t *device_caps);
236 int32_t ixgbe_host_interface_command(struct ixgbe_hw *hw, uint32_t *buffer,
237 				     uint32_t length, uint32_t timeout,
238 				     bool return_data);
239 int32_t ixgbe_hic_unlocked(struct ixgbe_hw *, uint32_t *buffer, uint32_t length, uint32_t timeout);
240 void ixgbe_clear_tx_pending(struct ixgbe_hw *hw);
241 
242 bool ixgbe_mng_present(struct ixgbe_hw *hw);
243 bool ixgbe_mng_enabled(struct ixgbe_hw *hw);
244 
245 void ixgbe_disable_rx_generic(struct ixgbe_hw *hw);
246 void ixgbe_enable_rx_generic(struct ixgbe_hw *hw);
247 int32_t ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
248 					      ixgbe_link_speed speed,
249 					      bool autoneg_wait_to_complete);
250 void ixgbe_set_soft_rate_select_speed(struct ixgbe_hw *hw,
251 				      ixgbe_link_speed speed);
252 
253 int32_t ixgbe_negotiate_fc(struct ixgbe_hw *hw, uint32_t adv_reg, uint32_t lp_reg,
254 			uint32_t adv_sym, uint32_t adv_asm, uint32_t lp_sym, uint32_t lp_asm);
255 
256 int32_t ixgbe_init_shared_code(struct ixgbe_hw *hw);
257 
258 int32_t ixgbe_init_ops_82598(struct ixgbe_hw *hw);
259 int32_t ixgbe_init_ops_82599(struct ixgbe_hw *hw);
260 int32_t ixgbe_init_ops_X540(struct ixgbe_hw *hw);
261 int32_t ixgbe_init_ops_X550(struct ixgbe_hw *hw);
262 int32_t ixgbe_init_ops_X550EM(struct ixgbe_hw *hw);
263 int32_t ixgbe_init_ops_X550EM_a(struct ixgbe_hw *hw);
264 int32_t ixgbe_init_ops_X550EM_x(struct ixgbe_hw *hw);
265 
266 int32_t ixgbe_set_mac_type(struct ixgbe_hw *hw);
267 int32_t ixgbe_init_hw(struct ixgbe_hw *hw);
268 enum ixgbe_media_type ixgbe_get_media_type(struct ixgbe_hw *hw);
269 int32_t ixgbe_identify_phy(struct ixgbe_hw *hw);
270 void ixgbe_flap_tx_laser(struct ixgbe_hw *hw);
271 int32_t ixgbe_check_link(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
272 			 bool *link_up, bool link_up_wait_to_complete);
273 
274 int32_t ixgbe_set_rar(struct ixgbe_hw *hw, uint32_t index, uint8_t *addr,
275 		      uint32_t vmdq, uint32_t enable_addr);
276 int32_t ixgbe_set_vmdq(struct ixgbe_hw *hw, uint32_t rar, uint32_t vmdq);
277 int32_t ixgbe_clear_vmdq(struct ixgbe_hw *hw, uint32_t rar, uint32_t vmdq);
278 int32_t ixgbe_init_uta_tables(struct ixgbe_hw *hw);
279 
280 void ixgbe_add_uc_addr(struct ixgbe_hw *hw, uint8_t *addr, uint32_t vmdq);
281 void ixgbe_set_mta(struct ixgbe_hw *hw, uint8_t *mc_addr);
282 
283 void ixgbe_disable_rx(struct ixgbe_hw *hw);
284 void ixgbe_enable_rx(struct ixgbe_hw *hw);
285 
286 /* PHY */
287 int32_t ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw);
288 bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, uint32_t phy_addr);
289 enum ixgbe_phy_type ixgbe_get_phy_type_from_id(uint32_t phy_id);
290 int32_t ixgbe_get_phy_id(struct ixgbe_hw *hw);
291 int32_t ixgbe_identify_phy_generic(struct ixgbe_hw *hw);
292 int32_t ixgbe_reset_phy_generic(struct ixgbe_hw *hw);
293 int32_t ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, uint32_t reg_addr,
294 			       uint32_t device_type, uint16_t *phy_data);
295 int32_t ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, uint32_t reg_addr,
296 				uint32_t device_type, uint16_t phy_data);
297 int32_t ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, uint32_t reg_addr,
298 				   uint32_t device_type, uint16_t *phy_data);
299 int32_t ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, uint32_t reg_addr,
300 				    uint32_t device_type, uint16_t phy_data);
301 int32_t ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw);
302 int32_t ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
303 					   ixgbe_link_speed speed,
304 					   bool autoneg_wait_to_complete);
305 int32_t ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
306 						   ixgbe_link_speed *speed,
307 						   bool *autoneg);
308 int32_t ixgbe_check_reset_blocked(struct ixgbe_hw *hw);
309 
310 /* PHY specific */
311 int32_t ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw,
312 				 ixgbe_link_speed *speed,
313 				 bool *link_up);
314 int32_t ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw);
315 int32_t ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
316 					   uint16_t *firmware_version);
317 int32_t ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
318 					       uint16_t *firmware_version);
319 
320 int32_t ixgbe_reset_phy_nl(struct ixgbe_hw *hw);
321 bool ixgbe_is_sfp(struct ixgbe_hw *hw);
322 int32_t ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on);
323 int32_t ixgbe_identify_module_generic(struct ixgbe_hw *hw);
324 int32_t ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw);
325 uint64_t ixgbe_get_supported_phy_sfp_layer_generic(struct ixgbe_hw *hw);
326 int32_t ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw);
327 int32_t ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
328 					    uint16_t *list_offset,
329 					    uint16_t *data_offset);
330 int32_t ixgbe_tn_check_overtemp(struct ixgbe_hw *hw);
331 int32_t ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, uint8_t byte_offset,
332 				    uint8_t dev_addr, uint8_t *data);
333 int32_t ixgbe_read_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, uint8_t byte_offset,
334 					     uint8_t dev_addr, uint8_t *data);
335 int32_t ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, uint8_t byte_offset,
336 				     uint8_t dev_addr, uint8_t data);
337 int32_t ixgbe_write_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, uint8_t byte_offset,
338 					      uint8_t dev_addr, uint8_t data);
339 int32_t ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, uint8_t byte_offset,
340 				      uint8_t *eeprom_data);
341 int32_t ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, uint8_t byte_offset,
342 				       uint8_t eeprom_data);
343 void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw);
344 int32_t ixgbe_read_i2c_combined_generic_int(struct ixgbe_hw *, uint8_t addr, uint16_t reg,
345 					uint16_t *val, bool lock);
346 int32_t ixgbe_read_i2c_combined_generic(struct ixgbe_hw *, uint8_t addr, uint16_t reg,
347 					uint16_t *val);
348 int32_t ixgbe_read_i2c_combined_generic_unlocked(struct ixgbe_hw *, uint8_t addr,
349 						 uint16_t reg, uint16_t *val);
350 int32_t ixgbe_write_i2c_combined_generic_int(struct ixgbe_hw *, uint8_t addr, uint16_t reg,
351 					uint16_t val, bool lock);
352 int32_t ixgbe_write_i2c_combined_generic(struct ixgbe_hw *, uint8_t addr, uint16_t reg,
353 					 uint16_t val);
354 int32_t ixgbe_write_i2c_combined_generic_unlocked(struct ixgbe_hw *, uint8_t addr,
355 						  uint16_t reg, uint16_t val);
356 
357 /* MBX */
358 int32_t ixgbe_read_mbx(struct ixgbe_hw *, uint32_t *, uint16_t, uint16_t);
359 int32_t ixgbe_write_mbx(struct ixgbe_hw *, uint32_t *, uint16_t, uint16_t);
360 int32_t ixgbe_read_posted_mbx(struct ixgbe_hw *, uint32_t *, uint16_t, uint16_t);
361 int32_t ixgbe_write_posted_mbx(struct ixgbe_hw *, uint32_t *, uint16_t, uint16_t);
362 int32_t ixgbe_check_for_msg(struct ixgbe_hw *, uint16_t);
363 int32_t ixgbe_check_for_ack(struct ixgbe_hw *, uint16_t);
364 int32_t ixgbe_check_for_rst(struct ixgbe_hw *, uint16_t);
365 void ixgbe_init_mbx_ops_generic(struct ixgbe_hw *hw);
366 void ixgbe_init_mbx_params_pf(struct ixgbe_hw *);
367 
368 #endif /* _IXGBE_H_ */
369