From patchwork Tue Sep 12 12:22:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 138317 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp539766vqx; Tue, 12 Sep 2023 09:47:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCP/emMz/71JgNEt8C6E3WovVKPMB3z/PEG7mnGfMI4nOJLGKH6IFiLUMxRNan1pU0AZMg X-Received: by 2002:a17:902:daca:b0:1be:f2a1:22d8 with SMTP id q10-20020a170902daca00b001bef2a122d8mr321063plx.14.1694537264339; Tue, 12 Sep 2023 09:47:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694537264; cv=none; d=google.com; s=arc-20160816; b=eJGkDP2TsNAdQ/EfDs5qkN+CCnj9LTzEZitDZhQWk0dwhMOQws/2ctEe3HG0izoEhI 6tXD/KsjDMLegy/4BAYVCDKkT9y20719svJX9WFSWd2c7UdwWLxIJaoPMwoMO1DZaLc+ 8octPGztMOJ3WEdZDImGh4BtjwmM0Nsg6ejO4nqjXSatR0qO4xkyJXEF8It1CIiF5wqj slLlg5n3YCSBExpKquvH1hYMitCQXGAGjG0w4VS4LhIIEYRdbu1di91/Cxck6Y00H6tI 8pxS2UQRN9YxBnm3WjVoZL+XAFVK2eEhoH53BIUB31YzN4/81ymqqlvNKxVSYO+CAOPB eegQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HgSiRWdgC/hwg8MbvdGK6CbTNx/MfKCBd8+7AqLBFRs=; fh=7pT+hAKdFm8SgkIrQfctQAWhXj//sVAB1OFY1O6ncNU=; b=twCmCkLi0al1m/TFVT9VFHE0yPuuNHlpfz4yd35PRkyafSpFiazWg06vPGUhBJJ0xq SVf7nJAltwQD9vL8c7bj8P3iaREaPQ4znMaZvBlNTXGXSG0px5hgyIkTsZ723p32nILR 0O3YSOwHc9TbouxvPxTqGfFJUTW801Gz+SpVQO5KItAvGOlwIWCkEAX75ZYZt4LslKaU 7LurA/HA0ybWenPBGxxUaQby2IqczSGpw92NJcEeItQo8PfPyo4kzOxGWmDp+NnudWyg hmnayLe+7CGWOIefjDgqoBtJdkvXGWlCTKGhe+oceR7A/CuEw/+6dzGoEY2jVyYaZW44 IzTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DBrGfpj0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id jg20-20020a17090326d400b001bda57935f8si8075537plb.563.2023.09.12.09.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 09:47:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DBrGfpj0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 43EA58174A7F; Tue, 12 Sep 2023 05:27:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235230AbjILM1l (ORCPT + 37 others); Tue, 12 Sep 2023 08:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235173AbjILM1C (ORCPT ); Tue, 12 Sep 2023 08:27:02 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D12510DC; Tue, 12 Sep 2023 05:26:57 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2b9c907bc68so94669131fa.2; Tue, 12 Sep 2023 05:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694521615; x=1695126415; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HgSiRWdgC/hwg8MbvdGK6CbTNx/MfKCBd8+7AqLBFRs=; b=DBrGfpj0YAPt07jvbvXQLELOhfXIg+GNvApcKL5krt20XHcuLrl6vLY7HbCG2zEDLb glXZOArZvJ7WRF0lLJknFLW2eyFabvp+fLxZgO2OMwdgD/4CsKu4MS7MfmqWXxuOFmNx PrLtSNzu+e23NbKwQoEEB3xfkFmaB689C2i5TFuxS6ENipsoHFnKubxZHbntL9LstDL+ 8EjU8KJvWXqgt33GcGRXCpbgNIxRL9amSit73dOdduFM10UePeZKR3n+EA5HojjRmw6n AE9ZHaWo+a4LQIiAQgp5tdjapuLKw/9wZRnRc6imJ82YZ6YJiauMtOJYBEg/rBkDHOfD RsDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694521615; x=1695126415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HgSiRWdgC/hwg8MbvdGK6CbTNx/MfKCBd8+7AqLBFRs=; b=Z2qcqwou0lcaMUq60S31vuRIQ2NH+BqNNGD6nXM/FW0gcZ1RvMFydP0tPoI8TjF4Wa 7w5pMAFiPJQF3/yCFHJ+Pn0/KHN/YxnfcA2BOb1ONCFNyvhlR3eQOBgHBAgTpc00x4dt VL6uy362JDM3zufOy2DqKUTze/BaCX/+8ebduVY+oMJITGiF9fjzBRjMuHhDxdtOOT6m FRw1Q5Rep5riURfurI7aqARgHf0/sclmEnRvoU65L9MiE1hu5vK9SPVS3gC34k3ZtBaa J99rXK/e8xX92p2EVAgjiRp9FIFp77KPNJ74tTM3LaGUIomvKKcsWeNqRd7N+qOZS2xn x3ag== X-Gm-Message-State: AOJu0YyZ9Gul2twK2otTFaJWDG3+AZk0xiSdNvscQGtG+jPA8pYd8f9+ 49sPGuwgABBqycLQdjhvxz/mJXNENn4AaQ== X-Received: by 2002:a19:8c4b:0:b0:500:d8d6:fbe4 with SMTP id i11-20020a198c4b000000b00500d8d6fbe4mr9195198lfj.49.1694521615356; Tue, 12 Sep 2023 05:26:55 -0700 (PDT) Received: from WBEC325.dom.local ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id g21-20020ac25395000000b004fe333128c0sm1737327lfh.242.2023.09.12.05.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 05:26:55 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Dan Carpenter , Simon Horman , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 7/8] net: dsa: vsc73xx: Implement vsc73xx 8021q tagger Date: Tue, 12 Sep 2023 14:22:01 +0200 Message-Id: <20230912122201.3752918-8-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912122201.3752918-1-paweldembicki@gmail.com> References: <20230912122201.3752918-1-paweldembicki@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 12 Sep 2023 05:27:57 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776851106606712224 X-GMAIL-MSGID: 1776851106606712224 This patch is a simple implementation of 802.1q tagging in the vsc73xx driver. Currently, devices with DSA_TAG_PROTO_NONE are not functional. The VSC73XX family doesn't provide any tag support for external Ethernet ports. The only option available is VLAN-based tagging, which requires constant hardware VLAN filtering. While the VSC73XX family supports provider bridging, it only supports QinQ without full implementation of 802.1AD. This means it only allows the doubled 0x8100 TPID. In the simple port mode, QinQ is enabled to preserve forwarding of VLAN-tagged frames. The tag driver introduces the most basic functionality required for proper tagging support. Signed-off-by: Pawel Dembicki --- v3: - Split tagger and tag implementation into separate commits drivers/net/dsa/Kconfig | 2 +- drivers/net/dsa/vitesse-vsc73xx-core.c | 48 +++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index f8c1d73b251d..120bc3ded9f2 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -126,7 +126,7 @@ config NET_DSA_SMSC_LAN9303_MDIO config NET_DSA_VITESSE_VSC73XX tristate - select NET_DSA_TAG_NONE + select NET_DSA_TAG_VSC73XX_8021Q select FIXED_PHY select VITESSE_PHY select GPIOLIB diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index d9a6eac1fcce..bf903502bac1 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -589,7 +590,7 @@ static enum dsa_tag_protocol vsc73xx_get_tag_protocol(struct dsa_switch *ds, * cannot access the tag. (See "Internal frame header" section * 3.9.1 in the manual.) */ - return DSA_TAG_PROTO_NONE; + return DSA_TAG_PROTO_VSC73XX_8021Q; } static int vsc73xx_setup(struct dsa_switch *ds) @@ -664,6 +665,12 @@ static int vsc73xx_setup(struct dsa_switch *ds) mdelay(50); + rtnl_lock(); + ret = dsa_tag_8021q_register(ds, htons(ETH_P_8021Q)); + rtnl_unlock(); + if (ret) + return ret; + /* Release reset from the internal PHYs */ vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GLORESET, VSC73XX_GLORESET_PHY_RESET); @@ -1412,6 +1419,43 @@ static int vsc73xx_port_vlan_del(struct dsa_switch *ds, int port, return 0; } +static int vsc73xx_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid, + u16 flags) +{ + bool untagged = flags & BRIDGE_VLAN_INFO_UNTAGGED; + bool pvid = flags & BRIDGE_VLAN_INFO_PVID; + struct vsc73xx *vsc = ds->priv; + int ret; + + if (untagged) { + if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) { + ret = vsc73xx_vlan_set_untagged(ds, port, vid, false); + if (ret) + return ret; + } else { + vsc->untagged_storage[port] = vid; + } + } + if (pvid) { + if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) { + ret = vsc73xx_vlan_set_pvid(ds, port, vid, false); + if (ret) + return ret; + } else { + vsc->pvid_storage[port] = vid; + } + } + + return vsc73xx_update_vlan_table(vsc, port, vid, 1); +} + +static int vsc73xx_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid) +{ + struct vsc73xx *vsc = ds->priv; + + return vsc73xx_update_vlan_table(vsc, port, vid, 0); +} + static int vsc73xx_port_setup(struct dsa_switch *ds, int port) { struct vsc73xx *vsc = ds->priv; @@ -1519,6 +1563,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_vlan_filtering = vsc73xx_port_vlan_filtering, .port_vlan_add = vsc73xx_port_vlan_add, .port_vlan_del = vsc73xx_port_vlan_del, + .tag_8021q_vlan_add = vsc73xx_tag_8021q_vlan_add, + .tag_8021q_vlan_del = vsc73xx_tag_8021q_vlan_del, }; static int vsc73xx_gpio_get(struct gpio_chip *chip, unsigned int offset)