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