Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci virtio(4): Sprinkle KNF.



details:   https://anonhg.NetBSD.org/src/rev/817e96e8fe56
branches:  trunk
changeset: 371887:817e96e8fe56
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Oct 15 19:53:27 2022 +0000

description:
virtio(4): Sprinkle KNF.

No functional change intended.

diffstat:

 sys/dev/pci/virtio.c |  207 +++++++++++++++++++++++++++-----------------------
 1 files changed, 113 insertions(+), 94 deletions(-)

diffs (truncated from 581 to 300 lines):

diff -r 4220548b4eee -r 817e96e8fe56 sys/dev/pci/virtio.c
--- a/sys/dev/pci/virtio.c      Sat Oct 15 19:51:04 2022 +0000
+++ b/sys/dev/pci/virtio.c      Sat Oct 15 19:53:27 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: virtio.c,v 1.58 2022/08/14 10:06:54 riastradh Exp $    */
+/*     $NetBSD: virtio.c,v 1.59 2022/10/15 19:53:27 riastradh Exp $    */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.58 2022/08/14 10:06:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.59 2022/10/15 19:53:27 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -105,8 +105,8 @@
                        continue;
                if (n != vq->vq_num) {
                        panic("%s: virtqueue size changed, vq index %d\n",
-                             device_xname(sc->sc_dev),
-                             vq->vq_index);
+                           device_xname(sc->sc_dev),
+                           vq->vq_index);
                }
                virtio_init_vq(sc, vq, true);
                sc->sc_ops->setup_queue(sc, vq->vq_index,
@@ -167,7 +167,8 @@
 
 
 uint8_t
-virtio_read_device_config_1(struct virtio_softc *sc, int index) {
+virtio_read_device_config_1(struct virtio_softc *sc, int index)
+{
        bus_space_tag_t    iot = sc->sc_devcfg_iot;
        bus_space_handle_t ioh = sc->sc_devcfg_ioh;
        uint8_t val;
@@ -179,7 +180,8 @@
 }
 
 uint16_t
-virtio_read_device_config_2(struct virtio_softc *sc, int index) {
+virtio_read_device_config_2(struct virtio_softc *sc, int index)
+{
        bus_space_tag_t    iot = sc->sc_devcfg_iot;
        bus_space_handle_t ioh = sc->sc_devcfg_ioh;
        uint16_t val;
@@ -190,13 +192,15 @@
 
        DPRINTFR("read_2", "%04x", val, index, 2);
        DPRINTFR2("read_2", "%04x",
-               bus_space_read_stream_2(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index),
-               bus_space_read_2(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index));
+           bus_space_read_stream_2(sc->sc_devcfg_iot, sc->sc_devcfg_ioh,
+               index),
+           bus_space_read_2(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index));
        return val;
 }
 
 uint32_t
-virtio_read_device_config_4(struct virtio_softc *sc, int index) {
+virtio_read_device_config_4(struct virtio_softc *sc, int index)
+{
        bus_space_tag_t    iot = sc->sc_devcfg_iot;
        bus_space_handle_t ioh = sc->sc_devcfg_ioh;
        uint32_t val;
@@ -207,8 +211,9 @@
 
        DPRINTFR("read_4", "%08x", val, index, 4);
        DPRINTFR2("read_4", "%08x",
-               bus_space_read_stream_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index),
-               bus_space_read_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index));
+           bus_space_read_stream_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh,
+               index),
+           bus_space_read_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index));
        return val;
 }
 
@@ -218,7 +223,8 @@
  * it. We access it using two 32 reads. See virtio spec 4.1.3.1.
  */
 uint64_t
-virtio_read_device_config_8(struct virtio_softc *sc, int index) {
+virtio_read_device_config_8(struct virtio_softc *sc, int index)
+{
        bus_space_tag_t    iot = sc->sc_devcfg_iot;
        bus_space_handle_t ioh = sc->sc_devcfg_ioh;
        union {
@@ -240,11 +246,13 @@
 
        DPRINTFR("read_8", "%08lx", val, index, 8);
        DPRINTFR2("read_8 low ", "%08x",
-               bus_space_read_stream_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index),
-               bus_space_read_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index));
+           bus_space_read_stream_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh,
+               index),
+           bus_space_read_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index));
        DPRINTFR2("read_8 high ", "%08x",
-               bus_space_read_stream_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index + 4),
-               bus_space_read_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index + 4));
+           bus_space_read_stream_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh,
+               index + 4),
+           bus_space_read_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index + 4));
        return val;
 }
 
