4 #include <linux/types.h>
5 #include <linux/skbuff.h>
8 #include <linux/bitops.h>
10 #define RX_DESC_COUNT 256
11 #define TX_DESC_COUNT 256
13 #define NB8800_DESC_LOW 4
15 #define RX_BUF_SIZE 1552
17 #define RX_COPYBREAK 256
18 #define RX_COPYHDR 128
20 #define MAX_MDC_CLOCK 2500000
22 /* Stargate Solutions SSN8800 core registers */
23 #define NB8800_TX_CTL1 0x000
25 #define TX_APPEND_FCS BIT(4)
26 #define TX_PAD_EN BIT(3)
27 #define TX_RETRY_EN BIT(2)
30 #define NB8800_TX_CTL2 0x001
32 #define NB8800_RX_CTL 0x004
33 #define RX_BC_DISABLE BIT(7)
34 #define RX_RUNT BIT(6)
35 #define RX_AF_EN BIT(5)
36 #define RX_PAUSE_EN BIT(3)
37 #define RX_SEND_CRC BIT(2)
38 #define RX_PAD_STRIP BIT(1)
41 #define NB8800_RANDOM_SEED 0x008
42 #define NB8800_TX_SDP 0x14
43 #define NB8800_TX_TPDP1 0x18
44 #define NB8800_TX_TPDP2 0x19
45 #define NB8800_SLOT_TIME 0x1c
47 #define NB8800_MDIO_CMD 0x020
48 #define MDIO_CMD_GO BIT(31)
49 #define MDIO_CMD_WR BIT(26)
50 #define MDIO_CMD_ADDR(x) ((x) << 21)
51 #define MDIO_CMD_REG(x) ((x) << 16)
52 #define MDIO_CMD_DATA(x) ((x) << 0)
54 #define NB8800_MDIO_STS 0x024
55 #define MDIO_STS_ERR BIT(31)
57 #define NB8800_MC_ADDR(i) (0x028 + (i))
58 #define NB8800_MC_INIT 0x02e
59 #define NB8800_UC_ADDR(i) (0x03c + (i))
61 #define NB8800_MAC_MODE 0x044
62 #define RGMII_MODE BIT(7)
63 #define HALF_DUPLEX BIT(4)
64 #define BURST_EN BIT(3)
65 #define LOOPBACK_EN BIT(2)
66 #define GMAC_MODE BIT(0)
68 #define NB8800_IC_THRESHOLD 0x050
69 #define NB8800_PE_THRESHOLD 0x051
70 #define NB8800_PF_THRESHOLD 0x052
71 #define NB8800_TX_BUFSIZE 0x054
72 #define NB8800_FIFO_CTL 0x056
73 #define NB8800_PQ1 0x060
74 #define NB8800_PQ2 0x061
75 #define NB8800_SRC_ADDR(i) (0x06a + (i))
76 #define NB8800_STAT_DATA 0x078
77 #define NB8800_STAT_INDEX 0x07c
78 #define NB8800_STAT_CLEAR 0x07d
80 #define NB8800_SLEEP_MODE 0x07e
81 #define SLEEP_MODE BIT(0)
83 #define NB8800_WAKEUP 0x07f
86 /* Aurora NB8800 host interface registers */
87 #define NB8800_TXC_CR 0x100
88 #define TCR_LK BIT(12)
89 #define TCR_DS BIT(11)
90 #define TCR_BTS(x) (((x) & 0x7) << 8)
91 #define TCR_DIE BIT(7)
92 #define TCR_TFI(x) (((x) & 0x7) << 4)
98 #define NB8800_TXC_SR 0x104
100 #define TSR_DI BIT(2)
101 #define TSR_TO BIT(1)
102 #define TSR_TI BIT(0)
104 #define NB8800_TX_SAR 0x108
105 #define NB8800_TX_DESC_ADDR 0x10c
107 #define NB8800_TX_REPORT_ADDR 0x110
108 #define TX_BYTES_TRANSFERRED(x) (((x) >> 16) & 0xffff)
109 #define TX_FIRST_DEFERRAL BIT(7)
110 #define TX_EARLY_COLLISIONS(x) (((x) >> 3) & 0xf)
111 #define TX_LATE_COLLISION BIT(2)
112 #define TX_PACKET_DROPPED BIT(1)
113 #define TX_FIFO_UNDERRUN BIT(0)
114 #define IS_TX_ERROR(r) ((r) & 0x07)
116 #define NB8800_TX_FIFO_SR 0x114
117 #define NB8800_TX_ITR 0x118
119 #define NB8800_RXC_CR 0x200
120 #define RCR_FL BIT(13)
121 #define RCR_LK BIT(12)
122 #define RCR_DS BIT(11)
123 #define RCR_BTS(x) (((x) & 7) << 8)
124 #define RCR_DIE BIT(7)
125 #define RCR_RFI(x) (((x) & 7) << 4)
126 #define RCR_LE BIT(3)
127 #define RCR_RS BIT(2)
128 #define RCR_DM BIT(1)
129 #define RCR_EN BIT(0)
131 #define NB8800_RXC_SR 0x204
132 #define RSR_DE BIT(3)
133 #define RSR_DI BIT(2)
134 #define RSR_RO BIT(1)
135 #define RSR_RI BIT(0)
137 #define NB8800_RX_SAR 0x208
138 #define NB8800_RX_DESC_ADDR 0x20c
140 #define NB8800_RX_REPORT_ADDR 0x210
141 #define RX_BYTES_TRANSFERRED(x) (((x) >> 16) & 0xFFFF)
142 #define RX_MULTICAST_PKT BIT(9)
143 #define RX_BROADCAST_PKT BIT(8)
144 #define RX_LENGTH_ERR BIT(7)
145 #define RX_FCS_ERR BIT(6)
146 #define RX_RUNT_PKT BIT(5)
147 #define RX_FIFO_OVERRUN BIT(4)
148 #define RX_LATE_COLLISION BIT(3)
149 #define RX_ALIGNMENT_ERROR BIT(2)
150 #define RX_ERROR_MASK 0xfc
151 #define IS_RX_ERROR(r) ((r) & RX_ERROR_MASK)
153 #define NB8800_RX_FIFO_SR 0x214
154 #define NB8800_RX_ITR 0x218
156 /* Sigma Designs SMP86xx additional registers */
157 #define NB8800_TANGOX_PAD_MODE 0x400
158 #define PAD_MODE_MASK 0x7
159 #define PAD_MODE_MII 0x0
160 #define PAD_MODE_RGMII 0x1
161 #define PAD_MODE_GTX_CLK_INV BIT(3)
162 #define PAD_MODE_GTX_CLK_DELAY BIT(4)
164 #define NB8800_TANGOX_MDIO_CLKDIV 0x420
165 #define NB8800_TANGOX_RESET 0x424
167 /* Hardware DMA descriptor */
168 struct nb8800_dma_desc
{
169 u32 s_addr
; /* start address */
170 u32 n_addr
; /* next descriptor address */
171 u32 r_addr
; /* report address */
175 #define DESC_ID BIT(23)
176 #define DESC_EOC BIT(22)
177 #define DESC_EOF BIT(21)
178 #define DESC_LK BIT(20)
179 #define DESC_DS BIT(19)
180 #define DESC_BTS(x) (((x) & 0x7) << 16)
182 /* DMA descriptor and associated data for rx.
183 * Allocated from coherent memory.
185 struct nb8800_rx_desc
{
187 struct nb8800_dma_desc desc
;
189 /* Status report filled in by hardware */
193 /* Address of buffer on rx ring */
194 struct nb8800_rx_buf
{
196 unsigned long offset
;
199 /* DMA descriptors and associated data for tx.
200 * Allocated from coherent memory.
202 struct nb8800_tx_desc
{
203 /* DMA descriptor. The second descriptor is used if packet
206 struct nb8800_dma_desc desc
[2];
208 /* Status report filled in by hardware */
211 /* Bounce buffer for initial unaligned part of packet */
212 u8 buf
[8] __aligned(8);
215 /* Packet in tx queue */
216 struct nb8800_tx_buf
{
217 /* Currently queued skb */
220 /* DMA address of the first descriptor */
223 /* DMA address of packet data */
226 /* Length of DMA mapping, less than skb->len if alignment
229 unsigned int dma_len
;
231 /* Number of packets in chain starting here */
232 unsigned int chain_len
;
234 /* Packet chain ready to be submitted to hardware */
239 struct napi_struct napi
;
243 /* RX DMA descriptors */
244 struct nb8800_rx_desc
*rx_descs
;
246 /* RX buffers referenced by DMA descriptors */
247 struct nb8800_rx_buf
*rx_bufs
;
249 /* Current end of chain */
252 /* Value for rx interrupt time register in NAPI interrupt mode */
255 /* Value for rx interrupt time register in NAPI poll mode */
258 /* Value for config field of rx DMA descriptors */
261 /* TX DMA descriptors */
262 struct nb8800_tx_desc
*tx_descs
;
264 /* TX packet queue */
265 struct nb8800_tx_buf
*tx_bufs
;
267 /* Number of free tx queue entries */
270 /* First free tx queue entry */
273 /* Next buffer to transmit */
276 /* Start of current packet chain */
277 struct nb8800_tx_buf
*tx_chain
;
279 /* Next buffer to reclaim */
282 /* Lock for DMA activation */
285 struct mii_bus
*mii_bus
;
286 struct device_node
*phy_node
;
288 /* PHY connection type from DT */
291 /* Current link status */
301 /* DMA base address of rx descriptors, see rx_descs above */
302 dma_addr_t rx_desc_dma
;
304 /* DMA base address of tx descriptors, see tx_descs above */
305 dma_addr_t tx_desc_dma
;
311 int (*init
)(struct net_device
*dev
);
312 int (*reset
)(struct net_device
*dev
);
315 #endif /* _NB8800_H_ */