generic: rtl8366: cleanup MIB counter printing

SVN-Revision: 21917
This commit is contained in:
Gabor Juhos 2010-06-26 19:16:27 +00:00
parent 0d6fb64ac3
commit e89c10585e
2 changed files with 94 additions and 120 deletions

View file

@ -189,7 +189,7 @@ static struct mib_counter rtl8366rb_mib_counters[RTL8366S_MIB_COUNT] = {
{ 0, 4, "IfInOctets" }, { 0, 4, "IfInOctets" },
{ 4, 4, "EtherStatsOctets" }, { 4, 4, "EtherStatsOctets" },
{ 8, 2, "EtherStatsUnderSizePkts" }, { 8, 2, "EtherStatsUnderSizePkts" },
{ 10, 2, "EtherFregament " }, { 10, 2, "EtherFragments" },
{ 12, 2, "EtherStatsPkts64Octets" }, { 12, 2, "EtherStatsPkts64Octets" },
{ 14, 2, "EtherStatsPkts65to127Octets" }, { 14, 2, "EtherStatsPkts65to127Octets" },
{ 16, 2, "EtherStatsPkts128to255Octets" }, { 16, 2, "EtherStatsPkts128to255Octets" },
@ -801,43 +801,30 @@ static ssize_t rtl8366rb_read_debugfs_mibs(struct file *file,
int i, j, len = 0; int i, j, len = 0;
char *buf = rtl->buf; char *buf = rtl->buf;
len += snprintf(buf + len, sizeof(rtl->buf) - len, "MIB Counters:\n"); len += snprintf(buf + len, sizeof(rtl->buf) - len,
len += snprintf(buf + len, sizeof(rtl->buf) - len, "Counter" "%-36s %12s %12s %12s %12s %12s %12s\n",
" " "Counter",
"Port 0 \t\t Port 1 \t\t Port 2 \t\t Port 3 \t\t " "Port 0", "Port 1", "Port 2",
"Port 4\n"); "Port 3", "Port 4", "Port 5");
for (i = 0; i < 33; ++i) { for (i = 0; i < ARRAY_SIZE(rtl8366rb_mib_counters); ++i) {
len += snprintf(buf + len, sizeof(rtl->buf) - len, "%d:%s ", len += snprintf(buf + len, sizeof(rtl->buf) - len, "%-36s ",
i, rtl8366rb_mib_counters[i].name); rtl8366rb_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;
if (!rtl8366_get_mib_counter(smi, i, j, &counter)) if (!rtl8366_get_mib_counter(smi, i, j, &counter))
len += snprintf(buf + len, len += snprintf(buf + len,
sizeof(rtl->buf) - len, sizeof(rtl->buf) - len,
"[%llu]", counter); "%12llu ", counter);
else else
len += snprintf(buf + len, len += snprintf(buf + len,
sizeof(rtl->buf) - len, sizeof(rtl->buf) - len,
"[error]"); "%12s ", "error");
if (j != RTL8366_NUM_PORTS - 1) {
if (counter < 100000)
len += snprintf(buf + len,
sizeof(rtl->buf) - len,
"\t");
len += snprintf(buf + len,
sizeof(rtl->buf) - len,
"\t");
}
} }
len += snprintf(buf + len, sizeof(rtl->buf) - len, "\n"); len += snprintf(buf + len, sizeof(rtl->buf) - len, "\n");
} }
len += snprintf(buf + len, sizeof(rtl->buf) - len, "\n");
return simple_read_from_buffer(user_buf, count, ppos, buf, len); return simple_read_from_buffer(user_buf, count, ppos, buf, len);
} }
@ -1290,15 +1277,15 @@ static int rtl8366rb_sw_get_port_mib(struct switch_dev *dev,
"Port %d MIB counters\n", "Port %d MIB counters\n",
val->port_vlan); val->port_vlan);
for (i = 0; i < RTL8366S_MIB_COUNT; ++i) { for (i = 0; i < ARRAY_SIZE(rtl8366rb_mib_counters); ++i) {
len += snprintf(buf + len, sizeof(rtl->buf) - len, len += snprintf(buf + len, sizeof(rtl->buf) - len,
"%d:%s\t", i, rtl8366rb_mib_counters[i].name); "%-36s: ", rtl8366rb_mib_counters[i].name);
if (!rtl8366_get_mib_counter(smi, i, val->port_vlan, &counter)) if (!rtl8366_get_mib_counter(smi, 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);
else else
len += snprintf(buf + len, sizeof(rtl->buf) - len, len += snprintf(buf + len, sizeof(rtl->buf) - len,
"[error]\n"); "%s\n", "error");
} }
val->value.s = buf; val->value.s = buf;

View file

@ -190,7 +190,7 @@ static struct mib_counter rtl8366s_mib_counters[RTL8366S_MIB_COUNT] = {
{ 0, 4, "IfInOctets" }, { 0, 4, "IfInOctets" },
{ 4, 4, "EtherStatsOctets" }, { 4, 4, "EtherStatsOctets" },
{ 8, 2, "EtherStatsUnderSizePkts" }, { 8, 2, "EtherStatsUnderSizePkts" },
{ 10, 2, "EtherFregament " }, { 10, 2, "EtherFragments" },
{ 12, 2, "EtherStatsPkts64Octets" }, { 12, 2, "EtherStatsPkts64Octets" },
{ 14, 2, "EtherStatsPkts65to127Octets" }, { 14, 2, "EtherStatsPkts65to127Octets" },
{ 16, 2, "EtherStatsPkts128to255Octets" }, { 16, 2, "EtherStatsPkts128to255Octets" },
@ -767,43 +767,30 @@ static ssize_t rtl8366s_read_debugfs_mibs(struct file *file,
int i, j, len = 0; int i, j, len = 0;
char *buf = rtl->buf; char *buf = rtl->buf;
len += snprintf(buf + len, sizeof(rtl->buf) - len, "MIB Counters:\n"); len += snprintf(buf + len, sizeof(rtl->buf) - len,
len += snprintf(buf + len, sizeof(rtl->buf) - len, "Counter" "%-36s %12s %12s %12s %12s %12s %12s\n",
" " "Counter",
"Port 0 \t\t Port 1 \t\t Port 2 \t\t Port 3 \t\t " "Port 0", "Port 1", "Port 2",
"Port 4\n"); "Port 3", "Port 4", "Port 5");
for (i = 0; i < 33; ++i) { for (i = 0; i < ARRAY_SIZE(rtl8366s_mib_counters); ++i) {
len += snprintf(buf + len, sizeof(rtl->buf) - len, "%d:%s ", len += snprintf(buf + len, sizeof(rtl->buf) - len, "%-36s ",
i, rtl8366s_mib_counters[i].name); 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;
if (!rtl8366_get_mib_counter(smi, i, j, &counter)) if (!rtl8366_get_mib_counter(smi, i, j, &counter))
len += snprintf(buf + len, len += snprintf(buf + len,
sizeof(rtl->buf) - len, sizeof(rtl->buf) - len,
"[%llu]", counter); "%12llu ", counter);
else else
len += snprintf(buf + len, len += snprintf(buf + len,
sizeof(rtl->buf) - len, sizeof(rtl->buf) - len,
"[error]"); "%12s ", "error");
if (j != RTL8366_NUM_PORTS - 1) {
if (counter < 100000)
len += snprintf(buf + len,
sizeof(rtl->buf) - len,
"\t");
len += snprintf(buf + len,
sizeof(rtl->buf) - len,
"\t");
}
} }
len += snprintf(buf + len, sizeof(rtl->buf) - len, "\n"); len += snprintf(buf + len, sizeof(rtl->buf) - len, "\n");
} }
len += snprintf(buf + len, sizeof(rtl->buf) - len, "\n");
return simple_read_from_buffer(user_buf, count, ppos, buf, len); return simple_read_from_buffer(user_buf, count, ppos, buf, len);
} }
@ -1257,15 +1244,15 @@ static int rtl8366s_sw_get_port_mib(struct switch_dev *dev,
"Port %d MIB counters\n", "Port %d MIB counters\n",
val->port_vlan); val->port_vlan);
for (i = 0; i < RTL8366S_MIB_COUNT; ++i) { for (i = 0; i < ARRAY_SIZE(rtl8366s_mib_counters); ++i) {
len += snprintf(buf + len, sizeof(rtl->buf) - len, len += snprintf(buf + len, sizeof(rtl->buf) - len,
"%d:%s\t", i, rtl8366s_mib_counters[i].name); "%-36s: ", rtl8366s_mib_counters[i].name);
if (!rtl8366_get_mib_counter(smi, i, val->port_vlan, &counter)) if (!rtl8366_get_mib_counter(smi, 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);
else else
len += snprintf(buf + len, sizeof(rtl->buf) - len, len += snprintf(buf + len, sizeof(rtl->buf) - len,
"[error]\n"); "%s\n", "error");
} }
val->value.s = buf; val->value.s = buf;