Skip to content

Commit 0ec2489

Browse files
committed
Added net_device_stats to push IO stats on the device
The xmm7360 module works great. But it seems dead on the UI because there are not stats available on the device. The system monitor etc can see the device but can't show the current statistics like speed, packets etc. This patch fixes that and addds net_device_stats to the driver and keeps track of the packets and number of bytes Tx/Rx'ed. Signed-off-by: Himanshu Chauhan <[email protected]>
1 parent 107b6ba commit 0ec2489

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

xmm7360.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ struct xmm_dev {
212212

213213
struct xmm_net *net;
214214
struct net_device *netdev;
215+
struct net_device_stats stats;
215216

216217
int error;
217218
int card_num;
@@ -919,8 +920,10 @@ static void xmm7360_net_flush(struct xmm_net *xn)
919920
{
920921
struct sk_buff *skb;
921922
struct mux_frame *frame = &xn->frame;
923+
struct net_device_stats *stats = &xn->xmm->stats;
922924
int ret;
923925
u32 unknown = 0;
926+
u32 pp = 0, bp = 0;
924927

925928
if (skb_queue_empty(&xn->queue))
926929
return;
@@ -929,6 +932,8 @@ static void xmm7360_net_flush(struct xmm_net *xn)
929932
xmm7360_mux_frame_add_tag(frame, 'ADBH', 0, NULL, 0);
930933

931934
while ((skb = skb_dequeue(&xn->queue))) {
935+
pp++;
936+
bp += skb->len;
932937
ret = xmm7360_mux_frame_append_packet(frame, skb);
933938
if (ret)
934939
goto drop;
@@ -948,11 +953,15 @@ static void xmm7360_net_flush(struct xmm_net *xn)
948953
goto drop;
949954

950955
xn->queued_packets = xn->queued_bytes = 0;
956+
stats->tx_packets += pp;
957+
stats->tx_bytes += bp;
951958

952959
return;
953960

954961
drop:
955962
dev_err(xn->xmm->dev, "Failed to ship coalesced frame");
963+
stats->tx_dropped += pp;
964+
return;
956965
}
957966

958967
static enum hrtimer_restart xmm7360_net_deadline_cb(struct hrtimer *t)
@@ -1010,6 +1019,7 @@ static void xmm7360_net_mux_handle_frame(struct xmm_net *xn, u8 *data, int len)
10101019
struct sk_buff *skb;
10111020
void *p;
10121021
u8 ip_version;
1022+
struct net_device_stats *stats = &xn->xmm->stats;
10131023

10141024
first = (void *)data;
10151025
if (ntohl(first->tag) == 'ACBH')
@@ -1056,6 +1066,9 @@ static void xmm7360_net_mux_handle_frame(struct xmm_net *xn, u8 *data, int len)
10561066
return;
10571067
}
10581068

1069+
stats->rx_packets++;
1070+
stats->rx_bytes += skb->len;
1071+
10591072
netif_rx(skb);
10601073
}
10611074
}
@@ -1084,10 +1097,17 @@ static void xmm7360_net_poll(struct xmm_dev *xmm)
10841097
}
10851098
}
10861099

1100+
static struct net_device_stats *xmm7360_net_stats(struct net_device *dev)
1101+
{
1102+
struct xmm_net *xn = netdev_priv(dev);
1103+
return &xn->xmm->stats;
1104+
}
1105+
10871106
static const struct net_device_ops xmm7360_netdev_ops = {
10881107
.ndo_uninit = xmm7360_net_uninit,
10891108
.ndo_open = xmm7360_net_open,
10901109
.ndo_stop = xmm7360_net_close,
1110+
.ndo_get_stats = xmm7360_net_stats,
10911111
.ndo_start_xmit = xmm7360_net_xmit,
10921112
};
10931113

0 commit comments

Comments
 (0)