ltq-atm/ltq-ptm: re-enable/fix reset_ppe() functionality for VR9
[openwrt/openwrt.git] / package / kernel / lantiq / ltq-ptm / src / ifxmips_ptm_adsl.c
index b096b0a702132f11ce5059b0afe483c82192a179..186c848693f975edbf68e2762eb2e3df08b62618 100644 (file)
@@ -44,6 +44,8 @@
 #include <linux/etherdevice.h>
 #include <linux/interrupt.h>
 #include <linux/netdevice.h>
+#include <linux/platform_device.h>
+#include <linux/of_device.h>
 #include <asm/io.h>
 
 /*
@@ -128,7 +130,9 @@ static int ptm_stop(struct net_device *);
   static unsigned int ptm_poll(int, unsigned int);
   static int ptm_napi_poll(struct napi_struct *, int);
 static int ptm_hard_start_xmit(struct sk_buff *, struct net_device *);
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0))
 static int ptm_change_mtu(struct net_device *, int);
+#endif
 static int ptm_ioctl(struct net_device *, struct ifreq *, int);
 static void ptm_tx_timeout(struct net_device *);
 
@@ -247,14 +251,16 @@ static struct net_device_ops g_ptm_netdev_ops = {
     .ndo_start_xmit      = ptm_hard_start_xmit,
     .ndo_validate_addr   = eth_validate_addr,
     .ndo_set_mac_address = eth_mac_addr,
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0))
     .ndo_change_mtu      = ptm_change_mtu,
+#endif
     .ndo_do_ioctl        = ptm_ioctl,
     .ndo_tx_timeout      = ptm_tx_timeout,
 };
 #endif
 
 static struct net_device *g_net_dev[2] = {0};
-static char *g_net_dev_name[2] = {"ptm0", "ptmfast0"};
+static char *g_net_dev_name[2] = {"dsl0", "dslfast0"};
 
 #ifdef CONFIG_IFX_PTM_RX_TASKLET
   static struct tasklet_struct g_ptm_tasklet[] = {
@@ -285,6 +291,10 @@ static void ptm_setup(struct net_device *dev, int ndev)
 
     /*  hook network operations */
     dev->netdev_ops      = &g_ptm_netdev_ops;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
+    /* Allow up to 1508 bytes, for RFC4638 */
+    dev->max_mtu         = ETH_DATA_LEN + 8;
+#endif
     netif_napi_add(dev, &g_ptm_priv_data.itf[ndev].napi, ptm_napi_poll, 25);
     dev->watchdog_timeo  = ETH_WATCHDOG_TIMEOUT;
 
@@ -405,7 +415,11 @@ static int ptm_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
     /*  allocate descriptor */
     desc_base = get_tx_desc(ndev, &f_full);
     if ( f_full ) {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0)
+        netif_trans_update(dev);
+#else
         dev->trans_start = jiffies;
+#endif
         netif_stop_queue(dev);
 
         IFX_REG_W32_MASK(0, 1 << (ndev + 16), MBOX_IGU1_ISRC);
@@ -439,7 +453,11 @@ static int ptm_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
     g_ptm_priv_data.itf[ndev].stats.tx_packets++;
     g_ptm_priv_data.itf[ndev].stats.tx_bytes += reg_desc.datalen;
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0)
+    netif_trans_update(dev);
+#else
     dev->trans_start = jiffies;
+#endif
     mailbox_signal(ndev, 1);
 
     adsl_led_flash();
@@ -451,7 +469,7 @@ PTM_HARD_START_XMIT_FAIL:
     g_ptm_priv_data.itf[ndev].stats.tx_dropped++;
     return NETDEV_TX_OK;
 }
-
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0))
 static int ptm_change_mtu(struct net_device *dev, int mtu)
 {
        /* Allow up to 1508 bytes, for RFC4638 */
@@ -460,6 +478,7 @@ static int ptm_change_mtu(struct net_device *dev, int mtu)
         dev->mtu = mtu;
         return 0;
 }
