xref: /openbsd/sys/dev/mii/mii.h (revision 16220405)
1*16220405Syuo /*	$OpenBSD: mii.h,v 1.14 2015/07/18 20:38:44 yuo Exp $	*/
28d139882Snate /*	$NetBSD: mii.h,v 1.8 2001/05/31 03:06:46 thorpej Exp $	*/
3b7694f16Sjason 
4b7694f16Sjason /*
5b7694f16Sjason  * Copyright (c) 1997 Manuel Bouyer.  All rights reserved.
6b7694f16Sjason  *
7b7694f16Sjason  * Modification to match BSD/OS 3.0 MII interface by Jason R. Thorpe,
8b7694f16Sjason  * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
9b7694f16Sjason  *
10b7694f16Sjason  * Redistribution and use in source and binary forms, with or without
11b7694f16Sjason  * modification, are permitted provided that the following conditions
12b7694f16Sjason  * are met:
13b7694f16Sjason  * 1. Redistributions of source code must retain the above copyright
14b7694f16Sjason  *    notice, this list of conditions and the following disclaimer.
15b7694f16Sjason  * 2. Redistributions in binary form must reproduce the above copyright
16b7694f16Sjason  *    notice, this list of conditions and the following disclaimer in the
17b7694f16Sjason  *    documentation and/or other materials provided with the distribution.
18b7694f16Sjason  *
19b7694f16Sjason  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20b7694f16Sjason  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21b7694f16Sjason  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22b7694f16Sjason  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23b7694f16Sjason  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24b7694f16Sjason  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25b7694f16Sjason  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26b7694f16Sjason  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27b7694f16Sjason  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28b7694f16Sjason  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29b7694f16Sjason  */
30b7694f16Sjason 
31b7694f16Sjason #ifndef _DEV_MII_MII_H_
32b7694f16Sjason #define	_DEV_MII_MII_H_
33b7694f16Sjason 
34b7694f16Sjason /*
35b7694f16Sjason  * Registers common to all PHYs.
36b7694f16Sjason  */
37b7694f16Sjason 
38b7694f16Sjason #define	MII_NPHY	32	/* max # of PHYs per MII */
39b7694f16Sjason 
40b7694f16Sjason /*
41b7694f16Sjason  * MII commands, used if a device must drive the MII lines
42b7694f16Sjason  * manually.
43b7694f16Sjason  */
44b7694f16Sjason #define	MII_COMMAND_START	0x01
45b7694f16Sjason #define	MII_COMMAND_READ	0x02
46b7694f16Sjason #define	MII_COMMAND_WRITE	0x01
47b7694f16Sjason #define	MII_COMMAND_ACK		0x02
48b7694f16Sjason 
49b7694f16Sjason #define	MII_BMCR	0x00 	/* Basic mode control register (rw) */
50b7694f16Sjason #define	BMCR_RESET	0x8000	/* reset */
51b7694f16Sjason #define	BMCR_LOOP	0x4000	/* loopback */
52ebf88804Snate #define	BMCR_SPEED0	0x2000	/* speed selection (LSB) */
53b7694f16Sjason #define	BMCR_AUTOEN	0x1000	/* autonegotiation enable */
54b7694f16Sjason #define	BMCR_PDOWN	0x0800	/* power down */
55b7694f16Sjason #define	BMCR_ISO	0x0400	/* isolate */
56b7694f16Sjason #define	BMCR_STARTNEG	0x0200	/* restart autonegotiation */
57b7694f16Sjason #define	BMCR_FDX	0x0100	/* Set duplex mode */
58b7694f16Sjason #define	BMCR_CTEST	0x0080	/* collision test */
59ebf88804Snate #define	BMCR_SPEED1	0x0040	/* speed selection (MSB) */
60ebf88804Snate 
61ebf88804Snate #define	BMCR_S10	0x0000		/* 10 Mb/s */
62ebf88804Snate #define	BMCR_S100	BMCR_SPEED0	/* 100 Mb/s */
63ebf88804Snate #define	BMCR_S1000	BMCR_SPEED1	/* 1000 Mb/s */
64ebf88804Snate 
65ebf88804Snate #define	BMCR_SPEED(x)	((x) & (BMCR_SPEED0|BMCR_SPEED1))
66b7694f16Sjason 
67b7694f16Sjason #define	MII_BMSR	0x01	/* Basic mode status register (ro) */
68b7694f16Sjason #define	BMSR_100T4	0x8000	/* 100 base T4 capable */
69b7694f16Sjason #define	BMSR_100TXFDX	0x4000	/* 100 base Tx full duplex capable */
70b7694f16Sjason #define	BMSR_100TXHDX	0x2000	/* 100 base Tx half duplex capable */
71b7694f16Sjason #define	BMSR_10TFDX	0x1000	/* 10 base T full duplex capable */
72b7694f16Sjason #define	BMSR_10THDX	0x0800	/* 10 base T half duplex capable */
735d6e3d42Snate #define	BMSR_MFPS	0x0040	/* MII Frame Preamble Suppression */
74ebf88804Snate #define	BMSR_100T2FDX	0x0400	/* 100 base T2 full duplex capable */
75ebf88804Snate #define	BMSR_100T2HDX	0x0200	/* 100 base T2 half duplex capable */
76ebf88804Snate #define	BMSR_EXTSTAT	0x0100	/* Extended status in register 15 */
77b7694f16Sjason #define	BMSR_ACOMP	0x0020	/* Autonegotiation complete */
78b7694f16Sjason #define	BMSR_RFAULT	0x0010	/* Link partner fault */
79b7694f16Sjason #define	BMSR_ANEG	0x0008	/* Autonegotiation capable */
80b7694f16Sjason #define	BMSR_LINK	0x0004	/* Link status */
81b7694f16Sjason #define	BMSR_JABBER	0x0002	/* Jabber detected */
82ebf88804Snate #define	BMSR_EXTCAP	0x0001	/* Extended capability */
83b7694f16Sjason 
84ebf88804Snate /*
85ebf88804Snate  * Note that the EXTSTAT bit indicates that there is extended status
86ebf88804Snate  * info available in register 15, but 802.3 section 22.2.4.3 also
87704acedcSaaron  * states that all 1000 Mb/s capable PHYs will set this bit to 1.
88ebf88804Snate  */
89ebf88804Snate 
90ebf88804Snate #define	BMSR_MEDIAMASK	(BMSR_100T4|BMSR_100TXFDX|BMSR_100TXHDX| \
91ebf88804Snate 			 BMSR_10TFDX|BMSR_10THDX|BMSR_100T2FDX|BMSR_100T2HDX)
92b7694f16Sjason 
93b7694f16Sjason /*
94b7694f16Sjason  * Convert BMSR media capabilities to ANAR bits for autonegotiation.
95b7694f16Sjason  * Note the shift chopps off the BMSR_ANEG bit.
96b7694f16Sjason  */
97b7694f16Sjason #define	BMSR_MEDIA_TO_ANAR(x)	(((x) & BMSR_MEDIAMASK) >> 6)
98b7694f16Sjason 
99b7694f16Sjason #define	MII_PHYIDR1	0x02	/* ID register 1 (ro) */
100b7694f16Sjason 
101b7694f16Sjason #define	MII_PHYIDR2	0x03	/* ID register 2 (ro) */
102b7694f16Sjason #define	IDR2_OUILSB	0xfc00	/* OUI LSB */
103b7694f16Sjason #define	IDR2_MODEL	0x03f0	/* vendor model */
104b7694f16Sjason #define	IDR2_REV	0x000f	/* vendor revision */
105b7694f16Sjason 
106b7694f16Sjason #define	MII_ANAR	0x04	/* Autonegotiation advertisement (rw) */
107ebf88804Snate 		/* section 28.2.4.1 and 37.2.6.1 */
108b7694f16Sjason #define ANAR_NP		0x8000	/* Next page (ro) */
109b7694f16Sjason #define	ANAR_ACK	0x4000	/* link partner abilities acknowledged (ro) */
110b7694f16Sjason #define ANAR_RF		0x2000	/* remote fault (ro) */
1115d6e3d42Snate #define	ANAR_FC		0x0400	/* local device supports PAUSE */
112b7694f16Sjason #define ANAR_T4		0x0200	/* local device supports 100bT4 */
113b7694f16Sjason #define ANAR_TX_FD	0x0100	/* local device supports 100bTx FD */
114b7694f16Sjason #define ANAR_TX		0x0080	/* local device supports 100bTx */
115b7694f16Sjason #define ANAR_10_FD	0x0040	/* local device supports 10bT FD */
116b7694f16Sjason #define ANAR_10		0x0020	/* local device supports 10bT */
117b7694f16Sjason #define	ANAR_CSMA	0x0001	/* protocol selector CSMA/CD */
118eea85addSkettenis #define	ANAR_PAUSE_NONE		(0 << 10)
119eea85addSkettenis #define	ANAR_PAUSE_SYM		(1 << 10)
120eea85addSkettenis #define	ANAR_PAUSE_ASYM		(2 << 10)
121eea85addSkettenis #define	ANAR_PAUSE_TOWARDS	(3 << 10)
122b7694f16Sjason 
12307efc2c1Sbrad #define	ANAR_X_FD	0x0020	/* local device supports 1000BASE-X FD */
12407efc2c1Sbrad #define	ANAR_X_HD	0x0040	/* local device supports 1000BASE-X HD */
125eea85addSkettenis #define	ANAR_X_PAUSE_NONE	(0 << 7)
126eea85addSkettenis #define	ANAR_X_PAUSE_SYM	(1 << 7)
127eea85addSkettenis #define	ANAR_X_PAUSE_ASYM	(2 << 7)
128eea85addSkettenis #define	ANAR_X_PAUSE_TOWARDS	(3 << 7)
12907efc2c1Sbrad 
130b7694f16Sjason #define	MII_ANLPAR	0x05	/* Autonegotiation lnk partner abilities (rw) */
131ebf88804Snate 		/* section 28.2.4.1 and 37.2.6.1 */
132b7694f16Sjason #define ANLPAR_NP	0x8000	/* Next page (ro) */
133b7694f16Sjason #define	ANLPAR_ACK	0x4000	/* link partner accepted ACK (ro) */
134b7694f16Sjason #define ANLPAR_RF	0x2000	/* remote fault (ro) */
1355d6e3d42Snate #define	ANLPAR_FC	0x0400	/* link partner supports PAUSE */
136b7694f16Sjason #define ANLPAR_T4	0x0200	/* link partner supports 100bT4 */
137b7694f16Sjason #define ANLPAR_TX_FD	0x0100	/* link partner supports 100bTx FD */
138b7694f16Sjason #define ANLPAR_TX	0x0080	/* link partner supports 100bTx */
139b7694f16Sjason #define ANLPAR_10_FD	0x0040	/* link partner supports 10bT FD */
140b7694f16Sjason #define ANLPAR_10	0x0020	/* link partner supports 10bT */
141b7694f16Sjason #define	ANLPAR_CSMA	0x0001	/* protocol selector CSMA/CD */
142eea85addSkettenis #define	ANLPAR_PAUSE_MASK	(3 << 10)
143eea85addSkettenis #define	ANLPAR_PAUSE_NONE	(0 << 10)
144eea85addSkettenis #define	ANLPAR_PAUSE_SYM	(1 << 10)
145eea85addSkettenis #define	ANLPAR_PAUSE_ASYM	(2 << 10)
146eea85addSkettenis #define	ANLPAR_PAUSE_TOWARDS	(3 << 10)
147b7694f16Sjason 
14807efc2c1Sbrad #define	ANLPAR_X_FD	0x0020	/* local device supports 1000BASE-X FD */
14907efc2c1Sbrad #define	ANLPAR_X_HD	0x0040	/* local device supports 1000BASE-X HD */
150eea85addSkettenis #define	ANLPAR_X_PAUSE_MASK	(3 << 7)
151eea85addSkettenis #define	ANLPAR_X_PAUSE_NONE	(0 << 7)
152eea85addSkettenis #define	ANLPAR_X_PAUSE_SYM	(1 << 7)
153eea85addSkettenis #define	ANLPAR_X_PAUSE_ASYM	(2 << 7)
154eea85addSkettenis #define	ANLPAR_X_PAUSE_TOWARDS	(3 << 7)
15507efc2c1Sbrad 
156b7694f16Sjason #define	MII_ANER	0x06	/* Autonegotiation expansion (ro) */
157ebf88804Snate 		/* section 28.2.4.1 and 37.2.6.1 */
158b7694f16Sjason #define ANER_MLF	0x0010	/* multiple link detection fault */
159b7694f16Sjason #define ANER_LPNP	0x0008	/* link parter next page-able */
160b7694f16Sjason #define ANER_NP		0x0004	/* next page-able */
161b7694f16Sjason #define ANER_PAGE_RX	0x0002	/* Page received */
162b7694f16Sjason #define ANER_LPAN	0x0001	/* link parter autoneg-able */
163b7694f16Sjason 
164ebf88804Snate #define	MII_ANNP	0x07	/* Autonegotiation next page */
165ebf88804Snate 		/* section 28.2.4.1 and 37.2.6.1 */
166ebf88804Snate 
167ebf88804Snate #define	MII_ANLPRNP	0x08	/* Autonegotiation link partner rx next page */
168ebf88804Snate 		/* section 32.5.1 and 37.2.6.1 */
169ebf88804Snate 
1708d139882Snate 			/* This is also the 1000baseT control register */
171ebf88804Snate #define	MII_100T2CR	0x09	/* 100base-T2 control register */
1728d139882Snate #define	GTCR_TEST_MASK	0xe000	/* see 802.3ab ss. 40.6.1.1.2 */
1738d139882Snate #define	GTCR_MAN_MS	0x1000	/* enable manual master/slave control */
1748d139882Snate #define	GTCR_ADV_MS	0x0800	/* 1 = adv. master, 0 = adv. slave */
1758d139882Snate #define	GTCR_PORT_TYPE	0x0400	/* 1 = DCE, 0 = DTE (NIC) */
1768d139882Snate #define	GTCR_ADV_1000TFDX 0x0200 /* adv. 1000baseT FDX */
1778d139882Snate #define	GTCR_ADV_1000THDX 0x0100 /* adv. 1000baseT HDX */
178ebf88804Snate 
1798d139882Snate 			/* This is also the 1000baseT status register */
180ebf88804Snate #define	MII_100T2SR	0x0a	/* 100base-T2 status register */
1818d139882Snate #define	GTSR_MAN_MS_FLT	0x8000	/* master/slave config fault */
1828d139882Snate #define	GTSR_MS_RES	0x4000	/* result: 1 = master, 0 = slave */
1838d139882Snate #define	GTSR_LRS	0x2000	/* local rx status, 1 = ok */
1848d139882Snate #define	GTSR_RRS	0x1000	/* remove rx status, 1 = ok */
1858d139882Snate #define	GTSR_LP_1000TFDX 0x0800	/* link partner 1000baseT FDX capable */
1868d139882Snate #define	GTSR_LP_1000THDX 0x0400	/* link partner 1000baseT HDX capable */
1878d139882Snate #define	GTSR_LP_ASM_DIR	0x0200	/* link partner asym. pause dir. capable */
1888d139882Snate #define	GTSR_IDLE_ERR	0x00ff	/* IDLE error count */
189ebf88804Snate 
190b8ed6786Syuo #define	MII_PSECR	0x0b	/* PSE control register */
191b8ed6786Syuo #define	PSECR_PACTLMASK	0x000c	/* pair control mask */
192b8ed6786Syuo #define	PSECR_PSEENMASK	0x0003	/* PSE enable mask */
193b8ed6786Syuo #define	PSECR_PINOUTB	0x0008	/* PSE pinout Alternative B */
194b8ed6786Syuo #define	PSECR_PINOUTA	0x0004	/* PSE pinout Alternative A */
195b8ed6786Syuo #define	PSECR_FOPOWTST	0x0002	/* Force Power Test Mode */
196b8ed6786Syuo #define	PSECR_PSEEN	0x0001	/* PSE Enabled */
197b8ed6786Syuo #define	PSECR_PSEDIS	0x0000	/* PSE Disabled */
198b8ed6786Syuo 
199b8ed6786Syuo #define	MII_PSESR	0x0c	/* PSE status register */
200*16220405Syuo #define	PSESR_PWRDENIED	0x1000	/* Power Denied */
201b8ed6786Syuo #define	PSESR_VALSIG	0x0800	/* Valid PD signature detected */
202b8ed6786Syuo #define	PSESR_INVALSIG	0x0400	/* Invalid PD signature detected */
203b8ed6786Syuo #define	PSESR_SHORTCIRC	0x0200	/* Short circuit condition detected */
204b8ed6786Syuo #define	PSESR_OVERLOAD	0x0100	/* Overload condition detected */
205b8ed6786Syuo #define	PSESR_MPSABSENT	0x0080	/* MPS absent condition detected */
206b8ed6786Syuo #define	PSESR_PDCLMASK	0x0070	/* PD Class mask */
207b8ed6786Syuo #define	PSESR_STATMASK	0x000e	/* PSE Status mask */
208b8ed6786Syuo #define	PSESR_PAIRCTABL	0x0001	/* PAIR Control Ability */
209b8ed6786Syuo #define	PSESR_PDCL_4		(4 << 4)	/* Class 4 */
210b8ed6786Syuo #define	PSESR_PDCL_3		(3 << 4)	/* Class 3 */
211b8ed6786Syuo #define	PSESR_PDCL_2		(2 << 4)	/* Class 2 */
212b8ed6786Syuo #define	PSESR_PDCL_1		(1 << 4)	/* Class 1 */
213b8ed6786Syuo #define	PSESR_PDCL_0		(0 << 4)	/* Class 0 */
214b8ed6786Syuo 
215b8ed6786Syuo #define	MII_MMDACR	0x0d	/* MMD access control register */
216b8ed6786Syuo #define	MMDACR_FUNCMASK		0xc000	/* function */
217b8ed6786Syuo #define	MMDACR_DADDRMASK 	0x001f	/* device address */
218b8ed6786Syuo #define	MMDACR_FN_ADDRESS	(0 << 14) /* address */
219b8ed6786Syuo #define	MMDACR_FN_DATANPI	(1 << 14) /* data, no post increment */
220b8ed6786Syuo #define	MMDACR_FN_DATAPIRW	(2 << 14) /* data, post increment on r/w */
221b8ed6786Syuo #define	MMDACR_FN_DATAPIW	(3 << 14) /* data, post increment on wr only */
222b8ed6786Syuo 
223b8ed6786Syuo #define	MII_MMDAADR	0x0e	/* MMD access address data register */
224b8ed6786Syuo 
225ebf88804Snate #define	MII_EXTSR	0x0f	/* Extended status register */
226ebf88804Snate #define	EXTSR_1000XFDX	0x8000	/* 1000X full-duplex capable */
227ebf88804Snate #define	EXTSR_1000XHDX	0x4000	/* 1000X half-duplex capable */
228ebf88804Snate #define	EXTSR_1000TFDX	0x2000	/* 1000T full-duplex capable */
229ebf88804Snate #define	EXTSR_1000THDX	0x1000	/* 1000T half-duplex capable */
230ebf88804Snate 
231ebf88804Snate #define	EXTSR_MEDIAMASK	(EXTSR_1000XFDX|EXTSR_1000XHDX| \
232ebf88804Snate 			 EXTSR_1000TFDX|EXTSR_1000THDX)
233ebf88804Snate 
234b7694f16Sjason #endif /* _DEV_MII_MII_H_ */
235