Author: sephe
Date: Fri Aug 12 08:07:56 2016
New Revision: 303998
URL: https://svnweb.freebsd.org/changeset/base/303998

Log:
  hyperv/hn: Switch to vmbus xact APIs for NVS RXBUF connection.
  
  MFC after:    1 week
  Sponsored by: Microsoft
  Differential Revision:        https://reviews.freebsd.org/D7469

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

Modified: head/sys/dev/hyperv/netvsc/hv_net_vsc.c
==============================================================================
--- head/sys/dev/hyperv/netvsc/hv_net_vsc.c     Fri Aug 12 08:07:19 2016        
(r303997)
+++ head/sys/dev/hyperv/netvsc/hv_net_vsc.c     Fri Aug 12 08:07:56 2016        
(r303998)
@@ -152,10 +152,14 @@ hv_nv_get_next_send_section(netvsc_dev *
 static int 
 hv_nv_init_rx_buffer_with_net_vsp(struct hn_softc *sc)
 {
+       struct vmbus_xact *xact;
+       struct hn_nvs_rxbuf_conn *conn;
+       const struct hn_nvs_rxbuf_connresp *resp;
+       size_t resp_len;
        struct hn_send_ctx sndc;
        netvsc_dev *net_dev;
-       nvsp_msg *init_pkt;
-       int ret = 0;
+       uint32_t status;
+       int error;
 
        net_dev = hv_nv_get_outbound_net_device(sc);
        if (!net_dev) {
@@ -167,7 +171,7 @@ hv_nv_init_rx_buffer_with_net_vsp(struct
            BUS_DMA_WAITOK | BUS_DMA_ZERO);
        if (net_dev->rx_buf == NULL) {
                device_printf(sc->hn_dev, "allocate rxbuf failed\n");
-               return ENOMEM;
+               return (ENOMEM);
        }
 
        /*
@@ -177,74 +181,76 @@ hv_nv_init_rx_buffer_with_net_vsp(struct
         * Only primary channel has RXBUF connected to it.  Sub-channels
         * just share this RXBUF.
         */
-       ret = vmbus_chan_gpadl_connect(sc->hn_prichan,
+       error = vmbus_chan_gpadl_connect(sc->hn_prichan,
            net_dev->rxbuf_dma.hv_paddr, net_dev->rx_buf_size,
            &net_dev->rx_buf_gpadl_handle);
-       if (ret != 0) {
-               device_printf(sc->hn_dev, "rxbuf gpadl connect failed: %d\n",
-                   ret);
+       if (error) {
+               if_printf(sc->hn_ifp, "rxbuf gpadl connect failed: %d\n",
+                   error);
                goto cleanup;
        }
-       
-       /* sema_wait(&ext->channel_init_sema); KYS CHECK */
 
-       /* Notify the NetVsp of the gpadl handle */
-       init_pkt = &net_dev->channel_init_packet;
+       /*
+        * Connect RXBUF to NVS.
+        */
 
-       memset(init_pkt, 0, sizeof(nvsp_msg));
+       xact = vmbus_xact_get(sc->hn_xact, sizeof(*conn));
+       if (xact == NULL) {
+               if_printf(sc->hn_ifp, "no xact for nvs rxbuf conn\n");
+               error = ENXIO;
+               goto cleanup;
+       }
 
-       init_pkt->hdr.msg_type = nvsp_msg_1_type_send_rx_buf;
-       init_pkt->msgs.vers_1_msgs.send_rx_buf.gpadl_handle =
-           net_dev->rx_buf_gpadl_handle;
-       init_pkt->msgs.vers_1_msgs.send_rx_buf.id =
-           NETVSC_RECEIVE_BUFFER_ID;
+       conn = vmbus_xact_req_data(xact);
+       conn->nvs_type = HN_NVS_TYPE_RXBUF_CONN;
+       conn->nvs_gpadl = net_dev->rx_buf_gpadl_handle;
+       conn->nvs_sig = HN_NVS_RXBUF_SIG;
 
-       /* Send the gpadl notification request */
+       hn_send_ctx_init_simple(&sndc, hn_nvs_sent_xact, xact);
+       vmbus_xact_activate(xact);
 
-       hn_send_ctx_init_simple(&sndc, hn_nvs_sent_wakeup, NULL);
-       ret = vmbus_chan_send(sc->hn_prichan,
+       error = vmbus_chan_send(sc->hn_prichan,
            VMBUS_CHANPKT_TYPE_INBAND, VMBUS_CHANPKT_FLAG_RC,
-           init_pkt, sizeof(nvsp_msg), (uint64_t)(uintptr_t)&sndc);
-       if (ret != 0) {
+           conn, sizeof(*conn), (uint64_t)(uintptr_t)&sndc);
+       if (error != 0) {
+               if_printf(sc->hn_ifp, "send nvs rxbuf conn failed: %d\n",
+                   error);
+               vmbus_xact_deactivate(xact);
+               vmbus_xact_put(xact);
                goto cleanup;
        }
 
-       sema_wait(&net_dev->channel_init_sema);
-
-       /* Check the response */
-       if (init_pkt->msgs.vers_1_msgs.send_rx_buf_complete.status
-           != nvsp_status_success) {
-               ret = EINVAL;
+       resp = vmbus_xact_wait(xact, &resp_len);
+       if (resp_len < sizeof(*resp)) {
+               if_printf(sc->hn_ifp, "invalid rxbuf conn resp length %zu\n",
+                   resp_len);
+               vmbus_xact_put(xact);
+               error = EINVAL;
+               goto cleanup;
+       }
+       if (resp->nvs_type != HN_NVS_TYPE_RXBUF_CONNRESP) {
+               if_printf(sc->hn_ifp, "not rxbuf conn resp, type %u\n",
+                   resp->nvs_type);
+               vmbus_xact_put(xact);
+               error = EINVAL;
                goto cleanup;
        }
 
-       net_dev->rx_section_count =
-           init_pkt->msgs.vers_1_msgs.send_rx_buf_complete.num_sections;
-
-       net_dev->rx_sections = malloc(net_dev->rx_section_count *
-           sizeof(nvsp_1_rx_buf_section), M_NETVSC, M_WAITOK);
-       memcpy(net_dev->rx_sections, 
-           init_pkt->msgs.vers_1_msgs.send_rx_buf_complete.sections,
-           net_dev->rx_section_count * sizeof(nvsp_1_rx_buf_section));
-
+       status = resp->nvs_status;
+       vmbus_xact_put(xact);
 
-       /*
-        * For first release, there should only be 1 section that represents
-        * the entire receive buffer
-        */
-       if (net_dev->rx_section_count != 1
-           || net_dev->rx_sections->offset != 0) {
-               ret = EINVAL;
+       if (status != HN_NVS_STATUS_OK) {
+               if_printf(sc->hn_ifp, "rxbuf conn failed: %x\n", status);
+               error = EINVAL;
                goto cleanup;
        }
+       net_dev->rx_section_count = 1;
 
-       goto exit;
+       return (0);
 
 cleanup:
        hv_nv_destroy_rx_buffer(net_dev);
-       
-exit:
-       return (ret);
+       return (error);
 }
 
 /*
@@ -371,6 +377,7 @@ hv_nv_destroy_rx_buffer(netvsc_dev *net_
                if (ret != 0) {
                        return (ret);
                }
+               net_dev->rx_section_count = 0;
        }
                
        /* Tear down the gpadl on the vsp end */
@@ -393,12 +400,6 @@ hv_nv_destroy_rx_buffer(netvsc_dev *net_
                net_dev->rx_buf = NULL;
        }
 
-       if (net_dev->rx_sections) {
-               free(net_dev->rx_sections, M_NETVSC);
-               net_dev->rx_sections = NULL;
-               net_dev->rx_section_count = 0;
-       }
-
        return (ret);
 }
 

Modified: head/sys/dev/hyperv/netvsc/hv_net_vsc.h
==============================================================================
--- head/sys/dev/hyperv/netvsc/hv_net_vsc.h     Fri Aug 12 08:07:19 2016        
(r303997)
+++ head/sys/dev/hyperv/netvsc/hv_net_vsc.h     Fri Aug 12 08:07:56 2016        
(r303998)
@@ -1060,7 +1060,6 @@ typedef struct netvsc_dev_ {
        uint32_t                                rx_buf_size;
        uint32_t                                rx_buf_gpadl_handle;
        uint32_t                                rx_section_count;
-       nvsp_1_rx_buf_section                   *rx_sections;
 
        /* Used for NetVSP initialization protocol */
        struct sema                             channel_init_sema;

Modified: head/sys/dev/hyperv/netvsc/if_hnreg.h
==============================================================================
--- head/sys/dev/hyperv/netvsc/if_hnreg.h       Fri Aug 12 08:07:19 2016        
(r303997)
+++ head/sys/dev/hyperv/netvsc/if_hnreg.h       Fri Aug 12 08:07:56 2016        
(r303998)
@@ -32,11 +32,15 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 
+#define HN_NVS_RXBUF_SIG               0xcafe
+
 #define HN_NVS_STATUS_OK               1
 
 #define HN_NVS_TYPE_INIT               1
 #define HN_NVS_TYPE_INIT_RESP          2
 #define HN_NVS_TYPE_NDIS_INIT          100
+#define HN_NVS_TYPE_RXBUF_CONN         101
+#define HN_NVS_TYPE_RXBUF_CONNRESP     102
 #define HN_NVS_TYPE_NDIS_CONF          125
 
 /*
@@ -83,4 +87,26 @@ struct hn_nvs_ndis_init {
 } __packed;
 CTASSERT(sizeof(struct hn_nvs_ndis_init) >= HN_NVS_REQSIZE_MIN);
 
+struct hn_nvs_rxbuf_conn {
+       uint32_t        nvs_type;       /* HN_NVS_TYPE_RXBUF_CONN */
+       uint32_t        nvs_gpadl;      /* RXBUF vmbus GPADL */
+       uint16_t        nvs_sig;        /* HN_NVS_RXBUF_SIG */
+       uint8_t         nvs_rsvd[22];
+} __packed;
+CTASSERT(sizeof(struct hn_nvs_rxbuf_conn) >= HN_NVS_REQSIZE_MIN);
+
+struct hn_nvs_rxbuf_sect {
+       uint32_t        nvs_start;
+       uint32_t        nvs_slotsz;
+       uint32_t        nvs_slotcnt;
+       uint32_t        nvs_end;
+} __packed;
+
+struct hn_nvs_rxbuf_connresp {
+       uint32_t        nvs_type;       /* HN_NVS_TYPE_RXBUF_CONNRESP */
+       uint32_t        nvs_status;     /* HN_NVS_STATUS_ */
+       uint32_t        nvs_nsect;      /* # of elem in nvs_sect */
+       struct hn_nvs_rxbuf_sect nvs_sect[];
+} __packed;
+
 #endif /* !_IF_HNREG_H_ */
_______________________________________________
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