xref: /freebsd/sys/dev/sfxge/sfxge.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1e948693eSPhilip Paeps /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4929c7febSAndrew Rybchenko  * Copyright (c) 2010-2016 Solarflare Communications Inc.
5e948693eSPhilip Paeps  * All rights reserved.
6e948693eSPhilip Paeps  *
7e948693eSPhilip Paeps  * This software was developed in part by Philip Paeps under contract for
8e948693eSPhilip Paeps  * Solarflare Communications, Inc.
9e948693eSPhilip Paeps  *
10e948693eSPhilip Paeps  * Redistribution and use in source and binary forms, with or without
113c838a9fSAndrew Rybchenko  * modification, are permitted provided that the following conditions are met:
12e948693eSPhilip Paeps  *
133c838a9fSAndrew Rybchenko  * 1. Redistributions of source code must retain the above copyright notice,
143c838a9fSAndrew Rybchenko  *    this list of conditions and the following disclaimer.
153c838a9fSAndrew Rybchenko  * 2. Redistributions in binary form must reproduce the above copyright notice,
163c838a9fSAndrew Rybchenko  *    this list of conditions and the following disclaimer in the documentation
173c838a9fSAndrew Rybchenko  *    and/or other materials provided with the distribution.
183c838a9fSAndrew Rybchenko  *
193c838a9fSAndrew Rybchenko  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
203c838a9fSAndrew Rybchenko  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
213c838a9fSAndrew Rybchenko  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223c838a9fSAndrew Rybchenko  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
233c838a9fSAndrew Rybchenko  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
243c838a9fSAndrew Rybchenko  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
253c838a9fSAndrew Rybchenko  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
263c838a9fSAndrew Rybchenko  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
273c838a9fSAndrew Rybchenko  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
283c838a9fSAndrew Rybchenko  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
293c838a9fSAndrew Rybchenko  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
303c838a9fSAndrew Rybchenko  *
313c838a9fSAndrew Rybchenko  * The views and conclusions contained in the software and documentation are
323c838a9fSAndrew Rybchenko  * those of the authors and should not be interpreted as representing official
333c838a9fSAndrew Rybchenko  * policies, either expressed or implied, of the FreeBSD Project.
34e948693eSPhilip Paeps  */
35e948693eSPhilip Paeps 
36e948693eSPhilip Paeps #ifndef _SFXGE_H
37e948693eSPhilip Paeps #define	_SFXGE_H
38e948693eSPhilip Paeps 
39e948693eSPhilip Paeps #include <sys/param.h>
40e948693eSPhilip Paeps #include <sys/kernel.h>
41e948693eSPhilip Paeps #include <sys/socket.h>
42e948693eSPhilip Paeps #include <sys/sysctl.h>
43e948693eSPhilip Paeps #include <sys/sx.h>
44e948693eSPhilip Paeps #include <vm/uma.h>
45e948693eSPhilip Paeps 
46e948693eSPhilip Paeps #include <net/ethernet.h>
47e948693eSPhilip Paeps #include <net/if.h>
4876039bc8SGleb Smirnoff #include <net/if_var.h>
49e948693eSPhilip Paeps #include <net/if_media.h>
50e948693eSPhilip Paeps #include <net/if_types.h>
51e948693eSPhilip Paeps 
523c838a9fSAndrew Rybchenko #include "sfxge_ioc.h"
533c838a9fSAndrew Rybchenko 
543c838a9fSAndrew Rybchenko /*
553c838a9fSAndrew Rybchenko  * Debugging
563c838a9fSAndrew Rybchenko  */
573c838a9fSAndrew Rybchenko #if 0
583c838a9fSAndrew Rybchenko #define	DBGPRINT(dev, fmt, args...) \
593c838a9fSAndrew Rybchenko 	device_printf(dev, "%s: " fmt "\n", __func__, ## args)
603c838a9fSAndrew Rybchenko #else
613c838a9fSAndrew Rybchenko #define	DBGPRINT(dev, fmt, args...)
623c838a9fSAndrew Rybchenko #endif
633c838a9fSAndrew Rybchenko 
64e948693eSPhilip Paeps /*
65e948693eSPhilip Paeps  * Backward-compatibility
66e948693eSPhilip Paeps  */
67e948693eSPhilip Paeps #ifndef CACHE_LINE_SIZE
68e948693eSPhilip Paeps /* This should be right on most machines the driver will be used on, and
69e948693eSPhilip Paeps  * we needn't care too much about wasting a few KB per interface.
70e948693eSPhilip Paeps  */
71e948693eSPhilip Paeps #define	CACHE_LINE_SIZE 128
72e948693eSPhilip Paeps #endif
73919c8da4SAndrew Rybchenko 
74e948693eSPhilip Paeps #ifndef IFCAP_LINKSTATE
75e948693eSPhilip Paeps #define	IFCAP_LINKSTATE 0
76e948693eSPhilip Paeps #endif
77919c8da4SAndrew Rybchenko 
78e948693eSPhilip Paeps #ifndef IFCAP_VLAN_HWTSO
79e948693eSPhilip Paeps #define	IFCAP_VLAN_HWTSO 0
80e948693eSPhilip Paeps #endif
81919c8da4SAndrew Rybchenko 
82e948693eSPhilip Paeps #ifndef IFM_10G_T
83e948693eSPhilip Paeps #define	IFM_10G_T IFM_UNKNOWN
84e948693eSPhilip Paeps #endif
85919c8da4SAndrew Rybchenko 
86e948693eSPhilip Paeps #ifndef IFM_10G_KX4
87e948693eSPhilip Paeps #define	IFM_10G_KX4 IFM_10G_CX4
88e948693eSPhilip Paeps #endif
89919c8da4SAndrew Rybchenko 
903c838a9fSAndrew Rybchenko #ifndef IFM_40G_CR4
913c838a9fSAndrew Rybchenko #define	IFM_40G_CR4 IFM_UNKNOWN
923c838a9fSAndrew Rybchenko #endif
933c838a9fSAndrew Rybchenko 
94e948693eSPhilip Paeps #ifdef IFM_ETH_RXPAUSE
95e948693eSPhilip Paeps #define	SFXGE_HAVE_PAUSE_MEDIAOPTS
96e948693eSPhilip Paeps #endif
97919c8da4SAndrew Rybchenko 
98e948693eSPhilip Paeps #ifndef CTLTYPE_U64
99e948693eSPhilip Paeps #define	CTLTYPE_U64 CTLTYPE_QUAD
100e948693eSPhilip Paeps #endif
101e948693eSPhilip Paeps 
102e948693eSPhilip Paeps #include "sfxge_rx.h"
103e948693eSPhilip Paeps #include "sfxge_tx.h"
104e948693eSPhilip Paeps 
105385b1d8eSGeorge V. Neville-Neil #define	ROUNDUP_POW_OF_TWO(_n)	(1ULL << flsl((_n) - 1))
106385b1d8eSGeorge V. Neville-Neil 
107e948693eSPhilip Paeps #define	SFXGE_IP_ALIGN	2
108e948693eSPhilip Paeps 
109e948693eSPhilip Paeps #define	SFXGE_ETHERTYPE_LOOPBACK	0x9000	/* Xerox loopback */
110e948693eSPhilip Paeps 
1119885e222SAndrew Rybchenko #define	SFXGE_MAGIC_RESERVED		0x8000
1129885e222SAndrew Rybchenko 
1139885e222SAndrew Rybchenko #define	SFXGE_MAGIC_DMAQ_LABEL_WIDTH	6
1149885e222SAndrew Rybchenko #define	SFXGE_MAGIC_DMAQ_LABEL_MASK \
1159885e222SAndrew Rybchenko 	((1 << SFXGE_MAGIC_DMAQ_LABEL_WIDTH) - 1)
1169885e222SAndrew Rybchenko 
117e1399ed7SAndrew Rybchenko enum sfxge_sw_ev {
118e1399ed7SAndrew Rybchenko 	SFXGE_SW_EV_RX_QFLUSH_DONE = 1,
119e1399ed7SAndrew Rybchenko 	SFXGE_SW_EV_RX_QFLUSH_FAILED,
120e1399ed7SAndrew Rybchenko 	SFXGE_SW_EV_RX_QREFILL,
121e1399ed7SAndrew Rybchenko 	SFXGE_SW_EV_TX_QFLUSH_DONE,
122e1399ed7SAndrew Rybchenko };
1239885e222SAndrew Rybchenko 
124e1399ed7SAndrew Rybchenko #define	SFXGE_SW_EV_MAGIC(_sw_ev) \
125e1399ed7SAndrew Rybchenko 	(SFXGE_MAGIC_RESERVED | ((_sw_ev) << SFXGE_MAGIC_DMAQ_LABEL_WIDTH))
1269885e222SAndrew Rybchenko 
12784bcd65eSAndrew Rybchenko static inline uint16_t
sfxge_sw_ev_mk_magic(enum sfxge_sw_ev sw_ev,unsigned int label)12884bcd65eSAndrew Rybchenko sfxge_sw_ev_mk_magic(enum sfxge_sw_ev sw_ev, unsigned int label)
12984bcd65eSAndrew Rybchenko {
13084bcd65eSAndrew Rybchenko 	KASSERT((label & SFXGE_MAGIC_DMAQ_LABEL_MASK) == label,
13184bcd65eSAndrew Rybchenko 	    ("(label & SFXGE_MAGIC_DMAQ_LABEL_MASK) != label"));
13284bcd65eSAndrew Rybchenko 	return SFXGE_SW_EV_MAGIC(sw_ev) | label;
13384bcd65eSAndrew Rybchenko }
13484bcd65eSAndrew Rybchenko 
13584bcd65eSAndrew Rybchenko static inline uint16_t
sfxge_sw_ev_rxq_magic(enum sfxge_sw_ev sw_ev,struct sfxge_rxq * rxq)13684bcd65eSAndrew Rybchenko sfxge_sw_ev_rxq_magic(enum sfxge_sw_ev sw_ev, struct sfxge_rxq *rxq)
13784bcd65eSAndrew Rybchenko {
13884bcd65eSAndrew Rybchenko 	return sfxge_sw_ev_mk_magic(sw_ev, 0);
13984bcd65eSAndrew Rybchenko }
14084bcd65eSAndrew Rybchenko 
14184bcd65eSAndrew Rybchenko static inline uint16_t
sfxge_sw_ev_txq_magic(enum sfxge_sw_ev sw_ev,struct sfxge_txq * txq)14284bcd65eSAndrew Rybchenko sfxge_sw_ev_txq_magic(enum sfxge_sw_ev sw_ev, struct sfxge_txq *txq)
14384bcd65eSAndrew Rybchenko {
14484bcd65eSAndrew Rybchenko 	return sfxge_sw_ev_mk_magic(sw_ev, txq->type);
14584bcd65eSAndrew Rybchenko }
14684bcd65eSAndrew Rybchenko 
147e948693eSPhilip Paeps enum sfxge_evq_state {
148e948693eSPhilip Paeps 	SFXGE_EVQ_UNINITIALIZED = 0,
149e948693eSPhilip Paeps 	SFXGE_EVQ_INITIALIZED,
150e948693eSPhilip Paeps 	SFXGE_EVQ_STARTING,
151e948693eSPhilip Paeps 	SFXGE_EVQ_STARTED
152e948693eSPhilip Paeps };
153e948693eSPhilip Paeps 
154e948693eSPhilip Paeps #define	SFXGE_EV_BATCH	16384
155e948693eSPhilip Paeps 
15662f5c496SAndrew Rybchenko #define	SFXGE_STATS_UPDATE_PERIOD_MS	1000
15762f5c496SAndrew Rybchenko 
158e948693eSPhilip Paeps struct sfxge_evq {
15976c85536SAndrew Rybchenko 	/* Structure members below are sorted by usage order */
16076c85536SAndrew Rybchenko 	struct sfxge_softc	*sc;
16176c85536SAndrew Rybchenko 	struct mtx		lock;
162e948693eSPhilip Paeps 	unsigned int		index;
16376c85536SAndrew Rybchenko 	enum sfxge_evq_state	init_state;
164e948693eSPhilip Paeps 	efsys_mem_t		mem;
165e948693eSPhilip Paeps 	efx_evq_t		*common;
166e948693eSPhilip Paeps 	unsigned int		read_ptr;
16776c85536SAndrew Rybchenko 	boolean_t		exception;
168e948693eSPhilip Paeps 	unsigned int		rx_done;
169e948693eSPhilip Paeps 	unsigned int		tx_done;
170e948693eSPhilip Paeps 
171e948693eSPhilip Paeps 	/* Linked list of TX queues with completions to process */
172e948693eSPhilip Paeps 	struct sfxge_txq	*txq;
173e948693eSPhilip Paeps 	struct sfxge_txq	**txqs;
17476c85536SAndrew Rybchenko 
17576c85536SAndrew Rybchenko 	/* Structure members not used on event processing path */
17676c85536SAndrew Rybchenko 	unsigned int		buf_base_id;
17776c85536SAndrew Rybchenko 	unsigned int		entries;
17833d45dc5SAndrew Rybchenko 	char			lock_name[SFXGE_LOCK_NAME_MAX];
179f38d0724SAndrew Rybchenko #if EFSYS_OPT_QSTATS
180f38d0724SAndrew Rybchenko 	clock_t			stats_update_time;
181f38d0724SAndrew Rybchenko 	uint64_t		stats[EV_NQSTATS];
182f38d0724SAndrew Rybchenko #endif
18376c85536SAndrew Rybchenko } __aligned(CACHE_LINE_SIZE);
184e948693eSPhilip Paeps 
185e948693eSPhilip Paeps #define	SFXGE_NDESCS	1024
186e948693eSPhilip Paeps #define	SFXGE_MODERATION	30
187e948693eSPhilip Paeps 
188e948693eSPhilip Paeps enum sfxge_intr_state {
189e948693eSPhilip Paeps 	SFXGE_INTR_UNINITIALIZED = 0,
190e948693eSPhilip Paeps 	SFXGE_INTR_INITIALIZED,
191e948693eSPhilip Paeps 	SFXGE_INTR_TESTING,
192e948693eSPhilip Paeps 	SFXGE_INTR_STARTED
193e948693eSPhilip Paeps };
194e948693eSPhilip Paeps 
195e948693eSPhilip Paeps struct sfxge_intr_hdl {
196e948693eSPhilip Paeps 	int			eih_rid;
197e948693eSPhilip Paeps 	void			*eih_tag;
198e948693eSPhilip Paeps 	struct resource		*eih_res;
199e948693eSPhilip Paeps };
200e948693eSPhilip Paeps 
201e948693eSPhilip Paeps struct sfxge_intr {
202e948693eSPhilip Paeps 	enum sfxge_intr_state	state;
203e948693eSPhilip Paeps 	struct resource		*msix_res;
204e948693eSPhilip Paeps 	struct sfxge_intr_hdl	*table;
205e948693eSPhilip Paeps 	int			n_alloc;
206e948693eSPhilip Paeps 	int			type;
207e948693eSPhilip Paeps 	efsys_mem_t		status;
208e948693eSPhilip Paeps 	uint32_t		zero_count;
209e948693eSPhilip Paeps };
210e948693eSPhilip Paeps 
211e948693eSPhilip Paeps enum sfxge_mcdi_state {
212e948693eSPhilip Paeps 	SFXGE_MCDI_UNINITIALIZED = 0,
213e948693eSPhilip Paeps 	SFXGE_MCDI_INITIALIZED,
214e948693eSPhilip Paeps 	SFXGE_MCDI_BUSY,
215e948693eSPhilip Paeps 	SFXGE_MCDI_COMPLETED
216e948693eSPhilip Paeps };
217e948693eSPhilip Paeps 
218e948693eSPhilip Paeps struct sfxge_mcdi {
219e948693eSPhilip Paeps 	struct mtx		lock;
2203c838a9fSAndrew Rybchenko 	efsys_mem_t		mem;
221e948693eSPhilip Paeps 	enum sfxge_mcdi_state	state;
222e948693eSPhilip Paeps 	efx_mcdi_transport_t	transport;
22333d45dc5SAndrew Rybchenko 
22433d45dc5SAndrew Rybchenko 	/* Only used in debugging output */
22533d45dc5SAndrew Rybchenko 	char			lock_name[SFXGE_LOCK_NAME_MAX];
226e948693eSPhilip Paeps };
227e948693eSPhilip Paeps 
228e948693eSPhilip Paeps struct sfxge_hw_stats {
229e948693eSPhilip Paeps 	clock_t			update_time;
230e948693eSPhilip Paeps 	efsys_mem_t		dma_buf;
231e948693eSPhilip Paeps 	void			*decode_buf;
232e948693eSPhilip Paeps };
233e948693eSPhilip Paeps 
234e948693eSPhilip Paeps enum sfxge_port_state {
235e948693eSPhilip Paeps 	SFXGE_PORT_UNINITIALIZED = 0,
236e948693eSPhilip Paeps 	SFXGE_PORT_INITIALIZED,
237e948693eSPhilip Paeps 	SFXGE_PORT_STARTED
238e948693eSPhilip Paeps };
239e948693eSPhilip Paeps 
240e948693eSPhilip Paeps struct sfxge_port {
241e948693eSPhilip Paeps 	struct sfxge_softc	*sc;
242e948693eSPhilip Paeps 	struct mtx		lock;
243e948693eSPhilip Paeps 	enum sfxge_port_state	init_state;
244e948693eSPhilip Paeps #ifndef SFXGE_HAVE_PAUSE_MEDIAOPTS
245e948693eSPhilip Paeps 	unsigned int		wanted_fc;
246e948693eSPhilip Paeps #endif
247e948693eSPhilip Paeps 	struct sfxge_hw_stats	phy_stats;
248e948693eSPhilip Paeps 	struct sfxge_hw_stats	mac_stats;
24958223d5bSAndrew Rybchenko 	uint16_t		stats_update_period_ms;
250e948693eSPhilip Paeps 	efx_link_mode_t		link_mode;
2513c838a9fSAndrew Rybchenko 	uint8_t			mcast_addrs[EFX_MAC_MULTICAST_LIST_MAX *
2523c838a9fSAndrew Rybchenko 					    EFX_MAC_ADDR_LEN];
2533c838a9fSAndrew Rybchenko 	unsigned int		mcast_count;
25433d45dc5SAndrew Rybchenko 
25533d45dc5SAndrew Rybchenko 	/* Only used in debugging output */
25633d45dc5SAndrew Rybchenko 	char			lock_name[SFXGE_LOCK_NAME_MAX];
257e948693eSPhilip Paeps };
258e948693eSPhilip Paeps 
259e948693eSPhilip Paeps enum sfxge_softc_state {
260e948693eSPhilip Paeps 	SFXGE_UNINITIALIZED = 0,
261e948693eSPhilip Paeps 	SFXGE_INITIALIZED,
262e948693eSPhilip Paeps 	SFXGE_REGISTERED,
263e948693eSPhilip Paeps 	SFXGE_STARTED
264e948693eSPhilip Paeps };
265e948693eSPhilip Paeps 
266e948693eSPhilip Paeps struct sfxge_softc {
267e948693eSPhilip Paeps 	device_t			dev;
268e948693eSPhilip Paeps 	struct sx			softc_lock;
26933d45dc5SAndrew Rybchenko 	char				softc_lock_name[SFXGE_LOCK_NAME_MAX];
270e948693eSPhilip Paeps 	enum sfxge_softc_state		init_state;
27104abf87bSJustin Hibbits 	if_t				ifnet;
272e948693eSPhilip Paeps 	unsigned int			if_flags;
273e948693eSPhilip Paeps 	struct sysctl_oid		*stats_node;
274f38d0724SAndrew Rybchenko #if EFSYS_OPT_QSTATS
275f38d0724SAndrew Rybchenko 	struct sysctl_oid		*evqs_stats_node;
276f38d0724SAndrew Rybchenko #endif
277bc85c897SGeorge V. Neville-Neil 	struct sysctl_oid		*txqs_node;
278e948693eSPhilip Paeps 
279e948693eSPhilip Paeps 	struct task			task_reset;
280e948693eSPhilip Paeps 
281e948693eSPhilip Paeps 	efx_family_t			family;
28236641d2bSAndrew Rybchenko 	unsigned int			mem_bar;
28336641d2bSAndrew Rybchenko 
284e948693eSPhilip Paeps 	caddr_t				vpd_data;
285e948693eSPhilip Paeps 	size_t				vpd_size;
286e948693eSPhilip Paeps 	efx_nic_t			*enp;
28733d45dc5SAndrew Rybchenko 	efsys_lock_t			enp_lock;
288e948693eSPhilip Paeps 
2898b447157SAndrew Rybchenko 	boolean_t			txq_dynamic_cksum_toggle_supported;
2908b447157SAndrew Rybchenko 
291385b1d8eSGeorge V. Neville-Neil 	unsigned int			rxq_entries;
292385b1d8eSGeorge V. Neville-Neil 	unsigned int			txq_entries;
293385b1d8eSGeorge V. Neville-Neil 
294e948693eSPhilip Paeps 	bus_dma_tag_t			parent_dma_tag;
295e948693eSPhilip Paeps 	efsys_bar_t			bar;
296e948693eSPhilip Paeps 
297e948693eSPhilip Paeps 	struct sfxge_intr		intr;
298e948693eSPhilip Paeps 	struct sfxge_mcdi		mcdi;
299e948693eSPhilip Paeps 	struct sfxge_port		port;
300e948693eSPhilip Paeps 	uint32_t			buffer_table_next;
301e948693eSPhilip Paeps 
302e948693eSPhilip Paeps 	struct sfxge_evq		*evq[SFXGE_RX_SCALE_MAX];
303e948693eSPhilip Paeps 	unsigned int			ev_moderation;
304fe900081SAndrew Rybchenko #if EFSYS_OPT_QSTATS
305e948693eSPhilip Paeps 	clock_t				ev_stats_update_time;
306e948693eSPhilip Paeps 	uint64_t			ev_stats[EV_NQSTATS];
307fe900081SAndrew Rybchenko #endif
308e948693eSPhilip Paeps 
309d9e49c83SAndrew Rybchenko 	unsigned int			max_rss_channels;
310e948693eSPhilip Paeps 	struct sfxge_rxq		*rxq[SFXGE_RX_SCALE_MAX];
31144fcad03SAndrew Rybchenko 	unsigned int			rx_indir_table[EFX_RSS_TBL_SIZE];
312e948693eSPhilip Paeps 
313e948693eSPhilip Paeps 	struct sfxge_txq		*txq[SFXGE_TXQ_NTYPES + SFXGE_RX_SCALE_MAX];
314e948693eSPhilip Paeps 
315e948693eSPhilip Paeps 	struct ifmedia			media;
316e948693eSPhilip Paeps 
317e948693eSPhilip Paeps 	size_t				rx_prefix_size;
318e948693eSPhilip Paeps 	size_t				rx_buffer_size;
3193c838a9fSAndrew Rybchenko 	size_t				rx_buffer_align;
320009d75e7SGleb Smirnoff 	int				rx_cluster_size;
321e948693eSPhilip Paeps 
3223c838a9fSAndrew Rybchenko 	unsigned int			evq_max;
323097de6f5SAndrew Rybchenko 	unsigned int			evq_count;
324133366a6SAndrew Rybchenko 	unsigned int			rxq_count;
325e2b05fe2SAndrew Rybchenko 	unsigned int			txq_count;
3263c838a9fSAndrew Rybchenko 
327a45a0da1SAndrew Rybchenko 	unsigned int			tso_fw_assisted;
328a45a0da1SAndrew Rybchenko #define	SFXGE_FATSOV1	(1 << 0)
329a45a0da1SAndrew Rybchenko #define	SFXGE_FATSOV2	(1 << 1)
330a45a0da1SAndrew Rybchenko 
3319c2c444bSAndrew Rybchenko #if EFSYS_OPT_MCDI_LOGGING
3329c2c444bSAndrew Rybchenko 	int				mcdi_logging;
3339c2c444bSAndrew Rybchenko #endif
334e948693eSPhilip Paeps };
335e948693eSPhilip Paeps 
3361eec1475SAndrew Rybchenko #define	SFXGE_LINK_UP(sc) \
3371eec1475SAndrew Rybchenko 	((sc)->port.link_mode != EFX_LINK_DOWN && \
3381eec1475SAndrew Rybchenko 	 (sc)->port.link_mode != EFX_LINK_UNKNOWN)
33904abf87bSJustin Hibbits #define	SFXGE_RUNNING(sc) (if_getdrvflags((sc)->ifnet) & IFF_DRV_RUNNING)
340e948693eSPhilip Paeps 
341385b1d8eSGeorge V. Neville-Neil #define	SFXGE_PARAM(_name)	"hw.sfxge." #_name
342385b1d8eSGeorge V. Neville-Neil 
343385b1d8eSGeorge V. Neville-Neil SYSCTL_DECL(_hw_sfxge);
344385b1d8eSGeorge V. Neville-Neil 
345e948693eSPhilip Paeps /*
346e948693eSPhilip Paeps  * From sfxge.c.
347e948693eSPhilip Paeps  */
348e948693eSPhilip Paeps extern void sfxge_schedule_reset(struct sfxge_softc *sc);
349e948693eSPhilip Paeps extern void sfxge_sram_buf_tbl_alloc(struct sfxge_softc *sc, size_t n,
350e948693eSPhilip Paeps 				     uint32_t *idp);
351e948693eSPhilip Paeps 
352e948693eSPhilip Paeps /*
353e948693eSPhilip Paeps  * From sfxge_dma.c.
354e948693eSPhilip Paeps  */
355e948693eSPhilip Paeps extern int sfxge_dma_init(struct sfxge_softc *sc);
356e948693eSPhilip Paeps extern void sfxge_dma_fini(struct sfxge_softc *sc);
357e948693eSPhilip Paeps extern int sfxge_dma_alloc(struct sfxge_softc *sc, bus_size_t len,
358e948693eSPhilip Paeps 			   efsys_mem_t *esmp);
359e948693eSPhilip Paeps extern void sfxge_dma_free(efsys_mem_t *esmp);
360e948693eSPhilip Paeps extern int sfxge_dma_map_sg_collapse(bus_dma_tag_t tag, bus_dmamap_t map,
3613c838a9fSAndrew Rybchenko 				     struct mbuf **mp,
3623c838a9fSAndrew Rybchenko 				     bus_dma_segment_t *segs,
3633c838a9fSAndrew Rybchenko 				     int *nsegs, int maxsegs);
364e948693eSPhilip Paeps 
365e948693eSPhilip Paeps /*
366e948693eSPhilip Paeps  * From sfxge_ev.c.
367e948693eSPhilip Paeps  */
368e948693eSPhilip Paeps extern int sfxge_ev_init(struct sfxge_softc *sc);
369e948693eSPhilip Paeps extern void sfxge_ev_fini(struct sfxge_softc *sc);
370e948693eSPhilip Paeps extern int sfxge_ev_start(struct sfxge_softc *sc);
371e948693eSPhilip Paeps extern void sfxge_ev_stop(struct sfxge_softc *sc);
372b64af6b0SAndrew Rybchenko extern int sfxge_ev_qpoll(struct sfxge_evq *evq);
373e948693eSPhilip Paeps 
374e948693eSPhilip Paeps /*
375e948693eSPhilip Paeps  * From sfxge_intr.c.
376e948693eSPhilip Paeps  */
377e948693eSPhilip Paeps extern int sfxge_intr_init(struct sfxge_softc *sc);
378e948693eSPhilip Paeps extern void sfxge_intr_fini(struct sfxge_softc *sc);
379e948693eSPhilip Paeps extern int sfxge_intr_start(struct sfxge_softc *sc);
380e948693eSPhilip Paeps extern void sfxge_intr_stop(struct sfxge_softc *sc);
381e948693eSPhilip Paeps 
382e948693eSPhilip Paeps /*
383e948693eSPhilip Paeps  * From sfxge_mcdi.c.
384e948693eSPhilip Paeps  */
385e948693eSPhilip Paeps extern int sfxge_mcdi_init(struct sfxge_softc *sc);
386e948693eSPhilip Paeps extern void sfxge_mcdi_fini(struct sfxge_softc *sc);
3873c838a9fSAndrew Rybchenko extern int sfxge_mcdi_ioctl(struct sfxge_softc *sc, sfxge_ioc_t *ip);
3883c838a9fSAndrew Rybchenko 
3893c838a9fSAndrew Rybchenko /*
3903c838a9fSAndrew Rybchenko  * From sfxge_nvram.c.
3913c838a9fSAndrew Rybchenko  */
3923c838a9fSAndrew Rybchenko extern int sfxge_nvram_ioctl(struct sfxge_softc *sc, sfxge_ioc_t *ip);
393e948693eSPhilip Paeps 
394e948693eSPhilip Paeps /*
395e948693eSPhilip Paeps  * From sfxge_port.c.
396e948693eSPhilip Paeps  */
397e948693eSPhilip Paeps extern int sfxge_port_init(struct sfxge_softc *sc);
398e948693eSPhilip Paeps extern void sfxge_port_fini(struct sfxge_softc *sc);
399e948693eSPhilip Paeps extern int sfxge_port_start(struct sfxge_softc *sc);
400e948693eSPhilip Paeps extern void sfxge_port_stop(struct sfxge_softc *sc);
401e948693eSPhilip Paeps extern void sfxge_mac_link_update(struct sfxge_softc *sc,
402e948693eSPhilip Paeps 				  efx_link_mode_t mode);
403e948693eSPhilip Paeps extern int sfxge_mac_filter_set(struct sfxge_softc *sc);
404e948693eSPhilip Paeps extern int sfxge_port_ifmedia_init(struct sfxge_softc *sc);
40504abf87bSJustin Hibbits extern uint64_t sfxge_get_counter(if_t ifp, ift_counter c);
406e948693eSPhilip Paeps 
407e948693eSPhilip Paeps #define	SFXGE_MAX_MTU (9 * 1024)
408e948693eSPhilip Paeps 
40933d45dc5SAndrew Rybchenko #define	SFXGE_ADAPTER_LOCK_INIT(_sc, _ifname)				\
41033d45dc5SAndrew Rybchenko 	do {								\
41133d45dc5SAndrew Rybchenko 		struct sfxge_softc *__sc = (_sc);			\
41233d45dc5SAndrew Rybchenko 									\
41333d45dc5SAndrew Rybchenko 		snprintf((__sc)->softc_lock_name,			\
41433d45dc5SAndrew Rybchenko 			 sizeof((__sc)->softc_lock_name),		\
41533d45dc5SAndrew Rybchenko 			 "%s:softc", (_ifname));			\
41633d45dc5SAndrew Rybchenko 		sx_init(&(__sc)->softc_lock, (__sc)->softc_lock_name);	\
41733d45dc5SAndrew Rybchenko 	} while (B_FALSE)
418763cab71SAndrew Rybchenko #define	SFXGE_ADAPTER_LOCK_DESTROY(_sc)					\
419763cab71SAndrew Rybchenko 	sx_destroy(&(_sc)->softc_lock)
420763cab71SAndrew Rybchenko #define	SFXGE_ADAPTER_LOCK(_sc)						\
421763cab71SAndrew Rybchenko 	sx_xlock(&(_sc)->softc_lock)
422763cab71SAndrew Rybchenko #define	SFXGE_ADAPTER_UNLOCK(_sc)					\
423763cab71SAndrew Rybchenko 	sx_xunlock(&(_sc)->softc_lock)
424763cab71SAndrew Rybchenko #define	SFXGE_ADAPTER_LOCK_ASSERT_OWNED(_sc)				\
425763cab71SAndrew Rybchenko 	sx_assert(&(_sc)->softc_lock, LA_XLOCKED)
426763cab71SAndrew Rybchenko 
42733d45dc5SAndrew Rybchenko #define	SFXGE_PORT_LOCK_INIT(_port, _ifname)				\
42833d45dc5SAndrew Rybchenko 	do {								\
42933d45dc5SAndrew Rybchenko 		struct sfxge_port *__port = (_port);			\
43033d45dc5SAndrew Rybchenko 									\
43133d45dc5SAndrew Rybchenko 		snprintf((__port)->lock_name,				\
43233d45dc5SAndrew Rybchenko 			 sizeof((__port)->lock_name),			\
43333d45dc5SAndrew Rybchenko 			 "%s:port", (_ifname));				\
43433d45dc5SAndrew Rybchenko 		mtx_init(&(__port)->lock, (__port)->lock_name,		\
43533d45dc5SAndrew Rybchenko 			 NULL, MTX_DEF);				\
43633d45dc5SAndrew Rybchenko 	} while (B_FALSE)
437763cab71SAndrew Rybchenko #define	SFXGE_PORT_LOCK_DESTROY(_port)					\
438763cab71SAndrew Rybchenko 	mtx_destroy(&(_port)->lock)
439763cab71SAndrew Rybchenko #define	SFXGE_PORT_LOCK(_port)						\
440763cab71SAndrew Rybchenko 	mtx_lock(&(_port)->lock)
441763cab71SAndrew Rybchenko #define	SFXGE_PORT_UNLOCK(_port)					\
442763cab71SAndrew Rybchenko 	mtx_unlock(&(_port)->lock)
443763cab71SAndrew Rybchenko #define	SFXGE_PORT_LOCK_ASSERT_OWNED(_port)				\
444763cab71SAndrew Rybchenko 	mtx_assert(&(_port)->lock, MA_OWNED)
445763cab71SAndrew Rybchenko 
44633d45dc5SAndrew Rybchenko #define	SFXGE_MCDI_LOCK_INIT(_mcdi, _ifname)				\
44733d45dc5SAndrew Rybchenko 	do {								\
44833d45dc5SAndrew Rybchenko 		struct sfxge_mcdi  *__mcdi = (_mcdi);			\
44933d45dc5SAndrew Rybchenko 									\
45033d45dc5SAndrew Rybchenko 		snprintf((__mcdi)->lock_name,				\
45133d45dc5SAndrew Rybchenko 			 sizeof((__mcdi)->lock_name),			\
45233d45dc5SAndrew Rybchenko 			 "%s:mcdi", (_ifname));				\
45333d45dc5SAndrew Rybchenko 		mtx_init(&(__mcdi)->lock, (__mcdi)->lock_name,		\
45433d45dc5SAndrew Rybchenko 			 NULL, MTX_DEF);				\
45533d45dc5SAndrew Rybchenko 	} while (B_FALSE)
456763cab71SAndrew Rybchenko #define	SFXGE_MCDI_LOCK_DESTROY(_mcdi)					\
457763cab71SAndrew Rybchenko 	mtx_destroy(&(_mcdi)->lock)
458763cab71SAndrew Rybchenko #define	SFXGE_MCDI_LOCK(_mcdi)						\
459763cab71SAndrew Rybchenko 	mtx_lock(&(_mcdi)->lock)
460763cab71SAndrew Rybchenko #define	SFXGE_MCDI_UNLOCK(_mcdi)					\
461763cab71SAndrew Rybchenko 	mtx_unlock(&(_mcdi)->lock)
462763cab71SAndrew Rybchenko #define	SFXGE_MCDI_LOCK_ASSERT_OWNED(_mcdi)				\
463763cab71SAndrew Rybchenko 	mtx_assert(&(_mcdi)->lock, MA_OWNED)
464763cab71SAndrew Rybchenko 
46533d45dc5SAndrew Rybchenko #define	SFXGE_EVQ_LOCK_INIT(_evq, _ifname, _evq_index)			\
46633d45dc5SAndrew Rybchenko 	do {								\
46733d45dc5SAndrew Rybchenko 		struct sfxge_evq  *__evq = (_evq);			\
46833d45dc5SAndrew Rybchenko 									\
46933d45dc5SAndrew Rybchenko 		snprintf((__evq)->lock_name,				\
47033d45dc5SAndrew Rybchenko 			 sizeof((__evq)->lock_name),			\
47133d45dc5SAndrew Rybchenko 			 "%s:evq%u", (_ifname), (_evq_index));		\
47233d45dc5SAndrew Rybchenko 		mtx_init(&(__evq)->lock, (__evq)->lock_name,		\
47333d45dc5SAndrew Rybchenko 			 NULL, MTX_DEF);				\
47433d45dc5SAndrew Rybchenko 	} while (B_FALSE)
475763cab71SAndrew Rybchenko #define	SFXGE_EVQ_LOCK_DESTROY(_evq)					\
476763cab71SAndrew Rybchenko 	mtx_destroy(&(_evq)->lock)
477763cab71SAndrew Rybchenko #define	SFXGE_EVQ_LOCK(_evq)						\
478763cab71SAndrew Rybchenko 	mtx_lock(&(_evq)->lock)
479763cab71SAndrew Rybchenko #define	SFXGE_EVQ_UNLOCK(_evq)						\
480763cab71SAndrew Rybchenko 	mtx_unlock(&(_evq)->lock)
481763cab71SAndrew Rybchenko #define	SFXGE_EVQ_LOCK_ASSERT_OWNED(_evq)				\
482763cab71SAndrew Rybchenko 	mtx_assert(&(_evq)->lock, MA_OWNED)
483763cab71SAndrew Rybchenko 
484e948693eSPhilip Paeps #endif /* _SFXGE_H */
485