]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/devs/eth/fec/v2_0/include/fec.h
TX53 Release 2011-12-20
[karo-tx-redboot.git] / packages / devs / eth / fec / v2_0 / include / fec.h
1 #ifndef _CYGONCE_ETH_FEC_H_
2 #define _CYGONCE_ETH_FEC_H_
3 //==========================================================================
4 //
5 //      dev/mxc_fec.h
6 //
7 //              Fast Ethernet MAC controller in i.MXx
8 //
9 //==========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14 //
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
18 //
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22 // for more details.
23 //
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 //
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
34 //
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
37 //
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //####BSDCOPYRIGHTBEGIN####
43 //
44 //
45 //####BSDCOPYRIGHTEND####
46 //==========================================================================
47 //#####DESCRIPTIONBEGIN####
48 //
49 // Author(s):    Fred Fan
50 // Contributors:
51 // Date:         2006-08-23
52 // Purpose:
53 // Description:
54 //
55 //####DESCRIPTIONEND####
56 //
57 //==========================================================================
58
59 #include <cyg/infra/cyg_type.h>
60
61 #include <cyg/hal/hal_io.h>
62
63 #ifdef CYGPKG_DEVS_ETH_PHY
64 /* generic PHY device access functions */
65 void mxc_fec_phy_init(void);
66 void mxc_fec_phy_reset(void);
67 bool mxc_fec_phy_read(int reg, int unit, unsigned short *data);
68 void mxc_fec_phy_write(int reg, int unit, unsigned short data);
69
70 #include <cyg/io/eth_phy.h>
71 #endif
72
73 /* The defines of event bits */
74 #define FEC_EVENT_HBERR         0x80000000
75 #define FEC_EVENT_BABR          0x40000000
76 #define FEC_EVENT_BABT          0x20000000
77 #define FEC_EVENT_GRA           0x10000000
78 #define FEC_EVENT_TXF           0x08000000
79 #define FEC_EVENT_TXB           0x04000000
80 #define FEC_EVENT_RXF           0x02000000
81 #define FEC_EVENT_RXB           0x01000000
82 #define FEC_EVENT_MII           0x00800000
83 #define FEC_EVENT_EBERR         0x00400000
84 #define FEC_EVENT_LC            0x00200000
85 #define FEC_EVENT_RL            0x00100000
86 #define FEC_EVENT_UN            0x00080000
87
88 #define FEC_EVENT_TX            FEC_EVENT_TXF
89 #define FEC_EVENT_TX_ERR        (FEC_EVENT_BABT | FEC_EVENT_LC | FEC_EVENT_RL | FEC_EVENT_UN)
90 #define FEC_EVENT_RX            FEC_EVENT_RXF
91 #define FEC_EVENT_ERR           (FEC_EVENT_HBERR | FEC_EVENT_EBERR)
92
93 #define FEC_RX_FRAMES           ((CYGNUM_IO_ETH_DRIVERS_NUM_PKT / 2) + 1)
94 #define FEC_FRAME_LEN           (1540 + 4)
95
96 /* the defines to active transmit or receive frame */
97 #define FEC_RX_TX_ACTIVE        0x01000000
98
99 /* the defines of Ethernet Control register */
100 #define FEC_RESET                       0x00000001
101 #define FEC_ETHER_EN            0x00000002
102
103 /* the defins of MII operation */
104 #define FEC_MII_ST                      0x40000000
105 #define FEC_MII_OP_OFF          28
106 #define FEC_MII_OP_MASK         0x03
107 #define FEC_MII_OP_RD           0x02
108 #define FEC_MII_OP_WR           0x01
109 #define FEC_MII_PA_OFF          23
110 #define FEC_MII_PA_MASK         0xFF
111 #define FEC_MII_RA_OFF          18
112 #define FEC_MII_RA_MASK         0xFF
113 #define FEC_MII_TA                      0x00020000
114 #define FEC_MII_DATA_OFF        0
115 #define FEC_MII_DATA_MASK       0x0000FFFF
116
117 #define FEC_MII_FRAME           (FEC_MII_ST | FEC_MII_TA)
118 #define FEC_MII_OP(x)           (((x) & FEC_MII_OP_MASK) << FEC_MII_OP_OFF)
119 #define FEC_MII_PA(pa)          (((pa)& FEC_MII_PA_MASK) << FEC_MII_PA_OFF)
120 #define FEC_MII_RA(ra)          (((ra)& FEC_MII_RA_MASK) << FEC_MII_RA_OFF)
121 #define FEC_MII_SET_DATA(v)     (((v) & FEC_MII_DATA_MASK) << FEC_MII_DATA_OFF)
122 #define FEC_MII_GET_DATA(v)     (((v) >> FEC_MII_DATA_OFF) & FEC_MII_DATA_MASK)
123 #define FEC_MII_READ(pa, ra) ((FEC_MII_FRAME | FEC_MII_OP(FEC_MII_OP_RD)) | \
124                                                                 FEC_MII_PA(pa) | FEC_MII_RA(ra))
125 #define FEC_MII_WRITE(pa, ra, v) (FEC_MII_FRAME | FEC_MII_OP(FEC_MII_OP_WR) | \
126                                                                         FEC_MII_PA(pa) | FEC_MII_RA(ra) | \
127                                                                         FEC_MII_SET_DATA(v))
128
129 #define MII_SPEED_SHIFT         1
130 #define MII_SPEED_MASK          0x0000003F
131 #define MII_SPEED(x)            ((((((x) + 499999) / 2500000) & MII_SPEED_MASK) >> 1) << MII_SPEED_SHIFT)
132
133 /* the defines of MIB control */
134 #define FEC_MIB_DISABLE         0x80000000
135
136 /* the defines of Receive Control*/
137 #define FEC_RCR_FCE                     0x00000020
138 #define FEC_RCR_BC_REJ          0x00000010
139 #define FEC_RCR_PROM            0x00000008
140 #define FEC_RCR_MII_MODE        0x00000004
141 #define FEC_RCR_DRT                     0x00000002
142
143 /* the defines of Transmit Control*/
144 #define FEC_TCR_RFC_PAUSE       0x00000010
145 #define FEC_TCR_FDEN            0x00000004
146 #define FEC_TCR_HBC                     0x00000002
147
148 /* the defines of buffer description*/
149 #define FEC_BD_RX_NUM           256
150 #define FEC_BD_TX_NUM           2
151
152 #ifdef CYGOPT_HAL_ARM_MXC_FEC_MIIGSK
153 /* the defines for MIIGSK */
154
155 /* RMII frequency control: 0=50MHz, 1=5MHz */
156 #define MIIGSK_CFGR_FRCONT                      (1 << 6)
157
158 /* loopback mode */
159 #define MIIGSK_CFGR_LBMODE                      (1 << 4)
160
161 /* echo mode */
162 #define MIIGSK_CFGR_EMODE                       (1 << 3)
163
164 /* MII gasket mode field */
165 #define MIIGSK_CFGR_IF_MODE_MASK        (3 << 0)
166
167 /* MMI/7-Wire mode */
168 #define MIIGSK_CFGR_IF_MODE_MII         (0 << 0)
169
170 /* RMII mode */
171 #define MIIGSK_CFGR_IF_MODE_RMII        (1 << 0)
172
173 /* reflects MIIGSK Enable bit (RO) */
174 #define MIIGSK_ENR_READY                        (1 << 2)
175
176 /* enable MIGSK (set by default) */
177 #define MIIGSK_ENR_EN                           (1 << 1)
178 #endif
179
180 typedef volatile void mxc_fec_reg_t;
181 #define eir                             0x004   /* Interrupt Event Register */
182 #define eimr                    0x008   /* Interrupt Mask Register */
183 #define rdar                    0x010   /* Receive Descriptor Active Register*/
184 #define tdar                    0x014   /* Transmit Descriptor Active Register*/
185 #define ecr                             0x024   /*Receive Descriptor Active Register*/
186 #define mmfr                    0x040   /*MII Management Frame Register */
187 #define mscr                    0x044   /*MII Speed Control Register */
188 #define mibc                    0x064   /*MII Control/Status Register */
189 #define rcr                             0x084   /*Receive Control Register */
190 #define tcr                             0x0C4   /*Transmit Control register */
191 #define palr                    0x0E4   /*Physical Address Low Register*/
192 #define paur                    0x0E8   /*Physical Address High+Type Register*/
193 #define opd                             0x0EC   /*Opcode+Pause Duration */
194 #define iaur                    0x118   /*Upper 32bits Individual Hash Table*/
195 #define ialr                    0x11c   /*lower 32bits Individual Hash Table*/
196 #define gaur                    0x120   /*Upper 32bits Group Hash Table*/
197 #define galr                    0x124   /*lower 32bits Group Hash Table*/
198 #define tfwr                    0x144   /*Trasmit FIFO Watermark */
199 #define frbr                    0x14c   /*FIFO Receive Bound Register*/
200 #define frsr                    0x150   /*FIFO Receive FIFO Start Registers*/
201 #define erdsr                   0x180   /*Pointer to Receive Descriptor Ring*/
202 #define etdsr                   0x184   /*Pointer to Transmit Descriptor Ring*/
203 #define emrbr                   0x188   /*Maximum Receive Buffer size*/
204 #ifdef CYGOPT_HAL_ARM_MXC_FEC_MIIGSK
205 #define miigsk_cfgr             0x300 /* MIIGSK Configuration Register */
206 #define miigsk_enr              0x308  /* MIIGSK Enable Register */
207 #endif
208
209 #define BD_RX_ST_EMPTY  0x8000
210 #define BD_RX_ST_WRAP   0x2000
211 #define BD_RX_ST_LAST   0x0800
212 #define BD_RX_ST_ERRS   0x0037
213
214 #define BD_TX_ST_RDY    0x8000
215 #define BD_TX_ST_WRAP   0x2000
216 #define BD_TX_ST_LAST   0x0800
217 #define BD_TX_ST_TC             0x0400
218 #define BD_TX_ST_ABC    0x0200
219
220 typedef struct mxc_fec_bd_t
221 {
222         unsigned short int length;      /*packet size*/
223         unsigned short int status;      /*control & statue of this buffer description*/
224         unsigned char      *data;       /*frame buffer address*/
225 } mxc_fec_bd_t;
226
227 typedef struct mxc_fec_priv_s
228 {
229         mxc_fec_reg_t *hw_reg;          /*the register base address of FEC*/
230 #ifdef CYGPKG_DEVS_ETH_PHY
231         eth_phy_access_t *phy;
232 #else
233         unsigned char   phy_addr;       /*the address of PHY which associated with FEC controller*/
234 #endif
235         unsigned char   tx_busy;        /*0:free, 1:transmitting frame*/
236         unsigned char   res[2];
237         unsigned long   status;         /*the status of FEC device:link-status etc.*/
238         unsigned long   tx_key;         /*save the key delivered from send function*/
239         mxc_fec_bd_t   *rx_bd;          /*the receive buffer description ring*/
240         mxc_fec_bd_t   *rx_cur;         /*the next recveive buffer description*/
241         mxc_fec_bd_t   *tx_bd;          /*the transmit buffer description rign*/
242         mxc_fec_bd_t   *tx_cur;         /*the next transmit buffer description*/
243         cyg_bool (*provide_esa)(unsigned char *);
244 } mxc_fec_priv_t;
245
246 #define MXC_FEC_PRIVATE(x)      ((mxc_fec_priv_t *)(x)->driver_private)
247
248 /*The defines of the status field of mxc_fec_priv_t */
249 #define FEC_STATUS_LINK_ON              0x80000000
250 #define FEC_STATUS_FULL_DPLX    0x40000000
251 #define FEC_STATUS_AUTO_NEG             0x20000000
252 #define FEC_STATUS_100M                 0x10000000
253
254 /*The defines about PHY */
255 #ifndef FEC_PHY_ADDR
256 #define PHY_PORT_ADDR                   0x01
257 #else
258 #define PHY_PORT_ADDR                   FEC_PHY_ADDR
259 #endif
260
261 #define PHY_CTRL_REG                    0x00
262 #define PHY_CTRL_RESET                  0x8000
263 #define PHY_CTRL_AUTO_NEG               0x1000
264 #define PHY_CTRL_FULL_DPLX              0x0100
265
266 #define PHY_STATUS_REG                  0x01
267 #define PHY_STATUS_LINK_ST              0x0004
268
269 #define PHY_IDENTIFY_1                  0x02
270 #define PHY_IDENTIFY_2                  0x03
271 #define PHY_ID1_SHIFT                   2
272 #define PHY_ID1_MASK                    0xFFFF
273 #define PHY_ID2_SHIFT                   8
274 #define PHY_ID2_MASK                    0xFC00
275 #define PHY_MODE_NUM                    0x03F0
276 #define PHY_REV_NUM                             0x000F
277
278 #define PHY_DIAG_REG                    0x12
279 #define PHY_DIAG_DPLX                   0x0800
280 #define PHY_DIAG_RATE                   0x0400
281
282 #define PHY_MODE_REG                    0x15
283 #define PHY_LED_SEL                             0x200
284
285 #define PHY_AUTO_NEG_REG                0x5
286 #define PHY_AUTO_10BASET                0x20
287 #define PHY_AUTO_10BASET_DPLX   0x40
288 #define PHY_AUTO_100BASET               0x80
289 #define PHY_AUTO_100BASET_DPLX  0x100
290
291 #define PHY_AUTO_NEG_EXP_REG    0x6
292 #define PHY_AUTO_NEG_NEW_PAGE   0x2
293 #define PHY_AUTO_NEG_CAP                0x1
294
295 #define PHY_INT_SRC_REG                 29
296 #define PHY_INT_AUTO_NEG                0x40
297 #define FEC_COMMON_TICK                 2
298 #define FEC_COMMON_TIMEOUT              (1000 * 1000)
299 #define FEC_MII_TICK                    2
300 #define FEC_MII_TIMEOUT                 (1000 * 1000)
301 #endif // _CYGONCE_ETH_FEC_H_