md/raid5: refactor raid5 "run"
[safe/jmp/linux-2.6] / drivers / net / ucc_geth.c
index 3d1966c..e879868 100644 (file)
@@ -188,17 +188,6 @@ static void mem_disp(u8 *addr, int size)
 }
 #endif /* DEBUG */
 
-#ifdef CONFIG_UGETH_FILTERING
-static void enqueue(struct list_head *node, struct list_head *lh)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&ugeth_lock, flags);
-       list_add_tail(node, lh);
-       spin_unlock_irqrestore(&ugeth_lock, flags);
-}
-#endif /* CONFIG_UGETH_FILTERING */
-
 static struct list_head *dequeue(struct list_head *lh)
 {
        unsigned long flags;
@@ -391,23 +380,6 @@ static int dump_init_enet_entries(struct ucc_geth_private *ugeth,
 }
 #endif
 
-#ifdef CONFIG_UGETH_FILTERING
-static struct enet_addr_container *get_enet_addr_container(void)
-{
-       struct enet_addr_container *enet_addr_cont;
-
-       /* allocate memory */
-       enet_addr_cont = kmalloc(sizeof(struct enet_addr_container), GFP_KERNEL);
-       if (!enet_addr_cont) {
-               ugeth_err("%s: No memory for enet_addr_container object.",
-                         __func__);
-               return NULL;
-       }
-
-       return enet_addr_cont;
-}
-#endif /* CONFIG_UGETH_FILTERING */
-
 static void put_enet_addr_container(struct enet_addr_container *enet_addr_cont)
 {
        kfree(enet_addr_cont);
@@ -420,28 +392,6 @@ static void set_mac_addr(__be16 __iomem *reg, u8 *mac)
        out_be16(&reg[2], ((u16)mac[1] << 8) | mac[0]);
 }
 
-#ifdef CONFIG_UGETH_FILTERING
-static int hw_add_addr_in_paddr(struct ucc_geth_private *ugeth,
-                                u8 *p_enet_addr, u8 paddr_num)
-{
-       struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
-
-       if (!(paddr_num < NUM_OF_PADDRS)) {
-               ugeth_warn("%s: Illegal paddr_num.", __func__);
-               return -EINVAL;
-       }
-
-       p_82xx_addr_filt =
-           (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
-           addressfiltering;
-
-       /* Ethernet frames are defined in Little Endian mode,    */
-       /* therefore to insert the address we reverse the bytes. */
-       set_mac_addr(&p_82xx_addr_filt->paddr[paddr_num].h, p_enet_addr);
-       return 0;
-}
-#endif /* CONFIG_UGETH_FILTERING */
-
 static int hw_clear_addr_in_paddr(struct ucc_geth_private *ugeth, u8 paddr_num)
 {
        struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
@@ -492,40 +442,30 @@ static void magic_packet_detection_enable(struct ucc_geth_private *ugeth)
 {
        struct ucc_fast_private *uccf;
        struct ucc_geth __iomem *ug_regs;
-       u32 maccfg2, uccm;
 
        uccf = ugeth->uccf;
        ug_regs = ugeth->ug_regs;
 
        /* Enable interrupts for magic packet detection */
-       uccm = in_be32(uccf->p_uccm);
-       uccm |= UCCE_MPD;
-       out_be32(uccf->p_uccm, uccm);
+       setbits32(uccf->p_uccm, UCC_GETH_UCCE_MPD);
 
        /* Enable magic packet detection */
-       maccfg2 = in_be32(&ug_regs->maccfg2);
-       maccfg2 |= MACCFG2_MPE;
-       out_be32(&ug_regs->maccfg2, maccfg2);
+       setbits32(&ug_regs->maccfg2, MACCFG2_MPE);
 }
 
 static void magic_packet_detection_disable(struct ucc_geth_private *ugeth)
 {
        struct ucc_fast_private *uccf;
        struct ucc_geth __iomem *ug_regs;
-       u32 maccfg2, uccm;
 
        uccf = ugeth->uccf;
        ug_regs = ugeth->ug_regs;
 
        /* Disable interrupts for magic packet detection */
-       uccm = in_be32(uccf->p_uccm);
-       uccm &= ~UCCE_MPD;
-       out_be32(uccf->p_uccm, uccm);
+       clrbits32(uccf->p_uccm, UCC_GETH_UCCE_MPD);
 
        /* Disable magic packet detection */
-       maccfg2 = in_be32(&ug_regs->maccfg2);
-       maccfg2 &= ~MACCFG2_MPE;
-       out_be32(&ug_regs->maccfg2, maccfg2);
+       clrbits32(&ug_regs->maccfg2, MACCFG2_MPE);
 }
 #endif /* MAGIC_PACKET */
 
@@ -635,7 +575,8 @@ static void get_statistics(struct ucc_geth_private *ugeth,
 
        /* Hardware only if user handed pointer and driver actually
        gathers hardware statistics */
-       if (hardware_statistics && (in_be32(&uf_regs->upsmr) & UPSMR_HSE)) {
+       if (hardware_statistics &&
+           (in_be32(&uf_regs->upsmr) & UCC_GETH_UPSMR_HSE)) {
                hardware_statistics->tx64 = in_be32(&ug_regs->tx64);
                hardware_statistics->tx127 = in_be32(&ug_regs->tx127);
                hardware_statistics->tx255 = in_be32(&ug_regs->tx255);
@@ -1231,9 +1172,7 @@ int init_flow_control_params(u32 automatic_flow_control_mode,
        out_be32(uempr_register, value);
 
        /* Set UPSMR register */
-       value = in_be32(upsmr_register);
-       value |= automatic_flow_control_mode;
-       out_be32(upsmr_register, value);
+       setbits32(upsmr_register, automatic_flow_control_mode);
 
        value = in_be32(maccfg1_register);
        if (rx_flow_control_enable)
@@ -1250,14 +1189,11 @@ static int init_hw_statistics_gathering_mode(int enable_hardware_statistics,
                                             u32 __iomem *upsmr_register,
                                             u16 __iomem *uescr_register)
 {
-       u32 upsmr_value = 0;
        u16 uescr_value = 0;
+
        /* Enable hardware statistics gathering if requested */
-       if (enable_hardware_statistics) {
-               upsmr_value = in_be32(upsmr_register);
-               upsmr_value |= UPSMR_HSE;
-               out_be32(upsmr_register, upsmr_value);
-       }
+       if (enable_hardware_statistics)
+               setbits32(upsmr_register, UCC_GETH_UPSMR_HSE);
 
        /* Clear hardware statistics counters */
        uescr_value = in_be16(uescr_register);
@@ -1283,23 +1219,17 @@ static int init_firmware_statistics_gathering_mode(int
 {
        /* Note: this function does not check if */
        /* the parameters it receives are NULL   */
-       u16 temoder_value;
-       u32 remoder_value;
 
        if (enable_tx_firmware_statistics) {
                out_be32(tx_rmon_base_ptr,
                         tx_firmware_statistics_structure_address);
-               temoder_value = in_be16(temoder_register);
-               temoder_value |= TEMODER_TX_RMON_STATISTICS_ENABLE;
-               out_be16(temoder_register, temoder_value);
+               setbits16(temoder_register, TEMODER_TX_RMON_STATISTICS_ENABLE);
        }
 
        if (enable_rx_firmware_statistics) {
                out_be32(rx_rmon_base_ptr,
                         rx_firmware_statistics_structure_address);
-               remoder_value = in_be32(remoder_register);
-               remoder_value |= REMODER_RX_RMON_STATISTICS_ENABLE;
-               out_be32(remoder_register, remoder_value);
+               setbits32(remoder_register, REMODER_RX_RMON_STATISTICS_ENABLE);
        }
 
        return 0;
@@ -1366,15 +1296,12 @@ static int init_check_frame_length_mode(int length_check,
 static int init_preamble_length(u8 preamble_length,
                                u32 __iomem *maccfg2_register)
 {
-       u32 value = 0;
-
        if ((preamble_length < 3) || (preamble_length > 7))
                return -EINVAL;
 
-       value = in_be32(maccfg2_register);
-       value &= ~MACCFG2_PREL_MASK;
-       value |= (preamble_length << MACCFG2_PREL_SHIFT);
-       out_be32(maccfg2_register, value);
+       clrsetbits_be32(maccfg2_register, MACCFG2_PREL_MASK,
+                       preamble_length << MACCFG2_PREL_SHIFT);
+
        return 0;
 }
 
@@ -1387,19 +1314,19 @@ static int init_rx_parameters(int reject_broadcast,
        value = in_be32(upsmr_register);
 
        if (reject_broadcast)
-               value |= UPSMR_BRO;
+               value |= UCC_GETH_UPSMR_BRO;
        else
-               value &= ~UPSMR_BRO;
+               value &= ~UCC_GETH_UPSMR_BRO;
 
        if (receive_short_frames)
-               value |= UPSMR_RSH;
+               value |= UCC_GETH_UPSMR_RSH;
        else
-               value &= ~UPSMR_RSH;
+               value &= ~UCC_GETH_UPSMR_RSH;
 
        if (promiscuous)
-               value |= UPSMR_PRO;
+               value |= UCC_GETH_UPSMR_PRO;
        else
-               value &= ~UPSMR_PRO;
+               value &= ~UCC_GETH_UPSMR_PRO;
 
        out_be32(upsmr_register, value);
 
@@ -1460,26 +1387,27 @@ static int adjust_enet_interface(struct ucc_geth_private *ugeth)
 
        /*                    Set UPSMR                      */
        upsmr = in_be32(&uf_regs->upsmr);
-       upsmr &= ~(UPSMR_RPM | UPSMR_R10M | UPSMR_TBIM | UPSMR_RMM);
+       upsmr &= ~(UCC_GETH_UPSMR_RPM | UCC_GETH_UPSMR_R10M |
+                  UCC_GETH_UPSMR_TBIM | UCC_GETH_UPSMR_RMM);
        if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) ||
            (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) ||
            (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) ||
            (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
            (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
            (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
-               upsmr |= UPSMR_RPM;
+               upsmr |= UCC_GETH_UPSMR_RPM;
                switch (ugeth->max_speed) {
                case SPEED_10:
-                       upsmr |= UPSMR_R10M;
+                       upsmr |= UCC_GETH_UPSMR_R10M;
                        /* FALLTHROUGH */
                case SPEED_100:
                        if (ugeth->phy_interface != PHY_INTERFACE_MODE_RTBI)
-                               upsmr |= UPSMR_RMM;
+                               upsmr |= UCC_GETH_UPSMR_RMM;
                }
        }
        if ((ugeth->phy_interface == PHY_INTERFACE_MODE_TBI) ||
            (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
-               upsmr |= UPSMR_TBIM;
+               upsmr |= UCC_GETH_UPSMR_TBIM;
        }
        out_be32(&uf_regs->upsmr, upsmr);
 
@@ -1567,9 +1495,9 @@ static void adjust_link(struct net_device *dev)
                                    (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
                                    (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
                                        if (phydev->speed == SPEED_10)
-                                               upsmr |= UPSMR_R10M;
+                                               upsmr |= UCC_GETH_UPSMR_R10M;
                                        else
-                                               upsmr &= ~(UPSMR_R10M);
+                                               upsmr &= ~UCC_GETH_UPSMR_R10M;
                                }
                                break;
                        default:
@@ -1608,6 +1536,11 @@ static void adjust_link(struct net_device *dev)
 static int init_phy(struct net_device *dev)
 {
        struct ucc_geth_private *priv = netdev_priv(dev);
+       struct device_node *np = priv->node;
+       struct device_node *phy, *mdio;
+       const phandle *ph;
+       char bus_name[MII_BUS_ID_SIZE];
+       const unsigned int *id;
        struct phy_device *phydev;
        char phy_id[BUS_ID_SIZE];
 
@@ -1615,8 +1548,18 @@ static int init_phy(struct net_device *dev)
        priv->oldspeed = 0;
        priv->oldduplex = -1;
 
-       snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT, priv->ug_info->mdio_bus,
-                priv->ug_info->phy_address);
+       ph = of_get_property(np, "phy-handle", NULL);
+       phy = of_find_node_by_phandle(*ph);
+       mdio = of_get_parent(phy);
+
+       id = of_get_property(phy, "reg", NULL);
+
+       of_node_put(phy);
+       of_node_put(mdio);
+
+       uec_mdio_bus_name(bus_name, mdio);
+       snprintf(phy_id, sizeof(phy_id), "%s:%02x",
+                                bus_name, *id);
 
        phydev = phy_connect(dev, phy_id, &adjust_link, 0, priv->phy_interface);
 
@@ -1652,10 +1595,8 @@ static int ugeth_graceful_stop_tx(struct ucc_geth_private *ugeth)
        uccf = ugeth->uccf;
 
        /* Mask GRACEFUL STOP TX interrupt bit and clear it */
-       temp = in_be32(uccf->p_uccm);
-       temp &= ~UCCE_GRA;
-       out_be32(uccf->p_uccm, temp);
-       out_be32(uccf->p_ucce, UCCE_GRA);       /* clear by writing 1 */
+       clrbits32(uccf->p_uccm, UCC_GETH_UCCE_GRA);
+       out_be32(uccf->p_ucce, UCC_GETH_UCCE_GRA);  /* clear by writing 1 */
 
        /* Issue host command */
        cecr_subblock =
@@ -1667,7 +1608,7 @@ static int ugeth_graceful_stop_tx(struct ucc_geth_private *ugeth)
        do {
                msleep(10);
                temp = in_be32(uccf->p_ucce);
-       } while (!(temp & UCCE_GRA) && --i);
+       } while (!(temp & UCC_GETH_UCCE_GRA) && --i);
 
        uccf->stopped_tx = 1;
 
@@ -1802,196 +1743,6 @@ static void ugeth_dump_regs(struct ucc_geth_private *ugeth)
 #endif
 }
 
-#ifdef CONFIG_UGETH_FILTERING
-static int ugeth_ext_filtering_serialize_tad(struct ucc_geth_tad_params *
-                                            p_UccGethTadParams,
-                                            struct qe_fltr_tad *qe_fltr_tad)
-{
-       u16 temp;
-
-       /* Zero serialized TAD */
-       memset(qe_fltr_tad, 0, QE_FLTR_TAD_SIZE);
-
-       qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_V;   /* Must have this */
-       if (p_UccGethTadParams->rx_non_dynamic_extended_features_mode ||
-           (p_UccGethTadParams->vtag_op != UCC_GETH_VLAN_OPERATION_TAGGED_NOP)
-           || (p_UccGethTadParams->vnontag_op !=
-               UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP)
-           )
-               qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_EF;
-       if (p_UccGethTadParams->reject_frame)
-               qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_REJ;
-       temp =
-           (u16) (((u16) p_UccGethTadParams->
-                   vtag_op) << UCC_GETH_TAD_VTAG_OP_SHIFT);
-       qe_fltr_tad->serialized[0] |= (u8) (temp >> 8); /* upper bits */
-
-       qe_fltr_tad->serialized[1] |= (u8) (temp & 0x00ff);     /* lower bits */
-       if (p_UccGethTadParams->vnontag_op ==
-           UCC_GETH_VLAN_OPERATION_NON_TAGGED_Q_TAG_INSERT)
-               qe_fltr_tad->serialized[1] |= UCC_GETH_TAD_V_NON_VTAG_OP;
-       qe_fltr_tad->serialized[1] |=
-           p_UccGethTadParams->rqos << UCC_GETH_TAD_RQOS_SHIFT;
-
-       qe_fltr_tad->serialized[2] |=
-           p_UccGethTadParams->vpri << UCC_GETH_TAD_V_PRIORITY_SHIFT;
-       /* upper bits */
-       qe_fltr_tad->serialized[2] |= (u8) (p_UccGethTadParams->vid >> 8);
-       /* lower bits */
-       qe_fltr_tad->serialized[3] |= (u8) (p_UccGethTadParams->vid & 0x00ff);
-
-       return 0;
-}
-
-static struct enet_addr_container_t
-    *ugeth_82xx_filtering_get_match_addr_in_hash(struct ucc_geth_private *ugeth,
-                                                struct enet_addr *p_enet_addr)
-{
-       struct enet_addr_container *enet_addr_cont;
-       struct list_head *p_lh;
-       u16 i, num;
-       int32_t j;
-       u8 *p_counter;
-
-       if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
-               p_lh = &ugeth->group_hash_q;
-               p_counter = &(ugeth->numGroupAddrInHash);
-       } else {
-               p_lh = &ugeth->ind_hash_q;
-               p_counter = &(ugeth->numIndAddrInHash);
-       }
-
-       if (!p_lh)
-               return NULL;
-
-       num = *p_counter;
-
-       for (i = 0; i < num; i++) {
-               enet_addr_cont =
-                   (struct enet_addr_container *)
-                   ENET_ADDR_CONT_ENTRY(dequeue(p_lh));
-               for (j = ENET_NUM_OCTETS_PER_ADDRESS - 1; j >= 0; j--) {
-                       if ((*p_enet_addr)[j] != (enet_addr_cont->address)[j])
-                               break;
-                       if (j == 0)
-                               return enet_addr_cont;  /* Found */
-               }
-               enqueue(p_lh, &enet_addr_cont->node);   /* Put it back */
-       }
-       return NULL;
-}
-
-static int ugeth_82xx_filtering_add_addr_in_hash(struct ucc_geth_private *ugeth,
-                                                struct enet_addr *p_enet_addr)
-{
-       enum ucc_geth_enet_address_recognition_location location;
-       struct enet_addr_container *enet_addr_cont;
-       struct list_head *p_lh;
-       u8 i;
-       u32 limit;
-       u8 *p_counter;
-
-       if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
-               p_lh = &ugeth->group_hash_q;
-               limit = ugeth->ug_info->maxGroupAddrInHash;
-               location =
-                   UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_GROUP_HASH;
-               p_counter = &(ugeth->numGroupAddrInHash);
-       } else {
-               p_lh = &ugeth->ind_hash_q;
-               limit = ugeth->ug_info->maxIndAddrInHash;
-               location =
-                   UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_INDIVIDUAL_HASH;
-               p_counter = &(ugeth->numIndAddrInHash);
-       }
-
-       if ((enet_addr_cont =
-            ugeth_82xx_filtering_get_match_addr_in_hash(ugeth, p_enet_addr))) {
-               list_add(p_lh, &enet_addr_cont->node);  /* Put it back */
-               return 0;
-       }
-       if ((!p_lh) || (!(*p_counter < limit)))
-               return -EBUSY;
-       if (!(enet_addr_cont = get_enet_addr_container()))
-               return -ENOMEM;
-       for (i = 0; i < ENET_NUM_OCTETS_PER_ADDRESS; i++)
-               (enet_addr_cont->address)[i] = (*p_enet_addr)[i];
-       enet_addr_cont->location = location;
-       enqueue(p_lh, &enet_addr_cont->node);   /* Put it back */
-       ++(*p_counter);
-
-       hw_add_addr_in_hash(ugeth, enet_addr_cont->address);
-       return 0;
-}
-
-static int ugeth_82xx_filtering_clear_addr_in_hash(struct ucc_geth_private *ugeth,
-                                                  struct enet_addr *p_enet_addr)
-{
-       struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
-       struct enet_addr_container *enet_addr_cont;
-       struct ucc_fast_private *uccf;
-       enum comm_dir comm_dir;
-       u16 i, num;
-       struct list_head *p_lh;
-       u32 *addr_h, *addr_l;
-       u8 *p_counter;
-
-       uccf = ugeth->uccf;
-
-       p_82xx_addr_filt =
-           (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
-           addressfiltering;
-
-       if (!
-           (enet_addr_cont =
-            ugeth_82xx_filtering_get_match_addr_in_hash(ugeth, p_enet_addr)))
-               return -ENOENT;
-
-       /* It's been found and removed from the CQ. */
-       /* Now destroy its container */
-       put_enet_addr_container(enet_addr_cont);
-
-       if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
-               addr_h = &(p_82xx_addr_filt->gaddr_h);
-               addr_l = &(p_82xx_addr_filt->gaddr_l);
-               p_lh = &ugeth->group_hash_q;
-               p_counter = &(ugeth->numGroupAddrInHash);
-       } else {
-               addr_h = &(p_82xx_addr_filt->iaddr_h);
-               addr_l = &(p_82xx_addr_filt->iaddr_l);
-               p_lh = &ugeth->ind_hash_q;
-               p_counter = &(ugeth->numIndAddrInHash);
-       }
-
-       comm_dir = 0;
-       if (uccf->enabled_tx)
-               comm_dir |= COMM_DIR_TX;
-       if (uccf->enabled_rx)
-               comm_dir |= COMM_DIR_RX;
-       if (comm_dir)
-               ugeth_disable(ugeth, comm_dir);
-
-       /* Clear the hash table. */
-       out_be32(addr_h, 0x00000000);
-       out_be32(addr_l, 0x00000000);
-
-       /* Add all remaining CQ elements back into hash */
-       num = --(*p_counter);
-       for (i = 0; i < num; i++) {
-               enet_addr_cont =
-                   (struct enet_addr_container *)
-                   ENET_ADDR_CONT_ENTRY(dequeue(p_lh));
-               hw_add_addr_in_hash(ugeth, enet_addr_cont->address);
-               enqueue(p_lh, &enet_addr_cont->node);   /* Put it back */
-       }
-
-       if (comm_dir)
-               ugeth_enable(ugeth, comm_dir);
-
-       return 0;
-}
-#endif /* CONFIG_UGETH_FILTERING */
-
 static int ugeth_82xx_filtering_clear_all_addr_in_hash(struct ucc_geth_private *
                                                       ugeth,
                                                       enum enet_addr_type
@@ -2054,28 +1805,6 @@ static int ugeth_82xx_filtering_clear_all_addr_in_hash(struct ucc_geth_private *
        return 0;
 }
 
-#ifdef CONFIG_UGETH_FILTERING
-static int ugeth_82xx_filtering_add_addr_in_paddr(struct ucc_geth_private *ugeth,
-                                                 struct enet_addr *p_enet_addr,
-                                                 u8 paddr_num)
-{
-       int i;
-
-       if ((*p_enet_addr)[0] & ENET_GROUP_ADDR)
-               ugeth_warn
-                   ("%s: multicast address added to paddr will have no "
-                    "effect - is this what you wanted?",
-                    __func__);
-
-       ugeth->indAddrRegUsed[paddr_num] = 1;   /* mark this paddr as used */
-       /* store address in our database */
-       for (i = 0; i < ENET_NUM_OCTETS_PER_ADDRESS; i++)
-               ugeth->paddr[paddr_num][i] = (*p_enet_addr)[i];
-       /* put in hardware */
-       return hw_add_addr_in_paddr(ugeth, p_enet_addr, paddr_num);
-}
-#endif /* CONFIG_UGETH_FILTERING */
-
 static int ugeth_82xx_filtering_clear_addr_in_paddr(struct ucc_geth_private *ugeth,
                                                    u8 paddr_num)
 {
@@ -2218,7 +1947,10 @@ static void ucc_geth_memclean(struct ucc_geth_private *ugeth)
        while (!list_empty(&ugeth->ind_hash_q))
                put_enet_addr_container(ENET_ADDR_CONT_ENTRY
                                        (dequeue(&ugeth->ind_hash_q)));
-
+       if (ugeth->ug_regs) {
+               iounmap(ugeth->ug_regs);
+               ugeth->ug_regs = NULL;
+       }
 }
 
 static void ucc_geth_set_multi(struct net_device *dev)
@@ -2234,12 +1966,9 @@ static void ucc_geth_set_multi(struct net_device *dev)
        uf_regs = ugeth->uccf->uf_regs;
 
        if (dev->flags & IFF_PROMISC) {
-
-               out_be32(&uf_regs->upsmr, in_be32(&uf_regs->upsmr) | UPSMR_PRO);
-
+               setbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
        } else {
-
-               out_be32(&uf_regs->upsmr, in_be32(&uf_regs->upsmr)&~UPSMR_PRO);
+               clrbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
 
                p_82xx_addr_filt =
                    (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->
@@ -2279,7 +2008,6 @@ static void ucc_geth_stop(struct ucc_geth_private *ugeth)
 {
        struct ucc_geth __iomem *ug_regs = ugeth->ug_regs;
        struct phy_device *phydev = ugeth->phydev;
-       u32 tempval;
 
        ugeth_vdbg("%s: IN", __func__);
 
@@ -2296,9 +2024,7 @@ static void ucc_geth_stop(struct ucc_geth_private *ugeth)
        out_be32(ugeth->uccf->p_ucce, 0xffffffff);
 
        /* Disable Rx and Tx */
-       tempval = in_be32(&ug_regs->maccfg1);
-       tempval &= ~(MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
-       out_be32(&ug_regs->maccfg1, tempval);
+       clrbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
 
        ucc_geth_memclean(ugeth);
 }
@@ -2412,19 +2138,23 @@ static int ucc_struct_init(struct ucc_geth_private *ugeth)
        /* Generate uccm_mask for receive */
        uf_info->uccm_mask = ug_info->eventRegMask & UCCE_OTHER;/* Errors */
        for (i = 0; i < ug_info->numQueuesRx; i++)
-               uf_info->uccm_mask |= (UCCE_RXBF_SINGLE_MASK << i);
+               uf_info->uccm_mask |= (UCC_GETH_UCCE_RXF0 << i);
 
        for (i = 0; i < ug_info->numQueuesTx; i++)
-               uf_info->uccm_mask |= (UCCE_TXBF_SINGLE_MASK << i);
+               uf_info->uccm_mask |= (UCC_GETH_UCCE_TXB0 << i);
        /* Initialize the general fast UCC block. */
        if (ucc_fast_init(uf_info, &ugeth->uccf)) {
                if (netif_msg_probe(ugeth))
                        ugeth_err("%s: Failed to init uccf.", __func__);
-               ucc_geth_memclean(ugeth);
                return -ENOMEM;
        }
 
-       ugeth->ug_regs = (struct ucc_geth __iomem *) ioremap(uf_info->regs, sizeof(struct ucc_geth));
+       ugeth->ug_regs = ioremap(uf_info->regs, sizeof(*ugeth->ug_regs));
+       if (!ugeth->ug_regs) {
+               if (netif_msg_probe(ugeth))
+                       ugeth_err("%s: Failed to ioremap regs.", __func__);
+               return -ENOMEM;
+       }
 
        return 0;
 }
@@ -2440,7 +2170,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
        struct ucc_geth __iomem *ug_regs;
        int ret_val = -EINVAL;
        u32 remoder = UCC_GETH_REMODER_INIT;
-       u32 init_enet_pram_offset, cecr_subblock, command, maccfg1;
+       u32 init_enet_pram_offset, cecr_subblock, command;
        u32 ifstat, i, j, size, l2qt, l3qt, length;
        u16 temoder = UCC_GETH_TEMODER_INIT;
        u16 test;
@@ -2476,7 +2206,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                if (netif_msg_ifup(ugeth))
                        ugeth_err("%s: Bad number of Rx threads value.",
                                        __func__);
-               ucc_geth_memclean(ugeth);
                return -EINVAL;
                break;
        }
@@ -2501,7 +2230,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                if (netif_msg_ifup(ugeth))
                        ugeth_err("%s: Bad number of Tx threads value.",
                                        __func__);
-               ucc_geth_memclean(ugeth);
                return -EINVAL;
                break;
        }
@@ -2538,10 +2266,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                                 &uf_regs->upsmr,
                                 &ug_regs->uempr, &ug_regs->maccfg1);
 
-       maccfg1 = in_be32(&ug_regs->maccfg1);
-       maccfg1 |= MACCFG1_ENABLE_RX;
-       maccfg1 |= MACCFG1_ENABLE_TX;
-       out_be32(&ug_regs->maccfg1, maccfg1);
+       setbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
 
        /*                    Set IPGIFG                     */
        /* For more details see the hardware spec.           */
@@ -2555,7 +2280,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                if (netif_msg_ifup(ugeth))
                        ugeth_err("%s: IPGIFG initialization parameter too large.",
                                  __func__);
-               ucc_geth_memclean(ugeth);
                return ret_val;
        }
 
@@ -2573,7 +2297,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                if (netif_msg_ifup(ugeth))
                        ugeth_err("%s: Half Duplex initialization parameter too large.",
                          __func__);
-               ucc_geth_memclean(ugeth);
                return ret_val;
        }
 
@@ -2628,7 +2351,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                                ugeth_err
                                    ("%s: Can not allocate memory for Tx bd rings.",
                                     __func__);
-                       ucc_geth_memclean(ugeth);
                        return -ENOMEM;
                }
                /* Zero unused end of bd ring, according to spec */
@@ -2664,7 +2386,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                                ugeth_err
                                    ("%s: Can not allocate memory for Rx bd rings.",
                                     __func__);
-                       ucc_geth_memclean(ugeth);
                        return -ENOMEM;
                }
        }
@@ -2680,7 +2401,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        if (netif_msg_ifup(ugeth))
                                ugeth_err("%s: Could not allocate tx_skbuff",
                                          __func__);
-                       ucc_geth_memclean(ugeth);
                        return -ENOMEM;
                }
 
@@ -2712,7 +2432,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        if (netif_msg_ifup(ugeth))
                                ugeth_err("%s: Could not allocate rx_skbuff",
                                          __func__);
-                       ucc_geth_memclean(ugeth);
                        return -ENOMEM;
                }
 
@@ -2746,7 +2465,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        ugeth_err
                            ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.",
                             __func__);
-               ucc_geth_memclean(ugeth);
                return -ENOMEM;
        }
        ugeth->p_tx_glbl_pram =
@@ -2769,7 +2487,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        ugeth_err
                            ("%s: Can not allocate DPRAM memory for p_thread_data_tx.",
                             __func__);
-               ucc_geth_memclean(ugeth);
                return -ENOMEM;
        }
 
@@ -2799,7 +2516,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        ugeth_err
                            ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.",
                             __func__);
