From patchwork Tue Jan 10 20:12:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 9508483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 19EDB606E1 for ; Tue, 10 Jan 2017 20:14:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A8F028423 for ; Tue, 10 Jan 2017 20:14:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F32072858A; Tue, 10 Jan 2017 20:14:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 350B128423 for ; Tue, 10 Jan 2017 20:14:10 +0000 (UTC) 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 1cR2o3-0002bh-9s; Tue, 10 Jan 2017 20:14:07 +0000 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cR2nU-0001ZJ-87 for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2017 20:13:34 +0000 Received: by mail-pf0-x241.google.com with SMTP id y143so9233371pfb.1 for ; Tue, 10 Jan 2017 12:13:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WKwWs0dQ3X7DmJxjPDLJAHB0GI2TCNM72PwGd1fv5II=; b=P69GKO3BoBdYxpnxIPUS9H1drnsXev61cIao2J/XomWpPUydJs/BkP4Lkd046nV9il CELFtY4UcgAhWoI1UDpEwp3VC25YxwOhq7RUMSaSNolqlE8WESBF5az5xL4FQ5aXcynJ JDeo8No2mVUolSDCC+U7GkkTDJL95IwpFRHsH6NXuO5sGQgwBBlArnZrfILUx0zFN+pI 5Dgd6nMA8Nh2uZu2ld6s6wE7bQDOiJQXXIt8J/lV8JxiBglGgYk2eMgXZq8mjIUhxHkq ZTrrJsbwubU26ARp7LJI7DqDYWGBuwPQxplH1jPaiqydQLWjrFNI1IUGSfwIwVdj3kUr hvYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WKwWs0dQ3X7DmJxjPDLJAHB0GI2TCNM72PwGd1fv5II=; b=J71PN7Tt1Ivgn4TH+uf/Dt7XJxy7TPerz890ugUzLZjbec/VoTnBXD8u7ou2CbvFVS cm0ICofmanFXOAjcq2qH4FRsZZQEyPsx01Z+sChCIxbzEzFUoNyLru4UGQH3VxIC5eAN GVFESvFKGBuUDpIrUuvQFiY0/vEFD3HjyiCZZiMaxUyNWyzLoZUw7sgJRayUXmyeI0E7 RYCnRQEbuQjobdSecEswJSr5jmBes55wlW+eNvfeO1rJ0EL86EqODVxpagobSqmRUw1N AtBaeu8hUDAKydIxnmLGTFoIz443Vx+uVFx9JlE8BbXeHwQsIRekEEw7rabHtuE6nZCW H+oQ== X-Gm-Message-State: AIkVDXLbHQH0MkMvVr6L5tZTK4bX/5UzW5xg0gLcTDYTogzxNYVjXRKJQz7pNeWnzDHaGA== X-Received: by 10.99.168.10 with SMTP id o10mr6099468pgf.105.1484079191411; Tue, 10 Jan 2017 12:13:11 -0800 (PST) Received: from fainelli-desktop.broadcom.com ([192.19.255.250]) by smtp.gmail.com with ESMTPSA id e127sm7741037pfh.89.2017.01.10.12.13.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jan 2017 12:13:10 -0800 (PST) From: Florian Fainelli To: netdev@vger.kernel.org Subject: [PATCH net-next 2/8] net: dsa: Make most functions take a dsa_port argument Date: Tue, 10 Jan 2017 12:12:29 -0800 Message-Id: <20170110201235.21771-3-f.fainelli@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170110201235.21771-1-f.fainelli@gmail.com> References: <20170110201235.21771-1-f.fainelli@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170110_121332_392915_3FBA13A2 X-CRM114-Status: GOOD ( 17.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Lunn , Florian Fainelli , Ingo Tuchscherer , Jason Cooper , Vivien Didelot , Greg Kroah-Hartman , open list , Russell King , Stuart Yoder , Martin Schwidefsky , Gregory Clement , Philippe Reynes , "David S. Miller" , "moderated list:ARM/Marvell Dove/MV78xx0/Orion SOC support" , Sebastian Hesselbarth MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In preparation for allowing platform data, and therefore no valid device_node pointer, make most DSA functions takes a pointer to a dsa_port structure whenever possible. While at it, introduce a dsa_port_is_valid() helper function which checks whether port->dn is NULL or not at the moment. Signed-off-by: Florian Fainelli --- net/dsa/dsa.c | 15 ++++++++------ net/dsa/dsa2.c | 61 +++++++++++++++++++++++++++++------------------------- net/dsa/dsa_priv.h | 4 ++-- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index fd532487dfdf..2306d1b87c83 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -110,8 +110,9 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr, /* basic switch operations **************************************************/ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev, - struct device_node *port_dn, int port) + struct dsa_port *dport, int port) { + struct device_node *port_dn = dport->dn; struct phy_device *phydev; int ret, mode; @@ -141,15 +142,15 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev, static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct device *dev) { - struct device_node *port_dn; + struct dsa_port *dport; int ret, port; for (port = 0; port < DSA_MAX_PORTS; port++) { if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) continue; - port_dn = ds->ports[port].dn; - ret = dsa_cpu_dsa_setup(ds, dev, port_dn, port); + dport = &ds->ports[port]; + ret = dsa_cpu_dsa_setup(ds, dev, dport, port); if (ret) return ret; } @@ -366,8 +367,10 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index, return ds; } -void dsa_cpu_dsa_destroy(struct device_node *port_dn) +void dsa_cpu_dsa_destroy(struct dsa_port *port) { + struct device_node *port_dn = port->dn; + if (of_phy_is_fixed_link(port_dn)) of_phy_deregister_fixed_link(port_dn); } @@ -393,7 +396,7 @@ static void dsa_switch_destroy(struct dsa_switch *ds) for (port = 0; port < DSA_MAX_PORTS; port++) { if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) continue; - dsa_cpu_dsa_destroy(ds->ports[port].dn); + dsa_cpu_dsa_destroy(&ds->ports[port]); /* Clearing a bit which is not set does no harm */ ds->cpu_port_mask |= ~(1 << port); diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index f0e3212ae9d5..91141ac6ec18 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -79,11 +79,16 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst, kref_put(&dst->refcount, dsa_free_dst); } -static bool dsa_port_is_dsa(struct device_node *port) +static bool dsa_port_is_valid(struct dsa_port *port) +{ + return !!port->dn; +} + +static bool dsa_port_is_dsa(struct dsa_port *port) { const char *name; - name = of_get_property(port, "label", NULL); + name = of_get_property(port->dn, "label", NULL); if (!name) return false; @@ -93,11 +98,11 @@ static bool dsa_port_is_dsa(struct device_node *port) return false; } -static bool dsa_port_is_cpu(struct device_node *port) +static bool dsa_port_is_cpu(struct dsa_port *port) { const char *name; - name = of_get_property(port, "label", NULL); + name = of_get_property(port->dn, "label", NULL); if (!name) return false; @@ -138,7 +143,7 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst, static int dsa_port_complete(struct dsa_switch_tree *dst, struct dsa_switch *src_ds, - struct device_node *port, + struct dsa_port *port, u32 src_port) { struct device_node *link; @@ -146,7 +151,7 @@ static int dsa_port_complete(struct dsa_switch_tree *dst, struct dsa_switch *dst_ds; for (index = 0;; index++) { - link = of_parse_phandle(port, "link", index); + link = of_parse_phandle(port->dn, "link", index); if (!link) break; @@ -169,13 +174,13 @@ static int dsa_port_complete(struct dsa_switch_tree *dst, */ static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds) { - struct device_node *port; + struct dsa_port *port; u32 index; int err; for (index = 0; index < DSA_MAX_PORTS; index++) { - port = ds->ports[index].dn; - if (!port) + port = &ds->ports[index]; + if (!dsa_port_is_valid(port)) continue; if (!dsa_port_is_dsa(port)) @@ -215,7 +220,7 @@ static int dsa_dst_complete(struct dsa_switch_tree *dst) return 0; } -static int dsa_dsa_port_apply(struct device_node *port, u32 index, +static int dsa_dsa_port_apply(struct dsa_port *port, u32 index, struct dsa_switch *ds) { int err; @@ -230,13 +235,13 @@ static int dsa_dsa_port_apply(struct device_node *port, u32 index, return 0; } -static void dsa_dsa_port_unapply(struct device_node *port, u32 index, +static void dsa_dsa_port_unapply(struct dsa_port *port, u32 index, struct dsa_switch *ds) { dsa_cpu_dsa_destroy(port); } -static int dsa_cpu_port_apply(struct device_node *port, u32 index, +static int dsa_cpu_port_apply(struct dsa_port *port, u32 index, struct dsa_switch *ds) { int err; @@ -253,7 +258,7 @@ static int dsa_cpu_port_apply(struct device_node *port, u32 index, return 0; } -static void dsa_cpu_port_unapply(struct device_node *port, u32 index, +static void dsa_cpu_port_unapply(struct dsa_port *port, u32 index, struct dsa_switch *ds) { dsa_cpu_dsa_destroy(port); @@ -261,13 +266,13 @@ static void dsa_cpu_port_unapply(struct device_node *port, u32 index, } -static int dsa_user_port_apply(struct device_node *port, u32 index, +static int dsa_user_port_apply(struct dsa_port *port, u32 index, struct dsa_switch *ds) { const char *name; int err; - name = of_get_property(port, "label", NULL); + name = of_get_property(port->dn, "label", NULL); err = dsa_slave_create(ds, ds->dev, index, name); if (err) { @@ -279,7 +284,7 @@ static int dsa_user_port_apply(struct device_node *port, u32 index, return 0; } -static void dsa_user_port_unapply(struct device_node *port, u32 index, +static void dsa_user_port_unapply(struct dsa_port *port, u32 index, struct dsa_switch *ds) { if (ds->ports[index].netdev) { @@ -291,7 +296,7 @@ static void dsa_user_port_unapply(struct device_node *port, u32 index, static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) { - struct device_node *port; + struct dsa_port *port; u32 index; int err; @@ -325,8 +330,8 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) } for (index = 0; index < DSA_MAX_PORTS; index++) { - port = ds->ports[index].dn; - if (!port) + port = &ds->ports[index]; + if (!dsa_port_is_valid(port)) continue; if (dsa_port_is_dsa(port)) { @@ -353,12 +358,12 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds) { - struct device_node *port; + struct dsa_port *port; u32 index; for (index = 0; index < DSA_MAX_PORTS; index++) { - port = ds->ports[index].dn; - if (!port) + port = &ds->ports[index]; + if (!dsa_port_is_valid(port)) continue; if (dsa_port_is_dsa(port)) { @@ -439,7 +444,7 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst) dst->applied = false; } -static int dsa_cpu_parse(struct device_node *port, u32 index, +static int dsa_cpu_parse(struct dsa_port *port, u32 index, struct dsa_switch_tree *dst, struct dsa_switch *ds) { @@ -447,7 +452,7 @@ static int dsa_cpu_parse(struct device_node *port, u32 index, struct net_device *ethernet_dev; struct device_node *ethernet; - ethernet = of_parse_phandle(port, "ethernet", 0); + ethernet = of_parse_phandle(port->dn, "ethernet", 0); if (!ethernet) return -EINVAL; @@ -480,13 +485,13 @@ static int dsa_cpu_parse(struct device_node *port, u32 index, static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds) { - struct device_node *port; + struct dsa_port *port; u32 index; int err; for (index = 0; index < DSA_MAX_PORTS; index++) { - port = ds->ports[index].dn; - if (!port) + port = &ds->ports[index]; + if (!dsa_port_is_valid(port)) continue; if (dsa_port_is_cpu(port)) { @@ -547,7 +552,7 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds) * to have access to a correct value, just like what * net/dsa/dsa.c::dsa_switch_setup_one does. */ - if (!dsa_port_is_cpu(port)) + if (!dsa_port_is_cpu(&ds->ports[reg])) ds->enabled_port_mask |= 1 << reg; } diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 7e3385ec73f4..a015ec97c289 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -50,8 +50,8 @@ struct dsa_slave_priv { /* dsa.c */ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev, - struct device_node *port_dn, int port); -void dsa_cpu_dsa_destroy(struct device_node *port_dn); + struct dsa_port *dport, int port); +void dsa_cpu_dsa_destroy(struct dsa_port *dport); const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol); int dsa_cpu_port_ethtool_setup(struct dsa_switch *ds); void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds);