Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci - KNF
details: https://anonhg.NetBSD.org/src/rev/67bd561b7f6a
branches: trunk
changeset: 454361:67bd561b7f6a
user: christos <christos%NetBSD.org@localhost>
date: Sat Sep 14 21:09:00 2019 +0000
description:
- KNF
- fix typo in error message
- use aprint* everywhere
- use loops to initialize mac
- remove unused variables
diffstat:
sys/dev/pci/if_vioif.c | 180 ++++++++++++++++++------------------------------
1 files changed, 68 insertions(+), 112 deletions(-)
diffs (truncated from 401 to 300 lines):
diff -r a8e5d50a2d46 -r 67bd561b7f6a sys/dev/pci/if_vioif.c
--- a/sys/dev/pci/if_vioif.c Sat Sep 14 17:11:39 2019 +0000
+++ b/sys/dev/pci/if_vioif.c Sat Sep 14 21:09:00 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_vioif.c,v 1.49 2019/05/23 13:10:52 msaitoh Exp $ */
+/* $NetBSD: if_vioif.c,v 1.50 2019/09/14 21:09:00 christos Exp $ */
/*
* Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.49 2019/05/23 13:10:52 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.50 2019/09/14 21:09:00 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_net_mpsafe.h"
@@ -470,25 +470,23 @@
allocsize += sizeof(struct virtio_net_ctrl_status) * 1;
allocsize += sizeof(struct virtio_net_ctrl_rx) * 1;
allocsize += sizeof(struct virtio_net_ctrl_mac_tbl)
- + sizeof(struct virtio_net_ctrl_mac_tbl)
- + ETHER_ADDR_LEN * VIRTIO_NET_CTRL_MAC_MAXENTRIES;
+ + sizeof(struct virtio_net_ctrl_mac_tbl)
+ + ETHER_ADDR_LEN * VIRTIO_NET_CTRL_MAC_MAXENTRIES;
allocsize += sizeof(struct virtio_net_ctrl_mq) * 1;
}
r = bus_dmamem_alloc(virtio_dmat(vsc), allocsize, 0, 0,
- &sc->sc_hdr_segs[0], 1, &rsegs, BUS_DMA_NOWAIT);
+ &sc->sc_hdr_segs[0], 1, &rsegs, BUS_DMA_NOWAIT);
if (r != 0) {
aprint_error_dev(sc->sc_dev,
- "DMA memory allocation failed, size %d, "
- "error code %d\n", allocsize, r);
+ "DMA memory allocation failed, size %d, "
+ "error code %d\n", allocsize, r);
goto err_none;
}
r = bus_dmamem_map(virtio_dmat(vsc),
- &sc->sc_hdr_segs[0], 1, allocsize,
- &vaddr, BUS_DMA_NOWAIT);
+ &sc->sc_hdr_segs[0], 1, allocsize, &vaddr, BUS_DMA_NOWAIT);
if (r != 0) {
aprint_error_dev(sc->sc_dev,
- "DMA memory map failed, "
- "error code %d\n", r);
+ "DMA memory map failed, error code %d\n", r);
goto err_dmamem_alloc;
}
@@ -511,11 +509,9 @@
P(p, ctrlq->ctrlq_cmd, sizeof(*ctrlq->ctrlq_cmd));
P(p, ctrlq->ctrlq_status, sizeof(*ctrlq->ctrlq_status));
P(p, ctrlq->ctrlq_rx, sizeof(*ctrlq->ctrlq_rx));
- P(p, ctrlq->ctrlq_mac_tbl_uc,
- sizeof(*ctrlq->ctrlq_mac_tbl_uc) + 0);
- P(p, ctrlq->ctrlq_mac_tbl_mc,
- (sizeof(*ctrlq->ctrlq_mac_tbl_mc)
- + ETHER_ADDR_LEN * VIRTIO_NET_CTRL_MAC_MAXENTRIES));
+ P(p, ctrlq->ctrlq_mac_tbl_uc, sizeof(*ctrlq->ctrlq_mac_tbl_uc));
+ P(p, ctrlq->ctrlq_mac_tbl_mc, sizeof(*ctrlq->ctrlq_mac_tbl_mc)
+ + ETHER_ADDR_LEN * VIRTIO_NET_CTRL_MAC_MAXENTRIES);
P(p, ctrlq->ctrlq_mq, sizeof(*ctrlq->ctrlq_mq));
}
@@ -565,8 +561,8 @@
&map); \
if (r != 0) { \
aprint_error_dev(sc->sc_dev, \
- "%s dmamap creation failed, " \
- "error code %d\n", usage, r); \
+ usage " dmamap creation failed, " \
+ "error code %d\n", r); \
goto err_reqs; \
} \
} while (0)
@@ -578,8 +574,8 @@
rw | BUS_DMA_NOWAIT); \
if (r != 0) { \
aprint_error_dev(sc->sc_dev, \
- usage " dmamap load failed, " \
- "error code %d\n", r); \
+ usage " dmamap load failed, " \
+ "error code %d\n", r); \
goto err_reqs; \
} \
} while (0)
@@ -693,8 +689,7 @@
if (virtio_child(vsc) != NULL) {
aprint_normal(": child already attached for %s; "
- "something wrong...\n",
- device_xname(parent));
+ "something wrong...\n", device_xname(parent));
return;
}
@@ -729,18 +724,10 @@
features = virtio_features(vsc);
if (features & VIRTIO_NET_F_MAC) {
- sc->sc_mac[0] = virtio_read_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+0);
- sc->sc_mac[1] = virtio_read_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+1);
- sc->sc_mac[2] = virtio_read_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+2);
- sc->sc_mac[3] = virtio_read_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+3);
- sc->sc_mac[4] = virtio_read_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+4);
- sc->sc_mac[5] = virtio_read_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+5);
+ for (i = 0; i < __arraycount(sc->sc_mac); i++) {
+ sc->sc_mac[i] = virtio_read_device_config_1(vsc,
+ VIRTIO_NET_CONFIG_MAC + i);
+ }
} else {
/* code stolen from sys/net/if_tap.c */
struct timeval tv;
@@ -748,27 +735,14 @@
getmicrouptime(&tv);
ui = (tv.tv_sec ^ tv.tv_usec) & 0xffffff;
memcpy(sc->sc_mac+3, (uint8_t *)&ui, 3);
- virtio_write_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+0,
- sc->sc_mac[0]);
- virtio_write_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+1,
- sc->sc_mac[1]);
- virtio_write_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+2,
- sc->sc_mac[2]);
- virtio_write_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+3,
- sc->sc_mac[3]);
- virtio_write_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+4,
- sc->sc_mac[4]);
- virtio_write_device_config_1(vsc,
- VIRTIO_NET_CONFIG_MAC+5,
- sc->sc_mac[5]);
+ for (i = 0; i < __arraycount(sc->sc_mac); i++) {
+ virtio_write_device_config_1(vsc,
+ VIRTIO_NET_CONFIG_MAC + i, sc->sc_mac[i]);
+ }
}
- aprint_normal_dev(self, "Ethernet address %s\n", ether_sprintf(sc->sc_mac));
+ aprint_normal_dev(self, "Ethernet address %s\n",
+ ether_sprintf(sc->sc_mac));
if ((features & VIRTIO_NET_F_CTRL_VQ) &&
(features & VIRTIO_NET_F_CTRL_RX)) {
@@ -814,7 +788,8 @@
rxq->rxq_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
- rxq->rxq_softint = softint_establish(softint_flags, vioif_rx_softint, rxq);
+ rxq->rxq_softint = softint_establish(softint_flags,
+ vioif_rx_softint, rxq);
if (rxq->rxq_softint == NULL) {
aprint_error_dev(self, "cannot establish rx softint\n");
goto err;
@@ -838,8 +813,8 @@
}
snprintf(qname, sizeof(qname), "tx%d", i);
r = virtio_alloc_vq(vsc, txq->txq_vq, nvqs,
- (sizeof(struct virtio_net_hdr)
- + (ETHER_MAX_LEN - ETHER_HDR_LEN)),
+ sizeof(struct virtio_net_hdr)
+ + (ETHER_MAX_LEN - ETHER_HDR_LEN),
VIRTIO_NET_TX_MAXNSEGS + 1, qname);
if (r != 0)
goto err;
@@ -861,7 +836,8 @@
NBPG, 1, "control");
if (r != 0) {
aprint_error_dev(self, "failed to allocate "
- "a virtqueue for control channel\n");
+ "a virtqueue for control channel, error code %d\n",
+ r);
sc->sc_has_ctrl = false;
cv_destroy(&ctrlq->ctrlq_wait);
@@ -971,7 +947,7 @@
r = vioif_set_promisc(sc, false);
if (r != 0)
aprint_error_dev(self, "resetting promisc mode failed, "
- "errror code %d\n", r);
+ "error code %d\n", r);
}
static void
@@ -1156,8 +1132,7 @@
panic("enqueue_prep for a tx buffer");
r = bus_dmamap_load_mbuf(virtio_dmat(vsc),
- txq->txq_dmamaps[slot],
- m, BUS_DMA_WRITE | BUS_DMA_NOWAIT);
+ txq->txq_dmamaps[slot], m, BUS_DMA_WRITE | BUS_DMA_NOWAIT);
if (r != 0) {
/* maybe just too fragmented */
struct mbuf *newm;
@@ -1171,8 +1146,8 @@
m = newm;
r = bus_dmamap_load_mbuf(virtio_dmat(vsc),
- txq->txq_dmamaps[slot],
- m, BUS_DMA_WRITE | BUS_DMA_NOWAIT);
+ txq->txq_dmamaps[slot], m,
+ BUS_DMA_WRITE | BUS_DMA_NOWAIT);
if (r != 0) {
aprint_error_dev(sc->sc_dev,
"tx dmamap load failed, error code %d\n",
@@ -1202,11 +1177,11 @@
memset(&txq->txq_hdrs[slot], 0, sizeof(struct virtio_net_hdr));
bus_dmamap_sync(virtio_dmat(vsc), txq->txq_dmamaps[slot],
- 0, txq->txq_dmamaps[slot]->dm_mapsize,
- BUS_DMASYNC_PREWRITE);
+ 0, txq->txq_dmamaps[slot]->dm_mapsize,
+ BUS_DMASYNC_PREWRITE);
bus_dmamap_sync(virtio_dmat(vsc), txq->txq_hdr_dmamaps[slot],
- 0, txq->txq_hdr_dmamaps[slot]->dm_mapsize,
- BUS_DMASYNC_PREWRITE);
+ 0, txq->txq_hdr_dmamaps[slot]->dm_mapsize,
+ BUS_DMASYNC_PREWRITE);
virtio_enqueue(vsc, vq, slot, txq->txq_hdr_dmamaps[slot], true);
virtio_enqueue(vsc, vq, slot, txq->txq_dmamaps[slot], true);
virtio_enqueue_commit(vsc, vq, slot, false);
@@ -1362,8 +1337,7 @@
rxq->rxq_mbufs[i] = m;
m->m_len = m->m_pkthdr.len = m->m_ext.ext_size;
r = bus_dmamap_load_mbuf(virtio_dmat(vsc),
- rxq->rxq_dmamaps[i],
- m, BUS_DMA_READ | BUS_DMA_NOWAIT);
+ rxq->rxq_dmamaps[i], m, BUS_DMA_READ | BUS_DMA_NOWAIT);
if (r) {
m_freem(m);
rxq->rxq_mbufs[i] = NULL;
@@ -1417,23 +1391,24 @@
if (rxq->rxq_mbufs[slot] == NULL) {
r = vioif_add_rx_mbuf(rxq, slot);
if (r != 0) {
- printf("%s: rx mbuf allocation failed, "
- "error code %d\n",
- device_xname(sc->sc_dev), r);
+ aprint_error_dev(sc->sc_dev,
+ "rx mbuf allocation failed, "
+ "error code %d\n", r);
break;
}
}
r = virtio_enqueue_reserve(vsc, vq, slot,
- rxq->rxq_dmamaps[slot]->dm_nsegs + 1);
+ rxq->rxq_dmamaps[slot]->dm_nsegs + 1);
if (r != 0) {
vioif_free_rx_mbuf(rxq, slot);
break;
}
bus_dmamap_sync(virtio_dmat(vsc), rxq->rxq_hdr_dmamaps[slot],
- 0, sizeof(struct virtio_net_hdr), BUS_DMASYNC_PREREAD);
+ 0, sizeof(struct virtio_net_hdr), BUS_DMASYNC_PREREAD);
bus_dmamap_sync(virtio_dmat(vsc), rxq->rxq_dmamaps[slot],
- 0, MCLBYTES, BUS_DMASYNC_PREREAD);
- virtio_enqueue(vsc, vq, slot, rxq->rxq_hdr_dmamaps[slot], false);
+ 0, MCLBYTES, BUS_DMASYNC_PREREAD);
+ virtio_enqueue(vsc, vq, slot, rxq->rxq_hdr_dmamaps[slot],
+ false);
virtio_enqueue(vsc, vq, slot, rxq->rxq_dmamaps[slot], false);
virtio_enqueue_commit(vsc, vq, slot, false);
ndone++;
@@ -1475,11 +1450,9 @@
len -= sizeof(struct virtio_net_hdr);
r = 1;
bus_dmamap_sync(virtio_dmat(vsc), rxq->rxq_hdr_dmamaps[slot],
- 0, sizeof(struct virtio_net_hdr),
- BUS_DMASYNC_POSTREAD);
+ 0, sizeof(struct virtio_net_hdr), BUS_DMASYNC_POSTREAD);
bus_dmamap_sync(virtio_dmat(vsc), rxq->rxq_dmamaps[slot],
- 0, MCLBYTES,
- BUS_DMASYNC_POSTREAD);
+ 0, MCLBYTES, BUS_DMASYNC_POSTREAD);
m = rxq->rxq_mbufs[slot];
KASSERT(m != NULL);
bus_dmamap_unload(virtio_dmat(vsc), rxq->rxq_dmamaps[slot]);
@@ -1604,11 +1577,10 @@
while (virtio_dequeue(vsc, vq, &slot, &len) == 0) {
r++;
bus_dmamap_sync(virtio_dmat(vsc), txq->txq_hdr_dmamaps[slot],
- 0, sizeof(struct virtio_net_hdr),
- BUS_DMASYNC_POSTWRITE);
+ 0, sizeof(struct virtio_net_hdr), BUS_DMASYNC_POSTWRITE);
bus_dmamap_sync(virtio_dmat(vsc), txq->txq_dmamaps[slot],
- 0, txq->txq_dmamaps[slot]->dm_mapsize,
- BUS_DMASYNC_POSTWRITE);
+ 0, txq->txq_dmamaps[slot]->dm_mapsize,
+ BUS_DMASYNC_POSTWRITE);
Home |
Main Index |
Thread Index |
Old Index