Author: sephe
Date: Wed Sep 28 04:45:00 2016
New Revision: 306391
URL: https://svnweb.freebsd.org/changeset/base/306391

Log:
  hyperv/hn: Reorganize the synthetic parts detach.
  
  MFC after:    1 week
  Sponsored by: Microsoft
  Differential Revision:        https://reviews.freebsd.org/D8047

Modified:
  head/sys/dev/hyperv/netvsc/hv_net_vsc.c
  head/sys/dev/hyperv/netvsc/hv_net_vsc.h
  head/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
  head/sys/dev/hyperv/netvsc/hv_rndis_filter.c
  head/sys/dev/hyperv/netvsc/hv_rndis_filter.h
  head/sys/dev/hyperv/netvsc/if_hnvar.h

Modified: head/sys/dev/hyperv/netvsc/hv_net_vsc.c
==============================================================================
--- head/sys/dev/hyperv/netvsc/hv_net_vsc.c     Wed Sep 28 04:34:21 2016        
(r306390)
+++ head/sys/dev/hyperv/netvsc/hv_net_vsc.c     Wed Sep 28 04:45:00 2016        
(r306391)
@@ -618,27 +618,15 @@ hn_nvs_attach(struct hn_softc *sc, int m
        return (0);
 }
 
-/*
- * Net VSC disconnect from VSP
- */
-static void
-hv_nv_disconnect_from_vsp(struct hn_softc *sc)
+void
+hn_nvs_detach(struct hn_softc *sc)
 {
+
+       /* NOTE: there are no requests to stop the NVS. */
        hn_nvs_disconn_rxbuf(sc);
        hn_nvs_disconn_chim(sc);
 }
 
-/*
- * Net VSC on device remove
- */
-int
-hv_nv_on_device_remove(struct hn_softc *sc)
-{
-       
-       hv_nv_disconnect_from_vsp(sc);
-       return (0);
-}
-
 void
 hn_nvs_sent_xact(struct hn_send_ctx *sndc,
     struct hn_softc *sc __unused, struct vmbus_channel *chan __unused,

Modified: head/sys/dev/hyperv/netvsc/hv_net_vsc.h
==============================================================================
--- head/sys/dev/hyperv/netvsc/hv_net_vsc.h     Wed Sep 28 04:34:21 2016        
(r306390)
+++ head/sys/dev/hyperv/netvsc/hv_net_vsc.h     Wed Sep 28 04:45:00 2016        
(r306391)
@@ -269,8 +269,6 @@ extern int hv_promisc_mode;
 struct hn_send_ctx;
 
 void netvsc_linkstatus_callback(struct hn_softc *sc, uint32_t status);
-int hn_nvs_attach(struct hn_softc *sc, int mtu);
-int hv_nv_on_device_remove(struct hn_softc *sc);
 int hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype,
        struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt);
 

Modified: head/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
==============================================================================
--- head/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c  Wed Sep 28 04:34:21 
2016        (r306390)
+++ head/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c  Wed Sep 28 04:45:00 
2016        (r306391)
@@ -348,6 +348,7 @@ static void hn_detach_allchans(struct hn
 static void hn_chan_callback(struct vmbus_channel *chan, void *xrxr);
 static void hn_set_ring_inuse(struct hn_softc *, int);
 static int hn_synth_attach(struct hn_softc *, int);
+static void hn_synth_detach(struct hn_softc *);
 static bool hn_tx_ring_pending(struct hn_tx_ring *);
 static void hn_suspend(struct hn_softc *);
 static void hn_resume(struct hn_softc *);
@@ -744,29 +745,19 @@ failed:
 }
 
 /*
- * Standard detach entry point
+ * TODO: Use this for error handling on attach path.
  */
 static int
 netvsc_detach(device_t dev)
 {
        struct hn_softc *sc = device_get_softc(dev);
 
-       if (bootverbose)
-               printf("netvsc_detach\n");
-
-       /*
-        * XXXKYS:  Need to clean up all our
-        * driver state; this is the driver
-        * unloading.
-        */
+       /* TODO: ether_ifdetach */
 
-       /*
-        * XXXKYS:  Need to stop outgoing traffic and unregister
-        * the netdevice.
-        */
-
-       hv_rf_on_device_remove(sc);
-       hn_detach_allchans(sc);
+       HN_LOCK(sc);
+       /* TODO: hn_stop */
+       hn_synth_detach(sc);
+       HN_UNLOCK(sc);
 
        hn_stop_tx_tasks(sc);
 
@@ -779,6 +770,8 @@ netvsc_detach(device_t dev)
 
        vmbus_xact_ctx_destroy(sc->hn_xact);
        HN_LOCK_DESTROY(sc);
+
+       /* TODO: if_free */
        return (0);
 }
 
@@ -1654,23 +1647,14 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, 
                if (ifp->if_drv_flags & IFF_DRV_RUNNING)
                        hn_suspend(sc);
 
