generic: provide get_port_stats() on rtl836x switches

This patch provides a generic switch_dev_ops 'get_port_stats()' callback by
taping into the relevant port MIB counters.

This callback is used by swconfig_leds led trigger to blink LEDs with port
network traffic.

Signed-off-by: Thibaut VARENE <hacks@slashdirt.org>
This commit is contained in:
Thibaut VARENE 2017-08-04 12:29:52 +02:00 committed by John Crispin
parent 3056d09b40
commit 0369e35891
6 changed files with 74 additions and 0 deletions

View File

@ -1030,6 +1030,33 @@ int rtl8366_sw_get_port_mib(struct switch_dev *dev,
}
EXPORT_SYMBOL_GPL(rtl8366_sw_get_port_mib);
int rtl8366_sw_get_port_stats(struct switch_dev *dev, int port,
struct switch_port_stats *stats,
int txb_id, int rxb_id)
{
struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
unsigned long long counter = 0;
int ret;
if (port >= smi->num_ports)
return -EINVAL;
ret = smi->ops->get_mib_counter(smi, txb_id, port, &counter);
if (ret)
return ret;
stats->tx_bytes = counter;
ret = smi->ops->get_mib_counter(smi, rxb_id, port, &counter);
if (ret)
return ret;
stats->rx_bytes = counter;
return 0;
}
EXPORT_SYMBOL_GPL(rtl8366_sw_get_port_stats);
int rtl8366_sw_get_vlan_info(struct switch_dev *dev,
const struct switch_attr *attr,
struct switch_val *val)

View File

