summaryrefslogtreecommitdiffstats
path: root/sys/dev/e1000
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2014-09-18 15:56:14 +0000
committerglebius <glebius@FreeBSD.org>2014-09-18 15:56:14 +0000
commit39fefafe214033dc06483dd023c2485e05ad321c (patch)
tree7a00e00af29505116ade54217ea22b40ed752459 /sys/dev/e1000
parent7288f5d2fcfc7e772a285573fa4a96957b72f3e5 (diff)
downloadFreeBSD-src-39fefafe214033dc06483dd023c2485e05ad321c.zip
FreeBSD-src-39fefafe214033dc06483dd023c2485e05ad321c.tar.gz
- Use if_inc_counter() to increment various counters.
- Do not ever set a counter to a value. For those counters that we don't increment, but return directly from hardware create cases in if_get_counter() method. Sponsored by: Netflix Sponsored by: Nginx, Inc.
Diffstat (limited to 'sys/dev/e1000')
-rw-r--r--sys/dev/e1000/if_em.c43
-rw-r--r--sys/dev/e1000/if_lem.c41
2 files changed, 53 insertions, 31 deletions
diff --git a/sys/dev/e1000/if_em.c b/sys/dev/e1000/if_em.c
index 99ecbf3..d8fc23e 100644
--- a/sys/dev/e1000/if_em.c
+++ b/sys/dev/e1000/if_em.c
@@ -215,6 +215,7 @@ static void em_start(if_t);
static void em_start_locked(if_t, struct tx_ring *);
#endif
static int em_ioctl(if_t, u_long, caddr_t);
+static uint64_t em_get_counter(if_t, ift_counter);
static void em_init(void *);
static void em_init_locked(struct adapter *);
static void em_stop(void *);
@@ -934,9 +935,9 @@ em_mq_start_locked(if_t ifp, struct tx_ring *txr, struct mbuf *m)
}
drbr_advance(ifp, txr->br);
enq++;
- if_incobytes(ifp, next->m_pkthdr.len);
+ if_inc_counter(ifp, IFCOUNTER_OBYTES, next->m_pkthdr.len);
if (next->m_flags & M_MCAST)
- if_incomcasts(ifp, 1);
+ if_inc_counter(ifp, IFCOUNTER_OMCASTS, 1);
if_etherbpfmtap(ifp, next);
if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0)
break;
@@ -2940,6 +2941,7 @@ em_setup_interface(device_t dev, struct adapter *adapter)
if_setsoftc(ifp, adapter);
if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
if_setioctlfn(ifp, em_ioctl);
+ if_setgetcounterfn(ifp, em_get_counter);
#ifdef EM_MULTIQUEUE
/* Multiqueue stack interface */
if_settransmitfn(ifp, em_mq_start);
@@ -3850,7 +3852,7 @@ em_txeof(struct tx_ring *txr)
tx_buffer = &txr->tx_buffers[first];
tx_desc = &txr->tx_base[first];
}
- if_incopackets(ifp, 1);
+ if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
/* See if we can continue to the next packet */
last = tx_buffer->next_eop;
if (last != -1) {
@@ -4450,7 +4452,7 @@ em_rxeof(struct rx_ring *rxr, int count, int *done)
--count;
sendmp = rxr->fmp;
if_setrcvif(sendmp, ifp);
- if_incipackets(ifp, 1);
+ if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
em_receive_checksum(cur, sendmp);
#ifndef __NO_STRICT_ALIGNMENT
if (adapter->hw.mac.max_frame_size >
@@ -5107,7 +5109,6 @@ em_disable_aspm(struct adapter *adapter)
static void
em_update_stats_counters(struct adapter *adapter)
{
- if_t ifp;
if(adapter->hw.phy.media_type == e1000_media_type_copper ||
(E1000_READ_REG(&adapter->hw, E1000_STATUS) & E1000_STATUS_LU)) {
@@ -5199,19 +5200,29 @@ em_update_stats_counters(struct adapter *adapter)
adapter->stats.tsctfc +=
E1000_READ_REG(&adapter->hw, E1000_TSCTFC);
}
- ifp = adapter->ifp;
-
- if_setcollisions(ifp, adapter->stats.colc);
+}
- /* Rx Errors */
- if_setierrors(ifp, adapter->dropped_pkts + adapter->stats.rxerrc +
- adapter->stats.crcerrs + adapter->stats.algnerrc +
- adapter->stats.ruc + adapter->stats.roc +
- adapter->stats.mpc + adapter->stats.cexterr);
+static uint64_t
+em_get_counter(if_t ifp, ift_counter cnt)
+{
+ struct adapter *adapter;
- /* Tx Errors */
- if_setoerrors(ifp, adapter->stats.ecol + adapter->stats.latecol +
- adapter->watchdog_events);
+ adapter = if_getsoftc(ifp);
+
+ switch (cnt) {
+ case IFCOUNTER_COLLISIONS:
+ return (adapter->stats.colc);
+ case IFCOUNTER_IERRORS:
+ return (adapter->dropped_pkts + adapter->stats.rxerrc +
+ adapter->stats.crcerrs + adapter->stats.algnerrc +
+ adapter->stats.ruc + adapter->stats.roc +
+ adapter->stats.mpc + adapter->stats.cexterr);
+ case IFCOUNTER_OERRORS:
+ return (adapter->stats.ecol + adapter->stats.latecol +
+ adapter->watchdog_events);
+ default:
+ return (if_get_counter_default(ifp, cnt));
+ }
}
/* Export a single 32-bit register via a read-only sysctl. */
diff --git a/sys/dev/e1000/if_lem.c b/sys/dev/e1000/if_lem.c
index 8424870..3639318 100644
--- a/sys/dev/e1000/if_lem.c
+++ b/sys/dev/e1000/if_lem.c
@@ -180,6 +180,7 @@ static int lem_resume(device_t);
static void lem_start(if_t);
static void lem_start_locked(if_t ifp);
static int lem_ioctl(if_t, u_long, caddr_t);
+static uint64_t lem_get_counter(if_t, ift_counter);
static void lem_init(void *);
static void lem_init_locked(struct adapter *);
static void lem_stop(void *);
@@ -2464,6 +2465,7 @@ lem_setup_interface(device_t dev, struct adapter *adapter)
if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
if_setioctlfn(ifp, lem_ioctl);
if_setstartfn(ifp, lem_start);
+ if_setgetcounterfn(ifp, lem_get_counter);
if_setsendqlen(ifp, adapter->num_tx_desc - 1);
if_setsendqready(ifp);
@@ -3122,7 +3124,7 @@ lem_txeof(struct adapter *adapter)
++num_avail;
if (tx_buffer->m_head) {
- if_incopackets(ifp, 1);
+ if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
bus_dmamap_sync(adapter->txtag,
tx_buffer->map,
BUS_DMASYNC_POSTWRITE);
@@ -3681,7 +3683,7 @@ lem_rxeof(struct adapter *adapter, int count, int *done)
if (accept_frame) {
if (lem_get_buf(adapter, i) != 0) {
- if_inciqdrops(ifp, 1);
+ if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1);
goto discard;
}
@@ -3712,7 +3714,7 @@ lem_rxeof(struct adapter *adapter, int count, int *done)
if (eop) {
if_setrcvif(adapter->fmp, ifp);
- if_incipackets(ifp, 1);
+ if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
lem_receive_checksum(adapter, current_desc,
adapter->fmp);
#ifndef __NO_STRICT_ALIGNMENT
@@ -4397,7 +4399,6 @@ lem_fill_descriptors (bus_addr_t address, u32 length,
static void
lem_update_stats_counters(struct adapter *adapter)
{
- if_t ifp;
if(adapter->hw.phy.media_type == e1000_media_type_copper ||
(E1000_READ_REG(&adapter->hw, E1000_STATUS) & E1000_STATUS_LU)) {
@@ -4472,19 +4473,29 @@ lem_update_stats_counters(struct adapter *adapter)
adapter->stats.tsctfc +=
E1000_READ_REG(&adapter->hw, E1000_TSCTFC);
}
- ifp = adapter->ifp;
-
- if_setcollisions(ifp, adapter->stats.colc);
+}
- /* Rx Errors */
- if_setierrors(ifp, adapter->dropped_pkts + adapter->stats.rxerrc +
- adapter->stats.crcerrs + adapter->stats.algnerrc +
- adapter->stats.ruc + adapter->stats.roc +
- adapter->stats.mpc + adapter->stats.cexterr);
+static uint64_t
+lem_get_counter(if_t ifp, ift_counter cnt)
+{
+ struct adapter *adapter;
- /* Tx Errors */
- if_setoerrors(ifp, adapter->stats.ecol + adapter->stats.latecol +
- adapter->watchdog_events);
+ adapter = if_getsoftc(ifp);
+
+ switch (cnt) {
+ case IFCOUNTER_COLLISIONS:
+ return (adapter->stats.colc);
+ case IFCOUNTER_IERRORS:
+ return (adapter->dropped_pkts + adapter->stats.rxerrc +
+ adapter->stats.crcerrs + adapter->stats.algnerrc +
+ adapter->stats.ruc + adapter->stats.roc +
+ adapter->stats.mpc + adapter->stats.cexterr);
+ case IFCOUNTER_OERRORS:
+ return (adapter->stats.ecol + adapter->stats.latecol +
+ adapter->watchdog_events);
+ default:
+ return (if_get_counter_default(ifp, cnt));
+ }
}
/* Export a single 32-bit register via a read-only sysctl. */
OpenPOWER on IntegriCloud