-               ucc_geth_memclean(ugeth);
                return -ENOMEM;
        }
 
@@ -2843,7 +2559,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                                ugeth_err
                                 ("%s: Can not allocate DPRAM memory for p_scheduler.",
                                     __func__);
-                       ucc_geth_memclean(ugeth);
                        return -ENOMEM;
                }
 
@@ -2894,7 +2609,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                                    ("%s: Can not allocate DPRAM memory for"
                                        " p_tx_fw_statistics_pram.",
                                        __func__);
-                       ucc_geth_memclean(ugeth);
                        return -ENOMEM;
                }
                ugeth->p_tx_fw_statistics_pram =
@@ -2934,7 +2648,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        ugeth_err
                            ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.",
                             __func__);
-               ucc_geth_memclean(ugeth);
                return -ENOMEM;
        }
        ugeth->p_rx_glbl_pram =
@@ -2956,7 +2669,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        ugeth_err
                            ("%s: Can not allocate DPRAM memory for p_thread_data_rx.",
                             __func__);
-               ucc_geth_memclean(ugeth);
                return -ENOMEM;
        }
 
@@ -2980,7 +2692,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                                ugeth_err
                                        ("%s: Can not allocate DPRAM memory for"
                                        " p_rx_fw_statistics_pram.", __func__);
