net: tsec: Cleanup tsec regs init and fix __iomem warns
[oweals/u-boot.git] / drivers / net / tsec.c
index 160bc0597d680fee4befaadda1b3412e2093b62b..adb6c123e583475ee662a6d31b1fd9161724ddda 100644 (file)
@@ -5,7 +5,7 @@
  * terms of the GNU Public License, Version 2, incorporated
  * herein by reference.
  *
- * Copyright 2004-2011 Freescale Semiconductor, Inc.
+ * Copyright 2004-2011, 2013 Freescale Semiconductor, Inc.
  * (C) Copyright 2003, Motorola, Inc.
  * author Andy Fleming
  *
@@ -33,19 +33,13 @@ typedef volatile struct rtxbd {
        rxbd8_t rxbd[PKTBUFSRX];
 } RTXBD;
 
-#define MAXCONTROLLERS (8)
-
-static struct tsec_private *privlist[MAXCONTROLLERS];
-static int num_tsecs = 0;
-
 #ifdef __GNUC__
 static RTXBD rtx __attribute__ ((aligned(8)));
 #else
 #error "rtx must be 64-bit aligned"
 #endif
 
-static int tsec_send(struct eth_device *dev,
-       volatile void *packet, int length);
+static int tsec_send(struct eth_device *dev, void *packet, int length);
 
 /* Default initializations for TSEC controllers. */
 
@@ -58,7 +52,7 @@ static struct tsec_info_struct tsec_info[] = {
 #endif
 #ifdef CONFIG_MPC85XX_FEC
        {
-               .regs = (tsec_t *)(TSEC_BASE_ADDR + 0x2000),
+               .regs = TSEC_GET_REGS(2, 0x2000),
                .devname = CONFIG_MPC85XX_FEC_NAME,
                .phyaddr = FEC_PHY_ADDR,
                .flags = FEC_FLAGS,
@@ -114,32 +108,31 @@ static void tsec_configure_serdes(struct tsec_private *priv)
  * result.
  * 2) Use the 8 most significant bits as a hash into a 256-entry
  * table.  The table is controlled through 8 32-bit registers:
- * gaddr0-7.  gaddr0's MSB is entry 0, and gaddr7's LSB is
- * gaddr7.  This means that the 3 most significant bits in the
+ * gaddr0-7.  gaddr0's MSB is entry 0, and gaddr7's LSB is entry
+ * 255.  This means that the 3 most significant bits in the
  * hash index which gaddr register to use, and the 5 other bits
  * indicate which bit (assuming an IBM numbering scheme, which
- * for PowerPC (tm) is usually the case) in the tregister holds
+ * for PowerPC (tm) is usually the case) in the register holds
  * the entry. */
 static int
-tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
+tsec_mcast_addr(struct eth_device *dev, const u8 *mcast_mac, u8 set)
 {
-       struct tsec_private *priv = privlist[1];
-       volatile tsec_t *regs = priv->regs;
-       volatile u32  *reg_array, value;
-       u8 result, whichbit, whichreg;
-
-       result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
-       whichbit = result & 0x1f;       /* the 5 LSB = which bit to set */
-       whichreg = result >> 5;         /* the 3 MSB = which reg to set it in */
-       value = (1 << (31-whichbit));
-
-       reg_array = &(regs->hash.gaddr0);
-
-       if (set) {
-               reg_array[whichreg] |= value;
-       } else {
-               reg_array[whichreg] &= ~value;
-       }
+       struct tsec_private *priv = (struct tsec_private *)dev->priv;
+       struct tsec __iomem *regs = priv->regs;
+       u32 result, value;
+       u8 whichbit, whichreg;
+
+       result = ether_crc(MAC_ADDR_LEN, mcast_mac);
+       whichbit = (result >> 24) & 0x1f; /* the 5 LSB = which bit to set */
+       whichreg = result >> 29; /* the 3 MSB = which reg to set it in */
+
+       value = 1 << (31-whichbit);
+
+       if (set)
+               setbits_be32(&regs->hash.gaddr0 + whichreg, value);
+       else
+               clrbits_be32(&regs->hash.gaddr0 + whichreg, value);
+
        return 0;
 }
 #endif /* Multicast TFTP ? */
@@ -148,7 +141,7 @@ tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
  * those we don't care about (unless zero is bad, in which case,
  * choose a more appropriate value)
  */
