Thu Mar 23 02:52:29 2023 UTC ()
vioif(4): rename sc_hdr_segs to sc_segs


(yamaguchi)
diff -r1.99 -r1.100 src/sys/dev/pci/if_vioif.c

cvs diff -r1.99 -r1.100 src/sys/dev/pci/if_vioif.c (expand / switch to unified diff)

--- src/sys/dev/pci/if_vioif.c 2023/03/23 02:48:29 1.99
+++ src/sys/dev/pci/if_vioif.c 2023/03/23 02:52:29 1.100
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_vioif.c,v 1.99 2023/03/23 02:48:29 yamaguchi Exp $ */ 1/* $NetBSD: if_vioif.c,v 1.100 2023/03/23 02:52:29 yamaguchi Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2020 The NetBSD Foundation, Inc.
5 * Copyright (c) 2010 Minoura Makoto. 5 * Copyright (c) 2010 Minoura Makoto.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 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 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 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 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 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. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.99 2023/03/23 02:48:29 yamaguchi Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.100 2023/03/23 02:52:29 yamaguchi Exp $");
31 31
32#ifdef _KERNEL_OPT 32#ifdef _KERNEL_OPT
33#include "opt_net_mpsafe.h" 33#include "opt_net_mpsafe.h"
34#endif 34#endif
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/kernel.h> 38#include <sys/kernel.h>
39#include <sys/atomic.h> 39#include <sys/atomic.h>
40#include <sys/bus.h> 40#include <sys/bus.h>
41#include <sys/condvar.h> 41#include <sys/condvar.h>
42#include <sys/device.h> 42#include <sys/device.h>
43#include <sys/evcnt.h> 43#include <sys/evcnt.h>
@@ -316,27 +316,27 @@ struct vioif_softc { @@ -316,27 +316,27 @@ struct vioif_softc {
316 int sc_max_nvq_pairs; 316 int sc_max_nvq_pairs;
317 int sc_req_nvq_pairs; 317 int sc_req_nvq_pairs;
318 int sc_act_nvq_pairs; 318 int sc_act_nvq_pairs;
319 319
320 uint8_t sc_mac[ETHER_ADDR_LEN]; 320 uint8_t sc_mac[ETHER_ADDR_LEN];
321 struct ethercom sc_ethercom; 321 struct ethercom sc_ethercom;
322 int sc_link_state; 322 int sc_link_state;
323 323
324 struct vioif_netqueue *sc_netqs; 324 struct vioif_netqueue *sc_netqs;
325 325
326 bool sc_has_ctrl; 326 bool sc_has_ctrl;
327 struct vioif_ctrlqueue sc_ctrlq; 327 struct vioif_ctrlqueue sc_ctrlq;
328 328
329 bus_dma_segment_t sc_hdr_segs[1]; 329 bus_dma_segment_t sc_segs[1];
330 void *sc_dmamem; 330 void *sc_dmamem;
331 void *sc_kmem; 331 void *sc_kmem;
332 332
333 void *sc_ctl_softint; 333 void *sc_ctl_softint;
334 334
335 struct workqueue *sc_txrx_workqueue; 335 struct workqueue *sc_txrx_workqueue;
336 bool sc_txrx_workqueue_sysctl; 336 bool sc_txrx_workqueue_sysctl;
337 u_int sc_tx_intr_process_limit; 337 u_int sc_tx_intr_process_limit;
338 u_int sc_tx_process_limit; 338 u_int sc_tx_process_limit;
339 u_int sc_rx_intr_process_limit; 339 u_int sc_rx_intr_process_limit;
340 u_int sc_rx_process_limit; 340 u_int sc_rx_process_limit;
341}; 341};
342#define VIRTIO_NET_TX_MAXNSEGS (16) /* XXX */ 342#define VIRTIO_NET_TX_MAXNSEGS (16) /* XXX */
@@ -742,34 +742,34 @@ vioif_alloc_mems(struct vioif_softc *sc) @@ -742,34 +742,34 @@ vioif_alloc_mems(struct vioif_softc *sc)
742 if (sc->sc_has_ctrl) { 742 if (sc->sc_has_ctrl) {
743 dmamemsize += sizeof(struct virtio_net_ctrl_cmd); 743 dmamemsize += sizeof(struct virtio_net_ctrl_cmd);
744 dmamemsize += sizeof(struct virtio_net_ctrl_status); 744 dmamemsize += sizeof(struct virtio_net_ctrl_status);
745 dmamemsize += sizeof(struct virtio_net_ctrl_rx); 745 dmamemsize += sizeof(struct virtio_net_ctrl_rx);
746 dmamemsize += sizeof(struct virtio_net_ctrl_mac_tbl) 746 dmamemsize += sizeof(struct virtio_net_ctrl_mac_tbl)
747 + ETHER_ADDR_LEN; 747 + ETHER_ADDR_LEN;
748 dmamemsize += sizeof(struct virtio_net_ctrl_mac_tbl) 748 dmamemsize += sizeof(struct virtio_net_ctrl_mac_tbl)
749 + ETHER_ADDR_LEN * VIRTIO_NET_CTRL_MAC_MAXENTRIES; 749 + ETHER_ADDR_LEN * VIRTIO_NET_CTRL_MAC_MAXENTRIES;
750 dmamemsize += sizeof(struct virtio_net_ctrl_mac_addr); 750 dmamemsize += sizeof(struct virtio_net_ctrl_mac_addr);
751 dmamemsize += sizeof(struct virtio_net_ctrl_mq); 751 dmamemsize += sizeof(struct virtio_net_ctrl_mq);
752 } 752 }
753 753
754 r = bus_dmamem_alloc(virtio_dmat(vsc), dmamemsize, 0, 0, 754 r = bus_dmamem_alloc(virtio_dmat(vsc), dmamemsize, 0, 0,
755 &sc->sc_hdr_segs[0], 1, &rsegs, BUS_DMA_NOWAIT); 755 &sc->sc_segs[0], 1, &rsegs, BUS_DMA_NOWAIT);
756 if (r != 0) { 756 if (r != 0) {
757 aprint_error_dev(sc->sc_dev, 757 aprint_error_dev(sc->sc_dev,
758 "DMA memory allocation failed, size %zu, " 758 "DMA memory allocation failed, size %zu, "
759 "error code %d\n", dmamemsize, r); 759 "error code %d\n", dmamemsize, r);
760 goto err_none; 760 goto err_none;
761 } 761 }
762 r = bus_dmamem_map(virtio_dmat(vsc),&sc->sc_hdr_segs[0], 1, 762 r = bus_dmamem_map(virtio_dmat(vsc), &sc->sc_segs[0], 1,
763 dmamemsize, &vaddr, BUS_DMA_NOWAIT); 763 dmamemsize, &vaddr, BUS_DMA_NOWAIT);
764 if (r != 0) { 764 if (r != 0) {
765 aprint_error_dev(sc->sc_dev, 765 aprint_error_dev(sc->sc_dev,
766 "DMA memory map failed, error code %d\n", r); 766 "DMA memory map failed, error code %d\n", r);
767 goto err_dmamem_alloc; 767 goto err_dmamem_alloc;
768 } 768 }
769 769
770 /* assign DMA memory */ 770 /* assign DMA memory */
771 memset(vaddr, 0, dmamemsize); 771 memset(vaddr, 0, dmamemsize);
772 sc->sc_dmamem = vaddr; 772 sc->sc_dmamem = vaddr;
773 p = (intptr_t) vaddr; 773 p = (intptr_t) vaddr;
774 774
775 for (qid = 0; qid < netq_num; qid++) { 775 for (qid = 0; qid < netq_num; qid++) {
@@ -943,27 +943,27 @@ err_reqs: @@ -943,27 +943,27 @@ err_reqs:
943 maps = sc->sc_netqs[qid].netq_maps; 943 maps = sc->sc_netqs[qid].netq_maps;
944 944
945 for (i = 0; i < vq_num; i++) { 945 for (i = 0; i < vq_num; i++) {
946 vioif_dmamap_destroy(sc, &maps[i].vnm_mbuf_map); 946 vioif_dmamap_destroy(sc, &maps[i].vnm_mbuf_map);
947 vioif_dmamap_destroy(sc, &maps[i].vnm_hdr_map); 947 vioif_dmamap_destroy(sc, &maps[i].vnm_hdr_map);
948 } 948 }
949 } 949 }
950 if (sc->sc_kmem) { 950 if (sc->sc_kmem) {
951 kmem_free(sc->sc_kmem, kmemsize); 951 kmem_free(sc->sc_kmem, kmemsize);
952 sc->sc_kmem = NULL; 952 sc->sc_kmem = NULL;
953 } 953 }
954 bus_dmamem_unmap(virtio_dmat(vsc), sc->sc_dmamem, dmamemsize); 954 bus_dmamem_unmap(virtio_dmat(vsc), sc->sc_dmamem, dmamemsize);
955err_dmamem_alloc: 955err_dmamem_alloc:
956 bus_dmamem_free(virtio_dmat(vsc), &sc->sc_hdr_segs[0], 1); 956 bus_dmamem_free(virtio_dmat(vsc), &sc->sc_segs[0], 1);
957err_none: 957err_none:
958 return -1; 958 return -1;
959} 959}
960 960
961static void 961static void
962vioif_attach(device_t parent, device_t self, void *aux) 962vioif_attach(device_t parent, device_t self, void *aux)
963{ 963{
964 struct vioif_softc *sc = device_private(self); 964 struct vioif_softc *sc = device_private(self);
965 struct virtio_softc *vsc = device_private(parent); 965 struct virtio_softc *vsc = device_private(parent);
966 struct vioif_netqueue *txq0; 966 struct vioif_netqueue *txq0;
967 struct vioif_ctrlqueue *ctrlq = &sc->sc_ctrlq; 967 struct vioif_ctrlqueue *ctrlq = &sc->sc_ctrlq;
968 uint64_t features, req_features; 968 uint64_t features, req_features;
969 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 969 struct ifnet *ifp = &sc->sc_ethercom.ec_if;