summaryrefslogtreecommitdiffstats
path: root/sys/dev/rt/if_rtvar.h
blob: bd21158d9dc1beab03d09246015da2202dc37b89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*-
 * Copyright (c) 2010-2011 Aleksandr Rybalko <ray@ddteam.net>
 * Copyright (c) 2009-2010 Alexander Egorenkov <egorenar@gmail.com>
 * Copyright (c) 2009 Damien Bergamini <damien.bergamini@free.fr>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef _IF_RTVAR_H_
#define	_IF_RTVAR_H_

#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/sockio.h>
#include <sys/mbuf.h>
#include <sys/kernel.h>
#include <sys/socket.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/taskqueue.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/endian.h>

#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/rman.h>

#include <net/bpf.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <net/ethernet.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/if_types.h>

#include "opt_if_rt.h"

#define	RT_SOFTC_LOCK(sc)		mtx_lock(&(sc)->lock)
#define	RT_SOFTC_UNLOCK(sc)		mtx_unlock(&(sc)->lock)
#define	RT_SOFTC_ASSERT_LOCKED(sc)	mtx_assert(&(sc)->lock, MA_OWNED)

#define	RT_SOFTC_TX_RING_LOCK(ring)		mtx_lock(&(ring)->lock)
#define	RT_SOFTC_TX_RING_UNLOCK(ring)		mtx_unlock(&(ring)->lock)
#define	RT_SOFTC_TX_RING_ASSERT_LOCKED(ring)	\
		    mtx_assert(&(ring)->lock, MA_OWNED)

#define	RT_SOFTC_TX_RING_COUNT		4

#ifndef IF_RT_RING_DATA_COUNT
#define	IF_RT_RING_DATA_COUNT	128
#endif

#define	RT_SOFTC_RX_RING_DATA_COUNT	IF_RT_RING_DATA_COUNT

#define	RT_SOFTC_MAX_SCATTER		10

#define	RT_SOFTC_TX_RING_DATA_COUNT	(IF_RT_RING_DATA_COUNT/4)
#define	RT_SOFTC_TX_RING_DESC_COUNT				\
	(RT_SOFTC_TX_RING_DATA_COUNT * RT_SOFTC_MAX_SCATTER)

#define	RT_TXDESC_SDL1_BURST		(1 << 15)
#define	RT_TXDESC_SDL1_LASTSEG		(1 << 14)
#define	RT_TXDESC_SDL0_DDONE		(1 << 15)
#define	RT_TXDESC_SDL0_LASTSEG		(1 << 14)
struct rt_txdesc
{
	uint32_t sdp0;
	uint16_t sdl1;
	uint16_t sdl0;
	uint32_t sdp1;
	uint8_t vid;
#define	TXDSCR_INS_VLAN_TAG	0x80
#define	TXDSCR_VLAN_PRIO_MASK	0x70
#define	TXDSCR_VLAN_IDX_MASK	0x0f
	uint8_t	pppoe;
#define	TXDSCR_USR_DEF_FLD	0x80
#define	TXDSCR_INS_PPPOE_HDR	0x10
#define	TXDSCR_PPPOE_SID_MASK	0x0f
	uint8_t qn;
#define	TXDSCR_QUEUE_MASK	0x07
	uint8_t	dst;
#define	TXDSCR_IP_CSUM_GEN	0x80
#define	TXDSCR_UDP_CSUM_GEN	0x40
#define	TXDSCR_TCP_CSUM_GEN	0x20
#define	TXDSCR_DST_PORT_MASK	0x07
#define	TXDSCR_DST_PORT_CPU	0x00
#define	TXDSCR_DST_PORT_GDMA1	0x01
#define	TXDSCR_DST_PORT_GDMA2	0x02
#define	TXDSCR_DST_PORT_PPE	0x06
#define	TXDSCR_DST_PORT_DISC	0x07
} __packed;

#define	RT_RXDESC_SDL0_DDONE		(1 << 15)
struct rt_rxdesc
{
	uint32_t sdp0;
	uint16_t sdl1;
	uint16_t sdl0;
	uint32_t sdp1;
	uint16_t foe;
#define	RXDSXR_FOE_ENTRY_VALID		0x40
#define	RXDSXR_FOE_ENTRY_MASK		0x3f
	uint8_t ai;
#define	RXDSXR_AI_COU_REASON		0xff
#define	RXDSXR_AI_PARSER_RSLT_MASK	0xff
	uint8_t src;
#define	RXDSXR_SRC_IPFVLD		0x80
#define	RXDSXR_SRC_L4FVLD		0x40
#define	RXDSXR_SRC_IP_CSUM_FAIL	0x20
#define	RXDSXR_SRC_L4_CSUM_FAIL	0x10
#define	RXDSXR_SRC_AIS			0x08
#define	RXDSXR_SRC_PORT_MASK		0x07
} __packed;

struct rt_softc_rx_data
{
	bus_dmamap_t dma_map;
	struct mbuf *m;
};

