ar71xx: merge latest ag71xx changes from trunk, fix wrong argument to phy_mii_ioctl()
authornbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Tue, 24 May 2011 09:17:31 +0000 (09:17 +0000)
committernbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Tue, 24 May 2011 09:17:31 +0000 (09:17 +0000)
git-svn-id: svn://svn.openwrt.org/openwrt/branches/backfire@26985 3c298f89-4303-0410-b956-a3cf2f4a3e73

target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx.h
target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_ar7240.c
target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_debugfs.c
target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_main.c
target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_phy.c

index bb4cb5ba9ff96b3db1e7c6f5149bef2b207ce6c1..30caaff027d94dedc72f03b96ea17b5e9a714843 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/platform_device.h>
 #include <linux/ethtool.h>
 #include <linux/etherdevice.h>
+#include <linux/if_vlan.h>
 #include <linux/phy.h>
 #include <linux/skbuff.h>
 #include <linux/dma-mapping.h>
@@ -35,8 +36,6 @@
 #include <asm/mach-ar71xx/ar71xx.h>
 #include <asm/mach-ar71xx/platform.h>
 
-#define ETH_FCS_LEN    4
-
 #define AG71XX_DRV_NAME                "ag71xx"
 #define AG71XX_DRV_VERSION     "0.5.35"
 
@@ -54,7 +53,7 @@
 #define AG71XX_TX_MTU_LEN      1540
 #define AG71XX_RX_PKT_RESERVE  64
 #define AG71XX_RX_PKT_SIZE     \
