1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef __TSEC_H
18#define __TSEC_H
19
20#include <net.h>
21#include <config.h>
22
23#define TSEC_SIZE 0x01000
24#define TSEC_MDIO_OFFSET 0x01000
25
26#define STD_TSEC_INFO(num) \
27{ \
28 .regs = (tsec_t *)(TSEC_BASE_ADDR + ((num - 1) * TSEC_SIZE)), \
29 .miiregs = (tsec_mdio_t *)(MDIO_BASE_ADDR), \
30 .miiregs_sgmii = (tsec_mdio_t *)(MDIO_BASE_ADDR \
31 + (num - 1) * TSEC_MDIO_OFFSET), \
32 .devname = CONFIG_TSEC##num##_NAME, \
33 .phyaddr = TSEC##num##_PHY_ADDR, \
34 .flags = TSEC##num##_FLAGS \
35}
36
37#define SET_STD_TSEC_INFO(x, num) \
38{ \
39 x.regs = (tsec_t *)(TSEC_BASE_ADDR + ((num - 1) * TSEC_SIZE)); \
40 x.miiregs = (tsec_mdio_t *)(MDIO_BASE_ADDR); \
41 x.miiregs_sgmii = (tsec_mdio_t *)(MDIO_BASE_ADDR \
42 + (num - 1) * TSEC_MDIO_OFFSET); \
43 x.devname = CONFIG_TSEC##num##_NAME; \
44 x.phyaddr = TSEC##num##_PHY_ADDR; \
45 x.flags = TSEC##num##_FLAGS;\
46}
47
48#define MAC_ADDR_LEN 6
49
50
51#define TSEC_TIMEOUT 1000
52#define TOUT_LOOP 1000000
53
54#define PHY_AUTONEGOTIATE_TIMEOUT 5000
55
56
57#define TBI_CR 0x00
58#define TBI_SR 0x01
59#define TBI_ANA 0x04
60#define TBI_ANLPBPA 0x05
61#define TBI_ANEX 0x06
62#define TBI_TBICON 0x11
63
64
65#define TBICON_CLK_SELECT 0x0020
66#define TBIANA_ASYMMETRIC_PAUSE 0x0100
67#define TBIANA_SYMMETRIC_PAUSE 0x0080
68#define TBIANA_HALF_DUPLEX 0x0040
69#define TBIANA_FULL_DUPLEX 0x0020
70#define TBICR_PHY_RESET 0x8000
71#define TBICR_ANEG_ENABLE 0x1000
72#define TBICR_RESTART_ANEG 0x0200
73#define TBICR_FULL_DUPLEX 0x0100
74#define TBICR_SPEED1_SET 0x0040
75
76
77
78#define MACCFG1_SOFT_RESET 0x80000000
79#define MACCFG1_RESET_RX_MC 0x00080000
80#define MACCFG1_RESET_TX_MC 0x00040000
81#define MACCFG1_RESET_RX_FUN 0x00020000
82#define MACCFG1_RESET_TX_FUN 0x00010000
83#define MACCFG1_LOOPBACK 0x00000100
84#define MACCFG1_RX_FLOW 0x00000020
85#define MACCFG1_TX_FLOW 0x00000010
86#define MACCFG1_SYNCD_RX_EN 0x00000008
87#define MACCFG1_RX_EN 0x00000004
88#define MACCFG1_SYNCD_TX_EN 0x00000002
89#define MACCFG1_TX_EN 0x00000001
90
91#define MACCFG2_INIT_SETTINGS 0x00007205
92#define MACCFG2_FULL_DUPLEX 0x00000001
93#define MACCFG2_IF 0x00000300
94#define MACCFG2_GMII 0x00000200
95#define MACCFG2_MII 0x00000100
96
97#define ECNTRL_INIT_SETTINGS 0x00001000
98#define ECNTRL_TBI_MODE 0x00000020
99#define ECNTRL_R100 0x00000008
100#define ECNTRL_SGMII_MODE 0x00000002
101
102#define miim_end -2
103#define miim_read -1
104
105#ifndef CONFIG_SYS_TBIPA_VALUE
106 #define CONFIG_SYS_TBIPA_VALUE 0x1f
107#endif
108#define MIIMCFG_INIT_VALUE 0x00000003
109#define MIIMCFG_RESET 0x80000000
110
111#define MIIMIND_BUSY 0x00000001
112#define MIIMIND_NOTVALID 0x00000004
113
114#define MIIM_CONTROL 0x00
115#define MIIM_CONTROL_RESET 0x00009140
116#define MIIM_CONTROL_INIT 0x00001140
117#define MIIM_CONTROL_RESTART 0x00001340
118#define MIIM_ANEN 0x00001000
119
120#define MIIM_CR 0x00
121#define MIIM_CR_RST 0x00008000
122#define MIIM_CR_INIT 0x00001000
123
124#define MIIM_STATUS 0x1
125#define MIIM_STATUS_AN_DONE 0x00000020
126#define MIIM_STATUS_LINK 0x0004
127#define PHY_BMSR_AUTN_ABLE 0x0008
128#define PHY_BMSR_AUTN_COMP 0x0020
129
130#define MIIM_PHYIR1 0x2
131#define MIIM_PHYIR2 0x3
132
133#define MIIM_ANAR 0x4
134#define MIIM_ANAR_INIT 0x1e1
135
136#define MIIM_TBI_ANLPBPA 0x5
137#define MIIM_TBI_ANLPBPA_HALF 0x00000040
138#define MIIM_TBI_ANLPBPA_FULL 0x00000020
139
140#define MIIM_TBI_ANEX 0x6
141#define MIIM_TBI_ANEX_NP 0x00000004
142#define MIIM_TBI_ANEX_PRX 0x00000002
143
144#define MIIM_GBIT_CONTROL 0x9
145#define MIIM_GBIT_CONTROL_INIT 0xe00
146
147#define MIIM_EXT_PAGE_ACCESS 0x1f
148
149
150#define MIIM_BCM54xx_AUXCNTL 0x18
151#define MIIM_BCM54xx_AUXCNTL_ENCODE(val) ((val & 0x7) << 12)|(val & 0x7)
152#define MIIM_BCM54xx_AUXSTATUS 0x19
153#define MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK 0x0700
154#define MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT 8
155
156#define MIIM_BCM54XX_SHD 0x1c
157#define MIIM_BCM54XX_SHD_WRITE 0x8000
158#define MIIM_BCM54XX_SHD_VAL(x) ((x & 0x1f) << 10)
159#define MIIM_BCM54XX_SHD_DATA(x) ((x & 0x3ff) << 0)
160#define MIIM_BCM54XX_SHD_WR_ENCODE(val, data) \
161 (MIIM_BCM54XX_SHD_WRITE | MIIM_BCM54XX_SHD_VAL(val) | \
162 MIIM_BCM54XX_SHD_DATA(data))
163
164#define MIIM_BCM54XX_EXP_DATA 0x15
165#define MIIM_BCM54XX_EXP_SEL 0x17
166#define MIIM_BCM54XX_EXP_SEL_SSD 0x0e00
167#define MIIM_BCM54XX_EXP_SEL_ER 0x0f00
168
169
170#define MIIM_CIS8201_AUX_CONSTAT 0x1c
171#define MIIM_CIS8201_AUXCONSTAT_INIT 0x0004
172#define MIIM_CIS8201_AUXCONSTAT_DUPLEX 0x0020
173#define MIIM_CIS8201_AUXCONSTAT_SPEED 0x0018
174#define MIIM_CIS8201_AUXCONSTAT_GBIT 0x0010
175#define MIIM_CIS8201_AUXCONSTAT_100 0x0008
176
177
178#define MIIM_CIS8201_EXT_CON1 0x17
179#define MIIM_CIS8201_EXTCON1_INIT 0x0000
180
181
182#define MIIM_CIS8204_EPHY_CON 0x17
183#define MIIM_CIS8204_EPHYCON_INIT 0x0006
184#define MIIM_CIS8204_EPHYCON_RGMII 0x1100
185
186
187#define MIIM_CIS8204_SLED_CON 0x1b
188#define MIIM_CIS8204_SLEDCON_INIT 0x1115
189
190#define MIIM_GBIT_CON 0x09
191#define MIIM_GBIT_CON_ADVERT 0x0e00
192
193
194
195#define MIIM_VSC8244_AUX_CONSTAT 0x1c
196#define MIIM_VSC8244_AUXCONSTAT_INIT 0x0000
197#define MIIM_VSC8244_AUXCONSTAT_DUPLEX 0x0020
198#define MIIM_VSC8244_AUXCONSTAT_SPEED 0x0018
199#define MIIM_VSC8244_AUXCONSTAT_GBIT 0x0010
200#define MIIM_VSC8244_AUXCONSTAT_100 0x0008
201#define MIIM_CONTROL_INIT_LOOPBACK 0x4000
202
203
204#define MIIM_VSC8244_EPHY_CON 0x17
205#define MIIM_VSC8244_EPHYCON_INIT 0x0006
206
207
208#define MIIM_VSC8244_LED_CON 0x1b
209#define MIIM_VSC8244_LEDCON_INIT 0xF011
210
211
212
213#define MIIM_VSC8601_EPHY_CON 0x17
214#define MIIM_VSC8601_EPHY_CON_INIT_SKEW 0x1120
215#define MIIM_VSC8601_SKEW_CTRL 0x1c
216
217
218#define MIIM_88E1011_PHY_STATUS 0x11
219#define MIIM_88E1011_PHYSTAT_SPEED 0xc000
220#define MIIM_88E1011_PHYSTAT_GBIT 0x8000
221#define MIIM_88E1011_PHYSTAT_100 0x4000
222#define MIIM_88E1011_PHYSTAT_DUPLEX 0x2000
223#define MIIM_88E1011_PHYSTAT_SPDDONE 0x0800
224#define MIIM_88E1011_PHYSTAT_LINK 0x0400
225
226#define MIIM_88E1011_PHY_SCR 0x10
227#define MIIM_88E1011_PHY_MDI_X_AUTO 0x0060
228
229
230#define MIIM_88E1111_PHY_LED_CONTROL 24
231#define MIIM_88E1111_PHY_LED_DIRECT 0x4100
232#define MIIM_88E1111_PHY_LED_COMBINE 0x411C
233
234
235#define MIIM_88E1121_PHY_LED_CTRL 16
236#define MIIM_88E1121_PHY_LED_PAGE 3
237#define MIIM_88E1121_PHY_LED_DEF 0x0030
238
239
240#define MIIM_88E1121_PHY_IRQ_EN 18
241#define MIIM_88E1121_PHY_IRQ_STATUS 19
242
243#define MIIM_88E1121_PHY_PAGE 22
244
245
246#define MIIM_88E1145_PHY_EXT_CR 20
247#define MIIM_M88E1145_RGMII_RX_DELAY 0x0080
248#define MIIM_M88E1145_RGMII_TX_DELAY 0x0002
249
250#define MIIM_88E1145_PHY_PAGE 29
251#define MIIM_88E1145_PHY_CAL_OV 30
252
253
254#define MIIM_RTL8211B_PHY_STATUS 0x11
255#define MIIM_RTL8211B_PHYSTAT_SPEED 0xc000
256#define MIIM_RTL8211B_PHYSTAT_GBIT 0x8000
257#define MIIM_RTL8211B_PHYSTAT_100 0x4000
258#define MIIM_RTL8211B_PHYSTAT_DUPLEX 0x2000
259#define MIIM_RTL8211B_PHYSTAT_SPDDONE 0x0800
260#define MIIM_RTL8211B_PHYSTAT_LINK 0x0400
261
262
263#define MIIM_DM9161_CR_STOP 0x0400
264#define MIIM_DM9161_CR_RSTAN 0x1200
265
266#define MIIM_DM9161_SCR 0x10
267#define MIIM_DM9161_SCR_INIT 0x0610
268
269
270#define MIIM_DM9161_SCSR 0x11
271#define MIIM_DM9161_SCSR_100F 0x8000
272#define MIIM_DM9161_SCSR_100H 0x4000
273#define MIIM_DM9161_SCSR_10F 0x2000
274#define MIIM_DM9161_SCSR_10H 0x1000
275
276
277#define MIIM_DM9161_10BTCSR 0x12
278#define MIIM_DM9161_10BTCSR_INIT 0x7800
279
280
281#define MIIM_LXT971_SR2 0x11
282#define MIIM_LXT971_SR2_SPEED_MASK 0x4200
283#define MIIM_LXT971_SR2_10HDX 0x0000
284#define MIIM_LXT971_SR2_10FDX 0x0200
285#define MIIM_LXT971_SR2_100HDX 0x4000
286#define MIIM_LXT971_SR2_100FDX 0x4200
287
288
289#define MIIM_DP83865_CR_INIT 0x9200
290
291
292#define MIIM_DP83865_LANR 0x11
293#define MIIM_DP83865_SPD_MASK 0x0018
294#define MIIM_DP83865_SPD_1000 0x0010
295#define MIIM_DP83865_SPD_100 0x0008
296#define MIIM_DP83865_DPX_FULL 0x0002
297
298#define MIIM_READ_COMMAND 0x00000001
299
300#define MRBLR_INIT_SETTINGS PKTSIZE_ALIGN
301
302#define MINFLR_INIT_SETTINGS 0x00000040
303
304#define DMACTRL_INIT_SETTINGS 0x000000c3
305#define DMACTRL_GRS 0x00000010
306#define DMACTRL_GTS 0x00000008
307
308#define TSTAT_CLEAR_THALT 0x80000000
309#define RSTAT_CLEAR_RHALT 0x00800000
310
311
312#define IEVENT_INIT_CLEAR 0xffffffff
313#define IEVENT_BABR 0x80000000
314#define IEVENT_RXC 0x40000000
315#define IEVENT_BSY 0x20000000
316#define IEVENT_EBERR 0x10000000
317#define IEVENT_MSRO 0x04000000
318#define IEVENT_GTSC 0x02000000
319#define IEVENT_BABT 0x01000000
320#define IEVENT_TXC 0x00800000
321#define IEVENT_TXE 0x00400000
322#define IEVENT_TXB 0x00200000
323#define IEVENT_TXF 0x00100000
324#define IEVENT_IE 0x00080000
325#define IEVENT_LC 0x00040000
326#define IEVENT_CRL 0x00020000
327#define IEVENT_XFUN 0x00010000
328#define IEVENT_RXB0 0x00008000
329#define IEVENT_GRSC 0x00000100
330#define IEVENT_RXF0 0x00000080
331
332#define IMASK_INIT_CLEAR 0x00000000
333#define IMASK_TXEEN 0x00400000
334#define IMASK_TXBEN 0x00200000
335#define IMASK_TXFEN 0x00100000
336#define IMASK_RXFEN0 0x00000080
337
338
339
340#define ATTR_INIT_SETTINGS 0x000000c0
341#define ATTRELI_INIT_SETTINGS 0x00000000
342
343
344
345#define TXBD_READY 0x8000
346#define TXBD_PADCRC 0x4000
347#define TXBD_WRAP 0x2000
348#define TXBD_INTERRUPT 0x1000
349#define TXBD_LAST 0x0800
350#define TXBD_CRC 0x0400
351#define TXBD_DEF 0x0200
352#define TXBD_HUGEFRAME 0x0080
353#define TXBD_LATECOLLISION 0x0080
354#define TXBD_RETRYLIMIT 0x0040
355#define TXBD_RETRYCOUNTMASK 0x003c
356#define TXBD_UNDERRUN 0x0002
357#define TXBD_STATS 0x03ff
358
359
360#define RXBD_EMPTY 0x8000
361#define RXBD_RO1 0x4000
362#define RXBD_WRAP 0x2000
363#define RXBD_INTERRUPT 0x1000
364#define RXBD_LAST 0x0800
365#define RXBD_FIRST 0x0400
366#define RXBD_MISS 0x0100
367#define RXBD_BROADCAST 0x0080
368#define RXBD_MULTICAST 0x0040
369#define RXBD_LARGE 0x0020
370#define RXBD_NONOCTET 0x0010
371#define RXBD_SHORT 0x0008
372#define RXBD_CRCERR 0x0004
373#define RXBD_OVERRUN 0x0002
374#define RXBD_TRUNCATED 0x0001
375#define RXBD_STATS 0x003f
376
377typedef struct txbd8
378{
379 ushort status;
380 ushort length;
381 uint bufPtr;
382} txbd8_t;
383
384typedef struct rxbd8
385{
386 ushort status;
387 ushort length;
388 uint bufPtr;
389} rxbd8_t;
390
391typedef struct rmon_mib
392{
393
394 uint tr64;
395 uint tr127;
396 uint tr255;
397 uint tr511;
398 uint tr1k;
399 uint trmax;
400 uint trmgv;
401
402 uint rbyt;
403 uint rpkt;
404 uint rfcs;
405 uint rmca;
406 uint rbca;
407 uint rxcf;
408 uint rxpf;
409 uint rxuo;
410 uint raln;
411 uint rflr;
412 uint rcde;
413 uint rcse;
414 uint rund;
415 uint rovr;
416 uint rfrg;
417 uint rjbr;
418 uint rdrp;
419
420 uint tbyt;
421 uint tpkt;
422 uint tmca;
423 uint tbca;
424 uint txpf;
425 uint tdfr;
426 uint tedf;
427 uint tscl;
428
429 uint tmcl;
430 uint tlcl;
431 uint txcl;
432 uint tncl;
433
434 uint res2;
435
436 uint tdrp;
437 uint tjbr;
438 uint tfcs;
439 uint txcf;
440 uint tovr;
441 uint tund;
442 uint tfrg;
443
444 uint car1;
445 uint car2;
446 uint cam1;
447 uint cam2;
448} rmon_mib_t;
449
450typedef struct tsec_hash_regs
451{
452 uint iaddr0;
453 uint iaddr1;
454 uint iaddr2;
455 uint iaddr3;
456 uint iaddr4;
457 uint iaddr5;
458 uint iaddr6;
459 uint iaddr7;
460 uint res1[24];
461 uint gaddr0;
462 uint gaddr1;
463 uint gaddr2;
464 uint gaddr3;
465 uint gaddr4;
466 uint gaddr5;
467 uint gaddr6;
468 uint gaddr7;
469 uint res2[24];
470} tsec_hash_t;
471
472typedef struct tsec_mdio {
473 uint res1[4];
474 uint ieventm;
475 uint imaskm;
476 uint res2;
477 uint emapm;
478 uint res3[320];
479 uint miimcfg;
480 uint miimcom;
481 uint miimadd;
482 uint miimcon;
483 uint miimstat;
484 uint miimind;
485 uint res4[690];
486} tsec_mdio_t;
487
488typedef struct tsec
489{
490
491 uint res000[4];
492
493 uint ievent;
494 uint imask;
495 uint edis;
496 uint res01c;
497 uint ecntrl;
498 uint minflr;
499 uint ptv;
500 uint dmactrl;
501 uint tbipa;
502
503 uint res034[3];
504 uint res040[48];
505
506
507 uint tctrl;
508 uint tstat;
509 uint res108;
510 uint tbdlen;
511 uint res110[5];
512 uint ctbptr;
513 uint res128[23];
514 uint tbptr;
515 uint res188[30];
516
517 uint res200;
518 uint tbase;
519 uint res208[42];
520 uint ostbd;
521 uint ostbdp;
522 uint res2b8[18];
523
524
525 uint rctrl;
526 uint rstat;
527 uint res308;
528 uint rbdlen;
529 uint res310[4];
530 uint res320;
531 uint crbptr;
532 uint res328[6];
533 uint mrblr;
534 uint res344[16];
535 uint rbptr;
536 uint res388[30];
537
538 uint res400;
539 uint rbase;
540 uint res408[62];
541
542
543 uint maccfg1;
544 uint maccfg2;
545 uint ipgifg;
546 uint hafdup;
547 uint maxfrm;
548 uint res514;
549 uint res518;
550
551 uint res51c;
552
553 uint resmdio[6];
554
555 uint res538;
556
557 uint ifstat;
558 uint macstnaddr1;
559 uint macstnaddr2;
560 uint res548[46];
561
562
563 uint res600[32];
564
565
566 rmon_mib_t rmon;
567 uint res740[48];
568
569
570 tsec_hash_t hash;
571
572 uint res900[128];
573
574
575 uint resb00[62];
576 uint attr;
577 uint attreli;
578
579
580 uint resc00[256];
581} tsec_t;
582
583#define TSEC_GIGABIT (1)
584
585
586
587#define TSEC_REDUCED (1 << 1)
588#define TSEC_SGMII (1 << 2)
589#define TSEC_FIBER (1 << 3)
590
591struct tsec_private {
592 volatile tsec_t *regs;
593 volatile tsec_mdio_t *phyregs;
594 volatile tsec_mdio_t *phyregs_sgmii;
595 struct phy_info *phyinfo;
596 uint phyaddr;
597 u32 flags;
598 uint link;
599 uint duplexity;
600 uint speed;
601};
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618struct phy_cmd {
619 uint mii_reg;
620 uint mii_data;
621 uint (*funct) (uint mii_reg, struct tsec_private * priv);
622};
623
624
625
626
627
628
629
630
631
632
633
634
635
636struct phy_info {
637 uint id;
638 char *name;
639 uint shift;
640
641
642 struct phy_cmd *config;
643
644
645 struct phy_cmd *startup;
646
647
648 struct phy_cmd *shutdown;
649};
650
651struct tsec_info_struct {
652 tsec_t *regs;
653 tsec_mdio_t *miiregs;
654 tsec_mdio_t *miiregs_sgmii;
655 char *devname;
656 unsigned int phyaddr;
657 u32 flags;
658};
659
660int tsec_standard_init(bd_t *bis);
661int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsec_info, int num);
662
663#endif
664