xref: /netbsd-src/sys/arch/arm/sunxi/sunxi_emac.h (revision 4d6fdc916e1da1cf536d3a085e6060475434d123)
19432a99aSjmcneill /*-
29432a99aSjmcneill  * Copyright (c) 2016 Jared McNeill <jmcneill@invisible.ca>
39432a99aSjmcneill  * All rights reserved.
49432a99aSjmcneill  *
59432a99aSjmcneill  * Redistribution and use in source and binary forms, with or without
69432a99aSjmcneill  * modification, are permitted provided that the following conditions
79432a99aSjmcneill  * are met:
89432a99aSjmcneill  * 1. Redistributions of source code must retain the above copyright
99432a99aSjmcneill  *    notice, this list of conditions and the following disclaimer.
109432a99aSjmcneill  * 2. Redistributions in binary form must reproduce the above copyright
119432a99aSjmcneill  *    notice, this list of conditions and the following disclaimer in the
129432a99aSjmcneill  *    documentation and/or other materials provided with the distribution.
139432a99aSjmcneill  *
149432a99aSjmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
159432a99aSjmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
169432a99aSjmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
179432a99aSjmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
189432a99aSjmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
199432a99aSjmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
209432a99aSjmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
219432a99aSjmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
229432a99aSjmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
239432a99aSjmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
249432a99aSjmcneill  * SUCH DAMAGE.
259432a99aSjmcneill  *
269432a99aSjmcneill  * $FreeBSD$
279432a99aSjmcneill  */
289432a99aSjmcneill 
299432a99aSjmcneill /*
309432a99aSjmcneill  * Allwinner Gigabit Ethernet
319432a99aSjmcneill  */
329432a99aSjmcneill 
339432a99aSjmcneill #ifndef __SUNXI_EMAC_H__
349432a99aSjmcneill #define __SUNXI_EMAC_H__
359432a99aSjmcneill 
369432a99aSjmcneill #define	EMAC_BASIC_CTL_0	0x00
379432a99aSjmcneill #define	 BASIC_CTL_SPEED	(0x3 << 2)
389432a99aSjmcneill #define	 BASIC_CTL_SPEED_SHIFT	2
399432a99aSjmcneill #define	 BASIC_CTL_SPEED_1000	0
409432a99aSjmcneill #define	 BASIC_CTL_SPEED_10	2
419432a99aSjmcneill #define	 BASIC_CTL_SPEED_100	3
429432a99aSjmcneill #define	 BASIC_CTL_LOOPBACK	(1 << 1)
439432a99aSjmcneill #define	 BASIC_CTL_DUPLEX	(1 << 0)
449432a99aSjmcneill #define	EMAC_BASIC_CTL_1	0x04
459432a99aSjmcneill #define	 BASIC_CTL_BURST_LEN	(0x3f << 24)
469432a99aSjmcneill #define	 BASIC_CTL_BURST_LEN_SHIFT 24
479432a99aSjmcneill #define	 BASIC_CTL_RX_TX_PRI	(1 << 1)
489432a99aSjmcneill #define	 BASIC_CTL_SOFT_RST	(1 << 0)
499432a99aSjmcneill #define	EMAC_INT_STA		0x08
50d1b80ee1Sjmcneill #define	 RGMII_LINK_STA_INT	(1 << 16)
51d1b80ee1Sjmcneill #define	 RX_EARLY_INT		(1 << 13)
52d1b80ee1Sjmcneill #define	 RX_OVERFLOW_INT	(1 << 12)
53d1b80ee1Sjmcneill #define	 RX_TIMEOUT_INT		(1 << 11)
54d1b80ee1Sjmcneill #define	 RX_DMA_STOPPED_INT	(1 << 10)
55d1b80ee1Sjmcneill #define	 RX_BUF_UA_INT		(1 << 9)
569432a99aSjmcneill #define	 RX_INT			(1 << 8)
57d1b80ee1Sjmcneill #define	 TX_EARLY_INT		(1 << 5)
589432a99aSjmcneill #define	 TX_UNDERFLOW_INT	(1 << 4)
59d1b80ee1Sjmcneill #define	 TX_TIMEOUT_INT		(1 << 3)
609432a99aSjmcneill #define	 TX_BUF_UA_INT		(1 << 2)
619432a99aSjmcneill #define	 TX_DMA_STOPPED_INT	(1 << 1)
629432a99aSjmcneill #define	 TX_INT			(1 << 0)
639432a99aSjmcneill #define	EMAC_INT_EN		0x0c
64d1b80ee1Sjmcneill #define	 RX_EARLY_INT_EN	(1 << 13)
65d1b80ee1Sjmcneill #define	 RX_OVERFLOW_INT_EN	(1 << 12)
66d1b80ee1Sjmcneill #define	 RX_TIMEOUT_INT_EN	(1 << 11)
67d1b80ee1Sjmcneill #define	 RX_DMA_STOPPED_INT_EN	(1 << 10)
68d1b80ee1Sjmcneill #define	 RX_BUF_UA_INT_EN	(1 << 9)
699432a99aSjmcneill #define	 RX_INT_EN		(1 << 8)
70d1b80ee1Sjmcneill #define	 TX_EARLY_INT_EN	(1 << 5)
719432a99aSjmcneill #define	 TX_UNDERFLOW_INT_EN	(1 << 4)
72d1b80ee1Sjmcneill #define	 TX_TIMEOUT_INT_EN	(1 << 3)
739432a99aSjmcneill #define	 TX_BUF_UA_INT_EN	(1 << 2)
749432a99aSjmcneill #define	 TX_DMA_STOPPED_INT_EN	(1 << 1)
759432a99aSjmcneill #define	 TX_INT_EN		(1 << 0)
769432a99aSjmcneill #define	EMAC_TX_CTL_0		0x10
779432a99aSjmcneill #define	 TX_EN			(1 << 31)
78d1b80ee1Sjmcneill #define	 TX_FRM_LEN_CTL		(1 << 30)
799432a99aSjmcneill #define	EMAC_TX_CTL_1		0x14
809432a99aSjmcneill #define	 TX_DMA_START		(1 << 31)
819432a99aSjmcneill #define	 TX_DMA_EN		(1 << 30)
82d1b80ee1Sjmcneill #define	 TX_TH			(0x7 << 8)
839432a99aSjmcneill #define	 TX_NEXT_FRAME		(1 << 2)
849432a99aSjmcneill #define	 TX_MD			(1 << 1)
859432a99aSjmcneill #define	 FLUSH_TX_FIFO		(1 << 0)
869432a99aSjmcneill #define	EMAC_TX_FLOW_CTL	0x1c
879432a99aSjmcneill #define	 PAUSE_TIME		(0xffff << 4)
889432a99aSjmcneill #define	 PAUSE_TIME_SHIFT	4
899432a99aSjmcneill #define	 TX_FLOW_CTL_EN		(1 << 0)
909432a99aSjmcneill #define	EMAC_TX_DMA_LIST	0x20
919432a99aSjmcneill #define	EMAC_RX_CTL_0		0x24
929432a99aSjmcneill #define	 RX_EN			(1 << 31)
93d1b80ee1Sjmcneill #define	 RX_FRM_LEN_CTL		(1 << 30)
949432a99aSjmcneill #define	 JUMBO_FRM_EN		(1 << 29)
959432a99aSjmcneill #define	 STRIP_FCS		(1 << 28)
969432a99aSjmcneill #define	 CHECK_CRC		(1 << 27)
97d1b80ee1Sjmcneill #define	 RX_PAUSE_FRM_MD	(1 << 17)
989432a99aSjmcneill #define	 RX_FLOW_CTL_EN		(1 << 16)
999432a99aSjmcneill #define	EMAC_RX_CTL_1		0x28
1009432a99aSjmcneill #define	 RX_DMA_START		(1 << 31)
1019432a99aSjmcneill #define	 RX_DMA_EN		(1 << 30)
102d1b80ee1Sjmcneill #define	 RX_FIFO_FLOW_CTL	(1 << 24)
103d1b80ee1Sjmcneill #define	 RX_FLOW_CTL_TH_DEACT	(0x3 << 22)
104d1b80ee1Sjmcneill #define	 RX_FLOW_CTL_TH_ACT	(0x3 << 20)
105d1b80ee1Sjmcneill #define	 RX_TH			(0x3 << 4)
106d1b80ee1Sjmcneill #define	 RX_ERR_FRM		(1 << 3)
107d1b80ee1Sjmcneill #define	 RX_RUNT_FRM		(1 << 2)
1089432a99aSjmcneill #define	 RX_MD			(1 << 1)
109d1b80ee1Sjmcneill #define	 FLUSH_RX_FRM		(1 << 0)
1109432a99aSjmcneill #define	EMAC_RX_DMA_LIST	0x34
1119432a99aSjmcneill #define	EMAC_RX_FRM_FLT		0x38
1129432a99aSjmcneill #define	 DIS_ADDR_FILTER	(1 << 31)
1139432a99aSjmcneill #define	 DIS_BROADCAST		(1 << 17)
1149432a99aSjmcneill #define	 RX_ALL_MULTICAST	(1 << 16)
1159432a99aSjmcneill #define	 CTL_FRM_FILTER		(0x3 << 12)
1169432a99aSjmcneill #define	 CTL_FRM_FILTER_SHIFT	12
1179432a99aSjmcneill #define	 HASH_MULTICAST		(1 << 9)
1189432a99aSjmcneill #define	 HASH_UNICAST		(1 << 8)
1199432a99aSjmcneill #define	 SA_FILTER_EN		(1 << 6)
1209432a99aSjmcneill #define	 SA_INV_FILTER		(1 << 5)
1219432a99aSjmcneill #define	 DA_INV_FILTER		(1 << 4)
1229432a99aSjmcneill #define	 FLT_MD			(1 << 1)
1239432a99aSjmcneill #define	 RX_ALL			(1 << 0)
1249432a99aSjmcneill #define	EMAC_RX_HASH_0		0x40
1259432a99aSjmcneill #define	EMAC_RX_HASH_1		0x44
1269432a99aSjmcneill #define	EMAC_MII_CMD		0x48
1279432a99aSjmcneill #define	 MDC_DIV_RATIO_M	(0x7 << 20)
1289432a99aSjmcneill #define	 MDC_DIV_RATIO_M_16	0
1299432a99aSjmcneill #define	 MDC_DIV_RATIO_M_32	1
1309432a99aSjmcneill #define	 MDC_DIV_RATIO_M_64	2
1319432a99aSjmcneill #define	 MDC_DIV_RATIO_M_128	3
1329432a99aSjmcneill #define	 MDC_DIV_RATIO_M_SHIFT	20
1339432a99aSjmcneill #define	 PHY_ADDR		(0x1f << 12)
1349432a99aSjmcneill #define	 PHY_ADDR_SHIFT		12
1359432a99aSjmcneill #define	 PHY_REG_ADDR		(0x1f << 4)
1369432a99aSjmcneill #define	 PHY_REG_ADDR_SHIFT	4
1379432a99aSjmcneill #define	 MII_WR			(1 << 1)
1389432a99aSjmcneill #define	 MII_BUSY		(1 << 0)
1399432a99aSjmcneill #define	EMAC_MII_DATA		0x4c
1409432a99aSjmcneill #define	EMAC_ADDR_HIGH(n)	(0x50 + (n) * 8)
1419432a99aSjmcneill #define	EMAC_ADDR_LOW(n)	(0x54 + (n) * 8)
1421a7bf6a9Sjmcneill #define	EMAC_TX_DMA_STA		0xb0
1431a7bf6a9Sjmcneill #define	EMAC_TX_DMA_CUR_DESC	0xb4
1441a7bf6a9Sjmcneill #define	EMAC_TX_DMA_CUR_BUF	0xb8
1459432a99aSjmcneill #define	EMAC_RX_DMA_STA		0xc0
1469432a99aSjmcneill #define	EMAC_RX_DMA_CUR_DESC	0xc4
1479432a99aSjmcneill #define	EMAC_RX_DMA_CUR_BUF	0xc8
1489432a99aSjmcneill #define	EMAC_RGMII_STA		0xd0
1499432a99aSjmcneill 
1509432a99aSjmcneill struct sunxi_emac_desc {
1519432a99aSjmcneill 	uint32_t	status;
1529432a99aSjmcneill /* Transmit */
1539432a99aSjmcneill #define	TX_DESC_CTL		(1 << 31)
1549432a99aSjmcneill #define	TX_HEADER_ERR		(1 << 16)
1559432a99aSjmcneill #define	TX_LENGTH_ERR		(1 << 14)
1569432a99aSjmcneill #define	TX_PAYLOAD_ERR		(1 << 12)
1579432a99aSjmcneill #define	TX_CRS_ERR		(1 << 10)
1589432a99aSjmcneill #define	TX_COL_ERR_0		(1 << 9)
1599432a99aSjmcneill #define	TX_COL_ERR_1		(1 << 8)
1609432a99aSjmcneill #define	TX_COL_CNT		(0xf << 3)
1619432a99aSjmcneill #define	TX_COL_CNT_SHIFT	3
1629432a99aSjmcneill #define	TX_DEFER_ERR		(1 << 2)
1639432a99aSjmcneill #define	TX_UNDERFLOW_ERR	(1 << 1)
1649432a99aSjmcneill #define	TX_DEFER		(1 << 0)
1659432a99aSjmcneill /* Receive */
1669432a99aSjmcneill #define	RX_DESC_CTL		(1 << 31)
1679432a99aSjmcneill #define	RX_DAF_FAIL		(1 << 30)
1689432a99aSjmcneill #define	RX_FRM_LEN		(0x3fff << 16)
1699432a99aSjmcneill #define	RX_FRM_LEN_SHIFT	16
1709432a99aSjmcneill #define	RX_NO_ENOUGH_BUF_ERR	(1 << 14)
1719432a99aSjmcneill #define	RX_SAF_FAIL		(1 << 13)
1729432a99aSjmcneill #define	RX_OVERFLOW_ERR		(1 << 11)
1739432a99aSjmcneill #define	RX_FIR_DESC		(1 << 9)
1749432a99aSjmcneill #define	RX_LAST_DESC		(1 << 8)
1759432a99aSjmcneill #define	RX_HEADER_ERR		(1 << 7)
1769432a99aSjmcneill #define	RX_COL_ERR		(1 << 6)
1779432a99aSjmcneill #define	RX_FRM_TYPE		(1 << 5)
1789432a99aSjmcneill #define	RX_LENGTH_ERR		(1 << 4)
1799432a99aSjmcneill #define	RX_PHY_ERR		(1 << 3)
1809432a99aSjmcneill #define	RX_CRC_ERR		(1 << 1)
1819432a99aSjmcneill #define	RX_PAYLOAD_ERR		(1 << 0)
1829432a99aSjmcneill 
1839432a99aSjmcneill 	uint32_t	size;
1849432a99aSjmcneill /* Transmit */
1859432a99aSjmcneill #define	TX_INT_CTL		(1 << 31)
1869432a99aSjmcneill #define	TX_LAST_DESC		(1 << 30)
1879432a99aSjmcneill #define	TX_FIR_DESC		(1 << 29)
1889432a99aSjmcneill #define	TX_CHECKSUM_CTL		(0x3 << 27)
1899432a99aSjmcneill #define	TX_CHECKSUM_CTL_IP	1
1909432a99aSjmcneill #define	TX_CHECKSUM_CTL_NO_PSE	2
1919432a99aSjmcneill #define	TX_CHECKSUM_CTL_FULL	3
1929432a99aSjmcneill #define	TX_CHECKSUM_CTL_SHIFT	27
1939432a99aSjmcneill #define	TX_CRC_CTL		(1 << 26)
194d1b80ee1Sjmcneill #define	TX_CHAIN_DESC		(1 << 24)
195d1b80ee1Sjmcneill #define	TX_BUF_SIZE		(0x7ff << 0)
1969432a99aSjmcneill #define	TX_BUF_SIZE_SHIFT	0
1979432a99aSjmcneill /* Receive */
1989432a99aSjmcneill #define	RX_INT_CTL		(1 << 31)
199d1b80ee1Sjmcneill #define	RX_CHAIN_DESC		(1 << 24)
200d1b80ee1Sjmcneill #define	RX_BUF_SIZE		(0x7ff << 0)
2019432a99aSjmcneill #define	RX_BUF_SIZE_SHIFT	0
2029432a99aSjmcneill 
2039432a99aSjmcneill 	uint32_t	addr;
2049432a99aSjmcneill 
2059432a99aSjmcneill 	uint32_t	next;
206*4d6fdc91Sjmcneill } __packed __aligned(64);
2079432a99aSjmcneill 
208*4d6fdc91Sjmcneill __CTASSERT(sizeof(struct sunxi_emac_desc) == 64);
2099432a99aSjmcneill 
2109432a99aSjmcneill #endif /* !__SUNXI_EMAC_H__ */
211