xref: /titanic_52/usr/src/uts/common/io/hme/hme.h (revision bd670b35a010421b6e1a5536c34453a827007c81)
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	_SYS_HME_H
27 #define	_SYS_HME_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #ifdef _KERNEL
34 
35 /* default IPG settings */
36 #define	IPG1	8
37 #define	IPG2	4
38 
39 /*
40  * Declarations and definitions specific to the
41  * FEPS 10/100 Mbps Ethernet (hme) device.
42  */
43 
44 /*
45  * Per-Stream instance state information.
46  *
47  * Each instance is dynamically allocated at open() and free'd
48  * at close().  Each per-Stream instance points to at most one
49  * per-device structure using the sb_hmep field.  All instances
50  * are threaded together into one list of active instances
51  * ordered on minor device number.
52  */
53 
54 #define	HME_2P0_REVID		0xa0 /* hme - feps. */
55 #define	HME_2P1_REVID		0x20
56 #define	HME_2P1_REVID_OBP	0x21
57 #define	HME_1C0_REVID		0xc0 /* cheerio 1.0, hme 2.0 equiv. */
58 #define	HME_2C0_REVID		0xc1 /* cheerio 2.0, hme 2.2 equiv. */
59 #define	HME_REV_VERS_MASK	0x0f /* Mask to retain bits for cheerio ver */
60 
61 typedef struct {
62 	ddi_dma_handle_t	dmah;
63 	ddi_acc_handle_t	acch;
64 	caddr_t			kaddr;
65 	uint32_t		paddr;
66 } hmebuf_t;
67 
68 /*
69  * HME Device Channel instance state information.
70  *
71  * Each instance is dynamically allocated on first attach.
72  */
73 struct	hme {
74 	mac_handle_t		hme_mh;		/* GLDv3 handle */
75 	mii_handle_t		hme_mii;
76 	dev_info_t		*dip;		/* associated dev_info */
77 	int			instance;	/* instance */
78 	ulong_t			pagesize;	/* btop(9F) */
79 
80 	int			hme_mifpoll_enable;
81 	int			hme_frame_enable;
82 	int			hme_lance_mode_enable;
83 	int			hme_rxcv_enable;
84 
85 	uint32_t		hme_lance_mode;
86 	uint32_t		hme_ipg0;
87 	uint32_t		hme_ipg1;
88 	uint32_t		hme_ipg2;
89 
90 	uint_t			hme_burstsizes; /* binary encoded val */
91 	uint32_t		hme_config;	/* Config reg store */
92 
93 	int			hme_phy_failure; /* phy failure type */
94 
95 	int			hme_64bit_xfer;	/* 64-bit Sbus xfers */
96 	int			hme_phyad;
97 
98 	int			hme_nlasttries;
99 	int			hme_cheerio_mode;
100 
101 	struct	ether_addr	hme_factaddr;	/* factory mac address */
102 	struct	ether_addr	hme_ouraddr;	/* individual address */
103 	uint32_t		hme_addrflags;	/* address flags */
104 	uint32_t		hme_flags;	/* misc. flags */
105 	boolean_t		hme_wantw;	/* xmit: out of resources */
106 	boolean_t		hme_started;	/* mac layer started */
107 
108 	uint8_t			hme_devno;
109 
110 	uint16_t		hme_ladrf[4];	/* 64 bit multicast filter */
111 	uint32_t		hme_ladrf_refcnt[64];
112 	boolean_t		hme_promisc;
113 	uint32_t		hme_multi;	/* refcount on mcast addrs */
114 
115 	struct	hme_global	*hme_globregp;	/* HME global regs */
116 	struct	hme_etx		*hme_etxregp;	/* HME ETX regs */
117 	struct	hme_erx		*hme_erxregp;	/* HME ERX regs */
118 	struct	hme_bmac	*hme_bmacregp;	/* BigMAC registers */
119 	struct	hme_mif		*hme_mifregp;	/* HME transceiver */
120 	unsigned char		*hme_romp;	/* fcode rom pointer */
121 
122 	kmutex_t	hme_xmitlock;		/* protect xmit-side fields */
123 	kmutex_t	hme_intrlock;		/* protect intr-side fields */
124 	ddi_iblock_cookie_t	hme_cookie;	/* interrupt cookie */
125 
126 	struct	hme_rmd	*hme_rmdp;	/* receive descriptor ring start */
127 	struct	hme_tmd	*hme_tmdp;	/* transmit descriptor ring start */
128 
129 	ddi_dma_handle_t	hme_rmd_dmah;
130 	ddi_acc_handle_t	hme_rmd_acch;
131 	caddr_t			hme_rmd_kaddr;
132 	uint32_t		hme_rmd_paddr;
133 
134 	ddi_dma_handle_t	hme_tmd_dmah;
135 	ddi_acc_handle_t	hme_tmd_acch;
136 	caddr_t			hme_tmd_kaddr;
137 	uint32_t		hme_tmd_paddr;
138 
139 	uint64_t		hme_rxindex;
140 	uint64_t		hme_txindex;
141 	uint64_t		hme_txreclaim;
142 
143 	hmebuf_t		*hme_tbuf;	/* hmebuf associated with TMD */
144 	hmebuf_t		*hme_rbuf;	/* hmebuf associated with RMD */
145 
146 	ddi_device_acc_attr_t	hme_dev_attr;
147 	ddi_acc_handle_t	hme_globregh;   /* HME global regs */
148 	ddi_acc_handle_t	hme_etxregh;    /* HME ETX regs */
149 	ddi_acc_handle_t	hme_erxregh;    /* HME ERX regs */
150 	ddi_acc_handle_t	hme_bmacregh;   /* BigMAC registers */
151 	ddi_acc_handle_t	hme_mifregh;    /* HME transceiver */
152 	ddi_acc_handle_t	hme_romh;	/* rom handle */
153 
154 	ddi_acc_handle_t	pci_config_handle; /* HME PCI config */
155 
156 	/*
157 	 * DDI dma handle, kernel virtual base,
158 	 * and io virtual base of IOPB area.
159 	 */
160 	ddi_dma_handle_t	hme_iopbhandle;
161 	ulong_t			hme_iopbkbase;
162 	uint32_t		hme_iopbiobase;
163 
164 	kstat_t	*hme_ksp;	/* kstat pointer */
165 	kstat_t	*hme_intrstats;	/* kstat interrupt counter */
166 
167 	uint64_t hme_ipackets;
168 	uint64_t hme_rbytes;
169 	uint64_t hme_ierrors;
170 	uint64_t hme_opackets;
171 	uint64_t hme_obytes;
172 	uint64_t hme_oerrors;
173 	uint64_t hme_multircv;		/* # multicast packets received */
174 	uint64_t hme_multixmt;		/* # multicast packets for xmit */
175 	uint64_t hme_brdcstrcv;		/* # broadcast packets received */
176 	uint64_t hme_brdcstxmt;		/* # broadcast packets for xmit */
177 	uint64_t hme_oflo;
178 	uint64_t hme_uflo;
179 	uint64_t hme_norcvbuf;		/* # rcv packets discarded */
180 	uint64_t hme_noxmtbuf;		/* # xmit packets discarded */
181 	uint64_t hme_duplex;
182 	uint64_t hme_align_errors;
183 	uint64_t hme_coll;
184 	uint64_t hme_fcs_errors;
185 	uint64_t hme_defer_xmts;
186 	uint64_t hme_sqe_errors;
187 	uint64_t hme_excol;
188 	uint64_t hme_fstcol;
189 	uint64_t hme_tlcol;
190 	uint64_t hme_toolong_errors;
191 	uint64_t hme_runt;
192 	uint64_t hme_carrier_errors;
193 	uint64_t hme_jab;
194 
195 	uint32_t hme_cvc;
196 	uint32_t hme_lenerr;
197 	uint32_t hme_buff;
198 	uint32_t hme_missed;
199 	uint32_t hme_nocanput;
200 	uint32_t hme_allocbfail;
201 	uint32_t hme_babl;
202 	uint32_t hme_tmder;
203 	uint32_t hme_txlaterr;
204 	uint32_t hme_rxlaterr;
205 	uint32_t hme_slvparerr;
206 	uint32_t hme_txparerr;
207 	uint32_t hme_rxparerr;
208 	uint32_t hme_slverrack;
209 	uint32_t hme_txerrack;
210 	uint32_t hme_rxerrack;
211 	uint32_t hme_txtagerr;
212 	uint32_t hme_rxtagerr;
213 	uint32_t hme_eoperr;
214 	uint32_t hme_notmds;
215 	uint32_t hme_notbufs;
216 	uint32_t hme_norbufs;
217 
218 	/*
219 	 * check if transmitter is hung
220 	 */
221 	uint32_t hme_starts;
222 	uint32_t hme_txhung;
223 	time_t hme_msg_time;
224 
225 	/*
226 	 * Debuging kstats
227 	 */
228 	uint32_t inits;
229 	uint32_t phyfail;
230 	uint32_t asic_rev;
231 };
232 
233 /* flags */
234 #define	HMERUNNING	0x01	/* chip is initialized */
235 #define	HMESUSPENDED	0x08	/* suspended interface */
236 #define	HMEINITIALIZED	0x10	/* interface initialized */
237 
238 /* Mac address flags */
239 
240 #define	HME_FACTADDR_PRESENT	0x01	/* factory MAC id present */
241 #define	HME_FACTADDR_USE	0x02	/* use factory MAC id */
242 
243 struct	hmekstat {
244 	struct kstat_named	hk_cvc;		/* code violation  errors */
245 	struct kstat_named	hk_lenerr;	/* rx len errors */
246 	struct kstat_named	hk_buff;	/* buff errors */
247 	struct kstat_named	hk_missed;	/* missed/dropped packets */
248 	struct kstat_named	hk_nocanput;	/* nocanput errors */
249 	struct kstat_named	hk_allocbfail;	/* allocb failures */
250 	struct kstat_named	hk_babl;	/* runt errors */
251 	struct kstat_named	hk_tmder;	/* tmd errors */
252 	struct kstat_named	hk_txlaterr;	/* tx late errors */
253 	struct kstat_named	hk_rxlaterr;	/* rx late errors */
254 	struct kstat_named	hk_slvparerr;	/* slave parity errors */
255 	struct kstat_named	hk_txparerr;	/* tx parity errors */
256 	struct kstat_named	hk_rxparerr;	/* rx parity errors */
257 	struct kstat_named	hk_slverrack;	/* slave error acks */
258 	struct kstat_named	hk_txerrack;	/* tx error acks */
259 	struct kstat_named	hk_rxerrack;	/* rx error acks */
260 	struct kstat_named	hk_txtagerr;	/* tx tag error */
261 	struct kstat_named	hk_rxtagerr;	/* rx tag error */
262 	struct kstat_named	hk_eoperr;	/* eop error */
263 	struct kstat_named	hk_notmds;	/* tmd errors */
264 	struct kstat_named	hk_notbufs;	/* tx buf errors */
265 	struct kstat_named	hk_norbufs;	/* rx buf errors */
266 
267 	struct kstat_named	hk_inits;		/* global inits */
268 	struct	kstat_named	hk_phyfail;		/* phy failures */
269 
270 	struct	kstat_named	hk_asic_rev;		/* asic_rev */
271 };
272 
273 #define	HMEDRAINTIME	(400000)	/* # microseconds xmit drain */
274 
275 #define	ROUNDUP(a, n)	(((a) + ((n) - 1)) & ~((n) - 1))
276 #define	ROUNDUP2(a, n)	(uchar_t *)((((uintptr_t)(a)) + ((n) - 1)) & ~((n) - 1))
277 
278 /*
279  * Xmit/receive buffer structure.
280  * This structure is organized to meet the following requirements:
281  * - bb_buf starts on an HMEBURSTSIZE boundary.
282  * - hmebuf is an even multiple of HMEBURSTSIZE
283  * - bb_buf[] is large enough to contain max VLAN frame (1522) plus
284  *   (3 x HMEBURSTSIZE) rounded up to the next HMEBURSTSIZE
285  * XXX What about another 128 bytes (HMEC requirement).
286  * Fast aligned copy requires both the source and destination
287  * addresses have the same offset from some N-byte boundary.
288  */
289 #define		HMEBURSTSIZE	(64)
290 #define		HMEBURSTMASK	(HMEBURSTSIZE - 1)
291 #define		HMEBUFSIZE	(1728)
292 
293 /*
294  * Define offset from start of bb_buf[] to point receive descriptor.
295  * Requirements:
296  * - must be 14 bytes back of a 4-byte boundary so the start of
297  *   the network packet is 4-byte aligned.
298  * - leave some headroom for others
299  */
300 #define		HMEHEADROOM	(34)
301 
302 /* Offset for the first byte in the receive buffer */
303 #define	HME_FSTBYTE_OFFSET	2
304 
305 #endif	/* _KERNEL */
306 
307 #ifdef	__cplusplus
308 }
309 #endif
310 
311 #endif	/* _SYS_HME_H */
312