-       (AG71XX_RX_PKT_RESERVE + ETH_HLEN + ETH_FRAME_LEN + ETH_FCS_LEN)
+       (AG71XX_RX_PKT_RESERVE + ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
 
 #define AG71XX_TX_RING_SIZE    64
 #define AG71XX_TX_THRES_STOP   (AG71XX_TX_RING_SIZE - 4)
@@ -91,7 +90,7 @@ struct ag71xx_buf {
        struct sk_buff          *skb;
        struct ag71xx_desc      *desc;
        dma_addr_t              dma_addr;
-       u32                     pad;
+       unsigned long           timestamp;
 };
 
 struct ag71xx_ring {
@@ -136,8 +135,6 @@ struct ag71xx_napi_stats {
 
 struct ag71xx_debug {
        struct dentry           *debugfs_dir;
-       struct dentry           *debugfs_int_stats;
-       struct dentry           *debugfs_napi_stats;
 
        struct ag71xx_int_stats int_stats;
        struct ag71xx_napi_stats napi_stats;
@@ -165,6 +162,7 @@ struct ag71xx {
        int                     duplex;
 
        struct work_struct      restart_work;
+       struct delayed_work     link_work;
        struct timer_list       oom_timer;
 
 #ifdef CONFIG_AG71XX_DEBUG_FS
index 3ce2f0a5db4905573ada383d7547abdd4b650b18..d84cc81aec04f24a9719bdf72020d45cdf5de0c0 100644 (file)
@@ -233,37 +233,39 @@ static inline u16 mk_high_addr(u32 reg)
 
 static u32 __ar7240sw_reg_read(struct mii_bus *mii, u32 reg)
 {
+       unsigned long flags;
        u16 phy_addr;
        u16 phy_reg;
        u32 hi, lo;
 
        reg = (reg & 0xfffffffc) >> 2;
-
-       ag71xx_mdio_mii_write(mii->priv, 0x1f, 0x10, mk_high_addr(reg));
-
        phy_addr = mk_phy_addr(reg);
        phy_reg = mk_phy_reg(reg);
 
+       local_irq_save(flags);
+       ag71xx_mdio_mii_write(mii->priv, 0x1f, 0x10, mk_high_addr(reg));
        lo = (u32) ag71xx_mdio_mii_read(mii->priv, phy_addr, phy_reg);
        hi = (u32) ag71xx_mdio_mii_read(mii->priv, phy_addr, phy_reg + 1);
+       local_irq_restore(flags);
 
        return (hi << 16) | lo;
 }
 
 static void __ar7240sw_reg_write(struct mii_bus *mii, u32 reg, u32 val)
 {
+       unsigned long flags;
        u16 phy_addr;
        u16 phy_reg;
 
        reg = (reg & 0xfffffffc) >> 2;
-
-       ag71xx_mdio_mii_write(mii->priv, 0x1f, 0x10, mk_high_addr(reg));
-
        phy_addr = mk_phy_addr(reg);
        phy_reg = mk_phy_reg(reg);
 
+       local_irq_save(flags);
+       ag71xx_mdio_mii_write(mii->priv, 0x1f, 0x10, mk_high_addr(reg));
        ag71xx_mdio_mii_write(mii->priv, phy_addr, phy_reg + 1, (val >> 16));
        ag71xx_mdio_mii_write(mii->priv, phy_addr, phy_reg, (val & 0xffff));
+       local_irq_restore(flags);
 }
 
 static u32 ar7240sw_reg_read(struct mii_bus *mii, u32 reg_addr)
@@ -826,6 +828,30 @@ static struct ar7240sw *ar7240_probe(struct ag71xx *ag)
        return as;
 }
 
+static void link_function(struct work_struct *work) {
+       struct ag71xx *ag = container_of(work, struct ag71xx, link_work.work);
+       unsigned long flags;
+       int i;
+       int status = 0;
+
+       for (i = 0; i < 4; i++) {
+               int link = ar7240sw_phy_read(ag->mii_bus, i, MII_BMSR);
+               if(link & BMSR_LSTATUS) {
+                       status = 1;
+                       break;
+               }
+       }
+
+       spin_lock_irqsave(&ag->lock, flags);
+       if(status != ag->link) {
+               ag->link = status;
+               ag71xx_link_adjust(ag);
+       }
+       spin_unlock_irqrestore(&ag->lock, flags);
+
+       schedule_delayed_work(&ag->link_work, HZ / 2);
+}
+
 void ag71xx_ar7240_start(struct ag71xx *ag)
 {
        struct ar7240sw *as = ag->phy_priv;
@@ -834,15 +860,17 @@ void ag71xx_ar7240_start(struct ag71xx *ag)
        ar7240sw_setup(as);
 
        ag->speed = SPEED_1000;
-       ag->link = 1;
        ag->duplex = 1;
 
        ar7240_set_addr(as, ag->dev->dev_addr);
        ar7240_hw_apply(&as->swdev);
+
+       schedule_delayed_work(&ag->link_work, HZ / 10);
 }
 
 void ag71xx_ar7240_stop(struct ag71xx *ag)
 {
+       cancel_delayed_work_sync(&ag->link_work);
 }
 
 int __devinit ag71xx_ar7240_init(struct ag71xx *ag)
@@ -856,10 +884,12 @@ int __devinit ag71xx_ar7240_init(struct ag71xx *ag)
        ag->phy_priv = as;
        ar7240sw_reset(as);
 
+       INIT_DELAYED_WORK(&ag->link_work, link_function);
+
        return 0;
 }
 
-void __devexit ag71xx_ar7240_cleanup(struct ag71xx *ag)
+void ag71xx_ar7240_cleanup(struct ag71xx *ag)
 {
        struct ar7240sw *as = ag->phy_priv;
 
index 8111cad3557dd2d4a5e06ed9b4e528db2bfd024d..90a50dad07296c7981a4eea3b89381aebc38dadc 100644 (file)
@@ -99,38 +99,48 @@ static ssize_t read_file_napi_stats(struct file *file, char __user *user_buf,
 {
        struct ag71xx *ag = file->private_data;
        struct ag71xx_napi_stats *stats = &ag->debug.napi_stats;
-       char buf[2048];
+       char *buf;
+       unsigned int buflen;
        unsigned int len = 0;
        unsigned long rx_avg = 0;
        unsigned long tx_avg = 0;
+       int ret;
        int i;
 
+       buflen = 2048;
+       buf = kmalloc(buflen, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
        if (stats->rx_count)
                rx_avg = stats->rx_packets / stats->rx_count;
 
        if (stats->tx_count)
                tx_avg = stats->tx_packets / stats->tx_count;
 
-       len += snprintf(buf + len, sizeof(buf) - len, "%3s  %10s %10s\n",
+       len += snprintf(buf + len, buflen - len, "%3s  %10s %10s\n",
                        "len", "rx", "tx");
 
        for (i = 1; i <= AG71XX_NAPI_WEIGHT; i++)
-               len += snprintf(buf + len, sizeof(buf) - len,
+               len += snprintf(buf + len, buflen - len,
                                "%3d: %10lu %10lu\n",
                                i, stats->rx[i], stats->tx[i]);
 
-       len += snprintf(buf + len, sizeof(buf) - len, "\n");
+       len += snprintf(buf + len, buflen - len, "\n");
 
-       len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
+       len += snprintf(buf + len, buflen - len, "%3s: %10lu %10lu\n",
                        "sum", stats->rx_count, stats->tx_count);
-       len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
+       len += snprintf(buf + len, buflen - len, "%3s: %10lu %10lu\n",
                        "avg", rx_avg, tx_avg);
-       len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
+       len += snprintf(buf + len, buflen - len, "%3s: %10lu %10lu\n",
                        "max", stats->rx_packets_max, stats->tx_packets_max);
-       len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
+       len += snprintf(buf + len, buflen - len, "%3s: %10lu %10lu\n",
                        "pkt", stats->rx_packets, stats->tx_packets);
 
-       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+       ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
+       kfree(buf);
+
+       return ret;
 }
 
 static const struct file_operations ag71xx_fops_napi_stats = {
@@ -139,11 +149,98 @@ static const struct file_operations ag71xx_fops_napi_stats = {
        .owner  = THIS_MODULE
 };
 
+#define DESC_PRINT_LEN 64
+
+static ssize_t read_file_ring(struct file *file, char __user *user_buf,
+                             size_t count, loff_t *ppos,
+                             struct ag71xx *ag,
+                             struct ag71xx_ring *ring,
+                             unsigned ring_size,
+                             unsigned desc_reg)
+{
+       char *buf;
+       unsigned int buflen;
+       unsigned int len = 0;
+       unsigned long flags;
+       ssize_t ret;
+       int curr;
+       int dirty;
+       u32 desc_hw;
+       int i;
+
+       buflen = (ring_size * DESC_PRINT_LEN);
+       buf = kmalloc(buflen, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       len += snprintf(buf + len, buflen - len,
+                       "Idx ... %-8s %-8s %-8s %-8s . %-10s\n",
+                       "desc", "next", "data", "ctrl", "timestamp");
+
+       spin_lock_irqsave(&ag->lock, flags);
+
+       curr = (ring->curr % ring_size);
+       dirty = (ring->dirty % ring_size);
+       desc_hw = ag71xx_rr(ag, desc_reg);
+       for (i = 0; i < ring_size; i++) {
+               struct ag71xx_buf *ab = &ring->buf[i];
+               u32 desc_dma = ((u32) ring->descs_dma) + i * ring->desc_size;
+
+               len += snprintf(buf + len, buflen - len,
+                       "%3d %c%c%c %08x %08x %08x %08x %c %10lu\n",
+                       i,
+                       (i == curr) ? 'C' : ' ',
+                       (i == dirty) ? 'D' : ' ',
+                       (desc_hw == desc_dma) ? 'H' : ' ',
+                       desc_dma,
+                       ab->desc->next,
+                       ab->desc->data,
+                       ab->desc->ctrl,
+                       (ab->desc->ctrl & DESC_EMPTY) ? 'E' : '*',
+                       ab->timestamp);
+       }
+
+       spin_unlock_irqrestore(&ag->lock, flags);
+
+       ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
+       kfree(buf);
+
+       return ret;
+}
+
+static ssize_t read_file_tx_ring(struct file *file, char __user *user_buf,
+                                size_t count, loff_t *ppos)
+{
+       struct ag71xx *ag = file->private_data;
+
+       return read_file_ring(file, user_buf, count, ppos, ag, &ag->tx_ring,
+                             AG71XX_TX_RING_SIZE, AG71XX_REG_TX_DESC);
+}
+
+static const struct file_operations ag71xx_fops_tx_ring = {
+       .open   = ag71xx_debugfs_generic_open,
+       .read   = read_file_tx_ring,
+       .owner  = THIS_MODULE
+};
+
+static ssize_t read_file_rx_ring(struct file *file, char __user *user_buf,
+                                size_t count, loff_t *ppos)
+{
+       struct ag71xx *ag = file->private_data;
+
+       return read_file_ring(file, user_buf, count, ppos, ag, &ag->rx_ring,
+                             AG71XX_RX_RING_SIZE, AG71XX_REG_RX_DESC);
+}
+
+static const struct file_operations ag71xx_fops_rx_ring = {
+       .open   = ag71xx_debugfs_generic_open,
+       .read   = read_file_rx_ring,
+       .owner  = THIS_MODULE
+};
+
 void ag71xx_debugfs_exit(struct ag71xx *ag)
 {
-       debugfs_remove(ag->debug.debugfs_napi_stats);
-       debugfs_remove(ag->debug.debugfs_int_stats);
-       debugfs_remove(ag->debug.debugfs_dir);
+       debugfs_remove_recursive(ag->debug.debugfs_dir);
 }
 
 int ag71xx_debugfs_init(struct ag71xx *ag)
@@ -151,31 +248,18 @@ int ag71xx_debugfs_init(struct ag71xx *ag)
        ag->debug.debugfs_dir = debugfs_create_dir(ag->dev->name,
                                                   ag71xx_debugfs_root);
        if (!ag->debug.debugfs_dir)
-               goto err;
-
-       ag->debug.debugfs_int_stats =
-                       debugfs_create_file("int_stats",
-                                           S_IRUGO,
-                                           ag->debug.debugfs_dir,
-                                           ag,
-                                           &ag71xx_fops_int_stats);
-       if (!ag->debug.debugfs_int_stats)
-               goto err;
-
-       ag->debug.debugfs_napi_stats =
-                       debugfs_create_file("napi_stats",
-                                           S_IRUGO,
-                                           ag->debug.debugfs_dir,
-                                           ag,
-                                           &ag71xx_fops_napi_stats);
-       if (!ag->debug.debugfs_napi_stats)
-               goto err;
+               return -ENOMEM;
 
-       return 0;
+       debugfs_create_file("int_stats", S_IRUGO, ag->debug.debugfs_dir,
+                           ag, &ag71xx_fops_int_stats);
+       debugfs_create_file("napi_stats", S_IRUGO, ag->debug.debugfs_dir,
+                           ag, &ag71xx_fops_napi_stats);
+       debugfs_create_file("tx_ring", S_IRUGO, ag->debug.debugfs_dir,
+                           ag, &ag71xx_fops_tx_ring);
+       debugfs_create_file("rx_ring", S_IRUGO, ag->debug.debugfs_dir,
+                           ag, &ag71xx_fops_rx_ring);
 
-err:
-       ag71xx_debugfs_exit(ag);
-       return -ENOMEM;
+       return 0;
 }
 
 int ag71xx_debugfs_root_init(void)
index eae443e8ceea8ff84ea35f7201870e04a8a28908..0eb5ce15bd49319366ac9281717ce3310539d022 100644 (file)
@@ -652,6 +652,7 @@ static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb,
                                  DMA_TO_DEVICE);
 
        ring->buf[i].skb = skb;
+       ring->buf[i].timestamp = jiffies;
 
        /* setup descriptor fields */
        desc->data = (u32) dma_addr;
@@ -713,7 +714,7 @@ static int ag71xx_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
                if (ag->phy_dev == NULL)
                        break;
 
-               return phy_mii_ioctl(ag->phy_dev, ifr, cmd);
+               return phy_mii_ioctl(ag->phy_dev, if_mii(ifr), cmd);
 
        default:
                break;
index d70aaf0921fdcb714808a2c08ecdae6e50d91770..75500277f4cda0bcd65935960c3e7542b65b08ae 100644 (file)
@@ -48,9 +48,9 @@ void ag71xx_phy_start(struct ag71xx *ag)
 
        if (ag->phy_dev) {
                phy_start(ag->phy_dev);
+       } else if (pdata->has_ar7240_switch) {
+               ag71xx_ar7240_start(ag);
        } else {
-               if (pdata->has_ar7240_switch)
-                       ag71xx_ar7240_start(ag);
                ag->link = 1;
                ag71xx_link_adjust(ag);
        }
@@ -217,7 +217,7 @@ int __devinit ag71xx_phy_connect(struct ag71xx *ag)
        return ag71xx_phy_connect_fixed(ag);
 }
 
-void __devexit ag71xx_phy_disconnect(struct ag71xx *ag)
+void ag71xx_phy_disconnect(struct ag71xx *ag)
 {
        struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);