realtek: dsa: move private drop counters into stats

The legacy debugfs implementation selects private diagnostic registers by
family at read time. Move these switch-wide counters into stats.c and
select immutable counter descriptors through priv->r->drop_desc.

Keep an explicit register offset for each of the 246 retained counters.
Omit the RTL838x bridge learned-entry discard counter at 0x6a9c and the
four reserved slots on RTL930x/RTL931x. All retained counters are 16-bit,
so a single OTTO_DROP macro and a common read path suffice. Correct two
RTL930x counter labels.

Expose a read-only realtek_otto_stats/drop_counters file. Serialize register
reads with reg_mutex, propagate regmap failures, and remove the debugfs
interface before switch teardown. A devm action also covers resource
cleanup; unavailable debugfs does not prevent switch operation. The fixed
root is owned by one device and is never reused by another instance.

Remove the legacy drop-counter data, reader and registrations. Other
legacy debugfs features and existing MIB exports are unchanged.

Assisted-by: ChatGPT (OpenAI GPT-6 Astra)
Link: https://github.com/openwrt/openwrt/pull/25931
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
This commit is contained in:
Markus Stockhausen committed 2026-10-18 08:03:20 +02:00
1 parent 814759483b
commit f5e8002b17
9 files changed
+388 -142

No files matched your search

