The following diff rewrites and simplifies the ioctl code for the
hme(4) driver.


Index: hme.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/hme.c,v
retrieving revision 1.56
diff -u -p -r1.56 hme.c
--- hme.c       23 Apr 2009 21:24:14 -0000      1.56
+++ hme.c       25 Apr 2009 09:28:55 -0000
@@ -229,7 +229,6 @@ hme_config(sc)
        ifp->if_watchdog = hme_watchdog;
        ifp->if_flags =
            IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
-       sc->sc_if_flags = ifp->if_flags;
        IFQ_SET_READY(&ifp->if_snd);
        ifp->if_capabilities = IFCAP_VLAN_MTU;
 
@@ -632,8 +631,8 @@ hme_init(sc)
 
        ifp->if_flags |= IFF_RUNNING;
        ifp->if_flags &= ~IFF_OACTIVE;
-       sc->sc_if_flags = ifp->if_flags;
        ifp->if_timer = 0;
+
        hme_start(ifp);
 }
 
@@ -1212,7 +1211,6 @@ hme_mii_statchg(dev)
                v &= ~HME_MAC_TXCFG_FULLDPLX;
                sc->sc_arpcom.ac_if.if_flags &= ~IFF_SIMPLEX;
        }
-       sc->sc_if_flags = sc->sc_arpcom.ac_if.if_flags;
        bus_space_write_4(t, mac, HME_MACI_TXCFG, v);
 }
 
@@ -1285,55 +1283,26 @@ hme_ioctl(ifp, cmd, data)
 
        switch (cmd) {
        case SIOCSIFADDR:
-               switch (ifa->ifa_addr->sa_family) {
+               ifp->if_flags |= IFF_UP;
+               if (!(ifp->if_flags & IFF_RUNNING))
+                       hme_init(sc);
 #ifdef INET
-               case AF_INET:
-                       if (ifp->if_flags & IFF_UP)
-                               hme_setladrf(sc);
-                       else {
-                               ifp->if_flags |= IFF_UP;
-                               hme_init(sc);
-                       }
+               if (ifa->ifa_addr->sa_family == AF_INET)
                        arp_ifinit(&sc->sc_arpcom, ifa);
-                       break;
 #endif
-               default:
-                       hme_init(sc);
-                       break;
-               }
                break;
 
        case SIOCSIFFLAGS:
-               if ((ifp->if_flags & IFF_UP) == 0 &&
-                   (ifp->if_flags & IFF_RUNNING) != 0) {
-                       /*
-                        * If interface is marked down and it is running, then
-                        * stop it.
-                        */
-                       hme_stop(sc);
-               } else if ((ifp->if_flags & IFF_UP) != 0 &&
-                          (ifp->if_flags & IFF_RUNNING) == 0) {
-                       /*
-                        * If interface is marked up and it is stopped, then
-                        * start it.
-                        */
-                       hme_init(sc);
-               } else if ((ifp->if_flags & IFF_UP) != 0) {
-                       /*
-                        * If setting debug or promiscuous mode, do not reset
-                        * the chip; for everything else, call hme_init()
-                        * which will trigger a reset.
-                        */
-#define RESETIGN (IFF_CANTCHANGE | IFF_DEBUG)
-                       if (ifp->if_flags == sc->sc_if_flags)
-                               break;
-                       if ((ifp->if_flags & (~RESETIGN))
-                           == (sc->sc_if_flags & (~RESETIGN)))
-                               hme_setladrf(sc);
+               if (ifp->if_flags & IFF_UP) {
+                       if (ifp->if_flags & IFF_RUNNING)
+                               error = ENETRESET;
                        else
                                hme_init(sc);
-#undef RESETIGN
+               } else {
+                       if (ifp->if_flags & IFF_RUNNING)
+                               hme_stop(sc);
                }
+
 #ifdef HMEDEBUG
                sc->sc_debug = (ifp->if_flags & IFF_DEBUG) != 0 ? 1 : 0;
 #endif
@@ -1354,7 +1323,6 @@ hme_ioctl(ifp, cmd, data)
                error = 0;
        }
 
-       sc->sc_if_flags = ifp->if_flags;
        splx(s);
        return (error);
 }
Index: hmevar.h
===================================================================
RCS file: /cvs/src/sys/dev/ic/hmevar.h,v
retrieving revision 1.12
diff -u -p -r1.12 hmevar.h
--- hmevar.h    17 Apr 2009 20:20:18 -0000      1.12
+++ hmevar.h    25 Apr 2009 09:09:44 -0000
@@ -80,7 +80,6 @@ struct hme_softc {
 
        int                     sc_debug;
        void                    *sc_sh;         /* shutdownhook cookie */
-       short                   sc_if_flags;
 
        /* Special hardware hooks */
        void    (*sc_hwreset)(struct hme_softc *);

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Reply via email to