-                       ucc_geth_memclean(ugeth);
                        return -ENOMEM;
                }
                ugeth->p_rx_fw_statistics_pram =
@@ -3003,7 +2714,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        ugeth_err
                            ("%s: Can not allocate DPRAM memory for"
                                " p_rx_irq_coalescing_tbl.", __func__);
-               ucc_geth_memclean(ugeth);
                return -ENOMEM;
        }
 
@@ -3072,7 +2782,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        ugeth_err
                            ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.",
                             __func__);
-               ucc_geth_memclean(ugeth);
                return -ENOMEM;
        }
 
@@ -3149,7 +2858,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        if (netif_msg_ifup(ugeth))
                                ugeth_err("%s: Null Extended Filtering Chain Pointer.",
                                          __func__);
-                       ucc_geth_memclean(ugeth);
                        return -EINVAL;
                }
 
@@ -3163,7 +2871,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                                ugeth_err
                                        ("%s: Can not allocate DPRAM memory for"
                                        " p_exf_glbl_param.", __func__);
-                       ucc_geth_memclean(ugeth);
                        return -ENOMEM;
                }
 
@@ -3211,7 +2918,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        ugeth_err
                            ("%s: Can not allocate memory for"
                                " p_UccInitEnetParamShadows.", __func__);
-               ucc_geth_memclean(ugeth);
                return -ENOMEM;
        }
        /* Zero out *p_init_enet_param_shadow */
