Author: sephe
Date: Mon Aug  7 02:23:34 2017
New Revision: 322131
URL: https://svnweb.freebsd.org/changeset/base/322131

Log:
  MFC 321836,321837
  
  321836
      hyperv/hn: Renaming and minor cleanup
  
      This prepares for the upcoming transparent VF support.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D11708
  
  321837
      hyperv/hn: Add comment about ether_ifattach event subscription.
  
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D11710

Modified:
  stable/10/sys/dev/hyperv/netvsc/if_hn.c
  stable/10/sys/dev/hyperv/netvsc/if_hnvar.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/hyperv/netvsc/if_hn.c
==============================================================================
--- stable/10/sys/dev/hyperv/netvsc/if_hn.c     Mon Aug  7 02:17:15 2017        
(r322130)
+++ stable/10/sys/dev/hyperv/netvsc/if_hn.c     Mon Aug  7 02:23:34 2017        
(r322131)
@@ -217,9 +217,9 @@ struct hn_rxinfo {
        uint32_t                        hash_value;
 };
 
-struct hn_update_vf {
+struct hn_rxvf_setarg {
        struct hn_rx_ring       *rxr;
-       struct ifnet            *vf;
+       struct ifnet            *vf_ifp;
 };
 
 #define HN_RXINFO_VLAN                 0x0001
@@ -259,6 +259,13 @@ static void                        hn_ifaddr_event(void *, 
struct ifnet *);
 static void                    hn_ifnet_attevent(void *, struct ifnet *);
 static void                    hn_ifnet_detevent(void *, struct ifnet *);
 
+static bool                    hn_ismyvf(const struct hn_softc *,
+                                   const struct ifnet *);
+static void                    hn_rxvf_change(struct hn_softc *,
+                                   struct ifnet *, bool);
+static void                    hn_rxvf_set(struct hn_softc *, struct ifnet *);
+static void                    hn_rxvf_set_task(void *, int);
+
 static int                     hn_rndis_rxinfo(const void *, int,
                                    struct hn_rxinfo *);
 static void                    hn_rndis_rx_data(struct hn_rx_ring *,
@@ -790,7 +797,7 @@ hn_rxfilter_config(struct hn_softc *sc)
        HN_LOCK_ASSERT(sc);
 
        if ((ifp->if_flags & IFF_PROMISC) ||
-           (sc->hn_flags & HN_FLAG_VF)) {
+           (sc->hn_flags & HN_FLAG_RXVF)) {
                filter = NDIS_PACKET_TYPE_PROMISCUOUS;
        } else {
                filter = NDIS_PACKET_TYPE_DIRECTED;
@@ -978,39 +985,39 @@ hn_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *i
 }
 
 static void
-hn_update_vf_task(void *arg, int pending __unused)
+hn_rxvf_set_task(void *xarg, int pending __unused)
 {
-       struct hn_update_vf *uv = arg;
+       struct hn_rxvf_setarg *arg = xarg;
 
-       uv->rxr->hn_rxvf_ifp = uv->vf;
+       arg->rxr->hn_rxvf_ifp = arg->vf_ifp;
 }
 
 static void
-hn_update_vf(struct hn_softc *sc, struct ifnet *vf)
+hn_rxvf_set(struct hn_softc *sc, struct ifnet *vf_ifp)
 {
        struct hn_rx_ring *rxr;
-       struct hn_update_vf uv;
+       struct hn_rxvf_setarg arg;
        struct task task;
        int i;
 
        HN_LOCK_ASSERT(sc);
 
-       TASK_INIT(&task, 0, hn_update_vf_task, &uv);
+       TASK_INIT(&task, 0, hn_rxvf_set_task, &arg);
 
        for (i = 0; i < sc->hn_rx_ring_cnt; ++i) {
                rxr = &sc->hn_rx_ring[i];
 
                if (i < sc->hn_rx_ring_inuse) {
-                       uv.rxr = rxr;
-                       uv.vf = vf;
+                       arg.rxr = rxr;
+                       arg.vf_ifp = vf_ifp;
                        vmbus_chan_run_task(rxr->hn_chan, &task);
                } else {
-                       rxr->hn_rxvf_ifp = vf;
+                       rxr->hn_rxvf_ifp = vf_ifp;
                }
        }
 }
 
-static __inline bool
+static bool
 hn_ismyvf(const struct hn_softc *sc, const struct ifnet *ifp)
 {
        const struct ifnet *hn_ifp;
@@ -1035,7 +1042,7 @@ hn_ismyvf(const struct hn_softc *sc, const struct ifne
 }
 
 static void
-hn_set_vf(struct hn_softc *sc, struct ifnet *ifp, bool vf)
+hn_rxvf_change(struct hn_softc *sc, struct ifnet *ifp, bool rxvf)
 {
        struct ifnet *hn_ifp;
 
@@ -1046,21 +1053,19 @@ hn_set_vf(struct hn_softc *sc, struct ifnet *ifp, bool
 
        if (!hn_ismyvf(sc, ifp))
                goto out;
-
        hn_ifp = sc->hn_ifp;
 
-       /* Now we're sure 'ifp' is a real VF device. */
-       if (vf) {
-               if (sc->hn_flags & HN_FLAG_VF)
+       if (rxvf) {
+               if (sc->hn_flags & HN_FLAG_RXVF)
                        goto out;
 
-               sc->hn_flags |= HN_FLAG_VF;
+               sc->hn_flags |= HN_FLAG_RXVF;
                hn_rxfilter_config(sc);
        } else {
-               if (!(sc->hn_flags & HN_FLAG_VF))
+               if (!(sc->hn_flags & HN_FLAG_RXVF))
                        goto out;
 
-               sc->hn_flags &= ~HN_FLAG_VF;
+               sc->hn_flags &= ~HN_FLAG_RXVF;
                if (hn_ifp->if_drv_flags & IFF_DRV_RUNNING)
                        hn_rxfilter_config(sc);
                else
@@ -1068,11 +1073,11 @@ hn_set_vf(struct hn_softc *sc, struct ifnet *ifp, bool
        }
 
        hn_nvs_set_datapath(sc,
-           vf ? HN_NVS_DATAPATH_VF : HN_NVS_DATAPATH_SYNTHETIC);
+           rxvf ? HN_NVS_DATAPATH_VF : HN_NVS_DATAPATH_SYNTHETIC);
 
-       hn_update_vf(sc, vf ? ifp : NULL);
+       hn_rxvf_set(sc, rxvf ? ifp : NULL);
 
-       if (vf) {
+       if (rxvf) {
                hn_suspend_mgmt(sc);
                sc->hn_link_flags &=
                    ~(HN_LINK_FLAG_LINKUP | HN_LINK_FLAG_NETCHG);
@@ -1081,12 +1086,13 @@ hn_set_vf(struct hn_softc *sc, struct ifnet *ifp, bool
                hn_resume_mgmt(sc);
        }
 
-       devctl_notify("HYPERV_NIC_VF", if_name(hn_ifp),
-           vf ? "VF_UP" : "VF_DOWN", NULL);
+       devctl_notify("HYPERV_NIC_VF", hn_ifp->if_xname,
+           rxvf ? "VF_UP" : "VF_DOWN", NULL);
 
-       if (bootverbose)
-               if_printf(hn_ifp, "Data path is switched %s %s\n",
-                   vf ? "to" : "from", if_name(ifp));
+       if (bootverbose) {
+               if_printf(hn_ifp, "datapath is switched %s %s\n",
+                   rxvf ? "to" : "from", ifp->if_xname);
+       }
 out:
        HN_UNLOCK(sc);
 }
@@ -1094,16 +1100,17 @@ out:
 static void
 hn_ifnet_event(void *arg, struct ifnet *ifp, int event)
 {
+
        if (event != IFNET_EVENT_UP && event != IFNET_EVENT_DOWN)
                return;
-
-       hn_set_vf(arg, ifp, event == IFNET_EVENT_UP);
+       hn_rxvf_change(arg, ifp, event == IFNET_EVENT_UP);
 }
 
 static void
 hn_ifaddr_event(void *arg, struct ifnet *ifp)
 {
-       hn_set_vf(arg, ifp, ifp->if_flags & IFF_UP);
+
+       hn_rxvf_change(arg, ifp, ifp->if_flags & IFF_UP);
 }
 
 static void
@@ -1517,6 +1524,12 @@ hn_attach(device_t dev)
        sc->hn_ifaddr_evthand = EVENTHANDLER_REGISTER(ifaddr_event,
            hn_ifaddr_event, sc, EVENTHANDLER_PRI_ANY);
 
+       /*
+        * NOTE:
+        * Subscribe ether_ifattach event, instead of ifnet_arrival event,
+        * since interface's LLADDR is needed; interface LLADDR is not
+        * available when ifnet_arrival event is triggered.
+        */
        sc->hn_ifnet_atthand = EVENTHANDLER_REGISTER(ether_ifattach_event,
            hn_ifnet_attevent, sc, EVENTHANDLER_PRI_ANY);
        sc->hn_ifnet_dethand = EVENTHANDLER_REGISTER(ifnet_departure_event,
@@ -2889,7 +2902,7 @@ hn_stop(struct hn_softc *sc, bool detaching)
         * If the VF is active, make sure the filter is not 0, even if
         * the synthetic NIC is down.
         */
-       if (!detaching && (sc->hn_flags & HN_FLAG_VF))
+       if (!detaching && (sc->hn_flags & HN_FLAG_RXVF))
                hn_rxfilter_config(sc);
 }
 
@@ -3421,13 +3434,13 @@ hn_vf_sysctl(SYSCTL_HANDLER_ARGS)
 {
        struct hn_softc *sc = arg1;
        char vf_name[IFNAMSIZ + 1];
-       struct ifnet *vf;
+       struct ifnet *vf_ifp;
 
        HN_LOCK(sc);
        vf_name[0] = '\0';
-       vf = sc->hn_vf_ifp;
-       if (vf != NULL)
-               snprintf(vf_name, sizeof(vf_name), "%s", if_name(vf));
+       vf_ifp = sc->hn_vf_ifp;
+       if (vf_ifp != NULL)
+               snprintf(vf_name, sizeof(vf_name), "%s", vf_ifp->if_xname);
        HN_UNLOCK(sc);
        return sysctl_handle_string(oidp, vf_name, sizeof(vf_name), req);
 }
@@ -3437,13 +3450,13 @@ hn_rxvf_sysctl(SYSCTL_HANDLER_ARGS)
 {
        struct hn_softc *sc = arg1;
        char vf_name[IFNAMSIZ + 1];
-       struct ifnet *vf;
+       struct ifnet *vf_ifp;
 
        HN_LOCK(sc);
        vf_name[0] = '\0';
-       vf = sc->hn_rx_ring[0].hn_rxvf_ifp;
-       if (vf != NULL)
-               snprintf(vf_name, sizeof(vf_name), "%s", if_name(vf));
+       vf_ifp = sc->hn_rx_ring[0].hn_rxvf_ifp;
+       if (vf_ifp != NULL)
+               snprintf(vf_name, sizeof(vf_name), "%s", vf_ifp->if_xname);
        HN_UNLOCK(sc);
        return sysctl_handle_string(oidp, vf_name, sizeof(vf_name), req);
 }
@@ -5397,7 +5410,7 @@ hn_suspend(struct hn_softc *sc)
        hn_polling(sc, 0);
 
        if ((sc->hn_ifp->if_drv_flags & IFF_DRV_RUNNING) ||
-           (sc->hn_flags & HN_FLAG_VF))
+           (sc->hn_flags & HN_FLAG_RXVF))
                hn_suspend_data(sc);
        hn_suspend_mgmt(sc);
 }
@@ -5487,16 +5500,16 @@ hn_resume(struct hn_softc *sc)
 {
 
        if ((sc->hn_ifp->if_drv_flags & IFF_DRV_RUNNING) ||
-           (sc->hn_flags & HN_FLAG_VF))
+           (sc->hn_flags & HN_FLAG_RXVF))
                hn_resume_data(sc);
 
        /*
         * When the VF is activated, the synthetic interface is changed
-        * to DOWN in hn_set_vf(). Here, if the VF is still active, we
-        * don't call hn_resume_mgmt() until the VF is deactivated in
-        * hn_set_vf().
+        * to DOWN in hn_rxvf_change().  Here, if the VF is still active,
+        * we don't call hn_resume_mgmt() until the VF is deactivated in
+        * hn_rxvf_change().
         */
-       if (!(sc->hn_flags & HN_FLAG_VF))
+       if (!(sc->hn_flags & HN_FLAG_RXVF))
                hn_resume_mgmt(sc);
 
        /*

Modified: stable/10/sys/dev/hyperv/netvsc/if_hnvar.h
==============================================================================
--- stable/10/sys/dev/hyperv/netvsc/if_hnvar.h  Mon Aug  7 02:17:15 2017        
(r322130)
+++ stable/10/sys/dev/hyperv/netvsc/if_hnvar.h  Mon Aug  7 02:23:34 2017        
(r322131)
@@ -252,7 +252,7 @@ struct hn_softc {
 #define HN_FLAG_NO_SLEEPING            0x0020
 #define HN_FLAG_RXBUF_REF              0x0040
 #define HN_FLAG_CHIM_REF               0x0080
-#define HN_FLAG_VF                     0x0100
+#define HN_FLAG_RXVF                   0x0100
 
 #define HN_FLAG_ERRORS                 (HN_FLAG_RXBUF_REF | HN_FLAG_CHIM_REF)
 
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to