2 * Copyright (c) 2010-2011 Solarflare Communications, Inc.
5 * This software was developed in part by Philip Paeps under contract for
6 * Solarflare Communications, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/condvar.h>
38 #include <sys/socket.h>
39 #include <sys/sysctl.h>
43 #include <net/ethernet.h>
45 #include <net/if_var.h>
46 #include <net/if_media.h>
47 #include <net/if_types.h>
50 * Backward-compatibility
52 #ifndef CACHE_LINE_SIZE
53 /* This should be right on most machines the driver will be used on, and
54 * we needn't care too much about wasting a few KB per interface.
56 #define CACHE_LINE_SIZE 128
58 #ifndef IFCAP_LINKSTATE
59 #define IFCAP_LINKSTATE 0
61 #ifndef IFCAP_VLAN_HWTSO
62 #define IFCAP_VLAN_HWTSO 0
65 #define IFM_10G_T IFM_UNKNOWN
68 #define IFM_10G_KX4 IFM_10G_CX4
70 #if __FreeBSD_version >= 800054
71 /* Networking core is multiqueue aware. We can manage our own TX
72 * queues and use m_pkthdr.flowid.
76 #if (__FreeBSD_version >= 800501 && __FreeBSD_version < 900000) || \
77 __FreeBSD_version >= 900003
78 #define SFXGE_HAVE_DESCRIBE_INTR
80 #ifdef IFM_ETH_RXPAUSE
81 #define SFXGE_HAVE_PAUSE_MEDIAOPTS
84 #define CTLTYPE_U64 CTLTYPE_QUAD
90 #define ROUNDUP_POW_OF_TWO(_n) (1ULL << flsl((_n) - 1))
92 #define SFXGE_IP_ALIGN 2
94 #define SFXGE_ETHERTYPE_LOOPBACK 0x9000 /* Xerox loopback */
96 enum sfxge_evq_state {
97 SFXGE_EVQ_UNINITIALIZED = 0,
98 SFXGE_EVQ_INITIALIZED,
103 #define SFXGE_EV_BATCH 16384
106 struct sfxge_softc *sc __aligned(CACHE_LINE_SIZE);
107 struct mtx lock __aligned(CACHE_LINE_SIZE);
109 enum sfxge_evq_state init_state;
111 unsigned int entries;
113 unsigned int buf_base_id;
118 unsigned int read_ptr;
119 unsigned int rx_done;
120 unsigned int tx_done;
122 /* Linked list of TX queues with completions to process */
123 struct sfxge_txq *txq;
124 struct sfxge_txq **txqs;
127 #define SFXGE_NDESCS 1024
128 #define SFXGE_MODERATION 30
130 enum sfxge_intr_state {
131 SFXGE_INTR_UNINITIALIZED = 0,
132 SFXGE_INTR_INITIALIZED,
137 struct sfxge_intr_hdl {
140 struct resource *eih_res;
144 enum sfxge_intr_state state;
145 struct resource *msix_res;
146 struct sfxge_intr_hdl *table;
153 enum sfxge_mcdi_state {
154 SFXGE_MCDI_UNINITIALIZED = 0,
155 SFXGE_MCDI_INITIALIZED,
163 enum sfxge_mcdi_state state;
164 efx_mcdi_transport_t transport;
167 struct sfxge_hw_stats {
173 enum sfxge_port_state {
174 SFXGE_PORT_UNINITIALIZED = 0,
175 SFXGE_PORT_INITIALIZED,
180 struct sfxge_softc *sc;
182 enum sfxge_port_state init_state;
183 #ifndef SFXGE_HAVE_PAUSE_MEDIAOPTS
184 unsigned int wanted_fc;
186 struct sfxge_hw_stats phy_stats;
187 struct sfxge_hw_stats mac_stats;
188 efx_link_mode_t link_mode;
191 enum sfxge_softc_state {
192 SFXGE_UNINITIALIZED = 0,
200 struct sx softc_lock;
201 enum sfxge_softc_state init_state;
203 unsigned int if_flags;
204 struct sysctl_oid *stats_node;
205 struct sysctl_oid *txqs_node;
207 struct task task_reset;
215 unsigned int rxq_entries;
216 unsigned int txq_entries;
218 bus_dma_tag_t parent_dma_tag;
221 struct sfxge_intr intr;
222 struct sfxge_mcdi mcdi;
223 struct sfxge_port port;
224 uint32_t buffer_table_next;
226 struct sfxge_evq *evq[SFXGE_RX_SCALE_MAX];
227 unsigned int ev_moderation;
228 clock_t ev_stats_update_time;
229 uint64_t ev_stats[EV_NQSTATS];
231 uma_zone_t rxq_cache;
232 struct sfxge_rxq *rxq[SFXGE_RX_SCALE_MAX];
233 unsigned int rx_indir_table[SFXGE_RX_SCALE_MAX];
236 struct sfxge_txq *txq[SFXGE_TXQ_NTYPES + SFXGE_RX_SCALE_MAX];
238 struct sfxge_txq *txq[SFXGE_TXQ_NTYPES];
241 struct ifmedia media;
243 size_t rx_prefix_size;
244 size_t rx_buffer_size;
245 uma_zone_t rx_buffer_zone;
247 #ifndef SFXGE_HAVE_MQ
248 struct mtx tx_lock __aligned(CACHE_LINE_SIZE);
252 #define SFXGE_LINK_UP(sc) ((sc)->port.link_mode != EFX_LINK_DOWN)
253 #define SFXGE_RUNNING(sc) ((sc)->ifnet->if_drv_flags & IFF_DRV_RUNNING)
255 #define SFXGE_PARAM(_name) "hw.sfxge." #_name
257 SYSCTL_DECL(_hw_sfxge);
262 extern void sfxge_schedule_reset(struct sfxge_softc *sc);
263 extern void sfxge_sram_buf_tbl_alloc(struct sfxge_softc *sc, size_t n,
269 extern int sfxge_dma_init(struct sfxge_softc *sc);
270 extern void sfxge_dma_fini(struct sfxge_softc *sc);
271 extern int sfxge_dma_alloc(struct sfxge_softc *sc, bus_size_t len,
273 extern void sfxge_dma_free(efsys_mem_t *esmp);
274 extern int sfxge_dma_map_sg_collapse(bus_dma_tag_t tag, bus_dmamap_t map,
275 struct mbuf **mp, bus_dma_segment_t *segs, int *nsegs, int maxsegs);
280 extern int sfxge_ev_init(struct sfxge_softc *sc);
281 extern void sfxge_ev_fini(struct sfxge_softc *sc);
282 extern int sfxge_ev_start(struct sfxge_softc *sc);
283 extern void sfxge_ev_stop(struct sfxge_softc *sc);
284 extern int sfxge_ev_qpoll(struct sfxge_softc *sc, unsigned int index);
289 extern int sfxge_intr_init(struct sfxge_softc *sc);
290 extern void sfxge_intr_fini(struct sfxge_softc *sc);
291 extern int sfxge_intr_start(struct sfxge_softc *sc);
292 extern void sfxge_intr_stop(struct sfxge_softc *sc);
297 extern int sfxge_mcdi_init(struct sfxge_softc *sc);
298 extern void sfxge_mcdi_fini(struct sfxge_softc *sc);
303 extern int sfxge_port_init(struct sfxge_softc *sc);
304 extern void sfxge_port_fini(struct sfxge_softc *sc);
305 extern int sfxge_port_start(struct sfxge_softc *sc);
306 extern void sfxge_port_stop(struct sfxge_softc *sc);
307 extern void sfxge_mac_link_update(struct sfxge_softc *sc,
308 efx_link_mode_t mode);
309 extern int sfxge_mac_filter_set(struct sfxge_softc *sc);
310 extern int sfxge_port_ifmedia_init(struct sfxge_softc *sc);
312 #define SFXGE_MAX_MTU (9 * 1024)
314 #endif /* _SFXGE_H */