]> git.sur5r.net Git - u-boot/blobdiff - drivers/net/pcnet.c
net: phy: broadcom: Add BCM Cygnus PHY
[u-boot] / drivers / net / pcnet.c
index 8c334c7abcc9a8077c2a638d985a628d9f791926..cfcb1b4e23326babd16ec1940cb3620cc5c5f65a 100644 (file)
@@ -80,7 +80,7 @@ struct pcnet_uncached_priv {
 typedef struct pcnet_priv {
        struct pcnet_uncached_priv *uc;
        /* Receive Buffer space */
-       unsigned char rx_buf[RX_RING_SIZE][PKT_BUF_SZ + 4];
+       unsigned char (*rx_buf)[RX_RING_SIZE][PKT_BUF_SZ + 4];
        int cur_rx;
        int cur_tx;
 } pcnet_priv_t;
@@ -335,6 +335,10 @@ static int pcnet_init(struct eth_device *dev, bd_t *bis)
                flush_dcache_range(addr, addr + sizeof(*lp->uc));
                addr = UNCACHED_SDRAM(addr);
                lp->uc = (struct pcnet_uncached_priv *)addr;
+
+               addr = (u32)memalign(ARCH_DMA_MINALIGN, sizeof(*lp->rx_buf));
+               flush_dcache_range(addr, addr + sizeof(*lp->rx_buf));
+               lp->rx_buf = (void *)addr;
        }
 
        uc = lp->uc;
@@ -348,7 +352,7 @@ static int pcnet_init(struct eth_device *dev, bd_t *bis)
         */
        lp->cur_rx = 0;
        for (i = 0; i < RX_RING_SIZE; i++) {
-               uc->rx_ring[i].base = PCI_TO_MEM_LE(dev, lp->rx_buf[i]);
+               uc->rx_ring[i].base = PCI_TO_MEM_LE(dev, (*lp->rx_buf)[i]);
                uc->rx_ring[i].buf_length = cpu_to_le16(-PKT_BUF_SZ);
                uc->rx_ring[i].status = cpu_to_le16(0x8000);
                PCNET_DEBUG1
@@ -430,7 +434,7 @@ static int pcnet_send(struct eth_device *dev, void *packet, int pkt_len)
 
        /* Wait for completion by testing the OWN bit */
        for (i = 1000; i > 0; i--) {
-               status = le16_to_cpu(entry->status);
+               status = readw(&entry->status);
                if ((status & 0x8000) == 0)
                        break;
                udelay(100);
@@ -447,11 +451,10 @@ static int pcnet_send(struct eth_device *dev, void *packet, int pkt_len)
         * Setup Tx ring. Caution: the write order is important here,
         * set the status with the "ownership" bits last.
         */
-       status = 0x8300;
-       entry->length = cpu_to_le16(-pkt_len);
-       entry->misc = 0x00000000;
-       entry->base = PCI_TO_MEM_LE(dev, packet);
-       entry->status = cpu_to_le16(status);
+       writew(-pkt_len, &entry->length);
+       writel(0, &entry->misc);
+       writel(PCI_TO_MEM(dev, packet), &entry->base);
+       writew(0x8300, &entry->status);
 
        /* Trigger an immediate send poll. */
        pcnet_write_csr(dev, 0, 0x0008);
@@ -467,50 +470,51 @@ static int pcnet_send(struct eth_device *dev, void *packet, int pkt_len)
 static int pcnet_recv (struct eth_device *dev)
 {
        struct pcnet_rx_head *entry;
+       unsigned char *buf;
        int pkt_len = 0;
-       u16 status;
+       u16 status, err_status;
 
        while (1) {
                entry = &lp->uc->rx_ring[lp->cur_rx];
                /*
                 * If we own the next entry, it's a new packet. Send it up.
                 */
-               status = le16_to_cpu(entry->status);
+               status = readw(&entry->status);
                if ((status & 0x8000) != 0)
                        break;
-               status >>= 8;
+               err_status = status >> 8;
 
-               if (status != 0x03) {   /* There was an error. */
+               if (err_status != 0x03) {       /* There was an error. */
                        printf("%s: Rx%d", dev->name, lp->cur_rx);
-                       PCNET_DEBUG1(" (status=0x%x)", status);
-                       if (status & 0x20)
+                       PCNET_DEBUG1(" (status=0x%x)", err_status);
+                       if (err_status & 0x20)
                                printf(" Frame");
-                       if (status & 0x10)
+                       if (err_status & 0x10)
                                printf(" Overflow");
-                       if (status & 0x08)
+                       if (err_status & 0x08)
                                printf(" CRC");
-                       if (status & 0x04)
+                       if (err_status & 0x04)
                                printf(" Fifo");
                        printf(" Error\n");
-                       entry->status &= le16_to_cpu(0x03ff);
+                       status &= 0x03ff;
 
                } else {
-                       pkt_len = (le32_to_cpu(entry->msg_length) & 0xfff) - 4;
+                       pkt_len = (readl(&entry->msg_length) & 0xfff) - 4;
                        if (pkt_len < 60) {
                                printf("%s: Rx%d: invalid packet length %d\n",
                                       dev->name, lp->cur_rx, pkt_len);
                        } else {
-                               invalidate_dcache_range(
-                                       (unsigned long)lp->rx_buf[lp->cur_rx],
-                                       (unsigned long)lp->rx_buf[lp->cur_rx] +
-                                       pkt_len);
-                               NetReceive(lp->rx_buf[lp->cur_rx], pkt_len);
+                               buf = (*lp->rx_buf)[lp->cur_rx];
+                               invalidate_dcache_range((unsigned long)buf,
+                                       (unsigned long)buf + pkt_len);
+                               net_process_received_packet(buf, pkt_len);
                                PCNET_DEBUG2("Rx%d: %d bytes from 0x%p\n",
-                                            lp->cur_rx, pkt_len,
-                                            lp->rx_buf[lp->cur_rx]);
+                                            lp->cur_rx, pkt_len, buf);
                        }
                }
-               entry->status |= cpu_to_le16(0x8000);
+
+               status |= 0x8000;
+               writew(status, &entry->status);
 
                if (++lp->cur_rx >= RX_RING_SIZE)
                        lp->cur_rx = 0;