struct rt_softc_rx_ring
{
	bus_dma_tag_t desc_dma_tag;
	bus_dmamap_t desc_dma_map;
	bus_addr_t desc_phys_addr;
	struct rt_rxdesc *desc;
	bus_dma_tag_t data_dma_tag;
	bus_dmamap_t spare_dma_map;
	struct rt_softc_rx_data data[RT_SOFTC_RX_RING_DATA_COUNT];
	int cur;
};

struct rt_softc_tx_data
{
	bus_dmamap_t dma_map;
	struct mbuf *m;
};

struct rt_softc_tx_ring
{
	struct mtx lock;
	bus_dma_tag_t desc_dma_tag;
	bus_dmamap_t desc_dma_map;
	bus_addr_t desc_phys_addr;
	struct rt_txdesc *desc;
	int desc_queued;
	int desc_cur;
	int desc_next;
	bus_dma_tag_t seg0_dma_tag;
	bus_dmamap_t seg0_dma_map;
	bus_addr_t seg0_phys_addr;
	uint8_t *seg0;
	bus_dma_tag_t data_dma_tag;
	struct rt_softc_tx_data data[RT_SOFTC_TX_RING_DATA_COUNT];
	int data_queued;
	int data_cur;
	int data_next;
	int qid;
};

struct rt_softc
{
	device_t 	 dev;
	struct mtx 	 lock;
	uint32_t 	 flags;

	int		 mem_rid;
	struct resource	*mem;
	int		 irq_rid;
	struct resource *irq;
	void		*irqh;

	bus_space_tag_t	 bst;
	bus_space_handle_t bsh;

	struct ifnet	*ifp;
	int 		 if_flags;
	struct ifmedia	 rt_ifmedia;

	uint32_t	 mac_rev;
	uint8_t		 mac_addr[ETHER_ADDR_LEN];
	device_t	 rt_miibus;

	uint32_t	 intr_enable_mask;
	uint32_t	 intr_disable_mask;
	uint32_t	 intr_pending_mask;

	struct task	 rx_done_task;
	int		 rx_process_limit;
	struct task	 tx_done_task;
	struct task	 periodic_task;
	struct callout	 periodic_ch;
	unsigned long	 periodic_round;
	struct taskqueue *taskqueue;

	struct rt_softc_rx_ring rx_ring;
	struct rt_softc_tx_ring tx_ring[RT_SOFTC_TX_RING_COUNT];
	int		 tx_ring_mgtqid;

	struct callout	 tx_watchdog_ch;
	int		 tx_timer;

	/* statistic counters */
	unsigned long	 interrupts;
	unsigned long	 tx_coherent_interrupts;
	unsigned long	 rx_coherent_interrupts;
	unsigned long	 rx_interrupts;
	unsigned long	 rx_delay_interrupts;
	unsigned long	 tx_interrupts[RT_SOFTC_TX_RING_COUNT];
	unsigned long	 tx_delay_interrupts;
	unsigned long	 tx_data_queue_full[RT_SOFTC_TX_RING_COUNT];
	unsigned long	 tx_watchdog_timeouts;
	unsigned long	 tx_defrag_packets;
	unsigned long	 no_tx_desc_avail;
	unsigned long	 rx_mbuf_alloc_errors;
	unsigned long	 rx_mbuf_dmamap_errors;
	unsigned long	 tx_queue_not_empty[2];

	unsigned long	 rx_bytes;
	unsigned long	 rx_packets;
	unsigned long	 rx_crc_err;
	unsigned long	 rx_phy_err;
	unsigned long	 rx_dup_packets;
	unsigned long	 rx_fifo_overflows;
	unsigned long	 rx_short_err;
	unsigned long	 rx_long_err;
	unsigned long	 tx_bytes;
	unsigned long	 tx_packets;
	unsigned long	 tx_skip;
	unsigned long	 tx_collision;

	int		 phy_addr;

#ifdef IF_RT_DEBUG
	int		 debug;
#endif
};

#ifdef IF_RT_DEBUG
enum
{
	RT_DEBUG_RX = 0x00000001,
	RT_DEBUG_TX = 0x00000002,
	RT_DEBUG_INTR = 0x00000004,
	RT_DEBUG_STATE = 0x00000008,
	RT_DEBUG_STATS = 0x00000010,
	RT_DEBUG_PERIODIC = 0x00000020,
	RT_DEBUG_WATCHDOG = 0x00000040,
	RT_DEBUG_ANY = 0xffffffff
};

#define	RT_DPRINTF(sc, m, fmt, ...)		\
	do { if ((sc)->debug & (m)) 		\
	    device_printf(sc->dev, fmt, __VA_ARGS__); } while (0)
#else
#define	RT_DPRINTF(sc, m, fmt, ...)
#endif /* #ifdef IF_RT_DEBUG */

#endif /* #ifndef _IF_RTVAR_H_ */
OpenPOWER on IntegriCloud