From patchwork Sat Apr 4 21:46:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Nakonechny X-Patchwork-Id: 458182 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 B26B01400A0 for ; Sun, 5 Apr 2015 07:46:53 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=skitlab.ru header.i=@skitlab.ru header.b=SRR51Mut; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752555AbbDDVq0 (ORCPT ); Sat, 4 Apr 2015 17:46:26 -0400 Received: from mail.skitlab.ru ([188.235.132.142]:58671 "EHLO mail.skitlab.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752353AbbDDVqZ (ORCPT ); Sat, 4 Apr 2015 17:46:25 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.skitlab.ru (Postfix) with ESMTP id CEB671060157; Sun, 5 Apr 2015 00:46:22 +0300 (MSK) Received: from mail.skitlab.ru ([127.0.0.1]) by localhost (zimbra.skitlab.int [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id cD6NMLWjKlGa; Sun, 5 Apr 2015 00:46:21 +0300 (MSK) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.skitlab.ru (Postfix) with ESMTP id B3CF61060185; Sun, 5 Apr 2015 00:46:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.9.2 mail.skitlab.ru B3CF61060185 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skitlab.ru; s=FB1EF416-3420-11E4-8645-170FD551C7D0; t=1428183981; bh=MbZ+fKlGLasAH/ta+y1zcH2/SNUFDA+jaindJYajYhU=; h=From:To:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:Content-Type; b=SRR51MutmiyowmYiW6NnnYMrxN1c/bYh4isrLiF8nIkIbgJ8+e0nqz2nehjwthL0w kOOaQ4epr3obvkwypJxIXRxlPLpBMg3aXbdD71XrCwBRvxouda0S2Gc8K2fdvgJnuH qaz8YPveEpIrLeWJ9ucM9B92xWC1sUyCOIxtqsQU= X-Virus-Scanned: amavisd-new at skitlab.ru Received: from mail.skitlab.ru ([127.0.0.1]) by localhost (zimbra.skitlab.int [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id XFET_P1GFhNb; Sun, 5 Apr 2015 00:46:21 +0300 (MSK) Received: from kuro.zhome (unknown [188.232.58.218]) by mail.skitlab.ru (Postfix) with ESMTPSA id 8727E1060157; Sun, 5 Apr 2015 00:46:21 +0300 (MSK) From: Pavel Nakonechny To: netdev@vger.kernel.org, Joe Perches Cc: "David S. Miller" , Grant Likely , Rob Herring , Florian Fainelli , Fabian Frederick , linux-kernel@vger.kernel.org Subject: [PATCH v2] net: dsa: fix filling routing table from OF description Date: Sun, 05 Apr 2015 00:46:21 +0300 Message-ID: <1516684.D2TdrA1BPT@kuro.zhome> Organization: SKTB SKiT User-Agent: KMail/4.14.6 (Linux/3.19.2-un-def-alt1; KDE/4.14.6; x86_64; ; ) MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org According to description in 'include/net/dsa.h', in cascade switches configurations where there are more than one interconnected devices, 'rtable' array in 'dsa_chip_data' structure is used to indicate which port on this switch should be used to send packets to that are destined for corresponding switch. However, dsa_of_setup_routing_table() fills 'rtable' with port numbers of the _target_ switch, but not current one. This commit removes redundant devicetree parsing and adds needed port number as a function argument. So dsa_of_setup_routing_table() now just looks for target switch number by parsing parent of 'link' device node. To remove possible misunderstandings with the way of determining target switch number, a corresponding comment was added to the source code and to the DSA device tree bindings documentation file. This was tested on a custom board with two Marvell 88E6095 switches with following corresponding routing tables: { -1, 10 } and { 8, -1 }. Signed-off-by: Pavel Nakonechny Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli --- Documentation/devicetree/bindings/net/dsa/dsa.txt | 4 +++- net/dsa/dsa.c | 23 +++++++---------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/Documentation/devicetree/bindings/net/dsa/dsa.txt b/Documentation/devicetree/bindings/net/dsa/dsa.txt index a62c889..e25e58d 100644 --- a/Documentation/devicetree/bindings/net/dsa/dsa.txt +++ b/Documentation/devicetree/bindings/net/dsa/dsa.txt @@ -19,7 +19,9 @@ the parent DSA node. The maximum number of allowed child nodes is 4 (DSA_MAX_SWITCHES). Each of these switch child nodes should have the following required properties: -- reg : Describes the switch address on the MII bus +- reg : Contains two fields. The first one describes the + address on the MII bus. The second is the switch + number that must be unique in cascaded configurations - #address-cells : Must be 1 - #size-cells : Must be 0 diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 947f550..1d56f84 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -375,12 +375,10 @@ static struct net_device *dev_to_net_device(struct device *dev) #ifdef CONFIG_OF static int dsa_of_setup_routing_table(struct dsa_platform_data *pd, struct dsa_chip_data *cd, - int chip_index, + int chip_index, int port_index, struct device_node *link) { - int ret; const __be32 *reg; - int link_port_addr; int link_sw_addr; struct device_node *parent_sw; int len; @@ -393,6 +391,10 @@ static int dsa_of_setup_routing_table(struct dsa_platform_data *pd, if (!reg || (len != sizeof(*reg) * 2)) return -EINVAL; + /* + * Get the destination switch number from the second field of its 'reg' + * property, i.e. for "reg = <0x19 1>" sw_addr is '1'. + */ link_sw_addr = be32_to_cpup(reg + 1); if (link_sw_addr >= pd->nr_chips) @@ -409,20 +411,9 @@ static int dsa_of_setup_routing_table(struct dsa_platform_data *pd, memset(cd->rtable, -1, pd->nr_chips * sizeof(s8)); } - reg = of_get_property(link, "reg", NULL); - if (!reg) { - ret = -EINVAL; - goto out; - } - - link_port_addr = be32_to_cpup(reg); - - cd->rtable[link_sw_addr] = link_port_addr; + cd->rtable[link_sw_addr] = port_index; return 0; -out: - kfree(cd->rtable); - return ret; } static void dsa_of_free_platform_data(struct dsa_platform_data *pd) @@ -528,7 +519,7 @@ static int dsa_of_probe(struct platform_device *pdev) if (!strcmp(port_name, "dsa") && link && pd->nr_chips > 1) { ret = dsa_of_setup_routing_table(pd, cd, - chip_index, link); + chip_index, port_index, link); if (ret) goto out_free_chip; }