]> nv-tegra.nvidia Code Review - linux-2.6.git/commitdiff
Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
authorLinus Torvalds <torvalds@g5.osdl.org>
Thu, 5 Jan 2006 00:31:56 +0000 (16:31 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Thu, 5 Jan 2006 00:31:56 +0000 (16:31 -0800)
67 files changed:
Documentation/networking/gianfar.txt [new file with mode: 0644]
drivers/net/8139too.c
drivers/net/Kconfig
drivers/net/Makefile
drivers/net/bonding/Makefile
drivers/net/bonding/bond_3ad.c
drivers/net/bonding/bond_3ad.h
drivers/net/bonding/bond_alb.c
drivers/net/bonding/bond_alb.h
drivers/net/bonding/bond_main.c
drivers/net/bonding/bond_sysfs.c [new file with mode: 0644]
drivers/net/bonding/bonding.h
drivers/net/chelsio/sge.c
drivers/net/chelsio/sge.h
drivers/net/e1000/e1000.h
drivers/net/e1000/e1000_ethtool.c
drivers/net/e1000/e1000_hw.c
drivers/net/e1000/e1000_hw.h
drivers/net/e1000/e1000_main.c
drivers/net/gianfar.c
drivers/net/gianfar.h
drivers/net/gianfar_ethtool.c
drivers/net/gianfar_mii.h
drivers/net/gianfar_sysfs.c [new file with mode: 0644]
drivers/net/ixp2000/Kconfig [new file with mode: 0644]
drivers/net/ixp2000/Makefile [new file with mode: 0644]
drivers/net/ixp2000/caleb.c [new file with mode: 0644]
drivers/net/ixp2000/caleb.h [new file with mode: 0644]
drivers/net/ixp2000/enp2611.c [new file with mode: 0644]
drivers/net/ixp2000/ixp2400-msf.c [new file with mode: 0644]
drivers/net/ixp2000/ixp2400-msf.h [new file with mode: 0644]
drivers/net/ixp2000/ixp2400_rx.uc [new file with mode: 0644]
drivers/net/ixp2000/ixp2400_rx.ucode [new file with mode: 0644]
drivers/net/ixp2000/ixp2400_tx.uc [new file with mode: 0644]
drivers/net/ixp2000/ixp2400_tx.ucode [new file with mode: 0644]
drivers/net/ixp2000/ixpdev.c [new file with mode: 0644]
drivers/net/ixp2000/ixpdev.h [new file with mode: 0644]
drivers/net/ixp2000/ixpdev_priv.h [new file with mode: 0644]
drivers/net/ixp2000/pm3386.c [new file with mode: 0644]
drivers/net/ixp2000/pm3386.h [new file with mode: 0644]
drivers/net/s2io.c
drivers/net/s2io.h
drivers/net/sis900.c
drivers/net/sis900.h
drivers/net/sk98lin/Makefile
drivers/net/sk98lin/h/skdrv2nd.h
drivers/net/sk98lin/h/skvpd.h
drivers/net/sk98lin/skethtool.c
drivers/net/sk98lin/skge.c
drivers/net/sk98lin/skproc.c [deleted file]
drivers/net/skge.c
drivers/net/skge.h
drivers/net/sky2.c [new file with mode: 0644]
drivers/net/sky2.h [new file with mode: 0644]
drivers/net/wan/lmc/lmc_prot.h [deleted file]
drivers/net/wireless/Kconfig
drivers/net/wireless/airo.c
drivers/net/wireless/atmel.c
drivers/net/wireless/hostap/Makefile
drivers/net/wireless/hostap/hostap_main.c [moved from drivers/net/wireless/hostap/hostap.c with 100% similarity]
drivers/net/wireless/ipw2100.c
drivers/net/wireless/ipw2100.h
drivers/net/wireless/ipw2200.c
drivers/net/wireless/ipw2200.h
include/linux/netdevice.h
net/core/dev.c
net/core/utils.c

diff --git a/Documentation/networking/gianfar.txt b/Documentation/networking/gianfar.txt
new file mode 100644 (file)
index 0000000..ad474ea
--- /dev/null
@@ -0,0 +1,72 @@
+The Gianfar Ethernet Driver
+Sysfs File description
+
+Author: Andy Fleming <afleming@freescale.com>
+Updated: 2005-07-28
+
+SYSFS
+
+Several of the features of the gianfar driver are controlled
+through sysfs files.  These are:
+
+bd_stash:
+To stash RX Buffer Descriptors in the L2, echo 'on' or '1' to
+bd_stash, echo 'off' or '0' to disable
+
+rx_stash_len:
+To stash the first n bytes of the packet in L2, echo the number
+of bytes to buf_stash_len.  echo 0 to disable.
+
+WARNING: You could really screw these up if you set them too low or high!
+fifo_threshold:
+To change the number of bytes the controller needs in the
+fifo before it starts transmission, echo the number of bytes to 
+fifo_thresh.  Range should be 0-511.
+
+fifo_starve:
+When the FIFO has less than this many bytes during a transmit, it
+enters starve mode, and increases the priority of TX memory
+transactions.  To change, echo the number of bytes to
+fifo_starve.  Range should be 0-511.
+
+fifo_starve_off:
+Once in starve mode, the FIFO remains there until it has this
+many bytes.  To change, echo the number of bytes to
+fifo_starve_off.  Range should be 0-511.
+
+CHECKSUM OFFLOADING
+
+The eTSEC controller (first included in parts from late 2005 like
+the 8548) has the ability to perform TCP, UDP, and IP checksums
+in hardware.  The Linux kernel only offloads the TCP and UDP
+checksums (and always performs the pseudo header checksums), so
+the driver only supports checksumming for TCP/IP and UDP/IP
+packets.  Use ethtool to enable or disable this feature for RX
+and TX.
+
+VLAN
+
+In order to use VLAN, please consult Linux documentation on
+configuring VLANs.  The gianfar driver supports hardware insertion and
+extraction of VLAN headers, but not filtering.  Filtering will be
+done by the kernel.
+
+MULTICASTING
+
+The gianfar driver supports using the group hash table on the
+TSEC (and the extended hash table on the eTSEC) for multicast
+filtering.  On the eTSEC, the exact-match MAC registers are used
+before the hash tables.  See Linux documentation on how to join
+multicast groups.
+
+PADDING
+
+The gianfar driver supports padding received frames with 2 bytes
+to align the IP header to a 16-byte boundary, when supported by
+hardware.
+
+ETHTOOL
+
+The gianfar driver supports the use of ethtool for many
+configuration options.  You must run ethtool only on currently
+open interfaces.  See ethtool documentation for details.
index 30bee11c48bd2d8364ac8f8e93abe47c5467593e..d2102a27d3071492dd4c3cd686e286c6dffaf8f4 100644 (file)
@@ -586,16 +586,16 @@ struct rtl8139_private {
        dma_addr_t tx_bufs_dma;
        signed char phys[4];            /* MII device addresses. */
        char twistie, twist_row, twist_col;     /* Twister tune state. */
-       unsigned int default_port:4;    /* Last dev->if_port value. */
+       unsigned int default_port : 4;  /* Last dev->if_port value. */
+       unsigned int have_thread : 1;
        spinlock_t lock;
        spinlock_t rx_lock;
        chip_t chipset;
-       pid_t thr_pid;
-       wait_queue_head_t thr_wait;
-       struct completion thr_exited;
        u32 rx_config;
        struct rtl_extra_stats xstats;
-       int time_to_die;
+
+       struct work_struct thread;
+
        struct mii_if_info mii;
        unsigned int regs_len;
        unsigned long fifo_copy_timeout;
@@ -620,7 +620,7 @@ static int rtl8139_open (struct net_device *dev);
 static int mdio_read (struct net_device *dev, int phy_id, int location);
 static void mdio_write (struct net_device *dev, int phy_id, int location,
                        int val);
-static void rtl8139_start_thread(struct net_device *dev);
+static void rtl8139_start_thread(struct rtl8139_private *tp);
 static void rtl8139_tx_timeout (struct net_device *dev);
 static void rtl8139_init_ring (struct net_device *dev);
 static int rtl8139_start_xmit (struct sk_buff *skb,
@@ -637,6 +637,7 @@ static struct net_device_stats *rtl8139_get_stats (struct net_device *dev);
 static void rtl8139_set_rx_mode (struct net_device *dev);
 static void __set_rx_mode (struct net_device *dev);
 static void rtl8139_hw_start (struct net_device *dev);
+static void rtl8139_thread (void *_data);
 static struct ethtool_ops rtl8139_ethtool_ops;
 
 /* write MMIO register, with flush */
@@ -1007,8 +1008,7 @@ static int __devinit rtl8139_init_one (struct pci_dev *pdev,
                (debug < 0 ? RTL8139_DEF_MSG_ENABLE : ((1 << debug) - 1));
        spin_lock_init (&tp->lock);
        spin_lock_init (&tp->rx_lock);
-       init_waitqueue_head (&tp->thr_wait);
-       init_completion (&tp->thr_exited);
+       INIT_WORK(&tp->thread, rtl8139_thread, dev);
        tp->mii.dev = dev;
        tp->mii.mdio_read = mdio_read;
        tp->mii.mdio_write = mdio_write;
@@ -1345,7 +1345,7 @@ static int rtl8139_open (struct net_device *dev)
                        dev->irq, RTL_R8 (MediaStatus),
                        tp->mii.full_duplex ? "full" : "half");
 
-       rtl8139_start_thread(dev);
+       rtl8139_start_thread(tp);
 
        return 0;
 }
@@ -1594,55 +1594,43 @@ static inline void rtl8139_thread_iter (struct net_device *dev,
                 RTL_R8 (Config1));
 }
 
-static int rtl8139_thread (void *data)
+static void rtl8139_thread (void *_data)
 {
-       struct net_device *dev = data;
+       struct net_device *dev = _data;
        struct rtl8139_private *tp = netdev_priv(dev);
-       unsigned long timeout;
-
-       daemonize("%s", dev->name);
-       allow_signal(SIGTERM);
-
-       while (1) {
-               timeout = next_tick;
-               do {
-                       timeout = interruptible_sleep_on_timeout (&tp->thr_wait, timeout);
-                       /* make swsusp happy with our thread */
-                       try_to_freeze();
-               } while (!signal_pending (current) && (timeout > 0));
-
-               if (signal_pending (current)) {
-                       flush_signals(current);
-               }
+       unsigned long thr_delay;
 
-               if (tp->time_to_die)
-                       break;
-
-               if (rtnl_lock_interruptible ())
-                       break;
+       if (rtnl_shlock_nowait() == 0) {
                rtl8139_thread_iter (dev, tp, tp->mmio_addr);
                rtnl_unlock ();
+
+               thr_delay = next_tick;
+       } else {
+               /* unlikely race.  mitigate with fast poll. */
+               thr_delay = HZ / 2;
        }
 
-       complete_and_exit (&tp->thr_exited, 0);
+       schedule_delayed_work(&tp->thread, thr_delay);
 }
 
-static void rtl8139_start_thread(struct net_device *dev)
+static void rtl8139_start_thread(struct rtl8139_private *tp)
 {
-       struct rtl8139_private *tp = netdev_priv(dev);
-
-       tp->thr_pid = -1;
        tp->twistie = 0;
-       tp->time_to_die = 0;
        if (tp->chipset == CH_8139_K)
                tp->twistie = 1;
        else if (tp->drv_flags & HAS_LNK_CHNG)
                return;
 
-       tp->thr_pid = kernel_thread(rtl8139_thread, dev, CLONE_FS|CLONE_FILES);
-       if (tp->thr_pid < 0) {
-               printk (KERN_WARNING "%s: unable to start kernel thread\n",
-                       dev->name);
+       tp->have_thread = 1;
+
+       schedule_delayed_work(&tp->thread, next_tick);
+}
+
+static void rtl8139_stop_thread(struct rtl8139_private *tp)
+{
+       if (tp->have_thread) {
+               cancel_rearming_delayed_work(&tp->thread);
+               tp->have_thread = 0;
        }
 }
 
@@ -2224,22 +2212,12 @@ static int rtl8139_close (struct net_device *dev)
 {
        struct rtl8139_private *tp = netdev_priv(dev);
        void __iomem *ioaddr = tp->mmio_addr;
-       int ret = 0;
        unsigned long flags;
 
        netif_stop_queue (dev);
 
-       if (tp->thr_pid >= 0) {
-               tp->time_to_die = 1;
-               wmb();
-               ret = kill_proc (tp->thr_pid, SIGTERM, 1);
-               if (ret) {
-                       printk (KERN_ERR "%s: unable to signal thread\n", dev->name);
-                       return ret;
-               }
-               wait_for_completion (&tp->thr_exited);
-       }
-       
+       rtl8139_stop_thread(tp);
+
        if (netif_msg_ifdown(tp))
                printk(KERN_DEBUG "%s: Shutting down ethercard, status was 0x%4.4x.\n",
                        dev->name, RTL_R16 (IntrStatus));
index ebd7313d7fc1c1652d26c37e9c984b92c57bcbe7..e2fa29b612cdffbea7c7488ebcd0a77ddf62f726 100644 (file)
@@ -1901,6 +1901,8 @@ config E1000_NAPI
 
          If in doubt, say N.
 
+source "drivers/net/ixp2000/Kconfig"
+
 config MYRI_SBUS
        tristate "MyriCOM Gigabit Ethernet support"
        depends on SBUS
@@ -2008,7 +2010,18 @@ config SKGE
 
          It does not support the link failover and network management 
          features that "portable" vendor supplied sk98lin driver does.
-       
+
+
+config SKY2
+       tristate "SysKonnect Yukon2 support (EXPERIMENTAL)"
+       depends on PCI && EXPERIMENTAL
+       select CRC32
+       ---help---
+         This driver support the Marvell Yukon 2 Gigabit Ethernet adapter.
+
+         To compile this driver as a module, choose M here: the module
+         will be called sky2.  This is recommended.
+
 config SK98LIN
        tristate "Marvell Yukon Chipset / SysKonnect SK-98xx Support"
        depends on PCI
@@ -2120,7 +2133,7 @@ config BNX2
 
 config SPIDER_NET
        tristate "Spider Gigabit Ethernet driver"
-       depends on PCI && PPC_BPA
+       depends on PCI && PPC_CELL
        help
          This driver supports the Gigabit Ethernet chips present on the
          Cell Processor-Based Blades from IBM.
index 4cffd34442aafaddc00865df86c26f410ccd61a2..b74a7cb5bae6e163c518199e28eb6269b5dc15d5 100644 (file)
@@ -13,7 +13,10 @@ obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
 
-gianfar_driver-objs := gianfar.o gianfar_ethtool.o gianfar_mii.o
+gianfar_driver-objs := gianfar.o \
+               gianfar_ethtool.o \
+               gianfar_mii.o \
+               gianfar_sysfs.o
 
 #
 # link order important here
@@ -59,6 +62,7 @@ spidernet-y += spider_net.o spider_net_ethtool.o sungem_phy.o
 obj-$(CONFIG_SPIDER_NET) += spidernet.o
 obj-$(CONFIG_TC35815) += tc35815.o
 obj-$(CONFIG_SKGE) += skge.o
+obj-$(CONFIG_SKY2) += sky2.o
 obj-$(CONFIG_SK98LIN) += sk98lin/
 obj-$(CONFIG_SKFP) += skfp/
 obj-$(CONFIG_VIA_RHINE) += via-rhine.o
@@ -202,6 +206,7 @@ obj-$(CONFIG_NET_TULIP) += tulip/
 obj-$(CONFIG_HAMRADIO) += hamradio/
 obj-$(CONFIG_IRDA) += irda/
 obj-$(CONFIG_ETRAX_ETHERNET) += cris/
+obj-$(CONFIG_ENP2611_MSF_NET) += ixp2000/
 
 obj-$(CONFIG_NETCONSOLE) += netconsole.o
 
index cf50384b469e9c83f8e3ed81c4258f706176e017..5cdae2bc055a9c27d679af0793d97bce459c0fd1 100644 (file)
@@ -4,5 +4,5 @@
 
 obj-$(CONFIG_BONDING) += bonding.o
 
-bonding-objs := bond_main.o bond_3ad.o bond_alb.o
+bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o
 
index d2f34d5a80835c786122a4ba359164d524b5bde6..f3f5825469d63c43b58df4851e8c56754ba7e800 100644 (file)
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
- *
- * Changes:
- *
- * 2003/05/01 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Amir Noam <amir.noam at intel dot com>
- *     - Added support for lacp_rate module param.
- *
- * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Based on discussion on mailing list, changed locking scheme
- *       to use lock/unlock or lock_bh/unlock_bh appropriately instead
- *       of lock_irqsave/unlock_irqrestore. The new scheme helps exposing
- *       hidden bugs and solves system hangs that occurred due to the fact
- *       that holding lock_irqsave doesn't prevent softirqs from running.
- *       This also increases total throughput since interrupts are not
- *       blocked on each transmitted packets or monitor timeout.
- *
- * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Renamed bond_3ad_link_status_changed() to
- *       bond_3ad_handle_link_change() for compatibility with TLB.
- *
- * 2003/05/20 - Amir Noam <amir.noam at intel dot com>
- *     - Fix long fail over time when releasing last slave of an active
- *       aggregator - send LACPDU on unbind of slave to tell partner this
- *       port is no longer aggregatable.
- *
- * 2003/06/25 - Tsippy Mendelson <tsippy.mendelson at intel dot com>
- *     - Send LACPDU as highest priority packet to further fix the above
- *       problem on very high Tx traffic load where packets may get dropped
- *       by the slave.
- *
- * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Code cleanup and style changes
  */
 
 //#define BONDING_DEBUG 1
@@ -1198,10 +1166,10 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
                        // detect loopback situation
                        if (!MAC_ADDRESS_COMPARE(&(lacpdu->actor_system), &(port->actor_system))) {
                                // INFO_RECEIVED_LOOPBACK_FRAMES
-                               printk(KERN_ERR DRV_NAME ": An illegal loopback occurred on adapter (%s)\n",
-                                               port->slave->dev->name);
-                               printk(KERN_ERR "Check the configuration to verify that all Adapters "
-                                               "are connected to 802.3ad compliant switch ports\n");
+                               printk(KERN_ERR DRV_NAME ": %s: An illegal loopback occurred on "
+                                      "adapter (%s). Check the configuration to verify that all "
+                                      "Adapters are connected to 802.3ad compliant switch ports\n",
+                                      port->slave->dev->master->name, port->slave->dev->name);
                                __release_rx_machine_lock(port);
                                return;
                        }
@@ -1378,8 +1346,9 @@ static void ad_port_selection_logic(struct port *port)
                        }
                }
                if (!curr_port) { // meaning: the port was related to an aggregator but was not on the aggregator port list
-                       printk(KERN_WARNING DRV_NAME ": Warning: Port %d (on %s) was "
+                       printk(KERN_WARNING DRV_NAME ": %s: Warning: Port %d (on %s) was "
                               "related to aggregator %d but was not on its port list\n",
+                              port->slave->dev->master->name,
                               port->actor_port_number, port->slave->dev->name,
                               port->aggregator->aggregator_identifier);
                }
@@ -1450,7 +1419,8 @@ static void ad_port_selection_logic(struct port *port)
 
                        dprintk("Port %d joined LAG %d(new LAG)\n", port->actor_port_number, port->aggregator->aggregator_identifier);
                } else {
-                       printk(KERN_ERR DRV_NAME ": Port %d (on %s) did not find a suitable aggregator\n",
+                       printk(KERN_ERR DRV_NAME ": %s: Port %d (on %s) did not find a suitable aggregator\n",
+                              port->slave->dev->master->name,
                               port->actor_port_number, port->slave->dev->name);
                }
        }
@@ -1582,8 +1552,9 @@ static void ad_agg_selection_logic(struct aggregator *aggregator)
 
                // check if any partner replys
                if (best_aggregator->is_individual) {
-                       printk(KERN_WARNING DRV_NAME ": Warning: No 802.3ad response from the link partner "
-                                       "for any adapters in the bond\n");
+                       printk(KERN_WARNING DRV_NAME ": %s: Warning: No 802.3ad response from "
+                              "the link partner for any adapters in the bond\n",
+                              best_aggregator->slave->dev->master->name);
                }
 
                // check if there are more than one aggregator
@@ -1915,7 +1886,8 @@ int bond_3ad_bind_slave(struct slave *slave)
        struct aggregator *aggregator;
 
        if (bond == NULL) {
-               printk(KERN_ERR "The slave %s is not attached to its bond\n", slave->dev->name);
+               printk(KERN_ERR DRV_NAME ": %s: The slave %s is not attached to its bond\n",
+                      slave->dev->master->name, slave->dev->name);
                return -1;
        }
 
@@ -1990,7 +1962,9 @@ void bond_3ad_unbind_slave(struct slave *slave)
 
        // if slave is null, the whole port is not initialized
        if (!port->slave) {
-               printk(KERN_WARNING DRV_NAME ": Trying to unbind an uninitialized port on %s\n", slave->dev->name);
+               printk(KERN_WARNING DRV_NAME ": Warning: %s: Trying to "
+                      "unbind an uninitialized port on %s\n",
+                      slave->dev->master->name, slave->dev->name);
                return;
        }
 
@@ -2021,7 +1995,8 @@ void bond_3ad_unbind_slave(struct slave *slave)
                                dprintk("Some port(s) related to LAG %d - replaceing with LAG %d\n", aggregator->aggregator_identifier, new_aggregator->aggregator_identifier);
 
                                if ((new_aggregator->lag_ports == port) && new_aggregator->is_active) {
-                                       printk(KERN_INFO DRV_NAME ": Removing an active aggregator\n");
+                                       printk(KERN_INFO DRV_NAME ": %s: Removing an active aggregator\n",
+                                              aggregator->slave->dev->master->name);
                                        // select new active aggregator
                                         select_new_active_agg = 1;
                                }
@@ -2051,15 +2026,17 @@ void bond_3ad_unbind_slave(struct slave *slave)
                                        ad_agg_selection_logic(__get_first_agg(port));
                                }
                        } else {
-                               printk(KERN_WARNING DRV_NAME ": Warning: unbinding aggregator, "
-                                      "and could not find a new aggregator for its ports\n");
+                               printk(KERN_WARNING DRV_NAME ": %s: Warning: unbinding aggregator, "
+                                      "and could not find a new aggregator for its ports\n",
+                                      slave->dev->master->name);
                        }
                } else { // in case that the only port related to this aggregator is the one we want to remove
                        select_new_active_agg = aggregator->is_active;
                        // clear the aggregator
                        ad_clear_agg(aggregator);
                        if (select_new_active_agg) {
-                               printk(KERN_INFO "Removing an active aggregator\n");
+                               printk(KERN_INFO DRV_NAME ": %s: Removing an active aggregator\n",
+                                      slave->dev->master->name);
                                // select new active aggregator
                                ad_agg_selection_logic(__get_first_agg(port));
                        }
@@ -2085,7 +2062,8 @@ void bond_3ad_unbind_slave(struct slave *slave)
                                        // clear the aggregator
                                        ad_clear_agg(temp_aggregator);
                                        if (select_new_active_agg) {
-                                               printk(KERN_INFO "Removing an active aggregator\n");
+                                               printk(KERN_INFO DRV_NAME ": %s: Removing an active aggregator\n",
+                                                      slave->dev->master->name);
                                                // select new active aggregator
                                                ad_agg_selection_logic(__get_first_agg(port));
                                        }
@@ -2131,7 +2109,8 @@ void bond_3ad_state_machine_handler(struct bonding *bond)
                // select the active aggregator for the bond
                if ((port = __get_first_port(bond))) {
                        if (!port->slave) {
-                               printk(KERN_WARNING DRV_NAME ": Warning: bond's first port is uninitialized\n");
+                               printk(KERN_WARNING DRV_NAME ": %s: Warning: bond's first port is "
+                                      "uninitialized\n", bond->dev->name);
                                goto re_arm;
                        }
 
@@ -2143,7 +2122,8 @@ void bond_3ad_state_machine_handler(struct bonding *bond)
        // for each port run the state machines
        for (port = __get_first_port(bond); port; port = __get_next_port(port)) {
                if (!port->slave) {
-                       printk(KERN_WARNING DRV_NAME ": Warning: Found an uninitialized port\n");
+                       printk(KERN_WARNING DRV_NAME ": %s: Warning: Found an uninitialized "
+                              "port\n", bond->dev->name);
                        goto re_arm;
                }
 
@@ -2184,7 +2164,8 @@ static void bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u
                port = &(SLAVE_AD_INFO(slave).port);
 
                if (!port->slave) {
-                       printk(KERN_WARNING DRV_NAME ": Warning: port of slave %s is uninitialized\n", slave->dev->name);
+                       printk(KERN_WARNING DRV_NAME ": %s: Warning: port of slave %s is "
+                              "uninitialized\n", slave->dev->name, slave->dev->master->name);
                        return;
                }
 
@@ -2230,8 +2211,9 @@ void bond_3ad_adapter_speed_changed(struct slave *slave)
 
        // if slave is null, the whole port is not initialized
        if (!port->slave) {
-               printk(KERN_WARNING DRV_NAME ": Warning: speed changed for uninitialized port on %s\n",
-                      slave->dev->name);
+               printk(KERN_WARNING DRV_NAME ": Warning: %s: speed "
+                      "changed for uninitialized port on %s\n",
+                      slave->dev->master->name, slave->dev->name);
                return;
        }
 
@@ -2257,8 +2239,9 @@ void bond_3ad_adapter_duplex_changed(struct slave *slave)
 
        // if slave is null, the whole port is not initialized
        if (!port->slave) {
-               printk(KERN_WARNING DRV_NAME ": Warning: duplex changed for uninitialized port on %s\n",
-                      slave->dev->name);
+               printk(KERN_WARNING DRV_NAME ": %s: Warning: duplex changed "
+                      "for uninitialized port on %s\n",
+                      slave->dev->master->name, slave->dev->name);
                return;
        }
 
@@ -2285,8 +2268,9 @@ void bond_3ad_handle_link_change(struct slave *slave, char link)
 
        // if slave is null, the whole port is not initialized
        if (!port->slave) {
-               printk(KERN_WARNING DRV_NAME ": Warning: link status changed for uninitialized port on %s\n",
-                       slave->dev->name);
+               printk(KERN_WARNING DRV_NAME ": Warning: %s: link status changed for "
+                      "uninitialized port on %s\n",
+                       slave->dev->master->name, slave->dev->name);
                return;
        }
 
@@ -2363,7 +2347,8 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
        }
 
        if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
-               printk(KERN_DEBUG "ERROR: bond_3ad_get_active_agg_info failed\n");
+               printk(KERN_DEBUG DRV_NAME ": %s: Error: "
+                      "bond_3ad_get_active_agg_info failed\n", dev->name);
                goto out;
        }
 
@@ -2372,7 +2357,9 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
 
        if (slaves_in_agg == 0) {
                /*the aggregator is empty*/
-               printk(KERN_DEBUG "ERROR: active aggregator is empty\n");
+               printk(KERN_DEBUG DRV_NAME ": %s: Error: active "
+                      "aggregator is empty\n",
+                      dev->name);
                goto out;
        }
 
@@ -2390,7 +2377,8 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
        }
 
        if (slave_agg_no >= 0) {
-               printk(KERN_ERR DRV_NAME ": Error: Couldn't find a slave to tx on for aggregator ID %d\n", agg_id);
+               printk(KERN_ERR DRV_NAME ": %s: Error: Couldn't find a slave to tx on "
+                      "for aggregator ID %d\n", dev->name, agg_id);
                goto out;
        }
 
index 673a30af5660f58a096f1253c34fb10bd40bcbec..5ee2cef5b037f9d5f0b41ff2015a34c3067af2a0 100644 (file)
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
- *
- * Changes:
- *
- * 2003/05/01 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Amir Noam <amir.noam at intel dot com>
- *     - Added support for lacp_rate module param.
- *
- * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Renamed bond_3ad_link_status_changed() to
- *       bond_3ad_handle_link_change() for compatibility with TLB.
- *
- * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Code cleanup and style changes
  */
 
 #ifndef __BOND_3AD_H__
index f8fce39611972f18fefdd8524368955425d84466..854ddfb90da19139bfcdbbe47810117772c4f8ef 100644 (file)
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
- *
- * Changes:
- *
- * 2003/06/25 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Fixed signed/unsigned calculation errors that caused load sharing
- *       to collapse to one slave under very heavy UDP Tx stress.
- *
- * 2003/08/06 - Amir Noam <amir.noam at intel dot com>
- *     - Add support for setting bond's MAC address with special
- *       handling required for ALB/TLB.
- *
- * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Code cleanup and style changes
- *
- * 2003/12/30 - Amir Noam <amir.noam at intel dot com>
- *     - Fixed: Cannot remove and re-enslave the original active slave.
- *
- * 2004/01/14 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Add capability to tag self generated packets in ALB/TLB modes.
  */
 
 //#define BONDING_DEBUG 1
@@ -198,20 +179,21 @@ static int tlb_initialize(struct bonding *bond)
 {
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
        int size = TLB_HASH_TABLE_SIZE * sizeof(struct tlb_client_info);
+       struct tlb_client_info *new_hashtbl;
        int i;
 
        spin_lock_init(&(bond_info->tx_hashtbl_lock));
 
-       _lock_tx_hashtbl(bond);
-
-       bond_info->tx_hashtbl = kmalloc(size, GFP_KERNEL);
-       if (!bond_info->tx_hashtbl) {
+       new_hashtbl = kmalloc(size, GFP_KERNEL);
+       if (!new_hashtbl) {
                printk(KERN_ERR DRV_NAME
-                      ": Error: %s: Failed to allocate TLB hash table\n",
+                      ": %s: Error: Failed to allocate TLB hash table\n",
                       bond->dev->name);
-               _unlock_tx_hashtbl(bond);
                return -1;
        }
+       _lock_tx_hashtbl(bond);
+
+       bond_info->tx_hashtbl = new_hashtbl;
 
        memset(bond_info->tx_hashtbl, 0, size);
 
@@ -513,7 +495,8 @@ static void rlb_update_client(struct rlb_client_info *client_info)
                                 client_info->mac_dst);
                if (!skb) {
                        printk(KERN_ERR DRV_NAME
-                              ": Error: failed to create an ARP packet\n");
+                              ": %s: Error: failed to create an ARP packet\n",
+                              client_info->slave->dev->master->name);
                        continue;
                }
 
@@ -523,7 +506,8 @@ static void rlb_update_client(struct rlb_client_info *client_info)
                        skb = vlan_put_tag(skb, client_info->vlan_id);
                        if (!skb) {
                                printk(KERN_ERR DRV_NAME
-                                      ": Error: failed to insert VLAN tag\n");
+                                      ": %s: Error: failed to insert VLAN tag\n",
+                                      client_info->slave->dev->master->name);
                                continue;
                        }
                }
@@ -606,8 +590,9 @@ static void rlb_req_update_subnet_clients(struct bonding *bond, u32 src_ip)
 
                if (!client_info->slave) {
                        printk(KERN_ERR DRV_NAME
-                              ": Error: found a client with no channel in "
-                              "the client's hash table\n");
+                              ": %s: Error: found a client with no channel in "
+                              "the client's hash table\n",
+                              bond->dev->name);
                        continue;
                }
                /*update all clients using this src_ip, that are not assigned
@@ -797,21 +782,22 @@ static int rlb_initialize(struct bonding *bond)
 {
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
        struct packet_type *pk_type = &(BOND_ALB_INFO(bond).rlb_pkt_type);
+       struct rlb_client_info  *new_hashtbl;
        int size = RLB_HASH_TABLE_SIZE * sizeof(struct rlb_client_info);
        int i;
 
        spin_lock_init(&(bond_info->rx_hashtbl_lock));
 
-       _lock_rx_hashtbl(bond);
-
-       bond_info->rx_hashtbl = kmalloc(size, GFP_KERNEL);
-       if (!bond_info->rx_hashtbl) {
+       new_hashtbl = kmalloc(size, GFP_KERNEL);
+       if (!new_hashtbl) {
                printk(KERN_ERR DRV_NAME
-                      ": Error: %s: Failed to allocate RLB hash table\n",
+                      ": %s: Error: Failed to allocate RLB hash table\n",
                       bond->dev->name);
-               _unlock_rx_hashtbl(bond);
                return -1;
        }
+       _lock_rx_hashtbl(bond);
+
+       bond_info->rx_hashtbl = new_hashtbl;
 
        bond_info->rx_hashtbl_head = RLB_NULL_INDEX;
 
@@ -927,7 +913,8 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
                        skb = vlan_put_tag(skb, vlan->vlan_id);
                        if (!skb) {
                                printk(KERN_ERR DRV_NAME
-                                      ": Error: failed to insert VLAN tag\n");
+                                      ": %s: Error: failed to insert VLAN tag\n",
+                                      bond->dev->name);
                                continue;
                        }
                }
@@ -956,11 +943,11 @@ static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[], int hw)
        s_addr.sa_family = dev->type;
        if (dev_set_mac_address(dev, &s_addr)) {
                printk(KERN_ERR DRV_NAME
-                      ": Error: dev_set_mac_address of dev %s failed! ALB "
+                      ": %s: Error: dev_set_mac_address of dev %s failed! ALB "
                       "mode requires that the base driver support setting "
                       "the hw address also when the network device's "
                       "interface is open\n",
-                      dev->name);
+                      dev->master->name, dev->name);
                return -EOPNOTSUPP;
        }
        return 0;
@@ -1153,16 +1140,16 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
                                       bond->alb_info.rlb_enabled);
 
                printk(KERN_WARNING DRV_NAME
-                      ": Warning: the hw address of slave %s is in use by "
+                      ": %s: Warning: the hw address of slave %s is in use by "
                       "the bond; giving it the hw address of %s\n",
-                      slave->dev->name, free_mac_slave->dev->name);
+                      bond->dev->name, slave->dev->name, free_mac_slave->dev->name);
 
        } else if (has_bond_addr) {
                printk(KERN_ERR DRV_NAME
-                      ": Error: the hw address of slave %s is in use by the "
+                      ": %s: Error: the hw address of slave %s is in use by the "
                       "bond; couldn't find a slave with a free hw address to "
                       "give it (this should not have happened)\n",
-                      slave->dev->name);
+                      bond->dev->name, slave->dev->name);
                return -EFAULT;
        }
 
@@ -1250,6 +1237,8 @@ int bond_alb_initialize(struct bonding *bond, int rlb_enabled)
                        tlb_deinitialize(bond);
                        return res;
                }
+       } else {
+               bond->alb_info.rlb_enabled = 0;
        }
 
        return 0;
@@ -1409,7 +1398,7 @@ void bond_alb_monitor(struct bonding *bond)
                read_lock(&bond->curr_slave_lock);
 
                bond_for_each_slave(bond, slave, i) {
-                       alb_send_learning_packets(slave,slave->dev->dev_addr);
+                       alb_send_learning_packets(slave, slave->dev->dev_addr);
                }
 
                read_unlock(&bond->curr_slave_lock);
index e4091cd8d6547e6474c622f71283f794c8557f5e..28f2a2fd1b5a956cb896561d2646690ed49bf230 100644 (file)
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
- *
- * Changes:
- *
- * 2003/08/06 - Amir Noam <amir.noam at intel dot com>
- *     - Add support for setting bond's MAC address with special
- *       handling required for ALB/TLB.
- *
- * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Code cleanup and style changes
  */
 
 #ifndef __BOND_ALB_H__
