blob: 95054be5fb3f6d060534a516464ca058672e361e [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
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 *
Claudiu Manoilaec84bf2013-09-30 12:44:42 +030010 * Copyright 2004, 2007, 2009, 2011, 2013 Freescale Semiconductor, Inc.
wdenk42d1f032003-10-15 23:53:47 +000011 * (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>
Eran Libertyf046ccd2005-07-28 10:08:46 -050021#include <config.h>
Andy Fleming063c1262011-04-08 02:10:54 -050022#include <phy.h>
23#include <asm/fsl_enet.h>
wdenk42d1f032003-10-15 23:53:47 +000024
Sandeep Gopalpetb9e186f2009-10-31 00:35:04 +053025#define TSEC_SIZE 0x01000
26#define TSEC_MDIO_OFFSET 0x01000
Eran Libertyf046ccd2005-07-28 10:08:46 -050027
Andy Fleming40ac3d42011-04-29 02:26:52 -050028#define CONFIG_SYS_MDIO_BASE_ADDR (MDIO_BASE_ADDR + 0x520)
Andy Fleming063c1262011-04-08 02:10:54 -050029
Claudiu Manoilaec84bf2013-09-30 12:44:42 +030030#define TSEC_GET_REGS(num, offset) \
31 (struct tsec __iomem *)\
32 (TSEC_BASE_ADDR + (((num) - 1) * (offset)))
33
34#define TSEC_GET_REGS_BASE(num) \
35 TSEC_GET_REGS((num), TSEC_SIZE)
36
37#define TSEC_GET_MDIO_REGS(num, offset) \
38 (struct tsec_mii_mng __iomem *)\
39 (CONFIG_SYS_MDIO_BASE_ADDR + ((num) - 1) * (offset))
40
41#define TSEC_GET_MDIO_REGS_BASE(num) \
42 TSEC_GET_MDIO_REGS((num), TSEC_MDIO_OFFSET)
43
Andy Fleming063c1262011-04-08 02:10:54 -050044#define DEFAULT_MII_NAME "FSL_MDIO"
45
Andy Fleming75b9d4a2008-08-31 16:33:26 -050046#define STD_TSEC_INFO(num) \
47{ \
Claudiu Manoilaec84bf2013-09-30 12:44:42 +030048 .regs = TSEC_GET_REGS_BASE(num), \
49 .miiregs_sgmii = TSEC_GET_MDIO_REGS_BASE(num), \
Andy Fleming75b9d4a2008-08-31 16:33:26 -050050 .devname = CONFIG_TSEC##num##_NAME, \
51 .phyaddr = TSEC##num##_PHY_ADDR, \
Andy Fleming063c1262011-04-08 02:10:54 -050052 .flags = TSEC##num##_FLAGS, \
53 .mii_devname = DEFAULT_MII_NAME \
Andy Fleming75b9d4a2008-08-31 16:33:26 -050054}
55
56#define SET_STD_TSEC_INFO(x, num) \
57{ \
Claudiu Manoilaec84bf2013-09-30 12:44:42 +030058 x.regs = TSEC_GET_REGS_BASE(num); \
59 x.miiregs_sgmii = TSEC_GET_MDIO_REGS_BASE(num); \
Andy Fleming75b9d4a2008-08-31 16:33:26 -050060 x.devname = CONFIG_TSEC##num##_NAME; \
61 x.phyaddr = TSEC##num##_PHY_ADDR; \
62 x.flags = TSEC##num##_FLAGS;\
Andy Fleming063c1262011-04-08 02:10:54 -050063 x.mii_devname = DEFAULT_MII_NAME;\
Andy Fleming75b9d4a2008-08-31 16:33:26 -050064}
65
wdenk42d1f032003-10-15 23:53:47 +000066#define MAC_ADDR_LEN 6
67
Wolfgang Denk53677ef2008-05-20 16:00:29 +020068/* #define TSEC_TIMEOUT 1000000 */
wdenk97d80fc2004-06-09 00:34:46 +000069#define TSEC_TIMEOUT 1000
Wolfgang Denk53677ef2008-05-20 16:00:29 +020070#define TOUT_LOOP 1000000
wdenk42d1f032003-10-15 23:53:47 +000071
Andy Fleming2abe3612008-08-31 16:33:27 -050072/* TBI register addresses */
73#define TBI_CR 0x00
74#define TBI_SR 0x01
75#define TBI_ANA 0x04
76#define TBI_ANLPBPA 0x05
77#define TBI_ANEX 0x06
78#define TBI_TBICON 0x11
79
80/* TBI MDIO register bit fields*/
81#define TBICON_CLK_SELECT 0x0020
82#define TBIANA_ASYMMETRIC_PAUSE 0x0100
83#define TBIANA_SYMMETRIC_PAUSE 0x0080
84#define TBIANA_HALF_DUPLEX 0x0040
85#define TBIANA_FULL_DUPLEX 0x0020
86#define TBICR_PHY_RESET 0x8000
87#define TBICR_ANEG_ENABLE 0x1000
88#define TBICR_RESTART_ANEG 0x0200
89#define TBICR_FULL_DUPLEX 0x0100
90#define TBICR_SPEED1_SET 0x0040
91
92
wdenk42d1f032003-10-15 23:53:47 +000093/* MAC register bits */
94#define MACCFG1_SOFT_RESET 0x80000000
95#define MACCFG1_RESET_RX_MC 0x00080000
96#define MACCFG1_RESET_TX_MC 0x00040000
97#define MACCFG1_RESET_RX_FUN 0x00020000
98#define MACCFG1_RESET_TX_FUN 0x00010000
99#define MACCFG1_LOOPBACK 0x00000100
100#define MACCFG1_RX_FLOW 0x00000020
101#define MACCFG1_TX_FLOW 0x00000010
102#define MACCFG1_SYNCD_RX_EN 0x00000008
103#define MACCFG1_RX_EN 0x00000004
104#define MACCFG1_SYNCD_TX_EN 0x00000002
105#define MACCFG1_TX_EN 0x00000001
106
107#define MACCFG2_INIT_SETTINGS 0x00007205
108#define MACCFG2_FULL_DUPLEX 0x00000001
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200109#define MACCFG2_IF 0x00000300
wdenk97d80fc2004-06-09 00:34:46 +0000110#define MACCFG2_GMII 0x00000200
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200111#define MACCFG2_MII 0x00000100
wdenk42d1f032003-10-15 23:53:47 +0000112
113#define ECNTRL_INIT_SETTINGS 0x00001000
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200114#define ECNTRL_TBI_MODE 0x00000020
Andy Fleming063c1262011-04-08 02:10:54 -0500115#define ECNTRL_REDUCED_MODE 0x00000010
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500116#define ECNTRL_R100 0x00000008
Andy Fleming063c1262011-04-08 02:10:54 -0500117#define ECNTRL_REDUCED_MII_MODE 0x00000004
Andy Fleming81f481c2007-04-23 02:24:28 -0500118#define ECNTRL_SGMII_MODE 0x00000002
wdenk42d1f032003-10-15 23:53:47 +0000119
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200120#ifndef CONFIG_SYS_TBIPA_VALUE
121 #define CONFIG_SYS_TBIPA_VALUE 0x1f
Joe Hammandcb84b72007-08-09 09:08:18 -0500122#endif
wdenk42d1f032003-10-15 23:53:47 +0000123
124#define MRBLR_INIT_SETTINGS PKTSIZE_ALIGN
125
126#define MINFLR_INIT_SETTINGS 0x00000040
127
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200128#define DMACTRL_INIT_SETTINGS 0x000000c3
129#define DMACTRL_GRS 0x00000010
130#define DMACTRL_GTS 0x00000008
wdenk42d1f032003-10-15 23:53:47 +0000131
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200132#define TSTAT_CLEAR_THALT 0x80000000
133#define RSTAT_CLEAR_RHALT 0x00800000
wdenk42d1f032003-10-15 23:53:47 +0000134
wdenk7abf0c52004-04-18 21:45:42 +0000135
wdenk42d1f032003-10-15 23:53:47 +0000136#define IEVENT_INIT_CLEAR 0xffffffff
137#define IEVENT_BABR 0x80000000
138#define IEVENT_RXC 0x40000000
139#define IEVENT_BSY 0x20000000
140#define IEVENT_EBERR 0x10000000
141#define IEVENT_MSRO 0x04000000
142#define IEVENT_GTSC 0x02000000
143#define IEVENT_BABT 0x01000000
144#define IEVENT_TXC 0x00800000
145#define IEVENT_TXE 0x00400000
146#define IEVENT_TXB 0x00200000
147#define IEVENT_TXF 0x00100000
148#define IEVENT_IE 0x00080000
149#define IEVENT_LC 0x00040000
150#define IEVENT_CRL 0x00020000
151#define IEVENT_XFUN 0x00010000
152#define IEVENT_RXB0 0x00008000
153#define IEVENT_GRSC 0x00000100
154#define IEVENT_RXF0 0x00000080
155
156#define IMASK_INIT_CLEAR 0x00000000
157#define IMASK_TXEEN 0x00400000
158#define IMASK_TXBEN 0x00200000
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200159#define IMASK_TXFEN 0x00100000
wdenk42d1f032003-10-15 23:53:47 +0000160#define IMASK_RXFEN0 0x00000080
161
162
163/* Default Attribute fields */
164#define ATTR_INIT_SETTINGS 0x000000c0
165#define ATTRELI_INIT_SETTINGS 0x00000000
166
167
168/* TxBD status field bits */
169#define TXBD_READY 0x8000
170#define TXBD_PADCRC 0x4000
171#define TXBD_WRAP 0x2000
172#define TXBD_INTERRUPT 0x1000
173#define TXBD_LAST 0x0800
174#define TXBD_CRC 0x0400
175#define TXBD_DEF 0x0200
176#define TXBD_HUGEFRAME 0x0080
177#define TXBD_LATECOLLISION 0x0080
178#define TXBD_RETRYLIMIT 0x0040
179#define TXBD_RETRYCOUNTMASK 0x003c
180#define TXBD_UNDERRUN 0x0002
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200181#define TXBD_STATS 0x03ff
wdenk42d1f032003-10-15 23:53:47 +0000182
183/* RxBD status field bits */
184#define RXBD_EMPTY 0x8000
185#define RXBD_RO1 0x4000
186#define RXBD_WRAP 0x2000
187#define RXBD_INTERRUPT 0x1000
188#define RXBD_LAST 0x0800
189#define RXBD_FIRST 0x0400
190#define RXBD_MISS 0x0100
191#define RXBD_BROADCAST 0x0080
192#define RXBD_MULTICAST 0x0040
193#define RXBD_LARGE 0x0020
194#define RXBD_NONOCTET 0x0010
195#define RXBD_SHORT 0x0008
196#define RXBD_CRCERR 0x0004
197#define RXBD_OVERRUN 0x0002
198#define RXBD_TRUNCATED 0x0001
199#define RXBD_STATS 0x003f
200
Claudiu Manoil9c9141f2013-10-04 19:13:53 +0300201struct txbd8 {
202 uint16_t status; /* Status Fields */
203 uint16_t length; /* Buffer length */
204 uint32_t bufptr; /* Buffer Pointer */
205};
wdenk42d1f032003-10-15 23:53:47 +0000206
Claudiu Manoil9c9141f2013-10-04 19:13:53 +0300207struct rxbd8 {
208 uint16_t status; /* Status Fields */
209 uint16_t length; /* Buffer Length */
210 uint32_t bufptr; /* Buffer Pointer */
211};
wdenk42d1f032003-10-15 23:53:47 +0000212
213typedef struct rmon_mib
214{
215 /* Transmit and Receive Counters */
216 uint tr64; /* Transmit and Receive 64-byte Frame Counter */
217 uint tr127; /* Transmit and Receive 65-127 byte Frame Counter */
218 uint tr255; /* Transmit and Receive 128-255 byte Frame Counter */
219 uint tr511; /* Transmit and Receive 256-511 byte Frame Counter */
220 uint tr1k; /* Transmit and Receive 512-1023 byte Frame Counter */
221 uint trmax; /* Transmit and Receive 1024-1518 byte Frame Counter */
222 uint trmgv; /* Transmit and Receive 1519-1522 byte Good VLAN Frame */
223 /* Receive Counters */
224 uint rbyt; /* Receive Byte Counter */
225 uint rpkt; /* Receive Packet Counter */
226 uint rfcs; /* Receive FCS Error Counter */
227 uint rmca; /* Receive Multicast Packet (Counter) */
228 uint rbca; /* Receive Broadcast Packet */
229 uint rxcf; /* Receive Control Frame Packet */
230 uint rxpf; /* Receive Pause Frame Packet */
231 uint rxuo; /* Receive Unknown OP Code */
232 uint raln; /* Receive Alignment Error */
233 uint rflr; /* Receive Frame Length Error */
234 uint rcde; /* Receive Code Error */
235 uint rcse; /* Receive Carrier Sense Error */
236 uint rund; /* Receive Undersize Packet */
237 uint rovr; /* Receive Oversize Packet */
238 uint rfrg; /* Receive Fragments */
239 uint rjbr; /* Receive Jabber */
240 uint rdrp; /* Receive Drop */
241 /* Transmit Counters */
242 uint tbyt; /* Transmit Byte Counter */
243 uint tpkt; /* Transmit Packet */
244 uint tmca; /* Transmit Multicast Packet */
245 uint tbca; /* Transmit Broadcast Packet */
246 uint txpf; /* Transmit Pause Control Frame */
247 uint tdfr; /* Transmit Deferral Packet */
248 uint tedf; /* Transmit Excessive Deferral Packet */
249 uint tscl; /* Transmit Single Collision Packet */
250 /* (0x2_n700) */
251 uint tmcl; /* Transmit Multiple Collision Packet */
252 uint tlcl; /* Transmit Late Collision Packet */
253 uint txcl; /* Transmit Excessive Collision Packet */
254 uint tncl; /* Transmit Total Collision */
255
256 uint res2;
257
258 uint tdrp; /* Transmit Drop Frame */
259 uint tjbr; /* Transmit Jabber Frame */
260 uint tfcs; /* Transmit FCS Error */
261 uint txcf; /* Transmit Control Frame */
262 uint tovr; /* Transmit Oversize Frame */
263 uint tund; /* Transmit Undersize Frame */
264 uint tfrg; /* Transmit Fragments Frame */
265 /* General Registers */
266 uint car1; /* Carry Register One */
267 uint car2; /* Carry Register Two */
268 uint cam1; /* Carry Register One Mask */
269 uint cam2; /* Carry Register Two Mask */
270} rmon_mib_t;
271
272typedef struct tsec_hash_regs
273{
274 uint iaddr0; /* Individual Address Register 0 */
275 uint iaddr1; /* Individual Address Register 1 */
276 uint iaddr2; /* Individual Address Register 2 */
277 uint iaddr3; /* Individual Address Register 3 */
278 uint iaddr4; /* Individual Address Register 4 */
279 uint iaddr5; /* Individual Address Register 5 */
280 uint iaddr6; /* Individual Address Register 6 */
281 uint iaddr7; /* Individual Address Register 7 */
282 uint res1[24];
283 uint gaddr0; /* Group Address Register 0 */
284 uint gaddr1; /* Group Address Register 1 */
285 uint gaddr2; /* Group Address Register 2 */
286 uint gaddr3; /* Group Address Register 3 */
287 uint gaddr4; /* Group Address Register 4 */
288 uint gaddr5; /* Group Address Register 5 */
289 uint gaddr6; /* Group Address Register 6 */
290 uint gaddr7; /* Group Address Register 7 */
291 uint res2[24];
292} tsec_hash_t;
293
Claudiu Manoilaec84bf2013-09-30 12:44:42 +0300294struct tsec {
wdenk42d1f032003-10-15 23:53:47 +0000295 /* General Control and Status Registers (0x2_n000) */
296 uint res000[4];
297
298 uint ievent; /* Interrupt Event */
299 uint imask; /* Interrupt Mask */
300 uint edis; /* Error Disabled */
301 uint res01c;
302 uint ecntrl; /* Ethernet Control */
303 uint minflr; /* Minimum Frame Length */
304 uint ptv; /* Pause Time Value */
305 uint dmactrl; /* DMA Control */
306 uint tbipa; /* TBI PHY Address */
307
308 uint res034[3];
309 uint res040[48];
310
311 /* Transmit Control and Status Registers (0x2_n100) */
312 uint tctrl; /* Transmit Control */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200313 uint tstat; /* Transmit Status */
wdenk42d1f032003-10-15 23:53:47 +0000314 uint res108;
315 uint tbdlen; /* Tx BD Data Length */
316 uint res110[5];
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200317 uint ctbptr; /* Current TxBD Pointer */
wdenk42d1f032003-10-15 23:53:47 +0000318 uint res128[23];
319 uint tbptr; /* TxBD Pointer */
320 uint res188[30];
321 /* (0x2_n200) */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200322 uint res200;
wdenk42d1f032003-10-15 23:53:47 +0000323 uint tbase; /* TxBD Base Address */
324 uint res208[42];
325 uint ostbd; /* Out of Sequence TxBD */
326 uint ostbdp; /* Out of Sequence Tx Data Buffer Pointer */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200327 uint res2b8[18];
wdenk42d1f032003-10-15 23:53:47 +0000328
329 /* Receive Control and Status Registers (0x2_n300) */
330 uint rctrl; /* Receive Control */
331 uint rstat; /* Receive Status */
332 uint res308;
333 uint rbdlen; /* RxBD Data Length */
334 uint res310[4];
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200335 uint res320;
336 uint crbptr; /* Current Receive Buffer Pointer */
wdenk42d1f032003-10-15 23:53:47 +0000337 uint res328[6];
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200338 uint mrblr; /* Maximum Receive Buffer Length */
wdenk42d1f032003-10-15 23:53:47 +0000339 uint res344[16];
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200340 uint rbptr; /* RxBD Pointer */
341 uint res388[30];
wdenk42d1f032003-10-15 23:53:47 +0000342 /* (0x2_n400) */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200343 uint res400;
344 uint rbase; /* RxBD Base Address */
345 uint res408[62];
wdenk42d1f032003-10-15 23:53:47 +0000346
347 /* MAC Registers (0x2_n500) */
348 uint maccfg1; /* MAC Configuration #1 */
349 uint maccfg2; /* MAC Configuration #2 */
350 uint ipgifg; /* Inter Packet Gap/Inter Frame Gap */
351 uint hafdup; /* Half-duplex */
352 uint maxfrm; /* Maximum Frame */
353 uint res514;
354 uint res518;
355
356 uint res51c;
357
Sandeep Gopalpetb9e186f2009-10-31 00:35:04 +0530358 uint resmdio[6];
wdenk42d1f032003-10-15 23:53:47 +0000359
360 uint res538;
361
362 uint ifstat; /* Interface Status */
363 uint macstnaddr1; /* Station Address, part 1 */
364 uint macstnaddr2; /* Station Address, part 2 */
365 uint res548[46];
366
367 /* (0x2_n600) */
368 uint res600[32];
369
370 /* RMON MIB Registers (0x2_n680-0x2_n73c) */
371 rmon_mib_t rmon;
372 uint res740[48];
373
374 /* Hash Function Registers (0x2_n800) */
375 tsec_hash_t hash;
376
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200377 uint res900[128];
wdenk42d1f032003-10-15 23:53:47 +0000378
379 /* Pattern Registers (0x2_nb00) */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200380 uint resb00[62];
381 uint attr; /* Default Attribute Register */
382 uint attreli; /* Default Attribute Extract Length and Index */
wdenk42d1f032003-10-15 23:53:47 +0000383
384 /* TSEC Future Expansion Space (0x2_nc00-0x2_nffc) */
385 uint resc00[256];
Claudiu Manoilaec84bf2013-09-30 12:44:42 +0300386};
wdenk42d1f032003-10-15 23:53:47 +0000387
Andy Fleming063c1262011-04-08 02:10:54 -0500388#define TSEC_GIGABIT (1 << 0)
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500389
Andy Fleming063c1262011-04-08 02:10:54 -0500390/* These flags currently only have meaning if we're using the eTSEC */
Peter Tyser5f6b1442009-11-09 13:09:48 -0600391#define TSEC_REDUCED (1 << 1) /* MAC-PHY interface uses RGMII */
392#define TSEC_SGMII (1 << 2) /* MAC-PHY interface uses SGMII */
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500393
wdenk97d80fc2004-06-09 00:34:46 +0000394struct tsec_private {
Claudiu Manoilaec84bf2013-09-30 12:44:42 +0300395 struct tsec __iomem *regs;
396 struct tsec_mii_mng __iomem *phyregs_sgmii;
Andy Fleming063c1262011-04-08 02:10:54 -0500397 struct phy_device *phydev;
398 phy_interface_t interface;
399 struct mii_dev *bus;
wdenk97d80fc2004-06-09 00:34:46 +0000400 uint phyaddr;
Andy Fleming063c1262011-04-08 02:10:54 -0500401 char mii_devname[16];
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500402 u32 flags;
wdenk97d80fc2004-06-09 00:34:46 +0000403};
404
Andy Flemingdd3d1f52008-08-31 16:33:25 -0500405struct tsec_info_struct {
Claudiu Manoilaec84bf2013-09-30 12:44:42 +0300406 struct tsec __iomem *regs;
407 struct tsec_mii_mng __iomem *miiregs_sgmii;
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500408 char *devname;
Andy Fleming063c1262011-04-08 02:10:54 -0500409 char *mii_devname;
410 phy_interface_t interface;
Andy Flemingdd3d1f52008-08-31 16:33:25 -0500411 unsigned int phyaddr;
412 u32 flags;
Andy Flemingdd3d1f52008-08-31 16:33:25 -0500413};
414
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500415int tsec_standard_init(bd_t *bis);
416int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsec_info, int num);
417
wdenk42d1f032003-10-15 23:53:47 +0000418#endif /* __TSEC_H */