From patchwork Mon Jul 6 20:52:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 234889 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp307860ilg; Mon, 6 Jul 2020 13:53:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwchSnFT3NO4K7uLEDjsk7oUfRqWnK7TCmdsSYZtjXKBm3KspbabFddipaghCSY7sdqgR3v X-Received: by 2002:aa7:d3cd:: with SMTP id o13mr56536324edr.176.1594068785331; Mon, 06 Jul 2020 13:53:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594068785; cv=none; d=google.com; s=arc-20160816; b=aBmfitESTfXQULHPZ6oidSoE7u/s44ByuwSRMA9uAMz+R+QErYlrGGRGEb0qiI0DIR wydqi9JWlmlvDCGcE2GZ3Lz04yyD3k+vw9ImC4EuVF+Oc2Gciw2y0fJmbhGprP5KgaiF 6NdBwzZ814zpWulTPTDyPk2NHpeSBAa0FqTCJLliE8ZzkvCtU1xQPvwmsYQRiTroS6Ji h2DECUAA69+SuFe7d4MAMnHDZmasYyEMhbt1pMokWpAhOkgC+FXHBgm5P5Fy+0pp48RZ T9JJ57M5rPQg+pT0l6CCiIW+IM8NUhk9opb6tl/umPu3b+i7fcaB0UNdhIFWGKXojDms pkKg== 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=IGRiCDosImo09IoK/bbV7wmdxtWQy6UAfjTnx38Q7Bo=; b=K33DaaFAHw5iP/I0jaDrudJFWx6+USMHxONlPPaeMI7ujF7a2V2ffb1kPIp9Yu13nB fEw3+gjTr3e9OECfNSqlY4NFaF9td5BB2ovOxpfc8o2pqG0yFRb9sXWfp3eMqOmy6SdK t4lpQARMOELmDOIbpy1YAXnE81bf1iVgGxfv3gZUhLQ+Rissz0tq7pnKGIIr+IY2pU6f 7C4NmmXkhe2OwbiGAI0es86LjaA944Uy1694aQXA4w+zpKcm9p3pYAa98DRlCG8kWYi5 /b+SugllnnN8yg2/kGVz2vgysXla7mX/zRHPELxs+1eIJCLZ9faVlbpoaauYq5Ef8j13 HOlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YbumsW7b; 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 k2si13319295eds.173.2020.07.06.13.53.05; Mon, 06 Jul 2020 13:53:05 -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=YbumsW7b; 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 S1727031AbgGFUxE (ORCPT + 9 others); Mon, 6 Jul 2020 16:53:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725941AbgGFUxD (ORCPT ); Mon, 6 Jul 2020 16:53:03 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83000C08C5DF for ; Mon, 6 Jul 2020 13:53:02 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id h22so40053553lji.9 for ; Mon, 06 Jul 2020 13:53:02 -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=IGRiCDosImo09IoK/bbV7wmdxtWQy6UAfjTnx38Q7Bo=; b=YbumsW7bQiN1yq7HrBRq3mtBzVIIOdhbZitKA3MVoINuEVSsetVz+FYmvYoqTnAOdm /pEYTx+SNIuj13maKN/UsybPzw21/Kb2YVqv+LtbZsT0A3MZYg62MiCCnxsTTQsn+OAj MLJGEawGQAhKq8LOBu+mKHULLkWWs3fNPxJQyKUlfQkJ+mnbp6VNvmLCHtcV0OzntVvr 81xyB5hWJa++60i5ZJJRgfVFbObM4qdaWX/g3T7rnJf2zbOaYI6kshJk94Sxrqxj5ZV0 uWDyeSSZBBKLUHBGrsF9sU/7Ew58Xamp/wbznbvupslRnLRGMYuPB6o5MjvIH6BujA5E TFQA== 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=IGRiCDosImo09IoK/bbV7wmdxtWQy6UAfjTnx38Q7Bo=; b=kzS1DCbpbSygAh1UOdFlMCaaGebyxQkJ1TFu1NlHnil6Qgr06gVevzNAsP7+LvtYNU UmGYZiCmQqkJg5EudQOV+eN5wnBwL2gJ+cMO61CRrSJZH8uD+WuY437D+buMYZbQvpM3 fEwFfKDu2pJskZB0N6W45H27LilAEyjj/eEEEoHjcwBNns9mE/AHTjNdnwevCuG9HSLF oqZEey/RzsqrU2Td+DOQ6HlnQBazNSaEfEk5wqf3rAnFVntDefIxZAh9k3Mm3SAvnqtb /osYBBgo3P6UmXk7btI4z2/2gHxbmL9fuGGhpCxKQ/G5+ndCsljKsJtfy8N+qOw9toY7 mJVA== X-Gm-Message-State: AOAM532Vq9PcXB3gFgDrcuh9HE12U0MLdCWCzBv8gtCR0BdOWZacNijY gwWg5UKu0myajg9WDUjLrAnwrQ== X-Received: by 2002:a2e:730c:: with SMTP id o12mr22541989ljc.165.1594068780891; Mon, 06 Jul 2020 13:53:00 -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 t10sm624714ljg.60.2020.07.06.13.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2020 13:53:00 -0700 (PDT) From: Linus Walleij To: Andrew Lunn , Vivien Didelot , Florian Fainelli , netdev@vger.kernel.org, "David S . Miller" Cc: Linus Walleij , DENG Qingfang , Mauri Sandberg Subject: [net-next PATCH 3/5 v4] net: dsa: rtl8366: Split out default VLAN config Date: Mon, 6 Jul 2020 22:52:43 +0200 Message-Id: <20200706205245.937091-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200706205245.937091-1-linus.walleij@linaro.org> References: <20200706205245.937091-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 Reviewed-by: Andrew Lunn Signed-off-by: Linus Walleij --- ChangeLog v3->v4: - Resend with the rest ChangeLog v2->v3: - Rebased on Andrew's patch for the (int) compile warning on GENMASK(). change is carried over. - Collect Andrew's review tag. 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 diff --git a/drivers/net/dsa/rtl8366.c b/drivers/net/dsa/rtl8366.c index 993cf3ac59d9..b907c0ed9697 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((int)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((int)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; }