Author: marius
Date: Wed Mar 31 20:43:24 2010
New Revision: 206001
URL: http://svn.freebsd.org/changeset/base/206001

Log:
  Hook the identification LEDs of igb(4), lem(4) and em(4) devices up with
  led(4) so they can be lit or f.e. made blink via `echo f2 > /dev/led/em0`
  for localization purposes.
  
  Approved by:  jfv
  MFC afer:     1 week (after r205869)

Modified:
  head/sys/dev/e1000/if_em.c
  head/sys/dev/e1000/if_em.h
  head/sys/dev/e1000/if_igb.c
  head/sys/dev/e1000/if_igb.h
  head/sys/dev/e1000/if_lem.c
  head/sys/dev/e1000/if_lem.h

Modified: head/sys/dev/e1000/if_em.c
==============================================================================
--- head/sys/dev/e1000/if_em.c  Wed Mar 31 20:37:44 2010        (r206000)
+++ head/sys/dev/e1000/if_em.c  Wed Mar 31 20:43:24 2010        (r206001)
@@ -77,6 +77,7 @@
 #include <netinet/udp.h>
 
 #include <machine/in_cksum.h>
+#include <dev/led/led.h>
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>
 
@@ -267,6 +268,7 @@ static void     em_release_hw_control(st
 static void    em_get_wakeup(device_t);
 static void     em_enable_wakeup(device_t);
 static int     em_enable_phy_wakeup(struct adapter *);
+static void    em_led_func(void *, int);
 
 static int     em_irq_fast(void *);
 
@@ -656,6 +658,9 @@ em_attach(device_t dev)
        /* Tell the stack that the interface is not active */
        adapter->ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
 
+       adapter->led_dev = led_create(em_led_func, adapter,
+           device_get_nameunit(dev));
+
        INIT_DEBUGOUT("em_attach: end");
 
        return (0);
@@ -769,6 +774,9 @@ em_resume(device_t dev)
        struct adapter *adapter = device_get_softc(dev);
        struct ifnet *ifp = adapter->ifp;
 
+       if (adapter->led_dev != NULL)
+               led_destroy(adapter->led_dev);
+
        EM_CORE_LOCK(adapter);
        em_init_locked(adapter);
        em_init_manageability(adapter);
@@ -2163,6 +2171,9 @@ em_stop(void *arg)
 
        e1000_reset_hw(&adapter->hw);
        E1000_WRITE_REG(&adapter->hw, E1000_WUC, 0);
+
+       e1000_led_off(&adapter->hw);
+       e1000_cleanup_led(&adapter->hw);
 }
 
 
@@ -4538,7 +4549,7 @@ em_get_wakeup(device_t dev)
 /*
  * Enable PCI Wake On Lan capability
  */
-void
+static void
 em_enable_wakeup(device_t dev)
 {
        struct adapter  *adapter = device_get_softc(dev);
@@ -4690,6 +4701,22 @@ out:
        return ret;
 }
 
+static void
+em_led_func(void *arg, int onoff)
+{
+       struct adapter  *adapter = arg;
+ 
+       EM_CORE_LOCK(adapter);
+       if (onoff) {
+               e1000_setup_led(&adapter->hw);
+               e1000_led_on(&adapter->hw);
+       } else {
+               e1000_led_off(&adapter->hw);
+               e1000_cleanup_led(&adapter->hw);
+       }
+       EM_CORE_UNLOCK(adapter);
+}
+
 /**********************************************************************
  *
  *  Update the board statistics counters.

Modified: head/sys/dev/e1000/if_em.h
==============================================================================
--- head/sys/dev/e1000/if_em.h  Wed Mar 31 20:37:44 2010        (r206000)
+++ head/sys/dev/e1000/if_em.h  Wed Mar 31 20:43:24 2010        (r206001)
@@ -337,6 +337,7 @@ struct adapter {
        /* FreeBSD operating-system-specific structures. */
        struct e1000_osdep osdep;
        struct device   *dev;
+       struct cdev     *led_dev;
 
        struct resource *memory;
        struct resource *flash;

Modified: head/sys/dev/e1000/if_igb.c
==============================================================================
--- head/sys/dev/e1000/if_igb.c Wed Mar 31 20:37:44 2010        (r206000)
+++ head/sys/dev/e1000/if_igb.c Wed Mar 31 20:43:24 2010        (r206001)
@@ -83,6 +83,7 @@
 #include <netinet/udp.h>
 
 #include <machine/in_cksum.h>
+#include <dev/led/led.h>
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>
 
@@ -234,6 +235,7 @@ static void igb_release_manageability(st
 static void     igb_get_hw_control(struct adapter *);
 static void     igb_release_hw_control(struct adapter *);
 static void     igb_enable_wakeup(device_t);
+static void     igb_led_func(void *, int);
 
 static int     igb_irq_fast(void *);
 static void    igb_add_rx_process_limit(struct adapter *, const char *,
@@ -585,6 +587,9 @@ igb_attach(device_t dev)
        /* Tell the stack that the interface is not active */
        adapter->ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
 
+       adapter->led_dev = led_create(igb_led_func, adapter,
+           device_get_nameunit(dev));
+
        INIT_DEBUGOUT("igb_attach: end");
 
        return (0);
@@ -624,6 +629,9 @@ igb_detach(device_t dev)
                return (EBUSY);
        }
 
+       if (adapter->led_dev != NULL)
+               led_destroy(adapter->led_dev);
+
 #ifdef DEVICE_POLLING
        if (ifp->if_capenable & IFCAP_POLLING)
                ether_poll_deregister(ifp);
@@ -2002,6 +2010,9 @@ igb_stop(void *arg)
 
        e1000_reset_hw(&adapter->hw);
        E1000_WRITE_REG(&adapter->hw, E1000_WUC, 0);
+
+       e1000_led_off(&adapter->hw);
+       e1000_cleanup_led(&adapter->hw);
 }
 
 
