1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef __TSEC_H
14#define __TSEC_H
15
16#include <net.h>
17#include <config.h>
18#include <phy.h>
19
20#ifndef CONFIG_DM_ETH
21
22#ifdef CONFIG_ARCH_LS1021A
23#define TSEC_SIZE 0x40000
24#define TSEC_MDIO_OFFSET 0x40000
25#else
26#define TSEC_SIZE 0x01000
27#define TSEC_MDIO_OFFSET 0x01000
28#endif
29
30#define CONFIG_SYS_MDIO_BASE_ADDR (MDIO_BASE_ADDR + 0x520)
31
32#define TSEC_GET_REGS(num, offset) \
33 (struct tsec __iomem *)\
34 (TSEC_BASE_ADDR + (((num) - 1) * (offset)))
35
36#define TSEC_GET_REGS_BASE(num) \
37 TSEC_GET_REGS((num), TSEC_SIZE)
38
39#define TSEC_GET_MDIO_REGS(num, offset) \
40 (struct tsec_mii_mng __iomem *)\
41 (CONFIG_SYS_MDIO_BASE_ADDR + ((num) - 1) * (offset))
42
43#define TSEC_GET_MDIO_REGS_BASE(num) \
44 TSEC_GET_MDIO_REGS((num), TSEC_MDIO_OFFSET)
45
46#define DEFAULT_MII_NAME "FSL_MDIO"
47
48#define STD_TSEC_INFO(num) \
49{ \
50 .regs = TSEC_GET_REGS_BASE(num), \
51 .miiregs_sgmii = TSEC_GET_MDIO_REGS_BASE(num), \
52 .devname = CONFIG_TSEC##num##_NAME, \
53 .phyaddr = TSEC##num##_PHY_ADDR, \
54 .flags = TSEC##num##_FLAGS, \
55 .mii_devname = DEFAULT_MII_NAME \
56}
57
58#define SET_STD_TSEC_INFO(x, num) \
59{ \
60 x.regs = TSEC_GET_REGS_BASE(num); \
61 x.miiregs_sgmii = TSEC_GET_MDIO_REGS_BASE(num); \
62 x.devname = CONFIG_TSEC##num##_NAME; \
63 x.phyaddr = TSEC##num##_PHY_ADDR; \
64 x.flags = TSEC##num##_FLAGS;\
65 x.mii_devname = DEFAULT_MII_NAME;\
66}
67
68#endif
69
70#define MAC_ADDR_LEN 6
71
72
73#define TSEC_TIMEOUT 1000
74#define TOUT_LOOP 1000000
75
76
77#define TBI_CR 0x00
78#define TBI_SR 0x01
79#define TBI_ANA 0x04
80#define TBI_ANLPBPA 0x05
81#define TBI_ANEX 0x06
82#define TBI_TBICON 0x11
83
84
85#define TBICON_CLK_SELECT 0x0020
86#define TBIANA_ASYMMETRIC_PAUSE 0x0100
87#define TBIANA_SYMMETRIC_PAUSE 0x0080
88#define TBIANA_HALF_DUPLEX 0x0040
89#define TBIANA_FULL_DUPLEX 0x0020
90#define TBICR_PHY_RESET 0x8000
91#define TBICR_ANEG_ENABLE 0x1000
92#define TBICR_RESTART_ANEG 0x0200
93#define TBICR_FULL_DUPLEX 0x0100
94#define TBICR_SPEED1_SET 0x0040
95
96
97#define MACCFG1_SOFT_RESET 0x80000000
98#define MACCFG1_RESET_RX_MC 0x00080000
99#define MACCFG1_RESET_TX_MC 0x00040000
100#define MACCFG1_RESET_RX_FUN 0x00020000
101#define MACCFG1_RESET_TX_FUN 0x00010000
102#define MACCFG1_LOOPBACK 0x00000100
103#define MACCFG1_RX_FLOW 0x00000020
104#define MACCFG1_TX_FLOW 0x00000010
105#define MACCFG1_SYNCD_RX_EN 0x00000008
106#define MACCFG1_RX_EN 0x00000004
107#define MACCFG1_SYNCD_TX_EN 0x00000002
108#define MACCFG1_TX_EN 0x00000001
109
110#define MACCFG2_INIT_SETTINGS 0x00007205
111#define MACCFG2_FULL_DUPLEX 0x00000001
112#define MACCFG2_IF 0x00000300
113#define MACCFG2_GMII 0x00000200
114#define MACCFG2_MII 0x00000100
115
116#define ECNTRL_INIT_SETTINGS 0x00001000
117#define ECNTRL_TBI_MODE 0x00000020
118#define ECNTRL_REDUCED_MODE 0x00000010
119#define ECNTRL_R100 0x00000008
120#define ECNTRL_REDUCED_MII_MODE 0x00000004
121#define ECNTRL_SGMII_MODE 0x00000002
122
123#ifndef CONFIG_SYS_TBIPA_VALUE
124# define CONFIG_SYS_TBIPA_VALUE 0x1f
125#endif
126
127#define MRBLR_INIT_SETTINGS PKTSIZE_ALIGN
128
129#define MINFLR_INIT_SETTINGS 0x00000040
130
131#define DMACTRL_INIT_SETTINGS 0x000000c3
132#define DMACTRL_GRS 0x00000010
133#define DMACTRL_GTS 0x00000008
134#define DMACTRL_LE 0x00008000
135
136#define TSTAT_CLEAR_THALT 0x80000000
137#define RSTAT_CLEAR_RHALT 0x00800000
138
139#define IEVENT_INIT_CLEAR 0xffffffff
140#define IEVENT_BABR 0x80000000
141#define IEVENT_RXC 0x40000000
142#define IEVENT_BSY 0x20000000
143#define IEVENT_EBERR 0x10000000
144#define IEVENT_MSRO 0x04000000
145#define IEVENT_GTSC 0x02000000
146#define IEVENT_BABT 0x01000000
147#define IEVENT_TXC 0x00800000
148#define IEVENT_TXE 0x00400000
149#define IEVENT_TXB 0x00200000
150#define IEVENT_TXF 0x00100000
151#define IEVENT_IE 0x00080000
152#define IEVENT_LC 0x00040000
153#define IEVENT_CRL 0x00020000
154#define IEVENT_XFUN 0x00010000
155#define IEVENT_RXB0 0x00008000
156#define IEVENT_GRSC 0x00000100
157#define IEVENT_RXF0 0x00000080
158
159#define IMASK_INIT_CLEAR 0x00000000
160#define IMASK_TXEEN 0x00400000
161#define IMASK_TXBEN 0x00200000
162#define IMASK_TXFEN 0x00100000
163#define IMASK_RXFEN0 0x00000080
164
165
166#define ATTR_INIT_SETTINGS 0x000000c0
167#define ATTRELI_INIT_SETTINGS 0x00000000
168
169
170#define TXBD_READY 0x8000
171#define TXBD_PADCRC 0x4000
172#define TXBD_WRAP 0x2000
173#define TXBD_INTERRUPT 0x1000
174#define TXBD_LAST 0x0800
175#define TXBD_CRC 0x0400
176#define TXBD_DEF 0x0200
177#define TXBD_HUGEFRAME 0x0080
178#define TXBD_LATECOLLISION 0x0080
179#define TXBD_RETRYLIMIT 0x0040
180#define TXBD_RETRYCOUNTMASK 0x003c
181#define TXBD_UNDERRUN 0x0002
182#define TXBD_STATS 0x03ff
183
184
185#define RXBD_EMPTY 0x8000
186#define RXBD_RO1 0x4000
187#define RXBD_WRAP 0x2000
188#define RXBD_INTERRUPT 0x1000
189#define RXBD_LAST 0x0800
190#define RXBD_FIRST 0x0400
191#define RXBD_MISS 0x0100
192#define RXBD_BROADCAST 0x0080
193#define RXBD_MULTICAST 0x0040
194#define RXBD_LARGE 0x0020
195#define RXBD_NONOCTET 0x0010
196#define RXBD_SHORT 0x0008
197#define RXBD_CRCERR 0x0004
198#define RXBD_OVERRUN 0x0002
199#define RXBD_TRUNCATED 0x0001
200#define RXBD_STATS 0x003f
201
202struct txbd8 {
203 uint16_t status;
204 uint16_t length;
205 uint32_t bufptr;
206};
207
208struct rxbd8 {
209 uint16_t status;
210 uint16_t length;
211 uint32_t bufptr;
212};
213
214struct tsec_rmon_mib {
215
216 u32 tr64;
217 u32 tr127;
218 u32 tr255;
219 u32 tr511;
220 u32 tr1k;
221 u32 trmax;
222 u32 trmgv;
223
224 u32 rbyt;
225 u32 rpkt;
226 u32 rfcs;
227 u32 rmca;
228 u32 rbca;
229 u32 rxcf;
230 u32 rxpf;
231 u32 rxuo;
232 u32 raln;
233 u32 rflr;
234 u32 rcde;
235 u32 rcse;
236 u32 rund;
237 u32 rovr;
238 u32 rfrg;
239 u32 rjbr;
240 u32 rdrp;
241
242 u32 tbyt;
243 u32 tpkt;
244 u32 tmca;
245 u32 tbca;
246 u32 txpf;
247 u32 tdfr;
248 u32 tedf;
249 u32 tscl;
250
251 u32 tmcl;
252 u32 tlcl;
253 u32 txcl;
254 u32 tncl;
255
256 u32 res2;
257
258 u32 tdrp;
259 u32 tjbr;
260 u32 tfcs;
261 u32 txcf;
262 u32 tovr;
263 u32 tund;
264 u32 tfrg;
265
266 u32 car1;
267 u32 car2;
268 u32 cam1;
269 u32 cam2;
270};
271
272struct tsec_hash_regs {
273 u32 iaddr0;
274 u32 iaddr1;
275 u32 iaddr2;
276 u32 iaddr3;
277 u32 iaddr4;
278 u32 iaddr5;
279 u32 iaddr6;
280 u32 iaddr7;
281 u32 res1[24];
282 u32 gaddr0;
283 u32 gaddr1;
284 u32 gaddr2;
285 u32 gaddr3;
286 u32 gaddr4;
287 u32 gaddr5;
288 u32 gaddr6;
289 u32 gaddr7;
290 u32 res2[24];
291};
292
293struct tsec {
294
295 u32 res000[4];
296
297 u32 ievent;
298 u32 imask;
299 u32 edis;
300 u32 res01c;
301 u32 ecntrl;
302 u32 minflr;
303 u32 ptv;
304 u32 dmactrl;
305 u32 tbipa;
306
307 u32 res034[3];
308 u32 res040[48];
309
310
311 u32 tctrl;
312 u32 tstat;
313 u32 res108;
314 u32 tbdlen;
315 u32 res110[5];
316 u32 ctbptr;
317 u32 res128[23];
318 u32 tbptr;
319 u32 res188[30];
320
321 u32 res200;
322 u32 tbase;
323 u32 res208[42];
324 u32 ostbd;
325 u32 ostbdp;
326 u32 res2b8[18];
327
328
329 u32 rctrl;
330 u32 rstat;
331 u32 res308;
332 u32 rbdlen;
333 u32 res310[4];
334 u32 res320;
335 u32 crbptr;
336 u32 res328[6];
337 u32 mrblr;
338 u32 res344[16];
339 u32 rbptr;
340 u32 res388[30];
341
342 u32 res400;
343 u32 rbase;
344 u32 res408[62];
345
346
347 u32 maccfg1;
348 u32 maccfg2;
349 u32 ipgifg;
350 u32 hafdup;
351 u32 maxfrm;
352 u32 res514;
353 u32 res518;
354
355 u32 res51c;
356
357 u32 resmdio[6];
358
359 u32 res538;
360
361 u32 ifstat;
362 u32 macstnaddr1;
363 u32 macstnaddr2;
364 u32 res548[46];
365
366
367 u32 res600[32];
368
369
370 struct tsec_rmon_mib rmon;
371 u32 res740[48];
372
373
374 struct tsec_hash_regs hash;
375
376 u32 res900[128];
377
378
379 u32 resb00[62];
380 u32 attr;
381 u32 attreli;
382
383
384 u32 resc00[256];
385};
386
387#define TSEC_GIGABIT (1 << 0)
388
389
390#define TSEC_REDUCED (1 << 1)
391#define TSEC_SGMII (1 << 2)
392
393#define TX_BUF_CNT 2
394
395struct tsec_private {
396 struct txbd8 __iomem txbd[TX_BUF_CNT];
397 struct rxbd8 __iomem rxbd[PKTBUFSRX];
398 struct tsec __iomem *regs;
399 struct tsec_mii_mng __iomem *phyregs_sgmii;
400 struct phy_device *phydev;
401 phy_interface_t interface;
402 struct mii_dev *bus;
403 uint phyaddr;
404 uint tbiaddr;
405 char mii_devname[16];
406 u32 flags;
407 uint rx_idx;
408 uint tx_idx;
409#ifndef CONFIG_DM_ETH
410 struct eth_device *dev;
411#else
412 struct udevice *dev;
413#endif
414};
415
416struct tsec_info_struct {
417 struct tsec __iomem *regs;
418 struct tsec_mii_mng __iomem *miiregs_sgmii;
419 char *devname;
420 char *mii_devname;
421 phy_interface_t interface;
422 unsigned int phyaddr;
423 u32 flags;
424};
425
426#ifndef CONFIG_DM_ETH
427int tsec_standard_init(bd_t *bis);
428int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsec_info, int num);
429#endif
430
431#endif
432