index 94cec3cf2a1304b994b8279daf0cd01cbf7c2dbc..2582d98ef5c3308c16214b75f520ec1abb1b97e4 100644 (file)
  *     b: if a hw mac address already is there, eth0's hw mac address
  *        will then be set from bond0.
  *
- * v0.1 - first working version.
- * v0.2 - changed stats to be calculated by summing slaves stats.
- *
- * Changes:
- * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
- * - fix leaks on failure at bond_init
- *
- * 2000/09/30 - Willy Tarreau <willy at meta-x.org>
- *     - added trivial code to release a slave device.
- *     - fixed security bug (CAP_NET_ADMIN not checked)
- *     - implemented MII link monitoring to disable dead links :
- *       All MII capable slaves are checked every <miimon> milliseconds
- *       (100 ms seems good). This value can be changed by passing it to
- *       insmod. A value of zero disables the monitoring (default).
- *     - fixed an infinite loop in bond_xmit_roundrobin() when there's no
- *       good slave.
- *     - made the code hopefully SMP safe
- *
- * 2000/10/03 - Willy Tarreau <willy at meta-x.org>
- *     - optimized slave lists based on relevant suggestions from Thomas Davis
- *     - implemented active-backup method to obtain HA with two switches:
- *       stay as long as possible on the same active interface, while we
- *       also monitor the backup one (MII link status) because we want to know
- *       if we are able to switch at any time. ( pass "mode=1" to insmod )
- *     - lots of stress testings because we need it to be more robust than the
- *       wires ! :->
- *
- * 2000/10/09 - Willy Tarreau <willy at meta-x.org>
- *     - added up and down delays after link state change.
- *     - optimized the slaves chaining so that when we run forward, we never
- *       repass through the bond itself, but we can find it by searching
- *       backwards. Renders the deletion more difficult, but accelerates the
- *       scan.
- *     - smarter enslaving and releasing.
- *     - finer and more robust SMP locking
- *
- * 2000/10/17 - Willy Tarreau <willy at meta-x.org>
- *     - fixed two potential SMP race conditions
- *
- * 2000/10/18 - Willy Tarreau <willy at meta-x.org>
- *     - small fixes to the monitoring FSM in case of zero delays
- * 2000/11/01 - Willy Tarreau <willy at meta-x.org>
- *     - fixed first slave not automatically used in trunk mode.
- * 2000/11/10 : spelling of "EtherChannel" corrected.
- * 2000/11/13 : fixed a race condition in case of concurrent accesses to ioctl().
- * 2000/12/16 : fixed improper usage of rtnl_exlock_nowait().
- *
- * 2001/1/3 - Chad N. Tindel <ctindel at ieee dot org>
- *     - The bonding driver now simulates MII status monitoring, just like
- *       a normal network device.  It will show that the link is down iff
- *       every slave in the bond shows that their links are down.  If at least
- *       one slave is up, the bond's MII status will appear as up.
- *
- * 2001/2/7 - Chad N. Tindel <ctindel at ieee dot org>
- *     - Applications can now query the bond from user space to get
- *       information which may be useful.  They do this by calling
- *       the BOND_INFO_QUERY ioctl.  Once the app knows how many slaves
- *       are in the bond, it can call the BOND_SLAVE_INFO_QUERY ioctl to
- *       get slave specific information (# link failures, etc).  See
- *       <linux/if_bonding.h> for more details.  The structs of interest
- *       are ifbond and ifslave.
- *
- * 2001/4/5 - Chad N. Tindel <ctindel at ieee dot org>
- *     - Ported to 2.4 Kernel
- *
- * 2001/5/2 - Jeffrey E. Mast <jeff at mastfamily dot com>
- *     - When a device is detached from a bond, the slave device is no longer
- *       left thinking that is has a master.
- *
- * 2001/5/16 - Jeffrey E. Mast <jeff at mastfamily dot com>
- *     - memset did not appropriately initialized the bond rw_locks. Used
- *       rwlock_init to initialize to unlocked state to prevent deadlock when
- *       first attempting a lock
- *     - Called SET_MODULE_OWNER for bond device
- *
- * 2001/5/17 - Tim Anderson <tsa at mvista.com>
- *     - 2 paths for releasing for slave release; 1 through ioctl
- *       and 2) through close. Both paths need to release the same way.
- *     - the free slave in bond release is changing slave status before
- *       the free. The netdev_set_master() is intended to change slave state
- *       so it should not be done as part of the release process.
- *     - Simple rule for slave state at release: only the active in A/B and
- *       only one in the trunked case.
- *
- * 2001/6/01 - Tim Anderson <tsa at mvista.com>
- *     - Now call dev_close when releasing a slave so it doesn't screw up
- *       out routing table.
- *
- * 2001/6/01 - Chad N. Tindel <ctindel at ieee dot org>
- *     - Added /proc support for getting bond and slave information.
- *       Information is in /proc/net/<bond device>/info.
- *     - Changed the locking when calling bond_close to prevent deadlock.
- *
- * 2001/8/05 - Janice Girouard <girouard at us.ibm.com>
- *     - correct problem where refcnt of slave is not incremented in bond_ioctl
- *       so the system hangs when halting.
- *     - correct locking problem when unable to malloc in bond_enslave.
- *     - adding bond_xmit_xor logic.
- *     - adding multiple bond device support.
- *
- * 2001/8/13 - Erik Habbinga <erik_habbinga at hp dot com>
- *     - correct locking problem with rtnl_exlock_nowait
- *
- * 2001/8/23 - Janice Girouard <girouard at us.ibm.com>
- *     - bzero initial dev_bonds, to correct oops
- *     - convert SIOCDEVPRIVATE to new MII ioctl calls
- *
- * 2001/9/13 - Takao Indoh <indou dot takao at jp dot fujitsu dot com>
- *     - Add the BOND_CHANGE_ACTIVE ioctl implementation
- *
- * 2001/9/14 - Mark Huth <mhuth at mvista dot com>
- *     - Change MII_LINK_READY to not check for end of auto-negotiation,
- *       but only for an up link.
- *
- * 2001/9/20 - Chad N. Tindel <ctindel at ieee dot org>
- *     - Add the device field to bonding_t.  Previously the net_device
- *       corresponding to a bond wasn't available from the bonding_t
- *       structure.
- *
- * 2001/9/25 - Janice Girouard <girouard at us.ibm.com>
- *     - add arp_monitor for active backup mode
- *
- * 2001/10/23 - Takao Indoh <indou dot takao at jp dot fujitsu dot com>
- *     - Various memory leak fixes
- *
- * 2001/11/5 - Mark Huth <mark dot huth at mvista dot com>
- *     - Don't take rtnl lock in bond_mii_monitor as it deadlocks under
- *       certain hotswap conditions.
- *       Note:  this same change may be required in bond_arp_monitor ???
- *     - Remove possibility of calling bond_sethwaddr with NULL slave_dev ptr
- *     - Handle hot swap ethernet interface deregistration events to remove
- *       kernel oops following hot swap of enslaved interface
- *
- * 2002/1/2 - Chad N. Tindel <ctindel at ieee dot org>
- *     - Restore original slave flags at release time.
- *
- * 2002/02/18 - Erik Habbinga <erik_habbinga at hp dot com>
- *     - bond_release(): calling kfree on our_slave after call to
- *       bond_restore_slave_flags, not before
- *     - bond_enslave(): saving slave flags into original_flags before
- *       call to netdev_set_master, so the IFF_SLAVE flag doesn't end
- *       up in original_flags
- *
- * 2002/04/05 - Mark Smith <mark.smith at comdev dot cc> and
- *              Steve Mead <steve.mead at comdev dot cc>
- *     - Port Gleb Natapov's multicast support patchs from 2.4.12
- *       to 2.4.18 adding support for multicast.
- *
- * 2002/06/10 - Tony Cureington <tony.cureington * hp_com>
- *     - corrected uninitialized pointer (ifr.ifr_data) in bond_check_dev_link;
- *       actually changed function to use MIIPHY, then MIIREG, and finally
- *       ETHTOOL to determine the link status
- *     - fixed bad ifr_data pointer assignments in bond_ioctl
- *     - corrected mode 1 being reported as active-backup in bond_get_info;
- *       also added text to distinguish type of load balancing (rr or xor)
- *     - change arp_ip_target module param from "1-12s" (array of 12 ptrs)
- *       to "s" (a single ptr)
- *
- * 2002/08/30 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Removed acquisition of xmit_lock in set_multicast_list; caused
- *       deadlock on SMP (lock is held by caller).
- *     - Revamped SIOCGMIIPHY, SIOCGMIIREG portion of bond_check_dev_link().
- *
- * 2002/09/18 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Fixed up bond_check_dev_link() (and callers): removed some magic
- *      numbers, banished local MII_ defines, wrapped ioctl calls to
- *      prevent EFAULT errors
- *
- * 2002/9/30 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - make sure the ip target matches the arp_target before saving the
- *      hw address.
- *
- * 2002/9/30 - Dan Eisner <eisner at 2robots dot com>
- *     - make sure my_ip is set before taking down the link, since
- *      not all switches respond if the source ip is not set.
- *
- * 2002/10/8 - Janice Girouard <girouard at us dot ibm dot com>
- *     - read in the local ip address when enslaving a device
- *     - add primary support
- *     - make sure 2*arp_interval has passed when a new device
- *       is brought on-line before taking it down.
- *
- * 2002/09/11 - Philippe De Muyter <phdm at macqel dot be>
- *     - Added bond_xmit_broadcast logic.
- *     - Added bond_mode() support function.
- *
- * 2002/10/26 - Laurent Deniel <laurent.deniel at free.fr>
- *     - allow to register multicast addresses only on active slave
- *       (useful in active-backup mode)
- *     - add multicast module parameter
- *     - fix deletion of multicast groups after unloading module
- *
- * 2002/11/06 - Kameshwara Rayaprolu <kameshwara.rao * wipro_com>
- *     - Changes to prevent panic from closing the device twice; if we close
- *       the device in bond_release, we must set the original_flags to down
- *       so it won't be closed again by the network layer.
- *
- * 2002/11/07 - Tony Cureington <tony.cureington * hp_com>
- *     - Fix arp_target_hw_addr memory leak
- *     - Created activebackup_arp_monitor function to handle arp monitoring
- *       in active backup mode - the bond_arp_monitor had several problems...
- *       such as allowing slaves to tx arps sequentially without any delay
- *       for a response
- *     - Renamed bond_arp_monitor to loadbalance_arp_monitor and re-wrote
- *       this function to just handle arp monitoring in load-balancing mode;
- *       it is a lot more compact now
- *     - Changes to ensure one and only one slave transmits in active-backup
- *       mode
- *     - Robustesize parameters; warn users about bad combinations of
- *       parameters; also if miimon is specified and a network driver does
- *       not support MII or ETHTOOL, inform the user of this
- *     - Changes to support link_failure_count when in arp monitoring mode
- *     - Fix up/down delay reported in /proc
- *     - Added version; log version; make version available from "modinfo -d"
- *     - Fixed problem in bond_check_dev_link - if the first IOCTL (SIOCGMIIPH)
- *      failed, the ETHTOOL ioctl never got a chance
- *
- * 2002/11/16 - Laurent Deniel <laurent.deniel at free.fr>
- *     - fix multicast handling in activebackup_arp_monitor
- *     - remove one unnecessary and confusing curr_active_slave == slave test
- *      in activebackup_arp_monitor
- *
- *  2002/11/17 - Laurent Deniel <laurent.deniel at free.fr>
- *     - fix bond_slave_info_query when slave_id = num_slaves
- *
- *  2002/11/19 - Janice Girouard <girouard at us dot ibm dot com>
- *     - correct ifr_data reference.  Update ifr_data reference
- *       to mii_ioctl_data struct values to avoid confusion.
- *
- *  2002/11/22 - Bert Barbe <bert.barbe at oracle dot com>
- *      - Add support for multiple arp_ip_target
- *
- *  2002/12/13 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Changed to allow text strings for mode and multicast, e.g.,
- *       insmod bonding mode=active-backup.  The numbers still work.
- *       One change: an invalid choice will cause module load failure,
- *       rather than the previous behavior of just picking one.
- *     - Minor cleanups; got rid of dup ctype stuff, atoi function
- *
- * 2003/02/07 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Added use_carrier module parameter that causes miimon to
- *       use netif_carrier_ok() test instead of MII/ETHTOOL ioctls.
- *     - Minor cleanups; consolidated ioctl calls to one function.
- *
- * 2003/02/07 - Tony Cureington <tony.cureington * hp_com>
- *     - Fix bond_mii_monitor() logic error that could result in
- *       bonding round-robin mode ignoring links after failover/recovery
- *
- * 2003/03/17 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - kmalloc fix (GFP_KERNEL to GFP_ATOMIC) reported by
- *       Shmulik dot Hen at intel.com.
- *     - Based on discussion on mailing list, changed use of
- *       update_slave_cnt(), created wrapper functions for adding/removing
- *       slaves, changed bond_xmit_xor() to check slave_cnt instead of
- *       checking slave and slave->dev (which only worked by accident).
- *     - Misc code cleanup: get arp_send() prototype from header file,
- *       add max_bonds to bonding.txt.
- *
- * 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Shmulik Hen <shmulik.hen at intel dot com>
- *     - Make sure only bond_attach_slave() and bond_detach_slave() can
- *       manipulate the slave list, including slave_cnt, even when in
- *       bond_release_all().
- *     - Fixed hang in bond_release() with traffic running:
- *       netdev_set_master() must not be called from within the bond lock.
- *
- * 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Shmulik Hen <shmulik.hen at intel dot com>
- *     - Fixed hang in bond_enslave() with traffic running:
- *       netdev_set_master() must not be called from within the bond lock.
- *
- * 2003/03/18 - Amir Noam <amir.noam at intel dot com>
- *     - Added support for getting slave's speed and duplex via ethtool.
- *       Needed for 802.3ad and other future modes.
- *
- * 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Shmulik Hen <shmulik.hen at intel dot com>
- *     - Enable support of modes that need to use the unique mac address of
- *       each slave.
- *       * bond_enslave(): Moved setting the slave's mac address, and
- *         openning it, from the application to the driver. This breaks
- *         backward comaptibility with old versions of ifenslave that open
- *          the slave before enalsving it !!!.
- *       * bond_release(): The driver also takes care of closing the slave
- *         and restoring its original mac address.
- *     - Removed the code that restores all base driver's flags.
- *       Flags are automatically restored once all undo stages are done
- *       properly.
- *     - Block possibility of enslaving before the master is up. This
- *       prevents putting the system in an unstable state.
- *
- * 2003/03/18 - Amir Noam <amir.noam at intel dot com>,
- *             Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Shmulik Hen <shmulik.hen at intel dot com>
- *     - Added support for IEEE 802.3ad Dynamic link aggregation mode.
- *
- * 2003/05/01 - Amir Noam <amir.noam at intel dot com>
- *     - Added ABI version control to restore compatibility between
- *       new/old ifenslave and new/old bonding.
- *
- * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Fixed bug in bond_release_all(): save old value of curr_active_slave
- *       before setting it to NULL.
- *     - Changed driver versioning scheme to include version number instead
- *       of release date (that is already in another field). There are 3
- *       fields X.Y.Z where:
- *             X - Major version - big behavior changes
- *             Y - Minor version - addition of features
- *             Z - Extra version - minor changes and bug fixes
- *       The current version is 1.0.0 as a base line.
- *
- * 2003/05/01 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Amir Noam <amir.noam at intel dot com>
- *     - Added support for lacp_rate module param.
- *     - Code beautification and style changes (mainly in comments).
- *       new version - 1.0.1
- *
- * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Based on discussion on mailing list, changed locking scheme
- *       to use lock/unlock or lock_bh/unlock_bh appropriately instead
- *       of lock_irqsave/unlock_irqrestore. The new scheme helps exposing
- *       hidden bugs and solves system hangs that occurred due to the fact
- *       that holding lock_irqsave doesn't prevent softirqs from running.
- *       This also increases total throughput since interrupts are not
- *       blocked on each transmitted packets or monitor timeout.
- *       new version - 2.0.0
- *
- * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Added support for Transmit load balancing mode.
- *     - Concentrate all assignments of curr_active_slave to a single point
- *       so specific modes can take actions when the primary adapter is
- *       changed.
- *     - Take the updelay parameter into consideration during bond_enslave
- *       since some adapters loose their link during setting the device.
- *     - Renamed bond_3ad_link_status_changed() to
- *       bond_3ad_handle_link_change() for compatibility with TLB.
- *       new version - 2.1.0
- *
- * 2003/05/01 - Tsippy Mendelson <tsippy.mendelson at intel dot com>
- *     - Added support for Adaptive load balancing mode which is
- *       equivalent to Transmit load balancing + Receive load balancing.
- *       new version - 2.2.0
- *
- * 2003/05/15 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Applied fix to activebackup_arp_monitor posted to bonding-devel
- *       by Tony Cureington <tony.cureington * hp_com>.  Fixes ARP
- *       monitor endless failover bug.  Version to 2.2.10
- *
- * 2003/05/20 - Amir Noam <amir.noam at intel dot com>
- *     - Fixed bug in ABI version control - Don't commit to a specific
- *       ABI version if receiving unsupported ioctl commands.
- *
- * 2003/05/22 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Fix ifenslave -c causing bond to loose existing routes;
- *       added bond_set_mac_address() that doesn't require the
- *       bond to be down.
- *     - In conjunction with fix for ifenslave -c, in
- *       bond_change_active(), changing to the already active slave
- *       is no longer an error (it successfully does nothing).
- *
- * 2003/06/30 - Amir Noam <amir.noam at intel dot com>
- *     - Fixed bond_change_active() for ALB/TLB modes.
- *       Version to 2.2.14.
- *
- * 2003/07/29 - Amir Noam <amir.noam at intel dot com>
- *     - Fixed ARP monitoring bug.
- *       Version to 2.2.15.
- *
- * 2003/07/31 - Willy Tarreau <willy at ods dot org>
- *     - Fixed kernel panic when using ARP monitoring without
- *       setting bond's IP address.
- *       Version to 2.2.16.
- *
- * 2003/08/06 - Amir Noam <amir.noam at intel dot com>
- *     - Back port from 2.6: use alloc_netdev(); fix /proc handling;
- *       made stats a part of bond struct so no need to allocate
- *       and free it separately; use standard list operations instead
- *       of pre-allocated array of bonds.
- *       Version to 2.3.0.
- *
- * 2003/08/07 - Jay Vosburgh <fubar at us dot ibm dot com>,
- *            Amir Noam <amir.noam at intel dot com> and
- *            Shmulik Hen <shmulik.hen at intel dot com>
- *     - Propagating master's settings: Distinguish between modes that
- *       use a primary slave from those that don't, and propagate settings
- *       accordingly; Consolidate change_active opeartions and add
- *       reselect_active and find_best opeartions; Decouple promiscuous
- *       handling from the multicast mode setting; Add support for changing
- *       HW address and MTU with proper unwind; Consolidate procfs code,
- *       add CHANGENAME handler; Enhance netdev notification handling.
- *       Version to 2.4.0.
- *
- * 2003/09/15 - Stephen Hemminger <shemminger at osdl dot org>,
- *            Amir Noam <amir.noam at intel dot com>
- *     - Convert /proc to seq_file interface.
- *       Change /proc/net/bondX/info to /proc/net/bonding/bondX.
- *       Set version to 2.4.1.
- *
- * 2003/11/20 - Amir Noam <amir.noam at intel dot com>
- *     - Fix /proc creation/destruction.
- *
- * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Massive cleanup - Set version to 2.5.0
- *       Code changes:
- *       o Consolidate format of prints and debug prints.
- *       o Remove bonding_t/slave_t typedefs and consolidate all casts.
- *       o Remove dead code and unnecessary checks.
- *       o Consolidate starting/stopping timers.
- *       o Consolidate handling of primary module param throughout the code.
- *       o Removed multicast module param support - all settings are done
- *         according to mode.
- *       o Slave list iteration - bond is no longer part of the list,
- *         added cyclic list iteration macros.
- *       o Consolidate error handling in all xmit functions.
- *       Style changes:
- *       o Consolidate function naming and declarations.
- *       o Consolidate function params and local variables names.
- *       o Consolidate return values.
- *       o Consolidate curly braces.
- *       o Consolidate conditionals format.
- *       o Change struct member names and types.
- *       o Chomp trailing spaces, remove empty lines, fix indentations.
- *       o Re-organize code according to context.
- *
- * 2003/12/30 - Amir Noam <amir.noam at intel dot com>
- *     - Fixed: Cannot remove and re-enslave the original active slave.
- *     - Fixed: Releasing the original active slave causes mac address
- *              duplication.
- *     - Add support for slaves that use ethtool_ops.
- *       Set version to 2.5.3.
- *
- * 2004/01/05 - Amir Noam <amir.noam at intel dot com>
- *     - Save bonding parameters per bond instead of using the global values.
- *       Set version to 2.5.4.
- *
- * 2004/01/14 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Enhance VLAN support:
- *       * Add support for VLAN hardware acceleration capable slaves.
- *       * Add capability to tag self generated packets in ALB/TLB modes.
- *       Set version to 2.6.0.
- * 2004/10/29 - Mitch Williams <mitch.a.williams at intel dot com>
- *      - Fixed bug when unloading module while using 802.3ad.  If
- *        spinlock debugging is turned on, this causes a stack dump.
- *        Solution is to move call to dev_remove_pack outside of the
- *        spinlock.
- *        Set version to 2.6.1.
- * 2005/06/05 - Jay Vosburgh <fubar@us.ibm.com>
- *     - Support for generating gratuitous ARPs in active-backup mode.
- *       Includes support for VLAN tagging all bonding-generated ARPs
- *       as needed.  Set version to 2.6.2.
- * 2005/06/08 - Jason Gabler <jygabler at lbl dot gov>
- *     - alternate hashing policy support for mode 2
- *       * Added kernel parameter "xmit_hash_policy" to allow the selection
- *         of different hashing policies for mode 2.  The original mode 2
- *         policy is the default, now found in xmit_hash_policy_layer2().
- *       * Added xmit_hash_policy_layer34()
- *     - Modified by Jay Vosburgh <fubar@us.ibm.com> to also support mode 4.
- *       Set version to 2.6.3.
- * 2005/09/26 - Jay Vosburgh <fubar@us.ibm.com>
- *     - Removed backwards compatibility for old ifenslaves.  Version 2.6.4.
  */
 
 //#define BONDING_DEBUG 1
@@ -557,6 +97,7 @@ static char *lacp_rate       = NULL;
 static char *xmit_hash_policy = NULL;
 static int arp_interval = BOND_LINK_ARP_INTERV;
 static char *arp_ip_target[BOND_MAX_ARP_TARGETS] = { NULL, };
+struct bond_params bonding_defaults;
 
 module_param(max_bonds, int, 0);
 MODULE_PARM_DESC(max_bonds, "Max number of bonded devices");
@@ -565,17 +106,24 @@ MODULE_PARM_DESC(miimon, "Link check interval in milliseconds");
 module_param(updelay, int, 0);
 MODULE_PARM_DESC(updelay, "Delay before considering link up, in milliseconds");
 module_param(downdelay, int, 0);
-MODULE_PARM_DESC(downdelay, "Delay before considering link down, in milliseconds");
+MODULE_PARM_DESC(downdelay, "Delay before considering link down, "
+                           "in milliseconds");
 module_param(use_carrier, int, 0);
-MODULE_PARM_DESC(use_carrier, "Use netif_carrier_ok (vs MII ioctls) in miimon; 0 for off, 1 for on (default)");
+MODULE_PARM_DESC(use_carrier, "Use netif_carrier_ok (vs MII ioctls) in miimon; "
+                             "0 for off, 1 for on (default)");
 module_param(mode, charp, 0);
-MODULE_PARM_DESC(mode, "Mode of operation : 0 for round robin, 1 for active-backup, 2 for xor");
+MODULE_PARM_DESC(mode, "Mode of operation : 0 for balance-rr, "
+                      "1 for active-backup, 2 for balance-xor, "
+                      "3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, "
+                      "6 for balance-alb");
 module_param(primary, charp, 0);
 MODULE_PARM_DESC(primary, "Primary network device to use");
 module_param(lacp_rate, charp, 0);
-MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner (slow/fast)");
+MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner "
+                           "(slow/fast)");
 module_param(xmit_hash_policy, charp, 0);
-MODULE_PARM_DESC(xmit_hash_policy, "XOR hashing method : 0 for layer 2 (default), 1 for layer 3+4");
+MODULE_PARM_DESC(xmit_hash_policy, "XOR hashing method: 0 for layer 2 (default)"
+                                  ", 1 for layer 3+4");
 module_param(arp_interval, int, 0);
 MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
 module_param_array(arp_ip_target, charp, NULL, 0);
@@ -586,30 +134,27 @@ MODULE_PARM_DESC(arp_ip_target, "arp targets in n.n.n.n form");
 static const char *version =
        DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n";
 
-static LIST_HEAD(bond_dev_list);
+LIST_HEAD(bond_dev_list);
 
 #ifdef CONFIG_PROC_FS
 static struct proc_dir_entry *bond_proc_dir = NULL;
 #endif
 
+extern struct rw_semaphore bonding_rwsem;
 static u32 arp_target[BOND_MAX_ARP_TARGETS] = { 0, } ;
 static int arp_ip_count        = 0;
 static int bond_mode   = BOND_MODE_ROUNDROBIN;
 static int xmit_hashtype= BOND_XMIT_POLICY_LAYER2;
 static int lacp_fast   = 0;
 
-struct bond_parm_tbl {
-       char *modename;
-       int mode;
-};
 
