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