Wed Jan 29 05:55:16 2020 UTC ()
Adopt <net/if_stats.h>.


(thorpej)
diff -r1.15 -r1.16 src/sys/dev/hyperv/if_hvn.c

cvs diff -r1.15 -r1.16 src/sys/dev/hyperv/if_hvn.c (expand / switch to unified diff)

--- src/sys/dev/hyperv/if_hvn.c 2019/12/27 05:59:53 1.15
+++ src/sys/dev/hyperv/if_hvn.c 2020/01/29 05:55:16 1.16
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_hvn.c,v 1.15 2019/12/27 05:59:53 nonaka Exp $ */ 1/* $NetBSD: if_hvn.c,v 1.16 2020/01/29 05:55:16 thorpej Exp $ */
2/* $OpenBSD: if_hvn.c,v 1.39 2018/03/11 14:31:34 mikeb Exp $ */ 2/* $OpenBSD: if_hvn.c,v 1.39 2018/03/11 14:31:34 mikeb Exp $ */
3 3
4/*- 4/*-
5 * Copyright (c) 2009-2012,2016 Microsoft Corp. 5 * Copyright (c) 2009-2012,2016 Microsoft Corp.
6 * Copyright (c) 2010-2012 Citrix Inc. 6 * Copyright (c) 2010-2012 Citrix Inc.
7 * Copyright (c) 2012 NetApp Inc. 7 * Copyright (c) 2012 NetApp Inc.
8 * Copyright (c) 2016 Mike Belopuhov <mike@esdenera.com> 8 * Copyright (c) 2016 Mike Belopuhov <mike@esdenera.com>
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * The OpenBSD port was done under funding by Esdenera Networks GmbH. 34 * The OpenBSD port was done under funding by Esdenera Networks GmbH.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.15 2019/12/27 05:59:53 nonaka Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.16 2020/01/29 05:55:16 thorpej Exp $");
39 39
40#ifdef _KERNEL_OPT 40#ifdef _KERNEL_OPT
41#include "opt_inet.h" 41#include "opt_inet.h"
42#include "opt_inet6.h" 42#include "opt_inet6.h"
43#include "opt_net_mpsafe.h" 43#include "opt_net_mpsafe.h"
44#endif 44#endif
45 45
46#include <sys/param.h> 46#include <sys/param.h>
47#include <sys/systm.h> 47#include <sys/systm.h>
48#include <sys/kernel.h> 48#include <sys/kernel.h>
49#include <sys/device.h> 49#include <sys/device.h>
50#include <sys/atomic.h> 50#include <sys/atomic.h>
51#include <sys/bus.h> 51#include <sys/bus.h>
@@ -488,36 +488,36 @@ hvn_start(struct ifnet *ifp) @@ -488,36 +488,36 @@ hvn_start(struct ifnet *ifp)
488 for (;;) { 488 for (;;) {
489 if (!sc->sc_tx_avail) { 489 if (!sc->sc_tx_avail) {
490 /* transient */ 490 /* transient */
491 ifp->if_flags |= IFF_OACTIVE; 491 ifp->if_flags |= IFF_OACTIVE;
492 break; 492 break;
493 } 493 }
494 494
495 IFQ_DEQUEUE(&ifp->if_snd, m); 495 IFQ_DEQUEUE(&ifp->if_snd, m);
496 if (m == NULL) 496 if (m == NULL)
497 break; 497 break;
498 498
499 if (hvn_encap(sc, m, &txd)) { 499 if (hvn_encap(sc, m, &txd)) {
500 /* the chain is too large */ 500 /* the chain is too large */
501 ifp->if_oerrors++; 501 if_statinc(ifp, if_oerrors);
502 m_freem(m); 502 m_freem(m);
503 continue; 503 continue;
504 } 504 }
505 505
506 bpf_mtap(ifp, m, BPF_D_OUT); 506 bpf_mtap(ifp, m, BPF_D_OUT);
507 507
508 if (hvn_rndis_output(sc, txd)) { 508 if (hvn_rndis_output(sc, txd)) {
509 hvn_decap(sc, txd); 509 hvn_decap(sc, txd);
510 ifp->if_oerrors++; 510 if_statinc(ifp, if_oerrors);
511 m_freem(m); 511 m_freem(m);
512 continue; 512 continue;
513 } 513 }
514 514
515 sc->sc_tx_next++; 515 sc->sc_tx_next++;
516 } 516 }
517} 517}
518 518
519static inline char * 519static inline char *
520hvn_rndis_pktinfo_append(struct rndis_packet_msg *pkt, size_t pktsize, 520hvn_rndis_pktinfo_append(struct rndis_packet_msg *pkt, size_t pktsize,
521 size_t datalen, uint32_t type) 521 size_t datalen, uint32_t type)
522{ 522{
523 struct rndis_pktinfo *pi; 523 struct rndis_pktinfo *pi;
@@ -668,27 +668,27 @@ hvn_txeof(struct hvn_softc *sc, uint64_t @@ -668,27 +668,27 @@ hvn_txeof(struct hvn_softc *sc, uint64_t
668 txd = &sc->sc_tx_desc[id]; 668 txd = &sc->sc_tx_desc[id];
669 669
670 if ((m = txd->txd_buf) == NULL) { 670 if ((m = txd->txd_buf) == NULL) {
671 device_printf(sc->sc_dev, "no mbuf @%u\n", id); 671 device_printf(sc->sc_dev, "no mbuf @%u\n", id);
672 return; 672 return;
673 } 673 }
674 txd->txd_buf = NULL; 674 txd->txd_buf = NULL;
675 675
676 bus_dmamap_sync(sc->sc_dmat, txd->txd_dmap, 676 bus_dmamap_sync(sc->sc_dmat, txd->txd_dmap,
677 0, txd->txd_dmap->dm_mapsize, 677 0, txd->txd_dmap->dm_mapsize,
678 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); 678 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
679 bus_dmamap_unload(sc->sc_dmat, txd->txd_dmap); 679 bus_dmamap_unload(sc->sc_dmat, txd->txd_dmap);
680 m_freem(m); 680 m_freem(m);
681 ifp->if_opackets++; 681 if_statinc(ifp, if_opackets);
682 682
683 txd->txd_ready = 1; 683 txd->txd_ready = 1;
684 684
685 atomic_inc_uint(&sc->sc_tx_avail); 685 atomic_inc_uint(&sc->sc_tx_avail);
686 ifp->if_flags &= ~IFF_OACTIVE; 686 ifp->if_flags &= ~IFF_OACTIVE;
687} 687}
688 688
689static int 689static int
690hvn_rx_ring_create(struct hvn_softc *sc) 690hvn_rx_ring_create(struct hvn_softc *sc)
691{ 691{
692 struct hvn_nvs_rxbuf_conn cmd; 692 struct hvn_nvs_rxbuf_conn cmd;
693 struct hvn_nvs_rxbuf_conn_resp *rsp; 693 struct hvn_nvs_rxbuf_conn_resp *rsp;
694 uint64_t tid; 694 uint64_t tid;
@@ -1550,27 +1550,27 @@ hvn_rxeof(struct hvn_softc *sc, uint8_t  @@ -1550,27 +1550,27 @@ hvn_rxeof(struct hvn_softc *sc, uint8_t
1550 return; 1550 return;
1551 } 1551 }
1552 1552
1553 pkt = (struct rndis_packet_msg *)buf; 1553 pkt = (struct rndis_packet_msg *)buf;
1554 if (pkt->rm_dataoffset + pkt->rm_datalen > len) { 1554 if (pkt->rm_dataoffset + pkt->rm_datalen > len) {
1555 device_printf(sc->sc_dev, 1555 device_printf(sc->sc_dev,
1556 "data packet out of bounds: %u@%u\n", pkt->rm_dataoffset, 1556 "data packet out of bounds: %u@%u\n", pkt->rm_dataoffset,
1557 pkt->rm_datalen); 1557 pkt->rm_datalen);
1558 return; 1558 return;
1559 } 1559 }
1560 1560
1561 if ((m = hvn_devget(sc, buf + RNDIS_HEADER_OFFSET + pkt->rm_dataoffset, 1561 if ((m = hvn_devget(sc, buf + RNDIS_HEADER_OFFSET + pkt->rm_dataoffset,
1562 pkt->rm_datalen)) == NULL) { 1562 pkt->rm_datalen)) == NULL) {
1563 ifp->if_ierrors++; 1563 if_statinc(ifp, if_ierrors);
1564 return; 1564 return;
1565 } 1565 }
1566 1566
1567 if (pkt->rm_pktinfooffset + pkt->rm_pktinfolen > len) { 1567 if (pkt->rm_pktinfooffset + pkt->rm_pktinfolen > len) {
1568 device_printf(sc->sc_dev, 1568 device_printf(sc->sc_dev,
1569 "pktinfo is out of bounds: %u@%u vs %u\n", 1569 "pktinfo is out of bounds: %u@%u vs %u\n",
1570 pkt->rm_pktinfolen, pkt->rm_pktinfooffset, len); 1570 pkt->rm_pktinfolen, pkt->rm_pktinfooffset, len);
1571 goto done; 1571 goto done;
1572 } 1572 }
1573 1573
1574 pi = (struct rndis_pktinfo *)(buf + RNDIS_HEADER_OFFSET + 1574 pi = (struct rndis_pktinfo *)(buf + RNDIS_HEADER_OFFSET +
1575 pkt->rm_pktinfooffset); 1575 pkt->rm_pktinfooffset);
1576 while (pkt->rm_pktinfolen > 0) { 1576 while (pkt->rm_pktinfolen > 0) {