-static struct bond_parm_tbl bond_lacp_tbl[] = {
+struct bond_parm_tbl bond_lacp_tbl[] = {
 {      "slow",         AD_LACP_SLOW},
 {      "fast",         AD_LACP_FAST},
 {      NULL,           -1},
 };
 
-static struct bond_parm_tbl bond_mode_tbl[] = {
+struct bond_parm_tbl bond_mode_tbl[] = {
 {      "balance-rr",           BOND_MODE_ROUNDROBIN},
 {      "active-backup",        BOND_MODE_ACTIVEBACKUP},
 {      "balance-xor",          BOND_MODE_XOR},
@@ -620,7 +165,7 @@ static struct bond_parm_tbl bond_mode_tbl[] = {
 {      NULL,                   -1},
 };
 
-static struct bond_parm_tbl xmit_hashtype_tbl[] = {
+struct bond_parm_tbl xmit_hashtype_tbl[] = {
 {      "layer2",               BOND_XMIT_POLICY_LAYER2},
 {      "layer3+4",             BOND_XMIT_POLICY_LAYER34},
 {      NULL,                   -1},
@@ -628,12 +173,11 @@ static struct bond_parm_tbl xmit_hashtype_tbl[] = {
 
 /*-------------------------- Forward declarations ---------------------------*/
 
-static inline void bond_set_mode_ops(struct bonding *bond, int mode);
 static void bond_send_gratuitous_arp(struct bonding *bond);
 
 /*---------------------------- General routines -----------------------------*/
 
-static const char *bond_mode_name(int mode)
+const char *bond_mode_name(int mode)
 {
        switch (mode) {
        case BOND_MODE_ROUNDROBIN :
@@ -910,7 +454,7 @@ static void bond_vlan_rx_add_vid(struct net_device *bond_dev, uint16_t vid)
        res = bond_add_vlan(bond, vid);
        if (res) {
                printk(KERN_ERR DRV_NAME
-                      ": %s: Failed to add vlan id %d\n",
+                      ": %s: Error: Failed to add vlan id %d\n",
                       bond_dev->name, vid);
        }
 }
@@ -944,7 +488,7 @@ static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)
        res = bond_del_vlan(bond, vid);
        if (res) {
                printk(KERN_ERR DRV_NAME
-                      ": %s: Failed to remove vlan id %d\n",
+                      ": %s: Error: Failed to remove vlan id %d\n",
                       bond_dev->name, vid);
        }
 }
@@ -1449,7 +993,7 @@ static struct slave *bond_find_best_slave(struct bonding *bond)
  *
  * Warning: Caller must hold curr_slave_lock for writing.
  */
-static void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
+void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
 {
        struct slave *old_active = bond->curr_active_slave;
 
@@ -1523,7 +1067,7 @@ static void bond_change_active_slave(struct bonding *bond, struct slave *new_act
  *
  * Warning: Caller must hold curr_slave_lock for writing.
  */
-static void bond_select_active_slave(struct bonding *bond)
+void bond_select_active_slave(struct bonding *bond)
 {
        struct slave *best_slave;
 
@@ -1591,7 +1135,7 @@ static void bond_detach_slave(struct bonding *bond, struct slave *slave)
 
 /*---------------------------------- IOCTL ----------------------------------*/
 
-static int bond_sethwaddr(struct net_device *bond_dev, struct net_device *slave_dev)
+int bond_sethwaddr(struct net_device *bond_dev, struct net_device *slave_dev)
 {
        dprintk("bond_dev=%p\n", bond_dev);
        dprintk("slave_dev=%p\n", slave_dev);
@@ -1631,7 +1175,7 @@ static int bond_compute_features(struct bonding *bond)
 }
 
 /* enslave device <slave> to bond device <master> */
-static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
+int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 {
        struct bonding *bond = bond_dev->priv;
        struct slave *new_slave = NULL;
@@ -1644,8 +1188,8 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
        if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL &&
                slave_dev->do_ioctl == NULL) {
                printk(KERN_WARNING DRV_NAME
-                      ": Warning : no link monitoring support for %s\n",
-                      slave_dev->name);
+                      ": %s: Warning: no link monitoring support for %s\n",
+                      bond_dev->name, slave_dev->name);
        }
 
        /* bond must be initialized by bond_open() before enslaving */
@@ -1666,17 +1210,17 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
                dprintk("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev->name);
                if (!list_empty(&bond->vlan_list)) {
                        printk(KERN_ERR DRV_NAME
-                              ": Error: cannot enslave VLAN "
+                              ": %s: Error: cannot enslave VLAN "
                               "challenged slave %s on VLAN enabled "
-                              "bond %s\n", slave_dev->name,
+                              "bond %s\n", bond_dev->name, slave_dev->name,
                               bond_dev->name);
                        return -EPERM;
                } else {
                        printk(KERN_WARNING DRV_NAME
-                              ": Warning: enslaved VLAN challenged "
+                              ": %s: Warning: enslaved VLAN challenged "
                               "slave %s. Adding VLANs will be blocked as "
                               "long as %s is part of bond %s\n",
-                              slave_dev->name, slave_dev->name,
+                              bond_dev->name, slave_dev->name, slave_dev->name,
                               bond_dev->name);
                        bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
                }
@@ -1706,12 +1250,11 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
 
        if (slave_dev->set_mac_address == NULL) {
                printk(KERN_ERR DRV_NAME
-                      ": Error: The slave device you specified does "
-                      "not support setting the MAC address.\n");
-               printk(KERN_ERR
-                      "Your kernel likely does not support slave devices.\n");
-
-               res = -EOPNOTSUPP;
+                       ": %s: Error: The slave device you specified does "
+                       "not support setting the MAC address. "
+                       "Your kernel likely does not support slave "
+                       "devices.\n", bond_dev->name);
+               res = -EOPNOTSUPP;
                goto err_undo_flags;
        }
 
@@ -1827,21 +1370,21 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
                         * the messages for netif_carrier.
                         */
                        printk(KERN_WARNING DRV_NAME
-                              ": Warning: MII and ETHTOOL support not "
+                              ": %s: Warning: MII and ETHTOOL support not "
                               "available for interface %s, and "
                               "arp_interval/arp_ip_target module parameters "
                               "not specified, thus bonding will not detect "
                               "link failures! see bonding.txt for details.\n",
-                              slave_dev->name);
+                              bond_dev->name, slave_dev->name);
                } else if (link_reporting == -1) {
                        /* unable get link status using mii/ethtool */
                        printk(KERN_WARNING DRV_NAME
-                              ": Warning: can't get link status from "
+                              ": %s: Warning: can't get link status from "
                               "interface %s; the network driver associated "
                               "with this interface does not support MII or "
                               "ETHTOOL link status reporting, thus miimon "
                               "has no effect on this interface.\n",
-                              slave_dev->name);
+                              bond_dev->name, slave_dev->name);
                }
        }
 
@@ -1868,15 +1411,15 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
        if (bond_update_speed_duplex(new_slave) &&
            (new_slave->link != BOND_LINK_DOWN)) {
                printk(KERN_WARNING DRV_NAME
-                      ": Warning: failed to get speed and duplex from %s, "
+                      ": %s: Warning: failed to get speed and duplex from %s, "
                       "assumed to be 100Mb/sec and Full.\n",
-                      new_slave->dev->name);
+                      bond_dev->name, new_slave->dev->name);
 
                if (bond->params.mode == BOND_MODE_8023AD) {
-                       printk(KERN_WARNING
-                              "Operation of 802.3ad mode requires ETHTOOL "
+                       printk(KERN_WARNING DRV_NAME
+                              ": %s: Warning: Operation of 802.3ad mode requires ETHTOOL "
                               "support in base driver for proper aggregator "
-                              "selection.\n");
+                              "selection.\n", bond_dev->name);
                }
        }
 
@@ -1958,6 +1501,10 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
 
        write_unlock_bh(&bond->lock);
 
+       res = bond_create_slave_symlinks(bond_dev, slave_dev);
+       if (res)
+               goto err_unset_master;
+
        printk(KERN_INFO DRV_NAME
               ": %s: enslaving %s as a%s interface with a%s link.\n",
               bond_dev->name, slave_dev->name,
@@ -1999,7 +1546,7 @@ err_undo_flags:
  *   for Bonded connections:
  *     The first up interface should be left on and all others downed.
  */
-static int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
+int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
 {
        struct bonding *bond = bond_dev->priv;
        struct slave *slave, *oldcurrent;
@@ -2010,7 +1557,7 @@ static int bond_release(struct net_device *bond_dev, struct net_device *slave_de
        if (!(slave_dev->flags & IFF_SLAVE) ||
            (slave_dev->master != bond_dev)) {
                printk(KERN_ERR DRV_NAME
-                      ": Error: %s: cannot release %s.\n",
+                      ": %s: Error: cannot release %s.\n",
                       bond_dev->name, slave_dev->name);
                return -EINVAL;
        }
@@ -2031,11 +1578,12 @@ static int bond_release(struct net_device *bond_dev, struct net_device *slave_de
                                 ETH_ALEN);
        if (!mac_addr_differ && (bond->slave_cnt > 1)) {
                printk(KERN_WARNING DRV_NAME
-                      ": Warning: the permanent HWaddr of %s "
+                      ": %s: Warning: the permanent HWaddr of %s "
                       "- %02X:%02X:%02X:%02X:%02X:%02X - is "
                       "still in use by %s. Set the HWaddr of "
                       "%s to a different address to avoid "
                       "conflicts.\n",
+                      bond_dev->name,
                       slave_dev->name,
                       slave->perm_hwaddr[0],
                       slave->perm_hwaddr[1],
@@ -2111,24 +1659,28 @@ static int bond_release(struct net_device *bond_dev, struct net_device *slave_de
                        bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
                } else {
                        printk(KERN_WARNING DRV_NAME
-                              ": Warning: clearing HW address of %s while it "
+                              ": %s: Warning: clearing HW address of %s while it "
                               "still has VLANs.\n",
-                              bond_dev->name);
+                              bond_dev->name, bond_dev->name);
                        printk(KERN_WARNING DRV_NAME
-                              ": When re-adding slaves, make sure the bond's "
-                              "HW address matches its VLANs'.\n");
+                              ": %s: When re-adding slaves, make sure the bond's "
+                              "HW address matches its VLANs'.\n",
+                              bond_dev->name);
                }
        } else if ((bond_dev->features & NETIF_F_VLAN_CHALLENGED) &&
                   !bond_has_challenged_slaves(bond)) {
                printk(KERN_INFO DRV_NAME
-                      ": last VLAN challenged slave %s "
+                      ": %s: last VLAN challenged slave %s "
                       "left bond %s. VLAN blocking is removed\n",
-                      slave_dev->name, bond_dev->name);
+                      bond_dev->name, slave_dev->name, bond_dev->name);
                bond_dev->features &= ~NETIF_F_VLAN_CHALLENGED;
        }
 
        write_unlock_bh(&bond->lock);
 
+       /* must do this from outside any spinlocks */
+       bond_destroy_slave_symlinks(bond_dev, slave_dev);
+
        bond_del_vlans_from_slave(bond, slave_dev);
 
        /* If the mode USES_PRIMARY, then we should only remove its
@@ -2220,6 +1772,7 @@ static int bond_release_all(struct net_device *bond_dev)
                 */
                write_unlock_bh(&bond->lock);
 
+               bond_destroy_slave_symlinks(bond_dev, slave_dev);
                bond_del_vlans_from_slave(bond, slave_dev);
 
                /* If the mode USES_PRIMARY, then we should only remove its
@@ -2274,12 +1827,13 @@ static int bond_release_all(struct net_device *bond_dev)
                bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
        } else {
                printk(KERN_WARNING DRV_NAME
-                      ": Warning: clearing HW address of %s while it "
+                      ": %s: Warning: clearing HW address of %s while it "
                       "still has VLANs.\n",
-                      bond_dev->name);
+                      bond_dev->name, bond_dev->name);
                printk(KERN_WARNING DRV_NAME
-                      ": When re-adding slaves, make sure the bond's "
-                      "HW address matches its VLANs'.\n");
+                      ": %s: When re-adding slaves, make sure the bond's "
+                      "HW address matches its VLANs'.\n",
+                      bond_dev->name);
        }
 
        printk(KERN_INFO DRV_NAME
@@ -2397,7 +1951,7 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in
 /*-------------------------------- Monitoring -------------------------------*/
 
 /* this function is called regularly to monitor each slave's link. */
-static void bond_mii_monitor(struct net_device *bond_dev)
+void bond_mii_monitor(struct net_device *bond_dev)
 {
        struct bonding *bond = bond_dev->priv;
        struct slave *slave, *oldcurrent;
@@ -2596,8 +2150,11 @@ static void bond_mii_monitor(struct net_device *bond_dev)
                        break;
                default:
                        /* Should not happen */
-                       printk(KERN_ERR "bonding: Error: %s  Illegal value (link=%d)\n",
-                              slave->dev->name, slave->link);
+                       printk(KERN_ERR DRV_NAME
+                              ": %s: Error: %s Illegal value (link=%d)\n",
+                              bond_dev->name,
+                              slave->dev->name,
+                              slave->link);
                        goto out;
                } /* end of switch (slave->link) */
 
@@ -2721,7 +2278,9 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
        struct flowi fl;
        struct rtable *rt;
 
-       for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) {
+       for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
+               if (!targets[i])
+                       continue;
                dprintk("basa: target %x\n", targets[i]);
                if (list_empty(&bond->vlan_list)) {
                        dprintk("basa: empty vlan: arp_send\n");
@@ -2825,7 +2384,7 @@ static void bond_send_gratuitous_arp(struct bonding *bond)
  * arp is transmitted to generate traffic. see activebackup_arp_monitor for
  * arp monitoring in active backup mode.
  */
-static void bond_loadbalance_arp_mon(struct net_device *bond_dev)
+void bond_loadbalance_arp_mon(struct net_device *bond_dev)
 {
        struct bonding *bond = bond_dev->priv;
        struct slave *slave, *oldcurrent;
@@ -2963,7 +2522,7 @@ out:
  * may have received.
  * see loadbalance_arp_monitor for arp monitoring in load balancing mode
  */
-static void bond_activebackup_arp_mon(struct net_device *bond_dev)
+void bond_activebackup_arp_mon(struct net_device *bond_dev)
 {
        struct bonding *bond = bond_dev->priv;
        struct slave *slave;
@@ -3249,6 +2808,8 @@ static void bond_info_show_master(struct seq_file *seq)
 {
        struct bonding *bond = seq->private;
        struct slave *curr;
+       int i;
+       u32 target;
 
        read_lock(&bond->curr_slave_lock);
        curr = bond->curr_active_slave;
@@ -3257,10 +2818,17 @@ static void bond_info_show_master(struct seq_file *seq)
        seq_printf(seq, "Bonding Mode: %s\n",
                   bond_mode_name(bond->params.mode));
 
+       if (bond->params.mode == BOND_MODE_XOR ||
+               bond->params.mode == BOND_MODE_8023AD) {
+               seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
+                       xmit_hashtype_tbl[bond->params.xmit_policy].modename,
+                       bond->params.xmit_policy);
+       }
+
        if (USES_PRIMARY(bond->params.mode)) {
                seq_printf(seq, "Primary Slave: %s\n",
-                          (bond->params.primary[0]) ?
-                               bond->params.primary : "None");
+                          (bond->primary_slave) ?
+                          bond->primary_slave->dev->name : "None");
 
                seq_printf(seq, "Currently Active Slave: %s\n",
                           (curr) ? curr->dev->name : "None");
@@ -3273,6 +2841,27 @@ static void bond_info_show_master(struct seq_file *seq)
        seq_printf(seq, "Down Delay (ms): %d\n",
                   bond->params.downdelay * bond->params.miimon);
 
+
+       /* ARP information */
+       if(bond->params.arp_interval > 0) {
+               int printed=0;
+               seq_printf(seq, "ARP Polling Interval (ms): %d\n",
+                               bond->params.arp_interval);
+
+               seq_printf(seq, "ARP IP target/s (n.n.n.n form):");
+
+               for(i = 0; (i < BOND_MAX_ARP_TARGETS) ;i++) {
+                       if (!bond->params.arp_targets[i])
+                               continue;
+                       if (printed)
+                               seq_printf(seq, ",");
+                       target = ntohl(bond->params.arp_targets[i]);
+                       seq_printf(seq, " %d.%d.%d.%d", HIPQUAD(target));
+                       printed = 1;
+               }
+               seq_printf(seq, "\n");
+       }
+
        if (bond->params.mode == BOND_MODE_8023AD) {
                struct ad_info ad_info;
 
@@ -3478,7 +3067,10 @@ static int bond_event_changename(struct bonding *bond)
        bond_remove_proc_entry(bond);
        bond_create_proc_entry(bond);
 #endif
-
+       down_write(&(bonding_rwsem));
+        bond_destroy_sysfs_entry(bond);
+        bond_create_sysfs_entry(bond);
+       up_write(&(bonding_rwsem));
        return NOTIFY_DONE;
 }
 
@@ -3955,6 +3547,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
                return -EPERM;
        }
 
+       down_write(&(bonding_rwsem));
        slave_dev = dev_get_by_name(ifr->ifr_slave);
 
        dprintk("slave_dev=%p: \n", slave_dev);
@@ -3987,6 +3580,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
                dev_put(slave_dev);
        }
 
+       up_write(&(bonding_rwsem));
        return res;
 }
 
@@ -4071,6 +3665,7 @@ static int bond_change_mtu(struct net_device *bond_dev, int new_mtu)
        bond_for_each_slave(bond, slave, i) {
                dprintk("s %p s->p %p c_m %p\n", slave,
                        slave->prev, slave->dev->change_mtu);
+
                res = dev_set_mtu(slave->dev, new_mtu);
 
                if (res) {
@@ -4397,8 +3992,9 @@ static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev)
                                struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
                                if (!skb2) {
                                        printk(KERN_ERR DRV_NAME
-                                              ": Error: bond_xmit_broadcast(): "
-                                              "skb_clone() failed\n");
+                                              ": %s: Error: bond_xmit_broadcast(): "
+                                              "skb_clone() failed\n",
+                                              bond_dev->name);
                                        continue;
                                }
 
@@ -4431,7 +4027,7 @@ out:
 /*
  * set bond mode specific net device operations
  */
-static inline void bond_set_mode_ops(struct bonding *bond, int mode)
+void bond_set_mode_ops(struct bonding *bond, int mode)
 {
        struct net_device *bond_dev = bond->dev;
 
@@ -4467,7 +4063,8 @@ static inline void bond_set_mode_ops(struct bonding *bond, int mode)
        default:
                /* Should never happen, mode already checked */
                printk(KERN_ERR DRV_NAME
-                      ": Error: Unknown bonding mode %d\n",
+                      ": %s: Error: Unknown bonding mode %d\n",
+                      bond_dev->name,
                       mode);
                break;
        }
@@ -4491,7 +4088,7 @@ static struct ethtool_ops bond_ethtool_ops = {
  * Does not allocate but creates a /proc entry.
  * Allowed to fail.
  */
-static int __init bond_init(struct net_device *bond_dev, struct bond_params *params)
+static int bond_init(struct net_device *bond_dev, struct bond_params *params)
 {
        struct bonding *bond = bond_dev->priv;
 
@@ -4565,7 +4162,7 @@ static int __init bond_init(struct net_device *bond_dev, struct bond_params *par
 /* De-initialize device specific data.
  * Caller must hold rtnl_lock.
  */
-static inline void bond_deinit(struct net_device *bond_dev)
+void bond_deinit(struct net_device *bond_dev)
 {
        struct bonding *bond = bond_dev->priv;
 
@@ -4601,7 +4198,7 @@ static void bond_free_all(void)
  * Convert string input module parms.  Accept either the
  * number of the mode or its string name.
  */
-static inline int bond_parse_parm(char *mode_arg, struct bond_parm_tbl *tbl)
+int bond_parse_parm(char *mode_arg, struct bond_parm_tbl *tbl)
 {
        int i;
 
@@ -4670,7 +4267,7 @@ static int bond_check_params(struct bond_params *params)
        if (max_bonds < 1 || max_bonds > INT_MAX) {
                printk(KERN_WARNING DRV_NAME
                       ": Warning: max_bonds (%d) not in range %d-%d, so it "
-                      "was reset to BOND_DEFAULT_MAX_BONDS (%d)",
+                      "was reset to BOND_DEFAULT_MAX_BONDS (%d)\n",
                       max_bonds, 1, INT_MAX, BOND_DEFAULT_MAX_BONDS);
                max_bonds = BOND_DEFAULT_MAX_BONDS;
        }
@@ -4881,81 +4478,96 @@ static int bond_check_params(struct bond_params *params)
        return 0;
 }
 
+/* Create a new bond based on the specified name and bonding parameters.
+ * Caller must NOT hold rtnl_lock; we need to release it here before we
+ * set up our sysfs entries.
+ */
+int bond_create(char *name, struct bond_params *params, struct bonding **newbond)
+{
+       struct net_device *bond_dev;
+       int res;
+
+       rtnl_lock();
+       bond_dev = alloc_netdev(sizeof(struct bonding), name, ether_setup);
+       if (!bond_dev) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: eek! can't alloc netdev!\n",
+                      name);
+               res = -ENOMEM;
+               goto out_rtnl;
+       }
+
+       /* bond_init() must be called after dev_alloc_name() (for the
+        * /proc files), but before register_netdevice(), because we
+        * need to set function pointers.
+        */
+
+       res = bond_init(bond_dev, params);
+       if (res < 0) {
+               goto out_netdev;
+       }
+
+       SET_MODULE_OWNER(bond_dev);
+
+       res = register_netdevice(bond_dev);
+       if (res < 0) {
+               goto out_bond;
+       }
+       if (newbond)
+               *newbond = bond_dev->priv;
+
+       rtnl_unlock(); /* allows sysfs registration of net device */
+       res = bond_create_sysfs_entry(bond_dev->priv);
+       goto done;
+out_bond:
+       bond_deinit(bond_dev);
+out_netdev:
+       free_netdev(bond_dev);
+out_rtnl:
+       rtnl_unlock();
+done:
+       return res;
+}
+
 static int __init bonding_init(void)
 {
-       struct bond_params params;
        int i;
        int res;
+       char new_bond_name[8];  /* Enough room for 999 bonds at init. */
 
        printk(KERN_INFO "%s", version);
 
-       res = bond_check_params(&params);
+       res = bond_check_params(&bonding_defaults);
        if (res) {
-               return res;
+               goto out;
        }
 
-       rtnl_lock();
-
 #ifdef CONFIG_PROC_FS
        bond_create_proc_dir();
 #endif
-
        for (i = 0; i < max_bonds; i++) {
-               struct net_device *bond_dev;
-
-               bond_dev = alloc_netdev(sizeof(struct bonding), "", ether_setup);
-               if (!bond_dev) {
-                       res = -ENOMEM;
-                       goto out_err;
-               }
-
-               res = dev_alloc_name(bond_dev, "bond%d");
-               if (res < 0) {
-                       free_netdev(bond_dev);
-                       goto out_err;
-               }
-
-               /* bond_init() must be called after dev_alloc_name() (for the
-                * /proc files), but before register_netdevice(), because we
-                * need to set function pointers.
-                */
-               res = bond_init(bond_dev, &params);
-               if (res < 0) {
-                       free_netdev(bond_dev);
-                       goto out_err;
-               }
-
-               SET_MODULE_OWNER(bond_dev);
-
-               res = register_netdevice(bond_dev);
-               if (res < 0) {
-                       bond_deinit(bond_dev);
-                       free_netdev(bond_dev);
-                       goto out_err;
-               }
+               sprintf(new_bond_name, "bond%d",i);
+               res = bond_create(new_bond_name,&bonding_defaults, NULL);
+               if (res)
+                       goto err;
        }
 
-       rtnl_unlock();
+       res = bond_create_sysfs();
+       if (res)
+               goto err;
+
        register_netdevice_notifier(&bond_netdev_notifier);
        register_inetaddr_notifier(&bond_inetaddr_notifier);
 
-       return 0;
-
-out_err:
-       /*
-        * rtnl_unlock() will run netdev_run_todo(), putting the
-        * thus-far-registered bonding devices into a state which
-        * unregigister_netdevice() will accept
-        */
-       rtnl_unlock();
+       goto out;
+err:
        rtnl_lock();
-
-       /* free and unregister all bonds that were successfully added */
        bond_free_all();
-
+       bond_destroy_sysfs();
        rtnl_unlock();
-
+out:
        return res;
+
 }
 
 static void __exit bonding_exit(void)
@@ -4965,6 +4577,7 @@ static void __exit bonding_exit(void)
 
        rtnl_lock();
        bond_free_all();
+       bond_destroy_sysfs();
        rtnl_unlock();
 }
 
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
new file mode 100644 (file)
index 0000000..32d13da
--- /dev/null
@@ -0,0 +1,1358 @@
+
+/*
+ * Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
+ *
+ * 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.
+ *
+ * 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.,
+ * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The full GNU General Public License is included in this distribution in the
+ * file called LICENSE.
+ *
+ */
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/device.h>
+#include <linux/sysdev.h>
+#include <linux/fs.h>
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/netdevice.h>
+#include <linux/inetdevice.h>
+#include <linux/in.h>
+#include <linux/sysfs.h>
+#include <linux/string.h>
+#include <linux/ctype.h>
+#include <linux/inet.h>
+#include <linux/rtnetlink.h>
+
+/* #define BONDING_DEBUG 1 */
+#include "bonding.h"
+#define to_class_dev(obj) container_of(obj,struct class_device,kobj)
+#define to_net_dev(class) container_of(class, struct net_device, class_dev)
+#define to_bond(cd)    ((struct bonding *)(to_net_dev(cd)->priv))
+
+/*---------------------------- Declarations -------------------------------*/
+
+
+extern struct list_head bond_dev_list;
+extern struct bond_params bonding_defaults;
+extern struct bond_parm_tbl bond_mode_tbl[];
+extern struct bond_parm_tbl bond_lacp_tbl[];
+extern struct bond_parm_tbl xmit_hashtype_tbl[];
+
+static int expected_refcount = -1;
+static struct class *netdev_class;
+/*--------------------------- Data Structures -----------------------------*/
+
+/* Bonding sysfs lock.  Why can't we just use the subsytem lock?
+ * Because kobject_register tries to acquire the subsystem lock.  If
+ * we already hold the lock (which we would if the user was creating
+ * a new bond through the sysfs interface), we deadlock.
+ * This lock is only needed when deleting a bond - we need to make sure
+ * that we don't collide with an ongoing ioctl.
+ */
+
+struct rw_semaphore bonding_rwsem;
+
+
+
+
+/*------------------------------ Functions --------------------------------*/
+
+/*
+ * "show" function for the bond_masters attribute.
+ * The class parameter is ignored.
+ */
+static ssize_t bonding_show_bonds(struct class *cls, char *buffer)
+{
+       int res = 0;
+       struct bonding *bond;
+
+       down_read(&(bonding_rwsem));
+
+       list_for_each_entry(bond, &bond_dev_list, bond_list) {
+               if (res > (PAGE_SIZE - IFNAMSIZ)) {
+                       /* not enough space for another interface name */
+                       if ((PAGE_SIZE - res) > 10)
+                               res = PAGE_SIZE - 10;
+                       res += sprintf(buffer + res, "++more++");
+                       break;
+               }
+               res += sprintf(buffer + res, "%s ",
+                              bond->dev->name);
+       }
+       res += sprintf(buffer + res, "\n");
+       res++;
+       up_read(&(bonding_rwsem));
+       return res;
+}
+
+/*
+ * "store" function for the bond_masters attribute.  This is what
+ * creates and deletes entire bonds.
+ *
+ * The class parameter is ignored.
+ *
+ */
+
+static ssize_t bonding_store_bonds(struct class *cls, const char *buffer, size_t count)
+{
+       char command[IFNAMSIZ + 1] = {0, };
+       char *ifname;
+       int res = count;
+       struct bonding *bond;
+       struct bonding *nxt;
+
+       down_write(&(bonding_rwsem));
+       sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
+       ifname = command + 1;
+       if ((strlen(command) <= 1) ||
+           !dev_valid_name(ifname))
+               goto err_no_cmd;
+
+       if (command[0] == '+') {
+
+               /* Check to see if the bond already exists. */
+               list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list)
+                       if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) {
+                               printk(KERN_ERR DRV_NAME
+                                       ": cannot add bond %s; it already exists\n",
+                                       ifname);
+                               res = -EPERM;
+                               goto out;
+                       }
+
+               printk(KERN_INFO DRV_NAME
+                       ": %s is being created...\n", ifname);
+               if (bond_create(ifname, &bonding_defaults, &bond)) {
+                       printk(KERN_INFO DRV_NAME
+                       ": %s interface already exists. Bond creation failed.\n",
+                       ifname);
+                       res = -EPERM;
+               }
+               goto out;
+       }
+
+       if (command[0] == '-') {
+               list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list)
+                       if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) {
+                               rtnl_lock();
+                               /* check the ref count on the bond's kobject.
+                                * If it's > expected, then there's a file open,
+                                * and we have to fail.
+                                */
+                               if (atomic_read(&bond->dev->class_dev.kobj.kref.refcount)
+                                                       > expected_refcount){
+                                       rtnl_unlock();
+                                       printk(KERN_INFO DRV_NAME
+                                               ": Unable remove bond %s due to open references.\n",
+                                               ifname);
+                                       res = -EPERM;
+                                       goto out;
+                               }
+                               printk(KERN_INFO DRV_NAME
+                                       ": %s is being deleted...\n",
+                                       bond->dev->name);
+                               unregister_netdevice(bond->dev);
+                               bond_deinit(bond->dev);
+                               bond_destroy_sysfs_entry(bond);
+                               rtnl_unlock();
+                               goto out;
+                       }
+
+               printk(KERN_ERR DRV_NAME
+                       ": unable to delete non-existent bond %s\n", ifname);
+               res = -ENODEV;
+               goto out;
+       }
+
+err_no_cmd:
+       printk(KERN_ERR DRV_NAME
+               ": no command found in bonding_masters. Use +ifname or -ifname.\n");
+       res = -EPERM;
+
+       /* Always return either count or an error.  If you return 0, you'll
+        * get called forever, which is bad.
+        */
+out:
+       up_write(&(bonding_rwsem));
+       return res;
+}
+/* class attribute for bond_masters file.  This ends up in /sys/class/net */
+static CLASS_ATTR(bonding_masters,  S_IWUSR | S_IRUGO,
+                 bonding_show_bonds, bonding_store_bonds);
+
+int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave)
+{
+       char linkname[IFNAMSIZ+7];
+       int ret = 0;
+
+       /* first, create a link from the slave back to the master */
+       ret = sysfs_create_link(&(slave->class_dev.kobj), &(master->class_dev.kobj),
+                               "master");
+       if (ret)
+               return ret;
+       /* next, create a link from the master to the slave */
+       sprintf(linkname,"slave_%s",slave->name);
+       ret = sysfs_create_link(&(master->class_dev.kobj), &(slave->class_dev.kobj),
+                               linkname);
+       return ret;
+
+}
+
+void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave)
+{
+       char linkname[IFNAMSIZ+7];
+
+       sysfs_remove_link(&(slave->class_dev.kobj), "master");
+       sprintf(linkname,"slave_%s",slave->name);
+       sysfs_remove_link(&(master->class_dev.kobj), linkname);
+}
+
+
+/*
+ * Show the slaves in the current bond.
+ */
+static ssize_t bonding_show_slaves(struct class_device *cd, char *buf)
+{
+       struct slave *slave;
+       int i, res = 0;
+       struct bonding *bond = to_bond(cd);
+
+       read_lock_bh(&bond->lock);
+       bond_for_each_slave(bond, slave, i) {
+               if (res > (PAGE_SIZE - IFNAMSIZ)) {
+                       /* not enough space for another interface name */
+                       if ((PAGE_SIZE - res) > 10)
+                               res = PAGE_SIZE - 10;
+                       res += sprintf(buf + res, "++more++");
+                       break;
+               }
+               res += sprintf(buf + res, "%s ", slave->dev->name);
+       }
+       read_unlock_bh(&bond->lock);
+       res += sprintf(buf + res, "\n");
+       res++;
+       return res;
+}
+
+/*
+ * Set the slaves in the current bond.  The bond interface must be
+ * up for this to succeed.
+ * This function is largely the same flow as bonding_update_bonds().
+ */
+static ssize_t bonding_store_slaves(struct class_device *cd, const char *buffer, size_t count)
+{
+       char command[IFNAMSIZ + 1] = { 0, };
+       char *ifname;
+       int i, res, found, ret = count;
+       struct slave *slave;
+       struct net_device *dev = 0;
+       struct bonding *bond = to_bond(cd);
+
+       /* Quick sanity check -- is the bond interface up? */
+       if (!(bond->dev->flags & IFF_UP)) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Unable to update slaves because interface is down.\n",
+                      bond->dev->name);
+               ret = -EPERM;
+               goto out;
+       }
+
+       /* Note:  We can't hold bond->lock here, as bond_create grabs it. */
+
+       sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
+       ifname = command + 1;
+       if ((strlen(command) <= 1) ||
+           !dev_valid_name(ifname))
+               goto err_no_cmd;
+
+       if (command[0] == '+') {
+
+               /* Got a slave name in ifname.  Is it already in the list? */
+               found = 0;
+               read_lock_bh(&bond->lock);
+               bond_for_each_slave(bond, slave, i)
+                       if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
+                               printk(KERN_ERR DRV_NAME
+                                      ": %s: Interface %s is already enslaved!\n",
+                                      bond->dev->name, ifname);
+                               ret = -EPERM;
+                               read_unlock_bh(&bond->lock);
+                               goto out;
+                       }
+
+               read_unlock_bh(&bond->lock);
+               printk(KERN_INFO DRV_NAME ": %s: Adding slave %s.\n",
+                      bond->dev->name, ifname);
+               dev = dev_get_by_name(ifname);
+               if (!dev) {
+                       printk(KERN_INFO DRV_NAME
+                              ": %s: Interface %s does not exist!\n",
+                              bond->dev->name, ifname);
+                       ret = -EPERM;
+                       goto out;
+               }
+               else
+                       dev_put(dev);
+
+               if (dev->flags & IFF_UP) {
+                       printk(KERN_ERR DRV_NAME
+                              ": %s: Error: Unable to enslave %s "
+                              "because it is already up.\n",
+                              bond->dev->name, dev->name);
+                       ret = -EPERM;
+                       goto out;
+               }
+               /* If this is the first slave, then we need to set
+                  the master's hardware address to be the same as the
+                  slave's. */
+               if (!(*((u32 *) & (bond->dev->dev_addr[0])))) {
+                       memcpy(bond->dev->dev_addr, dev->dev_addr,
+                              dev->addr_len);
+               }
+
+               /* Set the slave's MTU to match the bond */
+               if (dev->mtu != bond->dev->mtu) {
+                       if (dev->change_mtu) {
+                               res = dev->change_mtu(dev,
+                                                     bond->dev->mtu);
+                               if (res) {
+                                       ret = res;
+                                       goto out;
+                               }
+                       } else {
+                               dev->mtu = bond->dev->mtu;
+                       }
+               }
+               rtnl_lock();
+               res = bond_enslave(bond->dev, dev);
+               rtnl_unlock();
+               if (res) {
+                       ret = res;
+               }
+               goto out;
+       }
+
+       if (command[0] == '-') {
+               dev = NULL;
+               bond_for_each_slave(bond, slave, i)
+                       if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
+                               dev = slave->dev;
+                               break;
+                       }
+               if (dev) {
+                       printk(KERN_INFO DRV_NAME ": %s: Removing slave %s\n",
+                               bond->dev->name, dev->name);
+                       rtnl_lock();
+                       res = bond_release(bond->dev, dev);
+                       rtnl_unlock();
+                       if (res) {
+                               ret = res;
+                               goto out;
+                       }
+                       /* set the slave MTU to the default */
+                       if (dev->change_mtu) {
+                               dev->change_mtu(dev, 1500);
+                       } else {
+                               dev->mtu = 1500;
+                       }
+               }
+               else {
+                       printk(KERN_ERR DRV_NAME ": unable to remove non-existent slave %s for bond %s.\n",
+                               ifname, bond->dev->name);
+                       ret = -ENODEV;
+               }
+               goto out;
+       }
+
+err_no_cmd:
+       printk(KERN_ERR DRV_NAME ": no command found in slaves file for bond %s. Use +ifname or -ifname.\n", bond->dev->name);
+       ret = -EPERM;
+
+out:
+       return ret;
+}
+
+static CLASS_DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, bonding_store_slaves);
+
+/*
+ * Show and set the bonding mode.  The bond interface must be down to
+ * change the mode.
+ */
+static ssize_t bonding_show_mode(struct class_device *cd, char *buf)
+{
+       struct bonding *bond = to_bond(cd);
+
+       return sprintf(buf, "%s %d\n",
+                       bond_mode_tbl[bond->params.mode].modename,
+                       bond->params.mode) + 1;
+}
+
+static ssize_t bonding_store_mode(struct class_device *cd, const char *buf, size_t count)
+{
+       int new_value, ret = count;
+       struct bonding *bond = to_bond(cd);
+
+       if (bond->dev->flags & IFF_UP) {
+               printk(KERN_ERR DRV_NAME
+                      ": unable to update mode of %s because interface is up.\n",
+                      bond->dev->name);
+               ret = -EPERM;
+               goto out;
+       }
+
+       new_value = bond_parse_parm((char *)buf, bond_mode_tbl);
+       if (new_value < 0)  {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Ignoring invalid mode value %.*s.\n",
+                      bond->dev->name,
+                      (int)strlen(buf) - 1, buf);
+               ret = -EINVAL;
+               goto out;
+       } else {
+               bond->params.mode = new_value;
+               bond_set_mode_ops(bond, bond->params.mode);
+               printk(KERN_INFO DRV_NAME ": %s: setting mode to %s (%d).\n",
+                       bond->dev->name, bond_mode_tbl[new_value].modename, new_value);
+       }
+out:
+       return ret;
+}
+static CLASS_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, bonding_show_mode, bonding_store_mode);
+
+/*
+ * Show and set the bonding transmit hash method.  The bond interface must be down to
+ * change the xmit hash policy.
+ */
+static ssize_t bonding_show_xmit_hash(struct class_device *cd, char *buf)
+{
+       int count;
+       struct bonding *bond = to_bond(cd);
+
+       if ((bond->params.mode != BOND_MODE_XOR) &&
+           (bond->params.mode != BOND_MODE_8023AD)) {
+               // Not Applicable
+               count = sprintf(buf, "NA\n") + 1;
+       } else {
+               count = sprintf(buf, "%s %d\n",
+                       xmit_hashtype_tbl[bond->params.xmit_policy].modename,
+                       bond->params.xmit_policy) + 1;
+       }
+
+       return count;
+}
+
+static ssize_t bonding_store_xmit_hash(struct class_device *cd, const char *buf, size_t count)
+{
+       int new_value, ret = count;
+       struct bonding *bond = to_bond(cd);
+
+       if (bond->dev->flags & IFF_UP) {
+               printk(KERN_ERR DRV_NAME
+                      "%s: Interface is up. Unable to update xmit policy.\n",
+                      bond->dev->name);
+               ret = -EPERM;
+               goto out;
+       }
+
+       if ((bond->params.mode != BOND_MODE_XOR) &&
+           (bond->params.mode != BOND_MODE_8023AD)) {
+               printk(KERN_ERR DRV_NAME
+                      "%s: Transmit hash policy is irrelevant in this mode.\n",
+                      bond->dev->name);
+               ret = -EPERM;
+               goto out;
+       }
+
+       new_value = bond_parse_parm((char *)buf, xmit_hashtype_tbl);
+       if (new_value < 0)  {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Ignoring invalid xmit hash policy value %.*s.\n",
+                      bond->dev->name,
+                      (int)strlen(buf) - 1, buf);
+               ret = -EINVAL;
+               goto out;
+       } else {
+               bond->params.xmit_policy = new_value;
+               bond_set_mode_ops(bond, bond->params.mode);
+               printk(KERN_INFO DRV_NAME ": %s: setting xmit hash policy to %s (%d).\n",
+                       bond->dev->name, xmit_hashtype_tbl[new_value].modename, new_value);
+       }
+out:
+       return ret;
+}
+static CLASS_DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, bonding_show_xmit_hash, bonding_store_xmit_hash);
+
+/*
+ * Show and set the arp timer interval.  There are two tricky bits
+ * here.  First, if ARP monitoring is activated, then we must disable
+ * MII monitoring.  Second, if the ARP timer isn't running, we must
+ * start it.
+ */
+static ssize_t bonding_show_arp_interval(struct class_device *cd, char *buf)
+{
+       struct bonding *bond = to_bond(cd);
+
+       return sprintf(buf, "%d\n", bond->params.arp_interval) + 1;
+}
+
+static ssize_t bonding_store_arp_interval(struct class_device *cd, const char *buf, size_t count)
+{
+       int new_value, ret = count;
+       struct bonding *bond = to_bond(cd);
+
+       if (sscanf(buf, "%d", &new_value) != 1) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: no arp_interval value specified.\n",
+                      bond->dev->name);
+               ret = -EINVAL;
+               goto out;
+       }
+       if (new_value < 0) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
+                      bond->dev->name, new_value, INT_MAX);
+               ret = -EINVAL;
+               goto out;
+       }
+
+       printk(KERN_INFO DRV_NAME
+              ": %s: Setting ARP monitoring interval to %d.\n",
+              bond->dev->name, new_value);
+       bond->params.arp_interval = new_value;
+       if (bond->params.miimon) {
+               printk(KERN_INFO DRV_NAME
+                      ": %s: ARP monitoring cannot be used with MII monitoring. "
+                      "%s Disabling MII monitoring.\n",
+                      bond->dev->name, bond->dev->name);
+               bond->params.miimon = 0;
+               /* Kill MII timer, else it brings bond's link down */
+               if (bond->arp_timer.function) {
+                       printk(KERN_INFO DRV_NAME
+                       ": %s: Kill MII timer, else it brings bond's link down...\n",
+                      bond->dev->name);
+                       del_timer_sync(&bond->mii_timer);
+               }
+       }
+       if (!bond->params.arp_targets[0]) {
+               printk(KERN_INFO DRV_NAME
+                      ": %s: ARP monitoring has been set up, "
+                      "but no ARP targets have been specified.\n",
+                      bond->dev->name);
+       }
+       if (bond->dev->flags & IFF_UP) {
+               /* If the interface is up, we may need to fire off
+                * the ARP timer.  If the interface is down, the
+                * timer will get fired off when the open function
+                * is called.
+                */
+               if (bond->arp_timer.function) {
+                       /* The timer's already set up, so fire it off */
+                       mod_timer(&bond->arp_timer, jiffies + 1);
+               } else {
+                       /* Set up the timer. */
+                       init_timer(&bond->arp_timer);
+                       bond->arp_timer.expires = jiffies + 1;
+                       bond->arp_timer.data =
+                               (unsigned long) bond->dev;
+                       if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
+                               bond->arp_timer.function =
+                                       (void *)
+                                       &bond_activebackup_arp_mon;
+                       } else {
+                               bond->arp_timer.function =
+                                       (void *)
+                                       &bond_loadbalance_arp_mon;
+                       }
+                       add_timer(&bond->arp_timer);
+               }
+       }
+
+out:
+       return ret;
+}
+static CLASS_DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR , bonding_show_arp_interval, bonding_store_arp_interval);
+
+/*
+ * Show and set the arp targets.
+ */
+static ssize_t bonding_show_arp_targets(struct class_device *cd, char *buf)
+{
+       int i, res = 0;
+       struct bonding *bond = to_bond(cd);
+
+       for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
+               if (bond->params.arp_targets[i])
+                       res += sprintf(buf + res, "%u.%u.%u.%u ",
+                              NIPQUAD(bond->params.arp_targets[i]));
+       }
+       if (res)
+               res--;  /* eat the leftover space */
+       res += sprintf(buf + res, "\n");
+       res++;
+       return res;
+}
+
+static ssize_t bonding_store_arp_targets(struct class_device *cd, const char *buf, size_t count)
+{
+       u32 newtarget;
+       int i = 0, done = 0, ret = count;
+       struct bonding *bond = to_bond(cd);
+       u32 *targets;
+
+       targets = bond->params.arp_targets;
+       newtarget = in_aton(buf + 1);
+       /* look for adds */
+       if (buf[0] == '+') {
+               if ((newtarget == 0) || (newtarget == INADDR_BROADCAST)) {
+                       printk(KERN_ERR DRV_NAME
+                              ": %s: invalid ARP target %u.%u.%u.%u specified for addition\n",
+                              bond->dev->name, NIPQUAD(newtarget));
+                       ret = -EINVAL;
+                       goto out;
+               }
+               /* look for an empty slot to put the target in, and check for dupes */
+               for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
+                       if (targets[i] == newtarget) { /* duplicate */
+                               printk(KERN_ERR DRV_NAME
+                                      ": %s: ARP target %u.%u.%u.%u is already present\n",
+                                      bond->dev->name, NIPQUAD(newtarget));
+                               if (done)
+                                       targets[i] = 0;
+                               ret = -EINVAL;
+                               goto out;
+                       }
+                       if (targets[i] == 0 && !done) {
+                               printk(KERN_INFO DRV_NAME
+                                      ": %s: adding ARP target %d.%d.%d.%d.\n",
+                                      bond->dev->name, NIPQUAD(newtarget));
+                               done = 1;
+                               targets[i] = newtarget;
+                       }
+               }
+               if (!done) {
+                       printk(KERN_ERR DRV_NAME
+                              ": %s: ARP target table is full!\n",
+                              bond->dev->name);
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+       }
+       else if (buf[0] == '-') {
+               if ((newtarget == 0) || (newtarget == INADDR_BROADCAST)) {
+                       printk(KERN_ERR DRV_NAME
+                              ": %s: invalid ARP target %d.%d.%d.%d specified for removal\n",
+                              bond->dev->name, NIPQUAD(newtarget));
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
+                       if (targets[i] == newtarget) {
+                               printk(KERN_INFO DRV_NAME
+                                      ": %s: removing ARP target %d.%d.%d.%d.\n",
+                                      bond->dev->name, NIPQUAD(newtarget));
+                               targets[i] = 0;
+                               done = 1;
+                       }
+               }
+               if (!done) {
+                       printk(KERN_INFO DRV_NAME
+                              ": %s: unable to remove nonexistent ARP target %d.%d.%d.%d.\n",
+                              bond->dev->name, NIPQUAD(newtarget));
+                       ret = -EINVAL;
+                       goto out;
+               }
+       }
+       else {
+               printk(KERN_ERR DRV_NAME ": no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
+                       bond->dev->name);
+               ret = -EPERM;
+               goto out;
+       }
+
+out:
+       return ret;
+}
+static CLASS_DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
+
+/*
+ * Show and set the up and down delays.  These must be multiples of the
+ * MII monitoring value, and are stored internally as the multiplier.
+ * Thus, we must translate to MS for the real world.
+ */
+static ssize_t bonding_show_downdelay(struct class_device *cd, char *buf)
+{
+       struct bonding *bond = to_bond(cd);
+
+       return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon) + 1;
+}
+
+static ssize_t bonding_store_downdelay(struct class_device *cd, const char *buf, size_t count)
+{
+       int new_value, ret = count;
+       struct bonding *bond = to_bond(cd);
+
+       if (!(bond->params.miimon)) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Unable to set down delay as MII monitoring is disabled\n",
+                      bond->dev->name);
+               ret = -EPERM;
+               goto out;
+       }
+
+       if (sscanf(buf, "%d", &new_value) != 1) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: no down delay value specified.\n",
+                      bond->dev->name);
+               ret = -EINVAL;
+               goto out;
+       }
+       if (new_value < 0) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
+                      bond->dev->name, new_value, 1, INT_MAX);
+               ret = -EINVAL;
+               goto out;
+       } else {
+               if ((new_value % bond->params.miimon) != 0) {
+                       printk(KERN_WARNING DRV_NAME
+                              ": %s: Warning: down delay (%d) is not a multiple "
+                              "of miimon (%d), delay rounded to %d ms\n",
+                              bond->dev->name, new_value, bond->params.miimon,
+                              (new_value / bond->params.miimon) *
+                              bond->params.miimon);
+               }
+               bond->params.downdelay = new_value / bond->params.miimon;
+               printk(KERN_INFO DRV_NAME ": %s: Setting down delay to %d.\n",
+                      bond->dev->name, bond->params.downdelay * bond->params.miimon);
+
+       }
+
+out:
+       return ret;
+}
+static CLASS_DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR , bonding_show_downdelay, bonding_store_downdelay);
+
+static ssize_t bonding_show_updelay(struct class_device *cd, char *buf)
+{
+       struct bonding *bond = to_bond(cd);
+
+       return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon) + 1;
+
+}
+
+static ssize_t bonding_store_updelay(struct class_device *cd, const char *buf, size_t count)
+{
+       int new_value, ret = count;
+       struct bonding *bond = to_bond(cd);
+
+       if (!(bond->params.miimon)) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Unable to set up delay as MII monitoring is disabled\n",
+                      bond->dev->name);
+               ret = -EPERM;
+               goto out;
+       }
+
+       if (sscanf(buf, "%d", &new_value) != 1) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: no up delay value specified.\n",
+                      bond->dev->name);
+               ret = -EINVAL;
+               goto out;
+       }
+       if (new_value < 0) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
+                      bond->dev->name, new_value, 1, INT_MAX);
+               ret = -EINVAL;
+               goto out;
+       } else {
+               if ((new_value % bond->params.miimon) != 0) {
+                       printk(KERN_WARNING DRV_NAME
+                              ": %s: Warning: up delay (%d) is not a multiple "
+                              "of miimon (%d), updelay rounded to %d ms\n",
+                              bond->dev->name, new_value, bond->params.miimon,
+                              (new_value / bond->params.miimon) *
+                              bond->params.miimon);
+               }
+               bond->params.updelay = new_value / bond->params.miimon;
+               printk(KERN_INFO DRV_NAME ": %s: Setting up delay to %d.\n",
+                      bond->dev->name, bond->params.updelay * bond->params.miimon);
+
+       }
+
+out:
+       return ret;
+}
+static CLASS_DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR , bonding_show_updelay, bonding_store_updelay);
+
+/*
+ * Show and set the LACP interval.  Interface must be down, and the mode
+ * must be set to 802.3ad mode.
+ */
+static ssize_t bonding_show_lacp(struct class_device *cd, char *buf)
+{
+       struct bonding *bond = to_bond(cd);
+
+       return sprintf(buf, "%s %d\n",
+               bond_lacp_tbl[bond->params.lacp_fast].modename,
+               bond->params.lacp_fast) + 1;
+}
+
+static ssize_t bonding_store_lacp(struct class_device *cd, const char *buf, size_t count)
+{
+       int new_value, ret = count;
+       struct bonding *bond = to_bond(cd);
+
+       if (bond->dev->flags & IFF_UP) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Unable to update LACP rate because interface is up.\n",
+                      bond->dev->name);
+               ret = -EPERM;
+               goto out;
+       }
+
+       if (bond->params.mode != BOND_MODE_8023AD) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
+                      bond->dev->name);
+               ret = -EPERM;
+               goto out;
+       }
+
+       new_value = bond_parse_parm((char *)buf, bond_lacp_tbl);
+
+       if ((new_value == 1) || (new_value == 0)) {
+               bond->params.lacp_fast = new_value;
+               printk(KERN_INFO DRV_NAME
+                      ": %s: Setting LACP rate to %s (%d).\n",
+                      bond->dev->name, bond_lacp_tbl[new_value].modename, new_value);
+       } else {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Ignoring invalid LACP rate value %.*s.\n",
+                       bond->dev->name, (int)strlen(buf) - 1, buf);
+               ret = -EINVAL;
+       }
+out:
+       return ret;
+}
+static CLASS_DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, bonding_show_lacp, bonding_store_lacp);
+
+/*
+ * Show and set the MII monitor interval.  There are two tricky bits
+ * here.  First, if MII monitoring is activated, then we must disable
+ * ARP monitoring.  Second, if the timer isn't running, we must
+ * start it.
+ */
+static ssize_t bonding_show_miimon(struct class_device *cd, char *buf)
+{
+       struct bonding *bond = to_bond(cd);
+
+       return sprintf(buf, "%d\n", bond->params.miimon) + 1;
+}
+
+static ssize_t bonding_store_miimon(struct class_device *cd, const char *buf, size_t count)
+{
+       int new_value, ret = count;
+       struct bonding *bond = to_bond(cd);
+
+       if (sscanf(buf, "%d", &new_value) != 1) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: no miimon value specified.\n",
+                      bond->dev->name);
+               ret = -EINVAL;
+               goto out;
+       }
+       if (new_value < 0) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: Invalid miimon value %d not in range %d-%d; rejected.\n",
+                      bond->dev->name, new_value, 1, INT_MAX);
+               ret = -EINVAL;
+               goto out;
+       } else {
+               printk(KERN_INFO DRV_NAME
+                      ": %s: Setting MII monitoring interval to %d.\n",
+                      bond->dev->name, new_value);
+               bond->params.miimon = new_value;
+               if(bond->params.updelay)
+                       printk(KERN_INFO DRV_NAME
+                             ": %s: Note: Updating updelay (to %d) "
+                             "since it is a multiple of the miimon value.\n",
+                             bond->dev->name,
+                             bond->params.updelay * bond->params.miimon);
+               if(bond->params.downdelay)
+                       printk(KERN_INFO DRV_NAME
+                             ": %s: Note: Updating downdelay (to %d) "
+                             "since it is a multiple of the miimon value.\n",
+                             bond->dev->name,
+                             bond->params.downdelay * bond->params.miimon);
+               if (bond->params.arp_interval) {
+                       printk(KERN_INFO DRV_NAME
+                              ": %s: MII monitoring cannot be used with "
+                              "ARP monitoring. Disabling ARP monitoring...\n",
+                              bond->dev->name);
+                       bond->params.arp_interval = 0;
+                       /* Kill ARP timer, else it brings bond's link down */
+                       if (bond->mii_timer.function) {
+                               printk(KERN_INFO DRV_NAME
+                               ": %s: Kill ARP timer, else it brings bond's link down...\n",
+                              bond->dev->name);
+                               del_timer_sync(&bond->arp_timer);
+                       }
+               }
+
+               if (bond->dev->flags & IFF_UP) {
+                       /* If the interface is up, we may need to fire off
+                        * the MII timer. If the interface is down, the
+                        * timer will get fired off when the open function
+                        * is called.
+                        */
+                       if (bond->mii_timer.function) {
+                               /* The timer's already set up, so fire it off */
+                               mod_timer(&bond->mii_timer, jiffies + 1);
+                       } else {
+                               /* Set up the timer. */
+                               init_timer(&bond->mii_timer);
+                               bond->mii_timer.expires = jiffies + 1;
+                               bond->mii_timer.data =
+                                       (unsigned long) bond->dev;
+                               bond->mii_timer.function =
+                                       (void *) &bond_mii_monitor;
+                               add_timer(&bond->mii_timer);
+                       }
+               }
+       }
+out:
+       return ret;
+}
+static CLASS_DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, bonding_show_miimon, bonding_store_miimon);
+
+/*
+ * Show and set the primary slave.  The store function is much
+ * simpler than bonding_store_slaves function because it only needs to
+ * handle one interface name.
+ * The bond must be a mode that supports a primary for this be
+ * set.
+ */
+static ssize_t bonding_show_primary(struct class_device *cd, char *buf)
+{
+       int count = 0;
+       struct bonding *bond = to_bond(cd);
+
+       if (bond->primary_slave)
+               count = sprintf(buf, "%s\n", bond->primary_slave->dev->name) + 1;
+       else
+               count = sprintf(buf, "\n") + 1;
+
+       return count;
+}
+
+static ssize_t bonding_store_primary(struct class_device *cd, const char *buf, size_t count)
+{
+       int i;
+       struct slave *slave;
+       struct bonding *bond = to_bond(cd);
+
+       write_lock_bh(&bond->lock);
+       if (!USES_PRIMARY(bond->params.mode)) {
+               printk(KERN_INFO DRV_NAME
+                      ": %s: Unable to set primary slave; %s is in mode %d\n",
+                      bond->dev->name, bond->dev->name, bond->params.mode);
+       } else {
+               bond_for_each_slave(bond, slave, i) {
+                       if (strnicmp
+                           (slave->dev->name, buf,
+                            strlen(slave->dev->name)) == 0) {
+                               printk(KERN_INFO DRV_NAME
+                                      ": %s: Setting %s as primary slave.\n",
+                                      bond->dev->name, slave->dev->name);
+                               bond->primary_slave = slave;
+                               bond_select_active_slave(bond);
+                               goto out;
+                       }
+               }
+
+               /* if we got here, then we didn't match the name of any slave */
+
+               if (strlen(buf) == 0 || buf[0] == '\n') {
+                       printk(KERN_INFO DRV_NAME
+                              ": %s: Setting primary slave to None.\n",
+                              bond->dev->name);
+                       bond->primary_slave = 0;
+                               bond_select_active_slave(bond);
+               } else {
+                       printk(KERN_INFO DRV_NAME
+                              ": %s: Unable to set %.*s as primary slave as it is not a slave.\n",
+                              bond->dev->name, (int)strlen(buf) - 1, buf);
+               }
+       }
+out:
+       write_unlock_bh(&bond->lock);
+       return count;
+}
+static CLASS_DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, bonding_show_primary, bonding_store_primary);
+
+/*
+ * Show and set the use_carrier flag.
+ */
+static ssize_t bonding_show_carrier(struct class_device *cd, char *buf)
+{
+       struct bonding *bond = to_bond(cd);
+
+       return sprintf(buf, "%d\n", bond->params.use_carrier) + 1;
+}
+
+static ssize_t bonding_store_carrier(struct class_device *cd, const char *buf, size_t count)
+{
+       int new_value, ret = count;
+       struct bonding *bond = to_bond(cd);
+
+
+       if (sscanf(buf, "%d", &new_value) != 1) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: no use_carrier value specified.\n",
+                      bond->dev->name);
+               ret = -EINVAL;
+               goto out;
+       }
+       if ((new_value == 0) || (new_value == 1)) {
+               bond->params.use_carrier = new_value;
+               printk(KERN_INFO DRV_NAME ": %s: Setting use_carrier to %d.\n",
+                      bond->dev->name, new_value);
+       } else {
+               printk(KERN_INFO DRV_NAME
+                      ": %s: Ignoring invalid use_carrier value %d.\n",
+                      bond->dev->name, new_value);
+       }
+out:
+       return count;
+}
+static CLASS_DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, bonding_show_carrier, bonding_store_carrier);
+
+
+/*
+ * Show and set currently active_slave.
+ */
+static ssize_t bonding_show_active_slave(struct class_device *cd, char *buf)
+{
+       struct slave *curr;
+       struct bonding *bond = to_bond(cd);
+       int count;
+
+
+       read_lock(&bond->curr_slave_lock);
+       curr = bond->curr_active_slave;
+       read_unlock(&bond->curr_slave_lock);
+
+       if (USES_PRIMARY(bond->params.mode) && curr)
+               count = sprintf(buf, "%s\n", curr->dev->name) + 1;
+       else
+               count = sprintf(buf, "\n") + 1;
+       return count;
+}
+
+static ssize_t bonding_store_active_slave(struct class_device *cd, const char *buf, size_t count)
+{
+       int i;
+       struct slave *slave;
+        struct slave *old_active = NULL;
+        struct slave *new_active = NULL;
+       struct bonding *bond = to_bond(cd);
+
+       write_lock_bh(&bond->lock);
+       if (!USES_PRIMARY(bond->params.mode)) {
+               printk(KERN_INFO DRV_NAME
+                      ": %s: Unable to change active slave; %s is in mode %d\n",
+                      bond->dev->name, bond->dev->name, bond->params.mode);
+       } else {
+               bond_for_each_slave(bond, slave, i) {
+                       if (strnicmp
+                           (slave->dev->name, buf,
+                            strlen(slave->dev->name)) == 0) {
+                               old_active = bond->curr_active_slave;
+                               new_active = slave;
+                               if (new_active && (new_active == old_active)) {
+                                       /* do nothing */
+                                       printk(KERN_INFO DRV_NAME
+                                              ": %s: %s is already the current active slave.\n",
+                                              bond->dev->name, slave->dev->name);
+                                       goto out;
+                               }
+                               else {
+                                       if ((new_active) &&
+                                           (old_active) &&
+                                           (new_active->link == BOND_LINK_UP) &&
+                                           IS_UP(new_active->dev)) {
+                                               printk(KERN_INFO DRV_NAME
+                                                     ": %s: Setting %s as active slave.\n",
+                                                     bond->dev->name, slave->dev->name);
+                                               bond_change_active_slave(bond, new_active);
+                                       }
+                                       else {
+                                               printk(KERN_INFO DRV_NAME
+                                                     ": %s: Could not set %s as active slave; "
+                                                     "either %s is down or the link is down.\n",
+                                                     bond->dev->name, slave->dev->name,
+                                                     slave->dev->name);
+                                       }
+                                       goto out;
+                               }
+                       }
+               }
+
+               /* if we got here, then we didn't match the name of any slave */
+
+               if (strlen(buf) == 0 || buf[0] == '\n') {
+                       printk(KERN_INFO DRV_NAME
+                              ": %s: Setting active slave to None.\n",
+                              bond->dev->name);
+                       bond->primary_slave = 0;
+                               bond_select_active_slave(bond);
+               } else {
+                       printk(KERN_INFO DRV_NAME
+                              ": %s: Unable to set %.*s as active slave as it is not a slave.\n",
+                              bond->dev->name, (int)strlen(buf) - 1, buf);
+               }
+       }
+out:
+       write_unlock_bh(&bond->lock);
+       return count;
+
+}
+static CLASS_DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, bonding_show_active_slave, bonding_store_active_slave);
+
+
+/*
+ * Show link status of the bond interface.
+ */
+static ssize_t bonding_show_mii_status(struct class_device *cd, char *buf)
+{
+       struct slave *curr;
+       struct bonding *bond = to_bond(cd);
+
+       read_lock(&bond->curr_slave_lock);
+       curr = bond->curr_active_slave;
+       read_unlock(&bond->curr_slave_lock);
+
+       return sprintf(buf, "%s\n", (curr) ? "up" : "down") + 1;
+}
+static CLASS_DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
+
+
+/*
+ * Show current 802.3ad aggregator ID.
+ */
+static ssize_t bonding_show_ad_aggregator(struct class_device *cd, char *buf)
+{
+       int count = 0;
+       struct bonding *bond = to_bond(cd);
+
+       if (bond->params.mode == BOND_MODE_8023AD) {
+               struct ad_info ad_info;
+               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0 : ad_info.aggregator_id) + 1;
+       }
+       else
+               count = sprintf(buf, "\n") + 1;
+
+       return count;
+}
+static CLASS_DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
+
+
+/*
+ * Show number of active 802.3ad ports.
+ */
+static ssize_t bonding_show_ad_num_ports(struct class_device *cd, char *buf)
+{
+       int count = 0;
+       struct bonding *bond = to_bond(cd);
+
+       if (bond->params.mode == BOND_MODE_8023AD) {
+               struct ad_info ad_info;
+               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0: ad_info.ports) + 1;
+       }
+       else
+               count = sprintf(buf, "\n") + 1;
+
+       return count;
+}
+static CLASS_DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
+
+
+/*
+ * Show current 802.3ad actor key.
+ */
+static ssize_t bonding_show_ad_actor_key(struct class_device *cd, char *buf)
+{
+       int count = 0;
+       struct bonding *bond = to_bond(cd);
+
+       if (bond->params.mode == BOND_MODE_8023AD) {
+               struct ad_info ad_info;
+               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0 : ad_info.actor_key) + 1;
+       }
+       else
+               count = sprintf(buf, "\n") + 1;
+
+       return count;
+}
+static CLASS_DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
+
+
+/*
+ * Show current 802.3ad partner key.
+ */
+static ssize_t bonding_show_ad_partner_key(struct class_device *cd, char *buf)
+{
+       int count = 0;
+       struct bonding *bond = to_bond(cd);
+
+       if (bond->params.mode == BOND_MODE_8023AD) {
+               struct ad_info ad_info;
+               count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ?  0 : ad_info.partner_key) + 1;
+       }
+       else
+               count = sprintf(buf, "\n") + 1;
+
+       return count;
+}
+static CLASS_DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
+
+
+/*
+ * Show current 802.3ad partner mac.
+ */
+static ssize_t bonding_show_ad_partner_mac(struct class_device *cd, char *buf)
+{
+       int count = 0;
+       struct bonding *bond = to_bond(cd);
+
+       if (bond->params.mode == BOND_MODE_8023AD) {
+               struct ad_info ad_info;
+               if (!bond_3ad_get_active_agg_info(bond, &ad_info)) {
+                       count = sprintf(buf,"%02x:%02x:%02x:%02x:%02x:%02x\n",
+                                      ad_info.partner_system[0],
+                                      ad_info.partner_system[1],
+                                      ad_info.partner_system[2],
+                                      ad_info.partner_system[3],
+                                      ad_info.partner_system[4],
+                                      ad_info.partner_system[5]) + 1;
+               }
+       }
+       else
+               count = sprintf(buf, "\n") + 1;
+
+       return count;
+}
+static CLASS_DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
+
+
+
+static struct attribute *per_bond_attrs[] = {
+       &class_device_attr_slaves.attr,
+       &class_device_attr_mode.attr,
+       &class_device_attr_arp_interval.attr,
+       &class_device_attr_arp_ip_target.attr,
+       &class_device_attr_downdelay.attr,
+       &class_device_attr_updelay.attr,
+       &class_device_attr_lacp_rate.attr,
+       &class_device_attr_xmit_hash_policy.attr,
+       &class_device_attr_miimon.attr,
+       &class_device_attr_primary.attr,
+       &class_device_attr_use_carrier.attr,
+       &class_device_attr_active_slave.attr,
+       &class_device_attr_mii_status.attr,
+       &class_device_attr_ad_aggregator.attr,
+       &class_device_attr_ad_num_ports.attr,
+       &class_device_attr_ad_actor_key.attr,
+       &class_device_attr_ad_partner_key.attr,
+       &class_device_attr_ad_partner_mac.attr,
+       NULL,
+};
+
+static struct attribute_group bonding_group = {
+       .name = "bonding",
+       .attrs = per_bond_attrs,
+};
+
+/*
+ * Initialize sysfs.  This sets up the bonding_masters file in
+ * /sys/class/net.
+ */
+int bond_create_sysfs(void)
+{
+       int ret = 0;
+       struct bonding *firstbond;
+
+       init_rwsem(&bonding_rwsem);
+
+       /* get the netdev class pointer */
+       firstbond = container_of(bond_dev_list.next, struct bonding, bond_list);
+       if (!firstbond)
+               return -ENODEV;
+
+       netdev_class = firstbond->dev->class_dev.class;
+       if (!netdev_class)
+               return -ENODEV;
+
+       ret = class_create_file(netdev_class, &class_attr_bonding_masters);
+
+       return ret;
+
+}
+
+/*
+ * Remove /sys/class/net/bonding_masters.
+ */
+void bond_destroy_sysfs(void)
+{
+       if (netdev_class)
+               class_remove_file(netdev_class, &class_attr_bonding_masters);
+}
+
+/*
+ * Initialize sysfs for each bond.  This sets up and registers
+ * the 'bondctl' directory for each individual bond under /sys/class/net.
+ */
+int bond_create_sysfs_entry(struct bonding *bond)
+{
+       struct net_device *dev = bond->dev;
+       int err;
+
+       err = sysfs_create_group(&(dev->class_dev.kobj), &bonding_group);
+       if (err) {
+               printk(KERN_EMERG "eek! didn't create group!\n");
+       }
+
+       if (expected_refcount < 1)
+               expected_refcount = atomic_read(&bond->dev->class_dev.kobj.kref.refcount);
+
+       return err;
+}
+/*
+ * Remove sysfs entries for each bond.
+ */
+void bond_destroy_sysfs_entry(struct bonding *bond)
+{
+       struct net_device *dev = bond->dev;
+
+       sysfs_remove_group(&(dev->class_dev.kobj), &bonding_group);
+}
+
index 1433e91db0f7fb12b3fcec07c83288192202e4c5..015c7f1d1bc0843e3be52454505a8d99ad068fc9 100644 (file)
  *     This software may be used and distributed according to the terms
  *     of the GNU Public License, incorporated herein by reference.
  *
