]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/tsec.h
* Patch by Eran Liberty
[karo-tx-uboot.git] / drivers / tsec.h
1 /*
2  *  tsec.h
3  *
4  *  Driver for the Motorola Triple Speed Ethernet Controller
5  *
6  *  This software may be used and distributed according to the
7  *  terms of the GNU Public License, Version 2, incorporated
8  *  herein by reference.
9  *
10  * Copyright 2004 Freescale Semiconductor.
11  * (C) Copyright 2003, Motorola, Inc.
12  * maintained by Xianghua Xiao (x.xiao@motorola.com)
13  * author Andy Fleming
14  *
15  */
16
17 #ifndef __TSEC_H
18 #define __TSEC_H
19
20 #include <net.h>
21 #include <config.h>
22
23 #ifndef CFG_TSEC1_OFFSET
24     #define CFG_TSEC1_OFFSET    (0x24000)
25 #endif
26
27 #define TSEC_SIZE       0x01000
28
29 /* FIXME:  Should these be pushed back to 83xx and 85xx config files? */
30 #if defined(CONFIG_MPC85xx)
31     #define TSEC_BASE_ADDR      (CFG_IMMR + CFG_TSEC1_OFFSET)
32 #elif defined(CONFIG_MPC83XX)
33     #define TSEC_BASE_ADDR      (CFG_IMMRBAR + CFG_TSEC1_OFFSET)
34 #endif
35
36
37 #define MAC_ADDR_LEN 6
38
39 /* #define TSEC_TIMEOUT         1000000 */
40 #define TSEC_TIMEOUT 1000
41 #define TOUT_LOOP       1000000
42
43 /* MAC register bits */
44 #define MACCFG1_SOFT_RESET      0x80000000
45 #define MACCFG1_RESET_RX_MC     0x00080000
46 #define MACCFG1_RESET_TX_MC     0x00040000
47 #define MACCFG1_RESET_RX_FUN    0x00020000
48 #define MACCFG1_RESET_TX_FUN    0x00010000
49 #define MACCFG1_LOOPBACK        0x00000100
50 #define MACCFG1_RX_FLOW         0x00000020
51 #define MACCFG1_TX_FLOW         0x00000010
52 #define MACCFG1_SYNCD_RX_EN     0x00000008
53 #define MACCFG1_RX_EN           0x00000004
54 #define MACCFG1_SYNCD_TX_EN     0x00000002
55 #define MACCFG1_TX_EN           0x00000001
56
57 #define MACCFG2_INIT_SETTINGS   0x00007205
58 #define MACCFG2_FULL_DUPLEX     0x00000001
59 #define MACCFG2_IF              0x00000300
60 #define MACCFG2_GMII            0x00000200
61 #define MACCFG2_MII             0x00000100
62
63 #define ECNTRL_INIT_SETTINGS    0x00001000
64 #define ECNTRL_TBI_MODE         0x00000020
65 #define ECNTRL_R100             0x00000008
66
67 #define miim_end -2
68 #define miim_read -1
69
70 #define TBIPA_VALUE             0x1f
71 #define MIIMCFG_INIT_VALUE      0x00000003
72 #define MIIMCFG_RESET           0x80000000
73
74 #define MIIMIND_BUSY            0x00000001
75 #define MIIMIND_NOTVALID        0x00000004
76
77 #define MIIM_CONTROL            0x00
78 #define MIIM_CONTROL_RESET      0x00009140
79 #define MIIM_CONTROL_INIT       0x00001140
80 #define MIIM_ANEN               0x00001000
81
82 #define MIIM_CR                 0x00
83 #define MIIM_CR_RST             0x00008000
84 #define MIIM_CR_INIT            0x00001000
85
86 #define MIIM_STATUS             0x1
87 #define MIIM_STATUS_AN_DONE     0x00000020
88 #define MIIM_STATUS_LINK        0x0004
89
90 #define MIIM_PHYIR1             0x2
91 #define MIIM_PHYIR2             0x3
92
93 #define MIIM_ANAR               0x4
94 #define MIIM_ANAR_INIT          0x1e1
95
96 #define MIIM_TBI_ANLPBPA        0x5
97 #define MIIM_TBI_ANLPBPA_HALF   0x00000040
98 #define MIIM_TBI_ANLPBPA_FULL   0x00000020
99
100 #define MIIM_TBI_ANEX           0x6
101 #define MIIM_TBI_ANEX_NP        0x00000004
102 #define MIIM_TBI_ANEX_PRX       0x00000002
103
104 #define MIIM_GBIT_CONTROL       0x9
105 #define MIIM_GBIT_CONTROL_INIT  0xe00
106
107 /* Cicada Auxiliary Control/Status Register */
108 #define MIIM_CIS8201_AUX_CONSTAT        0x1c
109 #define MIIM_CIS8201_AUXCONSTAT_INIT    0x0004
110 #define MIIM_CIS8201_AUXCONSTAT_DUPLEX  0x0020
111 #define MIIM_CIS8201_AUXCONSTAT_SPEED   0x0018
112 #define MIIM_CIS8201_AUXCONSTAT_GBIT    0x0010
113 #define MIIM_CIS8201_AUXCONSTAT_100     0x0008
114
115 /* Cicada Extended Control Register 1 */
116 #define MIIM_CIS8201_EXT_CON1           0x17
117 #define MIIM_CIS8201_EXTCON1_INIT       0x0000
118
119 /* Cicada 8204 Extended PHY Control Register 1 */
120 #define MIIM_CIS8204_EPHY_CON           0x17
121 #define MIIM_CIS8204_EPHYCON_INIT       0x0006
122 #define MIIM_CIS8204_EPHYCON_RGMII      0x1000
123
124 /* Cicada 8204 Serial LED Control Register */
125 #define MIIM_CIS8204_SLED_CON           0x1b
126 #define MIIM_CIS8204_SLEDCON_INIT       0x1115
127
128 #define MIIM_GBIT_CON           0x09
129 #define MIIM_GBIT_CON_ADVERT    0x0e00
130
131 /* 88E1011 PHY Status Register */
132 #define MIIM_88E1011_PHY_STATUS         0x11
133 #define MIIM_88E1011_PHYSTAT_SPEED      0xc000
134 #define MIIM_88E1011_PHYSTAT_GBIT       0x8000
135 #define MIIM_88E1011_PHYSTAT_100        0x4000
136 #define MIIM_88E1011_PHYSTAT_DUPLEX     0x2000
137 #define MIIM_88E1011_PHYSTAT_SPDDONE    0x0800
138 #define MIIM_88E1011_PHYSTAT_LINK       0x0400
139
140 /* DM9161 Control register values */
141 #define MIIM_DM9161_CR_STOP     0x0400
142 #define MIIM_DM9161_CR_RSTAN    0x1200
143
144 #define MIIM_DM9161_SCR         0x10
145 #define MIIM_DM9161_SCR_INIT    0x0610
146
147 /* DM9161 Specified Configuration and Status Register */
148 #define MIIM_DM9161_SCSR        0x11
149 #define MIIM_DM9161_SCSR_100F   0x8000
150 #define MIIM_DM9161_SCSR_100H   0x4000
151 #define MIIM_DM9161_SCSR_10F    0x2000
152 #define MIIM_DM9161_SCSR_10H    0x1000
153
154 /* DM9161 10BT Configuration/Status */
155 #define MIIM_DM9161_10BTCSR     0x12
156 #define MIIM_DM9161_10BTCSR_INIT        0x7800
157
158 /* LXT971 Status 2 registers */
159 #define MIIM_LXT971_SR2         17  /* Status Register 2  */
160 #define MIIM_LXT971_SR2_SPEED_MASK      0xf000
161 #define MIIM_LXT971_SR2_10HDX   0x1000  /* 10 Mbit half duplex selected */
162 #define MIIM_LXT971_SR2_10FDX   0x2000  /* 10 Mbit full duplex selected */
163 #define MIIM_LXT971_SR2_100HDX  0x4000  /* 100 Mbit half duplex selected */
164 #define MIIM_LXT971_SR2_100FDX  0x8000  /* 100 Mbit full duplex selected */
165
166 #define MIIM_READ_COMMAND       0x00000001
167
168 #define MRBLR_INIT_SETTINGS     PKTSIZE_ALIGN
169
170 #define MINFLR_INIT_SETTINGS    0x00000040
171
172 #define DMACTRL_INIT_SETTINGS   0x000000c3
173 #define DMACTRL_GRS             0x00000010
174 #define DMACTRL_GTS             0x00000008
175
176 #define TSTAT_CLEAR_THALT       0x80000000
177 #define RSTAT_CLEAR_RHALT       0x00800000
178
179
180 #define IEVENT_INIT_CLEAR       0xffffffff
181 #define IEVENT_BABR             0x80000000
182 #define IEVENT_RXC              0x40000000
183 #define IEVENT_BSY              0x20000000
184 #define IEVENT_EBERR            0x10000000
185 #define IEVENT_MSRO             0x04000000
186 #define IEVENT_GTSC             0x02000000
187 #define IEVENT_BABT             0x01000000
188 #define IEVENT_TXC              0x00800000
189 #define IEVENT_TXE              0x00400000
190 #define IEVENT_TXB              0x00200000
191 #define IEVENT_TXF              0x00100000
192 #define IEVENT_IE               0x00080000
193 #define IEVENT_LC               0x00040000
194 #define IEVENT_CRL              0x00020000
195 #define IEVENT_XFUN             0x00010000
196 #define IEVENT_RXB0             0x00008000
197 #define IEVENT_GRSC             0x00000100
198 #define IEVENT_RXF0             0x00000080
199
200 #define IMASK_INIT_CLEAR        0x00000000
201 #define IMASK_TXEEN             0x00400000
202 #define IMASK_TXBEN             0x00200000
203 #define IMASK_TXFEN             0x00100000
204 #define IMASK_RXFEN0            0x00000080
205
206
207 /* Default Attribute fields */
208 #define ATTR_INIT_SETTINGS     0x000000c0
209 #define ATTRELI_INIT_SETTINGS  0x00000000
210
211
212 /* TxBD status field bits */
213 #define TXBD_READY              0x8000
214 #define TXBD_PADCRC             0x4000
215 #define TXBD_WRAP               0x2000
216 #define TXBD_INTERRUPT          0x1000
217 #define TXBD_LAST               0x0800
218 #define TXBD_CRC                0x0400
219 #define TXBD_DEF                0x0200
220 #define TXBD_HUGEFRAME          0x0080
221 #define TXBD_LATECOLLISION      0x0080
222 #define TXBD_RETRYLIMIT         0x0040
223 #define TXBD_RETRYCOUNTMASK     0x003c
224 #define TXBD_UNDERRUN           0x0002
225 #define TXBD_STATS              0x03ff
226
227 /* RxBD status field bits */
228 #define RXBD_EMPTY              0x8000
229 #define RXBD_RO1                0x4000
230 #define RXBD_WRAP               0x2000
231 #define RXBD_INTERRUPT          0x1000
232 #define RXBD_LAST               0x0800
233 #define RXBD_FIRST              0x0400
234 #define RXBD_MISS               0x0100
235 #define RXBD_BROADCAST          0x0080
236 #define RXBD_MULTICAST          0x0040
237 #define RXBD_LARGE              0x0020
238 #define RXBD_NONOCTET           0x0010
239 #define RXBD_SHORT              0x0008
240 #define RXBD_CRCERR             0x0004
241 #define RXBD_OVERRUN            0x0002
242 #define RXBD_TRUNCATED          0x0001
243 #define RXBD_STATS              0x003f
244
245 typedef struct txbd8
246 {
247         ushort       status;         /* Status Fields */
248         ushort       length;         /* Buffer length */
249         uint         bufPtr;         /* Buffer Pointer */
250 } txbd8_t;
251
252 typedef struct rxbd8
253 {
254         ushort       status;         /* Status Fields */
255         ushort       length;         /* Buffer Length */
256         uint         bufPtr;         /* Buffer Pointer */
257 } rxbd8_t;
258
259 typedef struct rmon_mib
260 {
261         /* Transmit and Receive Counters */
262         uint    tr64;           /* Transmit and Receive 64-byte Frame Counter */
263         uint    tr127;          /* Transmit and Receive 65-127 byte Frame Counter */
264         uint    tr255;          /* Transmit and Receive 128-255 byte Frame Counter */
265         uint    tr511;          /* Transmit and Receive 256-511 byte Frame Counter */
266         uint    tr1k;           /* Transmit and Receive 512-1023 byte Frame Counter */
267         uint    trmax;          /* Transmit and Receive 1024-1518 byte Frame Counter */
268         uint    trmgv;          /* Transmit and Receive 1519-1522 byte Good VLAN Frame */
269         /* Receive Counters */
270         uint    rbyt;           /* Receive Byte Counter */
271         uint    rpkt;           /* Receive Packet Counter */
272         uint    rfcs;           /* Receive FCS Error Counter */
273         uint    rmca;           /* Receive Multicast Packet (Counter) */
274         uint    rbca;           /* Receive Broadcast Packet */
275         uint    rxcf;           /* Receive Control Frame Packet */
276         uint    rxpf;           /* Receive Pause Frame Packet */
277         uint    rxuo;           /* Receive Unknown OP Code */
278         uint    raln;           /* Receive Alignment Error */
279         uint    rflr;           /* Receive Frame Length Error */
280         uint    rcde;           /* Receive Code Error */
281         uint    rcse;           /* Receive Carrier Sense Error */
282         uint    rund;           /* Receive Undersize Packet */
283         uint    rovr;           /* Receive Oversize Packet */
284         uint    rfrg;           /* Receive Fragments */
285         uint    rjbr;           /* Receive Jabber */
286         uint    rdrp;           /* Receive Drop */
287         /* Transmit Counters */
288         uint    tbyt;           /* Transmit Byte Counter */
289         uint    tpkt;           /* Transmit Packet */
290         uint    tmca;           /* Transmit Multicast Packet */
291         uint    tbca;           /* Transmit Broadcast Packet */
292         uint    txpf;           /* Transmit Pause Control Frame */
293         uint    tdfr;           /* Transmit Deferral Packet */
294         uint    tedf;           /* Transmit Excessive Deferral Packet */
295         uint    tscl;           /* Transmit Single Collision Packet */
296         /* (0x2_n700) */
297         uint    tmcl;           /* Transmit Multiple Collision Packet */
298         uint    tlcl;           /* Transmit Late Collision Packet */
299         uint    txcl;           /* Transmit Excessive Collision Packet */
300         uint    tncl;           /* Transmit Total Collision */
301
302         uint    res2;
303
304         uint    tdrp;           /* Transmit Drop Frame */
305         uint    tjbr;           /* Transmit Jabber Frame */
306         uint    tfcs;           /* Transmit FCS Error */
307         uint    txcf;           /* Transmit Control Frame */
308         uint    tovr;           /* Transmit Oversize Frame */
309         uint    tund;           /* Transmit Undersize Frame */
310         uint    tfrg;           /* Transmit Fragments Frame */
311         /* General Registers */
312         uint    car1;           /* Carry Register One */
313         uint    car2;           /* Carry Register Two */
314         uint    cam1;           /* Carry Register One Mask */
315         uint    cam2;           /* Carry Register Two Mask */
316 } rmon_mib_t;
317
318 typedef struct tsec_hash_regs
319 {
320         uint    iaddr0;         /* Individual Address Register 0 */
321         uint    iaddr1;         /* Individual Address Register 1 */
322         uint    iaddr2;         /* Individual Address Register 2 */
323         uint    iaddr3;         /* Individual Address Register 3 */
324         uint    iaddr4;         /* Individual Address Register 4 */
325         uint    iaddr5;         /* Individual Address Register 5 */
326         uint    iaddr6;         /* Individual Address Register 6 */
327         uint    iaddr7;         /* Individual Address Register 7 */
328         uint    res1[24];
329         uint    gaddr0;         /* Group Address Register 0 */
330         uint    gaddr1;         /* Group Address Register 1 */
331         uint    gaddr2;         /* Group Address Register 2 */
332         uint    gaddr3;         /* Group Address Register 3 */
333         uint    gaddr4;         /* Group Address Register 4 */
334         uint    gaddr5;         /* Group Address Register 5 */
335         uint    gaddr6;         /* Group Address Register 6 */
336         uint    gaddr7;         /* Group Address Register 7 */
337         uint    res2[24];
338 } tsec_hash_t;
339
340 typedef struct tsec
341 {
342         /* General Control and Status Registers (0x2_n000) */
343         uint    res000[4];
344
345         uint    ievent;         /* Interrupt Event */
346         uint    imask;          /* Interrupt Mask */
347         uint    edis;           /* Error Disabled */
348         uint    res01c;
349         uint    ecntrl;         /* Ethernet Control */
350         uint    minflr;         /* Minimum Frame Length */
351         uint    ptv;            /* Pause Time Value */
352         uint    dmactrl;        /* DMA Control */
353         uint    tbipa;          /* TBI PHY Address */
354
355         uint    res034[3];
356         uint    res040[48];
357
358         /* Transmit Control and Status Registers (0x2_n100) */
359         uint    tctrl;          /* Transmit Control */
360         uint    tstat;          /* Transmit Status */
361         uint    res108;
362         uint    tbdlen;         /* Tx BD Data Length */
363         uint    res110[5];
364         uint    ctbptr;         /* Current TxBD Pointer */
365         uint    res128[23];
366         uint    tbptr;          /* TxBD Pointer */
367         uint    res188[30];
368         /* (0x2_n200) */
369         uint        res200;
370         uint    tbase;          /* TxBD Base Address */
371         uint    res208[42];
372         uint    ostbd;          /* Out of Sequence TxBD */
373         uint    ostbdp;         /* Out of Sequence Tx Data Buffer Pointer */
374         uint        res2b8[18];
375
376         /* Receive Control and Status Registers (0x2_n300) */
377         uint    rctrl;          /* Receive Control */
378         uint    rstat;          /* Receive Status */
379         uint    res308;
380         uint    rbdlen;         /* RxBD Data Length */
381         uint    res310[4];
382         uint        res320;
383         uint    crbptr;         /* Current Receive Buffer Pointer */
384         uint    res328[6];
385         uint    mrblr;          /* Maximum Receive Buffer Length */
386         uint    res344[16];
387         uint    rbptr;          /* RxBD Pointer */
388         uint        res388[30];
389         /* (0x2_n400) */
390         uint        res400;
391         uint    rbase;          /* RxBD Base Address */
392         uint        res408[62];
393
394         /* MAC Registers (0x2_n500) */
395         uint    maccfg1;        /* MAC Configuration #1 */
396         uint    maccfg2;        /* MAC Configuration #2 */
397         uint    ipgifg;         /* Inter Packet Gap/Inter Frame Gap */
398         uint    hafdup;         /* Half-duplex */
399         uint    maxfrm;         /* Maximum Frame */
400         uint    res514;
401         uint    res518;
402
403         uint    res51c;
404
405         uint    miimcfg;        /* MII Management: Configuration */
406         uint    miimcom;        /* MII Management: Command */
407         uint    miimadd;        /* MII Management: Address */
408         uint    miimcon;        /* MII Management: Control */
409         uint    miimstat;       /* MII Management: Status */
410         uint    miimind;        /* MII Management: Indicators */
411
412         uint    res538;
413
414         uint    ifstat;         /* Interface Status */
415         uint    macstnaddr1;    /* Station Address, part 1 */
416         uint    macstnaddr2;    /* Station Address, part 2 */
417         uint    res548[46];
418
419         /* (0x2_n600) */
420         uint    res600[32];
421
422         /* RMON MIB Registers (0x2_n680-0x2_n73c) */
423         rmon_mib_t      rmon;
424         uint    res740[48];
425
426         /* Hash Function Registers (0x2_n800) */
427         tsec_hash_t     hash;
428
429         uint        res900[128];
430
431         /* Pattern Registers (0x2_nb00) */
432         uint        resb00[62];
433         uint        attr;          /* Default Attribute Register */
434         uint        attreli;       /* Default Attribute Extract Length and Index */
435
436         /* TSEC Future Expansion Space (0x2_nc00-0x2_nffc) */
437         uint    resc00[256];
438 } tsec_t;
439
440 #define TSEC_GIGABIT (1)
441
442 /* This flag currently only has
443  * meaning if we're using the eTSEC */
444 #define TSEC_REDUCED (1 << 1)
445
446 struct tsec_private {
447         volatile tsec_t *regs;
448         volatile tsec_t *phyregs;
449         struct phy_info *phyinfo;
450         uint phyaddr;
451         u32 flags;
452         uint link;
453         uint duplexity;
454         uint speed;
455 };
456
457
458 /*
459  * struct phy_cmd:  A command for reading or writing a PHY register
460  *
461  * mii_reg:  The register to read or write
462  *
463  * mii_data:  For writes, the value to put in the register.
464  *      A value of -1 indicates this is a read.
465  *
466  * funct: A function pointer which is invoked for each command.
467  *      For reads, this function will be passed the value read
468  *      from the PHY, and process it.
469  *      For writes, the result of this function will be written
470  *      to the PHY register
471  */
472 struct phy_cmd {
473     uint mii_reg;
474     uint mii_data;
475     uint (*funct) (uint mii_reg, struct tsec_private* priv);
476 };
477
478 /* struct phy_info: a structure which defines attributes for a PHY
479  *
480  * id will contain a number which represents the PHY.  During
481  * startup, the driver will poll the PHY to find out what its
482  * UID--as defined by registers 2 and 3--is.  The 32-bit result
483  * gotten from the PHY will be shifted right by "shift" bits to
484  * discard any bits which may change based on revision numbers
485  * unimportant to functionality
486  *
487  * The struct phy_cmd entries represent pointers to an arrays of
488  * commands which tell the driver what to do to the PHY.
489  */
490 struct phy_info {
491     uint id;
492     char *name;
493     uint shift;
494     /* Called to configure the PHY, and modify the controller
495      * based on the results */
496     struct phy_cmd *config;
497
498     /* Called when starting up the controller */
499     struct phy_cmd *startup;
500
501     /* Called when bringing down the controller */
502     struct phy_cmd *shutdown;
503 };
504
505 #endif /* __TSEC_H */