Author: sephe
Date: Fri Oct 14 08:18:55 2016
New Revision: 307304
URL: https://svnweb.freebsd.org/changeset/base/307304

Log:
  MFC 302636-302638
  
  302636
      hyperv/vmbus: Move channel map to vmbus_softc
  
      Sponsored by:   Microsoft OSTC
      Differential Revision:  https://reviews.freebsd.org/D6982
  
  302637
      hyperv/vmbus: Remove needed bits
  
      Sponsored by:   Microsoft OSTC
      Differential Revision:  https://reviews.freebsd.org/D7002
  
  302638
      hyperv/vmbus: Destroy channel list lock upon attach failure and detach.
  
      Sponsored by:   Microsoft OSTC
      Differential Revision:  https://reviews.freebsd.org/D7003

Modified:
  stable/11/sys/dev/hyperv/vmbus/hv_channel_mgmt.c
  stable/11/sys/dev/hyperv/vmbus/hv_connection.c
  stable/11/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
  stable/11/sys/dev/hyperv/vmbus/vmbus.c
  stable/11/sys/dev/hyperv/vmbus/vmbus_var.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/hyperv/vmbus/hv_channel_mgmt.c
==============================================================================
--- stable/11/sys/dev/hyperv/vmbus/hv_channel_mgmt.c    Fri Oct 14 08:14:51 
2016        (r307303)
+++ stable/11/sys/dev/hyperv/vmbus/hv_channel_mgmt.c    Fri Oct 14 08:18:55 
2016        (r307304)
@@ -123,7 +123,7 @@ vmbus_channel_process_offer(hv_vmbus_cha
                 */
                printf("VMBUS: got channel0 offer\n");
        } else {
-               hv_vmbus_g_connection.channels[relid] = new_channel;
+               sc->vmbus_chmap[relid] = new_channel;
        }
 
        TAILQ_FOREACH(channel, &sc->vmbus_chlist, ch_link) {
@@ -351,10 +351,10 @@ vmbus_channel_on_offer_rescind(struct vm
                    rescind->child_rel_id);
        }
 
-       channel = hv_vmbus_g_connection.channels[rescind->child_rel_id];
+       channel = sc->vmbus_chmap[rescind->child_rel_id];
        if (channel == NULL)
            return;
-       hv_vmbus_g_connection.channels[rescind->child_rel_id] = NULL;
+       sc->vmbus_chmap[rescind->child_rel_id] = NULL;
 
        taskqueue_enqueue(taskqueue_thread, &channel->ch_detach_task);
 }
@@ -451,8 +451,8 @@ hv_vmbus_release_unattached_channels(str
            }
            hv_vmbus_free_vmbus_channel(channel);
        }
-       bzero(hv_vmbus_g_connection.channels,
-           sizeof(hv_vmbus_channel*) * VMBUS_CHAN_MAX);
+       bzero(sc->vmbus_chmap,
+           sizeof(struct hv_vmbus_channel *) * VMBUS_CHAN_MAX);
 
        mtx_unlock(&sc->vmbus_chlist_lock);
 }

Modified: stable/11/sys/dev/hyperv/vmbus/hv_connection.c
==============================================================================
--- stable/11/sys/dev/hyperv/vmbus/hv_connection.c      Fri Oct 14 08:14:51 
2016        (r307303)
+++ stable/11/sys/dev/hyperv/vmbus/hv_connection.c      Fri Oct 14 08:18:55 
2016        (r307304)
@@ -43,53 +43,9 @@
 #include <dev/hyperv/vmbus/vmbus_reg.h>
 #include <dev/hyperv/vmbus/vmbus_var.h>
 