@ -146,6 +146,9 @@ int rtl8366_sw_get_vlan_enable(struct switch_dev *dev,
int rtl8366_sw_set_vlan_enable(struct switch_dev *dev,
const struct switch_attr *attr,
struct switch_val *val);
int rtl8366_sw_get_port_stats(struct switch_dev *dev, int port,
struct switch_port_stats *stats,
int txb_id, int rxb_id);
struct rtl8366_smi* rtl8366_smi_probe(struct platform_device *pdev);

View File

@ -205,6 +205,9 @@
#define RTL8366RB_QOS_DEFAULT_PREIFG 1
#define RTL8366RB_MIB_RXB_ID 0 /* IfInOctets */
#define RTL8366RB_MIB_TXB_ID 20 /* IfOutOctets */
static struct rtl8366_mib_counter rtl8366rb_mib_counters[] = {
{ 0, 0, 4, "IfInOctets" },
{ 0, 4, 4, "EtherStatsOctets" },
@ -1146,6 +1149,13 @@ static int rtl8366rb_sw_reset_port_mibs(struct switch_dev *dev,
RTL8366RB_MIB_CTRL_PORT_RESET(val->port_vlan));
}
static int rtl8366rb_sw_get_port_stats(struct switch_dev *dev, int port,
struct switch_port_stats *stats)
{
return (rtl8366_sw_get_port_stats(dev, port, stats,
RTL8366RB_MIB_TXB_ID, RTL8366RB_MIB_RXB_ID));
}
static struct switch_attr rtl8366rb_globals[] = {
{
.type = SWITCH_TYPE_INT,
@ -1317,6 +1327,7 @@ static const struct switch_dev_ops rtl8366_ops = {
.set_port_pvid = rtl8366_sw_set_port_pvid,
.reset_switch = rtl8366_sw_reset_switch,
.get_port_link = rtl8366rb_sw_get_port_link,
.get_port_stats = rtl8366rb_sw_get_port_stats,
};
static int rtl8366rb_switch_init(struct rtl8366_smi *smi)

View File

@ -181,6 +181,9 @@
#define RTL8366S_VLAN_FID_SHIFT 12
#define RTL8366S_VLAN_FID_MASK 0x7
#define RTL8366S_MIB_RXB_ID 0 /* IfInOctets */
#define RTL8366S_MIB_TXB_ID 20 /* IfOutOctets */
static struct rtl8366_mib_counter rtl8366s_mib_counters[] = {
{ 0, 0, 4, "IfInOctets" },
{ 0, 4, 4, "EtherStatsOctets" },
@ -982,6 +985,13 @@ static int rtl8366s_sw_reset_port_mibs(struct switch_dev *dev,
0, (1 << (val->port_vlan + 3)));
}
static int rtl8366s_sw_get_port_stats(struct switch_dev *dev, int port,
struct switch_port_stats *stats)
{
return (rtl8366_sw_get_port_stats(dev, port, stats,
RTL8366S_MIB_TXB_ID, RTL8366S_MIB_RXB_ID));
}
static struct switch_attr rtl8366s_globals[] = {
{
.type = SWITCH_TYPE_INT,
@ -1105,6 +1115,7 @@ static const struct switch_dev_ops rtl8366_ops = {
.set_port_pvid = rtl8366_sw_set_port_pvid,
.reset_switch = rtl8366_sw_reset_switch,
.get_port_link = rtl8366s_sw_get_port_link,
.get_port_stats = rtl8366s_sw_get_port_stats,
};
static int rtl8366s_switch_init(struct rtl8366_smi *smi)

View File

@ -253,6 +253,9 @@ struct rtl8367_initval {
u16 val;
};
#define RTL8367_MIB_RXB_ID 0 /* IfInOctets */
#define RTL8367_MIB_TXB_ID 20 /* IfOutOctets */
static struct rtl8366_mib_counter rtl8367_mib_counters[] = {
{ 0, 0, 4, "IfInOctets" },
{ 0, 4, 2, "Dot3StatsFCSErrors" },
@ -1535,6 +1538,13 @@ static int rtl8367_sw_reset_port_mibs(struct switch_dev *dev,
RTL8367_MIB_CTRL_PORT_RESET_MASK(port % 8));
}
static int rtl8367_sw_get_port_stats(struct switch_dev *dev, int port,
struct switch_port_stats *stats)
{
return (rtl8366_sw_get_port_stats(dev, port, stats,
RTL8367_MIB_TXB_ID, RTL8367_MIB_RXB_ID));
}
static struct switch_attr rtl8367_globals[] = {
{
.type = SWITCH_TYPE_INT,
@ -1622,6 +1632,7 @@ static const struct switch_dev_ops rtl8367_sw_ops = {
.set_port_pvid = rtl8366_sw_set_port_pvid,
.reset_switch = rtl8366_sw_reset_switch,
.get_port_link = rtl8367_sw_get_port_link,
.get_port_stats = rtl8367_sw_get_port_stats,
};
static int rtl8367_switch_init(struct rtl8366_smi *smi)

View File

@ -235,6 +235,9 @@ struct rtl8367b_initval {
u16 val;
};
#define RTL8367B_MIB_RXB_ID 0 /* IfInOctets */
#define RTL8367B_MIB_TXB_ID 28 /* IfOutOctets */
static struct rtl8366_mib_counter
rtl8367b_mib_counters[RTL8367B_NUM_MIB_COUNTERS] = {
{0, 0, 4, "ifInOctets" },
@ -1302,6 +1305,13 @@ static int rtl8367b_sw_reset_port_mibs(struct switch_dev *dev,
RTL8367B_MIB_CTRL0_PORT_RESET_MASK(port % 8));
}
static int rtl8367b_sw_get_port_stats(struct switch_dev *dev, int port,
struct switch_port_stats *stats)
{
return (rtl8366_sw_get_port_stats(dev, port, stats,
RTL8367B_MIB_TXB_ID, RTL8367B_MIB_RXB_ID));
}
static struct switch_attr rtl8367b_globals[] = {
{
.type = SWITCH_TYPE_INT,
@ -1382,6 +1392,7 @@ static const struct switch_dev_ops rtl8367b_sw_ops = {
.set_port_pvid = rtl8366_sw_set_port_pvid,
.reset_switch = rtl8366_sw_reset_switch,
.get_port_link = rtl8367b_sw_get_port_link,
.get_port_stats = rtl8367b_sw_get_port_stats,
};
static int rtl8367b_switch_init(struct rtl8366_smi *smi)