Author: sephe
Date: Wed Mar  2 03:07:31 2016
New Revision: 296296
URL: https://svnweb.freebsd.org/changeset/base/296296

Log:
  hyperv/hn: Make read buffer per-channel
  
  Submitted by: Hongjiang Zhang <honzhan microsoft com>
  Reorganized by:       sephe
  MFC after:    1 week
  Sponsored by: Microsoft OSTC

Modified:
  head/sys/dev/hyperv/include/hyperv.h
  head/sys/dev/hyperv/netvsc/hv_net_vsc.c
  head/sys/dev/hyperv/netvsc/hv_net_vsc.h

Modified: head/sys/dev/hyperv/include/hyperv.h
==============================================================================
--- head/sys/dev/hyperv/include/hyperv.h        Wed Mar  2 02:29:35 2016        
(r296295)
+++ head/sys/dev/hyperv/include/hyperv.h        Wed Mar  2 03:07:31 2016        
(r296296)
@@ -828,6 +828,7 @@ typedef struct hv_vmbus_channel {
         */
        void                            *hv_chan_priv1;
        void                            *hv_chan_priv2;
+       void                            *hv_chan_priv3;
 } hv_vmbus_channel;
 
 #define HV_VMBUS_CHAN_ISPRIMARY(chan)  ((chan)->primary_channel == NULL)

Modified: head/sys/dev/hyperv/netvsc/hv_net_vsc.c
==============================================================================
--- head/sys/dev/hyperv/netvsc/hv_net_vsc.c     Wed Mar  2 02:29:35 2016        
(r296295)
+++ head/sys/dev/hyperv/netvsc/hv_net_vsc.c     Wed Mar  2 03:07:31 2016        
(r296296)
@@ -49,6 +49,9 @@
 #include "hv_rndis.h"
 #include "hv_rndis_filter.h"
 
+/* priv1 and priv1 are consumed by the main driver */
+#define hv_chan_rdbuf  hv_chan_priv3
+
 MALLOC_DEFINE(M_NETVSC, "netvsc", "Hyper-V netvsc driver");
 
 /*
@@ -666,25 +669,30 @@ hv_nv_disconnect_from_vsp(netvsc_dev *ne
 netvsc_dev *
 hv_nv_on_device_add(struct hv_device *device, void *additional_info)
 {
+       struct hv_vmbus_channel *chan = device->channel;
        netvsc_dev *net_dev;
        int ret = 0;
 
        net_dev = hv_nv_alloc_net_device(device);
-       if (!net_dev)
-               goto cleanup;
+       if (net_dev == NULL)
+               return NULL;
 
        /* Initialize the NetVSC channel extension */
 
        sema_init(&net_dev->channel_init_sema, 0, "netdev_sema");
 
+       chan->hv_chan_rdbuf = malloc(NETVSC_PACKET_SIZE, M_NETVSC, M_WAITOK);
+
        /*
         * Open the channel
         */
-       ret = hv_vmbus_channel_open(device->channel,
+       ret = hv_vmbus_channel_open(chan,
            NETVSC_DEVICE_RING_BUFFER_SIZE, NETVSC_DEVICE_RING_BUFFER_SIZE,
-           NULL, 0, hv_nv_on_channel_callback, device->channel);
-       if (ret != 0)
+           NULL, 0, hv_nv_on_channel_callback, chan);
+       if (ret != 0) {
+               free(chan->hv_chan_rdbuf, M_NETVSC);
                goto cleanup;
+       }
 
        /*
         * Connect with the NetVsp
@@ -697,8 +705,8 @@ hv_nv_on_device_add(struct hv_device *de
 
 close:
        /* Now, we can close the channel safely */
-
-       hv_vmbus_channel_close(device->channel);
+       free(chan->hv_chan_rdbuf, M_NETVSC);
+       hv_vmbus_channel_close(chan);
 
 cleanup:
        /*
@@ -736,6 +744,7 @@ hv_nv_on_device_remove(struct hv_device 
                    HV_CHANNEL_CLOSING_NONDESTRUCTIVE_STATE;
        }
 
+       free(device->channel->hv_chan_rdbuf, M_NETVSC);
        hv_vmbus_channel_close(device->channel);
 
        sema_destroy(&net_dev->channel_init_sema);
@@ -975,7 +984,7 @@ hv_nv_on_channel_callback(void *xchan)
        if (net_dev == NULL)
                return;
 
-       buffer = net_dev->callback_buf;
+       buffer = chan->hv_chan_rdbuf;
 
        do {
                ret = hv_vmbus_channel_recv_packet_raw(chan,

Modified: head/sys/dev/hyperv/netvsc/hv_net_vsc.h
==============================================================================
--- head/sys/dev/hyperv/netvsc/hv_net_vsc.h     Wed Mar  2 02:29:35 2016        
(r296295)
+++ head/sys/dev/hyperv/netvsc/hv_net_vsc.h     Wed Mar  2 03:07:31 2016        
(r296296)
@@ -923,8 +923,6 @@ typedef struct netvsc_dev_ {
        hv_bool_uint8_t                         destroy;
        /* Negotiated NVSP version */
        uint32_t                                nvsp_version;
-       
-       uint8_t                                 
callback_buf[NETVSC_PACKET_SIZE]; 
 } netvsc_dev;
 
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to