]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/dev/sfxge/sfxge_rx.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / dev / sfxge / sfxge_rx.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_RX_H
33 #define _SFXGE_RX_H
34
35 #define SFXGE_MAGIC_RESERVED    0x8000
36
37 #define SFXGE_MAGIC_DMAQ_LABEL_WIDTH  6
38 #define SFXGE_MAGIC_DMAQ_LABEL_MASK   \
39         ((1 << SFXGE_MAGIC_DMAQ_LABEL_WIDTH) - 1)
40
41 #define SFXGE_MAGIC_RX_QFLUSH_DONE                                      \
42         (SFXGE_MAGIC_RESERVED | (1 << SFXGE_MAGIC_DMAQ_LABEL_WIDTH))
43
44 #define SFXGE_MAGIC_RX_QFLUSH_FAILED                                    \
45         (SFXGE_MAGIC_RESERVED | (2 << SFXGE_MAGIC_DMAQ_LABEL_WIDTH))
46
47 #define SFXGE_MAGIC_RX_QREFILL                                          \
48         (SFXGE_MAGIC_RESERVED | (3 << SFXGE_MAGIC_DMAQ_LABEL_WIDTH))
49
50 #define SFXGE_MAGIC_TX_QFLUSH_DONE                                      \
51         (SFXGE_MAGIC_RESERVED | (4 << SFXGE_MAGIC_DMAQ_LABEL_WIDTH))
52
53 #define SFXGE_RX_SCALE_MAX      EFX_MAXRSS
54
55 struct sfxge_rx_sw_desc {
56         struct mbuf     *mbuf;
57         bus_dmamap_t    map;
58         int             flags;
59         int             size;
60 };
61
62 /**
63  * struct sfxge_lro_conn - Connection state for software LRO
64  * @link: Link for hash table and free list.
65  * @active_link: Link for active_conns list
66  * @l2_id: Identifying information from layer 2
67  * @conn_hash: Hash of connection 4-tuple
68  * @nh: IP (v4 or v6) header of super-packet
69  * @source: Source TCP port number
70  * @dest: Destination TCP port number
71  * @n_in_order_pkts: Number of in-order packets with payload.
72  * @next_seq: Next in-order sequence number.
73  * @last_pkt_ticks: Time we last saw a packet on this connection.
74  * @mbuf: The mbuf we are currently holding.
75  *      If %NULL, then all following fields are undefined.
76  * @mbuf_tail: The tail of the frag_list of mbufs we're holding.
77  *      Only valid after at least one merge.
78  * @th_last: The TCP header of the last packet merged.
79  * @next_buf: The next RX buffer to process.
80  * @next_eh: Ethernet header of the next buffer.
81  * @next_nh: IP header of the next buffer.
82  * @delivered: True if we've delivered a payload packet up this interrupt.
83  */
84 struct sfxge_lro_conn {
85         TAILQ_ENTRY(sfxge_lro_conn) link;
86         LIST_ENTRY(sfxge_lro_conn) active_link;
87         uint16_t l2_id;
88         uint32_t conn_hash;
89         void *nh;
90         uint16_t source, dest;
91         int n_in_order_pkts;
92         unsigned next_seq;
93         unsigned last_pkt_ticks;
94         struct mbuf *mbuf;
95         struct mbuf *mbuf_tail;
96         struct tcphdr *th_last;
97         struct sfxge_rx_sw_desc next_buf;
98         void *next_eh;
99         void *next_nh;
100         int delivered;
101 };
102
103 /**
104  * struct sfxge_lro_state - Port state for software LRO
105  * @sc: The associated NIC.
106  * @conns_mask: Number of hash buckets - 1.
107  * @conns: Hash buckets for tracked connections.
108  * @conns_n: Length of linked list for each hash bucket.
109  * @active_conns: Connections that are holding a packet.
110  *      Connections are self-linked when not in this list.
111  * @free_conns: Free sfxge_lro_conn instances.
112  * @last_purge_ticks: The value of ticks last time we purged idle
113  *      connections.
114  * @n_merges: Number of packets absorbed by LRO.
115  * @n_bursts: Number of bursts spotted by LRO.
116  * @n_slow_start: Number of packets not merged because connection may be in
117  *      slow-start.
118  * @n_misorder: Number of out-of-order packets seen in tracked streams.
119  * @n_too_many: Incremented when we're trying to track too many streams.
120  * @n_new_stream: Number of distinct streams we've tracked.
121  * @n_drop_idle: Number of streams discarded because they went idle.
122  * @n_drop_closed: Number of streams that have seen a FIN or RST.
123  */
124 struct sfxge_lro_state {
125         struct sfxge_softc *sc;
126         unsigned conns_mask;
127         TAILQ_HEAD(sfxge_lro_tailq, sfxge_lro_conn) *conns;
128         unsigned *conns_n;
129         LIST_HEAD(, sfxge_lro_conn) active_conns;
130         TAILQ_HEAD(, sfxge_lro_conn) free_conns;
131         unsigned last_purge_ticks;
132         unsigned n_merges;
133         unsigned n_bursts;
134         unsigned n_slow_start;
135         unsigned n_misorder;
136         unsigned n_too_many;
137         unsigned n_new_stream;
138         unsigned n_drop_idle;
139         unsigned n_drop_closed;
140 };
141
142 enum sfxge_flush_state {
143         SFXGE_FLUSH_DONE = 0,
144         SFXGE_FLUSH_PENDING,
145         SFXGE_FLUSH_FAILED
146 };
147
148 enum sfxge_rxq_state {
149         SFXGE_RXQ_UNINITIALIZED = 0,
150         SFXGE_RXQ_INITIALIZED,
151         SFXGE_RXQ_STARTED
152 };
153
154 #define SFXGE_RX_BATCH  128
155
156 struct sfxge_rxq {
157         struct sfxge_softc              *sc __aligned(CACHE_LINE_SIZE);
158         unsigned int                    index;
159         efsys_mem_t                     mem;
160         unsigned int                    buf_base_id;
161         enum sfxge_rxq_state            init_state;
162
163         struct sfxge_rx_sw_desc         *queue __aligned(CACHE_LINE_SIZE);
164         unsigned int                    added;
165         unsigned int                    pending;
166         unsigned int                    completed;
167         unsigned int                    loopback;
168         struct sfxge_lro_state          lro;
169         struct callout                  refill_callout;
170         unsigned int                    refill_delay;
171
172         efx_rxq_t                       *common __aligned(CACHE_LINE_SIZE);
173         volatile enum sfxge_flush_state flush_state;
174 };
175
176 /*
177  * From sfxge_rx.c.
178  */
179 extern int sfxge_rx_init(struct sfxge_softc *sc);
180 extern void sfxge_rx_fini(struct sfxge_softc *sc);
181 extern int sfxge_rx_start(struct sfxge_softc *sc);
182 extern void sfxge_rx_stop(struct sfxge_softc *sc);
183 extern void sfxge_rx_qcomplete(struct sfxge_rxq *rxq, boolean_t eop);
184 extern void sfxge_rx_qrefill(struct sfxge_rxq *rxq);
185 extern void sfxge_rx_qflush_done(struct sfxge_rxq *rxq);
186 extern void sfxge_rx_qflush_failed(struct sfxge_rxq *rxq);
187 extern void sfxge_rx_scale_update(void *arg, int npending);
188
189 #endif