Received: by 10.223.164.221 with SMTP id h29csp355190wrb; Fri, 3 Nov 2017 16:07:41 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QfbhicfO0m8d/1Ux01tL7ySQ9HCarV2RmhorzFprTZGWCIC2y7+R71Cta065jweP+K8B89 X-Received: by 10.99.168.13 with SMTP id o13mr8552647pgf.435.1509750461341; Fri, 03 Nov 2017 16:07:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509750461; cv=none; d=google.com; s=arc-20160816; b=mBOFs7NzaVxG4xIhgyTFJb2Ci9G9yzIJMkp/Tw4kc7pgQKhuu0E3AqeXR62rt5NW45 jLB+B9bjpaM1qXdw0lW4f74WjRoOTl5dwjl3eOUd5n6vnnTQZCSpC/Xl9v/TpRVoHgMa aqIRekd7ZqM9Zd/tG4Hr4FXmUufR6YaU7Y1EjCXx9IScoEEhmZGtpKs4txM7MOEt+hIj KZyu7xyLfSJBzWUOJ+3Ly7/ODFoc+1IZnMTerv0GA9w/v5QmzAdd3SNTms1gWznpy/Ue 8I2Iemwp4NlRfncIOq8UY6WE1oh5HeHVLTwEkDJT1+JkTkn+S7TrpryuyLhoBe6237a1 GvYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Ql9ZKnQo+u26Y5HF3rEt43y3eB1ds/kAszRnMn/krNo=; b=Jxne2aJUVA360Hn6MxcoX+bhNNU782AAjBQcUp85/VaVgVtC+3avcG23+rkznKbunD sOzNQFN2FBA0/SBo6JI5jDv7ahdg+2j3Q5VmI7uL9xKYEyQFqlENOckdwr+ccbBdzzer f5xy1sTcOUPHbGvh2fbCX4SGwBQOUKBDsvsquBYx4UOXsoIcksuWIVu83Q5MFVBXrh7C ko+y671+6DPr6oP5gZGnV1pBcdEKnltyVLSHl5/VYzpgtXvDEs1Rh3jqP2m1arPnqanF xkPNf8d9mFmGLHIQdjSw5tITNsnDDHjxDfqCX3JxFqQ7shESNoG+WeFRJDbZ6o131iTL Ba5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f13si7115577pgn.698.2017.11.03.16.07.28; Fri, 03 Nov 2017 16:07:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756530AbdKCXG0 (ORCPT + 92 others); Fri, 3 Nov 2017 19:06:26 -0400 Received: from mail.savoirfairelinux.com ([208.88.110.44]:33428 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932411AbdKCXGD (ORCPT ); Fri, 3 Nov 2017 19:06:03 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 767199C2FCB; Fri, 3 Nov 2017 19:06:02 -0400 (EDT) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id znd_rXxAtiWg; Fri, 3 Nov 2017 19:05:54 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 2D9629C3029; Fri, 3 Nov 2017 19:05:47 -0400 (EDT) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id S6MmtjTcNJ-h; Fri, 3 Nov 2017 19:05:46 -0400 (EDT) Received: from weeman.mtl.sfl (unknown [192.168.49.192]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id CEBBD9C2FCB; Fri, 3 Nov 2017 19:05:46 -0400 (EDT) From: Vivien Didelot To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com, "David S. Miller" , Florian Fainelli , Andrew Lunn , Vivien Didelot Subject: [PATCH net-next 08/11] net: dsa: rework switch parsing Date: Fri, 3 Nov 2017 19:05:27 -0400 Message-Id: <20171103230530.996-9-vivien.didelot@savoirfairelinux.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171103230530.996-1-vivien.didelot@savoirfairelinux.com> References: <20171103230530.996-1-vivien.didelot@savoirfairelinux.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When parsing a switch, we have to identify to which tree it belongs and parse its ports. Provide two functions to separate the OF and platform data specific paths. Also use the of_property_read_variable_u32_array function to parse the OF member array instead of calling of_property_read_u32_index twice. Signed-off-by: Vivien Didelot --- net/dsa/dsa2.c | 117 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 5918fbddb0ab..dfcb6247f2f2 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -617,7 +617,8 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn) return 0; } -static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds) +static int dsa_switch_parse_ports_of(struct dsa_switch *ds, + struct device_node *dn) { struct device_node *ports, *port; struct dsa_port *dp; @@ -648,6 +649,39 @@ static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds) return 0; } +static int dsa_switch_parse_member_of(struct dsa_switch *ds, + struct device_node *dn) +{ + u32 m[2] = { 0, 0 }; + int sz; + + /* Don't error out if this optional property isn't found */ + sz = of_property_read_variable_u32_array(dn, "dsa,member", m, 2, 2); + if (sz < 0 && sz != -EINVAL) + return sz; + + ds->index = m[1]; + if (ds->index >= DSA_MAX_SWITCHES) + return -EINVAL; + + ds->dst = dsa_tree_touch(m[0]); + if (!ds->dst) + return -ENOMEM; + + return 0; +} + +static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn) +{ + int err; + + err = dsa_switch_parse_member_of(ds, dn); + if (err) + return err; + + return dsa_switch_parse_ports_of(ds, dn); +} + static int dsa_port_parse(struct dsa_port *dp, const char *name, struct device *dev) { @@ -673,7 +707,8 @@ static int dsa_port_parse(struct dsa_port *dp, const char *name, return 0; } -static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds) +static int dsa_switch_parse_ports(struct dsa_switch *ds, + struct dsa_chip_data *cd) { bool valid_name_found = false; struct dsa_port *dp; @@ -703,40 +738,19 @@ static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds) return 0; } -static int dsa_parse_member_dn(struct device_node *np, u32 *tree, u32 *index) +static int dsa_switch_parse(struct dsa_switch *ds, struct dsa_chip_data *cd) { - int err; + ds->cd = cd; - *tree = *index = 0; + /* We don't support interconnected switches nor multiple trees via + * platform data, so this is the unique switch of the tree. + */ + ds->index = 0; + ds->dst = dsa_tree_touch(0); + if (!ds->dst) + return -ENOMEM; - err = of_property_read_u32_index(np, "dsa,member", 0, tree); - if (err) { - /* Does not exist, but it is optional */ - if (err == -EINVAL) - return 0; - return err; - } - - err = of_property_read_u32_index(np, "dsa,member", 1, index); - if (err) - return err; - - if (*index >= DSA_MAX_SWITCHES) - return -EINVAL; - - return 0; -} - -static int dsa_parse_member(struct dsa_chip_data *pd, u32 *tree, u32 *index) -{ - if (!pd) - return -ENODEV; - - /* We do not support complex trees with dsa_chip_data */ - *tree = 0; - *index = 0; - - return 0; + return dsa_switch_parse_ports(ds, cd); } static int _dsa_register_switch(struct dsa_switch *ds) @@ -744,36 +758,21 @@ static int _dsa_register_switch(struct dsa_switch *ds) struct dsa_chip_data *pdata = ds->dev->platform_data; struct device_node *np = ds->dev->of_node; struct dsa_switch_tree *dst; - u32 tree, index; + unsigned int index; int i, err; - if (np) { - err = dsa_parse_member_dn(np, &tree, &index); - if (err) - return err; - } else { - err = dsa_parse_member(pdata, &tree, &index); - if (err) - return err; - } + if (np) + err = dsa_switch_parse_of(ds, np); + else if (pdata) + err = dsa_switch_parse(ds, pdata); + else + err = -ENODEV; - dst = dsa_tree_touch(tree); - if (!dst) - return -ENOMEM; + if (err) + return err; - ds->dst = dst; - ds->index = index; - ds->cd = pdata; - - if (np) { - err = dsa_parse_ports_of(np, ds); - if (err) - return err; - } else { - err = dsa_parse_ports(pdata, ds); - if (err) - return err; - } + index = ds->index; + dst = ds->dst; /* Initialize the routing table */ for (i = 0; i < DSA_MAX_SWITCHES; ++i) -- 2.14.3 From 1583483323942603263@xxx Wed Nov 08 07:49:36 +0000 2017 X-GM-THRID: 1583483323942603263 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread