From: Harshal Gohel Date: Wed, 13 Aug 2025 13:44:12 +0000 (+0000) Subject: realtek: dsa: rtl931x: add ethtool statistics support X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=3c95a60e33100227f1b5f80604d56b85039db990;p=openwrt%2Fopenwrt.git realtek: dsa: rtl931x: add ethtool statistics support Add MIB data structures and table access routines for the RTL931X family. These counters can now be exposed through the ethtool statistics interface. Signed-off-by: Harshal Gohel Co-developed-by: Sharadanand Karanjkar Signed-off-by: Sharadanand Karanjkar Signed-off-by: Sven Eckelmann Link: https://github.com/openwrt/openwrt/pull/20631 Signed-off-by: Hauke Mehrtens --- diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c index 6d2dcbe609..bed9198603 100644 --- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c +++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c @@ -326,6 +326,104 @@ const struct rtldsa_mib_desc rtldsa_930x_mib = { .list = rtldsa_930x_mib_list }; +const struct rtldsa_mib_list_item rtldsa_931x_mib_list[] = { + MIB_LIST_ITEM("ifOutDiscards", MIB_ITEM(MIB_TBL_STD, 36, 1)), + MIB_LIST_ITEM("dot1dTpPortInDiscards", MIB_ITEM(MIB_TBL_STD, 35, 1)), + MIB_LIST_ITEM("DropEvents", MIB_ITEM(MIB_TBL_STD, 25, 1)), + MIB_LIST_ITEM("tx_BroadcastPkts", MIB_ITEM(MIB_TBL_STD, 24, 1)), + MIB_LIST_ITEM("tx_MulticastPkts", MIB_ITEM(MIB_TBL_STD, 23, 1)), + MIB_LIST_ITEM("tx_CRCAlignErrors", MIB_ITEM(MIB_TBL_STD, 22, 1)), + MIB_LIST_ITEM("tx_UndersizePkts", MIB_ITEM(MIB_TBL_STD, 20, 1)), + MIB_LIST_ITEM("tx_OversizePkts", MIB_ITEM(MIB_TBL_STD, 18, 1)), + MIB_LIST_ITEM("tx_Fragments", MIB_ITEM(MIB_TBL_STD, 16, 1)), + MIB_LIST_ITEM("tx_Jabbers", MIB_ITEM(MIB_TBL_STD, 14, 1)), + MIB_LIST_ITEM("tx_Collisions", MIB_ITEM(MIB_TBL_STD, 12, 1)), + + MIB_LIST_ITEM("rx_UndersizeDropPkts", MIB_ITEM(MIB_TBL_PRV, 27, 1)), + MIB_LIST_ITEM("tx_PktsFlexibleOctetsSet1", MIB_ITEM(MIB_TBL_PRV, 22, 1)), + MIB_LIST_ITEM("rx_PktsFlexibleOctetsSet1", MIB_ITEM(MIB_TBL_PRV, 21, 1)), + MIB_LIST_ITEM("tx_PktsFlexibleOctetsCRCSet1", MIB_ITEM(MIB_TBL_PRV, 28, 1)), + MIB_LIST_ITEM("rx_PktsFlexibleOctetsCRCSet1", MIB_ITEM(MIB_TBL_PRV, 27, 1)), + MIB_LIST_ITEM("tx_PktsFlexibleOctetsSet0", MIB_ITEM(MIB_TBL_PRV, 18, 1)), + MIB_LIST_ITEM("rx_PktsFlexibleOctetsSet0", MIB_ITEM(MIB_TBL_PRV, 17, 1)), + MIB_LIST_ITEM("tx_PktsFlexibleOctetsCRCSet0", MIB_ITEM(MIB_TBL_PRV, 16, 1)), + MIB_LIST_ITEM("rx_PktsFlexibleOctetsCRCSet0", MIB_ITEM(MIB_TBL_PRV, 15, 1)), + MIB_LIST_ITEM("LengthFieldError", MIB_ITEM(MIB_TBL_PRV, 14, 1)), + MIB_LIST_ITEM("FalseCarrierTimes", MIB_ITEM(MIB_TBL_PRV, 13, 1)), + MIB_LIST_ITEM("UndersizeOctets", MIB_ITEM(MIB_TBL_PRV, 12, 1)), + MIB_LIST_ITEM("FramingErrors", MIB_ITEM(MIB_TBL_PRV, 11, 1)), + MIB_LIST_ITEM("rx_MacDiscards", MIB_ITEM(MIB_TBL_PRV, 9, 1)), + MIB_LIST_ITEM("rx_MacIPGShortDrop", MIB_ITEM(MIB_TBL_PRV, 8, 1)) +}; + +const struct rtldsa_mib_desc rtldsa_931x_mib = { + .symbol_errors = MIB_ITEM(MIB_TBL_STD, 29, 1), + + .if_in_octets = MIB_ITEM(MIB_TBL_STD, 51, 2), + .if_out_octets = MIB_ITEM(MIB_TBL_STD, 49, 2), + .if_in_ucast_pkts = MIB_ITEM(MIB_TBL_STD, 47, 2), + .if_in_mcast_pkts = MIB_ITEM(MIB_TBL_STD, 45, 2), + .if_in_bcast_pkts = MIB_ITEM(MIB_TBL_STD, 43, 2), + .if_out_ucast_pkts = MIB_ITEM(MIB_TBL_STD, 41, 2), + .if_out_mcast_pkts = MIB_ITEM(MIB_TBL_STD, 39, 2), + .if_out_bcast_pkts = MIB_ITEM(MIB_TBL_STD, 37, 2), + .if_out_discards = MIB_ITEM(MIB_TBL_STD, 36, 1), + .single_collisions = MIB_ITEM(MIB_TBL_STD, 35, 1), + .multiple_collisions = MIB_ITEM(MIB_TBL_STD, 33, 1), + .deferred_transmissions = MIB_ITEM(MIB_TBL_STD, 32, 1), + .late_collisions = MIB_ITEM(MIB_TBL_STD, 31, 1), + .excessive_collisions = MIB_ITEM(MIB_TBL_STD, 30, 1), + .crc_align_errors = MIB_ITEM(MIB_TBL_STD, 21, 1), + .rx_pkts_over_max_octets = MIB_ITEM(MIB_TBL_PRV, 23, 1), + + .unsupported_opcodes = MIB_ITEM(MIB_TBL_STD, 28, 1), + + .rx_undersize_pkts = MIB_ITEM(MIB_TBL_STD, 19, 1), + .rx_oversize_pkts = MIB_ITEM(MIB_TBL_STD, 17, 1), + .rx_fragments = MIB_ITEM(MIB_TBL_STD, 15, 1), + .rx_jabbers = MIB_ITEM(MIB_TBL_STD, 13, 1), + + .tx_pkts = { + MIB_ITEM(MIB_TBL_STD, 11, 1), + MIB_ITEM(MIB_TBL_STD, 9, 1), + MIB_ITEM(MIB_TBL_STD, 7, 1), + MIB_ITEM(MIB_TBL_STD, 5, 1), + MIB_ITEM(MIB_TBL_STD, 3, 1), + MIB_ITEM(MIB_TBL_STD, 1, 1), + MIB_ITEM(MIB_TBL_PRV, 26, 1), + MIB_ITEM(MIB_TBL_PRV, 24, 1) + }, + .rx_pkts = { + MIB_ITEM(MIB_TBL_STD, 10, 1), + MIB_ITEM(MIB_TBL_STD, 8, 1), + MIB_ITEM(MIB_TBL_STD, 6, 1), + MIB_ITEM(MIB_TBL_STD, 4, 1), + MIB_ITEM(MIB_TBL_STD, 2, 1), + MIB_ITEM(MIB_TBL_STD, 0, 1), + MIB_ITEM(MIB_TBL_PRV, 25, 1), + MIB_ITEM(MIB_TBL_PRV, 23, 1), + }, + .rmon_ranges = { + { 0, 64 }, + { 65, 127 }, + { 128, 255 }, + { 256, 511 }, + { 512, 1023 }, + { 1024, 1518 }, + { 1519, 12288 }, + { 12289, 65535 } + }, + + .drop_events = MIB_ITEM(MIB_TBL_STD, 25, 1), + .collisions = MIB_ITEM(MIB_TBL_STD, 12, 1), + + .rx_pause_frames = MIB_ITEM(MIB_TBL_STD, 27, 1), + .tx_pause_frames = MIB_ITEM(MIB_TBL_STD, 26, 1), + + .list_count = ARRAY_SIZE(rtldsa_931x_mib_list), + .list = rtldsa_931x_mib_list +}; + /* DSA callbacks */ @@ -859,6 +957,8 @@ static const struct rtldsa_mib_desc *rtldsa_get_mib_desc(struct rtl838x_switch_p return &rtldsa_839x_mib; case RTL9300_FAMILY_ID: return &rtldsa_930x_mib; + case RTL9310_FAMILY_ID: + return &rtldsa_931x_mib; default: return NULL; } diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c index ba939103f7..45daf6b0f0 100644 --- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c +++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c @@ -1662,6 +1662,35 @@ static void rtldsa_931x_led_init(struct rtl838x_switch_priv *priv) dev_dbg(dev, "%08x: %08x\n", 0xbb000600 + i * 4, sw_r32(0x0600 + i * 4)); } +static u64 rtldsa_931x_stat_port_table_read(int port, unsigned int mib_size, + unsigned int mib_offset, bool is_pvt) +{ + struct table_reg *r; + int field_offset; + u64 ret = 0; + + if (is_pvt) { + r = rtl_table_get(RTL9310_TBL_5, 1); + field_offset = 27; + } else { + r = rtl_table_get(RTL9310_TBL_5, 0); + field_offset = 52; + } + + rtl_table_read(r, port); + + if (mib_size == 2) { + ret = sw_r32(rtl_table_data(r, field_offset - (mib_offset + 1))); + ret <<= 32; + } + + ret |= sw_r32(rtl_table_data(r, field_offset - mib_offset)); + + rtl_table_release(r); + + return ret; +} + static void rtldsa_931x_qos_set_group_selector(int port, int group) { sw_w32_mask(RTL93XX_PORT_TBL_IDX_CTRL_IDX_MASK(port), @@ -1745,6 +1774,7 @@ const struct rtl838x_reg rtl931x_reg = { .stat_port_rst = RTL931X_STAT_PORT_RST, .stat_rst = RTL931X_STAT_RST, .stat_port_std_mib = 0, /* Not defined */ + .stat_port_table_read = rtldsa_931x_stat_port_table_read, .traffic_enable = rtl931x_traffic_enable, .traffic_disable = rtl931x_traffic_disable, .traffic_set = rtl931x_traffic_set,