]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/net/keystone_net.c
net: rtl8169: Build warning fixes for 64-bit
[karo-tx-uboot.git] / drivers / net / keystone_net.c
index 13a1778298afa124f70a5717d931f4b52938ce1c..0c5fdeefd758424bc64e97fd51ed97762e793094 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <net.h>
 #include <phy.h>
+#include <errno.h>
 #include <miiphy.h>
 #include <malloc.h>
 #include <asm/ti-common/keystone_nav.h>
@@ -30,6 +31,7 @@ static unsigned int sys_has_mdio = 1;
 #define RX_BUFF_NUMS   24
 #define RX_BUFF_LEN    1520
 #define MAX_SIZE_STREAM_BUFFER RX_BUFF_LEN
+#define SGMII_ANEG_TIMEOUT             4000
 
 static u8 rx_buffs[RX_BUFF_NUMS * RX_BUFF_LEN] __aligned(16);
 
@@ -169,7 +171,7 @@ int keystone_sgmii_link_status(int port)
               (status & SGMII_REG_STATUS_LINK);
 }
 
-int keystone_sgmii_config(int port, int interface)
+int keystone_sgmii_config(struct phy_device *phy_dev, int port, int interface)
 {
        unsigned int i, status, mask;
        unsigned int mr_adv_ability, control;
@@ -230,11 +232,35 @@ int keystone_sgmii_config(int port, int interface)
        if (control & SGMII_REG_CONTROL_AUTONEG)
                mask |= SGMII_REG_STATUS_AUTONEG;
 
-       for (i = 0; i < 1000; i++) {
+       status = __raw_readl(SGMII_STATUS_REG(port));
+       if ((status & mask) == mask)
+               return 0;
+
+       printf("\n%s Waiting for SGMII auto negotiation to complete",
+              phy_dev->dev->name);
+       while ((status & mask) != mask) {
+               /*
+                * Timeout reached ?
+                */
+               if (i > SGMII_ANEG_TIMEOUT) {
+                       puts(" TIMEOUT !\n");
+                       phy_dev->link = 0;
+                       return 0;
+               }
+
+               if (ctrlc()) {
+                       puts("user interrupt!\n");
+                       phy_dev->link = 0;
+                       return -EINTR;
+               }
+
+               if ((i++ % 500) == 0)
+                       printf(".");
+
+               udelay(1000);   /* 1 ms */
                status = __raw_readl(SGMII_STATUS_REG(port));
-               if ((status & mask) == mask)
-                       break;
        }
+       puts(" done\n");
 
        return 0;
 }
@@ -289,6 +315,11 @@ int mac_sl_config(u_int16_t port, struct mac_sl_cfg *cfg)
        writel(cfg->max_rx_len, DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_MAXLEN);
        writel(cfg->ctl, DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_CTL);
 
+#if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L)
+       /* Map RX packet flow priority to 0 */
+       writel(0, DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_RX_PRI_MAP);
+#endif
+
        return ret;
 }
 
@@ -367,9 +398,10 @@ static int keystone2_eth_open(struct eth_device *dev, bd_t *bis)
        sys_has_mdio =
                (eth_priv->sgmii_link_type == SGMII_LINK_MAC_PHY) ? 1 : 0;
 
-       keystone2_net_serdes_setup();
+       if (sys_has_mdio)
+               keystone2_mdio_reset(mdio_bus);
 
-       keystone_sgmii_config(eth_priv->slave_port - 1,
+       keystone_sgmii_config(phy_dev, eth_priv->slave_port - 1,
                              eth_priv->sgmii_link_type);
 
        udelay(10000);
@@ -473,7 +505,7 @@ static int keystone2_eth_rcv_packet(struct eth_device *dev)
        if (hd == NULL)
                return 0;
 
-       NetReceive((uchar *)pkt, pkt_size);
+       net_process_received_packet((uchar *)pkt, pkt_size);
 
        ksnav_release_rxhd(&netcp_pktdma, hd);
 
@@ -522,6 +554,8 @@ int keystone2_emac_initialize(struct eth_priv_t *eth_priv)
                        return res;
        }
 
+       keystone2_net_serdes_setup();
+
        /* Create phy device and bind it with driver */
 #ifdef CONFIG_KSNET_MDIO_PHY_CONFIG_ENABLE
        phy_dev = phy_connect(mdio_bus, eth_priv->phy_addr,
@@ -551,6 +585,12 @@ static void keystone2_net_serdes_setup(void)
                        &ks2_serdes_sgmii_156p25mhz,
                        CONFIG_KSNET_SERDES_LANES_PER_SGMII);
 
+#if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L)
+       ks2_serdes_init(CONFIG_KSNET_SERDES_SGMII2_BASE,
+                       &ks2_serdes_sgmii_156p25mhz,
+                       CONFIG_KSNET_SERDES_LANES_PER_SGMII);
+#endif
+
        /* wait till setup */
        udelay(5000);
 }