- *
- * 2003/03/18 - Amir Noam <amir.noam at intel dot com>,
- *             Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Shmulik Hen <shmulik.hen at intel dot com>
- *     - Added support for IEEE 802.3ad Dynamic link aggregation mode.
- *
- * 2003/05/01 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Amir Noam <amir.noam at intel dot com>
- *     - Code beautification and style changes (mainly in comments).
- *
- * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Added support for Transmit load balancing mode.
- *
- * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Code cleanup and style changes
- *
- * 2005/05/05 - Jason Gabler <jygabler at lbl dot gov>
- *      - added "xmit_policy" kernel parameter for alternate hashing policy
- *       support for mode 2
  */
 
 #ifndef _LINUX_BONDING_H
 #include <linux/timer.h>
 #include <linux/proc_fs.h>
 #include <linux/if_bonding.h>
+#include <linux/kobject.h>
 #include "bond_3ad.h"
 #include "bond_alb.h"
 
-#define DRV_VERSION    "2.6.5"
-#define DRV_RELDATE    "November 4, 2005"
+#define DRV_VERSION    "3.0.0"
+#define DRV_RELDATE    "November 8, 2005"
 #define DRV_NAME       "bonding"
 #define DRV_DESCRIPTION        "Ethernet Channel Bonding Driver"
 
@@ -152,6 +134,11 @@ struct bond_params {
        u32 arp_targets[BOND_MAX_ARP_TARGETS];
 };
 
+struct bond_parm_tbl {
+       char *modename;
+       int mode;
+};
+
 struct vlan_entry {
        struct list_head vlan_list;
        u32 vlan_ip;
@@ -159,7 +146,7 @@ struct vlan_entry {
 };
 
 struct slave {
-       struct net_device *dev; /* first - usefull for panic debug */
+       struct net_device *dev; /* first - useful for panic debug */
        struct slave *next;
        struct slave *prev;
        s16    delay;
@@ -185,7 +172,7 @@ struct slave {
  *    beforehand.
  */
 struct bonding {
-       struct   net_device *dev; /* first - usefull for panic debug */
+       struct   net_device *dev; /* first - useful for panic debug */
        struct   slave *first_slave;
        struct   slave *curr_active_slave;
        struct   slave *current_arp_slave;
@@ -255,6 +242,25 @@ extern inline void bond_set_slave_active_flags(struct slave *slave)
 
 struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr);
 int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
+int bond_create(char *name, struct bond_params *params, struct bonding **newbond);
+void bond_deinit(struct net_device *bond_dev);
+int bond_create_sysfs(void);
+void bond_destroy_sysfs(void);
+void bond_destroy_sysfs_entry(struct bonding *bond);
+int bond_create_sysfs_entry(struct bonding *bond);
+int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave);
+void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave);
+int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev);
+int bond_release(struct net_device *bond_dev, struct net_device *slave_dev);
+int bond_sethwaddr(struct net_device *bond_dev, struct net_device *slave_dev);
+void bond_mii_monitor(struct net_device *bond_dev);
+void bond_loadbalance_arp_mon(struct net_device *bond_dev);
+void bond_activebackup_arp_mon(struct net_device *bond_dev);
+void bond_set_mode_ops(struct bonding *bond, int mode);
+int bond_parse_parm(char *mode_arg, struct bond_parm_tbl *tbl);
+const char *bond_mode_name(int mode);
+void bond_select_active_slave(struct bonding *bond);
+void bond_change_active_slave(struct bonding *bond, struct slave *new_active);
 
 #endif /* _LINUX_BONDING_H */
 
