]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/net/mcffec.c
net: fec: use correct sizes to clear and flush descriptors
[karo-tx-uboot.git] / drivers / net / mcffec.c
index f93cf598e251d2b3ce1d56eb75458f7889c79802..fd7309937104407935fada5839769bbcb7eb8381 100644 (file)
@@ -5,36 +5,20 @@
  * (C) Copyright 2007 Freescale Semiconductor, Inc.
  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <malloc.h>
 
-#include <asm/fec.h>
-#include <asm/immap.h>
-
 #include <command.h>
 #include <net.h>
 #include <netdev.h>
 #include <miiphy.h>
 
+#include <asm/fec.h>
+#include <asm/immap.h>
+
 #undef ET_DEBUG
 #undef MII_DEBUG
 
 DECLARE_GLOBAL_DATA_PTR;
 
 struct fec_info_s fec_info[] = {
-#ifdef CFG_FEC0_IOBASE
+#ifdef CONFIG_SYS_FEC0_IOBASE
        {
         0,                     /* index */
-        CFG_FEC0_IOBASE,       /* io base */
-        CFG_FEC0_PINMUX,       /* gpio pin muxing */
-        CFG_FEC0_MIIBASE,      /* mii base */
+        CONFIG_SYS_FEC0_IOBASE,        /* io base */
+        CONFIG_SYS_FEC0_PINMUX,        /* gpio pin muxing */
+        CONFIG_SYS_FEC0_MIIBASE,       /* mii base */
         -1,                    /* phy_addr */
         0,                     /* duplex and speed */
         0,                     /* phy name */
@@ -70,17 +54,17 @@ struct fec_info_s fec_info[] = {
         (struct fec_info_s *)-1,
         },
 #endif
-#ifdef CFG_FEC1_IOBASE
+#ifdef CONFIG_SYS_FEC1_IOBASE
        {
         1,                     /* index */
-        CFG_FEC1_IOBASE,       /* io base */
-        CFG_FEC1_PINMUX,       /* gpio pin muxing */
-        CFG_FEC1_MIIBASE,      /* mii base */
+        CONFIG_SYS_FEC1_IOBASE,        /* io base */
+        CONFIG_SYS_FEC1_PINMUX,        /* gpio pin muxing */
+        CONFIG_SYS_FEC1_MIIBASE,       /* mii base */
         -1,                    /* phy_addr */
         0,                     /* duplex and speed */
         0,                     /* phy name */
         0,                     /* phy name init */
-#ifdef CFG_FEC_BUF_USE_SRAM
+#ifdef CONFIG_SYS_FEC_BUF_USE_SRAM
         (cbd_t *)DBUF_LENGTH,  /* RX BD */
 #else
         0,                     /* RX BD */
@@ -95,24 +79,11 @@ struct fec_info_s fec_info[] = {
 #endif
 };
 
-int fec_send(struct eth_device *dev, volatile void *packet, int length);
 int fec_recv(struct eth_device *dev);
 int fec_init(struct eth_device *dev, bd_t * bd);
 void fec_halt(struct eth_device *dev);
 void fec_reset(struct eth_device *dev);
 
-extern int fecpin_setclear(struct eth_device *dev, int setclear);
-
-#ifdef CFG_DISCOVER_PHY
-extern void __mii_init(void);
-extern uint mii_send(uint mii_cmd);
-extern int mii_discover_phy(struct eth_device *dev);
-extern int mcffec_miiphy_read(char *devname, unsigned char addr,
-                             unsigned char reg, unsigned short *value);
-extern int mcffec_miiphy_write(char *devname, unsigned char addr,
-                              unsigned char reg, unsigned short value);
-#endif
-
 void setFecDuplexSpeed(volatile fec_t * fecp, bd_t * bd, int dup_spd)
 {
        if ((dup_spd >> 16) == FULL) {
@@ -146,14 +117,14 @@ void setFecDuplexSpeed(volatile fec_t * fecp, bd_t * bd, int dup_spd)
        }
 }
 
-int fec_send(struct eth_device *dev, volatile void *packet, int length)
+static int fec_send(struct eth_device *dev, void *packet, int length)
 {
        struct fec_info_s *info = dev->priv;
        volatile fec_t *fecp = (fec_t *) (info->iobase);
        int j, rc;
        u16 phyStatus;
 
-       miiphy_read(dev->name, info->phy_addr, PHY_BMSR, &phyStatus);
+       miiphy_read(dev->name, info->phy_addr, MII_BMSR, &phyStatus);
 
        /* section 16.9.23.3
         * Wait for ready
@@ -175,7 +146,7 @@ int fec_send(struct eth_device *dev, volatile void *packet, int length)
        /* Activate transmit Buffer Descriptor polling */
        fecp->tdar = 0x01000000;        /* Descriptor polling active    */
 
-#ifndef CFG_FEC_BUF_USE_SRAM
+#ifndef CONFIG_SYS_FEC_BUF_USE_SRAM
        /*
         * FEC unable to initial transmit data packet.
         * A nop will ensure the descriptor polling active completed.
@@ -187,7 +158,7 @@ int fec_send(struct eth_device *dev, volatile void *packet, int length)
 
 #endif
 
-#ifdef CFG_UNIFY_CACHE
+#ifdef CONFIG_SYS_UNIFY_CACHE
        icache_invalid();
 #endif
 
@@ -222,9 +193,9 @@ int fec_recv(struct eth_device *dev)
        int length;
 
        for (;;) {
-#ifndef CFG_FEC_BUF_USE_SRAM
+#ifndef CONFIG_SYS_FEC_BUF_USE_SRAM
 #endif
-#ifdef CFG_UNIFY_CACHE
+#ifdef CONFIG_SYS_UNIFY_CACHE
                icache_invalid();
 #endif
                /* section 16.9.23.2 */
@@ -248,7 +219,8 @@ int fec_recv(struct eth_device *dev)
 
                        length -= 4;
                        /* Pass the packet up to the protocol layers. */
-                       NetReceive(NetRxPackets[info->rxIdx], length);
+                       net_process_received_packet(net_rx_packets[info->rxIdx],
+                                                   length);
 
                        fecp->eir |= FEC_EIR_RXF;
                }
@@ -428,22 +400,22 @@ int fec_init(struct eth_device *dev, bd_t * bd)
        struct fec_info_s *info = dev->priv;
        volatile fec_t *fecp = (fec_t *) (info->iobase);
        int i;
-       u8 *ea = NULL;
+       uchar ea[6];
 
        fecpin_setclear(dev, 1);
 
        fec_reset(dev);
 
 #if defined(CONFIG_CMD_MII) || defined (CONFIG_MII) || \
-       defined (CFG_DISCOVER_PHY)
+       defined (CONFIG_SYS_DISCOVER_PHY)
 
        mii_init();
 
        setFecDuplexSpeed(fecp, bd, info->dup_spd);
 #else
-#ifndef CFG_DISCOVER_PHY
+#ifndef CONFIG_SYS_DISCOVER_PHY
        setFecDuplexSpeed(fecp, bd, (FECDUPLEX << 16) | FECSPEED);
-#endif                         /* ifndef CFG_DISCOVER_PHY */
+#endif                         /* ifndef CONFIG_SYS_DISCOVER_PHY */
 #endif                         /* CONFIG_CMD_MII || CONFIG_MII */
 
        /* We use strictly polling mode only */
@@ -453,28 +425,28 @@ int fec_init(struct eth_device *dev, bd_t * bd)
        fecp->eir = 0xffffffff;
 
        /* Set station address   */
-       if ((u32) fecp == CFG_FEC0_IOBASE) {
-#ifdef CFG_FEC1_IOBASE
-               volatile fec_t *fecp1 = (fec_t *) (CFG_FEC1_IOBASE);
-               ea = &bd->bi_enet1addr[0];
+       if ((u32) fecp == CONFIG_SYS_FEC0_IOBASE) {
+#ifdef CONFIG_SYS_FEC1_IOBASE
+               volatile fec_t *fecp1 = (fec_t *) (CONFIG_SYS_FEC1_IOBASE);
+               eth_getenv_enetaddr("eth1addr", ea);
                fecp1->palr =
                    (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
                fecp1->paur = (ea[4] << 24) | (ea[5] << 16);
 #endif
-               ea = &bd->bi_enetaddr[0];
+               eth_getenv_enetaddr("ethaddr", ea);
                fecp->palr =
                    (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
                fecp->paur = (ea[4] << 24) | (ea[5] << 16);
        } else {
-#ifdef CFG_FEC0_IOBASE
-               volatile fec_t *fecp0 = (fec_t *) (CFG_FEC0_IOBASE);
-               ea = &bd->bi_enetaddr[0];
+#ifdef CONFIG_SYS_FEC0_IOBASE
+               volatile fec_t *fecp0 = (fec_t *) (CONFIG_SYS_FEC0_IOBASE);
+               eth_getenv_enetaddr("ethaddr", ea);
                fecp0->palr =
                    (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
                fecp0->paur = (ea[4] << 24) | (ea[5] << 16);
 #endif
-#ifdef CFG_FEC1_IOBASE
-               ea = &bd->bi_enet1addr[0];
+#ifdef CONFIG_SYS_FEC1_IOBASE
+               eth_getenv_enetaddr("eth1addr", ea);
                fecp->palr =
                    (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
                fecp->paur = (ea[4] << 24) | (ea[5] << 16);
@@ -506,7 +478,7 @@ int fec_init(struct eth_device *dev, bd_t * bd)
        for (i = 0; i < PKTBUFSRX; i++) {
                info->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
                info->rxbd[i].cbd_datlen = 0;   /* Reset */
-               info->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i];
+               info->rxbd[i].cbd_bufaddr = (uint) net_rx_packets[i];
        }
        info->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
 
@@ -568,14 +540,14 @@ int mcffec_initialize(bd_t * bis)
 {
        struct eth_device *dev;
        int i;
-#ifdef CFG_FEC_BUF_USE_SRAM
-       u32 tmp = CFG_INIT_RAM_ADDR + 0x1000;
+#ifdef CONFIG_SYS_FEC_BUF_USE_SRAM
+       u32 tmp = CONFIG_SYS_INIT_RAM_ADDR + 0x1000;
 #endif
 
-       for (i = 0; i < sizeof(fec_info) / sizeof(fec_info[0]); i++) {
+       for (i = 0; i < ARRAY_SIZE(fec_info); i++) {
 
                dev =
-                   (struct eth_device *)memalign(CFG_CACHELINE_SIZE,
+                   (struct eth_device *)memalign(CONFIG_SYS_CACHELINE_SIZE,
                                                  sizeof *dev);
                if (dev == NULL)
                        hang();
@@ -591,7 +563,7 @@ int mcffec_initialize(bd_t * bis)
                dev->recv = fec_recv;
 
                /* setup Receive and Transmit buffer descriptor */
-#ifdef CFG_FEC_BUF_USE_SRAM
+#ifdef CONFIG_SYS_FEC_BUF_USE_SRAM
                fec_info[i].rxbd = (cbd_t *)((u32)fec_info[i].rxbd + tmp);
                tmp = (u32)fec_info[i].rxbd;
                fec_info[i].txbd =
@@ -600,17 +572,17 @@ int mcffec_initialize(bd_t * bis)
                tmp = (u32)fec_info[i].txbd;
                fec_info[i].txbuf =
                    (char *)((u32)fec_info[i].txbuf + tmp +
-                   (CFG_TX_ETH_BUFFER * sizeof(cbd_t)));
+                   (CONFIG_SYS_TX_ETH_BUFFER * sizeof(cbd_t)));
                tmp = (u32)fec_info[i].txbuf;
 #else
                fec_info[i].rxbd =
-                   (cbd_t *) memalign(CFG_CACHELINE_SIZE,
+                   (cbd_t *) memalign(CONFIG_SYS_CACHELINE_SIZE,
                                       (PKTBUFSRX * sizeof(cbd_t)));
                fec_info[i].txbd =
-                   (cbd_t *) memalign(CFG_CACHELINE_SIZE,
+                   (cbd_t *) memalign(CONFIG_SYS_CACHELINE_SIZE,
                                       (TX_BUF_CNT * sizeof(cbd_t)));
                fec_info[i].txbuf =
-                   (char *)memalign(CFG_CACHELINE_SIZE, DBUF_LENGTH);
+                   (char *)memalign(CONFIG_SYS_CACHELINE_SIZE, DBUF_LENGTH);
 #endif
 
 #ifdef ET_DEBUG
@@ -618,7 +590,7 @@ int mcffec_initialize(bd_t * bis)
                       (int)fec_info[i].rxbd, (int)fec_info[i].txbd);
 #endif
 
-               fec_info[i].phy_name = (char *)memalign(CFG_CACHELINE_SIZE, 32);
+               fec_info[i].phy_name = (char *)memalign(CONFIG_SYS_CACHELINE_SIZE, 32);
 
                eth_register(dev);