-/*
- * Globals
- */
-hv_vmbus_connection hv_vmbus_g_connection =
-       { .connect_state = HV_DISCONNECTED };
-
-/**
- * Send a connect request on the partition service connection
- */
-int
-hv_vmbus_connect(struct vmbus_softc *sc)
-{
-       /**
-        * Make sure we are not connecting or connected
-        */
-       if (hv_vmbus_g_connection.connect_state != HV_DISCONNECTED) {
-               return (-1);
-       }
-
-       /**
-        * Initialize the vmbus connection
-        */
-       hv_vmbus_g_connection.connect_state = HV_CONNECTING;
-
-       hv_vmbus_g_connection.channels = malloc(sizeof(hv_vmbus_channel*) *
-           VMBUS_CHAN_MAX, M_DEVBUF, M_WAITOK | M_ZERO);
-
-       hv_vmbus_g_connection.connect_state = HV_CONNECTED;
-
-       return (0);
-}
-
-/**
- * Send a disconnect request on the partition service connection
- */
-int
-hv_vmbus_disconnect(void)
-{
-
-       free(hv_vmbus_g_connection.channels, M_DEVBUF);
-       hv_vmbus_g_connection.connect_state = HV_DISCONNECTED;
-
-       return (0);
-}
-
 static __inline void
