From patchwork Sat Aug 29 00:29:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Leite X-Patchwork-Id: 512100 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.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BE41C1401C7 for ; Sat, 29 Aug 2015 10:29:28 +1000 (AEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 2030828BD27; Sat, 29 Aug 2015 02:28:19 +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 0FF3528BD27 for ; Sat, 29 Aug 2015 02:28:15 +0200 (CEST) X-policyd-weight: using cached result; rate: -5.5 Received: from smtp.rcn.com (smtp.rcn.com [69.168.97.78]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sat, 29 Aug 2015 02:28:14 +0200 (CEST) X_CMAE_Category: , , X-CNFS-Analysis: v=2.0 cv=YJUdOG6x c=1 sm=1 a=B9hiZdbHwwKCHQef9MtDEA==:17 a=8ndMLmUfAAAA:8 a=1AzdBDPpWNrTpFc68AwA:9 a=B9hiZdbHwwKCHQef9MtDEA==:117 X-CM-Score: 0 X-Scanned-by: Cloudmark Authority Engine X-Authed-Username: bGVpdGVjQHN0YXRpY2t5LmNvbQ== Authentication-Results: smtp02.rcn.cmh.synacor.com smtp.mail=leitec@staticky.com; spf=neutral; sender-id=neutral Authentication-Results: smtp02.rcn.cmh.synacor.com header.from=leitec@staticky.com; sender-id=neutral Received-SPF: neutral (smtp02.rcn.cmh.synacor.com: 216.15.22.97 is neither permitted nor denied by domain of staticky.com) Received: from [216.15.22.97] ([216.15.22.97:38574] helo=dirk.lan.staticky.com) by smtp.rcn.com (envelope-from ) (ecelerity 3.6.2.43620 r(Platform:3.6.2.0)) with ESMTP id 15/96-01449-4DCF0E55; Fri, 28 Aug 2015 20:29:09 -0400 From: Claudio Leite To: openwrt-devel@lists.openwrt.org Date: Fri, 28 Aug 2015 20:29:01 -0400 Message-Id: <1440808141-15700-1-git-send-email-leitec@staticky.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1440792373-30272-1-git-send-email-leitec@staticky.com> References: <1440792373-30272-1-git-send-email-leitec@staticky.com> Subject: [OpenWrt-Devel] [PATCH v2] mvsw61xx: use standard swconfig get_port_link 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" The previous "link" and "status" functions were non-standard, and thus less useful for parsing. Signed-off-by: Claudio Leite --- v2: remove enums as well If accepted this should be also pushed to CC, assuming that's still possible. .../linux/generic/files/drivers/net/phy/mvsw61xx.c | 94 +++++----------------- 1 file changed, 18 insertions(+), 76 deletions(-) diff --git a/target/linux/generic/files/drivers/net/phy/mvsw61xx.c b/target/linux/generic/files/drivers/net/phy/mvsw61xx.c index 9417fd4..07b4343 100644 --- a/target/linux/generic/files/drivers/net/phy/mvsw61xx.c +++ b/target/linux/generic/files/drivers/net/phy/mvsw61xx.c @@ -219,73 +219,32 @@ mvsw61xx_set_pvid(struct switch_dev *dev, int port, int val) } static int -mvsw61xx_get_port_status(struct switch_dev *dev, - const struct switch_attr *attr, struct switch_val *val) +mvsw61xx_get_port_link(struct switch_dev *dev, int port, + struct switch_port_link *link) { - struct mvsw61xx_state *state = get_state(dev); - char *buf = state->buf; u16 status, speed; - int len; - - status = sr16(dev, MV_PORTREG(STATUS, val->port_vlan)); - speed = (status & MV_PORT_STATUS_SPEED_MASK) >> - MV_PORT_STATUS_SPEED_SHIFT; - - len = sprintf(buf, "link: "); - if (status & MV_PORT_STATUS_LINK) { - len += sprintf(buf + len, "up, speed: "); - - switch (speed) { - case MV_PORT_STATUS_SPEED_10: - len += sprintf(buf + len, "10"); - break; - case MV_PORT_STATUS_SPEED_100: - len += sprintf(buf + len, "100"); - break; - case MV_PORT_STATUS_SPEED_1000: - len += sprintf(buf + len, "1000"); - break; - } - len += sprintf(buf + len, " Mbps, duplex: "); + status = sr16(dev, MV_PORTREG(STATUS, port)); - if (status & MV_PORT_STATUS_FDX) - len += sprintf(buf + len, "full"); - else - len += sprintf(buf + len, "half"); - } else { - len += sprintf(buf + len, "down"); - } - - val->value.s = buf; - - return 0; -} + link->link = status & MV_PORT_STATUS_LINK; + if (!link->link) + return 0; -static int -mvsw61xx_get_port_speed(struct switch_dev *dev, - const struct switch_attr *attr, struct switch_val *val) -{ - u16 status, speed; + link->duplex = status & MV_PORT_STATUS_FDX; - status = sr16(dev, MV_PORTREG(STATUS, val->port_vlan)); speed = (status & MV_PORT_STATUS_SPEED_MASK) >> MV_PORT_STATUS_SPEED_SHIFT; - val->value.i = 0; - - if (status & MV_PORT_STATUS_LINK) { - switch (speed) { - case MV_PORT_STATUS_SPEED_10: - val->value.i = 10; - break; - case MV_PORT_STATUS_SPEED_100: - val->value.i = 100; - break; - case MV_PORT_STATUS_SPEED_1000: - val->value.i = 1000; - break; - } + switch (speed) { + case MV_PORT_STATUS_SPEED_10: + link->speed = SWITCH_PORT_SPEED_10; + break; + case MV_PORT_STATUS_SPEED_100: + link->speed = SWITCH_PORT_SPEED_100; + break; + case MV_PORT_STATUS_SPEED_1000: + link->speed = SWITCH_PORT_SPEED_1000; + break; } return 0; @@ -676,8 +635,6 @@ enum { enum { MVSW61XX_PORT_MASK, MVSW61XX_PORT_QMODE, - MVSW61XX_PORT_STATUS, - MVSW61XX_PORT_LINK, }; static const struct switch_attr mvsw61xx_global[] = { @@ -727,22 +684,6 @@ static const struct switch_attr mvsw61xx_port[] = { .get = mvsw61xx_get_port_qmode, .set = mvsw61xx_set_port_qmode, }, - [MVSW61XX_PORT_STATUS] = { - .id = MVSW61XX_PORT_STATUS, - .type = SWITCH_TYPE_STRING, - .description = "Return port status", - .name = "status", - .get = mvsw61xx_get_port_status, - .set = NULL, - }, - [MVSW61XX_PORT_LINK] = { - .id = MVSW61XX_PORT_LINK, - .type = SWITCH_TYPE_INT, - .description = "Get link speed", - .name = "link", - .get = mvsw61xx_get_port_speed, - .set = NULL, - }, }; static const struct switch_dev_ops mvsw61xx_ops = { @@ -758,6 +699,7 @@ static const struct switch_dev_ops mvsw61xx_ops = { .attr = mvsw61xx_port, .n_attr = ARRAY_SIZE(mvsw61xx_port), }, + .get_port_link = mvsw61xx_get_port_link, .get_port_pvid = mvsw61xx_get_pvid, .set_port_pvid = mvsw61xx_set_pvid, .get_vlan_ports = mvsw61xx_get_vlan_ports,