Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4748357ybg; Mon, 21 Oct 2019 13:54:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0lGc8J+34pjX816vW+gi5Bo0ESkWeHIlS9Fbr2+9L8MpLxl28H4ezEjRLdxc8dXJF8ZvS X-Received: by 2002:a50:ee92:: with SMTP id f18mr27973045edr.56.1571691272862; Mon, 21 Oct 2019 13:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571691272; cv=none; d=google.com; s=arc-20160816; b=jye+hHbuCf3X7HQMcm+ZfGSOUo67bVEgzV9e+MCVtmKRZFkUlk30+DTVwBhK8W2uZm Z4FrC0lvCMYC0xy6pmAQPUDfv+/sGqmoi2lAr0ERqKzAqSRq96Nv1lf/U7MCCYC6Xypk KZMovNEodXxF+wwctnSAo81b3vxp2PcerEGpjs+/5uV6p4IqJNg9PZN40H4VCOXKoPiv arS519f3/IVajzZTVGIlNPNPN3tfAs1YEpK9ldOPwhEFDML7gnQYsBw/Hltjbew04UWR VkA2x/eo0v424UZMRi8upIQYtQKzhhPYAgYCAJKODKoFn/wMEoDXM/6ZUsOi71qk+n+s xXGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jqgsFlrNKqExdggLkADsTZXOcKKODUTxvxGTYxobfK0=; b=hTCwVAHSTw+beMsGIE2w8TchTWFre/X2agRsz57Hce7r4OhB9P71sZiTYvefwC7eex PsouSq7/1Vg/azvywuZeaHpo8qckvfrldt6vgXjrNif6LBjrVhhtwFIFX3OyQyng2V8U cu3HSFKQEkwYQTH2sGdmjEIaecQullkVjiVkL6lyyR3j/1aCX5jJ8FAaHFWZdHtSfSnW iSyy1yqzu+53tS+8AK1EPHLx5AzoohKEyQhd0HoIME3HNFqavDry6XDrcQonuvlXdWik Td37sRW4MlaQDFetnHIfg9NwFmKW6Qa99oHnES/QPV3BJTGsw1FnOuFlOg4XmjOMhvcg ee7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ufFCTskx; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si9512525ejo.82.2019.10.21.13.54.09; Mon, 21 Oct 2019 13:54:32 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ufFCTskx; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730650AbfJUUxA (ORCPT + 99 others); Mon, 21 Oct 2019 16:53:00 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:40133 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730383AbfJUUvk (ORCPT ); Mon, 21 Oct 2019 16:51:40 -0400 Received: by mail-qk1-f193.google.com with SMTP id y81so10251799qkb.7; Mon, 21 Oct 2019 13:51:39 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=jqgsFlrNKqExdggLkADsTZXOcKKODUTxvxGTYxobfK0=; b=ufFCTskxImKTtNSFmXwBTnh8Wvwq4S5v0UHWaJec1kYgteEBH+FqJRa6gvrvcam4Jc wZcnfe6B9JuOUe/FfhpNlNzPyIQr9FHlGSz6aHUEavlx82hWPaF2DIN8vw3BNWhla+fY seP1Ofija8Y5FaK2akJ2LYA+ks1IxHMCX6AUFg7vIPBJ7qVohdznFd0wxJtMF5qrgmBr 8r2vIAyZO5vR2sEyFGy3YHaAJlgBJ5G1q7tx7VYQRdZgEFKE9jq2xa6X5to0/+V6CgjJ NTxsYmAHOvzQpmPfF9b5D8VQjx2ViZsEXlTjJtsJQc+dgtsJQKDfJiBVyJSrStDrcBjg T1gQ== 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:mime-version:content-transfer-encoding; bh=jqgsFlrNKqExdggLkADsTZXOcKKODUTxvxGTYxobfK0=; b=KjSb4+OLyZxgRldxmeHgBzGCLsnCmIT9eol0X6jr6U2j3EGvzcWg65Gw62ERenptV+ xjE5YCorVbGaRcNgyBwnYiyzPY7bC3jmBe2Sjw4xtpn1E166FsyckKKIf6i+4JkW/hn2 Zf9rUBajJ4+0bF1oqimuVvW9IDiqAsGBUbWLieIriqH8DbUoXw/LlUCJMh3Qdz3brGwr jnM/7t6hCiwZ+twB/bgnWJLD/DHi0boIhA5/ekh2AgVWAfl1LipjFB0ppmTOUVmVxeJY 6sRcSFdrGFQZcVCZUN/fd4H1KCUnRzkf3vBCsbmbnoCalHdrfFcaCcOC/ZVZzn4MiX97 NH/w== X-Gm-Message-State: APjAAAU5fXAuJKZI2wlPAE6xesBRPs9q6REXCYeubxkdIWBYdHHAEbp1 +5DLDe1Hxu+1LNsbqgxP0i0= X-Received: by 2002:a37:67d4:: with SMTP id b203mr24898207qkc.435.1571691098636; Mon, 21 Oct 2019 13:51:38 -0700 (PDT) Received: from localhost (modemcable249.105-163-184.mc.videotron.ca. [184.163.105.249]) by smtp.gmail.com with ESMTPSA id l129sm9831589qkd.84.2019.10.21.13.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 13:51:38 -0700 (PDT) From: Vivien Didelot To: "David S. Miller" Cc: linux-kernel@vger.kernel.org, Vivien Didelot , Florian Fainelli , Andrew Lunn , netdev@vger.kernel.org Subject: [PATCH net-next v2 02/16] net: dsa: add ports list in the switch fabric Date: Mon, 21 Oct 2019 16:51:16 -0400 Message-Id: <20191021205130.304149-3-vivien.didelot@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191021205130.304149-1-vivien.didelot@gmail.com> References: <20191021205130.304149-1-vivien.didelot@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a list of switch ports within the switch fabric. This will help the lookup of a port inside the whole fabric, and it is the first step towards supporting multiple CPU ports, before deprecating the usage of the unique dst->cpu_dp pointer. In preparation for a future allocation of the dsa_port structures, return -ENOMEM in case no structure is returned, even though this error cannot be reached yet. Signed-off-by: Vivien Didelot Reviewed-by: Florian Fainelli Reviewed-by: Andrew Lunn --- include/net/dsa.h | 5 +++++ net/dsa/dsa2.c | 48 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 2e4fe2f8962b..6ff6dfcdc61d 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -125,6 +125,9 @@ struct dsa_switch_tree { */ struct dsa_port *cpu_dp; + /* List of switch ports */ + struct list_head ports; + /* * Data for the individual switch chips. */ @@ -195,6 +198,8 @@ struct dsa_port { struct work_struct xmit_work; struct sk_buff_head xmit_queue; + struct list_head list; + /* * Give the switch driver somewhere to hang its per-port private data * structures (accessible from the tagger). diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 1716535167ee..ba27ff8b4445 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -45,6 +45,8 @@ static struct dsa_switch_tree *dsa_tree_alloc(int index) dst->index = index; + INIT_LIST_HEAD(&dst->ports); + INIT_LIST_HEAD(&dst->list); list_add_tail(&dst->list, &dsa_tree_list); @@ -616,6 +618,22 @@ static int dsa_tree_add_switch(struct dsa_switch_tree *dst, return err; } +static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index) +{ + struct dsa_switch_tree *dst = ds->dst; + struct dsa_port *dp; + + dp = &ds->ports[index]; + + dp->ds = ds; + dp->index = index; + + INIT_LIST_HEAD(&dp->list); + list_add_tail(&dp->list, &dst->ports); + + return dp; +} + static int dsa_port_parse_user(struct dsa_port *dp, const char *name) { if (!name) @@ -742,6 +760,20 @@ static int dsa_switch_parse_member_of(struct dsa_switch *ds, return 0; } +static int dsa_switch_touch_ports(struct dsa_switch *ds) +{ + struct dsa_port *dp; + int port; + + for (port = 0; port < ds->num_ports; port++) { + dp = dsa_port_touch(ds, port); + if (!dp) + return -ENOMEM; + } + + return 0; +} + static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn) { int err; @@ -750,6 +782,10 @@ static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn) if (err) return err; + err = dsa_switch_touch_ports(ds); + if (err) + return err; + return dsa_switch_parse_ports_of(ds, dn); } @@ -807,6 +843,8 @@ static int dsa_switch_parse_ports(struct dsa_switch *ds, static int dsa_switch_parse(struct dsa_switch *ds, struct dsa_chip_data *cd) { + int err; + ds->cd = cd; /* We don't support interconnected switches nor multiple trees via @@ -817,6 +855,10 @@ static int dsa_switch_parse(struct dsa_switch *ds, struct dsa_chip_data *cd) if (!ds->dst) return -ENOMEM; + err = dsa_switch_touch_ports(ds); + if (err) + return err; + return dsa_switch_parse_ports(ds, cd); } @@ -849,7 +891,6 @@ static int dsa_switch_probe(struct dsa_switch *ds) struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n) { struct dsa_switch *ds; - int i; ds = devm_kzalloc(dev, struct_size(ds, ports, n), GFP_KERNEL); if (!ds) @@ -858,11 +899,6 @@ struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n) ds->dev = dev; ds->num_ports = n; - for (i = 0; i < ds->num_ports; ++i) { - ds->ports[i].index = i; - ds->ports[i].ds = ds; - } - return ds; } EXPORT_SYMBOL_GPL(dsa_switch_alloc); -- 2.23.0