@@ -4613,7 +4624,7 @@ igb_is_valid_ether_addr(uint8_t *addr)
 /*
  * Enable PCI Wake On Lan capability
  */
-void
+static void
 igb_enable_wakeup(device_t dev)
 {
        u16     cap, status;
@@ -4634,6 +4645,21 @@ igb_enable_wakeup(device_t dev)
        return;
 }
 
+static void
+igb_led_func(void *arg, int onoff)
+{
+       struct adapter  *adapter = arg;
+
+       IGB_CORE_LOCK(adapter);
+       if (onoff) {
+               e1000_setup_led(&adapter->hw);
+               e1000_led_on(&adapter->hw);
+       } else {
+               e1000_led_off(&adapter->hw);
+               e1000_cleanup_led(&adapter->hw);
+       }
+       IGB_CORE_UNLOCK(adapter);
+}
 
 /**********************************************************************
  *

Modified: head/sys/dev/e1000/if_igb.h
==============================================================================
--- head/sys/dev/e1000/if_igb.h Wed Mar 31 20:37:44 2010        (r206000)
+++ head/sys/dev/e1000/if_igb.h Wed Mar 31 20:43:24 2010        (r206001)
@@ -361,6 +361,7 @@ struct adapter {
 
        struct e1000_osdep osdep;
        struct device   *dev;
+       struct cdev     *led_dev;
 
        struct resource *pci_mem;
        struct resource *msix_mem;

Modified: head/sys/dev/e1000/if_lem.c
==============================================================================
--- head/sys/dev/e1000/if_lem.c Wed Mar 31 20:37:44 2010        (r206000)
+++ head/sys/dev/e1000/if_lem.c Wed Mar 31 20:43:24 2010        (r206001)
@@ -79,6 +79,7 @@
 #include <netinet/udp.h>
 
 #include <machine/in_cksum.h>
+#include <dev/led/led.h>
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>
 
@@ -253,6 +254,7 @@ static void     lem_release_hw_control(s
 static void    lem_get_wakeup(device_t);
 static void     lem_enable_wakeup(device_t);
 static int     lem_enable_phy_wakeup(struct adapter *);
+static void    lem_led_func(void *, int);
 
 #ifdef EM_LEGACY_IRQ
 static void    lem_intr(void *);
@@ -667,6 +669,9 @@ lem_attach(device_t dev)
        /* Tell the stack that the interface is not active */
        adapter->ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
 
+       adapter->led_dev = led_create(lem_led_func, adapter,
+           device_get_nameunit(dev));
+
        INIT_DEBUGOUT("lem_attach: end");
 
        return (0);
@@ -722,6 +727,9 @@ lem_detach(device_t dev)
                ether_poll_deregister(ifp);
 #endif
 
+       if (adapter->led_dev != NULL)
+               led_destroy(adapter->led_dev);
+
        EM_CORE_LOCK(adapter);
        EM_TX_LOCK(adapter);
        adapter->in_detach = 1;
@@ -2252,6 +2260,9 @@ lem_stop(void *arg)
        e1000_reset_hw(&adapter->hw);
        if (adapter->hw.mac.type >= e1000_82544)
                E1000_WRITE_REG(&adapter->hw, E1000_WUC, 0);
+
+       e1000_led_off(&adapter->hw);
+       e1000_cleanup_led(&adapter->hw);
 }
 
 
@@ -4126,7 +4137,7 @@ lem_get_wakeup(device_t dev)
 /*
  * Enable PCI Wake On Lan capability
  */
-void
+static void
 lem_enable_wakeup(device_t dev)
 {
        struct adapter  *adapter = device_get_softc(dev);
@@ -4268,6 +4279,21 @@ out:
        return ret;
 }
 
+static void
+lem_led_func(void *arg, int onoff)
+{
+       struct adapter  *adapter = arg;
+
+       EM_CORE_LOCK(adapter);
+       if (onoff) {
+               e1000_setup_led(&adapter->hw);
+               e1000_led_on(&adapter->hw);
+       } else {
+               e1000_led_off(&adapter->hw);
+               e1000_cleanup_led(&adapter->hw);
+       }
+       EM_CORE_UNLOCK(adapter);
+}
 
 /*********************************************************************
 * 82544 Coexistence issue workaround.

Modified: head/sys/dev/e1000/if_lem.h
==============================================================================
--- head/sys/dev/e1000/if_lem.h Wed Mar 31 20:37:44 2010        (r206000)
+++ head/sys/dev/e1000/if_lem.h Wed Mar 31 20:43:24 2010        (r206001)
@@ -293,6 +293,7 @@ struct adapter {
        /* FreeBSD operating-system-specific structures. */
        struct e1000_osdep osdep;
        struct device   *dev;
+       struct cdev     *led_dev;
 
        struct resource *memory;
        struct resource *flash;
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to