xref: /rk3399_rockchip-uboot/drivers/net/ftmac110.h (revision 0628cb26591a8f7990ee9b8c886dcf6a4fa7a548)
1c4775476SKuo-Jung Su /*
2c4775476SKuo-Jung Su  * Faraday 10/100Mbps Ethernet Controller
3c4775476SKuo-Jung Su  *
4102a8cd3SKuo-Jung Su  * (C) Copyright 2013 Faraday Technology
5c4775476SKuo-Jung Su  * Dante Su <dantesu@faraday-tech.com>
6c4775476SKuo-Jung Su  *
71a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
8c4775476SKuo-Jung Su  */
9c4775476SKuo-Jung Su 
10c4775476SKuo-Jung Su #ifndef _FTMAC110_H
11c4775476SKuo-Jung Su #define _FTMAC110_H
12c4775476SKuo-Jung Su 
13c4775476SKuo-Jung Su struct ftmac110_regs {
14c4775476SKuo-Jung Su 	uint32_t isr;    /* 0x00: Interrups Status Register */
15c4775476SKuo-Jung Su 	uint32_t imr;    /* 0x04: Interrupt Mask Register */
16c4775476SKuo-Jung Su 	uint32_t mac[2]; /* 0x08: MAC Address */
17c4775476SKuo-Jung Su 	uint32_t mht[2]; /* 0x10: Multicast Hash Table Register */
18c4775476SKuo-Jung Su 	uint32_t txpd;   /* 0x18: Tx Poll Demand Register */
19c4775476SKuo-Jung Su 	uint32_t rxpd;   /* 0x1c: Rx Poll Demand Register */
20c4775476SKuo-Jung Su 	uint32_t txba;   /* 0x20: Tx Ring Base Address Register */
21c4775476SKuo-Jung Su 	uint32_t rxba;   /* 0x24: Rx Ring Base Address Register */
22c4775476SKuo-Jung Su 	uint32_t itc;    /* 0x28: Interrupt Timer Control Register */
23c4775476SKuo-Jung Su 	uint32_t aptc;   /* 0x2C: Automatic Polling Timer Control Register */
24c4775476SKuo-Jung Su 	uint32_t dblac;  /* 0x30: DMA Burst Length&Arbitration Control */
25c4775476SKuo-Jung Su 	uint32_t revr;   /* 0x34: Revision Register */
26c4775476SKuo-Jung Su 	uint32_t fear;   /* 0x38: Feature Register */
27c4775476SKuo-Jung Su 	uint32_t rsvd[19];
28c4775476SKuo-Jung Su 	uint32_t maccr;  /* 0x88: MAC Control Register */
29c4775476SKuo-Jung Su 	uint32_t macsr;  /* 0x8C: MAC Status Register */
30c4775476SKuo-Jung Su 	uint32_t phycr;  /* 0x90: PHY Control Register */
31c4775476SKuo-Jung Su 	uint32_t phydr;  /* 0x94: PHY Data Register */
32c4775476SKuo-Jung Su 	uint32_t fcr;    /* 0x98: Flow Control Register */
33c4775476SKuo-Jung Su 	uint32_t bpr;    /* 0x9C: Back Pressure Register */
34c4775476SKuo-Jung Su };
35c4775476SKuo-Jung Su 
36c4775476SKuo-Jung Su /*
37c4775476SKuo-Jung Su  * Interrupt status/mask register(ISR/IMR) bits
38c4775476SKuo-Jung Su  */
39c4775476SKuo-Jung Su #define ISR_ALL          0x3ff
40c4775476SKuo-Jung Su #define ISR_PHYSTCHG     (1 << 9) /* phy status change */
41c4775476SKuo-Jung Su #define ISR_AHBERR       (1 << 8) /* bus error */
42c4775476SKuo-Jung Su #define ISR_RXLOST       (1 << 7) /* rx lost */
43c4775476SKuo-Jung Su #define ISR_RXFIFO       (1 << 6) /* rx to fifo */
44c4775476SKuo-Jung Su #define ISR_TXLOST       (1 << 5) /* tx lost */
45c4775476SKuo-Jung Su #define ISR_TXOK         (1 << 4) /* tx to ethernet */
46c4775476SKuo-Jung Su #define ISR_NOTXBUF      (1 << 3) /* out of tx buffer */
47c4775476SKuo-Jung Su #define ISR_TXFIFO       (1 << 2) /* tx to fifo */
48c4775476SKuo-Jung Su #define ISR_NORXBUF      (1 << 1) /* out of rx buffer */
49c4775476SKuo-Jung Su #define ISR_RXOK         (1 << 0) /* rx to buffer */
50c4775476SKuo-Jung Su 
51c4775476SKuo-Jung Su /*
52c4775476SKuo-Jung Su  * MACCR control bits
53c4775476SKuo-Jung Su  */
54c4775476SKuo-Jung Su #define MACCR_100M       (1 << 18) /* 100Mbps mode */
55c4775476SKuo-Jung Su #define MACCR_RXBCST     (1 << 17) /* rx broadcast packet */
56c4775476SKuo-Jung Su #define MACCR_RXMCST     (1 << 16) /* rx multicast packet */
57c4775476SKuo-Jung Su #define MACCR_FD         (1 << 15) /* full duplex */
58c4775476SKuo-Jung Su #define MACCR_CRCAPD     (1 << 14) /* tx crc append */
59c4775476SKuo-Jung Su #define MACCR_RXALL      (1 << 12) /* rx all packets */
60c4775476SKuo-Jung Su #define MACCR_RXFTL      (1 << 11) /* rx packet even it's > 1518 byte */
61c4775476SKuo-Jung Su #define MACCR_RXRUNT     (1 << 10) /* rx packet even it's < 64 byte */
62c4775476SKuo-Jung Su #define MACCR_RXMCSTHT   (1 << 9)  /* rx multicast hash table */
63c4775476SKuo-Jung Su #define MACCR_RXEN       (1 << 8)  /* rx enable */
64c4775476SKuo-Jung Su #define MACCR_RXINHDTX   (1 << 6)  /* rx in half duplex tx */
65c4775476SKuo-Jung Su #define MACCR_TXEN       (1 << 5)  /* tx enable */
66c4775476SKuo-Jung Su #define MACCR_CRCDIS     (1 << 4)  /* tx packet even it's crc error */
67c4775476SKuo-Jung Su #define MACCR_LOOPBACK   (1 << 3)  /* loop-back */
68c4775476SKuo-Jung Su #define MACCR_RESET      (1 << 2)  /* reset */
69c4775476SKuo-Jung Su #define MACCR_RXDMAEN    (1 << 1)  /* rx dma enable */
70c4775476SKuo-Jung Su #define MACCR_TXDMAEN    (1 << 0)  /* tx dma enable */
71c4775476SKuo-Jung Su 
72c4775476SKuo-Jung Su /*
73c4775476SKuo-Jung Su  * PHYCR control bits
74c4775476SKuo-Jung Su  */
75c4775476SKuo-Jung Su #define PHYCR_READ       (1 << 26)
76c4775476SKuo-Jung Su #define PHYCR_WRITE      (1 << 27)
77c4775476SKuo-Jung Su #define PHYCR_REG_SHIFT  21
78c4775476SKuo-Jung Su #define PHYCR_ADDR_SHIFT 16
79c4775476SKuo-Jung Su 
80c4775476SKuo-Jung Su /*
81c4775476SKuo-Jung Su  * ITC control bits
82c4775476SKuo-Jung Su  */
83c4775476SKuo-Jung Su 
84c4775476SKuo-Jung Su /* Tx Cycle Length */
85c4775476SKuo-Jung Su #define ITC_TX_CYCLONG   (1 << 15) /* 100Mbps=81.92us; 10Mbps=819.2us */
86c4775476SKuo-Jung Su #define ITC_TX_CYCNORM   (0 << 15) /* 100Mbps=5.12us;  10Mbps=51.2us */
87c4775476SKuo-Jung Su /* Tx Threshold: Aggregate n interrupts as 1 interrupt */
88c4775476SKuo-Jung Su #define ITC_TX_THR(n)    (((n) & 0x7) << 12)
89c4775476SKuo-Jung Su /* Tx Interrupt Timeout = n * Tx Cycle */
90c4775476SKuo-Jung Su #define ITC_TX_ITMO(n)   (((n) & 0xf) << 8)
91c4775476SKuo-Jung Su /* Rx Cycle Length */
92c4775476SKuo-Jung Su #define ITC_RX_CYCLONG   (1 << 7)  /* 100Mbps=81.92us; 10Mbps=819.2us */
93c4775476SKuo-Jung Su #define ITC_RX_CYCNORM   (0 << 7)  /* 100Mbps=5.12us;  10Mbps=51.2us */
94c4775476SKuo-Jung Su /* Rx Threshold: Aggregate n interrupts as 1 interrupt */
95c4775476SKuo-Jung Su #define ITC_RX_THR(n)    (((n) & 0x7) << 4)
96c4775476SKuo-Jung Su /* Rx Interrupt Timeout = n * Rx Cycle */
97c4775476SKuo-Jung Su #define ITC_RX_ITMO(n)   (((n) & 0xf) << 0)
98c4775476SKuo-Jung Su 
99c4775476SKuo-Jung Su #define ITC_DEFAULT \
100c4775476SKuo-Jung Su 	(ITC_TX_THR(1) | ITC_TX_ITMO(0) | ITC_RX_THR(1) | ITC_RX_ITMO(0))
101c4775476SKuo-Jung Su 
102c4775476SKuo-Jung Su /*
103c4775476SKuo-Jung Su  * APTC contrl bits
104c4775476SKuo-Jung Su  */
105c4775476SKuo-Jung Su 
106c4775476SKuo-Jung Su /* Tx Cycle Length */
107c4775476SKuo-Jung Su #define APTC_TX_CYCLONG  (1 << 12) /* 100Mbps=81.92us; 10Mbps=819.2us */
108c4775476SKuo-Jung Su #define APTC_TX_CYCNORM  (0 << 12) /* 100Mbps=5.12us;  10Mbps=51.2us */
109c4775476SKuo-Jung Su /* Tx Poll Timeout = n * Tx Cycle, 0=No auto polling */
110c4775476SKuo-Jung Su #define APTC_TX_PTMO(n)  (((n) & 0xf) << 8)
111c4775476SKuo-Jung Su /* Rx Cycle Length */
112c4775476SKuo-Jung Su #define APTC_RX_CYCLONG  (1 << 4)  /* 100Mbps=81.92us; 10Mbps=819.2us */
113c4775476SKuo-Jung Su #define APTC_RX_CYCNORM  (0 << 4)  /* 100Mbps=5.12us;  10Mbps=51.2us */
114c4775476SKuo-Jung Su /* Rx Poll Timeout = n * Rx Cycle, 0=No auto polling */
115c4775476SKuo-Jung Su #define APTC_RX_PTMO(n)  (((n) & 0xf) << 0)
116c4775476SKuo-Jung Su 
117c4775476SKuo-Jung Su #define APTC_DEFAULT     (APTC_TX_PTMO(0) | APTC_RX_PTMO(1))
118c4775476SKuo-Jung Su 
119c4775476SKuo-Jung Su /*
120c4775476SKuo-Jung Su  * DBLAC contrl bits
121c4775476SKuo-Jung Su  */
122c4775476SKuo-Jung Su #define DBLAC_BURST_MAX_ANY  (0 << 14) /* un-limited */
123c4775476SKuo-Jung Su #define DBLAC_BURST_MAX_32X4 (2 << 14) /* max = 32 x 4 bytes */
124c4775476SKuo-Jung Su #define DBLAC_BURST_MAX_64X4 (3 << 14) /* max = 64 x 4 bytes */
125c4775476SKuo-Jung Su #define DBLAC_RXTHR_EN       (1 << 9)  /* enable rx threshold arbitration */
126c4775476SKuo-Jung Su #define DBLAC_RXTHR_HIGH(n)  (((n) & 0x7) << 6) /* upper bound = n/8 fifo */
127c4775476SKuo-Jung Su #define DBLAC_RXTHR_LOW(n)   (((n) & 0x7) << 3) /* lower bound = n/8 fifo */
128c4775476SKuo-Jung Su #define DBLAC_BURST_CAP16    (1 << 2)  /* support burst 16 */
129c4775476SKuo-Jung Su #define DBLAC_BURST_CAP8     (1 << 1)  /* support burst 8 */
130c4775476SKuo-Jung Su #define DBLAC_BURST_CAP4     (1 << 0)  /* support burst 4 */
131c4775476SKuo-Jung Su 
132c4775476SKuo-Jung Su #define DBLAC_DEFAULT \
133c4775476SKuo-Jung Su 	(DBLAC_RXTHR_EN | DBLAC_RXTHR_HIGH(6) | DBLAC_RXTHR_LOW(2))
134c4775476SKuo-Jung Su 
135c4775476SKuo-Jung Su /*
136c4775476SKuo-Jung Su  * descriptor structure
137c4775476SKuo-Jung Su  */
138*0628cb26SKuo-Jung Su struct ftmac110_desc {
139*0628cb26SKuo-Jung Su 	uint64_t ctrl;
140*0628cb26SKuo-Jung Su 	uint32_t pbuf;
141*0628cb26SKuo-Jung Su 	void    *vbuf;
142c4775476SKuo-Jung Su };
143c4775476SKuo-Jung Su 
144*0628cb26SKuo-Jung Su #define FTMAC110_RXD_END        ((uint64_t)1 << 63)
145*0628cb26SKuo-Jung Su #define FTMAC110_RXD_BUFSZ(x)   (((uint64_t)(x) & 0x7ff) << 32)
146c4775476SKuo-Jung Su 
147*0628cb26SKuo-Jung Su #define FTMAC110_RXD_OWNER      ((uint64_t)1 << 31) /* owner: 1=HW, 0=SW */
148*0628cb26SKuo-Jung Su #define FTMAC110_RXD_FRS        ((uint64_t)1 << 29) /* first pkt desc */
149*0628cb26SKuo-Jung Su #define FTMAC110_RXD_LRS        ((uint64_t)1 << 28) /* last pkt desc */
150*0628cb26SKuo-Jung Su #define FTMAC110_RXD_ODDNB      ((uint64_t)1 << 22) /* odd nibble */
151*0628cb26SKuo-Jung Su #define FTMAC110_RXD_RUNT       ((uint64_t)1 << 21) /* runt pkt */
152*0628cb26SKuo-Jung Su #define FTMAC110_RXD_FTL        ((uint64_t)1 << 20) /* frame too long */
153*0628cb26SKuo-Jung Su #define FTMAC110_RXD_CRC        ((uint64_t)1 << 19) /* pkt crc error */
154*0628cb26SKuo-Jung Su #define FTMAC110_RXD_ERR        ((uint64_t)1 << 18) /* bus error */
155*0628cb26SKuo-Jung Su #define FTMAC110_RXD_ERRMASK    ((uint64_t)0x1f << 18)
156*0628cb26SKuo-Jung Su #define FTMAC110_RXD_BCST       ((uint64_t)1 << 17) /* Bcst pkt */
157*0628cb26SKuo-Jung Su #define FTMAC110_RXD_MCST       ((uint64_t)1 << 16) /* Mcst pkt */
158*0628cb26SKuo-Jung Su #define FTMAC110_RXD_LEN(x)     ((uint64_t)((x) & 0x7ff))
159c4775476SKuo-Jung Su 
160*0628cb26SKuo-Jung Su #define FTMAC110_RXD_CLRMASK	\
161*0628cb26SKuo-Jung Su 	(FTMAC110_RXD_END | FTMAC110_RXD_BUFSZ(0x7ff))
162c4775476SKuo-Jung Su 
163*0628cb26SKuo-Jung Su #define FTMAC110_TXD_END    ((uint64_t)1 << 63) /* end of ring */
164*0628cb26SKuo-Jung Su #define FTMAC110_TXD_TXIC   ((uint64_t)1 << 62) /* tx done interrupt */
165*0628cb26SKuo-Jung Su #define FTMAC110_TXD_TX2FIC ((uint64_t)1 << 61) /* tx fifo interrupt */
166*0628cb26SKuo-Jung Su #define FTMAC110_TXD_FTS    ((uint64_t)1 << 60) /* first pkt desc */
167*0628cb26SKuo-Jung Su #define FTMAC110_TXD_LTS    ((uint64_t)1 << 59) /* last pkt desc */
168*0628cb26SKuo-Jung Su #define FTMAC110_TXD_LEN(x) ((uint64_t)((x) & 0x7ff) << 32)
169c4775476SKuo-Jung Su 
170*0628cb26SKuo-Jung Su #define FTMAC110_TXD_OWNER  ((uint64_t)1 << 31)	/* owner: 1=HW, 0=SW */
171*0628cb26SKuo-Jung Su #define FTMAC110_TXD_COL    ((uint64_t)3)		/* collision */
172*0628cb26SKuo-Jung Su 
173*0628cb26SKuo-Jung Su #define FTMAC110_TXD_CLRMASK    \
174*0628cb26SKuo-Jung Su 	(FTMAC110_TXD_END)
175c4775476SKuo-Jung Su 
176c4775476SKuo-Jung Su #endif  /* FTMAC110_H */
177