@@ -254,7 +262,8 @@
  * register to always be little endian. These functions cater for these.
  */
 uint16_t
-virtio_read_device_config_le_2(struct virtio_softc *sc, int index) {
+virtio_read_device_config_le_2(struct virtio_softc *sc, int index)
+{
        bus_space_tag_t    iot = sc->sc_devcfg_iot;
        bus_space_handle_t ioh = sc->sc_devcfg_ioh;
        uint16_t val;
@@ -265,13 +274,14 @@
 
        DPRINTFR("read_le_2", "%04x", val, index, 2);
        DPRINTFR2("read_le_2", "%04x",
-               bus_space_read_stream_2(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, 0),
-               bus_space_read_2(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, 0));
+           bus_space_read_stream_2(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, 0),
+           bus_space_read_2(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, 0));
        return val;
 }
 
 uint32_t
-virtio_read_device_config_le_4(struct virtio_softc *sc, int index) {
+virtio_read_device_config_le_4(struct virtio_softc *sc, int index)
+{
        bus_space_tag_t    iot = sc->sc_devcfg_iot;
        bus_space_handle_t ioh = sc->sc_devcfg_ioh;
        uint32_t val;
@@ -282,8 +292,8 @@
 
        DPRINTFR("read_le_4", "%08x", val, index, 4);
        DPRINTFR2("read_le_4", "%08x",
-               bus_space_read_stream_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, 0),
-               bus_space_read_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, 0));
+           bus_space_read_stream_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, 0),
+           bus_space_read_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, 0));
        return val;
 }
 
@@ -297,7 +307,8 @@
 }
 
 void
-virtio_write_device_config_2(struct virtio_softc *sc, int index, uint16_t value)
+virtio_write_device_config_2(struct virtio_softc *sc, int index,
+    uint16_t value)
 {
        bus_space_tag_t    iot = sc->sc_devcfg_iot;
        bus_space_handle_t ioh = sc->sc_devcfg_ioh;
@@ -308,7 +319,8 @@
 }
 
 void