index 53b41d99b00b2ec48fad8d963f1be24b8269d43e..2c5b849b7ba4fcecc414866940c0316189345c15 100644 (file)
@@ -1332,8 +1332,8 @@ intr_handler_t t1_select_intr_handler(adapter_t *adapter)
  *
  * This runs with softirqs disabled.
  */
-unsigned int t1_sge_tx(struct sk_buff *skb, struct adapter *adapter,
-                      unsigned int qid, struct net_device *dev)
+static int t1_sge_tx(struct sk_buff *skb, struct adapter *adapter,
+                    unsigned int qid, struct net_device *dev)
 {
        struct sge *sge = adapter->sge;
        struct cmdQ *q = &sge->cmdQ[qid];
@@ -1352,9 +1352,10 @@ unsigned int t1_sge_tx(struct sk_buff *skb, struct adapter *adapter,
                        set_bit(dev->if_port, &sge->stopped_tx_queues);
                        sge->stats.cmdQ_full[3]++;
                        spin_unlock(&q->lock);
-                       CH_ERR("%s: Tx ring full while queue awake!\n",
-                              adapter->name);
-                       return 1;
+                       if (!netif_queue_stopped(dev))
+                               CH_ERR("%s: Tx ring full while queue awake!\n",
+                                      adapter->name);
+                       return NETDEV_TX_BUSY;
                }
                if (unlikely(credits - count < q->stop_thres)) {
                        sge->stats.cmdQ_full[3]++;
@@ -1389,7 +1390,7 @@ unsigned int t1_sge_tx(struct sk_buff *skb, struct adapter *adapter,
                        writel(F_CMDQ0_ENABLE, adapter->regs + A_SG_DOORBELL);
                }
        }
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 #define MK_ETH_TYPE_MSS(type, mss) (((mss) & 0x3FFF) | ((type) << 14))
@@ -1449,7 +1450,7 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
                if (unlikely(skb->len < ETH_HLEN ||
                             skb->len > dev->mtu + eth_hdr_len(skb->data))) {
                        dev_kfree_skb_any(skb);
-                       return NET_XMIT_SUCCESS;
+                       return NETDEV_TX_OK;
                }
 
                /*
@@ -1467,7 +1468,7 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
                        skb = skb_realloc_headroom(skb, sizeof(*cpl));
                        dev_kfree_skb_any(orig_skb);
                        if (!skb)
-                               return -ENOMEM;
+                               return NETDEV_TX_OK;
                }
 
                if (!(adapter->flags & UDP_CSUM_CAPABLE) &&
@@ -1475,7 +1476,7 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
                    skb->nh.iph->protocol == IPPROTO_UDP)
                        if (unlikely(skb_checksum_help(skb, 0))) {
                                dev_kfree_skb_any(skb);
-                               return -ENOMEM;
+                               return NETDEV_TX_OK;
                        }
 
                /* Hmmm, assuming to catch the gratious arp... and we'll use
index 434b255868516045dbd67bc764d7ba8ea35d37e1..6d0d24a6364f75d8dc7908b58d83d6d1672b234e 100644 (file)
@@ -89,8 +89,6 @@ int t1_sge_configure(struct sge *, struct sge_params *);
 int t1_sge_set_coalesce_params(struct sge *, struct sge_params *);
 void t1_sge_destroy(struct sge *);
 intr_handler_t t1_select_intr_handler(adapter_t *adapter);
-unsigned int t1_sge_tx(struct sk_buff *skb, struct adapter *adapter,
-                      unsigned int qid, struct net_device *netdev);
 int t1_start_xmit(struct sk_buff *skb, struct net_device *dev);
 void t1_set_vlan_accel(struct adapter *adapter, int on_off);
 void t1_sge_start(struct sge *);
index 3f653a93e1bc78dc9ab7e730bdc9490cac4f5650..e02e9ba2e18b0b66166f2f877a2e282f0a4926f8 100644 (file)
@@ -188,11 +188,13 @@ struct e1000_tx_ring {
        /* array of buffer information structs */
        struct e1000_buffer *buffer_info;
 
-       struct e1000_buffer previous_buffer_info;
        spinlock_t tx_lock;
        uint16_t tdh;
        uint16_t tdt;
        uint64_t pkt;
+
+       boolean_t last_tx_tso;
+
 };
 
 struct e1000_rx_ring {
index 8eae8ba27e84da532250b16756c60456e00dcee1..c88f1a3c1b1db7d58a87a779d6517480e514d31c 100644 (file)
@@ -562,10 +562,29 @@ e1000_get_drvinfo(struct net_device *netdev,
                        struct ethtool_drvinfo *drvinfo)
 {
        struct e1000_adapter *adapter = netdev_priv(netdev);
+       char firmware_version[32];
+       uint16_t eeprom_data;
 
        strncpy(drvinfo->driver,  e1000_driver_name, 32);
        strncpy(drvinfo->version, e1000_driver_version, 32);
-       strncpy(drvinfo->fw_version, "N/A", 32);
+       
+       /* EEPROM image version # is reported as firware version # for
+        * 8257{1|2|3} controllers */
+       e1000_read_eeprom(&adapter->hw, 5, 1, &eeprom_data);
+       switch (adapter->hw.mac_type) {
+       case e1000_82571:
+       case e1000_82572:
+       case e1000_82573:
+               sprintf(firmware_version, "%d.%d-%d", 
+                       (eeprom_data & 0xF000) >> 12,
+                       (eeprom_data & 0x0FF0) >> 4,
+                       eeprom_data & 0x000F);
+               break;
+       default:
+               sprintf(firmware_version, "n/a");
+       }
+
+       strncpy(drvinfo->fw_version, firmware_version, 32);
        strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
        drvinfo->n_stats = E1000_STATS_LEN;
        drvinfo->testinfo_len = E1000_TEST_LEN;
@@ -960,13 +979,21 @@ e1000_free_desc_rings(struct e1000_adapter *adapter)
                }
        }
 
-       if(txdr->desc)
+       if(txdr->desc) {
                pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
-       if(rxdr->desc)
+               txdr->desc = NULL;
+       }
+       if(rxdr->desc) {
                pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
+               rxdr->desc = NULL;
+       }
 
        kfree(txdr->buffer_info);
+       txdr->buffer_info = NULL;
+
        kfree(rxdr->buffer_info);
+       rxdr->buffer_info = NULL;
+
        return;
 }
 
@@ -1301,21 +1328,32 @@ static int
 e1000_setup_loopback_test(struct e1000_adapter *adapter)
 {
        uint32_t rctl;
+       struct e1000_hw *hw = &adapter->hw;
 
-       if(adapter->hw.media_type == e1000_media_type_fiber ||
-          adapter->hw.media_type == e1000_media_type_internal_serdes) {
-               if(adapter->hw.mac_type == e1000_82545 ||
-                  adapter->hw.mac_type == e1000_82546 ||
-                  adapter->hw.mac_type == e1000_82545_rev_3 ||
-                  adapter->hw.mac_type == e1000_82546_rev_3)
+       if (hw->media_type == e1000_media_type_fiber ||
+          hw->media_type == e1000_media_type_internal_serdes) {
+               switch (hw->mac_type) {
+               case e1000_82545:
+               case e1000_82546:
+               case e1000_82545_rev_3:
+               case e1000_82546_rev_3:
                        return e1000_set_phy_loopback(adapter);
-               else {
-                       rctl = E1000_READ_REG(&adapter->hw, RCTL);
+                       break;
+               case e1000_82571:
+               case e1000_82572:
+#define E1000_SERDES_LB_ON 0x410
+                       e1000_set_phy_loopback(adapter);
+                       E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_ON);
+                       msec_delay(10);
+                       return 0;
+                       break;
+               default:
+                       rctl = E1000_READ_REG(hw, RCTL);
                        rctl |= E1000_RCTL_LBM_TCVR;
-                       E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
+                       E1000_WRITE_REG(hw, RCTL, rctl);
                        return 0;
                }
-       } else if(adapter->hw.media_type == e1000_media_type_copper)
+       } else if (hw->media_type == e1000_media_type_copper)
                return e1000_set_phy_loopback(adapter);
 
        return 7;
@@ -1326,25 +1364,36 @@ e1000_loopback_cleanup(struct e1000_adapter *adapter)
 {
        uint32_t rctl;
        uint16_t phy_reg;
+       struct e1000_hw *hw = &adapter->hw;
 
        rctl = E1000_READ_REG(&adapter->hw, RCTL);
        rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
        E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
 
-       if(adapter->hw.media_type == e1000_media_type_copper ||
-          ((adapter->hw.media_type == e1000_media_type_fiber ||
-            adapter->hw.media_type == e1000_media_type_internal_serdes) &&
-           (adapter->hw.mac_type == e1000_82545 ||
-            adapter->hw.mac_type == e1000_82546 ||
-            adapter->hw.mac_type == e1000_82545_rev_3 ||
-            adapter->hw.mac_type == e1000_82546_rev_3))) {
-               adapter->hw.autoneg = TRUE;
-               e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
-               if(phy_reg & MII_CR_LOOPBACK) {
+       switch (hw->mac_type) {
+       case e1000_82571:
+       case e1000_82572:
+               if (hw->media_type == e1000_media_type_fiber ||
+                  hw->media_type == e1000_media_type_internal_serdes){
+#define E1000_SERDES_LB_OFF 0x400
+                       E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_OFF);
+                       msec_delay(10);
+                       break;
+               }
+               /* fall thru for Cu adapters */
+       case e1000_82545:
+       case e1000_82546:
+       case e1000_82545_rev_3:
+       case e1000_82546_rev_3:
+       default:
+               hw->autoneg = TRUE;
+               e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
+               if (phy_reg & MII_CR_LOOPBACK) {
                        phy_reg &= ~MII_CR_LOOPBACK;
-                       e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
-                       e1000_phy_reset(&adapter->hw);
+                       e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
+                       e1000_phy_reset(hw);
                }
+               break;
        }
 }
 
@@ -1440,9 +1489,11 @@ static int
 e1000_loopback_test(struct e1000_adapter *adapter, uint64_t *data)
 {
        if((*data = e1000_setup_desc_rings(adapter))) goto err_loopback;
-       if((*data = e1000_setup_loopback_test(adapter))) goto err_loopback;
+       if((*data = e1000_setup_loopback_test(adapter)))
+               goto err_loopback_setup;
        *data = e1000_run_loopback_test(adapter);
        e1000_loopback_cleanup(adapter);
+err_loopback_setup:
        e1000_free_desc_rings(adapter);
 err_loopback:
        return *data;
@@ -1671,6 +1722,14 @@ e1000_phys_id(struct net_device *netdev, uint32_t data)
                msleep_interruptible(data * 1000);
                del_timer_sync(&adapter->blink_timer);
        }
+       else if(adapter->hw.mac_type < e1000_82573) {
+               E1000_WRITE_REG(&adapter->hw, LEDCTL, (E1000_LEDCTL_LED2_BLINK_RATE |
+                       E1000_LEDCTL_LED0_BLINK | E1000_LEDCTL_LED2_BLINK |
+                       (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED2_MODE_SHIFT) |
+                       (E1000_LEDCTL_MODE_LINK_ACTIVITY << E1000_LEDCTL_LED0_MODE_SHIFT) |
+                       (E1000_LEDCTL_MODE_LED_OFF << E1000_LEDCTL_LED1_MODE_SHIFT)));
+               msleep_interruptible(data * 1000);
+       }
        else {
                E1000_WRITE_REG(&adapter->hw, LEDCTL, (E1000_LEDCTL_LED2_BLINK_RATE |
                        E1000_LEDCTL_LED1_BLINK | E1000_LEDCTL_LED2_BLINK | 
index a267c5235fc0d153b08c07a7b4fe3fc41a1df666..136fc031e4ad555d168a8b0ac002b460ebea8ebb 100644 (file)
@@ -563,11 +563,13 @@ e1000_reset_hw(struct e1000_hw *hw)
             msec_delay(20);
             break;
         case e1000_82573:
-            udelay(10);
-            ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
-            ctrl_ext |= E1000_CTRL_EXT_EE_RST;
-            E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
-            E1000_WRITE_FLUSH(hw);
+            if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
+                udelay(10);
+                ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
+                ctrl_ext |= E1000_CTRL_EXT_EE_RST;
+                E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
+                E1000_WRITE_FLUSH(hw);
+            }
             /* fall through */
         case e1000_82571:
         case e1000_82572:
@@ -844,19 +846,27 @@ e1000_setup_link(struct e1000_hw *hw)
      * control setting, then the variable hw->fc will
      * be initialized based on a value in the EEPROM.
      */
-    if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data)) {
-        DEBUGOUT("EEPROM Read Error\n");
-        return -E1000_ERR_EEPROM;
-    }
-
-    if(hw->fc == e1000_fc_default) {
-        if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
-            hw->fc = e1000_fc_none;
-        else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
-                EEPROM_WORD0F_ASM_DIR)
-            hw->fc = e1000_fc_tx_pause;
-        else
+    if (hw->fc == e1000_fc_default) {
+        switch (hw->mac_type) {
+        case e1000_82573:
             hw->fc = e1000_fc_full;
+            break;
+        default:
+            ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
+                                        1, &eeprom_data);
+            if (ret_val) {
+                DEBUGOUT("EEPROM Read Error\n");
+                return -E1000_ERR_EEPROM;
+            }
+            if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
+                hw->fc = e1000_fc_none;
+            else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
+                    EEPROM_WORD0F_ASM_DIR)
+                hw->fc = e1000_fc_tx_pause;
+            else
+                hw->fc = e1000_fc_full;
+            break;
+        }
     }
 
     /* We want to save off the original Flow Control configuration just
@@ -2962,13 +2972,22 @@ e1000_phy_hw_reset(struct e1000_hw *hw)
     if(hw->mac_type > e1000_82543) {
         /* Read the device control register and assert the E1000_CTRL_PHY_RST
          * bit. Then, take it out of reset.
+         * For pre-e1000_82571 hardware, we delay for 10ms between the assert 
+         * and deassert.  For e1000_82571 hardware and later, we instead delay
+         * for 10ms after the deassertion.
          */
         ctrl = E1000_READ_REG(hw, CTRL);
         E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
         E1000_WRITE_FLUSH(hw);
-        msec_delay(10);
+        
+        if (hw->mac_type < e1000_82571) 
+            msec_delay(10);
+        
         E1000_WRITE_REG(hw, CTRL, ctrl);
         E1000_WRITE_FLUSH(hw);
+        
+        if (hw->mac_type >= e1000_82571)
+            msec_delay(10);
     } else {
         /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
          * bit to put the PHY into reset. Then, take it out of reset.
@@ -5278,9 +5297,13 @@ e1000_get_bus_info(struct e1000_hw *hw)
         hw->bus_speed = e1000_bus_speed_unknown;
         hw->bus_width = e1000_bus_width_unknown;
         break;
-    case e1000_82571:
     case e1000_82572:
     case e1000_82573:
+        hw->bus_type = e1000_bus_type_pci_express;
+        hw->bus_speed = e1000_bus_speed_2500;
+        hw->bus_width = e1000_bus_width_pciex_1;
+        break;
+    case e1000_82571:
         hw->bus_type = e1000_bus_type_pci_express;
         hw->bus_speed = e1000_bus_speed_2500;
         hw->bus_width = e1000_bus_width_pciex_4;
@@ -6650,6 +6673,12 @@ e1000_get_auto_rd_done(struct e1000_hw *hw)
         break;
     }
 
+    /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
+     * Need to wait for PHY configuration completion before accessing NVM
+     * and PHY. */
+    if (hw->mac_type == e1000_82573)
+        msec_delay(25);
+
     return E1000_SUCCESS;
 }
 
index 76ce12809a11641cc6788fcc75a99cdca1d5dd70..7caa35748ceac9c8236d1510f9335b2e57f9073b 100644 (file)
@@ -123,6 +123,7 @@ typedef enum {
     e1000_bus_width_32,
     e1000_bus_width_64,
     e1000_bus_width_pciex_1,
+    e1000_bus_width_pciex_2,
     e1000_bus_width_pciex_4,
     e1000_bus_width_reserved
 } e1000_bus_width;
@@ -149,6 +150,7 @@ typedef enum {
     e1000_igp_cable_length_90  = 90,
     e1000_igp_cable_length_100 = 100,
     e1000_igp_cable_length_110 = 110,
+    e1000_igp_cable_length_115 = 115,
     e1000_igp_cable_length_120 = 120,
     e1000_igp_cable_length_130 = 130,
     e1000_igp_cable_length_140 = 140,
@@ -1457,6 +1459,7 @@ struct e1000_hw {
 #define E1000_EECD_AUPDEN    0x00100000 /* Enable Autonomous FLASH update */
 #define E1000_EECD_SHADV     0x00200000 /* Shadow RAM Data Valid */
 #define E1000_EECD_SEC1VAL   0x00400000 /* Sector One Valid */
+#define E1000_EECD_SECVAL_SHIFT      22
 #define E1000_STM_OPCODE     0xDB00
 #define E1000_HICR_FW_RESET  0xC0
 
@@ -1951,7 +1954,6 @@ struct e1000_host_command_info {
 
 #define E1000_MDALIGN          4096
 
-#define E1000_GCR_BEM32                 0x00400000
 #define E1000_GCR_L1_ACT_WITHOUT_L0S_RX 0x08000000
 /* Function Active and Power State to MNG */
 #define E1000_FACTPS_FUNC0_POWER_STATE_MASK         0x00000003
index e0ae248b4313084337e07ff85279d4ed8d2de116..438a931fd55df4c6dd57e00d9480f35c4e9fb461 100644 (file)
@@ -711,6 +711,7 @@ e1000_probe(struct pci_dev *pdev,
                break;
        case e1000_82546:
        case e1000_82546_rev_3:
+       case e1000_82571:
                if((E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
                   && (adapter->hw.media_type == e1000_media_type_copper)) {
                        e1000_read_eeprom(&adapter->hw,
@@ -1158,7 +1159,6 @@ e1000_setup_tx_resources(struct e1000_adapter *adapter,
                return -ENOMEM;
        }
        memset(txdr->buffer_info, 0, size);
-       memset(&txdr->previous_buffer_info, 0, sizeof(struct e1000_buffer));
 
        /* round up to nearest 4K */
 
@@ -1813,11 +1813,6 @@ e1000_clean_tx_ring(struct e1000_adapter *adapter,
 
        /* Free all the Tx ring sk_buffs */
 
-       if (likely(tx_ring->previous_buffer_info.skb != NULL)) {
-               e1000_unmap_and_free_tx_resource(adapter,
-                               &tx_ring->previous_buffer_info);
-       }
-
        for(i = 0; i < tx_ring->count; i++) {
                buffer_info = &tx_ring->buffer_info[i];
                e1000_unmap_and_free_tx_resource(adapter, buffer_info);
@@ -1832,6 +1827,7 @@ e1000_clean_tx_ring(struct e1000_adapter *adapter,
 
        tx_ring->next_to_use = 0;
        tx_ring->next_to_clean = 0;
+       tx_ring->last_tx_tso = 0;
 
        writel(0, adapter->hw.hw_addr + tx_ring->tdh);
        writel(0, adapter->hw.hw_addr + tx_ring->tdt);
@@ -2437,6 +2433,16 @@ e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                buffer_info = &tx_ring->buffer_info[i];
                size = min(len, max_per_txd);
 #ifdef NETIF_F_TSO
+               /* Workaround for Controller erratum --
+                * descriptor for non-tso packet in a linear SKB that follows a
+                * tso gets written back prematurely before the data is fully
+                * DMAd to the controller */
+               if (!skb->data_len && tx_ring->last_tx_tso &&
+                               !skb_shinfo(skb)->tso_size) {
+                       tx_ring->last_tx_tso = 0;
+                       size -= 4;
+               }
+
                /* Workaround for premature desc write-backs
                 * in TSO mode.  Append 4-byte sentinel desc */
                if(unlikely(mss && !nr_frags && size == len && size > 8))
@@ -2693,6 +2699,14 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
        if(skb->ip_summed == CHECKSUM_HW)
                count++;
 #endif
+
+#ifdef NETIF_F_TSO
+       /* Controller Erratum workaround */
+       if (!skb->data_len && tx_ring->last_tx_tso &&
+               !skb_shinfo(skb)->tso_size)
+               count++;
+#endif
+
        count += TXD_USE_COUNT(len, max_txd_pwr);
 
        if(adapter->pcix_82544)
@@ -2774,9 +2788,10 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
                return NETDEV_TX_OK;
        }
 
-       if (likely(tso))
+       if (likely(tso)) {
+               tx_ring->last_tx_tso = 1;
                tx_flags |= E1000_TX_FLAGS_TSO;
-       else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
+       else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
                tx_flags |= E1000_TX_FLAGS_CSUM;
 
        /* Old method was to assume IPv4 packet by default if TSO was enabled.
@@ -3227,37 +3242,12 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
        eop_desc = E1000_TX_DESC(*tx_ring, eop);
 
        while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
-               /* Premature writeback of Tx descriptors clear (free buffers
-                * and unmap pci_mapping) previous_buffer_info */
-               if (likely(tx_ring->previous_buffer_info.skb != NULL)) {
-                       e1000_unmap_and_free_tx_resource(adapter,
-                                       &tx_ring->previous_buffer_info);
-               }
-
                for(cleaned = FALSE; !cleaned; ) {
                        tx_desc = E1000_TX_DESC(*tx_ring, i);
                        buffer_info = &tx_ring->buffer_info[i];
                        cleaned = (i == eop);
 
-#ifdef NETIF_F_TSO
-                       if (!(netdev->features & NETIF_F_TSO)) {
-#endif
-                               e1000_unmap_and_free_tx_resource(adapter,
-                                                                buffer_info);
-#ifdef NETIF_F_TSO
-                       } else {
-                               if (cleaned) {
-                                       memcpy(&tx_ring->previous_buffer_info,
-                                              buffer_info,
-                                              sizeof(struct e1000_buffer));
-                                       memset(buffer_info, 0,
-                                              sizeof(struct e1000_buffer));
-                               } else {
-                                       e1000_unmap_and_free_tx_resource(
-                                           adapter, buffer_info);
-                               }
-                       }
-#endif
+                       e1000_unmap_and_free_tx_resource(adapter, buffer_info);
 
                        tx_desc->buffer_addr = 0;
                        tx_desc->lower.data = 0;
@@ -3318,12 +3308,6 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
                        netif_stop_queue(netdev);
                }
        }
-#ifdef NETIF_F_TSO
-       if (unlikely(!(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
-           time_after(jiffies, tx_ring->previous_buffer_info.time_stamp + HZ)))
-               e1000_unmap_and_free_tx_resource(
-                   adapter, &tx_ring->previous_buffer_info);
-#endif
        return cleaned;
 }
 
index 0f030b73cbb328b246e170d85e9401182659d860..146f9513aea57f89e04cea2b5f201730590dfc1d 100644 (file)
@@ -2,7 +2,8 @@
  * drivers/net/gianfar.c
  *
  * Gianfar Ethernet Driver
- * Driver for FEC on MPC8540 and TSEC on MPC8540/MPC8560
+ * This driver is designed for the non-CPM ethernet controllers
+ * on the 85xx and 83xx family of integrated processors
  * Based on 8260_io/fcc_enet.c
  *
  * Author: Andy Fleming
@@ -22,8 +23,6 @@
  *  B-V +1.62
  *
  *  Theory of operation
- *  This driver is designed for the non-CPM ethernet controllers
- *  on the 85xx and 83xx family of integrated processors
  *
  *  The driver is initialized through platform_device.  Structures which
  *  define the configuration needed by the board are defined in a
 #endif
 
 const char gfar_driver_name[] = "Gianfar Ethernet";
-const char gfar_driver_version[] = "1.2";
+const char gfar_driver_version[] = "1.3";
 
 static int gfar_enet_open(struct net_device *dev);
 static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev);
@@ -139,6 +138,10 @@ static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int l
 static void gfar_vlan_rx_register(struct net_device *netdev,
                                struct vlan_group *grp);
 static void gfar_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
+void gfar_halt(struct net_device *dev);
+void gfar_start(struct net_device *dev);
+static void gfar_clear_exact_match(struct net_device *dev);
+static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr);
 
 extern struct ethtool_ops gfar_ethtool_ops;
 
@@ -146,12 +149,10 @@ MODULE_AUTHOR("Freescale Semiconductor, Inc");
 MODULE_DESCRIPTION("Gianfar Ethernet Driver");
 MODULE_LICENSE("GPL");
 
-int gfar_uses_fcb(struct gfar_private *priv)
+/* Returns 1 if incoming frames use an FCB */
+static inline int gfar_uses_fcb(struct gfar_private *priv)
 {
-       if (priv->vlan_enable || priv->rx_csum_enable)
-               return 1;
-       else
-               return 0;
+       return (priv->vlan_enable || priv->rx_csum_enable);
 }
 
 /* Set up the ethernet device structure, private data,
@@ -320,15 +321,10 @@ static int gfar_probe(struct platform_device *pdev)
        else
                priv->padding = 0;
 
-       dev->hard_header_len += priv->padding;
-
        if (dev->features & NETIF_F_IP_CSUM)
                dev->hard_header_len += GMAC_FCB_LEN;
 
        priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE;
-#ifdef CONFIG_GFAR_BUFSTASH
-       priv->rx_stash_size = STASH_LENGTH;
-#endif
        priv->tx_ring_size = DEFAULT_TX_RING_SIZE;
        priv->rx_ring_size = DEFAULT_RX_RING_SIZE;
 
@@ -350,6 +346,9 @@ static int gfar_probe(struct platform_device *pdev)
                goto register_fail;
        }
 
+       /* Create all the sysfs files */
+       gfar_init_sysfs(dev);
+
        /* Print out the device info */
        printk(KERN_INFO DEVICE_NAME, dev->name);
        for (idx = 0; idx < 6; idx++)
@@ -357,8 +356,7 @@ static int gfar_probe(struct platform_device *pdev)
        printk("\n");
 
        /* Even more device info helps when determining which kernel */
-       /* provided which set of benchmarks.  Since this is global for all */
-       /* devices, we only print it once */
+       /* provided which set of benchmarks. */
 #ifdef CONFIG_GFAR_NAPI
        printk(KERN_INFO "%s: Running with NAPI enabled\n", dev->name);
 #else
@@ -463,19 +461,9 @@ static void init_registers(struct net_device *dev)
        /* Initialize the max receive buffer length */
        gfar_write(&priv->regs->mrblr, priv->rx_buffer_size);
 
-#ifdef CONFIG_GFAR_BUFSTASH
-       /* If we are stashing buffers, we need to set the
-        * extraction length to the size of the buffer */
-       gfar_write(&priv->regs->attreli, priv->rx_stash_size << 16);
-#endif
-
        /* Initialize the Minimum Frame Length Register */
        gfar_write(&priv->regs->minflr, MINFLR_INIT_SETTINGS);
 
-       /* Setup Attributes so that snooping is on for rx */
-       gfar_write(&priv->regs->attr, ATTR_INIT_SETTINGS);
-       gfar_write(&priv->regs->attreli, ATTRELI_INIT_SETTINGS);
-
        /* Assign the TBI an address which won't conflict with the PHYs */
        gfar_write(&priv->regs->tbipa, TBIPA_VALUE);
 }
@@ -577,8 +565,7 @@ static void free_skb_resources(struct gfar_private *priv)
                for (i = 0; i < priv->rx_ring_size; i++) {
                        if (priv->rx_skbuff[i]) {
                                dma_unmap_single(NULL, rxbdp->bufPtr,
-                                               priv->rx_buffer_size
-                                               + RXBUF_ALIGNMENT,
+                                               priv->rx_buffer_size,
                                                DMA_FROM_DEVICE);
 
                                dev_kfree_skb_any(priv->rx_skbuff[i]);
@@ -636,6 +623,7 @@ int startup_gfar(struct net_device *dev)
        struct gfar *regs = priv->regs;
        int err = 0;
        u32 rctrl = 0;
+       u32 attrs = 0;
 
        gfar_write(&regs->imask, IMASK_INIT_CLEAR);
 
@@ -795,18 +783,50 @@ int startup_gfar(struct net_device *dev)
        if (priv->rx_csum_enable)
                rctrl |= RCTRL_CHECKSUMMING;
 
-       if (priv->extended_hash)
+       if (priv->extended_hash) {
                rctrl |= RCTRL_EXTHASH;
 
+               gfar_clear_exact_match(dev);
+               rctrl |= RCTRL_EMEN;
+       }
+
        if (priv->vlan_enable)
                rctrl |= RCTRL_VLAN;
 
+       if (priv->padding) {
+               rctrl &= ~RCTRL_PAL_MASK;
+               rctrl |= RCTRL_PADDING(priv->padding);
+       }
+
        /* Init rctrl based on our settings */
        gfar_write(&priv->regs->rctrl, rctrl);
 
        if (dev->features & NETIF_F_IP_CSUM)
                gfar_write(&priv->regs->tctrl, TCTRL_INIT_CSUM);
 
+       /* Set the extraction length and index */
+       attrs = ATTRELI_EL(priv->rx_stash_size) |
+               ATTRELI_EI(priv->rx_stash_index);
+
+       gfar_write(&priv->regs->attreli, attrs);
+
+       /* Start with defaults, and add stashing or locking
+        * depending on the approprate variables */
+       attrs = ATTR_INIT_SETTINGS;
+
+       if (priv->bd_stash_en)
+               attrs |= ATTR_BDSTASH;
+
+       if (priv->rx_stash_size != 0)
+               attrs |= ATTR_BUFSTASH;
+
+       gfar_write(&priv->regs->attr, attrs);
+
+       gfar_write(&priv->regs->fifo_tx_thr, priv->fifo_threshold);
+       gfar_write(&priv->regs->fifo_tx_starve, priv->fifo_starve);
+       gfar_write(&priv->regs->fifo_tx_starve_shutoff, priv->fifo_starve_off);
+
+       /* Start the controller */
        gfar_start(dev);
 
        return 0;
@@ -851,34 +871,32 @@ static int gfar_enet_open(struct net_device *dev)
        return err;
 }
 
-static struct txfcb *gfar_add_fcb(struct sk_buff *skb, struct txbd8 *bdp)
+static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb, struct txbd8 *bdp)
 {
        struct txfcb *fcb = (struct txfcb *)skb_push (skb, GMAC_FCB_LEN);
 
        memset(fcb, 0, GMAC_FCB_LEN);
 
-       /* Flag the bd so the controller looks for the FCB */
-       bdp->status |= TXBD_TOE;
-
        return fcb;
 }
 
 static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb)
 {
-       int len;
+       u8 flags = 0;
 
        /* If we're here, it's a IP packet with a TCP or UDP
         * payload.  We set it to checksum, using a pseudo-header
         * we provide
         */
-       fcb->ip = 1;
-       fcb->tup = 1;
-       fcb->ctu = 1;
-       fcb->nph = 1;
+       flags = TXFCB_DEFAULT;
 
-       /* Notify the controller what the protocol is */
-       if (skb->nh.iph->protocol == IPPROTO_UDP)
-               fcb->udp = 1;
+       /* Tell the controller what the protocol is */
+       /* And provide the already calculated phcs */
+       if (skb->nh.iph->protocol == IPPROTO_UDP) {
+               flags |= TXFCB_UDP;
+               fcb->phcs = skb->h.uh->check;
+       } else
+               fcb->phcs = skb->h.th->check;
 
        /* l3os is the distance between the start of the
         * frame (skb->data) and the start of the IP hdr.
@@ -887,17 +905,12 @@ static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb)
        fcb->l3os = (u16)(skb->nh.raw - skb->data - GMAC_FCB_LEN);
        fcb->l4os = (u16)(skb->h.raw - skb->nh.raw);
 
-       len = skb->nh.iph->tot_len - fcb->l4os;
-
-       /* Provide the pseudoheader csum */
-       fcb->phcs = ~csum_tcpudp_magic(skb->nh.iph->saddr,
-                       skb->nh.iph->daddr, len,
-                       skb->nh.iph->protocol, 0);
+       fcb->flags = flags;
 }
 
-void gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
+void inline gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
 {
-       fcb->vln = 1;
+       fcb->flags |= TXFCB_VLN;
        fcb->vlctl = vlan_tx_tag_get(skb);
 }
 
@@ -908,6 +921,7 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
        struct gfar_private *priv = netdev_priv(dev);
        struct txfcb *fcb = NULL;
        struct txbd8 *txbdp;
+       u16 status;
 
        /* Update transmit stats */
        priv->stats.tx_bytes += skb->len;
@@ -919,19 +933,22 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
        txbdp = priv->cur_tx;
 
        /* Clear all but the WRAP status flags */
-       txbdp->status &= TXBD_WRAP;
+       status = txbdp->status & TXBD_WRAP;
 
        /* Set up checksumming */
-       if ((dev->features & NETIF_F_IP_CSUM)
-                       && (CHECKSUM_HW == skb->ip_summed)) {
+       if (likely((dev->features & NETIF_F_IP_CSUM)
+                       && (CHECKSUM_HW == skb->ip_summed))) {
                fcb = gfar_add_fcb(skb, txbdp);
+               status |= TXBD_TOE;
                gfar_tx_checksum(skb, fcb);
        }
 
        if (priv->vlan_enable &&
                        unlikely(priv->vlgrp && vlan_tx_tag_present(skb))) {
-               if (NULL == fcb)
+               if (unlikely(NULL == fcb)) {
                        fcb = gfar_add_fcb(skb, txbdp);
+                       status |= TXBD_TOE;
+               }
 
                gfar_tx_vlan(skb, fcb);
        }
@@ -949,14 +966,16 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
            (priv->skb_curtx + 1) & TX_RING_MOD_MASK(priv->tx_ring_size);
 
        /* Flag the BD as interrupt-causing */
-       txbdp->status |= TXBD_INTERRUPT;
+       status |= TXBD_INTERRUPT;
 
        /* Flag the BD as ready to go, last in frame, and  */
        /* in need of CRC */
-       txbdp->status |= (TXBD_READY | TXBD_LAST | TXBD_CRC);
+       status |= (TXBD_READY | TXBD_LAST | TXBD_CRC);
 
        dev->trans_start = jiffies;
 
+       txbdp->status = status;
+
        /* If this was the last BD in the ring, the next one */
        /* is at the beginning of the ring */
        if (txbdp->status & TXBD_WRAP)
@@ -1010,21 +1029,7 @@ static struct net_device_stats * gfar_get_stats(struct net_device *dev)
 /* Changes the mac address if the controller is not running. */
 int gfar_set_mac_address(struct net_device *dev)
 {
-       struct gfar_private *priv = netdev_priv(dev);
-       int i;
-       char tmpbuf[MAC_ADDR_LEN];
-       u32 tempval;
-
-       /* Now copy it into the mac registers backwards, cuz */
-       /* little endian is silly */
-       for (i = 0; i < MAC_ADDR_LEN; i++)
-               tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->dev_addr[i];
-
-       gfar_write(&priv->regs->macstnaddr1, *((u32 *) (tmpbuf)));
-
-       tempval = *((u32 *) (tmpbuf + 4));
-
-       gfar_write(&priv->regs->macstnaddr2, tempval);
+       gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
 
        return 0;
 }
@@ -1110,7 +1115,7 @@ static int gfar_change_mtu(struct net_device *dev, int new_mtu)
            INCREMENTAL_BUFFER_SIZE;
 
        /* Only stop and start the controller if it isn't already
-        * stopped */
+        * stopped, and we changed something */
        if ((oldsize != tempsize) && (dev->flags & IFF_UP))
                stop_gfar(dev);
 
@@ -1220,6 +1225,7 @@ static irqreturn_t gfar_transmit(int irq, void *dev_id, struct pt_regs *regs)
 
 struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp)
 {
+       unsigned int alignamount;
        struct gfar_private *priv = netdev_priv(dev);
        struct sk_buff *skb = NULL;
        unsigned int timeout = SKB_ALLOC_TIMEOUT;
@@ -1231,18 +1237,18 @@ struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp)
        if (NULL == skb)
                return NULL;
 
+       alignamount = RXBUF_ALIGNMENT -
+               (((unsigned) skb->data) & (RXBUF_ALIGNMENT - 1));
+
        /* We need the data buffer to be aligned properly.  We will reserve
         * as many bytes as needed to align the data properly
         */
-       skb_reserve(skb,
-                   RXBUF_ALIGNMENT -
-                   (((unsigned) skb->data) & (RXBUF_ALIGNMENT - 1)));
+       skb_reserve(skb, alignamount);
 
        skb->dev = dev;
 
        bdp->bufPtr = dma_map_single(NULL, skb->data,
-                       priv->rx_buffer_size + RXBUF_ALIGNMENT,
-                       DMA_FROM_DEVICE);
+                       priv->rx_buffer_size, DMA_FROM_DEVICE);
 
        bdp->length = 0;
 
@@ -1350,7 +1356,7 @@ static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb)
        /* If valid headers were found, and valid sums
         * were verified, then we tell the kernel that no
         * checksumming is necessary.  Otherwise, it is */
-       if (fcb->cip && !fcb->eip && fcb->ctu && !fcb->etu)
+       if ((fcb->flags & RXFCB_CSUM_MASK) == (RXFCB_CIP | RXFCB_CTU))
                skb->ip_summed = CHECKSUM_UNNECESSARY;
        else
                skb->ip_summed = CHECKSUM_NONE;
@@ -1401,7 +1407,7 @@ static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
                skb->protocol = eth_type_trans(skb, dev);
 
                /* Send the packet up the stack */
-               if (unlikely(priv->vlgrp && fcb->vln))
+               if (unlikely(priv->vlgrp && (fcb->flags & RXFCB_VLN)))
                        ret = gfar_rx_vlan(skb, priv->vlgrp, fcb->vlctl);
                else
                        ret = RECEIVE(skb);
@@ -1620,6 +1626,7 @@ static void adjust_link(struct net_device *dev)
        spin_lock_irqsave(&priv->lock, flags);
        if (phydev->link) {
                u32 tempval = gfar_read(&regs->maccfg2);
+               u32 ecntrl = gfar_read(&regs->ecntrl);
 
                /* Now we make sure that we can be in full duplex mode.
                 * If not, we operate in half-duplex mode. */
@@ -1644,6 +1651,13 @@ static void adjust_link(struct net_device *dev)
                        case 10:
                                tempval =
                                    ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII);
+
+                               /* Reduced mode distinguishes
+                                * between 10 and 100 */
+                               if (phydev->speed == SPEED_100)
+                                       ecntrl |= ECNTRL_R100;
+                               else
+                                       ecntrl &= ~(ECNTRL_R100);
                                break;
                        default:
                                if (netif_msg_link(priv))
@@ -1657,6 +1671,7 @@ static void adjust_link(struct net_device *dev)
                }
 
                gfar_write(&regs->maccfg2, tempval);
+               gfar_write(&regs->ecntrl, ecntrl);
 
                if (!priv->oldlink) {
                        new_state = 1;
@@ -1721,6 +1736,9 @@ static void gfar_set_multi(struct net_device *dev)
                gfar_write(&regs->gaddr6, 0xffffffff);
                gfar_write(&regs->gaddr7, 0xffffffff);
        } else {
+               int em_num;
+               int idx;
+
                /* zero out the hash */
                gfar_write(&regs->igaddr0, 0x0);
                gfar_write(&regs->igaddr1, 0x0);
@@ -1739,18 +1757,47 @@ static void gfar_set_multi(struct net_device *dev)
                gfar_write(&regs->gaddr6, 0x0);
                gfar_write(&regs->gaddr7, 0x0);
 
+               /* If we have extended hash tables, we need to
+                * clear the exact match registers to prepare for
+                * setting them */
+               if (priv->extended_hash) {
+                       em_num = GFAR_EM_NUM + 1;
+                       gfar_clear_exact_match(dev);
+                       idx = 1;
+               } else {
+                       idx = 0;
+                       em_num = 0;
+               }
+
                if(dev->mc_count == 0)
                        return;
 
                /* Parse the list, and set the appropriate bits */
                for(mc_ptr = dev->mc_list; mc_ptr; mc_ptr = mc_ptr->next) {
-                       gfar_set_hash_for_addr(dev, mc_ptr->dmi_addr);
+                       if (idx < em_num) {
+                               gfar_set_mac_for_addr(dev, idx,
+                                               mc_ptr->dmi_addr);
+                               idx++;
+                       } else
+                               gfar_set_hash_for_addr(dev, mc_ptr->dmi_addr);
                }
        }
 
        return;
 }
 
+
+/* Clears each of the exact match registers to zero, so they
+ * don't interfere with normal reception */
+static void gfar_clear_exact_match(struct net_device *dev)
+{
+       int idx;
+       u8 zero_arr[MAC_ADDR_LEN] = {0,0,0,0,0,0};
+
+       for(idx = 1;idx < GFAR_EM_NUM + 1;idx++)
+               gfar_set_mac_for_addr(dev, idx, (u8 *)zero_arr);
+}
+
 /* Set the appropriate hash bit for the given addr */
 /* The algorithm works like so:
  * 1) Take the Destination Address (ie the multicast address), and
@@ -1781,6 +1828,32 @@ static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
        return;
 }
 
+
+/* There are multiple MAC Address register pairs on some controllers
+ * This function sets the numth pair to a given address
+ */
+static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr)
+{
+       struct gfar_private *priv = netdev_priv(dev);
+       int idx;
+       char tmpbuf[MAC_ADDR_LEN];
+       u32 tempval;
+       u32 *macptr = &priv->regs->macstnaddr1;
+
+       macptr += num*2;
+
+       /* Now copy it into the mac registers backwards, cuz */
+       /* little endian is silly */
+       for (idx = 0; idx < MAC_ADDR_LEN; idx++)
+               tmpbuf[MAC_ADDR_LEN - 1 - idx] = addr[idx];
+
+       gfar_write(macptr, *((u32 *) (tmpbuf)));
+
+       tempval = *((u32 *) (tmpbuf + 4));
+
+       gfar_write(macptr+1, tempval);
+}
+
 /* GFAR error interrupt handler */
 static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs)
 {
index 5065ba82cb7608324d7b8d6f1a2a37a2b5b3fff2..94a91da84fbb7ac5abe74cd6e63332c48ca9afa5 100644 (file)
@@ -90,12 +90,26 @@ extern const char gfar_driver_version[];
 #define GFAR_RX_MAX_RING_SIZE   256
 #define GFAR_TX_MAX_RING_SIZE   256
 
+#define GFAR_MAX_FIFO_THRESHOLD 511
+#define GFAR_MAX_FIFO_STARVE   511
+#define GFAR_MAX_FIFO_STARVE_OFF 511
+
 #define DEFAULT_RX_BUFFER_SIZE  1536
 #define TX_RING_MOD_MASK(size) (size-1)
 #define RX_RING_MOD_MASK(size) (size-1)
 #define JUMBO_BUFFER_SIZE 9728
 #define JUMBO_FRAME_SIZE 9600
 
+#define DEFAULT_FIFO_TX_THR 0x100
+#define DEFAULT_FIFO_TX_STARVE 0x40
+#define DEFAULT_FIFO_TX_STARVE_OFF 0x80
+#define DEFAULT_BD_STASH 1
+#define DEFAULT_STASH_LENGTH   64
+#define DEFAULT_STASH_INDEX    0
+
+/* The number of Exact Match registers */
+#define GFAR_EM_NUM    15
+
 /* Latency of interface clock in nanoseconds */
 /* Interface clock latency , in this case, means the
  * time described by a value of 1 in the interrupt
@@ -112,11 +126,11 @@ extern const char gfar_driver_version[];
 
 #define DEFAULT_TX_COALESCE 1
 #define DEFAULT_TXCOUNT        16
-#define DEFAULT_TXTIME 400
+#define DEFAULT_TXTIME 4
 
 #define DEFAULT_RX_COALESCE 1
 #define DEFAULT_RXCOUNT        16
-#define DEFAULT_RXTIME 400
+#define DEFAULT_RXTIME 4
 
 #define TBIPA_VALUE            0x1f
 #define MIIMCFG_INIT_VALUE     0x00000007
@@ -147,6 +161,7 @@ extern const char gfar_driver_version[];
 
 #define ECNTRL_INIT_SETTINGS   0x00001000
 #define ECNTRL_TBI_MODE         0x00000020
+#define ECNTRL_R100            0x00000008
 
 #define MRBLR_INIT_SETTINGS    DEFAULT_RX_BUFFER_SIZE
 
@@ -181,10 +196,12 @@ extern const char gfar_driver_version[];
 #define RCTRL_PRSDEP_MASK      0x000000c0
 #define RCTRL_PRSDEP_INIT      0x000000c0
 #define RCTRL_PROM             0x00000008
+#define RCTRL_EMEN             0x00000002
 #define RCTRL_CHECKSUMMING     (RCTRL_IPCSEN \
                | RCTRL_TUCSEN | RCTRL_PRSDEP_INIT)
 #define RCTRL_EXTHASH          (RCTRL_GHTX)
 #define RCTRL_VLAN             (RCTRL_PRSDEP_INIT)
+#define RCTRL_PADDING(x)       ((x << 16) & RCTRL_PAL_MASK)
 
 
 #define RSTAT_CLEAR_RHALT       0x00800000
@@ -251,28 +268,26 @@ extern const char gfar_driver_version[];
                IMASK_XFUN | IMASK_RXC | IMASK_BABT | IMASK_DPE \
                | IMASK_PERR)
 
+/* Fifo management */
+#define FIFO_TX_THR_MASK       0x01ff
+#define FIFO_TX_STARVE_MASK    0x01ff
+#define FIFO_TX_STARVE_OFF_MASK        0x01ff
 
 /* Attribute fields */
 
 /* This enables rx snooping for buffers and descriptors */
-#ifdef CONFIG_GFAR_BDSTASH
 #define ATTR_BDSTASH           0x00000800
-#else
-#define ATTR_BDSTASH           0x00000000
-#endif
 
-#ifdef CONFIG_GFAR_BUFSTASH
 #define ATTR_BUFSTASH          0x00004000
-#define STASH_LENGTH           64
-#else
-#define ATTR_BUFSTASH          0x00000000
-#endif
 
 #define ATTR_SNOOPING          0x000000c0
-#define ATTR_INIT_SETTINGS      (ATTR_SNOOPING \
-               | ATTR_BDSTASH | ATTR_BUFSTASH)
+#define ATTR_INIT_SETTINGS      ATTR_SNOOPING
 
 #define ATTRELI_INIT_SETTINGS   0x0
