]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/sfxge/sfxge.h
sfxge: remove obsolete Tx non-multi queue support
[FreeBSD/FreeBSD.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_var.h>
46 #include <net/if_media.h>
47 #include <net/if_types.h>
48
49 /*
50  * Backward-compatibility
51  */
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.
55  */
56 #define CACHE_LINE_SIZE 128
57 #endif
58 #ifndef IFCAP_LINKSTATE
59 #define IFCAP_LINKSTATE 0
60 #endif
61 #ifndef IFCAP_VLAN_HWTSO
62 #define IFCAP_VLAN_HWTSO 0
63 #endif
64 #ifndef IFM_10G_T
65 #define IFM_10G_T IFM_UNKNOWN
66 #endif
67 #ifndef IFM_10G_KX4
68 #define IFM_10G_KX4 IFM_10G_CX4
69 #endif
70 #if (__FreeBSD_version >= 800501 && __FreeBSD_version < 900000) || \
71         __FreeBSD_version >= 900003
72 #define SFXGE_HAVE_DESCRIBE_INTR
73 #endif
74 #ifdef IFM_ETH_RXPAUSE
75 #define SFXGE_HAVE_PAUSE_MEDIAOPTS
76 #endif
77 #ifndef CTLTYPE_U64
78 #define CTLTYPE_U64 CTLTYPE_QUAD
79 #endif
80
81 #include "sfxge_rx.h"
82 #include "sfxge_tx.h"
83
84 #define ROUNDUP_POW_OF_TWO(_n)  (1ULL << flsl((_n) - 1))
85
86 #define SFXGE_IP_ALIGN  2
87
88 #define SFXGE_ETHERTYPE_LOOPBACK        0x9000  /* Xerox loopback */
89
90 enum sfxge_evq_state {
91         SFXGE_EVQ_UNINITIALIZED = 0,
92         SFXGE_EVQ_INITIALIZED,
93         SFXGE_EVQ_STARTING,
94         SFXGE_EVQ_STARTED
95 };
96
97 #define SFXGE_EV_BATCH  16384
98
99 struct sfxge_evq {
100         /* Structure members below are sorted by usage order */
101         struct sfxge_softc      *sc;
102         struct mtx              lock;
103         unsigned int            index;
104         enum sfxge_evq_state    init_state;
105         efsys_mem_t             mem;
106         efx_evq_t               *common;
107         unsigned int            read_ptr;
108         boolean_t               exception;
109         unsigned int            rx_done;
110         unsigned int            tx_done;
111
112         /* Linked list of TX queues with completions to process */
113         struct sfxge_txq        *txq;
114         struct sfxge_txq        **txqs;
115
116         /* Structure members not used on event processing path */
117         unsigned int            buf_base_id;
118         unsigned int            entries;
119         char                    lock_name[SFXGE_LOCK_NAME_MAX];
120 } __aligned(CACHE_LINE_SIZE);
121
122 #define SFXGE_NDESCS    1024
123 #define SFXGE_MODERATION        30
124
125 enum sfxge_intr_state {
126         SFXGE_INTR_UNINITIALIZED = 0,
127         SFXGE_INTR_INITIALIZED,
128         SFXGE_INTR_TESTING,
129         SFXGE_INTR_STARTED
130 };
131
132 struct sfxge_intr_hdl {
133         int                     eih_rid;
134         void                    *eih_tag;
135         struct resource         *eih_res;
136 };
137
138 struct sfxge_intr {
139         enum sfxge_intr_state   state;
140         struct resource         *msix_res;
141         struct sfxge_intr_hdl   *table;
142         int                     n_alloc;
143         int                     type;
144         efsys_mem_t             status;
145         uint32_t                zero_count;
146 };
147
148 enum sfxge_mcdi_state {
149         SFXGE_MCDI_UNINITIALIZED = 0,
150         SFXGE_MCDI_INITIALIZED,
151         SFXGE_MCDI_BUSY,
152         SFXGE_MCDI_COMPLETED
153 };
154
155 struct sfxge_mcdi {
156         struct mtx              lock;
157         struct cv               cv;
158         enum sfxge_mcdi_state   state;
159         efx_mcdi_transport_t    transport;
160
161         /* Only used in debugging output */
162         char                    lock_name[SFXGE_LOCK_NAME_MAX];
163 };
164
165 struct sfxge_hw_stats {
166         clock_t                 update_time;
167         efsys_mem_t             dma_buf;
168         void                    *decode_buf;
169 };
170
171 enum sfxge_port_state {
172         SFXGE_PORT_UNINITIALIZED = 0,
173         SFXGE_PORT_INITIALIZED,
174         SFXGE_PORT_STARTED
175 };
176
177 struct sfxge_port {
178         struct sfxge_softc      *sc;
179         struct mtx              lock;
180         enum sfxge_port_state   init_state;
181 #ifndef SFXGE_HAVE_PAUSE_MEDIAOPTS
182         unsigned int            wanted_fc;
183 #endif
184         struct sfxge_hw_stats   phy_stats;
185         struct sfxge_hw_stats   mac_stats;
186         efx_link_mode_t         link_mode;
187
188         /* Only used in debugging output */
189         char                    lock_name[SFXGE_LOCK_NAME_MAX];
190 };
191
192 enum sfxge_softc_state {
193         SFXGE_UNINITIALIZED = 0,
194         SFXGE_INITIALIZED,
195         SFXGE_REGISTERED,
196         SFXGE_STARTED
197 };
198
199 struct sfxge_softc {
200         device_t                        dev;
201         struct sx                       softc_lock;
202         char                            softc_lock_name[SFXGE_LOCK_NAME_MAX];
203         enum sfxge_softc_state          init_state;
204         struct ifnet                    *ifnet;
205         unsigned int                    if_flags;
206         struct sysctl_oid               *stats_node;
207         struct sysctl_oid               *txqs_node;
208
209         struct task                     task_reset;
210
211         efx_family_t                    family;
212         caddr_t                         vpd_data;
213         size_t                          vpd_size;
214         efx_nic_t                       *enp;
215         efsys_lock_t                    enp_lock;
216
217         unsigned int                    rxq_entries;
218         unsigned int                    txq_entries;
219
220         bus_dma_tag_t                   parent_dma_tag;
221         efsys_bar_t                     bar;
222
223         struct sfxge_intr               intr;
224         struct sfxge_mcdi               mcdi;
225         struct sfxge_port               port;
226         uint32_t                        buffer_table_next;
227
228         struct sfxge_evq                *evq[SFXGE_RX_SCALE_MAX];
229         unsigned int                    ev_moderation;
230 #if EFSYS_OPT_QSTATS
231         clock_t                         ev_stats_update_time;
232         uint64_t                        ev_stats[EV_NQSTATS];
233 #endif
234
235         unsigned int                    max_rss_channels;
236         uma_zone_t                      rxq_cache;
237         struct sfxge_rxq                *rxq[SFXGE_RX_SCALE_MAX];
238         unsigned int                    rx_indir_table[SFXGE_RX_SCALE_MAX];
239
240         struct sfxge_txq                *txq[SFXGE_TXQ_NTYPES + SFXGE_RX_SCALE_MAX];
241
242         struct ifmedia                  media;
243
244         size_t                          rx_prefix_size;
245         size_t                          rx_buffer_size;
246         uma_zone_t                      rx_buffer_zone;
247
248         unsigned int                    evq_count;
249         unsigned int                    rxq_count;
250         unsigned int                    txq_count;
251 };
252
253 #define SFXGE_LINK_UP(sc) ((sc)->port.link_mode != EFX_LINK_DOWN)
254 #define SFXGE_RUNNING(sc) ((sc)->ifnet->if_drv_flags & IFF_DRV_RUNNING)
255
256 #define SFXGE_PARAM(_name)      "hw.sfxge." #_name
257
258 SYSCTL_DECL(_hw_sfxge);
259
260 /*
261  * From sfxge.c.
262  */
263 extern void sfxge_schedule_reset(struct sfxge_softc *sc);
264 extern void sfxge_sram_buf_tbl_alloc(struct sfxge_softc *sc, size_t n,
265                                      uint32_t *idp);
266
267 /*
268  * From sfxge_dma.c.
269  */
270 extern int sfxge_dma_init(struct sfxge_softc *sc);
271 extern void sfxge_dma_fini(struct sfxge_softc *sc);
272 extern int sfxge_dma_alloc(struct sfxge_softc *sc, bus_size_t len,
273     efsys_mem_t *esmp);
274 extern void sfxge_dma_free(efsys_mem_t *esmp);
275 extern int sfxge_dma_map_sg_collapse(bus_dma_tag_t tag, bus_dmamap_t map,
276     struct mbuf **mp, bus_dma_segment_t *segs, int *nsegs, int maxsegs);
277
278 /*
279  * From sfxge_ev.c.
280  */
281 extern int sfxge_ev_init(struct sfxge_softc *sc);
282 extern void sfxge_ev_fini(struct sfxge_softc *sc);
283 extern int sfxge_ev_start(struct sfxge_softc *sc);
284 extern void sfxge_ev_stop(struct sfxge_softc *sc);
285 extern int sfxge_ev_qpoll(struct sfxge_evq *evq);
286
287 /*
288  * From sfxge_intr.c.
289  */
290 extern int sfxge_intr_init(struct sfxge_softc *sc);
291 extern void sfxge_intr_fini(struct sfxge_softc *sc);
292 extern int sfxge_intr_start(struct sfxge_softc *sc);
293 extern void sfxge_intr_stop(struct sfxge_softc *sc);
294
295 /*
296  * From sfxge_mcdi.c.
297  */
298 extern int sfxge_mcdi_init(struct sfxge_softc *sc);
299 extern void sfxge_mcdi_fini(struct sfxge_softc *sc);
300
301 /*
302  * From sfxge_port.c.
303  */
304 extern int sfxge_port_init(struct sfxge_softc *sc);
305 extern void sfxge_port_fini(struct sfxge_softc *sc);
306 extern int sfxge_port_start(struct sfxge_softc *sc);
307 extern void sfxge_port_stop(struct sfxge_softc *sc);
308 extern void sfxge_mac_link_update(struct sfxge_softc *sc,
309     efx_link_mode_t mode);
310 extern int sfxge_mac_filter_set(struct sfxge_softc *sc);
311 extern int sfxge_port_ifmedia_init(struct sfxge_softc *sc);
312 extern uint64_t sfxge_get_counter(struct ifnet *ifp, ift_counter c);
313
314 #define SFXGE_MAX_MTU (9 * 1024)
315
316 #define SFXGE_ADAPTER_LOCK_INIT(_sc, _ifname)                           \
317         do {                                                            \
318                 struct sfxge_softc *__sc = (_sc);                       \
319                                                                         \
320                 snprintf((__sc)->softc_lock_name,                       \
321                          sizeof((__sc)->softc_lock_name),               \
322                          "%s:softc", (_ifname));                        \
323                 sx_init(&(__sc)->softc_lock, (__sc)->softc_lock_name);  \
324         } while (B_FALSE)
325 #define SFXGE_ADAPTER_LOCK_DESTROY(_sc)                                 \
326         sx_destroy(&(_sc)->softc_lock)
327 #define SFXGE_ADAPTER_LOCK(_sc)                                         \
328         sx_xlock(&(_sc)->softc_lock)
329 #define SFXGE_ADAPTER_UNLOCK(_sc)                                       \
330         sx_xunlock(&(_sc)->softc_lock)
331 #define SFXGE_ADAPTER_LOCK_ASSERT_OWNED(_sc)                            \
332         sx_assert(&(_sc)->softc_lock, LA_XLOCKED)
333
334 #define SFXGE_PORT_LOCK_INIT(_port, _ifname)                            \
335         do {                                                            \
336                 struct sfxge_port *__port = (_port);                    \
337                                                                         \
338                 snprintf((__port)->lock_name,                           \
339                          sizeof((__port)->lock_name),                   \
340                          "%s:port", (_ifname));                         \
341                 mtx_init(&(__port)->lock, (__port)->lock_name,          \
342                          NULL, MTX_DEF);                                \
343         } while (B_FALSE)
344 #define SFXGE_PORT_LOCK_DESTROY(_port)                                  \
345         mtx_destroy(&(_port)->lock)
346 #define SFXGE_PORT_LOCK(_port)                                          \
347         mtx_lock(&(_port)->lock)
348 #define SFXGE_PORT_UNLOCK(_port)                                        \
349         mtx_unlock(&(_port)->lock)
350 #define SFXGE_PORT_LOCK_ASSERT_OWNED(_port)                             \
351         mtx_assert(&(_port)->lock, MA_OWNED)
352
353 #define SFXGE_MCDI_LOCK_INIT(_mcdi, _ifname)                            \
354         do {                                                            \
355                 struct sfxge_mcdi  *__mcdi = (_mcdi);                   \
356                                                                         \
357                 snprintf((__mcdi)->lock_name,                           \
358                          sizeof((__mcdi)->lock_name),                   \
359                          "%s:mcdi", (_ifname));                         \
360                 mtx_init(&(__mcdi)->lock, (__mcdi)->lock_name,          \
361                          NULL, MTX_DEF);                                \
362         } while (B_FALSE)
363 #define SFXGE_MCDI_LOCK_DESTROY(_mcdi)                                  \
364         mtx_destroy(&(_mcdi)->lock)
365 #define SFXGE_MCDI_LOCK(_mcdi)                                          \
366         mtx_lock(&(_mcdi)->lock)
367 #define SFXGE_MCDI_UNLOCK(_mcdi)                                        \
368         mtx_unlock(&(_mcdi)->lock)
369 #define SFXGE_MCDI_LOCK_ASSERT_OWNED(_mcdi)                             \
370         mtx_assert(&(_mcdi)->lock, MA_OWNED)
371
372 #define SFXGE_EVQ_LOCK_INIT(_evq, _ifname, _evq_index)                  \
373         do {                                                            \
374                 struct sfxge_evq  *__evq = (_evq);                      \
375                                                                         \
376                 snprintf((__evq)->lock_name,                            \
377                          sizeof((__evq)->lock_name),                    \
378                          "%s:evq%u", (_ifname), (_evq_index));          \
379                 mtx_init(&(__evq)->lock, (__evq)->lock_name,            \
380                          NULL, MTX_DEF);                                \
381         } while (B_FALSE)
382 #define SFXGE_EVQ_LOCK_DESTROY(_evq)                                    \
383         mtx_destroy(&(_evq)->lock)
384 #define SFXGE_EVQ_LOCK(_evq)                                            \
385         mtx_lock(&(_evq)->lock)
386 #define SFXGE_EVQ_UNLOCK(_evq)                                          \
387         mtx_unlock(&(_evq)->lock)
388 #define SFXGE_EVQ_LOCK_ASSERT_OWNED(_evq)                               \
389         mtx_assert(&(_evq)->lock, MA_OWNED)
390
391 #endif /* _SFXGE_H */