@@ -3246,7 +2952,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                if (netif_msg_ifup(ugeth))
                        ugeth_err("%s: Invalid largest External Lookup Key Size.",
                                  __func__);
-               ucc_geth_memclean(ugeth);
                return -EINVAL;
        }
        ugeth->p_init_enet_param_shadow->largestexternallookupkeysize =
@@ -3273,7 +2978,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                if (netif_msg_ifup(ugeth))
                                ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
                                        __func__);
-               ucc_geth_memclean(ugeth);
                return ret_val;
        }
 
@@ -3289,7 +2993,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                if (netif_msg_ifup(ugeth))
                        ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
                                  __func__);
-               ucc_geth_memclean(ugeth);
                return ret_val;
        }
 
@@ -3299,7 +3002,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        if (netif_msg_ifup(ugeth))
                                ugeth_err("%s: Can not fill Rx bds with buffers.",
                                          __func__);
-                       ucc_geth_memclean(ugeth);
                        return ret_val;
                }
        }
@@ -3311,7 +3013,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        ugeth_err
                            ("%s: Can not allocate DPRAM memory for p_init_enet_pram.",
                             __func__);
-               ucc_geth_memclean(ugeth);
                return -ENOMEM;
        }
        p_init_enet_pram =
@@ -3353,48 +3054,6 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
        return 0;
 }
 
