From patchwork Tue Oct 6 14:40:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 526793 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 7EBF3140D6C for ; Wed, 7 Oct 2015 01:41:47 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753085AbbJFOla (ORCPT ); Tue, 6 Oct 2015 10:41:30 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:35043 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751979AbbJFOke (ORCPT ); Tue, 6 Oct 2015 10:40:34 -0400 Received: by wicge5 with SMTP id ge5so170199992wic.0 for ; Tue, 06 Oct 2015 07:40:33 -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:organization:message-id:date :user-agent:mime-version:content-type:content-transfer-encoding; bh=cts+h+L6gBRrTdZ4e4/u5xh9wjgtTaw0V2OgZDmemZQ=; b=BYEm0YRrUl+uX+dotj/ROmgQHi794tluliMTckj4Dq+urHx5KidqxV6AuizZXYyjgv 500Iv3jNr7Sg8w40miSuoW8Rr/lsCwEJffpZl0yDfgCN93aUOT6M51yUlL91JPGYXu27 2GhzJbVSYNoHLyDF3VgmH82MupmZIEdzzVVuOwYKB89HJl1C1vb2Iog9nEEExvT3X+VZ lX188QVS2f55v8ODNjYwcDFXYa5G2hHUaIrOWPlJki5kQ9hh+VKAkzfGqAiQ5PDYstPV 1CU5hdmP7PBxIkPHdcUEHx6umQXIvhqFb/EXs+CTslz80iWg1YeAAaDK9Fr0rLrVPesu 8Rfw== X-Gm-Message-State: ALoCoQkxGg6V4XnMS4hPU6boSxSVrVT0bdqk5lYfOd9iG3gQZA6oawww+dxCyaK4HWiAojdukY77 X-Received: by 10.194.116.73 with SMTP id ju9mr28363705wjb.108.1444142433675; Tue, 06 Oct 2015 07:40:33 -0700 (PDT) Received: from [10.200.207.21] ([89.101.192.72]) by smtp.gmail.com with ESMTPSA id h7sm32966141wjz.7.2015.10.06.07.40.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Oct 2015 07:40:33 -0700 (PDT) From: Neil Armstrong To: "David S. Miller" , Florian Fainelli , Guenter Roeck , vivien.didelot@savoirfairelinux.com, Andrew Lunn , Fabian Frederick , Pavel Nakonechny , Joe Perches , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, nbd@openwrt.org, sergei.shtylyov@cogentembedded.com Subject: [PATCH v3 3/5] net: dsa: complete dsa_switch_destroy X-Enigmail-Draft-Status: N1110 Organization: Baylibre Message-ID: <5613DD60.3010900@baylibre.com> Date: Tue, 6 Oct 2015 15:40:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When unbinding dsa, complete the dsa_switch_destroy to unregister the fixed link phy then cleanly unregister and destroy the net devices. Reviewed-by: Florian Fainelli Signed-off-by: Neil Armstrong --- net/dsa/dsa.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 14fac4e..6155923 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "dsa_priv.h" char dsa_driver_version[] = "0.1"; @@ -420,10 +421,46 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index, static void dsa_switch_destroy(struct dsa_switch *ds) { + struct device_node *port_dn; + struct phy_device *phydev; + struct dsa_chip_data *cd = ds->pd; + int port; + #ifdef CONFIG_NET_DSA_HWMON if (ds->hwmon_dev) hwmon_device_unregister(ds->hwmon_dev); #endif + + /* Disable configuration of the CPU and DSA ports */ + for (port = 0; port < DSA_MAX_PORTS; port++) { + if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) + continue; + + port_dn = cd->port_dn[port]; + if (of_phy_is_fixed_link(port_dn)) { + phydev = of_phy_find_device(port_dn); + if (phydev) { + int addr = phydev->addr; + + phy_device_free(phydev); + of_node_put(port_dn); + fixed_phy_del(addr); + } + } + } + + /* Destroy network devices for physical switch ports. */ + for (port = 0; port < DSA_MAX_PORTS; port++) { + if (!(ds->phys_port_mask & (1 << port))) + continue; + + if (!ds->ports[port]) + continue; + + unregister_netdev(ds->ports[port]); + free_netdev(ds->ports[port]); + } + mdiobus_unregister(ds->slave_mii_bus); mdiobus_free(ds->slave_mii_bus); }