Merge branch 'master' of git://git.denx.de/u-boot-fsl-qoriq
[oweals/u-boot.git] / drivers / net / fm / eth.c
index cb099cd84962fa7ba09da632683c1fd8622466ff..eb8e93618f27614aad40287f0ad794e2273c977b 100644 (file)
@@ -13,9 +13,9 @@
 #include <fsl_mdio.h>
 #include <miiphy.h>
 #include <phy.h>
-#include <asm/fsl_dtsec.h>
-#include <asm/fsl_tgec.h>
-#include <asm/fsl_memac.h>
+#include <fsl_dtsec.h>
+#include <fsl_tgec.h>
+#include <fsl_memac.h>
 
 #include "fm.h"
 
@@ -39,23 +39,37 @@ static void dtsec_configure_serdes(struct fm_eth *priv)
        u32 value;
        struct mii_dev bus;
        bus.priv = priv->mac->phyregs;
+       bool sgmii_2500 = (priv->enet_if ==
+                       PHY_INTERFACE_MODE_SGMII_2500) ? true : false;
+       int i = 0;
 
-       /* SGMII IF mode + AN enable */
-       value = PHY_SGMII_IF_MODE_AN | PHY_SGMII_IF_MODE_SGMII;
-       memac_mdio_write(&bus, 0, MDIO_DEVAD_NONE, 0x14, value);
+qsgmii_loop:
+       /* SGMII IF mode + AN enable only for 1G SGMII, not for 2.5G */
+       value = PHY_SGMII_IF_MODE_SGMII;
+       if (!sgmii_2500)
+               value |= PHY_SGMII_IF_MODE_AN;
+
+       memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0x14, value);
 
        /* Dev ability according to SGMII specification */
        value = PHY_SGMII_DEV_ABILITY_SGMII;
-       memac_mdio_write(&bus, 0, MDIO_DEVAD_NONE, 0x4, value);
+       memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0x4, value);
 
        /* Adjust link timer for SGMII  -
        1.6 ms in units of 8 ns = 2 * 10^5 = 0x30d40 */
-       memac_mdio_write(&bus, 0, MDIO_DEVAD_NONE, 0x13, 0x3);
-       memac_mdio_write(&bus, 0, MDIO_DEVAD_NONE, 0x12, 0xd40);
+       memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0x13, 0x3);
+       memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0x12, 0xd40);
 
        /* Restart AN */
-       value = PHY_SGMII_CR_DEF_VAL | PHY_SGMII_CR_RESET_AN;
-       memac_mdio_write(&bus, 0, MDIO_DEVAD_NONE, 0, value);
+       value = PHY_SGMII_CR_DEF_VAL;
+       if (!sgmii_2500)
+               value |= PHY_SGMII_CR_RESET_AN;
+       memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0, value);
+
+       if ((priv->enet_if == PHY_INTERFACE_MODE_QSGMII) && (i < 3)) {
+               i++;
+               goto qsgmii_loop;
+       }
 #else
        struct dtsec *regs = priv->mac->base;
        struct tsec_mii_mng *phyregs = priv->mac->phyregs;
@@ -83,10 +97,13 @@ static void dtsec_init_phy(struct eth_device *dev)
        out_be32(&regs->tbipa, CONFIG_SYS_TBIPA_VALUE);
 #endif
 
-       if (fm_eth->enet_if == PHY_INTERFACE_MODE_SGMII)
+       if (fm_eth->enet_if == PHY_INTERFACE_MODE_SGMII ||
+           fm_eth->enet_if == PHY_INTERFACE_MODE_QSGMII ||
+           fm_eth->enet_if == PHY_INTERFACE_MODE_SGMII_2500)
                dtsec_configure_serdes(fm_eth);
 }
 
