]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
MFC r285928 Do not enable UDP checksum offloading when running on the
[FreeBSD/releng/10.2.git] / sys / dev / hyperv / netvsc / hv_netvsc_drv_freebsd.c
1 /*-
2  * Copyright (c) 2010-2012 Citrix Inc.
3  * Copyright (c) 2009-2012 Microsoft Corp.
4  * Copyright (c) 2012 NetApp Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 /*-
30  * Copyright (c) 2004-2006 Kip Macy
31  * All rights reserved.
32  *
33  * Redistribution and use in source and binary forms, with or without
34  * modification, are permitted provided that the following conditions
35  * are met:
36  * 1. Redistributions of source code must retain the above copyright
37  *    notice, this list of conditions and the following disclaimer.
38  * 2. Redistributions in binary form must reproduce the above copyright
39  *    notice, this list of conditions and the following disclaimer in the
40  *    documentation and/or other materials provided with the distribution.
41  *
42  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52  * SUCH DAMAGE.
53  */
54
55 #include <sys/cdefs.h>
56 __FBSDID("$FreeBSD$");
57
58 #include "opt_inet6.h"
59 #include "opt_inet.h"
60
61 #include <sys/param.h>
62 #include <sys/systm.h>
63 #include <sys/sockio.h>
64 #include <sys/mbuf.h>
65 #include <sys/malloc.h>
66 #include <sys/module.h>
67 #include <sys/kernel.h>
68 #include <sys/socket.h>
69 #include <sys/queue.h>
70 #include <sys/lock.h>
71 #include <sys/sx.h>
72
73 #include <net/if.h>
74 #include <net/if_arp.h>
75 #include <net/ethernet.h>
76 #include <net/if_dl.h>
77 #include <net/if_media.h>
78
79 #include <net/bpf.h>
80
81 #include <net/if_types.h>
82 #include <net/if_vlan_var.h>
83 #include <net/if.h>
84
85 #include <netinet/in_systm.h>
86 #include <netinet/in.h>
87 #include <netinet/ip.h>
88 #include <netinet/if_ether.h>
89 #include <netinet/tcp.h>
90 #include <netinet/udp.h>
91 #include <netinet/ip6.h>
92
93 #include <vm/vm.h>
94 #include <vm/vm_param.h>
95 #include <vm/vm_kern.h>
96 #include <vm/pmap.h>
97
98 #include <machine/bus.h>
99 #include <machine/resource.h>
100 #include <machine/frame.h>
101 #include <machine/vmparam.h>
102
103 #include <sys/bus.h>
104 #include <sys/rman.h>
105 #include <sys/mutex.h>
106 #include <sys/errno.h>
107 #include <sys/types.h>
108 #include <machine/atomic.h>
109
110 #include <machine/intr_machdep.h>
111
112 #include <machine/in_cksum.h>
113
114 #include <dev/hyperv/include/hyperv.h>
115 #include "hv_net_vsc.h"
116 #include "hv_rndis.h"
117 #include "hv_rndis_filter.h"
118
119
120 /* Short for Hyper-V network interface */
121 #define NETVSC_DEVNAME    "hn"
122
123 /*
124  * It looks like offset 0 of buf is reserved to hold the softc pointer.
125  * The sc pointer evidently not needed, and is not presently populated.
126  * The packet offset is where the netvsc_packet starts in the buffer.
127  */
128 #define HV_NV_SC_PTR_OFFSET_IN_BUF         0
129 #define HV_NV_PACKET_OFFSET_IN_BUF         16
130
131
132 /*
133  * Data types
134  */
135
136 struct hv_netvsc_driver_context {
137         uint32_t                drv_inited;
138 };
139
140 /*
141  * Be aware that this sleepable mutex will exhibit WITNESS errors when
142  * certain TCP and ARP code paths are taken.  This appears to be a
143  * well-known condition, as all other drivers checked use a sleeping
144  * mutex to protect their transmit paths.
145  * Also Be aware that mutexes do not play well with semaphores, and there
146  * is a conflicting semaphore in a certain channel code path.
147  */
148 #define NV_LOCK_INIT(_sc, _name) \
149             mtx_init(&(_sc)->hn_lock, _name, MTX_NETWORK_LOCK, MTX_DEF)
150 #define NV_LOCK(_sc)            mtx_lock(&(_sc)->hn_lock)
151 #define NV_LOCK_ASSERT(_sc)     mtx_assert(&(_sc)->hn_lock, MA_OWNED)
152 #define NV_UNLOCK(_sc)          mtx_unlock(&(_sc)->hn_lock)
153 #define NV_LOCK_DESTROY(_sc)    mtx_destroy(&(_sc)->hn_lock)
154
155
156 /*
157  * Globals
158  */
159
160 int hv_promisc_mode = 0;    /* normal mode by default */
161
162 /* The one and only one */
163 static struct hv_netvsc_driver_context g_netvsc_drv;
164
165
166 /*
167  * Forward declarations
168  */
169 static void hn_stop(hn_softc_t *sc);
170 static void hn_ifinit_locked(hn_softc_t *sc);
171 static void hn_ifinit(void *xsc);
172 static int  hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
173 static int  hn_start_locked(struct ifnet *ifp);
174 static void hn_start(struct ifnet *ifp);
175
176 /*
177  * NetVsc get message transport protocol type 
178  */
179 static uint32_t get_transport_proto_type(struct mbuf *m_head)
180 {
181         uint32_t ret_val = TRANSPORT_TYPE_NOT_IP;
182         uint16_t ether_type = 0;
183         int ether_len = 0;
184         struct ether_vlan_header *eh;
185 #ifdef INET
186         struct ip *iph;
187 #endif
188 #ifdef INET6
189         struct ip6_hdr *ip6;
190 #endif
191
192         eh = mtod(m_head, struct ether_vlan_header*);
193         if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
194                 ether_len = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
195                 ether_type = eh->evl_proto;
196         } else {
197                 ether_len = ETHER_HDR_LEN;
198                 ether_type = eh->evl_encap_proto;
199         }
200
201         switch (ntohs(ether_type)) {
202 #ifdef INET6
203         case ETHERTYPE_IPV6:
204                 ip6 = (struct ip6_hdr *)(m_head->m_data + ether_len);
205
206                 if (IPPROTO_TCP == ip6->ip6_nxt) {
207                         ret_val = TRANSPORT_TYPE_IPV6_TCP;
208                 } else if (IPPROTO_UDP == ip6->ip6_nxt) {
209                         ret_val = TRANSPORT_TYPE_IPV6_UDP;
210                 }
211                 break;
212 #endif
213 #ifdef INET
214         case ETHERTYPE_IP:
215                 iph = (struct ip *)(m_head->m_data + ether_len);
216
217                 if (IPPROTO_TCP == iph->ip_p) {
218                         ret_val = TRANSPORT_TYPE_IPV4_TCP;
219                 } else if (IPPROTO_UDP == iph->ip_p) {
220                         ret_val = TRANSPORT_TYPE_IPV4_UDP;
221                 }
222                 break;
223 #endif
224         default:
225                 ret_val = TRANSPORT_TYPE_NOT_IP;
226                 break;
227         }
228
229         return (ret_val);
230 }
231
232 /*
233  * NetVsc driver initialization
234  * Note:  Filter init is no longer required
235  */
236 static int
237 netvsc_drv_init(void)
238 {
239         return (0);
240 }
241
242 /*
243  * NetVsc global initialization entry point
244  */
245 static void
246 netvsc_init(void)
247 {
248         if (bootverbose)
249                 printf("Netvsc initializing... ");
250
251         /*
252          * XXXKYS: cleanup initialization
253          */
254         if (!cold && !g_netvsc_drv.drv_inited) {
255                 g_netvsc_drv.drv_inited = 1;
256                 netvsc_drv_init();
257                 if (bootverbose)
258                         printf("done!\n");
259         } else if (bootverbose)
260                 printf("Already initialized!\n");
261 }
262
263 /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */
264 static const hv_guid g_net_vsc_device_type = {
265         .data = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46,
266                 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E}
267 };
268
269 /*
270  * Standard probe entry point.
271  *
272  */
273 static int
274 netvsc_probe(device_t dev)
275 {
276         const char *p;
277
278         p = vmbus_get_type(dev);
279         if (!memcmp(p, &g_net_vsc_device_type.data, sizeof(hv_guid))) {
280                 device_set_desc(dev, "Synthetic Network Interface");
281                 if (bootverbose)
282                         printf("Netvsc probe... DONE \n");
283
284                 return (BUS_PROBE_DEFAULT);
285         }
286
287         return (ENXIO);
288 }
289
290 /*
291  * Standard attach entry point.
292  *
293  * Called when the driver is loaded.  It allocates needed resources,
294  * and initializes the "hardware" and software.
295  */
296 static int
297 netvsc_attach(device_t dev)
298 {
299         struct hv_device *device_ctx = vmbus_get_devctx(dev);
300         netvsc_device_info device_info;
301         hn_softc_t *sc;
302         int unit = device_get_unit(dev);
303         struct ifnet *ifp;
304         int ret;
305
306         netvsc_init();
307
308         sc = device_get_softc(dev);
309         if (sc == NULL) {
310                 return (ENOMEM);
311         }
312
313         bzero(sc, sizeof(hn_softc_t));
314         sc->hn_unit = unit;
315         sc->hn_dev = dev;
316
317         NV_LOCK_INIT(sc, "NetVSCLock");
318
319         sc->hn_dev_obj = device_ctx;
320
321         ifp = sc->hn_ifp = sc->arpcom.ac_ifp = if_alloc(IFT_ETHER);
322         ifp->if_softc = sc;
323
324         if_initname(ifp, device_get_name(dev), device_get_unit(dev));
325         ifp->if_dunit = unit;
326         ifp->if_dname = NETVSC_DEVNAME;
327
328         ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
329         ifp->if_ioctl = hn_ioctl;
330         ifp->if_start = hn_start;
331         ifp->if_init = hn_ifinit;
332         /* needed by hv_rf_on_device_add() code */
333         ifp->if_mtu = ETHERMTU;
334         IFQ_SET_MAXLEN(&ifp->if_snd, 512);
335         ifp->if_snd.ifq_drv_maxlen = 511;
336         IFQ_SET_READY(&ifp->if_snd);
337
338         /*
339          * Tell upper layers that we support full VLAN capability.
340          */
341         ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
342         ifp->if_capabilities |=
343             IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | IFCAP_TSO;
344         ifp->if_capenable |=
345             IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | IFCAP_TSO;
346         /*
347          * Only enable UDP checksum offloading when it is on 2012R2 or
348          * later. UDP checksum offloading doesn't work on earlier
349          * Windows releases.
350          */
351         if (hv_vmbus_protocal_version >= HV_VMBUS_VERSION_WIN8_1)
352                 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_TSO;
353         else
354                 ifp->if_hwassist = CSUM_TCP | CSUM_TSO;
355
356         ret = hv_rf_on_device_add(device_ctx, &device_info);
357         if (ret != 0) {
358                 if_free(ifp);
359
360                 return (ret);
361         }
362         if (device_info.link_state == 0) {
363                 sc->hn_carrier = 1;
364         }
365
366         ether_ifattach(ifp, device_info.mac_addr);
367
368         return (0);
369 }
370
371 /*
372  * Standard detach entry point
373  */
374 static int
375 netvsc_detach(device_t dev)
376 {
377         struct hv_device *hv_device = vmbus_get_devctx(dev); 
378
379         if (bootverbose)
380                 printf("netvsc_detach\n");
381
382         /*
383          * XXXKYS:  Need to clean up all our
384          * driver state; this is the driver
385          * unloading.
386          */
387
388         /*
389          * XXXKYS:  Need to stop outgoing traffic and unregister
390          * the netdevice.
391          */
392
393         hv_rf_on_device_remove(hv_device, HV_RF_NV_DESTROY_CHANNEL);
394
395         return (0);
396 }
397
398 /*
399  * Standard shutdown entry point
400  */
401 static int
402 netvsc_shutdown(device_t dev)
403 {
404         return (0);
405 }
406
407 /*
408  * Send completion processing
409  *
410  * Note:  It looks like offset 0 of buf is reserved to hold the softc
411  * pointer.  The sc pointer is not currently needed in this function, and
412  * it is not presently populated by the TX function.
413  */
414 void
415 netvsc_xmit_completion(void *context)
416 {
417         netvsc_packet *packet = (netvsc_packet *)context;
418         struct mbuf *mb;
419         uint8_t *buf;
420
421         mb = (struct mbuf *)(uintptr_t)packet->compl.send.send_completion_tid;
422         buf = ((uint8_t *)packet) - HV_NV_PACKET_OFFSET_IN_BUF;
423
424         free(buf, M_NETVSC);
425
426         if (mb != NULL) {
427                 m_freem(mb);
428         }
429 }
430
431 /*
432  * Start a transmit of one or more packets
433  */
434 static int
435 hn_start_locked(struct ifnet *ifp)
436 {
437         hn_softc_t *sc = ifp->if_softc;
438         struct hv_device *device_ctx = vmbus_get_devctx(sc->hn_dev);
439         netvsc_dev *net_dev = sc->net_dev;
440         device_t dev = device_ctx->device;
441         uint8_t *buf;
442         netvsc_packet *packet;
443         struct mbuf *m_head, *m;
444         struct mbuf *mc_head = NULL;
445         struct ether_vlan_header *eh;
446         rndis_msg *rndis_mesg;
447         rndis_packet *rndis_pkt;
448         rndis_per_packet_info *rppi;
449         ndis_8021q_info *rppi_vlan_info;
450         rndis_tcp_ip_csum_info *csum_info;
451         rndis_tcp_tso_info *tso_info;   
452         int ether_len;
453         int i;
454         int num_frags;
455         int len;
456         int retries = 0;
457         int ret = 0;    
458         uint32_t rndis_msg_size = 0;
459         uint32_t trans_proto_type;
460         uint32_t send_buf_section_idx =
461             NVSP_1_CHIMNEY_SEND_INVALID_SECTION_INDEX;
462
463         while (!IFQ_DRV_IS_EMPTY(&sc->hn_ifp->if_snd)) {
464                 IFQ_DRV_DEQUEUE(&sc->hn_ifp->if_snd, m_head);
465                 if (m_head == NULL) {
466                         break;
467                 }
468
469                 len = 0;
470                 num_frags = 0;
471
472                 /* Walk the mbuf list computing total length and num frags */
473                 for (m = m_head; m != NULL; m = m->m_next) {
474                         if (m->m_len != 0) {
475                                 num_frags++;
476                                 len += m->m_len;
477                         }
478                 }
479
480                 /*
481                  * Reserve the number of pages requested.  Currently,
482                  * one page is reserved for the message in the RNDIS
483                  * filter packet
484                  */
485                 num_frags += HV_RF_NUM_TX_RESERVED_PAGE_BUFS;
486
487                 /* If exceeds # page_buffers in netvsc_packet */
488                 if (num_frags > NETVSC_PACKET_MAXPAGE) {
489                         device_printf(dev, "exceed max page buffers,%d,%d\n",
490                             num_frags, NETVSC_PACKET_MAXPAGE);
491                         m_freem(m_head);
492                         if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
493                         return (EINVAL);
494                 }
495
496                 /*
497                  * Allocate a buffer with space for a netvsc packet plus a
498                  * number of reserved areas.  First comes a (currently 16
499                  * bytes, currently unused) reserved data area.  Second is
500                  * the netvsc_packet. Third is an area reserved for an 
501                  * rndis_filter_packet struct. Fourth (optional) is a 
502                  * rndis_per_packet_info struct.
503                  * Changed malloc to M_NOWAIT to avoid sleep under spin lock.
504                  * No longer reserving extra space for page buffers, as they
505                  * are already part of the netvsc_packet.
506                  */
507                 buf = malloc(HV_NV_PACKET_OFFSET_IN_BUF +
508                         sizeof(netvsc_packet) + 
509                         sizeof(rndis_msg) +
510                         RNDIS_VLAN_PPI_SIZE +
511                         RNDIS_TSO_PPI_SIZE +
512                         RNDIS_CSUM_PPI_SIZE,
513                         M_NETVSC, M_ZERO | M_NOWAIT);
514                 if (buf == NULL) {
515                         device_printf(dev, "hn:malloc packet failed\n");
516                         m_freem(m_head);
517                         if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
518                         return (ENOMEM);
519                 }
520
521                 packet = (netvsc_packet *)(buf + HV_NV_PACKET_OFFSET_IN_BUF);
522                 *(vm_offset_t *)buf = HV_NV_SC_PTR_OFFSET_IN_BUF;
523
524                 packet->is_data_pkt = TRUE;
525
526                 /* Set up the rndis header */
527                 packet->page_buf_count = num_frags;
528
529                 /* Initialize it from the mbuf */
530                 packet->tot_data_buf_len = len;
531
532                 /*
533                  * extension points to the area reserved for the
534                  * rndis_filter_packet, which is placed just after
535                  * the netvsc_packet (and rppi struct, if present;
536                  * length is updated later).
537                  */
538                 packet->rndis_mesg = packet + 1;
539                 rndis_mesg = (rndis_msg *)packet->rndis_mesg;
540                 rndis_mesg->ndis_msg_type = REMOTE_NDIS_PACKET_MSG;
541
542                 rndis_pkt = &rndis_mesg->msg.packet;
543                 rndis_pkt->data_offset = sizeof(rndis_packet);
544                 rndis_pkt->data_length = packet->tot_data_buf_len;
545                 rndis_pkt->per_pkt_info_offset = sizeof(rndis_packet);
546
547                 rndis_msg_size = RNDIS_MESSAGE_SIZE(rndis_packet);
548
549                 /*
550                  * If the Hyper-V infrastructure needs to embed a VLAN tag,
551                  * initialize netvsc_packet and rppi struct values as needed.
552                  */
553                 if (m_head->m_flags & M_VLANTAG) {
554                         /*
555                          * set up some additional fields so the Hyper-V infrastructure will stuff the VLAN tag
556                          * into the frame.
557                          */
558                         packet->vlan_tci = m_head->m_pkthdr.ether_vtag;
559
560                         rndis_msg_size += RNDIS_VLAN_PPI_SIZE;
561
562                         rppi = hv_set_rppi_data(rndis_mesg, RNDIS_VLAN_PPI_SIZE,
563                             ieee_8021q_info);
564                 
565                         /* VLAN info immediately follows rppi struct */
566                         rppi_vlan_info = (ndis_8021q_info *)((char*)rppi + 
567                             rppi->per_packet_info_offset);
568                         /* FreeBSD does not support CFI or priority */
569                         rppi_vlan_info->u1.s1.vlan_id =
570                             packet->vlan_tci & 0xfff;
571                 }
572
573                 if (0 == m_head->m_pkthdr.csum_flags) {
574                         goto pre_send;
575                 }
576
577                 eh = mtod(m_head, struct ether_vlan_header*);
578                 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
579                         ether_len = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
580                 } else {
581                         ether_len = ETHER_HDR_LEN;
582                 }
583
584                 trans_proto_type = get_transport_proto_type(m_head);
585                 if (TRANSPORT_TYPE_NOT_IP == trans_proto_type) {
586                         goto pre_send;
587                 }
588
589                 /*
590                  * TSO packet needless to setup the send side checksum
591                  * offload.
592                  */
593                 if (m_head->m_pkthdr.csum_flags & CSUM_TSO) {
594                         goto do_tso;
595                 }
596
597                 /* setup checksum offload */
598                 rndis_msg_size += RNDIS_CSUM_PPI_SIZE;
599                 rppi = hv_set_rppi_data(rndis_mesg, RNDIS_CSUM_PPI_SIZE,
600                     tcpip_chksum_info);
601                 csum_info = (rndis_tcp_ip_csum_info *)((char*)rppi +
602                     rppi->per_packet_info_offset);
603
604                 if (trans_proto_type & (TYPE_IPV4 << 16)) {
605                         csum_info->xmit.is_ipv4 = 1;
606                 } else {
607                         csum_info->xmit.is_ipv6 = 1;
608                 }
609
610                 if (trans_proto_type & TYPE_TCP) {
611                         csum_info->xmit.tcp_csum = 1;
612                         csum_info->xmit.tcp_header_offset = 0;
613                 } else if (trans_proto_type & TYPE_UDP) {
614                         csum_info->xmit.udp_csum = 1;
615                 }
616
617                 goto pre_send;
618
619 do_tso:
620                 /* setup TCP segmentation offload */
621                 rndis_msg_size += RNDIS_TSO_PPI_SIZE;
622                 rppi = hv_set_rppi_data(rndis_mesg, RNDIS_TSO_PPI_SIZE,
623                     tcp_large_send_info);
624                 
625                 tso_info = (rndis_tcp_tso_info *)((char *)rppi +
626                     rppi->per_packet_info_offset);
627                 tso_info->lso_v2_xmit.type =
628                     RNDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE;
629                 
630 #ifdef INET
631                 if (trans_proto_type & (TYPE_IPV4 << 16)) {
632                         struct ip *ip =
633                             (struct ip *)(m_head->m_data + ether_len);
634                         unsigned long iph_len = ip->ip_hl << 2;
635                         struct tcphdr *th =
636                             (struct tcphdr *)((caddr_t)ip + iph_len);
637                 
638                         tso_info->lso_v2_xmit.ip_version =
639                             RNDIS_TCP_LARGE_SEND_OFFLOAD_IPV4;
640                         ip->ip_len = 0;
641                         ip->ip_sum = 0;
642                 
643                         th->th_sum = in_pseudo(ip->ip_src.s_addr,
644                             ip->ip_dst.s_addr,
645                             htons(IPPROTO_TCP));
646                 }
647 #endif
648 #if defined(INET6) && defined(INET)
649                 else
650 #endif
651 #ifdef INET6
652                 {
653                         struct ip6_hdr *ip6 =
654                             (struct ip6_hdr *)(m_head->m_data + ether_len);
655                         struct tcphdr *th = (struct tcphdr *)(ip6 + 1);
656
657                         tso_info->lso_v2_xmit.ip_version =
658                             RNDIS_TCP_LARGE_SEND_OFFLOAD_IPV6;
659                         ip6->ip6_plen = 0;
660                         th->th_sum = in6_cksum_pseudo(ip6, 0, IPPROTO_TCP, 0);
661                 }
662 #endif
663                 tso_info->lso_v2_xmit.tcp_header_offset = 0;
664                 tso_info->lso_v2_xmit.mss = m_head->m_pkthdr.tso_segsz;
665
666 pre_send:
667                 rndis_mesg->msg_len = packet->tot_data_buf_len + rndis_msg_size;
668                 packet->tot_data_buf_len = rndis_mesg->msg_len;
669
670                 /* send packet with send buffer */
671                 if (packet->tot_data_buf_len < net_dev->send_section_size) {
672                         send_buf_section_idx =
673                             hv_nv_get_next_send_section(net_dev);
674                         if (send_buf_section_idx !=
675                             NVSP_1_CHIMNEY_SEND_INVALID_SECTION_INDEX) {
676                                 char *dest = ((char *)net_dev->send_buf +
677                                     send_buf_section_idx *
678                                     net_dev->send_section_size);
679
680                                 memcpy(dest, rndis_mesg, rndis_msg_size);
681                                 dest += rndis_msg_size;
682                                 for (m = m_head; m != NULL; m = m->m_next) {
683                                         if (m->m_len) {
684                                                 memcpy(dest,
685                                                     (void *)mtod(m, vm_offset_t),
686                                                     m->m_len);
687                                                 dest += m->m_len;
688                                         }
689                                 }
690
691                                 packet->send_buf_section_idx =
692                                     send_buf_section_idx;
693                                 packet->send_buf_section_size =
694                                     packet->tot_data_buf_len;
695                                 packet->page_buf_count = 0;
696                                 goto do_send;
697                         }
698                 }
699
700                 /* send packet with page buffer */
701                 packet->page_buffers[0].pfn =
702                     atop(hv_get_phys_addr(rndis_mesg));
703                 packet->page_buffers[0].offset =
704                     (unsigned long)rndis_mesg & PAGE_MASK;
705                 packet->page_buffers[0].length = rndis_msg_size;
706
707                 /*
708                  * Fill the page buffers with mbuf info starting at index
709                  * HV_RF_NUM_TX_RESERVED_PAGE_BUFS.
710                  */
711                 i = HV_RF_NUM_TX_RESERVED_PAGE_BUFS;
712                 for (m = m_head; m != NULL; m = m->m_next) {
713                         if (m->m_len) {
714                                 vm_offset_t paddr =
715                                     vtophys(mtod(m, vm_offset_t));
716                                 packet->page_buffers[i].pfn =
717                                     paddr >> PAGE_SHIFT;
718                                 packet->page_buffers[i].offset =
719                                     paddr & (PAGE_SIZE - 1);
720                                 packet->page_buffers[i].length = m->m_len;
721                                 i++;
722                         }
723                 }
724
725                 packet->send_buf_section_idx = 
726                     NVSP_1_CHIMNEY_SEND_INVALID_SECTION_INDEX;
727                 packet->send_buf_section_size = 0;
728
729 do_send:
730
731                 /*
732                  * If bpf, copy the mbuf chain.  This is less expensive than
733                  * it appears; the mbuf clusters are not copied, only their
734                  * reference counts are incremented.
735                  * Needed to avoid a race condition where the completion
736                  * callback is invoked, freeing the mbuf chain, before the
737                  * bpf_mtap code has a chance to run.
738                  */
739                 if (ifp->if_bpf) {
740                         mc_head = m_copypacket(m_head, M_DONTWAIT);
741                 }
742 retry_send:
743                 /* Set the completion routine */
744                 packet->compl.send.on_send_completion = netvsc_xmit_completion;
745                 packet->compl.send.send_completion_context = packet;
746                 packet->compl.send.send_completion_tid = (uint64_t)(uintptr_t)m_head;
747
748                 /* Removed critical_enter(), does not appear necessary */
749                 ret = hv_nv_on_send(device_ctx, packet);
750                 if (ret == 0) {
751                         ifp->if_opackets++;
752                         /* if bpf && mc_head, call bpf_mtap code */
753                         if (mc_head) {
754                                 ETHER_BPF_MTAP(ifp, mc_head);
755                         }
756                 } else {
757                         retries++;
758                         if (retries < 4) {
759                                 goto retry_send;
760                         }
761
762                         IF_PREPEND(&ifp->if_snd, m_head);
763                         ifp->if_drv_flags |= IFF_DRV_OACTIVE;
764
765                         /*
766                          * Null the mbuf pointer so the completion function
767                          * does not free the mbuf chain.  We just pushed the
768                          * mbuf chain back on the if_snd queue.
769                          */
770                         packet->compl.send.send_completion_tid = 0;
771
772                         /*
773                          * Release the resources since we will not get any
774                          * send completion
775                          */
776                         netvsc_xmit_completion(packet);
777                         if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
778                 }
779
780                 /* if bpf && mc_head, free the mbuf chain copy */
781                 if (mc_head) {
782                         m_freem(mc_head);
783                 }
784         }
785
786         return (ret);
787 }
788
789 /*
790  * Link up/down notification
791  */
792 void
793 netvsc_linkstatus_callback(struct hv_device *device_obj, uint32_t status)
794 {
795         hn_softc_t *sc = device_get_softc(device_obj->device);
796
797         if (sc == NULL) {
798                 return;
799         }
800
801         if (status == 1) {
802                 sc->hn_carrier = 1;
803         } else {
804                 sc->hn_carrier = 0;
805         }
806 }
807
808 /*
809  * Append the specified data to the indicated mbuf chain,
810  * Extend the mbuf chain if the new data does not fit in
811  * existing space.
812  *
813  * This is a minor rewrite of m_append() from sys/kern/uipc_mbuf.c.
814  * There should be an equivalent in the kernel mbuf code,
815  * but there does not appear to be one yet.
816  *
817  * Differs from m_append() in that additional mbufs are
818  * allocated with cluster size MJUMPAGESIZE, and filled
819  * accordingly.
820  *
821  * Return 1 if able to complete the job; otherwise 0.
822  */
823 static int
824 hv_m_append(struct mbuf *m0, int len, c_caddr_t cp)
825 {
826         struct mbuf *m, *n;
827         int remainder, space;
828
829         for (m = m0; m->m_next != NULL; m = m->m_next)
830                 ;
831         remainder = len;
832         space = M_TRAILINGSPACE(m);
833         if (space > 0) {
834                 /*
835                  * Copy into available space.
836                  */
837                 if (space > remainder)
838                         space = remainder;
839                 bcopy(cp, mtod(m, caddr_t) + m->m_len, space);
840                 m->m_len += space;
841                 cp += space;
842                 remainder -= space;
843         }
844         while (remainder > 0) {
845                 /*
846                  * Allocate a new mbuf; could check space
847                  * and allocate a cluster instead.
848                  */
849                 n = m_getjcl(M_DONTWAIT, m->m_type, 0, MJUMPAGESIZE);
850                 if (n == NULL)
851                         break;
852                 n->m_len = min(MJUMPAGESIZE, remainder);
853                 bcopy(cp, mtod(n, caddr_t), n->m_len);
854                 cp += n->m_len;
855                 remainder -= n->m_len;
856                 m->m_next = n;
857                 m = n;
858         }
859         if (m0->m_flags & M_PKTHDR)
860                 m0->m_pkthdr.len += len - remainder;
861
862         return (remainder == 0);
863 }
864
865
866 /*
867  * Called when we receive a data packet from the "wire" on the
868  * specified device
869  *
870  * Note:  This is no longer used as a callback
871  */
872 int
873 netvsc_recv(struct hv_device *device_ctx, netvsc_packet *packet,
874     rndis_tcp_ip_csum_info *csum_info)
875 {
876         hn_softc_t *sc = (hn_softc_t *)device_get_softc(device_ctx->device);
877         struct mbuf *m_new;
878         struct ifnet *ifp;
879         device_t dev = device_ctx->device;
880         int size;
881
882         if (sc == NULL) {
883                 return (0); /* TODO: KYS how can this be! */
884         }
885
886         ifp = sc->hn_ifp;
887         
888         ifp = sc->arpcom.ac_ifp;
889
890         if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
891                 return (0);
892         }
893
894         /*
895          * Bail out if packet contains more data than configured MTU.
896          */
897         if (packet->tot_data_buf_len > (ifp->if_mtu + ETHER_HDR_LEN)) {
898                 return (0);
899         }
900
901         /*
902          * Get an mbuf with a cluster.  For packets 2K or less,
903          * get a standard 2K cluster.  For anything larger, get a
904          * 4K cluster.  Any buffers larger than 4K can cause problems
905          * if looped around to the Hyper-V TX channel, so avoid them.
906          */
907         size = MCLBYTES;
908
909         if (packet->tot_data_buf_len > MCLBYTES) {
910                 /* 4096 */
911                 size = MJUMPAGESIZE;
912         }
913
914         m_new = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, size);
915
916         if (m_new == NULL) {
917                 device_printf(dev, "alloc mbuf failed.\n");
918                 return (0);
919         }
920
921         hv_m_append(m_new, packet->tot_data_buf_len,
922                         packet->data);
923
924         m_new->m_pkthdr.rcvif = ifp;
925
926         /* receive side checksum offload */
927         m_new->m_pkthdr.csum_flags = 0;
928         if (NULL != csum_info) {
929                 /* IP csum offload */
930                 if (csum_info->receive.ip_csum_succeeded) {
931                         m_new->m_pkthdr.csum_flags |=
932                             (CSUM_IP_CHECKED | CSUM_IP_VALID);
933                 }
934
935                 /* TCP csum offload */
936                 if (csum_info->receive.tcp_csum_succeeded) {
937                         m_new->m_pkthdr.csum_flags |=
938                             (CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
939                         m_new->m_pkthdr.csum_data = 0xffff;
940                 }
941         }
942
943         if ((packet->vlan_tci != 0) &&
944             (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) != 0) {
945                 m_new->m_pkthdr.ether_vtag = packet->vlan_tci;
946                 m_new->m_flags |= M_VLANTAG;
947         }
948
949         /*
950          * Note:  Moved RX completion back to hv_nv_on_receive() so all
951          * messages (not just data messages) will trigger a response.
952          */
953
954         ifp->if_ipackets++;
955
956         /* We're not holding the lock here, so don't release it */
957         (*ifp->if_input)(ifp, m_new);
958
959         return (0);
960 }
961
962 /*
963  * Rules for using sc->temp_unusable:
964  * 1.  sc->temp_unusable can only be read or written while holding NV_LOCK()
965  * 2.  code reading sc->temp_unusable under NV_LOCK(), and finding 
966  *     sc->temp_unusable set, must release NV_LOCK() and exit
967  * 3.  to retain exclusive control of the interface,
968  *     sc->temp_unusable must be set by code before releasing NV_LOCK()
969  * 4.  only code setting sc->temp_unusable can clear sc->temp_unusable
970  * 5.  code setting sc->temp_unusable must eventually clear sc->temp_unusable
971  */
972
973 /*
974  * Standard ioctl entry point.  Called when the user wants to configure
975  * the interface.
976  */
977 static int
978 hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
979 {
980         hn_softc_t *sc = ifp->if_softc;
981         struct ifreq *ifr = (struct ifreq *)data;
982 #ifdef INET
983         struct ifaddr *ifa = (struct ifaddr *)data;
984 #endif
985         netvsc_device_info device_info;
986         struct hv_device *hn_dev;
987         int mask, error = 0;
988         int retry_cnt = 500;
989         
990         switch(cmd) {
991
992         case SIOCSIFADDR:
993 #ifdef INET
994                 if (ifa->ifa_addr->sa_family == AF_INET) {
995                         ifp->if_flags |= IFF_UP;
996                         if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
997                                 hn_ifinit(sc);
998                         arp_ifinit(ifp, ifa);
999                 } else
1000 #endif
1001                 error = ether_ioctl(ifp, cmd, data);
1002                 break;
1003         case SIOCSIFMTU:
1004                 hn_dev = vmbus_get_devctx(sc->hn_dev);
1005
1006                 /* Check MTU value change */
1007                 if (ifp->if_mtu == ifr->ifr_mtu)
1008                         break;
1009
1010                 if (ifr->ifr_mtu > NETVSC_MAX_CONFIGURABLE_MTU) {
1011                         error = EINVAL;
1012                         break;
1013                 }
1014
1015                 /* Obtain and record requested MTU */
1016                 ifp->if_mtu = ifr->ifr_mtu;
1017                 
1018                 do {
1019                         NV_LOCK(sc);
1020                         if (!sc->temp_unusable) {
1021                                 sc->temp_unusable = TRUE;
1022                                 retry_cnt = -1;
1023                         }
1024                         NV_UNLOCK(sc);
1025                         if (retry_cnt > 0) {
1026                                 retry_cnt--;
1027                                 DELAY(5 * 1000);
1028                         }
1029                 } while (retry_cnt > 0);
1030
1031                 if (retry_cnt == 0) {
1032                         error = EINVAL;
1033                         break;
1034                 }
1035
1036                 /* We must remove and add back the device to cause the new
1037                  * MTU to take effect.  This includes tearing down, but not
1038                  * deleting the channel, then bringing it back up.
1039                  */
1040                 error = hv_rf_on_device_remove(hn_dev, HV_RF_NV_RETAIN_CHANNEL);
1041                 if (error) {
1042                         NV_LOCK(sc);
1043                         sc->temp_unusable = FALSE;
1044                         NV_UNLOCK(sc);
1045                         break;
1046                 }
1047                 error = hv_rf_on_device_add(hn_dev, &device_info);
1048                 if (error) {
1049                         NV_LOCK(sc);
1050                         sc->temp_unusable = FALSE;
1051                         NV_UNLOCK(sc);
1052                         break;
1053                 }
1054
1055                 hn_ifinit_locked(sc);
1056
1057                 NV_LOCK(sc);
1058                 sc->temp_unusable = FALSE;
1059                 NV_UNLOCK(sc);
1060                 break;
1061         case SIOCSIFFLAGS:
1062                 do {
1063                        NV_LOCK(sc);
1064                        if (!sc->temp_unusable) {
1065                                sc->temp_unusable = TRUE;
1066                                retry_cnt = -1;
1067                        }
1068                        NV_UNLOCK(sc);
1069                        if (retry_cnt > 0) {
1070                                 retry_cnt--;
1071                                 DELAY(5 * 1000);
1072                        }
1073                 } while (retry_cnt > 0);
1074
1075                 if (retry_cnt == 0) {
1076                        error = EINVAL;
1077                        break;
1078                 }
1079
1080                 if (ifp->if_flags & IFF_UP) {
1081                         /*
1082                          * If only the state of the PROMISC flag changed,
1083                          * then just use the 'set promisc mode' command
1084                          * instead of reinitializing the entire NIC. Doing
1085                          * a full re-init means reloading the firmware and
1086                          * waiting for it to start up, which may take a
1087                          * second or two.
1088                          */
1089 #ifdef notyet
1090                         /* Fixme:  Promiscuous mode? */
1091                         if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1092                             ifp->if_flags & IFF_PROMISC &&
1093                             !(sc->hn_if_flags & IFF_PROMISC)) {
1094                                 /* do something here for Hyper-V */
1095                         } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1096                             !(ifp->if_flags & IFF_PROMISC) &&
1097                             sc->hn_if_flags & IFF_PROMISC) {
1098                                 /* do something here for Hyper-V */
1099                         } else
1100 #endif
1101                                 hn_ifinit_locked(sc);
1102                 } else {
1103                         if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1104                                 hn_stop(sc);
1105                         }
1106                 }
1107                 NV_LOCK(sc);
1108                 sc->temp_unusable = FALSE;
1109                 NV_UNLOCK(sc);
1110                 sc->hn_if_flags = ifp->if_flags;
1111                 error = 0;
1112                 break;
1113         case SIOCSIFCAP:
1114                 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1115                 if (mask & IFCAP_TXCSUM) {
1116                         if (IFCAP_TXCSUM & ifp->if_capenable) {
1117                                 ifp->if_capenable &= ~IFCAP_TXCSUM;
1118                                 ifp->if_hwassist &= ~(CSUM_TCP | CSUM_UDP);
1119                         } else {
1120                                 ifp->if_capenable |= IFCAP_TXCSUM;
1121                                 /*
1122                                  * Only enable UDP checksum offloading on
1123                                  * Windows Server 2012R2 or later releases.
1124                                  */
1125                                 if (hv_vmbus_protocal_version >=
1126                                     HV_VMBUS_VERSION_WIN8_1) {
1127                                         ifp->if_hwassist |=
1128                                             (CSUM_TCP | CSUM_UDP);
1129                                 } else {
1130                                         ifp->if_hwassist |= CSUM_TCP;
1131                                 }
1132                         }
1133                 }
1134
1135                 if (mask & IFCAP_RXCSUM) {
1136                         if (IFCAP_RXCSUM & ifp->if_capenable) {
1137                                 ifp->if_capenable &= ~IFCAP_RXCSUM;
1138                         } else {
1139                                 ifp->if_capenable |= IFCAP_RXCSUM;
1140                         }
1141                 }
1142
1143                 if (mask & IFCAP_TSO4) {
1144                         ifp->if_capenable ^= IFCAP_TSO4;
1145                         ifp->if_hwassist ^= CSUM_IP_TSO;
1146                 }
1147
1148                 if (mask & IFCAP_TSO6) {
1149                         ifp->if_capenable ^= IFCAP_TSO6;
1150                         ifp->if_hwassist ^= CSUM_IP6_TSO;
1151                 }
1152
1153                 error = 0;
1154                 break;
1155         case SIOCADDMULTI:
1156         case SIOCDELMULTI:
1157 #ifdef notyet
1158                 /* Fixme:  Multicast mode? */
1159                 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1160                         NV_LOCK(sc);
1161                         netvsc_setmulti(sc);
1162                         NV_UNLOCK(sc);
1163                         error = 0;
1164                 }
1165 #endif
1166                 /* FALLTHROUGH */
1167         case SIOCSIFMEDIA:
1168         case SIOCGIFMEDIA:
1169                 error = EINVAL;
1170                 break;
1171         default:
1172                 error = ether_ioctl(ifp, cmd, data);
1173                 break;
1174         }
1175
1176         return (error);
1177 }
1178
1179 /*
1180  *
1181  */
1182 static void
1183 hn_stop(hn_softc_t *sc)
1184 {
1185         struct ifnet *ifp;
1186         int ret;
1187         struct hv_device *device_ctx = vmbus_get_devctx(sc->hn_dev);
1188
1189         ifp = sc->hn_ifp;
1190
1191         if (bootverbose)
1192                 printf(" Closing Device ...\n");
1193
1194         ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1195         if_link_state_change(ifp, LINK_STATE_DOWN);
1196         sc->hn_initdone = 0;
1197
1198         ret = hv_rf_on_close(device_ctx);
1199 }
1200
1201 /*
1202  * FreeBSD transmit entry point
1203  */
1204 static void
1205 hn_start(struct ifnet *ifp)
1206 {
1207         hn_softc_t *sc;
1208
1209         sc = ifp->if_softc;
1210         NV_LOCK(sc);
1211         if (sc->temp_unusable) {
1212                 NV_UNLOCK(sc);
1213                 return;
1214         }
1215         hn_start_locked(ifp);
1216         NV_UNLOCK(sc);
1217 }
1218
1219 /*
1220  *
1221  */
1222 static void
1223 hn_ifinit_locked(hn_softc_t *sc)
1224 {
1225         struct ifnet *ifp;
1226         struct hv_device *device_ctx = vmbus_get_devctx(sc->hn_dev);
1227         int ret;
1228
1229         ifp = sc->hn_ifp;
1230
1231         if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1232                 return;
1233         }
1234
1235         hv_promisc_mode = 1;
1236
1237         ret = hv_rf_on_open(device_ctx);
1238         if (ret != 0) {
1239                 return;
1240         } else {
1241                 sc->hn_initdone = 1;
1242         }
1243         ifp->if_drv_flags |= IFF_DRV_RUNNING;
1244         ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1245         if_link_state_change(ifp, LINK_STATE_UP);
1246 }
1247
1248 /*
1249  *
1250  */
1251 static void
1252 hn_ifinit(void *xsc)
1253 {
1254         hn_softc_t *sc = xsc;
1255
1256         NV_LOCK(sc);
1257         if (sc->temp_unusable) {
1258                 NV_UNLOCK(sc);
1259                 return;
1260         }
1261         sc->temp_unusable = TRUE;
1262         NV_UNLOCK(sc);
1263
1264         hn_ifinit_locked(sc);
1265
1266         NV_LOCK(sc);
1267         sc->temp_unusable = FALSE;
1268         NV_UNLOCK(sc);
1269 }
1270
1271 #ifdef LATER
1272 /*
1273  *
1274  */
1275 static void
1276 hn_watchdog(struct ifnet *ifp)
1277 {
1278         hn_softc_t *sc;
1279         sc = ifp->if_softc;
1280
1281         printf("hn%d: watchdog timeout -- resetting\n", sc->hn_unit);
1282         hn_ifinit(sc);    /*???*/
1283         ifp->if_oerrors++;
1284 }
1285 #endif
1286
1287 static device_method_t netvsc_methods[] = {
1288         /* Device interface */
1289         DEVMETHOD(device_probe,         netvsc_probe),
1290         DEVMETHOD(device_attach,        netvsc_attach),
1291         DEVMETHOD(device_detach,        netvsc_detach),
1292         DEVMETHOD(device_shutdown,      netvsc_shutdown),
1293
1294         { 0, 0 }
1295 };
1296
1297 static driver_t netvsc_driver = {
1298         NETVSC_DEVNAME,
1299         netvsc_methods,
1300         sizeof(hn_softc_t)
1301 };
1302
1303 static devclass_t netvsc_devclass;
1304
1305 DRIVER_MODULE(hn, vmbus, netvsc_driver, netvsc_devclass, 0, 0);
1306 MODULE_VERSION(hn, 1);
1307 MODULE_DEPEND(hn, vmbus, 1, 1, 1);
1308 SYSINIT(netvsc_initx, SI_SUB_KTHREAD_IDLE, SI_ORDER_MIDDLE + 1, netvsc_init,
1309      NULL);
1310