xref: /illumos-gate/usr/src/uts/common/io/atge/atge.h (revision 581cede61ac9c14d8d4ea452562a567189eead78)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _ATGE_H
27 #define	_ATGE_H
28 
29 #ifdef __cplusplus
30 	extern "C" {
31 #endif
32 
33 #include <sys/mac_provider.h>
34 #include "atge_l1e_reg.h"
35 
36 #define	ATGE_SUCCESS	1
37 #define	ATGE_FAILURE	0
38 
39 #define	ATGE_PCI_REG_NUMBER	1
40 
41 #define	ROUNDUP(x, a)		(((x) + (a) - 1) & ~((a) - 1))
42 
43 /*
44  * Flags.
45  */
46 #define	ATGE_FLAG_PCIE		0x0001
47 #define	ATGE_FIXED_TYPE		0x0002
48 #define	ATGE_MSI_TYPE		0x0004
49 #define	ATGE_MSIX_TYPE		0x0008
50 #define	ATGE_FLAG_FASTETHER	0x0010
51 #define	ATGE_FLAG_JUMBO		0x0020
52 
53 #define	ATGE_CHIP_L1_DEV_ID	0x1048
54 #define	ATGE_CHIP_L2_DEV_ID	0x2048
55 #define	ATGE_CHIP_L1E_DEV_ID	0x1026
56 
57 #define	ATGE_PROMISC		0x001
58 #define	ATGE_ALL_MULTICST	0x002
59 
60 /*
61  * Timer for one second interval.
62  */
63 #define	ATGE_TIMER_INTERVAL	(1000 * 1000 * 1000)
64 
65 /*
66  * Chip state.
67  */
68 #define	ATGE_CHIP_INITIALIZED	0x0001
69 #define	ATGE_CHIP_RUNNING	0x0002
70 #define	ATGE_CHIP_STOPPED	0x0004
71 #define	ATGE_CHIP_SUSPENDED	0x0008
72 
73 #define	ETHER_CRC_LEN		0x4
74 
75 /*
76  * Descriptor increment and decrment operation.
77  */
78 #define	ATGE_DESC_INC(x, y)	((x) = ((x) + 1) % (y))
79 
80 /*
81  * I/O instructions
82  */
83 #define	OUTB(atge, p, v)  \
84 	ddi_put8((atge)->atge_io_handle, \
85 		(void *)((caddr_t)((atge)->atge_io_regs) + (p)), v)
86 
87 #define	OUTW(atge, p, v)  \
88 	ddi_put16((atge)->atge_io_handle, \
89 		(void *)((caddr_t)((atge)->atge_io_regs) + (p)), v)
90 
91 #define	OUTL(atge, p, v)  \
92 	ddi_put32((atge)->atge_io_handle, \
93 		(void *)((caddr_t)((atge)->atge_io_regs) + (p)), v)
94 
95 #define	INB(atge, p)      \
96 	ddi_get8((atge)->atge_io_handle, \
97 		(void *)(((caddr_t)(atge)->atge_io_regs) + (p)))
98 #define	INW(atge, p)      \
99 	ddi_get16((atge)->atge_io_handle, \
100 		(void *)(((caddr_t)(atge)->atge_io_regs) + (p)))
101 
102 #define	INL(atge, p)      \
103 	ddi_get32((atge)->atge_io_handle, \
104 		(void *)(((caddr_t)(atge)->atge_io_regs) + (p)))
105 
106 #define	FLUSH(atge, reg) \
107 	(void) INL(atge, reg)
108 
109 #define	OUTL_OR(atge, reg, v) \
110 	OUTL(atge, reg, (INL(atge, reg) | v))
111 
112 #define	OUTL_AND(atge, reg, v) \
113 	OUTL(atge, reg, (INL(atge, reg) & v))
114 
115 /*
116  * Descriptor and other endianess aware access.
117  */
118 #define	ATGE_PUT64(dma, addr, v) \
119 	ddi_put64(dma->acchdl, (addr), (v))
120 
121 #define	ATGE_PUT32(dma, addr, v) \
122 	ddi_put32(dma->acchdl, (addr), (v))
123 
124 #define	ATGE_GET32(dma, addr) \
125 	ddi_get32(dma->acchdl, (addr))
126 
127 #define	ATGE_GET64(dma, addr) \
128 	ddi_get64(dma->acchdl, (addr))
129 
130 #define	DMA_SYNC(dma, s, l, d)	\
131 	(void) ddi_dma_sync(dma->hdl, (off_t)(s), (l), d)
132 
133 
134 #define	ATGE_ADDR_LO(x)		((uint64_t)(x) & 0xFFFFFFFF)
135 #define	ATGE_ADDR_HI(x)		((uint64_t)(x) >> 32)
136 
137 
138 /*
139  * General purpose macros.
140  */
141 #define	ATGE_MODEL(atgep)	atgep->atge_model
142 
143 /*
144  * Different type of chip models.
145  */
146 typedef	enum {
147 	ATGE_CHIP_L1 = 1,
148 	ATGE_CHIP_L2,
149 	ATGE_CHIP_L1E,
150 } atge_model_t;
151 
152 typedef	struct	atge_cards {
153 	uint16_t	vendor_id;	/* PCI vendor id */
154 	uint16_t	device_id;	/* PCI device id */
155 	char		*cardname;	/* Description of the card */
156 	atge_model_t	model;		/* Model of the card */
157 } atge_cards_t;
158 
159 /*
160  * Number of Descriptors for TX and RX Ring.
161  */
162 #define	ATGE_TX_NUM_DESC	256
163 #define	ATGE_RX_NUM_DESC	256
164 
165 /*
166  * DMA Handle for all DMA work.
167  */
168 typedef	struct	atge_dma_data {
169 	ddi_dma_handle_t	hdl;
170 	ddi_acc_handle_t	acchdl;
171 	ddi_dma_cookie_t	cookie;
172 	caddr_t			addr;
173 	size_t			len;
174 	uint_t			count;
175 } atge_dma_t;
176 
177 /*
178  * TX descriptor table buffers.
179  */
180 typedef	struct	atge_tx_desc_tbl {
181 	atge_dma_t	desc_dma;
182 	void		*desc_buf;
183 } atge_tx_desc_tbl_t;
184 
185 /*
186  * RX descriptor table buffers.
187  */
188 typedef	struct	atge_rx_desc_tbl {
189 	atge_dma_t	desc_dma;
190 	void		*desc_buf;
191 } atge_rx_desc_tbl_t;
192 
193 struct	atge;
194 
195 /*
196  * Structure for ring data (TX/RX).
197  */
198 typedef	struct	atge_ring {
199 	struct	atge	*r_atge;
200 	atge_dma_t	**r_buf_tbl;
201 	atge_dma_t	*r_desc_ring;
202 	int		r_ndesc;
203 	int		r_consumer;
204 	int		r_producer;
205 	int		r_avail_desc;
206 } atge_ring_t;
207 
208 /*
209  * L1E specific private data.
210  */
211 typedef	struct	atge_l1e_data {
212 	atge_dma_t	**atge_l1e_rx_page;
213 	atge_dma_t	*atge_l1e_rx_cmb;
214 	int		atge_l1e_pagesize;
215 	int		atge_l1e_rx_curp;
216 	uint16_t	atge_l1e_rx_seqno;
217 	uint32_t	atge_l1e_proc_max;
218 	uint32_t	atge_l1e_rx_page_cons;
219 	uint32_t	atge_l1e_rx_page_prods[L1E_RX_PAGES];
220 } atge_l1e_data_t;
221 
222 /*
223  * Private instance data structure (per-instance soft-state).
224  */
225 typedef	struct	atge {
226 	/*
227 	 * Lock for the TX ring, RX ring and interrupt. In order to align
228 	 * these locks at 8-byte boundary, we have kept it at the beginning
229 	 * of atge_t.
230 	 */
231 	kmutex_t		atge_tx_lock;
232 	kmutex_t		atge_rx_lock;
233 	kmutex_t		atge_intr_lock;
234 	kmutex_t		atge_mii_lock;
235 
236 	/*
237 	 * Instance number and devinfo pointer.
238 	 */
239 	int			atge_unit;
240 	dev_info_t		*atge_dip;
241 	char			atge_name[8];
242 	atge_model_t		atge_model;
243 	int			atge_chip_rev;
244 	uint8_t			atge_revid;
245 
246 	/*
247 	 * Mac handle.
248 	 */
249 	mac_handle_t		atge_mh;
250 
251 	/*
252 	 * MII layer handle.
253 	 */
254 	mii_handle_t		atge_mii;
255 	link_state_t		atge_link_state;
256 
257 	/*
258 	 * Config Space Handle.
259 	 */
260 	ddi_acc_handle_t	atge_conf_handle;
261 
262 	/*
263 	 * IO registers mapped by DDI.
264 	 */
265 	ddi_acc_handle_t	atge_io_handle;
266 	caddr_t			atge_io_regs;
267 	uint_t			atge_intrs;
268 
269 	/*
270 	 * Interrupt management structures.
271 	 */
272 	ddi_intr_handle_t	*atge_intr_handle;
273 	int			atge_intr_types;
274 	int			atge_intr_cnt;
275 	uint_t			atge_intr_pri;
276 	int			atge_intr_size;
277 	int			atge_intr_cap;
278 
279 	/*
280 	 * Common structures.
281 	 */
282 	atge_ring_t		*atge_tx_ring;
283 	int			atge_tx_resched;
284 	int			atge_mtu;
285 	int			atge_int_mod;
286 	int			atge_max_frame_size;
287 
288 	/*
289 	 * Ethernet addresses.
290 	 */
291 	ether_addr_t		atge_ether_addr;
292 	ether_addr_t		atge_dev_addr;
293 	uint64_t		atge_mchash;
294 	uint32_t		atge_mchash_ref_cnt[64];
295 
296 	/*
297 	 * PHY register.
298 	 */
299 	int			atge_phyaddr;
300 
301 	/*
302 	 * Flags.
303 	 */
304 	int			atge_flags;
305 	uint32_t		atge_dma_rd_burst;
306 	uint32_t		atge_dma_wr_burst;
307 	int			atge_filter_flags;
308 	int			atge_chip_state;
309 
310 	/*
311 	 * Private data for the chip.
312 	 */
313 	void			*atge_private_data;
314 
315 	/*
316 	 * Buffer length.
317 	 */
318 	int			atge_rx_buf_len;
319 	int			atge_tx_buf_len;
320 
321 	/*
322 	 * Common stats.
323 	 */
324 	void			*atge_hw_stats;
325 	uint64_t		atge_ipackets;
326 	uint64_t		atge_opackets;
327 	uint64_t		atge_rbytes;
328 	uint64_t		atge_obytes;
329 	uint64_t		atge_brdcstxmt;
330 	uint64_t		atge_multixmt;
331 	uint64_t		atge_brdcstrcv;
332 	uint64_t		atge_multircv;
333 	unsigned		atge_norcvbuf;
334 	unsigned		atge_errrcv;
335 	unsigned		atge_errxmt;
336 	unsigned		atge_missed;
337 	unsigned		atge_underflow;
338 	unsigned		atge_overflow;
339 	unsigned		atge_align_errors;
340 	unsigned		atge_fcs_errors;
341 	unsigned		atge_carrier_errors;
342 	unsigned		atge_collisions;
343 	unsigned		atge_ex_collisions;
344 	unsigned		atge_tx_late_collisions;
345 	unsigned		atge_defer_xmts;
346 	unsigned		atge_first_collisions;
347 	unsigned		atge_multi_collisions;
348 	unsigned		atge_sqe_errors;
349 	unsigned		atge_macxmt_errors;
350 	unsigned		atge_macrcv_errors;
351 	unsigned		atge_toolong_errors;
352 	unsigned		atge_runt;
353 	unsigned		atge_jabber;
354 	unsigned		atge_noxmtbuf;
355 } atge_t;
356 
357 /*
358  * extern functions.
359  */
360 extern	void	atge_error(dev_info_t *, char *, ...);
361 
362 /*
363  * Debugging Support.
364  */
365 #ifdef	DEBUG
366 #define	ATGE_DB(arg)	atge_debug_func arg
367 #else
368 #define	ATGE_DB(arg)
369 #endif
370 
371 extern	int	atge_debug;
372 extern	void	atge_debug_func(char *, ...);
373 extern	atge_dma_t	*atge_alloc_a_dma_blk(atge_t *, ddi_dma_attr_t *,
374     int, int);
375 extern	void	atge_free_a_dma_blk(atge_dma_t *);
376 extern	atge_dma_t *atge_buf_alloc(atge_t *, size_t, int);
377 extern	void	atge_buf_free(atge_dma_t *);
378 extern	mblk_t *atge_get_mblk(int);
379 extern	void	atge_device_restart(atge_t *);
380 extern	int	atge_alloc_buffers(atge_ring_t *, size_t, size_t, int);
381 extern	void	atge_free_buffers(atge_ring_t *, size_t);
382 extern	void	atge_stop_timer(atge_t *);
383 extern	void	atge_start_timer(atge_t *);
384 extern	void	atge_mii_write(void *, uint8_t, uint8_t, uint16_t);
385 
386 #ifdef __cplusplus
387 }
388 #endif
389 
390 #endif	/* _ATGE_H */
391