+#ifdef CONFIG_PHYLIB
 static int tgec_is_fibre(struct eth_device *dev)
 {
        struct fm_eth *fm = dev->priv;
@@ -97,15 +114,16 @@ static int tgec_is_fibre(struct eth_device *dev)
        return hwconfig_arg_cmp(phyopt, "xfi");
 }
 #endif
+#endif
 
 static u16 muram_readw(u16 *addr)
 {
-       u32 base = (u32)addr & ~0x3;
-       u32 val32 = *(u32 *)base;
+       ulong base = (ulong)addr & ~0x3UL;
+       u32 val32 = in_be32((void *)base);
        int byte_pos;
        u16 ret;
 
-       byte_pos = (u32)addr & 0x3;
+       byte_pos = (ulong)addr & 0x3UL;
        if (byte_pos)
                ret = (u16)(val32 & 0x0000ffff);
        else
@@ -116,18 +134,18 @@ static u16 muram_readw(u16 *addr)
 
 static void muram_writew(u16 *addr, u16 val)
 {
-       u32 base = (u32)addr & ~0x3;
-       u32 org32 = *(u32 *)base;
+       ulong base = (ulong)addr & ~0x3UL;
+       u32 org32 = in_be32((void *)base);
        u32 val32;
        int byte_pos;
 
-       byte_pos = (u32)addr & 0x3;
+       byte_pos = (ulong)addr & 0x3UL;
        if (byte_pos)
                val32 = (org32 & 0xffff0000) | val;
        else
                val32 = (org32 & 0x0000ffff) | ((u32)val << 16);
 
-       *(u32 *)base = val32;
+       out_be32((void *)base, val32);
 }
 
 static void bmi_rx_port_disable(struct fm_bmi_rx_port *rx_port)
@@ -191,6 +209,8 @@ static int fm_eth_rx_port_parameter_init(struct fm_eth *fm_eth)
        u32 pram_page_offset;
        void *rx_bd_ring_base;
        void *rx_buf_pool;
+       u32 bd_ring_base_lo, bd_ring_base_hi;
+       u32 buf_lo, buf_hi;
        struct fm_port_bd *rxbd;
        struct fm_port_qd *rxqd;
        struct fm_bmi_rx_port *bmi_rx_port = fm_eth->rx_port;
@@ -199,16 +219,21 @@ static int fm_eth_rx_port_parameter_init(struct fm_eth *fm_eth)
        /* alloc global parameter ram at MURAM */
        pram = (struct fm_port_global_pram *)fm_muram_alloc(fm_eth->fm_index,
                FM_PRAM_SIZE, FM_PRAM_ALIGN);
+       if (!pram) {
+               printf("%s: No muram for Rx global parameter\n", __func__);
+               return -ENOMEM;
+       }
+
        fm_eth->rx_pram = pram;
 
        /* parameter page offset to MURAM */
-       pram_page_offset = (u32)pram - fm_muram_base(fm_eth->fm_index);
+       pram_page_offset = (void *)pram - fm_muram_base(fm_eth->fm_index);
 
        /* enable global mode- snooping data buffers and BDs */
-       pram->mode = PRAM_MODE_GLOBAL;
+       out_be32(&pram->mode, PRAM_MODE_GLOBAL);
 
        /* init the Rx queue descriptor pionter */
-       pram->rxqd_ptr = pram_page_offset + 0x20;
+       out_be32(&pram->rxqd_ptr, pram_page_offset + 0x20);
 
        /* set the max receive buffer length, power of 2 */
        muram_writew(&pram->mrblr, MAX_RXBUF_LOG2);
@@ -217,15 +242,18 @@ static int fm_eth_rx_port_parameter_init(struct fm_eth *fm_eth)
        rx_bd_ring_base = malloc(sizeof(struct fm_port_bd)
                        * RX_BD_RING_SIZE);
        if (!rx_bd_ring_base)
-               return 0;
+               return -ENOMEM;
+
        memset(rx_bd_ring_base, 0, sizeof(struct fm_port_bd)
                        * RX_BD_RING_SIZE);
 
        /* alloc Rx buffer from main memory */
        rx_buf_pool = malloc(MAX_RXBUF_LEN * RX_BD_RING_SIZE);
        if (!rx_buf_pool)
-               return 0;
+               return -ENOMEM;
+
        memset(rx_buf_pool, 0, MAX_RXBUF_LEN * RX_BD_RING_SIZE);
+       debug("%s: rx_buf_pool = %p\n", __func__, rx_buf_pool);
 
        /* save them to fm_eth */
        fm_eth->rx_bd_ring = rx_bd_ring_base;
@@ -235,18 +263,24 @@ static int fm_eth_rx_port_parameter_init(struct fm_eth *fm_eth)
        /* init Rx BDs ring */
        rxbd = (struct fm_port_bd *)rx_bd_ring_base;
        for (i = 0; i < RX_BD_RING_SIZE; i++) {
-               rxbd->status = RxBD_EMPTY;
-               rxbd->len = 0;
-               rxbd->buf_ptr_hi = 0;
-               rxbd->buf_ptr_lo = (u32)rx_buf_pool + i * MAX_RXBUF_LEN;
+               muram_writew(&rxbd->status, RxBD_EMPTY);
+               muram_writew(&rxbd->len, 0);
+               buf_hi = upper_32_bits(virt_to_phys(rx_buf_pool +
+                                       i * MAX_RXBUF_LEN));
+               buf_lo = lower_32_bits(virt_to_phys(rx_buf_pool +
+                                       i * MAX_RXBUF_LEN));
+               muram_writew(&rxbd->buf_ptr_hi, (u16)buf_hi);
+               out_be32(&rxbd->buf_ptr_lo, buf_lo);
                rxbd++;
        }
 
        /* set the Rx queue descriptor */
        rxqd = &pram->rxqd;
        muram_writew(&rxqd->gen, 0);
-       muram_writew(&rxqd->bd_ring_base_hi, 0);
-       rxqd->bd_ring_base_lo = (u32)rx_bd_ring_base;
+       bd_ring_base_hi = upper_32_bits(virt_to_phys(rx_bd_ring_base));
+       bd_ring_base_lo = lower_32_bits(virt_to_phys(rx_bd_ring_base));
+       muram_writew(&rxqd->bd_ring_base_hi, (u16)bd_ring_base_hi);
+       out_be32(&rxqd->bd_ring_base_lo, bd_ring_base_lo);
        muram_writew(&rxqd->bd_ring_size, sizeof(struct fm_port_bd)
                        * RX_BD_RING_SIZE);
        muram_writew(&rxqd->offset_in, 0);
@@ -255,7 +289,7 @@ static int fm_eth_rx_port_parameter_init(struct fm_eth *fm_eth)
        /* set IM parameter ram pointer to Rx Frame Queue ID */
        out_be32(&bmi_rx_port->fmbm_rfqid, pram_page_offset);
 
-       return 1;
+       return 0;
 }
 
 static int fm_eth_tx_port_parameter_init(struct fm_eth *fm_eth)
