3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * This file is based on mpc4200fec.c,
6 * (C) Copyright Motorola, Inc., 2000
17 /* #define DEBUG 0x28 */
19 #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI) && \
20 defined(CONFIG_MPC5xxx_FEC)
23 static void tfifo_print(mpc5xxx_fec_priv *fec);
24 static void rfifo_print(mpc5xxx_fec_priv *fec);
28 static uint32 local_crc32(char *string, unsigned int crc_value, int len);
32 uint8 data[1500]; /* actual data */
33 int length; /* actual length */
34 int used; /* buffer in use or not */
35 uint8 head[16]; /* MAC header(6 + 6 + 2) + 2(aligned) */
38 /********************************************************************/
40 static void mpc5xxx_fec_phydump (void)
43 uint8 phyAddr = CONFIG_PHY_ADDR;
45 #if CONFIG_PHY_TYPE == 0x79c874 /* AMD Am79C874 */
46 /* regs to print: 0...7, 16...19, 21, 23, 24 */
47 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
48 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
50 /* regs to print: 0...8, 16...20 */
51 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
52 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56 for (i = 0; i < 32; i++) {
58 miiphy_read(phyAddr, i, &phyStatus);
59 printf("Mii reg %d: 0x%04x\n", i, phyStatus);
65 /********************************************************************/
66 static int mpc5xxx_fec_rbd_init(mpc5xxx_fec_priv *fec)
72 for (ix = 0; ix < FEC_RBD_NUM; ix++) {
74 data = (char *)malloc(FEC_MAX_PKT_SIZE);
76 printf ("RBD INIT FAILED\n");
79 fec->rbdBase[ix].dataPointer = (uint32)data;
81 fec->rbdBase[ix].status = FEC_RBD_EMPTY;
82 fec->rbdBase[ix].dataLength = 0;
87 * have the last RBD to close the ring
89 fec->rbdBase[ix - 1].status |= FEC_RBD_WRAP;
95 /********************************************************************/
96 static void mpc5xxx_fec_tbd_init(mpc5xxx_fec_priv *fec)
100 for (ix = 0; ix < FEC_TBD_NUM; ix++) {
101 fec->tbdBase[ix].status = 0;
105 * Have the last TBD to close the ring
107 fec->tbdBase[ix - 1].status |= FEC_TBD_WRAP;
110 * Initialize some indices
113 fec->usedTbdIndex = 0;
114 fec->cleanTbdNum = FEC_TBD_NUM;
117 /********************************************************************/
118 static void mpc5xxx_fec_rbd_clean(mpc5xxx_fec_priv *fec, FEC_RBD * pRbd)
121 * Reset buffer descriptor as empty
123 if ((fec->rbdIndex) == (FEC_RBD_NUM - 1))
124 pRbd->status = (FEC_RBD_WRAP | FEC_RBD_EMPTY);
126 pRbd->status = FEC_RBD_EMPTY;
128 pRbd->dataLength = 0;
131 * Now, we have an empty RxBD, restart the SmartDMA receive task
133 SDMA_TASK_ENABLE(FEC_RECV_TASK_NO);
138 fec->rbdIndex = (fec->rbdIndex + 1) % FEC_RBD_NUM;
141 /********************************************************************/
142 static void mpc5xxx_fec_tbd_scrub(mpc5xxx_fec_priv *fec)
147 printf ("tbd_scrub: fec->cleanTbdNum = %d, fec->usedTbdIndex = %d\n",
148 fec->cleanTbdNum, fec->usedTbdIndex);
152 * process all the consumed TBDs
154 while (fec->cleanTbdNum < FEC_TBD_NUM) {
155 pUsedTbd = &fec->tbdBase[fec->usedTbdIndex];
156 if (pUsedTbd->status & FEC_TBD_READY) {
158 printf("Cannot clean TBD %d, in use\n", fec->cleanTbdNum);
164 * clean this buffer descriptor
166 if (fec->usedTbdIndex == (FEC_TBD_NUM - 1))
167 pUsedTbd->status = FEC_TBD_WRAP;
169 pUsedTbd->status = 0;
172 * update some indeces for a correct handling of the TBD ring
175 fec->usedTbdIndex = (fec->usedTbdIndex + 1) % FEC_TBD_NUM;
179 /********************************************************************/
180 static void mpc5xxx_fec_set_hwaddr(mpc5xxx_fec_priv *fec, char *mac)
182 uint8 currByte; /* byte for which to compute the CRC */
183 int byte; /* loop - counter */
184 int bit; /* loop - counter */
185 uint32 crc = 0xffffffff; /* initial value */
188 * The algorithm used is the following:
189 * we loop on each of the six bytes of the provided address,
190 * and we compute the CRC by left-shifting the previous
191 * value by one position, so that each bit in the current
192 * byte of the address may contribute the calculation. If
193 * the latter and the MSB in the CRC are different, then
194 * the CRC value so computed is also ex-ored with the
195 * "polynomium generator". The current byte of the address
196 * is also shifted right by one bit at each iteration.
197 * This is because the CRC generatore in hardware is implemented
198 * as a shift-register with as many ex-ores as the radixes
199 * in the polynomium. This suggests that we represent the
200 * polynomiumm itself as a 32-bit constant.
202 for (byte = 0; byte < 6; byte++) {
203 currByte = mac[byte];
204 for (bit = 0; bit < 8; bit++) {
205 if ((currByte & 0x01) ^ (crc & 0x01)) {
207 crc = crc ^ 0xedb88320;
218 * Set individual hash table register
221 fec->eth->iaddr1 = (1 << (crc - 32));
222 fec->eth->iaddr2 = 0;
224 fec->eth->iaddr1 = 0;
225 fec->eth->iaddr2 = (1 << crc);
229 * Set physical address
231 fec->eth->paddr1 = (mac[0] << 24) + (mac[1] << 16) + (mac[2] << 8) + mac[3];
232 fec->eth->paddr2 = (mac[4] << 24) + (mac[5] << 16) + 0x8808;
235 /********************************************************************/
236 static int mpc5xxx_fec_init(struct eth_device *dev, bd_t * bis)
238 DECLARE_GLOBAL_DATA_PTR;
239 mpc5xxx_fec_priv *fec = (mpc5xxx_fec_priv *)dev->priv;
240 struct mpc5xxx_sdma *sdma = (struct mpc5xxx_sdma *)MPC5XXX_SDMA;
241 const uint8 phyAddr = CONFIG_PHY_ADDR; /* Only one PHY */
244 printf ("mpc5xxx_fec_init... Begin\n");
248 * Initialize RxBD/TxBD rings
250 mpc5xxx_fec_rbd_init(fec);
251 mpc5xxx_fec_tbd_init(fec);
254 * Initialize GPIO pins
256 if (fec->xcv_type == SEVENWIRE) {
257 /* 10MBit with 7-wire operation */
258 *(vu_long *)MPC5XXX_GPS_PORT_CONFIG |= 0x00020000;
260 /* 100MBit with MD operation */
261 *(vu_long *)MPC5XXX_GPS_PORT_CONFIG |= 0x00050000;
265 * Clear FEC-Lite interrupt event register(IEVENT)
267 fec->eth->ievent = 0xffffffff;
270 * Set interrupt mask register
272 fec->eth->imask = 0x00000000;
275 * Set FEC-Lite receive control register(R_CNTRL):
277 if (fec->xcv_type == SEVENWIRE) {
279 * Frame length=1518; 7-wire mode
281 fec->eth->r_cntrl = 0x05ee0020; /*0x05ee0000;FIXME */
284 * Frame length=1518; MII mode;
286 fec->eth->r_cntrl = 0x05ee0024; /*0x05ee0004;FIXME */
289 if (fec->xcv_type == SEVENWIRE) {
291 * Set FEC-Lite transmit control register(X_CNTRL):
293 /*fec->eth->x_cntrl = 0x00000002; */ /* half-duplex, heartbeat */
294 fec->eth->x_cntrl = 0x00000000; /* half-duplex, heartbeat disabled */
296 /*fec->eth->x_cntrl = 0x00000006; */ /* full-duplex, heartbeat */
297 fec->eth->x_cntrl = 0x00000004; /* full-duplex, heartbeat disabled */
300 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
301 * and do not drop the Preamble.
303 fec->eth->mii_speed = (((gd->ipb_clk >> 20) / 5) << 1); /* No MII for 7-wire mode */
307 * Set Opcode/Pause Duration Register
309 fec->eth->op_pause = 0x00010020; /*FIXME0xffff0020; */
312 * Set Rx FIFO alarm and granularity value
314 fec->eth->rfifo_cntrl = 0x0c000000;
315 fec->eth->rfifo_alarm = 0x0000030c;
317 if (fec->eth->rfifo_status & 0x00700000 ) {
318 printf("mpc5xxx_fec_init() RFIFO error\n");
323 * Set Tx FIFO granularity value
325 fec->eth->tfifo_cntrl = 0x0c000000;
327 printf("tfifo_status: 0x%08x\n", fec->eth->tfifo_status);
328 printf("tfifo_alarm: 0x%08x\n", fec->eth->tfifo_alarm);
332 * Set transmit fifo watermark register(X_WMRK), default = 64
334 fec->eth->tfifo_alarm = 0x00000080;
335 fec->eth->x_wmrk = 0x2;
338 * Set individual address filter for unicast address
339 * and set physical address registers.
341 mpc5xxx_fec_set_hwaddr(fec, dev->enetaddr);
344 * Set multicast address filter
346 fec->eth->gaddr1 = 0x00000000;
347 fec->eth->gaddr2 = 0x00000000;
350 * Turn ON cheater FSM: ????
352 fec->eth->xmit_fsm = 0x03000000;
354 #if defined(CONFIG_MPC5200)
356 * Turn off COMM bus prefetch in the MGT5200 BestComm. It doesn't
357 * work w/ the current receive task.
359 sdma->PtdCntrl |= 0x00000001;
363 * Set priority of different initiators
365 sdma->IPR0 = 7; /* always */
366 sdma->IPR3 = 6; /* Eth RX */
367 sdma->IPR4 = 5; /* Eth Tx */
370 * Clear SmartDMA task interrupt pending bits
372 SDMA_CLEAR_IEVENT(FEC_RECV_TASK_NO);
375 * Initialize SmartDMA parameters stored in SRAM
377 *(int *)FEC_TBD_BASE = (int)fec->tbdBase;
378 *(int *)FEC_RBD_BASE = (int)fec->rbdBase;
379 *(int *)FEC_TBD_NEXT = (int)fec->tbdBase;
380 *(int *)FEC_RBD_NEXT = (int)fec->rbdBase;
382 if (fec->xcv_type != SEVENWIRE) {
384 * Initialize PHY(LXT971A):
386 * Generally, on power up, the LXT971A reads its configuration
387 * pins to check for forced operation, If not cofigured for
388 * forced operation, it uses auto-negotiation/parallel detection
389 * to automatically determine line operating conditions.
390 * If the PHY device on the other side of the link supports
391 * auto-negotiation, the LXT971A auto-negotiates with it
392 * using Fast Link Pulse(FLP) Bursts. If the PHY partner does not
393 * support auto-negotiation, the LXT971A automatically detects
394 * the presence of either link pulses(10Mbps PHY) or Idle
395 * symbols(100Mbps) and sets its operating conditions accordingly.
397 * When auto-negotiation is controlled by software, the following
398 * steps are recommended.
401 * The physical address is dependent on hardware configuration.
408 * Reset PHY, then delay 300ns
410 miiphy_write(phyAddr, 0x0, 0x8000);
413 if (fec->xcv_type == MII10) {
415 * Force 10Base-T, FDX operation
418 printf("Forcing 10 Mbps ethernet link... ");
420 miiphy_read(phyAddr, 0x1, &phyStatus);
422 miiphy_write(fec, phyAddr, 0x0, 0x0100);
424 miiphy_write(phyAddr, 0x0, 0x0180);
427 do { /* wait for link status to go down */
429 if ((timeout--) == 0) {
431 printf("hmmm, should not have waited...");
435 miiphy_read(phyAddr, 0x1, &phyStatus);
439 } while ((phyStatus & 0x0004)); /* !link up */
442 do { /* wait for link status to come back up */
444 if ((timeout--) == 0) {
445 printf("failed. Link is down.\n");
448 miiphy_read(phyAddr, 0x1, &phyStatus);
452 } while (!(phyStatus & 0x0004)); /* !link up */
457 } else { /* MII100 */
459 * Set the auto-negotiation advertisement register bits
461 miiphy_write(phyAddr, 0x4, 0x01e1);
464 * Set MDIO bit 0.12 = 1(&& bit 0.9=1?) to enable auto-negotiation
466 miiphy_write(phyAddr, 0x0, 0x1200);
469 * Wait for AN completion
475 if ((timeout--) == 0) {
477 printf("PHY auto neg 0 failed...\n");
482 if (miiphy_read(phyAddr, 0x1, &phyStatus) != 0) {
484 printf("PHY auto neg 1 failed 0x%04x...\n", phyStatus);
488 } while ((phyStatus & 0x0020) != 0x0020);
491 printf("PHY auto neg complete! \n");
498 * Enable FEC-Lite controller
500 fec->eth->ecntrl |= 0x00000006;
503 if (fec->xcv_type != SEVENWIRE)
504 mpc5xxx_fec_phydump ();
508 * Enable SmartDMA receive task
510 SDMA_TASK_ENABLE(FEC_RECV_TASK_NO);
513 printf("mpc5xxx_fec_init... Done \n");
519 /********************************************************************/
520 static void mpc5xxx_fec_halt(struct eth_device *dev)
522 #if defined(CONFIG_MPC5200)
523 struct mpc5xxx_sdma *sdma = (struct mpc5xxx_sdma *)MPC5XXX_SDMA;
525 mpc5xxx_fec_priv *fec = (mpc5xxx_fec_priv *)dev->priv;
526 int counter = 0xffff;
529 if (fec->xcv_type != SEVENWIRE)
530 mpc5xxx_fec_phydump ();
534 * mask FEC chip interrupts
539 * issue graceful stop command to the FEC transmitter if necessary
541 fec->eth->x_cntrl |= 0x00000001;
544 * wait for graceful stop to register
546 while ((counter--) && (!(fec->eth->ievent & 0x10000000))) ;
549 * Disable SmartDMA tasks
551 SDMA_TASK_DISABLE (FEC_XMIT_TASK_NO);
552 SDMA_TASK_DISABLE (FEC_RECV_TASK_NO);
554 #if defined(CONFIG_MPC5200)
556 * Turn on COMM bus prefetch in the MGT5200 BestComm after we're
557 * done. It doesn't work w/ the current receive task.
559 sdma->PtdCntrl &= ~0x00000001;
563 * Disable the Ethernet Controller
565 fec->eth->ecntrl &= 0xfffffffd;
568 * Clear FIFO status registers
570 fec->eth->rfifo_status &= 0x00700000;
571 fec->eth->tfifo_status &= 0x00700000;
573 fec->eth->reset_cntrl = 0x01000000;
576 * Issue a reset command to the FEC chip
578 fec->eth->ecntrl |= 0x1;
581 * wait at least 16 clock cycles
586 printf("Ethernet task stopped\n");
591 /********************************************************************/
593 static void tfifo_print(mpc5xxx_fec_priv *fec)
595 uint16 phyAddr = CONFIG_PHY_ADDR;
598 if ((fec->eth->tfifo_lrf_ptr != fec->eth->tfifo_lwf_ptr)
599 || (fec->eth->tfifo_rdptr != fec->eth->tfifo_wrptr)) {
601 miiphy_read(phyAddr, 0x1, &phyStatus);
602 printf("\nphyStatus: 0x%04x\n", phyStatus);
603 printf("ecntrl: 0x%08x\n", fec->eth->ecntrl);
604 printf("ievent: 0x%08x\n", fec->eth->ievent);
605 printf("x_status: 0x%08x\n", fec->eth->x_status);
606 printf("tfifo: status 0x%08x\n", fec->eth->tfifo_status);
608 printf(" control 0x%08x\n", fec->eth->tfifo_cntrl);
609 printf(" lrfp 0x%08x\n", fec->eth->tfifo_lrf_ptr);
610 printf(" lwfp 0x%08x\n", fec->eth->tfifo_lwf_ptr);
611 printf(" alarm 0x%08x\n", fec->eth->tfifo_alarm);
612 printf(" readptr 0x%08x\n", fec->eth->tfifo_rdptr);
613 printf(" writptr 0x%08x\n", fec->eth->tfifo_wrptr);
617 static void rfifo_print(mpc5xxx_fec_priv *fec)
619 uint16 phyAddr = CONFIG_PHY_ADDR;
622 if ((fec->eth->rfifo_lrf_ptr != fec->eth->rfifo_lwf_ptr)
623 || (fec->eth->rfifo_rdptr != fec->eth->rfifo_wrptr)) {
625 miiphy_read(phyAddr, 0x1, &phyStatus);
626 printf("\nphyStatus: 0x%04x\n", phyStatus);
627 printf("ecntrl: 0x%08x\n", fec->eth->ecntrl);
628 printf("ievent: 0x%08x\n", fec->eth->ievent);
629 printf("x_status: 0x%08x\n", fec->eth->x_status);
630 printf("rfifo: status 0x%08x\n", fec->eth->rfifo_status);
632 printf(" control 0x%08x\n", fec->eth->rfifo_cntrl);
633 printf(" lrfp 0x%08x\n", fec->eth->rfifo_lrf_ptr);
634 printf(" lwfp 0x%08x\n", fec->eth->rfifo_lwf_ptr);
635 printf(" alarm 0x%08x\n", fec->eth->rfifo_alarm);
636 printf(" readptr 0x%08x\n", fec->eth->rfifo_rdptr);
637 printf(" writptr 0x%08x\n", fec->eth->rfifo_wrptr);
642 /********************************************************************/
644 static int mpc5xxx_fec_send(struct eth_device *dev, volatile void *eth_data,
648 * This routine transmits one frame. This routine only accepts
649 * 6-byte Ethernet addresses.
651 mpc5xxx_fec_priv *fec = (mpc5xxx_fec_priv *)dev->priv;
655 printf("tbd status: 0x%04x\n", fec->tbdBase[0].status);
660 * Clear Tx BD ring at first
662 mpc5xxx_fec_tbd_scrub(fec);
665 * Check for valid length of data.
667 if ((data_length > 1500) || (data_length <= 0)) {
672 * Check the number of vacant TxBDs.
674 if (fec->cleanTbdNum < 1) {
676 printf("No available TxBDs ...\n");
682 * Get the first TxBD to send the mac header
684 pTbd = &fec->tbdBase[fec->tbdIndex];
685 pTbd->dataLength = data_length;
686 pTbd->dataPointer = (uint32)eth_data;
687 pTbd->status |= FEC_TBD_LAST | FEC_TBD_TC | FEC_TBD_READY;
688 fec->tbdIndex = (fec->tbdIndex + 1) % FEC_TBD_NUM;
691 printf("SDMA_TASK_ENABLE, fec->tbdIndex = %d \n", fec->tbdIndex);
697 if (fec->xcv_type != SEVENWIRE) {
699 miiphy_read(0, 0x1, &phyStatus);
703 * Enable SmartDMA transmit task
709 SDMA_TASK_ENABLE (FEC_XMIT_TASK_NO);
717 fec->cleanTbdNum -= 1;
719 #if (DEBUG & 0x129) && (DEBUG & 0x80000000)
720 printf ("smartDMA ethernet Tx task enabled\n");
723 * wait until frame is sent .
725 while (pTbd->status & FEC_TBD_READY) {
728 printf ("TDB status = %04x\n", pTbd->status);
736 /********************************************************************/
737 static int mpc5xxx_fec_recv(struct eth_device *dev)
740 * This command pulls one frame from the card
742 mpc5xxx_fec_priv *fec = (mpc5xxx_fec_priv *)dev->priv;
743 FEC_RBD *pRbd = &fec->rbdBase[fec->rbdIndex];
744 unsigned long ievent;
745 int frame_length, len = 0;
747 char buff[FEC_MAX_PKT_SIZE];
750 printf ("mpc5xxx_fec_recv %d Start...\n", fec->rbdIndex);
757 * Check if any critical events have happened
759 ievent = fec->eth->ievent;
760 fec->eth->ievent = ievent;
761 if (ievent & 0x20060000) {
762 /* BABT, Rx/Tx FIFO errors */
763 mpc5xxx_fec_halt(dev);
764 mpc5xxx_fec_init(dev, NULL);
767 if (ievent & 0x80000000) {
768 /* Heartbeat error */
769 fec->eth->x_cntrl |= 0x00000001;
771 if (ievent & 0x10000000) {
772 /* Graceful stop complete */
773 if (fec->eth->x_cntrl & 0x00000001) {
774 mpc5xxx_fec_halt(dev);
775 fec->eth->x_cntrl &= ~0x00000001;
776 mpc5xxx_fec_init(dev, NULL);
780 if (!(pRbd->status & FEC_RBD_EMPTY)) {
781 if ((pRbd->status & FEC_RBD_LAST) && !(pRbd->status & FEC_RBD_ERR) &&
782 ((pRbd->dataLength - 4) > 14)) {
785 * Get buffer address and size
787 frame = (NBUF *)pRbd->dataPointer;
788 frame_length = pRbd->dataLength - 4;
793 printf("recv data hdr:");
794 for (i = 0; i < 14; i++)
795 printf("%x ", *(frame->head + i));
800 * Fill the buffer and pass it to upper layers
802 memcpy(buff, frame->head, 14);
803 memcpy(buff + 14, frame->data, frame_length);
804 NetReceive(buff, frame_length);
808 * Reset buffer descriptor as empty
810 mpc5xxx_fec_rbd_clean(fec, pRbd);
812 SDMA_CLEAR_IEVENT (FEC_RECV_TASK_NO);
817 /********************************************************************/
818 int mpc5xxx_fec_initialize(bd_t * bis)
820 mpc5xxx_fec_priv *fec;
821 struct eth_device *dev;
823 char env_enetaddr[6];
826 fec = (mpc5xxx_fec_priv *)malloc(sizeof(*fec));
827 dev = (struct eth_device *)malloc(sizeof(*dev));
828 memset(dev, 0, sizeof *dev);
830 fec->eth = (ethernet_regs *)MPC5XXX_FEC;
831 fec->tbdBase = (FEC_TBD *)FEC_BD_BASE;
832 fec->rbdBase = (FEC_RBD *)(FEC_BD_BASE + FEC_TBD_NUM * sizeof(FEC_TBD));
833 #if defined(CONFIG_ICECUBE) ||
834 defined(CONFIG_PM520) ||
835 defined(CONFIG_TOP5200)
836 # ifndef CONFIG_FEC_10MBIT
837 fec->xcv_type = MII100;
839 fec->xcv_type = MII10;
842 #error fec->xcv_type not initialized.
845 dev->priv = (void *)fec;
846 dev->iobase = MPC5XXX_FEC;
847 dev->init = mpc5xxx_fec_init;
848 dev->halt = mpc5xxx_fec_halt;
849 dev->send = mpc5xxx_fec_send;
850 dev->recv = mpc5xxx_fec_recv;
852 sprintf(dev->name, "FEC ETHERNET");
856 * Try to set the mac address now. The fec mac address is
857 * a garbage after reset. When not using fec for booting
858 * the Linux fec driver will try to work with this garbage.
860 tmp = getenv("ethaddr");
862 for (i=0; i<6; i++) {
863 env_enetaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
865 tmp = (*end) ? end+1 : end;
867 mpc5xxx_fec_set_hwaddr(fec, env_enetaddr);
873 /* MII-interface related functions */
874 /********************************************************************/
875 int miiphy_read(uint8 phyAddr, uint8 regAddr, uint16 * retVal)
877 ethernet_regs *eth = (ethernet_regs *)MPC5XXX_FEC;
878 uint32 reg; /* convenient holder for the PHY register */
879 uint32 phy; /* convenient holder for the PHY */
880 int timeout = 0xffff;
883 * reading from any PHY's register is done by properly
884 * programming the FEC's MII data register.
886 reg = regAddr << FEC_MII_DATA_RA_SHIFT;
887 phy = phyAddr << FEC_MII_DATA_PA_SHIFT;
889 eth->mii_data = (FEC_MII_DATA_ST | FEC_MII_DATA_OP_RD | FEC_MII_DATA_TA | phy | reg);
892 * wait for the related interrupt
894 while ((timeout--) && (!(eth->ievent & 0x00800000))) ;
898 printf ("Read MDIO failed...\n");
904 * clear mii interrupt bit
906 eth->ievent = 0x00800000;
909 * it's now safe to read the PHY's register
911 *retVal = (uint16) eth->mii_data;
916 /********************************************************************/
917 int miiphy_write(uint8 phyAddr, uint8 regAddr, uint16 data)
919 ethernet_regs *eth = (ethernet_regs *)MPC5XXX_FEC;
920 uint32 reg; /* convenient holder for the PHY register */
921 uint32 phy; /* convenient holder for the PHY */
922 int timeout = 0xffff;
924 reg = regAddr << FEC_MII_DATA_RA_SHIFT;
925 phy = phyAddr << FEC_MII_DATA_PA_SHIFT;
927 eth->mii_data = (FEC_MII_DATA_ST | FEC_MII_DATA_OP_WR |
928 FEC_MII_DATA_TA | phy | reg | data);
931 * wait for the MII interrupt
933 while ((timeout--) && (!(eth->ievent & 0x00800000))) ;
937 printf ("Write MDIO failed...\n");
943 * clear MII interrupt bit
945 eth->ievent = 0x00800000;
951 static uint32 local_crc32(char *string, unsigned int crc_value, int len)
955 unsigned int crc, count;
961 * crc = 0xffffffff; * The initialized value should be 0xffffffff
965 for (i = len; --i >= 0;) {
967 for (count = 0; count < 8; count++) {
968 if ((c & 0x01) ^ (crc & 0x01)) {
970 crc = crc ^ 0xedb88320;
979 * In big endian system, do byte swaping for crc value
985 #endif /* CONFIG_MPC5xxx_FEC */