-               /* We must remove and add back the device to cause the new
-                * MTU to take effect.  This includes tearing down, but not
-                * deleting the channel, then bringing it back up.
-                */
-               error = hv_rf_on_device_remove(sc);
-               if (error) {
-                       HN_UNLOCK(sc);
-                       break;
-               }
-
                /*
-                * Detach all of the channels.
+                * Detach the synthetics parts, i.e. NVS and RNDIS.
                 */
-               hn_detach_allchans(sc);
+               hn_synth_detach(sc);
 
                /*
-                * Attach the synthetic parts, i.e. NVS and RNDIS.
+                * Reattach the synthetic parts, i.e. NVS and RNDIS,
+                * with the new MTU setting.
                 * XXX check error.
                 */
                hn_synth_attach(sc, ifr->ifr_mtu);
@@ -3520,6 +3504,26 @@ back:
        return (0);
 }
 
+/*
+ * NOTE:
+ * The interface must have been suspended though hn_suspend(), before
+ * this function get called.
+ */
+static void
+hn_synth_detach(struct hn_softc *sc)
+{
+       HN_LOCK_ASSERT(sc);
+
+       /* Detach the RNDIS first. */
+       hn_rndis_detach(sc);
+
+       /* Detach NVS. */
+       hn_nvs_detach(sc);
+
+       /* Detach all of the channels. */
+       hn_detach_allchans(sc);
+}
+
 static void
 hn_set_ring_inuse(struct hn_softc *sc, int ring_cnt)
 {

Modified: head/sys/dev/hyperv/netvsc/hv_rndis_filter.c
==============================================================================
--- head/sys/dev/hyperv/netvsc/hv_rndis_filter.c        Wed Sep 28 04:34:21 
2016        (r306390)
+++ head/sys/dev/hyperv/netvsc/hv_rndis_filter.c        Wed Sep 28 04:45:00 
2016        (r306391)
@@ -957,11 +957,8 @@ done:
        return (error);
 }
 
-/*
- * RNDIS filter halt device
- */
 static int
-hv_rf_halt_device(struct hn_softc *sc)
+hn_rndis_halt(struct hn_softc *sc)
 {
        struct vmbus_xact *xact;
        struct rndis_halt_req *halt;
@@ -1008,21 +1005,12 @@ hn_rndis_attach(struct hn_softc *sc)
        return (0);
 }
 
-/*
- * RNDIS filter on device remove
- */
-int
-hv_rf_on_device_remove(struct hn_softc *sc)
+void
+hn_rndis_detach(struct hn_softc *sc)
 {
-       int ret;
-
-       /* Halt and release the rndis device */
-       ret = hv_rf_halt_device(sc);
-
-       /* Pass control to inner driver to remove the device */
-       ret |= hv_nv_on_device_remove(sc);
 
-       return (ret);
+       /* Halt the RNDIS. */
+       hn_rndis_halt(sc);
 }
 
 /*

Modified: head/sys/dev/hyperv/netvsc/hv_rndis_filter.h
==============================================================================
--- head/sys/dev/hyperv/netvsc/hv_rndis_filter.h        Wed Sep 28 04:34:21 
2016        (r306390)
+++ head/sys/dev/hyperv/netvsc/hv_rndis_filter.h        Wed Sep 28 04:45:00 
2016        (r306391)
@@ -43,7 +43,6 @@ struct hn_rx_ring;
 void hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr,
     const void *data, int dlen);
 void hv_rf_channel_rollup(struct hn_rx_ring *rxr, struct hn_tx_ring *txr);
-int hv_rf_on_device_remove(struct hn_softc *sc);
 int hv_rf_on_open(struct hn_softc *sc);
 int hv_rf_on_close(struct hn_softc *sc);
 

Modified: head/sys/dev/hyperv/netvsc/if_hnvar.h
==============================================================================
--- head/sys/dev/hyperv/netvsc/if_hnvar.h       Wed Sep 28 04:34:21 2016        
(r306390)
+++ head/sys/dev/hyperv/netvsc/if_hnvar.h       Wed Sep 28 04:45:00 2016        
(r306391)
@@ -118,6 +118,7 @@ uint32_t    hn_chim_alloc(struct hn_softc *
 void           hn_chim_free(struct hn_softc *sc, uint32_t chim_idx);
 
 int            hn_rndis_attach(struct hn_softc *sc);
+void           hn_rndis_detach(struct hn_softc *sc);
 int            hn_rndis_conf_rss(struct hn_softc *sc, uint16_t flags);
 void           *hn_rndis_pktinfo_append(struct rndis_packet_msg *,
                    size_t pktsize, size_t pi_dlen, uint32_t pi_type);
@@ -127,6 +128,7 @@ int         hn_rndis_get_linkstatus(struct hn_s
                    uint32_t *link_status);
 
 int            hn_nvs_attach(struct hn_softc *sc, int mtu);
+void           hn_nvs_detach(struct hn_softc *sc);
 int            hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch);
 void           hn_nvs_sent_xact(struct hn_send_ctx *sndc, struct hn_softc *sc,
                    struct vmbus_channel *chan, const void *data, int dlen);
_______________________________________________
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