rtl8366s: simplify mib counters handling

SVN-Revision: 19326
This commit is contained in:
Gabor Juhos 2010-01-25 14:24:53 +00:00
parent 20df2bf825
commit 97b983c8b9

View file

@ -183,41 +183,46 @@ struct rtl8366s_vlan4kentry {
u16 g_dbg_reg; u16 g_dbg_reg;
#endif #endif
static const char *MIBCOUNTERS[] = { struct mib_counter {
"IfInOctets ", unsigned offset;
"EtherStatsOctets ", unsigned length;
"EtherStatsUnderSizePkts ", const char *name;
"EtherFregament ", };
"EtherStatsPkts64Octets ",
"EtherStatsPkts65to127Octets ", static struct mib_counter rtl8366s_mib_counters[RTL8366S_MIB_COUNT] = {
"EtherStatsPkts128to255Octets ", { 0, 4, "IfInOctets " },
"EtherStatsPkts256to511Octets ", { 4, 4, "EtherStatsOctets " },
"EtherStatsPkts512to1023Octets ", { 8, 2, "EtherStatsUnderSizePkts " },
"EtherStatsPkts1024to1518Octets ", { 10, 2, "EtherFregament " },
"EtherOversizeStats ", { 12, 2, "EtherStatsPkts64Octets " },
"EtherStatsJabbers ", { 14, 2, "EtherStatsPkts65to127Octets " },
"IfInUcastPkts ", { 16, 2, "EtherStatsPkts128to255Octets " },
"EtherStatsMulticastPkts ", { 18, 2, "EtherStatsPkts256to511Octets " },
"EtherStatsBroadcastPkts ", { 20, 2, "EtherStatsPkts512to1023Octets " },
"EtherStatsDropEvents ", { 22, 2, "EtherStatsPkts1024to1518Octets " },
"Dot3StatsFCSErrors ", { 24, 2, "EtherOversizeStats " },
"Dot3StatsSymbolErrors ", { 26, 2, "EtherStatsJabbers " },
"Dot3InPauseFrames ", { 28, 2, "IfInUcastPkts " },
"Dot3ControlInUnknownOpcodes ", { 30, 2, "EtherStatsMulticastPkts " },
"IfOutOctets ", { 32, 2, "EtherStatsBroadcastPkts " },
"Dot3StatsSingleCollisionFrames ", { 34, 2, "EtherStatsDropEvents " },
"Dot3StatMultipleCollisionFrames ", { 36, 2, "Dot3StatsFCSErrors " },
"Dot3sDeferredTransmissions ", { 38, 2, "Dot3StatsSymbolErrors " },
"Dot3StatsLateCollisions ", { 40, 2, "Dot3InPauseFrames " },
"EtherStatsCollisions ", { 42, 2, "Dot3ControlInUnknownOpcodes " },
"Dot3StatsExcessiveCollisions ", { 44, 2, "IfOutOctets " },
"Dot3OutPauseFrames ", { 46, 2, "Dot3StatsSingleCollisionFrames " },
"Dot1dBasePortDelayExceededDiscards", { 48, 2, "Dot3StatMultipleCollisionFrames " },
"Dot1dTpPortInDiscards ", { 50, 2, "Dot3sDeferredTransmissions " },
"IfOutUcastPkts ", { 52, 2, "Dot3StatsLateCollisions " },
"IfOutMulticastPkts ", { 54, 2, "EtherStatsCollisions " },
"IfOutBroadcastPkts ", { 56, 2, "Dot3StatsExcessiveCollisions " },
NULL, { 58, 2, "Dot3OutPauseFrames " },
{ 60, 2, "Dot1dBasePortDelayExceededDiscards" },
{ 62, 2, "Dot1dTpPortInDiscards " },
{ 64, 2, "IfOutUcastPkts " },
{ 66, 2, "IfOutMulticastPkts " },
{ 68, 2, "IfOutBroadcastPkts " },
}; };
static inline struct rtl8366s *sw_to_rtl8366s(struct switch_dev *sw) static inline struct rtl8366s *sw_to_rtl8366s(struct switch_dev *sw)
@ -299,24 +304,15 @@ static int rtl8366_get_mib_counter(struct rtl8366s *rtl, int counter,
struct rtl8366_smi *smi = &rtl->smi; struct rtl8366_smi *smi = &rtl->smi;
int i; int i;
int err; int err;
u32 addr, data, regoffset; u32 addr, data;
u64 mibvalue; u64 mibvalue;
/* address offset to MIBs counter */
const u16 mibLength[RTL8366S_MIB_COUNT] = {4, 4, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 4, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2};
if (port > RTL8366_NUM_PORTS || counter >= RTL8366S_MIB_COUNT) if (port > RTL8366_NUM_PORTS || counter >= RTL8366S_MIB_COUNT)
return -EINVAL; return -EINVAL;
regoffset = RTL8366S_MIB_COUNTER_PORT_OFFSET * (port); addr = RTL8366S_MIB_COUNTER_BASE +
RTL8366S_MIB_COUNTER_PORT_OFFSET * (port) +
for (i = 0; i < counter; i++) rtl8366s_mib_counters[counter].offset;
regoffset += mibLength[i];
addr = RTL8366S_MIB_COUNTER_BASE + regoffset;
/* /*
* Writing access counter address first * Writing access counter address first
@ -339,18 +335,12 @@ static int rtl8366_get_mib_counter(struct rtl8366s *rtl, int counter,
return -EIO; return -EIO;
mibvalue = 0; mibvalue = 0;
addr = addr + mibLength[counter] - 1; for (i = rtl8366s_mib_counters[counter].length; i > 0; i--) {
i = mibLength[counter]; err = rtl8366_smi_read_reg(smi, addr + (i - 1), &data);
while (i) {
err = rtl8366_smi_read_reg(smi, addr, &data);
if (err) if (err)
return err; return err;
mibvalue = (mibvalue << 16) | (data & 0xFFFF); mibvalue = (mibvalue << 16) | (data & 0xFFFF);
addr--;
i--;
} }
*val = mibvalue; *val = mibvalue;
@ -739,7 +729,7 @@ static ssize_t rtl8366s_read_debugfs_mibs(struct file *file,
for (i = 0; i < 33; ++i) { for (i = 0; i < 33; ++i) {
len += snprintf(buf + len, sizeof(rtl->buf) - len, "%d:%s ", len += snprintf(buf + len, sizeof(rtl->buf) - len, "%d:%s ",
i, MIBCOUNTERS[i]); i, rtl8366s_mib_counters[i].name);
for (j = 0; j < RTL8366_NUM_PORTS; ++j) { for (j = 0; j < RTL8366_NUM_PORTS; ++j) {
unsigned long long counter = 0; unsigned long long counter = 0;
@ -1220,7 +1210,7 @@ static int rtl8366s_sw_get_port_mib(struct switch_dev *dev,
for (i = 0; i < RTL8366S_MIB_COUNT; ++i) { for (i = 0; i < RTL8366S_MIB_COUNT; ++i) {
len += snprintf(buf + len, sizeof(rtl->buf) - len, len += snprintf(buf + len, sizeof(rtl->buf) - len,
"%d:%s\t", i, MIBCOUNTERS[i]); "%d:%s\t", i, rtl8366s_mib_counters[i].name);
if (!rtl8366_get_mib_counter(rtl, i, val->port_vlan, &counter)) if (!rtl8366_get_mib_counter(rtl, i, val->port_vlan, &counter))
len += snprintf(buf + len, sizeof(rtl->buf) - len, len += snprintf(buf + len, sizeof(rtl->buf) - len,
"[%llu]\n", counter); "[%llu]\n", counter);