-static int ucc_geth_close(struct net_device *dev);
-static int ucc_geth_open(struct net_device *dev);
-
-/* Reopen device. This will reset the MAC and PHY. */
-static void ucc_geth_timeout_work(struct work_struct *work)
-{
-       struct ucc_geth_private *ugeth;
-       struct net_device *dev;
-
-       ugeth = container_of(work, struct ucc_geth_private, timeout_work);
-       dev = ugeth->dev;
-
-       ugeth_vdbg("%s: IN", __func__);
-
-       dev->stats.tx_errors++;
-
-       ugeth_dump_regs(ugeth);
-
-       if (dev->flags & IFF_UP) {
-               /*
-                * Must reset MAC *and* PHY. This is done by reopening
-                * the device.
-                */
-               ucc_geth_close(dev);
-               ucc_geth_open(dev);
-       }
-
-       netif_tx_schedule_all(dev);
-}
-
-/*
- * ucc_geth_timeout gets called when a packet has not been
- * transmitted after a set amount of time.
- */
-static void ucc_geth_timeout(struct net_device *dev)
-{
-       struct ucc_geth_private *ugeth = netdev_priv(dev);
-
-       netif_carrier_off(dev);
-       schedule_work(&ugeth->timeout_work);
-}
-
 /* This is called by the kernel when a frame is ready for transmission. */
 /* It is pointed to by the dev->hard_start_xmit function pointer */
 static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev)