@@ -263,6 +297,7 @@ static int fm_eth_tx_port_parameter_init(struct fm_eth *fm_eth)
        struct fm_port_global_pram *pram;
        u32 pram_page_offset;
        void *tx_bd_ring_base;
+       u32 bd_ring_base_lo, bd_ring_base_hi;
        struct fm_port_bd *txbd;
        struct fm_port_qd *txqd;
        struct fm_bmi_tx_port *bmi_tx_port = fm_eth->tx_port;
@@ -271,22 +306,27 @@ static int fm_eth_tx_port_parameter_init(struct fm_eth *fm_eth)
        /* alloc global parameter ram at MURAM */
        pram = (struct fm_port_global_pram *)fm_muram_alloc(fm_eth->fm_index,
                FM_PRAM_SIZE, FM_PRAM_ALIGN);
+       if (!pram) {
+               printf("%s: No muram for Tx global parameter\n", __func__);
+               return -ENOMEM;
+       }
        fm_eth->tx_pram = pram;
 
        /* parameter page offset to MURAM */
-       pram_page_offset = (u32)pram - fm_muram_base(fm_eth->fm_index);
+       pram_page_offset = (void *)pram - fm_muram_base(fm_eth->fm_index);
 
        /* enable global mode- snooping data buffers and BDs */