-static void init_registers(tsec_t *regs)
+static void init_registers(struct tsec __iomem *regs)
 {
        /* Clear IEVENT */
        out_be32(&regs->ievent, IEVENT_INIT_CLEAR);
@@ -195,7 +188,7 @@ static void init_registers(tsec_t *regs)
  */
 static void adjust_link(struct tsec_private *priv, struct phy_device *phydev)
 {
-       tsec_t *regs = priv->regs;
+       struct tsec __iomem *regs = priv->regs;
        u32 ecntrl, maccfg2;
 
        if (!phydev->link) {
@@ -249,7 +242,7 @@ static void adjust_link(struct tsec_private *priv, struct phy_device *phydev)
 void redundant_init(struct eth_device *dev)
 {
        struct tsec_private *priv = dev->priv;
-       tsec_t *regs = priv->regs;
+       struct tsec __iomem *regs = priv->regs;
        uint t, count = 0;
        int fail = 1;
        static const u8 pkt[] = {
@@ -328,7 +321,7 @@ static void startup_tsec(struct eth_device *dev)
 {
        int i;
        struct tsec_private *priv = (struct tsec_private *)dev->priv;
-       tsec_t *regs = priv->regs;
+       struct tsec __iomem *regs = priv->regs;
 
        /* reset the indices to zero */
        rxIdx = 0;
@@ -377,12 +370,12 @@ static void startup_tsec(struct eth_device *dev)
  * do the same.         Presumably, this would be zero if there were no
  * errors
  */
-static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
+static int tsec_send(struct eth_device *dev, void *packet, int length)
 {
        int i;
        int result = 0;
        struct tsec_private *priv = (struct tsec_private *)dev->priv;
-       tsec_t *regs = priv->regs;
+       struct tsec __iomem *regs = priv->regs;
 
        /* Find an empty buffer descriptor */
        for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
@@ -418,7 +411,7 @@ static int tsec_recv(struct eth_device *dev)
 {
        int length;
        struct tsec_private *priv = (struct tsec_private *)dev->priv;
-       tsec_t *regs = priv->regs;
+       struct tsec __iomem *regs = priv->regs;
 
        while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
 
@@ -454,7 +447,7 @@ static int tsec_recv(struct eth_device *dev)
 static void tsec_halt(struct eth_device *dev)
 {
        struct tsec_private *priv = (struct tsec_private *)dev->priv;
-       tsec_t *regs = priv->regs;
+       struct tsec __iomem *regs = priv->regs;
 
        clrbits_be32(&regs->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
        setbits_be32(&regs->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
@@ -480,7 +473,8 @@ static int tsec_init(struct eth_device *dev, bd_t * bd)
        char tmpbuf[MAC_ADDR_LEN];
        int i;
        struct tsec_private *priv = (struct tsec_private *)dev->priv;
-       tsec_t *regs = priv->regs;
+       struct tsec __iomem *regs = priv->regs;
+       int ret;
 
        /* Make sure the controller is stopped */
        tsec_halt(dev);
@@ -512,7 +506,12 @@ static int tsec_init(struct eth_device *dev, bd_t * bd)
        startup_tsec(dev);
 
        /* Start up the PHY */
-       phy_startup(priv->phydev);
+       ret = phy_startup(priv->phydev);
+       if (ret) {
+               printf("Could not initialize PHY %s\n",
+                      priv->phydev->dev->name);
+               return ret;
+       }
 
        adjust_link(priv, priv->phydev);
 
@@ -522,7 +521,7 @@ static int tsec_init(struct eth_device *dev, bd_t * bd)
 
 static phy_interface_t tsec_get_interface(struct tsec_private *priv)
 {
-       tsec_t *regs = priv->regs;
+       struct tsec __iomem *regs = priv->regs;
        u32 ecntrl;
 
        ecntrl = in_be32(&regs->ecntrl);
@@ -571,7 +570,7 @@ static int init_phy(struct eth_device *dev)
 {
        struct tsec_private *priv = (struct tsec_private *)dev->priv;
        struct phy_device *phydev;
-       tsec_t *regs = priv->regs;
+       struct tsec __iomem *regs = priv->regs;
        u32 supported = (SUPPORTED_10baseT_Half |
                        SUPPORTED_10baseT_Full |
                        SUPPORTED_100baseT_Half |
@@ -621,7 +620,6 @@ static int tsec_initialize(bd_t *bis, struct tsec_info_struct *tsec_info)
        if (NULL == priv)
                return 0;
 
-       privlist[num_tsecs++] = priv;
        priv->regs = tsec_info->regs;
        priv->phyregs_sgmii = tsec_info->miiregs_sgmii;
 
@@ -679,7 +677,7 @@ int tsec_standard_init(bd_t *bis)
 {
        struct fsl_pq_mdio_info info;
 
-       info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
+       info.regs = TSEC_GET_MDIO_REGS_BASE(1);
        info.name = DEFAULT_MII_NAME;
 
        fsl_pq_mdio_init(bis, &info);