-vmbus_event_flags_proc(volatile u_long *event_flags, int flag_cnt)
+vmbus_event_flags_proc(struct vmbus_softc *sc, volatile u_long *event_flags,
+    int flag_cnt)
 {
        int f;
 
@@ -112,7 +68,7 @@ vmbus_event_flags_proc(volatile u_long *
                        flags &= ~(1UL << bit);
 
                        rel_id = rel_id_base + bit;
-                       channel = hv_vmbus_g_connection.channels[rel_id];
+                       channel = sc->vmbus_chmap[rel_id];
 
                        /* if channel is closed or closing */
                        if (channel == NULL || channel->rxq == NULL)
@@ -135,7 +91,7 @@ vmbus_event_proc(struct vmbus_softc *sc,
         * to get the id of the channel that has the pending interrupt.
         */
        eventf = VMBUS_PCPU_GET(sc, event_flags, cpu) + VMBUS_SINT_MESSAGE;
-       vmbus_event_flags_proc(eventf->evt_flags,
+       vmbus_event_flags_proc(sc, eventf->evt_flags,
            VMBUS_PCPU_GET(sc, event_flags_cnt, cpu));
 }
 
@@ -146,7 +102,7 @@ vmbus_event_proc_compat(struct vmbus_sof
 
        eventf = VMBUS_PCPU_GET(sc, event_flags, cpu) + VMBUS_SINT_MESSAGE;
        if (atomic_testandclear_long(&eventf->evt_flags[0], 0)) {
-               vmbus_event_flags_proc(sc->vmbus_rx_evtflags,
+               vmbus_event_flags_proc(sc, sc->vmbus_rx_evtflags,
                    VMBUS_CHAN_MAX_COMPAT >> VMBUS_EVTFLAG_SHIFT);
        }
 }

Modified: stable/11/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
==============================================================================
--- stable/11/sys/dev/hyperv/vmbus/hv_vmbus_priv.h      Fri Oct 14 08:14:51 
2016        (r307303)
+++ stable/11/sys/dev/hyperv/vmbus/hv_vmbus_priv.h      Fri Oct 14 08:18:55 
2016        (r307304)
@@ -97,25 +97,6 @@ typedef struct hv_vmbus_channel_packet_m
        hv_vmbus_multipage_buffer       range;
 } __packed hv_vmbus_channel_packet_multipage_buffer;
 
-/*
- * VM Bus connection states
- */
-typedef enum {
-       HV_DISCONNECTED,
-       HV_CONNECTING,
-       HV_CONNECTED,
-       HV_DISCONNECTING
-} hv_vmbus_connect_state;
-
-typedef struct {
-       hv_vmbus_connect_state                  connect_state;
-
-       /**
-        * channel table for fast lookup through id.
-       */
-       hv_vmbus_channel                        **channels;
-} hv_vmbus_connection;
-
 typedef union {
        uint32_t as_uint32_t;
        struct {
@@ -177,12 +158,6 @@ typedef struct {
        uint8_t                         rsvd_z4[1984];
 } hv_vmbus_monitor_page;
 
-/**
- * Global variables
- */
-
-extern hv_vmbus_connection     hv_vmbus_g_connection;
-
 /*
  * Private, VM Bus functions
  */
@@ -247,10 +222,4 @@ void                       
hv_vmbus_child_device_register(st
 int                    hv_vmbus_child_device_unregister(
                                        struct hv_device *child_dev);
 
-/**
- * Connection interfaces
- */
-int                    hv_vmbus_connect(struct vmbus_softc *);
-int                    hv_vmbus_disconnect(void);
-
 #endif  /* __HYPERV_PRIV_H__ */

Modified: stable/11/sys/dev/hyperv/vmbus/vmbus.c
==============================================================================
--- stable/11/sys/dev/hyperv/vmbus/vmbus.c      Fri Oct 14 08:14:51 2016        
(r307303)
+++ stable/11/sys/dev/hyperv/vmbus/vmbus.c      Fri Oct 14 08:18:55 2016        
(r307304)
@@ -1132,6 +1132,9 @@ vmbus_doattach(struct vmbus_softc *sc)
        sc->vmbus_gpadl = VMBUS_GPADL_START;
        mtx_init(&sc->vmbus_chlist_lock, "vmbus chlist", NULL, MTX_DEF);
        TAILQ_INIT(&sc->vmbus_chlist);
+       sc->vmbus_chmap = malloc(
+           sizeof(struct hv_vmbus_channel *) * VMBUS_CHAN_MAX, M_DEVBUF,
+           M_WAITOK | M_ZERO);
 
        /*
         * Create context for "post message" Hypercalls
@@ -1166,12 +1169,8 @@ vmbus_doattach(struct vmbus_softc *sc)
        sc->vmbus_flags |= VMBUS_FLAG_SYNIC;
 
        /*
-        * Connect to VMBus in the root partition
+        * Initialize vmbus, e.g. connect to Hypervisor.
         */
-       ret = hv_vmbus_connect(sc);
-       if (ret != 0)
-               goto cleanup;
-
        ret = vmbus_init(sc);
        if (ret != 0)
                goto cleanup;
@@ -1201,7 +1200,9 @@ cleanup:
                vmbus_msghc_ctx_destroy(sc->vmbus_msg_hc);
                sc->vmbus_msg_hc = NULL;
        }
+       free(sc->vmbus_chmap, M_DEVBUF);
        mtx_destroy(&sc->vmbus_scan_lock);
+       mtx_destroy(&sc->vmbus_chlist_lock);
 
        return (ret);
 }
@@ -1267,7 +1268,6 @@ vmbus_detach(device_t dev)
        hv_vmbus_release_unattached_channels(sc);
 
        vmbus_disconnect(sc);
-       hv_vmbus_disconnect();
 
        if (sc->vmbus_flags & VMBUS_FLAG_SYNIC) {
                sc->vmbus_flags &= ~VMBUS_FLAG_SYNIC;
@@ -1282,7 +1282,10 @@ vmbus_detach(device_t dev)
                sc->vmbus_msg_hc = NULL;
        }
 
+       free(sc->vmbus_chmap, M_DEVBUF);
        mtx_destroy(&sc->vmbus_scan_lock);
+       mtx_destroy(&sc->vmbus_chlist_lock);
+
        return (0);
 }
 

Modified: stable/11/sys/dev/hyperv/vmbus/vmbus_var.h
==============================================================================
--- stable/11/sys/dev/hyperv/vmbus/vmbus_var.h  Fri Oct 14 08:14:51 2016        
(r307303)
+++ stable/11/sys/dev/hyperv/vmbus/vmbus_var.h  Fri Oct 14 08:18:55 2016        
(r307304)
@@ -75,6 +75,7 @@ struct vmbus_softc {
 
        u_long                  *vmbus_rx_evtflags;
                                                /* compat evtflgs from host */
+       struct hv_vmbus_channel **vmbus_chmap;
        struct vmbus_msghc_ctx  *vmbus_msg_hc;
        struct vmbus_pcpu_data  vmbus_pcpu[MAXCPU];
 
_______________________________________________
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