Commit c76f523b authored by Adam Wujek's avatar Adam Wujek 💬

kernel/wr_nic: support variable number of counters in wr_nic

Changes also in wr_pstats.
Wr_nic now calls callback function in wr_pstats to get counters
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 5238b9d4
......@@ -228,10 +228,9 @@ static int wrn_start_xmit(struct sk_buff *skb, struct net_device *dev)
#if WR_IS_SWITCH
int (*wr_nic_pstats_callback)(int epnum,
unsigned int ctr[PSTATS_CNT_PP]);
struct net_device_stats *stats);
EXPORT_SYMBOL(wr_nic_pstats_callback);
static unsigned int nic_counters[PSTATS_CNT_PP];
static DEFINE_SPINLOCK(nic_counters_lock);
#endif
......@@ -241,31 +240,8 @@ struct net_device_stats *wrn_get_stats(struct net_device *dev)
#if WR_IS_SWITCH
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];
}
wr_nic_pstats_callback(ep->ep_number, &(ep->stats));
spin_unlock(&nic_counters_lock);
}
#endif
......
......@@ -27,6 +27,7 @@
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/moduleparam.h>
#include <linux/netdevice.h>
#include "../wbgen-regs/pstats-regs.h"
#include "wr_pstats.h"
......@@ -42,6 +43,66 @@ const char *portnames[] = {"port0", "port1", "port2", "port3", "port4",
"port5", "port6", "port7", "port8", "port9", "port10", "port11",
"port12", "port13", "port14", "port15", "port16", "port17"};
static struct pstats_version_description
pstats_desc[PSTATS_NAMES_ARRAY_SIZE] = {
[0] = {
.cnt_names = "Inv pstats ver reported by FPGA",
.rx_packets = 0,
.tx_packets = 0,
.rx_length_errors = 0,
.rx_crc_errors = 0,
.rx_fifo_errors = 0,
.tx_fifo_errors = 0
},
[1] = {
.cnt_names = "TX Underrun\n" /* 0 */
"RX Overrun\n" /* 1 */
"RX Invalid Code\n" /* 2 */
"RX Sync Lost\n" /* 3 */
"RX Pause Frames\n" /* 4 */
"RX Pfilter Dropped\n" /* 5 */
"RX PCS Errors\n" /* 6 */
"RX Giant Frames\n" /* 7 */
"RX Runt Frames\n" /* 8 */
"RX CRC Errors\n" /* 9 */
"RX Pclass 0\n" /* 10 */
"RX Pclass 1\n" /* 11 */
"RX Pclass 2\n" /* 12 */
"RX Pclass 3\n" /* 13 */
"RX Pclass 4\n" /* 14 */
"RX Pclass 5\n" /* 15 */
"RX Pclass 6\n" /* 16 */
"RX Pclass 7\n" /* 17 */
"TX Frames\n" /* 18 */
"RX Frames\n" /* 19 */
"RX Drop RTU Full\n" /* 20 */
"RX PRIO 0\n" /* 21 */
"RX PRIO 1\n" /* 22 */
"RX PRIO 2\n" /* 23 */
"RX PRIO 3\n" /* 24 */
"RX PRIO 4\n" /* 25 */
"RX PRIO 5\n" /* 26 */
"RX PRIO 6\n" /* 27 */
"RX PRIO 7\n" /* 28 */
"RTU Valid\n" /* 29 */
"RTU Responses\n" /* 30 */
"RTU Dropped\n" /* 31 */
"FastMatch: Priority\n" /* 32 */
"FastMatch: FastForward\n" /* 33 */
"FastMatch: NonForward\n" /* 34 */
"FastMatch: Resp Valid\n" /* 35 */
"FullMatch: Resp Valid\n" /* 36 */
"Forwarded\n" /* 37 */
"TRU Resp Valid", /* 38 */
.rx_packets = 19, /* RX Frames */
.tx_packets = 18, /* TX Frames */
.rx_length_errors = 7, /* RX Giant Frames */
.rx_crc_errors = 9, /* RX CRC Errors */
.rx_fifo_errors = 1, /* RX Overrun */
.tx_fifo_errors = 0 /* TX Underrun */
}
};
struct cntrs_dev {
unsigned int cntrs[PSTATS_NPORTS][PSTATS_CNT_PP];
......@@ -260,12 +321,11 @@ static int pstats_desc_handler(ctl_table *ctl, int write, void *buffer,
/* get version number */
data = pstats_readl(pstats_dev, INFO);
version = PSTATS_INFO_VER_R(data);
if (version >= PSTATS_NAMES_ARRAY_SIZE) {
if (version >= ARRAY_SIZE(pstats_desc))
version = 0;
}
ctl->data = (void *)pstats_names[version];
ctl->maxlen = strlen(pstats_names[version]);
ctl->data = (void *)pstats_desc[version].cnt_names;
ctl->maxlen = strlen(pstats_desc[version].cnt_names);
return proc_dostring(ctl, 0, buffer, lenp, ppos);
}
......@@ -322,15 +382,34 @@ static ctl_table proc_table[] = {
* 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 pstats_callback(int epnum, struct net_device_stats *stats)
{
int i;
unsigned int data;
unsigned int version;
unsigned int index;
data = pstats_readl(pstats_dev, INFO);
version = PSTATS_INFO_VER_R(data);
pstats_rd_cntrs(epnum);
/* We could just memcpy, but this has to change anyways*/
for (i = 0; i < PSTATS_CNT_PP; i++)
cntr[i] = pstats_dev.cntrs[epnum][i];
if (version >= ARRAY_SIZE(pstats_desc)) {
/* don't update counters,
* wrong version suppouse to be already reported */
return 0;
}
index = pstats_desc[version].rx_packets;
stats->rx_packets = (unsigned long) pstats_dev.cntrs[epnum][index];
index = pstats_desc[version].tx_packets;
stats->tx_packets = (unsigned long) pstats_dev.cntrs[epnum][index];
index = pstats_desc[version].rx_length_errors;
stats->rx_length_errors = (unsigned long)pstats_dev.cntrs[epnum][index];
index = pstats_desc[version].rx_crc_errors;
stats->rx_crc_errors = (unsigned long)pstats_dev.cntrs[epnum][index];
index = pstats_desc[version].rx_fifo_errors;
stats->rx_fifo_errors = (unsigned long)pstats_dev.cntrs[epnum][index];
index = pstats_desc[version].tx_fifo_errors;
stats->tx_fifo_errors = (unsigned long)pstats_dev.cntrs[epnum][index];
return 0;
}
......@@ -413,8 +492,8 @@ static int __init pstats_init(void)
data = pstats_readl(pstats_dev, INFO);
version = PSTATS_INFO_VER_R(data);
if (version >= PSTATS_NAMES_ARRAY_SIZE)
printk(KERN_INFO "port stats version %d not supported\n",
if (version >= ARRAY_SIZE(pstats_desc))
printk(KERN_INFO "pstats version %d not supported\n",
version);
printk(KERN_INFO "%s: initialized\n", KBUILD_MODNAME);
......
......@@ -7,50 +7,7 @@
#define WRVIC_BASE_IRQ (NR_AIC_IRQS + (5 * 32))
/*****/
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,
/* number of counters, add new entries before this line */
PSTATS_NUM_OF_COUNTERS,
};
#define PSTATS_NUM_OF_COUNTERS 39
#define PSTATS_NPORTS 18 /* how many eth ports are in the switch */
#define PSTATS_CNT_PP PSTATS_NUM_OF_COUNTERS /* how many counters per port */
......@@ -73,49 +30,16 @@ enum { /* names for values, from page 14 of hw/gw document */
#define PINFO_CNTPP 2
extern int (*wr_nic_pstats_callback)(int epnum,
unsigned int ctr[PSTATS_CNT_PP]);
static char *pstats_names[PSTATS_NAMES_ARRAY_SIZE] = {
[0] = "Inv pstats ver reported by FPGA" ,
[1] = "TX Underrun\n"
"RX Overrun\n"
"RX Invalid Code\n"
"RX Sync Lost\n"
"RX Pause Frames\n"
"RX Pfilter Dropped\n"
"RX PCS Errors\n"
"RX Giant Frames\n"
"RX Runt Frames\n"
"RX CRC Errors\n"
"RX Pclass 0\n"
"RX Pclass 1\n"
"RX Pclass 2\n"
"RX Pclass 3\n"
"RX Pclass 4\n"
"RX Pclass 5\n"
"RX Pclass 6\n"
"RX Pclass 7\n"
"TX Frames\n"
"RX Frames\n"
"RX Drop RTU Full\n"
"RX PRIO 0\n"
"RX PRIO 1\n"
"RX PRIO 2\n"
"RX PRIO 3\n"
"RX PRIO 4\n"
"RX PRIO 5\n"
"RX PRIO 6\n"
"RX PRIO 7\n"
"RTU Valid\n"
"RTU Responses\n"
"RTU Dropped\n"
"FastMatch: Priority\n"
"FastMatch: FastForward\n"
"FastMatch: NonForward\n"
"FastMatch: Resp Valid\n"
"FullMatch: Resp Valid\n"
"Forwarded\n"
"TRU Resp Valid"
struct net_device_stats *stats);
struct pstats_version_description {
unsigned int rx_packets;
unsigned int tx_packets;
unsigned int rx_length_errors;
unsigned int rx_crc_errors;
unsigned int rx_fifo_errors;
unsigned int tx_fifo_errors;
char *cnt_names;
};
#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