+obj-$(CONFIG_NET_VENDOR_AR231X) += ar231x.o
--- /dev/null
+++ b/drivers/net/ethernet/ar231x/ar231x.c
-@@ -0,0 +1,1265 @@
+@@ -0,0 +1,1254 @@
+/*
+ * ar231x.c: Linux driver for the Atheros AR231x Ethernet device.
+ *
+ * (at your option) any later version.
+ *
+ * Additional credits:
-+ * This code is taken from John Taylor's Sibyte driver and then
-+ * modified for the AR2313.
++ * This code is taken from John Taylor's Sibyte driver and then
++ * modified for the AR2313.
+ */
+
+#include <linux/module.h>
+#include <linux/ethtool.h>
+#include <linux/ctype.h>
+#include <linux/platform_device.h>
++#include <linux/io.h>
++#include <linux/uaccess.h>
+
+#include <net/sock.h>
+#include <net/ip.h>
+
-+#include <asm/io.h>
-+#include <asm/irq.h>
-+#include <asm/byteorder.h>
-+#include <asm/uaccess.h>
-+#include <asm/bootinfo.h>
-+
+#define AR2313_MTU 1692
+#define AR2313_PRIOS 1
+#define AR2313_QUEUES (2*AR2313_PRIOS)
+
+
+#ifndef min
-+#define min(a,b) (((a)<(b))?(a):(b))
++#define min(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef SMP_CACHE_BYTES
+#define VLAN_HDR 0
+#endif
+
-+#define AR2313_BUFSIZE (AR2313_MTU + VLAN_HDR + ETH_HLEN + CRC_LEN + RX_OFFSET)
++#define AR2313_BUFSIZE (AR2313_MTU + VLAN_HDR + ETH_HLEN + CRC_LEN + \
++ RX_OFFSET)
+
+#ifdef MODULE
+MODULE_LICENSE("GPL");
+static void ar231x_tx_timeout(struct net_device *dev);
+
+static int ar231x_mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum);
-+static int ar231x_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, u16 value);
++static int ar231x_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum,
++ u16 value);
+static int ar231x_mdiobus_reset(struct mii_bus *bus);
-+static int ar231x_mdiobus_probe (struct net_device *dev);
++static int ar231x_mdiobus_probe(struct net_device *dev);
+static void ar231x_adjust_link(struct net_device *dev);
+
+#ifndef ERR
+static void
+ar231x_netpoll(struct net_device *dev)
+{
-+ unsigned long flags;
++ unsigned long flags;
+
-+ local_irq_save(flags);
-+ ar231x_interrupt(dev->irq, dev);
-+ local_irq_restore(flags);
++ local_irq_save(flags);
++ ar231x_interrupt(dev->irq, dev);
++ local_irq_restore(flags);
+}
+#endif
+
+static const struct net_device_ops ar231x_ops = {
-+ .ndo_open = ar231x_open,
-+ .ndo_stop = ar231x_close,
-+ .ndo_start_xmit = ar231x_start_xmit,
-+ .ndo_set_rx_mode = ar231x_multicast_list,
-+ .ndo_do_ioctl = ar231x_ioctl,
-+ .ndo_change_mtu = eth_change_mtu,
++ .ndo_open = ar231x_open,
++ .ndo_stop = ar231x_close,
++ .ndo_start_xmit = ar231x_start_xmit,
++ .ndo_set_rx_mode = ar231x_multicast_list,
++ .ndo_do_ioctl = ar231x_ioctl,
++ .ndo_change_mtu = eth_change_mtu,
+ .ndo_validate_addr = eth_validate_addr,
-+ .ndo_set_mac_address = eth_mac_addr,
++ .ndo_set_mac_address = eth_mac_addr,
+ .ndo_tx_timeout = ar231x_tx_timeout,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+ .ndo_poll_controller = ar231x_netpoll,
+ tasklet_init(&sp->rx_tasklet, rx_tasklet_func, (unsigned long) dev);
+ tasklet_disable(&sp->rx_tasklet);
+
-+ sp->eth_regs =
-+ ioremap_nocache(virt_to_phys(ar_eth_base), sizeof(*sp->eth_regs));
++ sp->eth_regs = ioremap_nocache(virt_to_phys(ar_eth_base),
++ sizeof(*sp->eth_regs));
+ if (!sp->eth_regs) {
+ printk("Can't remap eth registers\n");
+ return -ENXIO;
+ return -1;
+ }
+
-+ printk("%s: %s: %02x:%02x:%02x:%02x:%02x:%02x, irq %d\n",
-+ dev->name, sp->name,
-+ dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
-+ dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5], dev->irq);
++ printk("%s: %s: %pM, irq %d\n", dev->name, sp->name, dev->dev_addr,
++ dev->irq);
+
+ sp->mii_bus = mdiobus_alloc();
+ if (sp->mii_bus == NULL)
+{
+ struct ar231x_private *sp = netdev_priv(dev);
+ if (sp->rx_ring != NULL) {
-+ kfree((void *) KSEG0ADDR(sp->rx_ring));
++ kfree((void *)KSEG0ADDR(sp->rx_ring));
+ sp->rx_ring = NULL;
+ sp->tx_ring = NULL;
+ }
+ ar231x_descr_t *space;
+
+ if (sp->rx_ring != NULL) {
-+ printk("%s: already done.\n", __FUNCTION__);
++ printk("%s: already done.\n", __func__);
+ return 0;
+ }
+
-+ size =
-+ (sizeof(ar231x_descr_t) * (AR2313_DESCR_ENTRIES * AR2313_QUEUES));
++ size = sizeof(ar231x_descr_t) * (AR2313_DESCR_ENTRIES * AR2313_QUEUES);
+ space = kmalloc(size, GFP_KERNEL);
+ if (space == NULL)
+ return 1;
+ dma_cache_inv((unsigned int) space, size);
+
+ /* now convert pointer to KSEG1 */
-+ space = (ar231x_descr_t *) KSEG1ADDR(space);
++ space = (ar231x_descr_t *)KSEG1ADDR(space);
+
-+ memset((void *) space, 0, size);
++ memset((void *)space, 0, size);
+
+ sp->rx_ring = space;
+ space += AR2313_DESCR_ENTRIES;
+ td->status = 0;
+ td->devcs = DMA_TX1_CHAINED;
+ td->addr = 0;
-+ td->descr =
-+ virt_to_phys(&sp->
-+ tx_ring[(j + 1) & (AR2313_DESCR_ENTRIES - 1)]);
++ td->descr = virt_to_phys(&sp->tx_ring[DSC_NEXT(j)]);
+ }
+
+ return 0;
+ ar231x_free_descriptors(dev);
+
+ if (sp->eth_regs)
-+ iounmap((void *) sp->eth_regs);
++ iounmap((void *)sp->eth_regs);
+ if (sp->dma_regs)
-+ iounmap((void *) sp->dma_regs);
++ iounmap((void *)sp->dma_regs);
+
+ if (sp->rx_skb) {
+ for (j = 0; j < AR2313_DESCR_ENTRIES; j++) {
+
+ add_timer(&sp->link_timer);
+ return 0;
-+
+}
+
+static void ar231x_link_timer_fn(unsigned long data)
+{
-+ struct net_device *dev = (struct net_device *) data;
++ struct net_device *dev = (struct net_device *)data;
+ struct ar231x_private *sp = netdev_priv(dev);
+
+ /**
+ * Loop faster when we don't have link.
+ * This was needed to speed up the AP bootstrap time.
+ */
-+ if (sp->link == 0) {
++ if (sp->link == 0)
+ mod_timer(&sp->link_timer, jiffies + HZ / 2);
-+ } else {
++ else
+ mod_timer(&sp->link_timer, jiffies + LINK_TIMER);
-+ }
+}
+
+static void ar231x_check_link(struct net_device *dev)
+ u16 reg;
+
+ sp->link = 1;
-+ reg = ar231x_mdiobus_read(sp->mii_bus, sp->phy, MII_BMCR);
++ reg = ar231x_mdiobus_read(sp->mii_bus, sp->phy,
++ MII_BMCR);
+ if (reg & BMCR_ANENABLE) {
+ /* auto neg enabled */
-+ reg = ar231x_mdiobus_read(sp->mii_bus, sp->phy, MII_LPA);
-+ duplex = (reg & (LPA_100FULL | LPA_10FULL)) ? 1 : 0;
++ reg = ar231x_mdiobus_read(sp->mii_bus, sp->phy,
++ MII_LPA);
++ duplex = reg & (LPA_100FULL | LPA_10FULL) ?
++ 1 : 0;
+ } else {
+ /* no auto neg, just read duplex config */
+ duplex = (reg & BMCR_FULLDPLX) ? 1 : 0;
+ if (duplex) {
+ /* full duplex */
+ sp->eth_regs->mac_control =
-+ ((sp->eth_regs->
-+ mac_control | MAC_CONTROL_F) & ~MAC_CONTROL_DRO);
++ (sp->eth_regs->mac_control |
++ MAC_CONTROL_F) & ~MAC_CONTROL_DRO;
+ } else {
+ /* half duplex */
+ sp->eth_regs->mac_control =
-+ ((sp->eth_regs->
-+ mac_control | MAC_CONTROL_DRO) & ~MAC_CONTROL_F);
++ (sp->eth_regs->mac_control |
++ MAC_CONTROL_DRO) & ~MAC_CONTROL_F;
+ }
+ } else {
+ /* no link */
+ ((32 << DMA_BUS_MODE_PBL_SHIFT) | DMA_BUS_MODE_BLE);
+
+ /* enable interrupts */
-+ sp->dma_regs->intr_ena = (DMA_STATUS_AIS |
-+ DMA_STATUS_NIS |
-+ DMA_STATUS_RI |
-+ DMA_STATUS_TI | DMA_STATUS_FBE);
++ sp->dma_regs->intr_ena = DMA_STATUS_AIS | DMA_STATUS_NIS |
++ DMA_STATUS_RI | DMA_STATUS_TI |
++ DMA_STATUS_FBE;
+ sp->dma_regs->xmt_base = virt_to_phys(sp->tx_ring);
+ sp->dma_regs->rcv_base = virt_to_phys(sp->rx_ring);
+ sp->dma_regs->control =
+ sp->eth_regs->mac_control = flags;
+
+ /* Set all Ethernet station address registers to their initial values */
-+ ethsah = ((((u_int) (dev->dev_addr[5]) << 8) & (u_int) 0x0000FF00) |
-+ (((u_int) (dev->dev_addr[4]) << 0) & (u_int) 0x000000FF));
++ ethsah = (((u_int) (dev->dev_addr[5]) << 8) & (u_int) 0x0000FF00) |
++ (((u_int) (dev->dev_addr[4]) << 0) & (u_int) 0x000000FF);
+
-+ ethsal = ((((u_int) (dev->dev_addr[3]) << 24) & (u_int) 0xFF000000) |
-+ (((u_int) (dev->dev_addr[2]) << 16) & (u_int) 0x00FF0000) |
-+ (((u_int) (dev->dev_addr[1]) << 8) & (u_int) 0x0000FF00) |
-+ (((u_int) (dev->dev_addr[0]) << 0) & (u_int) 0x000000FF));
++ ethsal = (((u_int) (dev->dev_addr[3]) << 24) & (u_int) 0xFF000000) |
++ (((u_int) (dev->dev_addr[2]) << 16) & (u_int) 0x00FF0000) |
++ (((u_int) (dev->dev_addr[1]) << 8) & (u_int) 0x0000FF00) |
++ (((u_int) (dev->dev_addr[0]) << 0) & (u_int) 0x000000FF);
+
+ sp->eth_regs->mac_addr[0] = ethsah;
+ sp->eth_regs->mac_addr[1] = ethsal;
+ /* Allocate descriptors */
+ if (ar231x_allocate_descriptors(dev)) {
+ printk("%s: %s: ar231x_allocate_descriptors failed\n",
-+ dev->name, __FUNCTION__);
++ dev->name, __func__);
+ ecode = -EAGAIN;
+ goto init_error;
+ }
+ GFP_KERNEL);
+ if (!(sp->rx_skb)) {
+ printk("%s: %s: rx_skb kmalloc failed\n",
-+ dev->name, __FUNCTION__);
++ dev->name, __func__);
+ ecode = -EAGAIN;
+ goto init_error;
+ }
+ GFP_KERNEL);
+ if (!(sp->tx_skb)) {
+ printk("%s: %s: tx_skb kmalloc failed\n",
-+ dev->name, __FUNCTION__);
++ dev->name, __func__);
+ ecode = -EAGAIN;
+ goto init_error;
+ }
+ dev->name, dev);
+ if (ecode) {
+ printk(KERN_WARNING "%s: %s: Requested IRQ %d is busy\n",
-+ dev->name, __FUNCTION__, dev->irq);
++ dev->name, __func__, dev->irq);
+ goto init_error;
+ }
+
+
+ return 0;
+
-+ init_error:
++init_error:
+ ar231x_init_cleanup(dev);
+ return ecode;
+}
+ */
+static void ar231x_load_rx_ring(struct net_device *dev, int nr_bufs)
+{
-+
+ struct ar231x_private *sp = netdev_priv(dev);
+ short i, idx;
+
+ skb = netdev_alloc_skb_ip_align(dev, AR2313_BUFSIZE);
+ if (!skb) {
+ printk("\n\n\n\n %s: No memory in system\n\n\n\n",
-+ __FUNCTION__);
++ __func__);
+ break;
+ }
+
+ skb->dev = dev;
+ sp->rx_skb[idx] = skb;
+
-+ rd = (ar231x_descr_t *) & sp->rx_ring[idx];
++ rd = (ar231x_descr_t *)&sp->rx_ring[idx];
+
+ /* initialize dma descriptor */
+ rd->devcs = ((AR2313_BUFSIZE << DMA_RX1_BSIZE_SHIFT) |
+ DMA_RX1_CHAINED);
+ rd->addr = virt_to_phys(skb->data);
-+ rd->descr =
-+ virt_to_phys(&sp->
-+ rx_ring[(idx + 1) & (AR2313_DESCR_ENTRIES - 1)]);
++ rd->descr = virt_to_phys(&sp->rx_ring[DSC_NEXT(idx)]);
+ rd->status = DMA_RX_OWN;
+
+ idx = DSC_NEXT(idx);
+
+ /* process at most the entire ring and then wait for another int */
+ while (1) {
-+
+ rxdesc = &sp->rx_ring[idx];
+ status = rxdesc->status;
++
+ if (status & DMA_RX_OWN) {
+ /* SiByte owns descriptor or descr not yet filled in */
+ rval = 0;
+
+ } else {
+ /* alloc new buffer. */
-+ skb_new = netdev_alloc_skb_ip_align(dev, AR2313_BUFSIZE);
++ skb_new = netdev_alloc_skb_ip_align(dev,
++ AR2313_BUFSIZE);
+ if (skb_new != NULL) {
-+
+ skb = sp->rx_skb[idx];
+ /* set skb */
-+ skb_put(skb,
-+ ((status >> DMA_RX_LEN_SHIFT) & 0x3fff) - CRC_LEN);
++ skb_put(skb, ((status >> DMA_RX_LEN_SHIFT) &
++ 0x3fff) - CRC_LEN);
+
+ dev->stats.rx_bytes += skb->len;
+ skb->protocol = eth_type_trans(skb, dev);
+
+ while (idx != sp->tx_prd) {
+ txdesc = &sp->tx_ring[idx];
++ status = txdesc->status;
+
-+ if ((status = txdesc->status) & DMA_TX_OWN) {
++ if (status & DMA_TX_OWN) {
+ /* ar231x dma still owns descr */
+ break;
+ }
+ /* done with this descriptor */
+ dma_unmap_single(NULL, txdesc->addr,
-+ txdesc->devcs & DMA_TX1_BSIZE_MASK,
-+ DMA_TO_DEVICE);
++ txdesc->devcs & DMA_TX1_BSIZE_MASK,
++ DMA_TO_DEVICE);
+ txdesc->status = 0;
+
+ if (status & DMA_TX_ERROR) {
+ dev->stats.tx_heartbeat_errors++;
+ if (status & (DMA_TX_ERR_LOSS | DMA_TX_ERR_LINK))
+ dev->stats.tx_carrier_errors++;
-+ if (status & (DMA_TX_ERR_LATE |
-+ DMA_TX_ERR_COL |
-+ DMA_TX_ERR_JABBER | DMA_TX_ERR_DEFER))
++ if (status & (DMA_TX_ERR_LATE | DMA_TX_ERR_COL |
++ DMA_TX_ERR_JABBER | DMA_TX_ERR_DEFER))
+ dev->stats.tx_aborted_errors++;
+ } else {
+ /* transmit OK */
+
+static void rx_tasklet_func(unsigned long data)
+{
-+ struct net_device *dev = (struct net_device *) data;
++ struct net_device *dev = (struct net_device *)data;
+ struct ar231x_private *sp = netdev_priv(dev);
+
-+ if (sp->unloading) {
++ if (sp->unloading)
+ return;
-+ }
+
+ if (ar231x_rx_int(dev)) {
+ tasklet_hi_schedule(&sp->rx_tasklet);
+
+static irqreturn_t ar231x_interrupt(int irq, void *dev_id)
+{
-+ struct net_device *dev = (struct net_device *) dev_id;
++ struct net_device *dev = (struct net_device *)dev_id;
+ struct ar231x_private *sp = netdev_priv(dev);
+ unsigned int status, enabled;
+
+ }
+
+ /* abnormal status */
-+ if (status & (DMA_STATUS_FBE | DMA_STATUS_TPS)) {
++ if (status & (DMA_STATUS_FBE | DMA_STATUS_TPS))
+ ar231x_restart(dev);
-+ }
++
+ return IRQ_HANDLED;
+}
+
+ unsigned int ethsal, ethsah;
+
+ /* reset the hardware, in case the MAC address changed */
-+ ethsah = ((((u_int) (dev->dev_addr[5]) << 8) & (u_int) 0x0000FF00) |
-+ (((u_int) (dev->dev_addr[4]) << 0) & (u_int) 0x000000FF));
++ ethsah = (((u_int) (dev->dev_addr[5]) << 8) & (u_int) 0x0000FF00) |
++ (((u_int) (dev->dev_addr[4]) << 0) & (u_int) 0x000000FF);
+
-+ ethsal = ((((u_int) (dev->dev_addr[3]) << 24) & (u_int) 0xFF000000) |
-+ (((u_int) (dev->dev_addr[2]) << 16) & (u_int) 0x00FF0000) |
-+ (((u_int) (dev->dev_addr[1]) << 8) & (u_int) 0x0000FF00) |
-+ (((u_int) (dev->dev_addr[0]) << 0) & (u_int) 0x000000FF));
++ ethsal = (((u_int) (dev->dev_addr[3]) << 24) & (u_int) 0xFF000000) |
++ (((u_int) (dev->dev_addr[2]) << 16) & (u_int) 0x00FF0000) |
++ (((u_int) (dev->dev_addr[1]) << 8) & (u_int) 0x0000FF00) |
++ (((u_int) (dev->dev_addr[0]) << 0) & (u_int) 0x000000FF);
+
+ sp->eth_regs->mac_addr[0] = ethsah;
+ sp->eth_regs->mac_addr[1] = ethsal;
+
+ /* kill the MAC */
+ sp->eth_regs->mac_control &= ~(MAC_CONTROL_RE | /* disable Receives */
-+ MAC_CONTROL_TE); /* disable Transmits */
++ MAC_CONTROL_TE); /* disable Transmits */
+ /* stop dma */
+ sp->dma_regs->control = 0;
+ sp->dma_regs->bus_mode = DMA_BUS_MODE_SWR;
+ int ret;
+
+ switch (cmd) {
-+
+ case SIOCETHTOOL:
+ spin_lock_irq(&sp->lock);
-+ ret = phy_ethtool_ioctl(sp->phy_dev, (void *) ifr->ifr_data);
++ ret = phy_ethtool_ioctl(sp->phy_dev, (void *)ifr->ifr_data);
+ spin_unlock_irq(&sp->lock);
+ return ret;
+
+ volatile ETHERNET_STRUCT *ethernet = sp->phy_regs;
+
+ ethernet->mii_addr = MII_ADDR(phy_addr, regnum);
-+ while (ethernet->mii_addr & MII_ADDR_BUSY);
++ while (ethernet->mii_addr & MII_ADDR_BUSY)
++ ;
+ return ethernet->mii_data >> MII_DATA_SHIFT;
+}
+
+static int
-+ar231x_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum,
-+ u16 value)
++ar231x_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, u16 value)
+{
+ struct net_device *const dev = bus->priv;
+ struct ar231x_private *sp = netdev_priv(dev);
+ volatile ETHERNET_STRUCT *ethernet = sp->phy_regs;
+
-+ while (ethernet->mii_addr & MII_ADDR_BUSY);
++ while (ethernet->mii_addr & MII_ADDR_BUSY)
++ ;
+ ethernet->mii_data = value << MII_DATA_SHIFT;
+ ethernet->mii_addr = MII_ADDR(phy_addr, regnum) | MII_ADDR_WRITE;
+
+ return 0;
+}
+
-+static int ar231x_mdiobus_probe (struct net_device *dev)
++static int ar231x_mdiobus_probe(struct net_device *dev)
+{
+ struct ar231x_private *const sp = netdev_priv(dev);
+ struct phy_device *phydev = NULL;
+ }
+
+ if (!phydev) {
-+ printk (KERN_ERR "ar231x: %s: no PHY found\n", dev->name);
++ printk(KERN_ERR "ar231x: %s: no PHY found\n", dev->name);
+ return -1;
+ }
+
+ BUG_ON(!phydev);
+ BUG_ON(phydev->attached_dev);
+
-+ phydev = phy_connect(dev, dev_name(&phydev->dev), &ar231x_adjust_link, 0,
-+ PHY_INTERFACE_MODE_MII);
++ phydev = phy_connect(dev, dev_name(&phydev->dev), &ar231x_adjust_link,
++ PHY_INTERFACE_MODE_MII);
+
+ if (IS_ERR(phydev)) {
+ printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
+
--- /dev/null
+++ b/drivers/net/ethernet/ar231x/ar231x.h
-@@ -0,0 +1,289 @@
+@@ -0,0 +1,288 @@
+/*
+ * ar231x.h: Linux driver for the Atheros AR231x Ethernet device.
+ *
+#include <linux/interrupt.h>
+#include <generated/autoconf.h>
+#include <linux/bitops.h>
-+#include <asm/bootinfo.h>
+#include <ar231x_platform.h>
+
+/* probe link timer - 5 secs */
+#define MAC_CONTROL_HO BIT(15) /* Hash only filtering */
+#define MAC_CONTROL_PB BIT(16) /* Pass Bad frames */
+#define MAC_CONTROL_IF BIT(17) /* Inverse filtering */
-+#define MAC_CONTROL_PR BIT(18) /* promiscuous mode (valid frames only) */
++#define MAC_CONTROL_PR BIT(18) /* promis mode (valid frames only) */
+#define MAC_CONTROL_PM BIT(19) /* pass multicast */
+#define MAC_CONTROL_F BIT(20) /* full-duplex */
+#define MAC_CONTROL_DRO BIT(23) /* Disable Receive Own */
+#define MAC_CONTROL_HBD BIT(28) /* heart-beat disabled (MUST BE SET) */
+#define MAC_CONTROL_BLE BIT(30) /* big endian mode */
-+#define MAC_CONTROL_RA BIT(31) /* receive all (valid and invalid frames) */
++#define MAC_CONTROL_RA BIT(31) /* rcv all (valid and invalid frames) */
+
+#define MII_ADDR_BUSY BIT(0)
+#define MII_ADDR_WRITE BIT(1)
+
+
+ struct timer_list link_timer;
-+ unsigned short phy; /* merlot phy = 1, samsung phy = 0x1f */
++ unsigned short phy; /* merlot phy = 1, samsung phy = 0x1f */
+ unsigned short mac;
+ unsigned short link; /* 0 - link down, 1 - link up */
+ u16 phy_data;