summaryrefslogtreecommitdiffstats
path: root/sys/dev/alc/if_alcvar.h
blob: f2d806f9bfe6d2484b7ad22cf1cfdec9306a4d3d (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
/*-
 * Copyright (c) 2009, Pyun YongHyeon <yongari@FreeBSD.org>
 * All rights reserved.
 *
 * 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_ALCVAR_H
#define	_IF_ALCVAR_H

#define	ALC_TX_RING_CNT		256
#define	ALC_TX_RING_ALIGN	sizeof(struct tx_desc)
#define	ALC_RX_RING_CNT		256
#define	ALC_RX_RING_ALIGN	sizeof(struct rx_desc)
#define	ALC_RX_BUF_ALIGN	4
#define	ALC_RR_RING_CNT		ALC_RX_RING_CNT
#define	ALC_RR_RING_ALIGN	sizeof(struct rx_rdesc)
#define	ALC_CMB_ALIGN		8
#define	ALC_SMB_ALIGN		8

#define	ALC_TSO_MAXSEGSIZE	4096
#define	ALC_TSO_MAXSIZE		(65535 + sizeof(struct ether_vlan_header))
#define	ALC_MAXTXSEGS		35

#define	ALC_ADDR_LO(x)		((uint64_t) (x) & 0xFFFFFFFF)
#define	ALC_ADDR_HI(x)		((uint64_t) (x) >> 32)

#define	ALC_DESC_INC(x, y)	((x) = ((x) + 1) % (y))

/* Water mark to kick reclaiming Tx buffers. */
#define	ALC_TX_DESC_HIWAT	((ALC_TX_RING_CNT * 6) / 10)

#define	ALC_MSI_MESSAGES	1
#define	ALC_MSIX_MESSAGES	1

#define	ALC_TX_RING_SZ		\
	(sizeof(struct tx_desc) * ALC_TX_RING_CNT)
#define	ALC_RX_RING_SZ		\
	(sizeof(struct rx_desc) * ALC_RX_RING_CNT)
#define	ALC_RR_RING_SZ		\
	(sizeof(struct rx_rdesc) * ALC_RR_RING_CNT)
#define	ALC_CMB_SZ		(sizeof(struct cmb))
#define	ALC_SMB_SZ		(sizeof(struct smb))

#define	ALC_PROC_MIN		16
#define	ALC_PROC_MAX		(ALC_RX_RING_CNT - 1)
#define	ALC_PROC_DEFAULT	(ALC_RX_RING_CNT / 4)

/*
 * The number of bits reserved for MSS in AR813x/AR815x controllers
 * are 13 bits. This limits the maximum interface MTU size in TSO
 * case(8191 + sizeof(struct ip) + sizeof(struct tcphdr)) as upper
 * stack should not generate TCP segments with MSS greater than the
 * limit. Also Atheros says that maximum MTU for TSO is 6KB.
 */
#define	ALC_TSO_MTU		(6 * 1024)

struct alc_rxdesc {
	struct mbuf		*rx_m;
	bus_dmamap_t		rx_dmamap;
	struct rx_desc		*rx_desc;
};

struct alc_txdesc {
	struct mbuf		*tx_m;
	bus_dmamap_t		tx_dmamap;
};

struct alc_ring_data {
	struct tx_desc		*alc_tx_ring;
	bus_addr_t		alc_tx_ring_paddr;
	struct rx_desc		*alc_rx_ring;
	bus_addr_t		alc_rx_ring_paddr;
	struct rx_rdesc		*alc_rr_ring;
	bus_addr_t		alc_rr_ring_paddr;
	struct cmb		*alc_cmb;
	bus_addr_t		alc_cmb_paddr;
	struct smb		*alc_smb;
	bus_addr_t		alc_smb_paddr;
};

struct alc_chain_data {
	bus_dma_tag_t		alc_parent_tag;
	bus_dma_tag_t		alc_buffer_tag;
	bus_dma_tag_t		alc_tx_tag;
	struct alc_txdesc	alc_txdesc[ALC_TX_RING_CNT];
	bus_dma_tag_t		alc_rx_tag;
	struct alc_rxdesc	alc_rxdesc[ALC_RX_RING_CNT];
	bus_dma_tag_t		alc_tx_ring_tag;
	bus_dmamap_t		alc_tx_ring_map;
	bus_dma_tag_t		alc_rx_ring_tag;
	bus_dmamap_t		alc_rx_ring_map;
	bus_dma_tag_t		alc_rr_ring_tag;
	bus_dmamap_t		alc_rr_ring_map;
	bus_dmamap_t		alc_rx_sparemap;
	bus_dma_tag_t		alc_cmb_tag;
	bus_dmamap_t		alc_cmb_map;
	bus_dma_tag_t		alc_smb_tag;
	bus_dmamap_t		alc_smb_map;

	int			alc_tx_prod;
	int			alc_tx_cons;
	int			alc_tx_cnt;
	int			alc_rx_cons;
	int			alc_rr_cons;
	int			alc_rxlen;

	struct mbuf		*alc_rxhead;
	struct mbuf		*alc_rxtail;
	struct mbuf		*alc_rxprev_tail;
};

struct alc_hw_stats {
	/* Rx stats. */
	uint32_t rx_frames;
	uint32_t rx_bcast_frames;
	uint32_t rx_mcast_frames;
	uint32_t rx_pause_frames;
	uint32_t rx_control_frames;
	uint32_t rx_crcerrs;
	uint32_t rx_lenerrs;
	uint64_t rx_bytes;
	uint32_t rx_runts;
	uint32_t rx_fragments;
	uint32_t rx_pkts_64;
	uint32_t rx_pkts_65_127;
	uint32_t rx_pkts_128_255;
	uint32_t rx_pkts_256_511;
	uint32_t rx_pkts_512_1023;
	uint32_t rx_pkts_1024_1518;
	uint32_t rx_pkts_1519_max;
	uint32_t rx_pkts_truncated;
	uint32_t rx_fifo_oflows;
	uint32_t rx_rrs_errs;
	uint32_t rx_alignerrs;
	uint64_t rx_bcast_bytes;
	uint64_t rx_mcast_bytes;
	uint32_t rx_pkts_filtered;
	/* Tx stats. */
	uint32_t tx_frames;
	uint32_t tx_bcast_frames;
	uint32_t tx_mcast_frames;
	uint32_t tx_pause_frames;
	uint32_t tx_excess_defer;
	uint32_t tx_control_frames;
	uint32_t tx_deferred;
	uint64_t tx_bytes;
	uint32_t tx_pkts_64;
	uint32_t tx_pkts_65_127;
	uint32_t tx_pkts_128_255;
	uint32_t tx_pkts_256_511;
	uint32_t tx_pkts_512_1023;
	uint32_t tx_pkts_1024_1518;
	uint32_t tx_pkts_1519_max;
	uint32_t tx_single_colls;
	uint32_t tx_multi_colls;
	uint32_t tx_late_colls;
	uint32_t tx_excess_colls;
	uint32_t tx_abort;
	uint32_t tx_underrun;
	uint32_t tx_desc_underrun;
	uint32_t tx_lenerrs;
	uint32_t tx_pkts_truncated;
	uint64_t tx_bcast_bytes;
	uint64_t tx_mcast_bytes;
};

struct alc_ident {
	uint16_t	vendorid;
	uint16_t	deviceid;
	uint32_t	max_framelen;
	const char	*name;
};

/*
 * Software state per device.
 */
struct alc_softc {
	struct ifnet 		*alc_ifp;
	device_t		alc_dev;
	device_t		alc_miibus;
	struct resource		*alc_res[1];
	struct resource_spec	*alc_res_spec;
	struct resource		*alc_irq[ALC_MSI_MESSAGES];
	struct resource_spec	*alc_irq_spec;
	void			*alc_intrhand[ALC_MSI_MESSAGES];
	struct alc_ident	*alc_ident;
	int			alc_rev;
	int			alc_chip_rev;
	int			alc_phyaddr;
	uint8_t			alc_eaddr[ETHER_ADDR_LEN];
	uint32_t		alc_dma_rd_burst;
	uint32_t		alc_dma_wr_burst;
	uint32_t		alc_rcb;
	int			alc_expcap;
	int			alc_pmcap;
	int			alc_flags;
#define	ALC_FLAG_PCIE		0x0001
#define	ALC_FLAG_PCIX		0x0002
#define	ALC_FLAG_MSI		0x0004
#define	ALC_FLAG_MSIX		0x0008
#define	ALC_FLAG_PM		0x0010
#define	ALC_FLAG_FASTETHER	0x0020
#define	ALC_FLAG_JUMBO		0x0040
#define	ALC_FLAG_ASPM_MON	0x0080
#define	ALC_FLAG_CMB_BUG	0x0100
#define	ALC_FLAG_SMB_BUG	0x0200
#define	ALC_FLAG_L0S		0x0400
#define	ALC_FLAG_L1S		0x0800
#define	ALC_FLAG_APS		0x1000
#define	ALC_FLAG_LINK		0x8000

	struct callout		alc_tick_ch;
	struct alc_hw_stats	alc_stats;
	struct alc_chain_data	alc_cdata;
	struct alc_ring_data	alc_rdata;
	int			alc_if_flags;
	int			alc_watchdog_timer;
	int			alc_process_limit;
	volatile int		alc_morework;
	int			alc_int_rx_mod;
	int			alc_int_tx_mod;
	int			alc_buf_size;

	struct task		alc_int_task;
	struct taskqueue	*alc_tq;
	struct mtx		alc_mtx;
};

/* Register access macros. */
#define	CSR_WRITE_4(_sc, reg, val)	\
	bus_write_4((_sc)->alc_res[0], (reg), (val))
#define	CSR_WRITE_2(_sc, reg, val)	\
	bus_write_2((_sc)->alc_res[0], (reg), (val))
#define	CSR_WRITE_1(_sc, reg, val)	\
	bus_write_1((_sc)->alc_res[0], (reg), (val))
#define	CSR_READ_2(_sc, reg)		\
	bus_read_2((_sc)->alc_res[0], (reg))
#define	CSR_READ_4(_sc, reg)		\
	bus_read_4((_sc)->alc_res[0], (reg))

#define	ALC_RXCHAIN_RESET(_sc)						\
do {									\
	(_sc)->alc_cdata.alc_rxhead = NULL;				\
	(_sc)->alc_cdata.alc_rxtail = NULL;				\
	(_sc)->alc_cdata.alc_rxprev_tail = NULL;			\
	(_sc)->alc_cdata.alc_rxlen = 0;					\
} while (0)

#define	ALC_LOCK(_sc)		mtx_lock(&(_sc)->alc_mtx)
#define	ALC_UNLOCK(_sc)		mtx_unlock(&(_sc)->alc_mtx)
#define	ALC_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->alc_mtx, MA_OWNED)

#define	ALC_TX_TIMEOUT		5
#define	ALC_RESET_TIMEOUT	100
#define	ALC_TIMEOUT		1000
#define	ALC_PHY_TIMEOUT		1000

#endif	/* _IF_ALCVAR_H */
OpenPOWER on IntegriCloud