From patchwork Wed Jun 17 08:31:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 188127 Delivered-To: patch@linaro.org Received: by 2002:a92:cf06:0:0:0:0:0 with SMTP id c6csp249806ilo; Wed, 17 Jun 2020 01:31:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZIqBRB1E4q4wxEq4OAONPAO1hDrz47/BU1gD8gnpWD6C0wsX0mqs2/9rhFYqvzyd8IMfy X-Received: by 2002:aa7:c356:: with SMTP id j22mr5915940edr.59.1592382712634; Wed, 17 Jun 2020 01:31:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592382712; cv=none; d=google.com; s=arc-20160816; b=v1LX0tI3rSJXA3IfOvhEQ66Yy4GzCnCtaYUJLHUFsDBwJWBb/29btmi9zj5rxwZGnr 335QxE9DPNDwq6ubL0ktLOeEIzMMmX/4nTotC6M0U07CNr+bQdaOYL8Gx8wAJjzPLSJ/ Pk+XZ7OPrwAKaDLptMZn2z9lKOToPtdbVzhAp3Mh7Qnz2BnPSjbZMA7MMRjNTSWCyvHg HXD2yljWWseSWVkmwSGxdp5mj9bmJncCcH4gJNHkdrbfffvsh1l3HvFHnViLCwskOn7k eFShzEIp6709nkEjM4SetC5CTpmCk88JJ4hleqEss+RcMkn3OtTmol+FnaphpSgz5g/4 x2mg== 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=c84FGVGvT0JUW6tVjnpdu63A5uo5FuKqONIDulr/ne0=; b=OP18U6pOHHZpbWe0sJhAFT60FGkz/87WG5b2ezVqOuAd5O5RVjr2M6HcyecZ8NadjM W9LFxkV46tUUwuF7dFteWdIdDtTk7tyHAwmD58CZL/98JxSLN+UNRQdOyEFXBxx9S4le YRmoLaA4KDS0b2I1vi/Jm4N+L8eX+OsgqLG2NFTt6h9s3YTBRLVmN3wdSQqSg1o5KmSQ J7KUgigguwlalCo2ZowdxmV+HYETIVYcG4ISSigzyRjmx3YUcIgPcTeRAog+WKisGq40 bGk9W5vnAdbRa+ApT4PUkXQYiydV0mxDQmbN4QN/I5Yxe9h7zVz02wHtSCcWneJ4gjBQ I0ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CRzdwEPv; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q22si12900014eji.446.2020.06.17.01.31.52; Wed, 17 Jun 2020 01:31:52 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CRzdwEPv; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726698AbgFQIbu (ORCPT + 9 others); Wed, 17 Jun 2020 04:31:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726491AbgFQIbt (ORCPT ); Wed, 17 Jun 2020 04:31:49 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80FEDC061573 for ; Wed, 17 Jun 2020 01:31:48 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id 9so1803250ljc.8 for ; Wed, 17 Jun 2020 01:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=c84FGVGvT0JUW6tVjnpdu63A5uo5FuKqONIDulr/ne0=; b=CRzdwEPvBkMKw0lHArpMOP7GwPMbN+yup9QItXTfJ6o/nCzcSUJqvzNyi1id76eqPJ 4DUV5gOvVyU0jKJFrklOcPq0ZJd1+4ZaR7eKwOeG3urgzKcdUH3hkaijHxitEAOWrLp4 wzcVNUiwME90+s21PG4Fn6ss8ow0Pj8LBZ8nU4ZpVDDsKvZ+EtJ46ELig5YTXAOEhFi4 YaqQRPAi+2uDd54ulE/pFiNcBCnmYRMR7slWbJCAa6FKC171s3pzF5JW/PFcF1hcuDsX ptMXjrh+3K3yl9BHW7BJ7Qd0khbxyS8u3Mlx4CmEPe5LQZBiqVLsHHeuV00qy4MSFU1q mYpA== 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=c84FGVGvT0JUW6tVjnpdu63A5uo5FuKqONIDulr/ne0=; b=VrYoGDXn8+/2OaOjHtFCmXLzac9bNIjRGIFTv6SS8s70fC4j//jG0rNc5Pap7JYJI6 zwMd//WfHiY+YpdBBzEDq+NflhQLVApcWfLZiYENfZDtnen/bTekFwWWv3Ds8auWBK9O 7nrC+sGEgLLjFXzYVLslciIX4hjDDV06H6TgnUDGPJmyOaEL0xH6FayFTUwb3xvAebb1 c4uVlu1TZZcm05yo86CPvmzlgXkw36NC0y5pRcVCcCOZq43l0E/vzk6EZvZ6WCEw9zkl zhrJhZrltpISmouZ7NrvDOFHiuwq8TuORXOPqwKoPivTJjTWeMzb248cKuJZo/vedZlr 838Q== X-Gm-Message-State: AOAM530a71kJMBQ/jk6kaafsMP/K7uzWgzy7PuFHd7j5soVNIzrdFySC Upx9KDNr3xFsX+d40t6tB+udpw== X-Received: by 2002:a2e:8896:: with SMTP id k22mr3254049lji.331.1592382706774; Wed, 17 Jun 2020 01:31:46 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id c3sm89554lfi.91.2020.06.17.01.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2020 01:31:46 -0700 (PDT) From: Linus Walleij To: Andrew Lunn , Vivien Didelot , Florian Fainelli Cc: netdev@vger.kernel.org, Linus Walleij , DENG Qingfang , Mauri Sandberg Subject: [net-next PATCH 3/5 v2] net: dsa: rtl8366: Split out default VLAN config Date: Wed, 17 Jun 2020 10:31:30 +0200 Message-Id: <20200617083132.1847234-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200617083132.1847234-1-linus.walleij@linaro.org> References: <20200617083132.1847234-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org We loop over the ports to initialize the default VLAN and PVID for each port. As we need to reuse the code to reinitialize a single port, break out the function rtl8366_set_default_vlan_and_pvid(). Cc: DENG Qingfang Cc: Mauri Sandberg Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebased on v5.8-rc1 and other changes. --- drivers/net/dsa/rtl8366.c | 70 ++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 27 deletions(-) -- 2.26.2 Reviewed-by: Andrew Lunn diff --git a/drivers/net/dsa/rtl8366.c b/drivers/net/dsa/rtl8366.c index ac88caca5ad4..66bd1241204c 100644 --- a/drivers/net/dsa/rtl8366.c +++ b/drivers/net/dsa/rtl8366.c @@ -253,6 +253,48 @@ int rtl8366_reset_vlan(struct realtek_smi *smi) } EXPORT_SYMBOL_GPL(rtl8366_reset_vlan); +static int rtl8366_set_default_vlan_and_pvid(struct realtek_smi *smi, + int port) +{ + u32 mask; + u16 vid; + int ret; + + /* This is the reserved default VLAN for this port */ + vid = port + 1; + + if (port == smi->cpu_port) + /* For the CPU port, make all ports members of this + * VLAN. + */ + mask = GENMASK(smi->num_ports - 1, 0); + else + /* For all other ports, enable itself plus the + * CPU port. + */ + mask = BIT(port) | BIT(smi->cpu_port); + + /* For each port, set the port as member of VLAN (port+1) + * and untagged, except for the CPU port: the CPU port (5) is + * member of VLAN 6 and so are ALL the other ports as well. + * Use filter 0 (no filter). + */ + dev_info(smi->dev, "Set VLAN %04x portmask to %08x (port %d %s)\n", + vid, mask, port, (port == smi->cpu_port) ? + "CPU PORT and all other ports" : "and CPU port"); + ret = rtl8366_set_vlan(smi, vid, mask, mask, 0); + if (ret) + return ret; + + dev_info(smi->dev, "Set PVID %04x on port %d\n", + vid, port); + ret = rtl8366_set_pvid(smi, port, vid); + if (ret) + return ret; + + return 0; +} + int rtl8366_init_vlan(struct realtek_smi *smi) { int port; @@ -266,33 +308,7 @@ int rtl8366_init_vlan(struct realtek_smi *smi) * it with the VLAN (port+1) */ for (port = 0; port < smi->num_ports; port++) { - u32 mask; - - if (port == smi->cpu_port) - /* For the CPU port, make all ports members of this - * VLAN. - */ - mask = GENMASK(smi->num_ports - 1, 0); - else - /* For all other ports, enable itself plus the - * CPU port. - */ - mask = BIT(port) | BIT(smi->cpu_port); - - /* For each port, set the port as member of VLAN (port+1) - * and untagged, except for the CPU port: the CPU port (5) is - * member of VLAN 6 and so are ALL the other ports as well. - * Use filter 0 (no filter). - */ - dev_info(smi->dev, "VLAN%d port mask for port %d, %08x\n", - (port + 1), port, mask); - ret = rtl8366_set_vlan(smi, (port + 1), mask, mask, 0); - if (ret) - return ret; - - dev_info(smi->dev, "VLAN%d port %d, PVID set to %d\n", - (port + 1), port, (port + 1)); - ret = rtl8366_set_pvid(smi, port, (port + 1)); + ret = rtl8366_set_default_vlan_and_pvid(smi, port); if (ret) return ret; }