xref: /freebsd/sys/dev/sfxge/sfxge_rx.h (revision 3fc36ee018bb836bd1796067cf4ef8683f166ebc)
1 /*-
2  * Copyright (c) 2010-2016 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 are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  *    this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  *    this list of conditions and the following disclaimer in the documentation
15  *    and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * The views and conclusions contained in the software and documentation are
30  * those of the authors and should not be interpreted as representing official
31  * policies, either expressed or implied, of the FreeBSD Project.
32  *
33  * $FreeBSD$
34  */
35 
36 #ifndef _SFXGE_RX_H
37 #define	_SFXGE_RX_H
38 
39 #include "opt_inet.h"
40 #include "opt_inet6.h"
41 
42 #if defined(INET) || defined(INET6)
43 #define	SFXGE_LRO	1
44 #endif
45 
46 #define	SFXGE_RX_SCALE_MAX	EFX_MAXRSS
47 
48 struct sfxge_rx_sw_desc {
49 	struct mbuf	*mbuf;
50 	bus_dmamap_t	map;
51 	int		flags;
52 	int		size;
53 };
54 
55 #ifdef SFXGE_LRO
56 
57 /**
58  * struct sfxge_lro_conn - Connection state for software LRO
59  * @link: Link for hash table and free list.
60  * @active_link: Link for active_conns list
61  * @l2_id: Identifying information from layer 2
62  * @conn_hash: Hash of connection 4-tuple
63  * @nh: IP (v4 or v6) header of super-packet
64  * @source: Source TCP port number
65  * @dest: Destination TCP port number
66  * @n_in_order_pkts: Number of in-order packets with payload.
67  * @next_seq: Next in-order sequence number.
68  * @last_pkt_ticks: Time we last saw a packet on this connection.
69  * @mbuf: The mbuf we are currently holding.
70  *	If %NULL, then all following fields are undefined.
71  * @mbuf_tail: The tail of the frag_list of mbufs we're holding.
72  *	Only valid after at least one merge.
73  * @th_last: The TCP header of the last packet merged.
74  * @next_buf: The next RX buffer to process.
75  * @next_eh: Ethernet header of the next buffer.
76  * @next_nh: IP header of the next buffer.
77  * @delivered: True if we've delivered a payload packet up this interrupt.
78  */
79 struct sfxge_lro_conn {
80 	TAILQ_ENTRY(sfxge_lro_conn) link;
81 	LIST_ENTRY(sfxge_lro_conn) active_link;
82 	uint16_t l2_id;
83 	uint32_t conn_hash;
84 	void *nh;
85 	uint16_t source, dest;
86 	int n_in_order_pkts;
87 	unsigned next_seq;
88 	unsigned last_pkt_ticks;
89 	struct mbuf *mbuf;
90 	struct mbuf *mbuf_tail;
91 	struct tcphdr *th_last;
92 	struct sfxge_rx_sw_desc next_buf;
93 	void *next_eh;
94 	void *next_nh;
95 	int delivered;
96 };
97 
98 /**
99  * struct sfxge_lro_state - Port state for software LRO
100  * @sc: The associated NIC.
101  * @conns_mask: Number of hash buckets - 1.
102  * @conns: Hash buckets for tracked connections.
103  * @conns_n: Length of linked list for each hash bucket.
104  * @active_conns: Connections that are holding a packet.
105  *	Connections are self-linked when not in this list.
106  * @free_conns: Free sfxge_lro_conn instances.
107  * @last_purge_ticks: The value of ticks last time we purged idle
108  *	connections.
109  * @n_merges: Number of packets absorbed by LRO.
110  * @n_bursts: Number of bursts spotted by LRO.
111  * @n_slow_start: Number of packets not merged because connection may be in
112  *	slow-start.
113  * @n_misorder: Number of out-of-order packets seen in tracked streams.
114  * @n_too_many: Incremented when we're trying to track too many streams.
115  * @n_new_stream: Number of distinct streams we've tracked.
116  * @n_drop_idle: Number of streams discarded because they went idle.
117  * @n_drop_closed: Number of streams that have seen a FIN or RST.
118  */
119 struct sfxge_lro_state {
120 	struct sfxge_softc *sc;
121 	unsigned conns_mask;
122 	TAILQ_HEAD(sfxge_lro_tailq, sfxge_lro_conn) *conns;
123 	unsigned *conns_n;
124 	LIST_HEAD(, sfxge_lro_conn) active_conns;
125 	TAILQ_HEAD(, sfxge_lro_conn) free_conns;
126 	unsigned last_purge_ticks;
127 	unsigned n_merges;
128 	unsigned n_bursts;
129 	unsigned n_slow_start;
130 	unsigned n_misorder;
131 	unsigned n_too_many;
132 	unsigned n_new_stream;
133 	unsigned n_drop_idle;
134 	unsigned n_drop_closed;
135 };
136 
137 #endif	/* SFXGE_LRO */
138 
139 enum sfxge_flush_state {
140 	SFXGE_FLUSH_DONE = 0,
141 	SFXGE_FLUSH_REQUIRED,
142 	SFXGE_FLUSH_PENDING,
143 	SFXGE_FLUSH_FAILED
144 };
145 
146 enum sfxge_rxq_state {
147 	SFXGE_RXQ_UNINITIALIZED = 0,
148 	SFXGE_RXQ_INITIALIZED,
149 	SFXGE_RXQ_STARTED
150 };
151 
152 #define	SFXGE_RX_BATCH	128
153 
154 struct sfxge_rxq {
155 	struct sfxge_softc		*sc __aligned(CACHE_LINE_SIZE);
156 	unsigned int			index;
157 	efsys_mem_t			mem;
158 	unsigned int			buf_base_id;
159 	enum sfxge_rxq_state		init_state;
160 	unsigned int			entries;
161 	unsigned int			ptr_mask;
162 
163 	struct sfxge_rx_sw_desc		*queue __aligned(CACHE_LINE_SIZE);
164 	unsigned int			added;
165 	unsigned int			pushed;
166 	unsigned int			pending;
167 	unsigned int			completed;
168 	unsigned int			loopback;
169 #ifdef SFXGE_LRO
170 	struct sfxge_lro_state		lro;
171 #endif
172 	unsigned int			refill_threshold;
173 	struct callout			refill_callout;
174 	unsigned int			refill_delay;
175 
176 	efx_rxq_t			*common __aligned(CACHE_LINE_SIZE);
177 	volatile enum sfxge_flush_state	flush_state;
178 };
179 
180 /*
181  * From sfxge_rx.c.
182  */
183 extern int sfxge_rx_init(struct sfxge_softc *sc);
184 extern void sfxge_rx_fini(struct sfxge_softc *sc);
185 extern int sfxge_rx_start(struct sfxge_softc *sc);
186 extern void sfxge_rx_stop(struct sfxge_softc *sc);
187 extern void sfxge_rx_qcomplete(struct sfxge_rxq *rxq, boolean_t eop);
188 extern void sfxge_rx_qrefill(struct sfxge_rxq *rxq);
189 extern void sfxge_rx_qflush_done(struct sfxge_rxq *rxq);
190 extern void sfxge_rx_qflush_failed(struct sfxge_rxq *rxq);
191 extern void sfxge_rx_scale_update(void *arg, int npending);
192 
193 #endif
194