@@ -448,6 +448,8 @@ static int rtl83xx_sw_probe(struct platform_device *pdev)
if (priv->r->lag_switch_init)
priv->r->lag_switch_init(priv);
otto_stats_dbgfs_init(priv);
return 0;
err_register_l3:
@@ -469,6 +471,9 @@ static void rtl83xx_sw_remove(struct platform_device *pdev)
/* TODO: */
pr_debug("Removing platform driver for rtl83xx-sw\n");
/* Stop debugfs readers before tearing down the switch. */
otto_stats_dbgfs_remove(priv);
/* unregister notifiers which will create workqueue entries with
* references to the switch structures. Also stop self-arming delayed
* work items to avoid them still accessing the DSA structures
@@ -58,81 +58,6 @@
#define RTL839X_MIR_RSPAN_TX_TAG_EN_CTRL (0x2554)
#define RTL839X_MIR_SAMPLE_RATE_CTRL (0x2558)
#define RTL838X_STAT_PRVTE_DROP_COUNTERS (0x6A00)
#define RTL839X_STAT_PRVTE_DROP_COUNTERS (0x3E00)
#define RTL930X_STAT_PRVTE_DROP_COUNTERS (0xB5B8)
#define RTL931X_STAT_PRVTE_DROP_COUNTERS (0xd800)
const char *rtl838x_drop_cntr[] = {
"ALE_TX_GOOD_PKTS", "MAC_RX_DROP", "ACL_FWD_DROP", "HW_ATTACK_PREVENTION_DROP",
"RMA_DROP", "VLAN_IGR_FLTR_DROP", "INNER_OUTER_CFI_EQUAL_1_DROP", "PORT_MOVE_DROP",
"NEW_SA_DROP", "MAC_LIMIT_SYS_DROP", "MAC_LIMIT_VLAN_DROP", "MAC_LIMIT_PORT_DROP",
"SWITCH_MAC_DROP", "ROUTING_EXCEPTION_DROP", "DA_LKMISS_DROP", "RSPAN_DROP",
"ACL_LKMISS_DROP", "ACL_DROP", "INBW_DROP", "IGR_METER_DROP",
"ACCEPT_FRAME_TYPE_DROP", "STP_IGR_DROP", "INVALID_SA_DROP", "SA_BLOCKING_DROP",
"DA_BLOCKING_DROP", "L2_INVALID_DPM_DROP", "MCST_INVALID_DPM_DROP", "RX_FLOW_CONTROL_DROP",
"STORM_SPPRS_DROP", "LALS_DROP", "VLAN_EGR_FILTER_DROP", "STP_EGR_DROP",
"SRC_PORT_FILTER_DROP", "PORT_ISOLATION_DROP", "ACL_FLTR_DROP", "MIRROR_FLTR_DROP",
"TX_MAX_DROP", "LINK_DOWN_DROP", "FLOW_CONTROL_DROP", "BRIDGE .1d discards"
};
const char *rtl839x_drop_cntr[] = {
"ALE_TX_GOOD_PKTS", "ERROR_PKTS", "EGR_ACL_DROP", "EGR_METER_DROP",
"OAM", "CFM", "VLAN_IGR_FLTR", "VLAN_ERR",
"INNER_OUTER_CFI_EQUAL_1", "VLAN_TAG_FORMAT", "SRC_PORT_SPENDING_TREE", "INBW",
"RMA", "HW_ATTACK_PREVENTION", "PROTO_STORM", "MCAST_SA",
"IGR_ACL_DROP", "IGR_METER_DROP", "DFLT_ACTION_FOR_MISS_ACL_AND_C2SC", "NEW_SA",
"PORT_MOVE", "SA_BLOCKING", "ROUTING_EXCEPTION", "SRC_PORT_SPENDING_TREE_NON_FWDING",
"MAC_LIMIT", "UNKNOW_STORM", "MISS_DROP", "CPU_MAC_DROP",
"DA_BLOCKING", "SRC_PORT_FILTER_BEFORE_EGR_ACL", "VLAN_EGR_FILTER", "SPANNING_TRE",
"PORT_ISOLATION", "OAM_EGRESS_DROP", "MIRROR_ISOLATION", "MAX_LEN_BEFORE_EGR_ACL",
"SRC_PORT_FILTER_BEFORE_MIRROR", "MAX_LEN_BEFORE_MIRROR", "SPECIAL_CONGEST_BEFORE_MIRROR",
"LINK_STATUS_BEFORE_MIRROR",
"WRED_BEFORE_MIRROR", "MAX_LEN_AFTER_MIRROR", "SPECIAL_CONGEST_AFTER_MIRROR",
"LINK_STATUS_AFTER_MIRROR",
"WRED_AFTER_MIRROR"
};
const char *rtl930x_drop_cntr[] = {
"OAM_PARSER", "UC_RPF", "DEI_CFI", "MAC_IP_SUBNET_BASED_VLAN", "VLAN_IGR_FILTER",
"L2_UC_MC", "IPV_IP6_MC_BRIDGE", "PTP", "USER_DEF_0_3", "RESERVED",
"RESERVED1", "RESERVED2", "BPDU_RMA", "LACP", "LLDP",
"EAPOL", "XX_RMA", "L3_IPUC_NON_IP", "IP4_IP6_HEADER_ERROR", "L3_BAD_IP",
"L3_DIP_DMAC_MISMATCH", "IP4_IP_OPTION", "IP_UC_MC_ROUTING_LOOK_UP_MISS", "L3_DST_NULL_INTF",
"L3_PBR_NULL_INTF",
"HOST_NULL_INTF", "ROUTE_NULL_INTF", "BRIDGING_ACTION", "ROUTING_ACTION", "IPMC_RPF",
"L2_NEXTHOP_AGE_OUT", "L3_UC_TTL_FAIL", "L3_MC_TTL_FAIL", "L3_UC_MTU_FAIL", "L3_MC_MTU_FAIL",
"L3_UC_ICMP_REDIR", "IP6_MLD_OTHER_ACT", "ND", "IP_MC_RESERVED", "IP6_HBH",
"INVALID_SA", "L2_HASH_FULL", "NEW_SA", "PORT_MOVE_FORBID", "STATIC_PORT_MOVING",
"DYNMIC_PORT_MOVING", "L3_CRC", "MAC_LIMIT", "ATTACK_PREVENT", "ACL_FWD_ACTION",
"OAMPDU", "OAM_MUX", "TRUNK_FILTER", "ACL_DROP", "IGR_BW",
"ACL_METER", "VLAN_ACCEPT_FRAME_TYPE", "MSTP_SRC_DROP_DISABLED_BLOCKING", "SA_BLOCK", "DA_BLOCK",
"STORM_CONTROL", "VLAN_EGR_FILTER", "MSTP_DESTINATION_DROP", "SRC_PORT_FILTER", "PORT_ISOLATION",
"TX_MAX_FRAME_SIZE", "EGR_LINK_STATUS", "MAC_TX_DISABLE", "MAC_PAUSE_FRAME", "MAC_RX_DROP",
"MIRROR_ISOLATE", "RX_FC", "EGR_QUEUE", "HSM_RUNOUT", "ROUTING_DISABLE", "INVALID_L2_NEXTHOP_ENTRY",
"L3_MC_SRC_FLT", "CPUTAG_FLT", "FWD_PMSK_NULL", "IPUC_ROUTING_LOOKUP_MISS", "MY_DEV_DROP",
"STACK_NONUC_BLOCKING_PMSK", "STACK_PORT_NOT_FOUND", "ACL_LOOPBACK_DROP", "IP6_ROUTING_EXT_HEADER"
};
const char *rtl931x_drop_cntr[] = {
"ALE_RX_GOOD_PKTS", "RX_MAX_FRAME_SIZE", "MAC_RX_DROP", "OPENFLOW_IP_MPLS_TTL", "OPENFLOW_TBL_MISS",
"IGR_BW", "SPECIAL_CONGEST", "EGR_QUEUE", "RESERVED", "EGR_LINK_STATUS", "STACK_UCAST_NONUCAST_TTL", /* 10 */
"STACK_NONUC_BLOCKING_PMSK", "L2_CRC", "SRC_PORT_FILTER", "PARSER_PACKET_TOO_LONG", "PARSER_MALFORM_PACKET",
"MPLS_OVER_2_LBL", "EACL_METER", "IACL_METER", "PROTO_STORM", "INVALID_CAPWAP_HEADER", /* 20 */
"MAC_IP_SUBNET_BASED_VLAN", "OAM_PARSER", "UC_MC_RPF", "IP_MAC_BINDING_MATCH_MISMATCH", "SA_BLOCK",
"TUNNEL_IP_ADDRESS_CHECK", "EACL_DROP", "IACL_DROP", "ATTACK_PREVENT", "SYSTEM_PORT_LIMIT_LEARN", /* 30 */
"OAMPDU", "CCM_RX", "CFM_UNKNOWN_TYPE", "LBM_LBR_LTM_LTR", "Y_1731", "VLAN_LIMIT_LEARN",
"VLAN_ACCEPT_FRAME_TYPE", "CFI_1", "STATIC_DYNAMIC_PORT_MOVING", "PORT_MOVE_FORBID", /* 40 */
"L3_CRC", "BPDU_PTP_LLDP_EAPOL_RMA", "MSTP_SRC_DROP_DISABLED_BLOCKING", "INVALID_SA", "NEW_SA",
"VLAN_IGR_FILTER", "IGR_VLAN_CONVERT", "GRATUITOUS_ARP", "MSTP_SRC_DROP", "L2_HASH_FULL", /* 50 */
"MPLS_UNKNOWN_LBL", "L3_IPUC_NON_IP", "TTL", "MTU", "ICMP_REDIRECT", "STORM_CONTROL", "L3_DIP_DMAC_MISMATCH",
"IP4_IP_OPTION", "IP6_HBH_EXT_HEADER", "IP4_IP6_HEADER_ERROR", /* 60 */
"ROUTING_IP_ADDR_CHECK", "ROUTING_EXCEPTION", "DA_BLOCK", "OAM_MUX", "PORT_ISOLATION", "VLAN_EGR_FILTER",
"MIRROR_ISOLATE", "MSTP_DESTINATION_DROP", "L2_MC_BRIDGE", "IP_UC_MC_ROUTING_LOOK_UP_MISS", /* 70 */
"L2_UC", "L2_MC", "IP4_MC", "IP6_MC", "L3_UC_MC_ROUTE", "UNKNOWN_L2_UC_FLPM", "BC_FLPM",
"VLAN_PRO_UNKNOWN_L2_MC_FLPM", "VLAN_PRO_UNKNOWN_IP4_MC_FLPM", "VLAN_PROFILE_UNKNOWN_IP6_MC_FLPM", /* 80 */
};
static ssize_t rtl838x_common_read(char __user *buffer, size_t count,
loff_t *ppos, unsigned int value)
{
@@ -218,69 +143,6 @@ static const struct file_operations stp_state_fops = {
.write = stp_state_write,
};
static ssize_t drop_counter_read(struct file *filp, char __user *buffer, size_t count,
loff_t *ppos)
{
struct otto_dsa_priv *priv = filp->private_data;
const char **d;
u32 v;
char *buf;
int n = 0, len, offset;
int num;
switch (priv->family_id) {
case RTL8380_FAMILY_ID:
d = rtl838x_drop_cntr;
offset = RTL838X_STAT_PRVTE_DROP_COUNTERS;
num = ARRAY_SIZE(rtl838x_drop_cntr);
BUILD_BUG_ON(num != 40);
break;
case RTL8390_FAMILY_ID:
d = rtl839x_drop_cntr;
offset = RTL839X_STAT_PRVTE_DROP_COUNTERS;
num = ARRAY_SIZE(rtl839x_drop_cntr);
BUILD_BUG_ON(num != 45);
break;
case RTL9300_FAMILY_ID:
d = rtl930x_drop_cntr;
offset = RTL930X_STAT_PRVTE_DROP_COUNTERS;
num = ARRAY_SIZE(rtl930x_drop_cntr);
BUILD_BUG_ON(num != 85);
break;
case RTL9310_FAMILY_ID:
d = rtl931x_drop_cntr;
offset = RTL931X_STAT_PRVTE_DROP_COUNTERS;
num = ARRAY_SIZE(rtl931x_drop_cntr);
BUILD_BUG_ON(num != 81);
break;
}
buf = kmalloc(30 * num, GFP_KERNEL);
if (!buf)
return -ENOMEM;
for (int i = 0; i < num; i++) {
v = sw_r32(offset + (i << 2)) & 0xffff;
n += sprintf(buf + n, "%s: %d\n", d[i], v);
}
if (count < strlen(buf)) {
kfree(buf);
return -ENOSPC;
}
len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
kfree(buf);
return len;
}
static const struct file_operations drop_counter_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = drop_counter_read,
};
static int rtldsa_pmsks_table_raw_show(struct seq_file *m, void *v)
{
struct otto_dsa_priv *priv = m->private;
@@ -826,8 +688,6 @@ void rtl838x_dbgfs_init(struct otto_dsa_priv *priv)
if (ret)
goto err;
debugfs_create_file("drop_counters", 0400, rtl838x_dir, priv, &drop_counter_fops);
debugfs_create_file("port_masks_table_raw", 0400, rtl838x_dir, priv,
&rtldsa_pmsks_table_raw_fops);
@@ -859,8 +719,6 @@ void rtl930x_dbgfs_init(struct otto_dsa_priv *priv)
priv->dbgfs_dir = dbg_dir;
debugfs_create_file("drop_counters", 0400, dbg_dir, priv, &drop_counter_fops);
debugfs_create_file("port_masks_table_raw", 0400, dbg_dir, priv,
&rtldsa_pmsks_table_raw_fops);
@@ -329,6 +329,7 @@ struct rtldsa_config {
int stat_port_std_mib;
int stat_port_prv_mib;
const struct otto_stats_mib_desc *mib_desc;
const struct otto_stats_drop_desc *drop_desc;
u64 (*stat_port_table_read)(int port, unsigned int mib_size, unsigned int offset, bool is_pvt);
void (*stat_counters_lock)(struct otto_dsa_priv *priv, int port);
void (*stat_counters_unlock)(struct otto_dsa_priv *priv, int port);
@@ -515,6 +516,7 @@ struct otto_dsa_priv {
struct otto_l3_ctrl *l3_ctrl;
u64 irq_mask;
struct dentry *dbgfs_dir;
struct dentry *stats_dbgfs_dir;
/** @lags_port_members: Port (bit) is part of a specific LAG */
u64 lags_port_members[MAX_LAGS];
@@ -211,6 +211,7 @@ const struct rtldsa_config rtldsa_838x_cfg = {
.stat_init = otto_stats_838x_init,
.stat_port_std_mib = RTL838X_STAT_PORT_STD_MIB,
.mib_desc = &otto_stats_838x_mib_desc,
.drop_desc = &otto_stats_838x_drop_desc,
.stat_counters_lock = otto_stats_counters_lock_register,
.stat_counters_unlock = otto_stats_counters_unlock_register,
.stat_update_counters_atomically = otto_stats_update_counters_atomically,
@@ -210,6 +210,7 @@ const struct rtldsa_config rtldsa_839x_cfg = {
.stat_rst = RTL839X_STAT_RST,
.stat_port_std_mib = RTL839X_STAT_PORT_STD_MIB,
.mib_desc = &otto_stats_839x_mib_desc,
.drop_desc = &otto_stats_839x_drop_desc,
.stat_counters_lock = otto_stats_counters_lock_register,
.stat_counters_unlock = otto_stats_counters_unlock_register,
.stat_update_counters_atomically = otto_stats_update_counters_atomically,
@@ -602,6 +602,7 @@ const struct rtldsa_config rtldsa_930x_cfg = {
.stat_port_std_mib = RTL930X_STAT_PORT_MIB_CNTR,
.stat_port_prv_mib = RTL930X_STAT_PORT_PRVTE_CNTR,
.mib_desc = &otto_stats_930x_mib_desc,
.drop_desc = &otto_stats_930x_drop_desc,
.stat_counters_lock = otto_stats_counters_lock_register,
.stat_counters_unlock = otto_stats_counters_unlock_register,
.stat_update_counters_atomically = otto_stats_update_counters_atomically,
@@ -437,6 +437,7 @@ const struct rtldsa_config rtldsa_931x_cfg = {
.stat_rst = RTL931X_STAT_RST,
.stat_port_std_mib = 0, /* Not defined */
.mib_desc = &otto_stats_931x_mib_desc,
.drop_desc = &otto_stats_931x_drop_desc,
.stat_port_table_read = otto_stats_931x_port_table_read,
.stat_counters_lock = otto_stats_counters_lock_table,
.stat_counters_unlock = otto_stats_counters_unlock_table,
@@ -2,7 +2,13 @@
#include <linux/bitmap.h>
#include <linux/cleanup.h>
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/regmap.h>
#include <linux/seq_file.h>
#include <linux/soc/realtek/otto_table.h>
#include <linux/string.h>
#include <net/dsa.h>
@@ -1125,3 +1131,365 @@ void otto_stats_930x_packet_cntr_clear(struct otto_dsa_priv *priv, int counter)
otto_table_release(tbl);
}
/* Switch-wide diagnostic counters, separate from the per-port MIBs. */
struct otto_stats_drop_counter {
const char *name;
u32 reg;
};
struct otto_stats_drop_desc {
const struct otto_stats_drop_counter *counters;
size_t num_counters;
};
#define OTTO_DROP(_reg, _name) \
{ .name = (_name), .reg = (_reg) }
static const struct otto_stats_drop_counter otto_stats_838x_drop_counters[] = {
OTTO_DROP(0x6a00, "ALE_TX_GOOD_PKTS"),
OTTO_DROP(0x6a04, "MAC_RX_DROP"),
OTTO_DROP(0x6a08, "ACL_FWD_DROP"),
OTTO_DROP(0x6a0c, "HW_ATTACK_PREVENTION_DROP"),
OTTO_DROP(0x6a10, "RMA_DROP"),
OTTO_DROP(0x6a14, "VLAN_IGR_FLTR_DROP"),
OTTO_DROP(0x6a18, "INNER_OUTER_CFI_EQUAL_1_DROP"),
OTTO_DROP(0x6a1c, "PORT_MOVE_DROP"),
OTTO_DROP(0x6a20, "NEW_SA_DROP"),
OTTO_DROP(0x6a24, "MAC_LIMIT_SYS_DROP"),
OTTO_DROP(0x6a28, "MAC_LIMIT_VLAN_DROP"),
OTTO_DROP(0x6a2c, "MAC_LIMIT_PORT_DROP"),
OTTO_DROP(0x6a30, "SWITCH_MAC_DROP"),
OTTO_DROP(0x6a34, "ROUTING_EXCEPTION_DROP"),
OTTO_DROP(0x6a38, "DA_LKMISS_DROP"),
OTTO_DROP(0x6a3c, "RSPAN_DROP"),
OTTO_DROP(0x6a40, "ACL_LKMISS_DROP"),
OTTO_DROP(0x6a44, "ACL_DROP"),
OTTO_DROP(0x6a48, "INBW_DROP"),
OTTO_DROP(0x6a4c, "IGR_METER_DROP"),
OTTO_DROP(0x6a50, "ACCEPT_FRAME_TYPE_DROP"),
OTTO_DROP(0x6a54, "STP_IGR_DROP"),
OTTO_DROP(0x6a58, "INVALID_SA_DROP"),
OTTO_DROP(0x6a5c, "SA_BLOCKING_DROP"),
OTTO_DROP(0x6a60, "DA_BLOCKING_DROP"),
OTTO_DROP(0x6a64, "L2_INVALID_DPM_DROP"),
OTTO_DROP(0x6a68, "MCST_INVALID_DPM_DROP"),
OTTO_DROP(0x6a6c, "RX_FLOW_CONTROL_DROP"),
OTTO_DROP(0x6a70, "STORM_SPPRS_DROP"),
OTTO_DROP(0x6a74, "LALS_DROP"),
OTTO_DROP(0x6a78, "VLAN_EGR_FILTER_DROP"),
OTTO_DROP(0x6a7c, "STP_EGR_DROP"),
OTTO_DROP(0x6a80, "SRC_PORT_FILTER_DROP"),
OTTO_DROP(0x6a84, "PORT_ISOLATION_DROP"),
OTTO_DROP(0x6a88, "ACL_FLTR_DROP"),
OTTO_DROP(0x6a8c, "MIRROR_FLTR_DROP"),
OTTO_DROP(0x6a90, "TX_MAX_DROP"),
OTTO_DROP(0x6a94, "LINK_DOWN_DROP"),
OTTO_DROP(0x6a98, "FLOW_CONTROL_DROP"),
};
const struct otto_stats_drop_desc otto_stats_838x_drop_desc = {
.counters = otto_stats_838x_drop_counters,
.num_counters = ARRAY_SIZE(otto_stats_838x_drop_counters),
};
static const struct otto_stats_drop_counter otto_stats_839x_drop_counters[] = {
OTTO_DROP(0x3e00, "ALE_TX_GOOD_PKTS"),
OTTO_DROP(0x3e04, "ERROR_PKTS"),
OTTO_DROP(0x3e08, "EGR_ACL_DROP"),
OTTO_DROP(0x3e0c, "EGR_METER_DROP"),
OTTO_DROP(0x3e10, "OAM"),
OTTO_DROP(0x3e14, "CFM"),
OTTO_DROP(0x3e18, "VLAN_IGR_FLTR"),
OTTO_DROP(0x3e1c, "VLAN_ERR"),
OTTO_DROP(0x3e20, "INNER_OUTER_CFI_EQUAL_1"),
OTTO_DROP(0x3e24, "VLAN_TAG_FORMAT"),
OTTO_DROP(0x3e28, "SRC_PORT_SPENDING_TREE"),
OTTO_DROP(0x3e2c, "INBW"),
OTTO_DROP(0x3e30, "RMA"),
OTTO_DROP(0x3e34, "HW_ATTACK_PREVENTION"),
OTTO_DROP(0x3e38, "PROTO_STORM"),
OTTO_DROP(0x3e3c, "MCAST_SA"),
OTTO_DROP(0x3e40, "IGR_ACL_DROP"),
OTTO_DROP(0x3e44, "IGR_METER_DROP"),
OTTO_DROP(0x3e48, "DFLT_ACTION_FOR_MISS_ACL_AND_C2SC"),
OTTO_DROP(0x3e4c, "NEW_SA"),
OTTO_DROP(0x3e50, "PORT_MOVE"),
OTTO_DROP(0x3e54, "SA_BLOCKING"),
OTTO_DROP(0x3e58, "ROUTING_EXCEPTION"),
OTTO_DROP(0x3e5c, "SRC_PORT_SPENDING_TREE_NON_FWDING"),
OTTO_DROP(0x3e60, "MAC_LIMIT"),
OTTO_DROP(0x3e64, "UNKNOW_STORM"),
OTTO_DROP(0x3e68, "MISS_DROP"),
OTTO_DROP(0x3e6c, "CPU_MAC_DROP"),
OTTO_DROP(0x3e70, "DA_BLOCKING"),
OTTO_DROP(0x3e74, "SRC_PORT_FILTER_BEFORE_EGR_ACL"),
OTTO_DROP(0x3e78, "VLAN_EGR_FILTER"),
OTTO_DROP(0x3e7c, "SPANNING_TRE"),
OTTO_DROP(0x3e80, "PORT_ISOLATION"),
OTTO_DROP(0x3e84, "OAM_EGRESS_DROP"),
OTTO_DROP(0x3e88, "MIRROR_ISOLATION"),
OTTO_DROP(0x3e8c, "MAX_LEN_BEFORE_EGR_ACL"),
OTTO_DROP(0x3e90, "SRC_PORT_FILTER_BEFORE_MIRROR"),
OTTO_DROP(0x3e94, "MAX_LEN_BEFORE_MIRROR"),
OTTO_DROP(0x3e98, "SPECIAL_CONGEST_BEFORE_MIRROR"),
OTTO_DROP(0x3e9c, "LINK_STATUS_BEFORE_MIRROR"),
OTTO_DROP(0x3ea0, "WRED_BEFORE_MIRROR"),
OTTO_DROP(0x3ea4, "MAX_LEN_AFTER_MIRROR"),
OTTO_DROP(0x3ea8, "SPECIAL_CONGEST_AFTER_MIRROR"),
OTTO_DROP(0x3eac, "LINK_STATUS_AFTER_MIRROR"),
OTTO_DROP(0x3eb0, "WRED_AFTER_MIRROR"),
};
const struct otto_stats_drop_desc otto_stats_839x_drop_desc = {
.counters = otto_stats_839x_drop_counters,
.num_counters = ARRAY_SIZE(otto_stats_839x_drop_counters),
};
static const struct otto_stats_drop_counter otto_stats_930x_drop_counters[] = {
OTTO_DROP(0xb5b8, "OAM_PARSER"),
OTTO_DROP(0xb5bc, "UC_RPF"),
OTTO_DROP(0xb5c0, "DEI_CFI"),
OTTO_DROP(0xb5c4, "MAC_IP_SUBNET_BASED_VLAN"),
OTTO_DROP(0xb5c8, "VLAN_IGR_FILTER"),
OTTO_DROP(0xb5cc, "L2_UC_MC_BRIDGE"),
OTTO_DROP(0xb5d0, "IP4_IP6_MC_BRIDGE"),
OTTO_DROP(0xb5d4, "PTP"),
OTTO_DROP(0xb5d8, "USER_DEF_0_3"),
OTTO_DROP(0xb5e8, "BPDU_RMA"),
OTTO_DROP(0xb5ec, "LACP"),
OTTO_DROP(0xb5f0, "LLDP"),
OTTO_DROP(0xb5f4, "EAPOL"),
OTTO_DROP(0xb5f8, "XX_RMA"),
OTTO_DROP(0xb5fc, "L3_IPUC_NON_IP"),
OTTO_DROP(0xb600, "IP4_IP6_HEADER_ERROR"),
OTTO_DROP(0xb604, "L3_BAD_IP"),
OTTO_DROP(0xb608, "L3_DIP_DMAC_MISMATCH"),
OTTO_DROP(0xb60c, "IP4_IP_OPTION"),
OTTO_DROP(0xb610, "IP_UC_MC_ROUTING_LOOK_UP_MISS"),
OTTO_DROP(0xb614, "L3_DST_NULL_INTF"),
OTTO_DROP(0xb618, "L3_PBR_NULL_INTF"),
OTTO_DROP(0xb61c, "HOST_NULL_INTF"),
OTTO_DROP(0xb620, "ROUTE_NULL_INTF"),
OTTO_DROP(0xb624, "BRIDGING_ACTION"),
OTTO_DROP(0xb628, "ROUTING_ACTION"),
OTTO_DROP(0xb62c, "IPMC_RPF"),
OTTO_DROP(0xb630, "L2_NEXTHOP_AGE_OUT"),
OTTO_DROP(0xb634, "L3_UC_TTL_FAIL"),
OTTO_DROP(0xb638, "L3_MC_TTL_FAIL"),
OTTO_DROP(0xb63c, "L3_UC_MTU_FAIL"),
OTTO_DROP(0xb640, "L3_MC_MTU_FAIL"),
OTTO_DROP(0xb644, "L3_UC_ICMP_REDIR"),
OTTO_DROP(0xb648, "IP6_MLD_OTHER_ACT"),
OTTO_DROP(0xb64c, "ND"),
OTTO_DROP(0xb650, "IP_MC_RESERVED"),
OTTO_DROP(0xb654, "IP6_HBH"),
OTTO_DROP(0xb658, "INVALID_SA"),
OTTO_DROP(0xb65c, "L2_HASH_FULL"),
OTTO_DROP(0xb660, "NEW_SA"),
OTTO_DROP(0xb664, "PORT_MOVE_FORBID"),
OTTO_DROP(0xb668, "STATIC_PORT_MOVING"),
OTTO_DROP(0xb66c, "DYNMIC_PORT_MOVING"),
OTTO_DROP(0xb670, "L3_CRC"),
OTTO_DROP(0xb674, "MAC_LIMIT"),
OTTO_DROP(0xb678, "ATTACK_PREVENT"),
OTTO_DROP(0xb67c, "ACL_FWD_ACTION"),
OTTO_DROP(0xb680, "OAMPDU"),
OTTO_DROP(0xb684, "OAM_MUX"),
OTTO_DROP(0xb688, "TRUNK_FILTER"),
OTTO_DROP(0xb68c, "ACL_DROP"),
OTTO_DROP(0xb690, "IGR_BW"),
OTTO_DROP(0xb694, "ACL_METER"),
OTTO_DROP(0xb698, "VLAN_ACCEPT_FRAME_TYPE"),
OTTO_DROP(0xb69c, "MSTP_SRC_DROP_DISABLED_BLOCKING"),
OTTO_DROP(0xb6a0, "SA_BLOCK"),
OTTO_DROP(0xb6a4, "DA_BLOCK"),
OTTO_DROP(0xb6a8, "STORM_CONTROL"),
OTTO_DROP(0xb6ac, "VLAN_EGR_FILTER"),
OTTO_DROP(0xb6b0, "MSTP_DESTINATION_DROP"),
OTTO_DROP(0xb6b4, "SRC_PORT_FILTER"),
OTTO_DROP(0xb6b8, "PORT_ISOLATION"),
OTTO_DROP(0xb6bc, "TX_MAX_FRAME_SIZE"),
OTTO_DROP(0xb6c0, "EGR_LINK_STATUS"),
OTTO_DROP(0xb6c4, "MAC_TX_DISABLE"),
OTTO_DROP(0xb6c8, "MAC_PAUSE_FRAME"),
OTTO_DROP(0xb6cc, "MAC_RX_DROP"),
OTTO_DROP(0xb6d0, "MIRROR_ISOLATE"),
OTTO_DROP(0xb6d4, "RX_FC"),
OTTO_DROP(0xb6d8, "EGR_QUEUE"),
OTTO_DROP(0xb6dc, "HSM_RUNOUT"),
OTTO_DROP(0xb6e0, "ROUTING_DISABLE"),
OTTO_DROP(0xb6e4, "INVALID_L2_NEXTHOP_ENTRY"),
OTTO_DROP(0xb6e8, "L3_MC_SRC_FLT"),
OTTO_DROP(0xb6ec, "CPUTAG_FLT"),
OTTO_DROP(0xb6f0, "FWD_PMSK_NULL"),
OTTO_DROP(0xb6f4, "IPUC_ROUTING_LOOKUP_MISS"),
OTTO_DROP(0xb6f8, "MY_DEV_DROP"),
OTTO_DROP(0xb6fc, "STACK_NONUC_BLOCKING_PMSK"),
OTTO_DROP(0xb700, "STACK_PORT_NOT_FOUND"),
OTTO_DROP(0xb704, "ACL_LOOPBACK_DROP"),
OTTO_DROP(0xb708, "IP6_ROUTING_EXT_HEADER"),
};
const struct otto_stats_drop_desc otto_stats_930x_drop_desc = {
.counters = otto_stats_930x_drop_counters,
.num_counters = ARRAY_SIZE(otto_stats_930x_drop_counters),
};
static const struct otto_stats_drop_counter otto_stats_931x_drop_counters[] = {
OTTO_DROP(0xd800, "ALE_RX_GOOD_PKTS"),
OTTO_DROP(0xd804, "RX_MAX_FRAME_SIZE"),
OTTO_DROP(0xd808, "MAC_RX_DROP"),
OTTO_DROP(0xd80c, "OPENFLOW_IP_MPLS_TTL"),
OTTO_DROP(0xd810, "OPENFLOW_TBL_MISS"),
OTTO_DROP(0xd814, "IGR_BW"),
OTTO_DROP(0xd818, "SPECIAL_CONGEST"),
OTTO_DROP(0xd81c, "EGR_QUEUE"),
OTTO_DROP(0xd824, "EGR_LINK_STATUS"),
OTTO_DROP(0xd828, "STACK_UCAST_NONUCAST_TTL"),
OTTO_DROP(0xd82c, "STACK_NONUC_BLOCKING_PMSK"),
OTTO_DROP(0xd830, "L2_CRC"),
OTTO_DROP(0xd834, "SRC_PORT_FILTER"),
OTTO_DROP(0xd838, "PARSER_PACKET_TOO_LONG"),
OTTO_DROP(0xd83c, "PARSER_MALFORM_PACKET"),
OTTO_DROP(0xd840, "MPLS_OVER_2_LBL"),
OTTO_DROP(0xd844, "EACL_METER"),
OTTO_DROP(0xd848, "IACL_METER"),
OTTO_DROP(0xd84c, "PROTO_STORM"),
OTTO_DROP(0xd850, "INVALID_CAPWAP_HEADER"),
OTTO_DROP(0xd854, "MAC_IP_SUBNET_BASED_VLAN"),
OTTO_DROP(0xd858, "OAM_PARSER"),
OTTO_DROP(0xd85c, "UC_MC_RPF"),
OTTO_DROP(0xd860, "IP_MAC_BINDING_MATCH_MISMATCH"),
OTTO_DROP(0xd864, "SA_BLOCK"),
OTTO_DROP(0xd868, "TUNNEL_IP_ADDRESS_CHECK"),
OTTO_DROP(0xd86c, "EACL_DROP"),
OTTO_DROP(0xd870, "IACL_DROP"),
OTTO_DROP(0xd874, "ATTACK_PREVENT"),
OTTO_DROP(0xd878, "SYSTEM_PORT_LIMIT_LEARN"),
OTTO_DROP(0xd87c, "OAMPDU"),
OTTO_DROP(0xd880, "CCM_RX"),
OTTO_DROP(0xd884, "CFM_UNKNOWN_TYPE"),
OTTO_DROP(0xd888, "LBM_LBR_LTM_LTR"),
OTTO_DROP(0xd88c, "Y_1731"),
OTTO_DROP(0xd890, "VLAN_LIMIT_LEARN"),
OTTO_DROP(0xd894, "VLAN_ACCEPT_FRAME_TYPE"),
OTTO_DROP(0xd898, "CFI_1"),
OTTO_DROP(0xd89c, "STATIC_DYNAMIC_PORT_MOVING"),
OTTO_DROP(0xd8a0, "PORT_MOVE_FORBID"),
OTTO_DROP(0xd8a4, "L3_CRC"),
OTTO_DROP(0xd8a8, "BPDU_PTP_LLDP_EAPOL_RMA"),
OTTO_DROP(0xd8ac, "MSTP_SRC_DROP_DISABLED_BLOCKING"),
OTTO_DROP(0xd8b0, "INVALID_SA"),
OTTO_DROP(0xd8b4, "NEW_SA"),
OTTO_DROP(0xd8b8, "VLAN_IGR_FILTER"),
OTTO_DROP(0xd8bc, "IGR_VLAN_CONVERT"),
OTTO_DROP(0xd8c0, "GRATUITOUS_ARP"),
OTTO_DROP(0xd8c4, "MSTP_SRC_DROP"),
OTTO_DROP(0xd8c8, "L2_HASH_FULL"),
OTTO_DROP(0xd8cc, "MPLS_UNKNOWN_LBL"),
OTTO_DROP(0xd8d0, "L3_IPUC_NON_IP"),
OTTO_DROP(0xd8d4, "TTL"),
OTTO_DROP(0xd8d8, "MTU"),
OTTO_DROP(0xd8dc, "ICMP_REDIRECT"),
OTTO_DROP(0xd8e0, "STORM_CONTROL"),
OTTO_DROP(0xd8e4, "L3_DIP_DMAC_MISMATCH"),
OTTO_DROP(0xd8e8, "IP4_IP_OPTION"),
OTTO_DROP(0xd8ec, "IP6_HBH_EXT_HEADER"),
OTTO_DROP(0xd8f0, "IP4_IP6_HEADER_ERROR"),
OTTO_DROP(0xd8f4, "ROUTING_IP_ADDR_CHECK"),
OTTO_DROP(0xd8f8, "ROUTING_EXCEPTION"),
OTTO_DROP(0xd8fc, "DA_BLOCK"),
OTTO_DROP(0xd900, "OAM_MUX"),
OTTO_DROP(0xd904, "PORT_ISOLATION"),
OTTO_DROP(0xd908, "VLAN_EGR_FILTER"),
OTTO_DROP(0xd90c, "MIRROR_ISOLATE"),
OTTO_DROP(0xd910, "MSTP_DESTINATION_DROP"),
OTTO_DROP(0xd914, "L2_MC_BRIDGE"),
OTTO_DROP(0xd918, "IP_UC_MC_ROUTING_LOOK_UP_MISS"),
OTTO_DROP(0xd91c, "L2_UC"),
OTTO_DROP(0xd920, "L2_MC"),
OTTO_DROP(0xd924, "IP4_MC"),
OTTO_DROP(0xd928, "IP6_MC"),
OTTO_DROP(0xd92c, "L3_UC_MC_ROUTE"),
OTTO_DROP(0xd930, "UNKNOWN_L2_UC_FLPM"),
OTTO_DROP(0xd934, "BC_FLPM"),
OTTO_DROP(0xd938, "VLAN_PRO_UNKNOWN_L2_MC_FLPM"),
OTTO_DROP(0xd93c, "VLAN_PRO_UNKNOWN_IP4_MC_FLPM"),
OTTO_DROP(0xd940, "VLAN_PROFILE_UNKNOWN_IP6_MC_FLPM"),
};
const struct otto_stats_drop_desc otto_stats_931x_drop_desc = {
.counters = otto_stats_931x_drop_counters,
.num_counters = ARRAY_SIZE(otto_stats_931x_drop_counters),
};
#undef OTTO_DROP
static int otto_stats_drop_counter_show(struct seq_file *m, void *v)
{
struct otto_dsa_priv *priv = m->private;
const struct otto_stats_drop_desc *desc = priv->r->drop_desc;
size_t i;
int err;
guard(mutex)(&priv->reg_mutex);
for (i = 0; i < desc->num_counters; i++) {
const struct otto_stats_drop_counter *counter = &desc->counters[i];
u32 value;
err = regmap_read(priv->map, counter->reg, &value);
if (err)
return err;
seq_printf(m, "%s: %u\n", counter->name, value & 0xffff);
}
return 0;
}
DEFINE_SHOW_ATTRIBUTE(otto_stats_drop_counter);
static void otto_stats_dbgfs_cleanup(void *data)
{
struct otto_dsa_priv *priv = data;
debugfs_remove(priv->stats_dbgfs_dir);
priv->stats_dbgfs_dir = NULL;
}
void otto_stats_dbgfs_remove(struct otto_dsa_priv *priv)
{
if (priv->stats_dbgfs_dir)
devm_release_action(priv->dev, otto_stats_dbgfs_cleanup, priv);
}
void otto_stats_dbgfs_init(struct otto_dsa_priv *priv)
{
struct device *dev = priv->dev;
struct dentry *root, *file;
if (!priv->r->drop_desc)
return;
/* The fixed directory belongs to this device; do not reuse a tree. */
root = debugfs_create_dir("realtek_otto_stats", NULL);
if (IS_ERR(root)) {
if (PTR_ERR(root) != -ENODEV)
dev_warn(dev, "could not create stats debugfs directory: %ld\n",
PTR_ERR(root));
return;
}
priv->stats_dbgfs_dir = root;
if (devm_add_action_or_reset(dev, otto_stats_dbgfs_cleanup, priv))
return;
file = debugfs_create_file("drop_counters", 0400, root, priv,
&otto_stats_drop_counter_fops);
if (IS_ERR(file)) {
dev_warn(dev, "could not create drop counter debugfs file: %ld\n",
PTR_ERR(file));
otto_stats_dbgfs_remove(priv);
}
}
@@ -167,6 +167,13 @@ extern const struct otto_stats_mib_desc otto_stats_839x_mib_desc;
extern const struct otto_stats_mib_desc otto_stats_930x_mib_desc;
extern const struct otto_stats_mib_desc otto_stats_931x_mib_desc;
struct otto_stats_drop_desc;
extern const struct otto_stats_drop_desc otto_stats_838x_drop_desc;
extern const struct otto_stats_drop_desc otto_stats_839x_drop_desc;
extern const struct otto_stats_drop_desc otto_stats_930x_drop_desc;
extern const struct otto_stats_drop_desc otto_stats_931x_drop_desc;
struct dsa_switch;
struct ethtool_eth_ctrl_stats;
struct ethtool_eth_mac_stats;
@@ -179,6 +186,8 @@ struct rtnl_link_stats64;
void otto_stats_init(struct otto_dsa_priv *priv);
void otto_stats_init_counters(struct otto_dsa_priv *priv);
void otto_stats_dbgfs_init(struct otto_dsa_priv *priv);
void otto_stats_dbgfs_remove(struct otto_dsa_priv *priv);
void otto_stats_838x_init(struct otto_dsa_priv *priv);
u64 otto_stats_931x_port_table_read(int port, unsigned int mib_size,
unsigned int mib_offset, bool is_pvt);