]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/net/davinci_emac.c
Merge http://git.denx.de/u-boot-sunxi
[karo-tx-uboot.git] / drivers / net / davinci_emac.c
index 2ac6874b35824593a5d200bdf021ea3c3c070448..08bc1afcf638be1dbde9e1c23662a829c2bfa298 100644 (file)
  *
  * ----------------------------------------------------------------------------
  *
- * 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.
+ * SPDX-License-Identifier:    GPL-2.0+
  *
- * 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.
- * ----------------------------------------------------------------------------
-
  * Modifications:
  * ver. 1.0: Sep 2005, Anant Gole - Created EMAC version for uBoot.
  * ver  1.1: Nov 2005, Anant Gole - Extended the RX logic for multiple descriptors
- *
  */
 #include <common.h>
 #include <command.h>
 #include <net.h>
 #include <miiphy.h>
 #include <malloc.h>
+#include <netdev.h>
+#include <linux/compiler.h>
 #include <asm/arch/emac_defs.h>
 #include <asm/io.h>
 #include "davinci_emac.h"
@@ -105,7 +93,8 @@ static volatile emac_desc    *emac_rx_active_tail = 0;
 static int                     emac_rx_queue_active = 0;
 
 /* Receive packet buffers */
-static unsigned char           emac_rx_buffers[EMAC_MAX_RX_BUFFERS * (EMAC_MAX_ETHERNET_PKT_SIZE + EMAC_PKT_ALIGN)];
+static unsigned char emac_rx_buffers[EMAC_MAX_RX_BUFFERS * EMAC_RXBUF_SIZE]
+                               __aligned(ARCH_DMA_MINALIGN);
 
 #ifndef CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT
 #define CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT      3
@@ -119,6 +108,26 @@ static u_int8_t    num_phy;
 
 phy_t                          phy[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT];
 