+#define ATTRELI_EL_MASK                0x3fff0000
+#define ATTRELI_EL(x) (x << 16)
+#define ATTRELI_EI_MASK                0x00003fff
+#define ATTRELI_EI(x) (x)
 
 
 /* TxBD status field bits */
@@ -328,6 +343,7 @@ extern const char gfar_driver_version[];
 #define RXFCB_CTU              0x0400
 #define RXFCB_EIP              0x0200
 #define RXFCB_ETU              0x0100
+#define RXFCB_CSUM_MASK                0x0f00
 #define RXFCB_PERR_MASK                0x000c
 #define RXFCB_PERR_BADL3       0x0008
 
@@ -339,14 +355,7 @@ struct txbd8
 };
 
 struct txfcb {
-       u8      vln:1,
-               ip:1,
-               ip6:1,
-               tup:1,
-               udp:1,
-               cip:1,
-               ctu:1,
-               nph:1;
+       u8      flags;
        u8      reserved;
        u8      l4os;   /* Level 4 Header Offset */
        u8      l3os;   /* Level 3 Header Offset */
@@ -362,14 +371,7 @@ struct rxbd8
 };
 
 struct rxfcb {
-       u16     vln:1,
-               ip:1,
-               ip6:1,
-               tup:1,
-               cip:1,
-               ctu:1,
-               eip:1,
-               etu:1;
+       u16     flags;
        u8      rq;     /* Receive Queue index */
        u8      pro;    /* Layer 4 Protocol */
        u16     reserved;
@@ -688,12 +690,17 @@ struct gfar_private {
        spinlock_t lock;
        unsigned int rx_buffer_size;
        unsigned int rx_stash_size;
+       unsigned int rx_stash_index;
        unsigned int tx_ring_size;
        unsigned int rx_ring_size;
+       unsigned int fifo_threshold;
+       unsigned int fifo_starve;
+       unsigned int fifo_starve_off;
 
        unsigned char vlan_enable:1,
                rx_csum_enable:1,
-               extended_hash:1;
+               extended_hash:1,
+               bd_stash_en:1;
        unsigned short padding;
        struct vlan_group *vlgrp;
        /* Info structure initialized by board setup code */
@@ -731,6 +738,6 @@ extern void stop_gfar(struct net_device *dev);
 extern void gfar_halt(struct net_device *dev);
 extern void gfar_phy_test(struct mii_bus *bus, struct phy_device *phydev,
                int enable, u32 regnum, u32 read);
-void gfar_setup_stashing(struct net_device *dev);
+void gfar_init_sysfs(struct net_device *dev);
 
 #endif /* __GIANFAR_H */
index cfa3cd7c91a0a9c777851379e1c63d9eeae217a9..765e810620fe95f68834e7fede0019190609a494 100644 (file)
@@ -125,7 +125,7 @@ static char stat_gstrings[][ETH_GSTRING_LEN] = {
 static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
 {
        struct gfar_private *priv = netdev_priv(dev);
-       
+
        if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
                memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
        else
index e85eb216fb5be40464e1dfdf0402f77059bfeafb..d527cf2f9c1d7f47398eaac003b361e79428b38b 100644 (file)
@@ -24,6 +24,7 @@
 #define MII_READ_COMMAND       0x00000001
 
 #define GFAR_SUPPORTED (SUPPORTED_10baseT_Half \
+               | SUPPORTED_10baseT_Full \
                | SUPPORTED_100baseT_Half \
                | SUPPORTED_100baseT_Full \
                | SUPPORTED_Autoneg \
diff --git a/drivers/net/gianfar_sysfs.c b/drivers/net/gianfar_sysfs.c
new file mode 100644 (file)
index 0000000..10d34cb
--- /dev/null
@@ -0,0 +1,311 @@
+/*
+ * drivers/net/gianfar_sysfs.c
+ *
+ * Gianfar Ethernet Driver
+ * This driver is designed for the non-CPM ethernet controllers
+ * on the 85xx and 83xx family of integrated processors
+ * Based on 8260_io/fcc_enet.c
+ *
+ * Author: Andy Fleming
+ * Maintainer: Kumar Gala (kumar.gala@freescale.com)
+ *
+ * Copyright (c) 2002-2005 Freescale Semiconductor, Inc.
+ *
+ * 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.
+ *
+ * Sysfs file creation and management
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/unistd.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/etherdevice.h>
+#include <linux/spinlock.h>
+#include <linux/mm.h>
+#include <linux/device.h>
+
+#include <asm/uaccess.h>
+#include <linux/module.h>
+#include <linux/version.h>
+
+#include "gianfar.h"
+
+#define GFAR_ATTR(_name) \
+static ssize_t gfar_show_##_name(struct class_device *cdev, char *buf); \
+static ssize_t gfar_set_##_name(struct class_device *cdev, \
+               const char *buf, size_t count); \
+static CLASS_DEVICE_ATTR(_name, 0644, gfar_show_##_name, gfar_set_##_name)
+
+#define GFAR_CREATE_FILE(_dev, _name) \
+       class_device_create_file(&_dev->class_dev, &class_device_attr_##_name)
+
+GFAR_ATTR(bd_stash);
+GFAR_ATTR(rx_stash_size);
+GFAR_ATTR(rx_stash_index);
+GFAR_ATTR(fifo_threshold);
+GFAR_ATTR(fifo_starve);
+GFAR_ATTR(fifo_starve_off);
+
+#define to_net_dev(cd) container_of(cd, struct net_device, class_dev)
+
+static ssize_t gfar_show_bd_stash(struct class_device *cdev, char *buf)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+
+       return sprintf(buf, "%s\n", priv->bd_stash_en? "on" : "off");
+}
+
+static ssize_t gfar_set_bd_stash(struct class_device *cdev,
+               const char *buf, size_t count)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+       int new_setting = 0;
+       u32 temp;
+       unsigned long flags;
+
+       /* Find out the new setting */
+       if (!strncmp("on", buf, count-1) || !strncmp("1", buf, count-1))
+               new_setting = 1;
+       else if (!strncmp("off", buf, count-1) || !strncmp("0", buf, count-1))
+               new_setting = 0;
+       else
+               return count;
+
+       spin_lock_irqsave(&priv->lock, flags);
+
+       /* Set the new stashing value */
+       priv->bd_stash_en = new_setting;
+
+       temp = gfar_read(&priv->regs->attr);
+       
+       if (new_setting)
+               temp |= ATTR_BDSTASH;
+       else
+               temp &= ~(ATTR_BDSTASH);
+
+       gfar_write(&priv->regs->attr, temp);
+
+       spin_unlock_irqrestore(&priv->lock, flags);
+
+       return count;
+}
+
+static ssize_t gfar_show_rx_stash_size(struct class_device *cdev, char *buf)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+
+       return sprintf(buf, "%d\n", priv->rx_stash_size);
+}
+
+static ssize_t gfar_set_rx_stash_size(struct class_device *cdev,
+               const char *buf, size_t count)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+       unsigned int length = simple_strtoul(buf, NULL, 0);
+       u32 temp;
+       unsigned long flags;
+
+       spin_lock_irqsave(&priv->lock, flags);
+       if (length > priv->rx_buffer_size)
+               return count;
+
+       if (length == priv->rx_stash_size)
+               return count;
+
+       priv->rx_stash_size = length;
+
+       temp = gfar_read(&priv->regs->attreli);
+       temp &= ~ATTRELI_EL_MASK;
+       temp |= ATTRELI_EL(length);
+       gfar_write(&priv->regs->attreli, temp);
+
+       /* Turn stashing on/off as appropriate */
+       temp = gfar_read(&priv->regs->attr);
+
+       if (length)
+               temp |= ATTR_BUFSTASH;
+       else
+               temp &= ~(ATTR_BUFSTASH);
+
+       gfar_write(&priv->regs->attr, temp);
+
+       spin_unlock_irqrestore(&priv->lock, flags);
+
+       return count;
+}
+
+
+/* Stashing will only be enabled when rx_stash_size != 0 */
+static ssize_t gfar_show_rx_stash_index(struct class_device *cdev, char *buf)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+
+       return sprintf(buf, "%d\n", priv->rx_stash_index);
+}
+
+static ssize_t gfar_set_rx_stash_index(struct class_device *cdev,
+               const char *buf, size_t count)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+       unsigned short index = simple_strtoul(buf, NULL, 0);
+       u32 temp;
+       unsigned long flags;
+
+       spin_lock_irqsave(&priv->lock, flags);
+       if (index > priv->rx_stash_size)
+               return count;
+
+       if (index == priv->rx_stash_index)
+               return count;
+
+       priv->rx_stash_index = index;
+
+       temp = gfar_read(&priv->regs->attreli);
+       temp &= ~ATTRELI_EI_MASK;
+       temp |= ATTRELI_EI(index);
+       gfar_write(&priv->regs->attreli, flags);
+
+       spin_unlock_irqrestore(&priv->lock, flags);
+
+       return count;
+}
+
+static ssize_t gfar_show_fifo_threshold(struct class_device *cdev, char *buf)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+
+       return sprintf(buf, "%d\n", priv->fifo_threshold);
+}
+
+static ssize_t gfar_set_fifo_threshold(struct class_device *cdev,
+               const char *buf, size_t count)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+       unsigned int length = simple_strtoul(buf, NULL, 0);
+       u32 temp;
+       unsigned long flags;
+
+       if (length > GFAR_MAX_FIFO_THRESHOLD)
+               return count;
+
+       spin_lock_irqsave(&priv->lock, flags);
+
+       priv->fifo_threshold = length;
+
+       temp = gfar_read(&priv->regs->fifo_tx_thr);
+       temp &= ~FIFO_TX_THR_MASK;
+       temp |= length;
+       gfar_write(&priv->regs->fifo_tx_thr, temp);
+
+       spin_unlock_irqrestore(&priv->lock, flags);
+
+       return count;
+}
+
+static ssize_t gfar_show_fifo_starve(struct class_device *cdev, char *buf)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+
+       return sprintf(buf, "%d\n", priv->fifo_starve);
+}
+
+
+static ssize_t gfar_set_fifo_starve(struct class_device *cdev,
+               const char *buf, size_t count)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+       unsigned int num = simple_strtoul(buf, NULL, 0);
+       u32 temp;
+       unsigned long flags;
+
+       if (num > GFAR_MAX_FIFO_STARVE)
+               return count;
+
+       spin_lock_irqsave(&priv->lock, flags);
+
+       priv->fifo_starve = num;
+
+       temp = gfar_read(&priv->regs->fifo_tx_starve);
+       temp &= ~FIFO_TX_STARVE_MASK;
+       temp |= num;
+       gfar_write(&priv->regs->fifo_tx_starve, temp);
+
+       spin_unlock_irqrestore(&priv->lock, flags);
+
+       return count;
+}
+
+static ssize_t gfar_show_fifo_starve_off(struct class_device *cdev, char *buf)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+
+       return sprintf(buf, "%d\n", priv->fifo_starve_off);
+}
+
+static ssize_t gfar_set_fifo_starve_off(struct class_device *cdev,
+               const char *buf, size_t count)
+{
+       struct net_device *dev = to_net_dev(cdev);
+       struct gfar_private *priv = netdev_priv(dev);
+       unsigned int num = simple_strtoul(buf, NULL, 0);
+       u32 temp;
+       unsigned long flags;
+
+       if (num > GFAR_MAX_FIFO_STARVE_OFF)
+               return count;
+
+       spin_lock_irqsave(&priv->lock, flags);
+
+       priv->fifo_starve_off = num;
+
+       temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff);
+       temp &= ~FIFO_TX_STARVE_OFF_MASK;
+       temp |= num;
+       gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp);
+
+       spin_unlock_irqrestore(&priv->lock, flags);
+
+       return count;
+}
+
+void gfar_init_sysfs(struct net_device *dev)
+{
+       struct gfar_private *priv = netdev_priv(dev);
+
+       /* Initialize the default values */
+       priv->rx_stash_size = DEFAULT_STASH_LENGTH;
+       priv->rx_stash_index = DEFAULT_STASH_INDEX;
+       priv->fifo_threshold = DEFAULT_FIFO_TX_THR;
+       priv->fifo_starve = DEFAULT_FIFO_TX_STARVE;
+       priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF;
+       priv->bd_stash_en = DEFAULT_BD_STASH;
+
+       /* Create our sysfs files */
+       GFAR_CREATE_FILE(dev, bd_stash);
+       GFAR_CREATE_FILE(dev, rx_stash_size);
+       GFAR_CREATE_FILE(dev, rx_stash_index);
+       GFAR_CREATE_FILE(dev, fifo_threshold);
+       GFAR_CREATE_FILE(dev, fifo_starve);
+       GFAR_CREATE_FILE(dev, fifo_starve_off);
+
+}
diff --git a/drivers/net/ixp2000/Kconfig b/drivers/net/ixp2000/Kconfig
new file mode 100644 (file)
index 0000000..2fec241
--- /dev/null
@@ -0,0 +1,6 @@
+config ENP2611_MSF_NET
+       tristate "Radisys ENP2611 MSF network interface support"
+       depends on ARCH_ENP2611
+       help
+         This is a driver for the MSF network interface unit in
+         the IXP2400 on the Radisys ENP2611 platform.
diff --git a/drivers/net/ixp2000/Makefile b/drivers/net/ixp2000/Makefile
new file mode 100644 (file)
index 0000000..fd38351
--- /dev/null
@@ -0,0 +1,3 @@
+obj-$(CONFIG_ENP2611_MSF_NET) += enp2611_mod.o
+
+enp2611_mod-objs := caleb.o enp2611.o ixp2400-msf.o ixpdev.o pm3386.o
diff --git a/drivers/net/ixp2000/caleb.c b/drivers/net/ixp2000/caleb.c
new file mode 100644 (file)
index 0000000..3595e10
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Helper functions for the SPI-3 bridge FPGA on the Radisys ENP2611
+ * Copyright (C) 2004, 2005 Lennert Buytenhek <buytenh@wantstofly.org>
+ * Dedicated to Marija Kulikova.
+ *
+ * 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.
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <asm/io.h>
+#include "caleb.h"
+
+#define CALEB_IDLO             0x00
+#define CALEB_IDHI             0x01
+#define CALEB_RID              0x02
+#define CALEB_RESET            0x03
+#define CALEB_INTREN0          0x04
+#define CALEB_INTREN1          0x05
+#define CALEB_INTRSTAT0                0x06
+#define CALEB_INTRSTAT1                0x07
+#define CALEB_PORTEN           0x08
+#define CALEB_BURST            0x09
+#define CALEB_PORTPAUS         0x0A
+#define CALEB_PORTPAUSD                0x0B
+#define CALEB_PHY0RX           0x10
+#define CALEB_PHY1RX           0x11
+#define CALEB_PHY0TX           0x12
+#define CALEB_PHY1TX           0x13
+#define CALEB_IXPRX_HI_CNTR    0x15
+#define CALEB_PHY0RX_HI_CNTR   0x16
+#define CALEB_PHY1RX_HI_CNTR   0x17
+#define CALEB_IXPRX_CNTR       0x18
+#define CALEB_PHY0RX_CNTR      0x19
+#define CALEB_PHY1RX_CNTR      0x1A
+#define CALEB_IXPTX_CNTR       0x1B
+#define CALEB_PHY0TX_CNTR      0x1C
+#define CALEB_PHY1TX_CNTR      0x1D
+#define CALEB_DEBUG0           0x1E
+#define CALEB_DEBUG1           0x1F
+
+
+static u8 caleb_reg_read(int reg)
+{
+       u8 value;
+
+       value = *((volatile u8 *)(ENP2611_CALEB_VIRT_BASE + reg));
+
+//     printk(KERN_INFO "caleb_reg_read(%d) = %.2x\n", reg, value);
+
+       return value;
+}
+
+static void caleb_reg_write(int reg, u8 value)
+{
+       u8 dummy;
+
+//     printk(KERN_INFO "caleb_reg_write(%d, %.2x)\n", reg, value);
+
+       *((volatile u8 *)(ENP2611_CALEB_VIRT_BASE + reg)) = value;
+
+       dummy = *((volatile u8 *)ENP2611_CALEB_VIRT_BASE);
+       __asm__ __volatile__("mov %0, %0" : "+r" (dummy));
+}
+
+
+void caleb_reset(void)
+{
+       /*
+        * Perform a chip reset.
+        */
+       caleb_reg_write(CALEB_RESET, 0x02);
+       udelay(1);
+
+       /*
+        * Enable all interrupt sources.  This is needed to get
+        * meaningful results out of the status bits (register 6
+        * and 7.)
+        */
+       caleb_reg_write(CALEB_INTREN0, 0xff);
+       caleb_reg_write(CALEB_INTREN1, 0x07);
+
+       /*
+        * Set RX and TX FIFO thresholds to 1.5kb.
+        */
+       caleb_reg_write(CALEB_PHY0RX, 0x11);
+       caleb_reg_write(CALEB_PHY1RX, 0x11);
+       caleb_reg_write(CALEB_PHY0TX, 0x11);
+       caleb_reg_write(CALEB_PHY1TX, 0x11);
+
+       /*
+        * Program SPI-3 burst size.
+        */
+       caleb_reg_write(CALEB_BURST, 0);        // 64-byte RBUF mpackets
+//     caleb_reg_write(CALEB_BURST, 1);        // 128-byte RBUF mpackets
+//     caleb_reg_write(CALEB_BURST, 2);        // 256-byte RBUF mpackets
+}
+
+void caleb_enable_rx(int port)
+{
+       u8 temp;
+
+       temp = caleb_reg_read(CALEB_PORTEN);
+       temp |= 1 << port;
+       caleb_reg_write(CALEB_PORTEN, temp);
+}
+
+void caleb_disable_rx(int port)
+{
+       u8 temp;
+
+       temp = caleb_reg_read(CALEB_PORTEN);
+       temp &= ~(1 << port);
+       caleb_reg_write(CALEB_PORTEN, temp);
+}
+
+void caleb_enable_tx(int port)
+{
+       u8 temp;
+
+       temp = caleb_reg_read(CALEB_PORTEN);
+       temp |= 1 << (port + 4);
+       caleb_reg_write(CALEB_PORTEN, temp);
+}
+
+void caleb_disable_tx(int port)
+{
+       u8 temp;
+
+       temp = caleb_reg_read(CALEB_PORTEN);
+       temp &= ~(1 << (port + 4));
+       caleb_reg_write(CALEB_PORTEN, temp);
+}
diff --git a/drivers/net/ixp2000/caleb.h b/drivers/net/ixp2000/caleb.h
new file mode 100644 (file)
index 0000000..e93a1ef
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Helper functions for the SPI-3 bridge FPGA on the Radisys ENP2611
+ * Copyright (C) 2004, 2005 Lennert Buytenhek <buytenh@wantstofly.org>
+ * Dedicated to Marija Kulikova.
+ *
+ * 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.
+ */
+
+#ifndef __CALEB_H
+#define __CALEB_H
+
+void caleb_reset(void);
+void caleb_enable_rx(int port);
+void caleb_disable_rx(int port);
+void caleb_enable_tx(int port);
+void caleb_disable_tx(int port);
+
+
+#endif
diff --git a/drivers/net/ixp2000/enp2611.c b/drivers/net/ixp2000/enp2611.c
new file mode 100644 (file)
index 0000000..d82651a
--- /dev/null
@@ -0,0 +1,245 @@
+/*
+ * IXP2400 MSF network device driver for the Radisys ENP2611
+ * Copyright (C) 2004, 2005 Lennert Buytenhek <buytenh@wantstofly.org>
+ * Dedicated to Marija Kulikova.
+ *
+ * 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.
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/init.h>
+#include <linux/moduleparam.h>
+#include <asm/arch/uengine.h>
+#include <asm/mach-types.h>
+#include <asm/io.h>
+#include "ixpdev.h"
+#include "caleb.h"
+#include "ixp2400-msf.h"
+#include "pm3386.h"
+
+/***********************************************************************
+ * The Radisys ENP2611 is a PCI form factor board with three SFP GBIC
+ * slots, connected via two PMC/Sierra 3386s and an SPI-3 bridge FPGA
+ * to the IXP2400.
+ *
+ *                +-------------+
+ * SFP GBIC #0 ---+             |       +---------+
+ *                |  PM3386 #0  +-------+         |
+ * SFP GBIC #1 ---+             |       | "Caleb" |         +---------+
+ *                +-------------+       |         |         |         |
+ *                                      | SPI-3   +---------+ IXP2400 |
+ *                +-------------+       | bridge  |         |         |
+ * SFP GBIC #2 ---+             |       | FPGA    |         +---------+
+ *                |  PM3386 #1  +-------+         |
+ *                |             |       +---------+
+ *                +-------------+
+ *              ^                   ^                  ^
+ *              | 1.25Gbaud         | 104MHz           | 104MHz
+ *              | SERDES ea.        | SPI-3 ea.        | SPI-3
+ *
+ ***********************************************************************/
+static struct ixp2400_msf_parameters enp2611_msf_parameters =
+{
+       .rx_mode =              IXP2400_RX_MODE_UTOPIA_POS |
+                               IXP2400_RX_MODE_1x32 |
+                               IXP2400_RX_MODE_MPHY |
+                               IXP2400_RX_MODE_MPHY_32 |
+                               IXP2400_RX_MODE_MPHY_POLLED_STATUS |
+                               IXP2400_RX_MODE_MPHY_LEVEL3 |
+                               IXP2400_RX_MODE_RBUF_SIZE_64,
+
+       .rxclk01_multiplier =   IXP2400_PLL_MULTIPLIER_16,
+
+       .rx_poll_ports =        3,
+
+       .rx_channel_mode = {
+               IXP2400_PORT_RX_MODE_MASTER |
+               IXP2400_PORT_RX_MODE_POS_PHY |
+               IXP2400_PORT_RX_MODE_POS_PHY_L3 |
+               IXP2400_PORT_RX_MODE_ODD_PARITY |
+               IXP2400_PORT_RX_MODE_2_CYCLE_DECODE,
+
+               IXP2400_PORT_RX_MODE_MASTER |
+               IXP2400_PORT_RX_MODE_POS_PHY |
+               IXP2400_PORT_RX_MODE_POS_PHY_L3 |
+               IXP2400_PORT_RX_MODE_ODD_PARITY |
+               IXP2400_PORT_RX_MODE_2_CYCLE_DECODE,
+
+               IXP2400_PORT_RX_MODE_MASTER |
+               IXP2400_PORT_RX_MODE_POS_PHY |
+               IXP2400_PORT_RX_MODE_POS_PHY_L3 |
+               IXP2400_PORT_RX_MODE_ODD_PARITY |
+               IXP2400_PORT_RX_MODE_2_CYCLE_DECODE,
+
+               IXP2400_PORT_RX_MODE_MASTER |
+               IXP2400_PORT_RX_MODE_POS_PHY |
+               IXP2400_PORT_RX_MODE_POS_PHY_L3 |
+               IXP2400_PORT_RX_MODE_ODD_PARITY |
+               IXP2400_PORT_RX_MODE_2_CYCLE_DECODE
+       },
+
+       .tx_mode =              IXP2400_TX_MODE_UTOPIA_POS |
+                               IXP2400_TX_MODE_1x32 |
+                               IXP2400_TX_MODE_MPHY |
+                               IXP2400_TX_MODE_MPHY_32 |
+                               IXP2400_TX_MODE_MPHY_POLLED_STATUS |
+                               IXP2400_TX_MODE_MPHY_LEVEL3 |
+                               IXP2400_TX_MODE_TBUF_SIZE_64,
+
+       .txclk01_multiplier =   IXP2400_PLL_MULTIPLIER_16,
+
+       .tx_poll_ports =        3,
+
+       .tx_channel_mode = {
+               IXP2400_PORT_TX_MODE_MASTER |
+               IXP2400_PORT_TX_MODE_POS_PHY |
+               IXP2400_PORT_TX_MODE_ODD_PARITY |
+               IXP2400_PORT_TX_MODE_2_CYCLE_DECODE,
+
+               IXP2400_PORT_TX_MODE_MASTER |
+               IXP2400_PORT_TX_MODE_POS_PHY |
+               IXP2400_PORT_TX_MODE_ODD_PARITY |
+               IXP2400_PORT_TX_MODE_2_CYCLE_DECODE,
+
+               IXP2400_PORT_TX_MODE_MASTER |
+               IXP2400_PORT_TX_MODE_POS_PHY |
+               IXP2400_PORT_TX_MODE_ODD_PARITY |
+               IXP2400_PORT_TX_MODE_2_CYCLE_DECODE,
+
+               IXP2400_PORT_TX_MODE_MASTER |
+               IXP2400_PORT_TX_MODE_POS_PHY |
+               IXP2400_PORT_TX_MODE_ODD_PARITY |
+               IXP2400_PORT_TX_MODE_2_CYCLE_DECODE
+       }
+};
+
+struct enp2611_ixpdev_priv
+{
+       struct ixpdev_priv              ixpdev_priv;
+       struct net_device_stats         stats;
+};
+
+static struct net_device *nds[3];
+static struct timer_list link_check_timer;
+
+static struct net_device_stats *enp2611_get_stats(struct net_device *dev)
+{
+       struct enp2611_ixpdev_priv *ip = netdev_priv(dev);
+
+       pm3386_get_stats(ip->ixpdev_priv.channel, &(ip->stats));
+
+       return &(ip->stats);
+}
+
+/* @@@ Poll the SFP moddef0 line too.  */
+/* @@@ Try to use the pm3386 DOOL interrupt as well.  */
+static void enp2611_check_link_status(unsigned long __dummy)
+{
+       int i;
+
+       for (i = 0; i < 3; i++) {
+               struct net_device *dev;
+               int status;
+
+               dev = nds[i];
+
+               status = pm3386_is_link_up(i);
+               if (status && !netif_carrier_ok(dev)) {
+                       /* @@@ Should report autonegotiation status.  */
+                       printk(KERN_INFO "%s: NIC Link is Up\n", dev->name);
+
+                       pm3386_enable_tx(i);
+                       caleb_enable_tx(i);
+                       netif_carrier_on(dev);
+               } else if (!status && netif_carrier_ok(dev)) {
+                       printk(KERN_INFO "%s: NIC Link is Down\n", dev->name);
+
+                       netif_carrier_off(dev);
+                       caleb_disable_tx(i);
+                       pm3386_disable_tx(i);
+               }
+       }
+
+       link_check_timer.expires = jiffies + HZ / 10;
+       add_timer(&link_check_timer);
+}
+
+static void enp2611_set_port_admin_status(int port, int up)
+{
+       if (up) {
+               caleb_enable_rx(port);
+
+               pm3386_set_carrier(port, 1);
+               pm3386_enable_rx(port);
+       } else {
+               caleb_disable_tx(port);
+               pm3386_disable_tx(port);
+               /* @@@ Flush out pending packets.  */
+               pm3386_set_carrier(port, 0);
+
+               pm3386_disable_rx(port);
+               caleb_disable_rx(port);
+       }
+}
+
+static int __init enp2611_init_module(void)
+{ 
+       int i;
+
+       if (!machine_is_enp2611())
+               return -ENODEV;
+
+       caleb_reset();
+       pm3386_reset();
+
+       for (i = 0; i < 3; i++) {
+               nds[i] = ixpdev_alloc(i, sizeof(struct enp2611_ixpdev_priv));
+               if (nds[i] == NULL) {
+                       while (--i >= 0)
+                               free_netdev(nds[i]);
+                       return -ENOMEM;
+               }
+
+               SET_MODULE_OWNER(nds[i]);
+               nds[i]->get_stats = enp2611_get_stats;
+               pm3386_init_port(i);
+               pm3386_get_mac(i, nds[i]->dev_addr);
+       }
+
+       ixp2400_msf_init(&enp2611_msf_parameters);
+
+       if (ixpdev_init(3, nds, enp2611_set_port_admin_status)) {
+               for (i = 0; i < 3; i++)
+                       free_netdev(nds[i]);
+               return -EINVAL;
+       }
+
+       init_timer(&link_check_timer);
+       link_check_timer.function = enp2611_check_link_status;
+       link_check_timer.expires = jiffies;
+       add_timer(&link_check_timer);
+
+       return 0;
+}
+
+static void __exit enp2611_cleanup_module(void)
+{
+       int i;
+
+       del_timer_sync(&link_check_timer);
+
+       ixpdev_deinit();
+       for (i = 0; i < 3; i++)
+               free_netdev(nds[i]);
+}
+
+module_init(enp2611_init_module);
+module_exit(enp2611_cleanup_module);
+MODULE_LICENSE("GPL");
diff --git a/drivers/net/ixp2000/ixp2400-msf.c b/drivers/net/ixp2000/ixp2400-msf.c
new file mode 100644 (file)
index 0000000..48a3a89
--- /dev/null
@@ -0,0 +1,213 @@
+/*
+ * Generic library functions for the MSF (Media and Switch Fabric) unit
+ * found on the Intel IXP2400 network processor.
+ *
+ * Copyright (C) 2004, 2005 Lennert Buytenhek <buytenh@wantstofly.org>
+ * Dedicated to Marija Kulikova.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <asm/hardware.h>
+#include <asm/arch/ixp2000-regs.h>
+#include <asm/delay.h>
+#include <asm/io.h>
+#include "ixp2400-msf.h"
+
+/*
+ * This is the Intel recommended PLL init procedure as described on
+ * page 340 of the IXP2400/IXP2800 Programmer's Reference Manual.
+ */
+static void ixp2400_pll_init(struct ixp2400_msf_parameters *mp)
+{
+       int rx_dual_clock;
+       int tx_dual_clock;
+       u32 value;
+
+       /*
+        * If the RX mode is not 1x32, we have to enable both RX PLLs
+        * (#0 and #1.)  The same thing for the TX direction.
+        */
+       rx_dual_clock = !!(mp->rx_mode & IXP2400_RX_MODE_WIDTH_MASK);
+       tx_dual_clock = !!(mp->tx_mode & IXP2400_TX_MODE_WIDTH_MASK);
+
+       /*
+        * Read initial value.
+        */
+       value = ixp2000_reg_read(IXP2000_MSF_CLK_CNTRL);
+
+       /*
+        * Put PLLs in powerdown and bypass mode.
+        */
+       value |= 0x0000f0f0;
+       ixp2000_reg_write(IXP2000_MSF_CLK_CNTRL, value);
+
+       /*
+        * Set single or dual clock mode bits.
+        */
+       value &= ~0x03000000;
+       value |= (rx_dual_clock << 24) | (tx_dual_clock << 25);
+
+       /*
+        * Set multipliers.
+        */
+       value &= ~0x00ff0000;
+       value |= mp->rxclk01_multiplier << 16;
+       value |= mp->rxclk23_multiplier << 18;
+       value |= mp->txclk01_multiplier << 20;
+       value |= mp->txclk23_multiplier << 22;
+
+       /*
+        * And write value.
+        */
+       ixp2000_reg_write(IXP2000_MSF_CLK_CNTRL, value);
+
+       /*
+        * Disable PLL bypass mode.
+        */
+       value &= ~(0x00005000 | rx_dual_clock << 13 | tx_dual_clock << 15);
+       ixp2000_reg_write(IXP2000_MSF_CLK_CNTRL, value);
+
+       /*
+        * Turn on PLLs.
+        */
+       value &= ~(0x00000050 | rx_dual_clock << 5 | tx_dual_clock << 7);
+       ixp2000_reg_write(IXP2000_MSF_CLK_CNTRL, value);
+
+       /*
+        * Wait for PLLs to lock.  There are lock status bits, but IXP2400
+        * erratum #65 says that these lock bits should not be relied upon
+        * as they might not accurately reflect the true state of the PLLs.
+        */
+       udelay(100);
+}
+
+/*
+ * Needed according to p480 of Programmer's Reference Manual.
+ */
+static void ixp2400_msf_free_rbuf_entries(struct ixp2400_msf_parameters *mp)
+{
+       int size_bits;
+       int i;
+
+       /*
+        * Work around IXP2400 erratum #69 (silent RBUF-to-DRAM transfer
+        * corruption) in the Intel-recommended way: do not add the RBUF
+        * elements susceptible to corruption to the freelist.
+        */
+       size_bits = mp->rx_mode & IXP2400_RX_MODE_RBUF_SIZE_MASK;
+       if (size_bits == IXP2400_RX_MODE_RBUF_SIZE_64) {
+               for (i = 1; i < 128; i++) {
+                       if (i == 9 || i == 18 || i == 27)
+                               continue;
+                       ixp2000_reg_write(IXP2000_MSF_RBUF_ELEMENT_DONE, i);
+               }
+       } else if (size_bits == IXP2400_RX_MODE_RBUF_SIZE_128) {
+               for (i = 1; i < 64; i++) {
+                       if (i == 4 || i == 9 || i == 13)
+                               continue;
+                       ixp2000_reg_write(IXP2000_MSF_RBUF_ELEMENT_DONE, i);
+               }
+       } else if (size_bits == IXP2400_RX_MODE_RBUF_SIZE_256) {
+               for (i = 1; i < 32; i++) {
+                       if (i == 2 || i == 4 || i == 6)
+                               continue;
+                       ixp2000_reg_write(IXP2000_MSF_RBUF_ELEMENT_DONE, i);
+               }
+       }
+}
+
+static u32 ixp2400_msf_valid_channels(u32 reg)
+{
+       u32 channels;
+
+       channels = 0;
+       switch (reg & IXP2400_RX_MODE_WIDTH_MASK) {
+       case IXP2400_RX_MODE_1x32:
+               channels = 0x1;
+               if (reg & IXP2400_RX_MODE_MPHY &&
+                   !(reg & IXP2400_RX_MODE_MPHY_32))
+                       channels = 0xf;
+               break;
+
+       case IXP2400_RX_MODE_2x16:
+               channels = 0x5;
+               break;
+
+       case IXP2400_RX_MODE_4x8:
+               channels = 0xf;
+               break;
+
+       case IXP2400_RX_MODE_1x16_2x8:
+               channels = 0xd;
+               break;
+       }
+
+       return channels;
+}
+
+static void ixp2400_msf_enable_rx(struct ixp2400_msf_parameters *mp)
+{
+       u32 value;
+
+       value = ixp2000_reg_read(IXP2000_MSF_RX_CONTROL) & 0x0fffffff;
+       value |= ixp2400_msf_valid_channels(mp->rx_mode) << 28;
+       ixp2000_reg_write(IXP2000_MSF_RX_CONTROL, value);
+}
+
+static void ixp2400_msf_enable_tx(struct ixp2400_msf_parameters *mp)
+{
+       u32 value;
+
+       value = ixp2000_reg_read(IXP2000_MSF_TX_CONTROL) & 0x0fffffff;
+       value |= ixp2400_msf_valid_channels(mp->tx_mode) << 28;
+       ixp2000_reg_write(IXP2000_MSF_TX_CONTROL, value);
+}
+
+
+void ixp2400_msf_init(struct ixp2400_msf_parameters *mp)
+{
+       u32 value;
+       int i;
+
+       /*
+        * Init the RX/TX PLLs based on the passed parameter block.
+        */
+       ixp2400_pll_init(mp);
+
+       /*
+        * Reset MSF.  Bit 7 in IXP_RESET_0 resets the MSF.
+        */
+       value = ixp2000_reg_read(IXP2000_RESET0);
+       ixp2000_reg_write(IXP2000_RESET0, value | 0x80);
+       ixp2000_reg_write(IXP2000_RESET0, value & ~0x80);
+
+       /*
+        * Initialise the RX section.
+        */
+       ixp2000_reg_write(IXP2000_MSF_RX_MPHY_POLL_LIMIT, mp->rx_poll_ports - 1);
+       ixp2000_reg_write(IXP2000_MSF_RX_CONTROL, mp->rx_mode);
+       for (i = 0; i < 4; i++) {
+               ixp2000_reg_write(IXP2000_MSF_RX_UP_CONTROL_0 + i,
+                                               mp->rx_channel_mode[i]);
+       }
+       ixp2400_msf_free_rbuf_entries(mp);
+       ixp2400_msf_enable_rx(mp);
+
+       /*
+        * Initialise the TX section.
+        */
+       ixp2000_reg_write(IXP2000_MSF_TX_MPHY_POLL_LIMIT, mp->tx_poll_ports - 1);
+       ixp2000_reg_write(IXP2000_MSF_TX_CONTROL, mp->tx_mode);
+       for (i = 0; i < 4; i++) {
+               ixp2000_reg_write(IXP2000_MSF_TX_UP_CONTROL_0 + i,
+                                               mp->tx_channel_mode[i]);
+       }
+       ixp2400_msf_enable_tx(mp);
+}
diff --git a/drivers/net/ixp2000/ixp2400-msf.h b/drivers/net/ixp2000/ixp2400-msf.h
new file mode 100644 (file)
index 0000000..3ac1af2
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Generic library functions for the MSF (Media and Switch Fabric) unit
+ * found on the Intel IXP2400 network processor.
+ *
+ * Copyright (C) 2004, 2005 Lennert Buytenhek <buytenh@wantstofly.org>
+ * Dedicated to Marija Kulikova.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ */
+
+#ifndef __IXP2400_MSF_H
+#define __IXP2400_MSF_H
+
+struct ixp2400_msf_parameters
+{
+       u32                             rx_mode;
+       unsigned                        rxclk01_multiplier:2;
+       unsigned                        rxclk23_multiplier:2;
+       unsigned                        rx_poll_ports:6;
+       u32                             rx_channel_mode[4];
+
+       u32                             tx_mode;
+       unsigned                        txclk01_multiplier:2;
+       unsigned                        txclk23_multiplier:2;
+       unsigned                        tx_poll_ports:6;
+       u32                             tx_channel_mode[4];
+};
+
+void ixp2400_msf_init(struct ixp2400_msf_parameters *mp);
+
+#define IXP2400_PLL_MULTIPLIER_48              0x00
+#define IXP2400_PLL_MULTIPLIER_24              0x01
+#define IXP2400_PLL_MULTIPLIER_16              0x02
+#define IXP2400_PLL_MULTIPLIER_12              0x03
+
+#define IXP2400_RX_MODE_CSIX                   0x00400000
+#define IXP2400_RX_MODE_UTOPIA_POS             0x00000000
+#define IXP2400_RX_MODE_WIDTH_MASK             0x00300000
+#define IXP2400_RX_MODE_1x16_2x8               0x00300000
+#define IXP2400_RX_MODE_4x8                    0x00200000
+#define IXP2400_RX_MODE_2x16                   0x00100000
+#define IXP2400_RX_MODE_1x32                   0x00000000
+#define IXP2400_RX_MODE_MPHY                   0x00080000
+#define IXP2400_RX_MODE_SPHY                   0x00000000
+#define IXP2400_RX_MODE_MPHY_32                        0x00040000
+#define IXP2400_RX_MODE_MPHY_4                 0x00000000
+#define IXP2400_RX_MODE_MPHY_POLLED_STATUS     0x00020000
+#define IXP2400_RX_MODE_MPHY_DIRECT_STATUS     0x00000000
+#define IXP2400_RX_MODE_CBUS_FULL_DUPLEX       0x00010000
+#define IXP2400_RX_MODE_CBUS_SIMPLEX           0x00000000
+#define IXP2400_RX_MODE_MPHY_LEVEL2            0x00004000
+#define IXP2400_RX_MODE_MPHY_LEVEL3            0x00000000
+#define IXP2400_RX_MODE_CBUS_8BIT              0x00002000
+#define IXP2400_RX_MODE_CBUS_4BIT              0x00000000
+#define IXP2400_RX_MODE_CSIX_SINGLE_FREELIST   0x00000200
+#define IXP2400_RX_MODE_CSIX_SPLIT_FREELISTS   0x00000000
+#define IXP2400_RX_MODE_RBUF_SIZE_MASK         0x0000000c
+#define IXP2400_RX_MODE_RBUF_SIZE_256          0x00000008
+#define IXP2400_RX_MODE_RBUF_SIZE_128          0x00000004
+#define IXP2400_RX_MODE_RBUF_SIZE_64           0x00000000
+
+#define IXP2400_PORT_RX_MODE_SLAVE             0x00000040
+#define IXP2400_PORT_RX_MODE_MASTER            0x00000000
+#define IXP2400_PORT_RX_MODE_POS_PHY_L3                0x00000020
+#define IXP2400_PORT_RX_MODE_POS_PHY_L2                0x00000000
+#define IXP2400_PORT_RX_MODE_POS_PHY           0x00000010
+#define IXP2400_PORT_RX_MODE_UTOPIA            0x00000000
+#define IXP2400_PORT_RX_MODE_EVEN_PARITY       0x0000000c
+#define IXP2400_PORT_RX_MODE_ODD_PARITY                0x00000008
+#define IXP2400_PORT_RX_MODE_NO_PARITY         0x00000000
+#define IXP2400_PORT_RX_MODE_UTOPIA_BIG_CELLS  0x00000002
+#define IXP2400_PORT_RX_MODE_UTOPIA_NORMAL_CELLS       0x00000000
+#define IXP2400_PORT_RX_MODE_2_CYCLE_DECODE    0x00000001
+#define IXP2400_PORT_RX_MODE_1_CYCLE_DECODE    0x00000000
+
+#define IXP2400_TX_MODE_CSIX                   0x00400000
+#define IXP2400_TX_MODE_UTOPIA_POS             0x00000000
+#define IXP2400_TX_MODE_WIDTH_MASK             0x00300000
+#define IXP2400_TX_MODE_1x16_2x8               0x00300000
+#define IXP2400_TX_MODE_4x8                    0x00200000
+#define IXP2400_TX_MODE_2x16                   0x00100000
+#define IXP2400_TX_MODE_1x32                   0x00000000
+#define IXP2400_TX_MODE_MPHY                   0x00080000
+#define IXP2400_TX_MODE_SPHY                   0x00000000
+#define IXP2400_TX_MODE_MPHY_32                        0x00040000
+#define IXP2400_TX_MODE_MPHY_4                 0x00000000
+#define IXP2400_TX_MODE_MPHY_POLLED_STATUS     0x00020000
+#define IXP2400_TX_MODE_MPHY_DIRECT_STATUS     0x00000000
+#define IXP2400_TX_MODE_CBUS_FULL_DUPLEX       0x00010000
+#define IXP2400_TX_MODE_CBUS_SIMPLEX           0x00000000
+#define IXP2400_TX_MODE_MPHY_LEVEL2            0x00004000
+#define IXP2400_TX_MODE_MPHY_LEVEL3            0x00000000
+#define IXP2400_TX_MODE_CBUS_8BIT              0x00002000
+#define IXP2400_TX_MODE_CBUS_4BIT              0x00000000
+#define IXP2400_TX_MODE_TBUF_SIZE_MASK         0x0000000c
+#define IXP2400_TX_MODE_TBUF_SIZE_256          0x00000008
+#define IXP2400_TX_MODE_TBUF_SIZE_128          0x00000004
+#define IXP2400_TX_MODE_TBUF_SIZE_64           0x00000000
+
+#define IXP2400_PORT_TX_MODE_SLAVE             0x00000040
+#define IXP2400_PORT_TX_MODE_MASTER            0x00000000
+#define IXP2400_PORT_TX_MODE_POS_PHY           0x00000010
+#define IXP2400_PORT_TX_MODE_UTOPIA            0x00000000
+#define IXP2400_PORT_TX_MODE_EVEN_PARITY       0x0000000c
+#define IXP2400_PORT_TX_MODE_ODD_PARITY                0x00000008
+#define IXP2400_PORT_TX_MODE_NO_PARITY         0x00000000
+#define IXP2400_PORT_TX_MODE_UTOPIA_BIG_CELLS  0x00000002
+#define IXP2400_PORT_TX_MODE_2_CYCLE_DECODE    0x00000001
+#define IXP2400_PORT_TX_MODE_1_CYCLE_DECODE    0x00000000
+
+
+#endif
diff --git a/drivers/net/ixp2000/ixp2400_rx.uc b/drivers/net/ixp2000/ixp2400_rx.uc
new file mode 100644 (file)
index 0000000..42a73e3
--- /dev/null
@@ -0,0 +1,408 @@
+/*
+ * RX ucode for the Intel IXP2400 in POS-PHY mode.
+ * Copyright (C) 2004, 2005 Lennert Buytenhek
+ * Dedicated to Marija Kulikova.
+ *
+ * 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.
+ *
+ * Assumptions made in this code:
+ * - The IXP2400 MSF is configured for POS-PHY mode, in a mode where
+ *   only one full element list is used.  This includes, for example,
+ *   1x32 SPHY and 1x32 MPHY32, but not 4x8 SPHY or 1x32 MPHY4.  (This
+ *   is not an exhaustive list.)
+ * - The RBUF uses 64-byte mpackets.
+ * - RX descriptors reside in SRAM, and have the following format:
+ *     struct rx_desc
+ *     {
+ *     // to uengine
+ *             u32     buf_phys_addr;
+ *             u32     buf_length;
+ *
+ *     // from uengine
+ *             u32     channel;
+ *             u32     pkt_length;
+ *     };
+ * - Packet data resides in DRAM.
+ * - Packet buffer addresses are 8-byte aligned.
+ * - Scratch ring 0 is rx_pending.
+ * - Scratch ring 1 is rx_done, and has status condition 'full'.
+ * - The host triggers rx_done flush and rx_pending refill on seeing INTA.
+ * - This code is run on all eight threads of the microengine it runs on.
+ *
+ * Local memory is used for per-channel RX state.
+ */
+
+#define RX_THREAD_FREELIST_0           0x0030
+#define RBUF_ELEMENT_DONE              0x0044
+
+#define CHANNEL_FLAGS                  *l$index0[0]
+#define CHANNEL_FLAG_RECEIVING         1
+#define PACKET_LENGTH                  *l$index0[1]
+#define PACKET_CHECKSUM                        *l$index0[2]
+#define BUFFER_HANDLE                  *l$index0[3]
+#define BUFFER_START                   *l$index0[4]
+#define BUFFER_LENGTH                  *l$index0[5]
+
+#define CHANNEL_STATE_SIZE             24      // in bytes
+#define CHANNEL_STATE_SHIFT            5       // ceil(log2(state size))
+
+
+       .sig volatile sig1
+       .sig volatile sig2
+       .sig volatile sig3
+
+       .sig mpacket_arrived
+       .reg add_to_rx_freelist
+       .reg read $rsw0, $rsw1
+       .xfer_order $rsw0 $rsw1
+
+       .reg zero
+
+       /*
+        * Initialise add_to_rx_freelist.
+        */
+       .begin
+               .reg temp
+               .reg temp2
+
+               immed[add_to_rx_freelist, RX_THREAD_FREELIST_0]
+               immed_w1[add_to_rx_freelist, (&$rsw0 | (&mpacket_arrived << 12))]
+
+               local_csr_rd[ACTIVE_CTX_STS]
+               immed[temp, 0]
+               alu[temp2, temp, and, 0x1f]
+               alu_shf[add_to_rx_freelist, add_to_rx_freelist, or, temp2, <<20]
+               alu[temp2, temp, and, 0x80]
+               alu_shf[add_to_rx_freelist, add_to_rx_freelist, or, temp2, <<18]
+       .end
+
+       immed[zero, 0]
+
+       /*
+        * Skip context 0 initialisation?
+        */
+       .begin
+               br!=ctx[0, mpacket_receive_loop#]
+       .end
+
+       /*
+        * Initialise local memory.
+        */
+       .begin
+               .reg addr
+               .reg temp
+
+               immed[temp, 0]
+       init_local_mem_loop#:
+               alu_shf[addr, --, b, temp, <<CHANNEL_STATE_SHIFT]
+               local_csr_wr[ACTIVE_LM_ADDR_0, addr]
+               nop
+               nop
+               nop
+
+               immed[CHANNEL_FLAGS, 0]
+
+               alu[temp, temp, +, 1]
+               alu[--, temp, and, 0x20]
+               beq[init_local_mem_loop#]
+       .end
+
+       /*
+        * Initialise signal pipeline.
+        */
+       .begin
+               local_csr_wr[SAME_ME_SIGNAL, (&sig1 << 3)]
+               .set_sig sig1
+
+               local_csr_wr[SAME_ME_SIGNAL, (&sig2 << 3)]
+               .set_sig sig2
+
+               local_csr_wr[SAME_ME_SIGNAL, (&sig3 << 3)]
+               .set_sig sig3
+       .end
+
+mpacket_receive_loop#:
+       /*
+        * Synchronise and wait for mpacket.
+        */
+       .begin
+               ctx_arb[sig1]
+               local_csr_wr[SAME_ME_SIGNAL, (0x80 | (&sig1 << 3))]
+
+               msf[fast_wr, --, add_to_rx_freelist, 0]
+               .set_sig mpacket_arrived
+               ctx_arb[mpacket_arrived]
+               .set $rsw0 $rsw1
+       .end
+
+       /*
+        * We halt if we see {inbparerr,parerr,null,soperror}.
+        */
+       .begin
+               alu_shf[--, 0x1b, and, $rsw0, >>8]
+               bne[abort_rswerr#]
+       .end
+
+       /*
+        * Point local memory pointer to this channel's state area.
+        */
+       .begin
+               .reg chanaddr
+
+               alu[chanaddr, $rsw0, and, 0x1f]
+               alu_shf[chanaddr, --, b, chanaddr, <<CHANNEL_STATE_SHIFT]
+               local_csr_wr[ACTIVE_LM_ADDR_0, chanaddr]
+               nop
+               nop
+               nop
+       .end
+
+       /*
+        * Check whether we received a SOP mpacket while we were already
+        * working on a packet, or a non-SOP mpacket while there was no
+        * packet pending.  (SOP == RECEIVING -> abort)  If everything's
+        * okay, update the RECEIVING flag to reflect our new state.
+        */
+       .begin
+               .reg temp
+               .reg eop
+
+               #if CHANNEL_FLAG_RECEIVING != 1
+               #error CHANNEL_FLAG_RECEIVING is not 1
+               #endif
+
+               alu_shf[temp, 1, and, $rsw0, >>15]
+               alu[temp, temp, xor, CHANNEL_FLAGS]
+               alu[--, temp, and, CHANNEL_FLAG_RECEIVING]
+               beq[abort_proterr#]
+
+               alu_shf[eop, 1, and, $rsw0, >>14]
+               alu[CHANNEL_FLAGS, temp, xor, eop]
+       .end
+
+       /*
+        * Copy the mpacket into the right spot, and in case of EOP,
+        * write back the descriptor and pass the packet on.
+        */
+       .begin
+               .reg buffer_offset
+               .reg _packet_length
+               .reg _packet_checksum
+               .reg _buffer_handle
+               .reg _buffer_start
+               .reg _buffer_length
+
+               /*
+                * Determine buffer_offset, _packet_length and
+                * _packet_checksum.
+                */
+               .begin
+                       .reg temp
+
+                       alu[--, 1, and, $rsw0, >>15]
+                       beq[not_sop#]
+
+                       immed[PACKET_LENGTH, 0]
+                       immed[PACKET_CHECKSUM, 0]
+
+               not_sop#:
+                       alu[buffer_offset, --, b, PACKET_LENGTH]
+                       alu_shf[temp, 0xff, and, $rsw0, >>16]
+                       alu[_packet_length, buffer_offset, +, temp]
+                       alu[PACKET_LENGTH, --, b, _packet_length]
+
+                       immed[temp, 0xffff]
+                       alu[temp, $rsw1, and, temp]
+                       alu[_packet_checksum, PACKET_CHECKSUM, +, temp]
+                       alu[PACKET_CHECKSUM, --, b, _packet_checksum]
+               .end
+
+               /*
+                * Allocate buffer in case of SOP.
+                */
+               .begin
+                       .reg temp
+
+                       alu[temp, 1, and, $rsw0, >>15]
+                       beq[skip_buffer_alloc#]
+
+                       .begin
+                               .sig zzz
+                               .reg read $stemp $stemp2
+                               .xfer_order $stemp $stemp2
+
+                       rx_nobufs#:
+                               scratch[get, $stemp, zero, 0, 1], ctx_swap[zzz]
+                               alu[_buffer_handle, --, b, $stemp]
+                               beq[rx_nobufs#]
+
+                               sram[read, $stemp, _buffer_handle, 0, 2],
+                                                               ctx_swap[zzz]
+                               alu[_buffer_start, --, b, $stemp]
+                               alu[_buffer_length, --, b, $stemp2]
+                       .end
+
+               skip_buffer_alloc#:
+               .end
+
+               /*
+                * Resynchronise.
+                */
+               .begin
+                       ctx_arb[sig2]
+                       local_csr_wr[SAME_ME_SIGNAL, (0x80 | (&sig2 << 3))]
+               .end
+
+               /*
+                * Synchronise buffer state.
+                */
+               .begin
+                       .reg temp
+
+                       alu[temp, 1, and, $rsw0, >>15]
+                       beq[copy_from_local_mem#]
+
+                       alu[BUFFER_HANDLE, --, b, _buffer_handle]
+                       alu[BUFFER_START, --, b, _buffer_start]
+                       alu[BUFFER_LENGTH, --, b, _buffer_length]
+                       br[sync_state_done#]
+
+               copy_from_local_mem#:
+                       alu[_buffer_handle, --, b, BUFFER_HANDLE]
+                       alu[_buffer_start, --, b, BUFFER_START]
+                       alu[_buffer_length, --, b, BUFFER_LENGTH]
+
+               sync_state_done#:
+               .end
+
+#if 0
+               /*
+                * Debug buffer state management.
+                */
+               .begin
+                       .reg temp
+
+                       alu[temp, 1, and, $rsw0, >>14]
+                       beq[no_poison#]
+                       immed[BUFFER_HANDLE, 0xdead]
+                       immed[BUFFER_START, 0xdead]
+                       immed[BUFFER_LENGTH, 0xdead]
+               no_poison#:
+
+                       immed[temp, 0xdead]
+                       alu[--, _buffer_handle, -, temp]
+                       beq[state_corrupted#]
+                       alu[--, _buffer_start, -, temp]
+                       beq[state_corrupted#]
+                       alu[--, _buffer_length, -, temp]
+                       beq[state_corrupted#]
+               .end
+#endif
+
+               /*
+                * Check buffer length.
+                */
+               .begin
+                       alu[--, _buffer_length, -, _packet_length]
+                       blo[buffer_overflow#]
+               .end
+
+               /*
+                * Copy the mpacket and give back the RBUF element.
+                */
+               .begin
+                       .reg element
+                       .reg xfer_size
+                       .reg temp
+                       .sig copy_sig
+
+                       alu_shf[element, 0x7f, and, $rsw0, >>24]
+                       alu_shf[xfer_size, 0xff, and, $rsw0, >>16]
+
+                       alu[xfer_size, xfer_size, -, 1]
+                       alu_shf[xfer_size, 0x10, or, xfer_size, >>3]
+                       alu_shf[temp, 0x10, or, xfer_size, <<21]
+                       alu_shf[temp, temp, or, element, <<11]
+                       alu_shf[--, temp, or, 1, <<18]
+
+                       dram[rbuf_rd, --, _buffer_start, buffer_offset, max_8],
+                                               indirect_ref, sig_done[copy_sig]
+                       ctx_arb[copy_sig]
+
+                       alu[temp, RBUF_ELEMENT_DONE, or, element, <<16]
+                       msf[fast_wr, --, temp, 0]
+               .end
+
+               /*
+                * If EOP, write back the packet descriptor.
+                */
+               .begin
+                       .reg write $stemp $stemp2
+                       .xfer_order $stemp $stemp2
+                       .sig zzz
+
+                       alu_shf[--, 1, and, $rsw0, >>14]
+                       beq[no_writeback#]
+
+                       alu[$stemp, $rsw0, and, 0x1f]
+                       alu[$stemp2, --, b, _packet_length]
+                       sram[write, $stemp, _buffer_handle, 8, 2], ctx_swap[zzz]
+
+               no_writeback#:
+               .end
+
+               /*
+                * Resynchronise.
+                */
+               .begin
+                       ctx_arb[sig3]
+                       local_csr_wr[SAME_ME_SIGNAL, (0x80 | (&sig3 << 3))]
+               .end
+
+               /*
+                * If EOP, put the buffer back onto the scratch ring.
+                */
+               .begin
+                       .reg write $stemp
+                       .sig zzz
+
+                       br_inp_state[SCR_Ring1_Status, rx_done_ring_overflow#]
+
+                       alu_shf[--, 1, and, $rsw0, >>14]
+                       beq[mpacket_receive_loop#]
+
+                       alu[--, 1, and, $rsw0, >>10]
+                       bne[rxerr#]
+
+                       alu[$stemp, --, b, _buffer_handle]
+                       scratch[put, $stemp, zero, 4, 1], ctx_swap[zzz]
+                       cap[fast_wr, 0, XSCALE_INT_A]
+                       br[mpacket_receive_loop#]
+
+               rxerr#:
+                       alu[$stemp, --, b, _buffer_handle]
+                       scratch[put, $stemp, zero, 0, 1], ctx_swap[zzz]
+                       br[mpacket_receive_loop#]
+               .end
+       .end
+
+
+abort_rswerr#:
+       halt
+
+abort_proterr#:
+       halt
+
+state_corrupted#:
+       halt
+
+buffer_overflow#:
+       halt
+
+rx_done_ring_overflow#:
+       halt
+
+
diff --git a/drivers/net/ixp2000/ixp2400_rx.ucode b/drivers/net/ixp2000/ixp2400_rx.ucode
new file mode 100644 (file)
index 0000000..e8aee2f
--- /dev/null
@@ -0,0 +1,130 @@
+static struct ixp2000_uengine_code ixp2400_rx =
+{
+       .cpu_model_bitmask      = 0x000003fe,
+       .cpu_min_revision       = 0,
+       .cpu_max_revision       = 255,
+
+       .uengine_parameters     = IXP2000_UENGINE_8_CONTEXTS |
+                                 IXP2000_UENGINE_PRN_UPDATE_EVERY |
+                                 IXP2000_UENGINE_NN_FROM_PREVIOUS |
+                                 IXP2000_UENGINE_ASSERT_EMPTY_AT_0 |
+                                 IXP2000_UENGINE_LM_ADDR1_PER_CONTEXT |
+                                 IXP2000_UENGINE_LM_ADDR0_PER_CONTEXT,
+
+       .initial_reg_values     = (struct ixp2000_reg_value []) {
+               { -1, -1 }
+       },
+
+       .num_insns              = 109,
+       .insns                  = (u8 []) {
+               0xf0, 0x00, 0x0c, 0xc0, 0x05,
+               0xf4, 0x44, 0x0c, 0x00, 0x05,
+               0xfc, 0x04, 0x4c, 0x00, 0x00,
+               0xf0, 0x00, 0x00, 0x3b, 0x00,
+               0xb4, 0x40, 0xf0, 0x3b, 0x1f,
+               0x8a, 0xc0, 0x50, 0x3e, 0x05,
+               0xb4, 0x40, 0xf0, 0x3b, 0x80,
+               0x9a, 0xe0, 0x00, 0x3e, 0x05,
+               0xf0, 0x00, 0x00, 0x07, 0x00,
+               0xd8, 0x05, 0xc0, 0x00, 0x11,
+               0xf0, 0x00, 0x00, 0x0f, 0x00,
+               0x91, 0xb0, 0x20, 0x0e, 0x00,
+               0xfc, 0x06, 0x60, 0x0b, 0x00,
+               0xf0, 0x00, 0x0c, 0x03, 0x00,
+               0xf0, 0x00, 0x0c, 0x03, 0x00,
+               0xf0, 0x00, 0x0c, 0x03, 0x00,
+               0xf0, 0x00, 0x0c, 0x02, 0x00,
+               0xb0, 0xc0, 0x30, 0x0f, 0x01,
+               0xa4, 0x70, 0x00, 0x0f, 0x20,
+               0xd8, 0x02, 0xc0, 0x01, 0x00,
+               0xfc, 0x10, 0xac, 0x23, 0x08,
+               0xfc, 0x10, 0xac, 0x43, 0x10,
+               0xfc, 0x10, 0xac, 0x63, 0x18,
+               0xe0, 0x00, 0x00, 0x00, 0x02,
+               0xfc, 0x10, 0xae, 0x23, 0x88,
+               0x3d, 0x00, 0x04, 0x03, 0x20,
+               0xe0, 0x00, 0x00, 0x00, 0x10,
+               0x84, 0x82, 0x02, 0x01, 0x3b,
+               0xd8, 0x1a, 0x00, 0x01, 0x01,
+               0xb4, 0x00, 0x8c, 0x7d, 0x80,
+               0x91, 0xb0, 0x80, 0x22, 0x00,
+               0xfc, 0x06, 0x60, 0x23, 0x00,
+               0xf0, 0x00, 0x0c, 0x03, 0x00,
+               0xf0, 0x00, 0x0c, 0x03, 0x00,
+               0xf0, 0x00, 0x0c, 0x03, 0x00,
+               0x94, 0xf0, 0x92, 0x01, 0x21,
+               0xac, 0x40, 0x60, 0x26, 0x00,
+               0xa4, 0x30, 0x0c, 0x04, 0x06,
+               0xd8, 0x1a, 0x40, 0x01, 0x00,
+               0x94, 0xe0, 0xa2, 0x01, 0x21,
+               0xac, 0x20, 0x00, 0x28, 0x06,
+               0x84, 0xf2, 0x02, 0x01, 0x21,
+               0xd8, 0x0b, 0x40, 0x01, 0x00,
+               0xf0, 0x00, 0x0c, 0x02, 0x01,
+               0xf0, 0x00, 0x0c, 0x02, 0x02,
+               0xa0, 0x00, 0x08, 0x04, 0x00,
+               0x95, 0x00, 0xc6, 0x01, 0xff,
+               0xa0, 0x80, 0x10, 0x30, 0x00,
+               0xa0, 0x60, 0x1c, 0x00, 0x01,
+               0xf0, 0x0f, 0xf0, 0x33, 0xff,
+               0xb4, 0x00, 0xc0, 0x31, 0x81,
+               0xb0, 0x80, 0xb0, 0x32, 0x02,
+               0xa0, 0x20, 0x20, 0x2c, 0x00,
+               0x94, 0xf0, 0xd2, 0x01, 0x21,
+               0xd8, 0x0f, 0x40, 0x01, 0x00,
+               0x19, 0x40, 0x10, 0x04, 0x20,
+               0xa0, 0x00, 0x26, 0x04, 0x00,
+               0xd8, 0x0d, 0xc0, 0x01, 0x00,
+               0x00, 0x42, 0x10, 0x80, 0x02,
+               0xb0, 0x00, 0x46, 0x04, 0x00,
+               0xb0, 0x00, 0x56, 0x08, 0x00,
+               0xe0, 0x00, 0x00, 0x00, 0x04,
+               0xfc, 0x10, 0xae, 0x43, 0x90,
+               0x84, 0xf0, 0x32, 0x01, 0x21,
+               0xd8, 0x11, 0x40, 0x01, 0x00,
+               0xa0, 0x60, 0x3c, 0x00, 0x02,
+               0xa0, 0x20, 0x40, 0x10, 0x00,
+               0xa0, 0x20, 0x50, 0x14, 0x00,
+               0xd8, 0x12, 0x00, 0x00, 0x18,
+               0xa0, 0x00, 0x28, 0x0c, 0x00,
+               0xb0, 0x00, 0x48, 0x10, 0x00,
+               0xb0, 0x00, 0x58, 0x14, 0x00,
+               0xaa, 0xf0, 0x00, 0x14, 0x01,
+               0xd8, 0x1a, 0xc0, 0x01, 0x05,
+               0x85, 0x80, 0x42, 0x01, 0xff,
+               0x95, 0x00, 0x66, 0x01, 0xff,
+               0xba, 0xc0, 0x60, 0x1b, 0x01,
+               0x9a, 0x30, 0x60, 0x19, 0x30,
+               0x9a, 0xb0, 0x70, 0x1a, 0x30,
+               0x9b, 0x50, 0x78, 0x1e, 0x04,
+               0x8a, 0xe2, 0x08, 0x1e, 0x21,
+               0x6a, 0x4e, 0x00, 0x13, 0x00,
+               0xe0, 0x00, 0x00, 0x00, 0x30,
+               0x9b, 0x00, 0x7a, 0x92, 0x04,
+               0x3d, 0x00, 0x04, 0x1f, 0x20,
+               0x84, 0xe2, 0x02, 0x01, 0x21,
+               0xd8, 0x16, 0x80, 0x01, 0x00,
+               0xa4, 0x18, 0x0c, 0x7d, 0x80,
+               0xa0, 0x58, 0x1c, 0x00, 0x01,
+               0x01, 0x42, 0x00, 0xa0, 0x02,
+               0xe0, 0x00, 0x00, 0x00, 0x08,
+               0xfc, 0x10, 0xae, 0x63, 0x98,
+               0xd8, 0x1b, 0x00, 0xc2, 0x14,
+               0x84, 0xe2, 0x02, 0x01, 0x21,
+               0xd8, 0x05, 0xc0, 0x01, 0x00,
+               0x84, 0xa2, 0x02, 0x01, 0x21,
+               0xd8, 0x19, 0x40, 0x01, 0x01,
+               0xa0, 0x58, 0x0c, 0x00, 0x02,
+               0x1a, 0x40, 0x00, 0x04, 0x24,
+               0x33, 0x00, 0x01, 0x2f, 0x20,
+               0xd8, 0x05, 0xc0, 0x00, 0x18,
+               0xa0, 0x58, 0x0c, 0x00, 0x02,
+               0x1a, 0x40, 0x00, 0x04, 0x20,
+               0xd8, 0x05, 0xc0, 0x00, 0x18,
+               0xe0, 0x00, 0x02, 0x00, 0x00,
+               0xe0, 0x00, 0x02, 0x00, 0x00,
+               0xe0, 0x00, 0x02, 0x00, 0x00,
+               0xe0, 0x00, 0x02, 0x00, 0x00,
+               0xe0, 0x00, 0x02, 0x00, 0x00,
+       }
+};
diff --git a/drivers/net/ixp2000/ixp2400_tx.uc b/drivers/net/ixp2000/ixp2400_tx.uc
new file mode 100644 (file)
index 0000000..d090d18
--- /dev/null
@@ -0,0 +1,272 @@
+/*
+ * TX ucode for the Intel IXP2400 in POS-PHY mode.
+ * Copyright (C) 2004, 2005 Lennert Buytenhek
+ * Dedicated to Marija Kulikova.
+ *
+ * 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.
+ *
+ * Assumptions made in this code:
+ * - The IXP2400 MSF is configured for POS-PHY mode, in a mode where
+ *   only one TBUF partition is used.  This includes, for example,
+ *   1x32 SPHY and 1x32 MPHY32, but not 4x8 SPHY or 1x32 MPHY4. (This
+ *   is not an exhaustive list.)
+ * - The TBUF uses 64-byte mpackets.
+ * - TX descriptors reside in SRAM, and have the following format:
+ *     struct tx_desc
+ *     {
+ *     // to uengine
+ *             u32     buf_phys_addr;
+ *             u32     pkt_length;
+ *             u32     channel;
+ *     };
+ * - Packet data resides in DRAM.
+ * - Packet buffer addresses are 8-byte aligned.
+ * - Scratch ring 2 is tx_pending.
+ * - Scratch ring 3 is tx_done, and has status condition 'full'.
+ * - This code is run on all eight threads of the microengine it runs on.
+ */
+
+#define TX_SEQUENCE_0          0x0060
+#define TBUF_CTRL              0x1800
+
+#define PARTITION_SIZE         128
+#define PARTITION_THRESH       96
+
+
+       .sig volatile sig1
+       .sig volatile sig2
+       .sig volatile sig3
+
+       .reg @old_tx_seq_0
+       .reg @mpkts_in_flight
+       .reg @next_tbuf_mpacket
+
+       .reg @buffer_handle
+       .reg @buffer_start
+       .reg @packet_length
+       .reg @channel
+       .reg @packet_offset
+
+       .reg zero
+
+       immed[zero, 0]
+
+       /*
+        * Skip context 0 initialisation?
+        */
+       .begin
+               br!=ctx[0, mpacket_tx_loop#]
+       .end
+
+       /*
+        * Wait until all pending TBUF elements have been transmitted.
+        */
+       .begin
+               .reg read $tx
+               .sig zzz
+
+       loop_empty#:
+               msf[read, $tx, zero, TX_SEQUENCE_0, 1], ctx_swap[zzz]
+               alu_shf[--, --, b, $tx, >>31]
+               beq[loop_empty#]
+
+               alu[@old_tx_seq_0, --, b, $tx]
+       .end
+
+       immed[@mpkts_in_flight, 0]
+       alu[@next_tbuf_mpacket, @old_tx_seq_0, and, (PARTITION_SIZE - 1)]
+
+       immed[@buffer_handle, 0]
+
+       /*
+        * Initialise signal pipeline.
+        */
+       .begin
+               local_csr_wr[SAME_ME_SIGNAL, (&sig1 << 3)]
+               .set_sig sig1
+
+               local_csr_wr[SAME_ME_SIGNAL, (&sig2 << 3)]
+               .set_sig sig2
+
+               local_csr_wr[SAME_ME_SIGNAL, (&sig3 << 3)]
+               .set_sig sig3
+       .end
+
+mpacket_tx_loop#:
+       .begin
+               .reg tbuf_element_index
+               .reg buffer_handle
+               .reg sop_eop
+               .reg packet_data
+               .reg channel
+               .reg mpacket_size
+
+               /*
+                * If there is no packet currently being transmitted,
+                * dequeue the next TX descriptor, and fetch the buffer
+                * address, packet length and destination channel number.
+                */
+               .begin
+                       .reg read $stemp $stemp2 $stemp3
+                       .xfer_order $stemp $stemp2 $stemp3
+                       .sig zzz
+
+                       ctx_arb[sig1]
+
+                       alu[--, --, b, @buffer_handle]
+                       bne[already_got_packet#]
+
+               tx_nobufs#:
+                       scratch[get, $stemp, zero, 8, 1], ctx_swap[zzz]
+                       alu[@buffer_handle, --, b, $stemp]
+                       beq[tx_nobufs#]
+
+                       sram[read, $stemp, $stemp, 0, 3], ctx_swap[zzz]
+                       alu[@buffer_start, --, b, $stemp]
+                       alu[@packet_length, --, b, $stemp2]
+                       beq[zero_byte_packet#]
+                       alu[@channel, --, b, $stemp3]
+                       immed[@packet_offset, 0]
+
+               already_got_packet#:
+                       local_csr_wr[SAME_ME_SIGNAL, (0x80 | (&sig1 << 3))]
+               .end
+
+               /*
+                * Determine tbuf element index, SOP/EOP flags, mpacket
+                * offset and mpacket size and cache buffer_handle and
+                * channel number.
+                */
+               .begin
+                       alu[tbuf_element_index, --, b, @next_tbuf_mpacket]
+                       alu[@next_tbuf_mpacket, @next_tbuf_mpacket, +, 1]
+                       alu[@next_tbuf_mpacket, @next_tbuf_mpacket, and,
+                                                       (PARTITION_SIZE - 1)]
+
+                       alu[buffer_handle, --, b, @buffer_handle]
+                       immed[@buffer_handle, 0]
+
+                       immed[sop_eop, 1]
+
+                       alu[packet_data, --, b, @packet_offset]
+                       bne[no_sop#]
+                       alu[sop_eop, sop_eop, or, 2]
+               no_sop#:
+                       alu[packet_data, packet_data, +, @buffer_start]
+
+                       alu[channel, --, b, @channel]
+
+                       alu[mpacket_size, @packet_length, -, @packet_offset]
+                       alu[--, 64, -, mpacket_size]
+                       bhs[eop#]
+                       alu[@buffer_handle, --, b, buffer_handle]
+                       immed[mpacket_size, 64]
+                       alu[sop_eop, sop_eop, and, 2]
+               eop#:
+
+                       alu[@packet_offset, @packet_offset, +, mpacket_size]
+               .end
+
+               /*
+                * Wait until there's enough space in the TBUF.
+                */
+               .begin
+                       .reg read $tx
+                       .reg temp
+                       .sig zzz
+
+                       ctx_arb[sig2]
+
+                       br[test_space#]
+
+               loop_space#:
+                       msf[read, $tx, zero, TX_SEQUENCE_0, 1], ctx_swap[zzz]
+
+                       alu[temp, $tx, -, @old_tx_seq_0]
+                       alu[temp, temp, and, 0xff]
+                       alu[@mpkts_in_flight, @mpkts_in_flight, -, temp]
+
+                       alu[@old_tx_seq_0, --, b, $tx]
+
+               test_space#:
+                       alu[--, PARTITION_THRESH, -, @mpkts_in_flight]
+                       blo[loop_space#]
+
+                       alu[@mpkts_in_flight, @mpkts_in_flight, +, 1]
+
+                       local_csr_wr[SAME_ME_SIGNAL, (0x80 | (&sig2 << 3))]
+               .end
+
+               /*
+                * Copy the packet data to the TBUF.
+                */
+               .begin
+                       .reg temp
+                       .sig copy_sig
+
+                       alu[temp, mpacket_size, -, 1]
+                       alu_shf[temp, 0x10, or, temp, >>3]
+                       alu_shf[temp, 0x10, or, temp, <<21]
+                       alu_shf[temp, temp, or, tbuf_element_index, <<11]
+                       alu_shf[--, temp, or, 1, <<18]
+
+                       dram[tbuf_wr, --, packet_data, 0, max_8],
+                                       indirect_ref, sig_done[copy_sig]
+                       ctx_arb[copy_sig]
+               .end
+
+               /*
+                * Mark TBUF element as ready-to-be-transmitted.
+                */
+               .begin
+                       .reg write $tsw $tsw2
+                       .xfer_order $tsw $tsw2
+                       .reg temp
+                       .sig zzz
+
+                       alu_shf[temp, channel, or, mpacket_size, <<24]
+                       alu_shf[$tsw, temp, or, sop_eop, <<8]
+                       immed[$tsw2, 0]
+
+                       immed[temp, TBUF_CTRL]
+                       alu_shf[temp, temp, or, tbuf_element_index, <<3]
+                       msf[write, $tsw, temp, 0, 2], ctx_swap[zzz]
+               .end
+
+               /*
+                * Resynchronise.
+                */
+               .begin
+                       ctx_arb[sig3]
+                       local_csr_wr[SAME_ME_SIGNAL, (0x80 | (&sig3 << 3))]
+               .end
+
+               /*
+                * If this was an EOP mpacket, recycle the TX buffer
+                * and signal the host.
+                */
+               .begin
+                       .reg write $stemp
+                       .sig zzz
+
+                       alu[--, sop_eop, and, 1]
+                       beq[mpacket_tx_loop#]
+
+               tx_done_ring_full#:
+                       br_inp_state[SCR_Ring3_Status, tx_done_ring_full#]
+
+                       alu[$stemp, --, b, buffer_handle]
+                       scratch[put, $stemp, zero, 12, 1], ctx_swap[zzz]
+                       cap[fast_wr, 0, XSCALE_INT_A]
+                       br[mpacket_tx_loop#]
+               .end
+       .end
+
+
+zero_byte_packet#:
+       halt
+
+
diff --git a/drivers/net/ixp2000/ixp2400_tx.ucode b/drivers/net/ixp2000/ixp2400_tx.ucode
new file mode 100644 (file)
index 0000000..a433e24
--- /dev/null
@@ -0,0 +1,98 @@
+static struct ixp2000_uengine_code ixp2400_tx =
+{
+       .cpu_model_bitmask      = 0x000003fe,
+       .cpu_min_revision       = 0,
+       .cpu_max_revision       = 255,
+
+       .uengine_parameters     = IXP2000_UENGINE_8_CONTEXTS |
+                                 IXP2000_UENGINE_PRN_UPDATE_EVERY |
+                                 IXP2000_UENGINE_NN_FROM_PREVIOUS |
+                                 IXP2000_UENGINE_ASSERT_EMPTY_AT_0 |
+                                 IXP2000_UENGINE_LM_ADDR1_PER_CONTEXT |
+                                 IXP2000_UENGINE_LM_ADDR0_PER_CONTEXT,
+
+       .initial_reg_values     = (struct ixp2000_reg_value []) {
+               { -1, -1 }
+       },
+
+       .num_insns              = 77,
+       .insns                  = (u8 []) {
+               0xf0, 0x00, 0x00, 0x07, 0x00,
+               0xd8, 0x03, 0x00, 0x00, 0x11,
+               0x3c, 0x40, 0x00, 0x04, 0xe0,
+               0x81, 0xf2, 0x02, 0x01, 0x00,
+               0xd8, 0x00, 0x80, 0x01, 0x00,
+               0xb0, 0x08, 0x06, 0x00, 0x00,
+               0xf0, 0x00, 0x0c, 0x00, 0x80,
+               0xb4, 0x49, 0x02, 0x03, 0x7f,
+               0xf0, 0x00, 0x02, 0x83, 0x00,
+               0xfc, 0x10, 0xac, 0x23, 0x08,
+               0xfc, 0x10, 0xac, 0x43, 0x10,
+               0xfc, 0x10, 0xac, 0x63, 0x18,
+               0xe0, 0x00, 0x00, 0x00, 0x02,
+               0xa0, 0x30, 0x02, 0x80, 0x00,
+               0xd8, 0x06, 0x00, 0x01, 0x01,
+               0x19, 0x40, 0x00, 0x04, 0x28,
+               0xb0, 0x0a, 0x06, 0x00, 0x00,
+               0xd8, 0x03, 0xc0, 0x01, 0x00,
+               0x00, 0x44, 0x00, 0x80, 0x80,
+               0xa0, 0x09, 0x06, 0x00, 0x00,
+               0xb0, 0x0b, 0x06, 0x04, 0x00,
+               0xd8, 0x13, 0x00, 0x01, 0x00,
+               0xb0, 0x0c, 0x06, 0x08, 0x00,
+               0xf0, 0x00, 0x0c, 0x00, 0xa0,
+               0xfc, 0x10, 0xae, 0x23, 0x88,
+               0xa0, 0x00, 0x12, 0x40, 0x00,
+               0xb0, 0xc9, 0x02, 0x43, 0x01,
+               0xb4, 0x49, 0x02, 0x43, 0x7f,
+               0xb0, 0x00, 0x22, 0x80, 0x00,
+               0xf0, 0x00, 0x02, 0x83, 0x00,
+               0xf0, 0x00, 0x0c, 0x04, 0x02,
+               0xb0, 0x40, 0x6c, 0x00, 0xa0,
+               0xd8, 0x08, 0x80, 0x01, 0x01,
+               0xaa, 0x00, 0x2c, 0x08, 0x02,
+               0xa0, 0xc0, 0x30, 0x18, 0x90,
+               0xa0, 0x00, 0x43, 0x00, 0x00,
+               0xba, 0xc0, 0x32, 0xc0, 0xa0,
+               0xaa, 0xb0, 0x00, 0x0f, 0x40,
+               0xd8, 0x0a, 0x80, 0x01, 0x04,
+               0xb0, 0x0a, 0x00, 0x08, 0x00,
+               0xf0, 0x00, 0x00, 0x0f, 0x40,
+               0xa4, 0x00, 0x2c, 0x08, 0x02,
+               0xa0, 0x8a, 0x00, 0x0c, 0xa0,
+               0xe0, 0x00, 0x00, 0x00, 0x04,
+               0xd8, 0x0c, 0x80, 0x00, 0x18,
+               0x3c, 0x40, 0x00, 0x04, 0xe0,
+               0xba, 0x80, 0x42, 0x01, 0x80,
+               0xb4, 0x40, 0x40, 0x13, 0xff,
+               0xaa, 0x88, 0x00, 0x10, 0x80,
+               0xb0, 0x08, 0x06, 0x00, 0x00,
+               0xaa, 0xf0, 0x0d, 0x80, 0x80,
+               0xd8, 0x0b, 0x40, 0x01, 0x05,
+               0xa0, 0x88, 0x0c, 0x04, 0x80,
+               0xfc, 0x10, 0xae, 0x43, 0x90,
+               0xba, 0xc0, 0x50, 0x0f, 0x01,
+               0x9a, 0x30, 0x50, 0x15, 0x30,
+               0x9a, 0xb0, 0x50, 0x16, 0x30,
+               0x9b, 0x50, 0x58, 0x16, 0x01,
+               0x8a, 0xe2, 0x08, 0x16, 0x21,
+               0x6b, 0x4e, 0x00, 0x83, 0x03,
+               0xe0, 0x00, 0x00, 0x00, 0x30,
+               0x9a, 0x80, 0x70, 0x0e, 0x04,
+               0x8b, 0x88, 0x08, 0x1e, 0x02,
+               0xf0, 0x00, 0x0c, 0x01, 0x81,
+               0xf0, 0x01, 0x80, 0x1f, 0x00,
+               0x9b, 0xd0, 0x78, 0x1e, 0x01,
+               0x3d, 0x42, 0x00, 0x1c, 0x20,
+               0xe0, 0x00, 0x00, 0x00, 0x08,
+               0xfc, 0x10, 0xae, 0x63, 0x98,
+               0xa4, 0x30, 0x0c, 0x04, 0x02,
+               0xd8, 0x03, 0x00, 0x01, 0x00,
+               0xd8, 0x11, 0xc1, 0x42, 0x14,
+               0xa0, 0x18, 0x00, 0x08, 0x00,
+               0x1a, 0x40, 0x00, 0x04, 0x2c,
+               0x33, 0x00, 0x01, 0x2f, 0x20,
+               0xd8, 0x03, 0x00, 0x00, 0x18,
+               0xe0, 0x00, 0x02, 0x00, 0x00,
+       }
+};
diff --git a/drivers/net/ixp2000/ixpdev.c b/drivers/net/ixp2000/ixpdev.c
new file mode 100644 (file)
index 0000000..09f03f4
--- /dev/null
@@ -0,0 +1,421 @@
+/*
+ * IXP2000 MSF network device driver
+ * Copyright (C) 2004, 2005 Lennert Buytenhek <buytenh@wantstofly.org>
+ * Dedicated to Marija Kulikova.
+ *
+ * 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.
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/init.h>
+#include <linux/moduleparam.h>
+#include <asm/arch/uengine.h>
+#include <asm/mach-types.h>
+#include <asm/io.h>
+#include "ixp2400_rx.ucode"
+#include "ixp2400_tx.ucode"
+#include "ixpdev_priv.h"
+#include "ixpdev.h"
+
+#define DRV_MODULE_VERSION     "0.2"
+
+static int nds_count;
+static struct net_device **nds;
+static int nds_open;
+static void (*set_port_admin_status)(int port, int up);
+
+static struct ixpdev_rx_desc * const rx_desc =
+       (struct ixpdev_rx_desc *)(IXP2000_SRAM0_VIRT_BASE + RX_BUF_DESC_BASE);
+static struct ixpdev_tx_desc * const tx_desc =
+       (struct ixpdev_tx_desc *)(IXP2000_SRAM0_VIRT_BASE + TX_BUF_DESC_BASE);
+static int tx_pointer;
+
+
+static int ixpdev_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+       struct ixpdev_priv *ip = netdev_priv(dev);
+       struct ixpdev_tx_desc *desc;
+       int entry;
+
+       if (unlikely(skb->len > PAGE_SIZE)) {
+               /* @@@ Count drops.  */
+               dev_kfree_skb(skb);
+               return 0;
+       }
+
+       entry = tx_pointer;
+       tx_pointer = (tx_pointer + 1) % TX_BUF_COUNT;
+
+       desc = tx_desc + entry;
+       desc->pkt_length = skb->len;
+       desc->channel = ip->channel;
+
+       skb_copy_and_csum_dev(skb, phys_to_virt(desc->buf_addr));
+       dev_kfree_skb(skb);
+
+       ixp2000_reg_write(RING_TX_PENDING,
+               TX_BUF_DESC_BASE + (entry * sizeof(struct ixpdev_tx_desc)));
+
+       dev->trans_start = jiffies;
+
+       local_irq_disable();
+       ip->tx_queue_entries++;
+       if (ip->tx_queue_entries == TX_BUF_COUNT_PER_CHAN)
+               netif_stop_queue(dev);
+       local_irq_enable();
+
+       return 0;
+}
+
+
+static int ixpdev_rx(struct net_device *dev, int *budget)
+{
+       while (*budget > 0) {
+               struct ixpdev_rx_desc *desc;
+               struct sk_buff *skb;
+               void *buf;
+               u32 _desc;
+
+               _desc = ixp2000_reg_read(RING_RX_DONE);
+               if (_desc == 0)
+                       return 0;
+
+               desc = rx_desc +
+                       ((_desc - RX_BUF_DESC_BASE) / sizeof(struct ixpdev_rx_desc));
+               buf = phys_to_virt(desc->buf_addr);
+
+               if (desc->pkt_length < 4 || desc->pkt_length > PAGE_SIZE) {
+                       printk(KERN_ERR "ixp2000: rx err, length %d\n",
+                                       desc->pkt_length);
+                       goto err;
+               }
+
+               if (desc->channel < 0 || desc->channel >= nds_count) {
+                       printk(KERN_ERR "ixp2000: rx err, channel %d\n",
+                                       desc->channel);
+                       goto err;
+               }
+
+               /* @@@ Make FCS stripping configurable.  */
+               desc->pkt_length -= 4;
+
+               if (unlikely(!netif_running(nds[desc->channel])))
+                       goto err;
+
+               skb = dev_alloc_skb(desc->pkt_length + 2);
+               if (likely(skb != NULL)) {
+                       skb->dev = nds[desc->channel];
+                       skb_reserve(skb, 2);
+                       eth_copy_and_sum(skb, buf, desc->pkt_length, 0);
+                       skb_put(skb, desc->pkt_length);
+                       skb->protocol = eth_type_trans(skb, skb->dev);
+
+                       skb->dev->last_rx = jiffies;
+
+                       netif_receive_skb(skb);
+               }
+
+err:
+               ixp2000_reg_write(RING_RX_PENDING, _desc);
+               dev->quota--;
+               (*budget)--;
+       }
+
+       return 1;
+}
+