-       pram->mode = PRAM_MODE_GLOBAL;
+       out_be32(&pram->mode, PRAM_MODE_GLOBAL);
 
        /* init the Tx queue descriptor pionter */
-       pram->txqd_ptr = pram_page_offset + 0x40;
+       out_be32(&pram->txqd_ptr, pram_page_offset + 0x40);
 
        /* alloc Tx buffer descriptors from main memory */
        tx_bd_ring_base = malloc(sizeof(struct fm_port_bd)
                        * TX_BD_RING_SIZE);
        if (!tx_bd_ring_base)
-               return 0;
+               return -ENOMEM;
+
        memset(tx_bd_ring_base, 0, sizeof(struct fm_port_bd)
                        * TX_BD_RING_SIZE);
        /* save it to fm_eth */
@@ -296,16 +336,19 @@ static int fm_eth_tx_port_parameter_init(struct fm_eth *fm_eth)
        /* init Tx BDs ring */
        txbd = (struct fm_port_bd *)tx_bd_ring_base;
        for (i = 0; i < TX_BD_RING_SIZE; i++) {
-               txbd->status = TxBD_LAST;
-               txbd->len = 0;
-               txbd->buf_ptr_hi = 0;
-               txbd->buf_ptr_lo = 0;
+               muram_writew(&txbd->status, TxBD_LAST);
+               muram_writew(&txbd->len, 0);
+               muram_writew(&txbd->buf_ptr_hi, 0);
+               out_be32(&txbd->buf_ptr_lo, 0);
+               txbd++;
        }
 
        /* set the Tx queue decriptor */
        txqd = &pram->txqd;
-       muram_writew(&txqd->bd_ring_base_hi, 0);
-       txqd->bd_ring_base_lo = (u32)tx_bd_ring_base;
+       bd_ring_base_hi = upper_32_bits(virt_to_phys(tx_bd_ring_base));
+       bd_ring_base_lo = lower_32_bits(virt_to_phys(tx_bd_ring_base));
+       muram_writew(&txqd->bd_ring_base_hi, (u16)bd_ring_base_hi);
+       out_be32(&txqd->bd_ring_base_lo, bd_ring_base_lo);
        muram_writew(&txqd->bd_ring_size, sizeof(struct fm_port_bd)
                        * TX_BD_RING_SIZE);
        muram_writew(&txqd->offset_in, 0);
@@ -314,29 +357,35 @@ static int fm_eth_tx_port_parameter_init(struct fm_eth *fm_eth)
        /* set IM parameter ram pointer to Tx Confirmation Frame Queue ID */
        out_be32(&bmi_tx_port->fmbm_tcfqid, pram_page_offset);
 
-       return 1;
+       return 0;
 }
 
 static int fm_eth_init(struct fm_eth *fm_eth)
 {
+       int ret;
 
-       if (!fm_eth_rx_port_parameter_init(fm_eth))
-               return 0;
+       ret = fm_eth_rx_port_parameter_init(fm_eth);
+       if (ret)
+               return ret;
 
-       if (!fm_eth_tx_port_parameter_init(fm_eth))
-               return 0;
+       ret = fm_eth_tx_port_parameter_init(fm_eth);
+       if (ret)
+               return ret;
 
-       return 1;
+       return 0;
 }
 
 static int fm_eth_startup(struct fm_eth *fm_eth)
 {
        struct fsl_enet_mac *mac;
+       int ret;
+
        mac = fm_eth->mac;
 
        /* Rx/TxBDs, Rx/TxQDs, Rx buff and parameter ram init */
-       if (!fm_eth_init(fm_eth))
-               return 0;
+       ret = fm_eth_init(fm_eth);
+       if (ret)
+               return ret;
        /* setup the MAC controller */
        mac->init_mac(mac);
 
@@ -351,7 +400,7 @@ static int fm_eth_startup(struct fm_eth *fm_eth)
        /* init bmi tx port, IM mode and disable */
        bmi_tx_port_init(fm_eth->tx_port);
 
-       return 1;
+       return 0;
 }
 
 static void fmc_tx_port_graceful_stop_enable(struct fm_eth *fm_eth)
