Received: by 10.223.164.202 with SMTP id h10csp748666wrb; Mon, 6 Nov 2017 14:59:46 -0800 (PST) X-Google-Smtp-Source: ABhQp+TiudJLeU/K4m+lLiJB9bNRFrn9JqsmDbsbKuOouDDnXpmXVGXOMvvv/WpduioaeJun5vPV X-Received: by 10.84.176.163 with SMTP id v32mr16286628plb.175.1510009186748; Mon, 06 Nov 2017 14:59:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510009186; cv=none; d=google.com; s=arc-20160816; b=AT5+E9h+UftFRkg7ZcGDRHjOTJ+hOVTBikaPC3hRB735wKLqwiApkEIvGBHYMc+i5E qQZ1Pm8tIw2nVsJ64bKALYJ2Km2j9071+WqNC8UhsjmEZFnU0e74kk3tD7O55xywN4tG sXJhIHrekKoxt8U15HvN4qLpKtkk4AMRMVmsQ/ySxT1SSHqjV+LHizejM2t00BUE2tdu jj49ZOZqz+ZrU9V13yoqMFgaw+7PLONk2iifyn5Ribtv1h02w7vTinzDHM0w1GR0KMrA moDGQiep5jG6EfhUgIDtMibAa7MqlIU/ufdj7j9GEitFU24WnZKvJzlxqzrvrh1SzZC1 ZrBg== 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=DPZKzKAN1jxWsUl07SWPM7SGqLufL646FhGIY40XUKQ=; b=eCkfqIAs8eCXBDPzrtVkN2MUer1+oBw8nRhOSiXqv1M3m9PwJtD2y5fNU0qlSmkT02 u0pXFW9LGao26IYrnMdSngbC8m9THv8t3iqi7x+CKIclzAjlY9rgX5yjDX6IUiR3cgLp AUya19BsFknO/mIjVaQZhhpteLM9dm1jxQe8givrYjVuF+AG49Tu4uob0zUAYGwHIKMm 4Xn6JpX/eBtcsHvBilcXrE0UjIYNePrnJ4zzVNNVox7UZ4OHhIVcpadeWciMNm2hiEAI 3q7z4Q0s8js1mspNW5IPM1TCQkmrENXSzDAy7rtAsDXuek1SD5ocV2zR+4hu4L/5dI84 OnQQ== 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 i6si10305268plt.797.2017.11.06.14.59.33; Mon, 06 Nov 2017 14:59:46 -0800 (PST) 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 S1754116AbdKFVMt (ORCPT + 95 others); Mon, 6 Nov 2017 16:12:49 -0500 Received: from mail.savoirfairelinux.com ([208.88.110.44]:55210 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753784AbdKFVMT (ORCPT ); Mon, 6 Nov 2017 16:12:19 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 9E7009C1A57; Mon, 6 Nov 2017 16:12:18 -0500 (EST) 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 RiBDRDC2Mmcl; Mon, 6 Nov 2017 16:12:18 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 7FC659C2F5B; Mon, 6 Nov 2017 16:12:16 -0500 (EST) 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 FUsmlejQd5N6; Mon, 6 Nov 2017 16:12:16 -0500 (EST) Received: from weeman.mtl.sfl (unknown [192.168.49.104]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 387609C2F0C; Mon, 6 Nov 2017 16:12:16 -0500 (EST) 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 09/11] net: dsa: setup routing table Date: Mon, 6 Nov 2017 16:11:51 -0500 Message-Id: <20171106211153.26529-10-vivien.didelot@savoirfairelinux.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171106211153.26529-1-vivien.didelot@savoirfairelinux.com> References: <20171106211153.26529-1-vivien.didelot@savoirfairelinux.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The *_complete() functions take too much arguments to do only one thing: they try to fetch the dsa_port structures corresponding to device nodes under the "link" list property of DSA ports, and use them to setup the routing table of switches. This patch simplifies them by providing instead simpler dsa_{port,switch,tree}_setup_routing_table functions which return a boolean value, true if the tree is complete. dsa_tree_setup_routing_table is called inside dsa_tree_setup which simplifies the switch registering function as well. A switch's routing table is now initialized before its setup. This also makes dsa_port_is_valid obsolete, remove it. Signed-off-by: Vivien Didelot --- net/dsa/dsa2.c | 108 ++++++++++++++++++++------------------------------------- 1 file changed, 37 insertions(+), 71 deletions(-) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 25ed41262ead..44d26b5977cd 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -94,14 +94,6 @@ static void dsa_tree_put(struct dsa_switch_tree *dst) kref_put(&dst->refcount, dsa_tree_release); } -/* For platform data configurations, we need to have a valid name argument to - * differentiate a disabled port from an enabled one - */ -static bool dsa_port_is_valid(struct dsa_port *port) -{ - return port->type != DSA_PORT_TYPE_UNUSED; -} - static bool dsa_port_is_dsa(struct dsa_port *port) { return port->type == DSA_PORT_TYPE_DSA; @@ -140,14 +132,12 @@ static struct dsa_port *dsa_tree_find_port_by_node(struct dsa_switch_tree *dst, return NULL; } -static int dsa_port_complete(struct dsa_switch_tree *dst, - struct dsa_switch *src_ds, - struct dsa_port *port, - u32 src_port) +static bool dsa_port_setup_routing_table(struct dsa_port *dp) { - struct device_node *dn = port->dn; + struct dsa_switch *ds = dp->ds; + struct dsa_switch_tree *dst = ds->dst; + struct device_node *dn = dp->dn; struct of_phandle_iterator it; - struct dsa_switch *dst_ds; struct dsa_port *link_dp; int err; @@ -155,66 +145,54 @@ static int dsa_port_complete(struct dsa_switch_tree *dst, link_dp = dsa_tree_find_port_by_node(dst, it.node); if (!link_dp) { of_node_put(it.node); - return 1; + return false; } - dst_ds = link_dp->ds; - - src_ds->rtable[dst_ds->index] = src_port; + ds->rtable[link_dp->ds->index] = dp->index; } - return 0; + return true; } -/* A switch is complete if all the DSA ports phandles point to ports - * known in the tree. A return value of 1 means the tree is not - * complete. This is not an error condition. A value of 0 is - * success. - */ -static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds) +static bool dsa_switch_setup_routing_table(struct dsa_switch *ds) { - struct dsa_port *port; - u32 index; - int err; + bool complete = true; + struct dsa_port *dp; + int i; - for (index = 0; index < ds->num_ports; index++) { - port = &ds->ports[index]; - if (!dsa_port_is_valid(port)) - continue; + for (i = 0; i < DSA_MAX_SWITCHES; i++) + ds->rtable[i] = DSA_RTABLE_NONE; - if (!dsa_port_is_dsa(port)) - continue; + for (i = 0; i < ds->num_ports; i++) { + dp = &ds->ports[i]; - err = dsa_port_complete(dst, ds, port, index); - if (err != 0) - return err; + if (dsa_port_is_dsa(dp)) { + complete = dsa_port_setup_routing_table(dp); + if (!complete) + break; + } } - return 0; + return complete; } -/* A tree is complete if all the DSA ports phandles point to ports - * known in the tree. A return value of 1 means the tree is not - * complete. This is not an error condition. A value of 0 is - * success. - */ -static int dsa_dst_complete(struct dsa_switch_tree *dst) +static bool dsa_tree_setup_routing_table(struct dsa_switch_tree *dst) { struct dsa_switch *ds; - u32 index; - int err; + bool complete = true; + int device; - for (index = 0; index < DSA_MAX_SWITCHES; index++) { - ds = dst->ds[index]; + for (device = 0; device < DSA_MAX_SWITCHES; device++) { + ds = dst->ds[device]; if (!ds) continue; - err = dsa_ds_complete(dst, ds); - if (err != 0) - return err; + complete = dsa_switch_setup_routing_table(ds); + if (!complete) + break; } - return 0; + return complete; } static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst) @@ -460,6 +438,7 @@ static void dsa_tree_teardown_master(struct dsa_switch_tree *dst) static int dsa_tree_setup(struct dsa_switch_tree *dst) { + bool complete; int err; if (dst->setup) { @@ -468,6 +447,10 @@ static int dsa_tree_setup(struct dsa_switch_tree *dst) return -EEXIST; } + complete = dsa_tree_setup_routing_table(dst); + if (!complete) + return 0; + err = dsa_tree_setup_default_cpu(dst); if (err) return err; @@ -727,7 +710,7 @@ static int _dsa_register_switch(struct dsa_switch *ds) struct device_node *np = ds->dev->of_node; struct dsa_switch_tree *dst; unsigned int index; - int i, err; + int err; if (np) err = dsa_switch_parse_of(ds, np); @@ -742,33 +725,16 @@ static int _dsa_register_switch(struct dsa_switch *ds) index = ds->index; dst = ds->dst; - /* Initialize the routing table */ - for (i = 0; i < DSA_MAX_SWITCHES; ++i) - ds->rtable[i] = DSA_RTABLE_NONE; - err = dsa_tree_add_switch(dst, ds); if (err) return err; - err = dsa_dst_complete(dst); - if (err < 0) - goto out_del_dst; - - /* Not all switches registered yet */ - if (err == 1) - return 0; - err = dsa_tree_setup(dst); if (err) { dsa_tree_teardown(dst); - goto out_del_dst; + dsa_tree_remove_switch(dst, index); } - return 0; - -out_del_dst: - dsa_tree_remove_switch(dst, index); - return err; } -- 2.14.3 From 1585515557881105724@xxx Thu Nov 30 18:11:05 +0000 2017 X-GM-THRID: 1582813368435034245 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread