From patchwork Thu May 14 15:14:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Morales Vega X-Patchwork-Id: 472374 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E0C2114027F for ; Fri, 15 May 2015 01:14:55 +1000 (AEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id BA71F280BE3; Thu, 14 May 2015 17:13:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00 autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 13BA72800FA for ; Thu, 14 May 2015 17:13:14 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .samknows. - helo: .mail-wi0-f178.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 14 May 2015 17:13:13 +0200 (CEST) Received: by wizk4 with SMTP id k4so245435947wiz.1 for ; Thu, 14 May 2015 08:14:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=eS+ssXk7xwklONZXyPdfSvDT1lYMdUDy5QTwi7SJogA=; b=KOsj4M8FZQzt1Kw8AroerT+rA1aQWDa92H3uVQBiUAglOzHhRDp8gcWPhnJDhBygvR OepYghGF7UGLq6FP3oAs1bNA8PEx4fV2QsUi7OEsWrn4U9GoyNukW/yNPKsU1ozl1NW/ at/QnoCyGhPrKtdObdYHBaK23z2ycNjsEcw25LySCw2DVM3YuSZmOmUYYfwbUjuXGSOm 8b6YSAs8uJse8aDZ0L2YxSfIx/ufdgUu6Fyb/0m5X8VKVp9NpkAWxglY1JSpCVsRDIxf 2aliderlMgWTLz/PQgeojxWU30e6Un8XTELewCcNW1QhITmnJNFfk2t/hEDSRpoo4U7N I6XQ== X-Gm-Message-State: ALoCoQlq4qdsUcWqwg1Cg8o/l1CnzAMebIAAO5Q5dBSx/iyrkio5xq+NT20GpCzACKWxTJwJ0UWh X-Received: by 10.180.88.8 with SMTP id bc8mr24537902wib.19.1431616469666; Thu, 14 May 2015 08:14:29 -0700 (PDT) Received: from localhost.localdomain (5751e334.skybroadband.com. [87.81.227.52]) by mx.google.com with ESMTPSA id pj5sm33228593wjb.40.2015.05.14.08.14.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 May 2015 08:14:28 -0700 (PDT) From: Cristian Morales Vega To: openwrt-devel@lists.openwrt.org Date: Thu, 14 May 2015 16:14:24 +0100 Message-Id: <1431616464-22954-1-git-send-email-cristian@samknows.com> X-Mailer: git-send-email 2.1.0 Subject: [OpenWrt-Devel] [PATCH] ralink: add support for mt7621 switch counters X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Signed-off-by: Cristian Morales Vega --- .../drivers/net/ethernet/ralink/gsw_mt7620a.c | 8 +- .../files/drivers/net/ethernet/ralink/mt7530.c | 197 ++++++++++++++++++++- .../files/drivers/net/ethernet/ralink/mt7530.h | 3 +- 3 files changed, 199 insertions(+), 9 deletions(-) diff --git a/target/linux/ramips/files/drivers/net/ethernet/ralink/gsw_mt7620a.c b/target/linux/ramips/files/drivers/net/ethernet/ralink/gsw_mt7620a.c index 8039704..257a9c5 100644 --- a/target/linux/ramips/files/drivers/net/ethernet/ralink/gsw_mt7620a.c +++ b/target/linux/ramips/files/drivers/net/ethernet/ralink/gsw_mt7620a.c @@ -728,10 +728,10 @@ int mt7620_gsw_config(struct fe_priv *priv) /* is the mt7530 internal or external */ if (priv->mii_bus && priv->mii_bus->phy_map[0x1f]) { - mt7530_probe(priv->device, gsw->base, NULL, 0); - mt7530_probe(priv->device, NULL, priv->mii_bus, 1); + mt7530_probe(priv->device, gsw->base, NULL, 0, 0); + mt7530_probe(priv->device, NULL, priv->mii_bus, 1, 0); } else { - mt7530_probe(priv->device, gsw->base, NULL, 1); + mt7530_probe(priv->device, gsw->base, NULL, 1, 0); } return 0; @@ -740,7 +740,7 @@ int mt7620_gsw_config(struct fe_priv *priv) int mt7621_gsw_config(struct fe_priv *priv) { if (priv->mii_bus && priv->mii_bus->phy_map[0x1f]) - mt7530_probe(priv->device, NULL, priv->mii_bus, 1); + mt7530_probe(priv->device, NULL, priv->mii_bus, 1, 1); return 0; } diff --git a/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.c b/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.c index 1352b25..cacf19e 100644 --- a/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.c +++ b/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.c @@ -63,6 +63,107 @@ enum { #define REG_HWTRAP 0x7804 +#define MIB_DESC(_s , _o, _n) \ + { \ + .size = (_s), \ + .offset = (_o), \ + .name = (_n), \ + } + +struct mt7xxx_mib_desc { + unsigned int size; + unsigned int offset; + const char *name; +}; + +#define MT7621_MIB_COUNTER_BASE 0x4000 +#define MT7621_MIB_COUNTER_PORT_OFFSET 0x100 +#define MT7621_STATS_TDPC 0x00 +#define MT7621_STATS_TCRC 0x04 +#define MT7621_STATS_TUPC 0x08 +#define MT7621_STATS_TMPC 0x0C +#define MT7621_STATS_TBPC 0x10 +#define MT7621_STATS_TCEC 0x14 +#define MT7621_STATS_TSCEC 0x18 +#define MT7621_STATS_TMCEC 0x1C +#define MT7621_STATS_TDEC 0x20 +#define MT7621_STATS_TLCEC 0x24 +#define MT7621_STATS_TXCEC 0x28 +#define MT7621_STATS_TPPC 0x2C +#define MT7621_STATS_TL64PC 0x30 +#define MT7621_STATS_TL65PC 0x34 +#define MT7621_STATS_TL128PC 0x38 +#define MT7621_STATS_TL256PC 0x3C +#define MT7621_STATS_TL512PC 0x40 +#define MT7621_STATS_TL1024PC 0x44 +#define MT7621_STATS_TOC 0x48 +#define MT7621_STATS_RDPC 0x60 +#define MT7621_STATS_RFPC 0x64 +#define MT7621_STATS_RUPC 0x68 +#define MT7621_STATS_RMPC 0x6C +#define MT7621_STATS_RBPC 0x70 +#define MT7621_STATS_RAEPC 0x74 +#define MT7621_STATS_RCEPC 0x78 +#define MT7621_STATS_RUSPC 0x7C +#define MT7621_STATS_RFEPC 0x80 +#define MT7621_STATS_ROSPC 0x84 +#define MT7621_STATS_RJEPC 0x88 +#define MT7621_STATS_RPPC 0x8C +#define MT7621_STATS_RL64PC 0x90 +#define MT7621_STATS_RL65PC 0x94 +#define MT7621_STATS_RL128PC 0x98 +#define MT7621_STATS_RL256PC 0x9C +#define MT7621_STATS_RL512PC 0xA0 +#define MT7621_STATS_RL1024PC 0xA4 +#define MT7621_STATS_ROC 0xA8 +#define MT7621_STATS_RDPC_CTRL 0xB0 +#define MT7621_STATS_RDPC_ING 0xB4 +#define MT7621_STATS_RDPC_ARL 0xB8 + +static const struct mt7xxx_mib_desc mt7621_mibs[] = { + MIB_DESC(1, MT7621_STATS_TDPC, "TxDrop"), + MIB_DESC(1, MT7621_STATS_TCRC, "TxCRC"), + MIB_DESC(1, MT7621_STATS_TUPC, "TxUni"), + MIB_DESC(1, MT7621_STATS_TMPC, "TxMulti"), + MIB_DESC(1, MT7621_STATS_TBPC, "TxBroad"), + MIB_DESC(1, MT7621_STATS_TCEC, "TxCollision"), + MIB_DESC(1, MT7621_STATS_TSCEC, "TxSingleCol"), + MIB_DESC(1, MT7621_STATS_TMCEC, "TxMultiCol"), + MIB_DESC(1, MT7621_STATS_TDEC, "TxDefer"), + MIB_DESC(1, MT7621_STATS_TLCEC, "TxLateCol"), + MIB_DESC(1, MT7621_STATS_TXCEC, "TxExcCol"), + MIB_DESC(1, MT7621_STATS_TPPC, "TxPause"), + MIB_DESC(1, MT7621_STATS_TL64PC, "Tx64Byte"), + MIB_DESC(1, MT7621_STATS_TL65PC, "Tx65Byte"), + MIB_DESC(1, MT7621_STATS_TL128PC, "Tx128Byte"), + MIB_DESC(1, MT7621_STATS_TL256PC, "Tx256Byte"), + MIB_DESC(1, MT7621_STATS_TL512PC, "Tx512Byte"), + MIB_DESC(1, MT7621_STATS_TL1024PC, "Tx1024Byte"), + MIB_DESC(2, MT7621_STATS_TOC, "TxByte"), + MIB_DESC(1, MT7621_STATS_RDPC, "RxDrop"), + MIB_DESC(1, MT7621_STATS_RFPC, "RxFiltered"), + MIB_DESC(1, MT7621_STATS_RUPC, "RxUni"), + MIB_DESC(1, MT7621_STATS_RMPC, "RxMulti"), + MIB_DESC(1, MT7621_STATS_RBPC, "RxBroad"), + MIB_DESC(1, MT7621_STATS_RAEPC, "RxAlignErr"), + MIB_DESC(1, MT7621_STATS_RCEPC, "RxCRC"), + MIB_DESC(1, MT7621_STATS_RUSPC, "RxUnderSize"), + MIB_DESC(1, MT7621_STATS_RFEPC, "RxFragment"), + MIB_DESC(1, MT7621_STATS_ROSPC, "RxOverSize"), + MIB_DESC(1, MT7621_STATS_RJEPC, "RxJabber"), + MIB_DESC(1, MT7621_STATS_RPPC, "RxPause"), + MIB_DESC(1, MT7621_STATS_RL64PC, "Rx64Byte"), + MIB_DESC(1, MT7621_STATS_RL65PC, "Rx65Byte"), + MIB_DESC(1, MT7621_STATS_RL128PC, "Rx128Byte"), + MIB_DESC(1, MT7621_STATS_RL256PC, "Rx256Byte"), + MIB_DESC(1, MT7621_STATS_RL512PC, "Rx512Byte"), + MIB_DESC(1, MT7621_STATS_RL1024PC, "Rx1024Byte"), + MIB_DESC(2, MT7621_STATS_ROC, "RxByte"), + MIB_DESC(1, MT7621_STATS_RDPC_CTRL, "RxCtrlDrop"), + MIB_DESC(1, MT7621_STATS_RDPC_ING, "RxIngDrop"), + MIB_DESC(1, MT7621_STATS_RDPC_ARL, "RxARLDrop") +}; + enum { /* Global attributes. */ MT7530_ATTR_ENABLE_VLAN, @@ -500,6 +601,63 @@ static const struct switch_attr mt7530_global[] = { }, }; +static u64 get_mib_counter(struct mt7530_priv *priv, int i, int port) +{ + unsigned int port_base; + u64 t; + + port_base = MT7621_MIB_COUNTER_BASE + + MT7621_MIB_COUNTER_PORT_OFFSET * port; + + t = mt7530_r32(priv, port_base + mt7621_mibs[i].offset); + if (mt7621_mibs[i].size == 2) { + u64 hi; + + hi = mt7530_r32(priv, port_base + mt7621_mibs[i].offset + 4); + t |= hi << 32; + } + + return t; +} + +static int mt7621_sw_get_port_mib(struct switch_dev *dev, + const struct switch_attr *attr, + struct switch_val *val) +{ + static char buf[4096]; + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev); + int i, len = 0; + + if (val->port_vlan >= MT7530_NUM_PORTS) + return -EINVAL; + + len += snprintf(buf + len, sizeof(buf) - len, + "Port %d MIB counters\n", val->port_vlan); + + for (i = 0; i < sizeof(mt7621_mibs) / sizeof(*mt7621_mibs); ++i) { + u64 counter; + len += snprintf(buf + len, sizeof(buf) - len, + "%-11s: ", mt7621_mibs[i].name); + counter = get_mib_counter(priv, i, val->port_vlan); + len += snprintf(buf + len, sizeof(buf) - len, "%llu\n", + counter); + } + + val->value.s = buf; + val->len = len; + return 0; +} + +static const struct switch_attr mt7621_port[] = { + { + .type = SWITCH_TYPE_STRING, + .name = "mib", + .description = "Get MIB counters for port", + .get = mt7621_sw_get_port_mib, + .set = NULL, + }, +}; + static const struct switch_attr mt7530_port[] = { }; @@ -514,6 +672,28 @@ static const struct switch_attr mt7530_vlan[] = { }, }; +static const struct switch_dev_ops mt7621_ops = { + .attr_global = { + .attr = mt7530_global, + .n_attr = ARRAY_SIZE(mt7530_global), + }, + .attr_port = { + .attr = mt7621_port, + .n_attr = ARRAY_SIZE(mt7621_port), + }, + .attr_vlan = { + .attr = mt7530_vlan, + .n_attr = ARRAY_SIZE(mt7530_vlan), + }, + .get_vlan_ports = mt7530_get_vlan_ports, + .set_vlan_ports = mt7530_set_vlan_ports, + .get_port_pvid = mt7530_get_port_pvid, + .set_port_pvid = mt7530_set_port_pvid, + .get_port_link = mt7530_get_port_link, + .apply_config = mt7530_apply_config, + .reset_switch = mt7530_reset_switch, +}; + static const struct switch_dev_ops mt7530_ops = { .attr_global = { .attr = mt7530_global, @@ -537,7 +717,8 @@ static const struct switch_dev_ops mt7530_ops = { }; int -mt7530_probe(struct device *dev, void __iomem *base, struct mii_bus *bus, int vlan) +mt7530_probe(struct device *dev, void __iomem *base, struct mii_bus *bus, + int vlan, bool is_mt7621) { struct switch_dev *swdev; struct mt7530_priv *mt7530; @@ -557,13 +738,21 @@ mt7530_probe(struct device *dev, void __iomem *base, struct mii_bus *bus, int vl swdev->alias = "mt7530"; swdev->name = "mt7530"; } else { - swdev->alias = "mt7620"; - swdev->name = "mt7620"; + if (is_mt7621) { + swdev->alias = "mt7621"; + swdev->name = "mt7621"; + } else { + swdev->alias = "mt7620"; + swdev->name = "mt7620"; + } } swdev->cpu_port = MT7530_CPU_PORT; swdev->ports = MT7530_NUM_PORTS; swdev->vlans = MT7530_NUM_VLANS; - swdev->ops = &mt7530_ops; + if (is_mt7621) + swdev->ops = &mt7621_ops; + else + swdev->ops = &mt7530_ops; ret = register_switch(swdev, NULL); if (ret) { diff --git a/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.h b/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.h index 1fc8c62..d62b300 100644 --- a/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.h +++ b/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.h @@ -15,6 +15,7 @@ #ifndef _MT7530_H__ #define _MT7530_H__ -int mt7530_probe(struct device *dev, void __iomem *base, struct mii_bus *bus, int vlan); +int mt7530_probe(struct device *dev, void __iomem *base, struct mii_bus *bus, + int vlan, bool is_mt7621); #endif