@@ -360,7 +409,7 @@ static void fmc_tx_port_graceful_stop_enable(struct fm_eth *fm_eth)
 
        pram = fm_eth->tx_pram;
        /* graceful stop transmission of frames */
-       pram->mode |= PRAM_MODE_GRACEFUL_STOP;
+       setbits_be32(&pram->mode, PRAM_MODE_GRACEFUL_STOP);
        sync();
 }
 
@@ -370,7 +419,7 @@ static void fmc_tx_port_graceful_stop_disable(struct fm_eth *fm_eth)
 
        pram = fm_eth->tx_pram;
        /* re-enable transmission of frames */
-       pram->mode &= ~PRAM_MODE_GRACEFUL_STOP;
+       clrbits_be32(&pram->mode, PRAM_MODE_GRACEFUL_STOP);
        sync();
 }
 
@@ -402,10 +451,15 @@ static int fm_eth_open(struct eth_device *dev, bd_t *bd)
        fmc_tx_port_graceful_stop_disable(fm_eth);
 
 #ifdef CONFIG_PHYLIB
-       ret = phy_startup(fm_eth->phydev);
-       if (ret) {
-               printf("%s: Could not initialize\n", fm_eth->phydev->dev->name);
-               return ret;
+       if (fm_eth->phydev) {
+               ret = phy_startup(fm_eth->phydev);
+               if (ret) {
+                       printf("%s: Could not initialize\n",
+                              fm_eth->phydev->dev->name);
+                       return ret;
+               }
+       } else {
+               return 0;
        }
 #else
        fm_eth->phydev->speed = SPEED_1000;
@@ -439,7 +493,10 @@ static void fm_eth_halt(struct eth_device *dev)
        /* disable bmi Rx port */
        bmi_rx_port_disable(fm_eth->rx_port);
 
-       phy_shutdown(fm_eth->phydev);
+#ifdef CONFIG_PHYLIB
+       if (fm_eth->phydev)
+               phy_shutdown(fm_eth->phydev);
+#endif
 }
 
 static int fm_eth_send(struct eth_device *dev, void *buf, int len)
@@ -455,19 +512,20 @@ static int fm_eth_send(struct eth_device *dev, void *buf, int len)
        txbd = fm_eth->cur_txbd;
 
        /* find one empty TxBD */