+static inline void davinci_flush_rx_descs(void)
+{
+       /* flush the whole RX descs area */
+       flush_dcache_range(EMAC_WRAPPER_RAM_ADDR + EMAC_RX_DESC_BASE,
+                       EMAC_WRAPPER_RAM_ADDR + EMAC_TX_DESC_BASE);
+}
+
+static inline void davinci_invalidate_rx_descs(void)
+{
+       /* invalidate the whole RX descs area */
+       invalidate_dcache_range(EMAC_WRAPPER_RAM_ADDR + EMAC_RX_DESC_BASE,
+                       EMAC_WRAPPER_RAM_ADDR + EMAC_TX_DESC_BASE);
+}
+
+static inline void davinci_flush_desc(emac_desc *desc)
+{
+       flush_dcache_range((unsigned long)desc,
+                       (unsigned long)desc + sizeof(*desc));
+}
+
 static int davinci_eth_set_mac_addr(struct eth_device *dev)
 {
        unsigned long           mac_hi;
@@ -198,7 +207,7 @@ static int davinci_eth_phy_detect(void)
        for (i = 0, j = 0; i < 32; i++)
                if (phy_act_state & (1 << i)) {
                        count++;
-                       if (count < CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT) {
+                       if (count <= CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT) {
                                active_phy_addr[j++] = i;
                        } else {
                                printf("%s: to many PHYs detected.\n",
@@ -470,7 +479,7 @@ static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
        emac_rx_active_head = emac_rx_desc;
        for (cnt = 0; cnt < EMAC_MAX_RX_BUFFERS; cnt++) {
                rx_desc->next = BD_TO_HW((u_int32_t)(rx_desc + 1));
-               rx_desc->buffer = &emac_rx_buffers[cnt * (EMAC_MAX_ETHERNET_PKT_SIZE + EMAC_PKT_ALIGN)];
+               rx_desc->buffer = &emac_rx_buffers[cnt * EMAC_RXBUF_SIZE];
                rx_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE;
                rx_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT;
                rx_desc++;
@@ -482,6 +491,8 @@ static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
        emac_rx_active_tail = rx_desc;
        emac_rx_queue_active = 1;
 
+       davinci_flush_rx_descs();
+
        /* Enable TX/RX */
        writel(EMAC_MAX_ETHERNET_PKT_SIZE, &adap_emac->RXMAXLEN);
        writel(0, &adap_emac->RXBUFFEROFFSET);
@@ -496,7 +507,8 @@ static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
        writel(1, &adap_emac->RXUNICASTSET);
 
        /* Enable MII interface and Full duplex mode */
-#ifdef CONFIG_SOC_DA8XX
+#if defined(CONFIG_SOC_DA8XX) || \
+       (defined(CONFIG_OMAP34XX) && defined(CONFIG_DRIVER_TI_EMAC_USE_RMII))
        writel((EMAC_MACCONTROL_MIIEN_ENABLE |
                EMAC_MACCONTROL_FULLDUPLEX_ENABLE |
                EMAC_MACCONTROL_RMIISPEED_100),
@@ -612,7 +624,7 @@ static int tx_send_loop = 0;
  * positive number (number of bytes transmitted) or negative for error
  */
 static int davinci_eth_send_packet (struct eth_device *dev,
-                                       volatile void *packet, int length)
+                                       void *packet, int length)
 {
        int ret_status = -1;
        int index;
@@ -639,6 +651,11 @@ static int davinci_eth_send_packet (struct eth_device *dev,
                                      EMAC_CPPI_SOP_BIT |
                                      EMAC_CPPI_OWNERSHIP_BIT |
                                      EMAC_CPPI_EOP_BIT);
+
+       flush_dcache_range((unsigned long)packet,
+                       (unsigned long)packet + length);
+       davinci_flush_desc(emac_tx_desc);
+
        /* Send the packet */
        writel(BD_TO_HW((unsigned long)emac_tx_desc), &adap_emac->TX0HDP);
 
@@ -671,6 +688,8 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
        volatile emac_desc *tail_desc;
        int status, ret = -1;
 
+       davinci_invalidate_rx_descs();
+
        rx_curr_desc = emac_rx_active_head;
        status = rx_curr_desc->pkt_flag_len;
        if ((rx_curr_desc) && ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0)) {
@@ -678,6 +697,9 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
                        /* Error in packet - discard it and requeue desc */
                        printf ("WARN: emac_rcv_pkt: Error in packet\n");
                } else {
+                       unsigned long tmp = (unsigned long)rx_curr_desc->buffer;
+
+                       invalidate_dcache_range(tmp, tmp + EMAC_RXBUF_SIZE);
                        NetReceive (rx_curr_desc->buffer,
                                    (rx_curr_desc->buff_off_len & 0xffff));
                        ret = rx_curr_desc->buff_off_len & 0xffff;
@@ -703,6 +725,7 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
                rx_curr_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE;
                rx_curr_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT;
                rx_curr_desc->next = 0;
+               davinci_flush_desc(rx_curr_desc);
 
                if (emac_rx_active_head == 0) {
                        printf ("INFO: emac_rcv_pkt: active queue head = 0\n");
@@ -720,11 +743,13 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
                        tail_desc->next = BD_TO_HW((ulong) curr_desc);
                        status = tail_desc->pkt_flag_len;
                        if (status & EMAC_CPPI_EOQ_BIT) {
+                               davinci_flush_desc(tail_desc);
                                writel(BD_TO_HW((ulong)curr_desc),
                                       &adap_emac->RX0HDP);
                                status &= ~EMAC_CPPI_EOQ_BIT;
                                tail_desc->pkt_flag_len = status;
                        }
+                       davinci_flush_desc(tail_desc);
                }
                return (ret);
        }
@@ -803,6 +828,7 @@ int davinci_emac_initialize(void)
                phy_id |= tmp & 0x0000ffff;
 
                switch (phy_id) {
+#ifdef PHY_KSZ8873
                case PHY_KSZ8873:
                        sprintf(phy[i].name, "KSZ8873 @ 0x%02x",
                                                active_phy_addr[i]);
@@ -811,6 +837,8 @@ int davinci_emac_initialize(void)
                        phy[i].get_link_speed = ksz8873_get_link_speed;
                        phy[i].auto_negotiate = ksz8873_auto_negotiate;
                        break;
+#endif
+#ifdef PHY_LXT972
                case PHY_LXT972:
                        sprintf(phy[i].name, "LXT972 @ 0x%02x",
                                                active_phy_addr[i]);
@@ -819,6 +847,8 @@ int davinci_emac_initialize(void)
                        phy[i].get_link_speed = lxt972_get_link_speed;
                        phy[i].auto_negotiate = lxt972_auto_negotiate;
                        break;
+#endif
+#ifdef PHY_DP83848
                case PHY_DP83848:
                        sprintf(phy[i].name, "DP83848 @ 0x%02x",
                                                active_phy_addr[i]);
@@ -827,6 +857,8 @@ int davinci_emac_initialize(void)
                        phy[i].get_link_speed = dp83848_get_link_speed;
                        phy[i].auto_negotiate = dp83848_auto_negotiate;
                        break;
+#endif
+#ifdef PHY_ET1011C
                case PHY_ET1011C:
                        sprintf(phy[i].name, "ET1011C @ 0x%02x",
                                                active_phy_addr[i]);
@@ -835,6 +867,7 @@ int davinci_emac_initialize(void)
                        phy[i].get_link_speed = et1011c_get_link_speed;
                        phy[i].auto_negotiate = gen_auto_negotiate;
                        break;
+#endif
                default:
                        sprintf(phy[i].name, "GENERIC @ 0x%02x",
                                                active_phy_addr[i]);
@@ -849,5 +882,14 @@ int davinci_emac_initialize(void)
                miiphy_register(phy[i].name, davinci_mii_phy_read,
                                                davinci_mii_phy_write);
        }
+
+#if defined(CONFIG_DRIVER_TI_EMAC_USE_RMII) && \
+               defined(CONFIG_MACH_DAVINCI_DA850_EVM) && \
+                       !defined(CONFIG_DRIVER_TI_EMAC_RMII_NO_NEGOTIATE)
+       for (i = 0; i < num_phy; i++) {
+               if (phy[i].is_phy_connected(i))
+                       phy[i].auto_negotiate(i);
+       }
+#endif
        return(1);
 }