From patchwork Sat Feb 25 21:51:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_Gonz=C3=A1lez_Cabanelas?= X-Patchwork-Id: 732452 X-Patchwork-Delegate: openwrt@kresin.me Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vW1tD4tCsz9s74 for ; Sun, 26 Feb 2017 08:52:52 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JhDfPllV"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jdVlb6iW"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-ID:Date:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=BPiqxck/6RabdsSwqmEzbsU7cs+dny43NCKW2n7rKDw=; b=JhDfPllVjFb9r6 vNoGVwJLif+VPCMSTWE+JdCYJFWcmvFCWECpWNZHHSlR3NJXS29gE00anQc2xNWPKEQmqFuXw9dMV /VUzDuU1jPjDnx6a3TA5QFvUQGNuRQRY4TMhuWW2BIUJvUZ3UJ/oQUcwBjKPGvjrB8AqdQ2IBd5Rh X+oUdHnXNNXhI0i8ezHwcwCYld4ItfBM8ZZJ8VBvCwjR33n60WgUToFwqYY1wVP5j7YKPZal7eyJT l3NeQIEdtgbSSoz2Xs0yd/T0RFPiGsohcxS9ZuLqsmK4OtPrvGFra3+55maFy+NfRrGD0h+epFGnf 64TPabs3aTr9uqK/RiEg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1chkG4-00028u-Ez; Sat, 25 Feb 2017 21:52:04 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1chkFf-00025g-9i for lede-dev@lists.infradead.org; Sat, 25 Feb 2017 21:51:41 +0000 Received: by mail-wr0-x243.google.com with SMTP id q39so6127034wrb.2 for ; Sat, 25 Feb 2017 13:51:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:user-agent:mime-version :content-transfer-encoding; bh=k2SCy8E76XTU4EI4ly/5PJl8CbhceWEpt3fDnmOcuuc=; b=jdVlb6iW4Utxk6ZW0aKLxezBN5E4h8hpnJjN0UKc1Ht9SEUBEGpIT6qqQgBzNqYQMS gHP5jo2RnM4EW1H3vZzox4eT4IeCGijQz0zlK22Q8gxluhy/8eK6gcCuXCbN2fraWbzr mvkSaYt8hYJ3tdvvyf8cB/w/3iutF8X9WQ4vmRc9EEb/Xy+BQwajq/cBb8seRIwpt73W NRdNBGZ4QYcuC+5QHNdXlYGxM4vDHByWA6bAQxO0z+D/rliZr+4DZjNeQZCuY6pHXdzD mpJYsyQQrhzOTJhYNjAJQX8640F6p1Hn4RkTUwu6JpIrvQdVpWBuFYwXWruuSV4MKLTn a7gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version:content-transfer-encoding; bh=k2SCy8E76XTU4EI4ly/5PJl8CbhceWEpt3fDnmOcuuc=; b=TJ8c9C2WG39vYd8RE5kMdYtnqvHB+7VRPtaWcYlVEtk9+Fc3ZleHjROABPUp46bZ2y DTKse0921Wk1f8HJZ0rj750HLz9MHPWLzyp4KWJnLuRUlZfPL+aeAbNmmdE7L92UWpZD shtb0VPQ+8sPcOKCIk4FOoc0WzbufLLp0PefMi84iZ9vPfWNYle/y0g2BzeQvXyOhB3C InBFg13THbddP+x7mMfnCadLkrwulYYenjpvz8dR13+Qdyku88Ooi1LLZYXK6W4py3sn C3+b4HBFCH+RfiXm0GF8B7fJbJqf+uslVZxKFnm8WJefjzmdI2QfmQWtMsToKGa31Kdv 6/KA== X-Gm-Message-State: AMke39lhkiHpTHXrmEuIrXMbZiJFR7bSwLpemvVU3ZbK4lbmsm2kyCmuiH0dZ8VeX5t9Qg== X-Received: by 10.223.170.70 with SMTP id q6mr8086626wrd.103.1488059476333; Sat, 25 Feb 2017 13:51:16 -0800 (PST) Received: from tool.localnet ([188.86.75.31]) by smtp.googlemail.com with ESMTPSA id g71sm7848688wmc.9.2017.02.25.13.51.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Feb 2017 13:51:15 -0800 (PST) From: Daniel Gonzalez Cabanelas To: lede-dev@lists.infradead.org Date: Sat, 25 Feb 2017 22:51:13 +0100 Message-ID: <8021994.eIdPYGzJH3@tool> User-Agent: KMail/4.14.10 (Linux/4.6.5-1-zen; KDE/4.14.14; x86_64; ; ) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170225_135139_528198_B4832E3E X-CRM114-Status: GOOD ( 13.38 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c0c:0:0:0:243 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (dgcbueu[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [LEDE-DEV] [RFC] AR8327 driver: implementing get_port_stats function X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Currently the switch LED trigger only shows link status, but not traffic activity by blinking the LEDs on the AR8316/AR8327 switch. It turns out that the get_port_stats is missing. I've made this patch, which works ok. But I'm not sure if there is any reason to not implement this function. And probably the function ar8xxx_sw_get_port_stats can be improved. There are a few boards with an AR8316/AR8327 switch that need this trigger, usually on the WAN port. As said without get_port_stats the light stays always fixed, like if there wasn't traffic activity. We can use the netdev trigger but then the light is always on even when the cable is unplugged, and there isn't the possibility of using a second LED trigger on the same port for indicating a reduced link speed. diff --git a/target/linux/generic/files/drivers/net/phy/ar8216.c b/target/linux/generic/files/drivers/net/phy/ar8216.c index 37877d5..ffaa77e 100644 --- a/target/linux/generic/files/drivers/net/phy/ar8216.c +++ b/target/linux/generic/files/drivers/net/phy/ar8216.c @@ -1001,6 +1001,41 @@ ar8xxx_sw_get_port_link(struct switch_dev *dev, int port, return 0; } +int +ar8xxx_sw_get_port_stats(struct switch_dev *dev, int port, + struct switch_port_stats *stats) +{ + struct ar8xxx_priv *priv = swdev_to_ar8xxx(dev); + const struct ar8xxx_chip *chip = priv->chip; + u64 *mib_stats, mib_data; + const char *mib_name; + int i; + + if (!ar8xxx_has_mib_counters(priv)) + return -EOPNOTSUPP; + + if (port >= dev->ports) + return -EINVAL; + + mutex_lock(&priv->mib_lock); + + ar8xxx_mib_fetch_port_stat(priv, port, false); + + mib_stats = &priv->mib_stats[port * chip->num_mibs]; + for (i = 0; i < chip->num_mibs; i++) { + mib_name = chip->mib_decs[i].name; + mib_data = mib_stats[i]; + if (!strcmp(mib_name, "TxByte")) + stats->tx_bytes = mib_data; + if (!strcmp(mib_name, "RxGoodByte")) + stats->rx_bytes = mib_data; + } + + mutex_unlock(&priv->mib_lock); + + return 0; +} + static int ar8xxx_sw_get_ports(struct switch_dev *dev, struct switch_val *val) { @@ -1696,6 +1731,7 @@ static const struct switch_dev_ops ar8xxx_sw_ops = { .apply_config = ar8xxx_sw_hw_apply, .reset_switch = ar8xxx_sw_reset_switch, .get_port_link = ar8xxx_sw_get_port_link, + .get_port_stats = ar8xxx_sw_get_port_stats, }; static const struct ar8xxx_chip ar8216_chip = { diff --git a/target/linux/generic/files/drivers/net/phy/ar8216.h b/target/linux/generic/files/drivers/net/phy/ar8216.h index d9508b9..8b05cf3 100644 --- a/target/linux/generic/files/drivers/net/phy/ar8216.h +++ b/target/linux/generic/files/drivers/net/phy/ar8216.h @@ -538,6 +538,9 @@ int ar8xxx_sw_get_port_link(struct switch_dev *dev, int port, struct switch_port_link *link); int +ar8xxx_sw_get_port_stats(struct switch_dev *dev, + int port, struct switch_port_stats *stats); +int ar8xxx_sw_set_port_reset_mib(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val); diff --git a/target/linux/generic/files/drivers/net/phy/ar8327.c b/target/linux/generic/files/drivers/net/phy/ar8327.c index 9b40cd7..e82563f 100644 --- a/target/linux/generic/files/drivers/net/phy/ar8327.c +++ b/target/linux/generic/files/drivers/net/phy/ar8327.c @@ -1372,6 +1372,7 @@ static const struct switch_dev_ops ar8327_sw_ops = { .apply_config = ar8327_sw_hw_apply, .reset_switch = ar8xxx_sw_reset_switch, .get_port_link = ar8xxx_sw_get_port_link, + .get_port_stats = ar8xxx_sw_get_port_stats, }; const struct ar8xxx_chip ar8327_chip = {