-       for (i = 0; txbd->status & TxBD_READY; i++) {
+       for (i = 0; muram_readw(&txbd->status) & TxBD_READY; i++) {
                udelay(100);
                if (i > 0x1000) {
-                       printf("%s: Tx buffer not ready\n", dev->name);
+                       printf("%s: Tx buffer not ready, txbd->status = 0x%x\n",
+                              dev->name, muram_readw(&txbd->status));
                        return 0;
                }
        }
        /* setup TxBD */
-       txbd->buf_ptr_hi = 0;
-       txbd->buf_ptr_lo = (u32)buf;
-       txbd->len = len;
+       muram_writew(&txbd->buf_ptr_hi, (u16)upper_32_bits(virt_to_phys(buf)));
+       out_be32(&txbd->buf_ptr_lo, lower_32_bits(virt_to_phys(buf)));
+       muram_writew(&txbd->len, len);
        sync();
-       txbd->status = TxBD_READY | TxBD_LAST;
+       muram_writew(&txbd->status, TxBD_READY | TxBD_LAST);
        sync();
 
        /* update TxQD, let RISC to send the packet */
@@ -479,10 +537,11 @@ static int fm_eth_send(struct eth_device *dev, void *buf, int len)
        sync();
 
        /* wait for buffer to be transmitted */
-       for (i = 0; txbd->status & TxBD_READY; i++) {
+       for (i = 0; muram_readw(&txbd->status) & TxBD_READY; i++) {
                udelay(100);
                if (i > 0x10000) {
-                       printf("%s: Tx error\n", dev->name);
+                       printf("%s: Tx error, txbd->status = 0x%x\n",
+                              dev->name, muram_readw(&txbd->status));
                        return 0;
                }
        }
@@ -504,27 +563,31 @@ static int fm_eth_recv(struct eth_device *dev)
        struct fm_port_global_pram *pram;
        struct fm_port_bd *rxbd, *rxbd_base;
        u16 status, len;
+       u32 buf_lo, buf_hi;
        u8 *data;
        u16 offset_out;
+       int ret = 1;
 
        fm_eth = (struct fm_eth *)dev->priv;
        pram = fm_eth->rx_pram;
        rxbd = fm_eth->cur_rxbd;
-       status = rxbd->status;
+       status = muram_readw(&rxbd->status);
 
        while (!(status & RxBD_EMPTY)) {
                if (!(status & RxBD_ERROR)) {
-                       data = (u8 *)rxbd->buf_ptr_lo;
-                       len = rxbd->len;
-                       NetReceive(data, len);
+                       buf_hi = muram_readw(&rxbd->buf_ptr_hi);
+                       buf_lo = in_be32(&rxbd->buf_ptr_lo);
+                       data = (u8 *)((ulong)(buf_hi << 16) << 16 | buf_lo);
+                       len = muram_readw(&rxbd->len);
+                       net_process_received_packet(data, len);
                } else {
                        printf("%s: Rx error\n", dev->name);
-                       return 0;
+                       ret = 0;
                }
 
                /* clear the RxBDs */
-               rxbd->status = RxBD_EMPTY;
-               rxbd->len = 0;
+               muram_writew(&rxbd->status, RxBD_EMPTY);
+               muram_writew(&rxbd->len, 0);
                sync();
 
                /* advance RxBD */
@@ -533,7 +596,7 @@ static int fm_eth_recv(struct eth_device *dev)
                if (rxbd >= (rxbd_base + RX_BD_RING_SIZE))
                        rxbd = rxbd_base;
                /* read next status */
-               status = rxbd->status;
+               status = muram_readw(&rxbd->status);
 
                /* update RxQD */
                offset_out = muram_readw(&pram->rxqd.offset_out);
@@ -545,7 +608,7 @@ static int fm_eth_recv(struct eth_device *dev)
        }
        fm_eth->cur_rxbd = (void *)rxbd;
 
-       return 1;
+       return ret;
 }
 
 static int fm_eth_init_mac(struct fm_eth *fm_eth, struct ccsr_fman *reg)
@@ -557,8 +620,19 @@ static int fm_eth_init_mac(struct fm_eth *fm_eth, struct ccsr_fman *reg)
        num = fm_eth->num;
 
 #ifdef CONFIG_SYS_FMAN_V3
-       if (fm_eth->type == FM_ETH_10G_E)
-               num += 8;
+#ifndef CONFIG_FSL_FM_10GEC_REGULAR_NOTATION
+       if (fm_eth->type == FM_ETH_10G_E) {
+               /* 10GEC1/10GEC2 use mEMAC9/mEMAC10 on T2080/T4240.
+                * 10GEC3/10GEC4 use mEMAC1/mEMAC2 on T2080.
+                * 10GEC1 uses mEMAC1 on T1024.
+                * so it needs to change the num.
+                */
+               if (fm_eth->num >= 2)
+                       num -= 2;
+               else
+                       num += 8;
+       }
+#endif
        base = &reg->memac[num].fm_memac;
        phyregs = &reg->memac[num].fm_memac_mdio;
 #else
@@ -575,7 +649,7 @@ static int fm_eth_init_mac(struct fm_eth *fm_eth, struct ccsr_fman *reg)
        /* alloc mac controller */
        mac = malloc(sizeof(struct fsl_enet_mac));
        if (!mac)
-               return 0;
+               return -ENOMEM;
        memset(mac, 0, sizeof(struct fsl_enet_mac));
 
        /* save the mac to fm_eth struct */
@@ -590,27 +664,30 @@ static int fm_eth_init_mac(struct fm_eth *fm_eth, struct ccsr_fman *reg)
                init_tgec(mac, base, phyregs, MAX_RXBUF_LEN);
 #endif
 
-       return 1;
+       return 0;
 }
 
 static int init_phy(struct eth_device *dev)
 {
        struct fm_eth *fm_eth = dev->priv;
+#ifdef CONFIG_PHYLIB
        struct phy_device *phydev = NULL;
        u32 supported;
+#endif
 
-#ifdef CONFIG_PHYLIB
        if (fm_eth->type == FM_ETH_1G_E)
                dtsec_init_phy(dev);
 
+#ifdef CONFIG_PHYLIB
        if (fm_eth->bus) {
                phydev = phy_connect(fm_eth->bus, fm_eth->phyaddr, dev,
                                        fm_eth->enet_if);
-       }
-
-       if (!phydev) {
-               printf("Failed to connect\n");
-               return -1;
+               if (!phydev) {
+                       printf("Failed to connect\n");
+                       return -1;
+               }
+       } else {
+               return 0;
        }
 
        if (fm_eth->type == FM_ETH_1G_E) {
@@ -642,17 +719,18 @@ int fm_eth_initialize(struct ccsr_fman *reg, struct fm_eth_info *info)
        struct eth_device *dev;
        struct fm_eth *fm_eth;
        int i, num = info->num;
+       int ret;
 
        /* alloc eth device */
        dev = (struct eth_device *)malloc(sizeof(struct eth_device));
        if (!dev)
-               return 0;
+               return -ENOMEM;
        memset(dev, 0, sizeof(struct eth_device));
 
        /* alloc the FMan ethernet private struct */
        fm_eth = (struct fm_eth *)malloc(sizeof(struct fm_eth));
        if (!fm_eth)
-               return 0;
+               return -ENOMEM;
        memset(fm_eth, 0, sizeof(struct fm_eth));
 
        /* save off some things we need from the info struct */
@@ -667,8 +745,9 @@ int fm_eth_initialize(struct ccsr_fman *reg, struct fm_eth_info *info)
        fm_eth->max_rx_len = MAX_RXBUF_LEN;
 
        /* init global mac structure */
-       if (!fm_eth_init_mac(fm_eth, reg))
-               return 0;
+       ret = fm_eth_init_mac(fm_eth, reg);
+       if (ret)
+               return ret;
 
        /* keep same as the manual, we call FMAN1, FMAN2, DTSEC1, DTSEC2, etc */
        if (fm_eth->type == FM_ETH_1G_E)
@@ -689,16 +768,16 @@ int fm_eth_initialize(struct ccsr_fman *reg, struct fm_eth_info *info)
        fm_eth->enet_if = info->enet_if;
 
        /* startup the FM im */
-       if (!fm_eth_startup(fm_eth))
-               return 0;
+       ret = fm_eth_startup(fm_eth);
+       if (ret)
+               return ret;
 
-       if (init_phy(dev))
-               return 0;
+       init_phy(dev);
 
        /* clear the ethernet address */
        for (i = 0; i < 6; i++)
                dev->enetaddr[i] = 0;
        eth_register(dev);
 
-       return 1;
+       return 0;
 }