Commit 2c6d94ee authored by Alessandro Rubini's avatar Alessandro Rubini

kernel: make wr_pstats and wr_nic talk

wr_nic now exports wr_nic_pstats_callback as a pointer. When wr_pstats
is loaded it writes its own pointer in there.

wr_nic can thus ask for statistics and updated net_device_stats with
the proper numbers.   The statistics on snmp reflect this, because
snmpd uses the standard device ioctl commands -- but very few of our
counters actually end up all the way to snmp.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 61d913c8
......@@ -5,9 +5,11 @@ wr-nic-objs := module.o device.o nic-core.o endpoint.o ethtool.o \
# accept WRN_DEBUG from the environment. It turns pr_debug() into printk.
ifdef WRN_DEBUG
EXTRA_CFLAGS += -DDEBUG
ccflags-y += -DDEBUG
endif
ccflags-y += -I$(src)/../wr_pstats
# What follows is standard stuff
export ARCH ?= arm
export CROSS_COMPILE ?= $(CROSS_COMPILE_ARM)
......
......@@ -20,6 +20,7 @@
#include <asm/unaligned.h>
#include "wr-nic.h"
#include "wr_pstats.h"
#include "nic-mem.h"
/*
......@@ -219,11 +220,46 @@ static int wrn_start_xmit(struct sk_buff *skb, struct net_device *dev)
return 0;
}
int (*wr_nic_pstats_callback)(int epnum,
unsigned int ctr[PSTATS_CNT_PP]);
EXPORT_SYMBOL(wr_nic_pstats_callback);
static unsigned int nic_counters[PSTATS_CNT_PP];
static DEFINE_SPINLOCK(nic_counters_lock);
struct net_device_stats *wrn_get_stats(struct net_device *dev)
{
struct wrn_ep *ep = netdev_priv(dev);
/* FIXME: we should get the RMON information from endpoint */
if (wr_nic_pstats_callback) {
int i;
spin_lock(&nic_counters_lock);
wr_nic_pstats_callback(ep->ep_number, nic_counters);
if (0) {
/* A stupid diagnostics, happens oh so often... */
printk(KERN_INFO "counters for %i:", ep->ep_number);
for (i = 0; i < PSTATS_CNT_PP; i++)
printk(KERN_CONT " %u", nic_counters[i]);
printk(KERN_CONT "\n");
} else {
/* Recover values in the kernel structure */
ep->stats.rx_packets =
nic_counters[PSTATS_C_R_FRAME];
ep->stats.tx_packets =
nic_counters[PSTATS_C_T_FRAME];
ep->stats.rx_length_errors =
nic_counters[PSTATS_C_R_GIANT];
ep->stats.rx_crc_errors =
nic_counters[PSTATS_C_R_CRC_ERROR];
ep->stats.rx_fifo_errors =
nic_counters[PSTATS_C_R_OVERRUN];
ep->stats.tx_fifo_errors =
nic_counters[PSTATS_C_T_UNDERRUN];
}
spin_unlock(&nic_counters_lock);
}
return &ep->stats;
return NULL;
}
......
......@@ -229,7 +229,19 @@ static ctl_table proc_table[] = {
{0,}
};
/*
* This module is optional, in a way, and if there it is loaded after
* wr_nic. So it must register itself to wr_nic, to export this.
*/
int pstats_callback(int epnum, unsigned int cntr[PSTATS_CNT_PP])
{
int i;
pstats_rd_cntrs(epnum);
for (i = 0; i < PSTATS_CNT_PP; i++)
cntr[i] = *cntr_idx(pstats_dev.cntrs, epnum, i);
return 0;
}
static struct ctl_table_header *pstats_header;
......@@ -249,7 +261,7 @@ static int __init pstats_init(void)
pstats_ctl_table[i].maxlen = PSTATS_CNT_PP*sizeof(unsigned int);
pstats_ctl_table[i].mode = 0444;
pstats_ctl_table[i].proc_handler = pstats_handler;
pstats_ctl_table[i].extra1 = i;
pstats_ctl_table[i].extra1 = (void *)i;
}
pstats_header = register_sysctl_table(proc_table);
......@@ -285,6 +297,8 @@ static int __init pstats_init(void)
spin_lock_init(&pstats_dev.port_mutex[i]);
pstats_irq_enable(portmsk);
wr_nic_pstats_callback = pstats_callback;
printk(KERN_INFO "%s: initialized\n", KBUILD_MODNAME);
return 0;
......
......@@ -21,5 +21,49 @@
#define PSTATS_IRQBUFSZ 16
extern int (*wr_nic_pstats_callback)(int epnum,
unsigned int ctr[PSTATS_CNT_PP]);
enum { /* names for values, from page 14 of hw/gw document */
PSTATS_C_T_UNDERRUN = 0,
PSTATS_C_R_OVERRUN,
PSTATS_C_R_INVALID_CODE,
PSTATS_C_R_SYNC_LOST,
PSTATS_C_R_PAUSE,
PSTATS_C_R_PFILTER_DROP,
PSTATS_C_R_PCS_ERROR,
PSTATS_C_R_GIANT,
PSTATS_C_R_RUNT,
PSTATS_C_R_CRC_ERROR,
PSTATS_C_R_PCLASS_0,
PSTATS_C_R_PCLASS_1,
PSTATS_C_R_PCLASS_2,
PSTATS_C_R_PCLASS_3,
PSTATS_C_R_PCLASS_4,
PSTATS_C_R_PCLASS_5,
PSTATS_C_R_PCLASS_6,
PSTATS_C_R_PCLASS_7,
PSTATS_C_T_FRAME,
PSTATS_C_R_FRAME,
PSTATS_C_RTU_REQ_FLAG,
PSTATS_C_R_PRI_0,
PSTATS_C_R_PRI_1,
PSTATS_C_R_PRI_2,
PSTATS_C_R_PRI_3,
PSTATS_C_R_PRI_4,
PSTATS_C_R_PRI_5,
PSTATS_C_R_PRI_6,
PSTATS_C_R_PRI_7,
PSTATS_C_RTU_REQ,
PSTATS_C_RTU_RESP,
PSTATS_C_RTU_DROPS,
PSTATS_C_RTU_HP,
PSTATS_C_RTU_FF,
PSTATS_C_RTU_NF,
PSTATS_C_RTU_FST,
PSTATS_C_RTU_FULL,
PSTATS_C_RTU_FWD,
PSTATS_C_RTU_RSP,
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment