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