]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/sfxge/sfxge.h
MFC: 277884
[FreeBSD/stable/10.git] / sys / dev / sfxge / sfxge.h
1 /*-
2  * Copyright (c) 2010-2011 Solarflare Communications, Inc.
3  * All rights reserved.
4  *
5  * This software was developed in part by Philip Paeps under contract for
6  * Solarflare Communications, Inc.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
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.
16  *
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
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31
32 #ifndef _SFXGE_H
33 #define _SFXGE_H
34
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>
40 #include <sys/sx.h>
41 #include <vm/uma.h>
42
43 #include <net/ethernet.h>
44 #include <net/if.h>
45 #include <net/if_media.h>
46 #include <net/if_types.h>
47
48 /*
49  * Backward-compatibility
50  */
51 #ifndef CACHE_LINE_SIZE
52 /* This should be right on most machines the driver will be used on, and
53  * we needn't care too much about wasting a few KB per interface.
54  */
55 #define CACHE_LINE_SIZE 128
56 #endif
57 #ifndef IFCAP_LINKSTATE
58 #define IFCAP_LINKSTATE 0
59 #endif
60 #ifndef IFCAP_VLAN_HWTSO
61 #define IFCAP_VLAN_HWTSO 0
62 #endif
63 #ifndef IFM_10G_T
64 #define IFM_10G_T IFM_UNKNOWN
65 #endif
66 #ifndef IFM_10G_KX4
67 #define IFM_10G_KX4 IFM_10G_CX4
68 #endif
69 #if __FreeBSD_version >= 800054
70 /* Networking core is multiqueue aware. We can manage our own TX
71  * queues and use m_pkthdr.flowid.
72  */
73 #define SFXGE_HAVE_MQ
74 #endif
75 #if (__FreeBSD_version >= 800501 && __FreeBSD_version < 900000) || \
76         __FreeBSD_version >= 900003
77 #define SFXGE_HAVE_DESCRIBE_INTR
78 #endif
79 #ifdef IFM_ETH_RXPAUSE
80 #define SFXGE_HAVE_PAUSE_MEDIAOPTS
81 #endif
82 #ifndef CTLTYPE_U64
83 #define CTLTYPE_U64 CTLTYPE_QUAD
84 #endif
85
86 #include "sfxge_rx.h"
87 #include "sfxge_tx.h"
88
89 #define ROUNDUP_POW_OF_TWO(_n)  (1ULL << flsl((_n) - 1))
90
91 #define SFXGE_IP_ALIGN  2
92
93 #define SFXGE_ETHERTYPE_LOOPBACK        0x9000  /* Xerox loopback */
94
95 enum sfxge_evq_state {
96         SFXGE_EVQ_UNINITIALIZED = 0,
97         SFXGE_EVQ_INITIALIZED,
98         SFXGE_EVQ_STARTING,
99         SFXGE_EVQ_STARTED
100 };
101
102 #define SFXGE_EV_BATCH  16384
103
104 struct sfxge_evq {
105         struct sfxge_softc      *sc  __aligned(CACHE_LINE_SIZE);
106         struct mtx              lock __aligned(CACHE_LINE_SIZE);
107
108         enum sfxge_evq_state    init_state;
109         unsigned int            index;
110         unsigned int            entries;
111         efsys_mem_t             mem;
112         unsigned int            buf_base_id;
113
114         boolean_t               exception;
115
116         efx_evq_t               *common;
117         unsigned int            read_ptr;
118         unsigned int            rx_done;
119         unsigned int            tx_done;
120
121         /* Linked list of TX queues with completions to process */
122         struct sfxge_txq        *txq;
123         struct sfxge_txq        **txqs;
124 };
125
126 #define SFXGE_NDESCS    1024
127 #define SFXGE_MODERATION        30
128
129 enum sfxge_intr_state {
130         SFXGE_INTR_UNINITIALIZED = 0,
131         SFXGE_INTR_INITIALIZED,
132         SFXGE_INTR_TESTING,
133         SFXGE_INTR_STARTED
134 };
135
136 struct sfxge_intr_hdl {
137         int                     eih_rid;
138         void                    *eih_tag;
139         struct resource         *eih_res;
140 };
141
142 struct sfxge_intr {
143         enum sfxge_intr_state   state;
144         struct resource         *msix_res;
145         struct sfxge_intr_hdl   *table;
146         int                     n_alloc;
147         int                     type;
148         efsys_mem_t             status;
149         uint32_t                zero_count;
150 };
151
152 enum sfxge_mcdi_state {
153         SFXGE_MCDI_UNINITIALIZED = 0,
154         SFXGE_MCDI_INITIALIZED,
155         SFXGE_MCDI_BUSY,
156         SFXGE_MCDI_COMPLETED
157 };
158
159 struct sfxge_mcdi {
160         struct mtx              lock;
161         struct cv               cv;
162         enum sfxge_mcdi_state   state;
163         efx_mcdi_transport_t    transport;
164 };
165
166 struct sfxge_hw_stats {
167         clock_t                 update_time;
168         efsys_mem_t             dma_buf;
169         void                    *decode_buf;
170 };
171
172 enum sfxge_port_state {
173         SFXGE_PORT_UNINITIALIZED = 0,
174         SFXGE_PORT_INITIALIZED,
175         SFXGE_PORT_STARTED
176 };
177
178 struct sfxge_port {
179         struct sfxge_softc      *sc;
180         struct mtx              lock;
181         enum sfxge_port_state   init_state;
182 #ifndef SFXGE_HAVE_PAUSE_MEDIAOPTS
183         unsigned int            wanted_fc;
184 #endif
185         struct sfxge_hw_stats   phy_stats;
186         struct sfxge_hw_stats   mac_stats;
187         efx_link_mode_t         link_mode;
188 };
189
190 enum sfxge_softc_state {
191         SFXGE_UNINITIALIZED = 0,
192         SFXGE_INITIALIZED,
193         SFXGE_REGISTERED,
194         SFXGE_STARTED
195 };
196
197 struct sfxge_softc {
198         device_t                        dev;
199         struct sx                       softc_lock;
200         enum sfxge_softc_state          init_state;
201         struct ifnet                    *ifnet;
202         unsigned int                    if_flags;
203         struct sysctl_oid               *stats_node;
204         struct sysctl_oid               *txqs_node;
205
206         struct task                     task_reset;
207
208         efx_family_t                    family;
209         caddr_t                         vpd_data;
210         size_t                          vpd_size;
211         efx_nic_t                       *enp;
212         struct mtx                      enp_lock;
213
214         unsigned int                    rxq_entries;
215         unsigned int                    txq_entries;
216
217         bus_dma_tag_t                   parent_dma_tag;
218         efsys_bar_t                     bar;
219
220         struct sfxge_intr               intr;
221         struct sfxge_mcdi               mcdi;
222         struct sfxge_port               port;
223         uint32_t                        buffer_table_next;
224
225         struct sfxge_evq                *evq[SFXGE_RX_SCALE_MAX];
226         unsigned int                    ev_moderation;
227         clock_t                         ev_stats_update_time;
228         uint64_t                        ev_stats[EV_NQSTATS];
229
230         uma_zone_t                      rxq_cache;
231         struct sfxge_rxq                *rxq[SFXGE_RX_SCALE_MAX];
232         unsigned int                    rx_indir_table[SFXGE_RX_SCALE_MAX];
233
234 #ifdef SFXGE_HAVE_MQ
235         struct sfxge_txq                *txq[SFXGE_TXQ_NTYPES + SFXGE_RX_SCALE_MAX];
236 #else
237         struct sfxge_txq                *txq[SFXGE_TXQ_NTYPES];
238 #endif
239
240         struct ifmedia                  media;
241
242         size_t                          rx_prefix_size;
243         size_t                          rx_buffer_size;
244         uma_zone_t                      rx_buffer_zone;
245
246 #ifndef SFXGE_HAVE_MQ
247         struct mtx                      tx_lock __aligned(CACHE_LINE_SIZE);
248 #endif
249 };
250
251 #define SFXGE_LINK_UP(sc) ((sc)->port.link_mode != EFX_LINK_DOWN)
252 #define SFXGE_RUNNING(sc) ((sc)->ifnet->if_drv_flags & IFF_DRV_RUNNING)
253
254 #define SFXGE_PARAM(_name)      "hw.sfxge." #_name
255
256 SYSCTL_DECL(_hw_sfxge);
257
258 /*
259  * From sfxge.c.
260  */
261 extern void sfxge_schedule_reset(struct sfxge_softc *sc);
262 extern void sfxge_sram_buf_tbl_alloc(struct sfxge_softc *sc, size_t n,
263                                      uint32_t *idp);
264
265 /*
266  * From sfxge_dma.c.
267  */
268 extern int sfxge_dma_init(struct sfxge_softc *sc);
269 extern void sfxge_dma_fini(struct sfxge_softc *sc);
270 extern int sfxge_dma_alloc(struct sfxge_softc *sc, bus_size_t len,
271     efsys_mem_t *esmp);
272 extern void sfxge_dma_free(efsys_mem_t *esmp);
273 extern int sfxge_dma_map_sg_collapse(bus_dma_tag_t tag, bus_dmamap_t map,
274     struct mbuf **mp, bus_dma_segment_t *segs, int *nsegs, int maxsegs);
275
276 /*
277  * From sfxge_ev.c.
278  */
279 extern int sfxge_ev_init(struct sfxge_softc *sc);
280 extern void sfxge_ev_fini(struct sfxge_softc *sc);
281 extern int sfxge_ev_start(struct sfxge_softc *sc);
282 extern void sfxge_ev_stop(struct sfxge_softc *sc);
283 extern int sfxge_ev_qpoll(struct sfxge_evq *evq);
284
285 /*
286  * From sfxge_intr.c.
287  */
288 extern int sfxge_intr_init(struct sfxge_softc *sc);
289 extern void sfxge_intr_fini(struct sfxge_softc *sc);
290 extern int sfxge_intr_start(struct sfxge_softc *sc);
291 extern void sfxge_intr_stop(struct sfxge_softc *sc);
292
293 /*
294  * From sfxge_mcdi.c.
295  */
296 extern int sfxge_mcdi_init(struct sfxge_softc *sc);
297 extern void sfxge_mcdi_fini(struct sfxge_softc *sc);
298
299 /*
300  * From sfxge_port.c.
301  */
302 extern int sfxge_port_init(struct sfxge_softc *sc);
303 extern void sfxge_port_fini(struct sfxge_softc *sc);
304 extern int sfxge_port_start(struct sfxge_softc *sc);
305 extern void sfxge_port_stop(struct sfxge_softc *sc);
306 extern void sfxge_mac_link_update(struct sfxge_softc *sc,
307     efx_link_mode_t mode);
308 extern int sfxge_mac_filter_set(struct sfxge_softc *sc);
309 extern int sfxge_port_ifmedia_init(struct sfxge_softc *sc);
310
311 #define SFXGE_MAX_MTU (9 * 1024)
312
313 #endif /* _SFXGE_H */