Adopt <net/if_stats.h>.

This commit is contained in:
thorpej 2020-01-31 22:41:07 +00:00
parent 71b3ef8c01
commit be29826f37

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_aq.c,v 1.5 2020/01/25 07:57:48 msaitoh Exp $ */
/* $NetBSD: if_aq.c,v 1.6 2020/01/31 22:41:07 thorpej Exp $ */
/**
* aQuantia Corporation Network Driver
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_aq.c,v 1.5 2020/01/25 07:57:48 msaitoh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_aq.c,v 1.6 2020/01/31 22:41:07 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_if_aq.h"
@ -867,12 +867,6 @@ struct aq_txring {
unsigned int txr_prodidx;
unsigned int txr_considx;
int txr_nfree;
/* counters */
uint64_t txr_opackets;
uint64_t txr_obytes;
uint64_t txr_omcasts;
uint64_t txr_oerrors;
};
struct aq_rxring {
@ -890,12 +884,6 @@ struct aq_rxring {
bus_dmamap_t dmamap;
} rxr_mbufs[AQ_RXD_NUM];
unsigned int rxr_readidx;
/* counters */
uint64_t rxr_ipackets;
uint64_t rxr_ibytes;
uint64_t rxr_ierrors;
uint64_t rxr_iqdrops;
};
struct aq_queue {
@ -4173,6 +4161,8 @@ aq_tx_intr(void *arg)
goto tx_intr_done;
}
net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
for (idx = txring->txr_considx; idx != hw_head;
idx = TXRING_NEXTIDX(idx), n++) {
@ -4180,10 +4170,10 @@ aq_tx_intr(void *arg)
bus_dmamap_unload(sc->sc_dmat,
txring->txr_mbufs[idx].dmamap);
txring->txr_opackets++;
txring->txr_obytes += m->m_pkthdr.len;
if_statinc_ref(nsr, if_opackets);
if_statadd_ref(nsr, if_obytes, m->m_pkthdr.len);
if (m->m_flags & M_MCAST)
txring->txr_omcasts++;
if_statinc_ref(nsr, if_omcasts);
m_freem(m);
txring->txr_mbufs[idx].m = NULL;
@ -4193,6 +4183,8 @@ aq_tx_intr(void *arg)
}
txring->txr_considx = idx;
IF_STAT_PUTREF(ifp);
if (ringidx == 0 && txring->txr_nfree >= AQ_TXD_MIN)
ifp->if_flags &= ~IFF_OACTIVE;
@ -4231,6 +4223,8 @@ aq_rx_intr(void *arg)
goto rx_intr_done;
}
net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
m0 = mprev = NULL;
for (idx = rxring->rxr_readidx;
idx != AQ_READ_REG_BIT(sc, RX_DMA_DESC_HEAD_PTR_REG(ringidx),
@ -4254,7 +4248,7 @@ aq_rx_intr(void *arg)
if ((rxd_status & RXDESC_STATUS_MACERR) ||
(rxd_type & RXDESC_TYPE_MAC_DMA_ERR)) {
rxring->rxr_ierrors++;
if_statinc_ref(nsr, if_ierrors);
goto rx_next;
}
@ -4269,7 +4263,7 @@ aq_rx_intr(void *arg)
* cannot allocate new mbuf.
* discard this packet, and reuse mbuf for next.
*/
rxring->rxr_iqdrops++;
if_statinc_ref(nsr, if_iqdrops);
goto rx_next;
}
rxring->rxr_mbufs[idx].m = NULL;
@ -4371,8 +4365,8 @@ aq_rx_intr(void *arg)
}
#endif
m_set_rcvif(m0, ifp);
rxring->rxr_ipackets++;
rxring->rxr_ibytes += m0->m_pkthdr.len;
if_statinc_ref(nsr, if_ipackets);
if_statadd_ref(nsr, if_ibytes, m0->m_pkthdr.len);
if_percpuq_enqueue(ifp->if_percpuq, m0);
m0 = mprev = NULL;
}
@ -4383,6 +4377,8 @@ aq_rx_intr(void *arg)
}
rxring->rxr_readidx = idx;
IF_STAT_PUTREF(ifp);
rx_intr_done:
mutex_exit(&rxring->rxr_mutex);
@ -4511,7 +4507,7 @@ aq_send_common_locked(struct ifnet *ifp, struct aq_softc *sc,
if (error != 0) {
/* too many mbuf chains? or not enough descriptors? */
m_freem(m);
txring->txr_oerrors++;
if_statinc(ifp, if_oerrors);
if (txring->txr_index == 0 && error == ENOBUFS)
ifp->if_flags |= IFF_OACTIVE;
break;
@ -4668,61 +4664,12 @@ aq_ioctl(struct ifnet *ifp, unsigned long cmd, void *data)
{
struct aq_softc *sc __unused;
struct ifreq *ifr __unused;
uint64_t opackets, oerrors, obytes, omcasts;
uint64_t ipackets, ierrors, ibytes, iqdrops;
int error, i, s;
int error, s;
sc = (struct aq_softc *)ifp->if_softc;
ifr = (struct ifreq *)data;
error = 0;
switch (cmd) {
case SIOCGIFDATA:
case SIOCZIFDATA:
opackets = oerrors = obytes = omcasts = 0;
ipackets = ierrors = ibytes = iqdrops = 0;
for (i = 0; i < sc->sc_nqueues; i++) {
struct aq_txring *txring = &sc->sc_queue[i].txring;
mutex_enter(&txring->txr_mutex);
if (cmd == SIOCZIFDATA) {
txring->txr_opackets = 0;
txring->txr_obytes = 0;
txring->txr_omcasts = 0;
txring->txr_oerrors = 0;
} else {
opackets += txring->txr_opackets;
oerrors += txring->txr_oerrors;
obytes += txring->txr_obytes;
omcasts += txring->txr_omcasts;
}
mutex_exit(&txring->txr_mutex);
struct aq_rxring *rxring = &sc->sc_queue[i].rxring;
mutex_enter(&rxring->rxr_mutex);
if (cmd == SIOCZIFDATA) {
rxring->rxr_ipackets = 0;
rxring->rxr_ibytes = 0;
rxring->rxr_ierrors = 0;
rxring->rxr_iqdrops = 0;
} else {
ipackets += rxring->rxr_ipackets;
ierrors += rxring->rxr_ierrors;
ibytes += rxring->rxr_ibytes;
iqdrops += rxring->rxr_iqdrops;
}
mutex_exit(&rxring->rxr_mutex);
}
ifp->if_opackets = opackets;
ifp->if_oerrors = oerrors;
ifp->if_obytes = obytes;
ifp->if_omcasts = omcasts;
ifp->if_ipackets = ipackets;
ifp->if_ierrors = ierrors;
ifp->if_ibytes = ibytes;
ifp->if_iqdrops = iqdrops;
break;
}
s = splnet();
error = ether_ioctl(ifp, cmd, data);
splx(s);