From patchwork Wed Dec 16 17:19:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 557565 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 C53A51402C9 for ; Thu, 17 Dec 2015 04:20:09 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=cu3w2oGi; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 6AE4728B794; Wed, 16 Dec 2015 18:19:32 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 2DD462841E4 for ; Wed, 16 Dec 2015 18:19:20 +0100 (CET) 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: .gmail. - helo: .mail-lf0-f44.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com [209.85.215.44]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Wed, 16 Dec 2015 18:19:19 +0100 (CET) Received: by mail-lf0-f44.google.com with SMTP id p203so34493809lfa.0 for ; Wed, 16 Dec 2015 09:19:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=rTa9uiWm7NosZk+De951H3KgTPACfxCP6ncSfGWWy2U=; b=cu3w2oGijmYShpRLJCwHgme6V/390vMJoVcLVmcpTIv3PFGsehQK3jSY5QMdeJHt8K jvV4mkVgH+GvHjh0CqyfQLt+Uv1BaLvFzx4VwSL4dUUYHG2dT4ly3bU0UXjQmeQQFaBE 3OZpMOAjrMQwxv1K/JeZCYnnzuUfExQNjXlNzS4bZ2okGpof4pgZ2NOTpy2zAsSVIQwc cXjPVyftpifgyQZns+3css1emEc/EIwLBD3eHSM9wLsUouuqJQwM6AhITSbiqvGd9gq+ 3+6u9cIKkBF0DPoDkBwzEqntXV4GDv1bpBxdKE9PWs5Xy7z6bSNRyQK3Gmg+43EFrIpk mA2g== X-Received: by 10.25.159.206 with SMTP id i197mr19037711lfe.89.1450286374186; Wed, 16 Dec 2015 09:19:34 -0800 (PST) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id l15sm263474lfg.49.2015.12.16.09.19.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Dec 2015 09:19:33 -0800 (PST) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: openwrt-devel@lists.openwrt.org, Felix Fietkau Date: Wed, 16 Dec 2015 18:19:01 +0100 Message-Id: <1450286343-5514-1-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.8.4.5 MIME-Version: 1.0 Subject: [OpenWrt-Devel] [PATCH 1/3] swconfig: add SWITCH_TYPE_LINK and support sending link info to user space 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: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" So far we were sending link data as a string. It got some drawbacks: 1) Didn't allow writing clean user space apps reading link state. It was needed to do some screen scraping. 2) Forced whole PORT_LINK communication to be string based. Adding support for *setting* port link required passing string and parting it in the kernel space. Signed-off-by: Rafał Miłecki --- .../linux/generic/files/drivers/net/phy/swconfig.c | 46 ++++++++++++++++++++++ target/linux/generic/files/include/linux/switch.h | 2 + .../generic/files/include/uapi/linux/switch.h | 16 ++++++++ 3 files changed, 64 insertions(+) diff --git a/target/linux/generic/files/drivers/net/phy/swconfig.c b/target/linux/generic/files/drivers/net/phy/swconfig.c index 6bb3be1..731bdcb 100644 --- a/target/linux/generic/files/drivers/net/phy/swconfig.c +++ b/target/linux/generic/files/drivers/net/phy/swconfig.c @@ -771,6 +771,43 @@ done: } static int +swconfig_send_link(struct sk_buff *msg, struct genl_info *info, int attr, + const struct switch_port_link *link) +{ + struct nlattr *p = NULL; + int err = 0; + + p = nla_nest_start(msg, attr); + if (nla_put_u32(msg, SWITCH_LINK_LINK, link->link)) + goto nla_put_failure; + if (nla_put_u32(msg, SWITCH_LINK_DUPLEX, link->duplex)) + goto nla_put_failure; + if (nla_put_u32(msg, SWITCH_LINK_ANEG, link->aneg)) + goto nla_put_failure; + if (nla_put_u32(msg, SWITCH_LINK_TX_FLOW, link->tx_flow)) + goto nla_put_failure; + if (nla_put_u32(msg, SWITCH_LINK_RX_FLOW, link->rx_flow)) + goto nla_put_failure; + if (nla_put_u32(msg, SWITCH_LINK_SPEED, link->speed)) + goto nla_put_failure; + if (link->eee & ADVERTISED_100baseT_Full) { + if (nla_put_flag(msg, SWITCH_LINK_FLAG_ADVERTISED_100BASET_FULL)) + goto nla_put_failure; + } + if (link->eee & ADVERTISED_1000baseT_Full) { + if (nla_put_flag(msg, SWITCH_LINK_FLAG_ADVERTISED_1000BASET_FULL)) + goto nla_put_failure; + } + nla_nest_end(msg, p); + + return err; + +nla_put_failure: + nla_nest_cancel(msg, p); + return -1; +} + +static int swconfig_get_attr(struct sk_buff *skb, struct genl_info *info) { struct genlmsghdr *hdr = nlmsg_data(info->nlhdr); @@ -794,6 +831,9 @@ swconfig_get_attr(struct sk_buff *skb, struct genl_info *info) val.value.ports = dev->portbuf; memset(dev->portbuf, 0, sizeof(struct switch_port) * dev->ports); + } else if (attr->type == SWITCH_TYPE_LINK) { + val.value.link = &dev->linkbuf; + memset(&dev->linkbuf, 0, sizeof(struct switch_port_link)); } err = attr->get(dev, attr, &val); @@ -824,6 +864,12 @@ swconfig_get_attr(struct sk_buff *skb, struct genl_info *info) if (err < 0) goto nla_put_failure; break; + case SWITCH_TYPE_LINK: + err = swconfig_send_link(msg, info, + SWITCH_ATTR_OP_VALUE_LINK, val.value.link); + if (err < 0) + goto nla_put_failure; + break; default: pr_debug("invalid type in attribute\n"); err = -EINVAL; diff --git a/target/linux/generic/files/include/linux/switch.h b/target/linux/generic/files/include/linux/switch.h index 4291364..eac35f9 100644 --- a/target/linux/generic/files/include/linux/switch.h +++ b/target/linux/generic/files/include/linux/switch.h @@ -122,6 +122,7 @@ struct switch_dev { struct mutex sw_mutex; struct switch_port *portbuf; struct switch_portmap *portmap; + struct switch_port_link linkbuf; char buf[128]; @@ -148,6 +149,7 @@ struct switch_val { const char *s; u32 i; struct switch_port *ports; + struct switch_port_link *link; } value; }; diff --git a/target/linux/generic/files/include/uapi/linux/switch.h b/target/linux/generic/files/include/uapi/linux/switch.h index a59b239..b599943 100644 --- a/target/linux/generic/files/include/uapi/linux/switch.h +++ b/target/linux/generic/files/include/uapi/linux/switch.h @@ -50,6 +50,7 @@ enum { SWITCH_ATTR_OP_VALUE_INT, SWITCH_ATTR_OP_VALUE_STR, SWITCH_ATTR_OP_VALUE_PORTS, + SWITCH_ATTR_OP_VALUE_LINK, SWITCH_ATTR_OP_DESCRIPTION, /* port lists */ SWITCH_ATTR_PORT, @@ -86,6 +87,7 @@ enum switch_val_type { SWITCH_TYPE_INT, SWITCH_TYPE_STRING, SWITCH_TYPE_PORTS, + SWITCH_TYPE_LINK, SWITCH_TYPE_NOVAL, }; @@ -97,6 +99,20 @@ enum { SWITCH_PORT_ATTR_MAX }; +/* link nested attributes */ +enum { + SWITCH_LINK_UNSPEC, + SWITCH_LINK_LINK, + SWITCH_LINK_DUPLEX, + SWITCH_LINK_ANEG, + SWITCH_LINK_TX_FLOW, + SWITCH_LINK_RX_FLOW, + SWITCH_LINK_SPEED, + SWITCH_LINK_FLAG_ADVERTISED_100BASET_FULL, + SWITCH_LINK_FLAG_ADVERTISED_1000BASET_FULL, + SWITCH_LINK_ATTR_MAX, +}; + #define SWITCH_ATTR_DEFAULTS_OFFSET 0x1000