]> git.sur5r.net Git - u-boot/blobdiff - drivers/net/rtl8169.c
mmc: sdhci: Avoid commands errors by simple timeout adaptation.
[u-boot] / drivers / net / rtl8169.c
index 83a05b45b9e5b19b47b1a4dd9acf33287a728fec..13fa9c02febcf751805c60ae0be999ea33ac875f 100644 (file)
 *    r8169.c: Etherboot device driver for the RealTek RTL-8169 Gigabit
 *    Written 2003 by Timothy Legge <tlegge@rogers.com>
 *
-*    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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * SPDX-License-Identifier:    GPL-2.0+
 *
 *    Portions of this code based on:
 *      r8169.c: A RealTek RTL-8169 Gigabit Ethernet driver
@@ -110,6 +98,9 @@ static int media[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1 };
 #define ETH_ALEN       MAC_ADDR_LEN
 #define ETH_ZLEN       60
 
+#define bus_to_phys(a) pci_mem_to_phys((pci_dev_t)dev->priv, (pci_addr_t)a)
+#define phys_to_bus(a) pci_phys_to_mem((pci_dev_t)dev->priv, (phys_addr_t)a)
+
 enum RTL8169_registers {
        MAC0 = 0,               /* Ethernet hardware address. */
        MAR0 = 8,               /* Multicast filter. */
@@ -438,7 +429,7 @@ static int rtl_recv(struct eth_device *dev)
                                tpc->RxDescArray[cur_rx].status =
                                        cpu_to_le32(OWNbit + RX_BUF_SIZE);
                        tpc->RxDescArray[cur_rx].buf_addr =
-                               cpu_to_le32((unsigned long)tpc->RxBufferRing[cur_rx]);
+                               cpu_to_le32(bus_to_phys(tpc->RxBufferRing[cur_rx]));
                        flush_cache((unsigned long)tpc->RxBufferRing[cur_rx],
                                        RX_BUF_SIZE);
                } else {
@@ -461,7 +452,7 @@ static int rtl_recv(struct eth_device *dev)
 /**************************************************************************
 SEND - Transmit a frame
 ***************************************************************************/
-static int rtl_send(struct eth_device *dev, volatile void *packet, int length)
+static int rtl_send(struct eth_device *dev, void *packet, int length)
 {
        /* send the packet to destination */
 
@@ -488,7 +479,7 @@ static int rtl_send(struct eth_device *dev, volatile void *packet, int length)
                ptxb[len++] = '\0';
 
        tpc->TxDescArray[entry].buf_Haddr = 0;
-       tpc->TxDescArray[entry].buf_addr = cpu_to_le32((unsigned long)ptxb);
+       tpc->TxDescArray[entry].buf_addr = cpu_to_le32(bus_to_phys(ptxb));
        if (entry != (NUM_TX_DESC - 1)) {
                tpc->TxDescArray[entry].status =
                        cpu_to_le32((OWNbit | FSbit | LSbit) |
@@ -593,9 +584,9 @@ static void rtl8169_hw_start(struct eth_device *dev)
 
        tpc->cur_rx = 0;
 
-       RTL_W32(TxDescStartAddrLow, (unsigned long)tpc->TxDescArray);
+       RTL_W32(TxDescStartAddrLow, bus_to_phys(tpc->TxDescArray));
        RTL_W32(TxDescStartAddrHigh, (unsigned long)0);
-       RTL_W32(RxDescStartAddrLow, (unsigned long)tpc->RxDescArray);
+       RTL_W32(RxDescStartAddrLow, bus_to_phys(tpc->RxDescArray));
        RTL_W32(RxDescStartAddrHigh, (unsigned long)0);
 
        /* RTL-8169sc/8110sc or later version */
@@ -646,7 +637,7 @@ static void rtl8169_init_ring(struct eth_device *dev)
 
                tpc->RxBufferRing[i] = &rxb[i * RX_BUF_SIZE];
                tpc->RxDescArray[i].buf_addr =
-                       cpu_to_le32((unsigned long)tpc->RxBufferRing[i]);
+                       cpu_to_le32(bus_to_phys(tpc->RxBufferRing[i]));
                flush_cache((unsigned long)tpc->RxBufferRing[i], RX_BUF_SIZE);
        }
 
@@ -736,7 +727,6 @@ INIT - Look for an adapter, this routine's visible to the outside
 static int rtl_init(struct eth_device *dev, bd_t *bis)
 {
        static int board_idx = -1;
-       static int printed_version = 0;
        int i, rc;
        int option = -1, Cap10_100 = 0, Cap1000 = 0;
 
@@ -748,8 +738,6 @@ static int rtl_init(struct eth_device *dev, bd_t *bis)
 
        board_idx++;
 
-       printed_version = 1;
-
        /* point to private storage */
        tpc = &tpx;
 
@@ -891,7 +879,12 @@ int rtl8169_initialize(bd_t *bis)
                debug ("rtl8169: REALTEK RTL8169 @0x%x\n", iobase);
 
                dev = (struct eth_device *)malloc(sizeof *dev);
+               if (!dev) {
+                       printf("Can not allocate memory of rtl8169\n");
+                       break;
+               }
 
+               memset(dev, 0, sizeof(*dev));
                sprintf (dev->name, "RTL8169#%d", card_number);
 
                dev->priv = (void *) devno;