@@ -3597,7 +3256,6 @@ static int ucc_geth_tx(struct net_device *dev, u8 txQ)
 static int ucc_geth_poll(struct napi_struct *napi, int budget)
 {
        struct ucc_geth_private *ugeth = container_of(napi, struct ucc_geth_private, napi);
-       struct net_device *dev = ugeth->dev;
        struct ucc_geth_info *ug_info;
        int howmany, i;
 
@@ -3608,14 +3266,8 @@ static int ucc_geth_poll(struct napi_struct *napi, int budget)
                howmany += ucc_geth_rx(ugeth, i, budget - howmany);
 
        if (howmany < budget) {
-               struct ucc_fast_private *uccf;
-               u32 uccm;
-
-               netif_rx_complete(dev, napi);
-               uccf = ugeth->uccf;
-               uccm = in_be32(uccf->p_uccm);
-               uccm |= UCCE_RX_EVENTS;
-               out_be32(uccf->p_uccm, uccm);
+               netif_rx_complete(napi);
+               setbits32(ugeth->uccf->p_uccm, UCCE_RX_EVENTS);
        }
 
        return howmany;
@@ -3645,17 +3297,17 @@ static irqreturn_t ucc_geth_irq_handler(int irq, void *info)
 
        /* check for receive events that require processing */
        if (ucce & UCCE_RX_EVENTS) {
-               if (netif_rx_schedule_prep(dev, &ugeth->napi)) {
+               if (netif_rx_schedule_prep(&ugeth->napi)) {
                        uccm &= ~UCCE_RX_EVENTS;
                        out_be32(uccf->p_uccm, uccm);
-                       __netif_rx_schedule(dev, &ugeth->napi);
+                       __netif_rx_schedule(&ugeth->napi);
                }
        }
 
        /* Tx event processing */
        if (ucce & UCCE_TX_EVENTS) {
                spin_lock(&ugeth->lock);
-               tx_mask = UCCE_TXBF_SINGLE_MASK;
+               tx_mask = UCC_GETH_UCCE_TXB0;
                for (i = 0; i < ug_info->numQueuesTx; i++) {
                        if (ucce & tx_mask)
                                ucc_geth_tx(dev, i);
@@ -3667,12 +3319,10 @@ static irqreturn_t ucc_geth_irq_handler(int irq, void *info)
 
        /* Errors and other events */
        if (ucce & UCCE_OTHER) {
-               if (ucce & UCCE_BSY) {
+               if (ucce & UCC_GETH_UCCE_BSY)
                        dev->stats.rx_errors++;
-               }
-               if (ucce & UCCE_TXE) {
+               if (ucce & UCC_GETH_UCCE_TXE)
                        dev->stats.tx_errors++;
-               }
        }
 
        return IRQ_HANDLED;
@@ -3716,7 +3366,7 @@ static int ucc_geth_open(struct net_device *dev)
        if (err) {
                if (netif_msg_ifup(ugeth))
                        ugeth_err("%s: Cannot configure internal struct, aborting.", dev->name);
-               return err;
+               goto out_err_stop;
        }
 
        napi_enable(&ugeth->napi);
@@ -3761,7 +3411,6 @@ static int ucc_geth_open(struct net_device *dev)
        if (err) {
                if (netif_msg_ifup(ugeth))
                        ugeth_err("%s: Cannot enable net device, aborting.", dev->name);
-               ucc_geth_stop(ugeth);
                goto out_err;
        }
 
@@ -3771,7 +3420,6 @@ static int ucc_geth_open(struct net_device *dev)
                if (netif_msg_ifup(ugeth))
                        ugeth_err("%s: Cannot get IRQ for net device, aborting.",
                                  dev->name);
-               ucc_geth_stop(ugeth);
                goto out_err;
        }
 
@@ -3781,7 +3429,8 @@ static int ucc_geth_open(struct net_device *dev)
 
 out_err:
        napi_disable(&ugeth->napi);
-
+out_err_stop:
+       ucc_geth_stop(ugeth);
        return err;
 }
 
@@ -3806,6 +3455,45 @@ static int ucc_geth_close(struct net_device *dev)
        return 0;
 }
 
+/* Reopen device. This will reset the MAC and PHY. */
+static void ucc_geth_timeout_work(struct work_struct *work)
+{
+       struct ucc_geth_private *ugeth;
+       struct net_device *dev;
+
+       ugeth = container_of(work, struct ucc_geth_private, timeout_work);
+       dev = ugeth->dev;
+
+       ugeth_vdbg("%s: IN", __func__);
+
+       dev->stats.tx_errors++;
+
+       ugeth_dump_regs(ugeth);
+
+       if (dev->flags & IFF_UP) {
+               /*
+                * Must reset MAC *and* PHY. This is done by reopening
+                * the device.
+                */
+               ucc_geth_close(dev);
+               ucc_geth_open(dev);
+       }
+
+       netif_tx_schedule_all(dev);
+}
+
+/*
+ * ucc_geth_timeout gets called when a packet has not been
+ * transmitted after a set amount of time.
+ */
+static void ucc_geth_timeout(struct net_device *dev)
+{
+       struct ucc_geth_private *ugeth = netdev_priv(dev);
+
+       netif_carrier_off(dev);
+       schedule_work(&ugeth->timeout_work);
+}
+
 static phy_interface_t to_phy_interface(const char *phy_connection_type)
 {
        if (strcasecmp(phy_connection_type, "mii") == 0)
@@ -4075,6 +3763,7 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
 
        ugeth->ug_info = ug_info;
        ugeth->dev = dev;
+       ugeth->node = np;
 
        return 0;
 }