-virtio_write_device_config_4(struct virtio_softc *sc, int index, uint32_t value)
+virtio_write_device_config_4(struct virtio_softc *sc, int index,
+    uint32_t value)
 {
        bus_space_tag_t    iot = sc->sc_devcfg_iot;
        bus_space_handle_t ioh = sc->sc_devcfg_ioh;
@@ -326,7 +338,8 @@
  * spec 4.1.3.1.
  */
 void
-virtio_write_device_config_8(struct virtio_softc *sc, int index, uint64_t value)
+virtio_write_device_config_8(struct virtio_softc *sc, int index,
+    uint64_t value)
 {
        bus_space_tag_t    iot = sc->sc_devcfg_iot;
        bus_space_handle_t ioh = sc->sc_devcfg_ioh;
@@ -359,7 +372,8 @@
  * register to always be little endian. These functions cater for these.
  */
 void
-virtio_write_device_config_le_2(struct virtio_softc *sc, int index, uint16_t value)
+virtio_write_device_config_le_2(struct virtio_softc *sc, int index,
+    uint16_t value)
 {
        bus_space_tag_t    iot = sc->sc_devcfg_iot;
        bus_space_handle_t ioh = sc->sc_devcfg_ioh;
@@ -370,7 +384,8 @@
 }
 
 void
-virtio_write_device_config_le_4(struct virtio_softc *sc, int index, uint32_t value)
+virtio_write_device_config_le_4(struct virtio_softc *sc, int index,
+    uint32_t value)
 {
        bus_space_tag_t    iot = sc->sc_devcfg_iot;
        bus_space_handle_t ioh = sc->sc_devcfg_ioh;
@@ -384,19 +399,22 @@
 /*
  * data structures endian helpers
  */
-uint16_t virtio_rw16(struct virtio_softc *sc, uint16_t val)
+uint16_t
+virtio_rw16(struct virtio_softc *sc, uint16_t val)
 {
        KASSERT(sc);
        return BYTE_ORDER != sc->sc_struct_endian ? bswap16(val) : val;
 }
 
-uint32_t virtio_rw32(struct virtio_softc *sc, uint32_t val)
+uint32_t
+virtio_rw32(struct virtio_softc *sc, uint32_t val)
 {
        KASSERT(sc);
        return BYTE_ORDER != sc->sc_struct_endian ? bswap32(val) : val;
 }
 
-uint64_t virtio_rw64(struct virtio_softc *sc, uint64_t val)
+uint64_t
+virtio_rw64(struct virtio_softc *sc, uint64_t val)
 {
        KASSERT(sc);
        return BYTE_ORDER != sc->sc_struct_endian ? bswap64(val) : val;
@@ -588,7 +606,7 @@
  */
 int
 virtio_postpone_intr(struct virtio_softc *sc, struct virtqueue *vq,
-               uint16_t nslots)
+    uint16_t nslots)
 {
        uint16_t        idx, nused;
 
@@ -600,7 +618,7 @@
        vq->vq_queued++;
 
        nused = (uint16_t)
-               (virtio_rw16(sc, vq->vq_used->idx) - vq->vq_used_idx);
+           (virtio_rw16(sc, vq->vq_used->idx) - vq->vq_used_idx);
        KASSERT(nused <= vq->vq_num);
 
        return nslots < nused;
@@ -616,7 +634,7 @@
        uint16_t        nslots;
 
        nslots = (uint16_t)
-               (virtio_rw16(sc, vq->vq_avail->idx) - vq->vq_used_idx) * 3 / 4;
+           (virtio_rw16(sc, vq->vq_avail->idx) - vq->vq_used_idx) * 3 / 4;
 
        return virtio_postpone_intr(sc, vq, nslots);
 }
@@ -631,7 +649,7 @@
        uint16_t        nslots;
 
        nslots = (uint16_t)
-               (virtio_rw16(sc, vq->vq_avail->idx) - vq->vq_used_idx);
+           (virtio_rw16(sc, vq->vq_avail->idx) - vq->vq_used_idx);
 
        return virtio_postpone_intr(sc, vq, nslots);
 }
@@ -705,7 +723,7 @@
                for (i = 0; i < vq_size; i++) {
                        vd = vq->vq_indirect;
                        vd += vq->vq_maxnsegs * i;
-                       for (j = 0; j < vq->vq_maxnsegs-1; j++) {
+                       for (j = 0; j < vq->vq_maxnsegs - 1; j++) {
                                vd[j].next = virtio_rw16(sc, j + 1);
                        }
                }
@@ -714,8 +732,8 @@
        /* free slot management */
        SIMPLEQ_INIT(&vq->vq_freelist);
        for (i = 0; i < vq_size; i++) {
-               SIMPLEQ_INSERT_TAIL(&vq->vq_freelist,
-                                   &vq->vq_entries[i], qe_list);
+               SIMPLEQ_INSERT_TAIL(&vq->vq_freelist, &vq->vq_entries[i],
+                   qe_list);
                vq->vq_entries[i].qe_index = i;
        }
        if (!reinit)
@@ -742,8 +760,8 @@
 {
        int vq_size, allocsize1, allocsize2, allocsize3, allocsize = 0;
        int rsegs, r, hdrlen;
-#define VIRTQUEUE_ALIGN(n)     (((n)+(VIRTIO_PAGE_SIZE-1))&    \
-                                ~(VIRTIO_PAGE_SIZE-1))
+#define VIRTQUEUE_ALIGN(n)     (((n) + (VIRTIO_PAGE_SIZE - 1)) &       \
+                                   ~(VIRTIO_PAGE_SIZE - 1))
 
        /* Make sure callers allocate vqs in order */
        KASSERT(sc->sc_nvqs == index);
@@ -753,8 +771,8 @@
        vq_size = sc->sc_ops->read_queue_size(sc, index);
        if (vq_size == 0) {
                aprint_error_dev(sc->sc_dev,
-                                "virtqueue not exist, index %d for %s\n",
-                                index, name);
+                   "virtqueue not exist, index %d for %s\n",
+                   index, name);
                goto err;
        }



Home | Main Index | Thread Index | Old Index