2 * Copyright (c) 2010-2011 Solarflare Communications, Inc.
5 * This software was developed in part by Philip Paeps under contract for
6 * Solarflare Communications, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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
35 #define SFXGE_MAGIC_RESERVED 0x8000
37 #define SFXGE_MAGIC_DMAQ_LABEL_WIDTH 6
38 #define SFXGE_MAGIC_DMAQ_LABEL_MASK \
39 ((1 << SFXGE_MAGIC_DMAQ_LABEL_WIDTH) - 1)
41 #define SFXGE_MAGIC_RX_QFLUSH_DONE \
42 (SFXGE_MAGIC_RESERVED | (1 << SFXGE_MAGIC_DMAQ_LABEL_WIDTH))
44 #define SFXGE_MAGIC_RX_QFLUSH_FAILED \
45 (SFXGE_MAGIC_RESERVED | (2 << SFXGE_MAGIC_DMAQ_LABEL_WIDTH))
47 #define SFXGE_MAGIC_RX_QREFILL \
48 (SFXGE_MAGIC_RESERVED | (3 << SFXGE_MAGIC_DMAQ_LABEL_WIDTH))
50 #define SFXGE_MAGIC_TX_QFLUSH_DONE \
51 (SFXGE_MAGIC_RESERVED | (4 << SFXGE_MAGIC_DMAQ_LABEL_WIDTH))
53 #define SFXGE_RX_SCALE_MAX EFX_MAXRSS
55 struct sfxge_rx_sw_desc {
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.
84 struct sfxge_lro_conn {
85 TAILQ_ENTRY(sfxge_lro_conn) link;
86 LIST_ENTRY(sfxge_lro_conn) active_link;
90 uint16_t source, dest;
93 unsigned last_pkt_ticks;
95 struct mbuf *mbuf_tail;
96 struct tcphdr *th_last;
97 struct sfxge_rx_sw_desc next_buf;
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
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
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.
124 struct sfxge_lro_state {
125 struct sfxge_softc *sc;
127 TAILQ_HEAD(sfxge_lro_tailq, sfxge_lro_conn) *conns;
129 LIST_HEAD(, sfxge_lro_conn) active_conns;
130 TAILQ_HEAD(, sfxge_lro_conn) free_conns;
131 unsigned last_purge_ticks;
134 unsigned n_slow_start;
137 unsigned n_new_stream;
138 unsigned n_drop_idle;
139 unsigned n_drop_closed;
142 enum sfxge_flush_state {
143 SFXGE_FLUSH_DONE = 0,
148 enum sfxge_rxq_state {
149 SFXGE_RXQ_UNINITIALIZED = 0,
150 SFXGE_RXQ_INITIALIZED,
154 #define SFXGE_RX_BATCH 128
157 struct sfxge_softc *sc __aligned(CACHE_LINE_SIZE);
160 unsigned int buf_base_id;
161 enum sfxge_rxq_state init_state;
163 struct sfxge_rx_sw_desc *queue __aligned(CACHE_LINE_SIZE);
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;
172 efx_rxq_t *common __aligned(CACHE_LINE_SIZE);
173 volatile enum sfxge_flush_state flush_state;
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);