TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2004 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
TsiChungLiew | f2208fb | 2007-07-05 23:13:58 -0500 | [diff] [blame] | 5 | * (C) Copyright 2007 Freescale Semiconductor, Inc. |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 6 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <malloc.h> |
| 29 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 30 | #include <command.h> |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 31 | #include <net.h> |
Ben Warren | 89973f8 | 2008-08-31 22:22:04 -0700 | [diff] [blame] | 32 | #include <netdev.h> |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 33 | #include <miiphy.h> |
| 34 | |
TsiChung Liew | 54bdcc9 | 2008-10-23 16:27:24 +0000 | [diff] [blame] | 35 | #include <asm/fec.h> |
| 36 | #include <asm/immap.h> |
| 37 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 38 | #undef ET_DEBUG |
| 39 | #undef MII_DEBUG |
| 40 | |
| 41 | /* Ethernet Transmit and Receive Buffers */ |
TsiChungLiew | f2208fb | 2007-07-05 23:13:58 -0500 | [diff] [blame] | 42 | #define DBUF_LENGTH 1520 |
| 43 | #define TX_BUF_CNT 2 |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 44 | #define PKT_MAXBUF_SIZE 1518 |
| 45 | #define PKT_MINBUF_SIZE 64 |
| 46 | #define PKT_MAXBLR_SIZE 1520 |
| 47 | #define LAST_PKTBUFSRX PKTBUFSRX - 1 |
| 48 | #define BD_ENET_RX_W_E (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY) |
| 49 | #define BD_ENET_TX_RDY_LST (BD_ENET_TX_READY | BD_ENET_TX_LAST) |
| 50 | |
| 51 | DECLARE_GLOBAL_DATA_PTR; |
| 52 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 53 | struct fec_info_s fec_info[] = { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 54 | #ifdef CONFIG_SYS_FEC0_IOBASE |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 55 | { |
| 56 | 0, /* index */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 57 | CONFIG_SYS_FEC0_IOBASE, /* io base */ |
| 58 | CONFIG_SYS_FEC0_PINMUX, /* gpio pin muxing */ |
| 59 | CONFIG_SYS_FEC0_MIIBASE, /* mii base */ |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 60 | -1, /* phy_addr */ |
| 61 | 0, /* duplex and speed */ |
| 62 | 0, /* phy name */ |
| 63 | 0, /* phyname init */ |
| 64 | 0, /* RX BD */ |
| 65 | 0, /* TX BD */ |
| 66 | 0, /* rx Index */ |
| 67 | 0, /* tx Index */ |
| 68 | 0, /* tx buffer */ |
| 69 | 0, /* initialized flag */ |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 70 | (struct fec_info_s *)-1, |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 71 | }, |
| 72 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 73 | #ifdef CONFIG_SYS_FEC1_IOBASE |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 74 | { |
| 75 | 1, /* index */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 76 | CONFIG_SYS_FEC1_IOBASE, /* io base */ |
| 77 | CONFIG_SYS_FEC1_PINMUX, /* gpio pin muxing */ |
| 78 | CONFIG_SYS_FEC1_MIIBASE, /* mii base */ |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 79 | -1, /* phy_addr */ |
| 80 | 0, /* duplex and speed */ |
| 81 | 0, /* phy name */ |
| 82 | 0, /* phy name init */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 83 | #ifdef CONFIG_SYS_FEC_BUF_USE_SRAM |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 84 | (cbd_t *)DBUF_LENGTH, /* RX BD */ |
| 85 | #else |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 86 | 0, /* RX BD */ |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 87 | #endif |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 88 | 0, /* TX BD */ |
| 89 | 0, /* rx Index */ |
| 90 | 0, /* tx Index */ |
| 91 | 0, /* tx buffer */ |
| 92 | 0, /* initialized flag */ |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 93 | (struct fec_info_s *)-1, |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 94 | } |
| 95 | #endif |
| 96 | }; |
| 97 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 98 | int fec_recv(struct eth_device *dev); |
| 99 | int fec_init(struct eth_device *dev, bd_t * bd); |
| 100 | void fec_halt(struct eth_device *dev); |
| 101 | void fec_reset(struct eth_device *dev); |
| 102 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 103 | void setFecDuplexSpeed(volatile fec_t * fecp, bd_t * bd, int dup_spd) |
| 104 | { |
| 105 | if ((dup_spd >> 16) == FULL) { |
| 106 | /* Set maximum frame length */ |
| 107 | fecp->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE) | FEC_RCR_MII_MODE | |
| 108 | FEC_RCR_PROM | 0x100; |
| 109 | fecp->tcr = FEC_TCR_FDEN; |
| 110 | } else { |
| 111 | /* Half duplex mode */ |
| 112 | fecp->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE) | |
| 113 | FEC_RCR_MII_MODE | FEC_RCR_DRT; |
| 114 | fecp->tcr &= ~FEC_TCR_FDEN; |
| 115 | } |
| 116 | |
| 117 | if ((dup_spd & 0xFFFF) == _100BASET) { |
TsiChung Liew | ff36fbb | 2008-05-28 13:06:25 -0500 | [diff] [blame] | 118 | #ifdef CONFIG_MCF5445x |
| 119 | fecp->rcr &= ~0x200; /* disabled 10T base */ |
| 120 | #endif |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 121 | #ifdef MII_DEBUG |
| 122 | printf("100Mbps\n"); |
| 123 | #endif |
| 124 | bd->bi_ethspeed = 100; |
| 125 | } else { |
TsiChung Liew | ff36fbb | 2008-05-28 13:06:25 -0500 | [diff] [blame] | 126 | #ifdef CONFIG_MCF5445x |
| 127 | fecp->rcr |= 0x200; /* enabled 10T base */ |
| 128 | #endif |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 129 | #ifdef MII_DEBUG |
| 130 | printf("10Mbps\n"); |
| 131 | #endif |
| 132 | bd->bi_ethspeed = 10; |
| 133 | } |
| 134 | } |
| 135 | |
Joe Hershberger | 10cbe3b | 2012-05-22 18:36:19 +0000 | [diff] [blame] | 136 | static int fec_send(struct eth_device *dev, void *packet, int length) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 137 | { |
| 138 | struct fec_info_s *info = dev->priv; |
| 139 | volatile fec_t *fecp = (fec_t *) (info->iobase); |
| 140 | int j, rc; |
| 141 | u16 phyStatus; |
| 142 | |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 143 | miiphy_read(dev->name, info->phy_addr, MII_BMSR, &phyStatus); |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 144 | |
| 145 | /* section 16.9.23.3 |
| 146 | * Wait for ready |
| 147 | */ |
| 148 | j = 0; |
| 149 | while ((info->txbd[info->txIdx].cbd_sc & BD_ENET_TX_READY) && |
| 150 | (j < MCFFEC_TOUT_LOOP)) { |
| 151 | udelay(1); |
| 152 | j++; |
| 153 | } |
| 154 | if (j >= MCFFEC_TOUT_LOOP) { |
| 155 | printf("TX not ready\n"); |
| 156 | } |
TsiChung | 0dca874 | 2007-07-10 15:45:43 -0500 | [diff] [blame] | 157 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 158 | info->txbd[info->txIdx].cbd_bufaddr = (uint) packet; |
| 159 | info->txbd[info->txIdx].cbd_datlen = length; |
| 160 | info->txbd[info->txIdx].cbd_sc |= BD_ENET_TX_RDY_LST; |
| 161 | |
| 162 | /* Activate transmit Buffer Descriptor polling */ |
| 163 | fecp->tdar = 0x01000000; /* Descriptor polling active */ |
| 164 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 165 | #ifndef CONFIG_SYS_FEC_BUF_USE_SRAM |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 166 | /* |
| 167 | * FEC unable to initial transmit data packet. |
Tsi-Chung Liew | f605479 | 2008-03-17 17:08:16 -0500 | [diff] [blame] | 168 | * A nop will ensure the descriptor polling active completed. |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 169 | * CF Internal RAM has shorter cycle access than DRAM. If use |
| 170 | * DRAM as Buffer descriptor and data, a nop is a must. |
| 171 | * Affect only V2 and V3. |
Tsi-Chung Liew | f605479 | 2008-03-17 17:08:16 -0500 | [diff] [blame] | 172 | */ |
Tsi-Chung Liew | f605479 | 2008-03-17 17:08:16 -0500 | [diff] [blame] | 173 | __asm__ ("nop"); |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 174 | |
Tsi-Chung Liew | f605479 | 2008-03-17 17:08:16 -0500 | [diff] [blame] | 175 | #endif |
| 176 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 177 | #ifdef CONFIG_SYS_UNIFY_CACHE |
TsiChungLiew | f2208fb | 2007-07-05 23:13:58 -0500 | [diff] [blame] | 178 | icache_invalid(); |
| 179 | #endif |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 180 | |
TsiChung | 0dca874 | 2007-07-10 15:45:43 -0500 | [diff] [blame] | 181 | j = 0; |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 182 | while ((info->txbd[info->txIdx].cbd_sc & BD_ENET_TX_READY) && |
| 183 | (j < MCFFEC_TOUT_LOOP)) { |
| 184 | udelay(1); |
| 185 | j++; |
| 186 | } |
| 187 | if (j >= MCFFEC_TOUT_LOOP) { |
| 188 | printf("TX timeout\n"); |
| 189 | } |
TsiChung | 0dca874 | 2007-07-10 15:45:43 -0500 | [diff] [blame] | 190 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 191 | #ifdef ET_DEBUG |
| 192 | printf("%s[%d] %s: cycles: %d status: %x retry cnt: %d\n", |
| 193 | __FILE__, __LINE__, __FUNCTION__, j, |
| 194 | info->txbd[info->txIdx].cbd_sc, |
| 195 | (info->txbd[info->txIdx].cbd_sc & 0x003C) >> 2); |
| 196 | #endif |
| 197 | |
TsiChung | 0dca874 | 2007-07-10 15:45:43 -0500 | [diff] [blame] | 198 | /* return only status bits */ |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 199 | rc = (info->txbd[info->txIdx].cbd_sc & BD_ENET_TX_STATS); |
| 200 | info->txIdx = (info->txIdx + 1) % TX_BUF_CNT; |
| 201 | |
| 202 | return rc; |
| 203 | } |
| 204 | |
| 205 | int fec_recv(struct eth_device *dev) |
| 206 | { |
| 207 | struct fec_info_s *info = dev->priv; |
| 208 | volatile fec_t *fecp = (fec_t *) (info->iobase); |
| 209 | int length; |
| 210 | |
| 211 | for (;;) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 212 | #ifndef CONFIG_SYS_FEC_BUF_USE_SRAM |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 213 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 214 | #ifdef CONFIG_SYS_UNIFY_CACHE |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 215 | icache_invalid(); |
TsiChung | 0dca874 | 2007-07-10 15:45:43 -0500 | [diff] [blame] | 216 | #endif |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 217 | /* section 16.9.23.2 */ |
| 218 | if (info->rxbd[info->rxIdx].cbd_sc & BD_ENET_RX_EMPTY) { |
| 219 | length = -1; |
| 220 | break; /* nothing received - leave for() loop */ |
| 221 | } |
| 222 | |
| 223 | length = info->rxbd[info->rxIdx].cbd_datlen; |
| 224 | |
| 225 | if (info->rxbd[info->rxIdx].cbd_sc & 0x003f) { |
| 226 | printf("%s[%d] err: %x\n", |
| 227 | __FUNCTION__, __LINE__, |
| 228 | info->rxbd[info->rxIdx].cbd_sc); |
| 229 | #ifdef ET_DEBUG |
| 230 | printf("%s[%d] err: %x\n", |
| 231 | __FUNCTION__, __LINE__, |
| 232 | info->rxbd[info->rxIdx].cbd_sc); |
| 233 | #endif |
| 234 | } else { |
| 235 | |
| 236 | length -= 4; |
| 237 | /* Pass the packet up to the protocol layers. */ |
| 238 | NetReceive(NetRxPackets[info->rxIdx], length); |
| 239 | |
| 240 | fecp->eir |= FEC_EIR_RXF; |
| 241 | } |
| 242 | |
| 243 | /* Give the buffer back to the FEC. */ |
| 244 | info->rxbd[info->rxIdx].cbd_datlen = 0; |
| 245 | |
| 246 | /* wrap around buffer index when necessary */ |
| 247 | if (info->rxIdx == LAST_PKTBUFSRX) { |
| 248 | info->rxbd[PKTBUFSRX - 1].cbd_sc = BD_ENET_RX_W_E; |
| 249 | info->rxIdx = 0; |
| 250 | } else { |
| 251 | info->rxbd[info->rxIdx].cbd_sc = BD_ENET_RX_EMPTY; |
| 252 | info->rxIdx++; |
| 253 | } |
| 254 | |
| 255 | /* Try to fill Buffer Descriptors */ |
| 256 | fecp->rdar = 0x01000000; /* Descriptor polling active */ |
| 257 | } |
| 258 | |
| 259 | return length; |
| 260 | } |
| 261 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 262 | #ifdef ET_DEBUG |
| 263 | void dbgFecRegs(struct eth_device *dev) |
| 264 | { |
| 265 | struct fec_info_s *info = dev->priv; |
| 266 | volatile fec_t *fecp = (fec_t *) (info->iobase); |
| 267 | |
| 268 | printf("=====\n"); |
| 269 | printf("ievent %x - %x\n", (int)&fecp->eir, fecp->eir); |
| 270 | printf("imask %x - %x\n", (int)&fecp->eimr, fecp->eimr); |
| 271 | printf("r_des_active %x - %x\n", (int)&fecp->rdar, fecp->rdar); |
| 272 | printf("x_des_active %x - %x\n", (int)&fecp->tdar, fecp->tdar); |
| 273 | printf("ecntrl %x - %x\n", (int)&fecp->ecr, fecp->ecr); |
| 274 | printf("mii_mframe %x - %x\n", (int)&fecp->mmfr, fecp->mmfr); |
| 275 | printf("mii_speed %x - %x\n", (int)&fecp->mscr, fecp->mscr); |
| 276 | printf("mii_ctrlstat %x - %x\n", (int)&fecp->mibc, fecp->mibc); |
| 277 | printf("r_cntrl %x - %x\n", (int)&fecp->rcr, fecp->rcr); |
| 278 | printf("x_cntrl %x - %x\n", (int)&fecp->tcr, fecp->tcr); |
| 279 | printf("padr_l %x - %x\n", (int)&fecp->palr, fecp->palr); |
| 280 | printf("padr_u %x - %x\n", (int)&fecp->paur, fecp->paur); |
| 281 | printf("op_pause %x - %x\n", (int)&fecp->opd, fecp->opd); |
| 282 | printf("iadr_u %x - %x\n", (int)&fecp->iaur, fecp->iaur); |
| 283 | printf("iadr_l %x - %x\n", (int)&fecp->ialr, fecp->ialr); |
| 284 | printf("gadr_u %x - %x\n", (int)&fecp->gaur, fecp->gaur); |
| 285 | printf("gadr_l %x - %x\n", (int)&fecp->galr, fecp->galr); |
| 286 | printf("x_wmrk %x - %x\n", (int)&fecp->tfwr, fecp->tfwr); |
| 287 | printf("r_bound %x - %x\n", (int)&fecp->frbr, fecp->frbr); |
| 288 | printf("r_fstart %x - %x\n", (int)&fecp->frsr, fecp->frsr); |
| 289 | printf("r_drng %x - %x\n", (int)&fecp->erdsr, fecp->erdsr); |
| 290 | printf("x_drng %x - %x\n", (int)&fecp->etdsr, fecp->etdsr); |
| 291 | printf("r_bufsz %x - %x\n", (int)&fecp->emrbr, fecp->emrbr); |
| 292 | |
| 293 | printf("\n"); |
| 294 | printf("rmon_t_drop %x - %x\n", (int)&fecp->rmon_t_drop, |
| 295 | fecp->rmon_t_drop); |
| 296 | printf("rmon_t_packets %x - %x\n", (int)&fecp->rmon_t_packets, |
| 297 | fecp->rmon_t_packets); |
| 298 | printf("rmon_t_bc_pkt %x - %x\n", (int)&fecp->rmon_t_bc_pkt, |
| 299 | fecp->rmon_t_bc_pkt); |
| 300 | printf("rmon_t_mc_pkt %x - %x\n", (int)&fecp->rmon_t_mc_pkt, |
| 301 | fecp->rmon_t_mc_pkt); |
| 302 | printf("rmon_t_crc_align %x - %x\n", (int)&fecp->rmon_t_crc_align, |
| 303 | fecp->rmon_t_crc_align); |
| 304 | printf("rmon_t_undersize %x - %x\n", (int)&fecp->rmon_t_undersize, |
| 305 | fecp->rmon_t_undersize); |
| 306 | printf("rmon_t_oversize %x - %x\n", (int)&fecp->rmon_t_oversize, |
| 307 | fecp->rmon_t_oversize); |
| 308 | printf("rmon_t_frag %x - %x\n", (int)&fecp->rmon_t_frag, |
| 309 | fecp->rmon_t_frag); |
| 310 | printf("rmon_t_jab %x - %x\n", (int)&fecp->rmon_t_jab, |
| 311 | fecp->rmon_t_jab); |
| 312 | printf("rmon_t_col %x - %x\n", (int)&fecp->rmon_t_col, |
| 313 | fecp->rmon_t_col); |
| 314 | printf("rmon_t_p64 %x - %x\n", (int)&fecp->rmon_t_p64, |
| 315 | fecp->rmon_t_p64); |
| 316 | printf("rmon_t_p65to127 %x - %x\n", (int)&fecp->rmon_t_p65to127, |
| 317 | fecp->rmon_t_p65to127); |
| 318 | printf("rmon_t_p128to255 %x - %x\n", (int)&fecp->rmon_t_p128to255, |
| 319 | fecp->rmon_t_p128to255); |
| 320 | printf("rmon_t_p256to511 %x - %x\n", (int)&fecp->rmon_t_p256to511, |
| 321 | fecp->rmon_t_p256to511); |
| 322 | printf("rmon_t_p512to1023 %x - %x\n", (int)&fecp->rmon_t_p512to1023, |
| 323 | fecp->rmon_t_p512to1023); |
| 324 | printf("rmon_t_p1024to2047 %x - %x\n", (int)&fecp->rmon_t_p1024to2047, |
| 325 | fecp->rmon_t_p1024to2047); |
| 326 | printf("rmon_t_p_gte2048 %x - %x\n", (int)&fecp->rmon_t_p_gte2048, |
| 327 | fecp->rmon_t_p_gte2048); |
| 328 | printf("rmon_t_octets %x - %x\n", (int)&fecp->rmon_t_octets, |
| 329 | fecp->rmon_t_octets); |
| 330 | |
| 331 | printf("\n"); |
| 332 | printf("ieee_t_drop %x - %x\n", (int)&fecp->ieee_t_drop, |
| 333 | fecp->ieee_t_drop); |
| 334 | printf("ieee_t_frame_ok %x - %x\n", (int)&fecp->ieee_t_frame_ok, |
| 335 | fecp->ieee_t_frame_ok); |
| 336 | printf("ieee_t_1col %x - %x\n", (int)&fecp->ieee_t_1col, |
| 337 | fecp->ieee_t_1col); |
| 338 | printf("ieee_t_mcol %x - %x\n", (int)&fecp->ieee_t_mcol, |
| 339 | fecp->ieee_t_mcol); |
| 340 | printf("ieee_t_def %x - %x\n", (int)&fecp->ieee_t_def, |
| 341 | fecp->ieee_t_def); |
| 342 | printf("ieee_t_lcol %x - %x\n", (int)&fecp->ieee_t_lcol, |
| 343 | fecp->ieee_t_lcol); |
| 344 | printf("ieee_t_excol %x - %x\n", (int)&fecp->ieee_t_excol, |
| 345 | fecp->ieee_t_excol); |
| 346 | printf("ieee_t_macerr %x - %x\n", (int)&fecp->ieee_t_macerr, |
| 347 | fecp->ieee_t_macerr); |
| 348 | printf("ieee_t_cserr %x - %x\n", (int)&fecp->ieee_t_cserr, |
| 349 | fecp->ieee_t_cserr); |
| 350 | printf("ieee_t_sqe %x - %x\n", (int)&fecp->ieee_t_sqe, |
| 351 | fecp->ieee_t_sqe); |
| 352 | printf("ieee_t_fdxfc %x - %x\n", (int)&fecp->ieee_t_fdxfc, |
| 353 | fecp->ieee_t_fdxfc); |
| 354 | printf("ieee_t_octets_ok %x - %x\n", (int)&fecp->ieee_t_octets_ok, |
| 355 | fecp->ieee_t_octets_ok); |
| 356 | |
| 357 | printf("\n"); |
| 358 | printf("rmon_r_drop %x - %x\n", (int)&fecp->rmon_r_drop, |
| 359 | fecp->rmon_r_drop); |
| 360 | printf("rmon_r_packets %x - %x\n", (int)&fecp->rmon_r_packets, |
| 361 | fecp->rmon_r_packets); |
| 362 | printf("rmon_r_bc_pkt %x - %x\n", (int)&fecp->rmon_r_bc_pkt, |
| 363 | fecp->rmon_r_bc_pkt); |
| 364 | printf("rmon_r_mc_pkt %x - %x\n", (int)&fecp->rmon_r_mc_pkt, |
| 365 | fecp->rmon_r_mc_pkt); |
| 366 | printf("rmon_r_crc_align %x - %x\n", (int)&fecp->rmon_r_crc_align, |
| 367 | fecp->rmon_r_crc_align); |
| 368 | printf("rmon_r_undersize %x - %x\n", (int)&fecp->rmon_r_undersize, |
| 369 | fecp->rmon_r_undersize); |
| 370 | printf("rmon_r_oversize %x - %x\n", (int)&fecp->rmon_r_oversize, |
| 371 | fecp->rmon_r_oversize); |
| 372 | printf("rmon_r_frag %x - %x\n", (int)&fecp->rmon_r_frag, |
| 373 | fecp->rmon_r_frag); |
| 374 | printf("rmon_r_jab %x - %x\n", (int)&fecp->rmon_r_jab, |
| 375 | fecp->rmon_r_jab); |
| 376 | printf("rmon_r_p64 %x - %x\n", (int)&fecp->rmon_r_p64, |
| 377 | fecp->rmon_r_p64); |
| 378 | printf("rmon_r_p65to127 %x - %x\n", (int)&fecp->rmon_r_p65to127, |
| 379 | fecp->rmon_r_p65to127); |
| 380 | printf("rmon_r_p128to255 %x - %x\n", (int)&fecp->rmon_r_p128to255, |
| 381 | fecp->rmon_r_p128to255); |
| 382 | printf("rmon_r_p256to511 %x - %x\n", (int)&fecp->rmon_r_p256to511, |
| 383 | fecp->rmon_r_p256to511); |
| 384 | printf("rmon_r_p512to1023 %x - %x\n", (int)&fecp->rmon_r_p512to1023, |
| 385 | fecp->rmon_r_p512to1023); |
| 386 | printf("rmon_r_p1024to2047 %x - %x\n", (int)&fecp->rmon_r_p1024to2047, |
| 387 | fecp->rmon_r_p1024to2047); |
| 388 | printf("rmon_r_p_gte2048 %x - %x\n", (int)&fecp->rmon_r_p_gte2048, |
| 389 | fecp->rmon_r_p_gte2048); |
| 390 | printf("rmon_r_octets %x - %x\n", (int)&fecp->rmon_r_octets, |
| 391 | fecp->rmon_r_octets); |
| 392 | |
| 393 | printf("\n"); |
| 394 | printf("ieee_r_drop %x - %x\n", (int)&fecp->ieee_r_drop, |
| 395 | fecp->ieee_r_drop); |
| 396 | printf("ieee_r_frame_ok %x - %x\n", (int)&fecp->ieee_r_frame_ok, |
| 397 | fecp->ieee_r_frame_ok); |
| 398 | printf("ieee_r_crc %x - %x\n", (int)&fecp->ieee_r_crc, |
| 399 | fecp->ieee_r_crc); |
| 400 | printf("ieee_r_align %x - %x\n", (int)&fecp->ieee_r_align, |
| 401 | fecp->ieee_r_align); |
| 402 | printf("ieee_r_macerr %x - %x\n", (int)&fecp->ieee_r_macerr, |
| 403 | fecp->ieee_r_macerr); |
| 404 | printf("ieee_r_fdxfc %x - %x\n", (int)&fecp->ieee_r_fdxfc, |
| 405 | fecp->ieee_r_fdxfc); |
| 406 | printf("ieee_r_octets_ok %x - %x\n", (int)&fecp->ieee_r_octets_ok, |
| 407 | fecp->ieee_r_octets_ok); |
| 408 | |
| 409 | printf("\n\n\n"); |
| 410 | } |
| 411 | #endif |
| 412 | |
| 413 | int fec_init(struct eth_device *dev, bd_t * bd) |
| 414 | { |
| 415 | struct fec_info_s *info = dev->priv; |
| 416 | volatile fec_t *fecp = (fec_t *) (info->iobase); |
| 417 | int i; |
Mike Frysinger | d3f8714 | 2009-02-11 19:01:26 -0500 | [diff] [blame] | 418 | uchar ea[6]; |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 419 | |
| 420 | fecpin_setclear(dev, 1); |
| 421 | |
| 422 | fec_reset(dev); |
| 423 | |
TsiChungLiew | ab77bc5 | 2007-08-15 15:39:17 -0500 | [diff] [blame] | 424 | #if defined(CONFIG_CMD_MII) || defined (CONFIG_MII) || \ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 425 | defined (CONFIG_SYS_DISCOVER_PHY) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 426 | |
| 427 | mii_init(); |
| 428 | |
| 429 | setFecDuplexSpeed(fecp, bd, info->dup_spd); |
| 430 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 431 | #ifndef CONFIG_SYS_DISCOVER_PHY |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 432 | setFecDuplexSpeed(fecp, bd, (FECDUPLEX << 16) | FECSPEED); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 433 | #endif /* ifndef CONFIG_SYS_DISCOVER_PHY */ |
TsiChungLiew | ab77bc5 | 2007-08-15 15:39:17 -0500 | [diff] [blame] | 434 | #endif /* CONFIG_CMD_MII || CONFIG_MII */ |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 435 | |
| 436 | /* We use strictly polling mode only */ |
| 437 | fecp->eimr = 0; |
| 438 | |
| 439 | /* Clear any pending interrupt */ |
| 440 | fecp->eir = 0xffffffff; |
| 441 | |
| 442 | /* Set station address */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 443 | if ((u32) fecp == CONFIG_SYS_FEC0_IOBASE) { |
| 444 | #ifdef CONFIG_SYS_FEC1_IOBASE |
| 445 | volatile fec_t *fecp1 = (fec_t *) (CONFIG_SYS_FEC1_IOBASE); |
Mike Frysinger | d3f8714 | 2009-02-11 19:01:26 -0500 | [diff] [blame] | 446 | eth_getenv_enetaddr("eth1addr", ea); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 447 | fecp1->palr = |
| 448 | (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]); |
| 449 | fecp1->paur = (ea[4] << 24) | (ea[5] << 16); |
| 450 | #endif |
Mike Frysinger | d3f8714 | 2009-02-11 19:01:26 -0500 | [diff] [blame] | 451 | eth_getenv_enetaddr("ethaddr", ea); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 452 | fecp->palr = |
| 453 | (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]); |
| 454 | fecp->paur = (ea[4] << 24) | (ea[5] << 16); |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 455 | } else { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 456 | #ifdef CONFIG_SYS_FEC0_IOBASE |
| 457 | volatile fec_t *fecp0 = (fec_t *) (CONFIG_SYS_FEC0_IOBASE); |
Mike Frysinger | d3f8714 | 2009-02-11 19:01:26 -0500 | [diff] [blame] | 458 | eth_getenv_enetaddr("ethaddr", ea); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 459 | fecp0->palr = |
| 460 | (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]); |
| 461 | fecp0->paur = (ea[4] << 24) | (ea[5] << 16); |
| 462 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 463 | #ifdef CONFIG_SYS_FEC1_IOBASE |
Mike Frysinger | d3f8714 | 2009-02-11 19:01:26 -0500 | [diff] [blame] | 464 | eth_getenv_enetaddr("eth1addr", ea); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 465 | fecp->palr = |
| 466 | (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]); |
| 467 | fecp->paur = (ea[4] << 24) | (ea[5] << 16); |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 468 | #endif |
| 469 | } |
| 470 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 471 | /* Clear unicast address hash table */ |
| 472 | fecp->iaur = 0; |
| 473 | fecp->ialr = 0; |
| 474 | |
| 475 | /* Clear multicast address hash table */ |
| 476 | fecp->gaur = 0; |
| 477 | fecp->galr = 0; |
| 478 | |
| 479 | /* Set maximum receive buffer size. */ |
| 480 | fecp->emrbr = PKT_MAXBLR_SIZE; |
| 481 | |
| 482 | /* |
| 483 | * Setup Buffers and Buffer Desriptors |
| 484 | */ |
| 485 | info->rxIdx = 0; |
| 486 | info->txIdx = 0; |
| 487 | |
| 488 | /* |
| 489 | * Setup Receiver Buffer Descriptors (13.14.24.18) |
| 490 | * Settings: |
| 491 | * Empty, Wrap |
| 492 | */ |
| 493 | for (i = 0; i < PKTBUFSRX; i++) { |
| 494 | info->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY; |
| 495 | info->rxbd[i].cbd_datlen = 0; /* Reset */ |
| 496 | info->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i]; |
| 497 | } |
| 498 | info->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP; |
| 499 | |
| 500 | /* |
| 501 | * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19) |
| 502 | * Settings: |
| 503 | * Last, Tx CRC |
| 504 | */ |
| 505 | for (i = 0; i < TX_BUF_CNT; i++) { |
| 506 | info->txbd[i].cbd_sc = BD_ENET_TX_LAST | BD_ENET_TX_TC; |
| 507 | info->txbd[i].cbd_datlen = 0; /* Reset */ |
| 508 | info->txbd[i].cbd_bufaddr = (uint) (&info->txbuf[0]); |
| 509 | } |
| 510 | info->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP; |
| 511 | |
| 512 | /* Set receive and transmit descriptor base */ |
| 513 | fecp->erdsr = (unsigned int)(&info->rxbd[0]); |
| 514 | fecp->etdsr = (unsigned int)(&info->txbd[0]); |
| 515 | |
| 516 | /* Now enable the transmit and receive processing */ |
| 517 | fecp->ecr |= FEC_ECR_ETHER_EN; |
| 518 | |
| 519 | /* And last, try to fill Rx Buffer Descriptors */ |
| 520 | fecp->rdar = 0x01000000; /* Descriptor polling active */ |
| 521 | |
| 522 | return 1; |
| 523 | } |
| 524 | |
| 525 | void fec_reset(struct eth_device *dev) |
| 526 | { |
| 527 | struct fec_info_s *info = dev->priv; |
| 528 | volatile fec_t *fecp = (fec_t *) (info->iobase); |
| 529 | int i; |
| 530 | |
| 531 | fecp->ecr = FEC_ECR_RESET; |
| 532 | for (i = 0; (fecp->ecr & FEC_ECR_RESET) && (i < FEC_RESET_DELAY); ++i) { |
| 533 | udelay(1); |
| 534 | } |
| 535 | if (i == FEC_RESET_DELAY) { |
| 536 | printf("FEC_RESET_DELAY timeout\n"); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | void fec_halt(struct eth_device *dev) |
| 541 | { |
| 542 | struct fec_info_s *info = dev->priv; |
| 543 | |
| 544 | fec_reset(dev); |
| 545 | |
| 546 | fecpin_setclear(dev, 0); |
| 547 | |
| 548 | info->rxIdx = info->txIdx = 0; |
| 549 | memset(info->rxbd, 0, PKTBUFSRX * sizeof(cbd_t)); |
| 550 | memset(info->txbd, 0, TX_BUF_CNT * sizeof(cbd_t)); |
| 551 | memset(info->txbuf, 0, DBUF_LENGTH); |
| 552 | } |
| 553 | |
| 554 | int mcffec_initialize(bd_t * bis) |
| 555 | { |
| 556 | struct eth_device *dev; |
| 557 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 558 | #ifdef CONFIG_SYS_FEC_BUF_USE_SRAM |
| 559 | u32 tmp = CONFIG_SYS_INIT_RAM_ADDR + 0x1000; |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 560 | #endif |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 561 | |
| 562 | for (i = 0; i < sizeof(fec_info) / sizeof(fec_info[0]); i++) { |
| 563 | |
TsiChungLiew | f2208fb | 2007-07-05 23:13:58 -0500 | [diff] [blame] | 564 | dev = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 565 | (struct eth_device *)memalign(CONFIG_SYS_CACHELINE_SIZE, |
TsiChungLiew | f2208fb | 2007-07-05 23:13:58 -0500 | [diff] [blame] | 566 | sizeof *dev); |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 567 | if (dev == NULL) |
| 568 | hang(); |
| 569 | |
| 570 | memset(dev, 0, sizeof(*dev)); |
| 571 | |
| 572 | sprintf(dev->name, "FEC%d", fec_info[i].index); |
| 573 | |
| 574 | dev->priv = &fec_info[i]; |
| 575 | dev->init = fec_init; |
| 576 | dev->halt = fec_halt; |
| 577 | dev->send = fec_send; |
| 578 | dev->recv = fec_recv; |
| 579 | |
| 580 | /* setup Receive and Transmit buffer descriptor */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 581 | #ifdef CONFIG_SYS_FEC_BUF_USE_SRAM |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 582 | fec_info[i].rxbd = (cbd_t *)((u32)fec_info[i].rxbd + tmp); |
| 583 | tmp = (u32)fec_info[i].rxbd; |
| 584 | fec_info[i].txbd = |
| 585 | (cbd_t *)((u32)fec_info[i].txbd + tmp + |
| 586 | (PKTBUFSRX * sizeof(cbd_t))); |
| 587 | tmp = (u32)fec_info[i].txbd; |
| 588 | fec_info[i].txbuf = |
| 589 | (char *)((u32)fec_info[i].txbuf + tmp + |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 590 | (CONFIG_SYS_TX_ETH_BUFFER * sizeof(cbd_t))); |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 591 | tmp = (u32)fec_info[i].txbuf; |
| 592 | #else |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 593 | fec_info[i].rxbd = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 594 | (cbd_t *) memalign(CONFIG_SYS_CACHELINE_SIZE, |
TsiChungLiew | f2208fb | 2007-07-05 23:13:58 -0500 | [diff] [blame] | 595 | (PKTBUFSRX * sizeof(cbd_t))); |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 596 | fec_info[i].txbd = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 597 | (cbd_t *) memalign(CONFIG_SYS_CACHELINE_SIZE, |
TsiChungLiew | f2208fb | 2007-07-05 23:13:58 -0500 | [diff] [blame] | 598 | (TX_BUF_CNT * sizeof(cbd_t))); |
| 599 | fec_info[i].txbuf = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 600 | (char *)memalign(CONFIG_SYS_CACHELINE_SIZE, DBUF_LENGTH); |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 601 | #endif |
| 602 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 603 | #ifdef ET_DEBUG |
| 604 | printf("rxbd %x txbd %x\n", |
| 605 | (int)fec_info[i].rxbd, (int)fec_info[i].txbd); |
| 606 | #endif |
| 607 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 608 | fec_info[i].phy_name = (char *)memalign(CONFIG_SYS_CACHELINE_SIZE, 32); |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 609 | |
| 610 | eth_register(dev); |
| 611 | |
TsiChungLiew | ab77bc5 | 2007-08-15 15:39:17 -0500 | [diff] [blame] | 612 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 613 | miiphy_register(dev->name, |
| 614 | mcffec_miiphy_read, mcffec_miiphy_write); |
| 615 | #endif |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 616 | if (i > 0) |
| 617 | fec_info[i - 1].next = &fec_info[i]; |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 618 | } |
TsiChung Liew | 1803f7f | 2008-08-19 21:26:32 +0000 | [diff] [blame] | 619 | fec_info[i - 1].next = &fec_info[0]; |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 620 | |
| 621 | /* default speed */ |
| 622 | bis->bi_ethspeed = 10; |
| 623 | |
Ben Warren | 86882b8 | 2008-08-26 22:16:25 -0700 | [diff] [blame] | 624 | return 0; |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 625 | } |