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