+#endif
 
 static int ptm_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 {
@@ -646,7 +665,9 @@ static INLINE int mailbox_rx_irq_handler(unsigned int ch)   //  return: < 0 - de
             skb->dev = g_net_dev[ndev];
             skb->protocol = eth_type_trans(skb, skb->dev);
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0))
             g_net_dev[ndev]->last_rx = jiffies;
+#endif
 
             netif_rx_ret = netif_receive_skb(skb);
 
@@ -919,8 +940,8 @@ static int proc_read_wanmib(char *page, char **start, off_t off, int count, int
     int len = 0;
     int i;
     char *title[] = {
-        "ptm0\n",
-        "ptmfast0\n"
+        "dsl0\n",
+        "dslfast0\n"
     };
 
     for ( i = 0; i < ARRAY_SIZE(title); i++ ) {
@@ -1429,6 +1450,19 @@ static int ptm_showtime_exit(void)
 }
 
 
+static const struct of_device_id ltq_ptm_match[] = {
+#ifdef CONFIG_DANUBE
+       { .compatible = "lantiq,ppe-danube", .data = NULL },
+#elif defined CONFIG_AMAZON_SE
+       { .compatible = "lantiq,ppe-ase", .data = NULL },
+#elif defined CONFIG_AR9
+       { .compatible = "lantiq,ppe-arx100", .data = NULL },
+#elif defined CONFIG_VR9
+       { .compatible = "lantiq,ppe-xrx200", .data = NULL },
+#endif
+       {},
+};
+MODULE_DEVICE_TABLE(of, ltq_ptm_match);
 
 /*
  * ####################################
@@ -1446,7 +1480,7 @@ static int ptm_showtime_exit(void)
  *    0    --- successful
  *    else --- failure, usually it is negative value of error code
  */
-static int ifx_ptm_init(void)
+static int ltq_ptm_probe(struct platform_device *pdev)
 {
     int ret;
     struct port_cell_info port_cell = {0};
@@ -1462,7 +1496,7 @@ static int ifx_ptm_init(void)
         goto INIT_PRIV_DATA_FAIL;
     }
 
-    ifx_ptm_init_chip();
+    ifx_ptm_init_chip(pdev);
     init_tables();
 
     for ( i = 0; i < ARRAY_SIZE(g_net_dev); i++ ) {
@@ -1510,6 +1544,9 @@ static int ifx_ptm_init(void)
 
     port_cell.port_num = 1;
     ifx_mei_atm_showtime_check(&g_showtime, &port_cell, &xdata_addr);
+    if ( g_showtime ) {
+       ptm_showtime_enter(&port_cell, &xdata_addr);
+    }
 
     ifx_mei_atm_showtime_enter = ptm_showtime_enter;
     ifx_mei_atm_showtime_exit  = ptm_showtime_exit;
@@ -1548,7 +1585,7 @@ INIT_PRIV_DATA_FAIL:
  *  Output:
  *   none
  */
-static void __exit ifx_ptm_exit(void)
+static int ltq_ptm_remove(struct platform_device *pdev)
 {
     int i;
 
@@ -1573,7 +1610,20 @@ static void __exit ifx_ptm_exit(void)
     ifx_ptm_uninit_chip();
 
     clear_priv_data();
+
+    return 0;
 }
 
-module_init(ifx_ptm_init);
-module_exit(ifx_ptm_exit);
+static struct platform_driver ltq_ptm_driver = {
+       .probe = ltq_ptm_probe,
+       .remove = ltq_ptm_remove,
+       .driver = {
+               .name = "ptm",
+               .owner = THIS_MODULE,
+               .of_match_table = ltq_ptm_match,
+       },
+};
+
+module_platform_driver(ltq_ptm_driver);
+
+MODULE_LICENSE("GPL");